|
-
Jan 9th, 2001, 04:05 AM
#1
Thread Starter
New Member
Hi, I'm making a game called Alien Invasion, and the main happening in this game is that an ufo appears on the screen and u try to shoot it before it dissapears.
I've written the code to make the ufo appear in random places, but i can't make the code to understand that i'm clicking on the ufo and to register hits/misses and also make the ufo dissapear if i use to much time...
this is the code i got so far:
Private Sub Form_Load()
Hits = 0
Life = 3
frmMainpage.Top = 0
frmMainpage.Left = 0
frmMainpage.Height = 567 * 15.15
frmMainpage.Width = 567 * 21.25
Run
End Sub
Private Sub imgAlien_Click()
Time = 0
Hits = Hits + 1
lblHit = Hit
Run
End Sub
Private Sub Run()
Dim Top As Single
Dim Left As Single
Dim b As Long
b = 0
Do While b <= 4
Randomize
Topp = Rnd(1) * (567 * 15)
Venstre = Rnd(1) * (567 * 21)
If Topp > 567 * 12 Then
Topp = 567 * 10
ElseIf Venstre > 567 * 17 Then
Venstre = 567 * 16
End If
With imgAlien
.Visible = True
.Top = Top
.Left = Left
End With
For Tid = 0 To 900000
Next Tid
b = b + 1
Loop
End Sub
This make the ufo appear on random places, but i need to make the program stop, register hits and then run again...
How do i do this?
-
Jan 11th, 2001, 02:14 PM
#2
Member
Hi norwegian neighbour!
Code:
For Time=0 To 90000
Next
(Check out "vb code" on top of the page next time you write a post with code in it, makes is easier to read for others )
This code doesn´t allow anything else to happen until time has run out, if you click the mouse nothing will happen.
Try read about the function "Timer", this one makes the time run constant. The loop in the code above will take longer on slower machines and shorter on faster ones.
Most people do say that the API call "GetTickCount" works better, but don´t bother right now if you haven´t tried APIs before.
Note: Don´t use "Time" as above either, there is already a function called Time in vb which returns the current time. (I think..)
Also read about the function "DoEvents", which will allow other events to occur while your loop is running.
It´s very simple though, just place it inside your loop somewhere.
Using your "imgAlien.click" looks like a good idea.
I hope I have given you a few hints, I really think the best thing for you is to just try-change-learn over and over...
Do it my way: buy two bottles of Coke, turn your mobile telephone OFF, tell your friends you are out of town for the weekend and make sure you have gotten enough sleep the night before...then you are ready to make some code! 
Balder = Viking God
VB6/VC++ Enterprise Editions
-
Jan 12th, 2001, 07:33 AM
#3
Thread Starter
New Member
How do i use the timer then?
I've tried to use that timer function, but i've got no idea how to use it...
If someone could show me cinda how to write a timer fuction or just a simple way to use it i would become a very happy man...
Please explain in a simple way how to use the timer function, please. :-)
-
Jan 12th, 2001, 08:15 AM
#4
-
Jan 12th, 2001, 09:21 AM
#5
Thread Starter
New Member
Thanks, but i got to loan a more advanced bock than the one i got, so i found it out meself...
The problems i am encountering now is how to make the program find out what screen resolution the screen has and setting the resolution to a fixed one, like 800:600 or sommin...
And also i can't change the interval in the timer function, i used the frase: tmrSynlig.interval=1000, when the original interval was to be 2000, but it didn't work, i'm sure i'll find it out soon enough ;-)
-
Jan 13th, 2001, 02:51 AM
#6
Member
Timer
Ok, there is the component Timer and there is the function Timer.
The component works as Alan777 described.
The function Timer, which you might find useful, returns the number of milliseconds elapsed since midnight.
I haven´t used it for a while, but something like this.
Code:
Dim Delay as Long
Delay = Timer
Do
DoEvents 'so other events can occur, like ClickUfo.click
Loop Until Timer = (Delay+1000) 'one second delay time
If you make "Delay" public, you can change it anywhere in your form code. So if you click the ufo you can set it to the Timer value again. Delay=Timer, and your loop will begin another one-second-interval again. Your ClickUfo.click might also contain code to delete the hitted ufo and then to create a new one.
Urgh...think it´s hard to think out the best way even for smaller problems. I always need to test my way to the most "optimal" solution.
I´m sure there are better and worse ways to do it, but it´s an idea.
Balder = Viking God
VB6/VC++ Enterprise Editions
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|