⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 playersprite.java

📁 男人下一百层手机游戏
💻 JAVA
字号:
package src;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;

/**
 * Main Sprite / Player Inherits the MIDP 2.0 Sprite class
 */
public class PlayerSprite extends Sprite {
	private static final int MOVE = 3;

	private int x, y;

	private int scnWidth, scnHeight;

	private int frameWidth, frameHeight;

	private int frame;

	private int lives;

	private ManMap map;

	public PlayerSprite(Image image, int frameWidth, int frameHeight,
			int scnWidth, int scnHeight) throws Exception {
		super(image, frameWidth, frameHeight);
		x = frameWidth / 2;
		y = frameHeight / 2;
		this.scnWidth = scnWidth;
		this.scnHeight = scnHeight;
		this.frameWidth = frameWidth;
		this.frameHeight = frameHeight;
		this.frame = 1;
		this.lives = 3;

	}

	public void startPosition() {
		setPosition(scnWidth / 2, 10);
	}

	public void moveLeft() {
		getXY();
		if (x - MOVE > 0)
			move(MOVE * -1, 0);
	}

	public void moveRight() {
		getXY();
		if (x + MOVE + frameWidth < scnWidth)
			move(MOVE, 0);
	}

	public void moveUp() {
		getXY();
		if (y - MOVE > 0) {
			move(0, MOVE * -1);
		} else if (y - MOVE < 0) {
			ManDownScreen.gameover = true;
		}
	}

	public void moveDown() {
		getXY();

		if (y + MOVE + frameHeight <= scnHeight) {
			move(0, MOVE * 3);
		} else {
			ManDownScreen.gameover = true;
		}
	}

	public void display(Graphics g) {
		this.setFrame(frame);
		this.paint(g);
	}

	public int getLives() {
		return lives;
	}

	public void setLives(int lives) {
		this.lives = lives;
	}

	public void getXY() {
		x = getX();
		y = getY();

	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -