initial commit
This commit is contained in:
62
src/player/Player.java
Executable file
62
src/player/Player.java
Executable file
@@ -0,0 +1,62 @@
|
||||
package player;
|
||||
|
||||
import static sjgs.core.jython.Jython.pi;
|
||||
import static sjgs.utils.pyutils.PyUtils.java2py;
|
||||
import java.awt.Graphics2D;
|
||||
import org.python.core.PyFunction;
|
||||
import org.python.core.PyObject;
|
||||
import core.Main;
|
||||
import jmp3.MP3Player;
|
||||
import sjgs.base_objects.PlayerBase;
|
||||
import sjgs.physics.structs.CollisionResponse;
|
||||
|
||||
public class Player extends PlayerBase {
|
||||
|
||||
public static final float WALKING_SPEED = Main.TILE_SIZE/6, JUMPING_SPEED = -Main.TILE_SIZE/2;
|
||||
public static final float WIDTH = Main.TILE_SIZE, HEIGHT = Main.TILE_SIZE;
|
||||
|
||||
private boolean prone, lookingUp;
|
||||
private final PyObject self;
|
||||
private final int playerMaxHealth;
|
||||
|
||||
public Player(final float x, final float y) {
|
||||
super(x, y, WIDTH, HEIGHT);
|
||||
self = java2py(this);
|
||||
playerMaxHealth = 7;
|
||||
setHealth(playerMaxHealth);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
final CollisionResponse response = applyPhysics();
|
||||
response.discard();
|
||||
manageJumping();
|
||||
runAnimations.__call__(self);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(final Graphics2D g2d) { PlayerRenderer.render(this, g2d); }
|
||||
|
||||
@Override
|
||||
protected void destroy() { removeFromHandler(); }
|
||||
|
||||
// ------------------------- GETTERS AND SETTERS ------------------------------------------------------------------------------//
|
||||
public boolean getProne() { return prone; }
|
||||
public boolean getLookingUp() { return lookingUp; }
|
||||
public void setProne(final boolean prone) { this.prone = prone; }
|
||||
public void setLookingUp(final boolean lookingUp) { this.lookingUp = lookingUp; }
|
||||
public PyObject getSelf() { return self; }
|
||||
// ------------------------ END GETTERS AND SETTERS ---------------------------------------------------------------------------//
|
||||
|
||||
public void jump() {
|
||||
setVelY(Player.JUMPING_SPEED); setJumping(true);
|
||||
MP3Player.play("/jump_sound.mp3");
|
||||
}
|
||||
public float getPlayerMaxHealth() { return playerMaxHealth; }
|
||||
|
||||
private static PyFunction runAnimations;
|
||||
public static void createPyFuncs() { runAnimations = pi.get("run_player_animations", PyFunction.class); }
|
||||
}
|
||||
Reference in New Issue
Block a user