forked from zcr1/OSGCC6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform.py
87 lines (69 loc) · 2.22 KB
/
platform.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
import pygame, os
from pygame.locals import *
import copy
import math
class Platform(pygame.sprite.Sprite):
maxDisplacement = 800
moveInc = 3
mouthjump = pygame.mixer.Sound("sounds/mouth-jump.wav")
def __init__(self, pos, death, number, move):
pygame.sprite.Sprite.__init__(self)
filepath = "/OSGCC6/images/newplatform" + number + ".png"
#print filepath
imgPath = os.path.dirname(os.path.dirname( os.path.realpath( __file__ ) ) ) + filepath
self.image = pygame.image.load(imgPath)
self.rect = self.image.get_rect()
self.rect.center = pos
self.worldPos = pos
self.death = (int)(death)
self.currDisplacement = 0
self.moveX = False
self.moveY = False
self.direction = [0,0]
self.active = False
self.acceleration = 1
self.type = move
self.gravyVent = False
self.sprung = False
if move == 1:
self.moveX = True
self.direction = [1,0]
elif move == 2:
self.moveY = True
self.direction = [0,1]
elif move == 3:
self.moveX = True
self.moveY = True
self.direction = [1,1]
elif move == 4: #vent of gravy
self.gravyVent = True
self.clock = pygame.time.Clock()
self.springDur = 0
def Update(self):
pass
def switchImage(self, num):
filepath = "/OSGCC6/images/newplatform" + num + ".png"
imgPath = os.path.dirname(os.path.dirname( os.path.realpath( __file__ ) ) ) + filepath
self.image = pygame.image.load(imgPath)
self.sprung = not self.sprung
#if not self.sprung:
# self.mouthjump.play()
def updatePos(self):
if self.gravyVent and self.sprung:
secs = self.clock.tick() / 1000.0
self.springDur += secs
if self.springDur > 0.5:
self.switchImage("10")
self.springDur = 0.0
delta = self.moveInc
if self.currDisplacement < self.maxDisplacement:
self.currDisplacement += delta
if self.currDisplacement > self.maxDisplacement:
self.currDisplacement = self.maxDisplacement
delta = self.currDisplacement - self.maxDisplacement
self.worldPos[1] += delta * self.direction[1] * self.acceleration
self.worldPos[0] += delta * self.direction[0]
elif self.currDisplacement == self.maxDisplacement:
self.direction[1] = - self.direction[1] * self.acceleration
self.direction[0] = - self.direction[0]
self.currDisplacement = 0