Part 1 - agulen/PacmanJava GitHub Wiki
Welcome to the Pacman Java lesson plan! I hope you find this repository useful for learning and and creating a fun & visually rewarding project. Before getting started with coding, you will need to set up a proper Java development environment. To do that, you will need to download and install the latest Java Development Kit and a Java IDE. Java SE 14 was used when this was written. For the IDE, I would recommend Eclipse.
Goal: Render Pacman at the top-left coordinate of the screen
Steps
- Create a
Pacman
class. It should contain:- Member Variables
- An integer for a x-coordinate
- An integer for a y-coordinate
- An Image for a Pacman image
- Functions
- A Pacman constructor to initialize the 3 member variables. In order to load the Pacman image properly, you can load in an image from a file path using
new ImageIcon(<file path here>).getImage()
. If you store the images in animg
folder, then the file path to pass into the ImageIcon constructor would beimg/pacman.jpg
- Getter for each member variable
- A
public void draw()
function to draw Pacman to the screen. You can pass in thegraphics
object fromGame's
paint()
function to draw the Pacman image to the screen. Utilize thegraphics.drawImage()
function too!
- A Pacman constructor to initialize the 3 member variables. In order to load the Pacman image properly, you can load in an image from a file path using
- Member Variables
You are given:
- The
Game
class, which will render a window to the screen for you. Read through the comments to understand how the code works. Try running the program before writing any code to see the window appear. - The
img
folder, which holds all of the necessary images for the project. You only needpacman.jpg
for this part in order to render Pacman.