Skip to content

Commit 03b7467

Browse files
committed
Tidying up before putting back together again
1 parent 4cef0d1 commit 03b7467

12 files changed

Lines changed: 606 additions & 235 deletions

File tree

Phaser/RenderManager.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Interface
2+
interface IPoint {
3+
getDist(): number;
4+
}
5+
6+
// Module
7+
module Shapes {
8+
9+
// Class
10+
export class Point implements IPoint {
11+
// Constructor
12+
constructor (public x: number, public y: number) { }
13+
14+
// Instance member
15+
getDist() { return Math.sqrt(this.x * this.x + this.y * this.y); }
16+
17+
// Static member
18+
static origin = new Point(0, 0);
19+
}
20+
21+
}
22+
23+
// Local variables
24+
var p: IPoint = new Shapes.Point(3, 4);
25+
var dist = p.getDist();

Phaser/cameras/Camera.ts

Lines changed: 18 additions & 133 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/// <reference path="../core/Point.ts" />
2+
/// <reference path="../core/Rectangle.ts" />
3+
/// <reference path="../core/Vec2.ts" />
14
/// <reference path="../gameobjects/Sprite.ts" />
25
/// <reference path="../Game.ts" />
36

@@ -89,23 +92,17 @@ module Phaser {
8992
*/
9093
public worldView: Rectangle;
9194

92-
/**
93-
* How many sprites will be rendered by this camera.
94-
* @type {number}
95-
*/
96-
public totalSpritesRendered: number;
97-
9895
/**
9996
* Scale factor of the camera.
100-
* @type {MicroPoint}
97+
* @type {Vec2}
10198
*/
102-
public scale: MicroPoint = new MicroPoint(1, 1);
99+
public scale: Vec2 = new Vec2(1, 1);
103100

104101
/**
105102
* Scrolling factor.
106103
* @type {MicroPoint}
107104
*/
108-
public scroll: MicroPoint = new MicroPoint(0, 0);
105+
public scroll: Vec2 = new Vec2(0, 0);
109106

110107
/**
111108
* Camera bounds.
@@ -119,79 +116,27 @@ module Phaser {
119116
*/
120117
public deadzone: Rectangle = null;
121118

122-
// Camera Border
123-
public disableClipping: bool = false;
124-
125-
/**
126-
* Whether render border of this camera or not. (default is false)
127-
* @type {boolean}
128-
*/
129-
public showBorder: bool = false;
130-
131119
/**
132-
* Color of border of this camera. (in css color string)
133-
* @type {string}
120+
* Disable the automatic camera canvas clipping when Camera is non-Stage sized.
121+
* @type {Boolean}
134122
*/
135-
public borderColor: string = 'rgb(255,255,255)';
123+
public disableClipping: bool = false;
136124

137125
/**
138126
* Whether the camera background is opaque or not. If set to true the Camera is filled with
139-
* the value of Camera.backgroundColor every frame.
127+
* the value of Camera.backgroundColor every frame. Normally you wouldn't enable this if the
128+
* Camera is the full Stage size, as the Stage.backgroundColor has the same effect. But for
129+
* multiple or mini cameras it can be very useful.
140130
* @type {boolean}
141131
*/
142132
public opaque: bool = false;
143133

144134
/**
145-
* Clears the camera every frame using a canvas clearRect call (default to true).
146-
* Note that this erases anything below the camera as well, so do not use it in conjuction with a camera
147-
* that uses alpha or that needs to be able to manage opacity. Equally if Camera.opaque is set to true
148-
* then set Camera.clear to false to save rendering time.
149-
* By default the Stage will clear itself every frame, so be sure not to double-up clear calls.
150-
* @type {boolean}
151-
*/
152-
public clear: bool = false;
153-
154-
/**
155-
* Background color in css color string.
135+
* The Background Color of the camera in css color string format, i.e. 'rgb(0,0,0)' or '#ff0000'.
136+
* Not used if the Camera.opaque property is false.
156137
* @type {string}
157138
*/
158-
private _bgColor: string = 'rgb(0,0,0)';
159-
160-
/**
161-
* Background texture to be rendered if background is visible.
162-
*/
163-
private _bgTexture;
164-
165-
/**
166-
* Background texture repeat style. (default is 'repeat')
167-
* @type {string}
168-
*/
169-
private _bgTextureRepeat: string = 'repeat';
170-
171-
// Camera Shadow
172-
/**
173-
* Render camera shadow or not. (default is false)
174-
* @type {boolean}
175-
*/
176-
public showShadow: bool = false;
177-
178-
/**
179-
* Color of shadow, in css color string.
180-
* @type {string}
181-
*/
182-
public shadowColor: string = 'rgb(0,0,0)';
183-
184-
/**
185-
* Blur factor of shadow.
186-
* @type {number}
187-
*/
188-
public shadowBlur: number = 10;
189-
190-
/**
191-
* Offset of the shadow from camera's position.
192-
* @type {MicroPoint}
193-
*/
194-
public shadowOffset: MicroPoint = new MicroPoint(4, 4);
139+
public backgroundColor: string = 'rgb(0,0,0)';
195140

196141
/**
197142
* Whether this camera visible or not. (default is true)
@@ -418,15 +363,6 @@ module Phaser {
418363
this._sx = this._stageX;
419364
this._sy = this._stageY;
420365

421-
// Shadow
422-
if (this.showShadow == true)
423-
{
424-
this._game.stage.context.shadowColor = this.shadowColor;
425-
this._game.stage.context.shadowBlur = this.shadowBlur;
426-
this._game.stage.context.shadowOffsetX = this.shadowOffset.x;
427-
this._game.stage.context.shadowOffsetY = this.shadowOffset.y;
428-
}
429-
430366
// Scale on
431367
if (this.scale.x !== 1 || this.scale.y !== 1)
432368
{
@@ -445,32 +381,11 @@ module Phaser {
445381
this._game.stage.context.translate(-(this._sx + this.worldView.halfWidth), -(this._sy + this.worldView.halfHeight));
446382
}
447383

448-
if (this.clear == true)
449-
{
450-
this._game.stage.context.clearRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
451-
}
452-
453384
// Background
454-
if (this.opaque == true)
385+
if (this.opaque)
455386
{
456-
if (this._bgTexture)
457-
{
458-
this._game.stage.context.fillStyle = this._bgTexture;
459-
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
460-
}
461-
else
462-
{
463-
this._game.stage.context.fillStyle = this._bgColor;
464-
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
465-
}
466-
}
467-
468-
// Shadow off
469-
if (this.showShadow == true)
470-
{
471-
this._game.stage.context.shadowBlur = 0;
472-
this._game.stage.context.shadowOffsetX = 0;
473-
this._game.stage.context.shadowOffsetY = 0;
387+
this._game.stage.context.fillStyle = this.backgroundColor;
388+
this._game.stage.context.fillRect(this._sx, this._sy, this.worldView.width, this.worldView.height);
474389
}
475390

476391
this.fx.render(this, this._stageX, this._stageY, this.worldView.width, this.worldView.height);
@@ -487,14 +402,6 @@ module Phaser {
487402
// Render all the Sprites
488403
this._game.world.group.render(this, this._sx, this._sy);
489404

490-
if (this.showBorder == true)
491-
{
492-
this._game.stage.context.strokeStyle = this.borderColor;
493-
this._game.stage.context.lineWidth = 1;
494-
this._game.stage.context.rect(this._sx, this._sy, this.worldView.width, this.worldView.height);
495-
this._game.stage.context.stroke();
496-
}
497-
498405
// Scale off
499406
if (this.scale.x !== 1 || this.scale.y !== 1)
500407
{
@@ -520,28 +427,6 @@ module Phaser {
520427

521428
}
522429

523-
public set backgroundColor(color: string) {
524-
525-
this._bgColor = color;
526-
527-
}
528-
529-
public get backgroundColor(): string {
530-
return this._bgColor;
531-
}
532-
533-
/**
534-
* Set camera background texture.
535-
* @param key {string} Asset key of the texture.
536-
* @param [repeat] {string} what kind of repeat will this texture used for background.
537-
*/
538-
public setTexture(key: string, repeat?: string = 'repeat') {
539-
540-
this._bgTexture = this._game.stage.context.createPattern(this._game.cache.getImage(key), repeat);
541-
this._bgTextureRepeat = repeat;
542-
543-
}
544-
545430
/**
546431
* Set position of this camera.
547432
* @param x {number} X position.
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/**
2+
* Phaser - Components - Physics
3+
*
4+
*
5+
*/
6+
7+
module Phaser.Components {
8+
9+
export class Physics {
10+
11+
/**
12+
* Whether this object will be moved by impacts with other objects or not.
13+
* @type {boolean}
14+
*/
15+
public immovable: bool;
16+
17+
/**
18+
* Basic speed of this object.
19+
*
20+
* Velocity is given in pixels per second. Therefore a velocity of
21+
* 100 will move at a rate of 100 pixels every 1000 ms (1sec). It's not balls-on
22+
* accurate due to the way timers work, but it's pretty close. Expect tolerance
23+
* of +- 10 px. Also that speed assumes no drag.
24+
*
25+
* @type {MicroPoint}
26+
*/
27+
public velocity: MicroPoint;
28+
29+
/**
30+
* The virtual mass of the object.
31+
* @type {number}
32+
*/
33+
public mass: number;
34+
35+
/**
36+
* The bounciness of the object.
37+
* @type {number}
38+
*/
39+
public elasticity: number;
40+
41+
/**
42+
* How fast the speed of this object is changing.
43+
* @type {number}
44+
*/
45+
public acceleration: MicroPoint;
46+
47+
/**
48+
* This isn't drag exactly, more like deceleration that is only applied
49+
* when acceleration is not affecting the sprite.
50+
* @type {MicroPoint}
51+
*/
52+
public drag: MicroPoint;
53+
54+
/**
55+
* It will cap the speed automatically if you use the acceleration
56+
* to change its velocity.
57+
* @type {MicroPoint}
58+
*/
59+
public maxVelocity: MicroPoint;
60+
61+
/**
62+
* How fast this object is rotating.
63+
* @type {number}
64+
*/
65+
public angularVelocity: number;
66+
67+
/**
68+
* How fast angularVelocity of this object is changing.
69+
* @type {number}
70+
*/
71+
public angularAcceleration: number;
72+
73+
/**
74+
* Deacceleration of angularVelocity will be applied when it's rotating.
75+
* @type {number}
76+
*/
77+
public angularDrag: number;
78+
79+
/**
80+
* It will cap the rotate speed automatically if you use the angularAcceleration
81+
* to change its angularVelocity.
82+
* @type {number}
83+
*/
84+
public maxAngular: number;
85+
86+
/**
87+
* Set this to false if you want to skip the automatic motion/movement stuff
88+
* (see updateMotion()).
89+
* @type {boolean}
90+
*/
91+
public moves: bool = true;
92+
93+
/**
94+
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts.
95+
* @type {number}
96+
*/
97+
public touching: number;
98+
99+
/**
100+
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating surface contacts from the previous game loop step.
101+
* @type {number}
102+
*/
103+
public wasTouching: number;
104+
105+
/**
106+
* Bit field of flags (use with UP, DOWN, LEFT, RIGHT, etc) indicating collision directions.
107+
* @type {number}
108+
*/
109+
public allowCollisions: number;
110+
111+
/**
112+
* Important variable for collision processing.
113+
* @type {MicroPoint}
114+
*/
115+
public last: MicroPoint;
116+
117+
/**
118+
* Internal function for updating the position and speed of this object.
119+
*/
120+
public update() {
121+
122+
var delta: number;
123+
var velocityDelta: number;
124+
125+
velocityDelta = (this._game.motion.computeVelocity(this.angularVelocity, this.angularAcceleration, this.angularDrag, this.maxAngular) - this.angularVelocity) / 2;
126+
this.angularVelocity += velocityDelta;
127+
this._angle += this.angularVelocity * this._game.time.elapsed;
128+
this.angularVelocity += velocityDelta;
129+
130+
velocityDelta = (this._game.motion.computeVelocity(this.velocity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
131+
this.velocity.x += velocityDelta;
132+
delta = this.velocity.x * this._game.time.elapsed;
133+
this.velocity.x += velocityDelta;
134+
this.frameBounds.x += delta;
135+
136+
velocityDelta = (this._game.motion.computeVelocity(this.velocity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
137+
this.velocity.y += velocityDelta;
138+
delta = this.velocity.y * this._game.time.elapsed;
139+
this.velocity.y += velocityDelta;
140+
this.frameBounds.y += delta;
141+
142+
}
143+
144+
145+
}
146+
147+
}

0 commit comments

Comments
 (0)