2012-08-07 19:59:52 +02:00
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
|
|
|
#
|
|
|
|
# level1.py
|
|
|
|
# --------------------
|
|
|
|
# date created : Tue Aug 7 2012
|
|
|
|
# copyright : (C) 2012 Sakse Dalum
|
|
|
|
# maintained by : Sakse Dalum <don_s@hongabar.org>
|
|
|
|
|
|
|
|
"""
|
|
|
|
The first level.
|
|
|
|
"""
|
|
|
|
|
2012-08-07 21:23:10 +02:00
|
|
|
import os
|
|
|
|
import pygame
|
2012-08-07 23:21:44 +02:00
|
|
|
import random
|
2012-08-07 21:23:10 +02:00
|
|
|
|
2012-08-07 19:59:52 +02:00
|
|
|
import level
|
|
|
|
import player
|
2012-08-07 21:23:10 +02:00
|
|
|
import tile
|
2012-08-07 23:21:44 +02:00
|
|
|
import block
|
2012-08-07 19:59:52 +02:00
|
|
|
|
|
|
|
class Level1(level.Level):
|
2012-08-07 21:23:10 +02:00
|
|
|
def __init__(self, graphics_dir):
|
|
|
|
self.__dict__.update(locals())
|
|
|
|
|
2012-08-07 23:21:44 +02:00
|
|
|
self.player = player.Player(self, 5*64, 5*48)
|
|
|
|
|
|
|
|
self.dimensions = 20, 20
|
2012-08-07 19:59:52 +02:00
|
|
|
|
2012-08-07 21:23:10 +02:00
|
|
|
self.tiles = []
|
2012-08-07 23:21:44 +02:00
|
|
|
self.objects = []
|
|
|
|
|
2012-08-07 21:23:10 +02:00
|
|
|
self.imgs = {}
|
|
|
|
|
|
|
|
self.load()
|
|
|
|
|
2012-08-07 23:21:44 +02:00
|
|
|
for i in range(self.dimensions[0]):
|
|
|
|
for j in range(self.dimensions[1]):
|
2012-08-07 21:23:10 +02:00
|
|
|
self.tiles.append(
|
2012-08-07 23:21:44 +02:00
|
|
|
tile.Tile(self, i*64, j*48, self.imgs['ground%d'
|
|
|
|
% (((i + j) % 2) + 1)]))
|
|
|
|
|
|
|
|
self.objects.append(self.player)
|
|
|
|
for i in range(100):
|
|
|
|
self.objects.append(block.Block(self, random.randint(0, 20)*64,
|
|
|
|
random.randint(0, 20)*48,
|
|
|
|
self.imgs['block1'],
|
|
|
|
movable=True))
|
2012-08-07 21:23:10 +02:00
|
|
|
|
|
|
|
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))
|
|
|
|
|
2012-08-07 23:21:44 +02:00
|
|
|
block_list = ['block1']
|
|
|
|
for block in block_list:
|
|
|
|
self.imgs[block] = pygame.image.load(os.path.join(
|
|
|
|
self.graphics_dir, 'blocks', '%s.png' % block))
|
|
|
|
|
2012-08-07 19:59:52 +02:00
|
|
|
def update(self, e, t, dt):
|
2012-08-07 23:21:44 +02:00
|
|
|
for obj in self.objects:
|
|
|
|
obj.update(e, t, dt)
|
2012-08-07 19:59:52 +02:00
|
|
|
|
|
|
|
def draw(self, window):
|
2012-08-07 21:23:10 +02:00
|
|
|
for tile in self.tiles:
|
|
|
|
tile.draw(window)
|
|
|
|
|
2012-08-07 23:21:44 +02:00
|
|
|
for obj in sorted(self.objects, key=lambda obj: (obj.y + obj.z)):
|
|
|
|
obj.draw(window)
|