Please take a look and offer any help. :)

Bigpapa3xl
12-15-2004, 01:04 AM
This is my first year in a programming class at my high school. I am currently in the first semester of Visual Basic .net. I am getting very curious about what can be done with the language so i began to make a game. Its a mortal kombat fighting game. I only have one fighter coded on one form but i thought that is pretty good to me. Please take a look and tell me what you think. Run the game and select Johnny Cage. Use the arrow buttons to move him (left, right, up, down)

Please offer any suggestions you may have. I would like to continue my work on the game, and make it into some thing really nice. :)

PS. Im glad to be here! Hope i have a good time. :)

Thanks

Bigpapa

Bigpapa3xl
12-16-2004, 05:57 PM
Anyone care to comment?

bigpapa

elnerdo
12-16-2004, 07:36 PM
Sure,

When I move the character left or if I jump, he disappears and then comes back.

Bigpapa3xl
12-16-2004, 10:26 PM
Thanks

Yes i did notice that. I was able the fix the moving left thing and disapearing, but as far as disapearing when he jumps i have no clue what is doing it. I am just beging the learn the code past my first 6 tutorals, and truthly a friend has helped me with the code. If you get a chance could you take a look at the code, and see what might be causing the disapearence of the fighter when you jump? Tomorrow i will post my revised edition, with the fixed horizontal movement, as well as a second fighter on the form.

Thanks

bigpapa

Iceplug
12-17-2004, 08:12 AM
OK, first off, you need to close your forms. Hiding them only forces me to hit the stop button, and you should be avoiding that as soon as possible.

So:
SelectionScreen.Show()
Me.Hide()
Should be:
Me.Hide() 'You won't see it anymore.
SelectionScreen.ShowDialog() 'Stop execution until this form is closed.
Me.Close()

Now, ArmoryBackGnd, you have four timers which all have the same interval.
You could save resources by using one timer and four if statements.
If T1on Then
'Timer1 code.
End If
If T2on Then
'Timer 2 code.
End If
If T3on Then
'Timer 3 code.
End If
If T4on Then
'Timer 4 code.
End If
I don't know what they are doing though. Timer 4 looks pretty useless.
And now, my Visual Studio has crashed. :-\

Bigpapa3xl
12-17-2004, 01:48 PM
Thanks so much for you help.

When i change the code to close the form like you said, when i click on the jonny cage picture it just ends the program. I have to take a better look at that. So for right now ill just leave it as it is.

Secondly those timers are susposed to make the fighter jump. Now i know there must be a better way to do this because when i do jump he disapears after like the 3rd try?

Im attaching the latest file. It has two fighters, JC user the arrow keys, and Reptile uses wasd. Reptile will not jump right, and i can not more both of the fighters at the same time. :( This is a lot harder then i thought. lol

Thanks for you help, and i hope you will be able to further assist me. :)

Thanks

Bigpapa
There were 2 EXEs that needed to be removed

Bigpapa3xl
12-17-2004, 11:11 PM
There were 2 EXEs that needed to be removed[/QUOTE]

Oh srry. Which ones needed to be taken out?

Bigpapa

Faith
12-18-2004, 07:30 AM
I quote the posting guideline 11. when I state:

Attaching or directly linking to EXE, DLL, OCX or other compiled executable files is strictly forbidden. You must attach source code instead, and MS Office files containing VBA code (macros) must be unlocked to permit viewing of the code content.

So I could make an educated guess, all exes were removed... :chuckle:

Iceplug
12-18-2004, 05:22 PM
Yes :cool:. I removed all 2 of the EXEs in your attachment.
After spending quite a bit of time trying to follow your code, I think I found the problem.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim a As Integer = 5
Do While a > 0
CageJumping.Top = CageJumping.Top - 10
a = a - 1
Loop
Timer2.Enabled = True
End Sub
First of all, you are not handling Timer2 at all. I suppose this is just for demonstration purposes.
This section of code
Do While a > 0
CageJumping.Top = CageJumping.Top - 10
a = a - 1
Loop
Is the same as just saying
CageJumping.Top = CageJumping.Top - 50
And everytime you enter this subroutine, a is set to 5, so this happens at every clock tick.

As to why Johnny Cage disappears... it is because the timer is still running after the Up key is pressed. So eventually the jumping image of JC flies off into the stratosphere, and when you press up, you switch off the standing image, and show the jumping image (which is nowhere to be seen).

For getting both people to move at once, you need to keep track of which keys are down by declaring an array of booleans. So, when you press the Down key, the element in the boolean array that corresponds to down will be set to True (in the KeyDown event), and then you set this corresponding boolean value to False in the KeyUp event.
So, when you want to check if the keys are pressed, you put the necessary code in a timer, and then check if the key is pressed by checking the boolean array element that corresponds to the key you are looking for. :)

Bigpapa3xl
12-18-2004, 11:14 PM
Yes :cool:. I removed all 2 of the EXEs in your attachment.
After spending quite a bit of time trying to follow your code, I think I found the problem.
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim a As Integer = 5
Do While a > 0
CageJumping.Top = CageJumping.Top - 10
a = a - 1
Loop
Timer2.Enabled = True
End Sub
First of all, you are not handling Timer2 at all. I suppose this is just for demonstration purposes.
This section of code
Do While a > 0
CageJumping.Top = CageJumping.Top - 10
a = a - 1
Loop
Is the same as just saying
CageJumping.Top = CageJumping.Top - 50
And everytime you enter this subroutine, a is set to 5, so this happens at every clock tick.

As to why Johnny Cage disappears... it is because the timer is still running after the Up key is pressed. So eventually the jumping image of JC flies off into the stratosphere, and when you press up, you switch off the standing image, and show the jumping image (which is nowhere to be seen).

For getting both people to move at once, you need to keep track of which keys are down by declaring an array of booleans. So, when you press the Down key, the element in the boolean array that corresponds to down will be set to True (in the KeyDown event), and then you set this corresponding boolean value to False in the KeyUp event.
So, when you want to check if the keys are pressed, you put the necessary code in a timer, and then check if the key is pressed by checking the boolean array element that corresponds to the key you are looking for. :)

Ok thank you very much. I finilly have something to work with. :)

Ok to address the jumping. I should get rid of the other 3 timers, then add a timer1.enabled = False to they keyup event? That would end the timer when i let the key up correct?

Ok now for the dual movement. I have not worked with arrays so i will have to research those. Here is how i kinda see it right now with my current knowlege.

Dim a new array
Dim the images as new boolens
Add the boolens to the array
If Then statements stating:
If the value is true then move the guy
If Fase dont.

Is that kinda how it is going to work? When i get time i am going to look around for some more information. This looks like this is going to work. :)

Thanks so much.

Bigpapa

Iceplug
12-19-2004, 07:49 PM
Ok to address the jumping. I should get rid of the other 3 timers, then add a timer1.enabled = False to they keyup event? That would end the timer when i let the key up correct?

You will need to somehow bring the jumping image of the player back to the original level. Otherwise your image will remain in the air from the last jump.

Dim the images as new boolens
You don't dim something as something else. An image is already declared as an image.
You will dim an array of booleans. You do not have to add anything to this array.
The corresponding part is for you to find some way to correlate a keycode with an index in the array.
If ek = Keys.Left Then
arry(0) = True '0 corresponds to left.
End If
:)

Bigpapa3xl
12-20-2004, 02:56 AM
Ok thanks so much. I am a complete noob when it comes to programming, so ill have to do some heavy research. At least now i know what to look for. :) You can count on me coming back with more questions.

Thanks so much!

BP

Bigpapa3xl
01-04-2005, 09:02 PM
Hey Hey im back.

Im all rested from Break, and im getting back into my game. Looking over everything over and over again, and searching MSDN. I am still coming up confused with the Array thing.

I have no clue how to start it off even. The example you gave me looks simple enough, but getting the whole thing in motion is my brick wall. MSDN is just confusing, and lacks good examples. I want to explain my situation, and goal one more time as clearly as i can for everyones benefit.

The Game:
Mortal Kombat, Two Pictureboxes on form, Each picturebox is a diff. fighter.
The Goal:
I want a two player game where both pictureboxes can be moved at the same time.
The Current Situation:
I am using the .keypress event to move the pictureboxes. This works but i cannot move more then one at the same time.

Please offer any help you can. You have been a great help so far, and pointed me in the right direction. :)

Thanks so much

BP

elnerdo
01-05-2005, 02:46 PM
to move more than one that a time use the keydown and keyup events and booleans for each key when that key is pressed down, make the boolean true, and when the key is pressed up, make the boolean false. then, in a main game timer, move the characters according to what booleans are true

Bigpapa3xl
01-05-2005, 03:41 PM
OK this is what i came up with, but i still cannot get them to move at the same time. :(

The source file is attached. The code was to long to paste

Thanks for your help. I hope im on the right track

BP

Bigpapa3xl
01-06-2005, 11:58 AM
Cant anyone help? Im cutting down the code so i can fit the important part on here so you dont have to open the file. :)


'tells if the left & right buttons are pressed.
Dim CageGoLeft, CageGoRight, ReptileGoLeft, ReptileGoRight As Boolean

Private Sub MoveFighter(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
'Move Cage by pressing the arrow keys
Select Case e.KeyCode
Case Keys.Left
CageGoLeft = True
Case Keys.Right
CageGoRight = True
End Select
'Move Reptile by pressing the WASD Keys
Select Case e.KeyCode
Case Keys.A
ReptileGoLeft = True
Case Keys.D
ReptileGoRight = True
End Select
End Sub

Private Sub MainTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainTimer.Tick
Select Case
'Move Cage using provided code if the boolean is true
Case CageGoLeft
Me.CageDucking.Left = Me.CageWalkingRight.Left
Me.CageJumping.Left = Me.CageWalkingRight.Left
Me.CageWalkingRight.Left = Me.CageStanding.Left
Me.CageWalkingLeft.Left = Me.CageWalkingRight.Left
Me.CageStanding.Left = Me.CageStanding.Left - 5
Me.CageWalkingLeft.Visible = True
Me.CageDucking.Hide()
Me.CageJumping.Hide()
Me.CageStanding.Hide()
Me.CageWalkingRight.Hide()
Case CageGoRight
Me.CageDucking.Left = Me.CageWalkingRight.Left
Me.CageJumping.Left = Me.CageWalkingRight.Left
Me.CageWalkingRight.Left = Me.CageStanding.Left
Me.CageWalkingLeft.Left = Me.CageWalkingRight.Left
Me.CageStanding.Left = Me.CageStanding.Left + 5
Me.CageWalkingRight.Visible = True
Me.CageDucking.Hide()
Me.CageJumping.Hide()
Me.CageStanding.Hide()
Me.CageWalkingLeft.Hide()
End Select

'Move Reptile usind proved code if the boolean is true
Select Case
Case ReptileGoLeft
Me.ReptileDucking.Left = Me.ReptileWalkingRight.Left
Me.ReptileJumping.Left = Me.ReptileWalkingRight.Left
Me.ReptileWalkingRight.Left = Me.ReptileStanding.Left
Me.ReptileWalkingLeft.Left = Me.ReptileWalkingRight.Left
Me.ReptileStanding.Left = Me.ReptileStanding.Left - 5
Me.ReptileWalkingLeft.Visible = True
Me.ReptileDucking.Hide()
Me.ReptileJumping.Hide()
Me.ReptileStanding.Hide()
Me.ReptileWalkingRight.Hide()
Case ReptileGoRight
Me.ReptileDucking.Left = Me.ReptileWalkingRight.Left
Me.ReptileJumping.Left = Me.ReptileWalkingRight.Left
Me.ReptileWalkingRight.Left = Me.ReptileStanding.Left
Me.ReptileWalkingLeft.Left = Me.ReptileWalkingRight.Left
Me.ReptileStanding.Left = Me.ReptileStanding.Left + 5
Me.ReptileWalkingRight.Visible = True
Me.ReptileDucking.Hide()
Me.ReptileJumping.Hide()
Me.ReptileStanding.Hide()
Me.ReptileWalkingLeft.Hide()
End Select

End Sub

Private Sub ArmoryBckGnd_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
'When the key lets up then stop moving
If e.KeyCode = Keys.Left Then
CageGoLeft = False
ElseIf e.KeyCode = Keys.Right Then
CageGoRight = False
End If
'Ditto
If e.KeyCode = Keys.A Then
ReptileGoLeft = False
ElseIf e.KeyCode = Keys.D Then
ReptileGoRight = False
End If
End Class


Thanks for any help ;)

BP

Iceplug
01-07-2005, 07:04 PM
How do you have a Select Case without a Case to select from?

Select Case youneedsomethinghere
'Move Cage using provided code if the boolean is true
Case CageGoLeft
Me.CageDucking.Left = Me.CageWalkingRight.Left
Me.CageJumping.Left = Me.CageWalkingRight.Left
Me.CageWalkingRight.Left = Me.CageStanding.Left
Me.CageWalkingLeft.Left = Me.CageWalkingRight.Left
Me.CageStanding.Left = Me.CageStanding.Left - 5
Me.CageWalkingLeft.Visible = True
Me.CageDucking.Hide()
Me.CageJumping.Hide()
Me.CageStanding.Hide()
Me.CageWalkingRight.Hide()
Case CageGoRight
Me.CageDucking.Left = Me.CageWalkingRight.Left
Me.CageJumping.Left = Me.CageWalkingRight.Left
Me.CageWalkingRight.Left = Me.CageStanding.Left
Me.CageWalkingLeft.Left = Me.CageWalkingRight.Left
Me.CageStanding.Left = Me.CageStanding.Left + 5
Me.CageWalkingRight.Visible = True
Me.CageDucking.Hide()
Me.CageJumping.Hide()
Me.CageStanding.Hide()
Me.CageWalkingLeft.Hide()
End Select

Otherwise, you should just use If statements.

If CageGoLeft Then
'blah...

You are also missing the End Sub on your ArmoryBckGnd_KeyUp subroutine.
:)

That being said, I can't run your project because I don't have the resx file which contains the pictures.

Bigpapa3xl
01-07-2005, 08:32 PM
OK thank you very much. :)

Here is my updated project. Ill take out all the exe files and leave everything else. I switched the cases to If/then statements, and pluged in that end sub. lol i cant believe i for got that.

Thanks so much

BP

Bigpapa3xl
01-08-2005, 10:57 PM
OK thank you very much. :)

Here is my updated project. Ill take out all the exe files and leave everything else. I switched the cases to If/then statements, and pluged in that end sub. lol i cant believe i for got that.

Thanks so much

BP

Iceplug could you help me out? There is no doubt you know what you are doing. I would really appreciated the hlep. :)

Thanks

BP

Faith
01-09-2005, 04:38 AM
I don't know if you have more problems than the fact that your MainTimer should be enabled at somepoint too, just put the enabled = true from the property browser, or then enable it somewhere in the code with MainTimer.Start()
Also about using If statements or SelectCase, if you were to use Select Case then you'd make an enumeration perhaps like this:

Enum PlayerStatus
WalkingLeft
WalkingRight
Jumping
Idling
Blaablaa
End Enum

And you would declare the Cage's status as:
Dim CageStatus as PlayerStatus
and then use
Select Case CageStatus
Case WalkingLeft
Case WalkingRight
Case Jumping
'And so forth
End Select

:)
Any other problems?

subzero0000
01-09-2005, 05:27 AM
I've got your thing edited a bit, here is the ArmoryBckGnd codes.
Now the two characters will move left and right correctly.
I've changed only little codes, so it'll not be too hard to follow.


These codes start from you setting up the global variable (maybe it's not called "global", anyway)
Paste them to overwrite your current codes.


'Declare the variables that will determin if the keys are pressed.
Enum PlayerMovement
Standing
WalkingLeft
WalkingRight
Jumping
Ducking
End Enum
Structure PlayerPosition
Dim top As Long
Dim left As Long
End Structure
Structure PlayerSpeed
Dim x As Short
Dim y As Short
End Structure
Dim CageMovement As PlayerMovement
Dim ReptileMovement As PlayerMovement
Dim CagePosition As PlayerPosition
Dim ReptilePosition As PlayerPosition
Dim CageSpeed As PlayerSpeed
Dim ReptileSpeed As PlayerSpeed

Private Sub MoveFighter(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
'set motion status depends on keypress
Select Case e.KeyCode
Case Keys.Left
CageMovement = PlayerMovement.WalkingLeft
Case Keys.Right
CageMovement = PlayerMovement.WalkingRight
Case Keys.Up
CageMovement = PlayerMovement.Jumping
Case Keys.Down
CageMovement = PlayerMovement.Ducking
Case Keys.A
ReptileMovement = PlayerMovement.WalkingLeft
Case Keys.D
ReptileMovement = PlayerMovement.WalkingRight
Case Keys.W
ReptileMovement = PlayerMovement.Jumping
Case Keys.S
ReptileMovement = PlayerMovement.Ducking
End Select
End Sub

Private Sub MainTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MainTimer.Tick
'Move Cage using provided code if the condition is true
If CageMovement = PlayerMovement.WalkingLeft Then
CageDucking.Visible = False
CageJumping.Visible = False
CageStanding.Visible = False
CageWalkingRight.Visible = False
With CageWalkingLeft
.Left = CagePosition.left
.Top = CagePosition.top
.Visible = True
.Left = CageWalkingLeft.Left - CageSpeed.x
End With
CagePosition.left = CageWalkingLeft.Left
CagePosition.top = CageWalkingLeft.Top
ElseIf CageMovement = PlayerMovement.WalkingRight Then
CageDucking.Visible = False
CageJumping.Visible = False
CageStanding.Visible = False
CageWalkingLeft.Visible = False
With CageWalkingRight
.Left = CagePosition.left
.Top = CagePosition.top
.Visible = True
.Left = CageWalkingRight.Left + CageSpeed.x
End With
CagePosition.left = CageWalkingRight.Left
CagePosition.top = CageWalkingRight.Top
Else
CageDucking.Visible = False
CageJumping.Visible = False
CageWalkingLeft.Visible = False
CageWalkingRight.Visible = False
With CageStanding
.Left = CagePosition.left
.Top = CagePosition.top
.Visible = True
End With
End If
'Move Reptile using provided code if the condition is true
If ReptileMovement = PlayerMovement.WalkingLeft Then
ReptileDucking.Visible = False
ReptileJumping.Visible = False
ReptileStanding.Visible = False
ReptileWalkingRight.Visible = False
With ReptileWalkingLeft
.Left = ReptilePosition.left
.Top = ReptilePosition.top
.Visible = True
.Left = ReptileWalkingLeft.Left - ReptileSpeed.x
End With
ReptilePosition.left = ReptileWalkingLeft.Left
ReptilePosition.top = ReptileWalkingLeft.Top
ElseIf ReptileMovement = PlayerMovement.WalkingRight Then
ReptileDucking.Visible = False
ReptileJumping.Visible = False
ReptileStanding.Visible = False
ReptileWalkingLeft.Visible = False
With ReptileWalkingRight
.Left = ReptilePosition.left
.Top = ReptilePosition.top
.Visible = True
.Left = ReptileWalkingRight.Left + ReptileSpeed.x
End With
ReptilePosition.left = ReptileWalkingRight.Left
ReptilePosition.top = ReptileWalkingRight.Top
Else
ReptileDucking.Visible = False
ReptileJumping.Visible = False
ReptileWalkingLeft.Visible = False
ReptileWalkingRight.Visible = False
With ReptileStanding
.Left = ReptilePosition.left
.Top = ReptilePosition.top
.Visible = True
End With
End If
End Sub

Private Sub ArmoryBckGnd_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
'When the key lets up then stop moving
CageMovement = PlayerMovement.Standing
ReptileMovement = PlayerMovement.Standing
End Sub

Private Sub ArmoryBckGnd_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
End
End Sub

Private Sub ArmoryBckGnd_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
'store initial position
CagePosition.left = CageStanding.Left
CagePosition.top = CageStanding.Top
ReptilePosition.left = ReptileStanding.Left
ReptilePosition.top = ReptileStanding.Top
'setup speed values
CageSpeed.x = 3
ReptileSpeed.x = 3
'setup and activate timer
MainTimer.Interval = 25
MainTimer.Enabled = True
End Sub
End Class


I'd recommend that you look around for "class" (object-oriented topic) tutorial.
Because it will be much better if you make a base class for fighter, instead of coding for every one of them in the main form.

Bigpapa3xl
01-09-2005, 09:19 AM
I'd recommend that you look around for "class" (object-oriented topic) tutorial.
Because it will be much better if you make a base class for fighter, instead of coding for every one of them in the main form.


Thank you so much. :) I wasn't expecting some on to recode the whole thing. :) You are so great! Everything is working fine and runs smoother then it ever has! Thank you so much!.

I hope i can decipher the code and add jumping and ducking, and eventually fighting moves, etc. :) Then finally add collision. Oh fun! ;)

I've dipped into the 'class' thing only a little. From what i know it would be a great improvement, but i will definitely need to read up on it a lot!

Thanks again to all for the great help! :D

BP

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum