Browse Source

Merge branch 'master' of hongabar.org:robotgame

master
Sakse Dalum 9 years ago
parent
commit
67611d3ad1
  1. 8
      robotgame.py
  2. 11
      robotgame/game.py
  3. 43
      robotgame/level2.py

8
robotgame.py

@ -72,11 +72,16 @@ if __name__ == '__main__':
const=True,
default=False,
help="disables in-game music")
parser.add_argument('-l',
'--level',
type=int,
help="go directly to level n")
args = vars(parser.parse_args())
resolution = tuple([int(x) for x in args['resolution'].split('x')])
fullscreen = bool(args['fullscreen'])
disable_music = bool(args['disable_music'])
goto_level = args['level']
print("Display width: %d, display height: %d, fullscreen: %s"
% (resolution[0], resolution[1], fullscreen))
@ -88,5 +93,6 @@ if __name__ == '__main__':
window = pygame.display.set_mode(resolution,
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()

11
robotgame/game.py

@ -27,6 +27,7 @@ The game. Handles everything.
import os
import pygame
import robotgame
import jukebox
import level
import main_menu
@ -35,7 +36,7 @@ import game_menu
class Game(object):
"""Create an object to handle the game."""
def __init__(self, window, directory, disable_music,
running=False, speed=30):
running=False, speed=30, initial_goto_level=None):
self.__dict__.update(locals())
self.objs = []
@ -56,7 +57,6 @@ class Game(object):
def load(self):
graphics_dir = os.path.join(self.directory, "resources", "graphics")
self.objs.append(main_menu.MainMenu(self, graphics_dir))
self.level = None
self.jukebox = jukebox.Jukebox(
os.path.join(self.directory, "resources", "music"),
@ -65,6 +65,13 @@ class Game(object):
if not self.disable_music:
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):
t = pygame.time.get_ticks()
dt = 0

43
robotgame/level2.py

@ -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…
Cancel
Save