Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 31st, 2006, 3:11 PM   #1
Rath72
Newbie
 
Join Date: May 2006
Posts: 8
Rep Power: 0 Rath72 is on a distinguished road
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.
Rath72 is offline   Reply With Quote
Old May 31st, 2006, 3:32 PM   #2
MBirchmeier
Hobbyist Programmer
 
Join Date: Oct 2005
Posts: 211
Rep Power: 4 MBirchmeier is on a distinguished road
Quote:
Originally Posted by Rath72
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.
The timer is a piece of code that executes every so often, you could use it easily for your countdown, but the elapsed time you should look into a TimeSpan object, or perhaps a StopWatch object if you're using .NET 2.0

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
MBirchmeier is offline   Reply With Quote
Old May 31st, 2006, 5:06 PM   #3
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
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:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old May 31st, 2006, 5:31 PM   #4
Rath72
Newbie
 
Join Date: May 2006
Posts: 8
Rep Power: 0 Rath72 is on a distinguished road
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?
Rath72 is offline   Reply With Quote
Old Jun 1st, 2006, 3:13 AM   #5
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 333
Rep Power: 3 kruptof is on a distinguished road
look up ^
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Jun 6th, 2006, 9:34 AM   #6
Rath72
Newbie
 
Join Date: May 2006
Posts: 8
Rep Power: 0 Rath72 is on a distinguished road
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?
Rath72 is offline   Reply With Quote
Old Jun 6th, 2006, 7:57 PM   #7
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Jun 6th, 2006, 9:05 PM   #8
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 6 bl00dninja is on a distinguished road
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
Attached Files
File Type: zip gopher.zip (12.6 KB, 17 views)
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Jun 14th, 2006, 7:55 AM   #9
Rath72
Newbie
 
Join Date: May 2006
Posts: 8
Rep Power: 0 Rath72 is on a distinguished road
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
Rath72 is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:38 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC