send edited code Main 2 public class Main2 public static vo

send edited code

Main 2

public class Main2 {

   public static void main(String[] args) {

       EZ.initialize(512, 512);

       EZ.addImage(\"metropolis.jpg\", 256, 256);

      

       Hero myHero = new Hero(100,390);

       //HeroPlus mySecondHero = new HeroPlus(100,390);

      

       while(true){

           myHero.processStates();

      

           //mySecondHero.processStates();

           EZ.refreshScreen();

       }

   }

}

Hero Plus

public class HeroPlus {

   EZImage heroStand;

   EZImage heroJump;

   EZImage heroLand;

   EZImage heroHover;

   EZImage heroPunch; // PUNCH

   int posx = 0;

   int posy = 0;

   int heroState = STAND;

  

   static final int STAND = 1;

   static final int JUMP = 2;

   static final int LAND = 3;

   static final int HOVER = 4;

   static final int PUNCH = 5;

   static final int JUMPHEIGHT = 100;

   static final int PUNCHDISTANCE = 50; // PUNCH

   int punchCounter = 0; // PUNCH

   int jumpCounter = 0;

   HeroPlus(int x, int y) {

       posx = x;

       posy = y;

       heroStand = EZ.addImage(\"superstand.png\", posx, posy);

       heroLand = EZ.addImage(\"superland.png\", posx, posy);

       heroJump = EZ.addImage(\"superjump.png\", posx, posy);

       heroHover = EZ.addImage(\"superhover.png\", posx, posy);

       heroPunch = EZ.addImage(\"superpunch.png\", posx, posy); // PUNCH

       hideHero();

       heroStand.show();

   }

   void hideHero() {

       heroStand.hide();

       heroLand.hide();

       heroJump.hide();

       heroHover.hide();

       heroPunch.hide(); // PUNCH

   }

   void positionHero(int x, int y) {

       heroStand.translateTo(x, y);

       heroJump.translateTo(x, y);

       heroLand.translateTo(x, y);

       heroHover.translateTo(x, y);

       heroPunch.translateTo(x, y); // PUNCH

   }

   void processStates() {

       switch (heroState) {

       case STAND:

           if (EZInteraction.wasKeyPressed(\'j\')) {

               heroState = JUMP;

               jumpCounter = 0;

               hideHero();

               heroJump.show();

           }

           break;

       case JUMP:

           jumpCounter++;

           if (EZInteraction.wasKeyPressed(\'p\')) {

               punchCounter = 0;

               hideHero();

               heroPunch.show();

               heroState = PUNCH;

           }

           if (jumpCounter > JUMPHEIGHT) {

               heroState = LAND;

               hideHero();

               heroLand.show();

           } else {

               posy -= 2;

               positionHero(posx, posy);

               if (EZInteraction.wasKeyPressed(\'h\')) {

                   heroState = HOVER;

                   hideHero();

                   heroHover.show();

               }

           }

           break;

       case PUNCH: // PUNCH

           punchCounter++;

           posx += 2;

           positionHero(posx, posy);

           if (punchCounter > PUNCHDISTANCE) {

               heroState = LAND;

               hideHero();

               heroLand.show();

           }

           break;

       case LAND:

           jumpCounter--;

           if (jumpCounter <= 0) {

               heroState = STAND;

               hideHero();

               heroStand.show();

           } else {

               posy += 2;

               positionHero(posx, posy);

               if (EZInteraction.wasKeyPressed(\'h\')) {

                   heroState = HOVER;

                   hideHero();

                   heroHover.show();

               }

           }

           break;

       case HOVER:

           if (EZInteraction.wasKeyPressed(\'l\')) {

               heroState = LAND;

               hideHero();

               heroLand.show();

           }

           break;

       }

   }

}

Solution


public class Main2 {
public static void main(String[] args) {

EZ.initialize(512, 512);
EZ.addImage(\"metropolis.jpg\", 256, 256);
  
// Hero myHero = new Hero(100,390);

HeroPlus mySecondHero = new HeroPlus(100,390);
  
while(true){
//myHero.processStates();
  
mySecondHero.processStates();
EZ.refreshScreen();
}
}

}
class HeroPlus {
EZImage heroStand;
EZImage heroJump;
EZImage heroLand;
EZImage heroHover;
EZImage heroPunch; // PUNCH
int posx = 0;
int posy = 0;
int heroState = STAND;
  
static final int STAND = 1;
static final int JUMP = 2;
static final int LAND = 3;
static final int HOVER = 4;
static final int PUNCH = 5;
static final int JUMPHEIGHT = 100;
static final int PUNCHDISTANCE = 50; // PUNCH

int punchCounter = 0; // PUNCH
int jumpCounter = 0;

HeroPlus(int x, int y) {
posx = x;
posy = y;
heroStand = EZ.addImage(\"superstand.png\", posx, posy);
heroLand = EZ.addImage(\"superland.png\", posx, posy);
heroJump = EZ.addImage(\"superjump.png\", posx, posy);
heroHover = EZ.addImage(\"superhover.png\", posx, posy);
heroPunch = EZ.addImage(\"superpunch.png\", posx, posy); // PUNCH
hideHero();
heroStand.show();
}

void hideHero() {
heroStand.hide();
heroLand.hide();
heroJump.hide();
heroHover.hide();
heroPunch.hide(); // PUNCH
}

void positionHero(int x, int y) {
heroStand.translateTo(x, y);
heroJump.translateTo(x, y);
heroLand.translateTo(x, y);
heroHover.translateTo(x, y);
heroPunch.translateTo(x, y); // PUNCH
}

void processStates() {
switch (heroState) {

case STAND:
if (EZInteraction.wasKeyPressed(\'j\')) {
heroState = JUMP;
jumpCounter = 0;
hideHero();
heroJump.show();
}
break;
case JUMP:
jumpCounter++;
if (EZInteraction.wasKeyPressed(\'p\')) {
punchCounter = 0;
hideHero();
heroPunch.show();
heroState = PUNCH;
}
if (jumpCounter > JUMPHEIGHT) {
heroState = LAND;
hideHero();
heroLand.show();
} else {
posy -= 2;
positionHero(posx, posy);
if (EZInteraction.wasKeyPressed(\'h\')) {
heroState = HOVER;
hideHero();
heroHover.show();
}
}
break;

case PUNCH: // PUNCH
punchCounter++;
posx += 2;
positionHero(posx, posy);
if (punchCounter > PUNCHDISTANCE) {
heroState = LAND;
hideHero();
heroLand.show();
}
break;
case LAND:
jumpCounter--;
if (jumpCounter <= 0) {
heroState = STAND;
hideHero();
heroStand.show();
} else {
posy += 2;
positionHero(posx, posy);
if (EZInteraction.wasKeyPressed(\'h\')) {
heroState = HOVER;
hideHero();
heroHover.show();
}
}
break;
case HOVER:
jumpCounter++;
if (EZInteraction.wasKeyPressed(\'j\')) {
punchCounter = 0;
hideHero();
heroPunch.show();
heroState = JUMP;
}
if (EZInteraction.wasKeyPressed(\'h\')) {
heroState = HOVER;
hideHero();
heroHover.show();
}
if (EZInteraction.wasKeyPressed(\'p\')) {
punchCounter = 0;
hideHero();
heroPunch.show();
heroState = PUNCH;
}
if (EZInteraction.wasKeyPressed(\'l\')) {
heroState = LAND;
hideHero();
heroLand.show();
}
break;
}
}

}

send edited code Main 2 public class Main2 { public static void main(String[] args) { EZ.initialize(512, 512); EZ.addImage(\
send edited code Main 2 public class Main2 { public static void main(String[] args) { EZ.initialize(512, 512); EZ.addImage(\
send edited code Main 2 public class Main2 { public static void main(String[] args) { EZ.initialize(512, 512); EZ.addImage(\
send edited code Main 2 public class Main2 { public static void main(String[] args) { EZ.initialize(512, 512); EZ.addImage(\
send edited code Main 2 public class Main2 { public static void main(String[] args) { EZ.initialize(512, 512); EZ.addImage(\
send edited code Main 2 public class Main2 { public static void main(String[] args) { EZ.initialize(512, 512); EZ.addImage(\
send edited code Main 2 public class Main2 { public static void main(String[] args) { EZ.initialize(512, 512); EZ.addImage(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site