- Spieler Attacke, Animation

This commit is contained in:
Max
2026-09-15 19:13:35 +02:00
parent a53a0a22c6
commit 6e7ff8d2eb
23 changed files with 212 additions and 68 deletions
Binary file not shown.
+3 -1
View File
@@ -7,4 +7,6 @@ comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ MyWorld.\r\n\ \r\n
comment2.params=
comment2.target=void\ prepare()
comment2.text=\r\n\ Prepare\ the\ world\ for\ the\ start\ of\ the\ program.\r\n\ That\ is\:\ create\ the\ initial\ objects\ and\ add\ them\ to\ the\ world.\r\n
numComments=3
comment3.params=
comment3.target=void\ act()
numComments=4
+18 -3
View File
@@ -8,7 +8,8 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
*/
public class MyWorld extends World
{
Player1 player1;
Player2 player2;
/**
* Constructor for objects of class MyWorld.
*
@@ -26,9 +27,23 @@ public class MyWorld extends World
*/
private void prepare()
{
player1 player1 = new player1();
player1 = new Player1();
addObject(player1,125,153);
player2 player2 = new player2();
player2 = new Player2();
addObject(player2,429,152);
}
public void act(){
if(player1.attacke()){
if(player1.getX() - player2.getX() < 50 && player1.getX() - player2.getX() > -50 && player1.getY() - player2.getY() < 30 && player1.getY() - player2.getY() > -30){
player2.leben = player2.leben -10;
}
}
if(player2.attacke()){
if(player1.getX() - player2.getX() < 50 && player1.getX() - player2.getX() > -50 && player1.getY() - player2.getY() < 30 && player1.getY() - player2.getY() > -30){
player1.leben = player1.leben -10;
}
}
showText(String.valueOf(player2.leben),300,300);
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 103 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.
+16 -7
View File
@@ -1,13 +1,22 @@
#BlueJ class context
comment0.target=player1
comment0.target=Player1
comment0.text=\r\n\ Write\ a\ description\ of\ class\ player\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=void\ act()
comment1.text=\r\n\ Act\ -\ do\ whatever\ the\ player\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n
comment1.target=Player1()
comment2.params=
comment2.target=void\ bewegung()
comment2.target=void\ act()
comment3.params=
comment3.target=void\ springen()
comment3.target=void\ bewegung()
comment4.params=
comment4.target=void\ gravitation()
numComments=5
comment4.target=void\ springen()
comment5.params=
comment5.target=boolean\ attacke()
comment6.params=
comment6.target=void\ animation1()
comment7.params=
comment7.target=void\ anitmationLaufen()
comment8.params=
comment8.target=void\ gravitation()
comment9.params=
comment9.target=void\ charakter()
numComments=10
+127 -5
View File
@@ -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);
}
}
Binary file not shown.
+10 -7
View File
@@ -1,13 +1,16 @@
#BlueJ class context
comment0.target=player2
comment0.target=Player2
comment0.text=\r\n\ Write\ a\ description\ of\ class\ player\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=void\ act()
comment1.text=\r\n\ Act\ -\ do\ whatever\ the\ player\ wants\ to\ do.\ This\ method\ is\ called\ whenever\r\n\ the\ 'Act'\ or\ 'Run'\ button\ gets\ pressed\ in\ the\ environment.\r\n
comment1.target=Player2()
comment2.params=
comment2.target=void\ bewegung()
comment2.target=void\ act()
comment3.params=
comment3.target=void\ springen()
comment3.target=void\ bewegung()
comment4.params=
comment4.target=void\ gravitation()
numComments=5
comment4.target=void\ springen()
comment5.params=
comment5.target=boolean\ attacke()
comment6.params=
comment6.target=void\ gravitation()
numComments=7
+23 -1
View File
@@ -6,12 +6,19 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
* @author (your name)
* @version (a version number or a date)
*/
public class player2 extends Actor
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;
Player2(){
leben = 100;
}
public void act()
{
bewegung();
@@ -42,6 +49,21 @@ public class player2 extends Actor
}
}
public boolean attacke(){
if(Greenfoot.isKeyDown("e")){
if(System.currentTimeMillis() >= c){
c = System.currentTimeMillis() + 2000;
return true;
}
else{
return false;
}
}
else{
return false;
}
}
public void gravitation(){
if(this.getY() < 370){
setRotation(90);
+15 -16
View File
@@ -1,14 +1,20 @@
#Greenfoot project file
class.MyWorld.image=crumpled-paper.jpg
class.player1.image=man01.png
class.player2.image=man01.png
class.Player1.image=man01.png
class.Player2.image=man01.png
dependency1.from=MyWorld
dependency1.to=Player1
dependency1.type=UsesDependency
dependency2.from=MyWorld
dependency2.to=Player2
dependency2.type=UsesDependency
editor.fx.0.height=737
editor.fx.0.width=814
editor.fx.0.x=151
editor.fx.0.y=86
editor.fx.0.x=117
editor.fx.0.y=30
height=686
package.numDependencies=0
package.numTargets=4
package.numDependencies=2
package.numTargets=3
project.charset=UTF-8
publish.hasSource=false
publish.locked=true
@@ -24,33 +30,26 @@ readme.x=10
readme.y=10
simulation.speed=48
target1.height=70
target1.name=player1
target1.name=Player2
target1.showInterface=false
target1.type=ClassTarget
target1.width=120
target1.x=0
target1.y=0
target2.height=70
target2.name=player2
target2.name=Player1
target2.showInterface=false
target2.type=ClassTarget
target2.width=120
target2.x=0
target2.y=0
target3.height=70
target3.name=startScreen
target3.name=MyWorld
target3.showInterface=false
target3.type=ClassTarget
target3.width=120
target3.x=0
target3.y=0
target4.height=70
target4.name=MyWorld
target4.showInterface=false
target4.type=ClassTarget
target4.width=120
target4.x=0
target4.y=0
version=3.1.0
width=1294
world.lastInstantiated=MyWorld
Binary file not shown.
-7
View File
@@ -1,7 +0,0 @@
#BlueJ class context
comment0.target=startScreen
comment0.text=\r\n\ Write\ a\ description\ of\ class\ startScreen\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=startScreen()
comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ startScreen.\r\n\ \r\n
numComments=2
-21
View File
@@ -1,21 +0,0 @@
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Write a description of class startScreen here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class startScreen extends World
{
/**
* Constructor for objects of class startScreen.
*
*/
public startScreen()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
}
}