Log In  
Follow
2bitchuck
Follow

Total amateur at this.

KiloWar 1.0
by 2bitchuck

Does anyone know if there are any good token optimization tutorials out there? Something like a collection of tips that show a suboptimal way of doing something and then demonstrate an optimized equivalent?

I'm about 25% through my latest game but about 60% through my token count already. Ordinarily I am much more inclined to finish functionality first and optimize/polish later, but in this case there is no way I will be able to finish if I don't clean up because I'll run out of tokens well before everything is in.

I suspect most of my problem is that I have a lot of tables and nested tables, like this:

-- this is 76 tokens total and I have a total of about 608 tokens worth of just these
ryl = (yl + (flr(yl/10)*1.5))*7.84
rec={rec1={x=ryl,ogx=ryl,y=32,ogy=32,sx=0,sy=32,speed=rnd(1.25),f=false},rec2={x=ryl,ogx=ryl,y=111,ogy=111,sx=0,sy=32,speed=rnd(1.25),f=false}}

which I then refer to values of like this (adding another 26 tokens): sspr(oteam.rec.rec1.sx,oteam.rec.rec1.sy,sprw,sprh,oteam.rec.rec1.x,oteam.rec.rec1.y,sprw,sprh,oteam.rec.rec1.f)

There are obvious things I could do here, like shoving "oteam.red.rec1" into something more compact so it's a single token instead of 3 every time, but I'm hoping there are more "best practices" sorts of things folks could point me to for general token savings and more proper ways to deal with data structures like this.

P#83365 2020-10-26 15:04

Cart #memory_2bc-0 | 2020-09-26 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA

I was working on a grid layout sector map for another project, but all I could think of was how the grid reminded me of the classic matching game Memory (or Concentration in some locales). So to get that out of my system so I could move on with my space game, I stopped and made a quick & dirty version of Memory.

Use the arrow keys to navigate the grid, X to flip a tile, Z to toggle show/hide the time clock (useful if you want to see how close you are to a personal best). When you match two tiles, they'll stay flipped. When you match all 16, the game is over! Try to see how fast you can match all 16 tiles. My personal best is 30 seconds, but I'm sure it can be done faster. I blame my arthritis for my performance :).

Unless there's a game breaking bug, I probably won't bother updating this. Like I said, this was mostly to get the thought of this game out of my head so I could keep making the game I'm actually trying to make! This was a fun diversion for a few hours though, and even though some of the sprites are hot garbage, I'm pretty fond of some of them (the snake, one-eyed demon head, and spider crab).

P#82286 2020-09-26 03:28

Cart #kilowar-3 | 2020-11-03 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
4

===UPDATES===
v1.0 - Played through about 200 matches (seriously) to find and fix the last couple of bugs hopefully (a race condition on coup fourré where you could end up with 8 cards in hand, hear the coup fourré sound, but not actually get the coup fourré and a condition where CPU could run out of cards first and leave the player unable to play or discard, thus effectively stopping the game). I had originally planned to update the sprites, but I honestly like them as is, so I'm keeping them!

v0.9.2 - Bug fixes related to end game no-winner nil conditions where player runs out of cards before CPU because player played one or more safeties after the deck ran out.

v0.9.1 - Fixed unchecked nil bug in case where CPU gets coup fourré with the emergency card and also has a Go card in hand (obscure devil of a bug!)

===ORIGINAL POST===

Hello everyone!

I made a PICO-8 version of the classic French car racing card game Mille Bornes! This is a game I've probably played thousands of times in my life from childhood through . . . not childhood (age is just a number, but it's a BIG number!)

In the game, you race against a CPU opponent to be the first to reach 700km (or, if you feel daring, extend the race to 1000km for a chance at bonus points). In addition to 1 point per km, you gain bonuses for playing safety cards, getting coup fourré (playing a safety card as the corresponding hazard is being played against you), winning a race without playing any 200km cards, extending to 1000km, winning after the deck has been emptied, and shutting out your opponent. You race until someone totals 5000 points and wins the match! You can see the cards and a brief rules description by pressing z on the start screen.

During the game, left & right arrows let you select a card to play or discard. x plays a card, z discards. The up arrow lets you play coup fourré if CPU plays a hazard for which you have the safety card. But be quick! You only have a short time to perform the coup fourré while the indicator flashes.

EDIT: I realized that the rules can be cumbersome to figure out if you've never played before. The Mille Bornes Wikipedia entry is actually a pretty good reference for the game rules.

This game is a lot of firsts for me: my first PICO-8 program, first experience with Lua, the first game programming of any kind I've done, first pixel art (quite obvious), first music composition (SUPER obvious). I'm proud of having created a fun, playable game, but it's very much the work of a game programing beginner, so don't expect highly optimized code or probably any techniques you should emulate :). I had 319 tokens left at the end and I'm sure there's plenty I could have done more efficiently.

Special thank you to @Krystman, whose Breakout tutorial was my impetus to give this a go, and from which tutorial I shamelessly grabbed the sash code to use for coup fourré. And thanks to everyone in this community. I think this is my first post, but I lurk & read the posts here frequently, amazed at all the cool ideas you all have and how willing you are to share your knowledge.

P#81787 2020-09-14 02:24 ( Edited 2020-11-03 14:25)

Follow Lexaloffle:        
Generated 2020-11-28 13:55 | 0.113s | 2097k | Q:49