Help with For loop that gets stuck in my game
Author |
Message |
MOUSECORD
|
Posted: Thu Jun 10, 2004 7:20 pm Post subject: Help with For loop that gets stuck in my game |
|
|
Hey i'm making missile command and this part of my game... the anti missile part -----
[code]
procedure mouse
var mousex, mousey, button : int
mousewhere (mousex, mousey, button)
if button = 1 then
for rad: 1..25
cls
drawfilloval (mousex, mousey, rad, rad, 66)
delay(25)
end for
for decreasing rad: 25..1
cls
drawfilloval (mousex, mousey, rad, rad, 66)
delay(25)
end for
end if
end mouse
loop
cls
mouse
delay(25)
View.Update
end loop
[code]
if i put something else in the loop say one of my misiles for the game (missile command) the missile lags until the mouse procedure is finished.... is there any way to get around this and still have the same Mouse Procedure affect ... i really need this anyone knows??[/code] |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Paul
|
Posted: Thu Jun 10, 2004 7:30 pm Post subject: (No subject) |
|
|
put the whole expanding/shrinking circles thingy in the main loop, that is not in its own for loop, and have a the radius decrease / increase using if statements in the loop, while ur other parts run at the same time.
Ur other option is to use a process, but some ppl here do not like processes, and for me they make View.Update harder to use. |
|
|
|
|
|
MOUSECORD
|
Posted: Thu Jun 10, 2004 8:35 pm Post subject: (No subject) |
|
|
okay but i'm not sure how to use if statements to make something add smoothly like that only jump to it...? |
|
|
|
|
|
Paul
|
Posted: Thu Jun 10, 2004 8:55 pm Post subject: (No subject) |
|
|
Well, I'll give u an example:
instead of this, which lags the ball falling:
code: |
setscreen ("offscreenonly")
var x, y : int := maxy
procedure mouse
var mousex, mousey, button : int
mousewhere (mousex, mousey, button)
if button = 1 then
for rad : 1 .. 25
View.Update
drawfilloval (mousex, mousey, rad - 1, rad - 1, white)
drawfilloval (mousex, mousey, rad, rad, 66)
delay (10)
end for
for decreasing rad : 25 .. 1
View.Update
drawfilloval (mousex, mousey, rad + 1, rad + 1, white)
drawfilloval (mousex, mousey, rad, rad, 66)
delay (10)
end for
end if
end mouse
x := 200
loop
y -= 3
if y <= 0 then
y := maxy
end if
drawfilloval (x, y, 10, 10, 12)
delay (10)
View.Update
cls
mouse
end loop
|
You have this, which has the ball and click in the same loop
code: |
setscreen ("offscreenonly")
var x, y : int := maxy
var radius, mousex, mousey, button, drawx, drawy : int:=0
var dir: string:="out"
var check:= false
procedure mouse
mousewhere (mousex, mousey, button)
if button = 1 then
if check= false then
drawx:=mousex
drawy:=mousey
end if
dir:= "out"
end if
if dir= "out" then
radius+= 1
drawfilloval (drawx, drawy, radius, radius, 66)
if radius >= 25 then
dir:= "in"
end if
end if
if dir= "in" then
radius-=1
drawfilloval (drawx, drawy, radius, radius, 66)
if radius <=0 then
dir:=""
check:= false
end if
end if
end mouse
x := 200
loop
y -= 3
if y <= 0 then
y := maxy
end if
drawfilloval (x, y, 10, 10, 12)
delay (10)
View.Update
cls
mouse
end loop
|
|
|
|
|
|
|
MOUSECORD
|
Posted: Thu Jun 10, 2004 8:59 pm Post subject: (No subject) |
|
|
how about this... it dosn't work but it has potential...
code: |
var rad : int := 0
loop
var mousex, mousey, button : int
mousewhere (mousex, mousey, button)
if button = 1 then
drawfilloval (mousex, mousey, rad, rad, 13)
rad += 5
if rad >= 50 then
rad += 5
end if
end if
delay(25)
cls
|
there must be a bug in here can u see it...? |
|
|
|
|
|
aside
|
Posted: Thu Jun 10, 2004 9:04 pm Post subject: (No subject) |
|
|
i'm not sure what are you doing, but i think the bug you are referring to is that it will continuely draw the circle bigger and bigger. try this:
code: |
var rad , cha: int := 0
cha:=5
loop
var mousex, mousey, button : int
mousewhere (mousex, mousey, button)
if button = 1 then
drawfilloval (mousex, mousey, rad, rad, 13)
rad += cha
if rad >= 50 then
cha := -5
end if
end if
if rad<= 0 then
cha:=5
end if
delay(25)
cls
|
I currently don't have turing available, so i'm only guessing |
|
|
|
|
|
MOUSECORD
|
Posted: Thu Jun 10, 2004 9:13 pm Post subject: (No subject) |
|
|
thanks dude really helped me out man... |
|
|
|
|
|
MOUSECORD
|
Posted: Thu Jun 10, 2004 9:17 pm Post subject: oh |
|
|
Oh when i run it now... i can click and hold it and it moves around with the mouse how can i make it so when u click it sticks to that quardinate and does a full around.... u kno??? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Paul
|
Posted: Thu Jun 10, 2004 9:27 pm Post subject: (No subject) |
|
|
well, my "check:= true / check:= false" part on the second code box does that in conjunction with variables: drawx and drawy |
|
|
|
|
|
MOUSECORD
|
Posted: Thu Jun 10, 2004 9:32 pm Post subject: but |
|
|
but look if u hold down click... the oval is still there and u can like paint the screen almost ... do u see... this is missile command u know how it goes out then back in staying on a point on the screen.... how can i do that this is my code now...
code: | mousewhere (mousex, mousey, button)
if button = 1 then
drawfilloval (mousex, mousey, rad, rad, 13)
rad += cha
if button = 0 then
rad := 0
end if
if rad >= 30 then
cha := -2
delay (25)
end if
if rad <= 0 then
cha := 2
end if
end if |
|
|
|
|
|
|
MOUSECORD
|
Posted: Thu Jun 10, 2004 9:50 pm Post subject: yeah |
|
|
yeah when u click it stays on the mouse how to i make it stay on the quardinate u clicked on |
|
|
|
|
|
|
|