📄 bomberplayer.java
字号:
}
}
}
/** if it can move now */
if (canMove) {
/** clear original spot */
clear = true; game.paintImmediately(x,
y - halfSize, width, height);
/** move up or down */
y += oy;
/** refresh the sprite */
clear = false; game.paintImmediately(x,
y - halfSize, width, height);
}
}
/** if it can move */
if (canMove) {
/** clear original spot */
clear = true; game.paintImmediately(x,
y - halfSize, width, height);
/** move right */
x += (size / 4);
/** refresh the sprite */
clear = false; game.paintImmediately(x,
y - halfSize, width, height);
}
/** if it can't move */
else {
moving = false;
/** refresh the sprite */
game.paintImmediately(x,
y - halfSize, width, height);
}
}
/** if up key is down */
else if ((currentDirKeyDown & BUP) > 0) {
state = UP;
canMove = false;
/** if north slot is empty */
canMove = (y % size != 0 || (x % size == 0 &&
(map.grid[x >> shiftCount][(y >> shiftCount) - 1]
<= BomberMap.NOTHING)));
/** if it can't move */
if (!canMove) {
int ox = 0;
/** see if it's a bit to the left */
for (ox = -offset; ox < 0; ox += (size / 4)) {
/** and the north slot is empty */
if ((x + ox) % size == 0 &&
map.grid[(x + ox) >> shiftCount]
[(y >> shiftCount) - 1] <= BomberMap.NOTHING) {
canMove = true; break;
}
}
/** if it still can't move */
if (!canMove) {
/** see if it's a bit to the right */
for (ox = (size / 4); ox <= offset; ox += (size / 4)) {
/** and the north block is empty */
if ((x + ox) % size == 0 &&
map.grid[(x + ox) >> shiftCount]
[(y >> shiftCount) - 1]
<= BomberMap.NOTHING) {
canMove = true; break;
}
}
}
/** if it can move */
if (canMove) {
/** clear original block */
clear = true; game.paintImmediately(x,
y - halfSize, width, height);
/** move right */
x += ox;
/** refresh the sprite */
clear = false; game.paintImmediately(x,
y - halfSize, width, height);
}
}
/** if it can move */
if (canMove) {
/** clear original block */
clear = true; game.paintImmediately(x,
y - halfSize, width, height);
/** move up */
y -= (size / 4);
/** refresh the sprite */
clear = false; game.paintImmediately(x,
y - halfSize, width, height);
}
/** if it can't move */
else {
/** refresh the block */
moving = false; game.paintImmediately(x,
y - halfSize, width, height);
}
}
/** if the down is is down */
else if ((currentDirKeyDown & BDOWN) > 0)
{
state = DOWN;
canMove = false;
/** if the south block is empty */
canMove = (y % size != 0 || (x % size == 0 &&
(map.grid[x >> shiftCount][(y >> shiftCount) + 1]
<= BomberMap.NOTHING)));
/** if it can't move */
if (!canMove) {
int ox = 0;
/** see if it's a bit to the west */
for (ox = -offset; ox < 0; ox += (size / 4)) {
/** and the south block is empty */
if ((x + ox) % size == 0 &&
map.grid[(x + ox) >> shiftCount]
[(y >> shiftCount) + 1] <= BomberMap.NOTHING) {
canMove = true; break;
}
}
/** if it still can't move */
if (!canMove) {
/** see if it's a bit to the east */
for (ox = (size / 4); ox <= offset;
ox += (size / 4)) {
/** and the south block is empty */
if ((x + ox) % size == 0 &&
map.grid[(x + ox) >> shiftCount]
[(y >> shiftCount) + 1]
<= BomberMap.NOTHING) {
canMove = true; break;
}
}
}
/** if it can move now */
if (canMove) {
/** clear orignal block */
clear = true; game.paintImmediately(x,
y - halfSize, width, height);
/** move left or right */
x += ox;
/** refresh the sprite */
clear = false; game.paintImmediately(x,
y - halfSize, width, height);
}
}
/** if it can move now */
if (canMove) {
/** clear original spot */
clear = true; game.paintImmediately(x,
y - halfSize, width, height);
/** move down */
y += (size / 4);
/** refresh the sprite */
clear = false; game.paintImmediately(x,
y - halfSize, width, height);
}
/** if it can't move */
else {
/** refresh the sprite */
moving = false; game.paintImmediately(x,
y - halfSize, width, height);
}
}
}
}
/** if all keys are up */
else if (!isExploding && !isDead && lastState != keyPressed)
{
/** reset frame to 0 */
frame = 0;
moving = false;
/** refresh sprite */
game.paintImmediately(x, y - halfSize, width, height);
lastState = keyPressed;
}
/** if it's exploding */
else if (!isDead && isExploding)
{
/** if frame reached 4 then it's dead */
if (frame >= 4) isDead = true;
/** refresh sprite */
game.paintImmediately(x, y - halfSize, width, height);
/** rotate frame count */
frame = (frame + 1) % 5;
}
/** if it's dead */
else if (isDead)
{
/** clear the block */
clear = true;
game.paintImmediately(x, y - halfSize, width, height);
/** exit the loop */
break;
}
/** see if the player stepped on any bonuses */
/** try normal position */
if (map.bonusGrid[x >> shiftCount][y >> shiftCount] != null)
{ bx = x; by = y; }
/** try a bit to the north */
else if (map.bonusGrid[x >> shiftCount][(y + halfSize)
>> shiftCount] != null) { bx = x; by = y + halfSize; }
/** try a bit to the left */
else if (map.bonusGrid[(x + halfSize) >> shiftCount][y
>> shiftCount] != null) { bx = x + halfSize; by = y; }
/** if the player did step on a bonus */
if (bx != 0 && by != 0) {
map.bonusGrid[bx >> shiftCount][by >>
shiftCount].giveToPlayer(playerNo);
bx = by = 0;
}
/** if it's dead, then exit the loop */
if (isDead) break;
/** delay 65 milliseconds */
try { sleep(65); } catch (Exception e) { }
}
interrupt();
}
/**
* Drawing method.
*/
public void paint(Graphics graphics)
{
Graphics g = graphics;
/** if java runtime is Java 2 */
if (Main.J2) { paint2D(graphics); }
/** if java runtime isn't Java 2 */
else {
/** if player isn't dead and clear mode isn't on */
if (!isDead && !clear)
{
/** if moving */
if (moving)
/** draw the animating image */
g.drawImage(sprites[playerNo - 1][state][frame],
x, y - (BomberMain.size / 2), width, height, null);
/** if not moving */
else
/** draw the still image */
g.drawImage(sprites[playerNo - 1][state][0],
x, y - (BomberMain.size / 2), width, height, null);
}
}
}
/**
* Drawing method for Java 2's Graphics2D
* @param graphics graphics handle
*/
public void paint2D(Graphics graphics) {
Graphics2D g2 = (Graphics2D)graphics;
/** set the rendering hints */
g2.setRenderingHints((RenderingHints)hints);
/** if player isn't dead and clear mode isn't on */
if (!isDead && !clear)
{
/** if moving */
if (moving)
/** draw the animating image */
g2.drawImage(sprites[playerNo - 1][state][frame],
x, y - (BomberMain.size / 2), width, height, null);
/** if not moving */
else
/** draw the still image */
g2.drawImage(sprites[playerNo - 1][state][0],
x, y - (BomberMain.size / 2), width, height, null);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -