Merge branch 'master' of hongabar.org:robotgame
This commit is contained in:
commit
67611d3ad1
|
@ -72,11 +72,16 @@ if __name__ == '__main__':
|
||||||
const=True,
|
const=True,
|
||||||
default=False,
|
default=False,
|
||||||
help="disables in-game music")
|
help="disables in-game music")
|
||||||
|
parser.add_argument('-l',
|
||||||
|
'--level',
|
||||||
|
type=int,
|
||||||
|
help="go directly to level n")
|
||||||
|
|
||||||
args = vars(parser.parse_args())
|
args = vars(parser.parse_args())
|
||||||
resolution = tuple([int(x) for x in args['resolution'].split('x')])
|
resolution = tuple([int(x) for x in args['resolution'].split('x')])
|
||||||
fullscreen = bool(args['fullscreen'])
|
fullscreen = bool(args['fullscreen'])
|
||||||
disable_music = bool(args['disable_music'])
|
disable_music = bool(args['disable_music'])
|
||||||
|
goto_level = args['level']
|
||||||
|
|
||||||
print("Display width: %d, display height: %d, fullscreen: %s"
|
print("Display width: %d, display height: %d, fullscreen: %s"
|
||||||
% (resolution[0], resolution[1], fullscreen))
|
% (resolution[0], resolution[1], fullscreen))
|
||||||
|
@ -88,5 +93,6 @@ if __name__ == '__main__':
|
||||||
window = pygame.display.set_mode(resolution,
|
window = pygame.display.set_mode(resolution,
|
||||||
pygame.FULLSCREEN if fullscreen else 0)
|
pygame.FULLSCREEN if fullscreen else 0)
|
||||||
|
|
||||||
game = robotgame.game.Game(window, directory, disable_music)
|
game = robotgame.game.Game(window, directory, disable_music,
|
||||||
|
initial_goto_level=goto_level)
|
||||||
game.start()
|
game.start()
|
||||||
|
|
|
@ -27,6 +27,7 @@ The game. Handles everything.
|
||||||
import os
|
import os
|
||||||
import pygame
|
import pygame
|
||||||
|
|
||||||
|
import robotgame
|
||||||
import jukebox
|
import jukebox
|
||||||
import level
|
import level
|
||||||
import main_menu
|
import main_menu
|
||||||
|
@ -35,7 +36,7 @@ import game_menu
|
||||||
class Game(object):
|
class Game(object):
|
||||||
"""Create an object to handle the game."""
|
"""Create an object to handle the game."""
|
||||||
def __init__(self, window, directory, disable_music,
|
def __init__(self, window, directory, disable_music,
|
||||||
running=False, speed=30):
|
running=False, speed=30, initial_goto_level=None):
|
||||||
self.__dict__.update(locals())
|
self.__dict__.update(locals())
|
||||||
|
|
||||||
self.objs = []
|
self.objs = []
|
||||||
|
@ -56,7 +57,6 @@ class Game(object):
|
||||||
def load(self):
|
def load(self):
|
||||||
graphics_dir = os.path.join(self.directory, "resources", "graphics")
|
graphics_dir = os.path.join(self.directory, "resources", "graphics")
|
||||||
|
|
||||||
self.objs.append(main_menu.MainMenu(self, graphics_dir))
|
|
||||||
self.level = None
|
self.level = None
|
||||||
self.jukebox = jukebox.Jukebox(
|
self.jukebox = jukebox.Jukebox(
|
||||||
os.path.join(self.directory, "resources", "music"),
|
os.path.join(self.directory, "resources", "music"),
|
||||||
|
@ -65,6 +65,13 @@ class Game(object):
|
||||||
if not self.disable_music:
|
if not self.disable_music:
|
||||||
self.jukebox.play()
|
self.jukebox.play()
|
||||||
|
|
||||||
|
if not self.initial_goto_level:
|
||||||
|
self.objs.append(main_menu.MainMenu(self, graphics_dir))
|
||||||
|
else:
|
||||||
|
exec 'from level%d import Level%d as level' % (self.initial_goto_level,
|
||||||
|
self.initial_goto_level)
|
||||||
|
self.goto_level(level(self, graphics_dir))
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
t = pygame.time.get_ticks()
|
t = pygame.time.get_ticks()
|
||||||
dt = 0
|
dt = 0
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
import os
|
||||||
|
import pygame
|
||||||
|
import random
|
||||||
|
import re
|
||||||
|
|
||||||
|
import level
|
||||||
|
import player
|
||||||
|
import tile
|
||||||
|
import block
|
||||||
|
import boulder
|
||||||
|
import lever
|
||||||
|
|
||||||
|
class Level2(level.Level):
|
||||||
|
def __init__(self, game, graphics_dir, paused=False):
|
||||||
|
level.Level.__init__(self, game, graphics_dir, paused)
|
||||||
|
|
||||||
|
self.dimensions = 20, 20
|
||||||
|
|
||||||
|
for i in range(self.dimensions[0]):
|
||||||
|
for j in range(self.dimensions[1]):
|
||||||
|
self.tiles.append(
|
||||||
|
tile.Tile(self, i*64, j*48, self.imgs['ground1']))
|
||||||
|
|
||||||
|
blocks = [block.Block(self, 64*4, 48, self.imgs['block1'])]
|
||||||
|
|
||||||
|
self.objects.extend(blocks)
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
"""Load all resources used in the level."""
|
||||||
|
tile_list = ['ground1', 'ground2']
|
||||||
|
|
||||||
|
for tile in tile_list:
|
||||||
|
self.imgs[tile] = pygame.image.load(os.path.join(
|
||||||
|
self.graphics_dir, 'tiles', '%s.png' % tile))
|
||||||
|
|
||||||
|
block_list = ['block1']
|
||||||
|
for block in block_list:
|
||||||
|
self.imgs[block] = pygame.image.load(os.path.join(
|
||||||
|
self.graphics_dir, 'blocks', '%s.png' % block))
|
||||||
|
|
||||||
|
def restart(self):
|
||||||
|
for obj in self.objects:
|
||||||
|
obj.reset_pos()
|
Loading…
Reference in New Issue