Super Sprint 4k

Well, I’m still a little over the 4k limit, but I haven’t started doing the optimisation of my code, I’m currently at 6526 bytes, but should make 4k by the end of Feb.

Anyway here it is Super Sprint 4k cough 7k :wink:

Super Sprint 4k

Instructions and source code are available on my site, I’m sure a few people here will wince horribly when they see the code.

A few outstanding issuse still to be finished, e.g. car animation, better collision detection etc.

Be kind,

Andy.

Interesting start :wink: Reverse and restart features would be nice

I can’t play it because my Mac doesn’t have Java 1.5, but you may find this first year entry very interesting…

http://www.pkl.net/~rsc/4KApplet/4KApplet.html

I managed to get all of Abuse’s cars in a jam in a corner :wink:

Whoa. Time-out! I just looked through the code, and there’s some serious optimizing that can be done:

  1. Replace the three parameter constructors of Color (i.e. new Color(240, 160, 0)) with the Hex equivalents (e.g. new Color(0xF0A000)).

  2. Move as many of those static entries into the main method as possible! You don’t pay extra for method variables (they’re all on the stack), but you do pay for fields and methods!

  3. Get rid of unnecessary class references. Being able to use “Point” is nice, but for what it costs, you should stick to a 2D array.

  4. Nice fonts are, well, nice, but configuring them costs some serious class space. Ditch 'em and use whatever the default is.

  5. Move all that INT data to a file. I know you think you’re saving space by using an embedded array, but what you’re actually doing is generating a constant pool entry plus a stack push operation for each array item! If you want to embed the data, encode it as a string and decode it at runtime.

  6. This:

JPanel panel = (JPanel) container.getContentPane();
    panel.setPreferredSize(new Dimension(WIDTH, HEIGHT));
    panel.setLayout(null);
    
    // setup our canvas size and put it into the content of the frame
  
    setBounds(0, 0, WIDTH, HEIGHT);
    panel.add(this);
    
    // Tell AWT not to bother repainting our canvas since we're
    // going to do that our self in accelerated mode
    setIgnoreRepaint(true);
    
    // finally make the window visible 
    container.pack();
    container.setResizable(false);
    container.setVisible(true);

Can be more succinctly stated as:

JPanel panel = (JPanel) container.getContentPane();
       
    // setup our canvas size and put it into the content of the frame
  
    setBounds(0, 0, WIDTH, HEIGHT);
    panel.add(this);
    
    // Tell AWT not to bother repainting our canvas since we're
    // going to do that our self in accelerated mode
    setIgnoreRepaint(true);
    
    // finally make the window visible 
    container.setResizable(false);
    container.setVisible(true);
  1. Inline those methods!

In short, you’ve got a lots of opportunities to fit this in 4K. :slight_smile:

Thanks for the quick responses, having tried a few quick optimisations I’ve knocked another 900bytes off the total, and that was just by inlining most of my methods!

jbanes, thanks for the links and tips, I’ll be sure to check them out.

I don’t use any Java 1.5 features, so I’ve changed the jnlp file so that everyone can play.

Feeback is such a wonderful boost to the ego, I really must get this finished now.

Thanks,

Andy.

Looks very interesting. Tried to run it on a Java 1.4 machine, but got this from the downloaded jar

Exception in thread "main" java.lang.UnsupportedClassVersionError: SS (Unsupported major.minor version 49.0)
        at java.lang.ClassLoader.defineClass0(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:251)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

Think this is because it is still compiled to a Java 1.5 class. The nice feedback from the webstart is that the splash screen just sits there, and then nothing happens. Would have been nice from sun, to give some sort info on what went wrong :stuck_out_tongue:

Anyway, it should be enough to change the “compile level” or something like that to 1.4 or lower.

I’ll change the target to 1.2 on the compiler for the next release. I forgot to do this when I changed the jnlp to reference 1.2 as well.

Check back in 18hrs for an update.

Andy.

PS: Happy Australia Day to all our Australian community members.

hehehe, v. fun game!

http://www.myjavaserver.com/~digiwired/hehehe.jpg

Im the only one left! ;D

DP

That’s the traffic jam I was talkin about! :slight_smile:

hehe, yeah that game was sooooo primitive =)

[quote]hehe, yeah that game was sooooo primitive =)
[/quote]
I seem to remember that was the time when you were certain that nothing useful would fit in 4k. :wink:

But you are correct. These days you’d have fit fullscreen, scrolling, and powerups into it! ;D

I’ve re-compiled the code with the target=1.2 flag, which has saved me another 100bytes, as well as allowing Mac users to finally play the game.

I’m in the progress of adding Mac support to my tutorials sections as well, so look out for those updates in the next day or two.

Regards,

Andy.

it still wont run on 1.4 :frowning:

Update the jar please! Im dyin to play this game! :smiley:

DP

Updated.

Never code when drunk, it doesn’t always go as planned.

Andy.

What ever happened to rotation? :o

If you make em top down, and add rotation, it would be super!

Rotation is one of the few things left on my to-do list, along with lap counter for your car and better collision detection.

I should be able to post an update on Sunday night that contains some/all of these updates.

I was concentrating this week on reducing the size (still over the limit) and making sure I compiled everything with 1.2 so our Mac friends can play along.

Andy.

Mac-compatibility means right now 1.4 and not 1.2 :wink:

[quote]hehe, yeah that game was sooooo primitive =)
[/quote]
I seem to remember everyone being blown away by it. :slight_smile:

[quote]Mac-compatibility means right now 1.4 and not 1.2 :wink:
[/quote]
So does this mean it needs to be re-compiled with 1.4? I would have thought that the 1.4 JVM could run 1.2 code, correct?

Andy.