Log In  


Cart #otrn_tt4-0 | 2020-05-07 | Code ▽ | Embed ▽ | No License
4

It's the fourth TweetTweetJam! My entry for this Jam is a stripped-down OutRun clone in 559 characters.

There's a couple things I'm proud of in this cart, so I'm posting an annotated, less-minified version of it below.

Controls

Use left and right arrows and stay on the road as long as possible! Sorry, if you crash you may have to refresh the page or reload the PICO-8 widget.

Code

g,l=color,line
poke(24366,1)pal(2,139,1)x,f,k,n,v,z,c=0,0,1,32,0,1,64::_::camera(-c,-c)memcpy(0,88,c*c)n-=1if(n<0)n=8+rnd(30)v=rnd(14)-7
for i=490,512 do
poke4(4*i,peek4(4*i-4)+v/k)end
cls(12)for d=512,c,-1 do
q=(d+f)\40%2y=c*c/d
r=y/c*(x+peek4(4*d))l(-c,y,c,y,3-q)l(r-y,y,r+y,y,5)l(r,y,r+1,y,9-4*q)end
a=btn()&3
if(a%3>0)a=6-4*a
x+=a*3b=-a/2o="w"
?o,a-9,58,0
?o,a+6,58
?o,-a-7,57
?o,4-a,57
?z.."m",1-c,1-c
u=8h=8g(12)for y=56,60 do
s=-y/c
rectfill((a+u)*s,y+s*h+1,(a-u)*s,y)a+=b
g(8)u=10h=6
end
z+=k\11
flip()
?"oops",0,0
f+=k
if(k<22)k+=1
if(abs(r)<c)goto _

Annotated code

--otrn
--by axnjaxn
--note: lines ending in -- show where i cut a newline
g,l=color,line
poke(24366,1)--
pal(2,139,1)--
--x: car's horizontal position
--f: odometer/used in determining lines and terrain colors
--k: speed
--n: downcounter to change direction
--v: current road direction
--z: odometer for display
--c: constant 64
x,f,k,n,v,z,c=0,0,1,32,0,1,64--
::_::--
camera(-c,-c)--
--advance the road data generated in sprite memory by 22 units (max speed)
memcpy(0,88,c*c)--
n-=1--
--each new road segment is determined here
if(n<0)n=8+rnd(30)v=rnd(14)-7
for i=490,512 do
   poke4(4*i,peek4(4*i-4)+v/k)--
end
--draw terrain
cls(12)--
for d=512,c,-1 do
   q=(d+f)\40%2--
   y=c*c/d
   r=y/c*(x+peek4(4*d))--
   --for each distance along the ground, i compute the y and x scale, then draw lines
   --this ends up using like 1.5k lines to draw a 61-row tall background
   l(-c,y,c,y,3-q)--
   l(r-y,y,r+y,y,5)--
   l(r,y,r+1,y,9-4*q)--
end
--a and b are the position and slope of the car's tilt
a=btn()&3
if(a%3>0)a=6-4*a
x+=a*3--
b=-a/2--
--wheels
o="w"
?o,a-9,58,0
?o,a+6,58
?o,-a-7,57
?o,4-a,57
--score
?z.."m",1-c,1-c
--car's body
u=8--
h=8--
g(12)--
for y=56,60 do
   s=-y/c
   --might have been able to save characters by dropping the +1 and altering h accordingly. oh well!
   rectfill((a+u)*s,y+s*h+1,(a-u)*s,y)--
   a+=b
   --since the first rect (the windshield) is different, always set the color/dims here
   g(8)--
   u=10--
   h=6
end
z+=k\11
flip()
--yes, putting it inside the game loop saves a single character. it gets erased unless the loop exits.
?"oops",0,0
f+=k
if(k<22)k+=1
if(abs(r)<c)goto _

4


1

This is pretty slick, you've got most of a regular racing game here.
I did notice a few things that could be minimized even further, such as the $ operator in place of peek4. Looks like you could pack even more into a sequel.=)


yeth


I had no idea the $ alias existed! That's great!


So is it supposed to disable when you crash


high score is:

4074M


It is! I didn't have enough left in my 560 characters to restart it, although if I'd known about $ I might have had enough for it!


Oh, one other thing I was thinking of was the directional control. While you may still need to multiply the whole output value by a constant to get the right movement amount (the default is 2 pixels/frame), you can replace this:

a=btn()&3
if(a%3>0)a=6-4a
x+=a
3 b=-a/2 a+=b (45 characters)

with this:

a=btn()
x+=a%4-3*(a%2) (22 characters)

Hope this comes in handy!


Doesn't that break the use of a and b for drawing the car?


Oh, does it? Sorry. I did a basic check of the code to see the value outputs, and saw some similarity in canceling out movement from the other side using multiplication and subtraction, but maybe I missed a layer. Well, hope it'll be useful for something, anyway.


Just means I've got you fooled, I guess :D

I hope you enjoyed looking through the code! It feels a little bit like showing how the magic trick works to post the annotated source, but I've learned a lot from comments people have been giving me!


DAMN LOOK AT THAT SCORE


IT'S HIGH AF


Also @axnjaxn plz add a way to restart



[Please log in to post a comment]