Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 132,112 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,081 people online right now. Registration is fast and FREE... Join Now!




Space invaders game

 
Reply to this topicStart new topic

Space invaders game, moving an image

somy360
post 10 Oct, 2008 - 02:35 AM
Post #1


New D.I.C Head

*
Joined: 18 Sep, 2008
Posts: 4

I am trying to make a space invaders game, I am currently trying to make an image move back and forth across the screen.

CODE

'Moves invaders back and forth across the screen
Dim X As Integer
Dim left_side As Integer
Dim right_side As Integer
X = 50
Imginvader1.Left = Imginvader1.Left + X
left_side = Imginvader1.Left
right_side = Imginvader1.Left + Imginvader1.Width
If left_side < ScaleLeft Then
X = -X
End If
If right_side > ScaleWidth Then
X = -X
End If


the image continues in the same direction when it reaches the edge of the form. Any help would be greatly appreciated.
User is offlineProfile CardPM

Go to the top of the page

Reverand Dave
post 10 Oct, 2008 - 08:37 AM
Post #2


D.I.C Regular

Group Icon
Joined: 27 Jul, 2008
Posts: 373



Thanked 2 times

Dream Kudos: 50
My Contributions


are you doing this inside a picturebox control?
User is offlineProfile CardPM

Go to the top of the page

somy360
post 10 Oct, 2008 - 09:48 AM
Post #3


New D.I.C Head

*
Joined: 18 Sep, 2008
Posts: 4

QUOTE(somy360 @ 10 Oct, 2008 - 03:35 AM) *

I am trying to make a space invaders game, I am currently trying to make an image move back and forth across the screen.

CODE

'Moves invaders back and forth across the screen
Dim X As Integer
Dim left_side As Integer
Dim right_side As Integer
X = 50
Imginvader1.Left = Imginvader1.Left + X
left_side = Imginvader1.Left
right_side = Imginvader1.Left + Imginvader1.Width
If left_side < ScaleLeft Then
X = -X
End If
If right_side > ScaleWidth Then
X = -X
End If


the image continues in the same direction when it reaches the edge of the form. Any help would be greatly appreciated.


No I'm not.
User is offlineProfile CardPM

Go to the top of the page

thava
post 11 Oct, 2008 - 02:42 AM
Post #4


D.I.C Regular

Group Icon
Joined: 17 Apr, 2007
Posts: 424



Thanked 17 times

Dream Kudos: 50
My Contributions


when ever the procedure calls
X= 50 is invoked and your code
x = -x
is just like a dummy that's why not work well and more over
change the condition like this

If left_side > ScaleLeft Then

left side will be always greater than the scale left when it lies in the form
If right_side < ScaleWidth Then

right_side will be always Lessr than the scalewidth when it lies in the form

hope you clear now
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/21/08 10:05AM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month