Alright, but I'm warning you though, this is pretty advanced. I'm going to do this by memory since I don't have VB in front of me right now. So there might be a mistake or two.
1) First of all, you will need to create a user defined data type called Sprite_Type:
2) Use the code I have above to serve as a base. Only this time I put the Sprite_Type in there.Code:Private Type Sprite_Type X As Long Y As Long Visible As Boolean Active As Boolean 'This obviously needs more but for beginner's purposes, this is fine 'for now. End Type
Code:Option Explicit 'This makes sure all variables have been declared. Private Type Sprite_Type X As Long Y As Long Visible As Boolean Active As Boolean 'This obviously needs more but for beginner's purposes, this is fine 'for now. End Type Private Declare Sub Sleep Lib "kernel32" (ByVal Milliseconds As Long) 'Needed for pausing between loops. This will be your first API you ever used. Dim Sprite As Sprite Type 'Make this an array if you want more sprites. Private Sub Form_Activate() Dim Game_Active As Boolean 'Boolean is either always true or false. ScaleMode = 3 'Makes the form's coordinate system based on 'pixels rather than twips. Picture1.ScaleMode = 3 'Makes the picturebox's coordinate system based on 'pixels rather than twips. Sprite.X = 0 Sprite.Y = 0 Sprite.Active = True Sprite.Visible = True Game_Active = True While Game_Active = True DoEvents 'So the program doesn't lock up and allow events to happen. Sleep 15 'Keep it around 60 FPS. 1000 / 15 = 66.66 If Sprite.Active = True And Sprite.Visible = True Then Picture1.Visible = True End If Sprite.X = Sprite.X + 1 If (Sprite.X) >= 250 Then 'If it collides at 250 Sprite.X = 250 'Stay at 250 Game_Active = False 'Exits the while loop. End If Picture1.Left = Sprite.X 'For every frame, move the picturebox '1 unit to the right. Picture1.Top = Sprite.Y Wend End Sub




Reply With Quote