How to keep an object(character) from moving
How to keep an object(character) from moving
How to keep an object(character) from moving
How to keep an object(character) from moving
How to keep an object(character) from moving
How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving
How to keep an object(character) from moving How to keep an object(character) from moving
How to keep an object(character) from moving
Go Back  Xtreme Visual Basic Talk > > > How to keep an object(character) from moving


Reply
 
Thread Tools Display Modes
  #1  
Old 05-31-2011, 07:13 PM
m4xic4n93 m4xic4n93 is offline
Newcomer
 
Join Date: May 2011
Posts: 1
Exclamation How to keep an object(character) from moving


Hey im a pretty new VB programmer I am programming a simple airplane game sort of like space invaders. I got a missile to fire and move, now i need for it to hit a target and for the missile to stay there and not move even if the user keeps pressing the key. here is my code:


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

If (Image2(0).Left = 9360 Or 9720) And (Image2(0).Top = 2880) Then
Image3.Visible = False
Explosion1.Visible = True
Else
Image3.Visible = True
Explosion1.Visible = False
End If











If KeyCode = Int(vbKeyLeft) Then
 Image1.Left = Image1.Left - 100
 Image2(0).Left = Image2(0).Left - 100
 Image2(1).Left = Image2(1).Left - 100
 Image2(2).Left = Image2(2).Left - 100
 Image2(3).Left = Image2(3).Left - 100
 Image2(4).Left = Image2(4).Left - 100
 Image2(5).Left = Image2(5).Left - 100
 Image2(6).Left = Image2(6).Left - 100
 Image2(7).Left = Image2(7).Left - 100
 Image2(8).Left = Image2(8).Left - 100
 Image2(9).Left = Image2(9).Left - 100
ElseIf KeyCode = Int(vbKeyRight) Then
 Image1.Left = Image1.Left + 100
 Image2(0).Left = Image2(0).Left + 100
 Image2(1).Left = Image2(1).Left + 100
 Image2(2).Left = Image2(2).Left + 100
 Image2(3).Left = Image2(3).Left + 100
 Image2(4).Left = Image2(4).Left + 100
 Image2(5).Left = Image2(5).Left + 100
 Image2(6).Left = Image2(6).Left + 100
 Image2(7).Left = Image2(7).Left + 100
 Image2(8).Left = Image2(8).Left + 100
 Image2(9).Left = Image2(9).Left + 100
ElseIf KeyCode = Int(vbKeyUp) Then
 Image1.Top = Image1.Top - 100
 Image2(0).Top = Image2(0).Top - 100
 Image2(1).Top = Image2(1).Top - 100
 Image2(2).Top = Image2(2).Top - 100
 Image2(3).Top = Image2(3).Top - 100
 Image2(4).Top = Image2(4).Top - 100
 Image2(5).Top = Image2(5).Top - 100
 Image2(6).Top = Image2(6).Top - 100
 Image2(7).Top = Image2(7).Top - 100
 Image2(8).Top = Image2(8).Top - 100
 Image2(9).Top = Image2(9).Top - 100
ElseIf KeyCode = Int(vbKeyDown) Then
 Image1.Top = Image1.Top + 100
 Image2(0).Top = Image2(0).Top + 100
 Image2(1).Top = Image2(1).Top + 100
 Image2(2).Top = Image2(2).Top + 100
 Image2(3).Top = Image2(3).Top + 100
 Image2(4).Top = Image2(4).Top + 100
 Image2(5).Top = Image2(5).Top + 100
 Image2(6).Top = Image2(6).Top + 100
 Image2(7).Top = Image2(7).Top + 100
 Image2(8).Top = Image2(8).Top + 100
 Image2(9).Top = Image2(9).Top + 100
End If

If KeyCode = Int(vbKeyA) Then
Image2(0).Top = Image2(0).Top - 100
Image2(0).Visible = True
End If

If KeyCode = Int(vbKeyS) Then
Image2(1).Top = Image2(1).Top - 100
Image2(1).Visible = True
End If

If KeyCode = Int(vbKeyD) Then
Image2(2).Top = Image2(2).Top - 100
Image2(2).Visible = True
End If

If KeyCode = Int(vbKeyF) Then
Image2(3).Top = Image2(3).Top - 100
Image2(3).Visible = True
End If

If KeyCode = Int(vbKeyG) Then
Image2(4).Top = Image2(4).Top - 100
Image2(4).Visible = True
End If

If KeyCode = Int(vbKeyH) Then
Image2(5).Top = Image2(5).Top - 100
Image2(5).Visible = True
End If

If KeyCode = Int(vbKeyJ) Then
Image2(6).Top = Image2(6).Top - 100
Image2(6).Visible = True
End If

If KeyCode = Int(vbKeyK) Then
Image2(7).Top = Image2(7).Top - 100
Image2(7).Visible = True
End If

If KeyCode = Int(vbKeyL) Then
Image2(8).Top = Image2(8).Top - 100
Image2(8).Visible = True
End If

If KeyCode = Int(vbKeyP) Then
Image2(9).Top = Image2(9).Top - 100
Image2(9).Visible = True
End If

Last edited by Flyguy; 06-01-2011 at 02:12 AM. Reason: Added [code][/code] tags
Reply With Quote
  #2  
Old 05-31-2011, 08:46 PM
AtmaWeapon's Avatar
AtmaWeaponHow to keep an object(character) from moving AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Are you sure you're using VB .NET? That looks like VB6 to me.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 06-01-2011, 02:13 AM
Flyguy's Avatar
FlyguyHow to keep an object(character) from moving Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 19,165
Default

This is indeed VB6, moved it to the VB6 forum.

The following line will not do what you expect it to do
Code:
If (Image2(0).Left = 9360 Or 9720) Then
It should be write like:
Code:
If (Image2(0).Left = 9360 Or Image2(0).Left = 9720) Then
The following lines can be simplified:
Code:
 Image2(0).Left = Image2(0).Left + 100
 Image2(1).Left = Image2(1).Left + 100
 Image2(2).Left = Image2(2).Left + 100
 Image2(3).Left = Image2(3).Left + 100
 Image2(4).Left = Image2(4).Left + 100
 Image2(5).Left = Image2(5).Left + 100
 Image2(6).Left = Image2(6).Left + 100
 Image2(7).Left = Image2(7).Left + 100
 Image2(8).Left = Image2(8).Left + 100
 Image2(9).Left = Image2(9).Left + 100
Code:
Dim i As Integer

For i = 0 To 9
 Image2(i).Left = Image2(i).Left + 100
Next i
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
How to keep an object(character) from moving
How to keep an object(character) from moving
How to keep an object(character) from moving How to keep an object(character) from moving
How to keep an object(character) from moving
How to keep an object(character) from moving
How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving How to keep an object(character) from moving
How to keep an object(character) from moving
How to keep an object(character) from moving
 
How to keep an object(character) from moving
How to keep an object(character) from moving
 
-->