Jump to content
IGNORED

projectile problem


Rabbit 2600

Recommended Posts

I'm having a hard time again with projectiles. I've set the ball up as the projectile, and it resides at the tip of player1's gun. So far so good. But when I press joy0up I want it to be shot, but I can't get it to work properly. It moves away 1 pixel and then resets. Any ideas?

 

The shooting code:

 if !BitOp_Flip_P1{4} then ballx = player1x : bally = player1y - 18 else ballx = player1x + 9 : bally = player1y - 18

  if !BitOp_Flip_P1{4} && joy0up then ballx = ballx - 1

Program: Metroid.bas

 

Link to comment
Share on other sites

Hm, I see. Well, I managed to get the player to be able to shoot both left and right now. But, when the player changes direction so does the shot, how do I prevent this?

 if !BitOp_Flip_P1{4} then ballx = ballx - 1 else ballx = ballx + 1

   drawscreen

 if collision(ball,playfield) then ballx = 255 : bally = 255

 if joy0up then ballx=player1x : bally = player1y

Complete source:

   rem  ****************************************************************
   rem  ****************************************************************
   rem  *
   rem  *  Fake Gravity Platformer Test
   rem  *
   rem  *  By Duane Alan Hahn (Random Terrain) using hints, tips,
   rem  *  code snippets, and more from AtariAge members such as
   rem  *  batari, SeaGtGruff, RevEng, Robert M, Atarius Maximus,
   rem  *  jrok, Nukey Shay, supercat, and GroovyBee.
   rem  *
   rem  ****************************************************************
   rem  ****************************************************************

   set kernel_options player1colors no_blank_lines




   rem  ****************************************************************
   rem  *
   rem  *  Create aliases for variables.
   rem  *
   rem  ****************************************************************
   rem  '
   rem  '  (You can have more than one alias for each variable.)
   rem  '
   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   dim P1_Left_Right=player1x.a
   dim P1_Up_Down=player1y.b
   dim Convert_X=c
   dim Convert_Y=d
   dim Counter_Jump=e
   dim Gravity_U_Counter=f
   dim Gravity_Up=g
   dim Gravity_D_Counter=h
   dim Gravity_Down=i
   dim Slide_Counter=j
   dim Slide_Speed=k
   dim Slide_Limit=l

   dim Master_Counter=m
   dim Frame_Counter = n

   dim BitOp_01=q
   dim BitOp_Fall_in_Progress=q
   dim BitOp_Slide_Left_in_Progress=q
   dim BitOp_Slide_Right_in_Progress=q
   dim BitOp_Fire_Debounce=q
   dim BitOp_Flip_P1=q

   AUDV0 = 0 : AUDV1 = 0

   missile0x = 200 : missile0y = 200


Start_Restart
   rem  @# Start-Restart
   rem  ****************************************************************
   rem  ****************************************************************
   rem  *
   rem  *
   rem  *  Program Start/Restart
   rem  *
   rem  *
   rem  ****************************************************************
   rem  ****************************************************************

   player1x=78
   player1y=79

   Convert_X=0
   Convert_Y=0
   Counter_Jump=0
   Gravity_U_Counter=0
   Gravity_Up=0
   Gravity_D_Counter=0
   Gravity_Down=0
   Slide_Counter=0
   Slide_Speed=1
   Slide_Limit=0
   Master_Counter=0
   Frame_Counter=0
   BitOp_01=0

   ballx = 200 : bally = 200



Level_0
   if p = 0 then playfield:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XX.X.XX...X....XX....X...XX.X.XX
 XX....X........X.........X....XX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 XX..............................
 XX..............................
 XX........XXXXXXXXXXXX..........
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end




Level_1
 if p = 1 then playfield:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 XX........XXXXXXXXXXXX........XX
 ..........XX........XX..........
 ........XXXX........XXXX........
 ......XXXX............XXXX......
 XXXXXXXX................XXXXXXXX
end



Level_2
 if p = 2 then playfield:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 ................................
 ............XXXX................
 ..........XXXXXX................
 XXXXXXXXXXXXXXXX....XXXXXXXXXXXX
end



Level_3
 if p = 3 then playfield:
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 XX............................XX
 ................................
 ........XX............XX........
 ........XX............XX........
 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
end




Main_Loop
   rem  @# Main Loop
   rem  ****************************************************************
   rem  ****************************************************************
   rem  ****************************************************************
   rem  ****************************************************************
   rem  *
   rem  *
   rem  *  MAIN LOOP
   rem  *
   rem  *
   rem  ****************************************************************
   rem  ****************************************************************
   rem  ****************************************************************
   rem  ****************************************************************


   rem  ****************************************************************
   rem  *
   rem  *  Set up colors.
   rem  *
   rem  ****************************************************************
   rem  '
   COLUPF = $96 : COLUBK=$00 : COLUP1 = $42 : COLUP0 = $42





   rem  ****************************************************************
   rem  *
   rem  *  Convert player sprite position to playfield position.
   rem  *
   rem  ****************************************************************
   rem  '
   Convert_X = (player1x-14)/4
   Convert_Y = player1y/8


   rem  ****************************************************************
   rem  *
   rem  *  Controls animation speed.
   rem  *
   rem  ****************************************************************
   rem  '
   Master_Counter=Master_Counter+1

   if Master_Counter < 4 then goto Skip_Frame_Counter

   Frame_Counter=Frame_Counter+1 : Master_Counter=0

   if Frame_Counter=4 then Frame_Counter=0

Skip_Frame_Counter




   rem  ****************************************************************
   rem  *
   rem  *  Default standing still position for player sprite.
   rem  *
   rem  ****************************************************************
   rem  '
   player1color:
    $40
    $40
    $D2
    $40
    $40
    $18
    $18
    $18
    $18
    $18
    $18
    $18
    $18
    $40
    $40
    $18
    $18
    $D2
    $18
    $40
    $D2
    $D2
    $D2
    $40
    $40
end

   player1:
        %00000000
        %11101110
        %01110111
        %01110111
        %01100110
        %01100110
        %11000110
        %11001100
        %11101100
        %01111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end




   rem  @# Jump
   rem  ****************************************************************
   rem  *
   rem  *  Jump.
   rem  *
   rem  ****************************************************************
   rem  '
   if !joy0fire then Counter_Jump=0 : Gravity_U_Counter=0 : Gravity_Up=2 : BitOp_Fire_Debounce{3}=0 : goto Skip_Jump


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Use when player moves left or right while jumping or falling.
   rem  '
   player1:
        %00000000
        %11101110
        %01110111
        %01110111
        %01100110
        %01100110
        %11000110
        %11001100
        %11101100
        %01111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  If player isn't moving left or right, use arms up sprite.
   rem  '
   if !joy0left && !joy0right then  player1:
        %00000000
        %11101110
        %01110111
        %01110111
        %01100110
        %01100110
        %11000110
        %11001100
        %11101100
        %01111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Don't allow jumping if player is falling.
   rem  '
   if BitOp_Fall_in_Progress{0} then goto Skip_Jump


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Fixes it so the player can't hold down the fire button to
   rem  '  jump repeatedly.
   rem  '
   if BitOp_Fire_Debounce{3} && !BitOp_Fall_in_Progress{0} && !Counter_Jump then goto Skip_Jump

   BitOp_Fire_Debounce{3}=1


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Reset jump counter if limit is reached and start a fall.
   rem  '
   Counter_Jump=Counter_Jump+1 

   if Counter_Jump > 11 then Counter_Jump=0 : BitOp_Fall_in_Progress{0}=1 : Gravity_U_Counter=0 : Gravity_Up=3 : goto Skip_Jump 


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Fake gravity jump (slows down near the top of jump).
   rem  '
   Gravity_U_Counter=Gravity_U_Counter+1

   if Gravity_U_Counter = 24 then Gravity_U_Counter=0 : if Gravity_Up>0 then Gravity_Up = Gravity_Up - 1 


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Only jump up if nothing is in the way.
   rem  '
   temp5 = (player1y-5)/8

   if pfread(Convert_X,temp5) then goto Skip_Jump

   if player1y > 12 then player1y=player1y-Gravity_Up

Skip_Jump





   rem  @# Fall
   rem  ****************************************************************
   rem  *
   rem  *  Fall down.
   rem  *
   rem  *****************************************************************
   rem  '
   temp5 = (player1y+1)/8

   if Counter_Jump || pfread(Convert_X,temp5) then goto Skip_Fall_01


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Use when player moves left or right while jumping or falling.
   rem  '
   player1:
        %00000000
        %11101110
        %01110111
        %01110111
        %01100110
        %01100110
        %11000110
        %11001100
        %11101100
        %01111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  If player isn't moving left or right, use arms up sprite.
   rem  '
   if !joy0left && !joy0right then  player1:
        %00000000
        %01011100
        %00101110
        %00101110
        %00101100
        %00101100
        %00101100
        %01011000
        %01011000
        %00111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Fake gravity fall (speed keeps increasing during a fall).
   rem  '
   Gravity_D_Counter=Gravity_D_Counter+1

   if Gravity_D_Counter = 8 then Gravity_Down = Gravity_Down + 1 : Gravity_D_Counter=0

   player1y=player1y+Gravity_Down


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Lets the program know a fall is in progress.
   rem  '
   BitOp_Fall_in_Progress{0}=1

   goto Skip_Fall_02

Skip_Fall_01


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Not falling. Clear related variables.
   rem  '
   BitOp_Fall_in_Progress{0}=0 : Gravity_Down=0 : Gravity_D_Counter=0


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  If player sprite touches playfield, move up one pixel.
   rem  '
   temp5 = (player1y)/8

   if pfread(Convert_X,temp5) then player1y=player1y-1

Skip_Fall_02




   rem  @# Squat
   rem  ****************************************************************
   rem  *
   rem  *  Squat.
   rem  *
   rem  *****************************************************************
   rem  '
   if !joy0down then goto Skip_Squat


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Don't squat if jumping or falling.
   rem  '
   if BitOp_Fall_in_Progress{0} then goto Skip_Squat
   if Counter_Jump then goto Skip_Squat

   player1color:
    $40
    $40
    $D2
    $40
    $40
    $18
    $18
    $18
    $18
    $18
    $18
    $18
    $18
    $40
    $40
    $18
    $18
    $D2
    $18
    $40
    $D2
    $D2
    $D2
    $40
    $40
end

   player1:
   %01100110
   %01111110
   %01011010
   %00111100
   %00011000
   %00111100
   %00111100
   %00011000
end

Skip_Squat




   rem  @# Left
   rem  ****************************************************************
   rem  *
   rem  *  Left.
   rem  *
   rem  *****************************************************************
   rem  '
   if !joy0left then goto Skip_Joy0Left


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Don't move left if a pfpixel is in the way.
   rem  '
   temp5 = (player1x-18)/4

   if pfread(temp5,Convert_Y) then goto Skip_Joy0Left


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Activate left slide and move left if not hitting border.
   rem  '
   BitOp_Slide_Left_in_Progress{1}=1 

   if player1x > 16 then P1_Left_Right=P1_Left_Right - 0.50

   player1color:
    $40
    $40
    $D2
    $40
    $40
    $18
    $18
    $18
    $18
    $18
    $18
    $18
    $18
    $40
    $40
    $18
    $18
    $D2
    $18
    $40
    $D2
    $D2
    $D2
    $40
    $40
end

   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Makes sure player sprite is facing the correct direction.
   rem  '
   BitOp_Flip_P1{4}=0


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Don't animate if jumping or falling.
   rem  '
   if Counter_Jump then goto Skip_Joy0Left

   if BitOp_Fall_in_Progress{0} then goto Skip_Joy0Left

   on Frame_Counter gosub Frame_00 Frame_01 Frame_00 Frame_02

Skip_Joy0Left




   rem  @# Right
   rem  ****************************************************************
   rem  *
   rem  *  Right.
   rem  *
   rem  *****************************************************************
   rem  '
   if !joy0right then goto Skip_Joy0Right


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Don't move right if a pfpixel is in the way.
   rem  '
   temp5 = (player1x-10)/4

   if pfread(temp5,Convert_Y) then goto Skip_Joy0Right


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Activate right slide and move right if not hitting border.
   rem  '
   BitOp_Slide_Right_in_Progress{2}=1 

   if player1x < 139 then P1_Left_Right=P1_Left_Right + 0.50

   player1color:
    $40
    $40
    $D2
    $40
    $40
    $18
    $18
    $18
    $18
    $18
    $18
    $18
    $18
    $40
    $40
    $18
    $18
    $D2
    $18
    $40
    $D2
    $D2
    $D2
    $40
    $40
end


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Makes sure sprite is facing the correct direction.
   rem  '
   BitOp_Flip_P1{4}=1


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Don't animate if jumping or falling.
   rem  '
   if Counter_Jump then goto Skip_Joy0Right

   if BitOp_Fall_in_Progress{0} then goto Skip_Joy0Right

   on Frame_Counter gosub Frame_00 Frame_01 Frame_00 Frame_02

Skip_Joy0Right




   rem  @# Slide
   rem  ****************************************************************
   rem  *
   rem  *  Slide.
   rem  *
   rem  *****************************************************************
   rem  '
   if joy0right || joy0left then Slide_Counter=0 : Slide_Speed=1 : goto Skip_Slide

   if !BitOp_Slide_Left_in_Progress{1} && !BitOp_Slide_Right_in_Progress{2} then goto Skip_Slide


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  If in the middle of jumping or falling, increase slide.
   rem  '
   Slide_Limit=31
   if BitOp_Fall_in_Progress{0} then Slide_Limit=127
   if Counter_Jump then Slide_Limit=127



   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Use slide sprite if not in the middle of jumping or falling.
   rem  '
   if !Counter_Jump && !BitOp_Fall_in_Progress{0} then player1:
        %00000000
        %01011100
        %00101110
        %00101110
        %00101100
        %00101100
        %00101100
        %01011000
        %01011000
        %00111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  If the counter doesn't match the speed, skip this section.
   rem  '
   Slide_Counter=Slide_Counter + 1
   if Slide_Counter < Slide_Speed then goto Skip_Slide


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Speed becomes slower each time it loops back around.
   rem  '
   Slide_Speed=Slide_Speed * 2


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  Slide either left or right (last direction player moved).
   rem  '
   if BitOp_Slide_Left_in_Progress{1} && player1x > 16 then P1_Left_Right=P1_Left_Right - 1.02
   if BitOp_Slide_Right_in_Progress{2} && player1x < 139 then P1_Left_Right=P1_Left_Right + 1.02


   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   rem  '  If the slowest speed is reached, stop sliding.
   rem  '
   if Slide_Speed > Slide_Limit then Slide_Speed=1 : Slide_Counter=0 : BitOp_Slide_Left_in_Progress{1}=0 : BitOp_Slide_Right_in_Progress{2}=0

Skip_Slide




   rem  ****************************************************************
   rem  *  Flip player sprite if necessary.
   rem  '
   REFP1=0 : if !BitOp_Flip_P1{4} then Skip_Main_Flip
   REFP1=8
Skip_Main_Flip




   rem  ****************************************************************
   rem  *  Reset Program:
   rem  *  Any Atari 2600 program should restart when the reset switch  
   rem  *  is pressed. It is part of the usual standards and procedures.
   rem  '
   if switchreset then goto Start_Restart

 if !BitOp_Flip_P1{4} then ballx = ballx - 1 else ballx = ballx + 1

   drawscreen

 if collision(ball,playfield) then ballx = 255 : bally = 255

 if joy0up then ballx=player1x : bally = player1y








 if player1x = 138 then player1x = 25 : p = (rand&3) 

 if p = 0 then goto Level_0

 if p = 1 then goto Level_1

 if p = 2 then goto Level_2

 if p = 3 then goto Level_3

   goto Main_Loop



   rem  ****************************************************************
   rem  *
   rem  *  Animation frames for player.
   rem  '
   rem  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Frame_00
   player1:
        %00000000
        %01011100
        %00101110
        %00101110
        %00101100
        %00101100
        %00101100
        %01011000
        %01011000
        %00111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end

   return


Frame_01
   player1:
        %00000000
        %11101110
        %01110111
        %01110111
        %01100110
        %01100110
        %11000110
        %11001100
        %11101100
        %01111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end

   return


Frame_02
   player1:
        %00000000
        %01011100
        %00101110
        %00101110
        %00101100
        %00101100
        %00101100
        %01011000
        %01011000
        %00111100
        %00111110
        %00011110
        %00011100
        %01011100
        %01101110
        %00011110
        %11100111
        %11111111
        %11100111
        %00111100
        %01011111
        %01001111
        %00101101
        %00111010
        %00001100
end

   return
Edited by Rabbit 2600
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...