📄 erix.java
字号:
/*
* @(#)Erix.java,
*
* Copyright (c) 2001-2004 Sony Ericsson Mobile Communication AB (SEMC).
*
* German Branch
* Heisenbergbogen 1, Aschheim 85609, Munich, Germany.
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* SEMC. ("Confidential Information"). You shall not disclose such
* Confidential Information and shall use it only in accordance with
* the terms of the license agreement you entered into with SEMC.
*
* @author venkat
* @version 1.7, 09/10/2003
*/
package com.sonyericsson.erix;
/**
* The Erix class contains the functionality to implement Erix behavior.
*/
public class Erix {
/**
* Erix Up Direction.
*/
public static final int UP_DIRECTION = 1;
/**
* Erix Down Direction.
*/
public static final int DOWN_DIRECTION = -1;
/**
* Erix Left Direction.
*/
public static final int LEFT_DIRECTION = -2;
/**
* Erix Right Direction.
*/
public static final int RIGHT_DIRECTION = 2;
/**
* Mask Bits where only 0th bit is set.
*/
public static byte ZERO_BIT_SET = 0x01;
/**
* Mask Bits where only 1st bit is set.
*/
public static byte FIRST_BIT_SET = 0x02;
/**
* Mask Bits where only 2nd bit is set.
*/
public static byte SECOND_BIT_SET = 0x04;
/**
* Mask Bits where only 3rd bit is set.
*/
public static byte THIRD_BIT_SET = 0x08;
/**
* Mask Bits where only 4th bit is set.
*/
public static byte FOURTH_BIT_SET = 0x10;
/**
* Mask Bits where only 5th bit is set.
*/
public static byte FIFTH_BIT_SET = 0x20;
/**
* Mask Bits where only 6th bit is set.
*/
public static byte SIXTH_BIT_SET = 0x40;
/**
* Mask Bits where only 7th bit is set.
*/
public static byte SEVENTH_BIT_SET = (byte)0x80;
/**
* Flag that indicates whether Erix is moving or not.
*/
public boolean m_bErixMoving;
/**
* Indicates the direction in which Erix is moving.
*/
public int m_nErixDirection;
/**
* Erix's X Position.
*/
public int m_nErixXPos;
/**
* Erix's Y Position.
*/
public int m_nErixYPos;
/**
* Erix's path bounds is defined by this array.
*/
public short m_arrErixPath[][];
/**
* The number of points in Erix's path.
*/
public int m_nNumberOfVertices;
/**
* Flag that indicates whether Erix is moving along the boundary or within
* the playfield.
*/
public boolean m_bIsErixOnBoundary;
/**
* The start point on the boundary. Erix moves between the boundary start
* point & the boundary end point.
*/
public int m_nErixBoundaryStartPoint;
/**
* The end point on the boundary. Erix moves between the boundary start
* point & the boundary end point.
*/
public int m_nErixBoundaryEndPoint;
/**
* The path bitmap of Erix. Both erix & Enemy check with this bitmap to find
* if Erix's path was crossed.
*/
public byte m_arrPathBitmap[][];
/**
* The counter for counting cycles to be skipped by Erix.
*/
public int m_nDelayCounter;
/**
* The amount of cycles to be skipped by Erix.
*/
public int m_nDelay;
/**
* Flag that indicates whether a key was pressed & remains set until the
* processing was complete.
*/
public boolean m_bKeyPressed;
/**
* Erix's Previous X Position.
*/
private int m_nPrevErixXPos;
/**
* Erix's Previous Y Position.
*/
private int m_nPrevErixYPos;
/**
* Reference to the Engine Object.
*/
//private GameEngine m_objEngine = null;
private GameEngine m_objEngine;
/**
* The maximum number of vertices in Erix's path.
*/
private final int MAX_ERIX_PATH_BOUNDS = 150;
/**
* Erix Constructor.
*/
public Erix(GameEngine objEngine) {
m_objEngine = objEngine;
m_nDelayCounter = 0;
m_nDelay = 0;
m_bErixMoving = false;
m_bKeyPressed = false;
m_nErixXPos = 0;
m_nErixYPos = 0;
m_nPrevErixXPos = -1;
m_nPrevErixYPos = -1;
m_arrErixPath = new short [MAX_ERIX_PATH_BOUNDS][2];
m_nNumberOfVertices = 0;
m_bIsErixOnBoundary = true;
m_arrPathBitmap = new byte[GameEngine.Y_MAX][m_objEngine.m_nColMax];
resetPath();
m_nErixBoundaryStartPoint = -1;
m_nErixBoundaryEndPoint = -1;
}
/**
* This method adds a point into the path data structure of Erix.
* This method would be called whenever Erix's direction of motion changes
* or when Erix starts moving.
*/
public void addBound() {
if(m_nNumberOfVertices == m_arrErixPath.length){
m_objEngine.reallocateTwoDArray(m_arrErixPath, 2);
}
m_arrErixPath[m_nNumberOfVertices][0] = (short)m_nErixXPos;
m_arrErixPath[m_nNumberOfVertices][1] = (short)m_nErixYPos;
updatePathBitmap();
m_nNumberOfVertices++;
}
/**
* This method resets the Path data structure of Erix after completion of a
* move.
*/
public void resetPath(){
m_nNumberOfVertices = 0;
m_nErixBoundaryStartPoint = -1;
m_nErixBoundaryEndPoint = -1;
int nRowMax = GameEngine.Y_MAX;
int nColMax = m_objEngine.m_nColMax;
for (int i = 0;i < nRowMax ; i++){
for (int j = 0; j < nColMax; j++){
m_arrPathBitmap[i][j] = 0;
}
}
}
/**
* This method updates the temporary path bitmap in Erix.
* The temporary path bitmap is used to to mark the path of movement of
* Erix.
* The temporary bitmap is erased and reused everytime Erix moves.
*/
public void updatePathBitmap() {
if(m_bIsErixOnBoundary){
return;
}
int nRowNum = m_nErixYPos;
int nColNum = m_nErixXPos >> 3; //was '/8'
int nBitPosition = m_nErixXPos % 8;
byte bytPathBits = m_arrPathBitmap[nRowNum][nColNum];
switch(nBitPosition){
case 0:
bytPathBits |= ZERO_BIT_SET;
break;
case 1:
bytPathBits |= FIRST_BIT_SET;
break;
case 2:
bytPathBits |= SECOND_BIT_SET;
break;
case 3:
bytPathBits |= THIRD_BIT_SET;
break;
case 4:
bytPathBits |= FOURTH_BIT_SET;
break;
case 5:
bytPathBits |= FIFTH_BIT_SET;
break;
case 6:
bytPathBits |= SIXTH_BIT_SET;
break;
case 7:
bytPathBits |= SEVENTH_BIT_SET;
break;
default:
break;
}
m_arrPathBitmap[nRowNum][nColNum] = bytPathBits;
}
/**
* This method checks if the path of Erix intersects with that of an Enemy
* or Erix itself.
* @return A boolean value specifying if the point intersected with Erix's
* path or not.
*/
public boolean isPathBeingCrossed() {
if(m_bIsErixOnBoundary){
return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -