- Spieler Attacke, Animation
This commit is contained in:
+127
-5
@@ -6,32 +6,59 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
||||
* @author (your name)
|
||||
* @version (a version number or a date)
|
||||
*/
|
||||
public class player1 extends Actor
|
||||
public class Player1 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;
|
||||
|
||||
Player1(){
|
||||
leben = 100;
|
||||
schautNachRechts = true;
|
||||
charakter();
|
||||
}
|
||||
public void act()
|
||||
{
|
||||
bewegung();
|
||||
gravitation();
|
||||
springen();
|
||||
animation1();
|
||||
anitmationLaufen();
|
||||
}
|
||||
|
||||
public void bewegung(){
|
||||
if(Greenfoot.isKeyDown("d")){
|
||||
setRotation(0);
|
||||
move(3);
|
||||
move(5);
|
||||
if(!schautNachRechts && attackPhase == 0){
|
||||
getImage().mirrorHorizontally();
|
||||
schautNachRechts = true;
|
||||
}
|
||||
laeuft = true;
|
||||
}
|
||||
if(Greenfoot.isKeyDown("a")){
|
||||
setRotation(0);
|
||||
move(-3);
|
||||
move(-5);
|
||||
if(schautNachRechts && attackPhase == 0){
|
||||
getImage().mirrorHorizontally();
|
||||
schautNachRechts = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void springen(){
|
||||
if(Greenfoot.isKeyDown("space") && this.getY() > 370 ){
|
||||
if(Greenfoot.isKeyDown("space") && this.getY() > 363 ){
|
||||
for(int i = 12; i > -12; i--){
|
||||
setRotation(270);
|
||||
move(i);
|
||||
@@ -42,12 +69,107 @@ public class player1 extends Actor
|
||||
}
|
||||
}
|
||||
|
||||
public boolean attacke(){
|
||||
if(Greenfoot.isKeyDown("e")){
|
||||
if(System.currentTimeMillis() >= c){
|
||||
|
||||
if (!attacking) {
|
||||
attacking = true;
|
||||
attackPhase = 1;
|
||||
attackTimer = System.currentTimeMillis();
|
||||
|
||||
setImage("1Combo2.png");
|
||||
GreenfootImage image = getImage();
|
||||
image.scale(80, 80);
|
||||
setImage(image);
|
||||
}
|
||||
|
||||
|
||||
c = System.currentTimeMillis() + 1000;
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void animation1(){
|
||||
if (attacking && attackPhase == 1 && System.currentTimeMillis() - attackTimer >= 300) {
|
||||
attackPhase = 2;
|
||||
setImage("2Combo1.png");
|
||||
GreenfootImage image = getImage();
|
||||
image.scale(80, 80);
|
||||
setImage(image);
|
||||
}
|
||||
if (attacking && attackPhase == 2 && System.currentTimeMillis() - attackTimer >= 600) {
|
||||
attacking = false;
|
||||
attackPhase = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void anitmationLaufen(){
|
||||
if(laeuft){
|
||||
if(laufPhase == 0){
|
||||
setImage("RenRun1.png");
|
||||
GreenfootImage image = getImage();
|
||||
image.scale(80, 80);
|
||||
setImage(image);
|
||||
laufPhase = 1;
|
||||
laufTimer = System.currentTimeMillis();
|
||||
}
|
||||
if(laufPhase == 1 && System.currentTimeMillis() - laufTimer >= 50){
|
||||
setImage("RenRun2.png");
|
||||
GreenfootImage image = getImage();
|
||||
image.scale(80, 80);
|
||||
setImage(image);
|
||||
laufPhase = 2;
|
||||
laufTimer = System.currentTimeMillis();
|
||||
}
|
||||
if(laufPhase == 2 && System.currentTimeMillis() - laufTimer >= 50){
|
||||
setImage("RenRun3.png");
|
||||
GreenfootImage image = getImage();
|
||||
image.scale(80, 80);
|
||||
setImage(image);
|
||||
laufPhase = 3;
|
||||
laufTimer = System.currentTimeMillis();
|
||||
}
|
||||
if(laufPhase == 3 && System.currentTimeMillis() - laufTimer >= 50){
|
||||
setImage("RenRun4.png");
|
||||
GreenfootImage image = getImage();
|
||||
image.scale(80, 80);
|
||||
setImage(image);
|
||||
laufPhase = 4;
|
||||
laufTimer = System.currentTimeMillis();
|
||||
}
|
||||
if(laufPhase == 4 && System.currentTimeMillis() - laufTimer >= 50){
|
||||
setImage("2Combo1.png");
|
||||
GreenfootImage image = getImage();
|
||||
image.scale(80, 80);
|
||||
setImage(image);
|
||||
laufPhase = 0;
|
||||
laufTimer = System.currentTimeMillis();
|
||||
laeuft = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void gravitation(){
|
||||
if(this.getY() < 370){
|
||||
if(this.getY() < 363){
|
||||
setRotation(90);
|
||||
move(4);
|
||||
setRotation(0);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void charakter(){
|
||||
setImage("2Combo1.png");
|
||||
GreenfootImage image = getImage();
|
||||
image.scale(80,80);
|
||||
setImage(image);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user