Midterm

Halley Huang
4 min readOct 27, 2021

--

— Pac-Man Game

Midterm: https://editor.p5js.org/halley_huang/sketches/tUGXofOvR

My midterm project is a re-creation of the Pac-Man game. The game is inspired by the p5 maze generator.(see the link below) The code is really helpful for me to build a customized map and every time you refresh it, you will get a different map. There are three .js files written for the map, move and the main sketch. Here are some other maze generator ideas I used for the map.

Declare arrays:

The arc shape is used to draw the pacman. The two of them will move with arrow keys and “WASD”. In order to move the two players, I used the ‘switch’ statement to execute different code blocks to control them separately. The two players will get random start position with a loop statement.

By the end of the game, you will see points you get. The first one will be at the top. There is a time countdown at the bottom of the interface.

I have most of the functionality I expected except for the ghosts. If given more time, I would like to add the ghosts in the game and have them move randomly. I would also like to add interaction between the two players. This is an idea I had later on, for example, if the two pacmans run into each other then game over. So they have to move away from one another and eat more food.

References:

Maze generator: https://editor.p5js.org/codingtrain/sketches/EBkm4txSA

JS Dictionary: https://www.w3schools.com/js/js_array_sort.asp

Angrypacman: https://codepen.io/matedemorphy/pen/bREMZJ

— Midterm Proposal

For the midterm project I want to make a recreation of one of my favorite games — the classic Pac-Man in P5. Here is what I have in mind.

My Sketch

How it works: Pac-Man will move with pressing arrow keys to eat the food. There are two sizes of food, big and small. the ghosts are either staying still or moving around within a range. Pac-Man will have three lives. If it touches the ghost then it will lose a life. If three lives are used up then game over. The more food pac-man eats the higher score the player will receive. There should also be a bar to show how many lives left at the top right.

To accomplish this, I will need to draw the map and score board with rectangular and circle shapes and texts. One thing challenging here is to measure and take notes of the distance between blocks and paths corresponding to the size of Pac-Man and the ghosts. Then, I will import jpeg files of the characters in the game then create objects for Pac-Man and the ghosts. Add a count function for documenting the score. The most important part of this project is to define variables and add key and mouse interaction based on the objects (Pac-Man, ghosts, food)to generate collision(when Pac-Man eats food). I also see this as a challenging part because I haven’t done many interactive projects yet. Moving forward, I need to look up more tutorials for this. Luckily, I found this instruction on interactivity that appeared to be helpful for me.(link below)

Here is the pseudo code:

-import jpegs

function draw(){draw the map and score board}

class Pac-Man(){construct pacman class}

--

--