-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer.py
64 lines (56 loc) · 2.19 KB
/
player.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
from mesh import Mesh
from utils import shape_to_mesh
import pyglet
from euclid3 import Vector2
from config import *
class Player(Mesh):
def __init__(self):
Mesh.__init__(self, BLOCK_SIZE * 10, BLOCK_SIZE * 10)
self.shape = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
]
v, i = shape_to_mesh(self.shape, 0xFFFFFF)
self.set_data(vertices=v, indices=i)
self.direction = Vector2(0, 0)
self.move_amount = 10.0
def move_left(self):
self.direction.x = -1
def move_right(self):
self.direction.x = 1
def move_end(self):
self.direction.x = 0
def move_mouse(self, x, y):
# their x and y is from bottom left
# my x and y is from top left
increment_x = x - self.position.x
if x > self.position.x:
if self.position.x + self.width + increment_x >= WIDTH:
self.Translate(WIDTH - self.width, self.position.y, self.position.z)
else:
self.translate(increment_x, 0.0, 0.0)
elif x < self.position.x:
if self.position.x + increment_x < 0:
self.Translate(0, self.position.y, self.position.z)
else:
self.translate(increment_x, 0.0, 0.0)
def update(self, dt):
super().update(dt)
if self.direction.x == 1:
if self.position.x + self.width + self.move_amount >= WIDTH:
self.Translate(WIDTH - self.width, self.position.y, self.position.z)
else:
self.translate(self.move_amount, 0.0, 0.0)
elif self.direction.x == -1:
if self.position.x + (self.move_amount * -1) < 0:
self.Translate(0, self.position.y, self.position.z)
else:
self.translate((self.move_amount * -1), 0.0, 0.0)