
-----------------------------------
Insectoid
Tue Aug 12, 2008 9:54 pm

[Tutorial] Your Very First Game
-----------------------------------
This is a tutorial to teach new programmers the basics of game making, all in one spot. This tutorial will cover the following areas, as well as provide links to tutorials that explore the topic more deeply:

-Character Movement
	- 8 point movement
	- 360 movement
	- Jumping

-Collision Detection
	-Whatdotcolor
	-Rectangular
	-Basic circle

-Sprites in Turing

-Important things to remember


Oh, and this is my first tutorial, so woo!

-----------------------------------
Insectoid
Tue Aug 12, 2008 10:04 pm

Re: [Tutorial] Your Very First Game
-----------------------------------
Movement

8-point movement

8-point movement is the simplest way to move a character. It isn't the best, though, because you can only move in 8 directions! It takes only a few lines of code to do. 

The first thing to learn is the command 'Input.KeyDown'. It works like this:


var keys : array char of Boolean %This is the variable you need. Don't ask about the 'array char of boolean', it doesn't matter.
loop
	Input.KeyDown (keys) %This tells the computer to check if a key is pressed, and which one
	If keys (KEY_UP_ARROW) then %this says 'if a key is pressed and the key pressed is the up arrow, then do something (in this case, increase the Y value).
		y += 1 
	End if
end loop


"So, now I know the command, how do I use it?"

Well, movement is all about changing the X and Y values of the character. So, in pseudo code, 


if (KEY_UP_ARROW) is pressed then
	y += 1  % this is the same as Y := Y + 1
End if
If (KEY_DOWN_ARROW) is pressed then
	y -= 1
End if
If (KEY_LEFT_ARROW) is pressed then
	x -= 1
end if
if (KEY_RIGHT_ARROW) is pressed then
	x += 1
end if


Get it? Great! Now we can create movement!


var x : int := 100
var y : int := 100
var keys : array char of boolean

loop
    Input.KeyDown (keys)
    if keys (KEY_UP_ARROW) and y < maxy then %makes sure the character won't go past the top of the screen
        y += 1
    end if

    if keys (KEY_DOWN_ARROW) and y > 0 then
        y -= 1
    end if

    if keys (KEY_LEFT_ARROW) and x > 0 then
        x -= 1
    end if

    if keys (KEY_RIGHT_ARROW) and x < maxx then
        x += 1
    end if
    Draw.FillOval (x, y, 10, 10, red)
    delay (10)
    cls
end loop


So now you've mastered 8-point movement. Great! But 8-point movement is pretty lame. 360 degrees is way more fun!


360 Degree Movement
 
     360 degree movement is far more fun than 8-point, because you can move in any direction! It is a bit more complicated though, because instead of directly manipulating the X and Y values, you adjust the amount added to them. This is where velocity comes in.

In 8-point movement, the velocity of the character is a set amount (in my case, 1). In 360, the velocity is controlled by the arrow keys. Since this is a new element in our program, we have to make it a variable:


var y_velocity : int := 0 % This should be zero at the start of the game
var x_velocity  : int := 0   


So, how do you use this in a game? I'll show you.


var x : int := 100
var y : int := 100
var x_velocity : int := 0
var y_velocity : int := 0

var keys : array char of boolean

loop
    Input.KeyDown (keys)
    if keys (KEY_UP_ARROW) and y_velocity < 5 then %makes sure the character won't go past the top of the screen
        y_velocity += 1 %See here, we are changing the velocity instead of the coordinates
    end if

    if keys (KEY_DOWN_ARROW) and y_velocity > -5 then % we also set the max speed here (5)
        y_velocity -= 1
    end if

    if keys (KEY_LEFT_ARROW) and x_velocity > -5 then
        x_velocity -= 1
    end if

    if keys (KEY_RIGHT_ARROW) and x_velocity < 5 then
        x_velocity += 1
    end if

    if y >= maxy or y = maxx or x 