[VB 6] - Platform Gravity
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity
[VB 6] - Platform Gravity [VB 6] - Platform Gravity
[VB 6] - Platform Gravity
Go Back  Xtreme Visual Basic Talk > > > [VB 6] - Platform Gravity


Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2011, 09:56 PM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default [VB 6] - Platform Gravity


Hey everyone who reads this..

im stuck in my platform game obviously.. im in grade 12, and for my school we don't learn VB much in IPT, so for the game we're making we all get to choose....

the question im asking is right now im using timers, and fake gravity.. here is an example.. ok my desktop doesnt have VB6 installed and i can't find the download.. so its basically
e.g.
if KeyCode = VbKeyUp Then
tmrJump.Enabled = True
tmrControl.Enabled = True
....
the jump timer is just the img moving up, while the control is an interval of 800 before activating the reverse of the jump, and it then checks for collision, cause we use public function collision..

while this works ok i cannot get him to fall naturally when he goes off the edge, instead he keeps moving as nothing is wrong... and my other teach mention something like

If KeyPress = VbKeyUp then
tmrJump.Enabled = True
this would activate some variables like

YDir = 15
XDir = 0

then he sadi something about something else.. but i need help.. i can either continue with what im doing, which i need help on.. or change the code to what he mentioned, either way i need help.. so any suggestions and even better a cut and paste code

Last edited by ilikebeds1; 08-08-2011 at 10:00 PM. Reason: Title to represent what version
Reply With Quote
  #2  
Old 08-09-2011, 05:46 AM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default *urgent bump*

sorry for bumping even though its at top still. i need it for tomoz.. so i will make it quick. what code should i used to make the img fall when no img is below them?
Reply With Quote
  #3  
Old 08-09-2011, 07:12 AM
PlausiblyDamp's Avatar
PlausiblyDamp[VB 6] - Platform Gravity PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Other than the fact we are not here to do your homework for you we can't really offer any advice as you haven't given us any real code to work with.

If you can show what you have done so far then we can certainly offer advice and suggestions as to what might work but without any real information to go on you aren't going to get many responses I am afraid to say.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #4  
Old 08-09-2011, 10:37 AM
passel's Avatar
passel[VB 6] - Platform Gravity passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I think your other "teach" was trying to say set the vertical speed to some value (15) when you jump. And you would subtract a value (representing gravity) from that amount each pass. You would move the object based on the value of the vertical speed.
So, think about it. If your gravity was 5, then the jump start moving up at 15, then next pass 10, the next pass 5, the next pass 0 (the top of the jump has been reached).
The next pass -5, it is starting to fall, the next pass -10, it is falling farther (faster), and so on until it reachs the ground, or you set a "terminal velocity" so there is a maximum speed the item will fall.
If the teachers are giving information too quickly for you to capture, and understand, you will need to be brave enough to get with them to ask for clarification.

Also, if you think you need additional time with VB on your own to learn, Microsoft provided a version of VB5 (Visual Basic - Control Creation Edition) for free. Its purpose was to allow creating controls. You can't use it to create executables, or work with databases.
But, you can create the type of programs you are likely to use in school, and run them in the IDE, which most people do anyway until they have a finished program.
VB6 has a few additional statements or functions that VB5 didn't have (in particular, the Replace function and another string function that I can't think of at the moment), but is a very useful tool for those who don't have VB6 but want to learn legacy VB.
Do a google search for vbcce and you will find places to download from, such as thevbzone.com
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 08-09-2011 at 10:46 AM.
Reply With Quote
  #5  
Old 08-09-2011, 03:46 PM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

Code:
Public Function Collision(Obj1 As Object, Obj2 As Object) As Boolean
    Collision = (Obj1.Top + Obj1.Height > Obj2.Top) And (Obj1.Top < Obj2.Top + Obj2.Height) And (Obj1.Left + Obj1.Width > Obj2.Left) And (Obj1.Left < Obj2.Left + Obj2.Width)
End Function

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyUp Then
    tmrJump.Enabled = True
    tmrControl.Enabled = True
Else
If KeyCode = vbKeyLeft Then
    i = i - 50
    imgBlob.Left = imgBlob.Left + i
Else
If KeyCode = vbKeyRight Then
    i = i + 50
    imgBlob.Left = imgBlob.Left + i
End If
End If
End If



End Sub

Sub tmrFall_Timer()
For n = 0 To 1
If Collision(imgBlob, imgBlackground(n)) Then  'This is just to make sure that your guy stops going down once he hits the bottom.
tmrControl.Enabled = False
tmrFall.Enabled = False 'just so next time he jumps you start from the begining again
Else
i = i + 20
imgBlob.Top = imgBlob.Top + i
End If
Next n

End Sub

Private Sub tmrJump_Timer()

i = i - 30
imgBlob.Top = imgBlob.Top + i

End Sub

Private Sub tmrControl_Timer()

tmrFall.Enabled = True
tmrJump.Enabled = False

End Sub
here is the code i have right now, i will show my teacher what you said, and see how i can use it. and yep. thats my crappy code right now
Reply With Quote
  #6  
Old 08-10-2011, 06:05 AM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

Here is the code now, once i tried to put in Ydir Xdir and Gravity.. i'm not that good obviously, but i was thinking of having a check collision, to ensure the 'Gravity' works so when im not over any of the ground i fall

Code:
Dim Ydir As Long
Dim Xdir As Long
Dim Grav As Long

Public Function Collision(Obj1 As Object, Obj2 As Object) As Boolean
    Collision = (Obj1.Top + Obj1.Height > Obj2.Top) And (Obj1.Top < Obj2.Top + Obj2.Height) And (Obj1.Left + Obj1.Width > Obj2.Left) And (Obj1.Left < Obj2.Left + Obj2.Width)
End Function


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyUp Then
    tmrJump.Enabled = True
Else
If KeyCode = vbKeyLeft Then
    tmrLeft.Enabled = True
Else
If KeyCode = vbKeyRight Then
    tmrRight.Enabled = True
End If
End If
End If

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyLeft Then
    tmrLeft.Enabled = False
Else
If KeyCode = vbKeyRight Then
   tmrRight.Enabled = False
End If
End If



End Sub


Sub tmrFall_Timer()

For n = 0 To 1
If Collision(imgBlob, imgBlackground(n)) Then  'This is just to make sure that your guy stops going down once he hits the bottom.
    tmrControl.Enabled = False
    tmrFall.Enabled = False
Else
    Ydir = Ydir + 2
    imgBlob.Top = imgBlob.Top + Ydir
End If
Next n

End Sub

Private Sub tmrJump_Timer()
tmrControl.Enabled = True
Ydir = -75
imgBlob.Top = imgBlob.Top + Ydir

End Sub

Private Sub tmrControl_Timer()

tmrFall.Enabled = True
tmrJump.Enabled = False

End Sub

Private Sub tmrLeft_Timer()
Xdir = -75
imgBlob.Left = imgBlob.Left + Xdir
End Sub

Private Sub tmrRight_Timer()
Xdir = 75
imgBlob.Left = imgBlob.Left + Xdir
End Sub
Reply With Quote
  #7  
Old 08-10-2011, 10:09 AM
passel's Avatar
passel[VB 6] - Platform Gravity passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Just some observations.
I'm assuming you've left the Scalemode of the Form set to the default Twips.
And your motion of 75 twips may convert to 5 pixels of movement.
But twips is not a constant across all machines, and can differ on a given machine if someone picks an option like Windows using a larger font, which changes the Dots Per Inch (DPI) setting, which changes the twips per pixel values.
Rather than use twips, it is preferable to set the Scalemode to Pixels, so your movment is mapped directly. Instead of moving 15 or 12 twips to move a pixel, you just move 1.
So, assuming your movement of 75 was moving you 5 pixels, you would now just move 5.

Second, since you're now moving by pixels, for smoother movement you won't want to use Integers or Longs for your positions or amount of movement. You should use the Single type, which will allow logical movement of fractional pixel increments. The actual position will of course, round to an integer position, but the motion over time should be smoother as opposed to having to move by whole pixels every frame.
If that is not clear, consider using an integer for speed.
The minimum speed is one pixel per tick.
The next higher minimum speed is two pixels per tick.
So the speed is doubled from the slowest, to the next slowest.
If you use a Single to allow fractional numbers, and you accumulate those in a Single,
you could move .5 pixels per frame, or .25 pixels per frame, or 1.1 pixels per frame, etc.
The object can move slower, i.e. one pixel every two frames, or one pixel every four frames, etc. and doesn't have to double in speed between the two minimums.

Third, you really shouldn't use multiple timers in VB. There is no guarantee that the timers will fire in a evenly distributed manner, or even round robin.
If you have two timers firing at the same rate, you might expect one to fire, then the other, so that if you had a counter in both, after the same period of time both counters are equal.
But, since there is no guarantee of which timer will fire when two or more are enabled, it is possible for one to fire more times than another, and maybe even starve a timer so it is firing much slower than desired and erratically.

I think your basic logic is OK. If you had some Booleans defined and you set them True or False, instead of the timers, then in a single timer that runs at your desired frame rate can check those booleans and move left, or move right and/or process your jump/fall logic (you might allow moving left or right while you are in the jump, as a lot of games do).

The initial settings for your jump, for instance, whould not be in the Jump Timer, but in the keyDown procedure where you determined you are jumping.
You would set the JumpMode boolean to true, instead of the timer, and set your YDir to -75.
I also expect that in the keydown you would also check to see if JumpMode was already active, so you don't reset YDir to -75, allowing continual jumping while in the air so that you could multi-jump off the top of the screen.

In your single timer, if Jump mode was active, you would diminish your vertical velocity by the gravity amount.
In that timer would also be the checks for moving left and moving right, and then collision testing.

You would leave your game frame timer running all the time. If none of the booleans were true, you wouldn't be moving, but when one or more is set, then you would be moving.
So you wouldn't be enabling and disabling various timers all the time.
An initial jump velocity of 75 with a gravity of 2 will probably result in some pretty high jumps, but that will be part of the development process.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 08-10-2011 at 04:09 PM.
Reply With Quote
  #8  
Old 08-10-2011, 03:21 PM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default Your defiantly a Guru :D

Thanks Passel, i will implement into my code, and once i have they all done and working i will repost the code to ensure it is all right.. but thanks, thats the best help i could ever get..


They don't call you the Guru for Nothing!
Reply With Quote
  #9  
Old 08-14-2011, 11:12 PM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

Late Reply, i got my TOnsills cut out, and i havent been focused on this as much as i hoped.. easy enough fix, but im not sure how.. i have the booleans set up, and each activating, but when it comes down to moving left or right in the xdir, it just doesn't seem to work.. any reason why not?

Code:
Dim Ydir As Single
Dim Xdir As Single
Dim Grav As Single
Dim MRight As Boolean
Dim MLeft As Boolean
Dim MUp As Boolean

Public Function Collision(Obj1 As Object, Obj2 As Object) As Boolean
    Collision = (Obj1.Top + Obj1.Height > Obj2.Top) And (Obj1.Top < Obj2.Top + Obj2.Height) And (Obj1.Left + Obj1.Width > Obj2.Left) And (Obj1.Left < Obj2.Left + Obj2.Width)
End Function


Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyUp Then
    If MUp = False Then
    MUp = True
    Else
If KeyCode = vbKeyLeft Then
    MLeft = True
Else
If KeyCode = vbKeyRight Then
   MRight = True
End If
End If
End If
End If

End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)

If KeyCode = vbKeyUp Then
    MUp = False
Else
If KeyCode = vbKeyLeft Then
    MLeft = False
Else
If KeyCode = vbKeyRight Then
   MRight = False
End If
End If
End If



End Sub


Sub tmrFall_Timer()

For n = 0 To 1
If Collision(imgBlob, imgBlackground(n)) Then  'This is just to make sure that your guy stops going down once he hits the bottom.
    tmrControl.Enabled = False
    tmrFall.Enabled = False
Else
    Ydir = Ydir + 2
    imgBlob.Top = imgBlob.Top - Ydir
End If
Next n

End Sub


Private Sub tmrControl_Timer()
Xdir = 10
If MLeft = True Then
    imgBlob.Left = imgBlob.Left + Xdir
Else
If MRight = True Then
    imgBlob.Left = imgBlob.Left - Xdir
Else
Ydir = 10
If MUp = True Then
    imgBlob.Top = imgBlob.Top - Ydir
End If
End If
End If


End Sub
Much Appreciation for everyone who helps
Reply With Quote
  #10  
Old 08-15-2011, 05:04 AM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

im thinking of using this below, as it seems smoother to use, but i dont have a way to implement it, plus with gravity and to jump
Code:
Dim X As Integer, Y As Integer, Gravity As Boolean
Private Sub Form_Load()
X = 25
Y = 50
Gravity = False
End Sub

Private Sub Timer_Timer()
Shape1.Move Shape1.Left + X, Shape1.Top + Y
If Shape1.Left <= 0 Then
    X = X * -1
End If

If Shape1.Left + Shape1.Width >= Me.ScaleWidth Then
X = X * -1
End If

If Shape1.Top <= 0 Then
    Y = Y * -1
End If

If Shape1.Top + Shape1.Height >= Me.ScaleHeight Then
    Y = Y * -1
    Gravity = True
End If

If Gravity = True Then
    Y = Y + 1
    If Y >= 50 Then
        Gravity = False
    End If
End If
End Sub
thats alright idea? i jsut need it to work so its pulling down when i jump and when i fall off objects
Reply With Quote
  #11  
Old 08-15-2011, 03:52 PM
passel's Avatar
passel[VB 6] - Platform Gravity passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Looking at your code in post #7, I did a test case of applying the changes I recommended as an experiment.
I used your collision test, and most of the key logic, but using booleans instead of timers.
I also changed the nested "If Then Elses" to "If Then ElseIf" which is easier on my eyes for this type of logic.
Since we don't have all your code, I just used an empty picturebox to represent the player, and a couple more empty pictureboxes, in a control array, to serve as platforms, as it seems to fit your code and the collision testing you have, although I hardcoded the collision loop rather than make it dynamic as you had it. You should keep it the way you had it.

I added some, probably not robust, logic for determining if the collsion occured because of landing on the floor or hitting my head, but if you hit the upper platform from the side while jumping from the lower platform, it causes another jump.
That may be bad, or perhaps it could be part of the climb strategy.

A possible problem with your movement code is that you have the three movements exclusive to each other, so that you can move left or right while you're jumping, at least in the post #9 code.

The post #10 code just looks like test code where the player is bouncing around the screen but if it goes off the bottom then it does some jump logic.
Just looking at it, I can't tell, but I suppose once it goes off the bottom once, it pretty much jumps continually, because it will reach the bottom again before the terminal velocity of 50 is reached.

In any case, I'll just give you that brief bit of code i wrote based on your post #7 code to see how it compares to what you've been doing, so you can decide how you want to proceed.

You can expand the form, so you can "fall off" either the left or right side of the lower "platform". When you fall to the bottom of the form, the program exits.
Attached Files
File Type: zip ilikebeds1.zip (2.4 KB, 21 views)
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #12  
Old 08-15-2011, 05:52 PM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

Thanks Passel, with using 'Else If' and basically fixing it all, i noticed how some of the things you used like the ydir= 0. i used that orignally but i could not implement it, where it would stop the picture from "falling" but seeing how you done it, makes me realise how simple some things can be, you just have to know where to implement it.

i will give credit to you, since the movement is out of the way, the only things i really need to do now is have the form follow the obj, like in game maker how you would use the view, so the view is fixed on him, and whereever he goes say within 500 pixels of the edges of the screen, it moves to keep him constantly around the centre of it.

Then i plan to have two more additions to the code, one where i collide with a certain object, which changes my colour, it then gives me the ability to land on different area platforms... so
for example
Code:
for i = 0 to 3
If imgDye.visible = False Then
imgBluePlatform.solid = True
then hopefully using something like that will help me gain further access, then i plan to having per say falling paint, which turns you back into your colourless form, this then means the dye reapears and more time is wasted,

*the game starts on a 90 seconds time for example and when it runs out you lose a life, and restart that level.. once all three lives are gone, game restarts. etc*
Reply With Quote
  #13  
Old 08-16-2011, 07:44 AM
passel's Avatar
passel[VB 6] - Platform Gravity passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I don't see any question, but for the scrolling display, you will need to change your logic so that movement of the player isn't directly moving the object that represents the player.
The object will stay in the center of the screen and you will update position variables that represent the players location in the game world.
Knowing the size of your window and that your player is at the center, you can calculate from his position what portion of the game world is visible on the screen.
You will then have to loop through all your other objects and the one's that intersect with the current coordinates of your screen will have to be moved or drawn in the proper relative position.
So, you will need to maintain all the objects "game world" location separately from their "physical" location in the window, as well.
Of course, this will also slow down your animation, as instead of having to move the one player around the screen, you now leave him in the center and have to move everything else.
Much more work for the program.

I don't know if it will help, but in this post the third attachment, simpleblt4.zip, as an example keeps a car in the center of the screen for most of the movement. If the edges of the world are reached, then it allows the car to move from the center, but as long as it is not near an edge, it remains in the center (or near the center) of the window.
It isn't directly applicable to your situation, and it could use some intelligent timing regulation, or dynamic movement distance adjustments, because it may run too fast on the current generation of machines, but it was just a slapped together demo, so isn't intended to be a polished project by any means.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 08-16-2011 at 08:07 AM.
Reply With Quote
  #14  
Old 08-16-2011, 08:48 AM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

yea after i wrote that, i began questioning if it was indeed possible.. i came to a conclusion of down sizing everything, to make it all fit into the one screen, then moving from form to form with different levels...

completely off topic, i don't suppose you work for a gaming company do you? i'm planning to go to the Qantm college in Brisbane here, and do the games programming.. something i always want to do..

yea so i downsized everything, and made the form load to another one, but even though i have form1 unload, it still seems to stay up in the background, and if im having like 15 levels, so 15 forms. i dont want 15 forms running the pc, and trying to burn out the clock.. is there some simple code to just go like.. open next form, close current form? plus when i made the second form, im not sure if its obtaining the same information from the same fox file, cause if it is, i might have to have everything else hidden on each of the levels.
Reply With Quote
  #15  
Old 08-16-2011, 09:10 AM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

also how long would 1 interval in timer be? or to be more exact how many intervals make 1 second? or even better how many intervals = 0.1 of a second
Reply With Quote
  #16  
Old 08-16-2011, 10:26 AM
passel's Avatar
passel[VB 6] - Platform Gravity passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I don't work for a gaming company.
My VB programming has mostly been a hobby.
But I've been interested in computer programming from the first time I had access to a programmable calculator back in 1975-76, so have managed to work at a couple of companies in capacities that allowed me to do a lot of software programming, but it has mostly involved simulators so the programming is mostly integration, connecting different computers or hardware or applications together to provide a simulation training environment for things like trains, planes, submarines, and automobiles (planes include mostly helicopters as of late).

There are different approaches you can take in regards to timers.
The simple use of a single VB Timer control can do for simple things.
The base clock that the timer runs at, which varies depending on hardware and/or operating system, will give you the real resolution you have to work with.
The Interval is specified in milliseconds, which is 1000 per second.
So to get .1 seconds (10 hz), you would specify an interval of 100.
But what the Timer control in VB6 guarantees is that there will be at least 100 milliseconds between the time you exit the timer event before the next event will occur.
The time spent in the event handler doing whatever work you have to do will not be counted.
So, if your drawing took 50 ms (milliseconds), to accomplish, and you had the timer interval set to 100 ms, the total loop time would be 150 ms, not 100 ms, so your update rate would be 50% slower than what you desired.
Also, lets assume that your drawing took almost no time, so the timer should fire every 100 ms. The reality is the base clock I mentioned will not have 1 ms resolution, but some other rate. The most common rate I've seen lately is 64hz (an interval of 15.625 ms).
So, if you choose some value, like 100 ms, the resolution is 15.625 ms, so the timer will fire at the first multiple of 15.625 that equals or exceeds 100 ms.
The multiple that meets this condition, assuming the above 64hz rate, is 7 clocks. (64hz means that you would need 6.4 ticks of the clock to equal 100 ms, so 6 ticks is short of 100.)
Seven ticks of the clock = 109.375 ms, so your selection of 100 ms would really fire at a minimum every 109+ ms, so your timing would be off by about 9 percent.

I could go on, but I need to do some real work soon or may run into trouble.
In the Top Ten Turorials thread there is a link labeled "A brief History of Time (And Date)" which should expand on some of the options available for timing.

The game started in the thread this post is a part of, uses a busy wait in the loop, rather than a timer, to run at the desired 30 hz frame rate.
The main drawback to a busy wait is that the program is sitting there spinning, chewing up CPU, and that is really draining on a laptop's battery, and a waste of energy when plugged in to the wall. But, it is a common way that games are written.
Another common option which works in most games (where the animation is not frame based) is just to determine what speed the various things should move in some unit of time, per millisecond is convenient since elapsed time in those units are available from a number of the Timing functions available.
How far your objects move then is just a function of multiplying the elapsed time in milliseconds * distance to move per millisecond.
This will ensure that the object moves the same distance per second on both a machine that is doing 20 frames per second, and another doing 130 frames per second.
The one doing 130 frames per second just looks smoother since the objects move shorter distances more often compared to the 20 frames per second machine which has to move the objects in larger steps to cover the same ground in the same period of time.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 08-16-2011 at 11:02 AM.
Reply With Quote
  #17  
Old 08-22-2011, 05:43 AM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

i'll try sum this all up in one, to fix my problems.

1. how do you make a picture type change into a different picture that is currently within its own folder?

2. making pictures disabled, would that mean ther ecode will not work unless its enabled? trying to use that to make multi platforms where you collide with one thing to unlock the ground for other areas.

3. *overall* if i were to collide with the dye, it goes invisble, then the other platforms become enabled.. if i get hit by the bouncy paint, then i turn back into black, the certain ground becomes disabled, the dye reapears.

4. fully functional three life count. that asks at the end if you want to play again, which opens the first form, making sure the other ones are unloaded, and if no then end program
Reply With Quote
  #18  
Old 08-23-2011, 09:20 AM
passel's Avatar
passel[VB 6] - Platform Gravity passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

1. ? assuming you mean you want to load the picture from a file on the disk you would normally use LoadPicture, like:
Picture1.Picture = LoadPicture("C:\1.jpg")

2. Disabled would normally prevent mouse or keyboard input to the control. If you didn't want to see the control you would set the .Visible property to False.
If you wanted to have multiple controls go invisible at the same time, you could put the controls into Frames. Then, if you make the frame visible or invisible, all the controls in the frame appear or disappear. You could have different levels simply by repositioning the frame to 0,0 and making it visible, while the previous levels frame is made invisible, for instance.
I don't know what you mean by making a picture disabled making their code not work, as a picture doesn't have code.
If you don't want to collide with a non-visible picture, you will have to track that yourself. The picture control will still be there for you to collide with, even if it is not visible, unless you move the control outside the bounds of where you can collide with it.

3. OK

4. You might be having problems unloading the forms, if you have a timer running. As soon as any code accesses a variable of a form, the form is reloaded if it in not in memory. So unload has to be the last code executed in a form. Probably best to set a Boolean indicating that the game is over, the timer event code would see the game is over, disable the timer, and call Unload Me at the end of the tick event processing.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #19  
Old 08-23-2011, 04:26 PM
ilikebeds1 ilikebeds1 is offline
Newcomer
 
Join Date: Aug 2011
Posts: 20
Default

here is my code, as it is now. i now need the timer, and lives, before i can start making multiply levels
Attached Files
File Type: zip vb assignment.zip (19.0 KB, 24 views)
Reply With Quote
  #20  
Old 08-24-2011, 10:19 AM
passel's Avatar
passel[VB 6] - Platform Gravity passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I hope you understand that this forum is to help you with your programming issues, not write code for you, or a code hand out site.

Have a look at this piece of code.
Code:
  If GameOver Then
    Unload Me          'make sure unload is the last thing access in the loop, otherwise the form will
                       'reload (but not be visible), and the timer will be reinitialized and continue
                       'cycling, leaving the executable running
  End If
If you read the comment it says this must be at the end of your code loop, but you have it in the middle. It should be at the bottom of your timer event.
Because it is not at the end of the timer event, the form is not unloaded because after you tell it to unload, it continues executing the code after that statement and has to reload the form to access variables in the form module. It doesn't show the form again, it just remains in memory cycling through the timer events as they continue to occur.

This commented out code
Code:
'If Collision(picBlob, picPainting) Then
'Form2.Show vbModal
'Unload Form1
'End If
Didn't work for a couple of reasons.
As soon as you show a form Modal, the form that launched the form is suspended, so it never gets to the next line of code (and none of its timer events are being generated, so no code at all from the first form is running while Form2 is shown).

If you don't want to return to your first form, you shouldn't show the second form modal.
If you do want to return to the first form, if you set the first Form's Visible property to false before showing the second form modal, then when the second form exits and your first form is allowed to continue, the first statement would be to set the Visible property back to True, if that is what you wanted.
Model Form is usually used for a pop-up or dialog where you enter some information and return to the mainform, so you wouldn't hide the first form usually.
Which also brings up that rather than changing the Visible property, you could also do Me.Hide and Me.Show instead.

If you really want to unload the first form, then that needs to be at the end of your code, not in the middle.
So, rather than show the form and unload the first at the point where you determine it needs to be done, set a flag and check for that at the end.
Code:
...game code...

If Collision(picBlob, picPainting) Then
  switchForm = True
End If

...game code...

'End of the timer event
  If GameOver Then
    Unload Me          'make sure unload is the last thing access in the loop, otherwise the form will
                       'reload (but not be visible), and the timer will be reinitialized and continue
                       'cycling, leaving the executable running
  ElseIf switchForm Then
    Form2.Show   'Not modal, so the next line will execute and unload this form
    Unload Me
  End If

End Sub  'the _Timer sub
If you want to have three lives, then when the player falls off the screen, rather than set GameOver, decrement a Life count, and if there are lives left, reset the game to the start of the current level.
If there are no more lives, then set GameOver.
And if you set GameOver, you may not just want to exit the program, but offer to start over at the first level.

If you're going to use separate forms for different levels, then you should add a Module (Project menu, Add Module selection) to keep track of all your game state variables, such as what level you're on, what the score is, how many lives you have, etc.
That way, these values can be reference directly from any form level code in the project.
You may want to move common code, to the module as well, such as your collision function, so you don't have to repeat that code in every form.
Move variables and subs that you will need to exist for the whole game from your existing form to the module. Don't leave a copy in the form, or the form code will use the local copy, not the global one.

Instead of having your initialization code in the Form_Load event handler, you would want to put that in a subroutine that you call from the Form_Load handler. That way, if you want to start a level over, you can just call that routine to reset everything for the level.

As an example of prompting the user, here is a msgbox example.
This will work with your current code (once the terminal logic has been moved to the end of the timer event), but it would be best to have an initialization Sub, rather than have to Unload the form to reinit things.
When the Form is Unloaded, but then has other code referencing the form, the IDE specified values, such as where the controls are located, and what state they are in initially, such as Timer interval, Timer Enabled, etc. are reset to their initial values. But the Form level variables, such as GameOver, are not reinitialized so have their prior value still in them. So, as seen in the following code, the GameOver boolean is specifically reset to false, otherwise, we would keep coming into this block of code and prompting the user if they wanted to continue or not.
Code:
  If GameOver Then
    Dim ans As Integer
    ans = MsgBox("Play again?", vbYesNo)
    If ans = vbNo Then
      tmrGameTick.Enabled = False
      Unload Me          'make sure unload is the last thing access in the loop, otherwise the form will
                         'reload (but not be visible), and the timer will be reinitialized and continue
                         'cycling, leaving the executable running
    Else 'assume yes
      GameOver = False   'Game not over
      Unload Me          'Won't really be unloaded since we have code after this
      Me.Show            'but will cause the controls to reset to their initial positions
    End If
  ElseIf switchForm Then
    tmrGameTick.Enabled = False
    Form2.Show
    Unload Me
  End If
P.S. I'll have to doublecheck your code on my laptop at home. I looked at the code on that laptop first, and I wondered why you had some of the pictureboxes invisible.
On my work laptop, these "invisible" pictureboxes are showing up black.
I looked at the selected background color, and I see they are set to the system color "Active Title Bar Text".
I'll have to check my laptop at home to see if they are still set to "Active Title Bar Text". You're setting the background of the form to White, so I'm guessing my "Active Title Bar Text" maps to something close to White so that is why I'm not seeing it.
For game purposes, if you want those pictureboxes to have black backgrounds, you should choose the color from the fixed palette of colors, which you did for the other pictureboxes and form, rather than from the indirect System Color palette, which changes based on the color scheme the user has selected.
The System Color palette is more suited for creating controls, so that controls you create don't clash with the scheme the user has selected.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.

Last edited by passel; 08-24-2011 at 11:14 AM.
Reply With Quote
Reply


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 Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity [VB 6] - Platform Gravity
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity [VB 6] - Platform Gravity
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity
 
[VB 6] - Platform Gravity
[VB 6] - Platform Gravity
 
-->