Posted: Fri Jan 13, 2006 5:31 pm Post subject: more than one movement at the same time
hi
i'm trying to make a game where i have a box and i can move it with the arrow keys, and also want to move circles across the screen at the same time. when ever i try to do it, only the circles move. I was wonder if someone could explain to me how to do both at the same time.
Font.Draw ("Instructions", 290, 75,(Font.New ("arial:10:bold,")),white)
Font.Draw ("Shoot the asteroids as they come down. Each time you shoot one, the next one comes faster.", 23, 55,(Font.New ("arial:10:bold,")),white)
Font.Draw ("If you let one go past you or if you get hit by one then you lose!", 125, 35,(Font.New ("arial:10:bold,")),white)
% mouse button
loop % A
mousewhere (x,y,b)
if x>250 and x<400 and y>100 and y<175 and b=1 then % B
delay (5)
cls
%background
drawfillbox (0,0,maxx,maxy,black)
for i : 0 .. 250 %stars in background
drawdot (Rand.Int (0, maxx), Rand.Int (0, maxy), 0)
end for
%draw ship
drawfillbox (x1, y1, x2, y2, 0)
%set movement
loop % C
Input.KeyDown (chars) %set input key down for movement
locate (1, 1)
%up arrow/direction
if chars (KEY_UP_ARROW) then % D
if y2 < 380 then %stop from going off the screen
drawfillbox (x1, y1, x2, y2, 255) %to cover box
y1 += 5 %to move box
y2 += 5
drawfillbox (x1, y1, x2, y2, 0) %box
delay (0)
end if
%right arrow
elsif chars (KEY_RIGHT_ARROW) then
if x2 < maxx then %stop from going off the screen
drawfillbox (x1, y1, x2, y2, 255) %to cover box
x1 += 5 %to move box
x2 += 5
drawfillbox (x1, y1, x2, y2, 0) %box
delay (0)
end if
%left arrow
elsif chars (KEY_LEFT_ARROW) then
if x1 > 0 then %stop from going off the screen
drawfillbox (x1, y1, x2, y2, 255) %to cover box
x1 -= 5 %to move box
x2 -= 5
drawfillbox (x1, y1, x2, y2, 0) %box
delay (0)
end if
%down arrow
elsif chars (KEY_DOWN_ARROW) then
if y1 > 0 then %stop from going off the screen
drawfillbox (x1, y1, x2, y2, 255) %to cover box
y1 -= 5 %to move box
y2 -= 5
drawfillbox (x1, y1, x2, y2, 0) %box
delay (0)
end if
end if % D
%make shooting
if chars (KEY_ENTER) then
shoot:=1
end if
if shoot = 1 then
drawfillbox (sx1, sy1, sx2, sy2, 255) %to cover shot
sy1 += 10 %to move box
sy2 += 10
drawfillbox (sx1, sy1, sx2, sy2, 14) %shot
end if
if sy1> maxy then
shoot := 0
end if
if shoot = 0 then
sx1 := x1+5
sy1 := y1+12
sx2 := x2-5
sy2 := y2+12
end if
delay (50)
loop
if a1 > 200 then
drawoval (b2 , maxy-a2, 20, 20, 0)
delay (16)
drawoval (b2 , maxy-a2, 20, 20, 255)
a2:= a2+1
end if
exit when a2 = 400
end loop
delay (1000)
loop
if a2 > 200 then
drawoval (b3 , maxy-a3, 20, 20, 0)
delay (14)
drawoval (b3 , maxy-a3, 20, 20, 255)
a3:= a3+1
exit when a3 = 400
end if
end loop
delay (1000)
loop
if a3 > 200 then
drawoval (b4 , maxy-a4, 20, 20, 0)
delay (12)
drawoval (b4 , maxy-a4, 20, 20, 255)
a4:= a4+1
end if
exit when a4 = 400
end loop
delay (1000)
loop
if a4 > 200 then
drawoval (b5 , maxy-a5, 20, 20, 0)
delay (10)
drawoval (b5 , maxy-a5, 20, 20, 255)
a5:= a5+1
end if
exit when a5 = 400
end loop
delay (1000)
loop
if a5 > 200 then
drawoval (b6 , maxy-a6, 20, 20, 0)
delay (8)
drawoval (b6 , maxy-a6, 20, 20, 255)
a6:= a6+1
exit when a6 = 400
end if
end loop
delay (1000)
loop
if a6 > 200 then
drawoval (b7 , maxy-a7, 20, 20, 0)
delay (6)
drawoval (b7 , maxy-a7, 20, 20, 255)
a7:= a7+1
end if
exit when a7 = 400
end loop
delay (1000)
loop
if a7 > 200 then
drawoval (b8 , maxy-a8, 20, 20, 0)
delay (4)
drawoval (b8 , maxy-a8, 20, 20, 255)
a8:= a8+1
exit when a8 = 400
end if
end loop
delay (1000)
loop
if a8 > 200 then
drawoval (b9 , maxy-a9, 20, 20, 0)
delay (2)
drawoval (b9 , maxy-a9, 20, 20, 255)
a9:= a9+1
end if
exit when a9 = 400
end loop
delay (1000)
loop
if a9 > 200 then
drawoval (b10 , maxy-a10, 20, 20, 0)
delay (0)
drawoval (b10 , maxy-a10, 20, 20, 255)
a10:= a10+1
end if
exit when a10 = 400
end loop
and try to move it works
so i only can't move when this part comes in
Tony
Posted: Fri Jan 13, 2006 7:08 pm Post subject: (No subject)
that is because you have a bunch of loops with delays in them. It takes quite a while for those loops to finish, and you're not checking for any input while inside the loops.
Posted: Fri Jan 13, 2006 7:44 pm Post subject: (No subject)
oooo
i get what you mean
so you're saying that i need to get the program to check for inputs while the asteroids fall.
hmmm
how would i do that though?
Tony
Posted: Fri Jan 13, 2006 8:31 pm Post subject: (No subject)
step procedures
code:
loop
check input
you move 1 step
asteroid moves 1 step
end loop
currently you have your loops set up so that an asteroid would move from beginning to end before letting go of the controls. Try to figure out how to let the asteroid move just 1 step, let go of the controls, and resume from where it left of next time
Posted: Fri Jan 13, 2006 8:46 pm Post subject: (No subject)
i'm not sure of what you saying....
what do you mean by letting go of the controls?
do you mean that i should get the program to check for inputs constantly before each move of the asteroid?
Sponsor Sponsor
Tony
Posted: Fri Jan 13, 2006 9:14 pm Post subject: (No subject)
(O_o) wrote:
do you mean that i should get the program to check for inputs constantly before each move of the asteroid?
not only check, but also process and move the user accordingly
Posted: Fri Jan 13, 2006 9:30 pm Post subject: (No subject)
so do you mean somthing like this?
code:
loop
if chars (KEY_UP_ARROW) then
if y2 < 380 then %stop from going off the screen
drawfillbox (x1, y1, x2, y2, 255) %to cover box
y1 += 5 %to move box
y2 += 5
drawfillbox (x1, y1, x2, y2, 0) %box
end if