forked from satanas/ngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sideview_scene.py
108 lines (87 loc) · 3.65 KB
/
sideview_scene.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
#================================================
#
# Dummy Scene for the Side-View Example (please execute sideview_example.py)
#
# Copyright (C) 2011 Wil Alvarez <[email protected]>
#
#===================================================
import pygame
import random
from ngine import scene
from ngine import collisions
from dummy_keys import *
from sideview_objects import *
class DummyScene(scene.Scene):
def __init__(self, director, _input, gamedata):
scene.Scene.__init__(self, director, _input, gamedata)
self.quit = False
def __load_map(self, filename):
self.maploader.load(filename)
for row in self.maploader.layers['unwalkable']:
for block in row:
if block.t_id == '00':
continue
tb, bb, lb, rb = self.maploader.get_collide_bounds(block.x, block.y)
Platform(self.res, block.t_id, (block.real_x, block.real_y), tb, bb, lb, rb)
for row in self.maploader.layers['characters']:
for char in row:
if char.t_id == '01':
self.player = Tux(self.res, (char.real_x, char.real_y), self.gblocks)
for row in self.maploader.layers['items']:
for item in row:
if item.t_id == '01':
Coin(self.res, (item.real_x, item.real_y))
def on_load(self):
self.layer1 = pygame.sprite.Group()
self.layer2 = pygame.sprite.Group()
self.gblocks = pygame.sprite.Group()
self.gcoins = pygame.sprite.Group()
self.all = pygame.sprite.Group()
Tux.containers = self.all, self.layer1
Platform.containers = self.all, self.layer2, self.gblocks
Coin.containers = self.all, self.layer2, self.gcoins
self.res.font.load_default('__default__', 16, (255,255,255))
self.res.bg.load(['bg1.png', 'bg2.png', 'scroll.png', 'north-pole.png'])
self.res.image.load(['tux.png', 'ice-ground.png', 'coin24.png'])
self.res.sound.load(['coin.ogg'])
self.__load_map('01.map')
self.effect = 0
self.on_loaded_map()
self.append_to_draw(self.layer2)
self.append_to_draw(self.layer1)
self.set_camera_target(self.player)
self.set_backgrounds(bg1='north-pole', bg3='scroll')
def handle_events(self):
self._input.handle_input()
if self._input.lookup(LEFT):
self.player.move(-1, 0)
self.scroll_bg(self.player.xspeed)
elif self._input.lookup(RIGHT):
self.player.move(1, 0)
self.scroll_bg(-self.player.xspeed)
if self._input.lookup(ACTION1):
self.player.jump()
if self._input.lookup(EXIT):
return True
if self.quit:
return True
return False
def check_collisions(self):
for coin in self.gcoins:
if collisions.check(self.player, coin):
coin.kill()
self.res.sound.play('coin')
def on_update(self):
self.all.update()
if self.player.rect.top > self.maploader.get_size()[1]:
self.quit = True
def on_draw(self):
self.__text_on_screen()
def __text_on_screen(self):
fps = str(int(self.director.clock.get_fps ()))
obj_count = str(len(self.all))
info1 = self.res.font.render('__default__', 'FPS: ' + fps)
info2 = self.res.font.render('__default__', 'Objects: ' + obj_count)
self.screen.blit(info1, (10, 10))
self.screen.blit(info2, (10, 20))