Added a background image to the menu.

This commit is contained in:
Sakse Dalum
2012-08-07 15:40:42 +02:00
parent 775e4a72a8
commit c579838f91
7 changed files with 102 additions and 13 deletions

View File

@@ -28,6 +28,8 @@ import os
import pygame
import jukebox
import level
import main_menu
class Game(object):
"""Create an object to handle the game."""
@@ -38,9 +40,15 @@ class Game(object):
self.clock = pygame.time.Clock()
self.jukebox = jukebox.Jukebox(os.path.abspath(os.path.join("resources",
"music")),
["basshit.ogg"])
self.jukebox = jukebox.Jukebox(
os.path.abspath(os.path.join("resources", "music")),
["basshit.ogg"])
# Add main menu object to list of objects.
self.objs.append(main_menu.MainMenu(self, os.path.abspath(os.path.join(
"resources", "graphics", "main_menu.png"))))
self.level = None
self.ticks = self.prev_ticks = pygame.time.get_ticks()
@@ -61,14 +69,19 @@ class Game(object):
self.draw()
self.clock.tick(self.speed)
def goto_level(self, level):
self.level = level
def update(self, t, dt):
"""
Update all game objects.
"""
# Retrieve and flush all events since last update call (this prevents
# event "bottlenecking"/lock-ups)
events = pygame.event.get()
for event in events:
e = pygame.event.get()
for event in e:
# Stop the game when closing the window
if event.type == pygame.QUIT:
self.stop()
@@ -80,12 +93,11 @@ class Game(object):
# Update all objects
for obj in self.objs:
if hasattr(obj, 'update'):
obj.update(t, dt)
self.prev_ticks = pygame.time.get_ticks()
obj.update(e, t, dt)
def draw(self):
"""
Update all game objects.
Draw all game objects.
"""
self.window.fill((0, 0, 0))
for obj in self.objs: