Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package sk.tuke.oop.game.actors.ripley;
- import sk.tuke.oop.framework.Actor;
- import sk.tuke.oop.framework.Animation;
- import sk.tuke.oop.framework.Input;
- import sk.tuke.oop.framework.Item;
- import sk.tuke.oop.game.actions.Drop;
- import sk.tuke.oop.game.actions.Fire;
- import sk.tuke.oop.game.actions.Move;
- import sk.tuke.oop.game.actions.Shift;
- import sk.tuke.oop.game.actions.Take;
- import sk.tuke.oop.game.actions.Use;
- import sk.tuke.oop.game.actors.Body;
- import sk.tuke.oop.game.actors.Cooler;
- import sk.tuke.oop.game.actors.openables.ExitDoor;
- import sk.tuke.oop.game.actors.openables.LockedDoor;
- import sk.tuke.oop.game.actors.openables.Locker;
- import sk.tuke.oop.game.items.Hammer;
- import sk.tuke.oop.game.items.Usable;
- import sk.tuke.oop.game.items.Wrench;
- public class Running implements RipleyState {
- private Ripley ripley;
- private Input input = Input.getInstance();
- private Move move;
- private boolean callBreak;
- private Animation animation = new Animation("sprites/player.png", 32, 32, 100);
- public Running(Ripley ripley){
- ripley.setAnimation(animation);
- ripley.getAnimation().setPingPong(true);
- this.ripley = ripley;
- callBreak = false;
- move = new Move(ripley,2,ripley.getX(),ripley.getY());
- }
- private void moveRipleyUp() {
- if (input.isKeyDown(Input.Key.UP))
- move = new Move(ripley, 2, 0, -1);
- }
- private void moveRipleyDown(){
- if (input.isKeyDown(Input.Key.DOWN))
- move = new Move(ripley, 2, 0, 1);
- }
- private void moveRipleftLeft(){
- if (input.isKeyDown(Input.Key.LEFT))
- move = new Move(ripley, 2, -1, 0);
- }
- private void moveRipleyRight(){
- if (input.isKeyDown(Input.Key.RIGHT))
- move = new Move(ripley, 2, 1, 0);
- }
- private void moveRipleyLeftUp(){
- if (input.isKeyDown(Input.Key.LEFT) && input.isKeyDown(Input.Key.UP))
- move = new Move(ripley, 2, -1, -1);
- }
- private void moveRipleyRightUp(){
- if (input.isKeyDown(Input.Key.RIGHT) && input.isKeyDown(Input.Key.UP))
- move = new Move(ripley, 2, 1, -1);
- }
- private void moveRipleyLeftDown(){
- if (input.isKeyDown(Input.Key.LEFT) && input.isKeyDown(Input.Key.DOWN))
- move = new Move(ripley, 2, -1, 1);
- }
- private void moveRipleyRightDown(){
- if (input.isKeyDown(Input.Key.RIGHT) && input.isKeyDown(Input.Key.DOWN))
- move = new Move(ripley, 2, 1, 1);
- }
- private void moveRipley(){
- moveRipleftLeft();
- moveRipleyDown();
- moveRipleyUp();
- moveRipleyRight();
- moveRipleyLeftDown();
- moveRipleyRightDown();
- moveRipleyLeftUp();
- moveRipleyRightUp();
- }
- private void ripleyBehaviour(){
- if (!input.isKeyDown(Input.Key.UP) && !input.isKeyDown(Input.Key.DOWN) && !input.isKeyDown(Input.Key.LEFT) && !input.isKeyDown(Input.Key.RIGHT)) {
- ripley.getAnimation().stop();
- }
- else {
- ripley.getAnimation().start();
- ripley.getAnimation().setPingPong(true);
- move.act();
- }
- }
- private void ripleyIsUsingItem(Actor actor){
- if(actor instanceof Cooler && input.isKeyPressed(Input.Key.E) && ripley.getBackpack().peek() instanceof Hammer){
- ((Cooler) actor).useBy(ripley);
- ripley.getBackpack().remove((Item) ripley.getBackpack().peek());
- }
- }
- private void openTheDoor(Use use, Actor actor){
- if(((ExitDoor) actor).isOpen() && !callBreak) {
- use.execute();
- callBreak = true;
- }
- else if(!((ExitDoor) actor).isOpen() && !callBreak) {
- use.execute();
- callBreak = true;
- }
- }
- private void ripleyCooler(Use use,Actor actor){
- if(actor instanceof Cooler && input.isKeyPressed(Input.Key.E) && ripley.getBackpack().peek() instanceof Wrench && !callBreak){
- use.execute();
- ripley.getBackpack().remove(ripley.getBackpack().peek());
- callBreak = true;
- }
- }
- private void lockedDoorAction(Use use,Actor actor){
- if(actor instanceof LockedDoor && input.isKeyPressed(Input.Key.E) && !((LockedDoor) actor).isLocked() && !callBreak ){
- use.execute();
- callBreak = true;
- }
- }
- private void lockerAction(Use use, Actor actor){
- if(actor instanceof Locker && input.isKeyPressed(Input.Key.E) && !callBreak ){
- use.execute();
- callBreak = true;
- }
- }
- private void finalAction(Use use, Actor actor){
- if(input.isKeyPressed(Input.Key.E) && !(actor instanceof Cooler) && !callBreak ){
- use.execute();
- callBreak = true;
- }
- }
- private void exitAction(Use use, Actor actor){
- if(actor instanceof ExitDoor && input.isKeyPressed(Input.Key.E) && !callBreak ){
- openTheDoor(use,actor);
- callBreak = true;
- }
- }
- private void ripleyAllActors(){
- for(Actor actor : ripley.getWorld()) {
- if (ripley.intersects(actor) && actor instanceof Usable && !(actor instanceof Ripley)) {
- Use use = new Use(actor,ripley);
- lockerAction(use,actor);
- ripleyIsUsingItem(actor);
- ripleyCooler(use,actor);
- lockedDoorAction(use,actor);
- exitAction(use,actor);
- finalAction(use,actor);
- if(callBreak){
- callBreak = false;
- break;
- }
- }
- }
- }
- @Override
- public void act() {
- Fire fire = new Fire(ripley);
- ripleyBehaviour();
- moveRipley();
- ripleyAllActors();
- takeIt();
- useIt();
- hitIt(fire);
- dropIt();
- shifIt();
- exit();
- }
- private void takeIt(){
- if(input.isKeyPressed(Input.Key.ENTER)) {
- for(Actor actor : ripley.getWorld()) {
- if (ripley.intersects(actor) && actor instanceof Item) {
- // System.out.println(actor);
- Take<Item> take = new Take<Item>(ripley.getBackpack(), (Item)actor);
- take.execute();
- // world.removeActor(actor);
- break;
- }
- }
- }
- }
- private void useIt(){
- if(input.isKeyPressed(Input.Key.U)) {
- for(Actor actor : ripley.getWorld()) {
- if (ripley.intersects(actor) && actor instanceof Body) {
- ripley.useBy(actor);
- break;
- }
- }
- }
- }
- private void exit(){
- if(input.isKeyPressed(Input.Key.ESCAPE)){
- System.exit(0);
- }
- }
- private void shifIt(){
- if(input.isKeyPressed(Input.Key.S)) {
- Shift shift = new Shift(ripley.getBackpack());
- shift.execute();
- }
- }
- private void dropIt(){
- if(input.isKeyPressed(Input.Key.BACK)) {
- Drop<Item> drop = new Drop<Item>(ripley.getBackpack(),ripley.getWorld(),ripley.getX(),ripley.getY());
- drop.execute();
- }
- }
- private void hitIt(Fire fire){
- if(input.isKeyPressed(Input.Key.SPACE)){
- fire.execute();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement