-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathactor.py
70 lines (61 loc) · 2.26 KB
/
actor.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
import pygame
import sys, os
class Actor(pygame.sprite.Sprite):
grav = 25#2.9
maxVel = 120
velDamp = .1
accDamp = .35
accDefault = 3
groundAcc = 30
airAcc = 10
left, right, onGround, onWall = False, False, False, False
def __init__(self, acc):
pygame.sprite.Sprite.__init__(self)
x, y = acc
self.pos = [x,y]
self.vel = [0.0,0.0]
self.acc = [0.0, Actor.grav]
self.theta = 0.0
self.dtheta = 0.0
imgpath = os.path.join("assets", "images", "rect.png")
self.image = pygame.Surface((30,30), pygame.SRCALPHA, 32).convert_alpha()#pygame.image.load(imgpath).convert_alpha()
self.image.fill((0,0,0,100))
self.rect = self.image.get_rect()
self.initialpos = self.rect.center = self.pos
def setLocation(self, pos):
x,y = pos
self.pos = [x,y]
self.vel = [0,0]
self.rect.center = self.pos
def jump(self):
if self.onGround is True or self.onWall is True:
self.vel[1] = -200
self.onGround, self.onWall = False, False
def offset(self, x, y):
self.pos = [a[0] + a[1] for a in zip(self.pos, [x,y])]
self.rect.center = self.pos
def update(self, offset=[0.0, 0.0]):
self.pos = [a+b+Actor.velDamp*c for a,b,c in zip(self.pos, offset, self.vel)]
#On above line: self.pos = [a +b + Actor.velDamp*c for a, b, c in zip(stuff)]
if abs(self.vel[0]) > Actor.maxVel and self.acc[0]*self.vel[0] > 0:
self.acc[0] = 0
self.vel = [a[0]+Actor.accDamp*a[1] for a in zip(self.vel, self.acc)]
if not (self.left or self.right):
if (self.onGround):
self.acc[0] = -.4*self.vel[0]
else:
self.acc[0] = -.12*self.vel[0]
self.rect.center = self.pos
if self.left:
self.leftPress()
elif self.right:
self.rightPress()
def leftPress(self):
if self.onGround: self.acc[0] = -Actor.groundAcc
else: self.acc[0] = -Actor.airAcc
def rightPress(self):
if self.onGround: self.acc[0] = Actor.groundAcc
else: self.acc[0] = Actor.airAcc
def reset(self):
self.pos = self.initialpos
self.rect.center = self.pos