Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sk.tuke.oop.game.actors;
- import sk.tuke.oop.framework.Actor;
- import sk.tuke.oop.framework.Animation;
- import sk.tuke.oop.framework.Input;
- import sk.tuke.oop.framework.World;
- import sk.tuke.oop.game.commands.MoveDown;
- import sk.tuke.oop.game.commands.MoveLeft;
- import sk.tuke.oop.game.commands.MoveRight;
- import sk.tuke.oop.game.commands.MoveUp;
- import sk.tuke.oop.game.items.Energy;
- public class Ripley implements Actor, Movable {
- private int x;
- private int y;
- private int width;
- private int height;
- private Animation playerAnimation;
- private World world;
- private String name;
- private MoveUp moveUp = new MoveUp(1);
- private MoveDown moveDown = new MoveDown(1);
- private MoveRight moveRight = new MoveRight(1);
- private MoveLeft moveLeft = new MoveLeft(1);
- public Ripley() {
- this.x = 100;
- this.y = 100;
- this.playerAnimation = new Animation("resources/sprites/player.png", 32, 32, 100);
- this.playerAnimation.setPingPong(true);
- }
- @Override
- public int getX() {
- return this.x;
- }
- @Override
- public int getY() {
- return this.y;
- }
- @Override
- public int getWidth() {
- return this.width;
- }
- @Override
- public int getHeight() {
- return this.height;
- }
- @Override
- public void setPosition(int x, int y) {
- this.x = x;
- this.y = y;
- }
- @Override
- public Animation getAnimation() {
- return this.playerAnimation;
- }
- @Override
- public void setAnimation(Animation animation) {
- this.playerAnimation = animation;
- }
- @Override
- public void act() {
- for(Actor actor : getWorld())
- if(this.intersects(actor))
- System.out.println("haha");
- Input input = Input.getInstance();
- if(input.isKeyPressed(Input.Key.ESCAPE))
- System.exit(0);
- else if(input.isKeyDown(Input.Key.UP)) {
- this.moveUp.execute(this);
- }
- else if(input.isKeyDown(Input.Key.LEFT)) {
- this.moveLeft.execute(this);
- }
- else if(input.isKeyDown(Input.Key.RIGHT)) {
- this.moveRight.execute(this);
- }
- else if(input.isKeyDown(Input.Key.DOWN)) {
- this.moveDown.execute(this);
- }
- else
- this.playerAnimation.stop();
- }
- @Override
- public boolean intersects(Actor actor) {
- if(Math.abs(this.x - actor.getX()) < this.getWidth() && Math.abs(this.y - actor.getY()) < this.getHeight())
- return true;
- else
- return false;
- }
- @Override
- public void addedToWorld(World world) {
- this.world = world;
- }
- @Override
- public World getWorld() {
- return this.world;
- }
- @Override
- public String getName() {
- return this.name;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement