-
Notifications
You must be signed in to change notification settings - Fork 1
/
workingAnimCycle.txt
156 lines (111 loc) · 5 KB
/
workingAnimCycle.txt
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import Levels
from PPlay.sprite import *
from PPlay.gameobject import *
from GameWindow import GameWindow
from Levels import *
from Input import *
import pygame
import Game
class Player:
direction = 2 #2 means right, 1 means left
standing = True
still = True
sprite = Sprite("sprites/player/right/julius-idle1-right.png", 15)
sprite.set_sequence_time(0, 14, 80, True)
sprite.set_position(200, 490)
walkSpeed = 200
@staticmethod
def spawnJulius():
Player.sprite.draw()
Player.sprite.update()
#Julius.setGravity()
#Julius.sprite.mask.scale((800, 900))
@staticmethod
def controlJulius(Level):
"""if(Input.getKeyDown("d")):
Player.direction = 2
if(Input.getKeyDown(("a"))):
Player.direction = 1"""
if(GameWindow.window.keyboard.key_pressed("d")):
Player.direction = 2
Player.still = False
elif(GameWindow.window.keyboard.key_pressed("a")):
Player.direction = 1
Player.still = False
else:
Player.still = True
if(Player.still and Player.standing and Player.direction == 2):
JuliusAnim.anims["idle1_right"] = True
#JuliusAnim.idle1_right = False
elif(Player.still and Player.standing and Player.direction == 1):
JuliusAnim.anims["idle1_left"] = True
#JuliusAnim.idle1_left = False
elif(not Player.still and Player.standing and Player.direction == 2):
JuliusAnim.anims["walk_right"] = True
elif(not Player.still and Player.standing and Player.direction == 1):
JuliusAnim.anims["walk_left"] = True
JuliusAnim.timeElapsed += GameWindow.window.delta_time()
if(not Player.still and Player.direction == 2):
if(Player.sprite.x < Level.scrollingLimit or Level.reachedLimitRight):
Player.sprite.x += Player.walkSpeed * GameWindow.window.delta_time()
elif(not Player.still and Player.direction == 1):
if(Player.sprite.x > Level.scrollingLimit or Level.reachedLimitLeft):
Player.sprite.x -= Player.walkSpeed * GameWindow.window.delta_time()
JuliusAnim.setAnims()
@staticmethod
def setGravity():
if(not pygame.sprite.collide_mask(Level1area1.tiles, Player.sprite)):
Player.sprite.y += 200 * GameWindow.window.delta_time()
class JuliusAnim():
anims = {
"idle1_right": False,
"idle1_right_animChanged": False,
"idle1_left": False,
"idle1_left_animChanged": False,
"walk_right": False,
"walk_right_animChanged": False,
"walk_left": False,
"walk_left_animChanged": False
}
timeElapsed = 0
currentX = 0
currentY = 0
@staticmethod
def changeAnim():
pass
@staticmethod
def setAnims():
currentX = Player.sprite.x
currentY = Player.sprite.y
if(JuliusAnim.anims["idle1_right"] and not JuliusAnim.anims["idle1_right_animChanged"]):
"""Player.sprite = Sprite("sprites/player/right/julius-idle1-right.png", 15)
Player.sprite.set_sequence_time(0, 14, 80, True)
Player.sprite.set_position(currentX, currentY)
JuliusAnim.idle1_right_animChanged = True
JuliusAnim.idle1_right = False
JuliusAnim.idle1_left_animChanged = False
JuliusAnim.walk_right_animChanged = False
JuliusAnim.walk_left_animChanged = False"""
JuliusAnim.changeAnimation("idle1_right", "sprites/player/right/julius-idle1-right.png", 15, 80)
elif(JuliusAnim.anims["idle1_left"] and not JuliusAnim.anims["idle1_left_animChanged"]):
JuliusAnim.changeAnimation("idle1_left", "sprites/player/left/julius-idle1-left.png", 15, 80)
elif(JuliusAnim.anims["walk_right"] and not JuliusAnim.anims["walk_right_animChanged"]):
JuliusAnim.changeAnimation("walk_right", "sprites/player/right/julius-walk-right.png", 16, 40)
elif (JuliusAnim.anims["walk_left"] and not JuliusAnim.anims["walk_left_animChanged"]):
#Player.sprite = Sprite("sprites/player/left/julius-walkstart-left.png", 5)
#Player.sprite.set_sequence_time(0, 4, 80, False)
#Player.sprite.set_position(currentX, currentY)
#if(JuliusAnim.timeElapsed >= 1):
JuliusAnim.changeAnimation("walk_left", "sprites/player/left/julius-walk-left.png", 16, 40)
@staticmethod
def changeAnimation(animation, sprite, maxFrames, animTime):
currentX = Player.sprite.x
currentY = Player.sprite.y
Player.sprite = Sprite(sprite, maxFrames)
Player.sprite.set_sequence_time(0, maxFrames - 1, animTime, True)
Player.sprite.set_position(currentX, currentY)
JuliusAnim.anims[animation + "_animChanged"] = True
JuliusAnim.anims[animation] = False
for anim in JuliusAnim.anims:
if(anim != animation + "_animChanged"):
JuliusAnim.anims[anim] = False