Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB Expert!

Join 244,309 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 867 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
10 Oct, 2008 - 02:35 AM
Post #1

New D.I.C Head
*

Joined: 18 Sep, 2008
Posts: 6

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
+Quote Post


Reverand Dave
RE: Space Invaders Game
10 Oct, 2008 - 08:37 AM
Post #2

D.I.C Regular
Group Icon

Joined: 27 Jul, 2008
Posts: 375



Thanked: 2 times
Dream Kudos: 50
My Contributions
are you doing this inside a picturebox control?
User is offlineProfile CardPM
+Quote Post

somy360
RE: Space Invaders Game
10 Oct, 2008 - 09:48 AM
Post #3

New D.I.C Head
*

Joined: 18 Sep, 2008
Posts: 6

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
+Quote Post

thava
RE: Space Invaders Game
11 Oct, 2008 - 02:42 AM
Post #4

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 670



Thanked: 35 times
Dream Kudos: 75
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
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 07:16PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month