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

YARA INTERNATIONAL

SCHOOL - RIYADH
AISSCE- 2022-23

A PROJECT REPORT ON

“ENDLESS RUNNER GAME”

Submitted by
ABSHAR AND AHMADULLAH
Grade XII

Under the Guidance of


Mr. Madar Abdul Rahman
HOD (Computer Science)

Department of Computer Science


YIS - RIYADH
YARA INTERNATIONAL
SCHOOL - RIYADH

CERTIFICATE

This is to certify that the project entitled, “Endless Runner Game.”


is a bonafide work done by Master Abshar and Master Ahmadullah of
Grade XII during the academic year 2022-2023.

Submitted for AISSCE Computer Science Practical Examination held on


at Yara International School, Riyadh.

PRINCIPAL INTERNAL EXAMINER

EXTERNAL EXAMINER
YARA INTERNATIONAL
SCHOOL - RIYADH

DECLARATION

I hereby declare that the project work entitled “ENDLESS


RUNNER GAME.”, submitted to the Department of Computer
Science, Yara International School, Riyadh, is prepared by me. All
the coding is the result of my personal effort.

Firas Khan
Grade XII
ACKNOWLEDGEMENT

I would like to express a deep sense of thanks and gratitude to my


teachers Mr. Madar Abdul Rahman and Mr. Imdadullah for guiding me
through the course of the project. His constructive advice & constant
motivation have been responsible for the successful completion of the
project.

My sincere thanks go to our Principal Mrs. Aasima Saleem for her


coordination in extending every possible support for the completion of
this project.

I also thank my parents for their motivation and support. I must thank my
classmates for their timely help and support in the completion of this
project.

Last but not least, I would like to thank all those who had helped
directly or indirectly towards the completion of this project.
TABLE OF CONTENT

SL.NO. TOPIC PAGE NO.

1. Introduction 1

2. Objective Of The Project 1

3. Proposed System 2

4. About Python and SQL 2


Hardware & Software
5. 3
Requirements
6. Modules Used 4

7. Source Code 5

8. Output Screens 15

9. Conclusion 24

10. Bibliography 25
1. Introduction
The proposed project “ENDLESS RUNNER GAME” has been developed to
challenge players to navigate through a continuously generated environment for
as long as possible. Unlike traditional games with defined levels and endpoints,
endless runners have no final destination, and the primary objective is to
survive and achieve the highest possible score.

The gameplay mechanics typically involve controlling a character, often in the


form of a runner, who automatically moves forward at a constant speed. Players
must navigate this character through a dynamically changing environment filled
with obstacles, hazards, and challenges. The challenge lies in reacting quickly
to obstacles, making split-second decisions, and mastering the game's controls
to avoid collisions and progress further.

2. Objective of the Project


The Endless Runner Game is designed to meet the following
Objectives:

● Simple and easy to operate

● Appealing Graphical User Interface

● Challenging yet Enjoyable Gameplay

● Working High score system

● In-Game Currency

● Unlockable Cosmetics

● Smooth and appealing animations


● Adjustable settings

3. Proposed System
Endless Runner Game will consist of:

Main Menu– it will be the first menu the player will prompted with, here the
high score and in-game currency will be displayed and the player can choose
to open other menus or play the game itself, here are all the other menus:

● Game – This is the game itself where the player can gain in-game credits

● Pause Menu – It appears when a player pauses, offering options like settings,

quitting, or resuming gameplay.

● Settings - This is where players can customize configurations.

● Shop – This is where players can use their in-game currency to unlock

cosmetics

● Locker – The player will be able to equip cosmetics in this menu

● Lose menu – The player can either restart the game or open the main

menu from here.

4. About Python and SQL


Python:

Python is an interpreter, object-oriented, high-level programming language

2
with dynamic semantics. It was developed by Guido Van Rossum.

Its high-level built in data structures, combined with dynamic typing and
dynamic binding; make it very attractive for Rapid Application
Development, as well as for use as a scripting or glue language to connect
existing components together.

Python's simple, easy to learn syntax emphasizes readability and therefore


reduces the cost of program maintenance. Python supports modules and
packages, which encourages program modularity and code reuse.

SQL:

The Structured Query Language (SQL) is the most popular query language
used by major relational database management systems such as MySQL,
ORACLE, SQL Server, etc.

SQL is easy to learn as the statements comprise of descriptive English


words and are not case sensitive. We can create and interact with a database
using SQL in an efficient and easy way. The benefit with SQL is that we
don’t have to specify how to get the data from the database. Rather, we
simply specify what is to be retrieved, and SQL does the rest. Although
called a query language, SQL can do much more besides querying.

SQL provides statements for defining the structure of the data, manipulating
data in the database, declare constraints and retrieve data from the database
in various ways, depending on our requirements.

5. Hardware & Software Requirements


Software:
Windows 7 or 10
Mac OS X 10.11 or higher, 64-bit
3
Linux: RHEL 6/7, 64-bit (almost all libraries also work in Ubuntu)
Python 3.0+

Hardware
Processor: Minimum 1 GHz; Recommended 2GHz or more
Hard Drive: Minimum 32 GB; Recommended 64 GB or more
Memory (RAM): Minimum 1 GB; Recommended 4 GB or above

6. Modules Used
Pygame:
Pygame is a cross-platform set of Python modules designed for writing video games.
It provides functionality to create 2D games and multimedia applications. Pygame is
built on top of the Simple DirectMedia Layer (SDL), which is a low-level
multimedia library. With Pygame, developers can handle graphics, sound, input
devices, and more to create interactive and visually appealing games in Python.
Sys:
The `sys` module in Python provides access to some variables used or
maintained by the Python interpreter and functions that interact with the interpreter.
It allows you to access and manipulate the Python runtime environment, such as
command line arguments, file I/O functionality, and interaction with the interpreter.

Sqlite3:
SQLite3 is a database engine written in the C programming language. SQLite was
designed to allow the program to be operated without installing a database
management system or requiring a database administrator. Unlike client–
server database management systems, the SQLite engine has no
standalone processes with which the application program communicates. Instead,
a linker integrates the SQLite library — statically or dynamically — into an

4
application program which uses SQLite's functionality through simple function calls,
reducing latency in database operations.
It is the most widely deployed database engine, as it is used by several of the
top web browsers, operating systems, mobile phones, and other embedded systems.
It can be used to create a database, define tables, insert and change rows, run queries
and manage an SQLite database file. It also serves as an example for writing
applications that use the SQLite library.

7. Source Code
import pygame
import sys
import random
import Pause
import gameover
import univar
import cryptography

pygame.init()
pygame.mixer.init()

window=pygame.display.set_mode((1920//2, 1080//2))
pygame.display.set_caption("Stickman Run")
icon=pygame.image.load("Assets/icon.png")
pygame.display.set_icon(icon)
5
bg=pygame.transform.scale(pygame.image.load("Assets/bg.png"),
(1920//2, 1080//2))
bg2=pygame.transform.scale(pygame.image.load("Assets/bg.png"),
(1920//2, 1080//2))
path=pygame.transform.scale(pygame.image.load("Assets/path.png"),
(1920//2, 1080//2))
player_jump=pygame.transform.scale(pygame.image.load("Animations
/Jump/jump.png"), (100,200))
pauseimg=pygame.transform.scale(pygame.image.load("Assets/
pausebtn.png"), (40, 40))

wbbfont=pygame.font.Font("Assets/wbbfont.ttf", 40)

def load_animation(path:str, ext:str, start:int, stop:int, x:int, y:int):

Animation=[]

for i in range(start, stop+1):


if i<10:
img=pygame.image.load(f"{path}000{i}.{ext}")
else:
img=pygame.image.load(f"{path}00{i}.{ext}")

6
imgn=pygame.transform.scale(img, (x,y)).convert_alpha()
imgn.set_alpha(255)
Animation.append(imgn)

return Animation

def text(txt, font, color, surface, x, y):


textobj = font.render(txt, 1, color)
textrect = textobj.get_rect()
textrect.topleft = (x, y)
surface.blit(textobj, textrect)

player_spawn=load_animation("Animations/Spawn/spawn", "png", 1,
73, 100, 200)
player_walk=load_animation("Animations/Walk/walk", "png", 1, 24,
100, 200)
player_run=load_animation("Animations/Run/run", "png", 1, 60,
130,200)
player_crouch=load_animation("Animations/Crouch/crouch", "png", 1,
60, 130, 200)

rocket=load_animation("Animations/Rocket/rocket", "png", 1, 85, 100,


50)
orb=load_animation("Animations/Orb/orb", "png", 1, 85, 62, 62)
7
fire=load_animation("Animations/Fire/fire", "png", 1, 85, 100, 50)

straw_hat_img=pygame.transform.rotate(pygame.transform.scale(pyga
me.image.load("Assets/straw hat.png"), (140, 100)), -4).convert_alpha()
straw_hat_img2=pygame.transform.rotate(pygame.transform.scale(pyg
ame.image.load("Assets/straw hat.png"), (140, 100)), -
10).convert_alpha()
straw_hat_img3=pygame.transform.rotate(pygame.transform.scale(pyg
ame.image.load("Assets/straw hat.png"), (140, 100)), -
33).convert_alpha()
law_hat_img=pygame.transform.rotate(pygame.transform.scale(pygam
e.image.load("Assets/law hat.png"), (140, 100)), -4).convert_alpha()
law_hat_img2=pygame.transform.rotate(pygame.transform.scale(pyga
me.image.load("Assets/law hat.png"), (140, 100)), -10).convert_alpha()
law_hat_img3=pygame.transform.rotate(pygame.transform.scale(pyga
me.image.load("Assets/law hat.png"), (140, 100)), -33).convert_alpha()

def main(mode: int):

global fire

Clock=pygame.time.Clock()

8
pygame.mixer.Channel(1).play(pygame.mixer.Sound('Audio/bgm.mp3')
)

if mode==2:
runtime=14
runtimeincrement=0
score=univar.score
else:
runtime=0
runtimeincrement=0.01666666
score=0

playerx=100
playery=250

rocketx=random.randint(1500, 2000)
rockety=random.choice([250, 350, 400])

orbx=random.randint(2000, 2500)
orby=random.choice([250, 350, 400])

firex=random.randint(2500, 3000)
firey=random.choice([250, 350, 400])

9
obstacle_speed_increment=-6.5

y=250
jumpIncrement=0

bgx=0
bgx2=960
bgxIncrement=0

pgx=0
pgx2=958
pgxIncrement=0

spawnFrameRate=0.5
spawnFrame=0

walkFrameRate=0.5
walkFrame=0

runFrameRate=0.5
runFrame=0

10
crouchFrameRate=0.5
crouchFrame=0

rocketFrameRate=0.5
rocketFrame=0

orbFrameRate=0.5
orbFrame=0

fireFrameRate=0.5
fireFrame=0

spawntime=0
timeIncrement=0

spawn=True
walk=False
run=False
jump=False
crouch=False
obstacles=False
click=False
pause=False

11
losetime=0
losetimeincrement=0

choices=[970, 1800, 2400, 2800]


randomNum=random.choice(choices)

attackRange=500

playerRect=player_run[0].get_rect()

x=0
x2=0

pauseBTN=pauseimg.get_rect()
pauseBTN.center=480, 50

money=univar.money

if univar.straw_hat:
straw_hat_alpha=255
law_hat_alpha=0

12
elif univar.law_hat:
straw_hat_alpha=0
law_hat_alpha=255
else:
straw_hat_alpha=0
law_hat_alpha=0

straw_hat_img.set_alpha(straw_hat_alpha)
straw_hat_img2.set_alpha(straw_hat_alpha)
straw_hat_img3.set_alpha(straw_hat_alpha)

law_hat_img.set_alpha(law_hat_alpha)
law_hat_img2.set_alpha(law_hat_alpha)
law_hat_img3.set_alpha(law_hat_alpha)

while True:

univar.score=int(score)
univar.money=int(money)

pygame.mixer.Channel(1).set_volume(univar.volume)

rocketRect=rocket[int(rocketFrame)].get_rect()

13
orbRect=orb[int(orbFrame)].get_rect()
fireRect=fire[int(fireFrame)].get_rect()

rocketRect.width=35
rocketRect.height=30

orbRect.width=35
orbRect.height=30

fireRect.width=35
fireRect.height=30

rocketRect.center=rocketx+30, rockety+27
orbRect.center=orbx+15, orby+25
fireRect.center=firex+25, firey+20

if len(playerRect.collidelistall([rocketRect,orbRect,fireRect]))!=0:
print("Collision")
x2=-1
losetimeincrement=0.01666666

if losetime>1:
pgxIncrement=0

14
bgxIncrement=0
obstacle_speed_increment=0
pause=False
with open("Data/money.txt", "w") as m:
m.write(str(univar.money))
m.close()
with open("Data/score.txt", "r") as s:
if int(s.read())<univar.score:
hs=True
s.close()
else:
hs=False
if hs:
with open("Data/score.txt", "w") as sw:
sw.write(str(univar.score))
sw.close()
score=0
gameover.gameover()

if obstacles:
rocketx+=obstacle_speed_increment
orbx+=obstacle_speed_increment

15
firex+=obstacle_speed_increment

if y<70:
if y<250:
jumpIncrement=+5
if y>250:
jumpIncrement=0
y=250
jump=False
run=True

if orbx>rocketx-attackRange and orbx<rocketx:


rocketx+=100
if firex>rocketx-attackRange and firex<rocketx:
rocketx+=100

if rocketx>orbx-attackRange and rocketx<orbx:


orbx+=100
if firex>orbx-attackRange and firex<orbx:
orbx+=100

if rocketx>firex-attackRange and rocketx<firex:


firex+=100

16
if orbx>firex-attackRange and orbx<firex:
firex+=100

if rocketx<-20:
rocketx=random.choice(choices)
choices.remove(rocketx)
rockety=random.choice([250, 350, 400])

if orbx<-20:
orbx=random.choice(choices)
choices.remove(orbx)
orby=random.choice([250, 350, 400])

if firex<-20:
firex=random.choice(choices)
choices.remove(firex)
firey=random.choice([250, 350, 400])

if len(choices)==0:
choices.extend([970, 1800, 2400, 2800])

mx,my=pygame.mouse.get_pos()
print(mx,my)

17
if pgx2 in [0,-1,-2,-3,1,2,3,4,5,6]:
pgx=960
if pgx in [0,-1,-2,-3,1,2,3,4,5,6]:
pgx2=956
if bgx2==0:
bgx=960
if bgx==0:
bgx2=960

window.blit(bg, (bgx,0))
window.blit(bg2, (bgx2,0))
window.blit(path, (pgx,0))
window.blit(path, (pgx2,0))

if runtime>13:
walk=False
spawn=False
run=True
runtime=0
runtimeincrement=0

if spawnFrame>72:

18
spawnFrameRate=0
spawnFrame=72
timeIncrement=0.0333

if mode!=2:
if spawntime>1.5:
player_spawn[72].set_alpha(0)
walk=True
spawn=False
spawnFrame=0
spawntime=0
timeIncrement=0

if walkFrame>23:
walkFrame=0

if runFrame>59:
runFrame=0

if crouchFrame>59:
crouchFrame=0

19
if rocketFrame>84:
rocketFrame=0

if orbFrame>84:
orbFrame=0

if fireFrame>84:
fireFrame=0

if spawn:
jump=False
run=False
crouch=False
window.blit(player_spawn[int(spawnFrame)], (playerx,
playery))
window.blit(straw_hat_img, (playerx-10, playery-55))
window.blit(law_hat_img, (playerx-10, playery-55))

if walk:
jump=False
run=False
crouch=False
bgxIncrement=-0.01

20
pgxIncrement=-1
window.blit(player_walk[int(walkFrame)], (playerx, playery))
window.blit(straw_hat_img, (playerx-10, playery-55))
window.blit(law_hat_img, (playerx-10, playery-55))

if run:
obstacles=True
bgxIncrement=-0.1
pgxIncrement=-5
pause=True
playerRect=player_run[int(runFrame)].get_rect()
playerRect.width=70
playerRect.center=playerx+60, playery+100
window.blit(player_run[int(runFrame)], (playerx, playery))
window.blit(straw_hat_img2, (playerx+35, playery-24))
window.blit(law_hat_img2, (playerx+35, playery-24))

if jump:
crouch=False
run=False
playerRect=player_jump.get_rect()
playerRect.width=55
playerRect.center=playerx+60, y+100

21
window.blit(player_jump, (100,y))
window.blit(straw_hat_img, (playerx, y-25))
window.blit(law_hat_img, (playerx, y-25))

if crouch:
jump=False
run=False
playerRect=player_crouch[int(crouchFrame)].get_rect()
playerRect.center=playerx+60, playery+200
window.blit(player_crouch[int(crouchFrame)], (playerx,
playery))
window.blit(straw_hat_img3, (playerx+40, playery+30))
window.blit(law_hat_img3, (playerx+40, playery+30))

if obstacles:
window.blit(rocket[int(rocketFrame)], (rocketx, rockety))
window.blit(orb[int(orbFrame)], (orbx, orby))
window.blit(fire[int(fireFrame)], (firex, firey))

for event in pygame.event.get():


if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

22
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_SPACE:
run=False
jump=True
jumpIncrement=-10
if spawn==False and walk==False:

pygame.mixer.Channel(2).play(pygame.mixer.Sound("Audio/jump.mp3
"))

pygame.mixer.Channel(2).set_volume(univar.nonmusicvol)
if event.key==pygame.K_0:
print("- - - - - - - - - - - - - - - - - - - -")
if event.key==pygame.K_c:
crouch=True
if event.type==pygame.KEYUP:
if event.key==pygame.K_c:
crouch=False
run=True
if event.type==pygame.MOUSEBUTTONDOWN:
click=True
if event.type==pygame.MOUSEBUTTONUP:
click=False

23
spawnFrame+=spawnFrameRate
walkFrame+=walkFrameRate
runFrame+=runFrameRate
crouchFrame+=crouchFrameRate

rocketFrame+=rocketFrameRate
orbFrame+=orbFrameRate
fireFrame+=fireFrameRate

spawntime+=timeIncrement
runtime+=runtimeincrement
losetime+=losetimeincrement

bgx+=bgxIncrement
pgx+=pgxIncrement

bgx2+=bgxIncrement
pgx2+=pgxIncrement

y+=jumpIncrement

24
x+=x2
playerx+=x
playery+=x

text("C - Crouch", wbbfont, (255,255,255), window, 265, 500)


text("SPACE - Jump", wbbfont, (255,255,255), window, 500, 500)

if pause:
window.blit(pauseimg, pauseBTN)
text(f'Score: {univar.score}', wbbfont, (255,255,255), window,
50, 50)
text(f'{univar.money}', wbbfont, (255,255,255), window, 880,
50)
text(f'$', wbbfont, (0,255,0), window, 860, 50)
score+=0.1
money+=0.09
if pauseBTN.collidepoint(mx,my):
if click:
pygame.mixer.Channel(1).set_volume(0)
Pause.pauseMenu()

playerRect.collidelistall([rocketRect,orbRect,fireRect])

25
Clock.tick(60)
text(str(int(Clock.get_fps())), wbbfont, (0,255,0), window, 860,
100)
pygame.display.update()

8. Output Screen

26
27
9. Conclusion
We have worked tirelessly to create an endless runner game that challenges
players to navigate through a continuously generated environment for as long as
possible. Their simple yet challenging gameplay mechanics, combined with the
endless and dynamically generated environments, make them accessible to players
of all skill levels.
We are thrilled to share that our upcoming game updates will introduce a
variety of exciting features, aiming to captivate and exhilarate our players.
We are considering the implementation of a leaderboard feature, allowing
players to be ranked based on their high scores
We have exciting plans to introduce an array of new themes and expand our
item shop, providing players with a richer and more immersive gaming experience.

10. Bibliography
 https://stackoverflow.com
 https://www.pygame.org/docs/

28

You might also like