![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2006
Posts: 8
Rep Power: 0
![]() |
help with timers for final class project
I'm making a game which is turning out to be similar to "Paperboy." I need some help with it on two topics.
1) I need to make a countdown to start (ie: 3 ... 2 ... 1 ... go). I'm assuming I need timer for this, but I don't know how to count elapsed time so such a countdown is workable. 2) I also need to be able to shoot things from the character. The character is able to move up and down so I'll need the projectiles to stay with it (hence the character has the gun and not some random patch of road). I've been given some great help in the past and while I'm continuing to try to figure this out myself it's really stumping me. Any and all solutions to either problem are appreciated. |
|
|
|
|
|
#2 | |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 211
Rep Power: 4
![]() |
Quote:
As for the Projectile You'd just need to have the Y-coordinate for the projectile (or X depending on your frame of reference) match that of the character, either via independant calculation, or by updating it with the updation of the characters coordinates. -MBirchmeier |
|
|
|
|
|
|
#3 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3
![]() |
yeah like MBirchmeier said you need to use a timer and the timer is milliseconds so to get that to seconds for your count down:
seconds=milliseconds/1000 (i think) if your timers interval is set at 1 then this should give you no problem
__________________
Quote:
|
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: May 2006
Posts: 8
Rep Power: 0
![]() |
ok so the projectile might be easier than I thought. as for the countdown, what kind of coding am I looking at. I currently have the timer's interval set at 10 so how would I go about coding for "after X amount of milliseconds, change from 3 to 2 ..." and so on?
|
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3
![]() |
look up ^
__________________
Quote:
|
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: May 2006
Posts: 8
Rep Power: 0
![]() |
How can I do a rapid fire? I set the spacebar as the fire button and I am currently only able to press one button at a time.
So now while I can shoot, I don't always have enough time to dodge obsticles. :o any help? |
|
|
|
|
|
#7 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Store everything going through Form_KeyDown and Form_KeyUp. When a key is pressed, set a flag to True, and when it's released, set it to False. Then check the flags instead of the keys.
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6
![]() |
this is source code from a "whack a gopher" game i made for school a couple semester ago. the damn thing has like three timers.
attached is the whole thing in zip format. look for timers and their usage Option Explicit
'global variables
Dim score As Integer
Dim randomNumber As Integer
Dim l4cap As Integer
'disable all the command buttons
'-when program is initially loaded
Private Sub Form_Load()
Dim x As Integer
Dim y As Integer
While (x < 25)
c1.Item(y).Enabled = False
x = x + 1
y = y + 1
Wend
'end code
End Sub
Private Sub start_Click()
'change caption back to initial value
Label3.Caption = "WHACK-A-GOPHER!!!"
'start all timers
Timer1.Enabled = True
Timer2.Enabled = True
Timer3.Enabled = True
'set timer3 variable
l4cap = 30
'set initial countdown time to 30
Label4.Caption = 30
'enable all command buttons
Dim x As Integer
Dim y As Integer
While (x < 25)
c1.Item(y).Enabled = True
x = x + 1
y = y + 1
Wend
'end code
End Sub
Private Sub reset_Click()
'change caption back to initial value
Label3.Caption = "WHACK-A-GOPHER!!!"
'"turn off" the gameplay
score = 0
Label1.Caption = score
Timer1.Enabled = False
Timer2.Enabled = False
Timer3.Enabled = False
'change all the commandbuttons to their start picture
Dim x As Integer
Dim y As Integer
x = 0
y = 0
While (x < 25)
c1.Item(y).Picture = LoadPicture(App.Path + "\smallBlank.gif")
x = x + 1
y = y + 1
Wend
'end code
'disable all command buttons
Dim x1 As Integer
Dim y1 As Integer
x1 = 0
y1 = 0
While (x1 < 25)
c1.Item(y1).Enabled = False
x1 = x1 + 1
y1 = y1 + 1
Wend
'end code
End Sub
'end program
Private Sub exit1_Click()
End
End Sub
'set difficulty to easy
Private Sub easy_Click(Index As Integer)
Timer1.Interval = 1000
End Sub
'see above
Private Sub normal_Click(Index As Integer)
Timer1.Interval = 750
End Sub
'see above
Private Sub hard_Click(Index As Integer)
Timer1.Interval = 550
End Sub
'see above
Private Sub asinine_Click()
Timer1.Interval = 100
End Sub
'display form with rules
Private Sub rules_Click(Index As Integer)
Call Load(Form2)
End Sub
'here's where the fun starts...
Private Sub c1_Click(Index As Integer)
'if you click on a gopher...
If c1.Item(randomNumber) Then
'keep player from double-clicking on the gopher
c1.Item(randomNumber).Enabled = False
'change command button to x'd-out gopher pic
c1.Item(randomNumber).Picture = LoadPicture(App.Path + "\deadGopher.gif")
'then give 'em some points!
score = score + 25
'show 'em their points so far
Label1.Caption = score
Else
'if they click on a blank they lose ten points
'(double-clicking on blanks is allowed)
score = score - 10
'show 'em their crappy score change
Label1.Caption = score
End If
End Sub
Private Sub Timer1_Timer()
're-enable the last-clicked gopher button
c1.Item(randomNumber).Enabled = True
'this code basically clears the buttons to blanks every second
Dim x As Integer
Dim y As Integer
x = 0
y = 0
While (x < 25)
c1.Item(y).Picture = LoadPicture(App.Path + "\smallBlank.gif")
x = x + 1
y = y + 1
Wend
'end code
'start generating a random number
Call Randomize
'between 0 and 24
randomNumber = Int(25 * Rnd())
'assaign command button array element
'-to the random number generated above
'-and give it the gopher picture
c1.Item(randomNumber).Picture = LoadPicture(App.Path + "\smallGopher.gif")
End Sub
Private Sub Timer2_Timer()
'stop the game
Timer1.Enabled = False
'display game-over dialogue
Label3.Caption = "GAME OVER"
'turn off all the buttons again
Dim x1 As Integer
Dim y1 As Integer
While (x1 < 25)
c1.Item(y1).Enabled = False
x1 = x1 + 1
y1 = y1 + 1
Wend
'end code
End Sub
'this is just the code for the countdown timer
'-in the lower right-hand corner
'-so player is aware of their impending failure (or success)
Private Sub Timer3_Timer()
If l4cap > 0 Then
l4cap = Label4.Caption
l4cap = l4cap - 1
Label4.Caption = l4cap
End If
'end code
End Sub
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#9 |
|
Newbie
Join Date: May 2006
Posts: 8
Rep Power: 0
![]() |
Aight guys new problem. Sorry, I'm a bit of a scrub. Countdown is working, shooting is working. I have a speed pad in the game which I have kinda forgotten about for a while. I have an idea of a code that might work, but it counts each interval individually and I'm sure there is an easier way to code this that I'm overlooking.
Here are the specifics: imgSpeedPad.Left = 14840 .Top = 2400 .Height = 645 .Width = 1335 The character sits horizontally in a side-scroller road and can move vertically. The front of the character is at 2040. I have a timer with an interval of 10. Below is a sample of the code I've begun using: If Secs = 0 Then
Accel = Accel 'same as tmrRoad
Secs = 1
ElseIf Secs = 1 Then
Accel = Accel + 0.5
Secs = 2
ElseIf Secs = 2 Then
Accel = Accel + 0.5
Secs = 3 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|