Rabbit 2600 Posted October 6, 2013 Share Posted October 6, 2013 Okay, I'm toying around with sprite position to playfield position and I noticed setting up normal collisions dosn't work (or I'm doing something very wrong) What would be the propper way of doing a collision between player0 and ball? 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 pfcolors 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 Start_Restart rem @# Start-Restart rem **************************************************************** rem **************************************************************** rem * rem * rem * Program Start/Restart rem * rem * rem **************************************************************** rem **************************************************************** player1x=18 player1y=79 ballx = 70 bally = 60 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 SCREEN1 if p = 0 then playfield: ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ .........XX..XX................. .......XXXX..................... XXXXXXXXXXX..XX..XX..XXXXXXXXXXX end SCREEN2 if p = 1 then playfield: ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ ................................ 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=$A6 : COLUP1 = $42 pfcolors: $00 $00 $00 $00 $1C $00 $00 $3C $00 $00 $CC $C6 end 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: $26 $9C $9C $9C $DA $DA $3C $3C $3C $26 end player1: %01100110 %00100100 %00111100 %00011000 %01011010 %00111100 %00011000 %00111100 %00111100 %00011000 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: %11000011 %01100011 %00111110 %00011100 %00111101 %01011110 %00011000 %00111100 %00111100 %00011000 end rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' If player isn't moving left or right, use arms up sprite. rem ' if !joy0left && !joy0right then player1: %01100110 %00100100 %00111100 %00011000 %00011000 %01111110 %10011001 %00111100 %00111100 %00011000 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 = 8 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: %11000011 %01100011 %00111110 %00011100 %00111101 %01011110 %00011000 %00111100 %00111100 %00011000 end rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' rem ' If player isn't moving left or right, use arms up sprite. rem ' if !joy0left && !joy0right then player1: %01100110 %00100100 %00111100 %00011000 %00011000 %01111110 %10011001 %00111100 %00111100 %00011000 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: $26 $9C $DA $DA $3C $3C $3C $26 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: $26 $9C $9C $9C $DA $DA $3C $3C $3C $26 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: $26 $9C $9C $9C $DA $DA $3C $3C $3C $26 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: %01100011 %00110110 %00011100 %00011000 %10111010 %01111100 %00110000 %01111000 %01111000 %00110000 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 drawscreen if collision(player0,ball) then reboot goto Main_Loop rem **************************************************************** rem * rem * Animation frames for player. rem ' rem '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Frame_00 player1: %01100110 %00100110 %00111100 %00011100 %00111100 %00011100 %00011000 %00111100 %00111100 %00011000 end return Frame_01 player1: %11000011 %01100011 %00111110 %00011100 %00111100 %01011110 %00011000 %00111100 %00111100 %00011000 end return Frame_02 player1: %00111100 %00011100 %00011100 %00011100 %00011100 %00011100 %00011000 %00111100 %00111100 %00011000 end return Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted October 6, 2013 Share Posted October 6, 2013 What happens if you move the collision thingy right before the drawscreen instead of right after it? Quote Link to comment Share on other sites More sharing options...
Rabbit 2600 Posted October 7, 2013 Author Share Posted October 7, 2013 That seemed to work! Cheers =D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.