rem Gate Racer v12 rem Steve Engelhardt 2/25/2013 rem rem 2K project - rem rem --->Requires custom files for compiling<--- rem Custom files available for download at the following link: rem http://www.atariage.com/forums/topic/208953-my-2k-game-experiment-gate-racer/page__st__25 rem *Timer.inc rem *score_graphics.asm rem *std_kernel.asm rem *pf_drawing.asm rem *pf_scrolling.asm rem *std_overscan.asm rem rem Left Difficulty switch turns oil slick on and off in the game. rem Right Difficulty switch turns velocity movement on and off in the game. rem rem v10 rem Eliminated option to remove oil slick rem Changed oil slick to slide you back and forth rather than instantly kill you. rem Added powerup. Randomly appears, makes you invincible for 3 or so gates rem Added Titlescreen rem rem v11 rem Eliminated option to change velocity controls, needed the space to fix the pixel bug. rem Fixed Bug in powerup code, it would remain on screen if you crashed and didn't touch it rem Changed std_kernel.asm modifications to get rid of the 'single pixel' bug. rem Changed Titlescreen rem include fixed_point_math.asm includesfile timer.inc set romsize 2k const one_tenth = 6 const leftborder = 15 const rightborder = 150 dim xmove = a.b dim direction = c dim velocityx = d.d dim velocityy = e.e dim scroll = f.f dim counter = g dim crash = h dim crashflag = i dim powerflag = j dim counter2 = k dim xball = n dim yball = o dim minutes=score dim seconds=score+1 dim tenths=score+2 dim frames=s dim rseed=rand dim state=t dim width=w dim Oilstart=x rem rem I set the titlescreen sprite here instead of in the 'Begin' loop so it doesn't flash rem on the screen every time you restart the game. rem player0: %11111111 %11110111 %11110000 %11110101 %11110110 %11110111 %11110101 %11110111 %00000000 %11100111 %10000100 %11000110 %10000100 %11100111 %00000000 %01000111 %01000100 %01000100 %11100111 %00000000 %10100101 %11100111 %10100101 %11100111 %00000000 %11100101 %10100110 %10100111 %10000101 %11100111 %00000000 %11100111 %11111111 %11111111 %00000000 %01111110 %01000010 %00111100 %10100101 %11100111 %10111101 %00111100 %10011001 %11111111 %10011001 end Init xmove = 70.0 rem direction = 0 velocityx = 0.0 score = 0 counter = 1 width = 8 Oilstart = 43 crash = 0 crashflag = 0 pfclear Begin rem set color and location of titlescreen sprite rem COLUP0=z player0x=72:player0y=55 rem set titlescreen sprite to double width rem NUSIZ0=$05 rem random number for placement of oil slick rem z = (rand&127)+15 rem randomly increase width of opening a bit rem Eliminating this saves 13 bytes. It makes the game easier. rem rem if z<30 then w=w+2 rem if oil slick reaches bottom of the screen, reset X position rem Can't eliminate this rem if y>90 then Oilstart=z rem Playfield Set rem need to run pfclear as the main loop comes back here to clear the screen between barriers rem PF0 sets road boundaries on either side COLUPF = $94 pfclear PF0=200 end if !counter then return drawscreen rem This pauses the game when you first start it, requiring a joystick press. rem The x=43 simply resets the location of the oil slick, not 100% needed. rem rem This requires 7 bytes: if !joy0fire then goto Begin rem This requires 11 bytes: if !joy0fire then x=43:goto Begin if !joy0fire then x=43:COLUP1=0:goto Begin pfpixel 0 31 on Main rem ------------------------------Main Loop Start-------------------------------------- rem | var44=var44|%10000000 var47=var47|%10000000 player0y = 85 rem Powerup Code rem rem increase height and width of missile rem NUSIZ0=$20 missile0height=5 rem rem this line allows for no more powerups to appear when you're already invincible rem if j=1 then missile0y=0:missile0x=0:goto skippower rem rem This randomizes the appearance of the powerup. rem if the random number is greater than 35, no powerup will appear. rem if z>35 then skippower rem rem Show the powerup missile0x=q+90:missile0y=counter+28 skippower rem rem Counter2 is incremented once per scrolling gate. After three, turn invicibility off. rem if collision(player0,missile0) then counter2=0:j=1 if counter2>3 then j=0:counter2=0 rem rem Remove the pixels for the gate opening rem pfhline q 0 r off rem Turn off crash sound rem AUDV1=0 rem Draw Road borders rem PF0=200 rem Oil slick rem changed from a sprite to the ball to save bytes. rem CTRLPF=$21 (sets ball height to 4 pixels wide) rem ballheight=4 rem rem Oil slick changed to Missile rem ability to turn off oil slick with left switch adds 7 bytes rem rem if !switchleftb then COLUP1=0:goto skipoil COLUP1=2 NUSIZ1=$20 missile1height=7 rem set X/Y position for the Oil Slick rem missile1x=x:missile1y=y skipoil rem This makes an 'engine rumble' sound. rem Uses 12 bytes, turning it off when car crashes would use another 4 bytes (for AUDV0=0). rem AUDF0=18:AUDC0=14:AUDV0=10 rem Removed the ability to reset during a game to save space. rem Needs 10 Bytes rem rem if switchreset then reboot rem next line slows the oil slick down as it moves down the screen rem state=state+1 if state>1 then y=y+1: state=0 rem y=y+1 rem This section controls the clock timer rem Nothing can be removed from this section rem tenths=tenths|$A0 minutes=minutes|$0B drawscreen frames=frames+1:if frames<>one_tenth then skip_tenths frames=0 tenths=tenths&$0F minutes=minutes&$F0 score=score+1 if tenths=$10 then score=score+90 if seconds=$60 then score=score+94000 skip_tenths rem this of course sets the screen to scroll down rem pfscroll down rem set the color of the score rem scorecolor = $A2 rem counter for changing the barriers rem counter=counter+1 rem I timed the counter to expire just as the barrier hits the bottom of the screen rem I added the 'gosub begin' to reset the playfield before drawing a new barrier, if rem you don't do that more than one barrier will remain on the screen rem I also gradually reduce the width from 12 down to 6. Ramps up the difficulty very quickly. rem if counter>87 then counter=0:counter2=counter2+1:goto change_barrier barrier_return rem assign player sprite (The Car) rem player0: %01111110 %01000010 %00111100 %10100101 %11100111 %10111101 %00111100 %10011001 %11111111 %10011001 end rem Setting the Right difficulty switch to A will skip the X/Y velocity rem You'll stop moving as soon as you stop pressing in one direction. rem rem I disabled this in V11 to save space. Needed it to fix pfpixel bug. rem rem if !switchrightb then goto altcontrol rem player velocity code rem if joy0right && direction then velocityx=velocityx+0.100 if joy0left && !direction then velocityx=velocityx-0.100 xmove = xmove + velocityx player0x = xmove if xmove<=leftborder then velocityx=-velocityx : direction=1 if xmove>=rightborder then velocityx=-velocityx : direction=0 rem player movement code rem if joy0right then direction = 1 if joy0left then direction = 0 if direction then velocityx=velocityx-0.0040 else velocityx=velocityx+0.0050 goto skip altcontrol rem 'No velocity' controls rem rem I disabled this in V11 to save space rem rem if joy0left then player0x=player0x-1 rem if joy0right then player0x=player0x+1 skip rem Old player movement code rem Changed it to save some space, kept it here for reference rem rem if joy0right then direction = 1 rem if joy0left then direction = 0 rem if !joy0left && !joy0right && direction && velocityx then velocityx=velocityx-0.0030 rem if !joy0left && !joy0right && !direction && velocityx then velocityx=velocityx+0.0030 rem if the player sprite (car) touches the playfield or the oil slick... Game over, man. rem rem Had 'God Mode' in there for testing: rem if switchbw then skipexplode rem rem skip collisions if you are invincible rem if j=1 then COLUP0=counter:goto skipexplode rem rem Set color of car rem COLUP0=10 if collision(player0,playfield) then goto explode if !collision(missile1,player0) then skipexplode if player0x>x then xmove=xmove-4 else xmove=xmove+4 skipexplode rem That's it, loop back. rem goto Main rem | | rem ------------------------------Main Loop End-------------------------------------- explode rem ---------------------------Car Crash Loop Start---------------------------------- rem | | rem This will remove the powerup from the screen if you crash while it's still on rem the screen. It will stay in place and not move when the game starts back up rem if you don't remove it here. rem missile0y=0:missile0x=0 rem Change score color to red when you crash rem scorecolor = $44 rem Crash Sound rem AUDF1=28:AUDC1=8:AUDV1=11 rem Crash Counter rem Used to turn off crash sound & flash colors rem crash=crash+1 if crash>68 then crash=1:crashflag=1 rem Set playfield road boundaries rem PF0=200 rem This is to make the oil slick appear correctly on the crash screen. rem Without it, the missile reverts back to 1 pixel wide and changes color to white. rem Not needed but looks much better with it. rem NUSIZ1=$20: COLUP1=2 rem Flash color when you die rem rem Changed it from flashing to just red, as now flashing indicates invincibility. rem COLUP0=66 rem Turns off sounds after counter expires. rem if crashflag=1 then AUDV0=0:AUDV1=0 rem This looks like duplicate code from the main loop, but it's required. rem If I don't add the tenths and minutes in this loop they won't display correctly rem when the game ends. rem tenths=tenths|$A0 minutes=minutes|$0B drawscreen rem Reset the Game when you hit fire. rem if joy0fire then goto Init rem loop back rem goto explode rem | | rem ---------------------------Car Crash Loop End------------------------------------ change_barrier rem -----------------------Gate Change Subroutine Start------------------------------ rem | | var44=0:var45=0:var46=0:var47=0 rem This code randomly changes the barrier openings. I had to tweak this quite a bit to rem keep the barriers where I wanted them (forming half off the screen isn't helpful). rem First I draw a solid pfhline, then I cut out the opening with two random numbers. rem Q is the left X position of the opening rem R is the right X position of the opening rem Calculate X position of the Left side of the opening rem q = (rand&31) rem rem The width starts out at 12. if the Random number is 17 or higher, I subtract the width rem to ensure the size of the opening on the right side is big enough. rem if q>15 then q=q-width rem Calculate X position of the Right side of the opening rem r = q+width rem if r>18 then r=r-2:q=q-2 rem Draw the solid horizontal line rem pfhline 0 0 31 on goto barrier_return rem | | rem -----------------------Gate Change Subroutine End--------------------------------