7 Replies - 3990 Views - Last Post: 22 February 2011 - 09:30 PM Rate Topic: -----

#1 PandaFace  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-February 11

Basic space invaders game timer problem

Posted 19 February 2011 - 03:40 AM

hi all

im almost completely new at programming (I'm using vb 2010, though searching around on the internet everything seems to be .NET or vb6)
i'm trying to make a sort of space invaders-type game (i know vb isnt the language to use but i'm really just doing it to pass the time) and am having trouble getting the bot that you play as to "shoot"

i can get it to shoot once, then wait it out till it hits the aliens / goes out of bounds, but can not make it fire two bullets, one after the other.

i've written this much:
        ElseIf e.KeyChar = ChrW(Keys.Space) Then
 bullet = New PictureBox
            Me.Controls.Add(bullet)
            bullet.BringToFront()
            bullet.Width = 6
            bullet.Height = 20
            bullet.BackColor = Color.Red
            bullet.Visible = True
            bullet.Left = bot.Left
            bullet.Top = bot.Top


to create a new "bullet" each time space is pressed but the timer that controls the movement of the bullet freezes the first bullet as soon as the second is shot

here is what i've written under the "timer_tick" sub:
        If bullet.Left >= alien.Left - 5 And bullet.Left <= alien.Left + 39 And bullet.Top <= alien.Top + 40 Then
            Timer1.Enabled = False
            MsgBox("You Win!!!")
            bullet.Visible = False

            Timer1.Enabled = False
        ElseIf bullet.Top = 0 Then
            bullet.Visible = False
        Else
            bullet.Top = bullet.Top - 2
        End If


(line ten being where the movement happens)
i've tried creating a new timer_tick sub each time space is pressed but it doesn't work.
any help would be greatly appreciated

thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Basic space invaders game timer problem

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10784
  • View blog
  • Posts: 40,160
  • Joined: 27-December 08

Re: Basic space invaders game timer problem

Posted 19 February 2011 - 03:37 PM

VB2010 is VB.NET. Moved to VB.NET.
Was This Post Helpful? 1
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Basic space invaders game timer problem

Posted 19 February 2011 - 05:12 PM

Not 100% sure here but instead of
bullet.top = bullet.top -2

maybe you could use the control collection: Something like

For each blt as Control in Me.Controls 
 if TypeOf blt is PictureBox Then
   ctype(blt, picturebox).Top -= 2
 End If
Next


See if that at least gets both bullets moving and then we can look at removing them as they reach 0 which should work in the same For Each loop.

This is just off the top of my head but it SEEMS like it would work.
Was This Post Helpful? 1
  • +
  • -

#4 PandaFace  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-February 11

Re: Basic space invaders game timer problem

Posted 20 February 2011 - 12:39 AM

View PostCharlieMay, on 19 February 2011 - 05:12 PM, said:

Not 100% sure here but instead of
bullet.top = bullet.top -2

maybe you could use the control collection: Something like

For each blt as Control in Me.Controls 
 if TypeOf blt is PictureBox Then
   ctype(blt, picturebox).Top -= 2
 End If
Next


See if that at least gets both bullets moving and then we can look at removing them as they reach 0 which should work in the same For Each loop.

This is just off the top of my head but it SEEMS like it would work.


awesome!
changed it slightly(previously it moved every picture box (i'm using quite a few) to the top of the screen) and it worked perfectly

thnx! =)
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Basic space invaders game timer problem

Posted 20 February 2011 - 07:01 AM

LOL yea, I guess I probably should have made sure I was only dealing with the bullet pictureboxes. :D
Was This Post Helpful? 0
  • +
  • -

#6 PandaFace  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-February 11

Re: Basic space invaders game timer problem

Posted 20 February 2011 - 09:13 PM

thnx a lot

another prob has arisen,
i'm usin a the keypress event to move the "bot", but it doesn't seem to work for arrow keys, only the letter, number, and symbol ones
(a & d work, i'm using them currently)

any suggestions?
Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Basic space invaders game timer problem

Posted 21 February 2011 - 06:57 AM

You can do it in the KeyDown event (instead of keypress)

Select Case e.KeyCode  
  Case Keys.Left
    'Code to process for Left
  Case Keys.Right
    'Code to process for Right
End Select

Was This Post Helpful? 0
  • +
  • -

#8 PandaFace  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 19-February 11

Re: Basic space invaders game timer problem

Posted 22 February 2011 - 09:30 PM

wow thanks a lot
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1