Skip to content

Commit

Permalink
added introduction, sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
mthenault committed Jul 21, 2012
1 parent eb9678b commit ea91484
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 73 deletions.
Binary file added A.TTF
Binary file not shown.
Binary file added images/johnson.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sounds/menu.wav
Binary file not shown.
Binary file added sounds/noise.wav
Binary file not shown.
6 changes: 3 additions & 3 deletions sources/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def game():



hud= hud.Hud(single_sprites)
hud= hud.Hud(single_sprites, menu, sounds)
#start the menu
menu.init2(single_sprites, sounds, background, hud)
menu.launch(0)
Expand Down Expand Up @@ -88,7 +88,7 @@ def game():


thegame=True
level =0
level =-1
spawnedBoss=False
while thegame:
compteur_shoot=compteur_shoot+1
Expand Down Expand Up @@ -246,7 +246,7 @@ def game():
enemy_list.remove(deadEnemies[index])

#blit the hud
hud.blit(ship, level)
level = hud.blit(ship, level)

#process ship hurt
countdown = ship.processHurt(countdown)
Expand Down
38 changes: 36 additions & 2 deletions sources/hud.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,25 @@ def updateProgbar(percent,x1, y1,max_width, color, direction, single_sprites):


class Hud():
def __init__(self, single_sprites):
def __init__(self, single_sprites, menu, sounds):
self.sounds=sounds
self.menu=menu
self.single_sprites=single_sprites
# Create a font
self.tinyfont = pygame.font.Font(None, 16)
self.font = pygame.font.Font(None,32)
self.font2 = pygame.font.Font(None, 150)
self.score_label = self.tinyfont.render("score", True, (255,255, 0))
self.inf = self.font.render("Inf.", True, (0,130, 255))
self.communication = pygame.font.Font("A.TTF",13)
self.communicationCall = pygame.font.Font("BITSUMIS.TTF",50)

#self.offset=0

self.johnsonOffset =0
self.textline1 = "Johnson here."
self.textline2 = "Your goal today is to destroy"
self.textline3 = "every enemy ship. "
self.textline4 = "I'm counting on you !"
def blit(self, ship, level):
# Render the text
#life_txt = self.font.render(str(ship.life), True, (255,0, 0))
Expand Down Expand Up @@ -89,3 +97,29 @@ def blit(self, ship, level):
screen.blit(self.single_sprites['ball1.png'],(5,
common_pygame.screenheight-55 ))
screen.blit(ammo_txt,(25, common_pygame.screenheight-55))

#beggining of the game : blit johnson
if level==0:
if self.johnsonOffset==200:
return 1
else:
self.johnsonOffset=self.johnsonOffset+1

if self.johnsonOffset==1:
self.menu.play_sound(self.sounds["noise.wav"])
#first 30 frames
if self.johnsonOffset<30:
if self.johnsonOffset%8>4:
screen.blit(self.communicationCall.render("Incoming call", True, (255,255,255)),(20, 15))
else:
screen.blit(self.single_sprites['johnson.png'],(10, 10))
if self.johnsonOffset>=30:
screen.blit(self.communication.render(self.textline1[:(self.johnsonOffset-30)*len(self.textline1)/30], True, (255,255,128)),(114, 26))
#next 60 ones
if self.johnsonOffset>=70:
screen.blit(self.communication.render(self.textline2[:(self.johnsonOffset-70)*len(self.textline2)/30], True, (255,255, 128)),(114, 44))
if self.johnsonOffset>=100:
screen.blit(self.communication.render(self.textline3[:(self.johnsonOffset-100)*len(self.textline3)/30], True, (255,255, 128)),(114, 44+18))
if self.johnsonOffset>=150:
screen.blit(self.communication.render(self.textline4[:(self.johnsonOffset-150)*len(self.textline4)/30], True, (255,255, 128)),(114, 44+18+18))
return level
137 changes: 69 additions & 68 deletions sources/load_resources.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,69 @@
import os
import common_pygame
import sprite_handling
import menu
import progressbar

pygame = common_pygame.pygame
sounds = dict()
single_sprites = dict()
sprite_sequences = dict()


def add_sound(soundfile):
global sounds
sounds[soundfile] = pygame.mixer.Sound(os.path.join('sounds', soundfile))
sounds[soundfile].set_volume(0.5)

def add_sprite(spritefile):
global single_sprites
single_sprites[spritefile]=pygame.image.load(os.path.join('images',spritefile)).convert_alpha()
single_sprites[spritefile].set_colorkey((255,0,255))


def add_sprite_sequence(spritesequence, h, w):
global sprite_sequences
sprite_sequences[spritesequence]= \
sprite_handling.load_sliced_sprites( w, h, spritesequence )

def load_resources(pygame_arg):
prog = progressbar.progressBar()
#loading sounds
#sounds is a dict that contains all the sounds
#global pygame = pygame_arg
prog.update(0)
soundlist=["laser.wav", "laser2.wav", "laser3.wav", "laser4.wav","laser5.wav", \
"explosion.wav", "explosion2.wav", "life.wav", "ouch.wav", "loser.wav", "shield1.wav", \
"armor.wav", "plasma1.wav", "plasmagun.wav"]

for index in xrange (len(soundlist)):
add_sound(soundlist[index])
prog.update(index*40/len(soundlist))

sprite_load_list=["sprite_ship.png","sprite_ship_fire.png", "sprite_ship_weapon2.png", \
"sprite_laser.png", "sprite_laser_blue.png", "sprite_lasershoot.png","sprite_enemy.png", \
"sprite_enemy_fire.png", "background.png","backgroundtransp.png", "asteroid1.png", \
"asteroid2.png", "asteroid3.png", "planet1.png", "planet2.png", "planet3.png", \
"lifebonus.png", "armorbonus.png", "lifeBonusRing.png", "armorBonusRing.png", \
"lifemask.png", "ball1.png", "sprite_laser_blue_light.png","sprite_laser_light.png", \
"ball1_light.png","lifeBonusLight.png","menu_micshooter.png", "menu_options.png",
"menu_optionsblurry.png", "menu_play.png","menu_playblurry.png","menu_resume.png", \
"menu_resumeblurry.png", "menu_quit.png", "menu_quitblurry.png","menu_sound.png", \
"menu_on.png", "menu_off.png","menu_resolution.png","menu_800600.png", "menu_800500.png", \
"sprite_enemy2.png", "plasmaBonusRing.png", "plasmabonus.png", "boss1.png", \
"particle1.png", "particle2.png", "particle3.png", "particle4.png", "barArmor.png", "barLife.png" ]

for index in xrange (len(sprite_load_list)):
add_sprite(sprite_load_list[index])
prog.update((index*60/len(sprite_load_list))+40)

pygame.display.set_icon(single_sprites["sprite_ship.png"])

#loading sprite sequences
add_sprite_sequence("sprite_explosion_list.png", 204, 256)
add_sprite_sequence("sprite_explosion_list_asteroid.png", 192, 192)
add_sprite_sequence("ship_hurt.png", 192/2, 192/2)
prog.update(100)
return (sounds, single_sprites, sprite_sequences)

import os
import common_pygame
import sprite_handling
import menu
import progressbar

pygame = common_pygame.pygame
sounds = dict()
single_sprites = dict()
sprite_sequences = dict()


def add_sound(soundfile):
global sounds
sounds[soundfile] = pygame.mixer.Sound(os.path.join('sounds', soundfile))
sounds[soundfile].set_volume(0.5)

def add_sprite(spritefile):
global single_sprites
single_sprites[spritefile]=pygame.image.load(os.path.join('images',spritefile)).convert_alpha()
single_sprites[spritefile].set_colorkey((255,0,255))


def add_sprite_sequence(spritesequence, h, w):
global sprite_sequences
sprite_sequences[spritesequence]= \
sprite_handling.load_sliced_sprites( w, h, spritesequence )

def load_resources(pygame_arg):
prog = progressbar.progressBar()
#loading sounds
#sounds is a dict that contains all the sounds
#global pygame = pygame_arg
prog.update(0)
soundlist=["laser.wav", "laser2.wav", "laser3.wav", "laser4.wav","laser5.wav", \
"explosion.wav", "explosion2.wav", "life.wav", "ouch.wav", "loser.wav", "shield1.wav", \
"armor.wav", "plasma1.wav", "plasmagun.wav", "noise.wav", "menu.wav"]

for index in xrange (len(soundlist)):
add_sound(soundlist[index])
prog.update(index*40/len(soundlist))

sprite_load_list=["sprite_ship.png","sprite_ship_fire.png", "sprite_ship_weapon2.png", \
"sprite_laser.png", "sprite_laser_blue.png", "sprite_lasershoot.png","sprite_enemy.png", \
"sprite_enemy_fire.png", "background.png","backgroundtransp.png", "asteroid1.png", \
"asteroid2.png", "asteroid3.png", "planet1.png", "planet2.png", "planet3.png", \
"lifebonus.png", "armorbonus.png", "lifeBonusRing.png", "armorBonusRing.png", \
"lifemask.png", "ball1.png", "sprite_laser_blue_light.png","sprite_laser_light.png", \
"ball1_light.png","lifeBonusLight.png","menu_micshooter.png", "menu_options.png",
"menu_optionsblurry.png", "menu_play.png","menu_playblurry.png","menu_resume.png", \
"menu_resumeblurry.png", "menu_quit.png", "menu_quitblurry.png","menu_sound.png", \
"menu_on.png", "menu_off.png","menu_resolution.png","menu_800600.png", "menu_800500.png", \
"sprite_enemy2.png", "plasmaBonusRing.png", "plasmabonus.png", "boss1.png", \
"particle1.png", "particle2.png", "particle3.png", "particle4.png", "barArmor.png", "barLife.png", \
"johnson.png" ]

for index in xrange (len(sprite_load_list)):
add_sprite(sprite_load_list[index])
prog.update((index*60/len(sprite_load_list))+40)

pygame.display.set_icon(single_sprites["sprite_ship.png"])

#loading sprite sequences
add_sprite_sequence("sprite_explosion_list.png", 204, 256)
add_sprite_sequence("sprite_explosion_list_asteroid.png", 192, 192)
add_sprite_sequence("ship_hurt.png", 192/2, 192/2)
prog.update(100)
return (sounds, single_sprites, sprite_sequences)

6 changes: 6 additions & 0 deletions sources/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,15 @@ def launch(self, withresume):
if pygame.key.get_pressed()[pygame.K_UP]:
if self.compteur>=5:
#print(self.selection)
self.play_sound(self.sounds["menu.wav"])
self.selection=self.selection-1
if self.selection==0:
self.selection=3
self.compteur=0

if pygame.key.get_pressed()[pygame.K_DOWN] and self.compteur>=5:
#print(self.selection)
self.play_sound(self.sounds["menu.wav"])
self.selection=self.selection+1
if self.selection==4:
self.selection=1
Expand Down Expand Up @@ -205,13 +207,15 @@ def launch(self, withresume):
#change the selection
if pygame.key.get_pressed()[pygame.K_UP]:
if self.compteur>=5:
self.play_sound(self.sounds["menu.wav"])
#print(self.selection)
self.selection=self.selection-1
if self.selection==0:
self.selection=4
self.compteur=0

if pygame.key.get_pressed()[pygame.K_DOWN] and self.compteur>=5:
self.play_sound(self.sounds["menu.wav"])
#print(self.selection)
self.selection=self.selection+1
if self.selection==5:
Expand All @@ -221,11 +225,13 @@ def launch(self, withresume):

if (pygame.key.get_pressed()[pygame.K_LEFT] or pygame.key.get_pressed()[pygame.K_RIGHT]) \
and self.selection==1 and self.compteur>=5:
self.play_sound(self.sounds["menu.wav"])
self.compteur=0
self.config['sound']= not self.config['sound']

if (pygame.key.get_pressed()[pygame.K_LEFT] or pygame.key.get_pressed()[pygame.K_RIGHT]) \
and self.selection==2 and self.compteur>=5:
self.play_sound(self.sounds["menu.wav"])
self.compteur=0
self.config['resolution']= not self.config['resolution']
if self.config['resolution']==0:
Expand Down

0 comments on commit ea91484

Please sign in to comment.