SlideShare a Scribd company logo
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;
}
}
}

More Related Content

More from suhshbhosale

What are the major evolutionary trends that developedamong major v.pdf
What are the major evolutionary trends that developedamong major v.pdfWhat are the major evolutionary trends that developedamong major v.pdf
What are the major evolutionary trends that developedamong major v.pdf
suhshbhosale
 
True or falsea. List index values must be integers.b. Lists can.pdf
True or falsea. List index values must be integers.b. Lists can.pdfTrue or falsea. List index values must be integers.b. Lists can.pdf
True or falsea. List index values must be integers.b. Lists can.pdf
suhshbhosale
 
True false correction questions and fill in the blank. Same rules app.pdf
True false correction questions and fill in the blank. Same rules app.pdfTrue false correction questions and fill in the blank. Same rules app.pdf
True false correction questions and fill in the blank. Same rules app.pdf
suhshbhosale
 
Show that all the singular points of the following functions are pol.pdf
Show that all the singular points of the following functions are pol.pdfShow that all the singular points of the following functions are pol.pdf
Show that all the singular points of the following functions are pol.pdf
suhshbhosale
 
The article at those photos groups 20 amino acids into 6 groups acco.pdf
The article at those photos groups 20 amino acids into 6 groups acco.pdfThe article at those photos groups 20 amino acids into 6 groups acco.pdf
The article at those photos groups 20 amino acids into 6 groups acco.pdf
suhshbhosale
 
Studying Viruses can be important because they are often disease .pdf
Studying Viruses can be important because they are often disease .pdfStudying Viruses can be important because they are often disease .pdf
Studying Viruses can be important because they are often disease .pdf
suhshbhosale
 
State true or false with reason (all from Complex Analysis)-(a) P.pdf
State true or false with reason (all from Complex Analysis)-(a) P.pdfState true or false with reason (all from Complex Analysis)-(a) P.pdf
State true or false with reason (all from Complex Analysis)-(a) P.pdf
suhshbhosale
 
Question 16What is a common tactic hackers use to allow themselves.pdf
Question 16What is a common tactic hackers use to allow themselves.pdfQuestion 16What is a common tactic hackers use to allow themselves.pdf
Question 16What is a common tactic hackers use to allow themselves.pdf
suhshbhosale
 
Qualified plan documents can be written to accommodate plan forfeitu.pdf
Qualified plan documents can be written to accommodate plan forfeitu.pdfQualified plan documents can be written to accommodate plan forfeitu.pdf
Qualified plan documents can be written to accommodate plan forfeitu.pdf
suhshbhosale
 
Proteins fold. How WhySolutionANSProtein folding Protein.pdf
Proteins fold. How WhySolutionANSProtein folding Protein.pdfProteins fold. How WhySolutionANSProtein folding Protein.pdf
Proteins fold. How WhySolutionANSProtein folding Protein.pdf
suhshbhosale
 
PLN 360560 Environmental Impact Assessment Homework No. 4 1. An appl.pdf
PLN 360560 Environmental Impact Assessment Homework No. 4 1. An appl.pdfPLN 360560 Environmental Impact Assessment Homework No. 4 1. An appl.pdf
PLN 360560 Environmental Impact Assessment Homework No. 4 1. An appl.pdf
suhshbhosale
 
one of the main design goals for the java programming language is se.pdf
one of the main design goals for the java programming language is se.pdfone of the main design goals for the java programming language is se.pdf
one of the main design goals for the java programming language is se.pdf
suhshbhosale
 
Meyer and colleagues performed three rounds of X-ray crystallography.pdf
Meyer and colleagues performed three rounds of X-ray crystallography.pdfMeyer and colleagues performed three rounds of X-ray crystallography.pdf
Meyer and colleagues performed three rounds of X-ray crystallography.pdf
suhshbhosale
 
Numerous diseases are caused by problems in DNA replication or repai.pdf
Numerous diseases are caused by problems in DNA replication or repai.pdfNumerous diseases are caused by problems in DNA replication or repai.pdf
Numerous diseases are caused by problems in DNA replication or repai.pdf
suhshbhosale
 
In the Mexican swordtail fish, the wild-type color is olive-green. Ot.pdf
In the Mexican swordtail fish, the wild-type color is olive-green. Ot.pdfIn the Mexican swordtail fish, the wild-type color is olive-green. Ot.pdf
In the Mexican swordtail fish, the wild-type color is olive-green. Ot.pdf
suhshbhosale
 
If we maintain a strict biological definition of “species”, H. sapie.pdf
If we maintain a strict biological definition of “species”, H. sapie.pdfIf we maintain a strict biological definition of “species”, H. sapie.pdf
If we maintain a strict biological definition of “species”, H. sapie.pdf
suhshbhosale
 
If taxpayers Monica, Traci , and Phillip are responsible persons in .pdf
If taxpayers Monica, Traci , and Phillip are responsible persons in .pdfIf taxpayers Monica, Traci , and Phillip are responsible persons in .pdf
If taxpayers Monica, Traci , and Phillip are responsible persons in .pdf
suhshbhosale
 
human biologyscientific method projectStep 1 Observe and Genera.pdf
human biologyscientific method projectStep 1 Observe and Genera.pdfhuman biologyscientific method projectStep 1 Observe and Genera.pdf
human biologyscientific method projectStep 1 Observe and Genera.pdf
suhshbhosale
 
I would appreciate help with these questions. Thank you.Question 1.pdf
I would appreciate help with these questions. Thank you.Question 1.pdfI would appreciate help with these questions. Thank you.Question 1.pdf
I would appreciate help with these questions. Thank you.Question 1.pdf
suhshbhosale
 
For settlements, what are the major components of a soil settlment W.pdf
For settlements, what are the major components of a soil settlment W.pdfFor settlements, what are the major components of a soil settlment W.pdf
For settlements, what are the major components of a soil settlment W.pdf
suhshbhosale
 

More from suhshbhosale (20)

What are the major evolutionary trends that developedamong major v.pdf
What are the major evolutionary trends that developedamong major v.pdfWhat are the major evolutionary trends that developedamong major v.pdf
What are the major evolutionary trends that developedamong major v.pdf
 
True or falsea. List index values must be integers.b. Lists can.pdf
True or falsea. List index values must be integers.b. Lists can.pdfTrue or falsea. List index values must be integers.b. Lists can.pdf
True or falsea. List index values must be integers.b. Lists can.pdf
 
True false correction questions and fill in the blank. Same rules app.pdf
True false correction questions and fill in the blank. Same rules app.pdfTrue false correction questions and fill in the blank. Same rules app.pdf
True false correction questions and fill in the blank. Same rules app.pdf
 
Show that all the singular points of the following functions are pol.pdf
Show that all the singular points of the following functions are pol.pdfShow that all the singular points of the following functions are pol.pdf
Show that all the singular points of the following functions are pol.pdf
 
The article at those photos groups 20 amino acids into 6 groups acco.pdf
The article at those photos groups 20 amino acids into 6 groups acco.pdfThe article at those photos groups 20 amino acids into 6 groups acco.pdf
The article at those photos groups 20 amino acids into 6 groups acco.pdf
 
Studying Viruses can be important because they are often disease .pdf
Studying Viruses can be important because they are often disease .pdfStudying Viruses can be important because they are often disease .pdf
Studying Viruses can be important because they are often disease .pdf
 
State true or false with reason (all from Complex Analysis)-(a) P.pdf
State true or false with reason (all from Complex Analysis)-(a) P.pdfState true or false with reason (all from Complex Analysis)-(a) P.pdf
State true or false with reason (all from Complex Analysis)-(a) P.pdf
 
Question 16What is a common tactic hackers use to allow themselves.pdf
Question 16What is a common tactic hackers use to allow themselves.pdfQuestion 16What is a common tactic hackers use to allow themselves.pdf
Question 16What is a common tactic hackers use to allow themselves.pdf
 
Qualified plan documents can be written to accommodate plan forfeitu.pdf
Qualified plan documents can be written to accommodate plan forfeitu.pdfQualified plan documents can be written to accommodate plan forfeitu.pdf
Qualified plan documents can be written to accommodate plan forfeitu.pdf
 
Proteins fold. How WhySolutionANSProtein folding Protein.pdf
Proteins fold. How WhySolutionANSProtein folding Protein.pdfProteins fold. How WhySolutionANSProtein folding Protein.pdf
Proteins fold. How WhySolutionANSProtein folding Protein.pdf
 
PLN 360560 Environmental Impact Assessment Homework No. 4 1. An appl.pdf
PLN 360560 Environmental Impact Assessment Homework No. 4 1. An appl.pdfPLN 360560 Environmental Impact Assessment Homework No. 4 1. An appl.pdf
PLN 360560 Environmental Impact Assessment Homework No. 4 1. An appl.pdf
 
one of the main design goals for the java programming language is se.pdf
one of the main design goals for the java programming language is se.pdfone of the main design goals for the java programming language is se.pdf
one of the main design goals for the java programming language is se.pdf
 
Meyer and colleagues performed three rounds of X-ray crystallography.pdf
Meyer and colleagues performed three rounds of X-ray crystallography.pdfMeyer and colleagues performed three rounds of X-ray crystallography.pdf
Meyer and colleagues performed three rounds of X-ray crystallography.pdf
 
Numerous diseases are caused by problems in DNA replication or repai.pdf
Numerous diseases are caused by problems in DNA replication or repai.pdfNumerous diseases are caused by problems in DNA replication or repai.pdf
Numerous diseases are caused by problems in DNA replication or repai.pdf
 
In the Mexican swordtail fish, the wild-type color is olive-green. Ot.pdf
In the Mexican swordtail fish, the wild-type color is olive-green. Ot.pdfIn the Mexican swordtail fish, the wild-type color is olive-green. Ot.pdf
In the Mexican swordtail fish, the wild-type color is olive-green. Ot.pdf
 
If we maintain a strict biological definition of “species”, H. sapie.pdf
If we maintain a strict biological definition of “species”, H. sapie.pdfIf we maintain a strict biological definition of “species”, H. sapie.pdf
If we maintain a strict biological definition of “species”, H. sapie.pdf
 
If taxpayers Monica, Traci , and Phillip are responsible persons in .pdf
If taxpayers Monica, Traci , and Phillip are responsible persons in .pdfIf taxpayers Monica, Traci , and Phillip are responsible persons in .pdf
If taxpayers Monica, Traci , and Phillip are responsible persons in .pdf
 
human biologyscientific method projectStep 1 Observe and Genera.pdf
human biologyscientific method projectStep 1 Observe and Genera.pdfhuman biologyscientific method projectStep 1 Observe and Genera.pdf
human biologyscientific method projectStep 1 Observe and Genera.pdf
 
I would appreciate help with these questions. Thank you.Question 1.pdf
I would appreciate help with these questions. Thank you.Question 1.pdfI would appreciate help with these questions. Thank you.Question 1.pdf
I would appreciate help with these questions. Thank you.Question 1.pdf
 
For settlements, what are the major components of a soil settlment W.pdf
For settlements, what are the major components of a soil settlment W.pdfFor settlements, what are the major components of a soil settlment W.pdf
For settlements, what are the major components of a soil settlment W.pdf
 

Recently uploaded

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 

Recently uploaded (20)

The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 

send edited codeMain 2public class Main2 {   public static voi.pdf

  • 1. 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;
  • 2. 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();
  • 3. } 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--;
  • 4. 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);
  • 5. 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);
  • 6. 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:
  • 7. 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;
  • 8. 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(); }