Skip to content

Commit a1a1ab3

Browse files
committed
First push to github
1 parent 5c705c4 commit a1a1ab3

368 files changed

Lines changed: 21609 additions & 2 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Phaser/.gitignore

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
#ignore thumbnails created by windows
3+
Thumbs.db
4+
#Ignore files build by Visual Studio
5+
*.obj
6+
*.exe
7+
*.pdb
8+
*.user
9+
*.aps
10+
*.pch
11+
*.vspscc
12+
*_i.c
13+
*_p.c
14+
*.ncb
15+
*.suo
16+
*.sln
17+
*.tlb
18+
*.tlh
19+
*.bak
20+
*.cache
21+
*.ilk
22+
*.log
23+
*.map
24+
*.orig
25+
*.js
26+
!kiwi-lite.js
27+
*.map
28+
*.config
29+
[Bb]in
30+
[Dd]ebug*/
31+
*.lib
32+
*.sbr
33+
obj/
34+
[Rr]elease*/
35+
_ReSharper*/
36+
[Tt]est[Rr]esult*

Phaser/Animations.ts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/// <reference path="Cache.ts" />
2+
/// <reference path="Game.ts" />
3+
/// <reference path="Sprite.ts" />
4+
/// <reference path="system/animation/Animation.ts" />
5+
/// <reference path="system/animation/AnimationLoader.ts" />
6+
/// <reference path="system/animation/Frame.ts" />
7+
/// <reference path="system/animation/FrameData.ts" />
8+
9+
class Animations {
10+
11+
constructor(game: Game, parent: Sprite) {
12+
13+
this._game = game;
14+
this._parent = parent;
15+
this._anims = {};
16+
17+
}
18+
19+
private _game: Game;
20+
private _parent: Sprite;
21+
22+
private _anims: {};
23+
private _frameIndex: number;
24+
private _frameData: FrameData = null;
25+
26+
public currentAnim: Animation;
27+
public currentFrame: Frame = null;
28+
29+
public loadFrameData(frameData: FrameData) {
30+
31+
this._frameData = frameData;
32+
33+
this.frame = 0;
34+
35+
}
36+
37+
public add(name: string, frames:number[] = null, frameRate: number = 60, loop: bool = false) {
38+
39+
if (this._frameData == null)
40+
{
41+
return;
42+
}
43+
44+
if (frames == null)
45+
{
46+
frames = this._frameData.getFrameIndexes();
47+
}
48+
else
49+
{
50+
if (this.validateFrames(frames) == false)
51+
{
52+
return;
53+
}
54+
}
55+
56+
this._anims[name] = new Animation(this._game, this._parent, this._frameData, name, frames, frameRate, loop);
57+
58+
this.currentAnim = this._anims[name];
59+
60+
}
61+
62+
private validateFrames(frames:number[]):bool {
63+
64+
var result = true;
65+
66+
for (var i = 0; i < frames.length; i++)
67+
{
68+
if (frames[i] > this._frameData.total)
69+
{
70+
return false;
71+
}
72+
}
73+
74+
}
75+
76+
public play(name: string, frameRate?: number = null, loop?: bool) {
77+
78+
if (this._anims[name])
79+
{
80+
this.currentAnim = this._anims[name];
81+
this.currentAnim.play(frameRate, loop);
82+
}
83+
84+
}
85+
86+
public stop(name: string) {
87+
88+
if (this._anims[name])
89+
{
90+
this.currentAnim = this._anims[name];
91+
this.currentAnim.stop();
92+
}
93+
94+
}
95+
96+
public update() {
97+
98+
if (this.currentAnim && this.currentAnim.update() == true)
99+
{
100+
this.currentFrame = this.currentAnim.currentFrame;
101+
this._parent.bounds.width = this.currentFrame.width;
102+
this._parent.bounds.height = this.currentFrame.height;
103+
}
104+
105+
}
106+
107+
public get frameTotal(): number {
108+
return this._frameData.total;
109+
}
110+
111+
public get frame(): number {
112+
return this._frameIndex;
113+
}
114+
115+
public set frame(value: number) {
116+
117+
this.currentFrame = this._frameData.getFrame(value);
118+
119+
if (this.currentFrame !== null)
120+
{
121+
this._parent.bounds.width = this.currentFrame.width;
122+
this._parent.bounds.height = this.currentFrame.height;
123+
this._frameIndex = value;
124+
}
125+
126+
}
127+
128+
}

Phaser/Basic.ts

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/// <reference path="Game.ts" />
2+
3+
/**
4+
* This is a useful "generic" object.
5+
* Both <code>GameObject</code> and <code>Group</code> extend this class,
6+
* as do the plugins. Has no size, position or graphical data.
7+
*
8+
* @author Adam Atomic
9+
* @author Richard Davey
10+
*/
11+
12+
class Basic {
13+
14+
/**
15+
* Instantiate the basic object.
16+
*/
17+
constructor(game:Game) {
18+
19+
this._game = game;
20+
this.ID = -1;
21+
this.exists = true;
22+
this.active = true;
23+
this.visible = true;
24+
this.alive = true;
25+
this.isGroup = false;
26+
this.ignoreDrawDebug = false;
27+
28+
}
29+
30+
/**
31+
* The essential reference to the main game object
32+
*/
33+
public _game: Game;
34+
35+
/**
36+
* Allows you to give this object a name. Useful for debugging, but not actually used internally.
37+
*/
38+
public name: string = '';
39+
40+
/**
41+
* IDs seem like they could be pretty useful, huh?
42+
* They're not actually used for anything yet though.
43+
*/
44+
public ID: number;
45+
46+
/**
47+
* A boolean to store if this object is a Group or not.
48+
* Saves us an expensive typeof check inside of core loops.
49+
*/
50+
public isGroup: bool;
51+
52+
/**
53+
* Controls whether <code>update()</code> and <code>draw()</code> are automatically called by FlxState/FlxGroup.
54+
*/
55+
public exists: bool;
56+
57+
/**
58+
* Controls whether <code>update()</code> is automatically called by FlxState/FlxGroup.
59+
*/
60+
public active: bool;
61+
62+
/**
63+
* Controls whether <code>draw()</code> is automatically called by FlxState/FlxGroup.
64+
*/
65+
public visible: bool;
66+
67+
/**
68+
* Useful state for many game objects - "dead" (!alive) vs alive.
69+
* <code>kill()</code> and <code>revive()</code> both flip this switch (along with exists, but you can override that).
70+
*/
71+
public alive: bool;
72+
73+
/**
74+
* Setting this to true will prevent the object from appearing
75+
* when the visual debug mode in the debugger overlay is toggled on.
76+
*/
77+
public ignoreDrawDebug: bool;
78+
79+
/**
80+
* Override this to null out iables or manually call
81+
* <code>destroy()</code> on class members if necessary.
82+
* Don't forget to call <code>super.destroy()</code>!
83+
*/
84+
public destroy() { }
85+
86+
/**
87+
* Pre-update is called right before <code>update()</code> on each object in the game loop.
88+
*/
89+
public preUpdate() {
90+
}
91+
92+
/**
93+
* Override this to update your class's position and appearance.
94+
* This is where most of your game rules and behavioral code will go.
95+
*/
96+
public update() {
97+
}
98+
99+
/**
100+
* Post-update is called right after <code>update()</code> on each object in the game loop.
101+
*/
102+
public postUpdate() {
103+
}
104+
105+
public render(camera:Camera, cameraOffsetX: number, cameraOffsetY: number) {
106+
}
107+
108+
/**
109+
* Handy for "killing" game objects.
110+
* Default behavior is to flag them as nonexistent AND dead.
111+
* However, if you want the "corpse" to remain in the game,
112+
* like to animate an effect or whatever, you should override this,
113+
* setting only alive to false, and leaving exists true.
114+
*/
115+
public kill() {
116+
this.alive = false;
117+
this.exists = false;
118+
}
119+
120+
/**
121+
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
122+
* In practice, this is most often called by <code>FlxObject.reset()</code>.
123+
*/
124+
public revive() {
125+
this.alive = true;
126+
this.exists = true;
127+
}
128+
129+
/**
130+
* Convert object to readable string name. Useful for debugging, save games, etc.
131+
*/
132+
public toString(): string {
133+
//return FlxU.getClassName(this, true);
134+
return "";
135+
}
136+
137+
}
138+

0 commit comments

Comments
 (0)