Web
Analytics
Log In  

15

Cart [#53607#] | Copy | Code | 2018-06-16 | Link
15

1.1 update:

  • Code optimisation
  • Muted alert sound for low fuel/ammo
  • Reinstated original title screen (much better!)
  • Added btn(5) X as alternative acceleration button for those using joypads/sticks.

My third little game - an arcade racer / shooter a bit like RoadBlasters, which was a favourite of mine as a kid.

Up = Accelerate
Down = Brake
Left/Right = Turn left / right
Z = Shoot
X = Alternative accelerate

Hope you enjoy it. Don't bother asking for improvements, I'm at the token limit :D On to the next thing!

racer arcade
P#53292 2018-06-05 11:57 ( Edited 2018-06-17 03:21)

::

Nice to see this one finished!
Good gameplay - blowing up cars is always fun!

Note: "I'm at the token limit"
...

No f**ng" way!!

You still have gazillion of tokens available:

  • replace all table creation by their inline variant. Ex:
function new_scenery(x,y,z,width,height,sprite_x,sprite_y,sprite_width,sprite_height,b_flip,stype,cwidth)
 return {
 x=x,
 y=y,
 z=z,
 width=width,
 height=height,
 sprite_x=sprite_x,
 sprite_y=sprite_y,
 sprite_width=sprite_width,
 sprite_height=sprite_height,
 collide_width=cwidth,
 b_flip=b_flip,
 stype=stype,
 }
end

That's 15 tokens less than the original version

  • abuse of single line variable initialization:
-- yes
local a,b,c=1,5,3
-- no
local a=1
local b=5
local c=3

First variant saves ~2 tokens per variables (and you have a lot of variables!)

Now you have plenty of space left :), couple of things could be improved:

  • real games are 60 fps :]
  • slightly reduce screenshake!
  • explosions should stay in place (seems to keep moving)
  • very annoying beep sound (low bullets)
P#53297 2018-06-05 15:21

::

Some more token savers:


palt()'s second argument defaults to true, so e.g. you can say palt(14) instead of palt(14,true) - two fewer tokens


pal() with no args includes what palt() with no args does, so you don't need to call both.


Why this?

 sy=30
 while sy<40 do
  sy+=1
  ...
 end

Rather than this?

 for sy=31,40 do
  ...
 end

Should be able to save tokens by doing something like this in draw_flag():

  local sn,y=245+f,60-20-4+sin(x/80+frame/30)*2
  spr(sn,x,y)
  spr(sn,x,y+8)
  spr(sn,x,y+16)
  spr(sn,x,y+24)

Similar stuff in draw_enemy_cars() and draw_player().


Use camera() for constant offsets to draw locations. Change:

 rectfill(0,55-hud_offset,128,66-hud_offset,c1)
 rectfill(0,45-hud_offset,128,55-hud_offset,c2)
 rectfill(0,37-hud_offset,128,47-hud_offset,c3)
 line(0,54-hud_offset,128,54-hud_offset,c1)
 line(0,52-hud_offset,128,52-hud_offset,c1)
 line(0,46-hud_offset,128,46-hud_offset,c2)
 line(0,44-hud_offset,128,44-hud_offset,c2)
 line(0,42-hud_offset,128,42-hud_offset,c2)
 line(0,35-hud_offset,128,35-hud_offset,c3)
 line(0,33-hud_offset,128,33-hud_offset,c3)
 line(0,31-hud_offset,128,31-hud_offset,c3)

To:

 camera(0,hud_offset)  -- or maybe -hud_offset, I forget
 rectfill(0,55,128,66,c1)
 rectfill(0,45,128,55,c2)
 rectfill(0,37,128,47,c3)
 line(0,54,128,54,c1)
 line(0,52,128,52,c1)
 line(0,46,128,46,c2)
 line(0,44,128,44,c2)
 line(0,42,128,42,c2)
 line(0,35,128,35,c3)
 line(0,33,128,33,c3)
 line(0,31,128,31,c3)
 camera() -- reset

Side note: rectfill()'s arguments are inclusive, e.g. to draw the width of the screen, use 0..127, not 0..128.

P#53304 2018-06-05 21:05 ( Edited 2018-06-05 21:07)

::

Token counting aside...

8747 points

Looks great, a real blast-from-the-past feel to it. :)

P#53305 2018-06-05 21:15 ( Edited 2018-06-05 21:16)

::

AMAZING !

P#53309 2018-06-06 01:56

::

Thanks guys for the token count recommendations - if I have room, I might be able to put back in road mines and my previous title screen.
I'll change the alert beep sound to be less intrusive - I've just loved alerts and flashing HUDs since Wing Commander :) I'll tone down the screenshake a bit. Twitter people were divided on that too but I think it adds punch. Perhaps could half it for enemy explosions.

60 fps would mean re-timing everything...I'll think about it ;)

Explosions were stationary initially but now move on purpose because momentum.

Thanks for all the expert tips on token optimisation...I did my best but I'm not a natural coder, so if something looks weird it's because that's how I did it.

Also, my math is shaky.

P#53312 2018-06-06 04:28

::

Just noticed another easy token save:

Where I suggested you do this:

 camera(0,hud_offset)  -- or maybe -hud_offset, I forget
 rectfill(0,55,128,66,c1)
 rectfill(0,45,128,55,c2)
 rectfill(0,37,128,47,c3)
 line(0,54,128,54,c1)
 line(0,52,128,52,c1)
 line(0,46,128,46,c2)
 line(0,44,128,44,c2)
 line(0,42,128,42,c2)
 line(0,35,128,35,c3)
 line(0,33,128,33,c3)
 line(0,31,128,31,c3)
 camera() -- reset

You can also assume that, once set, a color sticks, so you can also remove duplicate color args:

 camera(0,hud_offset)  -- or maybe -hud_offset, I forget
 rectfill(0,55,128,66,c1)
 rectfill(0,45,128,55,c2)
 rectfill(0,37,128,47,c3)
 line(0,54,128,54,c1)
 line(0,52,128,52)
 line(0,46,128,46,c2)
 line(0,44,128,44)
 line(0,42,128,42)
 line(0,35,128,35,c3)
 line(0,33,128,33)
 line(0,31,128,31)
 camera() -- reset

You might have other instances--I only noticed this when glancing at my suggestions.

Oh, actually, if you fix some accidental rectfill overlap, you can reduce it further by interleaving the rectfills without color args too:

 camera(0,hud_offset)  -- or maybe -hud_offset, I forget
 line(0,31,128,31,c3)
 line(0,33,128,33)
 line(0,35,128,35)
 rectfill(0,37,128,47)
 line(0,42,128,42,c2)
 line(0,44,128,44)
 line(0,46,128,46)
 rectfill(0,48,128,55)
 line(0,52,128,52,c1)
 line(0,54,128,54)
 rectfill(0,56,128,66)
 camera() -- reset

Should save 16 tokens.

P#53322 2018-06-06 11:03 ( Edited 2018-06-06 11:16)

::

1.1 update uploaded.
@felice - Most of your recommendations implemented. Many thanks. I now had enough room (1 token remaining :D) to put back my original title screen. Thank you.

P#53608 2018-06-16 15:19

::

While you are at it: can we skip the score at the end of a track? That's way too long :/

P#53610 2018-06-16 16:52

::

Sorry @fred72, I misappropriated your first reply to @Felice, I didn't realise you'd put in some valuable input too further up - that was very rude of me. Sorry! Thank you.

I'll decrease the score increment timer. perhaps it does take a little too long. I might have been too enamoured with the effect.

P#53623 2018-06-17 03:21 ( Edited 2018-06-17 08:31)

Log in to post a comment

user:
password:

New User | Account Help
:: New User
X
About | Contact | Updates | Terms of Use
Follow Lexaloffle:        
Generated 2018-09-25 13:22 | 0.270s | 1835k | Q:26