Sign in to follow this  
xtr33me

[.net] Make character jump in GDI+ VB.NET

Recommended Posts

Hi all. Forgive me if what you see below isn't up to par. I am new to this graphics programming stuff, so if you have any recommendations on the coding, or for that matter a simpler way of doing something, please critique. The reason I am posting this is because I need help making my character kenny jump. I thought about assigning the jump key to a timer, however when I put it in the timer event, it said I was unable to use the "keys.space" under the timer event because it says it is not part of "System.EventArgs" I am essentially going to try and create a pitfall game using kenny from southpark and various characters. Now currently I just have the form background as the background that will change when he reaches the right of the screen. I am going to have it rotate through screens eventually. Currently the ground is just part of the background. But as in pitfall I am going to want him to be able to drop to a lower level. If any of you have any ideas on how I will be able to have him drop to a lower level at times please let me know. I am using VB 2005 .net just so you know. Thanks for the help! Also, if you have any recommended books for .net game programming, please feel free to post the titles. Xtreme **CODE** Public Class Form1 Dim pos As Point Dim loc As String Dim dir As String Dim frame As Integer Dim formBack As Boolean Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown If pos.X < 485 Then Select Case formBack Case False Me.BackgroundImage = Image.FromFile("background/winter1.gif") Case True Me.BackgroundImage = Image.FromFile("background/winter2.gif") End Select If pos.X >= 485 Then pos.X = 5 End If '******************** 'Key Movement '******************** 'change direction graphic to left If e.KeyCode = Keys.Left Then pos.X -= 5 dir = "left" End If 'change direction graphic to right If e.KeyCode = Keys.Right Then pos.X += 5 dir = "right" End If frame += 1 If frame = 4 Then frame = 1 loc = "kenny/" & dir & frame & ".gif" Me.Invalidate() 'change to a crouch If e.KeyCode = Keys.Down Then loc = "kenny/rightCrouch1.gif" Me.Invalidate() End If ElseIf pos.X >= 485 Then pos.X = 5 formBack = Not (formBack) End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Setstyle(Controlstyles.DoubleBuffer, True) Setstyle(Controlstyles.AllPaintingInWmPaint, True) 'set default graphic and position loc = "kenny/right1.gif" pos.X = 5 pos.Y = 145 End Sub Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Dim Bmp As New Bitmap(loc) Bmp.MakeTransparent(Color.Lime) e.Graphics.DrawImage(New Bitmap(Bmp), pos) End Sub End Class

Share this post


Link to post
Share on other sites
This is probably because the Timer Event uses System.EventArgs, rather than System.KeyEventArgs and so you cannot check if the space bar was pressed in that instance of the Arguments.

Share this post


Link to post
Share on other sites
Yes you are correct. How would I go about making him jump though? Been having a heck of a time trying to find code that works in .net to do so. I also am aware that it is probably due to my little knowlegde on the subject.

Xtreme

Share this post


Link to post
Share on other sites
Well there are lots of ways to make something "jump".

In the keydown event you can make the spacebar jump the player if and only if the player is in a jumpable position, ie on the ground. When this happens you can increase (or decrease) the Y position to some max and then go back in the other direction.

Or you can give the player a Y Velocity that gets decreased over time, ie gravity. Either way will work, the second will be more realistic to the real world.

Share this post


Link to post
Share on other sites
Hey,
There is an article in the resources section of this site in the math/physics area I believe with an excellent article on jumping. check it out.
Hope this helps.
Svenjamin

EDIT: Its called "Gravity FAQ"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this