-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_world.js
121 lines (97 loc) · 2.65 KB
/
_world.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
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
/// <reference path="lib/jquery-1.7.1.js" />
/// <reference path="_eGravity.js" />
World = {
settings: {
width: 0,
height: 0,
gravity: 0,
hasColision: true
},
title: '',
context: null,
Elements: {
ball: null,
bricks: null,
plataform: null,
mensagens: null
},
load: function (context) {
if (context) World.context = context[0].getContext('2d');
World.settings.width = context.width();
World.settings.height = context.height();
World.settings.gravity = eGravity.TERRA;
},
update: function () {
World.Elements.ball.update();
World.Elements.plataform.update();
$(World.Elements.bricks).each(function () {
if (World.collision(World.Elements.ball, this)) {
this.update(World.Elements.ball);
World.Elements.ball.update(this);
} else {
this.update();
}
});
if (World.collision(World.Elements.ball, World.Elements.plataform)) {
World.Elements.ball.update(World.Elements.plataform);
World.Elements.plataform.update(World.Elements.ball);
}
Game.settings.velocity = World.Elements.bricks.length / 7;
},
collision: function (objeto1, objeto2) {
//Define os pontos corners dos objetos
left1 = objeto1.x;
left2 = objeto2.x;
right1 = objeto1.x + objeto1.settings.width;
right2 = objeto2.x + objeto2.settings.width;
top1 = objeto1.y;
top2 = objeto2.y;
bottom1 = objeto1.y + objeto1.settings.height;
bottom2 = objeto2.y + objeto2.settings.height;
/*Teste de rejeição para colisão de polígonos circundantes*/
if (bottom1 < top2) return false;
if (top1 > bottom2) return false;
if (right1 < left2) return false;
if (left1 > right2) return false;
console.log(objeto1.name + ' colidiu com ' + objeto2.name+' >> QTD TIJOLOS: '+(World.Elements.bricks.length - 1));
return World.settings.hasColision;
},
draw: function () {
World.clear();
World.Elements.plataform.draw(World.context);
$(World.Elements.bricks).each(function () {
if (this.draw) {
this.draw(World.context);
}
});
World.Elements.ball.draw(World.context);
World.Elements.mensagens.draw(World.context);
},
clear: function () {
World.context.clearRect(0, 0, World.settings.width, World.settings.height);
},
addElements: function (ball, bricks, plataform, mensagens) {
World.Elements.ball = ball;
World.Elements.bricks = bricks;
World.Elements.plataform = plataform;
World.Elements.mensagens = mensagens;
}
}
Model = function () {
this.UID = 0;
this.name = 'unknown';
this.image = null;
this.x = 0;
this.y = 0;
this.dx = 0;
this.dy = 0;
this.color = null;
this.draw = null; //functions
this.update = null; //functions
this.settings = {
movable: false,
width: 0,
height: 0,
weight: 0
};
}