Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m making a game in java that sort of moves like flappy bird. In this code so

ID: 3775014 • Letter: I

Question

I'm making a game in java that sort of moves like flappy bird. In this code so far there is a moving background with a picture of trump in the middle. I would like for you to make another class that will make bird go up if you press w and move down if you press s. Please answer correctly because I posted this twice and both people did not even use code that will make the bird go up or down. I only want one simple class code that will allow the picture of trump in this class to be able to move.

public class flappy {

   public static void main(String[] args) {

       // Setup EZ graphics system.

       EZ.initialize(1000,500); // PIXEL picture element

      

       EZImage sky1 = EZ.addImage("skyrepeat.jpg", 500,255);

       EZImage sky2 = EZ.addImage("skyrepeat.jpg", 1500, 255);

      

  

       EZImage[] trumpPictures = new EZImage[1];

       for (int i=0; i < 1; i++){

           trumpPictures[i]= EZ.addImage("bird.png", 500, i*100+250);//i starts at 0. use 50 to determine the first vertical position

       } //variable is no longer in scope

      

              

       while (true) {

           for (int i = 0; i < 1; i++){

          

           sky1.moveForward(-1);

           sky2.moveForward(-1);

          

  

          

           if (sky1.getXCenter() < -500) {

                   sky1.moveForward(2000);

           }

           if (sky2.getXCenter() < -500) {

                   sky2.moveForward(2000);

           }

  

      

           EZ.refreshScreen();

       }

   }

   }}

Explanation / Answer

package com.edu4java.samplegame; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.RenderingHints; import javax.swing.JFrame; import javax.swing.JPanel; @SuppressWarnings("serial") public class Game extends JPanel { int x = 0; int y = 0; private void moveBall() { x = x + 1; y = y + 1; } @Override public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.fillOval(x, y, 30, 30); } public static void main(String[] args) throws InterruptedException { JFrame frame = new JFrame("Sample Frame"); Game game = new Game(); frame.add(game); frame.setSize(300, 400); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); while (true) { game.moveBall(); game.repaint(); Thread.sleep(10); } } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote