Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b842a7b75 | |||
| 67db7a5e48 | |||
| 6e7ff8d2eb |
@@ -7,4 +7,6 @@ comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ MyWorld.\r\n\ \r\n
|
|||||||
comment2.params=
|
comment2.params=
|
||||||
comment2.target=void\ prepare()
|
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
|
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
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|||||||
*/
|
*/
|
||||||
public class MyWorld extends World
|
public class MyWorld extends World
|
||||||
{
|
{
|
||||||
|
Player1 player1;
|
||||||
|
Player2 player2;
|
||||||
/**
|
/**
|
||||||
* Constructor for objects of class MyWorld.
|
* Constructor for objects of class MyWorld.
|
||||||
*
|
*
|
||||||
@@ -26,9 +27,23 @@ public class MyWorld extends World
|
|||||||
*/
|
*/
|
||||||
private void prepare()
|
private void prepare()
|
||||||
{
|
{
|
||||||
player1 player1 = new player1();
|
player1 = new Player1();
|
||||||
addObject(player1,125,153);
|
addObject(player1,125,153);
|
||||||
player2 player2 = new player2();
|
player2 = new Player2();
|
||||||
addObject(player2,429,152);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 119 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 121 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 103 KiB |
|
After Width: | Height: | Size: 110 KiB |
|
After Width: | Height: | Size: 124 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 112 KiB |
|
After Width: | Height: | Size: 13 KiB |
@@ -1,13 +1,22 @@
|
|||||||
#BlueJ class context
|
#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
|
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.params=
|
||||||
comment1.target=void\ act()
|
comment1.target=Player1()
|
||||||
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
|
|
||||||
comment2.params=
|
comment2.params=
|
||||||
comment2.target=void\ bewegung()
|
comment2.target=void\ act()
|
||||||
comment3.params=
|
comment3.params=
|
||||||
comment3.target=void\ springen()
|
comment3.target=void\ bewegung()
|
||||||
comment4.params=
|
comment4.params=
|
||||||
comment4.target=void\ gravitation()
|
comment4.target=void\ springen()
|
||||||
numComments=5
|
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
|
||||||
|
|||||||
@@ -6,32 +6,59 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|||||||
* @author (your name)
|
* @author (your name)
|
||||||
* @version (a version number or a date)
|
* @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
|
* Act - do whatever the player wants to do. This method is called whenever
|
||||||
* the 'Act' or 'Run' button gets pressed in the environment.
|
* 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()
|
public void act()
|
||||||
{
|
{
|
||||||
bewegung();
|
bewegung();
|
||||||
gravitation();
|
gravitation();
|
||||||
springen();
|
springen();
|
||||||
|
animation1();
|
||||||
|
anitmationLaufen();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void bewegung(){
|
public void bewegung(){
|
||||||
if(Greenfoot.isKeyDown("d")){
|
if(Greenfoot.isKeyDown("d")){
|
||||||
setRotation(0);
|
setRotation(0);
|
||||||
move(3);
|
move(5);
|
||||||
|
if(!schautNachRechts && attackPhase == 0){
|
||||||
|
getImage().mirrorHorizontally();
|
||||||
|
schautNachRechts = true;
|
||||||
|
}
|
||||||
|
laeuft = true;
|
||||||
}
|
}
|
||||||
if(Greenfoot.isKeyDown("a")){
|
if(Greenfoot.isKeyDown("a")){
|
||||||
setRotation(0);
|
setRotation(0);
|
||||||
move(-3);
|
move(-5);
|
||||||
|
if(schautNachRechts && attackPhase == 0){
|
||||||
|
getImage().mirrorHorizontally();
|
||||||
|
schautNachRechts = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void springen(){
|
public void springen(){
|
||||||
if(Greenfoot.isKeyDown("space") && this.getY() > 370 ){
|
if(Greenfoot.isKeyDown("space") && this.getY() > 363 ){
|
||||||
for(int i = 12; i > -12; i--){
|
for(int i = 12; i > -12; i--){
|
||||||
setRotation(270);
|
setRotation(270);
|
||||||
move(i);
|
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(){
|
public void gravitation(){
|
||||||
if(this.getY() < 370){
|
if(this.getY() < 363){
|
||||||
setRotation(90);
|
setRotation(90);
|
||||||
move(4);
|
move(4);
|
||||||
setRotation(0);
|
setRotation(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void charakter(){
|
||||||
|
setImage("2Combo1.png");
|
||||||
|
GreenfootImage image = getImage();
|
||||||
|
image.scale(80,80);
|
||||||
|
setImage(image);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
#BlueJ class context
|
#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
|
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.params=
|
||||||
comment1.target=void\ act()
|
comment1.target=Player2()
|
||||||
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
|
|
||||||
comment2.params=
|
comment2.params=
|
||||||
comment2.target=void\ bewegung()
|
comment2.target=void\ act()
|
||||||
comment3.params=
|
comment3.params=
|
||||||
comment3.target=void\ springen()
|
comment3.target=void\ bewegung()
|
||||||
comment4.params=
|
comment4.params=
|
||||||
comment4.target=void\ gravitation()
|
comment4.target=void\ springen()
|
||||||
numComments=5
|
comment5.params=
|
||||||
|
comment5.target=boolean\ attacke()
|
||||||
|
comment6.params=
|
||||||
|
comment6.target=void\ gravitation()
|
||||||
|
numComments=7
|
||||||
|
|||||||
@@ -6,12 +6,19 @@ import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
|
|||||||
* @author (your name)
|
* @author (your name)
|
||||||
* @version (a version number or a date)
|
* @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
|
* Act - do whatever the player wants to do. This method is called whenever
|
||||||
* the 'Act' or 'Run' button gets pressed in the environment.
|
* the 'Act' or 'Run' button gets pressed in the environment.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
public int leben;
|
||||||
|
long c;
|
||||||
|
|
||||||
|
Player2(){
|
||||||
|
leben = 100;
|
||||||
|
}
|
||||||
public void act()
|
public void act()
|
||||||
{
|
{
|
||||||
bewegung();
|
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(){
|
public void gravitation(){
|
||||||
if(this.getY() < 370){
|
if(this.getY() < 370){
|
||||||
setRotation(90);
|
setRotation(90);
|
||||||
|
|||||||
@@ -1,27 +1,20 @@
|
|||||||
#Greenfoot project file
|
#Greenfoot project file
|
||||||
class.MyWorld.image=crumpled-paper.jpg
|
class.MyWorld.image=crumpled-paper.jpg
|
||||||
class.Pfeil.image=cursor.png
|
class.Player1.image=man01.png
|
||||||
class.player1.image=man01.png
|
class.Player2.image=man01.png
|
||||||
class.player2.image=man01.png
|
dependency1.from=MyWorld
|
||||||
dependency1.from=StartWorld
|
dependency1.to=Player1
|
||||||
dependency1.to=Pfeil
|
|
||||||
dependency1.type=UsesDependency
|
dependency1.type=UsesDependency
|
||||||
dependency2.from=StartWorld
|
dependency2.from=MyWorld
|
||||||
dependency2.to=MyWorld
|
dependency2.to=Player2
|
||||||
dependency2.type=UsesDependency
|
dependency2.type=UsesDependency
|
||||||
dependency3.from=MyWorld
|
|
||||||
dependency3.to=player1
|
|
||||||
dependency3.type=UsesDependency
|
|
||||||
dependency4.from=MyWorld
|
|
||||||
dependency4.to=player2
|
|
||||||
dependency4.type=UsesDependency
|
|
||||||
editor.fx.0.height=737
|
editor.fx.0.height=737
|
||||||
editor.fx.0.width=814
|
editor.fx.0.width=814
|
||||||
editor.fx.0.x=194
|
editor.fx.0.x=117
|
||||||
editor.fx.0.y=77
|
editor.fx.0.y=30
|
||||||
height=686
|
height=686
|
||||||
package.numDependencies=4
|
package.numDependencies=2
|
||||||
package.numTargets=6
|
package.numTargets=3
|
||||||
project.charset=UTF-8
|
project.charset=UTF-8
|
||||||
publish.hasSource=false
|
publish.hasSource=false
|
||||||
publish.locked=true
|
publish.locked=true
|
||||||
@@ -37,49 +30,28 @@ readme.x=10
|
|||||||
readme.y=10
|
readme.y=10
|
||||||
simulation.speed=48
|
simulation.speed=48
|
||||||
target1.height=70
|
target1.height=70
|
||||||
target1.name=player1
|
target1.name=Player2
|
||||||
target1.showInterface=false
|
target1.showInterface=false
|
||||||
target1.type=ClassTarget
|
target1.type=ClassTarget
|
||||||
target1.width=120
|
target1.width=120
|
||||||
target1.x=0
|
target1.x=0
|
||||||
target1.y=0
|
target1.y=0
|
||||||
target2.height=70
|
target2.height=70
|
||||||
target2.name=player2
|
target2.name=Player1
|
||||||
target2.showInterface=false
|
target2.showInterface=false
|
||||||
target2.type=ClassTarget
|
target2.type=ClassTarget
|
||||||
target2.width=120
|
target2.width=120
|
||||||
target2.x=0
|
target2.x=0
|
||||||
target2.y=0
|
target2.y=0
|
||||||
target3.height=70
|
target3.height=70
|
||||||
target3.name=Pfeil
|
target3.name=MyWorld
|
||||||
target3.showInterface=false
|
target3.showInterface=false
|
||||||
target3.type=ClassTarget
|
target3.type=ClassTarget
|
||||||
target3.width=120
|
target3.width=120
|
||||||
target3.x=0
|
target3.x=0
|
||||||
target3.y=0
|
target3.y=0
|
||||||
target4.height=70
|
|
||||||
target4.name=StartWorld
|
|
||||||
target4.showInterface=false
|
|
||||||
target4.type=ClassTarget
|
|
||||||
target4.width=120
|
|
||||||
target4.x=0
|
|
||||||
target4.y=0
|
|
||||||
target5.height=70
|
|
||||||
target5.name=startScreen
|
|
||||||
target5.showInterface=false
|
|
||||||
target5.type=ClassTarget
|
|
||||||
target5.width=120
|
|
||||||
target5.x=0
|
|
||||||
target5.y=0
|
|
||||||
target6.height=70
|
|
||||||
target6.name=MyWorld
|
|
||||||
target6.showInterface=false
|
|
||||||
target6.type=ClassTarget
|
|
||||||
target6.width=120
|
|
||||||
target6.x=0
|
|
||||||
target6.y=0
|
|
||||||
version=3.1.0
|
version=3.1.0
|
||||||
width=1294
|
width=1294
|
||||||
world.lastInstantiated=StartWorld
|
world.lastInstantiated=MyWorld
|
||||||
xPosition=0
|
xPosition=0
|
||||||
yPosition=0
|
yPosition=0
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||