Featured Posts, J2ME Programming

How to – Setup score storing script

Introduction

J2ME supports Http(s) communication, so people can use it to send and receive score to server. The sample script has been provided by our handsome lecturer – George Nguyen. However, we need to set it up in order to use it. Here is how.

2.     When should you apply this? (Optional)

People should apply this when they want to implement the script on their own server.

3.     Advantages & disadvantages

  • Advantages:
    • Full control over everything
    • Fast (not Mekong server!)
    • Can implement more features by re-coding the script
  • Disadvantages:
    • More complicating
    • Require server with appropriate support.
    • Require setup steps.
    • Require maintenance.

4.     Requirements

5.     Steps & Screen shots

1.      Extract the script bundle into a folder. For example: /mad
2.      If you use Mekong Server, proceed to the next step.

Setup an account on 000webhost.com (This is a very good free web hosting for PHP web applications. It supports nearly all popular PHP functions. If you cannot visit it to sign up, use a proxy or VPN instead because they block some of Vietnam’s IP ranges.)

Step 1. Go to Homepage, click Sign Up

Step 1. Go to Homepage, click Sign Up

Step 2. Fill in information

Step 2. Fill in information

3.      Use Filezilla to connect to the server.

3.1.   Mekong Server:
Host: mekong.rmit.edu.vn
Port: 22 (NOT21)
Username and password

3.2.   000webhost.com
Login to your account and CPanel, then click on View FTP Details to see details.

Link to login: http://members.000webhost.com/login.php

Step 3. Login to Your Account

Step 3. Login to Your Account

Step 4. Go to CPanel

Step 4. Go to CPanel

Step 5. View your host details and FTP info

Step 5. View your host details and FTP info

Step 6. This is FTP info to connect

Step 6. This is FTP info to connect

Step 7. Connect to FTP using FileZilla

Step 7. Connect to FTP using FileZilla

4.      Upload /mad to your /public_html folder.
Most web hosting use /public_html folder. If this is not your case, follow your web hosting provider instructions.

 

5.      Set permission for highscore.xml to 666 (This is the most important step)

In Filezilla, tab Remote, right-click on highscore.xml and choose “File permissions…” and type 666 in the textbox, click OK.

 

6.      Now, your script is ready to be used.

Use the URL as below:

Remember: this is HTTPS, and Mekong will redirect any HTTP to HTTPS. Therefore, in your J2ME, you must use HttpsConnection; otherwise you will receive only an html file whose content is a 302 – Found response from server.

Find chosenname.chosendomain information in your CPanel or on the Signup page, or in the email sent to you.

 

6.     Reference

Written by myself!

Student ID: 3342135

Degree: Bachelor of Information Technology – Application

Standard
Featured Posts

How-to: An Android widget

Introduction

A widget is a mini application that can be embedded in other applications, most often the Home screen.

Requirements

Ideally, you should have a background service running, so that the widget can communicate with it directly using Intents, instead of calling the main program’s activity.

Advantages and disadvantages

Having a widget is a good addition to your existing app. It allows the user to interact with the app, or its running services, without opening the main app. This creates convenience, and will mean the user is more likely to use our app over our competitors.

 

The disadvantage here is that widgets are hard to design well, because of space constraints. In addition, you have to be selective with what you display, making sure that the information being displayed is relevant and most interesting to the user, without having to check the main app for the full details.

 

Steps

Creating a widget has 2 steps. The first is to specify your Widget object in your manifest file.

<receiver android:name="ExampleAppWidgetProvider" >
    <intent-filter>
        <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
    </intent-filter>
    <meta-data android:name="android.appwidget.provider"
               android:resource="@xml/example_appwidget_info" />
</receiver>

Android:name here is the name of the class extending AppWidgetProvider that you have/will implement. The only filter you need to add is android.appwidget.action.APPWIDGET_UPDATE. You will be sending intents directly to the widget, so declaring other actions your widget will handle is not necessary here.

 

In the meta-data section, android:name=”android:appwidget.provider” signals that this is the descriptor for your app’s widget. The android:resource attribute specifies the resource that will be used to define the basics of your widget. This file should be in the directory res/xml/file.xml

 

An example:

<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
    android:minWidth="294dp"
    android:minHeight="72dp"
    android:updatePeriodMillis="86400000"
    android:previewImage="@drawable/preview"
    android:initialLayout="@layout/example_appwidget"
    android:configure="com.example.android.ExampleAppWidgetConfigure"
    android:resizeMode="horizontal|vertical">
</appwidget-provider>

The most interesting attributes are updatePeriodMilis, previewImage and configure. UpdatePeriodMilis specify how often your app will update (beware that there is a 30 min gap added to this, meaning using this attribute will not allow your app to update at a frequency of more than twice per hour). PreviewImage points to an image of your widget, shown when the user selects your widget. If not specified, it will use your app icon. Configure specifies an activity that will be used to configure your widget. ResizeMode specify whether your widget can be resized or not. Note that resizeMode is introduced in Android 3.1.

Next up is defining your widget’s layout. Note that for widgets, only these are allowed (not their subclasses):

Layouts: FrameLayout, LinearLayout, RelativeLayout

Classes: AnalogClock, Button, Chronometer, ImageButton, ImageView, ProgressBar, TextView, ViewFlipper, ListView, GridView, StackView, AdapterViewFlipper

 

In addition to this, you should not allow your widget to extend all the way to the edges. This means it may touch other widgets, which will not look nice. Therefore, a padding of 8dp is advised.

 

Now, you will need to define your widget class. What you need to do is subclass AppWidgetProvider and override some of the following methods:

 

onUpdate(): this is called at intervals defined in the XML file. This is also called when the user adds the widget, so you should have setup codes here, unless you also override onEnabled. The codes to update your widget GUI should also be here.

 

onEnabled(): This is called when the user add the first instance of your widget. Note that this is only called for the first time. Subsequent instances will not trigger this. If you need a global setup for all your widgets, this is the place.

 

onDisabled(): Called when the last instance of your widget is removed. This is where the final clean up work should be.

 

onDeleted(): Called every time the user removes an instance of your widget.

 

onReceive(): Called for each broadcast and before all the above methods. Android already handles intent filtering and appropriate method calls, so this is usually not needed.

 

That’s the basics of a widget! However, what if you need a widget that updates itself more often than once every 30 minutes? Like a media player widget that updates once a second? Here’s how to do it:

 

First, change updatePeriodMillis to 0. Next up, you should override onEnabled. The strategy here is to use AlarmManager to set up a repeating alarm that will run an intent. Something like this:

 

public void onEnabled(Context context) {
      AlarmManager manager = (AlarmManager) context
                  .getSystemService(Context.ALARM_SERVICE);
      Intent intent = new Intent(context, MyPlayerWidget.class);
      PendingIntent pIntent = PendingIntent.getBroadcast(context, 0, intent,
                  PendingIntent.FLAG_UPDATE_CURRENT);
      manager.setRepeating(AlarmManager.RTC,
                  System.currentTimeMillis() + 1000, 1000, pIntent);
}

 

You’ve just created an alarm that will go off every second! SetRepeating is the method to use in order to set a repeating alarm. The parameters are: alarm type, timestamp for the first alarm occasion, interval in milliseconds, and the PendingIntent you’ll use. For alarm type, there are 2 main types, the first being normal ones and the second being ones ending with WAKE_UP. The first type, when the device is not being used, will not wake the device to perform the intent. Instead, it will execute the intent when the device next wakes up. WAKE_UP will wake the device to execute the intent.

 

I recommend setting the type to RTC, because it uses the system’s current time using System.currentTimeMilis(). It is more familiar compared to ELAPSED_REALTIME, which is the time since boot.

 

Next, you will need to override onReceive to call your onUpdate method every time the alarm triggers and deliver the intent. Example:

 

public void onReceive(Context context, Intent intent) {
      super.onReceive(context, intent);
      ComponentName thisAppWidget = new ComponentName(
                  context.getPackageName(), getClass().getName());
      AppWidgetManager appWidgetManager = AppWidgetManager
                  .getInstance(context);
      int ids[] = appWidgetManager.getAppWidgetIds(thisAppWidget);
      onUpdate(context, appWidgetManager, ids);
}

 

And of course, you should have your onUpdate method update your GUI with relevant information every time the alarm ticks. You can do that using the code snippet below:

 

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
      ...
      ComponentName thisWidget = new ComponentName(context,
                  MyPlayerWidget.class);

 

      RemoteViews views = new RemoteViews(context.getPackageName(),
                        R.layout.widget);
      views.setOnClickPendingIntent(R.id.widget_play_pause, pIntent);

 

      views.setTextViewText(R.id.widget_textView, "Updated text!");
      ... more update stuff ...
      appWidgetManager.updateAppWidget(thisWidget, views);
}

References:

Google (2012). App Widgets. Available: http://developer.android.com/guide/topics/appwidgets/index.html Last accessed 7th May 2012.

Standard
Featured Posts, Games, J2ME Programming

How to make a basic bullet shooting game

Introduction

 

This is a bullet shooting game. During the time making this project, I have encountered many problems in creating this game.

In this How-To page, I will cover some topics that may be useful for you.

  • Process input from user
  • Display a background using TiledLayer
  • Making bullet pattern
  • Enemy move against wall
  • Vector normalization
  • Remove any sprite from layer manager

When you should apply this?

You can apply any solution above to enhance your game. However, making bullet pattern is optional.

Advantages and disadvantages, Requirement, Step and ScreenShot

  • Process input from user
public void getPlayerKeyInput() {

int keyState = getKeyStates();

int characterXPosition = character.getX();

int characterYPosition = character.getY();

if ((keyState & UP_PRESSED) != 0 && characterYPosition > 0) {

moveCharacter(0, -CHARACTER_MOVEMENT_SPEED);

}

if ((keyState & DOWN_PRESSED) != 0 && characterYPosition < HEIGHT - character.getHeight()) {

moveCharacter(0, CHARACTER_MOVEMENT_SPEED);

}

if ((keyState & LEFT_PRESSED) != 0 && characterXPosition > 0) {

moveCharacter(-CHARACTER_MOVEMENT_SPEED, 0);

}

if ((keyState & RIGHT_PRESSED) != 0 && characterXPosition < WIDTH - character.getWidth()) {

moveCharacter(CHARACTER_MOVEMENT_SPEED, 0);

}

}

Note: moveCharacter() is a method defined by programmer. It moves character. For example, character.move(dx, dy). The second Boolean logic is to make character to move inside the screen. WIDTH and HEIGHT are the width and height of the GameCanvas.

Advantages: Easy to control and edit the code

Disadvantage: Make the code longer

  • Display background using TiledLayer

 

private void displayBackground() {
int[] map = { 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 3, 4, 3, 4, 2, 4, 2, 4, 2, 4, 2, 1, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 4, 3, 3, 4, 3, 4, 3, 4, 2, 4, 2, 1, 2, 1, 1, 2, 1, 2, 1, 3, 1, 3, 4, 3, 4, 3, 3, 4, 3, 4, 2, 4, 2, 4, 2, 1, 2, 1, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 4, 3, 3, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 1, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 2, 4, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1 };
int count = 0; 
for (int i = 0; i < background.getRows(); i++) 
 { for (int j = 0; j < background.getColumns(); j++) { background.setCell(j, i, map[count]); count++; } 
} 
}

Note: there are many ways to setCell, but in my game, I use nested-loop.

I experience that when you setCell by TiledLayer. If you setCell(col, row, 0), the cell will be transparent.

Advantage: TiledLayer will help you make a customized background image. Its size is much smaller than you use a Graphics to draw the whole image.

Disadvantage:  The TiledLayer has limitation comparing to draw an image in the quality and the scenery.

  • Making bullet pattern

 

public void createCharacterBullet() {

if (!characterAbleToFire) {
return;
}
int characterXPosition = character.getRefPixelX();
int characterYPosition = character.getRefPixelY();

//bullet pattern
characterBulletLayerManage.append(
getCharacterBullet(characterBulletImage, 0, -6, characterXPosition, characterYPosition - 10));

if (characterBulletDamage > 15) {
characterBulletLayerManage.append(
getCharacterBullet(characterBulletImage, 0, -6, characterXPosition - 15, characterYPosition - 10));

characterBulletLayerManage.append(
getCharacterBullet(characterBulletImage, 0, -6, characterXPosition + 15, characterYPosition - 10));
}
if (characterBulletDamage > 30) {
characterBulletLayerManage.append(
getCharacterBullet(characterBulletImage, -2, -6, characterXPosition - 20, characterYPosition - 10));

characterBulletLayerManage.append(
getCharacterBullet(characterBulletImage, 2, -6, characterXPosition + 20, characterYPosition - 10));
}
characterAbleToFire = false;
}

 

private BulletSprite getCharacterBullet(Image image, int dx, int dy, int xRefPosition, int yRefPosition) {

BulletSprite characterBullet = new BulletSprite(new Sprite(image, 10, 15), characterBulletDamage, dx, dy);
characterBullet.defineReferencePixel(5, 7);
characterBullet.setRefPixelPosition(xRefPosition, yRefPosition);
return characterBullet;
}

For some reason, I cannot insert image in this post. Sorry for any inconvenience.

Advantage: It looks awesome.

Disadvantage: None

  • Enemy move against the wall

//move action

if (enemyXPosition < 0 || enemyXPosition > WIDTH) {
enemySprite.setFlag();
}
if (enemySprite.isFlag()) {
enemySprite.move(3, 0);
} else {
enemySprite.move(-3, 0);
}

Create a class called EnemySprite, and initial a boolean type called “flag”

enemySprite.setFlag() method does (this.flag = !flag;)

Advantage: It is easy to control character move

 

  • Vector normalization
public int[] getVectorNormalization(int x1, int y1, int x2, int y2) {

int[] coordinates = new int[2];
int a = x2 - x1;
int b = y2 - y1;
double length = Math.sqrt(a * a + b * b);
coordinates[0] = (int) (BULLET_SPEED * a / length);
coordinates[1] = (int) (BULLET_SPEED * b / length);
return coordinates;
}

The formular for vector is (x2 – x1, y2 – y1)

The length of the vector is  with a = x2 – x1, b = y2 – y1. To calculate normalized vector, use the formular . You can multiple with BULLET_SPEED to increase the speed of the bullet.

  • Remove any sprite from LayerManager

 

public void itemDropDown() {

for (int i = itemLayerManager.getSize() - 1; i >= 0; i--) {
Sprite item = (Sprite) itemLayerManager.getLayerAt(i);
int itemXPosition = item.getRefPixelX();
int itemYPosition = item.getRefPixelY();

if (itemXPosition < 0 || itemXPosition > WIDTH || itemYPosition < 0 || itemYPosition > HEIGHT) {
itemLayerManager.remove(item);
} else {
item.move(0, 4);
}
}
}

I experience that your program is easily catched Exception if you use normal for-loop.

On the reason that when you remove a layer, the size of the LayerManger reduce; however, in the for-loop the variable “i” still stores the old value and the LayerManager will catch ArrayIndexOutOfBound. Thus, it is better to use a for loop going from the last element to the first element.

  • Bullet pattern bonus

 

private void bossBulletPattern1(int enemyXPosition, int enemyYPosition, boolean doubleStrike) {

Image image = null;

switch (random.nextInt(3) + 1) {
case EnemySprite.ENEMY_1:
image = getImage("/image/Bullet1.PNG");
break;
case EnemySprite.ENEMY_2:
image = getImage("/image/Bullet2.PNG");
break;
case EnemySprite.ENEMY_3:
image = getImage("/image/Bullet3.PNG");
break;
}
final int NUMBER_OF_BULLET = 5;
int[] x = new int[NUMBER_OF_BULLET];
int[] y = new int[NUMBER_OF_BULLET];
final int SPACE = 5;
final int RADIUS = SPACE * (NUMBER_OF_BULLET + 1);

for (int i = 0; i < NUMBER_OF_BULLET; i++) {
x[i] = SPACE * (i + 1);
y[i] = (int) Math.sqrt(RADIUS * RADIUS - x[i] * x[i]);
}
for (int i = 0; i < NUMBER_OF_BULLET; i++) {
pattern1Handler(enemyXPosition, enemyYPosition, enemyXPosition + x[i], enemyYPosition + y[i], image, doubleStrike);
pattern1Handler(enemyXPosition, enemyYPosition, enemyXPosition - x[i], enemyYPosition + y[i], image, doubleStrike);
pattern1Handler(enemyXPosition, enemyYPosition, enemyXPosition - x[i], enemyYPosition - y[i], image, doubleStrike);
pattern1Handler(enemyXPosition, enemyYPosition, enemyXPosition + x[i], enemyYPosition - y[i], image, doubleStrike);
}
}

private void pattern1Handler(int enemyXPosition, int enemyYPosition, int newEnemyXPosition, int newEnemyYPosition,
Image image, boolean doubleStrike) {
int[] vector = getVectorNormalization(enemyXPosition, enemyYPosition, newEnemyXPosition, newEnemyYPosition);
enemyBulletLayerManger.append(getBulletSprite(new Sprite(image, 20, 20), 10, vector[0], vector[1], enemyXPosition, enemyYPosition));
if (doubleStrike) {
enemyBulletLayerManger.append(getBulletSprite(new Sprite(image, 20, 20), 10, vector[0], vector[1], newEnemyXPosition, newEnemyYPosition));
}
}

private void bossBulletPattern2(int xPosition, int yPosition) {

final int NUMBER_OF_BULLET = 5;
final int SPACEX = WIDTH / NUMBER_OF_BULLET;
final int SPACEY = HEIGHT / NUMBER_OF_BULLET;

int[] x = new int[NUMBER_OF_BULLET * 4];
int[] y = new int[NUMBER_OF_BULLET * 4];
int[] vector;
Image image = null;

switch (random.nextInt(3) + 1) {
case EnemySprite.ENEMY_1:
image = getImage("/image/Bullet1.PNG");
break;
case EnemySprite.ENEMY_2:
image = getImage("/image/Bullet2.PNG");
break;
case EnemySprite.ENEMY_3:
image = getImage("/image/Bullet3.PNG");
break;
}

for (int i = 0; i < NUMBER_OF_BULLET * 4; i++) {
if (i < NUMBER_OF_BULLET) {
x[i] = i * SPACEX;
y[i] = 0;
} else if (i < NUMBER_OF_BULLET * 2) {
x[i] = WIDTH;
y[i] = (NUMBER_OF_BULLET * 2 - i) * SPACEY;
} else if (i < NUMBER_OF_BULLET * 3) {
x[i] = (NUMBER_OF_BULLET * 3 - i) * SPACEX;
y[i] = HEIGHT;
} else {
x[i] = 0;
y[i] = (NUMBER_OF_BULLET * 4 - i) * SPACEY;
}
}
for (int i = 0; i < NUMBER_OF_BULLET * 4; i++) {
vector = getVectorNormalization(x[i], y[i],
xPosition, yPosition);
enemyBulletLayerManger.append(
getBulletSprite(new Sprite(image, 20, 20), 10, vector[0], vector[1], x[i], y[i]));
}
}

 

 

 

 

Reference

  1. J2ME Game Programming (Game Development) By Matin J.Wells
  2. JavaME < http://www.codeotaku.com/blog/2010-08/java-me-games/index>

 

Standard
Featured Posts

making a pass obstacle game on JavaME

COSC 2543

Mobile application development

Assignment 1

Name: Phan Thanh San

Student ID: s3342133

Introduction

This document will present the progress of making the Touhou Jumping game in J2ME as well as problems encountered during the making of the games.

This includes problems having with layers, image, and sprites in game canvas.

Step, Screen shots, advantages and disadvantages

Above is the menu interface which shows three options: New Game, Highscore, Setting and exit. The idea is to choose from one of the three options and the program will automatically change to the desired screen.

To change from the menu screen to another, for instance the high score screen, use the following code

if (menuList.getString(menuList.getSelectedIndex()).equals(“Highscore”)){

display = Display.getDisplay(this);

highScore.displayScore();

display.setCurrent(highScore);

}

This also applies to others, such as starting the game:

if (menuList.getString(menuList.getSelectedIndex()).equals(“New Game”)) {

display = Display.getDisplay(this);

BasicGameCanvas gameCanvas = new BasicGameCanvas(true, display, highScore);

display.setCurrent(gameCanvas);

try {

gameCanvas.start();

} catch (IOException ex) {

ex.printStackTrace();

}

}

 

Above is the beginning interface of the game.

To make the character move forward or jump

if ((keyState & UP_PRESSED) != 0 && !spriteProcessUpward) {

int x = suwakoSprite.getX();

int y = suwakoSprite.getY();

SuwakoLayer.remove(suwakoSprite);

suwakoSprite = new Sprite(suwakoImg2, 50, 86);

SuwakoLayer.append(suwakoSprite);

suwakoSprite.setPosition(x, y);

suwakoSprite.nextFrame();

spriteProcessUpward = true;

flag = false;

jump = true;

}

if ((keyState & RIGHT_PRESSED) != 0 && !spriteProcessForward) {

suwakoSprite.nextFrame();

suwakoSprite.move(2, 0);

suwakoSprite.setTransform(Sprite.TRANS_NONE);

spriteProcessForward = true;

            }

 

Spaming the enemy:

To make the enemy keeps coming at the player with an increasing number every time:

public void spamEnemy() {

if (!spam) {

return;

}

int x = suwakoSprite.getX() + 300;

final int SPACE = 60;

for (int i = 0; i < numberOfShangHai; i++) {

Sprite sprite = new Sprite(shanghaiImg, 44, 57);

sprite.setPosition(x + SPACE, 215);

x += SPACE;

sprite.setTransform(Sprite.TRANS_MIRROR);

ShanghaiLayer.append(sprite);

}

spam = false;

}

Making the diamond appears:

public void random() {

if (!spamDiamond) {

return;

}

Random random = new Random();

int n = random.nextInt(4);

int x = suwakoSprite.getX();

final int SPACE = 20;

for (int i = 0; i < n; i++) {

Sprite item = new Sprite(diamond, 30, 30);

item.setPosition(x + SPACE, 160);

ItemManager.append(item);

x += SPACE;

}

spamDiamond = false;

}

Making the enemy or diamonds disappear if the main character go pass it and the enemy go out of the canvas-also remove it to make the game less heavy.

for (int i = ShanghaiLayer.getSize() – 1; i >= 0; i–) {

Sprite sprite = (Sprite) ShanghaiLayer.getLayerAt(i);

int shanghaiXPosition = sprite.getX();

if (shanghaiXPosition < suwakoSprite.getX() – 100) {

ShanghaiLayer.remove(sprite);

}

}

As the enemy plays the role as obstacle, it is necessary to make the main character to die-or in other word, player fails the game if player touch the enemy

for (int i = ShanghaiLayer.getSize() – 1; i >= 0; i–) {

Sprite sprite = (Sprite) ShanghaiLayer.getLayerAt(i);

if (suwakoSprite.collidesWith(sprite, true)) {

System.out.println(“Game Over”);

//change to highscore

Highscore.updateScore(score);

highScore.displayScore();

display.setCurrent(highScore);

stopGame = true;

}

}

 

Note: in this game, timing is everything.

Reference

Martin Wells, Java ME Game Programming, second edition, viewed July, 28th 2012

Standard
Featured Posts, J2ME Programming

HOW TO DETECT COLLISION IN MARIO-BASED GAMES

Introduction

Mario-based games demands a greater details of implementation of collision detection than the already existed library in J2ME. For example, the methods provided only return true or false when detecting collision. This does not tell you the collision points, or which side of the Sprite the collision happen, which is necessary to tell if Mario jump on his enemy’s head or just hit him and die. However we can achieve the seemingly complicated algorithm with just an if clause. This how-to will give you some ideas about implementing such function.

2. When to apply?

Anywhere when you need more than just the boolean returned from collidesWith function in J2ME. If you want to know which side of the Sprite has been collided, use the algorithm presented below.

3. Advantages & Disadvantages

  • Advantages: easy and simple to implement
  • Disadvantages: may not be as precise as some other complex algorithm
  • Your Sprite must have some variables to indicate if it is moving or falling

4. Requirement

  • Your Sprite must have some variables to indicate if it is moving or falling

5. Steps

Here is the pseudo-code that show how-to implements the algorithm:

if collision happen

                if character is moving or jumping

                                he hits the enemy and die

                else if character is falling and he is above the enemy

                                he jump on the enemy’s head

                                enemy dies.

So the idea is simple: if the character hits the enemy when he is moving on the ground or jumping, then he dies, or if he is falling then he must hits the enemy’s head and the enemy dies. This idea is much more easier to implement than we do complex calculation to produce the same answer.

6. References

http://j2megame.uw.hu/ch10lev1sec247.html: provides a detailed explanation on how to detect collision in J2ME games in different ways.

Standard
Featured Posts

How to edit midi file for your j2me application

.1.       Introduction

This tutorial will help you know how to edit midi audio files so that you can achieve fine sound with small size.

 

       2.       When should you apply this?

Your audio files do not meet your application requirement like small, looping.

 

       3.       Advantages

You can adjust the file sound whatever you want. There are many functions and options to change.

 

       4.       Disadvantages

You need some basic knowledge about how to use the tool.

 

       5.       Requirement

Anvil Studio (free)

 

       6.       Steps and Screen shots

After open Avil Studio and put in a file, you will have a screen like this:

 

As you know, midi file is comprised up by many instruments with different types. Therefore, you can edit these instruments however you want to.

Right-click on an instrument, you can mute, play it solo or even delete it. Double-click on the “Instrument section”, you can change that to other types. You can also edit the volume of each sound.

 

To delete some parts of the midi song, first left-click on the part I mark with red. Then click File -> Truncate Song -> and choose either of 2 options: Delete from Start to current position or Delete from current position to End.

When you are done, left-click File -> Save Song.

 

       7.       Reference

Google.com

http://www.anvilstudio.com/

Contact me if you have any question: bachxvu@gmail.com

Standard
Featured Posts

How-to remove the background of the image

How-to remove the background of the image

Author: Le Hoang Hai

ID: s3298775

Lecturer: George Nguyen

1.     Introduction

In this article, I will show how to remove the background of the image to put into the game by using GIMP.

2.     When should you apply this?

Many images or sprite on the Internet has the background color. It is not flexible to put into our game. That is when you need to remove the background color.

3.     Advantage and disadvantage

Advantage: GIMP is free and lighter compare to Photoshop.

Disadvantage: take time to remove the background with different colors.

4.     Requirement

GIMP 2.8.0

5.     Steps

–          Open the image by GIMP

–          Choose Layer -> Add Alpha Channel.

–          Use Fuzzy Select Tool () and click on the background. The background which has the same color will be selected. Then we press ‘Delete’ button.

–          If the image still has some background left, we will also need to remove them. After that we can cut the image  and resize it.

6.     Reference

http://docs.gimp.org/2.8/en/gimp-layer-alpha-add.html

Standard