4d98573c7c
- walk Animation fertig
252 lines
8.0 KiB
Java
252 lines
8.0 KiB
Java
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|
|
|
/**
|
|
* Write a description of class player here.
|
|
*
|
|
* @author (your name)
|
|
* @version (a version number or a date)
|
|
*/
|
|
public class Player2 extends Actor
|
|
{
|
|
/**
|
|
* Act - do whatever the player wants to do. This method is called whenever
|
|
* the 'Act' or 'Run' button gets pressed in the environment.
|
|
*/
|
|
|
|
public int leben;
|
|
long c;
|
|
boolean schautNachRechts;
|
|
long attackTimer = 0;
|
|
int attackPhase = 0;
|
|
boolean attacking = false;
|
|
int laufPhase = 0;
|
|
long laufTimer = 0;
|
|
boolean laeuft = false;
|
|
int charakter;
|
|
|
|
Player2(int pCharakter){
|
|
charakter = pCharakter;
|
|
leben = 100;
|
|
schautNachRechts = false;
|
|
charakter();
|
|
}
|
|
public void act()
|
|
{
|
|
bewegung();
|
|
gravitation();
|
|
springen();
|
|
animation1();
|
|
anitmationLaufen();
|
|
}
|
|
|
|
public void bewegung(){
|
|
if(Greenfoot.isKeyDown("right")){
|
|
setRotation(0);
|
|
move(5);
|
|
if(!schautNachRechts && attackPhase == 0){
|
|
getImage().mirrorHorizontally();
|
|
schautNachRechts = true;
|
|
}
|
|
laeuft = true;
|
|
}
|
|
if(Greenfoot.isKeyDown("left")){
|
|
setRotation(0);
|
|
move(-5);
|
|
if(schautNachRechts && attackPhase == 0){
|
|
getImage().mirrorHorizontally();
|
|
schautNachRechts = false;
|
|
}
|
|
laeuft = true;
|
|
}
|
|
}
|
|
|
|
public void springen(){
|
|
if(Greenfoot.isKeyDown("up") && this.getY() > 289 ){
|
|
for(int i = 12; i > -12; i--){
|
|
setRotation(270);
|
|
move(i);
|
|
setRotation(0);
|
|
Greenfoot.delay(1);
|
|
bewegung();
|
|
}
|
|
}
|
|
}
|
|
|
|
public boolean attacke(){
|
|
if(Greenfoot.isKeyDown(".")){
|
|
if(System.currentTimeMillis() >= c){
|
|
|
|
if (!attacking) {
|
|
attacking = true;
|
|
attackPhase = 1;
|
|
attackTimer = System.currentTimeMillis();
|
|
|
|
if(schautNachRechts){
|
|
setImage("1Combo2.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
}
|
|
else{
|
|
setImage("1Combo2.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
getImage().mirrorHorizontally();
|
|
}
|
|
}
|
|
|
|
|
|
c = System.currentTimeMillis() + 500;
|
|
return true;
|
|
}
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void animation1(){
|
|
if (attacking && attackPhase == 1 && System.currentTimeMillis() - attackTimer >= 200) {
|
|
if(schautNachRechts){
|
|
attackPhase = 2;
|
|
setImage("2Combo1.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
}
|
|
else{
|
|
attackPhase = 2;
|
|
setImage("2Combo1.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
getImage().mirrorHorizontally();
|
|
}
|
|
}
|
|
if (attacking && attackPhase == 2 && System.currentTimeMillis() - attackTimer >= 300) {
|
|
attacking = false;
|
|
attackPhase = 0;
|
|
}
|
|
}
|
|
|
|
public void anitmationLaufen(){
|
|
if(laeuft){
|
|
if(schautNachRechts){
|
|
if(laufPhase == 0){
|
|
setImage("RenRun1.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
laufPhase = 1;
|
|
laufTimer = System.currentTimeMillis();
|
|
}
|
|
if(laufPhase == 1 && System.currentTimeMillis() - laufTimer >= 100){
|
|
setImage("RenRun2.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
laufPhase = 2;
|
|
laufTimer = System.currentTimeMillis();
|
|
}
|
|
if(laufPhase == 2 && System.currentTimeMillis() - laufTimer >= 100){
|
|
setImage("RenRun3.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
laufPhase = 3;
|
|
laufTimer = System.currentTimeMillis();
|
|
}
|
|
if(laufPhase == 3 && System.currentTimeMillis() - laufTimer >= 100){
|
|
setImage("RenRun4.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
laufPhase = 4;
|
|
laufTimer = System.currentTimeMillis();
|
|
}
|
|
if(laufPhase == 4 && System.currentTimeMillis() - laufTimer >= 100){
|
|
setImage("2Combo1.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
laufPhase = 0;
|
|
laufTimer = System.currentTimeMillis();
|
|
laeuft = false;
|
|
}
|
|
}
|
|
else{
|
|
if(laufPhase == 0){
|
|
setImage("RenRun1.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
getImage().mirrorHorizontally();
|
|
laufPhase = 1;
|
|
laufTimer = System.currentTimeMillis();
|
|
}
|
|
if(laufPhase == 1 && System.currentTimeMillis() - laufTimer >= 100){
|
|
setImage("RenRun2.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
getImage().mirrorHorizontally();
|
|
laufPhase = 2;
|
|
laufTimer = System.currentTimeMillis();
|
|
}
|
|
if(laufPhase == 2 && System.currentTimeMillis() - laufTimer >= 100){
|
|
setImage("RenRun3.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
getImage().mirrorHorizontally();
|
|
laufPhase = 3;
|
|
laufTimer = System.currentTimeMillis();
|
|
}
|
|
if(laufPhase == 3 && System.currentTimeMillis() - laufTimer >= 100){
|
|
setImage("RenRun4.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
getImage().mirrorHorizontally();
|
|
laufPhase = 4;
|
|
laufTimer = System.currentTimeMillis();
|
|
}
|
|
if(laufPhase == 4 && System.currentTimeMillis() - laufTimer >= 100){
|
|
setImage("2Combo1.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160, 160);
|
|
setImage(image);
|
|
getImage().mirrorHorizontally();
|
|
laufPhase = 0;
|
|
laufTimer = System.currentTimeMillis();
|
|
laeuft = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void gravitation(){
|
|
if(this.getY() < 290){
|
|
setRotation(90);
|
|
move(4);
|
|
setRotation(0);
|
|
|
|
}
|
|
}
|
|
|
|
public void charakter(){
|
|
if(charakter == 1){
|
|
setImage("2Combo1.png");
|
|
GreenfootImage image = getImage();
|
|
image.scale(160,160);
|
|
setImage(image);
|
|
getImage().mirrorHorizontally();
|
|
}
|
|
|
|
}
|
|
}
|