-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.js
83 lines (76 loc) · 1.98 KB
/
game.js
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
"use strict";
var keyState = {};
window.addEventListener('keydown',function(e){keyState[e.keyCode || e.which] = true;},true);
window.addEventListener('keyup',function(e){keyState[e.keyCode || e.which] = false;},true);
class world {
constructor(ctx)
{
this.ctx = document.getElementById(ctx).getContext('2d')
this.element = document.getElementById(ctx)
this.objects = []
}
addObject(newObject){
this.objects.push(newObject)
return this.objects.length-1
}
drawObjects(){
this.clear()
for (var objIndex = 0; objIndex < this.objects.length; objIndex ++) {
this.objects[objIndex].draw(this.ctx,this.objects[objIndex])
console.log(this.objects[objIndex].color)
console.log(objIndex)
}
}
clear() {
this.element.getContext('2d').clearRect(0, 0, this.element.width, this.element.height)
}
start(){
}
}
class object {
constructor(x,y,width,height,color,outline) {
this.x = x
this.y = y
this.width = width
this.height = height
this.color = typeof color !== 'undefined' ? color : "#FFFFFF";
}
draw(ctx,obj) {
ctx.fillStyle=obj.color
ctx.strokeStyle="#000000"
ctx.lineWidth = 2;
ctx.rect(obj.x, obj.y, obj.width, obj.height)
ctx.fill()
ctx.stroke()
}
}
class player extends object {
constructor(x,y,width,height,name,color,outline) {
super(x,y,width,height,color,outline)
this.image
this.name
this.score
this.velX
this.velY
}
}
class client extends player {
constructor(x,y,width,height,name,color,outline) {
super(x,y,width,height,name,color,outline)
}
}
var game
var obj
var cln
var timer
function main()
{
game = new world("game")
game.start()
game.addObject(new client (0,0,30,30,'Player','#5CD3FA','#000000'))
game.addObject(new object (250,50,60,30,'#444444','#000000'))
game.drawObjects(game)
console.log("-------")
game.objects[0].x = 30
game.drawObjects(game)
}