Showing posts with label j2me. Show all posts
Showing posts with label j2me. Show all posts

Friday, November 14, 2008

Arctan in J2ME

Presenting:


// calculation functions
public class Calculation {

// Because J2ME has no floating point numbers,
// some sort of fixed point math is required.
// My implementation is simply to shift 10 places.
// for example, 1024 (>> 10) = 1
// and 512 (>> 10) = 0.5
public static final int[] CosTable90 = {
1024, 1023, 1023, 1022, 1021, 1020, 1018,
1016, 1014, 1011, 1008, 1005, 1001, 997,
993, 989, 984, 979, 973, 968, 962,
955, 949, 942, 935, 928, 920, 912,
904, 895, 886, 877, 868, 858, 848,
838, 828, 817, 806, 795, 784, 772,
760, 748, 736, 724, 711, 698, 685,
671, 658, 644, 630, 616, 601, 587,
572, 557, 542, 527, 512, 496, 480,
464, 448, 432, 416, 400, 383, 366,
350, 333, 316, 299, 282, 265, 247,
230, 212, 195, 177, 160, 142, 124,
107, 89, 71, 53, 35, 17, 0
};

public static final int[] AtanTable = {
0, 1, 2, 3, 5, 6, 7, 8, 10, 11,
12, 13, 14, 16, 17, 18, 19, 20, 21, 22,
23, 25, 26, 27, 28, 29, 30, 30, 31, 32,
33, 34, 35, 36, 37, 37, 38, 39, 40, 40,
41, 42, 43, 43, 44, 45
};


// angle calculation function based on x = x1 - x2, y = y1 - y2
public static boolean ArcTan(int x, int y, AngleArray sincos)
{
int angle = atan( y, x );
if (angle == -300)
return false;

int rotangle = abs(angle) % 90;

int cos = CosTable90[rotangle];
int sin = CosTable90[90-rotangle];

if (angle >= 270) // quadrant IV
{
int tCos = cos;
cos = sin;
sin = -tCos;
}
else if (angle >= 180) // quadrant III
{
cos = -cos;
sin = -sin;
}
else if (angle >= 90) // quadrant II
{
int tCos = cos;
cos = -sin;
sin = tCos;
}


sincos.sin = sin;
sincos.cos = cos;

return true;
}


/// returns angle 0->359 in degrees
public static int atan( int Y, int X )
{
boolean swap = false;

int top = abs(Y);
int bottom = abs(X);
if (top > bottom)
{
int btemp = bottom;
bottom = top;
top = btemp;
swap = true;
}
else if (bottom == 0)
return -300;

// this should keep index inbounds [0, 45]
int index = (top * 45) / bottom;
int angle = AtanTable[index];

if (swap)
angle = 90 - angle;

// X & Y += 180
// X & !Y = ...90
// !X & Y = ... 270
if ( (X < 0) && (Y < 0) )
angle += 180;
else if (Y < 0)
{
angle = 90 - angle;
angle += 270;
}
else if ( X < 0)
{
angle = 90 - angle;
angle += 90;
}

if (angle == 360)
angle = 0;

return angle;
}

// for good measure, sin and cos functions
public static int sin( int angle )
{
int rotangle = abs(angle);
while (rotangle > 89)
rotangle -= 90;

int cos = CosTable90[rotangle];
int sin = CosTable90[90-rotangle];

if (angle >= 270) // quadrant IV
sin = -cos;

else if (angle >= 180) // quadrant III
sin = -sin;

else if (angle >= 90) // quadrant II
sin = cos;

return sin;
}

public static int cos( int angle )
{
int rotangle = abs(angle);
while (rotangle > 89)
rotangle -= 90;

int cos = CosTable90[rotangle];
int sin = CosTable90[90-rotangle];

if (angle >= 270) // quadrant IV
cos = sin;

else if (angle >= 180) // quadrant III
cos = -cos;

else if (angle >= 90) // quadrant II
cos = -sin;

return cos;
}

}

Thursday, July 17, 2008

Stiria - Demo 1!

There's still work to be done, as mentioned previously, but I've decided to throw caution to the wind and release the first demo of this game.

STIRIA - Galactic Ice Cube game

Download here (Stiria.jar, 152 kB)

Phone requirements:

The game runs under Java Micro Edition. As such, if your phone does not support Java, this game will not run on it. If you're not sure if your phone has Java, you can do a few things:

  1. Take a look at what games/apps you have on your cell phone. If they mention Java when they start up, you have Java.
  2. Try to install it anyway. It shouldn't cause any harm, apart from the time it takes to try.

Apart from that, your cell phone should have a reasonable resolution, something in the range of 150x150 pixels (hopefully larger) to enjoy the game experience. That last phrase is code for, "if your screen is too small you won't be able to see where you're going".  However, the game should run, and if you want to chance it on a smaller resolution, go ahead.

The current version of the game has a maximum resolution (of sorts) at 400x400 pixels. I have not tested it at that large a resolution, but some graphics stuff is likely to be messed up.

How to install on cell phone:

Download the above .jar file onto your phone.  If you can transfer files directly from your computer to your phone, that will work as well. (in that case just download the .jar onto your hard disk, then move it onto your phone)

.jad installer - Certain phones may require an installer to help them figure out what to do with the .jar.  This is it.  Transfer it onto your phone with the .jar, then (if it doesn't auto-install), run it from wherever it is on your phone.

Hopefully these instructions are enough to get the game up and running.  If not, complain in the comments section of this post or something. Hopefully I'll be able to resolve most issues. =)

How to play

Okay, now that the lame stuff is out of the way, it's hopefully running on your phone.  You have no idea what you've gotten yourself into!

  • Control our nameless, heroic ice cube as he adventures in OUTER SPACE! Why is he in outer space? That's a mystery.
  • Up = jump.
  • Right = accelerate to the right.
  • Left = accelerate to the left.
  • Fire = attack with ICE FURY (less impressive than it sounds)
  • Select = pause/unpause the game.
  • Up, Down, and Fire navigate the pause menu.

Tips:

  • Space is an unforgiving place. A jump in the wrong place or at the wrong time may result in your heading in exactly the direction you want to avoid. So plan ahead! That's how NASA does it.
  • There's no direct penalty for dying, apart from forcing you to restart the level.  There are many hazards in space, including asteroids and fire.  Ice cubes happen to be very negatively impacted by fire.
  • You have a mini-map than can be accessed when the game is paused.  On the map, the center of the screen is marked as your current location.  Things marked with a light blue "X" will lead to the completion of the level.
  • There are two levels in total.  Both are rather difficult.

That's it! Have fun, and don't be afraid to die!

Thursday, July 10, 2008

Stiria - status update

Slowly but surely, the demo is approaching completion. There's some stuff that needs to be done but is best left until after the demo -- an overhaul of the slow collision detection code, for example -- but by and large it's getting very close to where I'm comfortable releasing it into the wild.

The current plan is for the demo to have two levels and a boss. Initially I had planned to have a single level demo, but I don't want to waste anybody's time by making the gameplay shorter than the download time. =)

Stay tuned.

Thursday, January 31, 2008

Stiria

Stiria is a cell phone game I conceived of in late 2005/early 2006, involving a rather Kirby-like (), friendly ice cube as the playable character. The ice guy character (who I'm not sure if I even named), initially was to have all sorts of transformations in his quest to conquer/survive the difficulties of outer space and its wacky, varying gravity.

Shortly after I thought of the project, the first videos of Super Mario Galaxy came out -- and I felt a certain sense of being beaten to the punch. The project laid on the backburner
for a while, until I had to come up with a 4 week project for the final part of a software design course at the University of Illinois. I picked up the project then, and 4 weeks and a painful amount of work later, I had this to show for it:

Written in J2ME (now called java micro edition, or JME) using the Java Wireless Toolkit, the current version involves 40 or so planets floating around in space and exerting their gravity on the little guy.

The game in its present form is a single level without a real objective -- in the short time frame I had I was unable to finish a boss to end the level with. I have worked on the game some in the half-year since, but mostly on the underlying code to speed up the process. That said, I'm hoping I can find some time to come back to and finish the one level demo, at the very least. When I do I will post it here.

I have also considered this game a candidate for the Nintendo DS system, utilizing the DS's touchscreen. Taking on a DS homebrew project is another matter entirely, however. =)


Download both files to try on Java-supported cell phone (~152 kb total):

Demo 1 -- Java executable + installer (July 30, '08)

Newest beta release: 0.9.09