Worms 4K!!

I don’t know who wrote this, but I don’t think it was someone from JGO. anyway check this out:
http://javaunlimited.net/games/view.php?id=90

it’s a worms clone in 4K! :smiley: it lacks AI but works pretty good as a multiplayer

great job whoever glenn sanson is!

edit: oops there is AI!

Yeash, give the guy a chace to post next time. I waited a couple of days on Doom Buggy, and the author eventually showed up. :slight_smile:

Edit: I believe he’s registered on this site as the user Myself. He’s responsible for the Frozen Bubble for Java conversion.

Also, how do you turn on the AI?

Edit 2: Never mind on the AI. Either the page got edited or I’m not paying enough attention.

wow

:o

Wow! Nice game! ;D

I checked out the guys homepage and he is quite famous actually! He is the author of “Frozen Bubble” which is very well known in the Linux freeware gaming scene.

[quote=“DonaldEKnuth,post:5,topic:26136”]
You’re confused. He’s the guy who did the Java port, not the original game.

change sound/AI only works on alternate games.
the bullet sometimes goes through walls and doesn’t explode if hits a worm.
soemtimes is difficult to see the aiming cross, is it possible to make it red for example ?

test machine: athlon xp @3200+, xp pro and jre 1.5

Nice!

I finally found back my password (Last post in 2003?)…

Seems that W4K needs still need some work… I made a stupid mistake (used jdk5.0 to compile with a -source/target 1.4), and I used a function that does not exist in JDK1.4 -AudioSystem.getClip()-. The reflective method needed to get a Clip in JDK1.4 is way too costy (+200 bytes) and I don’t want to use sun.audio package as it’s not a standard package, so I’ll probably have to remove explosion sound

That will give me some bytes for further gameplay improvment :wink:

Short answers :

  • Frozen Bubble is not my game, I just made the J2SE port and the J2ME port (microFB)
  • Red cross is harder to see than a white one… I’ll try to make it blink (As I said, I now have some spare bytes :wink:

The version -without sound- should be available next Monday

– Glenn

I found it hard to shoot actually. I couldnt hit the actual worms if I had a direct hit…which im abit niffed about.
DP

Sound doesn’t work properly here anyway :wink: (Java1.5_04, Win2K)

The first time it plays, it sounds fine.
2nd time there is a little static, but no audible sfx,
Every time after that you just get silence.

Arghhh… I tried it on several computers, and it worked fine each time (except that there is a little static after each explosion), I personally use 1.5.0_06-b05 under XP…
I’ll try to add some notes about sound in the javaunlimited.net wiki as soon as I’ll be able to find how to reduce its size (Silence gave me 500 more bytes :wink: )

The quintessential example of sampled sound in a 4K game is Defender 4000. The key parts of the source code are as follows:

            
            byte[][] sounds = new byte[3][2000];

            //Generate some sounds!
            int step;
            
            //Laser
            step = 10;
            for(int i=0; i<2000; i++)
            {
                sounds[1][i] = ((i%step > 0) ? 32 : (byte)0);
                
                if(i%250 == 0) step += 2;
            }
            
            //BOOM
            step = 25;
            for(int i=0; i<2000; i++)
            {
                if(i < 500)
                {
                    sounds[2][i] = ((i%step > 0) ? 32 : (byte)0);
                    if(i%25 == 0) step--;
                }
                else
                {
                    sounds[2][i] = ((i%step > 0) ? 16 : (byte)0);
                     if(i%50 == 0) step++;
                }
            }

            //Sound Support
            AudioFormat format = new AudioFormat(8000.0f, 8 , 1, true, false);
            SourceDataLine line = (SourceDataLine) AudioSystem.getLine(new DataLine.Info(SourceDataLine.class, format));

            //Start the sounds
            line.open(format);
            line.start();

            //Main Loop
            while(true)
            {
                //Set the sound when an event happens by setting the variable 
                //"sound" to an index inside the "sounds[][]" array. Each sound
                //is a 1/4 of a second clip. (8000 samples per second.)
                sound = 2;

                //Play the sound
                if(System.currentTimeMillis() >= time+255)
                {
                    line.flush();
                    line.write(sounds[sound], 0, 2000);
                    
                    sound = 0;
                    time += 255;
                }
            }

The code above will produce very “electronic” sounds, but it’s SMALL. You can make the sounds more natural by computing them in a sine wave (I assume you’re probably doing this already), but it does cost something in code size. The other limitation is that only one sound can be played at a given time. Any new sounds wait up to a quarter of a second to play and may be supplanted by other sounds.

Hope this helps! :slight_smile:

Here is what I’ve done :


byte[] audioData = new byte[10000];
	            			
boolean silence = true;		
for (int i=0 ; i<8000 ; i++) {
    while(rand.nextInt() % 10 != 0) {
        audioData[i] = silence ? 0 : (byte)Math.abs(rand.nextInt() % (int)(1. + 63. * (1. + Math.cos(((double)i) * Math.PI / 8000.))));
        i++;				
    }
    silence = !silence;
}

AudioFormat audioFormat = new AudioFormat(8000f, 8, 1, false, false);
Clip clip = (Clip)AudioSystem.getLine(new DataLine.Info(Clip.class, audioFormat));
clip.open(new AudioInputStream(new ByteArrayInputStream(audioData), audioFormat, 10000));
clip.start();

And the result (with JoGa + 7zip)
Without sound : 3697 bytes
With sound : 4260 bytes

I won’t use it in the final version, but it should be useful for someone else…

By the way, I encountered a strange problem with proGuard… My ‘proguarded’ code seems to use a lot more CPU than the normal version (5/10% >> 100%)… Is it a common problem?

I had the same problem with Dachon 4k, so I had to skip the proguard step of the packing.

Of course, that meant I had to manually cut down another 300 bytes. :\

Updated…

No sound, but improved gameplay -see x30ice & darkprophet remarks ;)-

Bullet works perfect now.
If you could make some space a little improvement on cpu’s IA would make it more challenging so on large distances they keep shooting at the same place, missing every shot.

Updated AI + screenshots (javaunlimited and jws) + web site
Source code should be released soon (GPL licence)

Have fun :wink:

Edit :
Source is now available