package map;
import java.io.*;
import javax.microedition.lcdui.*;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2010</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
public class Displayable1
extends Canvas
implements Runnable {
Image role[] = new Image[4];
Graphics g;
int role_x = 0;
int role_y = 0;
int role_x_pos = 0;
int role_y_pos = 0;
Role m_role = new Role();
public static int currentX = 0;
public static int currentY = 0;
Draw draw = new Draw();
public Displayable1() {
init();
new Thread(this).start();
}
public void init() {
try {
for (int i = 0; i < 3; i++) {
role[i] = Image.createImage(Image.createImage("/role.png"), 0, 31 * i,
45, 31, 0);
}
role[3] = Image.createImage(Image.createImage("/role.png"), 0, 61, 45, 31,
2);
}
catch (IOException ex) {
System.out.println("+++");
}
}
public void paint(Graphics g) {
g.setColor(0);
g.setClip(0, 0, Draw.Screen_Width, Draw.Screen_Height);
g.fillRect(0, 0, Draw.Screen_Width, Draw.Screen_Height);
draw.paintMap(g, currentX, currentY);
draw.paintObject(g, currentX, currentY);
m_role.update();
m_role.paint(g);
}
public void keyPressed(int n) {
if (n == 54) { //right
m_role.dir = 3;
if (m_role.role_x >= 124) {
if (currentX < 33 - (Draw.Screen_Width / 16 + 1)) {
currentX += 1;
if (!m_role.checkPhy()) {
currentX -= 1;
}
}
else {
m_role.role_x += 8;
if (!m_role.checkPhy()) {
m_role.role_x -= 8;
}
if (m_role.role_x > 232) {
m_role.role_x = 232;
}
}
}
else {
m_role.role_x += 8;
if (!m_role.checkPhy()) {
m_role.role_x -= 8;
}
}
}
if (n == 52) { //left
m_role.dir = 2;
if (m_role.role_x < 124) {
if (currentX <= 33 - (Draw.Screen_Width / 16 + 1)) {
if (currentX > 0) {
currentX -= 1;
if (!m_role.checkPhy()) {
currentX += 1;
}
}
else {
m_role.role_x -= 8;
if (!m_role.checkPhy()) {
m_role.role_x += 8;
}
if (m_role.role_x < 8) {
m_role.role_x = 8;
}
}
}
}
else {
m_role.role_x -= 8;
if (!m_role.checkPhy()) {
m_role.role_x += 8;
}
}
}
if (n == 50) { //up
m_role.dir = 1;
if (m_role.role_y < 150) {
if (currentY <= 26 - (Draw.Screen_Height / 16 + 1)) {
if (currentY > 0) {
currentY -= 1;
if (!m_role.checkPhy()) {
currentY += 1;
}
}
else {
m_role.role_y -= 8;
if (!m_role.checkPhy()) {
m_role.role_y += 8;
}
if (m_role.role_y < 15) {
m_role.role_y = 15;
}
}
}
}
else {
m_role.role_y -= 8;
if (!m_role.checkPhy()) {
m_role.role_y += 8;
}
}
}
if (n == 56) { //down
m_role.dir = 0;
if (m_role.role_y >= 150) {
if (currentY < 26 - (Draw.Screen_Height / 16 + 1)) {
currentY += 1;
if (!m_role.checkPhy()) {
currentY -= 1;
}
}
else {
m_role.role_y += 8;
if (!m_role.checkPhy()) {
m_role.role_y -= 8;
}
if (m_role.role_y > 305) {
m_role.role_y = 305;
}
}
}
else {
m_role.role_y += 8;
if (!m_role.checkPhy()) {
m_role.role_y -= 8;
}
}
}
}
/**
* run
*/
public void run() {
while (true) {
try {
repaint();
}
catch (Exception e) {}
}
}
}