-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsideview_objects.py
132 lines (114 loc) · 4.56 KB
/
sideview_objects.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# -*- coding: utf-8 -*-
#================================================
#
# Dummy Objects for the Side-View Example (please execute sideview_example.py)
#
# Copyright (C) 2011 Wil Alvarez <[email protected]>
#
#===================================================
import pygame
from ngine import objects
from ngine.resources import tools
# A class that represent a little square box on screen
class Tux(objects.Actor, objects.FallingObject):
def __init__(self, res, pos, group):
objects.Actor.__init__(self, group)
objects.FallingObject.__init__(self)
#self.res = res
ckey = (0, 255, 0)
orig = res.image.get('tux')
self.right_array = [
tools.get_image_at(orig, 32, 0, 32, 32, ckey),
tools.get_image_at(orig, 64, 0, 32, 32, ckey),
tools.get_image_at(orig, 96, 0, 32, 32, ckey),
]
self.left_array = [
tools.get_image_at(orig, 32, 32, 32, 32, ckey),
tools.get_image_at(orig, 64, 32, 32, 32, ckey),
tools.get_image_at(orig, 96, 32, 32, 32, ckey),
]
self.right_image = tools.get_image_at(orig, 0, 0, 32, 32, ckey)
self.left_image = tools.get_image_at(orig, 128, 32, 32, 32, ckey)
self.jump_right_image = tools.get_image_at(orig, 128, 0, 32, 32, ckey)
self.jump_left_image = tools.get_image_at(orig, 0, 32, 32, 32, ckey)
self.xspeed = 3
self.yspeed = 2
self.anim_delay = 4
self.set_image(self.right_image, pos)
self.set_relative_rect()
self.set_array(self.right_array)
self.last_xdir = 1
def on_move(self, xdir, ydir):
if xdir < 0:
self.set_array(self.left_array)
elif xdir > 0:
self.set_array(self.right_array)
def on_collide_top(self, object):
self.jumping = False
self.jump_speed = 0
def jump(self):
if not self.jumping:
self.jump_speed = -11
self.jumping = True
def update(self):
self.check_gravity()
if self.xdir == 0 and self.ydir == 0:
if self.last_xdir < 0:
self.image = self.left_image
elif self.last_xdir > 0:
self.image = self.right_image
if self.jumping:
if self.last_xdir < 0:
self.image = self.jump_left_image
elif self.last_xdir > 0:
self.image = self.jump_right_image
self.xdir = 0
self.ydir = 0
# A class that represent a little square box on screen
class Platform(objects.SpriteObject, objects.CollidableObject, objects.UnwalkableObject):
def __init__(self, res, id, pos, top, bottom, left, right):
objects.SpriteObject.__init__(self)
objects.CollidableObject.__init__(self)
objects.UnwalkableObject.__init__(self, top, bottom, left, right)
self.res = res
image = pygame.Surface((24, 24))
image.fill((255,255,0))
orig = self.res.image.get('ice-ground')
if id == '01':
image = tools.get_image_at(orig, 0, 0, 24, 24)
elif id == '02':
image = tools.get_image_at(orig, 24, 0, 24, 24)
elif id == '03':
image = tools.get_image_at(orig, 48, 0, 24, 24)
elif id == '04':
image = tools.get_image_at(orig, 0, 24, 24, 24)
elif id == '05':
image = tools.get_image_at(orig, 24, 24, 24, 24)
elif id == '06':
image = tools.get_image_at(orig, 48, 24, 24, 24)
elif id == '07':
image = tools.get_image_at(orig, 0, 48, 24, 24)
elif id == '08':
image = tools.get_image_at(orig, 24, 48, 24, 24)
elif id == '09':
image = tools.get_image_at(orig, 48, 48, 24, 24)
self.set_image(image, pos)
self.set_relative_rect()
class Coin(objects.SpriteObject, objects.CollidableObject):
def __init__(self, res, pos):
objects.SpriteObject.__init__(self)
objects.CollidableObject.__init__(self)
self.anim_delay = 5
ckey = (0, 255, 0)
orig = res.image.get('coin24')
array = [
tools.get_image_at(orig, 0, 0, 24, 24, ckey),
tools.get_image_at(orig, 24, 0, 24, 24, ckey),
tools.get_image_at(orig, 48, 0, 24, 24, ckey),
tools.get_image_at(orig, 72, 0, 24, 24, ckey),
]
self.set_image(array[0], pos)
self.set_relative_rect()
self.set_array(array)
def update(self):
self.next_image()