number fall

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

Re: number fall

Postby DevelopmentTeam » Fri Jul 25, 2008 8:59 am

Its simple, you either use a single big image that you can repeat or small tiles.

We usually go with single image when there is a scenery and cannot be used a tile, In this case, we draw the image first at x position 0 and then -1 and then -2 and repeat the same image to fill the screen.

When you use tiles it the same way you have to move.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Re: number fall

Postby rahul7star » Sun Jul 27, 2008 2:46 am

hi back to preveious problm.......well now i made an array to hold chars...but m getting typical output ..Ljava.lang.String;@fe37eeb0
[Ljava.lang.String;@17f93429
[Ljava.lang.String;@f57f4513
[Ljava.lang.String;@6c37b19
[Ljava.lang.String;@12118c79
[Ljava.lang.String;@12aff8be
[Ljava.lang.String;@194ad684

whenever i print "newArray" value

////////// here is the code//
import java.util.Random;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import java.io.IOException;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class MainGame extends Canvas implements Runnable {

/* CONSTANTS */
/* Speed rate at which numbers fall */
private static final int FALL_SPEED = 5;
/* Value range of numbers on screen 0-*+1 */
private static final int VALUE_RANGE = 10;
/* Screen refresh rate */
private static final long FRAME_SPEED = 100;
public static int[] map;


private String chars[][]={{"Hellow"},{"HeLL"},{"Heo"},{"ello"},{"Hello"},{"Hello"},{"Hello"},{"Hello"},{"Hello"}};//"Welcome","hit","kick","fine","soccer","play","huge","welcome","matrix","gone","dog"};
/* VARIABLES */
//char array[][] ={{'h','e','l','l','0'},{'w','o','l','d'},{'w','o','l','d'},{'w','o','l','d'},{'w','o','l','d'},{'w','o','l','d'}};
String newArray[];
int width = getWidth();
int height = getHeight();
boolean startGame = false;
boolean newNumber = true;
int x = 0;
int y = 0;

Graphics g;
private Image image;

Random generatorNumber = new Random();
Random generatorX = new Random();
int randomNumber = 0;
int randomX = 0;
// = initialize the array as you desire
private int nextChar = 0;
//private char newArray[];

public void start() {

//map=new int[32 * 32];
/*generatorNumber.setSeed(System.currentTimeMillis());;
generatorX.setSeed(System.currentTimeMillis());*/
startGame = true;
final Thread t = new Thread(this);
t.start();
}

public void run() {
while (startGame) {
// System.out.println(charPos[0]);

goGoGo(g);

repaint();
serviceRepaints();

}
}

private void goGoGo(Graphics g) {

if (y > height) {
y = 0;
// copying first Word "hello"
[b]newArray = new String[chars[0].length];
for(int i=0;i<chars[0].length;i++)
newArray[i] = chars[0][i];
System.out.println(newArray);[/b]

// copying second Word "world"
newArray = new String[chars[1].length];
for(int i=0;i<chars[1].length;i++)
newArray[i] = chars[1][i];
System.out.println(newArray);




newArray = new String[chars[2].length];
for(int i=0;i<chars[2].length;i++)
newArray[i] = chars[2][i];
/////////
newArray = new String[chars[3].length];
for(int i=0;i<chars[3].length;i++)
newArray[i] = chars[3][i];
System.out.println(newArray);
newArray = new String[chars[4].length];
for(int i=0;i<chars[4].length;i++)
newArray[i] = chars[4][i];
System.out.println(newArray);

/*charPos[nextChar]=chars[randomNumber];
nextChar++;*/


newNumber = true;
}

if (newNumber) {

randomNumber = generatorNumber.nextInt();
randomNumber = Math.abs(generatorNumber.nextInt());// This creates
// the random
// number...
randomNumber = randomNumber % VALUE_RANGE;// This is a number
// between 0-100

randomX = generatorX.nextInt();
randomX = Math.abs(generatorX.nextInt());// This creates the random*/
// number...
randomX = 0 + randomX % width;// This is a number between 0-100

newNumber = false;
}


y += FALL_SPEED;
}

public void paint(Graphics g) {


g.setColor(0x000000);
g.fillRect(0, 0, width, height);


g.setColor(0xffffff);
g.drawString(""+chars[randomNumber][0], randomX, y, Graphics.TOP|Graphics.LEFT);
g.drawString(""+newArray, 100,200, Graphics.TOP|Graphics.LEFT);

try {

Thread.sleep(FRAME_SPEED);
} catch (InterruptedException e) {

e.printStackTrace();
}

}
}
rahul7star
Regular User
 
Posts: 84
Joined: Fri Aug 17, 2007 11:22 am

Re: number fall

Postby DevelopmentTeam » Sun Jul 27, 2008 10:02 am

g.drawString(""+newArray, 100,200, Graphics.TOP|Graphics.LEFT);

This line cannot draw the entire string. You have to draw the characters each separately in a for loop.

Code: Select all
for(int i = 0; i < newArray.length; i++) {
    g.drawString(""+newArray[i], 100,200, Graphics.TOP|Graphics.LEFT);[/b]
}


I think you are confusing with the character and string in this case. We still don't have a clue if you are trying to make characters fall or string.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Previous

Return to J2ME Games

Who is online

Users browsing this forum: No registered users and 2 guests

cron