Skip to content

Commit 39e7b84

Browse files
committed
Flixel level separation merged with the new Physics shapes.
1 parent 3e53c06 commit 39e7b84

18 files changed

Lines changed: 1782 additions & 208 deletions

Phaser/Phaser.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@
7676
<Content Include="core\Point.js">
7777
<DependentUpon>Point.ts</DependentUpon>
7878
</Content>
79+
<TypeScriptCompile Include="core\Polygon.ts" />
80+
<Content Include="core\Polygon.js">
81+
<DependentUpon>Polygon.ts</DependentUpon>
82+
</Content>
7983
<Content Include="core\Rectangle.js">
8084
<DependentUpon>Rectangle.ts</DependentUpon>
8185
</Content>

Phaser/components/sprite/Physics.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ module Phaser.Components {
2525

2626
this.velocity = new Vec2;
2727
this.acceleration = new Vec2;
28+
2829
this.touching = Phaser.Types.NONE;
30+
this.wasTouching = Phaser.Types.NONE;
31+
this.allowCollisions = Phaser.Types.ANY;
2932

3033
this.shape = this.game.world.physics.add(new Phaser.Physics.AABB(this.game, this._sprite, this._sprite.x, this._sprite.y, this._sprite.width, this._sprite.height));
3134

@@ -47,6 +50,7 @@ module Phaser.Components {
4750
* @type {boolean}
4851
*/
4952
public moves: bool = true;
53+
public mass: number = 1;
5054

5155
public gravity: Vec2;
5256
public drag: Vec2;
@@ -56,6 +60,8 @@ module Phaser.Components {
5660
public acceleration: Vec2;
5761

5862
public touching: number;
63+
public allowCollisions: number;
64+
public wasTouching: number;
5965

6066
public setCircle(diameter: number) {
6167

Phaser/core/Polygon.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/// <reference path="../Game.ts" />
2+
3+
/**
4+
* Phaser - Polygon
5+
*
6+
*
7+
*/
8+
9+
module Phaser {
10+
11+
export class Polygon {
12+
13+
/**
14+
*
15+
**/
16+
constructor(game: Game, points: Point[]) {
17+
18+
this.game = game;
19+
this.context = game.stage.context;
20+
21+
this.points = [];
22+
23+
for (var i = 0; i < points.length; i++)
24+
{
25+
this.points.push(new Point().copyFrom(points[i]));
26+
}
27+
28+
}
29+
30+
public points: Point[];
31+
public game: Game;
32+
public context: CanvasRenderingContext2D;
33+
34+
public render() {
35+
36+
this.context.beginPath();
37+
this.context.strokeStyle = 'rgb(255,255,0)';
38+
this.context.moveTo(this.points[0].x, this.points[0].y);
39+
40+
for (var i = 1; i < this.points.length; i++)
41+
{
42+
this.context.lineTo(this.points[i].x, this.points[i].y);
43+
}
44+
45+
this.context.lineTo(this.points[0].x, this.points[0].y);
46+
47+
this.context.stroke();
48+
this.context.closePath();
49+
50+
}
51+
52+
}
53+
54+
}

Phaser/physics/AABB.ts

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ module Phaser.Physics {
4747
public scale: Vec2;
4848
public bounds: Rectangle;
4949

50-
public oH: number;
51-
public oV: number;
52-
5350
public preUpdate() {
5451

5552
this.oldPosition.copyFrom(this.position);
@@ -88,12 +85,6 @@ module Phaser.Physics {
8885

8986
public render(context:CanvasRenderingContext2D) {
9087

91-
//context.beginPath();
92-
//context.strokeStyle = 'rgb(255,255,0)';
93-
//context.strokeRect(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
94-
//context.stroke();
95-
//context.closePath();
96-
9788
context.beginPath();
9889
context.strokeStyle = 'rgb(0,255,0)';
9990
context.strokeRect(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight, this.bounds.width, this.bounds.height);
@@ -104,7 +95,7 @@ module Phaser.Physics {
10495
context.fillStyle = 'rgb(0,255,0)';
10596
context.fillRect(this.position.x, this.position.y, 2, 2);
10697

107-
if (this.physics.touching == Phaser.Types.LEFT)
98+
if (this.physics.touching & Phaser.Types.LEFT)
10899
{
109100
context.beginPath();
110101
context.strokeStyle = 'rgb(255,0,0)';
@@ -113,7 +104,7 @@ module Phaser.Physics {
113104
context.stroke();
114105
context.closePath();
115106
}
116-
else if (this.physics.touching == Phaser.Types.RIGHT)
107+
if (this.physics.touching & Phaser.Types.RIGHT)
117108
{
118109
context.beginPath();
119110
context.strokeStyle = 'rgb(255,0,0)';
@@ -123,7 +114,7 @@ module Phaser.Physics {
123114
context.closePath();
124115
}
125116

126-
if (this.physics.touching == Phaser.Types.UP)
117+
if (this.physics.touching & Phaser.Types.UP)
127118
{
128119
context.beginPath();
129120
context.strokeStyle = 'rgb(255,0,0)';
@@ -132,7 +123,7 @@ module Phaser.Physics {
132123
context.stroke();
133124
context.closePath();
134125
}
135-
else if (this.physics.touching == Phaser.Types.DOWN)
126+
if (this.physics.touching & Phaser.Types.DOWN)
136127
{
137128
context.beginPath();
138129
context.strokeStyle = 'rgb(255,0,0)';
@@ -144,6 +135,74 @@ module Phaser.Physics {
144135

145136
}
146137

138+
public get hullWidth(): number {
139+
140+
if (this.deltaX > 0)
141+
{
142+
return this.bounds.width + this.deltaX;
143+
}
144+
else
145+
{
146+
return this.bounds.width - this.deltaX;
147+
}
148+
149+
}
150+
151+
public get hullHeight(): number {
152+
153+
if (this.deltaY > 0)
154+
{
155+
return this.bounds.height + this.deltaY;
156+
}
157+
else
158+
{
159+
return this.bounds.height - this.deltaY;
160+
}
161+
162+
}
163+
164+
public get hullX(): number {
165+
166+
if (this.position.x < this.oldPosition.x)
167+
{
168+
return this.position.x;
169+
}
170+
else
171+
{
172+
return this.oldPosition.x;
173+
}
174+
175+
}
176+
177+
public get hullY(): number {
178+
179+
if (this.position.y < this.oldPosition.y)
180+
{
181+
return this.position.y;
182+
}
183+
else
184+
{
185+
return this.oldPosition.y;
186+
}
187+
188+
}
189+
190+
public get deltaXAbs(): number {
191+
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
192+
}
193+
194+
public get deltaYAbs(): number {
195+
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
196+
}
197+
198+
public get deltaX(): number {
199+
return this.position.x - this.oldPosition.x;
200+
}
201+
202+
public get deltaY(): number {
203+
return this.position.y - this.oldPosition.y;
204+
}
205+
147206
}
148207

149208
}

Phaser/physics/Circle.ts

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ module Phaser.Physics {
4949
public bounds: Rectangle;
5050

5151
public radius: number;
52-
public oH: number;
53-
public oV: number;
5452

5553
public preUpdate() {
5654

5755
this.oldPosition.copyFrom(this.position);
5856

57+
this.bounds.x = this.position.x - this.bounds.halfWidth;
58+
this.bounds.y = this.position.y - this.bounds.halfHeight;
59+
5960
if (this.sprite)
6061
{
6162
this.position.setTo((this.sprite.x + this.bounds.halfWidth) + this.offset.x, (this.sprite.y + this.bounds.halfHeight) + this.offset.y);
@@ -74,8 +75,8 @@ module Phaser.Physics {
7475

7576
public update() {
7677

77-
this.bounds.x = this.position.x;
78-
this.bounds.y = this.position.y;
78+
//this.bounds.x = this.position.x;
79+
//this.bounds.y = this.position.y;
7980

8081
}
8182

@@ -89,15 +90,20 @@ module Phaser.Physics {
8990
public render(context:CanvasRenderingContext2D) {
9091

9192
context.beginPath();
92-
context.strokeStyle = 'rgb(0,255,0)';
93+
//context.strokeStyle = 'rgb(255,255,0)';
94+
//context.strokeRect(this.position.x - this.bounds.halfWidth, this.position.y - this.bounds.halfHeight, this.bounds.width, this.bounds.height);
95+
//context.fillStyle = 'rgba(0,0,255,0.8)';
96+
context.strokeStyle = 'rgba(0,0,255,0.5)';
9397
context.arc(this.position.x, this.position.y, this.radius, 0, Math.PI * 2);
98+
//context.fill();
9499
context.stroke();
95100
context.closePath();
96101

97102
// center point
98-
context.fillStyle = 'rgb(0,255,0)';
103+
context.fillStyle = 'rgb(255,255,0)';
99104
context.fillRect(this.position.x, this.position.y, 2, 2);
100105

106+
/*
101107
if (this.oH == 1)
102108
{
103109
context.beginPath();
@@ -135,9 +141,79 @@ module Phaser.Physics {
135141
context.stroke();
136142
context.closePath();
137143
}
144+
*/
145+
146+
}
147+
148+
public get hullWidth(): number {
149+
150+
if (this.deltaX > 0)
151+
{
152+
return this.bounds.width + this.deltaX;
153+
}
154+
else
155+
{
156+
return this.bounds.width - this.deltaX;
157+
}
158+
159+
}
160+
161+
public get hullHeight(): number {
162+
163+
if (this.deltaY > 0)
164+
{
165+
return this.bounds.height + this.deltaY;
166+
}
167+
else
168+
{
169+
return this.bounds.height - this.deltaY;
170+
}
171+
172+
}
173+
174+
public get hullX(): number {
175+
176+
if (this.position.x < this.oldPosition.x)
177+
{
178+
return this.position.x;
179+
}
180+
else
181+
{
182+
return this.oldPosition.x;
183+
}
138184

139185
}
140186

187+
public get hullY(): number {
188+
189+
if (this.position.y < this.oldPosition.y)
190+
{
191+
return this.position.y;
192+
}
193+
else
194+
{
195+
return this.oldPosition.y;
196+
}
197+
198+
}
199+
200+
public get deltaXAbs(): number {
201+
return (this.deltaX > 0 ? this.deltaX : -this.deltaX);
202+
}
203+
204+
public get deltaYAbs(): number {
205+
return (this.deltaY > 0 ? this.deltaY : -this.deltaY);
206+
}
207+
208+
public get deltaX(): number {
209+
return this.position.x - this.oldPosition.x;
210+
}
211+
212+
public get deltaY(): number {
213+
return this.position.y - this.oldPosition.y;
214+
}
215+
216+
141217
}
142218

143219
}

Phaser/physics/IPhysicsShape.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,23 @@ module Phaser.Physics {
2020
offset: Vec2;
2121

2222
bounds: Rectangle;
23-
oH: number;
24-
oV: number;
23+
//oH: number;
24+
//oV: number;
2525

2626
setSize(width: number, height: number);
2727
preUpdate();
2828
update();
2929
render(context:CanvasRenderingContext2D);
3030

31+
hullX;
32+
hullY;
33+
hullWidth;
34+
hullHeight;
35+
deltaX;
36+
deltaY;
37+
deltaXAbs;
38+
deltaYAbs;
39+
3140
}
3241

3342
}

0 commit comments

Comments
 (0)