Assignment 3 - Space Invaders Part 2 1. The first thing we need to do is to make the aliens move automatically. Let the

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Assignment 3 - Space Invaders Part 2 1. The first thing we need to do is to make the aliens move automatically. Let the

Post by answerhappygod »

Assignment 3 Space Invaders Part 2 1 The First Thing We Need To Do Is To Make The Aliens Move Automatically Let The 1
Assignment 3 Space Invaders Part 2 1 The First Thing We Need To Do Is To Make The Aliens Move Automatically Let The 1 (263.19 KiB) Viewed 30 times
Expected output of the game.
Below is the provided pygame zero code:
If possible please share the screenshot of the Mu editor
page.
Please do the code in Mu editor and set mode to pygame zero
because i cannot understand if done in other.
Thank you the provided code is below and we need to modify
it:
#Name:
#CWID: 50299257
#TITLE = 'COSC 1436 Space Invaders'
BLOCK_SIZE = 64
WORLD_SIZE = 10
WIDTH = WORLD_SIZE*BLOCK_SIZE
HEIGHT = WORLD_SIZE*BLOCK_SIZE
numAliens = 2
displayGrid = 0 # 0: do not show grid, 1: show grid
cell = Actor('gridbox.png', anchor=('left', 'top'))
cell.x = 0 * BLOCK_SIZE
cell.y = 0 * BLOCK_SIZE
spaceship = Actor("player1", anchor=('left', 'top'))
spaceship.x = 4.5*BLOCK_SIZE
spaceship.y = 9*BLOCK_SIZE
spaceship.aliens_killed = 0
spaceship.score = 0
spaceship.lives = 2
alien1 = Actor("alien11",anchor=('left', 'top'))
alien1.x = 2*BLOCK_SIZE
alien1.y = 2*BLOCK_SIZE
alien2 = Actor("alien21",anchor=('left', 'top'))
alien2.x = 3*BLOCK_SIZE
alien2.y = 2*BLOCK_SIZE
# You need to declare the necessary variables/properties.
def draw():
screen.clear()
spaceship.draw()
alien1.draw()
alien2.draw()
screen.draw.text("Score: "+ str(spaceship.score),
topleft=(8, 4), fontsize=32) # displays
score
screen.draw.text("Lives: "+ str(spaceship.lives),
topright=(WIDTH-8, 4), fontsize=32) # displays lives
# Modify the line below to displays the current
highest score:
screen.draw.text("Hi-Score: ", midtop=(WIDTH/2, 4),
fontsize=32) # Q6
def on_key_down(key):
"Put your code in this function."
def on_key_up(key):
"Put your code in this function."
def update():
"Put your code in this function."
Assignment 3 - Space Invaders Part 2 1. The first thing we need to do is to make the aliens move automatically. Let the aliens move from left to right. Once they reach the right border of the screen, they should re-enter the screen from the left border. Each alien should have a speed property, and the value of the speed is 1. (Hint: Refer to Assignment 1.) 2. We need to make the spaceship move when the user presses on the keyboard buttons. Modify the code so that the spaceship Actor moves 2 pixels to the right every time any key is pressed and held. (Oh yeah! Our spaceship is faster than the aliens'.) The movement should be continuous. The movement should stop the moment the player releases the key. To do that, you need to define the on_key_down(key), on_key_up(key), and update() functions. You also need to add a new property (variable) to the spaceship called dx. (Hint: Refer to Lab 2.) 3. If the spaceship moves out of the right border of the screen, we also want the spaceship to re- enter the screen from the left border. 4. We want to load the current highest score from a local disk file. The filename is "highScore.txt". This file is provided. You may modify the number in the file to any integer, and your program should still work. After you decompress (i.e., extract) the ZIP folder, you should be able to see this:
After you decompress (i.e., extract) the ZIP folder, you should be able to see this: M х highScore - Notepad File Edit Format View Help 123000 images highScore invaders2.py Important issue: In Python 3 mode, the data file should always be placed in the same directory as the Python program (the PY file). However, in Pygame Zero mode, the situation is different. A. If the version of Mu is 1.1.0, the data file should be placed in the same directory as the Python program. B. If the version of Mu is 1.0.2 or 1.0.3, the data file should be placed in the system directory of Mu. There is an easier way to figure out where you should place the data file. Launch Mu, and load "invaders2.py". Then click on the menu button "Images". A file explorer (finder for Mac OS) will pop up. It will show you a directory named "images". This directory may be the directory of the images of Space Invaders (Situation-A), or it may be the system directory of the default images of Mu (Situation-B). In either case, you should place "highScore.txt" in the parent directory of the images directory that you see.
Mu 1.1.0.beta.5. invaders2.py + t + A & ? بل Mode Load Save Play Images Fonts Sounds Music Zoom-in Zoom-out Theme Check Tidy Help Quit New x invaders2.py Show the images used by Pygame Zero. 1 Δ 2 PLEASE MAKE SURE TO INSERT YOUR INFORMATION: 3 4 Name : 5 1 Click on the button of Images 2021 fall> 1436.01E > TentativeHW3 > Invaders2 > images alien 10 alien11 alien12 alien 20 alien21 1 Situation-A: Place "highScore.txt" in the directory of "Invaders 2"
> mu_code > images alien alien_hurt cat1 cat2 1 Situation-B: Place "highScore.txt" in the directory of "mu_code" 5. Write code after the declarations of the spaceship and alien variables to read the number from the "highScore.txt" file. You need to declare the necessary variables for file operations. The highest score should be an integer. (Hint: Refer to the lecture of I/O.) 6. We want to display the highest score on top of the screen when the game is being played. Write code in the draw() function so that the screen looks like the image below. Part of the code is provided.
COSC 1436 Space Invaders х Score: 0 Hi-Score: 123000 Lives: 2 ibid 8
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply