-
Notifications
You must be signed in to change notification settings - Fork 2
/
level1.js
99 lines (76 loc) · 2.42 KB
/
level1.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
var to_be_destroyed;
var embox2dTest_level1 = function() {
//constructor
}
embox2dTest_level1.prototype.setNiceViewCenter = function() {
//called once when the user changes to this test from another test
PTM = 30;
setViewCenterWorld( new b2Vec2(0,0), true );
}
embox2dTest_level1.prototype.setup = function() {
//set up the Box2D scene here - the world is already created
//vector = new b2Vec2(0,0);
//setting static bodies
{
fixture.set_density(1);
fixture.set_restitution(0.5);
fixture.set_friction(0.3);
body.set_type(b2_staticBody);
body.set_position(new b2Vec2(0,0));
body.set_angle(0.0);
var ground = world.CreateBody(body);
shape.SetAsBox(2.5,0.2,new b2Vec2(-15,0),0);
fixture.set_shape(shape);
ground.CreateFixture(fixture);
shape.SetAsBox(5,0.5,new b2Vec2(-10,-10),0);
fixture.set_shape(shape);
ground.CreateFixture(fixture);
shape.SetAsBox(0.1,2,new b2Vec2(18,-8),0);
fixture.set_shape(shape);
ground.CreateFixture(fixture);
shape.SetAsBox(2,0.1,new b2Vec2(16,-8),0);
fixture.set_shape(shape);
ground.CreateFixture(fixture);
ground.userData = {};
ground.userData.color='#89BFC9';
}
body.set_type(b2_dynamicBody);
body.set_position(new b2Vec2(-15,1));
fixture.set_restitution(0.5);
fixture.set_friction(0.3);
circleShape.set_m_radius(1);
var ballBody =world.CreateBody(body);
fixture.set_shape(circleShape);
fixture.set_density(0.1);
ballBody.CreateFixture(fixture);
ballBody.userData = {};
ballBody.userData.color = 'rgba(192,57,43,0.8)';
ballBody.userData.id = 'ball';
body.set_type(b2_dynamicBody);
body.set_position(new b2Vec2(17,-7.5));
fixture.set_shape(circleShape);
fixture.set_density(0.2);
circleShape.set_m_radius(0.5);
ballBody = world.CreateBody(body);
ballBody.userData = {};
ballBody.userData.color = 'rgb(237,173,21)';
ballBody.userData.id = 'star';
ballBody.CreateFixture(fixture);
fixture.set_density(10);
fixture.set_restitution(0.2);
fixture.set_friction(0.6);
}
embox2dTest_level1.prototype.step = function() {
//this function will be called at the beginning of every time step
if(to_be_destroyed){
var body_reference = Box2D.wrapPointer(to_be_destroyed);
world.DestroyBody(body_reference);
//window.cancelAnimationFrame(requestId,5000);
body_reference == null;
//context.globalAlpha =0.5;
to_be_destroyed = null;
level=1;
$("#transition").css("zIndex",1);
//resetScene();
}
}