You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
2.5 KiB
Java
95 lines
2.5 KiB
Java
package Main;
|
|
|
|
import org.newdawn.slick.Animation;
|
|
import org.newdawn.slick.GameContainer;
|
|
import org.newdawn.slick.Graphics;
|
|
import org.newdawn.slick.SlickException;
|
|
import org.newdawn.slick.SpriteSheet;
|
|
import org.newdawn.slick.geom.Rectangle;
|
|
|
|
public class Player {
|
|
|
|
SpriteSheet robot;
|
|
Animation walk_right,walk_left,jump_left,jump_right,stand;
|
|
|
|
int xPos,yPos;
|
|
float xSpd,ySpd;
|
|
private State state;
|
|
boolean isRunningRight, isRunningLeft,isStandingRight, hasFloorContact, isLanded, ballhit;//checks
|
|
char move;//Bewegungsanimationswähler
|
|
|
|
Rectangle collisionarea;//Kollisionsviereck an den Füßen des Roboters
|
|
|
|
void init(GameContainer gc, State gameState , int yPos) throws SlickException{
|
|
|
|
this.yPos = yPos;
|
|
this.state = gameState;
|
|
|
|
robot = new SpriteSheet("Main/robot_sheet_good.png",50,100);
|
|
|
|
|
|
walk_right = new Animation(robot,0,0,6,0,true,200,true);
|
|
walk_left = new Animation(robot,0,1,6,1,true,200,true);
|
|
jump_right = new Animation(robot,0,2,5,2,true,200,true);
|
|
jump_right.setLooping(false);
|
|
jump_left = new Animation(robot,0,3,5,3,true,200,true);
|
|
jump_left.setLooping(false);
|
|
stand = new Animation(robot,0,4,2,4,true,200,true);
|
|
|
|
|
|
xPos = 400;
|
|
|
|
ySpd = 0;
|
|
xSpd = 0;
|
|
|
|
collisionarea = new Rectangle(xPos-15, yPos+20, 35, 20);
|
|
ballhit = false;
|
|
}
|
|
|
|
|
|
void render(GameContainer gc, Graphics g)throws SlickException{
|
|
switch(state.currentState){
|
|
case "titel": break;
|
|
case "start": case "paused":
|
|
//Auswahl der zu rendernden Animation
|
|
switch(move){
|
|
case 0: stand.draw(xPos-24,yPos-50);break;
|
|
case 1:/*Run right*/walk_right.draw(xPos-25, yPos-50); break;
|
|
case 2:/*Run left*/walk_left.draw(xPos-25, yPos-50); break;
|
|
case 3:/*jump right*/jump_right.draw(xPos-25, yPos-50);break;
|
|
case 4:/*jump left*/jump_left.draw(xPos-25, yPos-50);break;
|
|
|
|
}
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
void update(GameContainer gc, float _delta)throws SlickException{
|
|
|
|
//update der Position des Quadrates
|
|
collisionarea = new Rectangle(xPos-15, yPos+20, 35, 20);
|
|
|
|
switch(state.currentState){
|
|
case "paused":break;
|
|
case "start":
|
|
this.xPos += this.xSpd * _delta;
|
|
|
|
this.yPos += this.ySpd * _delta;
|
|
|
|
if(!hasFloorContact)//Gravitation
|
|
this.ySpd += 750.0f * _delta;
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
void setFloorContact(boolean status){
|
|
this.hasFloorContact=status;
|
|
}
|
|
|
|
Rectangle getCollisionarea(){
|
|
return collisionarea;
|
|
}
|
|
} |