Added a background image to the menu.
This commit is contained in:
parent
775e4a72a8
commit
c579838f91
Binary file not shown.
After Width: | Height: | Size: 282 KiB |
Binary file not shown.
After Width: | Height: | Size: 284 KiB |
|
@ -40,6 +40,9 @@ for module_name in module_names:
|
||||||
if not module.get_init():
|
if not module.get_init():
|
||||||
print("Failed to initialise %s module." % module_name)
|
print("Failed to initialise %s module." % module_name)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
if not pygame.image.get_extended():
|
||||||
|
print("Pygame does not support extended image support.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,8 @@ import os
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
import jukebox
|
import jukebox
|
||||||
|
import level
|
||||||
|
import main_menu
|
||||||
|
|
||||||
class Game(object):
|
class Game(object):
|
||||||
"""Create an object to handle the game."""
|
"""Create an object to handle the game."""
|
||||||
|
@ -38,9 +40,15 @@ class Game(object):
|
||||||
|
|
||||||
self.clock = pygame.time.Clock()
|
self.clock = pygame.time.Clock()
|
||||||
|
|
||||||
self.jukebox = jukebox.Jukebox(os.path.abspath(os.path.join("resources",
|
self.jukebox = jukebox.Jukebox(
|
||||||
"music")),
|
os.path.abspath(os.path.join("resources", "music")),
|
||||||
["basshit.ogg"])
|
["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()
|
self.ticks = self.prev_ticks = pygame.time.get_ticks()
|
||||||
|
|
||||||
|
@ -61,14 +69,19 @@ class Game(object):
|
||||||
self.draw()
|
self.draw()
|
||||||
self.clock.tick(self.speed)
|
self.clock.tick(self.speed)
|
||||||
|
|
||||||
|
|
||||||
|
def goto_level(self, level):
|
||||||
|
self.level = level
|
||||||
|
|
||||||
|
|
||||||
def update(self, t, dt):
|
def update(self, t, dt):
|
||||||
"""
|
"""
|
||||||
Update all game objects.
|
Update all game objects.
|
||||||
"""
|
"""
|
||||||
# Retrieve and flush all events since last update call (this prevents
|
# Retrieve and flush all events since last update call (this prevents
|
||||||
# event "bottlenecking"/lock-ups)
|
# event "bottlenecking"/lock-ups)
|
||||||
events = pygame.event.get()
|
e = pygame.event.get()
|
||||||
for event in events:
|
for event in e:
|
||||||
# Stop the game when closing the window
|
# Stop the game when closing the window
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
self.stop()
|
self.stop()
|
||||||
|
@ -80,12 +93,11 @@ class Game(object):
|
||||||
# Update all objects
|
# Update all objects
|
||||||
for obj in self.objs:
|
for obj in self.objs:
|
||||||
if hasattr(obj, 'update'):
|
if hasattr(obj, 'update'):
|
||||||
obj.update(t, dt)
|
obj.update(e, t, dt)
|
||||||
self.prev_ticks = pygame.time.get_ticks()
|
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
"""
|
"""
|
||||||
Update all game objects.
|
Draw all game objects.
|
||||||
"""
|
"""
|
||||||
self.window.fill((0, 0, 0))
|
self.window.fill((0, 0, 0))
|
||||||
for obj in self.objs:
|
for obj in self.objs:
|
||||||
|
|
|
@ -26,7 +26,6 @@ The jukebox. Handles playback of background music.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import pygame
|
import pygame
|
||||||
import random
|
|
||||||
|
|
||||||
class Jukebox(object):
|
class Jukebox(object):
|
||||||
"""Create an object to handle music playback."""
|
"""Create an object to handle music playback."""
|
||||||
|
@ -37,11 +36,9 @@ class Jukebox(object):
|
||||||
|
|
||||||
def play(self):
|
def play(self):
|
||||||
pygame.mixer.music.load(
|
pygame.mixer.music.load(
|
||||||
os.path.join(self.music_dir,
|
os.path.join(self.music_dir, self.music_files[self.iterator]))
|
||||||
self.music_files[self.iterator
|
|
||||||
% len(self.music_files)]))
|
|
||||||
pygame.mixer.music.play()
|
pygame.mixer.music.play()
|
||||||
self.iterator += 1
|
self.iterator = (self.iterator + 1) % len(self.music_files)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
pygame.mixer.music.stop()
|
pygame.mixer.music.stop()
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
# This file is part of ROBOTGAME
|
||||||
|
#
|
||||||
|
# ROBOTGAME is free software: you can redistribute it and/or modify it under the
|
||||||
|
# terms of the GNU General Public License as published by the Free Software
|
||||||
|
# Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# ROBOTGAME is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# ROBOTGAME. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
||||||
|
#
|
||||||
|
# level.py
|
||||||
|
# --------------------
|
||||||
|
# date created : Tue Aug 7 2012
|
||||||
|
# copyright : (C) 2012 Sakse Dalum
|
||||||
|
# maintained by : Sakse Dalum <don_s@hongabar.org>
|
||||||
|
|
||||||
|
"""
|
||||||
|
A generic level.
|
||||||
|
"""
|
||||||
|
|
||||||
|
class Level(object):
|
||||||
|
def __init__(self, level_name):
|
||||||
|
pass
|
|
@ -0,0 +1,48 @@
|
||||||
|
# This file is part of ROBOTGAME
|
||||||
|
#
|
||||||
|
# ROBOTGAME is free software: you can redistribute it and/or modify it under the
|
||||||
|
# terms of the GNU General Public License as published by the Free Software
|
||||||
|
# Foundation, either version 3 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# ROBOTGAME is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||||
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
|
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# ROBOTGAME. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
||||||
|
#
|
||||||
|
# main_menu.py
|
||||||
|
# --------------------
|
||||||
|
# date created : Tue Aug 7 2012
|
||||||
|
# copyright : (C) 2012 Sakse Dalum
|
||||||
|
# maintained by : Sakse Dalum <don_s@hongabar.org>
|
||||||
|
|
||||||
|
"""
|
||||||
|
The main menu.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
import level
|
||||||
|
|
||||||
|
class MainMenu(object):
|
||||||
|
def __init__(self, game, background_img_path):
|
||||||
|
self.__dict__.update(locals())
|
||||||
|
|
||||||
|
self.load()
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
self.background_img = pygame.image.load(self.background_img_path)
|
||||||
|
self.background_img = pygame.transform.smoothscale(
|
||||||
|
self.background_img, self.game.window.get_size())
|
||||||
|
|
||||||
|
def update(self, e, t, dt):
|
||||||
|
for event in e:
|
||||||
|
if event.type == pygame.KEYDOWN:
|
||||||
|
if event.key == pygame.K_SPACE:
|
||||||
|
self.game.goto_level(level.Level("landing"))
|
||||||
|
|
||||||
|
def draw(self, window):
|
||||||
|
window.blit(self.background_img, (0, 0))
|
Loading…
Reference in New Issue