Added tiles.
This commit is contained in:
parent
dc5acdf4c6
commit
90a11e9ed3
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
11
robotgame.py
11
robotgame.py
|
@ -62,11 +62,18 @@ if __name__ == '__main__':
|
||||||
action='store_const',
|
action='store_const',
|
||||||
const=True,
|
const=True,
|
||||||
default=False,
|
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())
|
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'])
|
||||||
|
|
||||||
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))
|
||||||
|
@ -78,5 +85,5 @@ 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)
|
game = robotgame.game.Game(window, disable_music)
|
||||||
game.start()
|
game.start()
|
||||||
|
|
|
@ -34,7 +34,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, running=False, speed=30):
|
def __init__(self, window, disable_music, running=False, speed=30):
|
||||||
self.__dict__.update(locals())
|
self.__dict__.update(locals())
|
||||||
|
|
||||||
self.objs = []
|
self.objs = []
|
||||||
|
@ -61,6 +61,7 @@ class Game(object):
|
||||||
os.path.abspath(os.path.join("resources", "music")),
|
os.path.abspath(os.path.join("resources", "music")),
|
||||||
["basshit.ogg"])
|
["basshit.ogg"])
|
||||||
self.jukebox.stop()
|
self.jukebox.stop()
|
||||||
|
if not self.disable_music:
|
||||||
self.jukebox.play()
|
self.jukebox.play()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
@ -92,7 +93,7 @@ class Game(object):
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
# Keep the music playing!
|
# 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()
|
self.jukebox.play()
|
||||||
|
|
||||||
# Update all objects
|
# Update all objects
|
||||||
|
|
|
@ -24,15 +24,43 @@
|
||||||
The first level.
|
The first level.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import pygame
|
||||||
|
|
||||||
import level
|
import level
|
||||||
import player
|
import player
|
||||||
|
import tile
|
||||||
|
|
||||||
class Level1(level.Level):
|
class Level1(level.Level):
|
||||||
def __init__(self):
|
def __init__(self, graphics_dir):
|
||||||
|
self.__dict__.update(locals())
|
||||||
|
|
||||||
self.player = player.Player(200, 200)
|
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):
|
def update(self, e, t, dt):
|
||||||
self.player.update(e, t, dt)
|
self.player.update(e, t, dt)
|
||||||
|
|
||||||
def draw(self, window):
|
def draw(self, window):
|
||||||
|
for tile in self.tiles:
|
||||||
|
tile.draw(window)
|
||||||
|
|
||||||
self.player.draw(window)
|
self.player.draw(window)
|
||||||
|
|
|
@ -59,7 +59,7 @@ class MainMenu(object):
|
||||||
for event in e:
|
for event in e:
|
||||||
if event.type == pygame.KEYDOWN:
|
if event.type == pygame.KEYDOWN:
|
||||||
if event.key == pygame.K_SPACE:
|
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.remove(self)
|
||||||
self.game.objs.append(game_menu.GameMenu(self.game,
|
self.game.objs.append(game_menu.GameMenu(self.game,
|
||||||
self.img_dir))
|
self.img_dir))
|
||||||
|
|
|
@ -44,4 +44,6 @@ class Player(worldobject.WorldObject):
|
||||||
self.move(-1, 0)
|
self.move(-1, 0)
|
||||||
|
|
||||||
def draw(self, window):
|
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)
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
||||||
|
#
|
||||||
|
# worldobject.py
|
||||||
|
# --------------------
|
||||||
|
# date created : Tue Aug 7 2012
|
||||||
|
# copyright : (C) 2012 Sakse Dalum
|
||||||
|
# maintained by : Sakse Dalum <don_s@hongabar.org>
|
||||||
|
|
||||||
|
"""
|
||||||
|
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))
|
|
@ -28,7 +28,8 @@ class WorldObject(object):
|
||||||
def __init__(self, x, y, speed=5, tile_x=64, tile_y=48):
|
def __init__(self, x, y, speed=5, tile_x=64, tile_y=48):
|
||||||
self.__dict__.update(locals())
|
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):
|
def move(self, move_x, move_y):
|
||||||
if self.move_x == self.x and self.move_y == self.y:
|
if self.move_x == self.x and self.move_y == self.y:
|
||||||
|
|
Loading…
Reference in New Issue