Computer Science Canada

Enemies in Game

Author:  13erka [ Tue Nov 02, 2004 12:15 pm ]
Post subject:  Enemies in Game

Hello. I`m extremely new to Turing and programming in general. I wanted to make a game in Turing similar to Space Invaders or any other game where all you have to do is shoot the ememies. This is what I have so far:

code:

View.Set ("position:centre;centre,graphics:750;500,offscreenonly")
colorback (black)
cls
% This controls maple
var x:int:=0
var y:int:=0
var charr1:array char of boolean
var rr1:int
var bg2:int
procedure DN1
View.Set ("offscreenonly")
% Maple goes right
Input.KeyDown (charr1)
locate (4,1)
if charr1 (KEY_RIGHT_ARROW) then
cls
x:=x+5
rr1:=Pic.FileNew ("stance.bmp")
Pic.Draw(rr1,x,y,picMerge)
Pic.Free(rr1)
delay (10)
View.Update
end if
% Maple goes up
Input.KeyDown (charr1)
locate (4,1)
if charr1 (KEY_UP_ARROW) then
cls
y:=y+5
rr1:=Pic.FileNew ("stance.bmp")
Pic.Draw(rr1,x,y,picMerge)
Pic.Free(rr1)
delay (10)
View.Update
end if
% Maple goes up
Input.KeyDown (charr1)
locate (4,1)
if charr1 (KEY_DOWN_ARROW) then
cls
y:=y-5
rr1:=Pic.FileNew ("stance.bmp")
Pic.Draw(rr1,x,y,picMerge)
Pic.Free(rr1)
delay (10)
View.Update
end if
% Maple goes left
Input.KeyDown (charr1)
locate (4,1)
if charr1 (KEY_LEFT_ARROW) then
cls
x:=x-5
rr1:=Pic.FileNew ("stance.bmp")
Pic.Draw(rr1,x,y,picMerge)
Pic.Free(rr1)
delay (10)
View.Update
end if
% Maple punches
Input.KeyDown (charr1)
locate (4,1)
if charr1 (KEY_ENTER) then
cls
rr1:=Pic.FileNew("Punch.bmp")
Pic.Draw(rr1,x,y,picMerge)
Pic.Free(rr1)
View.Update
delay (100)
cls
rr1:=Pic.FileNew("stance.bmp")
Pic.Draw(rr1,x,y,picMerge)
Pic.Free(rr1)
View.Update
end if
% Maple points
Input.KeyDown (charr1)
locate (4,1)
if charr1 (KEY_BACKSPACE) then
cls
rr1:=Pic.FileNew("point.bmp")
Pic.Draw(rr1,x,y,picMerge)
Pic.Free(rr1)
View.Update
delay (100)
cls
rr1:=Pic.FileNew("stance.bmp")
Pic.Draw(rr1,x,y,picMerge)
Pic.Free(rr1)
View.Update
end if

end DN1


loop
DN1
end loop
%end of maple control


I think my variables are pretty easy to understand. Now for my question:

How do I make enemies and how can I get Maple (the main character) to shoot them?

Author:  Delos [ Tue Nov 02, 2004 3:15 pm ]
Post subject: 

Well, let's see...

For this you'll want to look up types and records so that you'll be able to consider the entire character as one 'piece' as opposed to fifty variables floating around the place.

You seem to have the grasp of basic animation down, so creating a 'shooting' object from your character won't be difficult.

I especially like the way you've procedurized your programme. Given, you could have done a lot more of if (and I'd suggest you do), but for a beginner this is a great habit to get into.

Essentially, you'll have a number of enemy-type objects floating around...and within each loop of your main loop (the one you have at the bottom), you'll check what's going on with them. Every few loops, you can call a condition to move them, or to create some more of them, or whatever.
Also in this woderful loop, you can have your Input Detection going on. When the right key is pressed, you can call a procedure to create some sort of 'shooting' picture near your main character. This will itself be an object type thing...which will then be looked during each loop.

Is this making sense to you yet? You seem to be on the right track, even if something like this is quite a stretch for a beginner...


Arrow
Useful links.
Records
Records by Dodge
Ifs by tony
Arrays by Dodge
Arrays by tony


Good luck.

Author:  13erka [ Wed Nov 03, 2004 5:07 pm ]
Post subject:  Thanks a bunch!

Thanks a lot! I'll see if I can work it out at school.


: