COMPUTER Ip

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

ATOMIC ENERGY CENTRAL SCHOOL

ANUPURAM
2023-2024

COMPUTER INVESTIGATORY PROJECT


TOPIC: Space Invaders Game

NAME :
CLASS : XII
SECTION :B
CLASS ROLL NUMBER :

INTERNAL EXAMINER PRINCIPAL EXTERNAL EXAMINER

1
CERTIFICATE

This is to certify that of class XII- B,


Atomic Energy Central School, Anupuram has
successfully completed the investigatory project in
Computer science on the topic “Space Invaders” under
my guidance during the academic year 2023-2024 and
given a satisfactory account of it in this report file,
containing a record of his work.

INTERNAL
EXAMINER

2
ACKNOWLEDGEMET

In the accomplishment of this project successfully many people have


bestowed upon me their blessings and immense support.

I would like to express my special thanks of gratitude to our principal


Mr. C.N.S. RAGHAVAN as well as my teacher Mrs. SUJATA PRADHAN
who gave me this golden opportunity to work on this wonderful
project on the topic “Space Invaders”. Which also helped me in
doing a lot of research and helped me know about so many new
things.

Secondly, I would like to thank my parents and my friends who


helped me a lot in finalizing this project within the given time.

Last but not the least I would like to thank all the people who had
helped me directly or indirectly during the completion of this project
and providing me with the much-needed support and motivation.

3
Table of Contents

Serial Description Page


No. No.
1 Certificate 02
2 Acknowledgement 03
3 Introduction 05-08
4 Objective of the project 09
5 Proposed system 10
6 Modules used and their purposes 11
7 Source Code 12-18
8 Output Screens 19-20
9 Limitations & Future Scope 21
10 Requirements 22
11 Bibliography 23

4
Introduction
❖ About Space invaders Game :-

Space Invaders is a stationary shooter in which the player fires at aliens


overhead by moving a laser weapon horizontally across the bottom of
the screen. As a group, the aliens travel left and right, shifting
downward as they approach the screen’s edge. The objective is to shoot
all of the aliens to death. The game finishes quickly if the invaders reach
the bottom of the screen while the player has three lives.

5
❖ Python Overview:-

Python is a general-purpose high-level programming language. It is an open


source language, released under a GPL-Compatible license. Python Software
Foundation (PSF), a non-profit organization, holds the copy-right of python.
Guido Van Rossum conceived python in the late 1980s. It was released in
1991 at Centrum Wiskunde & Informatica (CWI) in the Netherlands as a
successor to the ABC language. He named this language after a popular
comedy show called „Monty Python‟s Flying Circus‟ (and not after python -
the snake). In the last few years, it‟s popularity has increased immensely.
According to stackoverflow.com‟s recent survey, python is in the top ten most
popular technologies in 2018. It is also dynamically-typed because it carries
out type-checking at run time. It does so to make sure that the type of construct
matches what we except it to be. The distinctive feature of python is that it is
an interpreted language. The Python IDLE (Integrated Development &
Learning Environment) executes instruction one line at a time. The python
programming language is one of the richest languages.

6
❖ Features of Python :-

1. Easy :-
Python is a very easy to learn and understand; using this python tutorial,
any beginner can understand the basics of python.

2. Interpreted :-
It is interpreted (executed) line by line. This makes it easy to test and
debug.
3. Object Oriented :-
The python programming language supports classes and objects.
4. Free and Open-Source :-
The language and it’s source code are available to the public for free;
there is no need to buy a costly license.
5. Portable :-
Since it is open source, we can run python on windows, mac, linux, or
any other platforms. Our programs will work without needing to the
changed for every machine.
6. GUI (Graphical User Interface) programming :-
We can use it to develop a GUI (Graphical User Interface). One way to
do this is through „Tkinter‟.
7. Large Library :-
Python provides us with a large standard library. We can use it to
implement a variety of functions without needing to reinvent the wheel
every time. Just pick the code we need and continue. This lets us to
focus on other important tasks.

7
❖ Advantages of Python :-

1. Extensible :-
2. Portable
3. Free & Open-Source
4. Readable
5. Embeddable
6. Improved Productivity
7. Simple and Easy
8. Object Oriented
9. Interpreted
10. Extensive Libraries

❖ How to install Python :-

1. Point your web browser to the download page on the Python


website (www.python.org).
2. Select the latest Windows x86 MSI Installer and click on the link
to download the .msi installer.
3. Run the installer.
4. Select „Install for all users‟ and click the Next > button.
5. Keep the default option (C:\Python32\) as the destination directory and
click Next > again.
6. Don’t make any changes in the „Customize Python 3.2.3‟ dialog,
just click Next > again.
7. Click Yes if asked if this program should be allowed to install
software on your system.
8. Click the Finish button when installation completes.

8
Objective of the project
The objective of this project is to let the students apply the programming
knowledge into a real-world situation/problem and exposed the students how
programming skills help in developing a good software.

Some key points are as follows :-

1. Utilising modern software tools for programming games.


2. Apply object oriented programming principles effectively when
developing small to medium sized projects.
3. Write effective procedural code to solve small to medium sized
problems.
4. Demonstrate a breadth of knowledge in computer science, as exemplified
in the area of game development.
5. Demonstrate ability to conduct a research or applied computer science
project, requiring writing and presentation skills which exemplify
scholarly style in computer science.

9
Proposed System
The objective is to use gunfire to kill every alien. In other words, don't get
killed so you can strike the invaders back. If the user always has three
lives, the game finishes immediately if the invaders (aliens) touch the
bottom of the screen.

10
Module used and their purposes

1. The Random Module :-

This module implements pseudo-random number generators for


various distributions.

The random module has a set of methods which used in


that game.

a. randint( ):
randint() method in Python returns a random integer value between
the two lower and higher limits (including both limits) provided as
two parameters.

2. The Turtle Module :-


turtle is a pre-installed Python library that enables users to
create pictures and shapes by providing them with a
virtual canvas. The onscreen pen that you use for drawing
is called the turtle and this is what gives the library its
name.

11
Source
Code

12
# importing turtle, math and random python modules
import turtle
import math
import random

# Set up the game window screen


window = turtle.Screen()
window.bgcolor("green")
window.title("Space Invaders - CopyAssignment")
window.bgpic("background.gif")

# Register the shape


turtle.register_shape("invader.gif")
turtle.register_shape("player.gif")

# Draw border
border_pen = turtle.Turtle()
border_pen.speed(0)
border_pen.color("white")
border_pen.penup()
border_pen.setposition(-300, -300)
border_pen.pendown()
border_pen.pensize(3)
for side in range(4):
border_pen.fd(600)
border_pen.lt(90)
border_pen.hideturtle()

# Set the score to 0


score = 0

# Draw the pen


score_pen = turtle.Turtle()
score_pen.speed(0)
score_pen.color("red")
score_pen.penup()
score_pen.setposition(-290, 280)
scorestring = "SCORE: %s" %
score
score_pen.write(scorestring, False, align="left",
font=("Arial", 14, "normal"))
score_pen.hideturtle()

13
# Create the player turtle
player = turtle.Turtle()
player.shape("player.gif")
player.penup()
player.speed(0)
player.setposition(0, -250)
player.setheading(90)

playerspeed = 15

# Choose a number of enemies


number_of_enemies = 10
# Creat an empty list of enemies
enemies = []

# Add enemies to the list


for i in range(number_of_enemies):
# create the enemy
enemies.append(turtle.Turtle())

for enemy in enemies:


# enemy.color("Red")
enemy.shape("invader.gif")
enemy.penup()
enemy.speed(0)
x = random.randint(-200, 200)
y = random.randint(100, 250)
enemy.setposition(x, y)

enemyspeed = 5

# Creat the player's bullet


bullet = turtle.Turtle()
bullet.color("white")
bullet.shape("triangle")
bullet.penup()
bullet.speed(0)
bullet.setheading(90)
bullet.shapesize(0.5, 0.5)
bullet.hideturtle()

bulletspeed = 30

14
# define bullet state
# ready - ready to
fire # fire - bullet is
firing bulletstate =
"ready"

# Move the player left and


right def move_left():
x =
player.xcor() x -
= playerspeed if
x < -280:
x = -280
player.setx(x)

def move_right():
x=
player.xcor()
x += playerspeed
if x > 280:
x = 280
player.setx(x)

def fire_bullet():
# Declare bulletstate as a global if it needs changed
global bulletstate
if bulletstate == "ready":
bulletstate = "fire"
# Move the bullet to the just above the player
x = player.xcor()
y = player.ycor() + 10
bullet.setposition(x, y)
bullet.showturtle()

# For collision between enemy and bullet


def isCollision_enemy_bullet(t1, t2):
distance = math.sqrt(
math.pow(t1.xcor() - t2.xcor(), 2) + math.pow(t1.ycor() - t2.ycor(), 2)
)
if distance < 25:
return True
else:
15
return False

16
# For collision between enemy and player
def isCollision_enemy_player(t1, t2):
distance = math.sqrt(
math.pow(t1.xcor() - t2.xcor(), 2) + math.pow(t1.ycor() - t2.ycor(), 2)
)
if distance < 30:
return True
else:
return False

# Create keyboard bindings


turtle.listen()
turtle.onkey(move_left, "Left")
turtle.onkey(move_right, "Right")
turtle.onkey(fire_bullet, "space")

# Main game loop


Game_Over = False
missed_enemies = 0
while True:

for enemy in
enemies: # Move
the enemy x =
enemy.xcor()
x += enemyspeed
enemy.setx(x)

# Move the enemy back and down


if enemy.xcor() > 270:
# Move all enemies down
for e in enemies:
y = e.ycor()
y -= 40
e.sety(y)
if e.ycor() < -285 and Game_Over == False:
e.hideturtle()
missed_enemies += 1
if missed_enemies == 5:
Game_Over = True
x = random.randint(-200, 200)
y = random.randint(100, 250)
e.setposition(x, y)
e.showturtle()

17
# Change enemy direction
enemyspeed *= -1

if enemy.xcor() < -270:


# Move all enemies down
for e in enemies:
y = e.ycor()
y -= 40
e.sety(y)
if e.ycor() < -285 and Game_Over == False:
e.hideturtle()
missed_enemies += 1
if missed_enemies == 5:
Game_Over = True
x = random.randint(-200, 200)
y = random.randint(100, 250)
e.setposition(x, y)
e.showturtle()
# Change enemy direction
enemyspeed *= -1

# check for a collision between the bullet and the enemy


if isCollision_enemy_bullet(bullet, enemy):
# Reset the bullet
bullet.hideturtle()
bulletstate = "ready"
bullet.setposition(0, -400)
# Reset the enemy
x = random.randint(-200, 200)
y = random.randint(100, 250)
enemy.setposition(x, y)
enemyspeed += 0.5
# update the score
score += 10
scorestring = "Score: %s" %
score score_pen.clear()
score_pen.write(
scorestring, False, align="left", font=("Arial", 14, "normal")
)
# check for a collision between the player and enemy
if isCollision_enemy_player(player, enemy):
Game_Over = True
if Game_Over ==
True:

18
player.hideturtle()
bullet.hideturtle()
for e in enemies:
e.hideturtle()
window.bgpic("end.gif")
break

# Move the bullet


if bulletstate == "fire":
y = bullet.ycor()
y += bulletspeed
bullet.sety(y)

# Check to see if the bullet has gone to the top


if bullet.ycor() > 275:
bullet.hideturtle()
bulletstate = "ready"

turtle.done()

19
Output
Screens

20
21
Limitations and Future Scope
❖ Limitations :-

∙ Only one player can play at a time.


∙ Registration of players cannot be done.
∙ Score of players cannot be saved.
∙ It does not provide timing system.
.

❖ Future Scope :-

∙ The number of player can be more than one at a time.


∙ Registration of players can be done.
∙ Score of players can be saved.
∙ Timing system can be provided.

22
Requirements
❖ Hardware required :-

□ Modern Operating System:


∙ Windows 7 or 10
∙ Mac OS X 10.11 or higher, 64-bit
∙ Linux: RHEL 6/7, 64-bit (almost all libraries also
work in Ubuntu)
□ X86 64-bit CPU (Intel / AMD architecture)
□ 4 GB RAM
□ 5 GB free space
□ Printer for printing project

❖ Software required :-

□ Operating System – Windows 10


□ Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 19:29:22) [MSC v.1916 3
bit (Intel)] on win32 for execution of program 2

23
Bibliography
1. www.wikipedia.com
2. www.geeksforgeeks.org
3. www.google.com
4. Computer Science with Python
by Sumita Arora Class XIIth(Book)

24
Thank You!!

25

You might also like