-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
123 lines (98 loc) · 5.47 KB
/
process.py
File metadata and controls
123 lines (98 loc) · 5.47 KB
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
### ====================================================================================================
### IMPORTS
### ====================================================================================================
import arcade
from utils import *
class Process:
### ====================================================================================================
### PARAMETERS
### ====================================================================================================
SCREEN_WIDTH = int(1920*0.75)
SCREEN_HEIGHT = int(1080*0.75)
### ====================================================================================================
### CONSTRUCTOR
### ====================================================================================================
def __init__(self):
pass
### ====================================================================================================
### INIT
### ====================================================================================================
def setup(self):
params = {
"filePath" : "images/codingFactory/cf_background.png",
"size" : (self.SCREEN_WIDTH, self.SCREEN_HEIGHT),
"filterColor": (255,255,255,128),
"position" : (self.SCREEN_WIDTH//2, self.SCREEN_HEIGHT//2)
}
self.background = createFixedSprite(params)
params = {
"filePath" : "images/codingFactory/cf.png",
"filterColor": (255,255,255,160),
"position" : (self.SCREEN_WIDTH//2, self.SCREEN_HEIGHT//2)
}
self.logo = createFixedSprite(params)
self.speedX = random()*5 + 5
self.speedY = random()*5 + 5
### ====================================================================================================
### UPDATE
### ====================================================================================================
def update(self,deltaTime):
self.logo.center_x += self.speedX * deltaTime * 60
self.logo.center_y += self.speedY * deltaTime * 60
if(self.logo.center_x < 0 or self.logo.center_x >= self.SCREEN_WIDTH):
self.speedX = -self.speedX
if(self.logo.center_y < 0 or self.logo.center_y >= self.SCREEN_HEIGHT):
self.speedY = -self.speedY
### ====================================================================================================
### RENDERING
### ====================================================================================================
def draw(self):
self.background.draw()
self.logo.draw()
message = "Are you ready to code ?"
paramTxt = {"x": 3*self.SCREEN_WIDTH//4,
"y": 60,
"alignH": "center",
"alignV": "center",
"message": message,
"size": 50,
"color": (255, 255, 255, 128),
}
drawText(paramTxt)
### ====================================================================================================
### KEYBOARD EVENTS
### key is taken from : arcade.key.xxx
### ====================================================================================================
def onKeyEvent(self,key,isPressed):
print(f"key={key} - isPressed={isPressed}")
### ====================================================================================================
### GAMEPAD BUTTON EVENTS
### buttonName can be "A", "B", "X", "Y", "LB", "RB", "VIEW", "MENU", "LSTICK", "RSTICK"
### ====================================================================================================
def onButtonEvent(self, gamepadNum,buttonName,isPressed):
print(f"GamePad={gamepadNum} - ButtonNum={buttonName} - isPressed={isPressed}")
### ====================================================================================================
### GAMEPAD AXIS EVENTS
### axisName can be "X", "Y", "RX", "RY", "Z"
### ====================================================================================================
def onAxisEvent(self, gamepadNum,axisName,analogValue):
print(f"GamePad={gamepadNum} - AxisName={axisName} - Value={analogValue}")
### ====================================================================================================
### MOUSE MOTION EVENTS
### ====================================================================================================
def onMouseMotionEvent(self,x,y,dx,dy):
print(f"MOUSE MOTION : x={x}/y={y} dx={dx}/dy={dy}")
### ====================================================================================================
### MOUSE BUTTON EVENTS
### ====================================================================================================
def onMouseButtonEvent(self,x,y,buttonNum,isPressed):
#print(f"MOUSE BUTTON : x={x}/y={y} buttonNum={buttonNum} isPressed={isPressed}")
if abs(self.logo.center_x - x) < self.logo.width//2.2:
if abs(self.logo.center_y - y) < self.logo.height // 2.2:
if isPressed:
if abs(self.speedX) < 1 and abs(self.speedY) < 1:
self.speedX *= 20
self.speedY *= 20
else:
self.speedX /= 20
self.speedY /= 20