|
-
May 20th, 2009, 04:02 PM
#1
Thread Starter
Member
[RESOLVED] Checking ".Left" of whole object [Space Invaders]
What I mean by "Checking ".left" of whole object" is making something happen if, for instance, a label were to hit an object. Instead of it needing to hit at the objects exact left, it could hit anywhere on the object.
Bit confusing...I know...here is an example...
I am currently making a space invaders game with vb.net 2003 as my final project for my computer programing class. I have been having so much trouble. I have the shot in a timer and when the space bar is hit, it enables this timer.
Code:
Select Case e.keycode
Case Keys.Space
If tmrShot.Enabled = False Then
tmrShot.Enabled = True'enable shot timer
lblShot.Location = imgShip.Location 'moves shot to ships location
lblShot.Left += 22 'moves shot over 22(to the right)
lblShot.Visible = True 'shows shot
End If
End Select
The above code is how I have it set up to enable the timer.
Then when the timer activates it should launch the shot from the ships location.
Here is the beginning part of my code in the timer.
Code:
If lblShot.Top = 12 Then
lblShot.Location = imgShip.Location
lblShot.Left += 22
tmrShot.Enabled = False
lblShot.Visible = False
Else
lblShot.Top -= 4
If lblShot.Visible = True Then
If lblShot.Top = imgR1.Top AndAlso lblShot.Left = imgR1.Left OrElse lblShot.Left = imgR1.Left + 14 OrElse lblShot.Left = imgR1.Left + 28 Then
imgR1.Hide()
lblShot.Visible = False
tmrShot.Enabled = False
lblScore.Text = Val(lblScore.Text) + 30
ElseIf lblShot.Top = imgR2.Top AndAlso lblShot.Left = imgR2.Left OrElse lblShot.Left = imgR2.Left + 14 OrElse lblShot.Left = imgR2.Left + 28 Then
imgR2.Hide()
lblShot.Visible = False
tmrShot.Enabled = False
lblScore.Text = Val(lblScore.Text) + 30
ElseIf lblShot.Top = imgR3.Top AndAlso lblShot.Left = imgR3.Left OrElse lblShot.Left = imgR3.Left + 14 OrElse lblShot.Left = imgR3.Left + 28 Then
imgR3.Hide()
lblShot.Visible = False
tmrShot.Enabled = False
lblScore.Text = Val(lblScore.Text) + 30
The Problem:Well first off, the first part of the check works, if the shot hits the left of any of the aliens it will hide it, disable the timer, add the score, and make the shot not visible. Here is the main problemThe other parts of the check where it is seeing if "lblShot" is equal to "imgR3.left + 14" or the same with plus 28, what will happen is that the if the shot is at the "+14" or "+28" mark, it will instantly jump up to the top red alien in that row and then hide only that one and no one else.
To sum it up:The shot will keep jumping to the top alien unless there it is on the objects exact left. I mainly need some way so the shot can hit anywhere on the alien and then do the code that it needs to.
Hope I made this clear enough, I was having some trouble thinking about how to describe my problem. So thanks for any help given, and ask questions if you need other information and I will try to post a reply ASAP. So thanks again
Last edited by Shadow45o; May 20th, 2009 at 04:51 PM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|