📄 fishman.java
字号:
package cn.zucc.mmf.harpoon;import cn.zucc.mmf.harpoon.util.ImageUtilities;import javax.microedition.lcdui.*;import javax.microedition.lcdui.game.*;public class Fishman extends Sprite { //public static final int UP = 1; //public static final int DOWN = 2; public static final int LEFT = 3; public static final int RIGHT = 4; public int totalMoney=0; public int currScore=0; public int m_dx, m_dy; public int m_moveX, m_moveY; public int m_dxPrevious; private int m_minX, m_minY; private int m_maxX, m_maxY; private static final String IMAGE_FILENAME = "/fisherman2.png"; private static final int IMAGE_COLUMNS = 2; private static final int IMAGE_ROWS = 1; private static final int IMAGE_X_MARGIN = 2; private static final int IMAGE_Y_MARGIN = 4; private static final int ANIM_FACE = 0; //private static final int ANIM_TAIL = 1; //private static final int ANIM_RIGHT = 2; //private static final int ANIM_HIT = 3; private static final int m_animations[][] = { {0,0,0,0,1,1,1,1}, {1}, {2,2,3,3,3}, {4} }; private static Image m_fishImage; public int ProtectState=0; public int PoisonState=0; public boolean PoisonReleaseState=false; public boolean NormalState=true; public boolean RestState=false; public int ResetState=0; public long protectTime=0; public long poisonTime=0; public long resetTime=0; public int screenwidth=0; public int screenheight=0; public Fork fork; public static final Image getImage() { try { m_fishImage = ImageUtilities.createImage(IMAGE_FILENAME); } catch (Exception e) { System.err.println("Error loading fish image"); return null; } return m_fishImage; } public Fishman(int screenwidth, int screenheight){ super(getImage(), m_fishImage.getWidth() / IMAGE_COLUMNS, m_fishImage.getHeight() / IMAGE_ROWS); try { Image image = ImageUtilities.createImage("/fork.png"); fork = new Fork(image); fork.setVisible(true); fork.defineReferencePixel(fork.getWidth() / 2, fork.getHeight() / 2); this.screenwidth = screenwidth; this.screenheight = screenheight; int width = getWidth(); int height = getHeight(); //set fish movement m_moveX = width / 20; //m_moveY = height / 4; //set movement boundaries //m_minX = -width/2; m_minX = 0; m_maxX = screenwidth - width; //m_maxY = screenheight - height; //center fish on screen center setPosition((screenwidth - width) / 2, 15); //setPosition(screenwidth,screenheight); setFrameSequence(m_animations[ANIM_FACE]); defineReferencePixel(width / 2, height / 2); fork.defineCollisionRectangle(fork.getWidth() / 2, fork.getHeight() / 2, fork.getWidth(), fork.getHeight()); } catch (Exception ex) { ex.printStackTrace(); } } public void swim(int direction) { switch (direction) { /*case UP: m_dy = -m_moveY; break; case DOWN: m_dy = m_moveY; break;*/ case LEFT: m_dx = -m_moveX; break; case RIGHT: m_dx = m_moveX; break; } } public void move() { int x = getX() + m_dx; int y = getY() + m_dy; //Check boundaries if (x <=m_minX) { x = m_minX; } else if (x >= m_maxX) { x = m_maxX; } /*if (y < m_minY) { y = m_minY; } else if (y > m_maxY) { y = m_maxY; }*/ setPosition(x, y); //If direction changed, set left/right sequence & transform if (m_dxPrevious != m_dx) { m_dxPrevious = m_dx; if (m_dx < 0) { //setTransform(TRANS_MIRROR); //setFrameSequence(m_animations[ANIM_RIGHT]); } else if (m_dx > 0) { setTransform(TRANS_NONE); //setFrameSequence(m_animations[ANIM_RIGHT]); } } //else { nextFrame(); //} m_dx = 0; m_dy = 0; } public void changeState(){ /* if(PoisonState==1){ PoisonState++; this.poisonTime=System.currentTimeMillis(); m_moveY=m_moveY/2; m_moveX=m_moveX/2; } if(PoisonReleaseState==true){ m_moveY=getHeight()/4; m_moveX=getWidth()/4; this.PoisonReleaseState=false; } if(ResetState==1){ ResetState++; this.resetTime=System.currentTimeMillis(); int[] start=new int[]{0}; this.move(); this.swim(RIGHT); setPosition(-this.getWidth()*3,screenheight-60); this.setVisible(false); } if(ProtectState==1){ ProtectState++; this.protectTime=System.currentTimeMillis(); } if(NormalState==true){ this.setVisible(true); } if(RestState==true){ }*/ } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -