Timer won't work for some reason
Author |
Message |
SeeknDestroy
|
Posted: Sun Jan 11, 2004 11:49 am Post subject: Timer won't work for some reason |
|
|
well, here's my code for a level of my shooter, and when i run it, the people dont stay, they just flash for a half a second then disappear, but i put a timer on them , well, here's my code, i don't want u guys to write me a code, just tell me whats wrong and how can i fix it, plz, im so new to turing, and well, plz help me
code: | var winID : int
winID := Window.Open ("position:top;center,graphics:640;480")
var win, win1 := 0
var x, y, button, number, enemies, btn, updown : int
var got_hit : boolean := false
var timer : int
process bg1
Pic.ScreenLoad ("level1.bmp", 0, 0, picCopy)
end bg1
procedure enemy1
fork bg1
mousewhere (x, y, button)
Pic.ScreenLoad ("level1enemy1.bmp", 300, 345, picCopy)
win1 := win1 + 1
if x > 300 and x < 556 and y > 345 and y < 480 and button = 1 then
win := win + 1
else
timer := 10000
end if
end enemy1
procedure enemy2
fork bg1 % The level background
mousewhere (x, y, button)
Pic.ScreenLoad ("level1enemy2.bmp", 0, 280, picCopy)
win1 := win1 + 1
if x > 0 and x < 196 and y > 280 and y < 415 and button = 1 then
win := win + 1
else
timer := 10000
end if
end enemy2
proc enemy3
fork bg1
Mouse.Where (x, y, button)
Pic.ScreenLoad ("level1enemy3.bmp", 163, 100, picCopy) %The third enemy
win1 := win1 + 1
if x > 163 and x < 359 and y > 100 and y < 331 and button = 1 then
win := win + 1
else
timer := 10000
end if
end enemy3
Pic.ScreenLoad ("level1.bmp", 0, 0, picCopy)
Pic.ScreenLoad ("beginbutton.bmp", 220, 205, picCopy)
buttonwait ("down", x, y, btn, updown)
if (220 <= x) and (x <= 420) and
(205 <= y) and (y <= 275) then
Pic.ScreenLoad ("level1.bmp", 0, 0, picCopy)
end if
loop
randint (enemies, 1, 3)
if enemies = 1 then
enemy1
elsif enemies = 2 then
enemy2
elsif enemies = 3 then
enemy3
end if
if win1 = 10 then
cls
put "You scored: ", win
exit
end if
end loop
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
SeeknDestroy
|
Posted: Sun Jan 11, 2004 12:58 pm Post subject: (No subject) |
|
|
plz, help me out, i mean there were 10 views and no replies.
|
|
|
|
|
|
Andy
|
Posted: Sun Jan 11, 2004 2:28 pm Post subject: (No subject) |
|
|
ok get winzip, and zip the code with the pictures so we can help
and comment the part u think is wrong
|
|
|
|
|
|
SeeknDestroy
|
Posted: Sun Jan 11, 2004 3:06 pm Post subject: (No subject) |
|
|
ok, thnx a bunch, well here is my code wit pictures. thnx a lot for the help, i really appreiciate it
Description: |
|
Download |
Filename: |
My Game.zip |
Filesize: |
23.23 KB |
Downloaded: |
274 Time(s) |
|
|
|
|
|
|
PaddyLong
|
Posted: Sun Jan 11, 2004 3:21 pm Post subject: (No subject) |
|
|
when I run it they stay until I click on them
|
|
|
|
|
|
SeeknDestroy
|
Posted: Sun Jan 11, 2004 3:28 pm Post subject: (No subject) |
|
|
yea, thats the problem, i tried to put a timer on them, but the timer doesn't seem to work and so i commented the timer, do u know a way around it? plz tell me. thnx
|
|
|
|
|
|
poly
|
Posted: Sun Jan 11, 2004 3:38 pm Post subject: (No subject) |
|
|
Okay I see what you want. You want it so the enemy will only appear for a certain amount of time (which you ahve chosen 1000).
Im gonna take a stab at saying(cause me dont have turing installed right now) the main problem is that the counter is in the procedure. AN easy way to do what you want is down where you have the actual game code you could do something like:
displayEnemy1 and counter starts
if the enemy1 has been clicked than clear him off screen if not keep him on or clear him off when counter reaches limit
displayEnemy2 and counter starts
if the enemy2 has been clicked than clear him off screen if not keep him on or clear him off when counter reaches limit
displayEnemy3 and counter starts
if the enemy3 has been clicked than clear him off screen if not keep him on or clear him off when counter reaches limit
... and well you cant get crappier pseudo-coding than that ladies and gents!
|
|
|
|
|
|
SeeknDestroy
|
Posted: Sun Jan 11, 2004 3:42 pm Post subject: (No subject) |
|
|
ok, kool, thnx for the help, ill see if i can code that
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
poly
|
Posted: Sun Jan 11, 2004 3:48 pm Post subject: (No subject) |
|
|
hmm you understood what i meant? Wow, after reading it I dont know what the hell i was talking about, im not much of an explaining kind of person
|
|
|
|
|
|
SeeknDestroy
|
Posted: Sun Jan 11, 2004 3:51 pm Post subject: (No subject) |
|
|
yea, i think u mean to put the timer thing at the bottom where i have the randint thing rite? but acutally, i've changed my code again, so now there is a pattern to the enemies appearing. and yea, after looking at the code again, i couldn't figure it out,
|
|
|
|
|
|
poly
|
Posted: Sun Jan 11, 2004 3:52 pm Post subject: (No subject) |
|
|
oh so now your stuck again? What part of the code did you change?
|
|
|
|
|
|
SeeknDestroy
|
Posted: Sun Jan 11, 2004 3:57 pm Post subject: (No subject) |
|
|
well, now my procedures arn't called through the randint thing. i created a loop and called the procedures in the loop.
so i dont need the counter n e more.
however, i tried to use the clock(timer) thing as a timer and in my procedures, but when i run it, the people either stay there, or they all flash for a millisecond and goes away
code: | enemy1
fork bg1
count := count + 1
loop
var timer : int := 0
clock (timer)
mousewhere (x, y, button)
Pic.ScreenLoad ("level1enemy1.bmp", 300, 345, picCopy)
fork crosshair
fork bg1
if x > 300 and x < 556 and y > 345 and y < 480 and button = 1 then
fork gun
win := win + 1
exit
end if
exit when timer >= 1000
end loop
end enemy1 |
|
|
|
|
|
|
SeeknDestroy
|
Posted: Sun Jan 11, 2004 6:17 pm Post subject: (No subject) |
|
|
well, i figured out a lot of the code thnx to all ur help. but now i can't get the timer to work. i declared a variable in every procedure where the enemies appear, and put in an exit when timer >= 1500 . and it just flashes reallly fast, and i know for a fact that its not the time 1500 cuz the first guy stays for that long, then the rest just flashes by. and here's my code
code: | % Enemy number 1 of level one
procedure enemy1
fork bg1
count := count + 1
loop
var timer := 0
clock (timer)
mousewhere (x, y, button)
Pic.ScreenLoad ("level1enemy1.bmp", 300, 345, picCopy)
fork crosshair
fork bg1
if x > 300 and x < 556 and y > 345 and y < 480 and button = 1 then
fork gun
win := win + 1
exit
end if
exit when timer >= 1500
end loop
end enemy1
% Enemy number 2 of level 1
procedure enemy2
fork bg1
count := count + 1
loop
var timer := 0
clock (timer)
mousewhere (x, y, button)
Pic.ScreenLoad ("level1enemy2.bmp", 0, 280, picCopy)
fork crosshair
fork bg1
if x > 0 and x < 196 and y > 280 and y < 415 and button = 1 then
fork gun
win := win + 1
exit
end if
exit when timer >= 1500
end loop
end enemy2
% Enemy number 3 of level 1
proc enemy3
fork bg1
count := count + 1
loop
var timer := 0
clock (timer)
mousewhere (x, y, button)
Pic.ScreenLoad ("level1enemy3.bmp", 163, 100, picCopy)
fork crosshair
fork bg1
if x > 163 and x < 359 and y > 100 and y < 331 and button = 1 then
fork gun
win := win + 1
exit
end if
exit when timer >= 1500
end loop
end enemy3
|
|
|
|
|
|
|
Dan
|
Posted: Sun Jan 11, 2004 11:55 pm Post subject: (No subject) |
|
|
well one thing was that var timer:= 0 was in the loop, that was probly a bad thing. the other is that i dont think the clock fucttion is wroking the way you whont it to.
i whould use the Time.Sec fuction b/c it is in Secondes not millseconeds and it wroked for this proagme when i tested it.
should look stoming like this:
code: |
% Enemy number 3 of level 1
proc enemy3
fork bg1
count := count + 1
var startTime:int := Time.Sec
var timer:int
loop
timer := Time.Sec - startTime
mousewhere (x, y, button)
Pic.ScreenLoad ("level1enemy3.bmp", 163, 100, picCopy)
fork bg1
if x > 163 and x < 359 and y > 100 and y < 331 and button = 1 then
win := win + 1
exit
end if
exit when timer >= 3
end loop
end enemy3
|
Time.Sec returns how many secnonds since 1970. so what you have to do is take the reading of it b4 the loop then subtrated Time.Sec from it to get how many seconds have pasted.
NOTES: 1. it is now in seconds not millsceonds, so you will whont a value like 1-3 not 1500
2. i did not have the code for some of your fuctions so i left them out of my sample code there
|
Computer Science Canada
Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more! |
|
|
|
|
SeeknDestroy
|
Posted: Mon Jan 12, 2004 4:20 pm Post subject: (No subject) |
|
|
o man, thanks soo much, i really appreciate it, this timer is awesome! thnx!
|
|
|
|
|
|
|
|