-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprites.py
74 lines (63 loc) · 2.06 KB
/
sprites.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
import pygame
from pygame import Color
from pygame import Rect
from pygame import Surface
from pygame.sprite import Sprite
class Ball(Sprite):
def __init__(self):
super().__init__()
self.image = Surface([10, 10])
self.image.fill(Color('red'))
self.rect = self.image.get_rect()
def update(self):
self.rect = self.rect.move(10, 0)
class Player(Sprite):
def __init__(self, x, y):
super().__init__()
self.xvel = 0
self.yvel = 0
self.onGround = True
self.image = Surface((32, 32))
self.image.fill(Color("#00FFFF"))
self.image.convert()
self.rect = Rect(x, y, 32, 32)
def update(self):
self.rect = self.rect.move(3, 0)
# if up:
# # only jump if on the ground
# if self.onGround:
# self.yvel -= 10
# if down:
# pass
# if left:
# self.xvel = -8
# if right:
# self.xvel = 8
# if not self.onGround:
# # only accelerate with gravity if in the air
# self.yvel += 0.3
# # max falling speed
# if self.yvel > 100:
# self.yvel = 100
# if not(left or right):
# self.xvel = 0
# # increment in x direction
# self.rect.left += self.xvel
# # increment in y direction
# self.rect.top += self.yvel
# # assuming we're in the air
# self.onGround = False
class Ladder(Sprite):
def __init__(self, position, side='left'):
super().__init__()
self.image = pygame.image.load('ladder.png').convert_alpha()
if side == 'right':
self.image = pygame.transform.flip(self.image, True, False)
self.rect = self.image.get_rect()
self.rect = self.rect.move(position)
class Platform(Sprite):
def __init__(self, position):
super().__init__()
self.image = pygame.image.load('platform.png').convert()
self.rect = self.image.get_rect()
self.rect = self.rect.move(position)