forums

TNT Basic Forums > Programming Q&A
Help with sprites
< Last Thread     Next Thread >
Author
Thread        Post A Reply

02-27-2006 16:45

Posted by:
MickMad

Location:
San Giovanni Rotondo, Italy

Click Here to Email MickMad   Find more posts by MickMad

Hi all,
I'm trying to make my first game in TNT Basic and so i decided to try a Space Invaders Clone.Simple.Or not?
At first i made a procedure to just draw the aliens, then I created another one to move them...they actually move, but when the aliens arrive to the end of the screen they should go down and walk backwards (everyone should know how they move, however)...
this is all the code


activate input
graphics mode 1024,768
set pen colour black
fill rect 0,0 to 1024,768
load images 128

global int alieni=0
global int alienoposx=74,alienoposy=10
global int morti=0
global int alienovel=10

sprite 10,544,694,2
drawalieni()
alieni=0
alienoposx=74
alienoposy=10

while not mouse button
movealieni()
wend

'Procedure

procedure drawalieni()
for alieni = 0 to 4
sprite alieni,alienoposx,alienoposy,0
alienoposx=alienoposx+74
next alieni
alienoposy=alienoposy+74
sprite 5,alienoposx,alienoposy,0
alienoposx=74
alieni=alieni+1
for alieni = 5 to 9
sprite alieni,alienoposx,alienoposy,0
alienoposx=alienoposx+74
next alieni
draw frame
end proc


procedure movealieni()
for alieni=0 to 9
if sprite X (4) >= 1014 or sprite x (9) >= 1014 or sprite X (0) <= 10 or sprite x (5) <=10
alienovel=-alienovel
alienoposy=sprite y (alieni)+10
alienoposx=sprite x (alieni)+alienovel
else
alienoposx=sprite x (alieni)+alienovel
alienoposy=sprite y (alieni)
end if
sprite alieni,alienoposx,alienoposy,0
draw frame
next alieni
end proc



The BOLD part is the moving procedure.
If you try this with 64x64 sprites (0 is the alien,2 the spacecraft) you 'll notice that when the aliens touch the rightmost part of the screen, they "disassmeble themselves", that is to say the upper aliens go into a way and the lower into another...try it and you'll say:"What the heck!?"..

For now this is only a test, to see how to move loads of sprites at the same time, later I'll add shooting and new aliens and waves and counters....

Well, if someone can help me, answer to this post...meanwhile I'll try to get at it myself...

02-27-2006 16:52

Posted by:
MickMad

Location:
San Giovanni Rotondo, Italy

Click Here to Email MickMad   Find more posts by MickMad

forgot this

I forgot to say that I use a FOR...NEXT for the moving procedure, but I'd like to know if there's a non-iterative cycle, but a cycle that checks the condition i ask to check for the elements i give, so that it checks if the rightmost aliens are near the wall and move all aliens backwards?????

02-27-2006 17:24

Posted by:
MickMad

Location:
San Giovanni Rotondo, Italy

Click Here to Email MickMad   Find more posts by MickMad

I almost made it

Ok, I tried to do this thing work with MOve Sprite...it's actually working, but the only thing i get is a bunch of aliens going back and forth onto my screen...
the procedure is


global int distx=634,disty=0

procedure movealieni()
repeat
if sprite x (4) >= 1014 or sprite x (0) <= 64

distx=-distx
disty=10

end if

move sprite 0,distx,disty,alienovel
move sprite 1,distx,disty,alienovel
move sprite 2,distx,disty,alienovel
move sprite 3,distx,disty,alienovel
move sprite 4,distx,disty,alienovel
move sprite 5,distx,disty,alienovel
move sprite 6,distx,disty,alienovel
move sprite 7,distx,disty,alienovel
move sprite 8,distx,disty,alienovel
move sprite 9,distx,disty,alienovel

disty=0

draw frame
until mouse button
end proc


Any help?

02-27-2006 17:49

Posted by:
MickMad

Location:
San Giovanni Rotondo, Italy

Click Here to Email MickMad   Find more posts by MickMad

HURRAY!

OK I FINALLY GOT IT!
Now I did this with a For into the If, since they only hv to go down when they begin going backwards...se the code to understand what i did...maybe if i finish it soon, I'll post it here, maybe as a Gmae in 60...




procedure movealieni()
repeat
if sprite x (4) >= 1014 or sprite x (0) <= 64
distx=-distx
for alieni = 0 to 9
alienoposy=sprite y (alieni)+10
sprite alieni,sprite x (alieni),alienoposy,0
next
end if
move sprite 0,distx,0,alienovel
move sprite 1,distx,0,alienovel
move sprite 2,distx,0,alienovel
move sprite 3,distx,0,alienovel
move sprite 4,distx,0,alienovel
move sprite 5,distx,0,alienovel
move sprite 6,distx,0,alienovel
move sprite 7,distx,0,alienovel
move sprite 8,distx,0,alienovel
move sprite 9,distx,0,alienovel
draw frame
until mouse button
end proc

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.