Jump to content
IGNORED

Missile trouble


Rabbit 2600

Recommended Posts

The missile will only move left if the joystick is held to the right and the fire button is held down at the same time. That's what's wrong with it.

 

You might want to look at this example program:

 

http://www.randomterrain.com/atari-2600-memories-batari-basic-commands.html#sprite_missile_example

Link to comment
Share on other sites

Yeah, the trouble was the missile not moving, I got it working now, haha. =)

 

Hm, I have yet another problem I've forgotten how to do properly. When the missile hits player1 I want it to get 1 of 4 positions chosen at random. And I've gotten that to work but, it instantly goes back to it's original position instead of staying in that position. Any ideas?

 

Source: Blast Zone.bas

 

The code in question:

  drawscreen

  if player1x < player0x then player1x = player1x + 1

  if player1x > player0x then player1x = player1x - 1

  if collision(missile0,player1) then player1x=255 : player1y=255 : missile0x = 255 : missile0y = 255 : a = (rand&3)

  if a = 0 then player1x=1:player1y=50
  if a = 1 then player1x=90:player1y=50
  if a = 2 then player1x=80:player1y=1
  if a = 3 then player1x=80:player1y=90

The entire code:

 rem Generated 2013-09-20 23:26:46 by Visual bB Version 1.0.0.554
 rem **********************************
 rem *<filename>                      *
 rem *<description>                   *
 rem *<author>                        *
 rem *<contact info>                  *
 rem *<license>                       *
 rem **********************************



   rem  ****************************************************************
   rem  *
   rem  *  Sprite with Missile
   rem  *
   rem  *  Example program by Duane Alan Hahn (Random Terrain) using
   rem  *  hints, tips, code snippets, and more from AtariAge members
   rem  *  such as batari, SeaGtGruff, RevEng, Robert M, Nukey Shay,
   rem  *  Atarius Maximus, jrok, supercat, GroovyBee, and bogax.
   rem  *
   rem  ****************************************************************
   rem  *
   rem  *  Instructions:
   rem  *  
   rem  *  Use the joystick to move the sprite. Press the fire button
   rem  *  to shoot the missile.
   rem  *
   rem  ****************************************************************



   rem  ****************************************************************
   rem  *
   rem  *  Create aliases for variables.
   rem  *
   rem  ****************************************************************
   rem  `
   rem  `  (You can have more than one alias for each variable.)
   rem  `
   rem  ````````````````````````````````````````````````````````````````

   rem  ````````````````````````````````````````````````````````````````
   rem  `  All-purpose bits for various jobs.
   rem  `
   dim _BitOp_All_Purpose_01 = t
   dim _Bit0_Debounce_Reset = t
   dim _Bit7_Missile0_Moving = t


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Player0/Missile0 direction bits.
   rem  `
   dim _BitOp_P0_M0_Direction = u
   dim _Bit0_Player0_Direction_Up = u
   dim _Bit1_Player0_Direction_Down = u
   dim _Bit2_Player0_Direction_Left = u
   dim _Bit3_Player0_Direction_Right = u
   dim _Bit4_Missile0_Direction_Up = u
   dim _Bit5_Missile0_Direction_Down = u
   dim _Bit6_Missile0_Direction_Left = u
   dim _Bit7_Missile0_Direction_Right = u




   rem  ****************************************************************
   rem  *
   rem  *  Defines the edges of the playfield for an 8 x 8 sprite.
   rem  *  If your sprite is a different size, you`ll need to adjust
   rem  *  the numbers.
   rem  `
   def _P_Edge_Left=1
   def _P_Edge_Right=153
   def _P_Edge_Top=9
   def _P_Edge_Bottom=88




   rem  ****************************************************************
   rem  *
   rem  *  Defines the edges of the playfield for the missile.
   rem  *  If the missile is a different size, you`ll need to adjust
   rem  *  the numbers.
   rem  `
   def _M_Edge_Left=2
   def _M_Edge_Right=158
   def _M_Edge_Top=2
   def _M_Edge_Bottom=87



   rem  ****************************************************************
   rem  ****************************************************************
   rem  *
   rem  *  Program Start/Restart
   rem  *
   rem  `
__Start_Restart


   rem  ****************************************************************
   rem  *
   rem  *  Mute volume of both sound channels.
   rem  `
   AUDV0 = 0 : AUDV1 = 0



   rem  ****************************************************************
   rem  *
   rem  *  Clears all normal variables.
   rem  `
   for temp5 = 0 to 25 : a[temp5] = 0 : next



   rem  ****************************************************************
   rem  *
   rem  *  Starting position of Player0.
   rem  `
   player0x = 77 : player0y = 53



   rem  ****************************************************************
   rem  *
   rem  *  Makes sure Missile0 is off the screen.
   rem  `
   missile0x = 200 : missile0y = 200



   rem  ****************************************************************
   rem  *
   rem  *  Defines Missile0 size.
   rem  `
   NUSIZ0 = $10 : missile0height = 1




   rem  ****************************************************************
   rem  *
   rem  *  Sets beginning direction that Missile0 will shoot if the
   rem  *  player doesn`t move.
   rem  `
   _Bit3_Player0_Direction_Right{3} = 1



   rem  ****************************************************************
   rem  *
   rem  *  Debounce the reset switch. (Holding it down won`t make it 
   rem  *  keep resetting.)
   rem  `
   _Bit0_Debounce_Reset{0} = 1












 player0x = 70
 player0y = 50

 player1x = 1
 player1y = 50

MAIN_LOOP

 a = 0


 COLUP0 = $2A

 COLUP1 = $2A

 if joy0down then player0:
        %01100110
        %11000011
        %10011001
        %10100101
        %10100101
        %10011001
        %11000011
        %01111110
end

 if joy0up then player0:
        %01111110
        %11000011
        %10011001
        %10100101
        %10100101
        %10011001
        %11000011
        %01100110
end

  if joy0left then player0:
        %01111110
        %11000011
        %10011001
        %00100101
        %00100101
        %10011001
        %11000011
        %01111110
end

  if joy0right then player0:
        %01111110
        %11000011
        %10011001
        %10100100
        %10100100
        %10011001
        %11000011
        %01111110
end






  f=f+1
  rem POSSIBLY INEFFICIENT CODE, SEPARATE COLOR INFO FOR EACH FRAME...
  if f = 10 then player1:
        %01111110
        %11000011
        %10000001
        %01100000
        %01100000
        %10000001
        %11000011
        %01111110
end

  if f = 20 then player1:
        %01111110
        %11000011
        %10000001
        %00110000
        %00110000
        %10000001
        %11000011
        %01111110
end

  if f = 30 then player1:
        %01111110
        %11000011
        %10000001
        %00011000
        %00011000
        %10000001
        %11000011
        %01111110
end

  if f = 40 then player1:
        %01111110
        %11000011
        %10000001
        %00001100
        %00001100
        %10000001
        %11000011
        %01111110
end

  if f = 50 then player1:
        %01111110
        %11000011
        %10000001
        %00000110
        %00000110
        %10000001
        %11000011
        %01111110
end


  if f = 60 then player1:
        %01111110
        %11000011
        %10000001
        %01000010
        %01000010
        %10000001
        %11000011
        %01111110
end


  if f=60 then f=0


















   rem  ****************************************************************
   rem  *
   rem  *  Joystick movement precheck.
   rem  *
   rem  ````````````````````````````````````````````````````````````````
   rem  `  If joystick isn`t moved in any direction, skip this section.
   rem  `
   if !joy0up && !joy0down && !joy0left && !joy0right then goto __Skip_Joystick_Precheck


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Joy0 has been moved. Clear Player0 direction bits.
   rem  `
   _BitOp_P0_M0_Direction = _BitOp_P0_M0_Direction & %11110000


__Skip_Joystick_Precheck




   rem  ****************************************************************
   rem  *
   rem  *  Joy0 Up
   rem  *
   rem  ````````````````````````````````````````````````````````````````
   rem  `  If joystick isn`t moved up, skip this section.
   rem  `
   if !joy0up then goto __Skip_Joy0_Up


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Turn on the up direction bit.
   rem  `
   _Bit0_Player0_Direction_Up{0} = 1


   rem  ````````````````````````````````````````````````````````````````
   rem  `  If hitting the edge, skip this section.
   rem  `
   if player0y <= _P_Edge_Top then goto __Skip_Joy0_Up


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Move Player0 up.
   rem  `



__Skip_Joy0_Up





   rem  ****************************************************************
   rem  *
   rem  *  Joy0 Down
   rem  *
   rem  ````````````````````````````````````````````````````````````````
   rem  `  If joystick isn`t moved down, skip this section.
   rem  `
   if !joy0down then goto __Skip_Joy0_Down


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Turn on the down direction bit.
   rem  `
   _Bit1_Player0_Direction_Down{1} = 1


   rem  ````````````````````````````````````````````````````````````````
   rem  `  If hitting the edge, skip this section.
   rem  `
   if player0y >= _P_Edge_Bottom then goto __Skip_Joy0_Down


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Move Player0 down.
   rem  `



__Skip_Joy0_Down





   rem  ****************************************************************
   rem  *
   rem  *  Joy0 Left
   rem  *
   rem  ````````````````````````````````````````````````````````````````
   rem  `  If joystick isn`t moved to the left, skip this section.
   rem  `
   if !joy0left then goto __Skip_Joy0_Left


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Turn on the left direction bit.
   rem  `
   _Bit2_Player0_Direction_Left{2} = 1


   rem  ````````````````````````````````````````````````````````````````
   rem  `  If hitting the edge, skip this section.
   rem  `
   if player0x <= _P_Edge_Left then goto __Skip_Joy0_Left


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Move Player0 to the left.
   rem  `



__Skip_Joy0_Left





   rem  ****************************************************************
   rem  *
   rem  *  Joy0 Right
   rem  *
   rem  ````````````````````````````````````````````````````````````````
   rem  `  If joystick isn`t moved to the right, skip this section.
   rem  `
   if !joy0right then goto __Skip_Joy0_Right


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Turn on the right direction bit.
   rem  `
   _Bit3_Player0_Direction_Right{3} = 1


   rem  ````````````````````````````````````````````````````````````````
   rem  `  If hitting the edge, skip this section.
   rem  `
   if player0x >= _P_Edge_Right then goto __Skip_Joy0_Right


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Move Player0 to the right.
   rem  `


__Skip_Joy0_Right




   rem  ****************************************************************
   rem  *
   rem  *  Fire Button:
   rem  *
   rem  *  If fire button is pressed and Missile0 is not moving, turn
   rem  *  on Missile0 movement.
   rem  *
   rem  ````````````````````````````````````````````````````````````````
   rem  `  If the fire button is not pressed, skip this section.
   rem  `
   if !joy0fire then goto __Skip_Fire


   rem  ````````````````````````````````````````````````````````````````
   rem  `  If Missile0 is moving, skip this section.
   rem  `
   if _Bit7_Missile0_Moving{7} then goto __Skip_Fire


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Turn on Missile0 movement.
   rem  `
   _Bit7_Missile0_Moving{7} = 1


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Set up starting position of Missile0.
   rem  `
   missile0y = player0y - 4 : missile0x = player0x + 4


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Take a `snapshot` of Player0 direction so Missile0 will
   rem  `  stay on track until it hits something.
   rem  `
   _Bit4_Missile0_Direction_Up{4} = _Bit0_Player0_Direction_Up{0}
   _Bit5_Missile0_Direction_Down{5} = _Bit1_Player0_Direction_Down{1}
   _Bit6_Missile0_Direction_Left{6} = _Bit2_Player0_Direction_Left{2}
   _Bit7_Missile0_Direction_Right{7} = _Bit3_Player0_Direction_Right{3}


__Skip_Fire




   rem  ****************************************************************
   rem  *
   rem  *  Move Missile0.
   rem  *
   rem  ````````````````````````````````````````````````````````````````
   rem  `  If Missile0 isn`t moving, skip this section.
   rem  `
   if !_Bit7_Missile0_Moving{7} then goto __Skip_Missile


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Move Missile0 in the appropriate direction.
   rem  `
   if _Bit4_Missile0_Direction_Up{4} then missile0y = missile0y - 2
   if _Bit5_Missile0_Direction_Down{5} then missile0y = missile0y + 2
   if _Bit6_Missile0_Direction_Left{6} then missile0x = missile0x - 2
   if _Bit7_Missile0_Direction_Right{7} then missile0x = missile0x + 2


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Clear Missile0 if it hits the edge of the screen.
   rem  `
   if missile0x < _M_Edge_Left then goto __Skip_to_Clear_Missile
   if missile0x > _M_Edge_Right then goto __Skip_to_Clear_Missile
   if missile0y < _M_Edge_Top then goto __Skip_to_Clear_Missile
   if missile0y > _M_Edge_Bottom then goto __Skip_to_Clear_Missile


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Clear Missile0 if it hits a playfield pixel.
   rem  `
   if collision(playfield,missile0) then goto __Skip_to_Clear_Missile


   goto __Skip_Missile


__Skip_to_Clear_Missile


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Clear Missile0 moving bit and move Missile0 off the screen.
   rem  `
   _Bit7_Missile0_Moving{7} = 0


   missile0x = 200 : missile0y = 200


__Skip_Missile


 drawscreen

 if player1x < player0x then player1x = player1x + 1

 if player1x > player0x then player1x = player1x - 1

 if collision(missile0,player1) then player1x=255 : player1y=255 : missile0x = 255 : missile0y = 255 : a = (rand&3)

 if a = 0 then player1x=1:player1y=50
 if a = 1 then player1x=90:player1y=50
 if a = 2 then player1x=80:player1y=1
 if a = 3 then player1x=80:player1y=90



   rem  ****************************************************************
   rem  *
   rem  *  Reset Program:
   rem  *
   rem  *  Any Atari 2600 program should restart when the reset switch  
   rem  *  is pressed. It is part of the usual standards and procedures.
   rem  *
   rem  ````````````````````````````````````````````````````````````````
   rem  `  If the reset switch is not pressed, turn off debounce and
   rem  `  skip this section.
   rem  `
   if !switchreset then _Bit0_Debounce_Reset{0} = 0 : goto __Skip_Main_Reset


   rem  ````````````````````````````````````````````````````````````````
   rem  `  If the reset switch hasn`t been released, skip this section.
   rem  `
   if _Bit0_Debounce_Reset{0} then goto __Skip_Main_Reset


   rem  ````````````````````````````````````````````````````````````````
   rem  `  Restart the program.
   rem  `
   goto __Start_Restart


__Skip_Main_Reset





 goto MAIN_LOOP
Edited by Rabbit 2600
Link to comment
Share on other sites

You always set player1 according to a regardless of whether there's a collision.

 

If there is a collision, you don't need to set player1x,y to 255 because you're

going to set it according to a immediately anyway.

 

Setting player1 with look up table indexed by a would probably be shorter and faster.

 

something like this maybe

if collision(missile0,player1) then a = rand & 3 : player1x=p1x[a] : player1y=p1y[a] : missile0x = 255 : missile0y = 255

data p1x
1, 90, 80, 80
end

data p1y
50, 50, 1, 90
end
Edited by bogax
Link to comment
Share on other sites

Interesting, that seems a bit more efficient. Thank you =)

 

Hm, I'm making small progress towards player1 moving towards player0. I managed to get it moving once. Then it stopped working, strange, but I think I'll find the solution soon.

 

Did you try that collision code?

 

(it moves in the x direction but not the y direction)

 

(not surprising because you're not moving it in the

y direction)

Edited by bogax
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...