Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

COSC 2336 Data Structures and Algorithms Assignment Add the following features to our Pac-man game that we implemented to review the material from programming I

COSC 2336 Data Structures and Algorithms Assignment

Add the following features to our Pac-man game that we implemented to review the material from programming I & II:

from random import randint # Global Variables TITLE = 'Review' BLOCK_SIZE = 64 WORLD_SIZE = 10 # Screen is 10 x 11 blocks WIDTH = WORLD_SIZE*BLOCK_SIZE HEIGHT = (WORLD_SIZE+1)*BLOCK_SIZE displayGrid = True # False: do not show grid, True: show grid ghosts = [] for i in range(4): g = Actor("ghost" + str(i) + ".png") ghosts.append(g) g.x = (4.5 + i) * BLOCK_SIZE g.y = 5.5 * BLOCK_SIZE

square = Actor("gridbox.png", anchor=("left","top")) square.x = 0.0 square.y = 0.0 pacman = Actor("pacman.png") pacman.x = BLOCK_SIZE/2 pacman.y = BLOCK_SIZE/2

def drawGrid(): for j in range(WORLD_SIZE): square.y = j*BLOCK_SIZE for i in range(WORLD_SIZE): square.x = i*BLOCK_SIZE square.draw() def drawGhosts(): #for i in range(len (ghosts)): #ghosts[i].draw() for a in ghosts: a.draw()

def draw(): screen.clear() screen.draw.text("Position:" + str(pacman.x)+"," + str(pacman.y), topleft=(2*BLOCK_SIZE, 10*BLOCK_SIZE), color="yellow", fontsize=40) if displayGrid: drawGrid() pacman.draw() drawGhosts() def on_key_up(key): if key == keys.LEFT: # pacman.x = pacman.x - BLOCK_SIZE can also be used pacman.x -= BLOCK_SIZE elif key == keys.RIGHT: pacman.x += BLOCK_SIZE elif key == keys.UP: pacman.y -= BLOCK_SIZE elif key == keys.DOWN: pacman.y += BLOCK_SIZE def move(g): rNumber = randint(1,100) if rNumber == 100: xDir = randint(-1,1) g.x = g.x + xDir * BLOCK_SIZE yDir = randint(-1,1) g.y = g.y + yDir * BLOCK_SIZE

def update(): for g in ghosts: move(g)

1. Our Pac-man, and the ghosts can move outside the boundary of the screen. Limit the movements of all the characters inside the screen. This can be done by preventing the movement from happening if a step takes the character outside the screen.

2. Assign the four ghosts different colors using ghost0.png, ghost1.png, ghost2.png, and ghost3.png. This was optional in Lab 0, but mandatory in Assignment 1.

3. Add a new property to Pac-man called invincible. Initially, the value should be false.

4. Add a new super-pallet to the screen. The pallet should be drawn on a random block position out of the 10 x 10 blocks. Every time you run the game, the super-pallet should be in a different location.

5. Make Pac-man invincible when a collision with the super-pallet occurs. The super-pallet should disappear from the screen.

6. The game should be over when Pac-man is not invincible and hits any of the ghosts. If Pacman is invincible, then the ghost that collided with Pac-man should return to the bottomright grid of the screen.

7. Our ghosts are currently moving in random fashion. Modify your code so all ghosts are moving towards Pac-man. The ghosts still need to move one block either up, down, left, or right (In the review demo, the ghosts may move in diagonal directions. This will not be allowed any more). To fix the extremely fast movement of the ghosts, we also want to move the ghost with a chance of 1 in a 100. What to Submit Submit your project electronically through D2L by attaching and submitting your Python program file (Assignment1.py). You do not need to submit the other files.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Science For Dummies

Authors: Lillian Pierson ,Jake Porway

2nd Edition

1119327636, 978-1119327639

More Books

Students also viewed these Databases questions