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 _

P#76082 2020-05-07 18:43

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.=)

P#76121 2020-05-08 12:19 ( Edited 2020-05-08 12:23)

yeth

P#76136 2020-05-08 14:50

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

P#76173 2020-05-08 15:57

So is it supposed to disable when you crash

P#76186 2020-05-08 18:04

high score is:

4074M

P#76187 2020-05-08 18:07 ( Edited 2020-05-08 18:25)

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!

P#76188 2020-05-08 18:31

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!

P#76193 2020-05-08 20:51 ( Edited 2020-05-08 21:01)

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

P#76199 2020-05-08 21:24

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.

P#76200 2020-05-08 21:31 ( Edited 2020-05-08 21:35)

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!

P#76203 2020-05-08 21:49

DAMN LOOK AT THAT SCORE


IT'S HIGH AF

P#76674 2020-05-15 22:26 ( Edited 2020-05-15 22:30)

Also @axnjaxn plz add a way to restart

P#76675 2020-05-15 22:31

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-28 08:47:38 | 0.019s | Q:32