-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestEvent.html
More file actions
111 lines (87 loc) · 3.04 KB
/
testEvent.html
File metadata and controls
111 lines (87 loc) · 3.04 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
<!-- Please carefully review the rules about academic integrity found in the academicIntegrity.md file found at the root of this project. -->
<!doctype html>
<html>
<head>
<title>Test Events</title>
<style>
/* Engine-Specific */
* {
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<canvas id="canv"></canvas>
<script src="./engine/Engine.js"></script>
<script src="./engine/Scene.js"></script>
<script src="./engine/GameObject.js"></script>
<script src="./engine/Component.js"></script>
<script src="./engine/Input.js"></script>
<script src="./engine/Vector2.js"></script>
<script src="./engine/Time.js"></script>
<script src="./engine/Collisions.js"></script>
<script src="./engine/Events.js"></script>
<script src="./engine/components/Transform.js"></script>
<script src="./engine/components/TextLabel.js"></script>
<script src="./engine/components/Polygon.js"></script>
<script src="./engine/components/Collider.js"></script>
<script>
class MainScene extends Scene {
constructor() {
super()
const button1GameObject = this.instantiate(new ButtonGameObject(), new Vector2(200, 100))
const button2GameObject = this.instantiate(new ButtonGameObject(), new Vector2(200, 300))
button1GameObject.addComponent(new Button1Controller())
button2GameObject.addComponent(new Button2Controller())
const controllerGameObject = this.instantiate(new GameObject("Controller Game Object"), new Vector2(500, 200))
controllerGameObject.addComponent(new TextLabel())
controllerGameObject.addComponent(new Controller())
}
}
class ButtonGameObject extends GameObject{
constructor(){
super("Button Game Object")
this.addComponent(new Polygon(), {points: [new Vector2(-100, -50), new Vector2(-100, 50), new Vector2(100, 50), new Vector2(100, -50)], fillStyle: "cyan"})
this.addComponent(new TextLabel(), {text: "Button"})
this.addComponent(new Collider())
}
}
class Button1Controller extends Component{
start(){
this.gameObject.getComponent(TextLabel).text = "Button 1"
}
update(){
}
onMouseUpAsButton(){
Events.handleEvent("button1", [])
}
}
class Button2Controller extends Component{
start(){
this.gameObject.getComponent(TextLabel).text = "Button 2"
this.gameObject.getComponent(Polygon).fillStyle = "pink"
}
update(){
}
onMouseUpAsButton(){
Events.handleEvent("button2", [])
}
}
class Controller extends Component{
start(){
this.gameObject.getComponent(TextLabel).text = "Waiting for events"
Events.registerListener("button1", this)
Events.registerListener("button2", this)
}
update(){
}
handleEvent(message, args){
this.gameObject.getComponent(TextLabel).text = message
}
}
Engine.currentScene = new MainScene()
Engine.start()
</script>
</body>
</html>