Author Topic: Smart Oscillating Objects  (Read 1116 times)

WetWookie

  • Cherry Eater
  • Posts: 90
  • OS:
  • Windows 10 Windows 10
  • Browser:
  • Firefox 49.0 Firefox 49.0
    • View Profile
  • Playstyle: Keyboard
Smart Oscillating Objects
« on: November 04, 2016, 11:28:41 AM »
As a thank you to TJ for hosting his Distances, Triangles, and Trig: For Game Makers class I've decided to release something a little special.

I present to you the Smart Oscillating Object (in this case packaged as an circular saw). To use the SOO you give it minimum and maximum x and y values, a speed for each axis and then place the object in the room anywhere between. The object will automatically calculate its speed, position and direction to continue its movement in each axis as an independent sine wave by calculating the inverse sine of the distance between the center of the two extremes and the location you placed the object in the room.

In the creation code of the object you'll set the following variables
MinX = The minimum x value
MaxX = The maximum x value
MinY = The minimum y value
MaxY = The maximum y value
TimeX = The number of room steps to travel from MinX to MaxX (ie TimeX = room_speed * 2; //Travel time of 2 seconds)
TimeY = The number of room steps to travel from MinY to MaxY (ie TimeY = room_speed * 2; //Travel time of 2 seconds)
XDir = The direction to start moving in the x axis (XDir = 1; will make the object move to the right to start. XDir = -1; will make the object move to the left to start.)
YDir = The direction to start moving in the x axis (YDir = 1; will make the object move down to start. XDir = -1; will make the object move up to start.)
MoveTypeX = The type of movement in the X direction. (Setting the value to Smooth makes the object move in a sine wave and Linear makes the object move at a constant speed);
MoveTypeY = The type of movement in the Y direction. (Setting the value to Smooth makes the object move in a sine wave and Linear makes the object move at a constant speed);




In this example the two saws have been stacked on top of each other at position (480, 256)
One saw has the following creation code
(click to show/hide)
The second saw's creation code is the same except that the XDir is set to 1 to make it start moving to the right. The movement in the X axis is being done at a constant speed while the movement in the Y axis is being done in a smooth sine wave automatically calculated based on the starting position's relationship to the min and max y values.



All four of these saws share the exact same creation code but because they were each placed in one of the four corners the sine waves for each were calculated based on their individual starting position.

(click to show/hide)
« Last Edit: November 04, 2016, 12:50:58 PM by WetWookie »