[j4k mk3] jm4k

Ok. Here is my entry :slight_smile:

jar link removed for yahoo’s crawler http://kaioa.com/games/jm4k.zip[soundbank required - it will just bomb out without one!]

4093 4092 bytes used. There wasn’t room for a manifest.mf - sorry :stuck_out_tongue:

java -cp .;jm4k.jar D

The game runs in fullscreen 640x480x32@0hz. It relys vsync for throtteling (sorry - no space) and is supposed to be run at 75hz.

Keys:
Press to start.
left = left
right = right
up or down = fire + thrust

You can also fly backwards if you want to, by pressing (and holding) the direction you want to move to first and then press (and hold) the direction you want to fire. It’s pretty funny, but also quite hard getting used to that.

The bar on the bottom labeled with ‘F’ “FUEL” is the fuel-meter. If it runs out, you die - game over. Flying into enemys and firing decreases it (more in higher levels). You can refill it by picking up the ‘F’ items and you also get a full bar at the start of each level.

The other bar on the bottom labeled with ‘W’ “WARP” is the warp-meter. It decreases automatically. If it runs out you’re in the next level.

The other things… well, you’ll see :wink:

Cool, it plays like an old B&W arcade :slight_smile:
Runs very smooth, and the sound is also pretty good. Having the shoot button mapped to the ‘up’ key is clever.
Very nicely done!

:slight_smile:

The sound is somewhat non static. The volume of the explosion effect depends on the distance (except for end of level and own death - those are fixed). And the volume of the bump against floor/ceiling depends on the speed. Well, most people won’t notice, but I thought it’s a cool thing (it was also very cheap to add ;)).

From level 5 upwards there are spikes on the floor and from level 10 upwards there are also spikes on the ceiling.

For offsetting the difficulty jump the spawn rate is decreased back to a lower level. Neat, isn’t it? Oh and that was a one liner:
if(Math.random()>1.0-(double)(l<15?(l>4?l%5+2:l%5+1):l-10)/250.0)
spawn here :slight_smile:

I also just spotted some unused vars… maybe it’s enough to label the bars properly… like “FUEL” and “WARP” (the way they have been).

Right now there are 824 lines of code… one constructor, main (one liner) and processKeyEvent (one liner) and nothing else. It’s so screwed ;D

Updated.

http://www.kaioa.com/games/jm4k.jar (same url)

4092 bytes now. The bars are now properly labeled and the “SPACE” text is blinking (insert credit-ish).

Removing some unused vars made that possible :wink:

switch the main for a static {} initializer as the app. entry point should save you afew bytes :wink:

But that won’t be enough for a manifest.mf right?.. Yep, not enough.

Well, basically there is everything I wanted to put in (plus some cheap fluff) except a manifest.

Hm. Ok there is another thing I could try.

[quote]switch the main for a static {} initializer as the app. entry point should save you afew bytes :wink:
[/quote]
If you have any exceptions, then it’s actually cheaper to define:

public static void main(String[] args) throws Exception

Throwing the exception from main is way less costly than a complete try/catch block. :slight_smile:

Level 5, $6344!
Nice.

Cas :slight_smile:

I don’t see how you are playing sounds without using a sound file… did you just view the bytes of some sound and hard code them into a byte array in your program or something?. The game is quite fun, I’m amazed at how much could be done with 4k… would remind me of a c64 game if it had a couple more colors :slight_smile:

level 10 ;D

[quote]I don’t see how you are playing sounds without using a sound file… did you just view the bytes of some sound and hard code them into a byte array in your program or something?
[/quote]
Well, there’s a hint… “soundbank required” :wink:

I just trigger midi events directly like this instrument, kinda lound and high pitch. That’s by far the cheapest way to produce any sounds - at least if you look at the required bytes.


import javax.sound.midi.*;
[...]
Synthesizer synth;
(synth = MidiSystem.getSynthesizer()).open();
Receiver synthRcvr = synth.getReceiver();

ShortMessage sm = new ShortMessage();

Instrument[] I=synth.getAvailableInstruments();

//instrument remapping
//will bomb out here with an IndexArrayOutOfBoundsException if there isn't a soundbank
synth.remapInstrument(I[118],I[0]); //shoot
synth.remapInstrument(I[116],I[1]); //explosion1
synth.remapInstrument(I[127],I[2]); //explosion2
synth.remapInstrument(I[ 98],I[3]); //bonus

[...]

//playing shoot sound, high pitch and not very loud
sm.setMessage(ShortMessage.NOTE_ON, 0, 80, 40);
synthRcvr.send(sm,-1); //instant play

Abuse did a similar thing in his 4k shooter game (j4k mk2). His approach was slightly different… not sure if his version is better or smaller.

The game is quite fun, I’m amazed at how much could be done with 4k

Thanks ;D


I just made a new version… featuring a title screen and it also explains the controls ingame.

See here:
http://kaioa.com/k/jm4k_title.png

Nice arrows huh? Well, it’s just:

g.drawString("LEFT \u2190\u2195\u2192 RIGHT",250,380);

Haha ;D

http://kaioa.com/games/jm4k.zip

It’s now a zip file, containing two files… it just gave me a little extra room :wink:
[tr][td]jm4k.jar[/td][td]39213934[/td][/tr][tr][td]d[/td][td]144[/td][/tr][tr][td]together[/td][td]40654078[/td][/tr]

Just made the title a bit nicer :wink:

whoa! This is actually fun… im amazed :smiley:

I cant* play it here, invalid display mode. Would you mind doing a 16bit colors version?

Oh that’s odd. I tried it on a 1.4 machine with a 16bit only card (voodoo banshee) and it worked there. :-/

Well, I have some bytes free… maybe it’s enough for a command line switch.

New version:
http://kaioa.com/games/jm4k.zip

jm4k.jar_3950
d_________144

total____4094

Run the game in 16bit mode:
java -cp .;jm4k.jar D any arguments will do the trick :slight_smile: