Sail 4K

Here is a new entry. http://unlimited.woogley.net/games/view.php?id=95

It’s a simple sailing game. You are the red sail boat.
Use the left and right arrow keys to control the rudder.
Use the up and down arrow keys to easy and trim the sail. To start moving use the the up arrow to easy the sail.
Navigate around the markers in an anti-clockwise direction and beat the other boats to earn a star.
The compitition gets harder each round.
The wind is blowing from the bottom of the screen. Remember for thoses that do not sail you can not sail directly into the wind.
The sail must be adjusted to the wind direction for maximum speed.
You can watch your progress on the mini display in the botom corner. Each completed leg of the race will turn red on the mini map once completed. If you take a marker too wide it will not register as being completed.

Some of the features.
Z sorted 3D sailing boats.
Water and wave effects as sailing boat moves through water.
Collision detection between boats and markers and boat to boat.

Very difficult to control.

Very very nice (and fast!) water. =D

:-[

java.lang.ClassCastException: sun.awt.image.DataBufferNative
	at W.<init>(Unknown Source)
	at W.main(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at com.sun.javaws.Launcher.executeApplication(Launcher.java:1154)
	at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1101)
	at com.sun.javaws.Launcher.continueLaunch(Launcher.java:944)
	at com.sun.javaws.Launcher.handleApplicationDesc(Launcher.java:515)
	at com.sun.javaws.Launcher.handleLaunchFile(Launcher.java:218)
	at com.sun.javaws.Launcher.run(Launcher.java:165)
	at java.lang.Thread.run(Thread.java:595)

kubuntu 5.10
jdk1.5.0_06

f.l.x What platform is the exception on.

Marcus you machine is just too fast. :slight_smile: I guess I will have to add a better timer loop.

No, no, I didn’t mean it ran too fast. It ran perfect. =)

Very smooth, is what I meant.

i get this : platform win 2000 screen bpp=16

Runs a bit slow on my Mac, quite fast on Windows.

It’s crashing on my machine as well:


java.lang.ClassCastException: sun.awt.image.DataBufferNative cannot be cast to java.awt.image.DataBufferInt
	at W.<init>(Unknown Source)
	at W.main(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:589)
	at com.sun.javaws.Launcher.executeApplication(Launcher.java:1176)
	at com.sun.javaws.Launcher.executeMainClass(Launcher.java:1122)
	at com.sun.javaws.Launcher.doLaunchApp(Launcher.java:970)
	at com.sun.javaws.Launcher.run(Launcher.java:104)
	at java.lang.Thread.run(Thread.java:626)

I’m running Ubuntu Linux with Java 1.6 b69. Just a guess, but it looks like it may be some sort of problem with the bit depth on mine, g666’s and f.l.x.'s computers. Linux only has a bit depth of 24 at most and g666 lists his as 16.

An error occurred while launching/running the application.

Title: Sail 4k
Vendor: Rick McConney
Category: Unexpected Error

sun.awt.image.DataBufferNative

i’m on suse 10, java 1.5

Works like a charm, even though I couldn’t get past the first level (didn’t really make an effort, it’s pretty hard I tell you) :slight_smile:

Thanks for the reports. I will try and change my color depth and see if I can reproduce the problem. I just ask for a compatible BufferedImage so I am not sure why I would get back one that fails. It looks like it might be when I try to get the raster and asign it to an int array. Does anyone have a code snipet of the platform independent way of getting at the writable raster of a compatible BufferedImage.

I am useing the following.


        BufferedImage image = g.getDeviceConfiguration().createCompatibleImage(width,height, Transparency.OPAQUE);
        int[] skyImagePixelData = ((DataBufferInt)image.getRaster().getDataBuffer()).getData();

I think I see the problem. Your casting the result of “image.getRaster().getDataBuffer()” to a DataBufferInt. All of our errors are class cast exceptions, involving some kind of DataBuffer , which I’m betting originate at that line of code. That cast will have to change to a plain DataBuffer for it to work without exceptions for us. Of course, I have no idea if that’ll work with your code.

Yes that is the problem. But what is the solution. It looks like I have assumed I could get a 32 bit color buffer to work with. But some platforms do not support such high color. I do not think I have the space to support multiple color depths. The algorithm for rendering the water looks totally different at 16 bits and 32 bits. At 32 bits it is nice and smooth, but at 16 bits I see all kinds or morie patterns in the water. For now the workaround for thoses that do have support for 32 bit color is to change the setting to 32 bit color and it will run fine. I will have to see if there is any way to support lower color depths.

I would love to here if any one has an easy solution.

Ok. I think I fixed the problem. I now use the following to create the buffer.


        BufferedImage skyImage = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);

So now since I create and int buffer it should be safe to cast it back to an int[] when I get the raster.

The only issue now is that since it is not a compatible image it will be converted on each redraw which might be a speed problem on some platforms. Let me know if the problem is fixed and how the speed is with the new way of doing things. Make sure you see the java webstart reloading the jar file if not try again my site always seems to need two tries to detect the jar is out of date.

It’s working without complaint now!

Quite nice, maybe a bit fast, but nice looking. Was first in goal, but I didn’t advanced a level. :frowning: Seems like one have to round the marks really close by for it to count. Varying wind directoins and stealing wind would really add to it I think, if possible to squeeze in. Boat also stops on a dime if there is no wind in sail. would be nice it if would glide a bit forward still.

Yeah after a while I started to get a vague understanding of how the wind and sail angles helped control the ship, but stopping dead immediately when you turn just the wrong angle doesn’t make sense. Also I had my sails pulled all the way back, then turned and hit forward and my sails completely flipped back around :stuck_out_tongue:

Great suggestions finally some one who knows how to sail :slight_smile:

I have done as much as I could fit in. I have made the rounding of the markers eaiser. You no longer have to be soo close. You still however can not be way away.
I have slowed the game down a bit.
I have added momentum to the boat so turning once moving is a little smoother.
I have add a wind indicator (the red line in the middle of the mini map).
And the wind now slowly changes over time.

I could not get the wind stealing in. It is too much computations to figure out who is bocking who. Too bad I would have liked to get that in.

Here’s the new link so you don’t have the scroll to the begining of the post.

http://unlimited.woogley.net/games/view.php?id=95

Yes if the wind is in your back and you change direction you will “Jibe”. That is the wind will swing the sails over to the other side of the boat. Many an sailor has gone over board this way. When going into the wind too far the wind will colapse the sail until the “Tack” or turn through the wind is complet. Then the sails will again fill at whatever setting was present before the turn.

Think of the sails being controlled by a length of rope. The up down arrows control the rope length. The wind will simply fill the sail until the rope is taught. But if you turn you can’t push a rope so the sail will be blown around until the rope is once again taught. Just like how a real sail boat works.

I won 8 times in a row, but as pointed out, I was too far away from the markers on 4 of them. It’s pretty fun though. My biggest problem is learning how to tack properly. The wind is usually against you on the bottom part of the lap. I have never sailed, but know the concepts, because I read a lot of Sci Fi/Fanatasy books and they are pretty descriptive sometimes.

Also, really nice water effects.

Holy psycho graphics, batman! :o