-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestInputEvents.html
More file actions
89 lines (70 loc) · 4.1 KB
/
testInputEvents.html
File metadata and controls
89 lines (70 loc) · 4.1 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
<!-- 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 Input 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/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()
//Static text at the top
this.instantiate(new GameObject("Title Text"), new Vector2(20, 20)).addComponent(new TextLabel(), { text: "Test Input Events - Push keyboard keys, move the mouse, and mouse down to test events", fillStyle: "Red"})
//The dynamic text
this.instantiate(new GameObject("Keys Down Text"), new Vector2(20, 60)).addComponent(new TextLabel())
this.instantiate(new GameObject("Keys Down This Frame Text"), new Vector2(20, 100)).addComponent(new TextLabel())
this.instantiate(new GameObject("Keys Up This Frame Text"), new Vector2(20, 140)).addComponent(new TextLabel())
this.instantiate(new GameObject("Mouse Position Text"), new Vector2(20, 180)).addComponent(new TextLabel())
this.instantiate(new GameObject("Mouse Position Last Frame Text"), new Vector2(20, 220)).addComponent(new TextLabel())
this.instantiate(new GameObject("Mouse Position Delta Text"), new Vector2(20, 260)).addComponent(new TextLabel())
this.instantiate(new GameObject("Mouse Buttons Down Text"), new Vector2(20, 300)).addComponent(new TextLabel())
this.instantiate(new GameObject("Mouse Buttons Down This Frame Text"), new Vector2(20, 340)).addComponent(new TextLabel())
this.instantiate(new GameObject("Mouse Buttons Up This Text"), new Vector2(20, 380)).addComponent(new TextLabel())
//The invisible controller
this.instantiate(new GameObject("Controller")).addComponent(new Controller())
}
}
class Controller extends Component {
update() {
//Keys Down
GameObject.find("Keys Down Text").getComponent(TextLabel).text = "Keys Down: " + Input.keysDown
GameObject.find("Keys Down This Frame Text").getComponent(TextLabel).text = "Keys Down This Frame: " + Input.keysDownThisFrame
GameObject.find("Keys Up This Frame Text").getComponent(TextLabel).text = "Keys Up This Frame: " + Input.keysUpThisFrame
//Mouse Position
if (Input.mousePosition)
GameObject.find("Mouse Position Text").getComponent(TextLabel).text = "Mouse Position: " + Input.mousePosition.x + ", " + Input.mousePosition.y
if (Input.mousePositionLastFrame)
GameObject.find("Mouse Position Last Frame Text").getComponent(TextLabel).text = "Mouse Position Last Frame: " + Input.mousePositionLastFrame.x + ", " + Input.mousePositionLastFrame.y
if (Input.mousePositionDelta)
GameObject.find("Mouse Position Delta Text").getComponent(TextLabel).text = "Mouse Position Delta: " + Input.mousePositionDelta.x + ", " + Input.mousePositionDelta.y
//Mouse Buttons Down
GameObject.find("Mouse Buttons Down Text").getComponent(TextLabel).text = "Mouse Buttons Down: " + Input.mouseButtonsDown
GameObject.find("Mouse Buttons Down This Frame Text").getComponent(TextLabel).text = "Mouse Buttons This Frame Down: " + Input.mouseButtonsDownThisFrame
GameObject.find("Mouse Buttons Up This Text").getComponent(TextLabel).text = "Mouse Buttons Up This Frame: " + Input.mouseButtonsUpThisFrame
}
}
Engine.currentScene = new MainScene()
Engine.start()
</script>
</body>
</html>