Game Development Community

dev|Pro Game Development Curriculum

Spin Break Dev Blog 02 - Pieces

by Jeremy Easoz · 04/09/2012 (9:15 am) · 2 comments

Disclaimer: Code here may or may not be optimal or even correct. I am the type of programmer that makes things work regardless of "right" or "wrong". In my opinion, developers that do will always come out ahead of developers that talk. Having a working product puts you ahead of the game.

Thanks to TorqueScript and the console you can quickly program pieces of your game and test them without worry or reliance on game logic.

Im my last blog I outlined pieces of the game and we will discuss some of this today.

A typical game session for Spin Break may look like this.
-Level Load--->Countdown Timer Start
-Countdown Timer End--->Start Input--->Start Rotating Spinner
-Spinner Exits Starting Zone--->Start Level Timer
-If the Spinner Takes Damage 3 Times --->Game Over
-If the Spinner Enters Goal Zone --->Stop Timers --->Load Next Level

The above game session is void of any fluff. No music, sounds, game over or victory fanfare. It's the game at it's very core.

Let's break the above into pieces we can program and test individually.
-Countdown Timer
-Input
-Spinner Object
-Start Zone (Triggers)
-Goal Zone (Triggers)

www.jeremyeasoz.com/dev/designs/spinbreak/sprite-spinner.pngLet's start with the Spinner Object. This is the main object of the game and connects to or affects many other objects of the game. We should focus on this first. First some questions.

What is it?
-t2dStaticSprite
What does it do?
-Rotates
-Moves
-Receives Input
-Collides with objects
-Modifies triggers
-Takes damage
(Maybe more)

Rotation
The design only calls for clockwise rotation, setAutoRotation(%speed) will rotate our static sprite clockwise if we feed it a positive number and counterclockwise for a negative number. It's not in the design but for almost 0 extra work we can do both. We should also keep track of the direction the spinner is spinning.

$so_RotationSpeed = 60.0;
$so_CurrentRotationDirection = "clockwise";

function SpinnerObject::rotateClockwise()
{
   $so_CurrentRotationDirection = "clockwise";
   soSpinner.setAutoRotation($so_RotationSpeed);
}

function SpinnerObject::rotateCounterClockwise()
{
   $so_CurrentRotationDirection = "counterClockwise";
   soSpinner.setAutoRotation(-$so_RotationSpeed);
}

Thanks to TorqueScript and the console we can have instant gratification of seeing our work in action.

-Open TGB
-Open or Create your project
-Create a new ImageMap
-Load crappy programmer art
-Drag it onto your level
-Edit the scripting section, class=SpinnerObject name=soSpinner
-Press play

This is where the fun comes in. The console allows you to compile scripts, recompile scripts, and exectue and change code on the fly. Typing exec("game/gameScripts/spinnerObject.cs"); into the console will compile the code for the spinner object. We have two functions SpinnerObject::rotateClockwise(); and SpinnerObject::rotateCounterClockwise(); Each of these functions can also be exected from the console. $so_rotationSpeed is a global so it can be modified from the console as well. You can type $so_rotationSpeed = 500; and then call SpinnerObject::rotateClockwise(); again to see the change in rotational speed. This is just a small example of the power of TorqueScript and the console. Imagine when you have the Countdown Timer, Level Timer, and various other objects created. You execute and test your game piece by piece through the console.

"Level Load--->Countdown Timer Start"
-CountdownTimer::start();
"Countdown Timer End--->Start Input--->Start Rotating Spinner"
-moveMap.push();
-SpinnerObject::RotateClockwise();
"Spinner Exits Starting Zone--->Start Level Timer"
-LevelTimer::start();

I think you see where this is going and it's a heck of a lot faster than recompiling the engine all day. TorqueScript is awesome on it's own but with the power of the console it turns Torque 2D into your own personal sandbox of game development.

I'm a little ahead on development compared to the dev blog so screenshots and videos will contain elements of the game that haven't been talked about here yet.


#1
04/09/2012 (12:11 pm)
So, do all spinners rotate at the same speed? Or will some spinners rotate at different speeds?

For the same reason you like to use TS to build programs I really like to use Python for testing algorithms. Must quicker to prototype.
#2
04/09/2012 (12:36 pm)
The Spinner will always rotate at a constant speed. The rate of speed at which it rotates may be something I change depending on difficulty. Beginner will rotate slower than normal and pro mode will spin faster than normal. Otherwise the speed is constant from level to level