Trials 4K [Work in progress / failed]

http://home.halden.net/tombr/trials4k/images/trials4k_01.jpg

An attempt at creating a Trials HD clone using Jakobsen/verlet physics. It’s not going terribly well. I’ve got it to the point where the physics feels ok. The wheel rotates, it is possible to move the rider back and forth, the wheels are connected with dampened springs etc. However I’ve done almost all I can think of to optimise it and I’m at the 4k limit. And it does not include any levels and the graphics is kind of … basic.

I’ve got 3 months to think of something clever. Still not sure if it will be good enough to enter the competition.

If you’re waiting for optimization tips, you should post your source code or at least parts of it, or the solutions you used. Else we can’t really help.

Remove the texts, that might give you some extra hundred bytes (“BACKSPACE to continue from last checkpoint” is quite long…, FPS is not needed in “production” environment).

I’ve written a 4k game before so I think I know most of tricks by know. But I’ve included the source if anyone want to have a go at it :slight_smile:

I’ve also made an applet you can test:
http://home.halden.net/tombr/trials4k/trials4k.html

Keys are:
left arrow - lean back
right arrow - lean forward
up arrow - accelerate
down arrow - break (kind of)
1 - restart level 1
2 - restart level 2
Backspace - continue from last checkpoint

The packed size of this is now around 3880 bytes. There are 2 dummy levels that takes around 115 bytes.

[attachment deleted by admin]

As a first glance at the code I would say to replace ArrayLists with Arrays. You are loosing bytes to method invocations and to auto boxing unboxing in your for loops on these lists.

I suggest replacing all your defined methods with a state machine inside your init() or run() method.

very nice !

well done

about size (I would suggest to only let the bike not the biker)

From a first glance:

If you want to use lists, then write ArrayList everywhere, not List, therefore your class will contain no reference to java.util.List when it is not necessary, so you get a few bytes.
Also I suggest Vector instead of ArrayList as its name is shorter and also implements the List interface…

Try moving all class variables into the run() method, local variables take much less bytes.

Also if you store the level inside your class, you also get many bytes (you can get rid of many class and method references like java.io.DataInputStream, getResourceAsStream()).

Also never catch exceptions like java.io.IOException, catch always Exception or Throwable (so you don’t have to reference new classes).

These can give like 200 bytes or even more…