Hey everybody
I am a student who is a beginner in programming and has no real experience in this field of area. I need urgent help regarding some coding for the alien(s).
We were given an assignment to devise a simple space invaders game on windows application Visual Basic. I have reached the stage of programming the alien to move from left to right, down diagonal, bounce off the wall towards left and move left stationary (0). However, now for some reason I cannot figure out how to make the alien travel, after typing this code, ' If Xpos.Text < 20 And Ypos.Text > 150 Then RightAdd.Text = 20 ' The alien shuffles from 0 to 20 for an infinite amount of time... it doesn't move the full length! In this case from x=21 to 480.... I mean shouldn't it be simple, if X reaches (a) and Y reaches (b) just Move right 20....why is it just moving between 0 - 20 really fast... ):
Here is my code for the first alien;
'Alien.Location = New Point(Xpos.Text, Ypos.Text)
Xpos.Text = Xpos.Text + Int(RightAdd.Text)
Ypos.Text = Ypos.Text + Int(DownAdd.Text)
If Xpos.Text < 10 Then RightAdd.Text = 20
If Xpos.Text > 480 Then DownAdd.Text = 5
If Ypos.Text > 150 Then DownAdd.Text = 0
If Ypos.Text > 130 Then RightAdd.Text = -20
------------------------------------- 'Up to hear everything is fine
If Xpos.Text < 20 And Ypos.Text > 150 Then RightAdd.Text = 20'
IN OTHER WORDS, if x = a and Y = b then move right 20 >>>>>
Is there something wrong with the code above?
Hope somebody could help or give me some advise....
Kind Regards
2 replies to this topic
#1
Posted 14 March 2011 - 03:50 PM
|
|
|
#2
Posted 15 March 2011 - 07:52 PM
Why are you using text fields for variables? (I'm assuming that's what they are, since you're referencing the .Text property.)
Trying to add an Int to a String (the datatype in a .Text property) isn't going to give you the results you want. Try declaring some Int variables to store your values for the alien positions.
Trying to add an Int to a String (the datatype in a .Text property) isn't going to give you the results you want. Try declaring some Int variables to store your values for the alien positions.
#3
Posted 23 March 2011 - 05:23 AM
Hey I solved the issue by adding this code:
If Xpos.Text > 700 Then Ypos.Text = Ypos.Text + 50
If Xpos.Text > 700 Then RightAdd.Text = -20
If Xpos.Text < 10 Then Ypos.Text = Ypos.Text + 50
If Xpos.Text < 10 Then RightAdd.Text = 20
--------------
But now I need help with the bullet, How do I make the spaceships bullet respawn contionously as I fire or press space????
My current code for the bulletimer is;
If bullet.Location.Y < 60 Then FireTimer.Enabled = False
If bullet.Location.Y > 0 Then FireTimer.Enabled = True
bullet.Location = New Point(bullet.Location.X, bullet.Location.Y - 70)
bullet.Visible = True
If bullet.Location.X > Alien1.Location.X And bullet.Location.X <= Alien1.Location.X + 100 Then Alien1.Visible = False
If bullet.Location.X > Alien2.Location.X And bullet.Location.X <= Alien2.Location.X + 100 Then Alien2.Visible = False
If bullet.Location.X > Alien3.Location.X And bullet.Location.X <= Alien3.Location.X + 100 Then Alien3.Visible = False
If bullet.Location.X > Alien4.Location.X And bullet.Location.X <= Alien4.Location.X + 100 Then Alien4.Visible = False
------
Basically when I fire first, you see the yellow bullet/missile hit the alien and make it dissapear, probem is, after the first bullet, the other bullets aren't visible (black) but the aliens still die or dissapear.
Thanks
If Xpos.Text > 700 Then Ypos.Text = Ypos.Text + 50
If Xpos.Text > 700 Then RightAdd.Text = -20
If Xpos.Text < 10 Then Ypos.Text = Ypos.Text + 50
If Xpos.Text < 10 Then RightAdd.Text = 20
--------------
But now I need help with the bullet, How do I make the spaceships bullet respawn contionously as I fire or press space????
My current code for the bulletimer is;
If bullet.Location.Y < 60 Then FireTimer.Enabled = False
If bullet.Location.Y > 0 Then FireTimer.Enabled = True
bullet.Location = New Point(bullet.Location.X, bullet.Location.Y - 70)
bullet.Visible = True
If bullet.Location.X > Alien1.Location.X And bullet.Location.X <= Alien1.Location.X + 100 Then Alien1.Visible = False
If bullet.Location.X > Alien2.Location.X And bullet.Location.X <= Alien2.Location.X + 100 Then Alien2.Visible = False
If bullet.Location.X > Alien3.Location.X And bullet.Location.X <= Alien3.Location.X + 100 Then Alien3.Visible = False
If bullet.Location.X > Alien4.Location.X And bullet.Location.X <= Alien4.Location.X + 100 Then Alien4.Visible = False
------
Basically when I fire first, you see the yellow bullet/missile hit the alien and make it dissapear, probem is, after the first bullet, the other bullets aren't visible (black) but the aliens still die or dissapear.
Thanks
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









