diff --git a/resources/graphics/tiles/ground1.png b/resources/graphics/tiles/ground1.png
new file mode 100644
index 0000000..e20bcea
Binary files /dev/null and b/resources/graphics/tiles/ground1.png differ
diff --git a/resources/graphics/tiles/ground2.png b/resources/graphics/tiles/ground2.png
new file mode 100644
index 0000000..137b720
Binary files /dev/null and b/resources/graphics/tiles/ground2.png differ
diff --git a/robotgame.py b/robotgame.py
index dde222c..3319a37 100755
--- a/robotgame.py
+++ b/robotgame.py
@@ -62,11 +62,18 @@ if __name__ == '__main__':
action='store_const',
const=True,
default=False,
- help="specifies the resolution of the game")
+ help="toggles fullscreen")
+ parser.add_argument('-n',
+ '--disable-music',
+ action='store_const',
+ const=True,
+ default=False,
+ help="disables in-game music")
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'])
print("Display width: %d, display height: %d, fullscreen: %s"
% (resolution[0], resolution[1], fullscreen))
@@ -78,5 +85,5 @@ if __name__ == '__main__':
window = pygame.display.set_mode(resolution,
pygame.FULLSCREEN if fullscreen else 0)
- game = robotgame.game.Game(window)
+ game = robotgame.game.Game(window, disable_music)
game.start()
diff --git a/robotgame/game.py b/robotgame/game.py
index a17f470..803a3fd 100644
--- a/robotgame/game.py
+++ b/robotgame/game.py
@@ -34,7 +34,7 @@ import game_menu
class Game(object):
"""Create an object to handle the game."""
- def __init__(self, window, running=False, speed=30):
+ def __init__(self, window, disable_music, running=False, speed=30):
self.__dict__.update(locals())
self.objs = []
@@ -61,7 +61,8 @@ class Game(object):
os.path.abspath(os.path.join("resources", "music")),
["basshit.ogg"])
self.jukebox.stop()
- self.jukebox.play()
+ if not self.disable_music:
+ self.jukebox.play()
def run(self):
t = pygame.time.get_ticks()
@@ -92,7 +93,7 @@ class Game(object):
self.stop()
# Keep the music playing!
- if not pygame.mixer.music.get_busy():
+ if not pygame.mixer.music.get_busy() and not self.disable_music:
self.jukebox.play()
# Update all objects
diff --git a/robotgame/level1.py b/robotgame/level1.py
index ff7e87a..bfac077 100644
--- a/robotgame/level1.py
+++ b/robotgame/level1.py
@@ -24,15 +24,43 @@
The first level.
"""
+import os
+import pygame
+
import level
import player
+import tile
class Level1(level.Level):
- def __init__(self):
+ def __init__(self, graphics_dir):
+ self.__dict__.update(locals())
+
self.player = player.Player(200, 200)
+ self.tiles = []
+ self.imgs = {}
+
+ self.load()
+
+ for i in range(0, 10):
+ for j in range(0, 10):
+ self.tiles.append(
+ tile.Tile(i*64, j*48,
+ self.imgs['ground%d' % (((i + j) % 2) + 1)]))
+
+ 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))
+
def update(self, e, t, dt):
self.player.update(e, t, dt)
def draw(self, window):
+ for tile in self.tiles:
+ tile.draw(window)
+
self.player.draw(window)
diff --git a/robotgame/main_menu.py b/robotgame/main_menu.py
index d5fca8c..8179955 100644
--- a/robotgame/main_menu.py
+++ b/robotgame/main_menu.py
@@ -59,7 +59,7 @@ class MainMenu(object):
for event in e:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
- self.game.goto_level(level1.Level1())
+ self.game.goto_level(level1.Level1(self.img_dir))
self.game.objs.remove(self)
self.game.objs.append(game_menu.GameMenu(self.game,
self.img_dir))
diff --git a/robotgame/player.py b/robotgame/player.py
index b193ab7..4ea04e6 100644
--- a/robotgame/player.py
+++ b/robotgame/player.py
@@ -44,4 +44,6 @@ class Player(worldobject.WorldObject):
self.move(-1, 0)
def draw(self, window):
- pygame.draw.circle(window, (255, 255, 255), (self.x, self.y), 20)
+ pygame.draw.circle(window, (255, 255, 255), (self.x + self.tile_x / 2,
+ self.y + self.tile_y / 2),
+ 20)
diff --git a/robotgame/tile.py b/robotgame/tile.py
new file mode 100644
index 0000000..7edea35
--- /dev/null
+++ b/robotgame/tile.py
@@ -0,0 +1,35 @@
+# 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 .
+#
+# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
+#
+# worldobject.py
+# --------------------
+# date created : Tue Aug 7 2012
+# copyright : (C) 2012 Sakse Dalum
+# maintained by : Sakse Dalum
+
+"""
+A generic world object.
+"""
+
+import worldobject
+
+class Tile(worldobject.WorldObject):
+ def __init__(self, x, y, img):
+ self.__dict__.update(locals())
+ worldobject.WorldObject.__init__(self, x, y)
+
+ def draw(self, window):
+ window.blit(self.img, (self.x, self.y), (0, 0, self.tile_x, self.tile_y))
diff --git a/robotgame/worldobject.py b/robotgame/worldobject.py
index f30f408..e48ab52 100644
--- a/robotgame/worldobject.py
+++ b/robotgame/worldobject.py
@@ -28,7 +28,8 @@ class WorldObject(object):
def __init__(self, x, y, speed=5, tile_x=64, tile_y=48):
self.__dict__.update(locals())
- self.move_x, self.move_y = self.x, self.y
+ self.move_x = self.x = self.x - (self.x % self.tile_x)
+ self.move_y = self.y = self.y - (self.y % self.tile_y)
def move(self, move_x, move_y):
if self.move_x == self.x and self.move_y == self.y: