Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / move multiple sprites (commanding multiple sprites)

Author
Message
scuzz
14
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 18th Jul 2010 18:26
Hey, I am making a "dodge the objects" game, so i need to create multiple sprites and have them move up (or across) the screen but i cant seem to find the right code - unless i use my super uneffecient code.
[code
load image "balloon.bmp",1
load image "thorn.bmp",2

rem create thorns
for x = 2 to 10
xpos=rnd(500)
ypos=rnd(2000)
sprite x,xpos,ypos,2
scale sprite x, 25
next x

xpos1 = 100
ypos1 = 100
do
rem controls
if leftkey() <> 0 then dec xpos1
if rightkey() <> 0 then inc xpos1
if upkey() <> 0 then dec ypos1
if downkey() <> 0 then inc ypos1
sprite 1,xpos1,ypos1,1
move sprite 2,1
move sprite 3,1
move sprite 4,1
move sprite 5,1
move sprite 6,1
move sprite 7,1
move sprite 8,1
move sprite 9,1

if sprite collision (2,1) then hide sprite 1
if sprite collision (3,1) then hide sprite 1
if sprite collision (4,1) then hide sprite 1
if sprite collision (5,1) then hide sprite 1
if sprite collision (6,1) then hide sprite 1
if sprite collision (7,1) then hide sprite 1
if sprite collision (8,1) then hide sprite 1
loop

end
]
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 18th Jul 2010 19:15 Edited at: 18th Jul 2010 19:16
You can use a FOR loop to move the sprites just like you did to create them:



Also, for the code tags, you just need to put a [code ] tag before your code and then a [/code ] tag after it, don't try to jam your code inside the tag .

scuzz
14
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 19th Jul 2010 00:21
thanks a lot, exactly what i was looking for.

but how would i get sprites to be created randomly in between 2 given positions. For instance, instead of ypos=rnd(2000) I wanted it to spawn between 1500 and 3500.
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 19th Jul 2010 00:24
Just a little addition .



scuzz
14
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 19th Jul 2010 02:04
thanks man, you are very helpful. oneee lasstttt question lol. do you by any chance know how to make a counter - so when you die it can say "you lasted 52 seconds" or "you dodged 36 objects"
BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 19th Jul 2010 02:19
No problem. You might try some tutorials next time, though, these are pretty basic questions that would probably be answered by a good beginner tutorial: this is a good one.

For your counter, you would want to use a variable (see the above tutorial for more info about these). You would set the variable to 0 at the beginning:

counter=0

And then increase it every time the counted thing happened...so, for example, every time one of the objects moves past the player you would do:

counter=counter+1
or
inc counter

Time is a little easier - there is the command TIMER(), which counts time in milliseconds. You would store the time at the beginning of the game with another variable:

timecounter=timer()

And at the end of the game, calculate the time elapsed with it:

timeelapsed=timer()-timecounter

scuzz
14
Years of Service
User Offline
Joined: 27th Mar 2010
Location:
Posted: 19th Jul 2010 02:59
thanks a lot. and yeah, sorry for the amatuer questions, ill check out that tutorial.

Login to post a reply

Server time is: 2024-11-24 14:01:48
Your offset time is: 2024-11-24 14:01:48