├── bin
├── remx-air.swc
└── remx-flash.swc
├── framework
├── assets
│ └── profiler
│ │ └── graphics.png
└── source
│ └── remx
│ ├── GameServer.as
│ ├── ResourceRX.as
│ ├── DataRX.as
│ ├── MusicRX.as
│ ├── GraphicRX.as
│ ├── TextCharacter.as
│ ├── SoundRX.as
│ ├── FontFrame.as
│ ├── SpriteFrame.as
│ ├── TilesetFrame.as
│ ├── WidgetFrame.as
│ ├── FontRX.as
│ ├── SpriteFrameset.as
│ ├── WidgetRX.as
│ ├── TilesetRX.as
│ ├── SpriteRX.as
│ ├── GameSystem.as
│ ├── GraphicMesh.as
│ ├── ResourcePackage.as
│ ├── Game.as
│ ├── Exception.as
│ ├── Data.as
│ ├── GridData.as
│ ├── GameConfig.as
│ ├── GameScreen.as
│ ├── Graphic.as
│ ├── DataInput.as
│ ├── DataOutput.as
│ ├── Grid.as
│ ├── Sprite.as
│ ├── Widget.as
│ ├── GameStorage.as
│ ├── Text.as
│ ├── GameNetwork.as
│ ├── GameProfiler.as
│ ├── GameAudio.as
│ ├── GameControls.as
│ ├── GameResource.as
│ ├── GameGraphics.as
│ └── GameApp.as
├── demos
└── flash
│ ├── 05 - Parallax Grids
│ ├── bin
│ │ ├── Demo.swf
│ │ └── res
│ │ │ ├── demo.swf
│ │ │ └── demo.xml
│ ├── src
│ │ ├── res
│ │ │ ├── demo.fla
│ │ │ └── demo
│ │ │ │ └── tiles.png
│ │ ├── Demo.as
│ │ └── DemoScreen.as
│ ├── src-libs
│ │ └── remx-flash.swc
│ └── index.htm
│ ├── 06 - Dynamic Text
│ ├── bin
│ │ ├── Demo.swf
│ │ └── res
│ │ │ ├── demo.swf
│ │ │ └── demo.xml
│ ├── src
│ │ ├── res
│ │ │ ├── demo.fla
│ │ │ └── demo
│ │ │ │ └── chars.png
│ │ ├── Demo.as
│ │ └── DemoScreen.as
│ ├── src-libs
│ │ └── remx-flash.swc
│ └── index.htm
│ ├── 01 - Screen and Sprite
│ ├── bin
│ │ ├── Demo.swf
│ │ └── res
│ │ │ ├── demo.swf
│ │ │ └── demo.xml
│ ├── src
│ │ ├── res
│ │ │ ├── demo.fla
│ │ │ └── demo
│ │ │ │ └── robo.png
│ │ ├── Demo.as
│ │ └── DemoScreen.as
│ ├── src-libs
│ │ └── remx-flash.swc
│ └── index.htm
│ ├── 04 - Screen and Widget
│ ├── bin
│ │ ├── Demo.swf
│ │ └── res
│ │ │ ├── demo.swf
│ │ │ └── demo.xml
│ ├── src
│ │ ├── res
│ │ │ ├── demo.fla
│ │ │ └── demo
│ │ │ │ └── button.png
│ │ ├── Demo.as
│ │ └── DemoScreen.as
│ ├── src-libs
│ │ └── remx-flash.swc
│ └── index.htm
│ ├── 02 - Screen and Animated Sprite
│ ├── bin
│ │ ├── Demo.swf
│ │ └── res
│ │ │ ├── demo.swf
│ │ │ └── demo.xml
│ ├── src
│ │ ├── res
│ │ │ ├── demo.fla
│ │ │ └── demo
│ │ │ │ └── robo_frames.png
│ │ ├── Demo.as
│ │ └── DemoScreen.as
│ ├── src-libs
│ │ └── remx-flash.swc
│ └── index.htm
│ └── 03 - Screen and Animated Sprites
│ ├── bin
│ ├── Demo.swf
│ └── res
│ │ ├── demo.swf
│ │ └── demo.xml
│ ├── src
│ ├── res
│ │ ├── demo.fla
│ │ └── demo
│ │ │ └── robo_frames.png
│ ├── Demo.as
│ └── DemoScreen.as
│ ├── src-libs
│ └── remx-flash.swc
│ └── index.htm
├── README
└── LICENSE
/bin/remx-air.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/bin/remx-air.swc
--------------------------------------------------------------------------------
/bin/remx-flash.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/bin/remx-flash.swc
--------------------------------------------------------------------------------
/framework/assets/profiler/graphics.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/framework/assets/profiler/graphics.png
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/bin/Demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/05 - Parallax Grids/bin/Demo.swf
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/bin/Demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/06 - Dynamic Text/bin/Demo.swf
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/bin/res/demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/06 - Dynamic Text/bin/res/demo.swf
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/src/res/demo.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/06 - Dynamic Text/src/res/demo.fla
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/bin/Demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/01 - Screen and Sprite/bin/Demo.swf
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/bin/Demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/04 - Screen and Widget/bin/Demo.swf
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/bin/res/demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/05 - Parallax Grids/bin/res/demo.swf
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/src/res/demo.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/05 - Parallax Grids/src/res/demo.fla
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/bin/res/demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/01 - Screen and Sprite/bin/res/demo.swf
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/src/res/demo.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/01 - Screen and Sprite/src/res/demo.fla
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/bin/res/demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/04 - Screen and Widget/bin/res/demo.swf
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/src/res/demo.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/04 - Screen and Widget/src/res/demo.fla
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/src/res/demo/tiles.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/05 - Parallax Grids/src/res/demo/tiles.png
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/src-libs/remx-flash.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/06 - Dynamic Text/src-libs/remx-flash.swc
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/src/res/demo/chars.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/06 - Dynamic Text/src/res/demo/chars.png
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/src/res/demo/robo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/01 - Screen and Sprite/src/res/demo/robo.png
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/bin/Demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/02 - Screen and Animated Sprite/bin/Demo.swf
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/src-libs/remx-flash.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/05 - Parallax Grids/src-libs/remx-flash.swc
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/src-libs/remx-flash.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/01 - Screen and Sprite/src-libs/remx-flash.swc
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/bin/Demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/03 - Screen and Animated Sprites/bin/Demo.swf
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/src-libs/remx-flash.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/04 - Screen and Widget/src-libs/remx-flash.swc
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/src/res/demo/button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/04 - Screen and Widget/src/res/demo/button.png
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/bin/res/demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/02 - Screen and Animated Sprite/bin/res/demo.swf
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/src/res/demo.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/02 - Screen and Animated Sprite/src/res/demo.fla
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/bin/res/demo.swf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/03 - Screen and Animated Sprites/bin/res/demo.swf
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/src/res/demo.fla:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/03 - Screen and Animated Sprites/src/res/demo.fla
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/src-libs/remx-flash.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/02 - Screen and Animated Sprite/src-libs/remx-flash.swc
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/src-libs/remx-flash.swc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/03 - Screen and Animated Sprites/src-libs/remx-flash.swc
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/src/res/demo/robo_frames.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/02 - Screen and Animated Sprite/src/res/demo/robo_frames.png
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/src/res/demo/robo_frames.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/AdamHarte/ReMX/HEAD/demos/flash/03 - Screen and Animated Sprites/src/res/demo/robo_frames.png
--------------------------------------------------------------------------------
/framework/source/remx/GameServer.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | public final class GameServer extends GameSystem
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // CONSTRUCTOR
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | /**
14 | */
15 | public function GameServer()
16 | {}
17 |
18 | }// EOC
19 | }
--------------------------------------------------------------------------------
/framework/source/remx/ResourceRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal class ResourceRX
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var id:String = null;
14 |
15 | //------------------------------------------------------------------------------------------
16 | //
17 | // CONSTRUCTOR
18 | //
19 | //------------------------------------------------------------------------------------------
20 |
21 | /**
22 | */
23 | public function ResourceRX()
24 | {}
25 |
26 | }// EOC
27 | }
--------------------------------------------------------------------------------
/framework/source/remx/DataRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.utils.ByteArray;
4 |
5 | /**
6 | */
7 | internal final class DataRX extends ResourceRX
8 | {
9 | //------------------------------------------------------------------------------------------
10 | //
11 | // INTERNAL PROPERTIES
12 | //
13 | //------------------------------------------------------------------------------------------
14 |
15 | internal var bytes:ByteArray = null;
16 |
17 | //------------------------------------------------------------------------------------------
18 | //
19 | // CONSTRUCTOR
20 | //
21 | //------------------------------------------------------------------------------------------
22 |
23 | /**
24 | */
25 | public function DataRX()
26 | {}
27 |
28 | }// EOC
29 | }
--------------------------------------------------------------------------------
/framework/source/remx/MusicRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class MusicRX extends ResourceRX
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | public var path:String = null;
14 | public var repeated:Boolean = false;
15 |
16 | //------------------------------------------------------------------------------------------
17 | //
18 | // CONSTRUCTOR
19 | //
20 | //------------------------------------------------------------------------------------------
21 |
22 | /**
23 | */
24 | public function MusicRX()
25 | {}
26 |
27 | }// EOC
28 | }
--------------------------------------------------------------------------------
/framework/source/remx/GraphicRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.display.BitmapData;
4 |
5 | /**
6 | */
7 | internal class GraphicRX extends ResourceRX
8 | {
9 | //------------------------------------------------------------------------------------------
10 | //
11 | // INTERNAL PROPERTIES
12 | //
13 | //------------------------------------------------------------------------------------------
14 |
15 | internal var image:BitmapData = null;
16 |
17 | //------------------------------------------------------------------------------------------
18 | //
19 | // CONSTRUCTOR
20 | //
21 | //------------------------------------------------------------------------------------------
22 |
23 | /**
24 | */
25 | public function GraphicRX()
26 | {}
27 |
28 | }// EOC
29 | }
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | --------------------------------------------------------------------------------
2 |
3 | ReMX Framework
4 | Copyright (c) 2011, RetroModular. All rights reserved.
5 |
6 | --------------------------------------------------------------------------------
7 |
8 | ReMX is a 2D arcade game framework that uses the ActionScript 3.0 (AS3) Stage3D
9 | API (Molehill) for GPU accelerated graphics rendering. With the exception of the
10 | main document class and a few GUI elements used for game profiling and virtual
11 | gamepads on mobile devices, the native AS3 display list is not used, all game
12 | graphics are pushed to the GPU using Molehill.
13 |
14 | For more information and documention, see the wiki:
15 | https://github.com/RetroModular/ReMX/wiki/Introduction
16 |
17 | --------------------------------------------------------------------------------
--------------------------------------------------------------------------------
/framework/source/remx/TextCharacter.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class TextCharacter
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var x:Number = 0.0;
14 | internal var y:Number = 0.0;
15 | internal var frame:FontFrame = null;
16 |
17 | //------------------------------------------------------------------------------------------
18 | //
19 | // CONSTRUCTOR
20 | //
21 | //------------------------------------------------------------------------------------------
22 |
23 | /**
24 | */
25 | public function TextCharacter()
26 | {}
27 |
28 | }// EOC
29 | }
--------------------------------------------------------------------------------
/framework/source/remx/SoundRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.media.Sound;
4 |
5 | /**
6 | */
7 | internal final class SoundRX extends ResourceRX
8 | {
9 | //------------------------------------------------------------------------------------------
10 | //
11 | // INTERNAL PROPERTIES
12 | //
13 | //------------------------------------------------------------------------------------------
14 |
15 | public var source:Sound = null;
16 | public var repeated:Boolean = false;
17 |
18 | //------------------------------------------------------------------------------------------
19 | //
20 | // CONSTRUCTOR
21 | //
22 | //------------------------------------------------------------------------------------------
23 |
24 | /**
25 | */
26 | public function SoundRX()
27 | {}
28 |
29 | }// EOC
30 | }
--------------------------------------------------------------------------------
/framework/source/remx/FontFrame.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class FontFrame
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var u1:Number = 0.0;
14 | internal var v1:Number = 0.0;
15 | internal var u2:Number = 0.0;
16 | internal var v2:Number = 0.0;
17 |
18 | //------------------------------------------------------------------------------------------
19 | //
20 | // CONSTRUCTOR
21 | //
22 | //------------------------------------------------------------------------------------------
23 |
24 | /**
25 | */
26 | public function FontFrame()
27 | {}
28 |
29 | }// EOC
30 | }
--------------------------------------------------------------------------------
/framework/source/remx/SpriteFrame.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class SpriteFrame
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var u1:Number = 0.0;
14 | internal var v1:Number = 0.0;
15 | internal var u2:Number = 0.0;
16 | internal var v2:Number = 0.0;
17 |
18 | //------------------------------------------------------------------------------------------
19 | //
20 | // CONSTRUCTOR
21 | //
22 | //------------------------------------------------------------------------------------------
23 |
24 | /**
25 | */
26 | public function SpriteFrame()
27 | {}
28 |
29 | }// EOC
30 | }
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/index.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 06 - Dynamic Text
5 |
29 |
30 |
31 |
37 |
38 |
--------------------------------------------------------------------------------
/framework/source/remx/TilesetFrame.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class TilesetFrame
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var u1:Number = 0.0;
14 | internal var v1:Number = 0.0;
15 | internal var u2:Number = 0.0;
16 | internal var v2:Number = 0.0;
17 |
18 | internal var flags:uint = 0;
19 |
20 | //------------------------------------------------------------------------------------------
21 | //
22 | // CONSTRUCTOR
23 | //
24 | //------------------------------------------------------------------------------------------
25 |
26 | /**
27 | */
28 | public function TilesetFrame()
29 | {}
30 |
31 | }// EOC
32 | }
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/index.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 05 - Parallax Grids
5 |
29 |
30 |
31 |
37 |
38 |
--------------------------------------------------------------------------------
/framework/source/remx/WidgetFrame.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class WidgetFrame
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var u1:Number = 0.0;
14 | internal var v1:Number = 0.0;
15 | internal var u2:Number = 0.0;
16 | internal var v2:Number = 0.0;
17 |
18 | internal var sound:String = null;
19 |
20 | //------------------------------------------------------------------------------------------
21 | //
22 | // CONSTRUCTOR
23 | //
24 | //------------------------------------------------------------------------------------------
25 |
26 | /**
27 | */
28 | public function WidgetFrame()
29 | {}
30 |
31 | }// EOC
32 | }
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/index.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 01 - Screen and Sprite
5 |
29 |
30 |
31 |
37 |
38 |
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/index.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 04 - Screen and Widget
5 |
29 |
30 |
31 |
37 |
38 |
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/index.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 02 - Screen and Animated Sprite
5 |
29 |
30 |
31 |
37 |
38 |
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/index.htm:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 03 - Screen and Animated Sprites
5 |
29 |
30 |
31 |
37 |
38 |
--------------------------------------------------------------------------------
/framework/source/remx/FontRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.utils.Dictionary;
4 |
5 | /**
6 | */
7 | internal final class FontRX extends GraphicRX
8 | {
9 | //------------------------------------------------------------------------------------------
10 | //
11 | // INTERNAL PROPERTIES
12 | //
13 | //------------------------------------------------------------------------------------------
14 |
15 | internal var tracking:Number = 0.0;
16 | internal var leading:Number = 0.0;
17 |
18 | internal var frameWidth:Number = 0.0;
19 | internal var frameHeight:Number = 0.0;
20 |
21 | internal var frames:Dictionary = new Dictionary();
22 |
23 | //------------------------------------------------------------------------------------------
24 | //
25 | // CONSTRUCTOR
26 | //
27 | //------------------------------------------------------------------------------------------
28 |
29 | /**
30 | */
31 | public function FontRX()
32 | {}
33 |
34 | }// EOC
35 | }
--------------------------------------------------------------------------------
/framework/source/remx/SpriteFrameset.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class SpriteFrameset
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var animated:Boolean = false;
14 | internal var repeated:Boolean = false;
15 |
16 | internal var frameList:Vector. = new Vector.();
17 | internal var frameCount:int = 0;
18 |
19 | //------------------------------------------------------------------------------------------
20 | //
21 | // CONSTRUCTOR
22 | //
23 | //------------------------------------------------------------------------------------------
24 |
25 | /**
26 | */
27 | public function SpriteFrameset()
28 | {}
29 |
30 | //------------------------------------------------------------------------------------------
31 | //
32 | // INTERNAL METHODS
33 | //
34 | //------------------------------------------------------------------------------------------
35 |
36 | /**
37 | */
38 | internal function addFrame( frame:SpriteFrame ):void
39 | {
40 | frameList[frameCount++] = frame;
41 | }
42 |
43 | }// EOC
44 | }
--------------------------------------------------------------------------------
/framework/source/remx/WidgetRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class WidgetRX extends GraphicRX
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var frameWidth:Number = 0.0;
14 | internal var frameHeight:Number = 0.0;
15 |
16 | internal var frameList:Vector. = new Vector.();
17 | internal var frameCount:int = 0;
18 |
19 | //------------------------------------------------------------------------------------------
20 | //
21 | // CONSTRUCTOR
22 | //
23 | //------------------------------------------------------------------------------------------
24 |
25 | /**
26 | */
27 | public function WidgetRX()
28 | {}
29 |
30 | //------------------------------------------------------------------------------------------
31 | //
32 | // INTERNAL METHODS
33 | //
34 | //------------------------------------------------------------------------------------------
35 |
36 | /**
37 | */
38 | internal function addFrame( frame:WidgetFrame ):void
39 | {
40 | frameList[frameCount++] = frame;
41 | }
42 |
43 | }// EOC
44 | }
--------------------------------------------------------------------------------
/framework/source/remx/TilesetRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class TilesetRX extends GraphicRX
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var frameWidth:Number = 0.0;
14 | internal var frameHeight:Number = 0.0;
15 |
16 | internal var frameList:Vector. = new Vector.();
17 | internal var frameCount:int = 0;
18 |
19 | //------------------------------------------------------------------------------------------
20 | //
21 | // CONSTRUCTOR
22 | //
23 | //------------------------------------------------------------------------------------------
24 |
25 | /**
26 | */
27 | public function TilesetRX()
28 | {}
29 |
30 | //------------------------------------------------------------------------------------------
31 | //
32 | // INTERNAL METHODS
33 | //
34 | //------------------------------------------------------------------------------------------
35 |
36 | /**
37 | */
38 | internal function addFrame( frame:TilesetFrame ):void
39 | {
40 | frameList[frameCount++] = frame;
41 | }
42 |
43 | }// EOC
44 | }
--------------------------------------------------------------------------------
/framework/source/remx/SpriteRX.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class SpriteRX extends GraphicRX
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var frameTime:Number = 0.0;
14 | internal var frameWidth:Number = 0.0;
15 | internal var frameHeight:Number = 0.0;
16 |
17 | internal var framesetList:Vector. = new Vector.();
18 | internal var framesetCount:int = 0;
19 |
20 | //------------------------------------------------------------------------------------------
21 | //
22 | // CONSTRUCTOR
23 | //
24 | //------------------------------------------------------------------------------------------
25 |
26 | /**
27 | */
28 | public function SpriteRX()
29 | {}
30 |
31 | //------------------------------------------------------------------------------------------
32 | //
33 | // INTERNAL METHODS
34 | //
35 | //------------------------------------------------------------------------------------------
36 |
37 | /**
38 | */
39 | internal function addFrameset( frameset:SpriteFrameset ):void
40 | {
41 | framesetList[framesetCount++] = frameset;
42 | }
43 |
44 | }// EOC
45 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameSystem.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal class GameSystem
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // STATIC - INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | static internal var constructorLocked:Boolean = true;
14 |
15 | //------------------------------------------------------------------------------------------
16 | //
17 | // CONSTRUCTOR
18 | //
19 | //------------------------------------------------------------------------------------------
20 |
21 | /**
22 | */
23 | public function GameSystem()
24 | {
25 | if( constructorLocked )
26 | {
27 | throw new Exception( "GameSystem instance cannot be constructed" );
28 | }
29 | }
30 |
31 | //------------------------------------------------------------------------------------------
32 | //
33 | // INTERNAL METHODS
34 | //
35 | //------------------------------------------------------------------------------------------
36 |
37 | /**
38 | */
39 | internal function initialize( game:GameApp ):void {}
40 |
41 | /**
42 | */
43 | internal function shutdown():void {}
44 |
45 | /**
46 | */
47 | internal function update():void {}
48 |
49 | /**
50 | */
51 | internal function reset():void {}
52 |
53 | }// EOC
54 | }
--------------------------------------------------------------------------------
/framework/source/remx/GraphicMesh.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | internal final class GraphicMesh
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // INTERNAL PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | internal var x:Number = 0.0;
14 | internal var y:Number = 0.0;
15 |
16 | internal var vertexList:Vector. = new Vector.();
17 | internal var vertexCount:int = 0;
18 |
19 | internal var indexList:Vector. = new Vector.();
20 | internal var indexCount:int = 0;
21 |
22 | //------------------------------------------------------------------------------------------
23 | //
24 | // CONSTRUCTOR
25 | //
26 | //------------------------------------------------------------------------------------------
27 |
28 | /**
29 | */
30 | public function GraphicMesh()
31 | {}
32 |
33 | //------------------------------------------------------------------------------------------
34 | //
35 | // INTERNAL METHODS
36 | //
37 | //------------------------------------------------------------------------------------------
38 |
39 | /**
40 | */
41 | internal function reset():void
42 | {
43 | x = 0.0;
44 | y = 0.0;
45 |
46 | vertexCount = 0;
47 | vertexList.length = 0;
48 |
49 | indexCount = 0;
50 | indexList.length = 0;
51 | }
52 |
53 | }// EOC
54 | }
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/src/Demo.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.Game;
4 | import remx.GameConfig;
5 |
6 | /**
7 | * The main SWF document class. This is where you configure the
8 | * game and register the game screens and resource packages.
9 | */
10 | public final class Demo extends Game
11 | {
12 | /**
13 | */
14 | public function Demo()
15 | {
16 | // CREATE A GAME CONFIG OBJECT
17 | var config:GameConfig = new GameConfig();
18 |
19 | // SET THE GAME WIDTH AND HEIGHT (THE FRAME RATE IS OPTIONAL)
20 | config.gameWidth = 640;
21 | config.gameHeight = 480;
22 | config.gameFrameRate = 40; // This is the default value.
23 |
24 | // OVERRIDE THE DEBUG MODE (OPTIONAL)
25 | // This value will default to TRUE if the SWF is running in a debug version of
26 | // the Flash Player or AIR Runtime, otherwise is will default to FALSE.
27 | // Setting this value to FALSE will improve rendering times.
28 | config.debug = false;
29 |
30 | // REGISTER THE GAME SCREENS
31 | // The screen ID "main" MUST be used to register a primary screen which
32 | // is the first screen that gets constructed when the game is initialized.
33 | config.registerScreen( "main", DemoScreen );
34 |
35 | // REGISTER THE RESOURCE PACKAGES
36 | // The package ID "main" CAN be used to register a primary resource package.
37 | // If a primary resource package is registered it will be loaded BEFORE the
38 | // primary screen is constructed.
39 | config.registerResourcePackage( "main", "res/demo.xml" );
40 |
41 | // SEND THE CONFIG OBJECT TO THE SUPER CONSTRUCTOR
42 | super( config );
43 | }
44 |
45 | }// EOC
46 | }
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/src/Demo.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.Game;
4 | import remx.GameConfig;
5 |
6 | /**
7 | * The main SWF document class. This is where you configure the
8 | * game and register the game screens and resource packages.
9 | */
10 | public final class Demo extends Game
11 | {
12 | /**
13 | */
14 | public function Demo()
15 | {
16 | // CREATE A GAME CONFIG OBJECT
17 | var config:GameConfig = new GameConfig();
18 |
19 | // SET THE GAME WIDTH AND HEIGHT (THE FRAME RATE IS OPTIONAL)
20 | config.gameWidth = 640;
21 | config.gameHeight = 480;
22 | config.gameFrameRate = 40; // This is the default value.
23 |
24 | // OVERRIDE THE DEBUG MODE (OPTIONAL)
25 | // This value will default to TRUE if the SWF is running in a debug version of
26 | // the Flash Player or AIR Runtime, otherwise is will default to FALSE.
27 | // Setting this value to FALSE will improve rendering times.
28 | config.debug = false;
29 |
30 | // REGISTER THE GAME SCREENS
31 | // The screen ID "main" MUST be used to register a primary screen which
32 | // is the first screen that gets constructed when the game is initialized.
33 | config.registerScreen( "main", DemoScreen );
34 |
35 | // REGISTER THE RESOURCE PACKAGES
36 | // The package ID "main" CAN be used to register a primary resource package.
37 | // If a primary resource package is registered it will be loaded BEFORE the
38 | // primary screen is constructed.
39 | config.registerResourcePackage( "main", "res/demo.xml" );
40 |
41 | // SEND THE CONFIG OBJECT TO THE SUPER CONSTRUCTOR
42 | super( config );
43 | }
44 |
45 | }// EOC
46 | }
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/src/Demo.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.Game;
4 | import remx.GameConfig;
5 |
6 | /**
7 | * The main SWF document class. This is where you configure the
8 | * game and register the game screens and resource packages.
9 | */
10 | public final class Demo extends Game
11 | {
12 | /**
13 | */
14 | public function Demo()
15 | {
16 | // CREATE A GAME CONFIG OBJECT
17 | var config:GameConfig = new GameConfig();
18 |
19 | // SET THE GAME WIDTH AND HEIGHT (THE FRAME RATE IS OPTIONAL)
20 | config.gameWidth = 640;
21 | config.gameHeight = 480;
22 | config.gameFrameRate = 40; // This is the default value.
23 |
24 | // OVERRIDE THE DEBUG MODE (OPTIONAL)
25 | // This value will default to TRUE if the SWF is running in a debug version of
26 | // the Flash Player or AIR Runtime, otherwise is will default to FALSE.
27 | // Setting this value to FALSE will improve rendering times.
28 | config.debug = false;
29 |
30 | // REGISTER THE GAME SCREENS
31 | // The screen ID "main" MUST be used to register a primary screen which
32 | // is the first screen that gets constructed when the game is initialized.
33 | config.registerScreen( "main", DemoScreen );
34 |
35 | // REGISTER THE RESOURCE PACKAGES
36 | // The package ID "main" CAN be used to register a primary resource package.
37 | // If a primary resource package is registered it will be loaded BEFORE the
38 | // primary screen is constructed.
39 | config.registerResourcePackage( "main", "res/demo.xml" );
40 |
41 | // SEND THE CONFIG OBJECT TO THE SUPER CONSTRUCTOR
42 | super( config );
43 | }
44 |
45 | }// EOC
46 | }
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/src/Demo.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.Game;
4 | import remx.GameConfig;
5 |
6 | /**
7 | * The main SWF document class. This is where you configure the
8 | * game and register the game screens and resource packages.
9 | */
10 | public final class Demo extends Game
11 | {
12 | /**
13 | */
14 | public function Demo()
15 | {
16 | // CREATE A GAME CONFIG OBJECT
17 | var config:GameConfig = new GameConfig();
18 |
19 | // SET THE GAME WIDTH AND HEIGHT (THE FRAME RATE IS OPTIONAL)
20 | config.gameWidth = 640;
21 | config.gameHeight = 480;
22 | config.gameFrameRate = 40; // This is the default value.
23 |
24 | // OVERRIDE THE DEBUG MODE (OPTIONAL)
25 | // This value will default to TRUE if the SWF is running in a debug version of
26 | // the Flash Player or AIR Runtime, otherwise is will default to FALSE.
27 | // Setting this value to FALSE will improve rendering times.
28 | config.debug = false;
29 |
30 | // REGISTER THE GAME SCREENS
31 | // The screen ID "main" MUST be used to register a primary screen which
32 | // is the first screen that gets constructed when the game is initialized.
33 | config.registerScreen( "main", DemoScreen );
34 |
35 | // REGISTER THE RESOURCE PACKAGES
36 | // The package ID "main" CAN be used to register a primary resource package.
37 | // If a primary resource package is registered it will be loaded BEFORE the
38 | // primary screen is constructed.
39 | config.registerResourcePackage( "main", "res/demo.xml" );
40 |
41 | // SEND THE CONFIG OBJECT TO THE SUPER CONSTRUCTOR
42 | super( config );
43 | }
44 |
45 | }// EOC
46 | }
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/bin/res/demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/bin/res/demo.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/bin/res/demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/bin/res/demo.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/demos/flash/02 - Screen and Animated Sprite/src/DemoScreen.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.GameApp;
4 | import remx.GameScreen;
5 | import remx.Sprite;
6 |
7 | /**
8 | * This is the primary (main) game screen, it is the first screen to be
9 | * constructed when the game is initialized.
10 | *
11 | * Because a primary (main) resource package was registered this screen can access the
12 | * resources in that package as soon as the onConstruct() method is called.
13 | */
14 | public class DemoScreen extends GameScreen
15 | {
16 | private var game:GameApp;
17 | private var robo:Sprite; // remx.Sprite
18 |
19 | /**
20 | * This method is called when the screen is constructed.
21 | */
22 | protected override function onConstruct( game:GameApp ):void
23 | {
24 | this.game = game;
25 |
26 | // Sprite objects should not be created directly, the createSprite() method
27 | // should be used. Any sprite objects created directly will not be
28 | // provided with the information they need to be rendered.
29 | robo = game.resource.createSprite( "robo" );
30 |
31 | // For this demo the sprite is simply positioned in the middle of the screen.
32 | robo.x = game.width - robo.width >> 1;
33 | robo.y = game.height - robo.height >> 1;
34 | }
35 |
36 | /**
37 | * This method is called once per frame. Anything that needs to be
38 | * updated must be updated when this method is called.
39 | */
40 | protected override function onUpdate():void
41 | {}
42 |
43 | /**
44 | * This method is called once per frame. Any graphics that need to be
45 | * rendered must be rendered when this method is called.
46 | */
47 | protected override function onRender():void
48 | {
49 | // All graphics are rendered using the graphics.draw() method.
50 | game.graphics.draw( robo );
51 | }
52 |
53 | }// EOC
54 | }
--------------------------------------------------------------------------------
/demos/flash/01 - Screen and Sprite/src/DemoScreen.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.GameApp;
4 | import remx.GameScreen;
5 | import remx.Sprite;
6 |
7 | /**
8 | * This is the primary (main) game screen, it is the first screen to be
9 | * constructed when the game is initialized.
10 | *
11 | * Because a primary (main) resource package was registered this screen can access the
12 | * resources in that package as soon as the onConstruct() method is called.
13 | */
14 | public class DemoScreen extends GameScreen
15 | {
16 | private var game:GameApp;
17 | private var sprite:Sprite; // remx.Sprite
18 |
19 | /**
20 | * This method is called when the screen is constructed.
21 | */
22 | protected override function onConstruct( game:GameApp ):void
23 | {
24 | this.game = game;
25 |
26 | // Sprite objects should not be created directly, the createSprite() method
27 | // should be used. Any sprite objects created directly will not be
28 | // provided with the information they need to be rendered.
29 | sprite = game.resource.createSprite( "demoSprite" );
30 |
31 | // For this demo the sprite is simply positioned in the middle of the screen.
32 | sprite.x = game.width - sprite.width >> 1;
33 | sprite.y = game.height - sprite.height >> 1;
34 | }
35 |
36 | /**
37 | * This method is called once per frame. Anything that needs to be
38 | * updated must be updated when this method is called.
39 | */
40 | protected override function onUpdate():void
41 | {}
42 |
43 | /**
44 | * This method is called once per frame. Any graphics that need to be
45 | * rendered must be rendered when this method is called.
46 | */
47 | protected override function onRender():void
48 | {
49 | // All graphics are rendered using the graphics.draw() method.
50 | game.graphics.draw( sprite );
51 | }
52 |
53 | }// EOC
54 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | --------------------------------------------------------------------------------
2 |
3 | ReMX Framework
4 | Copyright (c) 2011, RetroModular. All rights reserved.
5 |
6 | --------------------------------------------------------------------------------
7 |
8 | TERMS AND CONDITIONS OF USE:
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice,
14 | this list of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice,
17 | this list of conditions and the following disclaimer in the documentation
18 | and/or other materials provided with the distribution.
19 |
20 | * The name RetroModular may not be used to endorse or promote products
21 | derived from this software.
22 |
23 | --------------------------------------------------------------------------------
24 |
25 | DISCLAIMER:
26 |
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
28 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
31 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
34 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 |
38 | -------------------------------------------------------------------------------
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/bin/res/demo.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/framework/source/remx/ResourcePackage.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.display.BitmapData;
4 | import flash.utils.Dictionary;
5 |
6 | /**
7 | */
8 | internal final class ResourcePackage
9 | {
10 | //------------------------------------------------------------------------------------------
11 | //
12 | // INTERNAL PROPERTIES
13 | //
14 | //------------------------------------------------------------------------------------------
15 |
16 | internal var id:String = null;
17 | internal var path:String = null;
18 |
19 | internal var images:Dictionary = new Dictionary();
20 |
21 | internal var data:Dictionary = new Dictionary();
22 | internal var fonts:Dictionary = new Dictionary();
23 | internal var music:Dictionary = new Dictionary();
24 | internal var sounds:Dictionary = new Dictionary();
25 | internal var sprites:Dictionary = new Dictionary();
26 | internal var tilesets:Dictionary = new Dictionary();
27 | internal var widgets:Dictionary = new Dictionary();
28 |
29 | //------------------------------------------------------------------------------------------
30 | //
31 | // CONSTRUCTOR
32 | //
33 | //------------------------------------------------------------------------------------------
34 |
35 | /**
36 | */
37 | public function ResourcePackage()
38 | {}
39 |
40 | //------------------------------------------------------------------------------------------
41 | //
42 | // INTERNAL METHODS
43 | //
44 | //------------------------------------------------------------------------------------------
45 |
46 | /**
47 | */
48 | internal function dispose():void
49 | {
50 | for each( var image:BitmapData in images )
51 | {
52 | image.dispose();
53 | }
54 |
55 | images = null;
56 | data = null;
57 | fonts = null;
58 | music = null;
59 | sounds = null;
60 | sprites = null;
61 | tilesets = null;
62 | widgets = null;
63 | }
64 |
65 | }// EOC
66 | }
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/src/Demo.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.Game;
4 | import remx.GameConfig;
5 |
6 | /**
7 | * The main SWF document class. This is where you configure the
8 | * game and register the game screens and resource packages.
9 | */
10 | public final class Demo extends Game
11 | {
12 | /**
13 | */
14 | public function Demo()
15 | {
16 | // CREATE A GAME CONFIG OBJECT
17 | var config:GameConfig = new GameConfig();
18 |
19 | // SET THE GAME WIDTH AND HEIGHT (THE FRAME RATE IS OPTIONAL)
20 | config.gameWidth = 640;
21 | config.gameHeight = 480;
22 | config.gameFrameRate = 40; // This is the default value.
23 |
24 | // SET THE BACKGROUND COLOR FOR THE SCREENS (OPTIONAL).
25 | config.gameBackground = 0xFFFFFF; // The default is 0x000000 (black).
26 |
27 | // ENABLE THE PROFILER (OPTIONAL).
28 | // The profiler will appear as a 40px high bar at the top of each screen.
29 | config.profile = true; // The default is FALSE.
30 |
31 | // OVERRIDE THE DEBUG MODE (OPTIONAL)
32 | // This value will default to TRUE if the SWF is running in a debug version of
33 | // the Flash Player or AIR Runtime, otherwise is will default to FALSE.
34 | // Setting this value to FALSE will improve rendering times.
35 | config.debug = false;
36 |
37 | // REGISTER THE GAME SCREENS
38 | // The screen ID "main" MUST be used to register a primary screen which
39 | // is the first screen that gets constructed when the game is initialized.
40 | config.registerScreen( "main", DemoScreen );
41 |
42 | // REGISTER THE RESOURCE PACKAGES
43 | // The package ID "main" CAN be used to register a primary resource package.
44 | // If a primary resource package is registered it will be loaded BEFORE the
45 | // primary screen is constructed.
46 | config.registerResourcePackage( "main", "res/demo.xml" );
47 |
48 | // SEND THE CONFIG OBJECT TO THE SUPER CONSTRUCTOR
49 | super( config );
50 | }
51 |
52 | }// EOC
53 | }
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/src/Demo.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.Game;
4 | import remx.GameConfig;
5 |
6 | /**
7 | * The main SWF document class. This is where you configure the
8 | * game and register the game screens and resource packages.
9 | */
10 | public final class Demo extends Game
11 | {
12 | /**
13 | */
14 | public function Demo()
15 | {
16 | // CREATE A GAME CONFIG OBJECT
17 | var config:GameConfig = new GameConfig();
18 |
19 | // SET THE GAME WIDTH AND HEIGHT (THE FRAME RATE IS OPTIONAL)
20 | config.gameWidth = 640;
21 | config.gameHeight = 480;
22 | config.gameFrameRate = 40; // This is the default value.
23 |
24 | // SET THE BACKGROUND COLOR FOR THE SCREENS (OPTIONAL).
25 | config.gameBackground = 0xD0E2D9; // The default is 0x000000 (black).
26 |
27 | // ENABLE THE PROFILER (OPTIONAL).
28 | // The profiler will appear as a 40px high bar at the top of each screen.
29 | config.profile = true; // The default is FALSE.
30 |
31 | // OVERRIDE THE DEBUG MODE (OPTIONAL)
32 | // This value will default to TRUE if the SWF is running in a debug version of
33 | // the Flash Player or AIR Runtime, otherwise is will default to FALSE.
34 | // Setting this value to FALSE will improve rendering times.
35 | config.debug = false;
36 |
37 | // REGISTER THE GAME SCREENS
38 | // The screen ID "main" MUST be used to register a primary screen which
39 | // is the first screen that gets constructed when the game is initialized.
40 | config.registerScreen( "main", DemoScreen );
41 |
42 | // REGISTER THE RESOURCE PACKAGES
43 | // The package ID "main" CAN be used to register a primary resource package.
44 | // If a primary resource package is registered it will be loaded BEFORE the
45 | // primary screen is constructed.
46 | config.registerResourcePackage( "main", "res/demo.xml" );
47 |
48 | // SEND THE CONFIG OBJECT TO THE SUPER CONSTRUCTOR
49 | super( config );
50 | }
51 |
52 | }// EOC
53 | }
--------------------------------------------------------------------------------
/framework/source/remx/Game.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.display.Sprite;
4 |
5 | /**
6 | */
7 | public class Game extends Sprite
8 | {
9 | //------------------------------------------------------------------------------------------
10 | //
11 | // STATIC - PRIVATE PROPERTIES
12 | //
13 | //------------------------------------------------------------------------------------------
14 |
15 | static private var instance:Game = null;
16 |
17 | //------------------------------------------------------------------------------------------
18 | //
19 | // PRIVATE PROPERTIES
20 | //
21 | //------------------------------------------------------------------------------------------
22 |
23 | private var game:GameApp = null;
24 | private var config:GameConfig = null;
25 |
26 | //------------------------------------------------------------------------------------------
27 | //
28 | // CONSTRUCTOR
29 | //
30 | //------------------------------------------------------------------------------------------
31 |
32 | /**
33 | */
34 | public function Game( config:GameConfig )
35 | {
36 | this.config = config;
37 |
38 | if( Object(this).constructor == null )
39 | {
40 | throw new Exception( "Game class must be extended" );
41 | }
42 |
43 | if( instance != null )
44 | {
45 | throw new Exception( "Game instance cannot be constructed" );
46 | }
47 |
48 | instance = this;
49 |
50 | if( stage != null )
51 | {
52 | initialize();
53 | }
54 | }
55 |
56 | //------------------------------------------------------------------------------------------
57 | //
58 | // INTERNAL METHODS
59 | //
60 | //------------------------------------------------------------------------------------------
61 |
62 | /**
63 | */
64 | internal function initialize():void
65 | {
66 | if( game == null )
67 | {
68 | GameApp.constructorLocked = false;
69 | game = new GameApp();
70 | GameApp.constructorLocked = true;
71 |
72 | game.run( stage, config );
73 | }
74 | }
75 |
76 | }// EOC
77 | }
--------------------------------------------------------------------------------
/demos/flash/04 - Screen and Widget/src/DemoScreen.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.GameApp;
4 | import remx.GameScreen;
5 | import remx.Widget;
6 |
7 | /**
8 | * This is the primary (main) game screen, it is the first screen to be
9 | * constructed when the game is initialized.
10 | *
11 | * Because a primary (main) resource package was registered this screen can access the
12 | * resources in that package as soon as the onConstruct() method is called.
13 | */
14 | public class DemoScreen extends GameScreen
15 | {
16 | private var game:GameApp;
17 | private var widget:Widget;
18 |
19 | /**
20 | * This method is called when the screen is constructed.
21 | */
22 | protected override function onConstruct( game:GameApp ):void
23 | {
24 | this.game = game;
25 |
26 | // Widgets objects should not be created directly, the createWidget() method
27 | // should be used. Any widget objects created directly will not be
28 | // provided with the information they need to be rendered.
29 | widget = game.resource.createWidget( "roboButton" );
30 |
31 | // For this demo this widget is simply positioned in the middle of the screen.
32 | widget.x = game.width - widget.width >> 1;
33 | widget.y = game.height - widget.height >> 1;
34 |
35 | // Add a onClick listener, this will be called when the widget is clicked.
36 | widget.onClick = onWidgetClick;
37 | }
38 |
39 | /**
40 | * This method is called once per frame. Anything that needs to be
41 | * updated must be updated when this method is called.
42 | */
43 | protected override function onUpdate():void
44 | {}
45 |
46 | /**
47 | * This method is called once per frame. Any graphics that need to be
48 | * drawn to the screen must be drawn when this method is called.
49 | */
50 | protected override function onRender():void
51 | {
52 | // Draw the widget to the screen.
53 | game.graphics.draw( widget );
54 | }
55 |
56 | /**
57 | */
58 | private function onWidgetClick( widget:Widget ):void
59 | {
60 | // Disable the widget.
61 | widget.enabled = false;
62 | }
63 |
64 | }// EOC
65 | }
--------------------------------------------------------------------------------
/framework/source/remx/Exception.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.system.Capabilities;
4 |
5 | RUNTIME::AIR
6 | {
7 | import flash.filesystem.File;
8 | import flash.filesystem.FileMode;
9 | import flash.filesystem.FileStream;
10 | }
11 |
12 | /**
13 | */
14 | public final class Exception extends Error
15 | {
16 | //------------------------------------------------------------------------------------------
17 | //
18 | // CONSTRUCTOR
19 | //
20 | //------------------------------------------------------------------------------------------
21 |
22 | /**
23 | */
24 | public function Exception( message:String, ...tokens )
25 | {
26 | var i:int = tokens.length;
27 |
28 | while( i-- )
29 | {
30 | message = message.replace( "%" + ( i + 1 ), tokens[i] );
31 | }
32 |
33 | if( Capabilities.isDebugger == false )
34 | {
35 | log( message );
36 | }
37 |
38 | super( message );
39 | }
40 |
41 | //------------------------------------------------------------------------------------------
42 | //
43 | // PUBLIC METHODS
44 | //
45 | //------------------------------------------------------------------------------------------
46 |
47 | /**
48 | */
49 | public function toString():String
50 | {
51 | return "ReMX Error: " + message;
52 | }
53 |
54 | //------------------------------------------------------------------------------------------
55 | //
56 | // PRIVATE METHODS
57 | //
58 | //------------------------------------------------------------------------------------------
59 |
60 | /**
61 | */
62 | RUNTIME::AIR
63 | private function log( message:String ):void
64 | {
65 | var file:File = new File( "app-storage:/exceptions" );
66 | var stream:FileStream = new FileStream();
67 |
68 | try
69 | {
70 | stream.open( file, FileMode.APPEND );
71 | }
72 | catch( error:Error )
73 | {
74 | return;
75 | }
76 |
77 | stream.writeUTFBytes( message + "\n" );
78 | stream.close();
79 | }
80 |
81 | /**
82 | */
83 | RUNTIME::FLASH
84 | private function log( message:String ):void
85 | {}
86 |
87 | }// EOC
88 | }
--------------------------------------------------------------------------------
/demos/flash/03 - Screen and Animated Sprites/src/DemoScreen.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import flash.geom.Point;
4 |
5 | import remx.GameApp;
6 | import remx.GameScreen;
7 | import remx.Sprite;
8 |
9 | /**
10 | * This is the primary (main) game screen, it is the first screen to be
11 | * constructed when the game is initialized.
12 | *
13 | * Because a primary (main) resource package was registered this screen can access the
14 | * resources in that package as soon as the onConstruct() method is called.
15 | */
16 | public class DemoScreen extends GameScreen
17 | {
18 | private var game:GameApp;
19 | private var robo:Sprite; // remx.Sprite
20 | private var points:Vector. = new Vector.();
21 |
22 | /**
23 | * This method is called when the screen is constructed.
24 | */
25 | protected override function onConstruct( game:GameApp ):void
26 | {
27 | this.game = game;
28 |
29 | // Sprite objects should not be created directly, the createSprite() method
30 | // should be used. Any sprite objects created directly will not be
31 | // provided with the information they need to be rendered.
32 | robo = game.resource.createSprite( "robo" );
33 |
34 | // For this demo a few Point objects with random x and y values are
35 | // created to represent the position of each sprite drawn to the screen.
36 | var i:int = 0;
37 | var n:int = 100;
38 | while( i < n )
39 | {
40 | points[i] = new Point( Math.random() * 600, Math.random() * 440 );
41 | i++;
42 | }
43 | }
44 |
45 | /**
46 | * This method is called once per frame. Anything that needs to be
47 | * updated must be updated when this method is called.
48 | */
49 | protected override function onUpdate():void
50 | {}
51 |
52 | /**
53 | * This method is called once per frame. Any graphics that need to be
54 | * drawn to the screen must be drawn when this method is called.
55 | */
56 | protected override function onRender():void
57 | {
58 | // For this demo a single sprite is drawn multiple times.
59 | var i:int = points.length;
60 | while( i-- )
61 | {
62 | robo.x = points[i].x;
63 | robo.y = points[i].y;
64 |
65 | // Draw the sprite at its new position.
66 | game.graphics.draw( robo );
67 | }
68 | }
69 |
70 | }// EOC
71 | }
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/src/DemoScreen.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.GameApp;
4 | import remx.GameScreen;
5 | import remx.Grid;
6 | import remx.GridData;
7 | import remx.Text;
8 |
9 | /**
10 | * This is the primary (main) game screen, it is the first screen to be
11 | * constructed when the game is initialized.
12 | *
13 | * Because a primary (main) resource package was registered this screen can access the
14 | * resources in that package as soon as the onConstruct() method is called.
15 | */
16 | public class DemoScreen extends GameScreen
17 | {
18 | private var game:GameApp;
19 | private var text:Text;
20 | private var string:String;
21 |
22 | /**
23 | * This method is called when the screen is constructed.
24 | */
25 | protected override function onConstruct( game:GameApp ):void
26 | {
27 | this.game = game;
28 |
29 | // Text objects should not be created directly, the createText() method
30 | // should be used. Any text objects created directly will not be
31 | // provided with the information they need to be rendered.
32 | text = game.resource.createText( "chunky" );
33 | }
34 |
35 | /**
36 | * This method is called once per frame. Anything that needs to be
37 | * updated must be updated when this method is called.
38 | */
39 | protected override function onUpdate():void
40 | {
41 | // Add a random character to the string.
42 | if( Math.random() > 0.9 )
43 | {
44 | string += " ";
45 | }
46 | else if( Math.random() > 0.9 )
47 | {
48 | string += "\n";
49 | }
50 | else
51 | {
52 | string += String.fromCharCode( 65 + ( 16 * Math.random() >> 0 ) );
53 | }
54 |
55 | // Update the text.
56 | text.setText( string );
57 |
58 | // Center the text.
59 | text.x = game.width - text.width >> 1;
60 | text.y = game.height - text.height >> 1;
61 |
62 | // Limit the string length.
63 | if( string.length == 200 )
64 | {
65 | string = "";
66 | }
67 | }
68 |
69 | /**
70 | * This method is called once per frame. Any graphics that need to be
71 | * drawn to the screen must be drawn when this method is called.
72 | */
73 | protected override function onRender():void
74 | {
75 | // Draw the text to the screen.
76 | game.graphics.draw( text );
77 | }
78 |
79 | }// EOC
80 | }
--------------------------------------------------------------------------------
/demos/flash/06 - Dynamic Text/bin/res/demo.xml:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/framework/source/remx/Data.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.utils.IDataInput;
4 | import flash.utils.IDataOutput;
5 |
6 | /**
7 | */
8 | public class Data
9 | {
10 | //------------------------------------------------------------------------------------------
11 | //
12 | // PRIVATE PROPERTIES
13 | //
14 | //------------------------------------------------------------------------------------------
15 |
16 | private var input:DataInput = null;
17 | private var output:DataOutput = null;
18 |
19 | //------------------------------------------------------------------------------------------
20 | //
21 | // CONSTRUCTOR
22 | //
23 | //------------------------------------------------------------------------------------------
24 |
25 | /**
26 | */
27 | public function Data()
28 | {
29 | if( Object(this).constructor == Data )
30 | {
31 | throw new Exception( "Data class must be extended" );
32 | }
33 | }
34 |
35 | //------------------------------------------------------------------------------------------
36 | //
37 | // INTERNAL METHODS
38 | //
39 | //------------------------------------------------------------------------------------------
40 |
41 | /**
42 | */
43 | internal function construct( rx:DataRX ):void
44 | {
45 | var p:uint = rx.bytes.position;
46 |
47 | restore( rx.bytes, true );
48 |
49 | rx.bytes.position = p;
50 | }
51 |
52 | /**
53 | */
54 | internal function save( stream:IDataOutput ):void
55 | {
56 | if( output == null )
57 | {
58 | output = new DataOutput();
59 | output.owner = this;
60 | }
61 |
62 | output.stream = stream;
63 | onSave( output );
64 | output.stream = null;
65 | }
66 |
67 | /**
68 | */
69 | internal function restore( stream:IDataInput, resourceData:Boolean=false ):void
70 | {
71 | if( input == null )
72 | {
73 | input = new DataInput();
74 | input.owner = this;
75 | }
76 |
77 | input.stream = stream;
78 | onRestore( input, resourceData );
79 | input.stream = null;
80 | }
81 |
82 | //------------------------------------------------------------------------------------------
83 | //
84 | // PROTECTED METHODS
85 | //
86 | //------------------------------------------------------------------------------------------
87 |
88 | /**
89 | */
90 | protected function onSave( output:DataOutput ):void {}
91 |
92 | /**
93 | */
94 | protected function onRestore( input:DataInput, resourceData:Boolean ):void {}
95 |
96 | }// EOC
97 | }
--------------------------------------------------------------------------------
/framework/source/remx/GridData.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | public final class GridData extends Data
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // PUBLIC PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | public var rows:uint = 0;
14 | public var columns:uint = 0;
15 | public var tilemap:Vector. = null;
16 |
17 | //------------------------------------------------------------------------------------------
18 | //
19 | // CONSTRUCTOR
20 | //
21 | //------------------------------------------------------------------------------------------
22 |
23 | /**
24 | */
25 | public function GridData()
26 | {}
27 |
28 | //------------------------------------------------------------------------------------------
29 | //
30 | // PUBLIC METHODS
31 | //
32 | //------------------------------------------------------------------------------------------
33 |
34 | /**
35 | */
36 | public function isValid():Boolean
37 | {
38 | if( rows == 0 || columns == 0 || tilemap == null )
39 | {
40 | return false;
41 | }
42 |
43 | return ( rows * columns == tilemap.length );
44 | }
45 |
46 | //------------------------------------------------------------------------------------------
47 | //
48 | // PROTECTED METHODS
49 | //
50 | //------------------------------------------------------------------------------------------
51 |
52 | /**
53 | */
54 | protected override function onSave( output:DataOutput ):void
55 | {
56 | output.writeU16( rows );
57 | output.writeU16( columns );
58 |
59 | if( tilemap == null )
60 | {
61 | output.writeU16( 0 );
62 | return;
63 | }
64 |
65 | var i:int = 0;
66 | var n:int = tilemap.length;
67 |
68 | output.writeU16( n );
69 |
70 | while( i < n )
71 | {
72 | output.writeU16( tilemap[i] );
73 | i++;
74 | }
75 | }
76 |
77 | /**
78 | */
79 | protected override function onRestore( input:DataInput, resourceData:Boolean ):void
80 | {
81 | rows = input.readU16();
82 | columns = input.readU16();
83 |
84 | var i:int = 0;
85 | var n:int = input.readU16();
86 |
87 | if( n == 0 )
88 | {
89 | return;
90 | }
91 |
92 | tilemap = new Vector.( n );
93 |
94 | while( i < n )
95 | {
96 | tilemap[i] = input.readU16();
97 | i++;
98 | }
99 | }
100 |
101 | }// EOC
102 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameConfig.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.system.Capabilities;
4 | import flash.utils.Dictionary;
5 |
6 | /**
7 | */
8 | public final class GameConfig
9 | {
10 | //------------------------------------------------------------------------------------------
11 | //
12 | // PUBLIC PROPERTIES
13 | //
14 | //------------------------------------------------------------------------------------------
15 |
16 | public var gameUID:uint = 0;
17 | public var gameWidth:uint = 0;
18 | public var gameHeight:uint = 0;
19 | public var gameFrameRate:uint = 40;
20 | public var gameBackground:uint = 0x000000;
21 |
22 | public var debug:Boolean = Capabilities.isDebugger;
23 | public var profile:Boolean = false;
24 |
25 | //------------------------------------------------------------------------------------------
26 | //
27 | // INTERNAL PROPERTIES
28 | //
29 | //------------------------------------------------------------------------------------------
30 |
31 | internal var hasMainScreen:Boolean = false;
32 | internal var hasMainResource:Boolean = false;
33 |
34 | internal var screenClasses:Dictionary = new Dictionary();
35 | internal var descriptorPaths:Dictionary = new Dictionary();
36 |
37 | //------------------------------------------------------------------------------------------
38 | //
39 | // CONSTRUCTOR
40 | //
41 | //------------------------------------------------------------------------------------------
42 |
43 | /**
44 | */
45 | public function GameConfig()
46 | {}
47 |
48 | //------------------------------------------------------------------------------------------
49 | //
50 | // PUBLIC METHODS
51 | //
52 | //------------------------------------------------------------------------------------------
53 |
54 | /**
55 | */
56 | public function registerScreen( screenID:String, screenClass:Class ):void
57 | {
58 | if( screenClasses[screenID] != null )
59 | {
60 | throw new Exception( "Parameter 'screenID' must be a unique screen identifier" );
61 | }
62 |
63 | if( screenID == "main" )
64 | {
65 | hasMainScreen = true;
66 | }
67 |
68 | screenClasses[screenID] = screenClass;
69 | }
70 |
71 | /**
72 | */
73 | public function registerResourcePackage( packageID:String, descriptorPath:String ):void
74 | {
75 | if( descriptorPaths[packageID] != null )
76 | {
77 | throw new Exception( "Parameter 'packageID' must be a unique resource package identifier" );
78 | }
79 |
80 | if( packageID == "main" )
81 | {
82 | hasMainResource = true;
83 | }
84 |
85 | descriptorPaths[packageID] = descriptorPath.replace( /^\/{1,}/, "" );
86 | }
87 |
88 | }// EOC
89 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameScreen.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | public class GameScreen
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // PRIVATE PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | private var deactivated:Boolean = true;
14 |
15 | //------------------------------------------------------------------------------------------
16 | //
17 | // CONSTRUCTOR
18 | //
19 | //------------------------------------------------------------------------------------------
20 |
21 | /**
22 | */
23 | public function GameScreen()
24 | {
25 | if( Object(this).constructor == GameScreen )
26 | {
27 | throw new Exception( "GameScreen class must be extended" );
28 | }
29 | }
30 |
31 | //------------------------------------------------------------------------------------------
32 | //
33 | // INTERNAL METHODS
34 | //
35 | //------------------------------------------------------------------------------------------
36 |
37 | /**
38 | */
39 | internal function construct( game:GameApp ):void
40 | {
41 | onConstruct( game );
42 | }
43 |
44 | /**
45 | */
46 | internal function deconstruct():void
47 | {
48 | onDeconstruct();
49 | }
50 |
51 | /**
52 | */
53 | internal function update():void
54 | {
55 | onUpdate();
56 | }
57 |
58 | /**
59 | */
60 | internal function render():void
61 | {
62 | onRender();
63 | }
64 |
65 | /**
66 | */
67 | internal function activate():void
68 | {
69 | if( deactivated )
70 | {
71 | onActivate();
72 | deactivated = false;
73 | }
74 | }
75 |
76 | /**
77 | */
78 | internal function deactivate():void
79 | {
80 | if( deactivated == false )
81 | {
82 | onDeactivate();
83 | deactivated = true;
84 | }
85 | }
86 |
87 | //------------------------------------------------------------------------------------------
88 | //
89 | // PROTECTED METHODS
90 | //
91 | //------------------------------------------------------------------------------------------
92 |
93 | /**
94 | */
95 | protected function onConstruct( game:GameApp ):void {}
96 |
97 | /**
98 | */
99 | protected function onDeconstruct():void {}
100 |
101 | /**
102 | */
103 | protected function onUpdate():void {}
104 |
105 | /**
106 | */
107 | protected function onRender():void {}
108 |
109 | /**
110 | */
111 | protected function onActivate():void {}
112 |
113 | /**
114 | */
115 | protected function onDeactivate():void {}
116 |
117 | }// EOC
118 | }
--------------------------------------------------------------------------------
/framework/source/remx/Graphic.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | public class Graphic
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // PUBLIC PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | public var x:Number = 0.0;
14 | public var y:Number = 0.0;
15 | public var width:Number = 0.0;
16 | public var height:Number = 0.0;
17 |
18 | public var cameraScalerX:Number = 1.0;
19 | public var cameraScalerY:Number = 1.0;
20 |
21 | //------------------------------------------------------------------------------------------
22 | //
23 | // INTERNAL PROPERTIES
24 | //
25 | //------------------------------------------------------------------------------------------
26 |
27 | internal var graphicRX:GraphicRX = null;
28 |
29 | internal var clipped:Boolean = false;
30 | internal var interactive:Boolean = false;
31 |
32 | //------------------------------------------------------------------------------------------
33 | //
34 | // PRIVATE PROPERTIES
35 | //
36 | //------------------------------------------------------------------------------------------
37 |
38 | private var game:GameApp = null;
39 |
40 | //------------------------------------------------------------------------------------------
41 | //
42 | // CONSTRUCTOR
43 | //
44 | //------------------------------------------------------------------------------------------
45 |
46 | /**
47 | */
48 | public function Graphic()
49 | {
50 | if( Object(this).constructor == Graphic )
51 | {
52 | throw new Exception( "Graphic class must be extended" );
53 | }
54 | }
55 |
56 | //------------------------------------------------------------------------------------------
57 | //
58 | // INTERNAL METHODS
59 | //
60 | //------------------------------------------------------------------------------------------
61 |
62 | /**
63 | */
64 | internal function construct( game:GameApp, rx:GraphicRX ):void
65 | {
66 | this.game = game;
67 | graphicRX = rx;
68 |
69 | onConstruct();
70 | }
71 |
72 | /**
73 | */
74 | internal function render( mesh:GraphicMesh ):void {}
75 |
76 | /**
77 | */
78 | internal function mouseEnter():void {}
79 |
80 | /**
81 | */
82 | internal function mouseHover():void {}
83 |
84 | /**
85 | */
86 | internal function mouseLeave():void {}
87 |
88 | //------------------------------------------------------------------------------------------
89 | //
90 | // PROTECTED METHODS
91 | //
92 | //------------------------------------------------------------------------------------------
93 |
94 | /**
95 | */
96 | protected function onConstruct():void {}
97 |
98 | }// EOC
99 | }
--------------------------------------------------------------------------------
/framework/source/remx/DataInput.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.utils.ByteArray;
4 | import flash.utils.IDataInput;
5 |
6 | /**
7 | */
8 | public class DataInput
9 | {
10 | //------------------------------------------------------------------------------------------
11 | //
12 | // STATIC - PRIVATE PROPERTIES
13 | //
14 | //------------------------------------------------------------------------------------------
15 |
16 | static private var buffer:ByteArray = null;
17 |
18 | //------------------------------------------------------------------------------------------
19 | //
20 | // INTERNAL PROPERTIES
21 | //
22 | //------------------------------------------------------------------------------------------
23 |
24 | internal var owner:Data = null;
25 | internal var stream:IDataInput = null;
26 |
27 | //------------------------------------------------------------------------------------------
28 | //
29 | // CONSTRUCTOR
30 | //
31 | //------------------------------------------------------------------------------------------
32 |
33 | /**
34 | */
35 | public function DataInput()
36 | {}
37 |
38 | //------------------------------------------------------------------------------------------
39 | //
40 | // PUBLIC METHODS
41 | //
42 | //------------------------------------------------------------------------------------------
43 |
44 | /**
45 | */
46 | public function readU8():uint
47 | {
48 | return stream.readUnsignedByte();
49 | }
50 |
51 | /**
52 | */
53 | public function readU16():uint
54 | {
55 | return stream.readUnsignedShort();
56 | }
57 |
58 | /**
59 | */
60 | public function readU32():uint
61 | {
62 | return stream.readUnsignedInt();
63 | }
64 |
65 | /**
66 | */
67 | public function readS8():int
68 | {
69 | return stream.readByte();
70 | }
71 |
72 | /**
73 | */
74 | public function readS16():int
75 | {
76 | return stream.readShort();
77 | }
78 |
79 | /**
80 | */
81 | public function readS32():int
82 | {
83 | return stream.readInt();
84 | }
85 |
86 | /**
87 | */
88 | public function readFLOAT():Number
89 | {
90 | return stream.readFloat();
91 | }
92 |
93 | /*
94 |
95 | public function readFLOAT2():*
96 | {}
97 |
98 | public function readFLOAT3():*
99 | {}
100 |
101 | public function readFLOAT4():*
102 | {}
103 |
104 | */
105 |
106 | /**
107 | */
108 | public function readSTRING():String
109 | {
110 | return stream.readUTFBytes( stream.readUnsignedInt() );
111 | }
112 |
113 | /**
114 | */
115 | public function readDATA( dataClass:Class ):*
116 | {
117 | var data:Data = new dataClass();
118 | data.restore( stream );
119 | return data;
120 | }
121 |
122 | }// EOC
123 | }
--------------------------------------------------------------------------------
/framework/source/remx/DataOutput.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.utils.ByteArray;
4 | import flash.utils.IDataOutput;
5 |
6 | /**
7 | */
8 | public class DataOutput
9 | {
10 | //------------------------------------------------------------------------------------------
11 | //
12 | // STATIC - PRIVATE PROPERTIES
13 | //
14 | //------------------------------------------------------------------------------------------
15 |
16 | static private var buffer:ByteArray = null;
17 |
18 | //------------------------------------------------------------------------------------------
19 | //
20 | // INTERNAL PROPERTIES
21 | //
22 | //------------------------------------------------------------------------------------------
23 |
24 | internal var owner:Data = null;
25 | internal var stream:IDataOutput = null;
26 |
27 | //------------------------------------------------------------------------------------------
28 | //
29 | // CONSTRUCTOR
30 | //
31 | //------------------------------------------------------------------------------------------
32 |
33 | /**
34 | */
35 | public function DataOutput()
36 | {}
37 |
38 | //------------------------------------------------------------------------------------------
39 | //
40 | // PUBLIC METHODS
41 | //
42 | //------------------------------------------------------------------------------------------
43 |
44 | /**
45 | */
46 | public function writeU8( value:uint ):void
47 | {
48 | stream.writeByte( value );
49 | }
50 |
51 | /**
52 | */
53 | public function writeU16( value:uint ):void
54 | {
55 | stream.writeByte( value );
56 | }
57 |
58 | /**
59 | */
60 | public function writeU32( value:uint ):void
61 | {
62 | stream.writeUnsignedInt( value );
63 | }
64 |
65 | /**
66 | */
67 | public function writeS8( value:int ):void
68 | {
69 | stream.writeByte( value );
70 | }
71 |
72 | /**
73 | */
74 | public function writeS16( value:int ):void
75 | {
76 | stream.writeShort( value );
77 | }
78 |
79 | /**
80 | */
81 | public function writeS32( value:int ):void
82 | {
83 | stream.writeInt( value );
84 | }
85 |
86 | /**
87 | */
88 | public function writeFLOAT( value:Number ):void
89 | {
90 | stream.writeFloat( value );
91 | }
92 |
93 | /*
94 |
95 | public function writeFLOAT2( value:* ):void
96 | {}
97 |
98 | public function writeFLOAT3( value:* ):void
99 | {}
100 |
101 | public function writeFLOAT4( value:* ):void
102 | {}
103 |
104 | */
105 |
106 | /**
107 | */
108 | public function writeSTRING( value:String ):void
109 | {
110 | if( buffer == null )
111 | {
112 | buffer = new ByteArray();
113 | }
114 |
115 | buffer.writeUTFBytes( value );
116 |
117 | stream.writeUnsignedInt( buffer.length );
118 | stream.writeBytes( buffer );
119 |
120 | buffer.length = 0;
121 | }
122 |
123 | /**
124 | */
125 | public function writeDATA( value:Data ):void
126 | {
127 | if( value == owner )
128 | {
129 | throw new Exception( "A data object cannot write itself to an output stream" );
130 | }
131 |
132 | value.save( stream );
133 | }
134 |
135 | }// EOC
136 | }
--------------------------------------------------------------------------------
/demos/flash/05 - Parallax Grids/src/DemoScreen.as:
--------------------------------------------------------------------------------
1 | package
2 | {
3 | import remx.GameApp;
4 | import remx.GameScreen;
5 | import remx.Grid;
6 | import remx.GridData;
7 |
8 | /**
9 | * This is the primary (main) game screen, it is the first screen to be
10 | * constructed when the game is initialized.
11 | *
12 | * Because a primary (main) resource package was registered this screen can access the
13 | * resources in that package as soon as the onConstruct() method is called.
14 | */
15 | public class DemoScreen extends GameScreen
16 | {
17 | private var game:GameApp;
18 | private var floor:Grid;
19 | private var background:Grid;
20 |
21 | /**
22 | * This method is called when the screen is constructed.
23 | */
24 | protected override function onConstruct( game:GameApp ):void
25 | {
26 | this.game = game;
27 |
28 | // Grid objects should not be created directly, the createGrid() method
29 | // should be used. Any grid objects created directly will not be
30 | // provided with the information they need to be rendered.
31 | floor = game.resource.createGrid( "floor.tiles" );
32 | background = game.resource.createGrid( "background.tiles" );
33 |
34 | // The grids now have the tilesets but they do not know how to
35 | // draw the tiles. In order to provide that information we will
36 | // manually create two GridData objects for this demo.
37 | floor.data = new GridData();
38 | // Specify the number of columns and rows for the tilemap.
39 | floor.data.columns = 8;
40 | floor.data.rows = 4;
41 | // Populate the 8x4 tilemap with tile indices. The indices are
42 | // zero-based index values of the tiles within the tilesets that
43 | // were defined in the resource package descriptor.
44 | floor.data.tilemap = new [
45 | 0, 1, 2, 3, 0, 1, 2, 3,
46 | 1, 2, 3, 0, 1, 2, 3, 0,
47 | 2, 3, 0, 1, 2, 3, 0, 1,
48 | 3, 0, 1, 2, 3, 0, 1, 2
49 | ];
50 | // Tell the grid to repeat the tilemap so it fills the entire screen.
51 | floor.repeat = true;
52 |
53 | // Repeat the process for the background grid. This is very simple because
54 | // it only contains one tile.
55 | background.data = new GridData();
56 | background.data.columns = 1;
57 | background.data.rows = 1;
58 | background.data.tilemap = new [
59 | 0
60 | ];
61 | background.repeat = true;
62 |
63 | // We now tell the background grid not to track the movement
64 | // of the camera (see below) absolutely, we do that by
65 | // adjusting the following scaler properties. This can be
66 | // done to any graphic object.
67 | background.cameraScalerX = 0.5; // half of the tracking along the x axis
68 | }
69 |
70 | /**
71 | * This method is called once per frame. Anything that needs to be
72 | * updated must be updated when this method is called.
73 | */
74 | protected override function onUpdate():void
75 | {
76 | // Increase the camera's x position.
77 | // More information about the camera will be provided at a later date.
78 | game.graphics.cameraX += 1;
79 | }
80 |
81 | /**
82 | * This method is called once per frame. Any graphics that need to be
83 | * drawn to the screen must be drawn when this method is called.
84 | */
85 | protected override function onRender():void
86 | {
87 | // Draw the grids to the screen.
88 | game.graphics.draw( background );
89 | game.graphics.draw( floor );
90 | }
91 |
92 | }// EOC
93 | }
--------------------------------------------------------------------------------
/framework/source/remx/Grid.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | public class Grid extends Graphic
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // PUBLIC PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | public var data:GridData = null;
14 | public var repeat:Boolean = false;
15 |
16 | //------------------------------------------------------------------------------------------
17 | //
18 | // PRIVATE PROPERTIES
19 | //
20 | //------------------------------------------------------------------------------------------
21 |
22 | private var game:GameApp = null;
23 |
24 | private var tilesetRX:TilesetRX = null;
25 |
26 | //------------------------------------------------------------------------------------------
27 | //
28 | // CONSTRUCTOR
29 | //
30 | //------------------------------------------------------------------------------------------
31 |
32 | /**
33 | */
34 | public function Grid()
35 | {
36 | clipped = true;
37 | }
38 |
39 | //------------------------------------------------------------------------------------------
40 | //
41 | // INTERNAL METHODS
42 | //
43 | //------------------------------------------------------------------------------------------
44 |
45 | /**
46 | */
47 | internal override function construct( game:GameApp, rx:GraphicRX ):void
48 | {
49 | this.game = game;
50 |
51 | tilesetRX = rx as TilesetRX;
52 |
53 | width = game.width;
54 | height = game.height;
55 |
56 | super.construct( game, rx );
57 | }
58 |
59 | /**
60 | */
61 | internal override function render( mesh:GraphicMesh ):void
62 | {
63 | if( data == null || data.isValid() == false )
64 | {
65 | return;
66 | }
67 |
68 | var cx:Number = game.graphics.cameraX * cameraScalerX;
69 | var cy:Number = game.graphics.cameraY * cameraScalerY;
70 |
71 | var mc:int = data.columns;
72 | var mr:int = data.rows;
73 | var mx:int;
74 | var my:int = mesh.y / tilesetRX.frameHeight >> 0;
75 | var mi:int;
76 | var mn:int = data.tilemap.length;
77 |
78 | var gc:int = 2 + ( width / tilesetRX.frameWidth >> 0 );
79 | var gr:int = 2 + ( height / tilesetRX.frameHeight >> 0 );
80 | var gx:int;
81 | var gy:int = 0;
82 |
83 | var x1:Number;
84 | var y1:Number;
85 | var x2:Number;
86 | var y2:Number;
87 | var i:int;
88 | var j:int;
89 | var frame:TilesetFrame;
90 |
91 | while( gy < gr )
92 | {
93 | y1 = y + tilesetRX.frameHeight * gy;
94 |
95 | if( cy != 0.0 )
96 | {
97 | y1 -= cy % tilesetRX.frameHeight;
98 | }
99 |
100 | y2 = y1 + tilesetRX.frameHeight;
101 |
102 | mx = mesh.x / tilesetRX.frameWidth >> 0;
103 | gx = 0;
104 |
105 | while( gx < gc )
106 | {
107 | if( repeat )
108 | {
109 | mi = ( mx < mc ? mx : mx % mc )
110 | + ( my < mr ? my : my % mr ) * mc;
111 | }
112 | else
113 | {
114 | if( mx >= mc || my >= mr )
115 | {
116 | mx++;
117 | gx++;
118 | continue;
119 | }
120 |
121 | mi = mx + my * mc;
122 | }
123 |
124 | if( data.tilemap[mi] >= tilesetRX.frameCount )
125 | {
126 | mx++;
127 | gx++;
128 | continue;
129 | }
130 |
131 | x1 = x + tilesetRX.frameWidth * gx;
132 |
133 | if( cx != 0.0 )
134 | {
135 | x1 -= cx % tilesetRX.frameWidth;
136 | }
137 |
138 | x2 = x1 + tilesetRX.frameWidth;
139 |
140 | frame = tilesetRX.frameList[ data.tilemap[mi] ];
141 |
142 | i = mesh.vertexCount;
143 |
144 | mesh.vertexList[i++] = x1;
145 | mesh.vertexList[i++] = y1;
146 | mesh.vertexList[i++] = frame.u1;
147 | mesh.vertexList[i++] = frame.v1;
148 |
149 | mesh.vertexList[i++] = x2;
150 | mesh.vertexList[i++] = y1;
151 | mesh.vertexList[i++] = frame.u2;
152 | mesh.vertexList[i++] = frame.v1;
153 |
154 | mesh.vertexList[i++] = x1;
155 | mesh.vertexList[i++] = y2;
156 | mesh.vertexList[i++] = frame.u1;
157 | mesh.vertexList[i++] = frame.v2;
158 |
159 | mesh.vertexList[i++] = x2;
160 | mesh.vertexList[i++] = y2;
161 | mesh.vertexList[i++] = frame.u2;
162 | mesh.vertexList[i++] = frame.v2;
163 |
164 | mesh.vertexCount = i;
165 |
166 | i >>= 2;
167 |
168 | j = mesh.indexCount;
169 |
170 | mesh.indexList[j++] = i - 1;
171 | mesh.indexList[j++] = i - 2;
172 | mesh.indexList[j++] = i - 3;
173 | mesh.indexList[j++] = i - 4;
174 | mesh.indexList[j++] = i - 3;
175 | mesh.indexList[j++] = i - 2;
176 |
177 | mesh.indexCount = j;
178 |
179 | mx++;
180 | gx++;
181 | }
182 |
183 | my++;
184 | gy++;
185 | }
186 | }
187 |
188 | }// EOC
189 | }
--------------------------------------------------------------------------------
/framework/source/remx/Sprite.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | public class Sprite extends Graphic
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // PUBLIC PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | public var flipHorizontal:Boolean = false;
14 | public var flipVertical:Boolean = false;
15 |
16 | //------------------------------------------------------------------------------------------
17 | //
18 | // PRIVATE PROPERTIES
19 | //
20 | //------------------------------------------------------------------------------------------
21 |
22 | private var game:GameApp = null;
23 |
24 | private var spriteRX:SpriteRX = null;
25 | private var spriteFrame:SpriteFrame = null;
26 | private var spriteFrameset:SpriteFrameset = null;
27 |
28 | private var frameIndex:int = 0;
29 | private var framesetIndex:int = 0;
30 |
31 | private var timeStamp:Number = 0.0;
32 |
33 | //------------------------------------------------------------------------------------------
34 | //
35 | // CONSTRUCTOR
36 | //
37 | //------------------------------------------------------------------------------------------
38 |
39 | /**
40 | */
41 | public function Sprite()
42 | {}
43 |
44 | //------------------------------------------------------------------------------------------
45 | //
46 | // PUBLIC METHODS
47 | //
48 | //------------------------------------------------------------------------------------------
49 |
50 | /**
51 | */
52 | public final function getFrame():int
53 | {
54 | return frameIndex;
55 | }
56 |
57 | /**
58 | */
59 | public final function setFrame( index:int ):void
60 | {
61 | if( spriteFrameset.animated )
62 | {
63 | return;
64 | }
65 |
66 | if( index < 0 )
67 | {
68 | index = 0;
69 | }
70 | else if( index >= spriteFrameset.frameCount )
71 | {
72 | index = spriteFrameset.frameCount;
73 | }
74 |
75 | if( frameIndex != index )
76 | {
77 | frameIndex = index;
78 | spriteFrame = spriteFrameset.frameList[index];
79 | }
80 | }
81 |
82 | /**
83 | */
84 | public final function getFrameset():int
85 | {
86 | return framesetIndex;
87 | }
88 |
89 | /**
90 | */
91 | public final function setFrameset( index:int ):void
92 | {
93 | if( index < 0 )
94 | {
95 | index = 0;
96 | }
97 | else if( index >= spriteRX.framesetCount )
98 | {
99 | index = spriteRX.framesetCount - 1;
100 | }
101 |
102 | if( framesetIndex != index )
103 | {
104 | framesetIndex = index;
105 | spriteFrameset = spriteRX.framesetList[index];
106 |
107 | frameIndex = 0;
108 | spriteFrame = spriteFrameset.frameList[0];
109 |
110 | timeStamp = 0.0;
111 | }
112 | }
113 |
114 | //------------------------------------------------------------------------------------------
115 | //
116 | // INTERNAL METHODS
117 | //
118 | //------------------------------------------------------------------------------------------
119 |
120 | /**
121 | */
122 | internal override function construct( game:GameApp, rx:GraphicRX ):void
123 | {
124 | this.game = game;
125 |
126 | spriteRX = rx as SpriteRX;
127 | spriteFrameset = spriteRX.framesetList[0];
128 | spriteFrame = spriteFrameset.frameList[0];
129 |
130 | width = spriteRX.frameWidth;
131 | height = spriteRX.frameHeight;
132 |
133 | super.construct( game, rx );
134 | }
135 |
136 | /**
137 | */
138 | internal override function render( mesh:GraphicMesh ):void
139 | {
140 | if( spriteFrameset.animated )
141 | {
142 | var index:int = 0;
143 |
144 | if( timeStamp == 0.0 )
145 | {
146 | timeStamp = game.timeTotal;
147 | }
148 | else
149 | {
150 | index = ( game.timeTotal - timeStamp ) / spriteRX.frameTime;
151 |
152 | if( index < 0 )
153 | {
154 | index = 0;
155 | }
156 | else if( index >= spriteFrameset.frameCount )
157 | {
158 | if( spriteFrameset.repeated )
159 | {
160 | index %= spriteFrameset.frameCount;
161 | }
162 | else
163 | {
164 | index = spriteFrameset.frameCount - 1;
165 | }
166 | }
167 | }
168 |
169 | if( frameIndex != index )
170 | {
171 | frameIndex = index;
172 | spriteFrame = spriteFrameset.frameList[index];
173 | }
174 | }
175 |
176 | var x1:Number = mesh.x;
177 | var y1:Number = mesh.y;
178 | var x2:Number = x1 + width;
179 | var y2:Number = y1 + height;
180 |
181 | var i:int = mesh.vertexCount;
182 |
183 | mesh.vertexList[i++] = x1;
184 | mesh.vertexList[i++] = y1;
185 | mesh.vertexList[i++] = flipHorizontal ? spriteFrame.u2 : spriteFrame.u1;
186 | mesh.vertexList[i++] = flipVertical ? spriteFrame.v2 : spriteFrame.v1;
187 |
188 | mesh.vertexList[i++] = x2;
189 | mesh.vertexList[i++] = y1;
190 | mesh.vertexList[i++] = flipHorizontal ? spriteFrame.u1 : spriteFrame.u2;
191 | mesh.vertexList[i++] = flipVertical ? spriteFrame.v2 : spriteFrame.v1;
192 |
193 | mesh.vertexList[i++] = x1;
194 | mesh.vertexList[i++] = y2;
195 | mesh.vertexList[i++] = flipHorizontal ? spriteFrame.u2 : spriteFrame.u1;
196 | mesh.vertexList[i++] = flipVertical ? spriteFrame.v1 : spriteFrame.v2;
197 |
198 | mesh.vertexList[i++] = x2;
199 | mesh.vertexList[i++] = y2;
200 | mesh.vertexList[i++] = flipHorizontal ? spriteFrame.u1 : spriteFrame.u2;
201 | mesh.vertexList[i++] = flipVertical ? spriteFrame.v1 : spriteFrame.v2;
202 |
203 | mesh.vertexCount = i;
204 |
205 | i >>= 2;
206 |
207 | var j:int = mesh.indexCount;
208 |
209 | mesh.indexList[j++] = i - 1;
210 | mesh.indexList[j++] = i - 2;
211 | mesh.indexList[j++] = i - 3;
212 | mesh.indexList[j++] = i - 4;
213 | mesh.indexList[j++] = i - 3;
214 | mesh.indexList[j++] = i - 2;
215 |
216 | mesh.indexCount = j;
217 | }
218 |
219 | }// EOC
220 | }
--------------------------------------------------------------------------------
/framework/source/remx/Widget.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | /**
4 | */
5 | public class Widget extends Graphic
6 | {
7 | //------------------------------------------------------------------------------------------
8 | //
9 | // PUBLIC PROPERTIES
10 | //
11 | //------------------------------------------------------------------------------------------
12 |
13 | public var enabled:Boolean = true;
14 |
15 | //------------------------------------------------------------------------------------------
16 | //
17 | // PUBLIC PROPERTIES - EVENTS
18 | //
19 | //------------------------------------------------------------------------------------------
20 |
21 | public var onClick:Function = null; // ( widget:Widget ):void
22 | public var onPress:Function = null; // ( widget:Widget ):void
23 | public var onRelease:Function = null; // ( widget:Widget ):void
24 |
25 | //------------------------------------------------------------------------------------------
26 | //
27 | // PRIVATE PROPERTIES
28 | //
29 | //------------------------------------------------------------------------------------------
30 |
31 | private var game:GameApp = null;
32 |
33 | private var widgetRX:WidgetRX = null;
34 | private var widgetFrame:WidgetFrame = null;
35 |
36 | private var pressed:Boolean = false;
37 | private var hasMouse:Boolean = false;
38 |
39 | //------------------------------------------------------------------------------------------
40 | //
41 | // CONSTRUCTOR
42 | //
43 | //------------------------------------------------------------------------------------------
44 |
45 | /**
46 | */
47 | public function Widget()
48 | {
49 | interactive = true;
50 | }
51 |
52 | //------------------------------------------------------------------------------------------
53 | //
54 | // INTERNAL METHODS
55 | //
56 | //------------------------------------------------------------------------------------------
57 |
58 | /**
59 | */
60 | internal override function construct( game:GameApp, rx:GraphicRX ):void
61 | {
62 | this.game = game;
63 |
64 | widgetRX = rx as WidgetRX;
65 | widgetFrame = widgetRX.frameList[0];
66 |
67 | width = widgetRX.frameWidth;
68 | height = widgetRX.frameHeight;
69 |
70 | super.construct( game, rx );
71 | }
72 |
73 | /**
74 | */
75 | internal override function render( mesh:GraphicMesh ):void
76 | {
77 | var x1:Number = mesh.x;
78 | var y1:Number = mesh.y;
79 | var x2:Number = x1 + width;
80 | var y2:Number = y1 + height;
81 |
82 | var i:int = mesh.vertexCount;
83 |
84 | mesh.vertexList[i++] = x1;
85 | mesh.vertexList[i++] = y1;
86 | mesh.vertexList[i++] = widgetFrame.u1;
87 | mesh.vertexList[i++] = widgetFrame.v1;
88 |
89 | mesh.vertexList[i++] = x2;
90 | mesh.vertexList[i++] = y1;
91 | mesh.vertexList[i++] = widgetFrame.u2;
92 | mesh.vertexList[i++] = widgetFrame.v1;
93 |
94 | mesh.vertexList[i++] = x1;
95 | mesh.vertexList[i++] = y2;
96 | mesh.vertexList[i++] = widgetFrame.u1;
97 | mesh.vertexList[i++] = widgetFrame.v2;
98 |
99 | mesh.vertexList[i++] = x2;
100 | mesh.vertexList[i++] = y2;
101 | mesh.vertexList[i++] = widgetFrame.u2;
102 | mesh.vertexList[i++] = widgetFrame.v2;
103 |
104 | mesh.vertexCount = i;
105 |
106 | i >>= 2;
107 |
108 | var j:int = mesh.indexCount;
109 |
110 | mesh.indexList[j++] = i - 1;
111 | mesh.indexList[j++] = i - 2;
112 | mesh.indexList[j++] = i - 3;
113 | mesh.indexList[j++] = i - 4;
114 | mesh.indexList[j++] = i - 3;
115 | mesh.indexList[j++] = i - 2;
116 |
117 | mesh.indexCount = j;
118 | }
119 |
120 | /**
121 | */
122 | internal override function mouseEnter():void
123 | {
124 | pressed = game.controls.isMouseButtonPressed();
125 | hasMouse = true;
126 |
127 | if( pressed )
128 | {
129 | broadcastPress();
130 | }
131 |
132 | updateFrame();
133 | }
134 |
135 | /**
136 | */
137 | internal override function mouseHover():void
138 | {
139 | if( pressed == game.controls.isMouseButtonPressed() )
140 | {
141 | return;
142 | }
143 |
144 | pressed = game.controls.isMouseButtonPressed();
145 |
146 | if( pressed )
147 | {
148 | broadcastPress();
149 | }
150 | else
151 | {
152 | broadcastRelease();
153 | broadcastClick();
154 | }
155 |
156 | updateFrame();
157 | }
158 |
159 | /**
160 | */
161 | internal override function mouseLeave():void
162 | {
163 | hasMouse = false;
164 |
165 | if( pressed )
166 | {
167 | pressed = false;
168 | broadcastRelease();
169 | }
170 |
171 | updateFrame();
172 | }
173 |
174 | //------------------------------------------------------------------------------------------
175 | //
176 | // PRIVATE METHODS
177 | //
178 | //------------------------------------------------------------------------------------------
179 |
180 | /**
181 | */
182 | private function updateFrame():void
183 | {
184 | var index:int = enabled == false ? 3 : pressed ? 2 : hasMouse ? 1 : 0;
185 |
186 | if( index > widgetRX.frameCount )
187 | {
188 | index = widgetRX.frameCount;
189 | }
190 |
191 | widgetFrame = widgetRX.frameList[index];
192 | }
193 |
194 | //------------------------------------------------------------------------------------------
195 | //
196 | // PRIVATE METHODS - BROADCASTERS
197 | //
198 | //------------------------------------------------------------------------------------------
199 |
200 | /**
201 | */
202 | private function broadcastClick():void
203 | {
204 | if( enabled && onClick != null )
205 | {
206 | onClick( this );
207 | }
208 | }
209 |
210 | /**
211 | */
212 | private function broadcastPress():void
213 | {
214 | if( enabled && onPress != null )
215 | {
216 | onPress( this );
217 | }
218 | }
219 |
220 | /**
221 | */
222 | private function broadcastRelease():void
223 | {
224 | if( enabled && onRelease != null )
225 | {
226 | onRelease( this );
227 | }
228 | }
229 |
230 | }// EOC
231 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameStorage.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.utils.Dictionary;
4 | import flash.utils.getDefinitionByName;
5 | import flash.utils.getQualifiedClassName;
6 |
7 | RUNTIME::AIR
8 | {
9 | import flash.filesystem.File;
10 | import flash.filesystem.FileMode;
11 | import flash.filesystem.FileStream;
12 | }
13 |
14 | RUNTIME::FLASH
15 | {
16 | import flash.net.SharedObject;
17 | import flash.utils.ByteArray;
18 | }
19 |
20 | /**
21 | */
22 | public final class GameStorage extends GameSystem
23 | {
24 | //------------------------------------------------------------------------------------------
25 | //
26 | // PRIVATE PROPERTIES
27 | //
28 | //------------------------------------------------------------------------------------------
29 |
30 | private var game:GameApp = null;
31 |
32 | private var encodedCache:Dictionary = new Dictionary();
33 |
34 | RUNTIME::AIR
35 | private var file:File = new File();
36 |
37 | RUNTIME::AIR
38 | private var stream:FileStream = new FileStream();
39 |
40 | RUNTIME::FLASH
41 | private var so:SharedObject = SharedObject.getLocal( "remx.storage" );
42 |
43 | //------------------------------------------------------------------------------------------
44 | //
45 | // CONSTRUCTOR
46 | //
47 | //------------------------------------------------------------------------------------------
48 |
49 | /**
50 | */
51 | public function GameStorage()
52 | {}
53 |
54 | //------------------------------------------------------------------------------------------
55 | //
56 | // PUBLIC METHODS
57 | //
58 | //------------------------------------------------------------------------------------------
59 |
60 | /**
61 | */
62 | RUNTIME::AIR
63 | public function hasData( id:String ):Boolean
64 | {
65 | file.url = game.DATA_DIRECTORY + "/" + encodeID( id );
66 | return file.exists;
67 | }
68 |
69 | /**
70 | */
71 | RUNTIME::AIR
72 | public function getData( id:String ):*
73 | {
74 | file.url = game.DATA_DIRECTORY + "/" + encodeID( id );
75 |
76 | if( file.exists == false )
77 | {
78 | return null;
79 | }
80 |
81 | stream.open( file, FileMode.READ );
82 |
83 | var dataClass:Class = getDefinitionByName( stream.readUTF() ) as Class;
84 |
85 | var data:Data = new dataClass();
86 | data.restore( stream );
87 |
88 | stream.close();
89 |
90 | return data;
91 | }
92 |
93 | /**
94 | */
95 | RUNTIME::AIR
96 | public function setData( id:String, data:Data ):Boolean
97 | {
98 | file.url = game.DATA_DIRECTORY + "/" + encodeID( id );
99 |
100 | stream.open( file, FileMode.WRITE );
101 | stream.writeUTF( getQualifiedClassName( data ) );
102 |
103 | data.save( stream );
104 |
105 | stream.close();
106 |
107 | return true;
108 | }
109 |
110 | /**
111 | */
112 | RUNTIME::AIR
113 | public function deleteData( id:String ):Boolean
114 | {
115 | file.url = game.DATA_DIRECTORY + "/" + encodeID( id );
116 |
117 | if( file.exists )
118 | {
119 | file.deleteFile();
120 | return true;
121 | }
122 |
123 | return false;
124 | }
125 |
126 | /**
127 | */
128 | RUNTIME::AIR
129 | public function clear():Boolean
130 | {
131 | file.url = game.DATA_DIRECTORY;
132 |
133 | try
134 | {
135 | file.deleteDirectory( true );
136 | return true;
137 | }
138 | catch( error:Error )
139 | {}
140 |
141 | return false;
142 | }
143 |
144 | /**
145 | */
146 | RUNTIME::FLASH
147 | public function hasData( id:String ):Boolean
148 | {
149 | return so.data[encodeID( id )] != null;
150 | }
151 |
152 | /**
153 | */
154 | RUNTIME::FLASH
155 | public function getData( id:String ):*
156 | {
157 | var bytes:ByteArray = so.data[encodeID( id )];
158 |
159 | if( bytes == null )
160 | {
161 | return null;
162 | }
163 |
164 | bytes.position = 0;
165 |
166 | var dataClass:Class = getDefinitionByName( bytes.readUTF() ) as Class;
167 |
168 | var data:Data = new dataClass();
169 | data.restore( bytes );
170 |
171 | return data;
172 | }
173 |
174 | /**
175 | */
176 | RUNTIME::FLASH
177 | public function setData( id:String, data:Data ):Boolean
178 | {
179 | var bytes:ByteArray = new ByteArray();
180 |
181 | bytes.writeUTF( getQualifiedClassName( data ) );
182 |
183 | data.save( bytes );
184 |
185 | so.data[encodeID( id )] = bytes;
186 |
187 | return true;
188 | }
189 |
190 | /**
191 | */
192 | RUNTIME::FLASH
193 | public function deleteData( id:String ):Boolean
194 | {
195 | var bytes:ByteArray = so.data[encodeID( id )];
196 |
197 | if( bytes != null )
198 | {
199 | bytes.length = 0;
200 | delete so.data[encodeID( id )];
201 | return true;
202 | }
203 |
204 | return false;
205 | }
206 |
207 | /**
208 | */
209 | RUNTIME::FLASH
210 | public function clear():Boolean
211 | {
212 | var bytes:ByteArray;
213 |
214 | for( var id:String in so.data )
215 | {
216 | bytes = so.data[id];
217 | bytes.length = 0;
218 | delete so.data[id];
219 | }
220 |
221 | return true;
222 | }
223 |
224 | //------------------------------------------------------------------------------------------
225 | //
226 | // INTERNAL METHODS
227 | //
228 | //------------------------------------------------------------------------------------------
229 |
230 | /**
231 | */
232 | internal override function initialize( game:GameApp ):void
233 | {
234 | this.game = game;
235 | }
236 |
237 | //------------------------------------------------------------------------------------------
238 | //
239 | // PRIVATE METHODS
240 | //
241 | //------------------------------------------------------------------------------------------
242 |
243 | /**
244 | */
245 | private function encodeID( id:String ):String
246 | {
247 | if( encodedCache[id] != null )
248 | {
249 | return encodedCache[id];
250 | }
251 |
252 | var i:int = id.length;
253 | var a:Array = new Array( i );
254 |
255 | while( i-- )
256 | {
257 | a[i] = id.charCodeAt( i ).toString( 16 );
258 | }
259 |
260 | return encodedCache[id] = a.join( "" );
261 | }
262 |
263 | }// EOC
264 | }
--------------------------------------------------------------------------------
/framework/source/remx/Text.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.text.Font;
4 |
5 | /**
6 | */
7 | public class Text extends Graphic
8 | {
9 | //------------------------------------------------------------------------------------------
10 | //
11 | // PUBLIC PROPERTIES
12 | //
13 | //------------------------------------------------------------------------------------------
14 |
15 | public var maxWidth:Number = 0.0;
16 |
17 | //------------------------------------------------------------------------------------------
18 | //
19 | // PRIVATE PROPERTIES
20 | //
21 | //------------------------------------------------------------------------------------------
22 |
23 | private var game:GameApp = null;
24 |
25 | private var fontRX:FontRX = null;
26 |
27 | private var text:String = "";
28 | private var characters:Vector. = new Vector.();
29 |
30 | //------------------------------------------------------------------------------------------
31 | //
32 | // CONSTRUCTOR
33 | //
34 | //------------------------------------------------------------------------------------------
35 |
36 | /**
37 | */
38 | public function Text()
39 | {}
40 |
41 | //------------------------------------------------------------------------------------------
42 | //
43 | // PUBLIC METHODS
44 | //
45 | //------------------------------------------------------------------------------------------
46 |
47 | /**
48 | */
49 | public function getText():String
50 | {
51 | return text;
52 | }
53 |
54 | /**
55 | */
56 | public function setText( value:String ):void
57 | {
58 | width = 0.0;
59 | height = 0.0;
60 | text = value;
61 |
62 | var i:int = 0;
63 | var n:int = value.length;
64 |
65 | characters.length = n;
66 |
67 | if( n == 0 )
68 | {
69 | return;
70 | }
71 |
72 | var max:Number = maxWidth;
73 |
74 | if( max <= 0.0 || max > game.width )
75 | {
76 | max = game.width;
77 | }
78 |
79 | var x:Number = 0.0;
80 | var y:Number = 0.0;
81 | var word:int = 0;
82 | var code:int = 0;
83 | var char:TextCharacter;
84 |
85 | while( i < n )
86 | {
87 | width = x > width ? x : width;
88 | height = y;
89 |
90 | code = value.charCodeAt( i );
91 |
92 | if( code == 10 )
93 | {
94 | x = 0.0;
95 | y += fontRX.frameHeight + fontRX.leading;
96 | word = 0;
97 |
98 | characters[i] = null;
99 | i++;
100 | continue;
101 | }
102 | else if( code == 32 )
103 | {
104 | code = i != 0 ? value.charCodeAt( i - 1 ) : 0;
105 |
106 | if( code != 44 && code != 46 && code != 58 && code != 59 )
107 | {
108 | x += fontRX.frameWidth + fontRX.tracking;
109 |
110 | if( x > max )
111 | {
112 | x = 0.0;
113 | y += fontRX.frameHeight + fontRX.leading;
114 | }
115 | }
116 |
117 | word = 0;
118 |
119 | characters[i] = null;
120 | i++;
121 | continue;
122 | }
123 | else if( fontRX.frames[code] == null )
124 | {
125 | if( code > 96 && code < 123 )
126 | {
127 | code -= 32;
128 |
129 | if( fontRX.frames[code] == null )
130 | {
131 | characters[i] = null;
132 | i++;
133 | continue;
134 | }
135 | }
136 | else
137 | {
138 | characters[i] = null;
139 | i++;
140 | continue;
141 | }
142 | }
143 |
144 | char = characters[i];
145 |
146 | if( char == null )
147 | {
148 | char = new TextCharacter();
149 | }
150 |
151 | char.x = x;
152 | char.y = y;
153 | char.frame = fontRX.frames[code];
154 |
155 | characters[i] = char;
156 | word++;
157 |
158 | x += fontRX.frameWidth + fontRX.tracking;
159 |
160 | if( x > max )
161 | {
162 | x = 0.0;
163 |
164 | if( y != 0.0 )
165 | {
166 | y += fontRX.frameHeight + fontRX.leading;
167 | }
168 |
169 | var j:int = 0;
170 |
171 | while( j < word )
172 | {
173 | char = characters[ i - ( word - j - 1 ) ];
174 | char.x = x;
175 | char.y = y;
176 |
177 | x += fontRX.frameWidth + fontRX.tracking;
178 | j++;
179 | }
180 |
181 | if( x > max )
182 | {
183 | max = x;
184 | }
185 | }
186 |
187 | i++;
188 | }
189 |
190 | width += fontRX.frameWidth;
191 | height += fontRX.frameHeight;
192 | }
193 |
194 | //------------------------------------------------------------------------------------------
195 | //
196 | // INTERNAL METHODS
197 | //
198 | //------------------------------------------------------------------------------------------
199 |
200 | /**
201 | */
202 | internal override function construct( game:GameApp, rx:GraphicRX ):void
203 | {
204 | this.game = game;
205 |
206 | fontRX = rx as FontRX;
207 |
208 | super.construct( game, rx );
209 | }
210 |
211 | /**
212 | */
213 | internal override function render( mesh:GraphicMesh ):void
214 | {
215 | var x1:Number;
216 | var y1:Number;
217 | var x2:Number;
218 | var y2:Number;
219 | var i:int;
220 | var j:int;
221 | var c:TextCharacter;
222 |
223 | var ci:int = 0;
224 | var cn:int = characters.length;
225 |
226 | while( ci < cn )
227 | {
228 | c = characters[ci];
229 |
230 | if( c == null )
231 | {
232 | ci++;
233 | continue;
234 | }
235 |
236 | x1 = c.x + mesh.x;
237 | y1 = c.y + mesh.y;
238 | x2 = x1 + fontRX.frameWidth;
239 | y2 = y1 + fontRX.frameHeight;
240 |
241 | i = mesh.vertexCount;
242 |
243 | mesh.vertexList[i++] = x1;
244 | mesh.vertexList[i++] = y1;
245 | mesh.vertexList[i++] = c.frame.u1;
246 | mesh.vertexList[i++] = c.frame.v1;
247 |
248 | mesh.vertexList[i++] = x2;
249 | mesh.vertexList[i++] = y1;
250 | mesh.vertexList[i++] = c.frame.u2;
251 | mesh.vertexList[i++] = c.frame.v1;
252 |
253 | mesh.vertexList[i++] = x1;
254 | mesh.vertexList[i++] = y2;
255 | mesh.vertexList[i++] = c.frame.u1;
256 | mesh.vertexList[i++] = c.frame.v2;
257 |
258 | mesh.vertexList[i++] = x2;
259 | mesh.vertexList[i++] = y2;
260 | mesh.vertexList[i++] = c.frame.u2;
261 | mesh.vertexList[i++] = c.frame.v2;
262 |
263 | mesh.vertexCount = i;
264 |
265 | i >>= 2;
266 |
267 | j = mesh.indexCount;
268 |
269 | mesh.indexList[j++] = i - 1;
270 | mesh.indexList[j++] = i - 2;
271 | mesh.indexList[j++] = i - 3;
272 | mesh.indexList[j++] = i - 4;
273 | mesh.indexList[j++] = i - 3;
274 | mesh.indexList[j++] = i - 2;
275 |
276 | mesh.indexCount = j;
277 |
278 | ci++;
279 | }
280 | }
281 |
282 | }// EOC
283 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameNetwork.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.events.Event;
4 | import flash.events.IOErrorEvent;
5 | import flash.net.URLRequestMethod;
6 | import flash.net.URLStream;
7 | import flash.utils.ByteArray;
8 | import flash.utils.getDefinitionByName;
9 | import flash.utils.getQualifiedClassName;
10 |
11 | /**
12 | */
13 | public final class GameNetwork extends GameSystem
14 | {
15 | //------------------------------------------------------------------------------------------
16 | //
17 | // PUBLIC PROPERTIES - EVENTS
18 | //
19 | //------------------------------------------------------------------------------------------
20 |
21 | public var onRequestSent:Function = null; // ( requestID:uint ):void
22 | public var onResponse:Function = null; // ( requestID:uint, data:Data ):void
23 |
24 | //------------------------------------------------------------------------------------------
25 | //
26 | // PRIVATE PROPERTIES
27 | //
28 | //------------------------------------------------------------------------------------------
29 |
30 | private const REQUEST_METHOD:String = URLRequestMethod.POST;
31 | private const REQUEST_CONTENT_TYPE:String = "application/x-remx-data";
32 |
33 | private var game:GameApp = null;
34 |
35 | private var queue:Vector. = new Vector.();
36 |
37 | private var stream:URLStream = null;
38 |
39 | //------------------------------------------------------------------------------------------
40 | //
41 | // CONSTRUCTOR
42 | //
43 | //------------------------------------------------------------------------------------------
44 |
45 | /**
46 | */
47 | public function GameNetwork()
48 | {}
49 |
50 | //------------------------------------------------------------------------------------------
51 | //
52 | // PUBLIC METHODS
53 | //
54 | //------------------------------------------------------------------------------------------
55 |
56 | /**
57 | */
58 | public function sendRequest( uri:String, data:Data=null ):uint
59 | {
60 | var bytes:ByteArray = new ByteArray();
61 |
62 | bytes.writeUnsignedInt( game.config.gameUID );
63 |
64 | if( data != null )
65 | {
66 | bytes.writeUTF( getQualifiedClassName( data ) );
67 | data.save( bytes );
68 | }
69 | else
70 | {
71 | bytes.writeShort( 0 );
72 | }
73 |
74 | var nr:NetworkRequest = new NetworkRequest();
75 |
76 | nr.request.data = bytes;
77 | nr.request.method = REQUEST_METHOD;
78 | nr.request.contentType = REQUEST_CONTENT_TYPE;
79 |
80 | if( queue.push( nr ) == 1 )
81 | {
82 | sendNextRequest();
83 | }
84 |
85 | return nr.id;
86 | }
87 |
88 | //------------------------------------------------------------------------------------------
89 | //
90 | // INTERNAL METHODS
91 | //
92 | //------------------------------------------------------------------------------------------
93 |
94 | /**
95 | */
96 | internal override function initialize( game:GameApp ):void
97 | {
98 | this.game = game;
99 | }
100 |
101 | /**
102 | */
103 | internal override function shutdown():void
104 | {
105 | try
106 | {
107 | stream.close();
108 | }
109 | catch( error:Error )
110 | {}
111 | }
112 |
113 | /**
114 | */
115 | internal override function reset():void
116 | {
117 | onRequestSent = null;
118 | onResponse = null;
119 |
120 | try
121 | {
122 | stream.close();
123 | stream.removeEventListener( Event.OPEN, onStreamOpen );
124 | stream.removeEventListener( Event.COMPLETE, onStreamComplete );
125 | stream.removeEventListener( IOErrorEvent.IO_ERROR, onStreamIOError );
126 | stream = null;
127 | }
128 | catch( error:Error )
129 | {}
130 | }
131 |
132 | //------------------------------------------------------------------------------------------
133 | //
134 | // PRIVATE METHODS
135 | //
136 | //------------------------------------------------------------------------------------------
137 |
138 | /**
139 | */
140 | private function sendNextRequest():void
141 | {
142 | stream = new URLStream();
143 |
144 | stream.addEventListener( Event.OPEN, onStreamOpen );
145 | stream.addEventListener( Event.COMPLETE, onStreamComplete );
146 | stream.addEventListener( IOErrorEvent.IO_ERROR, onStreamIOError );
147 |
148 | try
149 | {
150 | stream.load( queue[0].request );
151 | }
152 | catch( error:Error )
153 | {
154 | throw new Exception( error.message );
155 | }
156 | }
157 |
158 | //------------------------------------------------------------------------------------------
159 | //
160 | // PRIVATE METHODS - BROADCASTERS
161 | //
162 | //------------------------------------------------------------------------------------------
163 |
164 | /**
165 | */
166 | private function broadcastRequestSent( requestID:uint ):void
167 | {
168 | if( onRequestSent != null )
169 | {
170 | onRequestSent( requestID );
171 | }
172 | }
173 |
174 | /**
175 | */
176 | private function broadcastResponse( requestID:uint, data:Data ):void
177 | {
178 | if( onResponse != null )
179 | {
180 | onResponse( requestID, data );
181 | }
182 | }
183 |
184 | //------------------------------------------------------------------------------------------
185 | //
186 | // PRIVATE METHODS - NATIVE EVENT LISTENERS
187 | //
188 | //------------------------------------------------------------------------------------------
189 |
190 | /**
191 | */
192 | private function onStreamOpen( event:Event ):void
193 | {
194 | broadcastRequestSent( queue[0].id );
195 | }
196 |
197 | /**
198 | */
199 | private function onStreamComplete( event:Event ):void
200 | {
201 | stream.removeEventListener( Event.OPEN, onStreamOpen );
202 | stream.removeEventListener( Event.COMPLETE, onStreamComplete );
203 | stream.removeEventListener( IOErrorEvent.IO_ERROR, onStreamIOError );
204 |
205 | var data:Data = null;
206 |
207 | if( stream.bytesAvailable != 0 )
208 | {
209 | var dataClass:Class = getDefinitionByName( stream.readUTF() ) as Class;
210 |
211 | data = new dataClass();
212 | data.restore( stream );
213 | }
214 |
215 | stream = null;
216 |
217 | broadcastResponse( queue.shift().id, data );
218 |
219 | if( queue.length != 0 && stream == null )
220 | {
221 | sendNextRequest();
222 | }
223 | }
224 |
225 | /**
226 | */
227 | private function onStreamIOError( event:IOErrorEvent ):void
228 | {
229 | throw new Exception( event.text );
230 | }
231 |
232 | }// EOC
233 | }
234 |
235 | import flash.net.URLRequest;
236 |
237 | /**
238 | */
239 | final class NetworkRequest
240 | {
241 | static private var nextID:uint = 1;
242 |
243 | public const id:uint = nextID++;
244 | public const request:URLRequest = new URLRequest();
245 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameProfiler.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.display.Bitmap;
4 | import flash.display.BitmapData;
5 | import flash.geom.Point;
6 | import flash.geom.Rectangle;
7 | import flash.system.System;
8 | import flash.utils.setInterval;
9 |
10 | /**
11 | */
12 | public final class GameProfiler extends GameSystem
13 | {
14 | //------------------------------------------------------------------------------------------
15 | //
16 | // ASSETS
17 | //
18 | //------------------------------------------------------------------------------------------
19 |
20 | [Embed( source="/profiler/graphics.png" )]
21 | static private const GraphicsPNG:Class;
22 |
23 | //------------------------------------------------------------------------------------------
24 | //
25 | // PRIVATE PROPERTIES
26 | //
27 | //------------------------------------------------------------------------------------------
28 |
29 | private const MB_BOLD:uint = 0;
30 | private const MB_REGULAR:uint = 1;
31 | private const HARDWARE:uint = 2;
32 | private const SOFTWARE:uint = 3;
33 | private const FRAME_RATE:uint = 4;
34 | private const FRAME_TIME:uint = 5;
35 | private const MEMORY:uint = 6;
36 | private const RENDERING_MODE:uint = 7;
37 |
38 | private const BACKGROUND:uint = 0xE0000000;
39 |
40 | private var game:GameApp = null;
41 |
42 | private var digitsBold:Vector. = null;
43 | private var digitsRegular:Vector. = null;
44 | private var textBlocks:Vector. = null;
45 |
46 | private var point:Point = null;
47 | private var bitmap:Bitmap = null;
48 | private var bitmapData:BitmapData = null;
49 | private var bitmapRect:Rectangle = null;
50 | private var graphics:BitmapData = null;
51 |
52 | private var updateCount:Number = 0.0;
53 | private var fpsCount:Number = 0.0;
54 | private var fpsTotal:Number = 0.0;
55 | private var frameCount:Number = 0.0;
56 | private var frameTime:Number = 0.0;
57 | private var frameTimeTotal:Number = 0.0;
58 | private var peakMemory:Number = 0.0;
59 |
60 | private var interval:uint = 0;
61 |
62 | //------------------------------------------------------------------------------------------
63 | //
64 | // CONSTRUCTOR
65 | //
66 | //------------------------------------------------------------------------------------------
67 |
68 | /**
69 | */
70 | public function GameProfiler()
71 | {}
72 |
73 | //------------------------------------------------------------------------------------------
74 | //
75 | // INTERNAL METHODS
76 | //
77 | //------------------------------------------------------------------------------------------
78 |
79 | /**
80 | */
81 | internal override function initialize( game:GameApp ):void
82 | {
83 | this.game = game;
84 |
85 | digitsBold = new [
86 | new Rectangle( 0.0, 0.0, 6.0, 7.0 ),
87 | new Rectangle( 7.0, 0.0, 3.0, 7.0 ),
88 | new Rectangle( 11.0, 0.0, 6.0, 7.0 ),
89 | new Rectangle( 18.0, 0.0, 6.0, 7.0 ),
90 | new Rectangle( 25.0, 0.0, 7.0, 7.0 ),
91 | new Rectangle( 33.0, 0.0, 6.0, 7.0 ),
92 | new Rectangle( 40.0, 0.0, 6.0, 7.0 ),
93 | new Rectangle( 47.0, 0.0, 6.0, 7.0 ),
94 | new Rectangle( 54.0, 0.0, 6.0, 7.0 ),
95 | new Rectangle( 61.0, 0.0, 6.0, 7.0 )
96 | ];
97 |
98 | digitsRegular = new [
99 | new Rectangle( 0.0, 8.0, 5.0, 7.0 ),
100 | new Rectangle( 6.0, 8.0, 2.0, 7.0 ),
101 | new Rectangle( 9.0, 8.0, 5.0, 7.0 ),
102 | new Rectangle( 15.0, 8.0, 5.0, 7.0 ),
103 | new Rectangle( 21.0, 8.0, 6.0, 7.0 ),
104 | new Rectangle( 28.0, 8.0, 5.0, 7.0 ),
105 | new Rectangle( 34.0, 8.0, 5.0, 7.0 ),
106 | new Rectangle( 40.0, 8.0, 5.0, 7.0 ),
107 | new Rectangle( 46.0, 8.0, 5.0, 7.0 ),
108 | new Rectangle( 52.0, 8.0, 5.0, 7.0 )
109 | ];
110 |
111 | textBlocks = new [
112 | new Rectangle( 68.0, 0.0, 14.0, 7.0 ),
113 | new Rectangle( 58.0, 8.0, 11.0, 7.0 ),
114 | new Rectangle( 0.0, 16.0, 49.0, 7.0 ),
115 | new Rectangle( 0.0, 24.0, 49.0, 7.0 ),
116 | new Rectangle( 0.0, 32.0, 66.0, 19.0 ),
117 | new Rectangle( 0.0, 52.0, 63.0, 19.0 ),
118 | new Rectangle( 0.0, 72.0, 43.0, 19.0 ),
119 | new Rectangle( 0.0, 93.0, 90.0, 7.0 )
120 | ];
121 |
122 | point = new Point();
123 | bitmap = new Bitmap();
124 | bitmapData = new BitmapData( game.width - 4, 39, true, BACKGROUND );
125 | bitmapRect = bitmapData.rect;
126 | graphics = Bitmap(new GraphicsPNG()).bitmapData;
127 |
128 | bitmap.x = 2.0;
129 | bitmap.y = 2.0;
130 | bitmap.bitmapData = bitmapData;
131 |
132 | game.stage.addChild( bitmap );
133 |
134 | interval = setInterval( updateStats, 1000.0 );
135 | }
136 |
137 | /**
138 | */
139 | internal override function update():void
140 | {
141 | fpsCount++;
142 | frameCount++;
143 | }
144 |
145 | /**
146 | */
147 | internal function startPass( t:Number ):void
148 | {
149 | frameTime = t;
150 | }
151 |
152 | /**
153 | */
154 | internal function endPass( t:Number ):void
155 | {
156 | frameTime = t - frameTime;
157 | frameTimeTotal += frameTime;
158 | }
159 |
160 | //------------------------------------------------------------------------------------------
161 | //
162 | // PRIVATE METHODS
163 | //
164 | //------------------------------------------------------------------------------------------
165 |
166 | /**
167 | */
168 | private function updateStats():void
169 | {
170 | updateCount++;
171 |
172 | bitmapData.fillRect( bitmapRect, BACKGROUND );
173 |
174 | draw( 10.0, 10.0, textBlocks[FRAME_RATE] );
175 | draw( 113.0, 10.0, textBlocks[FRAME_TIME] );
176 | draw( 213.0, 10.0, textBlocks[MEMORY] );
177 | draw( 318.0, 10.0, textBlocks[RENDERING_MODE] );
178 |
179 | var memory:Number = System.totalMemoryNumber / 1024.0 / 1024.0;
180 |
181 | if( peakMemory < memory )
182 | {
183 | peakMemory = memory;
184 | }
185 |
186 | fpsTotal += fpsCount;
187 |
188 | drawDigits2( 80.0, 10.0, Math.round( fpsCount ), true );
189 | drawDigits2( 55.0, 22.0, Math.round( fpsTotal / updateCount ) );
190 |
191 | fpsCount = 0.0;
192 |
193 | drawDigits2( 180.0, 10.0, Math.round( frameTime ), true );
194 | drawDigits2( 158.0, 22.0, Math.round( frameTimeTotal / frameCount ) );
195 |
196 | drawDigits3( 260.0, 10.0, memory, true );
197 | drawDigits3( 240.0, 22.0, peakMemory );
198 | draw( 284.0, 10.0, textBlocks[MB_BOLD] );
199 | draw( 261.0, 22.0, textBlocks[MB_REGULAR] );
200 |
201 | if( game.context.driverInfo == "Software" )
202 | {
203 | draw( 318.0, 22.0, textBlocks[SOFTWARE] );
204 | }
205 | else
206 | {
207 | draw( 318.0, 22.0, textBlocks[HARDWARE] );
208 | }
209 | }
210 |
211 | /**
212 | */
213 | private function draw( x:Number, y:Number, r:Rectangle ):void
214 | {
215 | point.x = x;
216 | point.y = y;
217 | bitmapData.copyPixels( graphics, r, point, null, null, true );
218 | }
219 |
220 | /**
221 | */
222 | private function drawDigits2( x:Number, y:Number, d:int, bold:Boolean=false ):void
223 | {
224 | var s:String = String(d);
225 | var i:int;
226 | var r:Rectangle;
227 |
228 | if( d < 10 )
229 | {
230 | s = "0" + s;
231 | }
232 |
233 | i = int(s.charAt( 0 ));
234 | r = bold ? digitsBold[i] : digitsRegular[i];
235 | draw( x, y, r );
236 |
237 | x = x + r.width + 1.0;
238 | i = int(s.charAt( 1 ));
239 | r = bold ? digitsBold[i] : digitsRegular[i];
240 | draw( x, y, r );
241 | }
242 |
243 | /**
244 | */
245 | private function drawDigits3( x:Number, y:Number, d:int, bold:Boolean=false ):void
246 | {
247 | var s:String = String(d);
248 | var i:int;
249 | var r:Rectangle;
250 |
251 | if( d < 10 )
252 | {
253 | s = "00" + s;
254 | }
255 | else if( d < 100 )
256 | {
257 | s = "0" + s;
258 | }
259 |
260 | i = int(s.charAt( 0 ));
261 | r = bold ? digitsBold[i] : digitsRegular[i];
262 | draw( x, y, r );
263 |
264 | x = x + r.width + 1.0;
265 | i = int(s.charAt( 1 ));
266 | r = bold ? digitsBold[i] : digitsRegular[i];
267 | draw( x, y, r );
268 |
269 | x = x + r.width + 1.0;
270 | i = int(s.charAt( 2 ));
271 | r = bold ? digitsBold[i] : digitsRegular[i];
272 | draw( x, y, r );
273 | }
274 |
275 | }// EOC
276 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameAudio.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.events.Event;
4 | import flash.events.IOErrorEvent;
5 | import flash.media.Sound;
6 | import flash.media.SoundChannel;
7 | import flash.media.SoundTransform;
8 | import flash.net.URLRequest;
9 | import flash.utils.Dictionary;
10 |
11 | /**
12 | */
13 | public final class GameAudio extends GameSystem
14 | {
15 | //------------------------------------------------------------------------------------------
16 | //
17 | // PUBLIC PROPERTIES
18 | //
19 | //------------------------------------------------------------------------------------------
20 |
21 | public var masterSoundVolume:Number = 1.0;
22 | public var masterMusicVolume:Number = 1.0;
23 |
24 | public var musicFadeTime:Number = 2.0;
25 |
26 | //------------------------------------------------------------------------------------------
27 | //
28 | // PRIVATE PROPERTIES
29 | //
30 | //------------------------------------------------------------------------------------------
31 |
32 | private const ERR_RESOURCE_NOT_FOUND:String =
33 | "%1 resource '%2' does not exist";
34 |
35 | private var game:GameApp = null;
36 |
37 | private var soundRegister:Dictionary = new Dictionary();
38 | private var musicRegister:Dictionary = new Dictionary();
39 |
40 | private var nextChannelID:uint = 1;
41 | private var channels:Dictionary = new Dictionary();
42 |
43 | private var musicRX:MusicRX = null;
44 | private var musicRX2:MusicRX = null;
45 | private var musicPlayer:Sound = null;
46 | private var musicChannel:SoundChannel = null;
47 | private var musicFading:Boolean = false;
48 | private var musicFadeStep:Number = 0.0;
49 | private var musicFadeVolume:Number = 0.0;
50 |
51 | private var transform:SoundTransform = new SoundTransform();
52 |
53 | //------------------------------------------------------------------------------------------
54 | //
55 | // CONSTRUCTOR
56 | //
57 | //------------------------------------------------------------------------------------------
58 |
59 | /**
60 | */
61 | public function GameAudio()
62 | {}
63 |
64 | //------------------------------------------------------------------------------------------
65 | //
66 | // PUBLIC METHODS
67 | //
68 | //------------------------------------------------------------------------------------------
69 |
70 | /**
71 | */
72 | public function playSound( soundID:String, volume:Number=1.0, balance:Number=0.0 ):uint
73 | {
74 | var sound:SoundRX = soundRegister[soundID];
75 |
76 | if( sound == null )
77 | {
78 | throw new Exception( ERR_RESOURCE_NOT_FOUND, "Sound", soundID );
79 | }
80 |
81 | transform.volume = volume * masterSoundVolume;
82 | transform.pan = balance;
83 |
84 | if( sound.repeated )
85 | {
86 | channels[nextChannelID] = sound.source.play( 0.0, int.MAX_VALUE, transform );
87 | return nextChannelID++;
88 | }
89 |
90 | sound.source.play( 0.0, 0, transform );
91 | return 0;
92 | }
93 |
94 | /**
95 | */
96 | public function stopSound( channelID:uint ):void
97 | {
98 | var channel:SoundChannel = channels[channelID];
99 |
100 | if( channel == null )
101 | {
102 | return;
103 | }
104 |
105 | channel.stop();
106 | delete channels[channelID];
107 | }
108 |
109 | /**
110 | */
111 | public function stopSounds():void
112 | {
113 | for( var id:* in channels )
114 | {
115 | SoundChannel(channels[id]).stop();
116 | delete channels[id];
117 | }
118 | }
119 |
120 | /**
121 | */
122 | public function setSoundVolume( channelID:uint, volume:Number ):void
123 | {
124 | var channel:SoundChannel = channels[channelID];
125 |
126 | if( channel == null )
127 | {
128 | return;
129 | }
130 |
131 | transform = channel.soundTransform;
132 | transform.volume = volume * masterSoundVolume;
133 |
134 | channel.soundTransform = transform;
135 | }
136 |
137 | /**
138 | */
139 | public function setSoundBalance( channelID:uint, balance:Number ):void
140 | {
141 | var channel:SoundChannel = channels[channelID];
142 |
143 | if( channel == null )
144 | {
145 | return;
146 | }
147 |
148 | transform = channel.soundTransform;
149 | transform.pan = balance;
150 |
151 | channel.soundTransform = transform;
152 | }
153 |
154 | /**
155 | */
156 | public function playMusic( musicID:String ):void
157 | {
158 | var music:MusicRX = musicRegister[musicID];
159 |
160 | if( music == null )
161 | {
162 | throw new Exception( ERR_RESOURCE_NOT_FOUND, "Music", musicID );
163 | }
164 |
165 | stopMusic();
166 |
167 | if( musicFading )
168 | {
169 | musicRX2 = music;
170 | return;
171 | }
172 |
173 | musicRX = music;
174 | startMusic();
175 | }
176 |
177 | /**
178 | */
179 | public function stopMusic():void
180 | {
181 | musicRX2 = null;
182 |
183 | if( musicRX == null || musicFading )
184 | {
185 | return;
186 | }
187 |
188 | if( musicFadeTime > 0.0 )
189 | {
190 | musicFadeVolume = musicChannel.soundTransform.volume;
191 | musicFadeStep = musicFadeVolume / ( musicFadeTime * game.config.gameFrameRate );
192 | musicFading = true;
193 | return;
194 | }
195 |
196 | musicChannel.removeEventListener( Event.SOUND_COMPLETE, onMusicComplete );
197 | musicChannel.stop();
198 |
199 | try
200 | {
201 | musicPlayer.removeEventListener( IOErrorEvent.IO_ERROR, onMusicIOError );
202 | musicPlayer.close();
203 | }
204 | catch( error:Error )
205 | {}
206 |
207 | musicRX = null;
208 | musicPlayer = null;
209 | }
210 |
211 | //------------------------------------------------------------------------------------------
212 | //
213 | // INTERNAL METHODS
214 | //
215 | //------------------------------------------------------------------------------------------
216 |
217 | /**
218 | */
219 | internal override function initialize( game:GameApp ):void
220 | {
221 | this.game = game;
222 | }
223 |
224 | /**
225 | */
226 | internal override function update():void
227 | {
228 | if( musicFading == false )
229 | {
230 | return;
231 | }
232 |
233 | musicFadeVolume -= musicFadeStep * game.timeDelta;
234 |
235 | if( musicFadeVolume > 0.0 )
236 | {
237 | transform.volume = musicFadeVolume;
238 | transform.pan = 0.0;
239 | musicChannel.soundTransform = transform;
240 | return
241 | }
242 |
243 | musicChannel.removeEventListener( Event.SOUND_COMPLETE, onMusicComplete );
244 | musicChannel.stop();
245 |
246 | try
247 | {
248 | musicPlayer.removeEventListener( IOErrorEvent.IO_ERROR, onMusicIOError );
249 | musicPlayer.close();
250 | }
251 | catch( error:Error )
252 | {}
253 |
254 | musicRX = musicRX2;
255 | musicRX2 = null;
256 | musicPlayer = null;
257 | musicFading = false;
258 |
259 | startMusic();
260 | }
261 |
262 | /**
263 | */
264 | internal function registerSound( sound:SoundRX ):void
265 | {
266 | soundRegister[sound.id] = sound;
267 | }
268 |
269 | /**
270 | */
271 | internal function unregisterSound( sound:SoundRX ):void
272 | {
273 | delete soundRegister[sound.id];
274 | }
275 |
276 | /**
277 | */
278 | internal function registerMusic( music:MusicRX ):void
279 | {
280 | musicRegister[music.id] = music;
281 | }
282 |
283 | /**
284 | */
285 | internal function unregisterMusic( music:MusicRX ):void
286 | {
287 | delete musicRegister[music.id];
288 | }
289 |
290 | //------------------------------------------------------------------------------------------
291 | //
292 | // PRIVATE METHODS
293 | //
294 | //------------------------------------------------------------------------------------------
295 |
296 | /**
297 | */
298 | private function startMusic():void
299 | {
300 | if( musicRX == null )
301 | {
302 | return;
303 | }
304 |
305 | musicPlayer = new Sound();
306 | musicPlayer.addEventListener( IOErrorEvent.IO_ERROR, onMusicIOError );
307 |
308 | try
309 | {
310 | musicPlayer.load( new URLRequest( musicRX.path ) );
311 | }
312 | catch( error:Error )
313 | {
314 | throw new Exception( error.message );
315 | }
316 |
317 | transform.volume = masterMusicVolume;
318 | transform.pan = 0.0;
319 |
320 | musicChannel = musicPlayer.play( 0.0, 0, transform );
321 | musicChannel.addEventListener( Event.SOUND_COMPLETE, onMusicComplete );
322 | }
323 |
324 | //------------------------------------------------------------------------------------------
325 | //
326 | // PRIVATE METHODS - NATIVE EVENT LISTENERS
327 | //
328 | //------------------------------------------------------------------------------------------
329 |
330 | /**
331 | */
332 | private function onMusicComplete( event:Event ):void
333 | {
334 | musicChannel.removeEventListener( Event.SOUND_COMPLETE, onMusicComplete );
335 |
336 | try
337 | {
338 | musicPlayer.removeEventListener( IOErrorEvent.IO_ERROR, onMusicIOError );
339 | musicPlayer.close();
340 | }
341 | catch( error:Error )
342 | {}
343 |
344 | if( musicRX.repeated )
345 | {
346 | startMusic();
347 | return;
348 | }
349 |
350 | musicRX = null;
351 | musicPlayer = null;
352 | }
353 |
354 | /**
355 | */
356 | private function onMusicIOError( event:IOErrorEvent ):void
357 | {
358 | throw new Exception( event.text );
359 | }
360 |
361 | }// EOC
362 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameControls.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.events.KeyboardEvent;
4 | import flash.events.MouseEvent;
5 | import flash.events.TouchEvent;
6 | import flash.system.Capabilities;
7 | import flash.system.TouchscreenType;
8 | import flash.ui.Multitouch;
9 | import flash.ui.MultitouchInputMode;
10 | import flash.utils.Dictionary;
11 |
12 | /**
13 | */
14 | public final class GameControls extends GameSystem
15 | {
16 | //------------------------------------------------------------------------------------------
17 | //
18 | // PUBLIC PROPERTIES
19 | //
20 | //------------------------------------------------------------------------------------------
21 |
22 | public const MOUSE_BUTTON_LEFT:uint = 0;
23 | public const MOUSE_BUTTON_RIGHT:uint = 1;
24 |
25 | public var mouseX:Number = 0.0;
26 | public var mouseY:Number = 0.0;
27 |
28 | //------------------------------------------------------------------------------------------
29 | //
30 | // PUBLIC PROPERTIES - EVENTS
31 | //
32 | //------------------------------------------------------------------------------------------
33 |
34 | public var onKeyPress:Function = null; // ( key:uint ):void
35 | public var onKeyRelease:Function = null; // ( key:uint ):void
36 | public var onMouseButtonPress:Function = null; // ( button:uint ):void
37 | public var onMouseButtonRelease:Function = null; // ( button:uint ):void
38 |
39 | //------------------------------------------------------------------------------------------
40 | //
41 | // PRIVATE PROPERTIES
42 | //
43 | //------------------------------------------------------------------------------------------
44 |
45 | private var game:GameApp = null;
46 |
47 | private var pressedKeys:Dictionary = new Dictionary();
48 | private var pressedMouseButtons:Dictionary = new Dictionary();
49 |
50 | private var touchPointID:int = 0;
51 |
52 | //------------------------------------------------------------------------------------------
53 | //
54 | // CONSTRUCTOR
55 | //
56 | //------------------------------------------------------------------------------------------
57 |
58 | /**
59 | */
60 | public function GameControls()
61 | {}
62 |
63 | //------------------------------------------------------------------------------------------
64 | //
65 | // PUBLIC METHODS
66 | //
67 | //------------------------------------------------------------------------------------------
68 |
69 | /**
70 | */
71 | public function pressKey( key:uint ):void
72 | {
73 | if( pressedKeys[key] == null )
74 | {
75 | pressedKeys[key] = key;
76 | broadcastKeyPress( key );
77 | }
78 | }
79 |
80 | /**
81 | */
82 | public function releaseKey( key:uint ):void
83 | {
84 | if( pressedKeys[key] != null )
85 | {
86 | delete pressedKeys[key];
87 | broadcastKeyRelease( key );
88 | }
89 | }
90 |
91 | /**
92 | */
93 | public function releaseKeys():void
94 | {
95 | for each( var key:uint in pressedKeys )
96 | {
97 | releaseKey( key );
98 | }
99 | }
100 |
101 | /**
102 | */
103 | public function isKeyPressed( key:uint ):Boolean
104 | {
105 | return pressedKeys[key] != null;
106 | }
107 |
108 | /**
109 | */
110 | public function pressMouseButton( button:uint=0 ):void
111 | {
112 | if( pressedMouseButtons[button] == null )
113 | {
114 | pressedMouseButtons[button] = button;
115 | broadcastMouseButtonPress( button );
116 | }
117 | }
118 |
119 | /**
120 | */
121 | public function releaseMouseButton( button:uint=0 ):void
122 | {
123 | if( pressedMouseButtons[button] != null )
124 | {
125 | delete pressedMouseButtons[button];
126 | broadcastMouseButtonRelease( button );
127 | }
128 | }
129 |
130 | /**
131 | */
132 | public function releaseMouseButtons():void
133 | {
134 | for each( var button:uint in pressedMouseButtons )
135 | {
136 | releaseMouseButton( button );
137 | }
138 | }
139 |
140 | /**
141 | */
142 | public function isMouseButtonPressed( button:uint=0 ):Boolean
143 | {
144 | return pressedMouseButtons[button] != null;
145 | }
146 |
147 | //------------------------------------------------------------------------------------------
148 | //
149 | // INTERNAL METHODS
150 | //
151 | //------------------------------------------------------------------------------------------
152 |
153 | /**
154 | */
155 | internal override function initialize( game:GameApp ):void
156 | {
157 | this.game = game;
158 |
159 | game.stage.addEventListener( KeyboardEvent.KEY_DOWN, onKeyDown );
160 | game.stage.addEventListener( KeyboardEvent.KEY_UP, onKeyUp );
161 |
162 | if( Capabilities.touchscreenType == TouchscreenType.NONE )
163 | {
164 | game.stage.addEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
165 | game.stage.addEventListener( MouseEvent.MOUSE_UP, onMouseUp );
166 |
167 | RUNTIME::AIR
168 | {
169 | game.stage.addEventListener( MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown );
170 | game.stage.addEventListener( MouseEvent.RIGHT_MOUSE_UP, onRightMouseUp );
171 | }
172 | }
173 | else
174 | {
175 | Multitouch.inputMode = MultitouchInputMode.TOUCH_POINT;
176 |
177 | game.stage.addEventListener( TouchEvent.TOUCH_BEGIN, onTouchBegin );
178 | game.stage.addEventListener( TouchEvent.TOUCH_END, onTouchEnd );
179 | }
180 | }
181 |
182 | /**
183 | */
184 | internal override function shutdown():void
185 | {
186 | game.stage.removeEventListener( KeyboardEvent.KEY_DOWN, onKeyDown );
187 | game.stage.removeEventListener( KeyboardEvent.KEY_UP, onKeyUp );
188 |
189 | if( Capabilities.touchscreenType == TouchscreenType.NONE )
190 | {
191 | game.stage.removeEventListener( MouseEvent.MOUSE_DOWN, onMouseDown );
192 | game.stage.removeEventListener( MouseEvent.MOUSE_UP, onMouseUp );
193 |
194 | RUNTIME::AIR
195 | {
196 | game.stage.removeEventListener( MouseEvent.RIGHT_MOUSE_DOWN, onRightMouseDown );
197 | game.stage.removeEventListener( MouseEvent.RIGHT_MOUSE_UP, onRightMouseUp );
198 | }
199 | }
200 | else
201 | {
202 | game.stage.removeEventListener( TouchEvent.TOUCH_BEGIN, onTouchBegin );
203 | game.stage.removeEventListener( TouchEvent.TOUCH_END, onTouchEnd );
204 | }
205 | }
206 |
207 | /**
208 | */
209 | internal override function update():void
210 | {
211 | var x:Number = game.stage.mouseX;
212 | var y:Number = game.stage.mouseY;
213 |
214 | mouseX = x < 0.0 ? 0.0 : x >= game.width ? game.width - 1.0 : x;
215 | mouseY = y < 0.0 ? 0.0 : y >= game.height ? game.height - 1.0 : y;
216 | }
217 |
218 | /**
219 | */
220 | internal override function reset():void
221 | {
222 | onKeyPress = null;
223 | onKeyRelease = null;
224 | onMouseButtonPress = null;
225 | onMouseButtonRelease = null;
226 |
227 | releaseKeys();
228 | releaseMouseButtons();
229 | }
230 |
231 | //------------------------------------------------------------------------------------------
232 | //
233 | // PRIVATE METHODS - BROADCASTERS
234 | //
235 | //------------------------------------------------------------------------------------------
236 |
237 | /**
238 | */
239 | private function broadcastKeyPress( key:uint ):void
240 | {
241 | if( onKeyPress != null )
242 | {
243 | onKeyPress( key );
244 | }
245 | }
246 |
247 | /**
248 | */
249 | private function broadcastKeyRelease( key:uint ):void
250 | {
251 | if( onKeyRelease != null )
252 | {
253 | onKeyRelease( key );
254 | }
255 | }
256 |
257 | /**
258 | */
259 | private function broadcastMouseButtonPress( button:uint ):void
260 | {
261 | if( onMouseButtonPress != null )
262 | {
263 | onMouseButtonPress( button );
264 | }
265 | }
266 |
267 | /**
268 | */
269 | private function broadcastMouseButtonRelease( button:uint ):void
270 | {
271 | if( onMouseButtonRelease != null )
272 | {
273 | onMouseButtonRelease( button );
274 | }
275 | }
276 |
277 | //------------------------------------------------------------------------------------------
278 | //
279 | // PRIVATE METHODS - NATIVE EVENT LISTENERS
280 | //
281 | //------------------------------------------------------------------------------------------
282 |
283 | /**
284 | */
285 | private function onKeyDown( event:KeyboardEvent ):void
286 | {
287 | pressKey( event.keyCode );
288 | }
289 |
290 | /**
291 | */
292 | private function onKeyUp( event:KeyboardEvent ):void
293 | {
294 | releaseKey( event.keyCode );
295 | }
296 |
297 | /**
298 | */
299 | private function onMouseDown( event:MouseEvent ):void
300 | {
301 | pressMouseButton( MOUSE_BUTTON_LEFT );
302 | }
303 |
304 | /**
305 | */
306 | private function onMouseUp( event:MouseEvent ):void
307 | {
308 | releaseMouseButton( MOUSE_BUTTON_LEFT );
309 | }
310 |
311 | /**
312 | */
313 | RUNTIME::AIR
314 | private function onRightMouseDown( event:MouseEvent ):void
315 | {
316 | pressMouseButton( MOUSE_BUTTON_RIGHT );
317 | }
318 |
319 | /**
320 | */
321 | RUNTIME::AIR
322 | private function onRightMouseUp( event:MouseEvent ):void
323 | {
324 | releaseMouseButton( MOUSE_BUTTON_RIGHT );
325 | }
326 |
327 | /**
328 | */
329 | private function onTouchBegin( event:TouchEvent ):void
330 | {
331 | if( touchPointID == 0 )
332 | {
333 | touchPointID = event.touchPointID;
334 | pressMouseButton( MOUSE_BUTTON_LEFT );
335 | }
336 | }
337 |
338 | /**
339 | */
340 | private function onTouchEnd( event:TouchEvent ):void
341 | {
342 | if( touchPointID == event.touchPointID )
343 | {
344 | touchPointID = 0;
345 | releaseMouseButton( MOUSE_BUTTON_LEFT );
346 | }
347 | }
348 |
349 | }// EOC
350 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameResource.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.display.BitmapData;
4 | import flash.utils.Dictionary;
5 |
6 | /**
7 | */
8 | public final class GameResource extends GameSystem
9 | {
10 | //------------------------------------------------------------------------------------------
11 | //
12 | // PUBLIC PROPERTIES - EVENTS
13 | //
14 | //------------------------------------------------------------------------------------------
15 |
16 | public var onLoadStart:Function = null; // ( packageID:String ):void
17 | public var onLoadComplete:Function = null; // ( packageID:String ):void
18 | public var onLoadProgress:Function = null; // ( packageID:String, progress:Number ):void
19 |
20 | //------------------------------------------------------------------------------------------
21 | //
22 | // PRIVATE PROPERTIES
23 | //
24 | //------------------------------------------------------------------------------------------
25 |
26 | private const ERR_RESOURCE_NOT_FOUND:String =
27 | "Resource package '%1' has not been registered";
28 |
29 | private const ERR_RESOURCE_RX_NOT_FOUND:String =
30 | "%1 resource '%2' does not exist";
31 |
32 | private const DATA:String = "Data";
33 | private const FONT:String = "Font";
34 | private const SPRITE:String = "Sprite";
35 | private const TILESET:String = "Tileset";
36 | private const WIDGET:String = "Widget";
37 |
38 | //
39 | private var game:GameApp = null;
40 |
41 | //
42 | private var resources:Dictionary = new Dictionary();
43 |
44 | //
45 | private var queue:Vector. = new Vector.();
46 |
47 | //
48 | private var loader:ResourceLoader = null;
49 |
50 | //------------------------------------------------------------------------------------------
51 | //
52 | // CONSTRUCTOR
53 | //
54 | //------------------------------------------------------------------------------------------
55 |
56 | /**
57 | */
58 | public function GameResource()
59 | {}
60 |
61 | //------------------------------------------------------------------------------------------
62 | //
63 | // PUBLIC METHODS
64 | //
65 | //------------------------------------------------------------------------------------------
66 |
67 | /**
68 | */
69 | public function load( packageID:String ):Boolean
70 | {
71 | if( resources[packageID] != null )
72 | {
73 | return false;
74 | }
75 |
76 | var resource:ResourcePackage;
77 |
78 | for each( resource in queue )
79 | {
80 | if( resource.id == packageID )
81 | {
82 | return false;
83 | }
84 | }
85 |
86 | var descriptorPath:String = game.config.descriptorPaths[packageID];
87 |
88 | if( descriptorPath == null )
89 | {
90 | throw new Exception( ERR_RESOURCE_NOT_FOUND, packageID );
91 | }
92 |
93 | resource = new ResourcePackage();
94 | resource.id = packageID;
95 | resource.path = descriptorPath;
96 |
97 | if( queue.push( resource ) == 1 )
98 | {
99 | loadResource();
100 | }
101 |
102 | return true;
103 | }
104 |
105 | /**
106 | */
107 | public function unload( packageID:String ):Boolean
108 | {
109 | var resource:ResourcePackage = resources[packageID];
110 |
111 | if( resource != null )
112 | {
113 | for each( var image:BitmapData in resource.images )
114 | {
115 | game.graphics.unregisterImage( image );
116 | }
117 |
118 | for each( var sound:SoundRX in resource.sounds )
119 | {
120 | game.audio.unregisterSound( sound );
121 | }
122 |
123 | for each( var music:MusicRX in resource.music )
124 | {
125 | game.audio.unregisterMusic( music );
126 | }
127 |
128 | resource.dispose();
129 | delete resources[packageID];
130 | return true;
131 | }
132 |
133 | var i:int = 1;
134 | var n:int = queue.length;
135 |
136 | while( i < n )
137 | {
138 | if( queue[i].id == packageID )
139 | {
140 | queue.splice( i, 1 );
141 | return true;
142 | }
143 | }
144 |
145 | return false;
146 | }
147 |
148 | /**
149 | */
150 | public function createData( dataID:String, dataClass:Class ):*
151 | {
152 | var rx:DataRX;
153 |
154 | for each( var resource:ResourcePackage in resources )
155 | {
156 | if( ( rx = resource.data[dataID] ) != null )
157 | {
158 | break;
159 | }
160 | }
161 |
162 | if( rx == null )
163 | {
164 | throw new Exception( ERR_RESOURCE_RX_NOT_FOUND, DATA, dataID );
165 | }
166 |
167 | var data:Data = new dataClass();
168 | data.construct( rx );
169 |
170 | return data;
171 | }
172 |
173 | /**
174 | */
175 | public function createGrid( tilesetID:String, gridClass:Class=null ):*
176 | {
177 | var rx:TilesetRX;
178 |
179 | for each( var resource:ResourcePackage in resources )
180 | {
181 | if( ( rx = resource.tilesets[tilesetID] ) != null )
182 | {
183 | break;
184 | }
185 | }
186 |
187 | if( rx == null )
188 | {
189 | throw new Exception( ERR_RESOURCE_RX_NOT_FOUND, TILESET, tilesetID );
190 | }
191 |
192 | var grid:Grid = gridClass == null ? new Grid() : new gridClass();
193 | grid.construct( game, rx );
194 |
195 | return grid;
196 | }
197 |
198 | /**
199 | */
200 | public function createSprite( spriteID:String, spriteClass:Class=null ):*
201 | {
202 | var rx:SpriteRX;
203 |
204 | for each( var resource:ResourcePackage in resources )
205 | {
206 | if( ( rx = resource.sprites[spriteID] ) != null )
207 | {
208 | break;
209 | }
210 | }
211 |
212 | if( rx == null )
213 | {
214 | throw new Exception( ERR_RESOURCE_RX_NOT_FOUND, SPRITE, spriteID );
215 | }
216 |
217 | var sprite:Sprite = spriteClass == null ? new Sprite() : new spriteClass();
218 | sprite.construct( game, rx );
219 |
220 | return sprite;
221 | }
222 |
223 | /**
224 | */
225 | public function createText( fontID:String, textClass:Class=null ):*
226 | {
227 | var rx:FontRX;
228 |
229 | for each( var resource:ResourcePackage in resources )
230 | {
231 | if( ( rx = resource.fonts[fontID] ) != null )
232 | {
233 | break;
234 | }
235 | }
236 |
237 | if( rx == null )
238 | {
239 | throw new Exception( ERR_RESOURCE_RX_NOT_FOUND, FONT, fontID );
240 | }
241 |
242 | var text:Text = textClass == null ? new Text() : new textClass();
243 | text.construct( game, rx );
244 |
245 | return text;
246 | }
247 |
248 | /**
249 | */
250 | public function createWidget( widgetID:String, widgetClass:Class=null ):*
251 | {
252 | var rx:WidgetRX;
253 |
254 | for each( var resource:ResourcePackage in resources )
255 | {
256 | if( ( rx = resource.widgets[widgetID] ) != null )
257 | {
258 | break;
259 | }
260 | }
261 |
262 | if( rx == null )
263 | {
264 | throw new Exception( ERR_RESOURCE_RX_NOT_FOUND, WIDGET, widgetID );
265 | }
266 |
267 | var widget:Widget = widgetClass == null ? new Widget() : new widgetClass();
268 | widget.construct( game, rx );
269 |
270 | return widget;
271 | }
272 |
273 | //------------------------------------------------------------------------------------------
274 | //
275 | // INTERNAL METHODS
276 | //
277 | //------------------------------------------------------------------------------------------
278 |
279 | /**
280 | */
281 | internal override function initialize( game:GameApp ):void
282 | {
283 | this.game = game;
284 | }
285 |
286 | /**
287 | */
288 | internal override function shutdown():void
289 | {
290 | if( loader != null )
291 | {
292 | loader.abort();
293 | }
294 | }
295 |
296 | /**
297 | */
298 | internal override function update():void
299 | {
300 | if( loader == null )
301 | {
302 | return;
303 | }
304 |
305 | loader.update();
306 |
307 | if( loader.progress != 1.0 )
308 | {
309 | broadcastLoadProgress( queue[0].id, loader.progress );
310 | return;
311 | }
312 |
313 | loader = null;
314 |
315 | var resource:ResourcePackage = queue.shift();
316 | resources[resource.id] = resource;
317 |
318 | for each( var image:BitmapData in resource.images )
319 | {
320 | game.graphics.registerImage( image );
321 | }
322 |
323 | for each( var sound:SoundRX in resource.sounds )
324 | {
325 | game.audio.registerSound( sound );
326 | }
327 |
328 | for each( var music:MusicRX in resource.music )
329 | {
330 | game.audio.registerMusic( music );
331 | }
332 |
333 | broadcastLoadComplete( resource.id );
334 |
335 | if( queue.length != 0 && loader == null )
336 | {
337 | loadResource();
338 | }
339 | }
340 |
341 | /**
342 | */
343 | internal override function reset():void
344 | {
345 | if( queue.length > 1 )
346 | {
347 | queue.length = 1;
348 | }
349 |
350 | onLoadStart = null;
351 | onLoadComplete = null;
352 | onLoadProgress = null;
353 | }
354 |
355 | //------------------------------------------------------------------------------------------
356 | //
357 | // PRIVATE METHODS
358 | //
359 | //------------------------------------------------------------------------------------------
360 |
361 | /**
362 | */
363 | private function loadResource():void
364 | {
365 | var resource:ResourcePackage = queue[0];
366 |
367 | loader = new ResourceLoader();
368 | loader.load( resource );
369 |
370 | broadcastLoadStart( resource.id );
371 | }
372 |
373 | //------------------------------------------------------------------------------------------
374 | //
375 | // PRIVATE METHODS - BROADCASTERS
376 | //
377 | //------------------------------------------------------------------------------------------
378 |
379 | /**
380 | */
381 | private function broadcastLoadStart( packageID:String ):void
382 | {
383 | if( onLoadStart != null )
384 | {
385 | onLoadStart( packageID );
386 | }
387 | }
388 |
389 | /**
390 | */
391 | private function broadcastLoadComplete( packageID:String ):void
392 | {
393 | if( onLoadComplete != null )
394 | {
395 | onLoadComplete( packageID );
396 | }
397 | }
398 |
399 | /**
400 | */
401 | private function broadcastLoadProgress( packageID:String, progress:Number ):void
402 | {
403 | if( onLoadProgress != null )
404 | {
405 | onLoadProgress( packageID, progress );
406 | }
407 | }
408 |
409 | }// EOC
410 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameGraphics.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import com.adobe.utils.AGALMiniAssembler;
4 |
5 | import flash.display.BitmapData;
6 | import flash.display.ShaderParameterType;
7 | import flash.display3D.Context3DBlendFactor;
8 | import flash.display3D.Context3DCompareMode;
9 | import flash.display3D.Context3DProgramType;
10 | import flash.display3D.Context3DTextureFormat;
11 | import flash.display3D.IndexBuffer3D;
12 | import flash.display3D.Program3D;
13 | import flash.display3D.VertexBuffer3D;
14 | import flash.display3D.textures.Texture;
15 | import flash.geom.Rectangle;
16 | import flash.utils.ByteArray;
17 | import flash.utils.Dictionary;
18 |
19 | /**
20 | */
21 | public final class GameGraphics extends GameSystem
22 | {
23 | //------------------------------------------------------------------------------------------
24 | //
25 | // STATIC - PRIVATE PROPERTIES
26 | //
27 | //------------------------------------------------------------------------------------------
28 |
29 | static private const ASSEMBLER:AGALMiniAssembler = new AGALMiniAssembler();
30 |
31 | static private const FRAGMENT_SHADER:String = Context3DProgramType.FRAGMENT;
32 | static private const VERTEX_SHADER:String = Context3DProgramType.VERTEX;
33 |
34 | static private const BLEND_SOURCE:String = Context3DBlendFactor.SOURCE_ALPHA;
35 | static private const BLEND_DESTINATION:String = Context3DBlendFactor.ONE_MINUS_SOURCE_ALPHA;
36 |
37 | static private const DEPTH_TEST:String = Context3DCompareMode.NEVER;
38 |
39 | static private const BGRA:String = Context3DTextureFormat.BGRA;
40 | static private const FLOAT2:String = ShaderParameterType.FLOAT2;
41 | static private const FLOAT3:String = ShaderParameterType.FLOAT3;
42 | static private const FLOAT4:String = ShaderParameterType.FLOAT4;
43 |
44 | //------------------------------------------------------------------------------------------
45 | //
46 | // PUBLIC PROPERTIES
47 | //
48 | //------------------------------------------------------------------------------------------
49 |
50 | public var cameraX:Number = 0.0;
51 | public var cameraY:Number = 0.0;
52 |
53 | //------------------------------------------------------------------------------------------
54 | //
55 | // PRIVATE PROPERTIES
56 | //
57 | //------------------------------------------------------------------------------------------
58 |
59 | private const standardVertexShader:ByteArray =
60 | ASSEMBLER.assemble(
61 | VERTEX_SHADER,
62 | "m44 op, va0, vc0 \n" +
63 | "mov v0, va1"
64 | );
65 |
66 | private const standardFragmentShader:ByteArray =
67 | ASSEMBLER.assemble(
68 | FRAGMENT_SHADER,
69 | "tex ft0, v0, fs0 <2d,clamp,nearest> \n" +
70 | "mov oc, ft0"
71 | );
72 |
73 | private const projectionMatrix:Vector. =
74 | new [
75 | 1.0, 0.0, 0.0, -1.0,
76 | 0.0, 1.0, 0.0, 1.0,
77 | 0.0, 0.0, 1.0, 0.0,
78 | 0.0, 0.0, 0.0, 1.0
79 | ];
80 |
81 | private var game:GameApp = null;
82 | private var program:Program3D = null;
83 |
84 | private var imageRegister:Dictionary = new Dictionary();
85 | private var imageTextures:Dictionary = new Dictionary();
86 |
87 | private var graphicMesh:GraphicMesh = null;
88 | private var graphicImage:BitmapData = null;
89 |
90 | private var currentUIGraphic:Graphic = null;
91 | private var pendingUIGraphic:Graphic = null;
92 |
93 | private var drawTrianglesCount:int = 0;
94 |
95 | private var clipRect:Rectangle = new Rectangle();
96 | private var usingClipRect:Boolean = false;
97 |
98 | private var backgroundR:Number = 0.0;
99 | private var backgroundG:Number = 0.0;
100 | private var backgroundB:Number = 0.0;
101 |
102 | //------------------------------------------------------------------------------------------
103 | //
104 | // CONSTRUCTOR
105 | //
106 | //------------------------------------------------------------------------------------------
107 |
108 | /**
109 | */
110 | public function GameGraphics()
111 | {}
112 |
113 | //------------------------------------------------------------------------------------------
114 | //
115 | // PUBLIC METHODS
116 | //
117 | //------------------------------------------------------------------------------------------
118 |
119 | /**
120 | */
121 | public function draw( graphic:Graphic, absolute:Boolean=false ):void
122 | {
123 | if( cameraX < 0.0 )
124 | {
125 | cameraX = 0.0;
126 | }
127 |
128 | if( cameraY < 0.0 )
129 | {
130 | cameraY = 0.0;
131 | }
132 |
133 | if( graphic.graphicRX == null )
134 | {
135 | return;
136 | }
137 |
138 | if( graphicImage != graphic.graphicRX.image )
139 | {
140 | drawMesh();
141 | graphicImage = imageRegister[graphic.graphicRX.image];
142 |
143 | if( graphicImage == null )
144 | {
145 | return;
146 | }
147 | }
148 |
149 | if( graphic.width < 0.0 || graphic.height < 0.0 )
150 | {
151 | return;
152 | }
153 |
154 | if( graphic.clipped )
155 | {
156 | clipRect.x = graphic.x;
157 | clipRect.y = graphic.y;
158 | clipRect.width = graphic.width;
159 | clipRect.height = graphic.height;
160 |
161 | usingClipRect = true;
162 | game.context.setScissorRectangle( clipRect );
163 | }
164 | else if( usingClipRect )
165 | {
166 | usingClipRect = false;
167 | game.context.setScissorRectangle( null );
168 | }
169 |
170 | var x:Number;
171 | var y:Number;
172 | var r:Number;
173 | var b:Number;
174 |
175 | if( graphic.clipped )
176 | {
177 | x = cameraX * graphic.cameraScalerX;
178 | y = cameraY * graphic.cameraScalerY;
179 | }
180 | else
181 | {
182 | x = graphic.x - ( absolute ? 0.0 : cameraX * graphic.cameraScalerX );
183 | y = graphic.y - ( absolute ? 0.0 : cameraY * graphic.cameraScalerY );
184 |
185 | if( x > game.width || y > game.height )
186 | {
187 | return;
188 | }
189 |
190 | r = x + graphic.width;
191 | b = y + graphic.height;
192 |
193 | if( r < 0.0 || b < 0.0 )
194 | {
195 | return;
196 | }
197 | }
198 |
199 | if( graphic.interactive )
200 | {
201 | var px:Number = game.controls.mouseX;
202 | var py:Number = game.controls.mouseY;
203 |
204 | if( px >= x && py >= y && px < r && py < b )
205 | {
206 | pendingUIGraphic = graphic;
207 | }
208 | }
209 |
210 | graphicMesh.x = x;
211 | graphicMesh.y = y;
212 |
213 | graphic.render( graphicMesh );
214 | }
215 |
216 | //------------------------------------------------------------------------------------------
217 | //
218 | // INTERNAL METHODS
219 | //
220 | //------------------------------------------------------------------------------------------
221 |
222 | /**
223 | */
224 | internal override function initialize( game:GameApp ):void
225 | {
226 | this.game = game;
227 |
228 | projectionMatrix[0] = 2.0 / game.width;
229 | projectionMatrix[5] = -2.0 / game.height;
230 |
231 | backgroundR = ( 1.0 / 255.0 ) * ( game.config.gameBackground >> 16 & 255 );
232 | backgroundG = ( 1.0 / 255.0 ) * ( game.config.gameBackground >> 8 & 255 );
233 | backgroundB = ( 1.0 / 255.0 ) * ( game.config.gameBackground >> 0 & 255 );
234 |
235 | reboot();
236 | }
237 |
238 | /**
239 | */
240 | internal override function update():void
241 | {
242 | game.context.clear( backgroundR, backgroundG, backgroundB );
243 |
244 | drawTrianglesCount = 0;
245 |
246 | if( pendingUIGraphic == null )
247 | {
248 | if( currentUIGraphic == null )
249 | {
250 | return;
251 | }
252 |
253 | currentUIGraphic.mouseLeave();
254 | currentUIGraphic = null;
255 | return;
256 | }
257 |
258 | if( pendingUIGraphic == currentUIGraphic )
259 | {
260 | currentUIGraphic.mouseHover();
261 | pendingUIGraphic = null;
262 | return;
263 | }
264 |
265 | if( currentUIGraphic != null )
266 | {
267 | currentUIGraphic.mouseLeave();
268 | }
269 |
270 | currentUIGraphic = pendingUIGraphic;
271 | currentUIGraphic.mouseEnter();
272 |
273 | pendingUIGraphic = null;
274 | }
275 |
276 | /**
277 | */
278 | internal override function reset():void
279 | {
280 | graphicMesh.reset();
281 |
282 | graphicImage = null;
283 | currentUIGraphic = null;
284 | pendingUIGraphic = null;
285 | }
286 |
287 | /**
288 | */
289 | internal function reboot():void
290 | {
291 | program = game.context.createProgram();
292 | program.upload(
293 | standardVertexShader,
294 | standardFragmentShader
295 | );
296 |
297 | game.context.setProgram( program );
298 | game.context.setProgramConstantsFromVector( VERTEX_SHADER, 0, projectionMatrix );
299 |
300 | game.context.setBlendFactors( BLEND_SOURCE, BLEND_DESTINATION );
301 | game.context.setDepthTest( false, DEPTH_TEST );
302 |
303 | game.context.configureBackBuffer( game.width, game.height, 0, false );
304 |
305 | for each( var image:BitmapData in imageRegister )
306 | {
307 | registerImage( image );
308 | }
309 |
310 | graphicMesh = new GraphicMesh();
311 | graphicImage = null;
312 | }
313 |
314 | /**
315 | */
316 | internal function present():void
317 | {
318 | drawMesh();
319 | game.context.present();
320 | }
321 |
322 | /**
323 | */
324 | internal function registerImage( image:BitmapData ):void
325 | {
326 | if( game.context == null )
327 | {
328 | imageRegister[image] = image;
329 | return;
330 | }
331 |
332 | var texture:Texture = imageTextures[image];
333 |
334 | if( texture != null )
335 | {
336 | texture.dispose();
337 | }
338 |
339 | texture = game.context.createTexture( image.width, image.height, BGRA, false );
340 | texture.uploadFromBitmapData( image );
341 |
342 | imageRegister[image] = image;
343 | imageTextures[image] = texture;
344 | }
345 |
346 | /**
347 | */
348 | internal function unregisterImage( image:BitmapData ):void
349 | {
350 | var texture:Texture = imageTextures[image];
351 |
352 | if( texture != null )
353 | {
354 | texture.dispose();
355 | }
356 |
357 | delete imageRegister[image];
358 | delete imageTextures[image];
359 | }
360 |
361 | //------------------------------------------------------------------------------------------
362 | //
363 | // PRIVATE METHODS
364 | //
365 | //------------------------------------------------------------------------------------------
366 |
367 | /**
368 | */
369 | private function drawMesh():void
370 | {
371 | if( graphicImage == null || graphicMesh.vertexCount == 0 )
372 | {
373 | return;
374 | }
375 |
376 | var vc:int;
377 | var ic:int;
378 | var vb:VertexBuffer3D;
379 | var ib:IndexBuffer3D;
380 | var tx:Texture;
381 |
382 | vc = graphicMesh.vertexCount >> 2;
383 | ic = graphicMesh.indexCount;
384 |
385 | vb = game.context.createVertexBuffer( vc, 4 );
386 | ib = game.context.createIndexBuffer( ic );
387 |
388 | vb.uploadFromVector( graphicMesh.vertexList, 0, vc );
389 | ib.uploadFromVector( graphicMesh.indexList, 0, ic );
390 |
391 | tx = imageTextures[graphicImage];
392 |
393 | game.context.setTextureAt( 0, tx );
394 | game.context.setVertexBufferAt( 0, vb, 0, FLOAT2 );
395 | game.context.setVertexBufferAt( 1, vb, 2, FLOAT2 );
396 |
397 | game.context.drawTriangles( ib );
398 |
399 | vb.dispose();
400 | ib.dispose();
401 |
402 | graphicMesh.reset();
403 | graphicImage = null;
404 |
405 | if( ++drawTrianglesCount == 65 )
406 | {
407 | throw new Exception( "The number of graphic meshes rendered during this frame has exceeded 64" );
408 | }
409 | }
410 |
411 | }// EOC
412 | }
--------------------------------------------------------------------------------
/framework/source/remx/GameApp.as:
--------------------------------------------------------------------------------
1 | package remx
2 | {
3 | import flash.display.Stage;
4 | import flash.display.Stage3D;
5 | import flash.display.StageAlign;
6 | import flash.display.StageDisplayState;
7 | import flash.display.StageQuality;
8 | import flash.display.StageScaleMode;
9 | import flash.display3D.Context3D;
10 | import flash.events.Event;
11 | import flash.geom.Rectangle;
12 | import flash.utils.getTimer;
13 |
14 | RUNTIME::AIR
15 | {
16 | import flash.desktop.NativeApplication;
17 | import flash.display.NativeWindow;
18 | import flash.display.StageAspectRatio;
19 | import flash.filesystem.File;
20 | import flash.filesystem.FileMode;
21 | import flash.filesystem.FileStream;
22 | }
23 |
24 | /**
25 | */
26 | public final class GameApp
27 | {
28 | //------------------------------------------------------------------------------------------
29 | //
30 | // INTERNAL PROPERTIES
31 | //
32 | //------------------------------------------------------------------------------------------
33 |
34 | static internal var constructorLocked:Boolean = true;
35 |
36 | //------------------------------------------------------------------------------------------
37 | //
38 | // PUBLIC PROPERTIES
39 | //
40 | //------------------------------------------------------------------------------------------
41 |
42 | public var audio:GameAudio = null;
43 | public var controls:GameControls = null;
44 | public var graphics:GameGraphics = null;
45 | public var network:GameNetwork = null;
46 | public var profiler:GameProfiler = null;
47 | public var resource:GameResource = null;
48 | public var server:GameServer = null;
49 | public var storage:GameStorage = null;
50 |
51 | public var timeDelta:Number = 0.0;
52 | public var timeTotal:Number = 0.0;
53 | public var timeScale:Number = 1.0;
54 | public var timeStamp:Number = 0.0;
55 |
56 | public var width:Number = 0.0;
57 | public var height:Number = 0.0;
58 |
59 | //------------------------------------------------------------------------------------------
60 | //
61 | // INTERNAL PROPERTIES
62 | //
63 | //------------------------------------------------------------------------------------------
64 |
65 | RUNTIME::AIR
66 | {
67 | internal const CACHE_DIRECTORY:String = "app-storage:/cache";
68 | internal const CORE_DIRECTORY:String = "app-storage:/core";
69 | internal const DATA_DIRECTORY:String = "app-storage:/data";
70 | internal const DOWNLOADS_DIRECTORY:String = "app-storage:/downloads";
71 | internal const EXTENSIONS_DIRECTORY:String = "app-storage:/extensions";
72 | }
73 |
74 | internal var stage:Stage = null;
75 | internal var surface:Stage3D = null;
76 | internal var context:Context3D = null;
77 |
78 | internal var config:GameConfig = null;
79 |
80 | //------------------------------------------------------------------------------------------
81 | //
82 | // PRIVATE PROPERTIES
83 | //
84 | //------------------------------------------------------------------------------------------
85 |
86 | private var initialized:Boolean = false;
87 | private var rebooting:Boolean = false;
88 | private var deactivated:Boolean = false;
89 | private var screenLocked:Boolean = false;
90 |
91 | private var screen:GameScreen = null;
92 |
93 | //------------------------------------------------------------------------------------------
94 | //
95 | // CONSTRUCTOR
96 | //
97 | //------------------------------------------------------------------------------------------
98 |
99 | /**
100 | */
101 | public function GameApp()
102 | {
103 | if( constructorLocked )
104 | {
105 | throw new Exception( "GameApp instance cannot be constructed" );
106 | }
107 | }
108 |
109 | //------------------------------------------------------------------------------------------
110 | //
111 | // PUBLIC METHODS
112 | //
113 | //------------------------------------------------------------------------------------------
114 |
115 | /**
116 | */
117 | public function setScreen( screenID:String ):void
118 | {
119 | if( screenLocked )
120 | {
121 | throw new Exception( "Screens cannot be set during screen construction or deconstruction" );
122 | }
123 |
124 | screenLocked = true;
125 |
126 | if( screen != null )
127 | {
128 | screen.deconstruct();
129 |
130 | audio .reset();
131 | controls.reset();
132 | graphics.reset();
133 | network .reset();
134 | resource.reset();
135 | server .reset();
136 | storage .reset();
137 |
138 | if( config.profile )
139 | {
140 | profiler.reset();
141 | }
142 |
143 | screen = null;
144 | }
145 |
146 | if( screenID == null )
147 | {
148 | screenLocked = false;
149 | return;
150 | }
151 |
152 | var screenClass:Class = config.screenClasses[screenID];
153 |
154 | if( screenClass == null )
155 | {
156 | throw new Exception( "Screen '" + screenID + "' has not been registered" );
157 | }
158 |
159 | screen = new screenClass();
160 | screen.construct( this );
161 |
162 | screenLocked = false;
163 | }
164 |
165 | //------------------------------------------------------------------------------------------
166 | //
167 | // INTERNAL METHODS
168 | //
169 | //------------------------------------------------------------------------------------------
170 |
171 | /**
172 | */
173 | internal function run( stage:Stage, config:GameConfig ):void
174 | {
175 | this.stage = stage;
176 | this.config = config;
177 |
178 | width = config.gameWidth;
179 | height = config.gameHeight;
180 |
181 | stage.align = StageAlign.TOP_LEFT;
182 | stage.quality = StageQuality.LOW;
183 | stage.scaleMode = StageScaleMode.NO_SCALE;
184 | stage.mouseChildren = false;
185 |
186 | RUNTIME::AIR
187 | {
188 | var application:NativeApplication = NativeApplication.nativeApplication;
189 |
190 | application.autoExit = true;
191 | application.addEventListener( Event.EXITING, onApplicationExiting );
192 | application.addEventListener( Event.ACTIVATE, onApplicationActivate );
193 | application.addEventListener( Event.DEACTIVATE, onApplicationDeactivate );
194 |
195 | if( NativeWindow.isSupported )
196 | {
197 | // Limit the frame rate to 60 for desktop games.
198 | if( config.gameFrameRate > 60 )
199 | {
200 | stage.frameRate = 60;
201 | config.gameFrameRate = 60;
202 | }
203 | else
204 | {
205 | stage.frameRate = config.gameFrameRate;
206 | }
207 |
208 | stage.stageWidth = width;
209 | stage.stageHeight = height;
210 |
211 | restoreWindowPosition();
212 |
213 | stage.nativeWindow.activate();
214 | stage.nativeWindow.addEventListener( Event.CLOSING, onWindowClosing );
215 | }
216 | else
217 | {
218 | // Limit the frame rate to 40 for mobile games.
219 | if( config.gameFrameRate > 40 )
220 | {
221 | stage.frameRate = 40;
222 | config.gameFrameRate = 40;
223 | }
224 | else
225 | {
226 | stage.frameRate = config.gameFrameRate;
227 | }
228 |
229 | stage.autoOrients = false;
230 |
231 | if( width > height )
232 | {
233 | stage.setAspectRatio( StageAspectRatio.LANDSCAPE );
234 | }
235 | else
236 | {
237 | stage.setAspectRatio( StageAspectRatio.PORTRAIT );
238 | }
239 |
240 | stage.displayState = StageDisplayState.FULL_SCREEN_INTERACTIVE;
241 | }
242 | }
243 |
244 | RUNTIME::FLASH
245 | {
246 | // Limit the frame rate to 60 for browser games.
247 | if( config.gameFrameRate > 60 )
248 | {
249 | stage.frameRate = 60;
250 | config.gameFrameRate = 60;
251 | }
252 | else
253 | {
254 | stage.frameRate = config.gameFrameRate;
255 | }
256 |
257 | stage.showDefaultContextMenu = false;
258 |
259 | stage.addEventListener( Event.ACTIVATE, onStageActivate );
260 | stage.addEventListener( Event.DEACTIVATE, onStageDeactivate );
261 | }
262 |
263 | surface = stage.stage3Ds[0];
264 |
265 | try
266 | {
267 | // These will replace the current 'viewport' property.
268 | Object(surface).x = 0.0;
269 | Object(surface).y = 0.0;
270 | Object(surface).visible = true;
271 | }
272 | catch( error:Error )
273 | {
274 | Object(surface).viewPort = new Rectangle( 0.0, 0.0, width, height );
275 | }
276 |
277 | surface.addEventListener( Event.CONTEXT3D_CREATE, onContextCreate );
278 | surface.requestContext3D();
279 |
280 | stage.addEventListener( Event.ENTER_FRAME, onStageEnterFrame );
281 | }
282 |
283 | //------------------------------------------------------------------------------------------
284 | //
285 | // PRIVATE METHODS
286 | //
287 | //------------------------------------------------------------------------------------------
288 |
289 | /**
290 | */
291 | private function initialize():void
292 | {
293 | if( initialized )
294 | {
295 | return;
296 | }
297 |
298 | GameSystem.constructorLocked = false;
299 |
300 | audio = new GameAudio();
301 | controls = new GameControls();
302 | graphics = new GameGraphics();
303 | network = new GameNetwork();
304 | profiler = new GameProfiler();
305 | resource = new GameResource();
306 | server = new GameServer();
307 | storage = new GameStorage();
308 |
309 | GameSystem.constructorLocked = true;
310 |
311 | audio .initialize( this );
312 | controls.initialize( this );
313 | graphics.initialize( this );
314 | network .initialize( this );
315 | resource.initialize( this );
316 | server .initialize( this );
317 | storage .initialize( this );
318 |
319 | if( config.profile )
320 | {
321 | profiler.initialize( this );
322 | }
323 |
324 | initialized = true;
325 |
326 | if( config.hasMainResource )
327 | {
328 | resource.onLoadComplete = onResourceLoadComplete;
329 | resource.onLoadProgress = onResourceLoadProgress;
330 | resource.load( "main" );
331 | return;
332 | }
333 |
334 | setScreen( "main" );
335 | }
336 |
337 | /**
338 | */
339 | private function shutdown():void
340 | {
341 | if( initialized )
342 | {
343 | setScreen( null );
344 |
345 | audio .shutdown();
346 | controls.shutdown();
347 | graphics.shutdown();
348 | network .shutdown();
349 | profiler.shutdown();
350 | resource.shutdown();
351 | server .shutdown();
352 | storage .shutdown();
353 |
354 | if( config.profile )
355 | {
356 | profiler.shutdown();
357 | }
358 |
359 | audio = null;
360 | controls = null;
361 | graphics = null;
362 | network = null;
363 | profiler = null;
364 | resource = null;
365 | server = null;
366 | storage = null;
367 |
368 | initialized = false;
369 | }
370 |
371 | RUNTIME::AIR
372 | {
373 | clearCache();
374 |
375 | try
376 | {
377 | // This is not supported on mobile devices.
378 | NativeApplication.nativeApplication.exit();
379 | }
380 | catch( error:Error )
381 | {}
382 | }
383 | }
384 |
385 | /**
386 | */
387 | private function update():void
388 | {
389 | if( initialized == false )
390 | {
391 | return;
392 | }
393 |
394 | context = surface.context3D;
395 |
396 | if( context == null )
397 | {
398 | rebooting = true;
399 | return;
400 | }
401 |
402 | if( rebooting )
403 | {
404 | graphics.reboot();
405 |
406 | rebooting = false;
407 | return;
408 | }
409 |
410 | var time:Number = getTimer();
411 |
412 | if( timeStamp == 0.0 )
413 | {
414 | timeStamp = time;
415 | }
416 | else
417 | {
418 | if( timeScale < 0.0 )
419 | {
420 | timeScale = 0.0;
421 | }
422 |
423 | var tt:Number = time - timeStamp;
424 | var td:Number = tt / ( 1000.0 / stage.frameRate );
425 |
426 | timeTotal += tt * timeScale;
427 | timeDelta = td * timeScale;
428 | timeStamp = time;
429 | }
430 |
431 | if( config.profile )
432 | {
433 | profiler.startPass( getTimer() );
434 | }
435 |
436 | var activeScreen:GameScreen = screen;
437 |
438 | // This needs to be in a try/catch statement because the game could be
439 | // shutdown at any point during the update.
440 | try
441 | {
442 | audio .update();
443 | controls.update();
444 | graphics.update();
445 | network .update();
446 | resource.update();
447 | server .update();
448 | storage .update();
449 |
450 | if( config.profile )
451 | {
452 | profiler.update();
453 | }
454 |
455 | if( screen != null )
456 | {
457 | // Only update the screen if it was not replaced during a system update.
458 | if( screen == activeScreen )
459 | {
460 | screen.update();
461 | }
462 |
463 | screen.render();
464 | }
465 |
466 | graphics.present();
467 | }
468 | catch( error:Error )
469 | {
470 | // Only throw the error if the game was not shutdown during the update.
471 | if( initialized )
472 | {
473 | throw error;
474 | }
475 | }
476 |
477 | if( config.profile )
478 | {
479 | profiler.endPass( getTimer() );
480 | }
481 | }
482 |
483 | /**
484 | */
485 | private function activate():void
486 | {
487 | if( initialized && deactivated )
488 | {
489 | if( screen != null )
490 | {
491 | screen.activate();
492 | }
493 |
494 | deactivated = false;
495 | }
496 | }
497 |
498 | /**
499 | */
500 | private function deactivate():void
501 | {
502 | if( initialized && deactivated == false )
503 | {
504 | if( screen != null )
505 | {
506 | screen.deactivate();
507 | }
508 |
509 | deactivated = true;
510 | }
511 | }
512 |
513 | /**
514 | */
515 | RUNTIME::AIR
516 | private function clearCache():void
517 | {
518 | var file:File = new File( CACHE_DIRECTORY );
519 |
520 | try
521 | {
522 | file.deleteDirectory( true );
523 | }
524 | catch( error:Error )
525 | {}
526 | }
527 |
528 | /**
529 | */
530 | RUNTIME::AIR
531 | private function saveWindowPosition():void
532 | {
533 | var file:File = new File( CORE_DIRECTORY + "/window" );
534 | var stream:FileStream = new FileStream();
535 |
536 | try
537 | {
538 | stream.open( file, FileMode.WRITE );
539 | }
540 | catch( error:Error )
541 | {
542 | return;
543 | }
544 |
545 | stream.writeShort( stage.nativeWindow.x );
546 | stream.writeShort( stage.nativeWindow.y );
547 | stream.close();
548 | }
549 |
550 | /**
551 | */
552 | RUNTIME::AIR
553 | private function restoreWindowPosition():void
554 | {
555 | var file:File = new File( CORE_DIRECTORY + "/window" );
556 | var stream:FileStream = new FileStream();
557 |
558 | try
559 | {
560 | stream.open( file, FileMode.READ );
561 | }
562 | catch( error:Error )
563 | {
564 | return;
565 | }
566 |
567 | stage.nativeWindow.x = stream.readShort();
568 | stage.nativeWindow.y = stream.readShort();
569 | stream.close();
570 | }
571 |
572 | //------------------------------------------------------------------------------------------
573 | //
574 | // PRIVATE METHODS - EVENT LISTENERS
575 | //
576 | //------------------------------------------------------------------------------------------
577 |
578 | /**
579 | */
580 | private function onResourceLoadComplete( resourceID:String ):void
581 | {
582 | resource.onLoadComplete = null;
583 | resource.onLoadProgress = null;
584 |
585 | setScreen( "main" );
586 | }
587 |
588 | /**
589 | */
590 | private function onResourceLoadProgress( resourceID:String, progress:Number ):void
591 | {}
592 |
593 | //------------------------------------------------------------------------------------------
594 | //
595 | // PRIVATE METHODS - NATIVE EVENT LISTENERS
596 | //
597 | //------------------------------------------------------------------------------------------
598 |
599 | /**
600 | */
601 | RUNTIME::AIR
602 | private function onApplicationExiting( event:Event ):void
603 | {
604 | var application:NativeApplication = NativeApplication.nativeApplication;
605 |
606 | application.autoExit = true;
607 | application.addEventListener( Event.EXITING, onApplicationExiting );
608 | application.addEventListener( Event.ACTIVATE, onApplicationActivate );
609 | application.addEventListener( Event.DEACTIVATE, onApplicationDeactivate );
610 |
611 | shutdown();
612 | }
613 |
614 | /**
615 | */
616 | RUNTIME::AIR
617 | private function onApplicationActivate( event:Event ):void
618 | {
619 | activate();
620 | }
621 |
622 | /**
623 | */
624 | RUNTIME::AIR
625 | private function onApplicationDeactivate( event:Event ):void
626 | {
627 | deactivate();
628 | }
629 |
630 | /**
631 | */
632 | RUNTIME::AIR
633 | private function onWindowClosing( event:Event ):void
634 | {
635 | stage.nativeWindow.removeEventListener( Event.CLOSING, onWindowClosing );
636 |
637 | saveWindowPosition();
638 | }
639 |
640 | /**
641 | */
642 | RUNTIME::FLASH
643 | private function onStageActivate( event:Event ):void
644 | {
645 | activate();
646 | }
647 |
648 | /**
649 | */
650 | RUNTIME::FLASH
651 | private function onStageDeactivate( event:Event ):void
652 | {
653 | deactivate();
654 | }
655 |
656 | /**
657 | */
658 | private function onStageEnterFrame( event:Event ):void
659 | {
660 | update();
661 | }
662 |
663 | /**
664 | */
665 | private function onContextCreate( event:Event ):void
666 | {
667 | context = surface.context3D;
668 |
669 | if( config.debug )
670 | {
671 | context.enableErrorChecking = true;
672 | }
673 |
674 | initialize();
675 | }
676 |
677 | }// EOC
678 | }
--------------------------------------------------------------------------------