100% found this document useful (2 votes)
3K views68 pages

MINI REPORT Final PDF

This document describes a mini project report on Python game development submitted by 4 students. It includes an introduction to the project, literature survey of existing systems, analysis of the proposed system including software flow, interfaces, requirements and source code. It also covers the design approach, UML diagrams, modules, and testing strategies. The appendices provide screenshots of the game and discussions of cognitive benefits and disadvantages of gaming. The project aims to develop a 2D car racing game using Python and Pygame with AI control of traffic to avoid collisions and reach the goal of collecting trophies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
3K views68 pages

MINI REPORT Final PDF

This document describes a mini project report on Python game development submitted by 4 students. It includes an introduction to the project, literature survey of existing systems, analysis of the proposed system including software flow, interfaces, requirements and source code. It also covers the design approach, UML diagrams, modules, and testing strategies. The appendices provide screenshots of the game and discussions of cognitive benefits and disadvantages of gaming. The project aims to develop a 2D car racing game using Python and Pygame with AI control of traffic to avoid collisions and reach the goal of collecting trophies.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 68

PYTHON GAME DEVELOPMENT

A MINI PROJECT REPORT

SUBMITTED IN PARTIAL FULFILMENT OF THE REQUIREMENTS FOR


THE ACADEMIC PROJECT

IN
COMPUTER SCIENCE AND ENGINEERING
BY
M.SHIVA SHANKAR 2210315843
M.SAI VENKATA CHAITANYA 2210315842
B.KRUTHIKA REDDY 2210315833
Y.VENKATA NARASIMHA REDDY 2210315863

UNDER THE GUIDANCE OF


A.PHANI SHEETAL
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

SCHOOL OF TECHNOLOGY
GITAM(Deemed to be University)
HYDERABAD

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING


OCTOBER-2018

I
SCHOOL OF TECHNOLOGY Rudraram Village, Patancheru Mandal
GITAM (Deemed to be university) Sangareddy Dist-502329,TS,INDIA
Hyderabad Ph:08455-220556/57;Fax:08455-20046

Website:-www.gitam.edu
DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

CERTIFICATE

This is to be certify that Mini Project Report entitled “ PYTHON GAME


DEVELOPMENT ” which is submitted by B.Kruthika Reddy (2210315833), M.Sai
Venkata Chaitanya(2210315842), M.Shiva Shankar(2210315843) & Y.Venkata
Narasimha Reddy(2210315863) students of VII Semester, IV year (Batch no:-
<MPBSNUM_114>) in partial fulfilment of the requirement for their mini project
work carried out under my guidance and supervision.

A.Phani Sheetal Dr.S.Phani Kumar


Assistant professor HOD-CSE
Project Guide

Name and signature of panel member(s).

1.

2.

3.

II
DECLARATION

We ,B.Kruthika Reddy (2210315833), M.Sai Venkata Chaitanya


(2210315842), M.Shiva Shankar (2210315843) & Y.Venkata Narasimha Reddy
(2210315863) hereby declare that the mini project report entitled “PYTHON GAME
DEVELOPMENT”, under the guidance of A.Phani Sheetal , Assistant Professor,
Department of Computer Science and Engineering, School of Technology ,GITAM
(Deemed to be University) , Hyderabad, has been submitted mini project evaluation .

This is a record of bona fide work carried out by us and the content embodied
in this project have not been reproduced /copied from any source. The content
embodied in this project report have not been submitted to any other university or
institute for the award of any other degree or diploma.

M.SHIVA SHANKAR
(2210315843)

M.SAI VENKATA CHAITANYA


(2210315842)

B.KRUTHIKA REDDY
(2210315833)

Y.VENKATA NARASIMHA REDDY


(2210315863)

III
ACKNOWLEDGEMENT

We would like to express our sincere gratitude to our guide Mrs.Phani


Sheetal(Assistant Professor) for providing their invaluable guidance, comments and
suggestions throughout the period of our work. We would like to specially thank
Mr.Rajendra Prasad for guiding us and helping us with the procedure to be followed
for the fulfilment of our project
We would also like to thank Dr.S.Phani Kumar (HOD CSE Department) for
giving us the opportunity to do mini project and including it as apart of our
curriculum .

IV
LIST OF CONTENTS

TITLE I
CERTIFICATE II
DECLARATION III
ACKNOWLEDGEMENT IV
CONTENTS V,VI
ABSTRACT VII
LIST OF FIGURES VIII
LIST OF SCREENS XI

1. INTRODUCTION……………………………………………….….…1
2. LITERATURE SURVEY………………………………………..…….2
2.1 EXSISTING SYSTEM………………………………………….…2
2.2 LIMITATION…………………………………………..…….……3
2.3 PROPOSED SYSTEM..……………………………………..……3
2.4 ADVANTAGES………….……………………………….…….…5
2.5 PYTHON DISADVANTAGES………………………………..….6
3. ANALYSIS……………………………………………………………7
3.1 SOFTWARE FLOW………………………………………….…..7
3.2 SOFTWARE AND HARDWARE INTERFACE………..…..……7
3.3 MINIMUM SYSTEM REQUIREMENTS……………………….8
3.4 SOURCE CODE………………………………………………….9
3.5 SOUND INTEGRATION………………………………..………30
4. DESIGN……………………………………………………..………32
4.1 GAME DESIGN APPROACH……………………………….…32
4.1 UML DIAGRAMS………………………………………………36
4.2 MODULES AND FUNCTIONALITY……………………….…41

V
5. TESTING……………………………………………………………44
5.1 TESTING STRATEGIES………………………………………44
5.2 COMMON BUGS……………………………………………..45
6.SCREEN OUTPUTS………………………………..……….…..….47
7.COGNITIVE BENIFITS OF GAMING……..………………….…..52
8.DISADVANTAGES OF GAMING…..………………….…….……55
9.CONCLUSION………………………………………..…………….57
10.FUTURE WORKS………………………………………..……..…58
11.BIBLIOGRAPHY…………………………………………….……59

VI
Python Game Development

ABSTRACT

It is always great to build games with graphical interface .Python GUI

Programming + Turtle + other advanced python modules are used to build graphical
user interfaces (GUI) and games from scratch. By learning from basics of Python i.e.
variables, slicing, string, some module, arithmetic and logical operations, looping,
functions, object oriented programming it creates the base for logical
implementation .After getting familiar with the basics & by understanding the
working of Pygame , Pymunk and OpenGL and Blender basics stuff. By using all the
tools, softwares mentioned above we are planning to make a game from the various
ideas we got such as 2d racing with some AI control for traffic or Arcade game.

VII
LIST OF FIGURES

Figure A……………………………………….…………………..7

Figure B:Game approach…………………….…………….…….32

Figure B:Class Diagram………………….……………………….36

Figure C:UseCase Diagram……………………………………….37

Figure D:Sequence Digram……………………………………….38

Figure F:UseCase Diagram……………………………………….39

Figure G:FlowChart…………………..……………………….….40

VIII
LIST OF SCREENS

Figure H:Initial Display……………………………….……….….24

Figure I:After Initial………………………………………….….25

Figure J:User Input……………………………..……………..….26

Figure K:Avoid Collision…………………………..………..…….26

Figure L:Case of collision…………………………………….….27

Figure M:Goal State……………………………………..….…….27

Figure N:Game over………………………………….………….28

IX
PYTHON GAME DEVELOPMENT

1.INTRODUCTION

Python is an interpreted high-level programming language for general-


purpose programming.Python features a dynamic type system and automatic memory
management. It supports multiple programming paradigms, including object-oriented,
imperative, functional and procedural, and has a large and comprehensive standard
library.

In order to make games with the Python language, it is essential to use


Pygame ,it is a cross platform Python library which wraps SDL. It provides many
features like Sprite groups and sound/image loading and easy changing of an objects
position. It also provides the programmer access to key and mouse events.So the
game which is a part of mini project is in 2-D(two dimensions) so it makes it
compatible to use python with pygame module.

To work upon the game it is essential to have prerequisite knowledge on the


syntax of python. The IDLE which is editor which comes along with python during
installation can be used for development .PyCharm is an IDE which is quite suitable
for developing python games.

The 2-D game is about Car Racing With Some AI control for Traffic. The
objective of the game is to collect the trophies placed in random location of map by
avoiding the traffic and collision by the other cars. The game can be integrated with
Music to get real gaming experience.

SoT,GU-HYD,Dept of CSE, 2018-19 1


PYTHON GAME DEVELOPMENT

2.LITERATURE SURVEY

2.1 Existing System


The existing system called 2D-game development using Raspberry Pi
published in 2016 International Conference on Information Communication and
Embedded Systems (ICICES) .This is IEEE standard project game development
mentioned in the IEEE explore.

The existing system explains that Raspberry Pi is a single board computer with
ARM11 microprocessor and sizes in the dimension of a credit card. The main idea of
this paper is about controlling a game, written in Python Tkinter, using Accelerometer
and Hand Gestures. Accelerometer is conjoined with Raspberry Pi for detecting left or
right movements and by the tilting of the device, the game is controlled by Pi. Hand
gestures will be captured by camera module which is interfaced with Raspberry Pi
then ascertains the hand gestures using SimpleCV and an image processing program
written in python, which is installed in Raspberry Pi.

At present the input device which is primarily used to manipulate video games
is called a game controller, and varies across platforms. For example, a controller
might consist of only a button and a joystick, while another may feature a dozen
buttons and one or more joysticks.

Early personal computer games often needed a keyboard for gameplay, or


more commonly, required the user to buy a joystick with at least one button. Many
modern computer games allow or require player to use a keyboard and a mouse
simultaneously. A few of the most common game controllers are gamepads, mouse,
keyboards, and joysticks.

SoT,GU-HYD,Dept of CSE, 2018-19 2


PYTHON GAME DEVELOPMENT

2.2 Limitations
The following points express the limitations of the existing system :

The existing system uses a accelerometer and other sensors to get the inputs for the
game but , the sensor might get some noise in the values due to external
environment factors .

Since the input is taken through sensors the processing of input might take long
time .

Raspberry Pie being a Mini computer with limited capabilities and system
configuration it usually crashes when there are a lot of processes running .

Raspberry Pie due to its restricted System configuration , it sometimes can’t render
the required frames per second (FPS) for the game and the game becomes too
slow . It takes a lot of time to load environment in the game.

Since the Raspberry Pie doesn’t have any GPU or graphic card it is impossible for
rendering some graphics and it is not possible to output the threshold amount of
resolution and pixels .

2.3 Proposed System

The 2-D game development is done using Python and the modules supporting
it. It makes use of PyGame module for implementing the graphics ,movements and
actions that should be performed on objects in the game for the input given by the
gamer. Nowadays, pip is probably the best method for installing PyGame, since it
comes with the latest versions of Python 2 and Python 3.Pygame is a cross-platform
set of Python modules designed for writing video games. It includes computer

SoT,GU-HYD,Dept of CSE, 2018-19 3


PYTHON GAME DEVELOPMENT

graphics and sound libraries designed to be used with the Python programming
language.

Pygame is a python module used to program games like tkinter is also python
module pygame programming is a bit complicated, Built over the Simple DirectMedia
Layer (SDL) library, with the intention of allowing real-time computer game
development without the low-level mechanics of the C programming language and its
derivatives. This is based on the assumption that the most expensive functions inside
games (mainly the graphics part) can be abstracted from the game logic, making it
possible to use a high-level programming language, such as Python, to structure the
game.

Applications using pygame can run on Android phones and tablets with the
use of Pygame Subset for Android . Sound, vibration, keyboard, and accelerometer
are supported on Android.The 2-D python game is about a Car game . The description
of the game is given with respect to the performance , environment ,actuators and
other percepts (inputs) .

Initially the car appears in some random location of the map .The car may end
up on dead end road , T junction road , X road or on a Straight lane road . The user or
gamer is supposed to control the car using the arrow keys , the forward pointing
arrow is for accelerating forward and backward pointing arrow is for decelerating .the
left ,right arrows keys are used to turn the car lest and right respectively . The time
duration of the game is usually 60 seconds or 1 minute . The user can get points by
collecting the violets trophies that he/she finds in the different locations of the map .

The user can get to know the location of the trophies by analysing the arrow direction
shown on the bottom right of the screen .The real challenge comes into play when
user is subjected to the traffic caused by the other cars which run in random locations
or others ways in the map. The gamer or user when makes any collision with the other
cars using his own car then the score is deducted.

SoT,GU-HYD,Dept of CSE, 2018-19 4


PYTHON GAME DEVELOPMENT

The number of cars running on the road can be changed. The acceleration and
top speed of the other cars and the gamer car can be changed .

2.4The Advantages

The advantages when compared to the existing system are mentioned below:-

The game takes input from the keyboard rather than the sensors , so there is no
question of discrepancy or noise in the input which the game gets .

A major advantage of using Python for game development is that the language is
very easy to learn Apart from that, you will be heavily into Object oriented with
Python even though it may seem that you aren't doing anything related to object
oriented Python is completely object oriented for that fact .

The language is agile by nature and makes refactoring easy, thus ensuring constant
improvement of your game design and higher code quality. Python is designed to
easily call from and to C, C++ and Java code, so, say, the need to write
performance-intensive modules of your game in C++ will not bring trouble .

Extensive out-of-the-box tools


Python comes in handy with a vast standard library, well-designed built-ins and the
availability of multiple third-party libraries and models for database access, math,
statistics, COM and much more. With many pre-built programming tasks at their
fingertips, developers can do more with less code.

Rapid prototyping
With Python, you can try out new ideas and solutions in a day, not weeks, or you can
even integrate prototyping in the development process. The language is agile by

SoT,GU-HYD,Dept of CSE, 2018-19 5


PYTHON GAME DEVELOPMENT

nature and makes refactoring easy, thus ensuring constant improvement of your game
design and higher code quality.

Integration
Python is designed to easily call from and to C, C++ and Java code, so, say, the need
to write performance-intensive modules of your game in C++ will not bring trouble. It
is possible to write and debug code in Python and then convert it by hand into C++.

Cross-platform
Python games perform smoothly on a platform, making support cost-saving and easy.

2.5Python Disadvantages

Performance
An interpreted language, Python is expected to run slower than compiled languages.
However, according to Brian Curtin, a member of the Python Software Foundation
board of directors and a core contributor to CPython, it’s all about separating the
language from the runtime. “Certain benchmarks of Python code run under PyPy run
faster than the equivalent C code or others,” he says.

Design limitations
As a dynamically typed language, Python requires considerable testing, bringing
errors that only show up at runtime.

SoT,GU-HYD,Dept of CSE, 2018-19 6


PYTHON GAME DEVELOPMENT

3.ANALYSIS

3.1 Software Flow:-


In terms of software, the car racing game can be showed as:
(Figure A)

3.2 Hardware and Software interface:-


The basic hardware modules are keyboard and VGA screen, therefore, the
interface is to connect this two modules with software.
To achieve this, we should implement the two hardware drivers.

DRIVER BASIC IMPLEMENTATION FUNCTION


KEYBOARD Detect accelerate ,decelerate ,steer left and right.

VGA SCREEN DRIVER Render and show cars and background environment

SoT,GU-HYD,Dept of CSE, 2018-19 7


PYTHON GAME DEVELOPMENT

3.3 The Minimum System Requirements

For installing Python


Processor:-Single core or multiple core processor
RAM:-1 Gb or more
64 Mb graphics
ROM:- 40 Gb (for OS and its requirements)
Operating System:-Windows ,Mac OS and Linux

For installing PyCharm


Windows:
• Microsoft Windows 10/8/7/Vista/2003/XP (incl.64-bit)
• 1 GB RAM minimum
• 2 GB RAM recommended
• 1024x768 minimum screen resolution
• Python 2.4 or higher, Jython, PyPy or IronPython

Mac:
• Mac OS X 10.8 or higher
• 1 GB RAM minimum
• 2 GB RAM recommended
• Python 2.4 or higher, Jython, PyPy or IronPython

Linux:
• 512 MB RAM minimum,
• 1 GB RAM recommended
• 1024x768 minimum screen resolution
• Python 2.4 or higher, Jython, PyPy or IronPython

SoT,GU-HYD,Dept of CSE, 2018-19 8


PYTHON GAME DEVELOPMENT

3.4 Source Code

3.4.1 MAIN MODULE:-


import os, sys, pygame, random, array, gamemode
import direction, bounds, timeout, menu
from pygame.locals import *

#Import game modules.


from loader import load_image
import player, maps, traffic, camera, tracks
from pygame import mixer # Load the required library

mixer.init()
mixer.music.load('/Users/shivashankar/Desktop/RACEGAME/media/uturn.mp3')
mixer.music.play()

TRAFFIC_COUNT = 500
CENTER_W = -1
CENTER_H = -1

#Main function.
def main():
#initialize objects.
clock = pygame.time.Clock()
running = True
font = pygame.font.Font(None, 24)
car = player.Player()

SoT,GU-HYD,Dept of CSE, 2018-19 9


PYTHON GAME DEVELOPMENT

cam = camera.Camera()
target = gamemode.Finish()
bound_alert = bounds.Alert()
time_alert = timeout.Alert()
info = menu.Alert()
pointer = direction.Tracker(int(CENTER_W * 2), int(CENTER_H * 2))
#create sprite groups.
map_s = pygame.sprite.Group()
player_s = pygame.sprite.Group()
traffic_s = pygame.sprite.Group()
tracks_s = pygame.sprite.Group()
target_s = pygame.sprite.Group()
pointer_s = pygame.sprite.Group()
timer_alert_s = pygame.sprite.Group()
bound_alert_s = pygame.sprite.Group()
menu_alert_s = pygame.sprite.Group()

#generate tiles
for tile_num in range (0, len(maps.map_tile)):
maps.map_files.append(load_image(maps.map_tile[tile_num], False))
for x in range (0, 10):
for y in range (0, 10):
map_s.add(maps.Map(maps.map_1[x][y], x * 1000, y * 1000,
maps.map_1_rot[x][y]))

#load tracks
tracks.initialize()
#load finish
target_s.add(target)
#load direction

SoT,GU-HYD,Dept of CSE, 2018-19 10


PYTHON GAME DEVELOPMENT

pointer_s.add(pointer)
#load alerts
timer_alert_s.add(time_alert)
bound_alert_s.add(bound_alert)
menu_alert_s.add(info)
#load traffic
traffic.initialize(CENTER_W, CENTER_H)
for count in range(0, TRAFFIC_COUNT):
traffic_s.add(traffic.Traffic())

player_s.add(car)

cam.set_pos(car.x, car.y)

while running:
#Render loop.

#Check for menu/reset, (keyup event - trigger ONCE)


for event in pygame.event.get():
if event.type == pygame.KEYUP:
if keys[K_m]:
if (info.visibility == True):
info.visibility = False
else:
info.visibility = True
if (keys[K_p]):
car.reset()
target.reset()
if (keys[K_q]):
pygame.quit()

SoT,GU-HYD,Dept of CSE, 2018-19 11


PYTHON GAME DEVELOPMENT

sys.exit(0)

if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:


running = False
break

#Check for key input. (KEYDOWN, trigger often)


keys = pygame.key.get_pressed()
if (target.timeleft > 0):
if keys[K_LEFT]:
car.steerleft()
if keys[K_RIGHT]:
car.steerright()
if keys[K_UP]:
car.accelerate()
else:
car.soften()
if keys[K_DOWN]:
car.deaccelerate()

cam.set_pos(car.x, car.y)

#Show text data.


text_fps = font.render('FPS: ' + str(int(clock.get_fps())), 1, (224, 16, 16))
textpos_fps = text_fps.get_rect(centery=25, centerx=60)

text_score = font.render('Score: ' + str(target.score), 1, (224, 16, 16))


textpos_score = text_fps.get_rect(centery=45, centerx=60)

SoT,GU-HYD,Dept of CSE, 2018-19 12


PYTHON GAME DEVELOPMENT

text_timer = font.render('Timer: ' + str(int((target.timeleft / 60)/60)) + ":" +


str(int((target.timeleft / 60) % 60)), 1, (224, 16, 16))
textpos_timer = text_fps.get_rect(centery=65, centerx=60)

#Render Scene.
screen.blit(background, (0,0))

#cam.set_pos(car.x, car.y)

map_s.update(cam.x, cam.y)
map_s.draw(screen)

#Conditional renders/effects
car.grass(screen.get_at(((int(CENTER_W-5), int(CENTER_H-5)))).g)
if (car.tracks):
tracks_s.add(tracks.Track(cam.x + CENTER_W, cam.y + CENTER_H,
car.dir))

#Just render..
tracks_s.update(cam.x, cam.y)
tracks_s.draw(screen)

player_s.update(cam.x, cam.y)
player_s.draw(screen)

traffic_s.update(cam.x, cam.y)
traffic_s.draw(screen)

target_s.update(cam.x, cam.y)
target_s.draw(screen)

SoT,GU-HYD,Dept of CSE, 2018-19 13


PYTHON GAME DEVELOPMENT

pointer_s.update(car.x + CENTER_W, car.y + CENTER_H, target.x, target.y)


pointer_s.draw(screen)

#Conditional renders.
if (bounds.breaking(car.x+CENTER_W, car.y+CENTER_H) == True):
bound_alert_s.update()
bound_alert_s.draw(screen)
if (target.timeleft == 0):
timer_alert_s.draw(screen)
car.speed = 0
text_score = font.render('Final Score: ' + str(target.score), 1, (224, 16, 16))
textpos_score = text_fps.get_rect(centery=CENTER_H+56,
centerx=CENTER_W-20)
if (info.visibility == True):
menu_alert_s.draw(screen)

#Blit Blit..
screen.blit(text_fps, textpos_fps)
screen.blit(text_score, textpos_score)
screen.blit(text_timer, textpos_timer)
pygame.display.flip()

#Check collision!!!
if pygame.sprite.spritecollide(car, traffic_s, False):
car.impact()
target.car_crash()

if pygame.sprite.spritecollide(car, target_s, True):


target.claim_flag()

SoT,GU-HYD,Dept of CSE, 2018-19 14


PYTHON GAME DEVELOPMENT

target.generate_finish()
target_s.add(target)
clock.tick(64)

#initialization
pygame.init()
screen = pygame.display.set_mode((pygame.display.Info().current_w,
pygame.display.Info().current_h),
pygame.FULLSCREEN)

pygame.display.set_caption('Race of Math.')
pygame.mouse.set_visible(False)
font = pygame.font.Font(None, 24)

CENTER_W = int(pygame.display.Info().current_w /2)


CENTER_H = int(pygame.display.Info().current_h /2)

#new background surface


background = pygame.Surface(screen.get_size())
background = background.convert_alpha()
background.fill((26, 26, 26))

#Enter the mainloop.


main()
pygame.quit()
sys.exit(0)

SoT,GU-HYD,Dept of CSE, 2018-19 15


PYTHON GAME DEVELOPMENT

3.4.2 TRAFFIC MODULE


import pygame, os, sys, math, maps
from pygame.locals import *
from random import randint
from loader import load_image

BOUND_MIN = 380
BOUND_MAX = 620
TURN_LOCK = 375
DISPLACEMENT = 65
CENTER_W = -1
CENTER_H = -1
HALF_TILE = 500

cars = []
car_files = ['traffic1.png', 'traffic2.png', 'traffic3.png',
'traffic4.png', 'traffic5.png']

#Rotate cars.
def rot_center(image, rect, angle):
"""rotate an image while keeping its center"""
rot_image = pygame.transform.rotate(image, angle)
rot_rect = rot_image.get_rect(center=rect.center)
return rot_image,rot_rect

#Initialize cars.
def initialize(center_w, center_h):
CENTER_W = center_w
CENTER_H = center_h

SoT,GU-HYD,Dept of CSE, 2018-19 16


PYTHON GAME DEVELOPMENT

for index in range(0, len(car_files)):


cars.append(load_image(car_files[index], True))

#Traffic sprite and AI controller


class Traffic(pygame.sprite.Sprite):

def road_tile(self):
x = randint(0,9)
y = randint(0,9)
while (maps.map_1[x][y] != 0):
x = randint(0,9)
y = randint(0,9)
return x * 1000 + HALF_TILE, y * 1000 + HALF_TILE

#Turn the vehicle!


def turning(self):
self.turning_cooldown = TURN_LOCK
try:
tile_type = maps.map_1[int((self.y + CENTER_H) / 1000)][int((self.x +
CENTER_W) / 1000)]
tile_rot = maps.map_1_rot[int((self.y + CENTER_H) / 1000)][int((self.x +
CENTER_W) / 1000)]

#turn controller
if tile_type == maps.turn:
if (tile_rot + 2 == self.dir / 90) or (-(tile_rot + 2) == self.dir / 90):
self.dir += 90
else:
self.dir -= 90

SoT,GU-HYD,Dept of CSE, 2018-19 17


PYTHON GAME DEVELOPMENT

#split controller
if tile_type == maps.split:
self.dir = -180 - tile_rot * 90
self.dir += randint(-1, 1) * 90

#crossing controller
if tile_type == maps.crossing:
self.dir += randint(1,3) * 90

#dead end controller


if tile_type == maps.deadend:
self.dir -= 180

except:
return

#Rotate the image.


def rotate(self):
self.image, self.rect = rot_center(self.image_orig, self.rect, self.dir)

#Initialize the object.


def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = cars[randint(0, len(cars))-1]
self.rect = self.image.get_rect()
self.image_orig = self.image
self.screen = pygame.display.get_surface()
self.id = randint(0,99)
self.area = self.screen.get_rect()
self.x, self.y = self.road_tile()

SoT,GU-HYD,Dept of CSE, 2018-19 18


PYTHON GAME DEVELOPMENT

self.rect.topleft = self.x, self.y


self.dir = 0
self.turning()
self.rotate()
self.speed = randint(145, 245) / 100
self.turning_cooldown = 0

#Update the position.


def update(self, cam_x, cam_y):
"""update direction of traffic based on current tile"""
self.x = self.x + self.speed * math.cos(math.radians(270-self.dir))
self.y = self.y + self.speed * math.sin(math.radians(270-self.dir))

#trigger turn when vehicle is at center of tile.


if (self.turning_cooldown > 0):
self.turning_cooldown = self.turning_cooldown - 1
elif (randint(0, DISPLACEMENT) == 2):
if (self.x % 1000 > BOUND_MIN and self.x % 1000 < BOUND_MAX):
if (self.y % 1000 > BOUND_MIN and self.y % 1000 < BOUND_MAX):
self.turning()
self.rotate()

self.rect.topleft = self.x - cam_x, self.y - cam_y

3.4.3 PLAYER MODULE


import os, sys, pygame, math, maps
from pygame.locals import *
from random import randint
from loader import load_image

SoT,GU-HYD,Dept of CSE, 2018-19 19


PYTHON GAME DEVELOPMENT

#base variables
GRASS_SPEED = 0.715 #what is speed of car on grass
GRASS_GREEN = 75
CENTER_X = -1
CENTER_Y = -1

#Rotate car.
def rot_center(image, rect, angle):
"""rotate an image while keeping its center"""
rot_image = pygame.transform.rotate(image, angle)
rot_rect = rot_image.get_rect(center=rect.center)
return rot_image,rot_rect

def findspawn(): # find the position in which player reside


x = randint(0,9)
y = randint(0,9)
while(maps.map_1[y][x] == 5):
x = randint(0,9)
y = randint(0,9)
return x * 1000 + CENTER_X, y * 1000 + CENTER_Y

#define car as Player.


class Player(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = load_image('car_player.png')
self.rect = self.image.get_rect()
self.image_orig = self.image
self.screen = pygame.display.get_surface()
self.area = self.screen.get_rect()

SoT,GU-HYD,Dept of CSE, 2018-19 20


PYTHON GAME DEVELOPMENT

CENTER_X = int(pygame.display.Info().current_w /2)


CENTER_Y = int(pygame.display.Info().current_h /2)
self.x = CENTER_X
self.y = CENTER_Y
self.rect.topleft = self.x, self.y
self.x, self.y = findspawn()
self.dir = 0
self.speed = 0.0
self.maxspeed = 14.5
self.minspeed = -1.85
self.acceleration = 0.1
self.deacceleration = 0.12
self.softening = 0.04
self.steering = 1.60
self.tracks = False
#Reset the car to position
def reset(self):
self.x = int(pygame.display.Info().current_w /2)
self.y = int(pygame.display.Info().current_h /2)
self.speed = 0.0
self.dir = 0
self.image, self.rect = rot_center(self.image_orig, self.rect, self.dir)
self.rect.topleft = self.x, self.y
self.x, self.y = findspawn()

#Emit tracks.. to show track


def emit_tracks(self):
self.tracks = True

#Don't emit tracks..

SoT,GU-HYD,Dept of CSE, 2018-19 21


PYTHON GAME DEVELOPMENT

def reset_tracks(self):
self.tracks = False

#If the car is on grass, decrease speed and emit tracks.


def grass(self, value):
if value > GRASS_GREEN:
if self.speed - self.deacceleration > GRASS_SPEED * 2:
self.speed = self.speed - self.deacceleration * 2
self.emit_tracks()

#Push back on impact


def impact(self):
if self.speed > 0:
self.speed = self.minspeed

def soften(self):
if self.speed > 0:
self.speed -= self.softening
if self.speed < 0:
self.speed += self.softening

#Accelerate the vehicle


def accelerate(self):
if self.speed < self.maxspeed:
self.speed = self.speed + self.acceleration
if self.speed < self.maxspeed / 3:
self.emit_tracks()

#Deaccelerate.
def deaccelerate(self):

SoT,GU-HYD,Dept of CSE, 2018-19 22


PYTHON GAME DEVELOPMENT

if self.speed > self.minspeed:


self.speed = self.speed - self.deacceleration
self.emit_tracks()

#Steer.
def steerleft(self):
self.dir = self.dir+self.steering
if self.dir > 360:
self.dir = 0
if (self.speed > self.maxspeed / 2):
self.emit_tracks()
self.image, self.rect = rot_center(self.image_orig, self.rect, self.dir)

#Steer.
def steerright(self):
self.dir = self.dir-self.steering
if self.dir < 0:
self.dir = 360
if (self.speed > self.maxspeed / 2):
self.emit_tracks()
self.image, self.rect = rot_center(self.image_orig, self.rect, self.dir)

#fix this function


def update(self, last_x, last_y):
self.x = self.x + self.speed * math.cos(math.radians(270-self.dir))
self.y = self.y + self.speed * math.sin(math.radians(270-self.dir))
self.reset_tracks()

3.4.4 MAP FILE MODULE


import os, sys, pygame, math

SoT,GU-HYD,Dept of CSE, 2018-19 23


PYTHON GAME DEVELOPMENT

from pygame.locals import *


from loader import load_image
from random import randrange

# Map filenames.
map_files = []
map_tile = ['X.png', 'I.png', 'L.png', 'T.png', 'O.png', 'null.png'] #images of file

# Map to tile.
crossing = 0
straight = 1
turn = 2
split = 3
deadend = 4
null = 5

# tilemap.
map_1 = [
[2, 1, 3, 1, 1, 3, 1, 1, 1, 4],
[1, 5, 1, 5, 4, 0, 1, 2, 5, 4],
[1, 4, 3, 1, 3, 3, 1, 3, 2, 1],
[3, 1, 3, 1, 3, 5, 4, 5, 1, 1],
[3, 2, 1, 5, 1, 5, 3, 1, 0, 3],
[1, 2, 0, 1, 0, 3, 0, 4, 1, 1],
[1, 5, 1, 4, 2, 1, 1, 2, 3, 1],
[1, 2, 0, 1, 3, 3, 0, 0, 2, 1],
[1, 1, 4, 2, 2, 5, 1, 2, 1, 3],
[2, 3, 1, 3, 1, 1, 3, 1, 1, 2]
]

SoT,GU-HYD,Dept of CSE, 2018-19 24


PYTHON GAME DEVELOPMENT

# tilemap rotation, x90ccw


map_1_rot = [
[1, 1, 0, 1, 1, 0, 1, 1, 1, 3],
[0, 0, 0, 0, 1, 0, 1, 0, 0, 0],
[0, 1, 2, 1, 0, 2, 1, 2, 0, 0],
[1, 1, 0, 1, 3, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 0, 1, 1, 0, 3],
[0, 2, 0, 1, 0, 0, 0, 3, 0, 0],
[0, 0, 0, 1, 3, 0, 0, 1, 3, 0],
[0, 1, 0, 1, 0, 2, 0, 0, 3, 0],
[0, 0, 2, 1, 3, 0, 0, 2, 1, 3],
[2, 2, 1, 2, 1, 1, 2, 1, 1, 3]
]

class Map(pygame.sprite.Sprite):
def __init__(self, tile_map, y, x, rot):
pygame.sprite.Sprite.__init__(self)
self.image = map_files[tile_map]
self.rect = self.image.get_rect()

if rot != 0:
self.image = pygame.transform.rotate(self.image, rot * 90)

self.x = x
self.y = y

# Realign the map


def update(self, cam_x, cam_y):
self.rect.topleft = self.x - cam_x, self.y - cam_y

SoT,GU-HYD,Dept of CSE, 2018-19 25


PYTHON GAME DEVELOPMENT

3.4.5 CAMERA MODULE.


#Show a dialog when time is out.
from loader import load_image
import pygame
from pygame.locals import *

NOTE_HALF_X = 212
NOTE_HALF_Y = 112

#Alert body.
class Alert(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = load_image('timeout.png')
self.rect = self.image.get_rect()
self.x = int(pygame.display.Info().current_w /2) - NOTE_HALF_X
self.y = int(pygame.display.Info().current_h /2) - NOTE_HALF_Y
self.rect.topleft = self.x, self.y

3.5.6 DIRECTIONS MODULE


import pygame, math
from pygame.locals import *
from loader import load_image

PI = 3.14
#rotate the arrow.
def rot_center(image, rect, angle):
"""rotate an image while keeping its center"""
rot_image = pygame.transform.rotate(image, angle)
rot_rect = rot_image.get_rect(center=rect.center)

SoT,GU-HYD,Dept of CSE, 2018-19 26


PYTHON GAME DEVELOPMENT

return rot_image,rot_rect

#Guide the player with a giant arrow.


class Tracker(pygame.sprite.Sprite):

def __init__(self, screen_x, screen_y):


pygame.sprite.Sprite.__init__(self)
self.image_orig = load_image('direction.png', False)
self.image = self.image_orig
self.rect = self.image.get_rect()
self.rect_orig = self.rect
self.x = screen_x - 150
self.y = screen_y - 150
self.rect.topleft = self.x, self.y
self.dir = 0

#Update the rotation of the arrow.


def update(self, point_x, point_y, target_x, target_y):
self.dir = (math.atan2(point_y - target_y, target_x - point_x) * 180 / PI)
self.image, self.rect = rot_center(self.image_orig, self.rect_orig, self.dir)

3.4.7 BOUNDS MODULE


from loader import load_image
import pygame
from pygame.locals import *

BOUND_MIN = 0
BOUND_MAX = 1000 * 10
NOTE_HALF_X = 211
NOTE_HALF_Y = 112

SoT,GU-HYD,Dept of CSE, 2018-19 27


PYTHON GAME DEVELOPMENT

#check the bounds vs car coordinates.

def breaking(car_x, car_y):


if car_x < BOUND_MIN or car_x > BOUND_MAX:
return True
if (car_y < BOUND_MIN or car_y > BOUND_MAX):
return True
return False

#alertbox.
class Alert(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = load_image('bounds.png')
self.rect = self.image.get_rect()
self.x = int(pygame.display.Info().current_w /2) - NOTE_HALF_X
self.y = int(pygame.display.Info().current_h /2) - NOTE_HALF_Y
self.rect.topleft = self.x, self.y

3.4.8 TIMEOUT MODULE


#Show a dialog when time is out.
from loader import load_image
import pygame
from pygame.locals import *

NOTE_HALF_X = 212
NOTE_HALF_Y = 112

#Alert body.
class Alert(pygame.sprite.Sprite):

SoT,GU-HYD,Dept of CSE, 2018-19 28


PYTHON GAME DEVELOPMENT

def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = load_image('timeout.png')
self.rect = self.image.get_rect()
self.x = int(pygame.display.Info().current_w /2) - NOTE_HALF_X
self.y = int(pygame.display.Info().current_h /2) - NOTE_HALF_Y
self.rect.topleft = self.x, self.y

3.4.9 MENU AND GAME DESCRIPTION MODULE


from loader import load_image
import pygame
from pygame.locals import *

BOUND_MIN = 0
BOUND_MAX = 1000 * 10
NOTE_HALF_X = 211
NOTE_HALF_Y = 242

#Alert box.
class Alert(pygame.sprite.Sprite):
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.image = load_image('menu.png')
self.rect = self.image.get_rect()
self.x = int(pygame.display.Info().current_w /2) - NOTE_HALF_X
self.y = int(pygame.display.Info().current_h /2) - NOTE_HALF_Y
self.rect.topleft = self.x, self.y
self.visibility = True

SoT,GU-HYD,Dept of CSE, 2018-19 29


PYTHON GAME DEVELOPMENT

3.5 Sound Integration

Video games are meant to immerse the player into a sort of virtual reality. We
do this mainly visually, but it can make a massive difference and be a massive
improvement to your game if you add sounds as well.
Sounds generally come in two major forms: Either "ambient" noise or as
results of player actions. With PyGame, you get two choices: Music or Sounds. Music
will just play in the background when you call it to, and sounds will play at any time
you call them to play. We're going to cover both here by adding them both to our
current game. First, use a simple tune from YouTube as our game's music and then
add a "crash" sound that will play if we hit any of the blocks.

To start, let's make a sound:


crash_sound = pygame.mixer.Sound("crash.wav")

The above will assign the crash.wav sound file to play when we call
crash_sound within PyGame's sound playing functionality. Notice the file is .wav.
PyGame can handle .mp3 as well, but it is somewhat glitchy, and will work
sometimes and other times it wont. For the safest bet, go with .wav.
Now that we know how to call sounds, how can we do music?

pygame.mixer.music.load('jazz.wav')
pygame.mixer.music.play(-1)

The above code will play the music file indefinitely (though you can call it to
stop). The -1 signals PyGame to just play forever, but, if you put, say, a 5 in there,
then the music would play once and 5 more times.
Now, want the music to play, and it is, then crash sound to play when
crashed. Also, like to stop the music if this is the case.
So, within our crash function…

SoT,GU-HYD,Dept of CSE, 2018-19 30


PYTHON GAME DEVELOPMENT

def crash():
pygame.mixer.Sound.play(crash_sound)
pygame.mixer.music.stop()
largeText = pygame.font.SysFont("comicsansms",115)
TextSurf, TextRect = text_objects("You Crashed", largeText)
Above, calling PyGame to play the crash_sound, as well as to stop the music.
This means the music will start over again if the game is re-played.
Now, the only other thing to do is learn how to pause/unpause music when the
player pauses the game. This is easy enough.

In our paused function:


def paused():
pygame.mixer.music.pause()

And then of course we must unpause it:

def unpause():
global pause
pygame.mixer.music.unpause()
pause = False

SoT,GU-HYD,Dept of CSE, 2018-19 31


PYTHON GAME DEVELOPMENT

4.DESIGN

4.1 Game Design Approach


(Figure B)

Examining complex processes is never an easy task; thus, approaches that try
to divide such complexity into smaller parts that can be more easily understood are
necessary. This is called analysis. Analysing the game design cognition process is a
critical part of developing a deeper understanding about how such process works.

SoT,GU-HYD,Dept of CSE, 2018-19 32


PYTHON GAME DEVELOPMENT

Therefore, proposing the following layered view as a breakdown of the game design
cognitive process, where each layer corresponds to a generalisation or

abstraction of the layers below it, and a specialisation or concretisation of the layers
above it.

The Concept Layer


Concept is a pretty broad term meaning “the abstract description of an idea”.
In games, the concept is composed of a couple of phrases that describe the game's
style, general setting, and sometimes the main plot motivation, as well as the types of
characters and interactions involved. Game concepts are generally short, but they
serve as the ultimate definition of the game, something that the developers should
keep in mind at all times to make sure that they are really making the game they were
supposed to.

Therefore, the game concept is the topmost layer of our proposed architecture,
tying all the other layers together into cohesive game design.As an example of a game
with a strong concept behind it, let's take a look at Blizzard's blockbuster Diablo. The
game could be described as “a fantasy role-playing game with a strong focus on hack-
and-slash action, item collection and dungeon exploration”.

The whole game has been constructed around this concept, such that items
with increasing power both allow and drive the player to explore the dungeon deeper
and deeper, killing more and more monsters to get another, even more powerful item,
and so on.

SoT,GU-HYD,Dept of CSE, 2018-19 33


PYTHON GAME DEVELOPMENT

Context Layer
The context of a game, as far as the proposed architecture is concerned,
comprises the story, circumstances and motivation presented to the player. Why must
the player do what he is doing? Does he have to save the princess from the castle or

must he save the world from an alien invasion? The context does not have to be story-
driven, but it must define a more concrete view of the game that the players can easily
refer to.

The Core Layer: Content and Features


Although the context defines a more material view of the game's concept, it
still lacks any game-specific components. For example, the concept and context of a
game could also be implemented as a movie or a book, with only minor adjustments.
It is in the next layer down the line that such game-related functionality becomes
clear.

Contents of a game are basically what players see and most often can touch
inside the game space. The player's avatar itself is game content, together with any
other characters, weapons, items, scenario objects, etc., that are there for the player to
interact with, using the game system. We can think of content as the concretisation of
the game from the perspective of the player.

Features, on the other hand, are the mid-level description of gameplay, often
represented as use cases (“squad control”, ”vehicle riding”) and broad system
descriptions (“price fluctuation”, “real-time cloth physics”), which comprise the
different ways in which the player can touch the game or be touched by it. They also
define the nature of the player's interaction, in terms of the feedback perceived by the
player from his actions in the game world (“destructible environments”, “believable
emotional NPCs”).

SoT,GU-HYD,Dept of CSE, 2018-19 34


PYTHON GAME DEVELOPMENT

The Mechanics Layer


The mechanics of a game are the “brain” of a game's design. Whenever the
player wishes to perform an action, he must invoke one of the available verbs in the
given game state (more on this in the next section). Then his input is processed
internally by a set or rules and an output is given (hopefully being what the player had

intended to do). Game mechanics must be designed to be the gears that spin under the
hood; all the player must do is step on the gas and feel the car moving. He does not
need to understand how the engine works to be able to drive.

The Verbs Layer


This layer consists of the actions that will be performed by the player during
the game. These actions mean the desire of the player being enforced upon the game
as low-level micro-decisions that will use the mechanics layer to run the player
through his game experience. Some of these verbs might be “shoot”, “jump”, “brake”,
or even “change camera perspective”, “craft an item” and “move units”.

Verbs are related to specific game states, that define which verbs are available
to the player at any given moment. For example, if “in car” is a game state for Grand
Theft Auto, “accelerate” and “brake” might be some of the available game verbs, as
“shoot” and “reload” would be verbs for the “weapon drawn” game state

SoT,GU-HYD,Dept of CSE, 2018-19 35


PYTHON GAME DEVELOPMENT

4.2 UML Diagrams:-


4.2.1 Class Diagram
(Figure C)

All the modules are connected to main module and the execution of program
starts from main module . Few classes are dependent on each other for their
execution.

SoT,GU-HYD,Dept of CSE, 2018-19 36


PYTHON GAME DEVELOPMENT

4.2.2 Use Case Diagram


(Figure D)

Upon the keys or action performed by the user or the gamer the score is
calculated by the computer and the result is displayed .

SoT,GU-HYD,Dept of CSE, 2018-19 37


PYTHON GAME DEVELOPMENT

Incase the car goes out of bound or game is completed you can restart the game and
the gamer can quit game by pressing Q .The Score displayed depends upon the score
calculated .

4.2.3 SEQUENCE DIAGRAM


(Figure E)

SoT,GU-HYD,Dept of CSE, 2018-19 38


PYTHON GAME DEVELOPMENT

4.2.4 USE CASE DIAGRAM:-


(Figure F)

Another way of expressing a use case diagram of race and track where in it
describes the action of the car such as moving ,stopping and completing game .

The Game completes as soon the timer stops and the game should start at the
start of timer .

SoT,GU-HYD,Dept of CSE, 2018-19 39


PYTHON GAME DEVELOPMENT

4.2.5 FLOWCHART
The fundamental running order of car racing game is simply demonstrated as
following flowchart.
The Start of the game is from user side and its end also from user side .
(Figure G)

SoT,GU-HYD,Dept of CSE, 2018-19 40


PYTHON GAME DEVELOPMENT

4.3 Modules and its Functionality


The game will be consisting of the following modules:-

Player

Maps

Camera

Direction

Game Mode

Time out

Tracks

Main

Bounds

Loader

Menu

Traffic

Most of the above modules are mandatory for the functioning of the game .Few
module are optional they are meant adding additional functionality and creativity to
game .

The following paragraphs shall give a brief description of the modules :-

Main Module :- This is the module from where the execution of the program starts ,
all the modules are imported into this main module , the type of user input is verified
here and the required function is called . It checks for input given by user during the
menu . It is responsible for the loading the maps ,cars and others images shown by
calling the function of the required modules.

SoT,GU-HYD,Dept of CSE, 2018-19 41


PYTHON GAME DEVELOPMENT

Maps Module:- This module is responsible for loading the map images ,mapping to
tiles and realigning maps according to user turns . It is a module where in the code is
available free to use in the internet .

Player Module:- This module is responsible for rotating the car ,find the residing
location of he car in the map , emitting or demmiting tracks , accelerating /
decelerating ,steering the car the left and right and to decrease the speed on impact .

Traffic Module:- This is a module which is responsible for the traffic creation in the
game .The number of cars ,their speeds can be increased or decreased .This module is
also responsible for the AI control of the cars in the maps .

Time out Module:- This module is responsible for loading the time out image after
the gamer has exceeded the time given to him/her.

Menu Module:- This module is used for responsible for loading the menu image
during the initial starting of the game.

Camera Module:- This module is responsible for keeping tracking track of the
coordinates of the car when moving in the maps .

Loader Module:- This module is used for loading the image and media use for the
game . It is used for assigning the path of the media.

Bounds Module:- It is used for showing the alert message when the car is out of the
bounds of the map . It is used for checking whether the car is in the bounds of the map
or not and it is used to send alert when the car is out of bounds.

SoT,GU-HYD,Dept of CSE, 2018-19 42


PYTHON GAME DEVELOPMENT

Direction Module:- Thos module is used for showing the player where to find the
violet flag in the map . It is used for rotating the arrow to indicate the location of the
flag and updating the arrow according to the location of the flag.

Gamemode Module:- This module is used for calculating the points the player
gained upon the actions he/she performed . The player gains points when the player
collects the violet flag . The points the player gains is equal to 15 . If the player has
crashed into another vehicle 2 points are deducted . Upon the end of the game the
variable are again initialised to initial values.

SoT,GU-HYD,Dept of CSE, 2018-19 43


PYTHON GAME DEVELOPMENT

5.TESTING
Testing plays an important role in every development step of a game. A game
testing is done at different levels of development process to detect various defects and
bugs. Including test cases, there are many unconventional methods involved in
finding bugs.

5.1 Testing Strategies:-


Following are different methods used to find bugs in games to ensure hassle free user
experience:

Exploratory testing: Game testers play games like the regular end users do, to find
bugs and defects. Different testers have various ways and approach to play the
game that helps in discovering bugs or defects.

Break the rules: Do not follow the same set of instructions every time while
testing. Go beyond the scope of test cases to find potential vulnerability or defect
and choose different ways to achieve the same result

Use unconventional method: Play game in a wrong order or incorrectly, such as


not doing any actions, skipping some steps and observe the changes that happen.

Use all functions everywhere: Try to use all functions even at every stage even if
it is not of any use at that point.

Try things that are not allowed: Press buttons rapidly at different places. Before
finishing level retrace steps and check the result

SoT,GU-HYD,Dept of CSE, 2018-19 44


PYTHON GAME DEVELOPMENT

Examine Effects: Try playing games with minimum inputs or minimum user
actions. Similarly, try playing games with maximum inputs. Try to walk through
walls, obstructions or objects and examine the effects

Test cases: Production or development team suggests testers the specific areas of a
game that needs to be tested. Testers follow test cases given by the development
team and complete each action as per given directions.

Functionality testing: Test menu and every menu function, and assure that it is
working correctly.

Durability testing: Test for odd situations like load game without a memory card,
run the game for 48 hours and check how game respond

Appoint different testers for the same job: If a same tester is performing test cases
over and over for every new build, then the person may lose enthusiasm and focus.
This can lead to missed defects or bugs. New testers will start work with a new
point of view and can find new bugs if any. Always rotate testers to get best results.

Performance Testing:A game with incredible graphics and features may still fail to
satisfy a player if the game is too slow or freeze up at certain levels. The critical
success factor of a game is its underlying development and testing. For this, run a
game without pause or keep on increasing the number of players if it is a multi-
player game.

Running such tests would give you data on how the performance is at high load and if
there is any bugs detected. If the results show performance issues, then it means that
your game has bugs that need to be fixed.

SoT,GU-HYD,Dept of CSE, 2018-19 45


PYTHON GAME DEVELOPMENT

5.2 Common Bugs


The following are common types of bugs seen in game testing:

Crash or Hang: If game suddenly freezes or closes, then it is a very important bug
that slows down the development process.

Game Play defects: When a particular feature is not doing its intended function, it
is said to be a game play defect

Collision: Incorrect physics of 3D objects.

logic: artificial intelligence affects factors such as movement and positioning of


players.

Graphics: corruption of graphics, missing textures, etc

Text: wrong, missing or wrongly spelled text, text extending out of the textbox

Sound: missing or wrong sound effects, lip sync not matching sound

Music: inconsistency, change of volume, looping effect

There are many more similar defects which can be found in peripherals, dialogues,
loading games, networks, consumer rating, etc.

5.2.1 Testing Bugs and its improvements


Game development and testing is a long and complex process. Unconventional
methods, test cases and close observation help to find every kind of bug in games.
The expectation of gamers has increased considerably, so even a small error can
spell doom to the success of a game.

SoT,GU-HYD,Dept of CSE, 2018-19 46


PYTHON GAME DEVELOPMENT

6. SCREEN OUTPUTS

1.Initial display of the game the program has been ruined or executed for the main
module .
(Figure H)

The initial screen output shows the following:-


Menu
FPS(Frames per second)
Game goal
Timer
Score
Basic user instruction
Pink arrow for user help during Game
Background/environment of the car

SoT,GU-HYD,Dept of CSE, 2018-19 47


PYTHON GAME DEVELOPMENT

2.After the gamer has entered the M key on the keyboard the game starts.
(Figure I)

The following can be observed from the screen output 2


the timer started
frames per seconds is variable
arrow direction is varying according to user input
Score

The user can use the following keys in this scenario


Up arrow
Down arrow
Left arrow
Right arrow
P to rest
Q to Quit

SoT,GU-HYD,Dept of CSE, 2018-19 48


PYTHON GAME DEVELOPMENT

3.The gamer can reach his goal by analysis the position of pink flag by taking help of
pink arrow on the bottom right of the screen.
(Figure J)

4.The user should reach the pink trophy by avoiding the collision from cars on his/her
way and take turns with precision and care
(Figure K)

SoT,GU-HYD,Dept of CSE, 2018-19 49


PYTHON GAME DEVELOPMENT

5.The user is supposed to take a U turn when observes a dead and should take

necessary efforts to avoid collision and collision leads to deduction in the score by 4.
Negative score is also valid
(Figure L)

6.The user should collect as many as pink trophies possible to score +15 for each
pink trophy
(Figure M).

SoT,GU-HYD,Dept of CSE, 2018-19 50


PYTHON GAME DEVELOPMENT

7.At end of the timer .The screen shows game over menu and shows score calculated
after collecting trophies and considering collision .You can either continue the game
by restarting or Exit by pressing Q.
(Figure N)

SoT,GU-HYD,Dept of CSE, 2018-19 51


PYTHON GAME DEVELOPMENT

7.COGNITIVE BENEFITS OF PLAYING VIDEO GAMES

Contrary to the traditional belief that gaming is merely an addictive source of


entertainment and diversion, recent research has proved that gaming has numerous
benefits and key among them, is the development of cognitive skills in both children
and adults. Just as physical exercise helps in improving and strengthening your
muscles, cognitive games help to indulge one's brain in constant stimulation, thus
improving the brain's performance. The following are some of the cognitive benefits
of playing video games.

1. Improves coordination
When an adult or child is playing a video game, he or she is not only staring at
the computer inactively. The activities and actions on the screen provide a lot of
mental stimulation. For one to play, he or she will need to coordinate their visual,
audial and physical movement.

2. Improves problem-solving skills


Video games involve certain rules. This means that the player has to think
carefully before making any move to ensure that they stay within the required rules of
that particular game. The player needs to make split- second decisions that will
determine whether or not he or she will advance to the next level.

3. Enhances memory
Playing your favourite video game may require both visual and audial
memory. The player is required to read or listen to the instructions which might only
be provided at the beginning of the game, thus the need to remember them throughout
the entire game. Mastery of the keys on your keyboard helps you easily move your
characters in the game. This helps improve your memory, whether short- term or long-
term.

SoT,GU-HYD,Dept of CSE, 2018-19 52


PYTHON GAME DEVELOPMENT

4. Improves attention and concentration


Video games especially action games, have proven to be able to capture the
player's attention for the entire period of the game. This is brought about by the
player's need to achieve certain objectives within the game, and be able to progress to
the next level.

5. It is a great source of learning


Gaming is not only beneficial to adults and teenagers, but to children as well.
Many modern education institutions incorporate video games as a teaching
methodology. This helps these children improve their academic skills by providing
video games that are specifically aimed at enhancing their cognitive and creative
skills.

6. Improves the brain's speed


While gaming, the brain receives multiple stimulations, both Visual and
audial. According to research, individuals who play video games frequently can
process these stimulators faster than others. These stimulators ensure that the brain is
continuously working to interpret them.

7. Enhances multitasking skills


An action game, for example, may require you to be very observant. It
requires you to be able to move your joystick or keys while looking at the various
features on your screen such as energy levels, oncoming adversaries, ammunitions
left, available time among other factors, all which are vital to winning. This ensures
that the player can observe and react accordingly to all requirements of that particular
game.

8. Improves social skills


Online gaming enables many players to engage in a particular game
simultaneously. As such, there is constant communication between the players which

SoT,GU-HYD,Dept of CSE, 2018-19 53


PYTHON GAME DEVELOPMENT

in turn results in the development of meaningful as well as casual relationships among


them.
This helps players meet new friends while also strengthening bonds with their
old friends.Though computer games might be beneficial, there is need to play them in
moderation. It is also important to pick the right game as not all of them provide the
same cognitive benefits. Age should also be a factor. Small children should not be
exposed to violent games.

SoT,GU-HYD,Dept of CSE, 2018-19 54


PYTHON GAME DEVELOPMENT

8.THE DISADVANTAGES OF PLAYING VIDEO GAMES

Talk about gamers in the 21st century and you’re probably referring to those
who play games on computer systems, a medium which has all but replaced formats
such as board games and pen-and-paper role-playing games. While some people
suggest playing games on a computer can aid in the development of skills such as
improving reflexes, critics point out some disadvantages.

General Health
Spending a long period of time playing at a computer can have detrimental
effects on your health. For a start, you're sitting in one position, pressing the same
buttons repeatedly, which can lead to hand and eye strain. A long game session can
leave you physically tired, affecting your performance at school or work; overall, this
could result in lower personal attainment.

Epilepsy
Computer games can trigger epileptic attacks in sufferers who play, which can
be extremely dangerous. Often, such an attack is a result of flashing images contained
in the game. However, according to “The Effect of Video-game Software in Video-
game Epilepsy” by S. Ricci et al., attacks can also result from emotional excitement
or sleep deprivation which stems from playing these games.

Aggressive Behaviour
Some critics of computer gaming have pointed toward the violent content of
some games, such as the “Grand Theft Auto” series, as being a factor in influencing
players toward aggressive action and attitudes in real life. Researchers from the
University of Missouri-Columbia found a causal link between game playing and
aggression after studying the brain patterns of 39 gamers. Critics also fear that gamers
become desensitised to violence as a result of what they see on computer screens.

SoT,GU-HYD,Dept of CSE, 2018-19 55


PYTHON GAME DEVELOPMENT

Games are All-Consuming


Many computer games require a substantial commitment of time and energy to
complete, and players must give up other pursuits to concentrate on completing their
favourite games. Other games, such as “Farmville” for example, require regular
participation to avoid being unsuccessful in the game. The result is that players often
abandon other hobbies and spend their time on the computer instead. In some cases,
the time spent on a game can lead to a full-blown addiction, and the player may have
difficulty adjusting to life away from the game, says the Tech Addiction website.

High Cost
The cost of computer gaming can fluctuate based on how many games you buy and
the type of titles you like to play, but with new games costing as much as $60, gaming
can be a pricey hobby. A larger expense can come in the form of the computer
upgrades needed to run the most recent games; for example, you might need to
purchase a new graphics card, costing around $60 or $70.

SoT,GU-HYD,Dept of CSE, 2018-19 56


PYTHON GAME DEVELOPMENT

9.CONCLUSION

Therefore by using the language python , IDE PyCharm and IDLE , the
python libraries such as pygame for multimedia and sound the game has been created
and is functioning to the level that it meets its objective .The Game worked on
different OS and different Specification computers and delivered the same
performance on all . There may be some areas of improvements and efficiency which
will be carried out in future.

SoT,GU-HYD,Dept of CSE, 2018-19 57


PYTHON GAME DEVELOPMENT

10.FUTURE WORKS

This project or game takes in consideration that all cars move at same speed in
every situation and the game has same kind of automobiles all round ,this situation is
not same in the real world . In the real world there are cars ,trucks ,2 wheelers and
others automobiles moving at different speeds .This project has background music
associated with the game but we can add sound of collision ,acceleration in the car to
make more real and entertaining .Multiplayer can also be implemented wherein the
player who collects more pink flags is considered the winner.

SoT,GU-HYD,Dept of CSE, 2018-19 58


PYTHON GAME DEVELOPMENT

11.BIBLIOGRAPHY

https://pythonprogramming.net/adding-sounds-music-pygame/
https://www.python.org
http://www.gamasutra.com
https://www.pygame.org/docs/
https://en.wikipedia.org/wiki/Pygame
https://www.jetbrains.com
https://stackoverflow.com/questions/1347791/unicode-error-unicodeescape-codec-
cant-decode-bytes-cannot-open-text-file
https://www.testbytes.net/blog/bugs-in-game-testing/
Author: Bill Lubanovic, Introducing Python: Modern Computing in Simple
Packages , Publisher: Shroff/O'Reilly; First edition (1 December 2014)

SoT,GU-HYD,Dept of CSE, 2018-19 59

You might also like