- Not yet done
- Buggy and ugly (but hey its JavaME anyway)
- UGLY!
Created
March 5, 2012 13:17
-
-
Save b1nary/1978270 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ch.seta.awsomepixelship; | |
import java.io.IOException; | |
import java.util.Random; | |
import javax.microedition.lcdui.Canvas; | |
import javax.microedition.lcdui.Graphics; | |
import javax.microedition.lcdui.Image; | |
public class ActionCanvas extends Canvas implements Runnable{ | |
Image player; | |
int p_x = getWidth()/2-15; | |
int p_y = getHeight(); | |
int speed = 1; | |
private String keyValue = ""; | |
private String movement = ""; | |
private Random rand; | |
private Bullet bullet; | |
static final int MAX_GAME_SPEED = 33; | |
static int fps; | |
ActionCanvas(){ | |
rand = new Random(); | |
setFullScreenMode(true); | |
try { | |
player = Image.createImage("/ship.gif"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
bullet = new Bullet(); | |
new Thread(this).start(); | |
} | |
public void run(){ | |
try { | |
while(true){ | |
long starttime = System.currentTimeMillis(); | |
repaint(); | |
serviceRepaints(); | |
Thread.yield(); | |
long exectime = System.currentTimeMillis()-starttime; | |
//if(exectime > MAX_GAME_SPEED){ | |
// Thread.sleep(MAX_GAME_SPEED-(int)exectime); | |
// fps = 1000/MAX_GAME_SPEED; | |
//} else { | |
// fps = (int) (1000/exectime); | |
//} | |
} | |
} catch (Exception e){ | |
System.out.println("ERROR:FUUU "+e); | |
} | |
} | |
public void paint(Graphics g){ | |
if((System.currentTimeMillis()+"").endsWith("1")){ | |
g.setColor(0, 144, 0); | |
} else { | |
g.setColor(0, 0, 0); | |
} | |
g.fillRect(0, 0, getWidth(), getHeight()); | |
g.drawImage(player, p_x, p_y, Graphics.TOP | Graphics.LEFT); | |
g.setColor(255,0,0); | |
g.drawString(fps+""+p_x, 10, 10, Graphics.TOP | Graphics.LEFT); | |
g.drawString(bullet.count()+"", 20, 20, Graphics.TOP|Graphics.LEFT); | |
this.move(); | |
} | |
public void move(){ | |
if(movement.equals("LEFT")){ | |
p_x -= speed; | |
if(p_x < 0){ p_x = 0; } | |
} else if(movement.equals("RIGHT")){ | |
p_x += speed; | |
if(p_x > (getWidth()-30)){ p_x = (getWidth()-30); } | |
} | |
if(movement.equals("UP")){ | |
bullet.newone(p_x,p_y); | |
} | |
} | |
protected void keyPressed(int keyCode){ | |
keyValue = getKeyName(keyCode); | |
movement = keyValue; | |
} | |
protected void keyReleased(int keyCode){ | |
movement = ""; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ch.seta.awsomepixelship; | |
import java.io.IOException; | |
import java.util.Hashtable; | |
import javax.microedition.lcdui.Image; | |
public class Bullet { | |
static int MAX_BULLET = 4; | |
private Image[] bullet = new Image[5]; | |
Hashtable bullets = new Hashtable(); | |
Bullet(){ | |
try { | |
bullet[0] = Image.createImage("/bullet/bullet1.gif"); | |
bullet[1] = Image.createImage("/bullet/bullet2.gif"); | |
bullet[2] = Image.createImage("/bullet/bullet3.gif"); | |
bullet[3] = Image.createImage("/bullet/bullet4.gif"); | |
bullet[4] = Image.createImage("/bullet/bullet5.gif"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void newone(int p_x, int p_y) { | |
int[] arr = new int[2]; | |
arr[0] = p_x; | |
arr[1] = p_y; | |
bullets.put(bullets.size()+"", arr); | |
} | |
public int count(){ | |
return bullets.size(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ch.seta.awsomepixelship; | |
import javax.microedition.midlet.MIDlet; | |
import javax.microedition.lcdui.Display; | |
public class Main extends MIDlet{ | |
public void startApp(){ | |
Display display = Display.getDisplay(this); | |
ActionCanvas ac = new ActionCanvas(); | |
display.setCurrent(ac); | |
} | |
public void pauseApp(){} | |
public void destroyApp(boolean unconditional){} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment