Computer Science & E
Lab 12: Space Invaders Game in Python – Part 3Academic HonestyThe work you turn in is to be your work, not copied from someone else, from the web, or generated by a program.Never allow anyone access to your files.Never give anyone your password.Never share your USB memory or email your files to anyone else.Never give anyone a printed copy of your file or an electronic copy.Never allow anyone to copy your work.PurposeIn the next few labs we will create Space Invaders Game using python and Turtle which you can play like the video attached. The Space Invaders Lab is divided into several labs and this is the second part of it. You should have already set up playing area for space invaders in Lab 10 and moving the player and enemy in Lab 11. In this part, you will learn how to detect collision between two turtles (meaning bullet and enemy, enemy and player), then update the score based on that. 13258801574800Since this part is based on the lab 11, create new file called Lab12XY where XY are your initials. Then, you need to open the Lab 11 and copy everything from there. We will update your previous lab and change it to create new functionalities.117094058991500Until now, you should have created the playing area that looks like the image below and player and enemy moving.You should look this video as you are working on the lab for more elaborate explanation of Lab 12 Collision between two turtlesYou can check if there is collision between two turtles by checking distance between them. There is a function in python to calculate distance of turtle from a point. distance = turtle.distance(x, y) which calculates distance of a turtle from point (x,y)This can be extended to calculate the distance between two turtles turtle1 and turtle2 by doingdistance = turtle1.distance(turtle2.xcor(), turtle2.ycor())This is just the same function just replacing the point (x, y) by the x and y coordinate of another turtle. Create a function called isCollision (turtle1, turtle2) which takes two turtles as parameters. Inside this function, if the distance between two turtles is less than 15 then return True which means that there is collision otherwise return False.When bullet collides with enemyCheck if the bullet collides with any enemy by calling functions isCollision (bullet, enemy).If there is collision, then we increase the score by 10. You know how to write score in Lab 10. Remember, before writing the score you need to clear the score_pen using score_pen.clear(). You are not creating a new pen; we already created a score pen in Lab 10.Apart from incrementing score, you need to hide the bullet turtle and set the bulletState to “ready” so that we can fire the bullet again.One more thing, we will replace the enemy as well and set the position of the enemy to starting random position. Check Lab 10 how to set to random position.When enemy collides with playerCheck if the player collides with any enemy by calling functions isCollision (player, enemy). If player collides with enemy, then it means game over.So, hide the enemy turtle and player turtle. You know how to hide the turtles from previous labs.Also, set the gameOver to True so that the loop does not continue, and game is over. Create a new turtle called game_turtle which is only used to display GAME OVER. Set the pencolor of that turtle to red. Display that GAME is over and you lose using the following game_turtle.write("GAME OVER", False, align="center", font=("Arial", 20, "normal"))Also hide the game_turtle at the end.Set up when you winFor this lab, a player wins if the score is more than or equals to 200.set the gameOver to True so that the loop does not continue, and game is over. Create a new turtle called game_turtle which is only used to display YOU WIN. Set the pencolor of that turtle to green. Display YOU WIN using the following . game_turtle.write("YOU WIN !!", False, align="center", font=("Arial", 20, "normal"))Also hide the game_turtle at the end.Finally, you have created a Space Invaders by yourself, show it to your friends and enjoy playing. Submitting your filesCopy your .py file and move it to your X:\101Labs directory for grading.Make sure your files are named Lab12XY.py where XY are your initialsPrint your code and submit it to your lab instructor at the beginning of your next lab class. ................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related searches
- igcse computer science workbooks pdf
- igcse computer science workbook
- igcse computer science workbook answer
- igcse computer science coursebook pdf
- computer science people
- what is computer science like
- computer science revision
- igcse computer science revision notes
- college computer science project ideas
- ideas for computer science project
- computer science projects for students
- computer science final project