Class 12 Computer Science Project Rough Draft v2 - Shravanth
Class 12 Computer Science Project Rough Draft v2 - Shravanth
PROJECT ON
SKY STRIKE GAME
CERTIFICATE
This is to certify that the Computer Science Project titled Sky Strike
Game. which has been submitted to SUGUNA PIP School, meeting
the requirements of the CBSE Board practical examination for the
academic year 2024 – 2025, is a bonafide work done by Shravanth S
Sennimalai.
1
ACKNOWLEDGEMENT
I would like to thank Mr. M.Poovannnan, Principal, Coimbatore for
this immeasurable direction towards the course of action and support
throughout the project.
I would also like to thank my Faculty Guide, Mrs. Nithiya R, for his
valuable mentoring throughout the project. My knowledgeable teacher's
interesting lectures have helped me understand various concepts related
to Python. I got ample opportunity to do research, which enriched and
broadened my knowledge and understanding of this area.
Register Number :
Class : XII - A1
Date of Submission :
2
DECLARATION
I, hereby certify that the work contained in this report is original and has
been completed by me under the supervision of the faculty.
3
ABSTRACT
Sky Strike is an exhilarating 2D arcade shooter game that challenges
players to defend against waves of descending enemies in a test of
reflexes, precision, and survival. As players pilot a lone shooter, they
face increasingly difficult waves of enemies with varying speeds and
attack patterns, driven by a dynamic difficulty system. Offering multiple
levels of challenge, from Easy to Extreme, Sky Strike provides an
accessible start for newcomers and a hardcore experience for seasoned
players. The game’s leaderboard captures top scores, encouraging
players to aim for high rankings and replay for personal bests. With a
visually engaging interface, responsive controls, and a focus on fluid,
action-packed gameplay, Sky Strike offers an addictive and competitive
experience that invites players to return for "one more game."
Ideal for fans of retro arcade games and competitive shooters, Sky Strike
combines classic gameplay with modern features like user tracking,
difficulty settings, and a vibrant, interactive menu system, creating a
balanced blend of nostalgia and innovation.
4
INDEX
5
INTRODUCTION
Sky Strike is a 2D arcade shooter game project developed using Python and
Pygame, designed to provide players with an engaging and competitive
action experience. The game combines classic arcade shooter mechanics with
modern enhancements, focusing on responsive controls, diverse difficulty
levels, and a compelling leaderboard system. Players take control of a lone
fighter, battling waves of increasingly challenging enemies while navigating
through progressively difficult stages. With power-ups, enemy variations, and
a constantly updated leaderboard, Sky Strike is designed to be both fun for
casual players and challenging for high-score enthusiasts.
This project not only showcases the capabilities of Pygame for game
development but also serves as an excellent foundation for learning game
design principles, including user interface design, event handling, collision
detection, and difficulty scaling.
6
CLASSES AND FUNCTIONS USED
1. Class Button:
○ Defines an interactive button with customizable text, color
changes on hover, and clickable functionality.
2. Function get_font(size):
○ Returns a font object with the specified size to standardize
font styling across the game.
3. Function d_pause():
○ Displays a pause overlay with "Restart" and "Menu" options
and returns buttons for handling pause interactions.
4. Function leaderboard2(level):
○ Renders the leaderboard screen showing top player scores
filtered by difficulty level.
5. Function main_menu():
○ Displays the main menu with options to play, view the
leaderboard, or quit, and manages user selections.
6. Function leaderboard(level):
○ Reads and sorts leaderboard data from a CSV file based on
score and difficulty, returning a filtered list.
7. Function difficulty_choose():
○ Presents difficulty options (Easy, Hard, Extreme) to the
player, adjusts game variables based on selection, and returns
the chosen level.
8. Function draw_text(text, font, text_col, x, y):
○ Renders centered text on the screen at a specified position for
consistent text display.
9. Function obusername():
○ Collects the player's username input, starts the game with the
selected difficulty, and saves scores post-game.
7
10. Function play(lev):
○ The core gameplay loop where enemies move, bullets fire,
collisions are checked, and scores are tracked, with pause
functionality.
8
SOURCE CODE
import pygame
import random
import math
from pygame import mixer
import sys
import csv
run = True
run2 = True
run3 = True
play_again = False
text = ""
mixer.init()
pygame.init()
mixer.music.load('explosion.wav')
mixer.music.load('background.wav')
mixer.music.play(-1)
button_surface = pygame.image.load("buttonmenu.png")
button_surface = pygame.transform.scale(button_surface, (400,
75))
button_surface_2 =
pygame.transform.scale(button_surface,(200,50))
9
return pygame.font.Font("HeadlinerNo45-59y8.ttf", size)
def d_pause():
pygame.draw.rect(surface, (128, 128, 128, 200), [0, 0, 800,
600]) ##4th - Transparent 128 - Gray
pygame.draw.rect(surface, "dark gray", [100, 150, 600, 50],
0, 10) # last for rounded corners
reset = pygame.draw.rect(surface, "white", [100, 220, 290,
50], 0, 10)
save = pygame.draw.rect(surface, "white", [410, 220, 290,
50], 0, 10)
surface.blit(font.render('Game Paused: Escape to Resume',
True, "black"), (220, 160))
surface.blit(font.render('Restart', True, "black"), (200,
230))
surface.blit(font.render('Menu', True, "black"), (520, 230))
screen.blit(surface, (0, 0))
return reset, save
def leaderboard2(level):
global MAIN_MENU_BUTTON2
screen.fill("white")
font_defeat = pygame.font.SysFont('Arial', 70, 'bold')
leaderboard_txt = font_defeat.render("LEADERBOARD", True,
"Black")
screen.blit(leaderboard_txt, (120, 40))
name_txt_font = pygame.font.Font("HeadlinerNo45-59y8.ttf",
65)
name_txt_font_2 = pygame.font.Font("HeadlinerNo45-59y8.ttf",
40)
name_txt, score_txt = name_txt_font.render("Name", True,
"Black"), name_txt_font.render("Score", True, "Black")
screen.blit(name_txt, (200, 150))
screen.blit(score_txt, (500, 150))
leaderboard_list = leaderboard(level)
for i in range(5):
10
try:
name_txt_2, score_txt_2 =
name_txt_font_2.render("{}".format(leaderboard_list[i][0]),
True,"Black"),
name_txt_font_2.render("{}".format(leaderboard_list[i][1]),
True, "Black")
screen.blit(name_txt_2, (180, 230 + 50 * i))
screen.blit(score_txt_2, (540, 230 + 50 * i))
except IndexError:
break
button_surface = pygame.image.load("buttonmenu.png")
button_surface = pygame.transform.scale(button_surface, (200,
75))
MAIN_MENU_BUTTON2 = Button(button_surface, pos=(200, 530),
text_input="MAIN MENU",
font=get_font(40), base_color="#000000", hovering_color="white")
button_surface = pygame.transform.scale(button_surface, (300,
75))
LEVEL_BUTTON = Button(button_surface, pos=(550, 530),
text_input="DIFFICULTY :
{}".format(["EASY", "HARD", "EXTREME"][level - 1]),
font=get_font(40),
base_color="#000000", hovering_color="white")
MAIN_MENU_BUTTON2.changeColor(pygame.mouse.get_pos())
MAIN_MENU_BUTTON2.update(screen)
LEVEL_BUTTON.update(screen)
class Button():
def __init__(self, image, pos, text_input, font, base_color,
hovering_color):
self.image = image
self.x_pos = pos[0]
self.y_pos = pos[1]
self.font = font
self.base_color, self.hovering_color = base_color,
hovering_color
self.text_input = text_input
self.text = self.font.render(self.text_input, True,
self.base_color)
if self.image is None:
11
self.image = self.text
self.rect = self.image.get_rect(center=(self.x_pos,
self.y_pos))
self.text_rect = self.text.get_rect(center=(self.x_pos,
self.y_pos))
self.rect.bottom):
return True
return False
self.rect.bottom):
self.text = self.font.render(self.text_input, True,
self.hovering_color)
else:
self.text = self.font.render(self.text_input, True,
self.base_color)
def main_menu():
global play_again
while True:
screen.blit(BG, (0, 0))
if play_again:
obusername()
play_again = not play_again
MENU_MOUSE_POS = pygame.mouse.get_pos()
12
MENU_TEXT = get_font(120).render("MAIN MENU", True,
"black")
MENU_RECT = MENU_TEXT.get_rect(center=(400, 100))
screen.blit(MENU_TEXT, MENU_RECT)
leaderboard2(level)
13
if pygame.mouse.get_pressed()[0] and
MAIN_MENU_BUTTON2.checkForInput(pygame.mouse.get_pos()):
break
pygame.display.update()
if QUIT_BUTTON.checkForInput(MENU_MOUSE_POS):
pygame.quit()
sys.exit()
pygame.display.update()
def leaderboard(level):
fh = open("leaderboard.csv", "r", newline="")
reader = csv.reader(fh)
reader = list(reader)
temp_list = sorted(reader, key=lambda x: x[1], reverse=True)
fh.close()
return [i for i in temp_list if i[2] == str(level)]
def difficulty_choose():
global x_speed, y_speed, enemy_number,text
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
pygame.quit()
exit()
##DIFFICULTY LEVEL
if event.type==pygame.MOUSEBUTTONDOWN:
if EASY.checkForInput(pygame.mouse.get_pos()):
x_speed, y_speed,enemy_number= -0.75,80,3
return 1
if HARD.checkForInput(pygame.mouse.get_pos()):
x_speed, y_speed,enemy_number= -1,70,5
return 2
if EXTREME.checkForInput(pygame.mouse.get_pos()):
x_speed, y_speed,enemy_number= -1.25,70,6
return 3
if
MAIN_MENU_BUTTON.checkForInput(pygame.mouse.get_pos()):
text=""
main_menu()
14
screen.fill("white")
font_defeat = pygame.font.Font("HeadlinerNo45-59y8.ttf",
120)
difficulty_txt=font_defeat.render("SELECT
DIFFICULTY",True,"Black")
screen.blit(difficulty_txt,(120,50))
EASY=Button(button_surface, pos=(400, 250),
text_input="EASY",
font=get_font(50), base_color="#000000", hovering_color="white")
HARD=Button(button_surface, pos=(400, 350),
text_input="HARD",
font=get_font(50), base_color="#000000", hovering_color="white")
EXTREME=Button(button_surface, pos=(400, 450),
text_input="EXTREME",
font=get_font(50), base_color="#000000", hovering_color="white")
def obusername():
font_defeat = pygame.font.SysFont('Arial', 64, 'bold')
# define font
font = pygame.font.Font("HeadlinerNo45-59y8.ttf", 60)
15
# create empty string
global text, play_again, score
# game loop
run = True
while run:
# update background
screen.fill("white")
# event handler
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
# handle text input
if event.type == pygame.TEXTINPUT:
text += event.text
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_BACKSPACE:
text = text[:-1]
if play_again or event.type == pygame.KEYDOWN and
event.key == pygame.K_RETURN:
level = difficulty_choose()
score = play(level)
fh = open("leaderboard.csv", "a", newline="")
writer = csv.writer(fh)
writer.writerow([text, score, level])
fh.close()
##if not run2:
##afdefeat()
# update display
16
pygame.display.flip()
var = 1
while run3:
if var == 1:
screen.fill("white")
font_defeat = pygame.font.SysFont('Arial', 70,
'bold')
img_defeat = font_defeat.render("GAME OVER", True,
'Black')
screen.blit(img_defeat, (160, 50))
draw_text("Your Score Is " + str(score), font,
TEXT_COL, 390, 200)
button_surface = pygame.image.load("buttonmenu.png")
button_surface =
pygame.transform.scale(button_surface, (200, 75))
PLAY_AGAIN_BUTTON = Button(button_surface, pos=(400,
450),
text_input="PLAY AGAIN",
font=get_font(50), base_color="#000000",
hovering_color="white")
LEADERBOARD_BUTTON = Button(button_surface, pos=(250,
350),
text_input="LEADERBOARD",
font=get_font(50), base_color="#000000",
hovering_color="white")
MAIN_MENU_BUTTON = Button(button_surface, pos=(550,
350),
text_input="MAIN MENU",
font=get_font(50), base_color="#000000",
hovering_color="white")
for button in [PLAY_AGAIN_BUTTON, LEADERBOARD_BUTTON,
MAIN_MENU_BUTTON]:
button.changeColor(pygame.mouse.get_pos())
button.update(screen)
if var == 2:
leaderboard2(level)
if pygame.mouse.get_pressed()[0] and
MAIN_MENU_BUTTON2.checkForInput(pygame.mouse.get_pos()):
run2 = True
17
run3 = False
text = ""
break
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if
LEADERBOARD_BUTTON.checkForInput(pygame.mouse.get_pos()):
var = 2
if
PLAY_AGAIN_BUTTON.checkForInput(pygame.mouse.get_pos()):
run3 = False
run2 = True
play_again = not play_again
if
MAIN_MENU_BUTTON.checkForInput(pygame.mouse.get_pos()):
text = ""
run2 = True
run3 = False
pygame.display.flip()
run3 = True
def play(lev):
screen.fill("white")
level = lev
global run2
pause = False
global score, x_speed, y_speed, enemy_number
score = 0
bg = pygame.image.load("whitebg.jpg")
shooter = pygame.image.load("shooter.png")
bullet = pygame.image.load("bullet.png")
##ENEMY
enemy_img = list()
enemy_X = []
enemy_Y = []
18
enemy_speed_X = []
enemy_speed_Y = []
for i in range(enemy_number):
enemy_img.append(pygame.image.load("enemy.png"))
enemy_X.append(random.randint(0, 736))
enemy_Y.append(random.randint(30, 150))
enemy_speed_X.append(random.choice([x_speed, -x_speed]))
enemy_speed_Y.append(y_speed)
##BULLET
check = False
bullet_X = 386
bullet_Y = 490
##SHOOTER
shooter_X = 370
shooter_speed = 0
def score_text():
img = font.render(f'Score:{score}', True, 'black')
screen.blit(img, (10, 10))
run = True
camper, time = True, pygame.time.get_ticks()
while run:
surface3 = pygame.surface.Surface((800, 600))
surface3.fill('red')
screen.blit(bg if level < 3 else surface3, (0, 0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit()
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if not pause and not camper:
if event.key == pygame.K_LEFT:
shooter_speed = -2
if event.key == pygame.K_RIGHT:
19
shooter_speed = +2
if event.key == pygame.K_SPACE:
if check is False:
check = True ##Prevents bullet
glitching
bullet_X = shooter_X
##PAUSE CHECK
if event.key == pygame.K_ESCAPE:
if pause:
pause = False
else:
pause = True
if event.type == pygame.KEYUP:
shooter_speed = 0
20
##ENEMY MULTIPLE
for i in range(enemy_number):
screen.blit(enemy_img[i], (enemy_X[i], enemy_Y[i]))
if not pause and not camper:
enemy_X[i] += enemy_speed_X[i]
##BOUNCE BACK FROM WALLS
if enemy_X[i] <= 0:
enemy_speed_X[i] = -enemy_speed_X[i]
enemy_Y[i] += enemy_speed_Y[i]
if enemy_X[i] >= 736:
enemy_speed_X[i] = -enemy_speed_X[i]
enemy_Y[i] += enemy_speed_Y[i]
##GAMEOVER
if enemy_Y[i] > 420:
for j in range(enemy_number):
enemy_Y[j] = 2000
run2 = False
break
if not run2:
run = False
break
if check is True:
screen.blit(bullet, (bullet_X, bullet_Y))
if not pause:
bullet_Y -= 4 ##Bullet Speed
if bullet_Y <= 0:
21
bullet_Y = 490
check = False ##Bullet should only release after
space bar pressed
##PAUSE MENU
if pause:
restart, save = d_pause()
if not run:
run = not run
return score
main_menu()
22
OUTPUT
23
24
25
26
27
28
SCOPE FOR ENHANCEMENT
The Sky Strike game offers exciting potential for future enhancements that
could significantly enrich the player experience and increase replayability.
The game’s UI and UX can also be improved for a more polished feel. Visual
feedback such as explosion effects, bullet impacts, and score animations would
make the game more visually engaging, while an interactive tutorial mode could
help new players become familiar with the controls and mechanics.
Customizable controls would give players more flexibility, making the game
accessible to a wider audience.
29
CONCLUSION
In conclusion, the Sky Strike game project has successfully demonstrated the
power of engaging gameplay, simple yet dynamic mechanics, and a
well-designed user interface. Through this project, we have created an
immersive experience that combines fast-paced action with strategic
elements, challenging players to improve their skills as they navigate
increasingly difficult levels. This project has provided a solid foundation in
game development, from implementing core gameplay elements and
interactive menus to integrating sound, graphics, and scoring systems that
enhance user engagement.
30
BIBLIOGRAPHY
Text Reference:
● Sumita Arora. Computer Science with Python Textbook for Class XII.
Dhanpat Rai & Co. (P) Ltd, 2024 ,(ISBN 978-81-7700-236-2)
● Sumita Arora. Computer Science with Python Textbook for Class XI.
Dhanpat Rai & CO. (P) Ltd, 2023, (ISBN 978-81-7700-230-0)
Web Reference:
● https://www.geeksforgeeks.org/python-display-text-to-pygame-
window/
● https://github.com/pygame/pygame
● https://www.youtube.com/watch?v=AY9MnQ4x3zk
31