CG Mini Project PDF

Title CG Mini Project
Author Jatin Jawale
Course Computer Graphics
Institution University of Mumbai
Pages 11
File Size 439.1 KB
File Type PDF
Total Downloads 90
Total Views 166

Summary

A mini-project made for the subject of Computer Graphics- A game written in Python...


Description

0

A SIMPLE VIDEO GAME A Mini Project for Computer Graphics

ACADEMIC YEAR 2017-2018 SE CMPN 1

NAME

ROLL NO.

Jatin Jawale

28

MONTH OF SUBMISSION: APRIL 2018

Computer Graphics Mini Project |1

AIM To make a game with animation and graphics as a project for Computer Graphics

OBJECTIVE To build a game using a programming language. The game is a basic ‘Shoot ‘em up’ type, where the player shoots his enemies. The player’s score should increase with each hit and decrease when the enemy hits the player. Also, the player should have a limited life, which when over signifies the end of the game.

DESCRIPTION The above objective was accomplished by using Python Programming Language. The player is ‘sitting’ in a spaceship and has to move through space by killing his enemies. The player has to take care of not only the ships, but the periodic meteors as well, varying in size. The player’s shield decreases every time he is hit by the enemy mob or the meteors. When the player’s shield falls below a certain percentage, the player is granted a ‘life’ which he can get by catching it. The player’s shield goes back to 100%.

DETAILS OF HARDWARE AND SOFTWARE The project is made entirely in Python using ‘tkinter’ module. No other special software is required. The only extra things needed are the images of the various objects used in the game. The game also has a soundtrack which loops throughout the game. Also, there are sounds for each bullet shot, mod killed and meteor hit.

Computer Graphics Mini Project |2

SCREENSHOTS

PLAYER

MOB SHIP

METEORS

THE STARTING SCREEN OF THE GAME

Computer Graphics Mini Project |3

THE START OF THE GAME

THE PLAYER CAN SHOOT THE MOB WITH BULLETS

Computer Graphics Mini Project |4

THE ANIMATION WHEN PLAYER HITS A MOB MEMBER

METEORS ALSO ARRIVE TO TROUBLE THE PLAYER

Computer Graphics Mini Project |5

PLAYER’S SHIELD KEEPS REDUCING AS IT KEEPS GETTING HIT

PLAYER GETS A LIFE

Computer Graphics Mini Project |6

PROGRAM CODE import pygame as pg import random import os import time WIDTH=800 HEIGHT=600 FPS=60 #Setting colors black=(0,0,0) white=(255,255,255) red=(255,0,0) green=(0,255,0) blue=(0,0,255) pg.init() pg.mixer.init() screen=pg.display.set_mode((WIDTH, HEIGHT)) pg.display.set_caption('SHOOT SHOOT SHOOT') clock=pg.time.Clock() game_folder=os.path.dirname(__file__) img_dir=os.path.join(game_folder, 'Images') #Getting required images background=pg.image.load(os.path.join(img_dir, 'Space.png')).convert() background_rect=background.get_rect() player_img=pg.image.load(os.path.join(img_dir,"playe r.png")).convert() mob_img=pg.image.load(os.path.join(img_dir,"enemy Ship.png")).convert() bullet_img=pg.image.load(os.path.join(img_dir,"laserG reen.png")).convert() meteor_img=pg.image.load(os.path.join(img_dir,"met eorBig.png")).convert() get_shield=pg.image.load(os.path.join(img_dir,"life.pn g")).convert() explosion_animation={} explosion_animation['large']=[] explosion_animation['small']=[] explosion_animation['player']=[]

for i in range(0,9): filename='regularExplosion0{}.png'.format(i) img=pg.image.load(os.path.join(img_dir, filename)).convert() img.set_colorkey(black) img_large=pg.transform.scale(img, (75,75)) explosion_animation['large'].append(img_large) img_small=pg.transform.scale(img, (30,30)) explosion_animation['small'].append(img_small) filename='sonicExplosion0{}.png'.format(i) img_p=pg.image.load(os.path.join(img_dir, filename)).convert() img_p.set_colorkey(black) img_player=pg.transform.scale(img,(75,75)) explosion_animation['player'].append(img_player) #Getting requires audio files sound_dir=os.path.join(game_folder, 'Sounds') pg.mixer.music.load(os.path.join(sound_dir, "Background_new.ogg" )) pg.mixer.music.set_volume(0.5) laser_sound=pg.mixer.Sound(os.path.join(sound_dir, "Laser_Shoot18.wav" )) mob_sound=pg.mixer.Sound(os.path.join(sound_dir, 'Explosion42.wav')) meteor_sound=pg.mixer.Sound(os.path.join(sound_di r, 'Explosion17.wav')) explosion_sound=pg.mixer.Sound(os.path.join(sound_ dir, 'Explosion13.wav')) death_sound=pg.mixer.Sound(os.path.join(sound_dir, 'Death.wav')) powerup_sound=pg.mixer.Sound(os.path.join(sound_ dir, 'powerup.wav')) #set up the requirements font_name=pg.font.match_font('ARDESTINE') def draw_text(surf, text, size, x, y): font=pg.font.Font(font_name, size) text_surface=font.render(text, False, white) text_rect=text_surface.get_rect() text_rect.midtop=(x,y) surf.blit(text_surface, text_rect)

Computer Graphics Mini Project |7

def draw_shield(surface,x,y,value): if (value0): self.xspeed+=-7 if(keystate[pg.K_RIGHT] and self.rect.right self.shoot_delay): self.last_shot=now laser_sound.play() bullet=Bullets(self.rect.centerx, self.rect.top) all_sprites.add(bullet) bullet_sprites.add(bullet)

class Meteor(pg.sprite.Sprite): def __init__(self): pg.sprite.Sprite.__init__(self) self.image_original=meteor_img #Keeping the original imagw self.image_original.set_colorkey(black) #so that when rotation takes place, self.image=self.image_original.copy() #the original image is not disturbed self.rect=self.image.get_rect() self.radius=20 self.rect.x=random.randrange(WIDTH-self.rect.width) self.rect.y=random.randrange(-250,-200) self.yspeed=random.randrange(4,10) self.xspeed=random.randrange(-3,3) self.rot=0 self.rot_speed=random.randrange(-5,5) self.last_update=pg.time.get_ticks() def rotate(self): now=pg.time.get_ticks() if(now-self.last_update>50): self.last_update=now self.rot=(self.rot+self.rot_speed)%360 new_image=pg.transform.rotate(self.image_original, self.rot) old_center=self.rect.center self.image=new_image self.rect=self.image.get_rect() self.rect.center=old_center def update(self): self.rotate() self.rect.y+=self.yspeed self.rect.x+=self.xspeed if(self.rect.top>HEIGHT+10 or self.rect.leftWIDTH +20): self.rect.x=random.randrange(WIDTH-self.rect.width) self.rect.y=random.randrange(-100,-50) self.yspeed=random.randint(4,10)

Computer Graphics Mini Project |8

class Powerup(pg.sprite.Sprite): def __init__(self): pg.sprite.Sprite.__init__(self) self.image=get_shield self.image.set_colorkey(black) self.rect=self.image.get_rect() self.rect.x=random.randrange(0,WIDTH) self.rect.y=-10 self.yspeed=5 def update(self): self.rect.y+=self.yspeed class Mob(pg.sprite.Sprite): def __init__(self): pg.sprite.Sprite.__init__(self) self.image=pg.transform.scale(mob_img,(50,38)) self.image.set_colorkey(black) self.rect=self.image.get_rect() self.radius=20 self.rect.x=random.randrange(WIDTH-self.rect.width) self.rect.y=random.randrange(-100,-50) self.yspeed=1 def update(self): self.rect.y+=self.yspeed if(self.rect.top>HEIGHT+10): self.rect.x=random.randrange(WIDTH-self.rect.width) self.rect.y=random.randrange(-100,-50) self.yspeed=random.randint(1,5) class Bullets(pg.sprite.Sprite): def __init__(self, x, y): pg.sprite.Sprite.__init__(self) self.image=bullet_img self.image.set_colorkey(black) self.rect=self.image.get_rect() self.rect.bottom=y self.rect.centerx=x self.yspeed= -8 def update(self): self.rect.y+=self.yspeed if(self.rect.bottom=self.frame_rate): self.last_update=now self.frame+=1 if(self.frame==len(explosion_animation[self.size])): self.kill() else: center=self.rect.center self.image=explosion_animation[self.size][self.frame] self.rect=self.image.get_rect() self.rect.center=center def make_mob(*varargs): m=Mob() all_sprites.add(m) mob_sprites.add(m) for i in varargs: m.yspeed=m.yspeed+random.randrange(0,1+int(i/5)) kills=0 pg.mixer.music.play(loops=-1) running=True gameover=True

Computer Graphics Mini Project |9

def show_go_screen(): screen.blit(background, background_rect) draw_text(screen, 'JJ\'s BIZZARE ADVENTURE',64, WIDTH/2, HEIGHT/4) draw_text(screen, 'Use Arrow keys to move, Spacebar to fire bullets',42, WIDTH/2, HEIGHT/2 ) draw_text(screen, 'Press any key to start playing', 36, WIDTH/2, HEIGHT*3/4) pg.display.flip() waiting =True while(waiting): clock.tick(FPS) for event in pg.event.get(): if event.type==pg.QUIT: pg.quit() if event.type==pg.KEYUP: waiting=False while running: if(gameover): show_go_screen() gameover=False all_sprites=pg.sprite.Group() player=Player() all_sprites.add(player) powerup_sprites=pg.sprite.Group() bullet_sprites=pg.sprite.Group() mob_sprites=pg.sprite.Group() met_sprites=pg.sprite.Group() for i in range(8): make_mob() score=0 kills=0 clock.tick(FPS) #Events for event in pg.event.get(): if(event.type==pg.QUIT): running=False all_sprites.update() mob_sprites.update()

#Check for collision hits=pg.sprite.spritecollide(player, mob_sprites, True, pg.sprite.collide_circle) for hit in hits: player.shield-=10 if(player.shield...


Similar Free PDFs