locked
Hit Detection RRS feed

  • Question

  • I am making Space Invaders.

    I made the missile animated.

    Is there way for me to hide the invader when the missile passes through it?

    I read somewhere that I wouldn't be able to do it because the missile is animated.

    XVL216 (Game)

    If it is impossible how would I make the missile move when I press space and say 1 missile is launched for every 2 seconds the space bar is held down.
    • Edited by Dinomite07 Tuesday, November 11, 2014 6:51 PM
    Tuesday, November 11, 2014 6:19 PM

Answers

All replies

  • While the animated missile moves the position at each moment is unknown, so it is not possible to do something based on position.

    Jan [ WhTurner ] The Netherlands

    • Marked as answer by Dinomite07 Tuesday, November 11, 2014 8:33 PM
    Tuesday, November 11, 2014 6:50 PM
    Answerer
  • KBD125

    I have no idea on how to make a missile move.

    I got the ship. Made an array of missiles.

    Trying to figure out how to make it so when space is held down every 2 seconds a missile comes out and goes across the screen till it disappears. You have a max of 20 missiles on the screen and missiles are reused.


    • Edited by Dinomite07 Tuesday, November 11, 2014 8:10 PM
    Tuesday, November 11, 2014 8:09 PM
    • Marked as answer by Dinomite07 Tuesday, November 11, 2014 8:33 PM
    Tuesday, November 11, 2014 8:15 PM
  • FDL612

    Is it possible to have two while statements?

    I can't figure out what is wrong.








    • Edited by Dinomite07 Wednesday, November 12, 2014 3:28 AM
    Tuesday, November 11, 2014 8:52 PM
  • Have you read my reply at your old thread already?

    https://social.msdn.microsoft.com/Forums/en-US/3113bf7b-d5b3-42f3-af4f-acb576a7a04f/missile


    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Wednesday, November 12, 2014 2:25 AM
    Answerer
  • Yes, but the tutorial code is not choppy and I kinda figured out the how creator did it.

    Code is working fine. Just freezes when I try to shoot.


    LJB257

    • Edited by Dinomite07 Wednesday, November 12, 2014 4:54 AM
    Wednesday, November 12, 2014 2:58 AM
  • KBD125

    I have no idea on how to make a missile move.

    I got the ship. Made an array of missiles.

    Trying to figure out how to make it so when space is held down every 2 seconds a missile comes out and goes across the screen till it disappears. You have a max of 20 missiles on the screen and missiles are reused.


    How about this ?  in this case, if you press space key over 500msec , missile is launched. 

    GraphicsWindow.KeyDown = OnKeyDown
    GraphicsWindow.KeyUp=OnkeyUp
    OnKeyUp()
    gw = 700
    gh = 500
    GraphicsWindow.Width = gw
    GraphicsWindow.Height = gh
    GraphicsWindow.DrawImage("http://i58.tinypic.com/t66qeg.png",0,0) '  Black??
    Speed="X=Left\=-3\;Right\=3\;Down\=0\;Up\=0\;Space\=0;Y=Left\=0\;Right\=0\;Down\=3\;Up\=-3\;Space\=0;" ' player's  speed
    player = Shapes.AddImage("http://i57.tinypic.com/1e7xtz.png")
    Shapes.Move(player,250,200)
    '  Missile
    delay=10                         '  program.delay  time  10 msec
    disappear=2000                   '  disappear time     2000 msec  
    Mis_speed=gh/(disappear/delay)   '  speed= 500/(2000/10) = 2.5 dots
    MissileNMB=20
    Launchtime=500                    ' If space key is held over 500msec, missile is launched
    For i=1 to MissileNMB
      missile[i] = Shapes.AddImage("http://i61.tinypic.com/vxn1xy.png")
      Shapes.Move(missile[i] ,100,-100)  '  Y=-100   to hide
    endfor

    While ("True")
      If TF="True" Then
        pasttime=Clock.ElapsedMilliseconds-t0
        GraphicsWindow.Title=NN+" Space " +(pasttime)
        If pasttime>=Launchtime then    '  space key is held over 500msec
          MM=MM+1
          Shapes.Move(missile[MM],playerX + 15,playerY - 20)  '  missile is set
          If MM=MissileNMB Then
            MM=0
          EndIf
         OnKeyUp()   
      EndIf
      EndIf
      Player_Missile_Move()
      Program.Delay(delay)
    EndWhile

    Sub OnKeyDown
      lastKey = GraphicsWindow.LastKey
      If (lastKey = "Space") Then
        NN=NN+1
        If NN=1 Then
          t0=clock.ElapsedMilliseconds
        EndIf
        TF="True"
      EndIf
    EndSub

    Sub Player_Missile_Move
      Shapes.Move(player,Shapes.GetLeft(player)+Speed["X"][Lastkey],Shapes.GetTop(player)+Speed["Y"][Lastkey]) ' player moved
      playerX = Shapes.GetLeft(player)             '  Player's new position -X
      playerY= Shapes.GetTop(player)               '  Player's new position -Y 
      If (playerX<-50  Or gw+50<playerX) Then
        shapes.Move(player,(gw-playerx),playerY)   '  player warps  X-direction
      ElseIf (playerY<-50 Or gh+50<playery) Then
        shapes.Move(player,playerX,(gh-playerY))   '  player warps  Y-direction
      EndIf
      For i=1 To MissileNMB
        Shapes.Move(missile[i],Shapes.GetLeft(missile[i]),Shapes.GetTop(missile[i])-Mis_speed) ' missile moved
      EndFor
      Speed="X=Left\=-3\;Right\=3\;Down\=0\;Up\=0\;Space\="+Speed["X"][Lastkey] +";Y=Left\=0\;Right\=0\;Down\=3\;Up\=-3\;Space\="+Speed["Y"][Lastkey] '
    EndSub

    Sub OnKeyUp
      TF="False"
      NN=0
    EndSub  


    Wednesday, November 12, 2014 4:46 AM
    Answerer