-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestGameObjectHierarchy.html
More file actions
118 lines (95 loc) · 4.09 KB
/
Copy pathtestGameObjectHierarchy.html
File metadata and controls
118 lines (95 loc) · 4.09 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
<!-- 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 Game Object Hierarchy</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/SceneManager.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 src="./engine/components/RigidBody.js"></script>
<script>
const square = [new Vector2(-50, -50), new Vector2(-50, 50), new Vector2(50, 50), new Vector2(50, -50)]
class MainScene extends Scene {
constructor() {
super()
const text = this.instantiate(new GameObject("Text"), new Vector2(100, 100))
text.addComponent(new TextLabel(), {text: "Level 1"})
const text2 = this.instantiate(new GameObject("Text2"), new Vector2(100, 100))
text2.addComponent(new TextLabel(), {text: "Sub Text"})
text2.transform.setParent(text.transform)
text.addComponent(new Level1Controller())
const parentPolygon = this.instantiate(new GameObject("Parent"), new Vector2(0, 0))
parentPolygon.transform.scale = new Vector2(1, 1)
parentPolygon.addComponent(new Polygon(), {points: square})
parentPolygon.addComponent(new KeyboardController())
const childPolygon = this.instantiate(new GameObject("Child"), new Vector2(250, 200))
childPolygon.addComponent(new Polygon(), {points: square, fillStyle: "blue", strokeStyle: "red"})
childPolygon.addComponent(new Collider())
childPolygon.addComponent(new RigidBody())
childPolygon.addComponent(new CollisionResponse())
childPolygon.transform.setParent(parentPolygon.transform)
const grandchildPolygon = this.instantiate(new GameObject("Grandchild"), new Vector2(-200, -200))
grandchildPolygon.addComponent(new Polygon, {points: square, fillStyle: "green"})
grandchildPolygon.addComponent(new Collider())
grandchildPolygon.addComponent(new RigidBody())
grandchildPolygon.addComponent(new CollisionResponse())
grandchildPolygon.transform.setParent(childPolygon.transform)
const targetPolygon = this.instantiate(new GameObject("Target"), new Vector2(400, 400))
targetPolygon.addComponent(new Polygon(), {points: square, fillStyle: "red"})
targetPolygon.addComponent(new Collider())
}
}
class Level1Controller extends Component{
start(){
this.sceneStart = Time.time
}
update(){
}
}
class CollisionResponse extends Component{
update(){
// this.transform.rotation += Time.deltaTime
this.transform.scale = new Vector2(10,1)
}
onCollisionEnter(){
console.log("Collision Enter")
}
onMouseOver(){
console.log("On Mouse Over")
}
}
class KeyboardController extends Component{
fixedUpdate(){
const offset = new Vector2(0,0)
if(Input.keysDown.includes("ArrowLeft")) offset.plusEquals(new Vector2(-1, 0))
if(Input.keysDown.includes("ArrowRight")) offset.plusEquals(new Vector2(1, 0))
if(Input.keysDown.includes("ArrowUp")) offset.plusEquals(new Vector2(0, -1))
if(Input.keysDown.includes("ArrowDown")) offset.plusEquals(new Vector2(0, 1))
this.transform.position.plusEquals(offset.times(100 * Time.deltaTime))
}
}
SceneManager.currentScene = new MainScene()
Engine.start()
</script>
</body>
</html>