2012-10-12 13:50:02 +02:00
|
|
|
# This file is part of A Robot's Conundrum.
|
2012-08-10 18:54:48 +02:00
|
|
|
#
|
2012-10-12 13:50:02 +02:00
|
|
|
# A Robot's Conundrum 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.
|
2012-08-10 18:54:48 +02:00
|
|
|
#
|
2012-10-12 13:50:02 +02:00
|
|
|
# A Robot's Conundrum 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.
|
2012-08-10 18:54:48 +02:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
2012-10-12 13:50:02 +02:00
|
|
|
# A Robot's Conundrum. If not, see <http://www.gnu.org/licenses/>.
|
2012-08-10 18:54:48 +02:00
|
|
|
#
|
|
|
|
# ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' '
|
|
|
|
#
|
|
|
|
# loader.py
|
|
|
|
# --------------------
|
|
|
|
# date created : Fri Aug 10 2012
|
|
|
|
# copyright : (C) 2012 Sakse Dalum
|
|
|
|
# maintained by : Sakse Dalum <don_s@hongabar.org>
|
|
|
|
|
|
|
|
"""
|
|
|
|
A loader object.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pygame
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
|
|
|
class Loader(object):
|
2012-08-12 22:15:01 +02:00
|
|
|
def __init__(self, game, directory):
|
2012-08-10 18:54:48 +02:00
|
|
|
self.__dict__.update(locals())
|
|
|
|
self.imgs = {}
|
|
|
|
|
|
|
|
def load(self):
|
|
|
|
"""Load all game resources."""
|
|
|
|
l = ['ground1', 'ground2']
|
|
|
|
for o in l:
|
|
|
|
self.imgs[o] = pygame.image.load(os.path.join(
|
|
|
|
self.directory, 'tiles', '%s.png' % o))
|
|
|
|
|
2012-08-20 19:23:10 +02:00
|
|
|
for o in range(1, 13):
|
2012-11-15 18:36:50 +01:00
|
|
|
for i in ('', '-lifted', '-down'):
|
|
|
|
s = 'symbolblock%02d%s' % (o, i)
|
|
|
|
self.imgs[s] = (
|
2012-08-12 19:47:55 +02:00
|
|
|
pygame.image.load(os.path.join(
|
2012-11-15 18:36:50 +01:00
|
|
|
self.directory, 'symbols', 'blocks', s + '.png')))
|
2012-08-20 19:23:10 +02:00
|
|
|
for o in range(13, 18):
|
|
|
|
for i in range(16, 20):
|
|
|
|
self.imgs['symbol%02d-%04d' % (o, i)] = (
|
|
|
|
pygame.image.load(os.path.join(
|
|
|
|
self.directory, 'symbols', 'blocks',
|
|
|
|
'block%02d-%04d.png' % (o, i))))
|
2012-08-12 19:47:55 +02:00
|
|
|
|
2012-08-10 18:54:48 +02:00
|
|
|
for o in range(1, 7):
|
|
|
|
self.imgs['indoor%d' % o] = pygame.image.load(os.path.join(
|
|
|
|
self.directory, 'tiles', 'indoor', 'ground%02d.png' % o))
|
|
|
|
|
2012-11-15 18:36:50 +01:00
|
|
|
l = ['block1', 'block1-lifted', 'block3', '../lasertarget',
|
2012-08-13 16:20:45 +02:00
|
|
|
'../lasersource_up', '../lasersource_down', '../lasersource_right',
|
2012-11-15 18:36:50 +01:00
|
|
|
'../lasertarget_glow', '../laser_beam_horizontal',
|
|
|
|
'../laser_beam_vertical']
|
2012-08-10 18:54:48 +02:00
|
|
|
for o in l:
|
2012-08-13 00:05:44 +02:00
|
|
|
self.imgs[os.path.basename(o)] = pygame.image.load(os.path.join(
|
2012-08-10 18:54:48 +02:00
|
|
|
self.directory, 'blocks', '%s.png' % o))
|
2012-08-13 00:05:44 +02:00
|
|
|
self.imgs['lasersource_left'] = pygame.transform.flip(
|
|
|
|
self.imgs['lasersource_right'], 1, 0)
|
2012-08-20 19:23:10 +02:00
|
|
|
|
|
|
|
l = ['hole', 'well', 'wall', 'wall_outside', 'intro-screen',
|
|
|
|
'spacecraft']
|
2012-08-10 18:54:48 +02:00
|
|
|
for o in l:
|
|
|
|
self.imgs[o] = pygame.image.load(os.path.join(
|
|
|
|
self.directory, '%s.png' % o))
|
|
|
|
|
2012-08-12 22:15:01 +02:00
|
|
|
|
|
|
|
# Special treatment
|
|
|
|
screen_size = self.game.window.get_size()
|
|
|
|
img_size = self.imgs['intro-screen'].get_size()
|
|
|
|
factors = (float(img_size[0]) / 1920, float(img_size[1]) / 1440)
|
|
|
|
|
|
|
|
self.imgs['intro-screen'] = pygame.transform.smoothscale(
|
|
|
|
self.imgs['intro-screen'],
|
|
|
|
(int(screen_size[0]*factors[0]),
|
|
|
|
int(screen_size[1]*factors[1])))
|
|
|
|
|
|
|
|
### Moat
|
2012-08-10 18:54:48 +02:00
|
|
|
l = ['moat_corner_north',
|
|
|
|
'moat_corner_south',
|
|
|
|
'moat_corner_north_flip',
|
|
|
|
'moat_corner_south_flip',
|
|
|
|
'moat_end_horizontal',
|
|
|
|
'moat_horizontal',
|
|
|
|
'moat_vertical']
|
|
|
|
for o in l:
|
|
|
|
self.imgs[o] = pygame.image.load(os.path.join(
|
|
|
|
self.directory, 'moat', '%s.png' % o))
|
|
|
|
|
|
|
|
# Special treatment
|
|
|
|
self.imgs['moat_end_horizontal_flip'] = pygame.transform.flip(
|
|
|
|
self.imgs['moat_end_horizontal'], 1, 0)
|
|
|
|
|
2012-08-20 20:00:30 +02:00
|
|
|
### Elevator
|
|
|
|
for n, p in (('elevator', 'elevator'),
|
|
|
|
('elevator_bottom', 'bottom_corners'),
|
|
|
|
('elevator_top', 'top_corners')):
|
|
|
|
self.imgs[n] = pygame.image.load(os.path.join(
|
|
|
|
self.directory, 'elevator', p + '.png'))
|
|
|
|
|
2012-08-10 18:54:48 +02:00
|
|
|
# Load animations
|
|
|
|
for anim, directory in (
|
|
|
|
[('boulder_up', os.path.join('boulder', 'up')),
|
|
|
|
('boulder_down', os.path.join('boulder', 'down')),
|
|
|
|
('boulder_right', os.path.join('boulder', 'right')),
|
|
|
|
('boulder_left', os.path.join('boulder', 'right')),
|
|
|
|
('boulder_falling', os.path.join('boulder_fall')),
|
|
|
|
|
|
|
|
('lever_updown', os.path.join('lever', 'down-up')),
|
|
|
|
('lever_leftright', os.path.join('lever', 'left-right')),
|
|
|
|
|
|
|
|
('arrow_up', os.path.join('matt', 'up')),
|
|
|
|
('arrow_right', os.path.join('matt', 'right')),
|
|
|
|
('arrow_down', os.path.join('matt', 'down')),
|
2012-08-10 22:31:15 +02:00
|
|
|
('arrow_left', os.path.join('matt', 'right')),
|
|
|
|
|
2012-08-11 02:22:29 +02:00
|
|
|
('stairs', 'stairs'),
|
2012-08-11 14:47:06 +02:00
|
|
|
('elevating_column', 'elevating_column'),
|
2012-08-11 02:22:29 +02:00
|
|
|
|
2012-08-12 19:05:54 +02:00
|
|
|
('mirror', 'mirror'),
|
2012-11-15 18:36:50 +01:00
|
|
|
('weight_indicator', 'weight_indicator'),
|
2012-08-12 19:05:54 +02:00
|
|
|
|
|
|
|
('door', 'door')]
|
2012-08-10 18:54:48 +02:00
|
|
|
):
|
|
|
|
|
|
|
|
self.imgs[anim] = []
|
|
|
|
|
|
|
|
# Find all image files for the given animation
|
|
|
|
anim_files = []
|
|
|
|
for root, dirs, files in os.walk(os.path.join(
|
|
|
|
self.directory, directory)):
|
|
|
|
for f in files:
|
|
|
|
if re.match(r"^.*\.(png)$", '/'.join([root, f])):
|
|
|
|
anim_files.append('/'.join([root, f]))
|
|
|
|
|
|
|
|
# Sort and load the files
|
|
|
|
for f in sorted(anim_files):
|
|
|
|
img = pygame.image.load(f)
|
|
|
|
|
|
|
|
# Special treatment:
|
2012-08-13 00:05:44 +02:00
|
|
|
if anim in ('arrow_left',):
|
2012-08-10 18:54:48 +02:00
|
|
|
img = pygame.transform.flip(img, 1, 0)
|
|
|
|
|
2012-08-20 19:23:10 +02:00
|
|
|
if (anim in ('arrow_left', 'arrow_right',
|
|
|
|
'arrow_up', 'arrow_down')
|
|
|
|
and len(self.imgs[anim]) >= 16):
|
|
|
|
self.imgs[anim + '_lifted'] = img
|
|
|
|
continue
|
|
|
|
|
2012-08-10 18:54:48 +02:00
|
|
|
self.imgs[anim].append(img)
|
|
|
|
|
|
|
|
####### PLAYER #######
|
|
|
|
|
|
|
|
for anim, directory in (
|
2012-08-20 19:23:10 +02:00
|
|
|
(('idle_up', os.path.join('robot_idle', 'up')),
|
2012-08-10 18:54:48 +02:00
|
|
|
('idle_down', os.path.join('robot_idle', 'down')),
|
|
|
|
('idle_right', os.path.join('robot_idle', 'right')),
|
|
|
|
('idle_left', os.path.join('robot_idle', 'right')),
|
|
|
|
('carry_up', os.path.join('robot_carry', 'up')),
|
|
|
|
('carry_down', os.path.join('robot_carry', 'down')),
|
|
|
|
('carry_right', os.path.join('robot_carry', 'right')),
|
|
|
|
('carry_left', os.path.join('robot_carry', 'right')),
|
|
|
|
|
|
|
|
# Lever
|
|
|
|
|
|
|
|
('lever_down_right', os.path.join('robot_lever', 'horizontal',
|
|
|
|
'down_left')),
|
|
|
|
('lever_down_left', os.path.join('robot_lever', 'horizontal',
|
|
|
|
'down_left')),
|
|
|
|
('lever_down_up', os.path.join('robot_lever', 'vertical',
|
|
|
|
'down_down')),
|
|
|
|
('lever_down_down', os.path.join('robot_lever', 'vertical',
|
|
|
|
'down_down')),
|
|
|
|
|
|
|
|
('lever_up_right', os.path.join('robot_lever', 'horizontal',
|
|
|
|
'up_right')),
|
|
|
|
('lever_up_left', os.path.join('robot_lever', 'horizontal',
|
|
|
|
'up_right')),
|
|
|
|
('lever_up_up', os.path.join('robot_lever', 'vertical',
|
|
|
|
'up_up')),
|
|
|
|
('lever_up_down', os.path.join('robot_lever', 'vertical',
|
|
|
|
'up_up')),
|
|
|
|
|
|
|
|
('lever_right_right', os.path.join('robot_lever', 'horizontal',
|
|
|
|
'right_right')),
|
|
|
|
('lever_right_left', os.path.join('robot_lever', 'horizontal',
|
|
|
|
'right_right')),
|
|
|
|
('lever_right_up', os.path.join('robot_lever', 'vertical',
|
|
|
|
'left_up')),
|
|
|
|
('lever_right_down', os.path.join('robot_lever', 'vertical',
|
|
|
|
'right_down')),
|
|
|
|
|
|
|
|
('lever_left_right', os.path.join('robot_lever', 'horizontal',
|
|
|
|
'right_right')),
|
|
|
|
('lever_left_left', os.path.join('robot_lever', 'horizontal',
|
|
|
|
'left_left')),
|
|
|
|
('lever_left_up', os.path.join('robot_lever', 'vertical',
|
|
|
|
'left_up')),
|
|
|
|
('lever_left_down', os.path.join('robot_lever', 'vertical',
|
|
|
|
'right_down'))
|
2012-08-20 19:23:10 +02:00
|
|
|
)):
|
2012-08-10 18:54:48 +02:00
|
|
|
|
|
|
|
self.imgs['robot_' + anim] = []
|
|
|
|
|
|
|
|
# Find all image files for the given animation
|
|
|
|
anim_files = []
|
|
|
|
for root, dirs, files in os.walk(os.path.join(
|
|
|
|
self.directory, directory)):
|
|
|
|
for f in files:
|
|
|
|
if re.match(r"^.*\.(png)$", '/'.join([root, f])):
|
|
|
|
anim_files.append('/'.join([root, f]))
|
|
|
|
|
|
|
|
# Sort and load the files
|
|
|
|
for f in sorted(anim_files):
|
|
|
|
img = pygame.image.load(f)
|
|
|
|
|
|
|
|
# Special treatment:
|
|
|
|
if anim in ['idle_left', 'carry_left',
|
|
|
|
|
|
|
|
'lever_down_right', 'lever_left_down',
|
2012-08-10 22:31:15 +02:00
|
|
|
'lever_up_left', 'lever_right_up',
|
|
|
|
'lever_left_right']:
|
2012-08-10 18:54:48 +02:00
|
|
|
img = pygame.transform.flip(img, 1, 0)
|
|
|
|
|
|
|
|
if anim in ['lever_right_left', 'lever_left_right',
|
|
|
|
'lever_down_up', 'lever_up_down']:
|
|
|
|
self.imgs['robot_' + anim].insert(0, img)
|
|
|
|
else:
|
|
|
|
self.imgs['robot_' + anim].append(img)
|