Total members 11895 |It is currently Tue Dec 03, 2024 8:27 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka






 Project Name:   Red Snake 3D
* Programmer:   msi_333
* Type:   Game
* Technology:  Java(J2me)
* IDE:   NetBeans
* Description:   he game is easy to playing.Move the snake to the food.

The 3D graphices concepts are implemented already in java 3D package in j2me so what u have to learn is the API of this classes for example
(Camera,BackGround,Light,Vertixarray,Indexarray,Apperance,Transform,...)

The game contain 3 levels (Hard,Normal,Easy)
The Defferents between these levels are the values of Sleeep.

Attachment:
File comment: Snake 3d j2me project with source code
Red_Snake3D(2).rar [234.34 KiB]
Downloaded 7080 times

Attachment:
File comment: Screen shot of snake 3d
Snake3Dshot.GIF
Snake3Dshot.GIF [ 7.92 KiB | Viewed 23336 times ]

Here is a same codes of it :
Gameloop.java
java code
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.m3g.Background;
import javax.microedition.m3g.Camera;
import javax.microedition.m3g.Graphics3D;
import javax.microedition.m3g.Light;
import javax.microedition.m3g.Transform;

public class GameLoop extends Canvas{

private Graphics3D iG3D;
private Camera iCamera;
private Light iLight;//A scene graph node that represents different kinds of light sources
private float iAngle=-45.0f;
private Background iBackground= new Background();
private Ground myg;
private SnakeBody mybody;
private Snakecube3D[] cubarr;
private SnakeFood skfood;
private boolean gameMode;
private Transform transform;
private boolean gameStarted;
private String[] choices=new String[]{"Easy","Normal","Hard"};
private short ch;
private myThread gameThread;

/** Creates a new instance of myCan */
public GameLoop() {
transform = new Transform();

transform.postTranslate(0.0f,10.0f,0.0f);
transform.postRotate(-35.0f,1.0f,0.0f,0.0f);
/*Camera is looking down with angle 35
*
*/
setCommandListener(new CommandListener() {
public void commandAction(Command command, Displayable displayable) {
if(command.getCommandType()==command.EXIT){
if(!gameMode)
MIDletMain.quitApp();
else {
mybody.GameOver=true;
}
}

}
});
try{
addCommand(new Command("Exit",Command.EXIT,1));
} catch(Exception e){
e.printStackTrace();
}
}



protected void paint(Graphics g) {
if(gameMode) {

if(mybody.GameOver) {
// Game ends
gameMode=false;

}
iG3D.bindTarget(g,true,Graphics3D.TRUE_COLOR | Graphics3D.DITHER);



Transform camtans = new Transform();

iG3D.resetLights();//Resest Lights Computations

iG3D.clear(iBackground);// Refresh the Background
iG3D.addLight(iLight,transform);


camtans.postTranslate(mybody.getXcamera(),mybody.getYcamera(),mybody.getZcamera());
camtans.postRotate(iAngle,1.0f,0.0f,0.0f);
iG3D.setCamera(iCamera,camtans);



iG3D.render(myg.getIVbgd(),myg.getIIbgd(),myg.getIAppearancegd(),myg.getTransform());

if(!mybody.isGamePause()&&gameStarted)
mybody.update(skfood);


for(int i=0;i<mybody.getLen();i++) {
iG3D.render(cubarr[i].getIVbcube(),cubarr[i].getIIbcube(),cubarr[i].getIAppearancecube(),cubarr[i].getTransform());
}
if(!skfood.checkEaten())
iG3D.render(skfood.getIVbcube(),skfood.getIIbcube(),skfood.getIAppearancecube(),skfood.getTransform());



iG3D.releaseTarget();
drawHeader(g);

if(!gameMode) {
gameStarted=false;
// gameMode=false;
try {

Thread.sleep(1000);

gameThread.setGamemode(false);



gameThread=null;//destroy thread;
} catch (InterruptedException ex) {

}
}


} else {
drawList(g);
}
}
public void drawList(Graphics g) {
g.fillRect(0,0,300,300);

g.setColor(0xFF0000);
g.fillRect(40,100+(ch*20),50,15);
g.setColor(0xFFFFFF);//white
for(int i=0;i<choices.length;i++)
g.drawString(choices[i],50,100+(i*20),0);

g.setColor(0xFF0000);
g.fillRect(30,105+(ch*20),10,5);

// g.drawString(choices[i],50,100+(i*20),0);


g.setColor(0x00FF00);
g.drawString("Snake3D Game",60,10,0);


}
public void drawHeader(Graphics g) {
g.setColor(0xFFFF00);

g.drawRect(10,10,60,15);
g.drawString("Score :"+mybody.getScore(),12,10,0);

g.setColor(0x00FF99);
if(mybody.GameOver) {
g.setColor(0xFF0000);
g.drawRect(155,10,70,15);
g.drawString("Game Over",160,10,0);
} else if(mybody.isGamePause()) {
g.drawRect(155,10,70,15);
g.drawString(" Paused",160,10,0);
} else if(gameStarted) {
g.drawRect(155,10,70,15);
g.drawString("Level :"+choices[ch],160,10,0);
} else {
g.drawString("Press any key to start",100,10,0);
}

}
protected void keyPressed(int keyCode) {

short action=(short)getGameAction(keyCode);
if(gameMode) {
if(gameMode)
gameStarted=true;
if(gameStarted) {
/**
* Game Mode
*
**/
if(mybody.canChange) {

if(action==RIGHT) {

mybody.setDirection((short)3);


} else if(action==LEFT) {
mybody.setDirection((short)4);

} else if(action==UP) {

mybody.setDirection((short)1);
} else if(action==DOWN) {

mybody.setDirection((short)2);
}
}

if(action==GAME_A) {
iAngle+=5f;
} else if(action==GAME_B) {
iAngle-=5f;
}
if(action==FIRE) {
mybody.setGamePause(!mybody.isGamePause());

}
}


} else {
/**
* Main Menu
*
**/
if(action==UP) {

if(ch>0)
ch-=1;


} else if(action==DOWN) {

if(ch<2)

ch+=1;

} else if(action==FIRE) {


{
gameMode=true;
gameStarted=false;
SnakeBody.GameOver=false;
SnakeBody.canChange=true;
SnakeBody.GamePause=false;
mybody=new SnakeBody();
skfood=new SnakeFood();
cubarr=mybody.getMyBody();
iG3D=Graphics3D.getInstance();
iCamera= new Camera();

iCamera.setPerspective(100.0f,(float)getWidth()/(float)getHeight(),1.0f,1500.0f);
iLight=new Light();
iLight.setColor(0xFFFFFFFF);
iLight.setIntensity(1.20f);
myg=new Ground();

iBackground.setColor(0x000000);

gameThread=new myThread((short)(230-(ch*70)));
gameThread.start();
mybody.setValue((short)(2*(ch+1)));
}
}
repaint();
}

}

class myThread extends Thread {
private short sleeptime;
private boolean gamemode;
myThread(short time) {
sleeptime=time;
gamemode=true;
}
public void run() {
while(gamemode) {


try {
repaint();
Thread.sleep(sleeptime);
} catch (InterruptedException ex) {
//ex.printStackTrace();
}
}
}

public void setGamemode(boolean gamemode) {
this.gamemode = gamemode;
}

}

}

i hope you like it .



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Can't download.Can any1 help?



Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

how . ? the rar exists , you just must be log in .


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Right,had some problem with DAP.Got it.Thanks.



Author:
Newbie
User avatar Posts: 2
Have thanks: 0 time

updated.


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 5 posts ] 

  Related Posts  to : Snake 3d on mobile (J2me)
 Need Snake Game implemented using J2me on Mobile     -  
 j2me Red Snake 3D     -  
 Snake applet     -  
 Simple Snake Game     -  
 Snake Game 2D (J2SE)     -  
 Snake Java (SE) Game     -  
 need help in java 1.4 snake game project     -  
 What is the J2ME!!!!     -  
 J2ME     -  
 looking for J2ME opportunities     -  



Topic Tags

Java Projects, Java J2ME
cron






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com