Fabian_Russ
Newcomer
- Joined
- Sep 29, 2008
- Messages
- 23
Hi, I am currently using Visual Basic 2008.
I started my game and added my sprites and got my obstacles set up.
I do not know how to detect Collision.
How do I make it where if my character touches the building. He Stops Moving.
And
I am trying to find out which side of the building my character is touching.
For Example.
If my character touches the top side of the building then Collision = 1
If my character touches the left side of the building then Collision = 2
If my character touches the right side of the building then Collision = 3
If my character touches the bottom side of the building then Collision = 4
I just can't figure out how to find the side of the building I am touching.
I am using Pictureboxes for Everything.
I tried looking it up first... There is no sense in making a post if you can't find something yourself.
I have spent about 9 hours straight looking this up and I CANNOT for the life of me find something that works the way I need it to.
--------------------------------------------------------------------------
This piece of code is composed of :
1. Key Down Event.
2. Key Up Event.
3. A Timer to move the character and run the Sub that Animates movements.
4. A Sub to Control and Animate the movements.
5. The Animations to run.
--------------------------------------------------------------------------
*** = Something I am trying to add.
------------------------Dimming my functions--------------------------
Animation tells it what frame to use.
EXAMPLE : When Walking the Animation number is reset to 0 then increases by 1 with the timer. and as it increases. it animates!
Direction tells what way you face after key up **** or if you hit a collision
Example : When hitting the Up Arrow, You walk Up. and Direction = 1, When releasing the Up Arrow, Direction = 1 so you face Up.
Example2 : When hitting the Left Arrow, You walk Left. and Direction = 2, When releasing the Left Arrow, Direction = 2 so you face Left.
***Collision : When you hit an object, The number tells the key you are holding down to stop the timer and quit animating, it takes the direction and makes you face the way you where walking, The collision integer tells a number when hitting an object. and that number tells which key to stop.
Example : You walk into a wall, You quit animating that you are walking and start standing, You stand the direction you last walked.
'Collision = I am working on this to try to keep track of Your direction and what you hit. If it = 1 then when you hit something. It will stop you. and make you face forward according to the direction
Any help would be appreciated, I am nervous (This is my first post.) so I am trying to explain it as simple as possible to the person who is reading.
any help is APPRECIATED!!!! Thx!
Here is what I have for coding : (MAY NOT BE THE BEST, BUT 99% of it WORKS.)
------------------------Dimming------------------------
Dim Animation As Integer
Dim Direction As Integer
Dim Collision As Integer
'1. =============== Controls (Form Keydown Event)=============
Private Sub Walking_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Up Then
Direction = 1
If Collision = 1 Then
Player.Image = Player_Stand_Up
WalkMovement.Stop()
Else
WalkMovement.Start()
End If
End If
If e.KeyCode = Keys.Left Then
Direction = 2
If Collision = 2 Then
Player.Image = Player_Stand_Left
WalkMovement.Stop()
Else
WalkMovement.Start()
End If
End If
If e.KeyCode = Keys.Right Then
Direction = 3
If Collision = 3 Then
Player.Image = Player_Stand_Right
WalkMovement.Stop()
Else
WalkMovement.Start()
End If
End If
If e.KeyCode = Keys.Down Then
Direction = 4
If Collision = 4 Then
Player.Image = Player_Stand_Down
WalkMovement.Stop()
Else
WalkMovement.Start()
End If
End If
'2. ===============Controls (Form KeyUp Event) =========
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If Direction = 1 Then
Player.Image = Player_Stand_Up
End If
If Direction = 2 Then
Player.Image = Player_Stand_Left
End If
If Direction = 3 Then
Player.Image = Player_Stand_Right
End If
If Direction = 4 Then
Player.Image = Player_Stand_Down
End If
'3. ===========Walk Movement (Timer)====================
Private Sub WalkMovement_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WalkMovement.Tick
WalkAnimationController()
If Direction = 1 Then
Player.Location = New Point(Player.Location.X, Player.Location.Y - 2)
WalkUp()
End If
If Direction = 2 Then
Player.Location = New Point(Player.Location.X - 2, Player.Location.Y)
WalkLeft()
End If
If Direction = 3 Then
Player.Location = New Point(Player.Location.X + 2, Player.Location.Y)
WalkRight()
End If
If Direction = 4 Then
Player.Location = New Point(Player.Location.X, Player.Location.Y + 2)
WalkDown()
End If
End Sub
'4. =========== Sub That Animates Sprite (Sub)====================
Sub WalkAnimationController()
Animation = Animation + 1
If Animation > 8 Then
Animation = 0
End If
End Sub
'5. =========== Lots of Animations (Large Amount of Subs)====================
Sub WalkUp()
Direction = 1
If Animation = 2 Then
Player.Image = Player_Walk_Up1
End If
If Animation = 4 Then
Player.Image = Player_Stand_Up
End If
If Animation = 6 Then
Player.Image = Player_Walk_Up2
End If
If Animation = 8 Then
Player.Image = Player_Stand_Up
End If
End Sub
Sub WalkLeft()
Direction = 2
If Animation = 2 Then
Player.Image = Player_Walk_Left1
End If
If Animation = 4 Then
Player.Image = Player_Stand_Left
End If
If Animation = 6 Then
Player.Image = Player_Walk_Left2
End If
If Animation = 8 Then
Player.Image = Player_Stand_Left
End If
End Sub
Sub WalkRight()
Direction = 3
If Animation = 2 Then
Player.Image = Player_Walk_Right1
End If
If Animation = 4 Then
Player.Image = Player_Stand_Right
End If
If Animation = 6 Then
Player.Image = Player_Walk_Right2
End If
If Animation = 8 Then
Player.Image = Player_Stand_Right
End If
End Sub
Sub WalkDown()
Direction = 4
If Animation = 2 Then
Player.Image = Player_Walk_Down1
End If
If Animation = 4 Then
Player.Image = Player_Stand_Down
End If
If Animation = 6 Then
Player.Image = Player_Walk_Down2
End If
If Animation = 8 Then
Player.Image = Player_Stand_Down
End If
End Sub
I have attached my project.
If you have any info you want to get into detail about
You can IM me at : Fabianruss@hotmail.com
Or, Email me at : Fabian.Russ@comcast.net
I started my game and added my sprites and got my obstacles set up.
I do not know how to detect Collision.
How do I make it where if my character touches the building. He Stops Moving.
And
I am trying to find out which side of the building my character is touching.
For Example.
If my character touches the top side of the building then Collision = 1
If my character touches the left side of the building then Collision = 2
If my character touches the right side of the building then Collision = 3
If my character touches the bottom side of the building then Collision = 4
I just can't figure out how to find the side of the building I am touching.
I am using Pictureboxes for Everything.
I tried looking it up first... There is no sense in making a post if you can't find something yourself.
I have spent about 9 hours straight looking this up and I CANNOT for the life of me find something that works the way I need it to.
--------------------------------------------------------------------------
This piece of code is composed of :
1. Key Down Event.
2. Key Up Event.
3. A Timer to move the character and run the Sub that Animates movements.
4. A Sub to Control and Animate the movements.
5. The Animations to run.
--------------------------------------------------------------------------
*** = Something I am trying to add.
------------------------Dimming my functions--------------------------
Animation tells it what frame to use.
EXAMPLE : When Walking the Animation number is reset to 0 then increases by 1 with the timer. and as it increases. it animates!
Direction tells what way you face after key up **** or if you hit a collision
Example : When hitting the Up Arrow, You walk Up. and Direction = 1, When releasing the Up Arrow, Direction = 1 so you face Up.
Example2 : When hitting the Left Arrow, You walk Left. and Direction = 2, When releasing the Left Arrow, Direction = 2 so you face Left.
***Collision : When you hit an object, The number tells the key you are holding down to stop the timer and quit animating, it takes the direction and makes you face the way you where walking, The collision integer tells a number when hitting an object. and that number tells which key to stop.
Example : You walk into a wall, You quit animating that you are walking and start standing, You stand the direction you last walked.
'Collision = I am working on this to try to keep track of Your direction and what you hit. If it = 1 then when you hit something. It will stop you. and make you face forward according to the direction
Any help would be appreciated, I am nervous (This is my first post.) so I am trying to explain it as simple as possible to the person who is reading.
any help is APPRECIATED!!!! Thx!
Here is what I have for coding : (MAY NOT BE THE BEST, BUT 99% of it WORKS.)
------------------------Dimming------------------------
Dim Animation As Integer
Dim Direction As Integer
Dim Collision As Integer
'1. =============== Controls (Form Keydown Event)=============
Private Sub Walking_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Up Then
Direction = 1
If Collision = 1 Then
Player.Image = Player_Stand_Up
WalkMovement.Stop()
Else
WalkMovement.Start()
End If
End If
If e.KeyCode = Keys.Left Then
Direction = 2
If Collision = 2 Then
Player.Image = Player_Stand_Left
WalkMovement.Stop()
Else
WalkMovement.Start()
End If
End If
If e.KeyCode = Keys.Right Then
Direction = 3
If Collision = 3 Then
Player.Image = Player_Stand_Right
WalkMovement.Stop()
Else
WalkMovement.Start()
End If
End If
If e.KeyCode = Keys.Down Then
Direction = 4
If Collision = 4 Then
Player.Image = Player_Stand_Down
WalkMovement.Stop()
Else
WalkMovement.Start()
End If
End If
'2. ===============Controls (Form KeyUp Event) =========
Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If Direction = 1 Then
Player.Image = Player_Stand_Up
End If
If Direction = 2 Then
Player.Image = Player_Stand_Left
End If
If Direction = 3 Then
Player.Image = Player_Stand_Right
End If
If Direction = 4 Then
Player.Image = Player_Stand_Down
End If
'3. ===========Walk Movement (Timer)====================
Private Sub WalkMovement_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles WalkMovement.Tick
WalkAnimationController()
If Direction = 1 Then
Player.Location = New Point(Player.Location.X, Player.Location.Y - 2)
WalkUp()
End If
If Direction = 2 Then
Player.Location = New Point(Player.Location.X - 2, Player.Location.Y)
WalkLeft()
End If
If Direction = 3 Then
Player.Location = New Point(Player.Location.X + 2, Player.Location.Y)
WalkRight()
End If
If Direction = 4 Then
Player.Location = New Point(Player.Location.X, Player.Location.Y + 2)
WalkDown()
End If
End Sub
'4. =========== Sub That Animates Sprite (Sub)====================
Sub WalkAnimationController()
Animation = Animation + 1
If Animation > 8 Then
Animation = 0
End If
End Sub
'5. =========== Lots of Animations (Large Amount of Subs)====================
Sub WalkUp()
Direction = 1
If Animation = 2 Then
Player.Image = Player_Walk_Up1
End If
If Animation = 4 Then
Player.Image = Player_Stand_Up
End If
If Animation = 6 Then
Player.Image = Player_Walk_Up2
End If
If Animation = 8 Then
Player.Image = Player_Stand_Up
End If
End Sub
Sub WalkLeft()
Direction = 2
If Animation = 2 Then
Player.Image = Player_Walk_Left1
End If
If Animation = 4 Then
Player.Image = Player_Stand_Left
End If
If Animation = 6 Then
Player.Image = Player_Walk_Left2
End If
If Animation = 8 Then
Player.Image = Player_Stand_Left
End If
End Sub
Sub WalkRight()
Direction = 3
If Animation = 2 Then
Player.Image = Player_Walk_Right1
End If
If Animation = 4 Then
Player.Image = Player_Stand_Right
End If
If Animation = 6 Then
Player.Image = Player_Walk_Right2
End If
If Animation = 8 Then
Player.Image = Player_Stand_Right
End If
End Sub
Sub WalkDown()
Direction = 4
If Animation = 2 Then
Player.Image = Player_Walk_Down1
End If
If Animation = 4 Then
Player.Image = Player_Stand_Down
End If
If Animation = 6 Then
Player.Image = Player_Walk_Down2
End If
If Animation = 8 Then
Player.Image = Player_Stand_Down
End If
End Sub
I have attached my project.
If you have any info you want to get into detail about
You can IM me at : Fabianruss@hotmail.com
Or, Email me at : Fabian.Russ@comcast.net
Last edited: