📄 player.java
字号:
package com.brackeen.javagamebook.tilegame.sprites;
import com.brackeen.javagamebook.graphics.Animation;
/**
The Player.
*/
public class Player extends Creature {
private static final float JUMP_SPEED = -.95f;
private boolean onGround;
public Player(Animation left, Animation right,
Animation deadLeft, Animation deadRight)
{
super(left, right, deadLeft, deadRight);
}
public void collideHorizontal() {
setVelocityX(0);
}
public void collideVertical() {
// check if collided with ground
if (getVelocityY() > 0) {
onGround = true;
}
setVelocityY(0);
}
public void setY(float y) {
// check if falling
if (Math.round(y) > Math.round(getY())) {
onGround = false;
}
super.setY(y);
}
public void wakeUp() {
// do nothing
}
/**
Makes the player jump if the player is on the ground or
if forceJump is true.
*/
public void jump(boolean forceJump) {
if (onGround || forceJump) {
onGround = false;
setVelocityY(JUMP_SPEED);
}
}
public float getMaxSpeed() {
return 0.5f;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -