├── .gitignore ├── README.md ├── StarlingPunkExample.as3proj ├── docs ├── AC_OETags.js ├── SPDocs.docproj ├── all-classes.html ├── all-index-A.html ├── all-index-B.html ├── all-index-C.html ├── all-index-D.html ├── all-index-E.html ├── all-index-F.html ├── all-index-G.html ├── all-index-H.html ├── all-index-I.html ├── all-index-J.html ├── all-index-K.html ├── all-index-L.html ├── all-index-M.html ├── all-index-N.html ├── all-index-O.html ├── all-index-P.html ├── all-index-Q.html ├── all-index-R.html ├── all-index-S.html ├── all-index-T.html ├── all-index-U.html ├── all-index-V.html ├── all-index-W.html ├── all-index-X.html ├── all-index-Y.html ├── all-index-Z.html ├── asdoc.js ├── class-summary.html ├── com │ └── saia │ │ └── starlingPunk │ │ ├── SP.html │ │ ├── SPCamera.html │ │ ├── SPEngine.html │ │ ├── SPEntity.html │ │ ├── SPMask.html │ │ ├── SPWorld.html │ │ ├── class-list.html │ │ ├── effects │ │ ├── SPEffects.html │ │ ├── ShakeEffect.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── events │ │ ├── EngineEvent.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── graphics │ │ ├── SPTilemap.html │ │ ├── SpriteCanvas.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── helpers │ │ ├── Primitives.html │ │ ├── SPMath.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── masks │ │ ├── SPGrid.html │ │ ├── SPHitbox.html │ │ ├── SPMasklist.html │ │ ├── SPPixelmask.html │ │ ├── class-list.html │ │ └── package-detail.html │ │ ├── package-detail.html │ │ └── utils │ │ ├── Key.html │ │ ├── SPInput.html │ │ ├── class-list.html │ │ └── package-detail.html ├── cookies.js ├── help.js ├── images │ ├── AirIcon12x12.gif │ ├── P_AlternativeMetadataIndicator_30x28_N.png │ ├── collapsed.gif │ ├── detailHeaderRule.jpg │ ├── detailSectionHeader.jpg │ ├── expanded.gif │ ├── inherit-arrow.gif │ ├── inheritedSummary.gif │ ├── logo.jpg │ ├── titleTableBottom.jpg │ ├── titleTableMiddle.jpg │ └── titleTableTop.jpg ├── index-list.html ├── index.html ├── override.css ├── package-frame.html ├── package-list.html ├── package-summary.html ├── print.css ├── style.css └── title-bar.html ├── lib ├── com │ └── saia │ │ └── starlingPunk │ │ ├── SP.as │ │ ├── SPCamera.as │ │ ├── SPEngine.as │ │ ├── SPEntity.as │ │ ├── SPMask.as │ │ ├── SPWorld.as │ │ ├── behaviors │ │ ├── Behavior.as │ │ ├── BehaviorManager.as │ │ └── IBehavior.as │ │ ├── console │ │ └── SPConsole.as │ │ ├── effects │ │ ├── SPEffects.as │ │ └── ShakeEffect.as │ │ ├── events │ │ └── EngineEvent.as │ │ ├── extensions │ │ └── ogmopunk │ │ │ ├── ImageDefinition.as │ │ │ ├── OgmoEntityDefinition.as │ │ │ ├── OgmoLayer.as │ │ │ ├── OgmoProject.as │ │ │ ├── OgmoTileSet.as │ │ │ ├── OgmoValue.as │ │ │ └── layers │ │ │ ├── EntityLayer.as │ │ │ ├── GridLayer.as │ │ │ └── TileLayer.as │ │ ├── graphics │ │ ├── SPTilemap.as │ │ └── SpriteCanvas.as │ │ ├── helpers │ │ ├── Alignment.as │ │ ├── ColorUtils.as │ │ ├── Primitives.as │ │ └── SPMath.as │ │ ├── masks │ │ ├── SPGrid.as │ │ ├── SPHitbox.as │ │ ├── SPMasklist.as │ │ └── SPPixelmask.as │ │ └── utils │ │ ├── Key.as │ │ └── SPInput.as ├── starling.swc └── starling │ └── extensions │ ├── ColorArgb.as │ ├── PDParticle.as │ ├── PDParticleSystem.as │ ├── Particle.as │ ├── ParticleDesignerPS.as │ └── ParticleSystem.as ├── license.txt └── src ├── GameEngine.as ├── Main.as ├── com └── saia │ └── starlingPunkExamples │ ├── cameraScroller │ └── worlds │ │ └── ScrollingWorld.as │ ├── embeds │ └── ExampleAssets.as │ ├── helpers │ └── ExampleManager.as │ ├── platformer │ ├── controllers │ │ └── LevelController.as │ ├── entities │ │ ├── GoalEntity.as │ │ └── PlatformerPlayer.as │ └── worlds │ │ ├── PlatformerLevelOne.as │ │ ├── PlatformerLevelTwo.as │ │ └── PlatformerWorld.as │ └── shipShooter │ ├── controller │ └── ScoreController.as │ ├── entities │ ├── AlienEntity.as │ ├── BulletEntity.as │ ├── PlayerEntity.as │ ├── RestartText.as │ └── ScoreEntity.as │ ├── particles │ ├── ExplosionParticles.as │ └── Particles.as │ └── worlds │ └── PlayWorld.as └── media ├── fonts ├── bmpFontData.fnt └── bmpFontTexture.png ├── levels ├── burger.png ├── goal.png ├── groundTileSet.png ├── level01.oel ├── level02.oel ├── marioTile.png ├── platformTile.png ├── platformerProject.oep ├── scrollingCamera.oep ├── scrollingLevel.oel └── tileset.png ├── particles ├── explosion.pex └── explosionTexture.png └── textures ├── Alien.png ├── PlayerEntity.png ├── Ship.png ├── TestShape.png ├── textureAtlas.png ├── textureAtlas.tps ├── textureAtlas.xml └── tileset.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Build and Release Folders 2 | bin-debug/ 3 | bin-release/ 4 | 5 | # Project property files 6 | .actionScriptProperties 7 | .flexProperties 8 | .settings/ 9 | .project 10 | /obj 11 | /obj 12 | /obj 13 | /obj 14 | /obj/StarlingPunkExampleConfig.old 15 | /obj/StarlingPunkExampleConfig.xml -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | StarlingPunk 2 | ============ 3 | 4 | ###Update Version 1.5 Change Log 5 | * added mouseX, mouseY and mouseWheelDelta support to SPInput 6 | 7 | ---------------------------------------------------------------- 8 | 9 | ###Update Version 1.4 Change Log 10 | * added Starling's new AssetManager class to SP for easy access 11 | * updated to starling 1.3 12 | * added behavior system 13 | * laid ground work for debug console 14 | * several performance optimizations partially when getting an entity's width/height 15 | 16 | ---------------------------------------------------------------- 17 | 18 | ###Update Version 1.3 Change Log 19 | * created SPCamera class!!!! 20 | * added crazy experimental camera zoom and rotation abilities to platformer example 21 | * rebuilt SPTilesets to support massive amounts of tiles 22 | * SP class now has elapsedTime variable to write framerate independent code 23 | * fixed bug in SPWorld removeAll class so it actually removes all 24 | * added dispose flag to SPWorld 25 | * cleaned up and removed a couple old unused classes 26 | 27 | ---------------------------------------------------------------- 28 | 29 | ###Update Version 1.2 Change Log 30 | * fixed issues with entities hit box collision 31 | * hit box size wasn't being factored in by pixelMask 32 | * ported some more properties and methods for hit boxes from flashPunk 33 | * changed class names to reflect StarlingPunks naming convention 34 | 35 | ---------------------------------------------------------------- 36 | 37 | ###Update Version 1.1 Change Log 38 | * Tilemap support 39 | * Ogmo editor intergration 40 | * Collision Mask support 41 | * Grid collision 42 | * Pixel Mask collision 43 | * Fixed bug with type only getting set when pass through entity constructor 44 | * added support for entity depth layers 45 | * added collideTypes method to entity class 46 | * misc bug fixes/performance improvements 47 | 48 | ###Future release plans: 49 | * Port Camera class 50 | * Extension for box2D Physics Library 51 | * Component based behavior system sorta like Unity3D 52 | * Helper functions for sound effects 53 | 54 | 55 | Check out the examples that come with StarlingPunk: 56 | http://andysaia.com/blog/starlingPunkTilemaps/starlingPunk-example.html 57 | 58 | ---------------------------------------------------------------- 59 | 60 | ###What is StarlingPunk: 61 | 62 | StarlingPunk is a framework built on top the Starling library designed to add structure and organization to your 2D game projects. It’s perfect for rapidly prototyping ideas and promotes code reuse between projects. As you may have been able to tell from the name, StarlingPunk is heavily inspired by the popular FlashPunk framework, although its not a direct port. 63 | 64 | 65 | ### Why StarlingPunk: 66 | * Easily encapsulate code into worlds and entities 67 | * Manages collections of entities based on assigned types 68 | * Fast and easy collision detection system 69 | * All the power of starling performance, sprite sheets, particles, mobile development 70 | 71 | ### Why build this on top of Starling: 72 | * Best of both worlds allowing us to mix and match regular Starling code with FlashPunk like organization. 73 | * Fast Stage3D hardware accelerated graphics 74 | * Provides a familiar structure for Actionscript developers 75 | * Harness the power of the display-list, worlds and entities extend the starling sprite class meaning display objects can be nested within them 76 | * Pre-existing Starling code can easily be incorporated into the framework 77 | * Starling already does a ton of things right, sprite-sheet animation, events, dynamic resolutions 78 | * Tons of tools and extensions will already work, like sprite-manager and particles 79 | 80 | ### Planned future releases: 81 | * Integration with the Nape physics library 82 | * Helper functions for sound effects 83 | * Port Debug console -------------------------------------------------------------------------------- /StarlingPunkExample.as3proj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 89 | 90 | 91 | 92 | 93 | 94 | -------------------------------------------------------------------------------- /docs/AC_OETags.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ADOBE SYSTEMS INCORPORATED 4 | // Copyright 2008 Adobe Systems Incorporated 5 | // All Rights Reserved. 6 | // 7 | // NOTICE: Adobe permits you to use, modify, and distribute this file 8 | // in accordance with the terms of the license agreement accompanying it. 9 | // 10 | //////////////////////////////////////////////////////////////////////////////// 11 | 12 | 13 | //v1.0 14 | function AC_AddExtension(src, ext) 15 | { 16 | if (src.indexOf('?') != -1) 17 | return src.replace(/\?/, ext+'?'); 18 | else 19 | return src + ext; 20 | } 21 | 22 | function AC_Generateobj(objAttrs, params, embedAttrs) 23 | { 24 | var str = ' '; 30 | str += ' 2 | 3 | Starling Punk Documentation 4 | C:\Users\Andy\Desktop\asdoc_sample\classes\com 5 | 6 | C:\Users\Andy\Desktop\docs 7 | 1 8 | -external-library-path=C:\Users\Andy\Desktop\asdoc_sample\ext\ 9 | -------------------------------------------------------------------------------- /docs/all-classes.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | All Classes - API Documentation 5 | 6 | 7 | 8 | 9 | 10 | 11 |

All Classes

12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
EngineEvent
Key
Primitives
ShakeEffect
SP
SPCamera
SPEffects
SPEngine
SPEntity
SPGrid
SPHitbox
SPInput
SPMask
SPMasklist
SPMath
SPPixelmask
SpriteCanvas
SPTilemap
SPWorld
71 | 72 | 73 | -------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/class-list.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk - API Documentation

Package com.saia.starlingPunk

Classes
SP
SPCamera
SPEngine
SPEntity
SPMask
SPWorld
-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/effects/SPEffects.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.effects.SPEffects 6 |
Packagecom.saia.starlingPunk.effects
Classpublic class SPEffects
InheritanceSPEffects Inheritance Object

14 | Collections of built-in effects 15 |



Public Methods
 MethodDefined By
  
shake(intensity:Number = 10, duration:Number = 1000):ShakeEffect
[static] 16 | 17 |
SPEffects
Method Detail
shake()method
public static function shake(intensity:Number = 10, duration:Number = 1000):ShakeEffect

20 | 21 |

Parameters
intensity:Number (default = 10) — size of randomness of shake effect 22 |
 
duration:Number (default = 1000) — length of shake 23 |

Returns
ShakeEffect — returns an instance of the shake effect class 24 |




-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/effects/class-list.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.effects - API Documentation

Package com.saia.starlingPunk.effects

Classes
ShakeEffect
SPEffects
-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/effects/package-detail.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.effects Summary 6 |



Classes
 ClassDescription
 ShakeEffect 14 | Shake effect class randomizes the position of the world for a given duration 15 |
 SPEffects 16 | Collections of built-in effects 17 |

-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/events/class-list.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.events - API Documentation

Package com.saia.starlingPunk.events

Classes
EngineEvent
-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/events/package-detail.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.events Summary 6 |



Classes
 ClassDescription
 EngineEvent 14 | Called when the engine pauses and unpauses useful for stoping background processes or timers 15 |

-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/graphics/class-list.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.graphics - API Documentation

Package com.saia.starlingPunk.graphics

Classes
SpriteCanvas
SPTilemap
-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/graphics/package-detail.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.graphics Summary 6 |



Classes
 ClassDescription
 SpriteCanvas 14 | This class is used interally for StarlingPunk's Tilemap system.
 SPTilemap 15 | A canvas to which Tiles can be drawn for fast multiple tile rendering.

-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/helpers/Primitives.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.helpers.Primitives 6 |
Packagecom.saia.starlingPunk.helpers
Classpublic class Primitives
InheritancePrimitives Inheritance Object

14 | This Class contains helper classes for drawing primitive shapes usufuly for prototyping 15 |



Public Methods
 MethodDefined By
  
circle(radius:Number = 50, color:uint = 0xFF0000):Image
[static]
Primitives
  
rect(width:Number = 100, height:Number = 100, color:uint = 0xFF0000):Image
[static]
Primitives
Method Detail
circle()method
public static function circle(radius:Number = 50, color:uint = 0xFF0000):Image

Parameters
radius:Number (default = 50)
 
color:uint (default = 0xFF0000)

Returns
Image
rect()method 
public static function rect(width:Number = 100, height:Number = 100, color:uint = 0xFF0000):Image

Parameters
width:Number (default = 100)
 
height:Number (default = 100)
 
color:uint (default = 0xFF0000)

Returns
Image




-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/helpers/SPMath.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.helpers.SPMath 6 |
Packagecom.saia.starlingPunk.helpers
Classpublic class SPMath
InheritanceSPMath Inheritance Object

14 | Collection of Math helper methods 15 |



Public Methods
 MethodDefined By
  
getRandomIndex(array:*):int
[static] 16 | returns a random index of the given array 17 |
SPMath
  
range(minNum:Number, maxNum:Number):Number
[static] 18 | returns random number inbetween min and max 19 |
SPMath
Method Detail
getRandomIndex()method
public static function getRandomIndex(array:*):int

22 | returns a random index of the given array 23 |

Parameters
array:*

Returns
int
range()method 
public static function range(minNum:Number, maxNum:Number):Number

24 | returns random number inbetween min and max 25 |

Parameters
minNum:Number
 
maxNum:Number

Returns
Number — random number inbetween min and max 26 |




-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/helpers/class-list.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.helpers - API Documentation

Package com.saia.starlingPunk.helpers

Classes
Primitives
SPMath
-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/helpers/package-detail.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.helpers Summary 6 |



Classes
 ClassDescription
 Primitives 14 | This Class contains helper classes for drawing primitive shapes usufuly for prototyping 15 |
 SPMath 16 | Collection of Math helper methods 17 |

-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/masks/class-list.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.masks - API Documentation

Package com.saia.starlingPunk.masks

Classes
SPGrid
SPHitbox
SPMasklist
SPPixelmask
-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/masks/package-detail.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.masks Summary 6 |



Classes
 ClassDescription
 SPGrid 14 | Uses a hash grid to determine collision, faster than 15 | using hundreds of Entities for tiled levels, etc.
 SPHitbox 16 | Uses parent's hitbox to determine collision.
 SPMasklist 17 | A Mask that can contain multiple Masks of one or various types.
 SPPixelmask 18 | A bitmap mask used for pixel-perfect collision.

-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/package-detail.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk Summary 6 |



Classes
 ClassDescription
 SP 14 | Static catch-all class used to access global properties and functions.
 SPCamera 15 | Camera class used for scrolling game worlds.
 SPEngine 16 | Main game Sprite class, Manages the game loop.
 SPEntity 17 | Main game Entity class updated by World.
 SPMask 18 | Base class for Entity collision masks.
 SPWorld 19 | Updated by Engine, main game container that holds all currently active Entities.

-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/utils/class-list.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.utils - API Documentation

Package com.saia.starlingPunk.utils

Classes
Key
SPInput
-------------------------------------------------------------------------------- /docs/com/saia/starlingPunk/utils/package-detail.html: -------------------------------------------------------------------------------- 1 | com.saia.starlingPunk.utils Summary 6 |



Classes
 ClassDescription
 Key 14 | Contains static key constants to be used by Input.
 SPInput 15 | Static class updated by Engine.

-------------------------------------------------------------------------------- /docs/cookies.js: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // ADOBE SYSTEMS INCORPORATED 4 | // Copyright 2006-2008 Adobe Systems Incorporated 5 | // All Rights Reserved. 6 | // 7 | // NOTICE: Adobe permits you to use, modify, and distribute this file 8 | // in accordance with the terms of the license agreement accompanying it. 9 | // 10 | //////////////////////////////////////////////////////////////////////////////// 11 | 12 | /** 13 | * Read the JavaScript cookies tutorial at: 14 | * http://www.netspade.com/articles/javascript/cookies.xml 15 | */ 16 | 17 | /** 18 | * Sets a Cookie with the given name and value. 19 | * 20 | * name Name of the cookie 21 | * value Value of the cookie 22 | * [expires] Expiration date of the cookie (default: end of current session) 23 | * [path] Path where the cookie is valid (default: path of calling document) 24 | * [domain] Domain where the cookie is valid 25 | * (default: domain of calling document) 26 | * [secure] Boolean value indicating if the cookie transmission requires a 27 | * secure transmission 28 | */ 29 | function setCookie(name, value, expires, path, domain, secure) 30 | { 31 | document.cookie= name + "=" + escape(value) + 32 | ((expires) ? "; expires=" + expires.toGMTString() : "") + 33 | ((path) ? "; path=" + path : "") + 34 | ((domain) ? "; domain=" + domain : "") + 35 | ((secure) ? "; secure" : ""); 36 | } 37 | 38 | /** 39 | * Gets the value of the specified cookie. 40 | * 41 | * name Name of the desired cookie. 42 | * 43 | * Returns a string containing value of specified cookie, 44 | * or null if cookie does not exist. 45 | */ 46 | function getCookie(name) 47 | { 48 | var dc = document.cookie; 49 | var prefix = name + "="; 50 | var begin = dc.indexOf("; " + prefix); 51 | if (begin == -1) 52 | { 53 | begin = dc.indexOf(prefix); 54 | if (begin != 0) return null; 55 | } 56 | else 57 | { 58 | begin += 2; 59 | } 60 | var end = document.cookie.indexOf(";", begin); 61 | if (end == -1) 62 | { 63 | end = dc.length; 64 | } 65 | return unescape(dc.substring(begin + prefix.length, end)); 66 | } 67 | 68 | /** 69 | * Deletes the specified cookie. 70 | * 71 | * name name of the cookie 72 | * [path] path of the cookie (must be same as path used to create cookie) 73 | * [domain] domain of the cookie (must be same as domain used to create cookie) 74 | */ 75 | function deleteCookie(name, path, domain) 76 | { 77 | if (getCookie(name)) 78 | { 79 | document.cookie = name + "=" + 80 | ((path) ? "; path=" + path : "") + 81 | ((domain) ? "; domain=" + domain : "") + 82 | "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /docs/images/AirIcon12x12.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/AirIcon12x12.gif -------------------------------------------------------------------------------- /docs/images/P_AlternativeMetadataIndicator_30x28_N.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/P_AlternativeMetadataIndicator_30x28_N.png -------------------------------------------------------------------------------- /docs/images/collapsed.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/collapsed.gif -------------------------------------------------------------------------------- /docs/images/detailHeaderRule.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/detailHeaderRule.jpg -------------------------------------------------------------------------------- /docs/images/detailSectionHeader.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/detailSectionHeader.jpg -------------------------------------------------------------------------------- /docs/images/expanded.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/expanded.gif -------------------------------------------------------------------------------- /docs/images/inherit-arrow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/inherit-arrow.gif -------------------------------------------------------------------------------- /docs/images/inheritedSummary.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/inheritedSummary.gif -------------------------------------------------------------------------------- /docs/images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/logo.jpg -------------------------------------------------------------------------------- /docs/images/titleTableBottom.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/titleTableBottom.jpg -------------------------------------------------------------------------------- /docs/images/titleTableMiddle.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/titleTableMiddle.jpg -------------------------------------------------------------------------------- /docs/images/titleTableTop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/docs/images/titleTableTop.jpg -------------------------------------------------------------------------------- /docs/index-list.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Starling Punk Documentation 4 | 5 | 6 | 7 | 8 | 9 |

Index

10 | 11 | 12 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
AN
BO
CP
DQ
ER
FS
GT
HU
IV
JW
KX
LY
MZ
70 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | API Documentation 4 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | <body> 31 | <h2>Frame Alert</h2> 32 | <p> 33 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 34 | <br> 35 | Link to <a href="package-summary.html">Non-frame version.</a> 36 | </p> 37 | </body> 38 | 39 | 40 | -------------------------------------------------------------------------------- /docs/override.css: -------------------------------------------------------------------------------- 1 | /* 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // 4 | // ADOBE SYSTEMS INCORPORATED 5 | // Copyright 2008 Adobe Systems Incorporated 6 | // All Rights Reserved. 7 | // 8 | // NOTICE: Adobe permits you to use, modify, and distribute this file 9 | // in accordance with the terms of the license agreement accompanying it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////// 12 | */ -------------------------------------------------------------------------------- /docs/package-frame.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Starling Punk Documentation 4 | 5 | 6 | 7 | 8 | 9 | <body> 10 | <h2>Frame Alert</h2> 11 | <p>This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. 12 | <br> 13 | Link to<a href="package-summary.html">Non-frame version.</a> 14 | </p> 15 | </body> 16 | 17 | 18 | -------------------------------------------------------------------------------- /docs/package-list.html: -------------------------------------------------------------------------------- 1 | Package List - API Documentation

Packages

com.saia.starlingPunk
com.saia.starlingPunk.effects
com.saia.starlingPunk.events
com.saia.starlingPunk.graphics
com.saia.starlingPunk.helpers
com.saia.starlingPunk.masks
com.saia.starlingPunk.utils
-------------------------------------------------------------------------------- /docs/package-summary.html: -------------------------------------------------------------------------------- 1 | All Packages 6 |


 packageDescription
 com.saia.starlingPunk
 com.saia.starlingPunk.effects
 com.saia.starlingPunk.events
 com.saia.starlingPunk.graphics
 com.saia.starlingPunk.helpers
 com.saia.starlingPunk.masks
 com.saia.starlingPunk.utils

-------------------------------------------------------------------------------- /docs/print.css: -------------------------------------------------------------------------------- 1 | /* 2 | //////////////////////////////////////////////////////////////////////////////// 3 | // 4 | // ADOBE SYSTEMS INCORPORATED 5 | // Copyright 2005-2008 Adobe Systems Incorporated 6 | // All Rights Reserved. 7 | // 8 | // NOTICE: Adobe permits you to use, modify, and distribute this file 9 | // in accordance with the terms of the license agreement accompanying it. 10 | // 11 | //////////////////////////////////////////////////////////////////////////////// 12 | */ 13 | 14 | body { 15 | color: #000000; 16 | background: #ffffff; 17 | font-family: "Times New Roman", Times, serif; 18 | font-size: 12pt; 19 | } 20 | a { 21 | text-decoration: none; 22 | color: #000000; 23 | } 24 | pre { 25 | white-space: -moz-pre-wrap; /* Mozilla */ 26 | white-space: -pre-wrap; /* Opera 4-6 */ 27 | white-space: -o-pre-wrap; /* Opera 7 */ 28 | word-wrap: break-word; /* IE */ 29 | } 30 | .titleTableTopNav, .titleTableSubNav, .logoImage { 31 | display: none; 32 | } 33 | .packageFrame { 34 | display: none; 35 | } 36 | .titleTableSubTitle { 37 | font-weight: bold; 38 | } 39 | .classHeaderTableLabel { 40 | padding-right: 10px; 41 | vertical-align: top; 42 | } 43 | .showHideLinks { 44 | display: none; 45 | } 46 | html>body code { 47 | font-size: 10pt; 48 | } 49 | .summaryTableTitle, .detailSectionHeader { 50 | font-size: 14pt; 51 | font-weight: bold; 52 | padding-top: 15px; 53 | padding-bottom: 5px; 54 | } 55 | .summaryTable { 56 | border: 1px solid #000000; 57 | border-collapse: collapse; 58 | width: 100%; 59 | } 60 | .summaryTableDescription { 61 | padding-bottom: 20px; 62 | } 63 | .summaryTableSignatureCol, .summaryTableOwnerCol, .summaryTableLastCol, .summaryTableCol { 64 | border: 1px solid #000000; 65 | } 66 | .summaryTablePaddingCol { 67 | border: 1px solid #000000; 68 | border-right: 0px; 69 | } 70 | .summaryTableInheritanceCol, .summaryTableOperatorCol, .summaryTableStatementCol, .summaryTableSecondCol { 71 | border: 1px solid #000000; 72 | border-left: 0px; 73 | } 74 | .summaryTableLastCol { 75 | vertical-align: top; 76 | } 77 | .detailHeader { 78 | font-size: 13pt; 79 | padding-top: 100px; 80 | } 81 | .detailHeaderName { 82 | font-weight: bold; 83 | } 84 | .detailHeaderType { 85 | padding-left: 5px; 86 | } 87 | .detailHeaderRule { 88 | background: #FF0000; 89 | } 90 | .seeAlso { 91 | padding-bottom: 20px; 92 | margin-top: -20px; 93 | } 94 | .innertable { 95 | border-collapse: collapse; 96 | } 97 | .innertable td,.innertable th { 98 | border: 1px solid #000000; 99 | padding-left: 5px; 100 | padding-right: 5px; 101 | } 102 | .listing { 103 | font-size: 10pt; 104 | } 105 | .feedbackLink { 106 | display: none; 107 | } 108 | .copyright { 109 | font-size: 10pt; 110 | } -------------------------------------------------------------------------------- /docs/title-bar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Starling Punk Documentation 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 22 | 23 | 24 | 25 | 38 | 39 |
13 | 14 | 15 | 16 | 19 | 20 |
Starling Punk Documentation  17 | All Packages  |  All Classes  |  Index  |  No Frames 18 |
21 |
26 | 27 | 28 | 29 | 32 | 33 | 34 | 35 | 36 |
 
 
37 |
40 | 41 | -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/SPCamera.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk 2 | { 3 | import flash.geom.Rectangle; 4 | import starling.display.Sprite; 5 | 6 | /** 7 | * Camera class used for scrolling game worlds. Note that the scale and rotate properties are still somewhat experimental 8 | * and your results may vary depending on what you're trying to do. 9 | * @author Andy Saia 10 | */ 11 | public class SPCamera 12 | { 13 | private var _x:Number; 14 | private var _y:Number; 15 | private var _world:SPWorld; 16 | private var _zoom:Number; 17 | private var _rotation:Number; 18 | private var _viewPort:Rectangle; 19 | private var _container:Sprite; 20 | 21 | public function SPCamera() 22 | { 23 | _container = new Sprite(); 24 | } 25 | 26 | //--------------- 27 | // getters and setters 28 | //--------------- 29 | 30 | /** 31 | * a rectangle of the camera's visible area 32 | */ 33 | public function get viewPort():Rectangle 34 | { 35 | return _viewPort; 36 | } 37 | 38 | /** 39 | * x position of the camera 40 | */ 41 | public function get x():Number 42 | { 43 | //returns inverted container x pos 44 | return -_container.x; 45 | } 46 | 47 | public function set x(value:Number):void 48 | { 49 | //inverting container xPos 50 | _container.x = -value; 51 | _viewPort.x = value; 52 | } 53 | 54 | /** 55 | * y position of the camera 56 | */ 57 | public function get y():Number 58 | { 59 | //returns inverted container y pos 60 | return -_container.y; 61 | } 62 | 63 | public function set y(value:Number):void 64 | { 65 | //inverting container yPos 66 | _container.y = -value; 67 | _viewPort.y = value; 68 | } 69 | 70 | /** 71 | * the camera container that every world is a child of 72 | */ 73 | public function get container():Sprite 74 | { 75 | return _container; 76 | } 77 | 78 | /** 79 | * zoom amount of the camera 80 | */ 81 | public function get zoom():Number 82 | { 83 | return _zoom; 84 | } 85 | 86 | public function set zoom(value:Number):void 87 | { 88 | _zoom = value; 89 | _world.scaleX = _zoom; 90 | _world.scaleY = _zoom; 91 | 92 | //TODO: figure out exact viewport postion and size when scaling 93 | //var scaleAmount:Number = 1 + (1 - _zoom); 94 | //_viewPort.width = SP.width * scaleAmount; 95 | //_viewPort.height = SP.height * scaleAmount; 96 | } 97 | 98 | /** 99 | * rotation of the camera 100 | */ 101 | public function get rotation():Number 102 | { 103 | return _rotation; 104 | } 105 | 106 | public function set rotation(value:Number):void 107 | { 108 | _rotation = value; 109 | _world.rotation = _rotation; 110 | } 111 | 112 | //--------------- 113 | // public methods 114 | //--------------- 115 | 116 | public function setWorld(world:SPWorld):void 117 | { 118 | _world = world; 119 | reset(); 120 | } 121 | 122 | /** 123 | * sets the camera's position 124 | * @param x 125 | * @param y 126 | */ 127 | public function setPosition(x:Number, y:Number):void 128 | { 129 | this.x = x; 130 | this.y = y; 131 | } 132 | 133 | /** 134 | * resets camera to orignal position 135 | */ 136 | public function reset():void 137 | { 138 | _viewPort = new Rectangle(0, 0, SP.width, SP.height); 139 | zoom = 1; 140 | rotation = 0; 141 | setPosition(0, 0); 142 | focus(SP.halfWidth, SP.halfHeight); 143 | } 144 | 145 | /** 146 | * pivot point of the camera when scaling and rotating 147 | */ 148 | public function focus(x:Number, y:Number):void 149 | { 150 | _world.pivotX = x; 151 | _world.pivotY = y; 152 | _world.x = _world.pivotX; 153 | _world.y = _world.pivotY; 154 | } 155 | } 156 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/SPEngine.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk 2 | { 3 | import com.saia.starlingPunk.events.EngineEvent; 4 | import com.saia.starlingPunk.utils.SPInput; 5 | import starling.core.Starling; 6 | import starling.display.Sprite; 7 | import starling.events.EnterFrameEvent; 8 | import starling.events.Event; 9 | import starling.utils.AssetManager; 10 | 11 | /** 12 | * Main game Sprite class, Manages the game loop. 13 | * @author Andy Saia 14 | */ 15 | 16 | public class SPEngine extends Sprite 17 | { 18 | /** 19 | * If the game should stop updating/rendering. 20 | */ 21 | private var _paused:Boolean = false; 22 | 23 | /** 24 | * Constructor. Defines startup information about your game. 25 | * @param width The width of your game. 26 | * @param height The height of your game. 27 | * @param frameRate The game framerate, in frames per second. 28 | * @param fixed If a fixed-framerate should be used. 29 | */ 30 | public function SPEngine() 31 | { 32 | // global game objects 33 | SP.engine = this; 34 | SP.camera = new SPCamera(); 35 | SP._world = new SPWorld; 36 | SP.assets = new AssetManager(); 37 | addChild(SP.camera.container); 38 | SP.camera.container.addChild(SP._world); 39 | 40 | // on-stage event listener 41 | addEventListener(Event.ADDED_TO_STAGE, onStage); 42 | } 43 | 44 | //---------- 45 | // getters and setters 46 | //---------- 47 | 48 | public function get paused():Boolean 49 | { 50 | return _paused; 51 | } 52 | 53 | public function set paused(value:Boolean):void 54 | { 55 | _paused = value; 56 | if (value) 57 | dispatchEvent(new EngineEvent(EngineEvent.PAUSED)); 58 | else 59 | dispatchEvent(new EngineEvent(EngineEvent.UNPAUSED)); 60 | } 61 | 62 | /** 63 | * Override this, called after Engine has been added to the stage. 64 | */ 65 | public function init():void { } 66 | 67 | /** 68 | * Updates the game, updating the World and Entities. 69 | */ 70 | public function update():void 71 | { 72 | if (SP._world.active) 73 | { 74 | SP._world.engineUpdate(); 75 | } 76 | SP._world.updateLists(); 77 | if (SP._goto) checkWorld(); 78 | 79 | } 80 | 81 | /** @private Event handler for stage entry. */ 82 | private function onStage(e:Event = null):void 83 | { 84 | // remove event listener 85 | removeEventListener(Event.ADDED_TO_STAGE, onStage); 86 | 87 | SP.stage = stage; 88 | 89 | // enable input 90 | SPInput.enable(); 91 | 92 | // global game properties 93 | SP.width = stage.stageWidth; 94 | SP.height = stage.stageHeight; 95 | 96 | // switch worlds 97 | if (SP._goto) checkWorld(); 98 | 99 | // game start 100 | init(); 101 | 102 | // start game loop 103 | addEventListener(Event.ENTER_FRAME, onEnterFrame); 104 | } 105 | 106 | /** @private Framerate independent game loop. */ 107 | private function onEnterFrame(e:EnterFrameEvent):void 108 | { 109 | // update loop 110 | if (!_paused) update(); 111 | 112 | SP.passedTime = e.passedTime; 113 | 114 | // update input 115 | SPInput.update(); 116 | 117 | // update console 118 | if (SP._console) SP._console.update(); 119 | } 120 | 121 | /** @private Switch Worlds if they've changed. */ 122 | private function checkWorld():void 123 | { 124 | if (!SP._goto) return; 125 | 126 | SP._world.end(); 127 | SP.camera.container.removeChild(SP._world, true); 128 | SP._world.updateLists(); 129 | SP._world = SP._goto; 130 | SP._goto = null; 131 | SP._world.updateLists(); 132 | SP.camera.container.addChild(SP._world); 133 | SP.camera.setWorld(SP._world); 134 | SP._world.begin(); 135 | SP._world.updateLists(); 136 | } 137 | } 138 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/SPMask.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk 2 | { 3 | import com.saia.starlingPunk.masks.SPMasklist; 4 | import flash.geom.Rectangle; 5 | import flash.utils.Dictionary; 6 | import flash.utils.getDefinitionByName; 7 | import flash.utils.getQualifiedClassName; 8 | 9 | /** 10 | * Base class for Entity collision masks. 11 | */ 12 | public class SPMask 13 | { 14 | /** 15 | * The parent Entity of this mask. 16 | */ 17 | public var parent:SPEntity; 18 | 19 | /** 20 | * The parent Masklist of the mask. 21 | */ 22 | public var list:SPMasklist; 23 | 24 | /** 25 | * Constructor. 26 | */ 27 | public function SPMask() 28 | { 29 | _class = Class(getDefinitionByName(getQualifiedClassName(this))); 30 | _check[SPMask] = collideMask; 31 | _check[SPMasklist] = collideMasklist; 32 | } 33 | 34 | /** 35 | * Checks for collision with another Mask. 36 | * @param mask The other Mask to check against. 37 | * @return If the Masks overlap. 38 | */ 39 | public function collide(mask:SPMask):Boolean 40 | { 41 | if (_check[mask._class] != null) return _check[mask._class](mask); 42 | if (mask._check[_class] != null) return mask._check[_class](this); 43 | return false; 44 | } 45 | 46 | /** @private Collide against an Entity. */ 47 | private function collideMask(other:SPMask):Boolean 48 | { 49 | return parent.collideRect(other.parent.getRect(other.parent.x, other.parent.y), parent.x, parent.y); 50 | return parent.x - parent.pivotX + parent.originX + parent.hitWidth > other.parent.x - other.parent.pivotX - other.parent.originX 51 | && parent.y - parent.pivotY + parent.originY + parent.hitHeight > other.parent.y - other.parent.pivotY - other.parent.originY 52 | && parent.x - parent.pivotX - parent.originX < other.parent.x - other.parent.pivotX - other.parent.originX + other.parent.hitWidth 53 | && parent.y - parent.pivotY - parent.originY < other.parent.y - other.parent.pivotY - other.parent.originY + other.parent.hitHeight; 54 | } 55 | 56 | /** @private Collide against a Masklist. */ 57 | protected function collideMasklist(other:SPMasklist):Boolean 58 | { 59 | return other.collide(this); 60 | } 61 | 62 | /** @private Assigns the mask to the parent. */ 63 | internal function assignTo(parent:SPEntity):void 64 | { 65 | this.parent = parent; 66 | if (parent) update(); 67 | } 68 | 69 | /** @private Updates the parent's bounds for this mask. */ 70 | protected function update():void 71 | { 72 | } 73 | 74 | // Mask information. 75 | /** @private */ private var _class:Class; 76 | /** @private */ protected var _check:Dictionary = new Dictionary; 77 | } 78 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/behaviors/Behavior.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.behaviors 2 | { 3 | import com.saia.starlingPunk.SPEntity; 4 | import flash.utils.getQualifiedClassName; 5 | /** 6 | * base class for behaviors 7 | */ 8 | public class Behavior implements IBehavior 9 | { 10 | protected var _name:String; 11 | protected var _entity:SPEntity; 12 | 13 | public function Behavior(entity:SPEntity = null) 14 | { 15 | _entity = entity; 16 | 17 | var classPath:String = getQualifiedClassName(this) as String; 18 | _name = classPath.slice(classPath.lastIndexOf("::") + 2); 19 | } 20 | 21 | //--------------- 22 | // getters and setters 23 | //--------------- 24 | 25 | public function get name():String 26 | { 27 | return _name; 28 | } 29 | 30 | public function get entity():SPEntity 31 | { 32 | return _entity; 33 | } 34 | 35 | //--------------- 36 | // abstract methods 37 | //--------------- 38 | 39 | public function added():void 40 | { 41 | } 42 | 43 | public function removed():void 44 | { 45 | 46 | } 47 | 48 | public function onUpdate():void 49 | { 50 | 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/behaviors/BehaviorManager.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.behaviors 2 | { 3 | /** 4 | * base behavior manager, adds/removes and updates all behaviors 5 | */ 6 | public class BehaviorManager 7 | { 8 | protected var _allBehaviors:Vector.; 9 | protected var _behaviorsToRemove:Vector.; 10 | protected var _behaviorsToAdd:Vector.; 11 | 12 | public function BehaviorManager() 13 | { 14 | _allBehaviors = new Vector.(); 15 | _behaviorsToAdd = new Vector.(); 16 | _behaviorsToRemove = new Vector.(); 17 | } 18 | 19 | //--------------- 20 | // public methods 21 | //--------------- 22 | 23 | /** 24 | * adds the behavior to the list of behaviors to get added on the next frame 25 | * @param behavior 26 | */ 27 | public function add(behavior:IBehavior):void 28 | { 29 | _behaviorsToAdd.push(behavior); 30 | } 31 | 32 | /** 33 | * adds the behavior to the list of behaviors to get removed on the next frame 34 | * @param behavior 35 | */ 36 | public function remove(behavior:IBehavior):void 37 | { 38 | _behaviorsToRemove.push(behavior); 39 | } 40 | 41 | /** 42 | * adds an enables this behavior immediately instead of waiting for the next frame 43 | * @param behavior 44 | */ 45 | public function addImmediate(behavior:IBehavior):void 46 | { 47 | _allBehaviors.push(behavior); 48 | behavior.added(); 49 | } 50 | 51 | /** 52 | * removes an disables this behavior immediately instead of waiting for the next frame 53 | * @param behavior 54 | */ 55 | public function removeImmediate(behavior:IBehavior):void 56 | { 57 | var index:int = _allBehaviors.indexOf(behavior); 58 | if (index == -1) return; //return if behavior is not part of behavior list 59 | 60 | behavior.removed(); 61 | _allBehaviors.splice(index, 1); 62 | } 63 | 64 | /** 65 | * returns a list of all the behaviors weither they are enabled or not 66 | * @return 67 | */ 68 | public function getAllBehaviors():Vector. 69 | { 70 | return _allBehaviors; 71 | } 72 | 73 | /** 74 | * returns a behavior by its name 75 | * @param name 76 | * @return 77 | */ 78 | public function getBehaviorByName(name:String):IBehavior 79 | { 80 | var numBehaviors:int = _allBehaviors.length; 81 | var behavior:IBehavior = null; 82 | for (var i:int = 0; i < numBehaviors; i++) 83 | { 84 | var currentBehavior:IBehavior = _allBehaviors[i]; 85 | if (currentBehavior.name == name) 86 | { 87 | behavior = currentBehavior; 88 | break; 89 | } 90 | } 91 | 92 | return behavior; 93 | } 94 | 95 | /** 96 | * returns a behavior at the supplied index 97 | * @param index 98 | * @return 99 | */ 100 | public function getBehaviorAt(index:int):IBehavior 101 | { 102 | return _allBehaviors[index]; 103 | } 104 | 105 | /** 106 | * returns the number of behaviors this manager has regardless whether their enabled or not 107 | * @return 108 | */ 109 | public function getNumOfBehaviors():int 110 | { 111 | return _allBehaviors.length; 112 | } 113 | 114 | /** 115 | * removes all this managers behaviors 116 | */ 117 | public function removeAllBehaviors():void 118 | { 119 | while (_allBehaviors.length) 120 | { 121 | removeImmediate(_allBehaviors[0]); 122 | } 123 | } 124 | 125 | /** 126 | * updates all the behaviors and checks to see if any are ready to be removed or added 127 | */ 128 | public function update():void 129 | { 130 | var numBehaviors:int = _allBehaviors.length; 131 | for (var i:int = 0; i < numBehaviors; i++) 132 | { 133 | //updates all the behaviors 134 | _allBehaviors[i].onUpdate(); 135 | } 136 | 137 | if (_behaviorsToRemove.length > 0) 138 | removeOldBehaviors(); 139 | 140 | if (_behaviorsToAdd.length > 0) 141 | addNewBehaviors(); 142 | } 143 | 144 | //--------------- 145 | // protected methods 146 | //--------------- 147 | 148 | protected function addNewBehaviors():void 149 | { 150 | while (_behaviorsToAdd.length) 151 | { 152 | addImmediate(_behaviorsToAdd[0]); 153 | _behaviorsToAdd.splice(0, 1); 154 | } 155 | } 156 | 157 | protected function removeOldBehaviors():void 158 | { 159 | while (_behaviorsToRemove.length) 160 | { 161 | removeImmediate(_behaviorsToRemove[0]); 162 | _behaviorsToRemove.splice(0, 1); 163 | } 164 | } 165 | } 166 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/behaviors/IBehavior.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.behaviors 2 | { 3 | 4 | /** 5 | * interface that defines what a behavior is 6 | */ 7 | public interface IBehavior 8 | { 9 | function added():void; 10 | 11 | function removed():void; 12 | 13 | function onUpdate():void; 14 | 15 | function get name():String; 16 | } 17 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/console/SPConsole.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.console 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunk.SPEntity; 5 | 6 | import flash.display.BitmapData; 7 | import flash.display.Graphics; 8 | import flash.display.Shape; 9 | import flash.geom.Rectangle; 10 | 11 | import starling.display.BlendMode; 12 | import starling.display.Image; 13 | import starling.display.Sprite; 14 | import starling.textures.Texture; 15 | 16 | /** 17 | * This is the basic placeholder for the console class, very little is working right now and should be avoided by typical users. 18 | * @author Andy Saia 19 | */ 20 | public class SPConsole 21 | { 22 | private var _enabled:Boolean; 23 | private var _container:Sprite; 24 | private var _allHitGraphics:Vector.; 25 | 26 | public function SPConsole() 27 | { 28 | } 29 | 30 | //------------------- 31 | // public methods 32 | //------------------- 33 | 34 | public function enable():void 35 | { 36 | trace("WARNING: the console class has not been implemented yet, this functionality provided here should be considered extremely experimental."); 37 | 38 | 39 | //return if already enabled 40 | if (_enabled) return; 41 | 42 | _enabled = true; 43 | 44 | _container = new Sprite(); 45 | SP.camera.container.addChild(_container); 46 | _allHitGraphics = new Vector.(); 47 | } 48 | 49 | public function update():void 50 | { 51 | //get out if console isn't enabled 52 | if (!_enabled) return; 53 | _container.parent.setChildIndex(_container, _container.parent.numChildren - 1); 54 | renderHitBoxes(); 55 | } 56 | 57 | //------------------- 58 | // private methods 59 | //------------------- 60 | 61 | private function renderHitBoxes():void 62 | { 63 | if (!SP.world) return; 64 | 65 | var hitBoxes:Vector. = getHitBoxes(); 66 | var numHitBoxes:int = hitBoxes.length; 67 | if (numHitBoxes == 0) return; 68 | 69 | //this method isn't working objects pop in and out 70 | getHitRectsForEntities(hitBoxes); 71 | 72 | for (var i:int = 0; i < numHitBoxes; i++) 73 | { 74 | var hitRect:Rectangle = hitBoxes[i]; 75 | var hitGraphic:Image = _allHitGraphics[i]; 76 | hitGraphic.x = hitRect.x; 77 | hitGraphic.y = hitRect.y; 78 | hitGraphic.width = hitRect.width; 79 | hitGraphic.height = hitRect.height; 80 | } 81 | } 82 | 83 | private function getHitBoxes():Vector. 84 | { 85 | //sure there are faster ways of doing this 86 | var entites:Vector. = SP.world.getAllEntities(); 87 | var hitBoxes:Vector. = new Vector.(); 88 | var numEntities:int = entites.length; 89 | for (var i:int = 0; i < numEntities; i++) 90 | { 91 | var entity:SPEntity = entites[i]; 92 | var hitbox:Rectangle = entity.hitBounds; 93 | if (hitbox.width != 0 || hitbox.height != 0) 94 | hitBoxes.push(hitbox); 95 | } 96 | 97 | return hitBoxes; 98 | } 99 | 100 | private function getHitRectsForEntities(allHitBoxes:Vector.):void 101 | { 102 | var numHitBoxes:int = allHitBoxes.length; 103 | if (numHitBoxes == _allHitGraphics.length) return; 104 | 105 | while(numHitBoxes < _allHitGraphics.length) 106 | { 107 | var lastIndex:int = 0; 108 | var oldImage:Image = _allHitGraphics[lastIndex]; 109 | _allHitGraphics.splice(lastIndex, 1); 110 | oldImage.removeFromParent(true); 111 | //TODO: probably should pool these 112 | } 113 | 114 | 115 | while(numHitBoxes > _allHitGraphics.length) 116 | { 117 | var newImage:Image = getHitRectGraphic(); 118 | _allHitGraphics.push(newImage); 119 | _container.addChild(newImage); 120 | } 121 | } 122 | 123 | private function getHitRectGraphic():Image 124 | { 125 | var shape:Shape = new Shape(); 126 | var lineWidth:Number = 5; 127 | shape.graphics.lineStyle(lineWidth, 0xFF0000); 128 | shape.graphics.drawRect(0, 0, 100, 100); 129 | var bitmapData:BitmapData = new BitmapData(100, 100, true, 0x00FFFFFF); 130 | bitmapData.draw(shape); 131 | var hitRectGraphic:Image = new Image(Texture.fromBitmapData(bitmapData)); 132 | hitRectGraphic.touchable = false; 133 | return hitRectGraphic; 134 | } 135 | 136 | public function destory():void 137 | { 138 | //TODO: clean everything up 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/effects/SPEffects.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.effects 2 | { 3 | /** 4 | * Collections of built-in effects 5 | * @author Andy Saia 6 | */ 7 | public class SPEffects 8 | { 9 | /** 10 | * 11 | * @param intensity size of randomness of shake effect 12 | * @param duration length of shake 13 | * @return returns an instance of the shake effect class 14 | */ 15 | public static function shake(intensity:Number = 10, duration:Number = 1000):ShakeEffect 16 | { 17 | var shakeEffect:ShakeEffect = new ShakeEffect(intensity, duration); 18 | shakeEffect.start(); 19 | return shakeEffect; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/effects/ShakeEffect.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.effects 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import flash.events.TimerEvent; 5 | import flash.geom.Point; 6 | import flash.utils.Timer; 7 | import starling.events.Event; 8 | /** 9 | * Shake effect class randomizes the position of the world for a given duration 10 | * @author Andy Saia 11 | */ 12 | public class ShakeEffect 13 | { 14 | private var _intensity:Number; 15 | private var _duration:Number; 16 | private var _isShakeing:Boolean; 17 | 18 | private var _startPos:Point; 19 | public function ShakeEffect(intensity:Number = 10, duration:Number = 1000) 20 | { 21 | _duration = duration; 22 | _intensity = intensity; 23 | 24 | _startPos = new Point(SP.halfWidth, SP.halfHeight); 25 | 26 | _isShakeing = false; 27 | } 28 | 29 | //---------- 30 | // getters and setters 31 | //---------- 32 | 33 | public function get intensity():Number 34 | { 35 | return _intensity; 36 | } 37 | 38 | public function get duration():Number 39 | { 40 | return _duration; 41 | } 42 | 43 | /** 44 | * Amount of random variation 45 | */ 46 | public function set intensity(value:Number):void 47 | { 48 | _intensity = value; 49 | } 50 | 51 | /** 52 | * Length of shakeing in milliseconds 53 | * @param length in milliseconds 54 | */ 55 | public function set duration(value:Number):void 56 | { 57 | _duration = value; 58 | } 59 | 60 | public function get isShakeing():Boolean 61 | { 62 | return _isShakeing; 63 | } 64 | 65 | //---------- 66 | // public methods 67 | //---------- 68 | 69 | /** 70 | * starts the shake effect 71 | */ 72 | public function start():void 73 | { 74 | var timer:Timer = new Timer(_duration, 1); 75 | timer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete, false, 0, true); 76 | timer.start(); 77 | 78 | SP.world.addEventListener(Event.ENTER_FRAME, enterFrame); 79 | _isShakeing = true; 80 | } 81 | 82 | //---------- 83 | // event handlers 84 | //---------- 85 | 86 | private function enterFrame(e:Event):void 87 | { 88 | shake(); 89 | } 90 | 91 | private function onTimerComplete(e:TimerEvent):void 92 | { 93 | var target:Timer = e.currentTarget as Timer; 94 | target.removeEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete); 95 | SP.world.removeEventListener(Event.ENTER_FRAME, enterFrame); 96 | 97 | SP.world.x = _startPos.x; 98 | SP.world.y = _startPos.y; 99 | _isShakeing = false; 100 | } 101 | 102 | //---------- 103 | // private methods 104 | //---------- 105 | 106 | private function shake():void 107 | { 108 | SP.world.x = _startPos.x - (Math.random() * _intensity - (_intensity * .5)); 109 | SP.world.y = _startPos.y - (Math.random() * _intensity - (_intensity * .5)); 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/events/EngineEvent.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.events 2 | { 3 | import starling.events.Event; 4 | 5 | /** 6 | * Called when the engine pauses and unpauses useful for stoping background processes or timers 7 | */ 8 | public class EngineEvent extends Event 9 | { 10 | /** 11 | * Paused event dispatched when the engine is paused 12 | */ 13 | public static const PAUSED:String = "paused"; 14 | /** 15 | * Unpaused event dispatched when the engine is unpaused 16 | */ 17 | public static const UNPAUSED:String = "unpaused"; 18 | 19 | public function EngineEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false) 20 | { 21 | super(type, bubbles); 22 | 23 | } 24 | 25 | public override function toString():String 26 | { 27 | return ("EngineEvent" + "type" + "bubbles"+ "cancelable"+ "eventPhase"); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/extensions/ogmopunk/ImageDefinition.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.extensions.ogmopunk 2 | { 3 | /** 4 | * ... 5 | * @author Erin M Gunn 6 | */ 7 | public class ImageDefinition 8 | { 9 | public var drawMode:String; 10 | public var imagePath:String; 11 | public var tiled:Boolean; 12 | public var color:uint; 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/extensions/ogmopunk/OgmoEntityDefinition.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.extensions.ogmopunk 2 | { 3 | import com.saia.starlingPunk.SPEntity; 4 | import flash.geom.Point; 5 | import flash.utils.getDefinitionByName; 6 | /** 7 | * ... 8 | * @author Erin M Gunn 9 | */ 10 | public class OgmoEntityDefinition 11 | { 12 | public var name:String; 13 | public var className:String; 14 | 15 | public var limit:int; 16 | public var resizableX:Boolean; 17 | public var resizableY:Boolean; 18 | public var rotatable:Boolean; 19 | public var rotateIncrements:int; 20 | public var values:Vector.; 21 | 22 | public var size:Point; 23 | public var origin:Point; 24 | public var imageDef:ImageDefinition; 25 | 26 | public function loadData(dta:XML):SPEntity 27 | { 28 | var clsRef:Class = (getDefinitionByName(className) as Class); 29 | var e:SPEntity = new clsRef; 30 | e.x = dta.@x; 31 | e.y = dta.@y; 32 | //e.type = name; 33 | //e.setHitbox(size.x, size.y, origin.x, origin.y); 34 | var value:OgmoValue; 35 | for (var i:int = 0; i < values.length; i++) 36 | { 37 | value = values[i]; 38 | if (value.type == uint) value.mValue = uint(dta.attribute(value.name).toString().replace("#", "0x")); 39 | else if (value.type == Boolean) value.mValue = dta.attribute(value.name).toString() == "True"; 40 | else if (value.type == Number) value.mValue = Number(dta.attribute(value.name)); 41 | else value.mValue = dta.attribute(value.name).toString() as value.type; 42 | if (e.hasOwnProperty(value.name)) 43 | { 44 | if ((typeof e[value.name] == typeof Function || e[value.name] is Function) && value.type == String && clsRef.hasOwnProperty(value.value)) 45 | { 46 | e[value.name] = clsRef[value.value as String]; 47 | } 48 | else e[value.name] = value.value as value.type; 49 | } 50 | } 51 | if (resizableX) e.width = dta.@width; 52 | if (resizableY) e.height = dta.@height; 53 | 54 | var nodes:Vector. = new Vector.; 55 | for each(var node:XML in dta.children()) 56 | { 57 | if (node.localName() == "node") 58 | { 59 | nodes.push(new Point(node.@x, node.@y)); 60 | } 61 | } 62 | if (nodes.length > 0) 63 | { 64 | e["nodes"] = nodes; 65 | } 66 | 67 | return e; 68 | } 69 | } 70 | 71 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/extensions/ogmopunk/OgmoLayer.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.extensions.ogmopunk 2 | { 3 | import com.saia.starlingPunk.SPEntity; 4 | import flash.geom.Point; 5 | /** 6 | * ... 7 | * @author Erin M Gunn 8 | */ 9 | public class OgmoLayer 10 | { 11 | internal var mName:String; 12 | public function get name():String 13 | { 14 | return mName; 15 | } 16 | 17 | internal var mGrid:Point; 18 | public function get grid():Point 19 | { 20 | return mGrid; 21 | } 22 | 23 | internal var mScrollFator:Point; 24 | public function get scrollFactor():Point 25 | { 26 | return mScrollFator; 27 | } 28 | 29 | internal var mData:XML 30 | public function get data():XML 31 | { 32 | return mData; 33 | } 34 | 35 | public function loadData():Vector. 36 | { 37 | return null; 38 | } 39 | } 40 | 41 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/extensions/ogmopunk/OgmoTileSet.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.extensions.ogmopunk 2 | { 3 | 4 | import flash.display.Bitmap; 5 | import flash.events.Event; 6 | import flash.geom.Point; 7 | /** 8 | * ... 9 | * @author Erin M Gunn 10 | */ 11 | public class OgmoTileSet 12 | { 13 | internal var mTileSet:Object; 14 | public function get tileSet():Object 15 | { 16 | return mTileSet; 17 | } 18 | 19 | internal var mName:String; 20 | public function get name():String 21 | { 22 | return mName; 23 | } 24 | 25 | internal var mFilePath:String; 26 | public function get filePath():String 27 | { 28 | return mFilePath; 29 | } 30 | 31 | internal var mTileSize:Point; 32 | public function get tileSize():Point 33 | { 34 | return mTileSize; 35 | } 36 | 37 | internal var mTileSep:uint; 38 | public function get tileSep():uint 39 | { 40 | return mTileSep; 41 | } 42 | 43 | public function onInitTileset(e:Event):void 44 | { 45 | mTileSet = Bitmap(e.target.loader.content).bitmapData; 46 | OgmoProject.mEventQueue--; 47 | } 48 | 49 | public static function LoadTileset(dataElement:XML, tileSetsContainer:Object):OgmoTileSet 50 | { 51 | var t:OgmoTileSet = new OgmoTileSet(); 52 | t.mName = dataElement.Name; 53 | t.mFilePath = dataElement.FilePath; 54 | t.mTileSize = new Point(dataElement.TileSize.Width, dataElement.TileSize.Height); 55 | t.mTileSep = dataElement.TileSep; 56 | if (tileSetsContainer.hasOwnProperty(t.mName)) t.mTileSet = tileSetsContainer[t.mName]; 57 | 58 | return t; 59 | } 60 | } 61 | 62 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/extensions/ogmopunk/OgmoValue.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.extensions.ogmopunk 2 | { 3 | /** 4 | * ... 5 | * @author Erin M Gunn 6 | */ 7 | public class OgmoValue 8 | { 9 | internal var mName:String; 10 | public function get name():String 11 | { 12 | return mName; 13 | } 14 | 15 | internal var mValue:Object 16 | public function get value():Object 17 | { 18 | return mValue; 19 | } 20 | 21 | internal var mType:Class; 22 | public function get type():Class 23 | { 24 | return mType; 25 | } 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/extensions/ogmopunk/layers/EntityLayer.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.extensions.ogmopunk.layers 2 | { 3 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoEntityDefinition; 4 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoLayer; 5 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoProject; 6 | import com.saia.starlingPunk.SPEntity; 7 | /** 8 | * ... 9 | * @author Erin M Gunn 10 | */ 11 | public class EntityLayer extends OgmoLayer 12 | { 13 | 14 | override public function loadData():Vector. 15 | { 16 | var entities:Vector. = new Vector.(); 17 | 18 | var xml:XML; 19 | for each(xml in this.data.children()) 20 | { 21 | var eDef:OgmoEntityDefinition = OgmoProject.entities[xml.localName().toString()]; 22 | var e:SPEntity = eDef.loadData(xml); 23 | entities.push(e); 24 | } 25 | return entities; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/extensions/ogmopunk/layers/GridLayer.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.extensions.ogmopunk.layers 2 | { 3 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoLayer; 4 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoProject; 5 | import com.saia.starlingPunk.masks.SPGrid; 6 | import com.saia.starlingPunk.SPEntity; 7 | /** 8 | * ... 9 | * @author Erin M Gunn 10 | */ 11 | public class GridLayer extends OgmoLayer 12 | { 13 | public var mExportMode:String; 14 | public function get exportMode():String 15 | { 16 | return mExportMode; 17 | } 18 | 19 | override public function loadData():Vector. 20 | { 21 | var e:SPEntity = new SPEntity(0, 0, name); 22 | var grid:SPGrid = new SPGrid(OgmoProject.levelDims.x, OgmoProject.levelDims.y, grid.x, grid.y); 23 | if (exportMode == "Bitstring") 24 | { 25 | grid.loadFromString(data.toString(), '', '\n'); 26 | } 27 | e.mask = grid; 28 | 29 | e.setHitWidth(OgmoProject.levelDims.x); 30 | e.setHitHeight(OgmoProject.levelDims.y); 31 | var es:Vector. = new Vector.(); 32 | es.push(e); 33 | return es; 34 | 35 | return null; 36 | } 37 | 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/extensions/ogmopunk/layers/TileLayer.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.extensions.ogmopunk.layers 2 | { 3 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoLayer; 4 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoProject; 5 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoTileSet; 6 | import com.saia.starlingPunk.graphics.SPTilemap; 7 | import com.saia.starlingPunk.SPEntity; 8 | /** 9 | * ... 10 | * @author Erin M Gunn 11 | */ 12 | public class TileLayer extends OgmoLayer 13 | { 14 | 15 | public var mExportMode:String; 16 | public function get exportMode():String 17 | { 18 | return mExportMode; 19 | } 20 | 21 | override public function loadData():Vector. 22 | { 23 | var tileSet:OgmoTileSet = OgmoProject.tileSets[this.data.@tileset]; 24 | var e:SPEntity = new SPEntity(0, 0, tileSet.name); 25 | var tilemap:SPTilemap = new SPTilemap(OgmoProject.levelDims.x, OgmoProject.levelDims.y, tileSet.tileSize.x, tileSet.tileSize.y) 26 | if (!OgmoProject.tileSetImages) throw new Error("You must first call the createTilesFromTextureAtlas method in the OgmoProject class"); 27 | 28 | //passes the image vector to the tile class 29 | tilemap.createTilesFromVector(OgmoProject.getTileSet(tileSet.name)); 30 | 31 | //e.graphic.scrollX = scrollFactor.x; 32 | //e.graphic.scrollY = scrollFactor.y; 33 | 34 | if (exportMode == "CSV") 35 | { 36 | var str:String = this.data.toString(); 37 | str = str.replace(new RegExp('-1', 'g'), ''); 38 | tilemap.loadFromString(str); 39 | } 40 | 41 | var es:Vector. = new Vector.(); 42 | es.push(e); 43 | e.addChild(tilemap); 44 | 45 | return es; 46 | } 47 | } 48 | 49 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/graphics/SpriteCanvas.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.graphics 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import flash.geom.Rectangle; 5 | import starling.display.BlendMode; 6 | import starling.display.Sprite; 7 | 8 | /** 9 | * This class is used interally for StarlingPunk's Tilemap system. Its optimized for displaying thousands of images by only rendering what's visible by the camera 10 | * @author Andy Saia 11 | */ 12 | public class SpriteCanvas 13 | { 14 | private var _width:Number; 15 | private var _height:Number; 16 | private var _numColumns:int; 17 | private var _numRows:int; 18 | 19 | private var _spriteColumns:Vector.>; 20 | private var _refreshFlag:Boolean; 21 | private var _spriteRect:Rectangle; 22 | private var _rect:Rectangle; 23 | private var _viewPadding:int = 20; 24 | private var _container:Sprite; 25 | 26 | public function SpriteCanvas(container:Sprite, width:Number, height:Number) 27 | { 28 | _container = container; 29 | _width = width; 30 | _height = height; 31 | 32 | _numColumns = Math.ceil(_width / SP.width); 33 | _numRows = Math.ceil(_height / SP.height); 34 | _spriteRect = new Rectangle(0, 0, SP.width, SP.height); 35 | _rect = new Rectangle(); 36 | 37 | populateSpriteArray(); 38 | } 39 | 40 | //------------------- 41 | // public methods 42 | //------------------- 43 | 44 | /** 45 | * returns the sprite object at the given column and row index 46 | * @param column 47 | * @param row 48 | * @return 49 | */ 50 | public function getSpriteTile(column:int, row:int):Sprite 51 | { 52 | var columnIndex:int = Math.floor(column / SP.width); 53 | var rowIndex:int = Math.floor(row / SP.height); 54 | var sprite:Sprite = _spriteColumns[columnIndex][rowIndex]; 55 | sprite.x = columnIndex * SP.width; 56 | sprite.y = rowIndex * SP.height; 57 | sprite.blendMode = BlendMode.NONE; 58 | 59 | return sprite; 60 | } 61 | 62 | /** 63 | * flattens all the sprite tiles in order to batch their rendering 64 | */ 65 | public function flattenSpriteTiles():void 66 | { 67 | for (var x:int = 0; x < _numColumns; x++) 68 | { 69 | for (var y:int = 0; y < _numRows; y++) 70 | { 71 | if (x != 0 || y != 0) 72 | { 73 | _spriteColumns[x][y].flatten(); 74 | } 75 | } 76 | } 77 | } 78 | 79 | /** 80 | * called internally by SPTilemap, checks if each tile is visible by the game camera 81 | */ 82 | public function update():void 83 | { 84 | checkSpriteVisibilites(); 85 | 86 | //this drastically reduces the number of draw calls but there is a pretty serious delay when it reflattens the container sprite 87 | //hopefully future versions will further optimise this 88 | /* 89 | if (_refreshFlag) 90 | { 91 | _container.flatten(); 92 | _refreshFlag = false; 93 | } 94 | */ 95 | } 96 | 97 | /** 98 | * remove all sprites and dispose of everything for garbage collector 99 | */ 100 | public function destroy():void 101 | { 102 | for (var x:int = 0; x < _numColumns; x++) 103 | { 104 | for (var y:int = 0; y < _numRows; y++) 105 | { 106 | if (x != 0 || y != 0) 107 | { 108 | var sprite:Sprite = _spriteColumns[x][y]; 109 | sprite.removeFromParent(true); 110 | } 111 | } 112 | } 113 | _spriteColumns = null; 114 | } 115 | 116 | //--------------- 117 | // private methods 118 | //--------------- 119 | 120 | private function populateSpriteArray():void 121 | { 122 | _refreshFlag = false; 123 | 124 | _spriteColumns = new Vector.>([_numColumns]); 125 | for (var x:int = 0; x < _numColumns; x++) 126 | { 127 | var spriteRows:Vector. = new Vector.([_numRows]); 128 | for (var y:int = 0; y < _numRows; y++) 129 | { 130 | spriteRows[y] = new Sprite(); 131 | } 132 | _spriteColumns[x] = spriteRows; 133 | } 134 | } 135 | 136 | private function checkSpriteVisibilites():void 137 | { 138 | //the collision rectangle gets offset in case where scrolling quickly 139 | var viewPort:Rectangle = SP.camera.viewPort; 140 | _rect.width = viewPort.width + _viewPadding; 141 | _rect.height = viewPort.height + _viewPadding; 142 | _rect.x = viewPort.x - _viewPadding; 143 | _rect.y = viewPort.y - _viewPadding; 144 | 145 | var activeTileX:int = Math.floor(viewPort.x / SP.width); 146 | var activeTileY:int = Math.floor(viewPort.y / SP.height); 147 | if (activeTileX - 1 >= 0) 148 | activeTileX -= 1; 149 | else 150 | activeTileX = 0; 151 | 152 | if (activeTileY - 1 >= 0) 153 | activeTileY -= 1; 154 | else 155 | activeTileY = 0; 156 | 157 | for (var x:int = activeTileX; x < activeTileX + 3; x++) 158 | { 159 | if (x >= _numColumns) return; 160 | for (var y:int = activeTileY; y < activeTileY + 3; y++) 161 | { 162 | if (y >= _numRows) return; 163 | var sprite:Sprite = _spriteColumns[x][y]; 164 | 165 | _spriteRect.x = x * SP.width; 166 | _spriteRect.y = y * SP.height; 167 | if (_rect.intersects(_spriteRect)) 168 | { 169 | if (!sprite.parent) 170 | { 171 | _container.addChild(sprite); 172 | _refreshFlag = true; 173 | } 174 | } 175 | else if (sprite.parent) 176 | { 177 | sprite.removeFromParent(); 178 | _refreshFlag = true; 179 | } 180 | } 181 | } 182 | } 183 | } 184 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/helpers/ColorUtils.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.helpers 2 | { 3 | /** 4 | * ... 5 | * @author Andy Saia 6 | */ 7 | public class ColorUtils 8 | { 9 | public static function RGBToHex(r:uint, g:uint, b:uint):uint 10 | { 11 | var hex:uint = (r << 16 | g << 8 | b); 12 | return hex; 13 | } 14 | 15 | public static function HexToRGB(hex:uint):Vector. 16 | { 17 | var rgb:Vector. = new Vector.(); 18 | 19 | var r:uint = hex >> 16 & 0xFF; 20 | var g:uint = hex >> 8 & 0xFF; 21 | var b:uint = hex & 0xFF; 22 | 23 | rgb.push(r, g, b); 24 | return rgb; 25 | } 26 | 27 | public static function HexToDeci(hex:String):uint 28 | { 29 | if (hex.substr(0, 2) != "0x") 30 | { 31 | hex = "0x" + hex; 32 | } 33 | return new uint(hex); 34 | } 35 | 36 | public static function hexToHsv(color:uint):Vector. 37 | { 38 | var colors:Vector. = HexToRGB(color); 39 | return RGBtoHSV(colors[0], colors[1], colors[2]); 40 | } 41 | 42 | public static function hsvToHex(h:Number, s:Number, v:Number):uint 43 | { 44 | var colors:Vector. = HSVtoRGB(h, s, v); 45 | return RGBToHex(colors[0], colors[1], colors[2]); 46 | } 47 | 48 | /** 49 | * Converts Red, Green, Blue to Hue, Saturation, Value 50 | * @r channel between 0-255 51 | * @s channel between 0-255 52 | * @v channel between 0-255 53 | */ 54 | public static function RGBtoHSV(r:uint, g:uint, b:uint):Vector. 55 | { 56 | var max:uint = Math.max(r, g, b); 57 | var min:uint = Math.min(r, g, b); 58 | 59 | var hue:Number = 0; 60 | var saturation:Number = 0; 61 | var value:Number = 0; 62 | 63 | var hsv:Vector. = new Vector.(); 64 | 65 | //get Hue 66 | if (max == min) 67 | hue = 0; 68 | else if (max == r) 69 | hue = (60 * (g-b) / (max-min) + 360) % 360; 70 | else if (max == g) 71 | hue = (60 * (b-r) / (max-min) + 120); 72 | else if (max == b) 73 | hue = (60 * (r-g) / (max-min) + 240); 74 | 75 | //get Value 76 | value = max; 77 | 78 | //get Saturation 79 | if(max == 0) 80 | saturation = 0; 81 | else 82 | saturation = (max - min) / max; 83 | 84 | hsv = Vector.([Math.round(hue), Math.round(saturation * 100), Math.round(value / 255 * 100)]); 85 | return hsv; 86 | } 87 | 88 | 89 | /** 90 | * Converts Hue, Saturation, Value to Red, Green, Blue 91 | * @h Angle between 0-360 92 | * @s percent between 0-100 93 | * @v percent between 0-100 94 | */ 95 | public static function HSVtoRGB(h:Number, s:Number, v:Number):Vector. 96 | { 97 | var r:Number = 0; 98 | var g:Number = 0; 99 | var b:Number = 0; 100 | var rgb:Vector. = new Vector.(); 101 | 102 | var tempS:Number = s / 100; 103 | var tempV:Number = v / 100; 104 | 105 | var hi:int = Math.floor(h/60) % 6; 106 | var f:Number = h/60 - Math.floor(h/60); 107 | var p:Number = (tempV * (1 - tempS)); 108 | var q:Number = (tempV * (1 - f * tempS)); 109 | var t:Number = (tempV * (1 - (1 - f) * tempS)); 110 | 111 | switch(hi) 112 | { 113 | case 0: r = tempV; g = t; b = p; break; 114 | case 1: r = q; g = tempV; b = p; break; 115 | case 2: r = p; g = tempV; b = t; break; 116 | case 3: r = p; g = q; b = tempV; break; 117 | case 4: r = t; g = p; b = tempV; break; 118 | case 5: r = tempV; g = p; b = q; break; 119 | } 120 | 121 | rgb = Vector.([Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]); 122 | return rgb; 123 | } 124 | 125 | } 126 | 127 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/helpers/Primitives.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.helpers 2 | { 3 | import flash.display.BitmapData; 4 | import flash.display.Shape; 5 | import starling.display.Image; 6 | import starling.textures.Texture; 7 | /** 8 | * This Class contains helper classes for drawing primitive shapes usufuly for prototyping 9 | * @author Andy Saia 10 | */ 11 | public class Primitives 12 | { 13 | public static function rect(width:Number = 100, height:Number = 100, color:uint = 0xFF0000):Image 14 | { 15 | var bmpData:BitmapData = new BitmapData(width, height, false, color); 16 | var image:Image = new Image(Texture.fromBitmapData(bmpData)); 17 | return image; 18 | } 19 | 20 | public static function circle(radius:Number = 50, color:uint = 0xFF0000):Image 21 | { 22 | var shape:Shape = new Shape(); 23 | shape.graphics.beginFill(color); 24 | shape.graphics.drawCircle(radius, radius, radius); 25 | 26 | var bmpData:BitmapData = new BitmapData(radius * 2, radius * 2, true, 0x00FFFFFF); 27 | bmpData.draw(shape, null, null, null, null, true); 28 | var image:Image = new Image(Texture.fromBitmapData(bmpData)); 29 | return image; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/helpers/SPMath.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.helpers 2 | { 3 | /** 4 | * Collection of Math helper methods 5 | * @author Andy Saia 6 | */ 7 | public class SPMath 8 | { 9 | 10 | /** 11 | * returns random number inbetween min and max 12 | * @param minNum 13 | * @param maxNum 14 | * @return random number inbetween min and max 15 | */ 16 | public static function range(minNum:Number, maxNum:Number):Number 17 | { 18 | return (Math.floor(Math.random() * (maxNum - minNum + 1)) + minNum); 19 | } 20 | 21 | /** 22 | * returns a random index of the given array 23 | */ 24 | public static function getRandomIndex(array:*):int 25 | { 26 | var index:int = Math.floor(Math.random() * array.length); 27 | return index; 28 | } 29 | 30 | /** 31 | * converts degrees to radians 32 | */ 33 | public static function degreesToRadians(degrees:Number):Number 34 | { 35 | return degrees * Math.PI / 180; 36 | } 37 | 38 | /** 39 | * converts radians to degrees 40 | */ 41 | public static function radiansToDegrees(radians:Number):Number 42 | { 43 | return radians * 180 / Math.PI; 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/masks/SPHitbox.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.masks 2 | { 3 | import com.saia.starlingPunk.SPMask; 4 | 5 | /** 6 | * Uses parent's hitbox to determine collision. This class is used 7 | * internally by FlashPunk, you don't need to use this class because 8 | * this is the default behaviour of Entities without a Mask object. 9 | */ 10 | public class SPHitbox extends SPMask 11 | { 12 | /** 13 | * Constructor. 14 | * @param width Width of the hitbox. 15 | * @param height Height of the hitbox. 16 | * @param x X offset of the hitbox. 17 | * @param y Y offset of the hitbox. 18 | */ 19 | public function SPHitbox(width:uint = 1, height:uint = 1, x:int = 0, y:int = 0) 20 | { 21 | _width = width; 22 | _height = height; 23 | _x = x; 24 | _y = y; 25 | _check[SPMask] = collideMask; 26 | _check[SPHitbox] = collideHitbox; 27 | } 28 | 29 | /** @private Collides against an Entity. */ 30 | private function collideMask(other:SPMask):Boolean 31 | { 32 | return parent.x + _x + _width > other.parent.x - other.parent.pivotX 33 | && parent.y + _y + _height > other.parent.y - other.parent.pivotY 34 | && parent.x + _x < other.parent.x - other.parent.pivotX + other.parent.originX + other.parent.hitWidth 35 | && parent.y + _y < other.parent.y - other.parent.pivotY + other.parent.originY + other.parent.hitHeight; 36 | } 37 | 38 | /** @private Collides against a Hitbox. */ 39 | private function collideHitbox(other:SPHitbox):Boolean 40 | { 41 | return parent.x + _x + _width > other.parent.x + other._x 42 | && parent.y + _y + _height > other.parent.y + other._y 43 | && parent.x + _x < other.parent.x + other._x + other._width 44 | && parent.y + _y < other.parent.y + other._y + other._height; 45 | } 46 | 47 | /** 48 | * X offset. 49 | */ 50 | public function get x():int { return _x; } 51 | public function set x(value:int):void 52 | { 53 | if (_x == value) return; 54 | _x = value; 55 | if (list) list.update(); 56 | else if (parent) update(); 57 | } 58 | 59 | /** 60 | * Y offset. 61 | */ 62 | public function get y():int { return _y; } 63 | public function set y(value:int):void 64 | { 65 | if (_y == value) return; 66 | _y = value; 67 | if (list) list.update(); 68 | else if (parent) update(); 69 | } 70 | 71 | /** 72 | * Width. 73 | */ 74 | public function get width():int { return _width; } 75 | public function set width(value:int):void 76 | { 77 | if (_width == value) return; 78 | _width = value; 79 | if (list) list.update(); 80 | else if (parent) update(); 81 | } 82 | 83 | /** 84 | * Height. 85 | */ 86 | public function get height():int { return _height; } 87 | public function set height(value:int):void 88 | { 89 | if (_height == value) return; 90 | _height = value; 91 | if (list) list.update(); 92 | else if (parent) update(); 93 | } 94 | 95 | /** @private Updates the parent's bounds for this mask. */ 96 | override protected function update():void 97 | { 98 | // update entity bounds 99 | parent.originX = -_x; 100 | parent.originY = -_y; 101 | parent.width = _width; 102 | parent.height = _height; 103 | 104 | // update parent list 105 | if (list) list.update(); 106 | } 107 | 108 | // Hitbox information. 109 | /** @private */ internal var _width:uint; 110 | /** @private */ internal var _height:uint; 111 | /** @private */ internal var _x:int; 112 | /** @private */ internal var _y:int; 113 | } 114 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/masks/SPMasklist.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.masks 2 | { 3 | import com.saia.starlingPunk.SPMask; 4 | 5 | /** 6 | * A Mask that can contain multiple Masks of one or various types. 7 | */ 8 | public class SPMasklist extends SPHitbox 9 | { 10 | /** 11 | * Constructor. 12 | * @param ...mask Masks to add to the list. 13 | */ 14 | public function SPMasklist(...mask) 15 | { 16 | for each (var m:SPMask in mask) add(m); 17 | } 18 | 19 | /** @private Collide against a mask. */ 20 | override public function collide(mask:SPMask):Boolean 21 | { 22 | for each (var m:SPMask in _masks) 23 | { 24 | if (m.collide(mask)) return true; 25 | } 26 | return false; 27 | } 28 | 29 | /** 30 | * Adds a Mask to the list. 31 | * @param mask The Mask to add. 32 | * @return The added Mask. 33 | */ 34 | public function add(mask:SPMask):SPMask 35 | { 36 | _masks[_count ++] = mask; 37 | mask.list = this; 38 | update(); 39 | return mask; 40 | } 41 | 42 | /** 43 | * Removes the Mask from the list. 44 | * @param mask The Mask to remove. 45 | * @return The removed Mask. 46 | */ 47 | public function remove(mask:SPMask):SPMask 48 | { 49 | if (_masks.indexOf(mask) < 0) return mask; 50 | _temp.length = 0; 51 | for each (var m:SPMask in _masks) 52 | { 53 | if (m == mask) 54 | { 55 | mask.list = null; 56 | _count --; 57 | update(); 58 | } 59 | else _temp[_temp.length] = m; 60 | } 61 | var temp:Vector. = _masks; 62 | _masks = _temp; 63 | _temp = temp; 64 | return mask; 65 | } 66 | 67 | /** 68 | * Removes the Mask at the index. 69 | * @param index The Mask index. 70 | */ 71 | public function removeAt(index:uint = 0):void 72 | { 73 | _temp.length = 0; 74 | var i:int = _masks.length; 75 | index %= i; 76 | while (i --) 77 | { 78 | if (i == index) 79 | { 80 | _masks[index].list = null; 81 | _count --; 82 | update(); 83 | } 84 | else _temp[_temp.length] = _masks[index]; 85 | } 86 | var temp:Vector. = _masks; 87 | _masks = _temp; 88 | _temp = temp; 89 | } 90 | 91 | /** 92 | * Removes all Masks from the list. 93 | */ 94 | public function removeAll():void 95 | { 96 | for each (var m:SPMask in _masks) m.list = null; 97 | _masks.length = _temp.length = _count = 0; 98 | update(); 99 | } 100 | 101 | /** 102 | * Gets a Mask from the list. 103 | * @param index The Mask index. 104 | * @return The Mask at the index. 105 | */ 106 | public function getMask(index:uint = 0):SPMask 107 | { 108 | return _masks[index % _masks.length]; 109 | } 110 | 111 | /** @private Updates the parent's bounds for this mask. */ 112 | override protected function update():void 113 | { 114 | // find bounds of the contained masks 115 | var t:int, l:int, r:int, b:int, h:SPHitbox, i:int = _count; 116 | while (i --) 117 | { 118 | if ((h == _masks[i] as SPHitbox)) 119 | { 120 | if (h._x < l) l = h._x; 121 | if (h._y < t) t = h._y; 122 | if (h._x + h._width > r) r = h._x + h._width; 123 | if (h._y + h._height > b) b = h._y + h._height; 124 | } 125 | } 126 | 127 | // update hitbox bounds 128 | _x = l; 129 | _y = t; 130 | _width = r - l; 131 | _height = b - t; 132 | super.update(); 133 | } 134 | 135 | /** 136 | * Amount of Masks in the list. 137 | */ 138 | public function get count():uint { return _count; } 139 | 140 | // List information. 141 | /** @private */ private var _masks:Vector. = new Vector.; 142 | /** @private */ private var _temp:Vector. = new Vector.; 143 | /** @private */ private var _count:uint; 144 | } 145 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/masks/SPPixelmask.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.masks 2 | { 3 | import adobe.utils.CustomActions; 4 | import com.saia.starlingPunk.SPMask; 5 | import com.saia.starlingPunk.SP; 6 | import flash.display.BitmapData; 7 | import flash.geom.Point; 8 | import flash.geom.Rectangle; 9 | 10 | /** 11 | * A bitmap mask used for pixel-perfect collision. 12 | */ 13 | public class SPPixelmask extends SPHitbox 14 | { 15 | /** 16 | * Alpha threshold of the bitmap used for collision. 17 | */ 18 | public var threshold:uint = 1; 19 | 20 | /** 21 | * Constructor. 22 | * @param source The image to use as a mask. 23 | * @param x X offset of the mask. 24 | * @param y Y offset of the mask. 25 | */ 26 | public function SPPixelmask(source:BitmapData, x:int = 0, y:int = 0) 27 | { 28 | // fetch mask data 29 | if (source is BitmapData) _data = source; 30 | if (source is Class) _data = source; 31 | if (!_data) throw new Error("Invalid Pixelmask source image."); 32 | 33 | // set mask properties 34 | _width = data.width; 35 | _height = data.height; 36 | _x = x; 37 | _y = y; 38 | 39 | // set callback functions 40 | _check[SPMask] = collideMask; 41 | _check[SPPixelmask] = collidePixelmask; 42 | _check[SPHitbox] = collideHitbox; 43 | } 44 | 45 | /** @private Collide against an Entity. */ 46 | private function collideMask(other:SPMask):Boolean 47 | { 48 | _point.x = parent.x + _x; 49 | _point.y = parent.y + _y; 50 | _rect.x = other.parent.x - other.parent.pivotX - other.parent.originX; 51 | _rect.y = other.parent.y - other.parent.pivotY - other.parent.originY; 52 | _rect.width = other.parent.width; 53 | _rect.height = other.parent.height; 54 | return _data.hitTest(_point, threshold, _rect); 55 | } 56 | 57 | /** @private Collide against a Hitbox. */ 58 | private function collideHitbox(other:SPHitbox):Boolean 59 | { 60 | _point.x = parent.x + _x; 61 | _point.y = parent.y + _y; 62 | _rect.x = other.parent.x + other._x; 63 | _rect.y = other.parent.y + other._y; 64 | _rect.width = other._width; 65 | _rect.height = other._height; 66 | return _data.hitTest(_point, threshold, _rect); 67 | } 68 | 69 | /** @private Collide against a Pixelmask. */ 70 | private function collidePixelmask(other:SPPixelmask):Boolean 71 | { 72 | _point.x = parent.x + _x; 73 | _point.y = parent.y + _y; 74 | _point2.x = other.parent.x + other._x; 75 | _point2.y = other.parent.y + other._y; 76 | return _data.hitTest(_point, threshold, other._data, _point2, other.threshold); 77 | } 78 | 79 | /** 80 | * Current BitmapData mask. 81 | */ 82 | public function get data():BitmapData { return _data; } 83 | public function set data(value:BitmapData):void 84 | { 85 | _data = value; 86 | _width = value.width; 87 | _height = value.height; 88 | update(); 89 | } 90 | 91 | // Pixelmask information. 92 | /** @private */ internal var _data:BitmapData; 93 | 94 | // Global objects. 95 | /** @private */ private var _rect:Rectangle = SP.rect; 96 | /** @private */ private var _point:Point = SP.point; 97 | /** @private */ private var _point2:Point = SP.point2; 98 | } 99 | } -------------------------------------------------------------------------------- /lib/com/saia/starlingPunk/utils/Key.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunk.utils 2 | { 3 | /** 4 | * Contains static key constants to be used by Input. 5 | */ 6 | public class Key 7 | { 8 | public static const ANY:int = -1; 9 | 10 | public static const LEFT:int = 37; 11 | public static const UP:int = 38; 12 | public static const RIGHT:int = 39; 13 | public static const DOWN:int = 40; 14 | 15 | public static const ENTER:int = 13; 16 | public static const CONTROL:int = 17; 17 | public static const SPACE:int = 32; 18 | public static const SHIFT:int = 16; 19 | public static const BACKSPACE:int = 8; 20 | public static const CAPS_LOCK:int = 20; 21 | public static const DELETE:int = 46; 22 | public static const END:int = 35; 23 | public static const ESCAPE:int = 27; 24 | public static const HOME:int = 36; 25 | public static const INSERT:int = 45; 26 | public static const TAB:int = 9; 27 | public static const PAGE_DOWN:int = 34; 28 | public static const PAGE_UP:int = 33; 29 | public static const LEFT_SQUARE_BRACKET:int = 219; 30 | public static const RIGHT_SQUARE_BRACKET:int = 221; 31 | 32 | public static const A:int = 65; 33 | public static const B:int = 66; 34 | public static const C:int = 67; 35 | public static const D:int = 68; 36 | public static const E:int = 69; 37 | public static const F:int = 70; 38 | public static const G:int = 71; 39 | public static const H:int = 72; 40 | public static const I:int = 73; 41 | public static const J:int = 74; 42 | public static const K:int = 75; 43 | public static const L:int = 76; 44 | public static const M:int = 77; 45 | public static const N:int = 78; 46 | public static const O:int = 79; 47 | public static const P:int = 80; 48 | public static const Q:int = 81; 49 | public static const R:int = 82; 50 | public static const S:int = 83; 51 | public static const T:int = 84; 52 | public static const U:int = 85; 53 | public static const V:int = 86; 54 | public static const W:int = 87; 55 | public static const X:int = 88; 56 | public static const Y:int = 89; 57 | public static const Z:int = 90; 58 | 59 | public static const F1:int = 112; 60 | public static const F2:int = 113; 61 | public static const F3:int = 114; 62 | public static const F4:int = 115; 63 | public static const F5:int = 116; 64 | public static const F6:int = 117; 65 | public static const F7:int = 118; 66 | public static const F8:int = 119; 67 | public static const F9:int = 120; 68 | public static const F10:int = 121; 69 | public static const F11:int = 122; 70 | public static const F12:int = 123; 71 | public static const F13:int = 124; 72 | public static const F14:int = 125; 73 | public static const F15:int = 126; 74 | 75 | public static const DIGIT_0:int = 48; 76 | public static const DIGIT_1:int = 49; 77 | public static const DIGIT_2:int = 50; 78 | public static const DIGIT_3:int = 51; 79 | public static const DIGIT_4:int = 52; 80 | public static const DIGIT_5:int = 53; 81 | public static const DIGIT_6:int = 54; 82 | public static const DIGIT_7:int = 55; 83 | public static const DIGIT_8:int = 56; 84 | public static const DIGIT_9:int = 57; 85 | 86 | public static const NUMPAD_0:int = 96; 87 | public static const NUMPAD_1:int = 97; 88 | public static const NUMPAD_2:int = 98; 89 | public static const NUMPAD_3:int = 99; 90 | public static const NUMPAD_4:int = 100; 91 | public static const NUMPAD_5:int = 101; 92 | public static const NUMPAD_6:int = 102; 93 | public static const NUMPAD_7:int = 103; 94 | public static const NUMPAD_8:int = 104; 95 | public static const NUMPAD_9:int = 105; 96 | public static const NUMPAD_ADD:int = 107; 97 | public static const NUMPAD_DECIMAL:int = 110; 98 | public static const NUMPAD_DIVIDE:int = 111; 99 | public static const NUMPAD_ENTER:int = 108; 100 | public static const NUMPAD_MULTIPLY:int = 106; 101 | public static const NUMPAD_SUBTRACT:int = 109; 102 | 103 | /** 104 | * Returns the name of the key. 105 | * @param char The key to name. 106 | * @return The name. 107 | */ 108 | public static function name(char:int):String 109 | { 110 | if (char >= A && char <= Z) return String.fromCharCode(char); 111 | if (char >= F1 && char <= F15) return "F" + String(char - 111); 112 | if (char >= 96 && char <= 105) return "NUMPAD " + String(char - 96); 113 | switch (char) 114 | { 115 | case LEFT: 116 | return "LEFT"; 117 | 118 | case UP: 119 | return "UP"; 120 | 121 | case RIGHT: 122 | return "RIGHT"; 123 | 124 | case DOWN: 125 | return "DOWN"; 126 | 127 | case ENTER: 128 | return "ENTER"; 129 | 130 | case CONTROL: 131 | return "CONTROL"; 132 | 133 | case SPACE: 134 | return "SPACE"; 135 | 136 | case SHIFT: 137 | return "SHIFT"; 138 | 139 | case BACKSPACE: 140 | return "BACKSPACE"; 141 | 142 | case CAPS_LOCK: 143 | return "CAPS LOCK"; 144 | 145 | case DELETE: 146 | return "DELETE"; 147 | 148 | case END: 149 | return "END"; 150 | 151 | case ESCAPE: 152 | return "ESCAPE"; 153 | 154 | case HOME: 155 | return "HOME"; 156 | 157 | case INSERT: 158 | return "INSERT"; 159 | 160 | case TAB: 161 | return "TAB"; 162 | 163 | case PAGE_DOWN: 164 | return "PAGE DOWN"; 165 | 166 | case PAGE_UP: 167 | return "PAGE UP"; 168 | 169 | case NUMPAD_ADD: 170 | return "NUMPAD ADD"; 171 | 172 | case NUMPAD_DECIMAL: 173 | return "NUMPAD DECIMAL"; 174 | 175 | case NUMPAD_DIVIDE: 176 | return "NUMPAD DIVIDE"; 177 | 178 | case NUMPAD_ENTER: 179 | return "NUMPAD ENTER"; 180 | 181 | case NUMPAD_MULTIPLY: 182 | return "NUMPAD MULTIPLY"; 183 | 184 | case NUMPAD_SUBTRACT: 185 | return "NUMPAD SUBTRACT"; 186 | 187 | default: 188 | return String.fromCharCode(char); 189 | } 190 | return String.fromCharCode(char); 191 | } 192 | } 193 | } -------------------------------------------------------------------------------- /lib/starling.swc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/lib/starling.swc -------------------------------------------------------------------------------- /lib/starling/extensions/ColorArgb.as: -------------------------------------------------------------------------------- 1 | // ================================================================================================= 2 | // 3 | // Starling Framework - Particle System Extension 4 | // Copyright 2011 Gamua OG. All Rights Reserved. 5 | // 6 | // This program is free software. You can redistribute and/or modify it 7 | // in accordance with the terms of the accompanying license agreement. 8 | // 9 | // ================================================================================================= 10 | 11 | package starling.extensions 12 | { 13 | public class ColorArgb 14 | { 15 | public var red:Number; 16 | public var green:Number; 17 | public var blue:Number; 18 | public var alpha:Number; 19 | 20 | public function ColorArgb(red:Number=0, green:Number=0, blue:Number=0, alpha:Number=0) 21 | { 22 | this.red = red; 23 | this.green = green; 24 | this.blue = blue; 25 | this.alpha = alpha; 26 | } 27 | 28 | public function toRgb():uint 29 | { 30 | var r:Number = red; if (r < 0.0) r = 0.0; else if (r > 1.0) r = 1.0; 31 | var g:Number = green; if (g < 0.0) g = 0.0; else if (g > 1.0) g = 1.0; 32 | var b:Number = blue; if (b < 0.0) b = 0.0; else if (b > 1.0) b = 1.0; 33 | 34 | return int(r * 255) << 16 | int(g * 255) << 8 | int(b * 255); 35 | } 36 | 37 | public function toArgb():uint 38 | { 39 | var a:Number = alpha; if (a < 0.0) a = 0.0; else if (a > 1.0) a = 1.0; 40 | var r:Number = red; if (r < 0.0) r = 0.0; else if (r > 1.0) r = 1.0; 41 | var g:Number = green; if (g < 0.0) g = 0.0; else if (g > 1.0) g = 1.0; 42 | var b:Number = blue; if (b < 0.0) b = 0.0; else if (b > 1.0) b = 1.0; 43 | 44 | return int(a * 255) << 24 | int(r * 255) << 16 | int(g * 255) << 8 | int(b * 255); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /lib/starling/extensions/PDParticle.as: -------------------------------------------------------------------------------- 1 | // ================================================================================================= 2 | // 3 | // Starling Framework - Particle System Extension 4 | // Copyright 2012 Gamua OG. All Rights Reserved. 5 | // 6 | // This program is free software. You can redistribute and/or modify it 7 | // in accordance with the terms of the accompanying license agreement. 8 | // 9 | // ================================================================================================= 10 | 11 | package starling.extensions 12 | { 13 | public class PDParticle extends Particle 14 | { 15 | public var colorArgb:ColorArgb; 16 | public var colorArgbDelta:ColorArgb; 17 | public var startX:Number, startY:Number; 18 | public var velocityX:Number, velocityY:Number; 19 | public var radialAcceleration:Number; 20 | public var tangentialAcceleration:Number; 21 | public var emitRadius:Number, emitRadiusDelta:Number; 22 | public var emitRotation:Number, emitRotationDelta:Number; 23 | public var rotationDelta:Number; 24 | public var scaleDelta:Number; 25 | 26 | public function PDParticle() 27 | { 28 | colorArgb = new ColorArgb(); 29 | colorArgbDelta = new ColorArgb(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /lib/starling/extensions/Particle.as: -------------------------------------------------------------------------------- 1 | // ================================================================================================= 2 | // 3 | // Starling Framework - Particle System Extension 4 | // Copyright 2011 Gamua OG. All Rights Reserved. 5 | // 6 | // This program is free software. You can redistribute and/or modify it 7 | // in accordance with the terms of the accompanying license agreement. 8 | // 9 | // ================================================================================================= 10 | 11 | package starling.extensions 12 | { 13 | public class Particle 14 | { 15 | public var x:Number; 16 | public var y:Number; 17 | public var scale:Number; 18 | public var rotation:Number; 19 | public var color:uint; 20 | public var alpha:Number; 21 | public var currentTime:Number; 22 | public var totalTime:Number; 23 | 24 | public function Particle() 25 | { 26 | x = y = rotation = currentTime = 0.0; 27 | totalTime = alpha = scale = 1.0; 28 | color = 0xffffff; 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /lib/starling/extensions/ParticleDesignerPS.as: -------------------------------------------------------------------------------- 1 | // ================================================================================================= 2 | // 3 | // Starling Framework - Particle System Extension 4 | // Copyright 2012 Gamua OG. All Rights Reserved. 5 | // 6 | // This program is free software. You can redistribute and/or modify it 7 | // in accordance with the terms of the accompanying license agreement. 8 | // 9 | // ================================================================================================= 10 | 11 | package starling.extensions 12 | { 13 | import starling.textures.Texture; 14 | 15 | /** This class is only available for backwards-compatibility. 16 | * This was the old name of the 'PDParticleSystem' class. */ 17 | public class ParticleDesignerPS extends PDParticleSystem 18 | { 19 | private static var sDeprecationNotified:Boolean = false; 20 | 21 | public function ParticleDesignerPS(config:XML, texture:Texture) 22 | { 23 | if (!sDeprecationNotified) 24 | { 25 | sDeprecationNotified = true; 26 | trace("[Starling] The class 'ParticleDesignerPS' is deprecated. " + 27 | "Please use 'PDParticleSystem' instead."); 28 | } 29 | super(config, texture); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 Andy Saia 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/GameEngine.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunk.SPEngine; 5 | import com.saia.starlingPunkExamples.platformer.controllers.LevelController; 6 | 7 | /** 8 | * ... 9 | * @author Andy Saia 10 | */ 11 | public class GameEngine extends SPEngine 12 | { 13 | public function GameEngine() 14 | { 15 | super(); 16 | } 17 | 18 | //------------------- 19 | // event handlers 20 | //------------------- 21 | 22 | override public function init():void 23 | { 24 | super.init(); 25 | SP.world = LevelController.getCurrentLevel(); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/Main.as: -------------------------------------------------------------------------------- 1 | package 2 | { 3 | import flash.display.Sprite; 4 | import flash.display.StageAlign; 5 | import flash.display.StageScaleMode; 6 | import flash.events.Event; 7 | import starling.core.Starling; 8 | 9 | /** 10 | * This is normal Starling setup class 11 | * @author Andy Saia 12 | */ 13 | 14 | [SWF(width="800", height="600", backgroundColor="#FFFFFF", frameRate="60")] 15 | public class Main extends Sprite 16 | { 17 | public function Main():void 18 | { 19 | if (stage) init(); 20 | else addEventListener(Event.ADDED_TO_STAGE, init); 21 | } 22 | 23 | private function init(e:Event = null):void 24 | { 25 | removeEventListener(Event.ADDED_TO_STAGE, init); 26 | // entry point 27 | 28 | //Starling.handleLostContext = true; 29 | var starling:Starling = new Starling(GameEngine, stage); 30 | stage.scaleMode = StageScaleMode.NO_SCALE; 31 | stage.align = StageAlign.TOP_LEFT; 32 | 33 | starling.showStats = true; 34 | starling.start(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/cameraScroller/worlds/ScrollingWorld.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.cameraScroller.worlds 2 | { 3 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoProject; 4 | import com.saia.starlingPunk.graphics.SPTilemap; 5 | import com.saia.starlingPunk.SP; 6 | import com.saia.starlingPunk.SPEntity; 7 | import com.saia.starlingPunk.SPWorld; 8 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 9 | import com.saia.starlingPunkExamples.helpers.ExampleManager; 10 | import flash.geom.Point; 11 | import flash.geom.Rectangle; 12 | import starling.events.Touch; 13 | import starling.events.TouchEvent; 14 | import starling.textures.Texture; 15 | import starling.textures.TextureAtlas; 16 | 17 | 18 | 19 | /** 20 | * ... 21 | * @author Andy Saia 22 | */ 23 | public class ScrollingWorld extends SPWorld 24 | { 25 | private var _camXOffset:Number; 26 | private var _camYOffset:Number; 27 | private var _camSpeed:Number = 20; 28 | private var _mouseX:Number = 0; 29 | private var _mouseY:Number = 0; 30 | private var _tilemap:SPTilemap; 31 | 32 | public function ScrollingWorld() 33 | { 34 | } 35 | 36 | //------------------- 37 | // overrides 38 | //------------------- 39 | 40 | override public function begin():void 41 | { 42 | super.begin(); 43 | 44 | _camXOffset = 0; 45 | _camYOffset = 0; 46 | 47 | //load the embedded project file 48 | OgmoProject.LoadProject(ExampleAssets.OGMO_SCROLLING_PROJECT, this as Class); 49 | var textureAtlas:TextureAtlas = new TextureAtlas(Texture.fromBitmap(new ExampleAssets.ATLAS_TEXTURE()), XML(new ExampleAssets.ATLAS_DATA())); 50 | //before loading the level you must tell OgmoPunk which images to use for the tileset 51 | OgmoProject.createTileSetListFromTextureAtlas("groundTileSet", textureAtlas, ["platformTile", "marioTile"]); 52 | 53 | loadLevel(ExampleAssets.SCROLLING_LEVEL); 54 | 55 | SP.stage.addEventListener(TouchEvent.TOUCH, onTouch); 56 | 57 | //display example instructions 58 | ExampleManager.displayText(); 59 | } 60 | 61 | private function onTouch(e:TouchEvent):void 62 | { 63 | var touch:Touch = e.getTouch(this); 64 | if (touch) 65 | { 66 | _mouseX = touch.globalX; 67 | _mouseY = touch.globalY; 68 | _camXOffset = (touch.globalX - SP.halfWidth) / SP.halfWidth; 69 | _camYOffset = (touch.globalY - SP.halfHeight) / SP.halfHeight; 70 | } 71 | 72 | } 73 | 74 | override public function update():void 75 | { 76 | super.update(); 77 | checkCameraBounds(); 78 | 79 | //update example manager 80 | ExampleManager.checkExampleChange(); 81 | } 82 | 83 | override public function remove(entity:SPEntity):void 84 | { 85 | super.remove(entity); 86 | } 87 | 88 | //------------------- 89 | // private methods 90 | //------------------- 91 | 92 | private function loadLevel(levelData:Class):void 93 | { 94 | var levelLayers:Vector. = OgmoProject.LoadLevel(levelData); 95 | for each (var entity:SPEntity in levelLayers) 96 | { 97 | add(entity); 98 | _tilemap = SPTilemap(entity.getChildAt(0)); 99 | } 100 | } 101 | 102 | private function checkCameraBounds():void 103 | { 104 | var viewPort:Rectangle = SP.camera.viewPort; 105 | if (viewPort.x + _camXOffset * _camSpeed < 0) 106 | SP.camera.x = 0; 107 | else 108 | SP.camera.x += _camXOffset * _camSpeed; 109 | 110 | if (viewPort.y + _camYOffset * _camSpeed < 0) 111 | SP.camera.y = 0; 112 | else 113 | SP.camera.y += _camYOffset * _camSpeed; 114 | 115 | if (viewPort.x + _camXOffset * _camSpeed > 5000 - viewPort.width) 116 | SP.camera.x = 5000 - viewPort.width; 117 | 118 | if (viewPort.y + _camYOffset * _camSpeed > 5000 - viewPort.height) 119 | SP.camera.y = 5000 - viewPort.height; 120 | 121 | var focus:Point = SP.camera.container.globalToLocal(new Point(_mouseX, _mouseY)); 122 | SP.camera.focus(focus.x, focus.y); 123 | } 124 | } 125 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/embeds/ExampleAssets.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.embeds 2 | { 3 | /** 4 | * ... 5 | * @author Andy Saia 6 | */ 7 | public class ExampleAssets 8 | { 9 | //------------ 10 | // Ogmo Levels 11 | //------------ 12 | [Embed(source = "../../../../media/levels/platformerProject.oep", mimeType = "application/octet-stream")] 13 | public static const OGMO_PROJECT:Class; 14 | 15 | [Embed(source="../../../../media/levels/level01.oel", mimeType="application/octet-stream")] 16 | public static const LEVEL01:Class; 17 | 18 | [Embed(source="../../../../media/levels/level02.oel", mimeType="application/octet-stream")] 19 | public static const LEVEL02:Class; 20 | 21 | 22 | [Embed(source="../../../../media/levels/scrollingCamera.oep", mimeType="application/octet-stream")] 23 | public static const OGMO_SCROLLING_PROJECT:Class; 24 | 25 | [Embed(source="../../../../media/levels/scrollingLevel.oel", mimeType="application/octet-stream")] 26 | public static const SCROLLING_LEVEL:Class; 27 | 28 | //------------ 29 | // texture atlas 30 | //------------ 31 | 32 | [Embed(source="../../../../media/textures/textureAtlas.png")] 33 | public static const ATLAS_TEXTURE:Class; 34 | [Embed(source = "../../../../media/textures/textureAtlas.xml", mimeType = "application/octet-stream")] 35 | public static const ATLAS_DATA:Class; 36 | 37 | //---------- 38 | // textures 39 | //---------- 40 | [Embed(source = "../../../../media/textures/Alien.png")] 41 | public static const ALIEN_TEXTURE:Class; 42 | 43 | [Embed(source="../../../../media/textures/Ship.png")] 44 | public static const SHIP_TEXTURE:Class; 45 | 46 | //---------- 47 | // fonts 48 | //---------- 49 | [Embed(source = "../../../../media/fonts/bmpFontData.fnt", mimeType = "application/octet-stream")] 50 | public static const FONT_DATA:Class; 51 | 52 | [Embed(source="../../../../media/fonts/bmpFontTexture.png")] 53 | public static const BMP_FONT_TEXTURE:Class; 54 | 55 | //---------- 56 | // particles 57 | //---------- 58 | [Embed(source="../../../../media/particles/explosion.pex", mimeType="application/octet-stream")] 59 | public static const PARTICLE_DATA:Class; 60 | 61 | [Embed(source="../../../../media/particles/explosionTexture.png")] 62 | public static const PARTICLE_TEXTURE:Class; 63 | 64 | } 65 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/helpers/ExampleManager.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.helpers 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunk.utils.Key; 5 | import com.saia.starlingPunk.utils.SPInput; 6 | import com.saia.starlingPunkExamples.cameraScroller.worlds.ScrollingWorld; 7 | import com.saia.starlingPunkExamples.platformer.controllers.LevelController; 8 | import com.saia.starlingPunkExamples.shipShooter.worlds.PlayWorld; 9 | import starling.text.TextField; 10 | import starling.utils.Color; 11 | import starling.utils.HAlign; 12 | import starling.utils.VAlign; 13 | /** 14 | * ... 15 | * @author Andy Saia 16 | */ 17 | public class ExampleManager 18 | { 19 | 20 | public function ExampleManager() 21 | { 22 | 23 | } 24 | 25 | public static function displayText(message:String = ""):void 26 | { 27 | var textField:TextField = createTextField(); 28 | textField.text = "use numbers keys (1-3) to see other examples " + message; 29 | textField.hAlign = HAlign.LEFT; 30 | 31 | SP.world.addChildAt(textField, SP.world.numChildren); 32 | textField.x = 200; 33 | textField.y = 40; 34 | } 35 | 36 | public static function checkExampleChange():void 37 | { 38 | if (SPInput.check(Key.DIGIT_1)) 39 | { 40 | SP.world = LevelController.getCurrentLevel(); 41 | } 42 | 43 | if (SPInput.check(Key.DIGIT_2)) 44 | { 45 | SP.world = new ScrollingWorld(); 46 | } 47 | 48 | if (SPInput.check(Key.DIGIT_3)) 49 | { 50 | SP.world = new PlayWorld(); 51 | } 52 | } 53 | 54 | private static function createTextField():TextField 55 | { 56 | var textfield:TextField = new TextField(SP.width, 100, ""); 57 | textfield.fontSize = 16; 58 | textfield.color = Color.BLACK; 59 | textfield.hAlign = HAlign.CENTER; 60 | textfield.vAlign = VAlign.TOP; 61 | return textfield; 62 | } 63 | 64 | } 65 | 66 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/platformer/controllers/LevelController.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.platformer.controllers 2 | { 3 | import com.saia.starlingPunk.SPWorld; 4 | import com.saia.starlingPunkExamples.cameraScroller.worlds.ScrollingWorld; 5 | import com.saia.starlingPunkExamples.platformer.worlds.PlatformerLevelOne; 6 | import com.saia.starlingPunkExamples.platformer.worlds.PlatformerLevelTwo; 7 | /** 8 | * ... 9 | * @author Andy Saia 10 | */ 11 | public class LevelController 12 | { 13 | private static var levels:Vector. = new [new PlatformerLevelOne(), new PlatformerLevelTwo()]; 14 | private static var currentLevelIndex:int = 0; 15 | 16 | public static function getCurrentLevel():SPWorld 17 | { 18 | return levels[currentLevelIndex]; 19 | } 20 | 21 | public static function nextLevel():SPWorld 22 | { 23 | currentLevelIndex++; 24 | if (currentLevelIndex > levels.length -1) 25 | { 26 | currentLevelIndex = 0; 27 | } 28 | return getCurrentLevel(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/platformer/entities/GoalEntity.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.platformer.entities 2 | { 3 | import com.saia.starlingPunk.SPEntity; 4 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 5 | import starling.display.Image; 6 | import starling.textures.Texture; 7 | import starling.textures.TextureAtlas; 8 | 9 | /** 10 | * ... 11 | * @author Andy Saia 12 | */ 13 | public class GoalEntity extends SPEntity 14 | { 15 | 16 | public function GoalEntity() 17 | { 18 | super(0, 0, "goal"); 19 | } 20 | 21 | override public function added():void 22 | { 23 | super.added(); 24 | setupGraphic(); 25 | } 26 | 27 | override public function removed():void 28 | { 29 | removeChildren(0, -1, true); 30 | super.removed(); 31 | } 32 | 33 | 34 | private function setupGraphic():void 35 | { 36 | var textureAtlas:TextureAtlas = new TextureAtlas(Texture.fromBitmap(new ExampleAssets.ATLAS_TEXTURE()), XML(new ExampleAssets.ATLAS_DATA())); 37 | var image:Image = new Image(textureAtlas.getTexture("goal")); 38 | addChild(image); 39 | } 40 | 41 | } 42 | 43 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/platformer/entities/PlatformerPlayer.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.platformer.entities 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunk.SPEntity; 5 | import com.saia.starlingPunk.utils.Key; 6 | import com.saia.starlingPunk.utils.SPInput; 7 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 8 | import com.saia.starlingPunkExamples.platformer.controllers.LevelController; 9 | import flash.geom.Point; 10 | import starling.display.Image; 11 | import starling.textures.Texture; 12 | import starling.textures.TextureAtlas; 13 | 14 | /** 15 | * ... 16 | * @author Andy Saia 17 | */ 18 | public class PlatformerPlayer extends SPEntity 19 | { 20 | private static var FRICTION:Number = .5; 21 | private static var ACEL:Number = 1; 22 | private static var JUMP_AMOUNT:Number = 7; 23 | private static var GRAVITY:Number = .2; 24 | private static var MAX_SPEED:Number = 4; 25 | private static var JUMP_SPEED:Number = 7; 26 | 27 | private var _vel:Point; 28 | private var _isJumpReleased:Boolean; 29 | private var _isCameraEnabled:Boolean 30 | 31 | public function PlatformerPlayer() 32 | { 33 | super(40, 40, "player"); 34 | } 35 | 36 | //------------------- 37 | // overrides 38 | //------------------- 39 | 40 | override public function added():void 41 | { 42 | super.added(); 43 | setupGraphic(); 44 | _vel = new Point(); 45 | _isJumpReleased = true; 46 | _isCameraEnabled = false; 47 | 48 | //define input 49 | SPInput.define("right", [Key.RIGHT]); 50 | SPInput.define("left", [Key.LEFT]); 51 | SPInput.define("jump", [Key.UP]); 52 | } 53 | 54 | override public function removed():void 55 | { 56 | removeChildren(0, -1, true); 57 | super.removed(); 58 | } 59 | 60 | override public function update():void 61 | { 62 | super.update(); 63 | updateMovement(); 64 | updateInput(); 65 | updateCollision(); 66 | 67 | updateCamera(); 68 | 69 | //press spacebar to enable the camera 70 | if (SPInput.pressed(Key.SPACE)) 71 | { 72 | if (_isCameraEnabled) 73 | disableCamera(); 74 | else 75 | enableCamera(); 76 | } 77 | } 78 | 79 | //------------------- 80 | // private methods 81 | //------------------- 82 | 83 | private function updateInput():void 84 | { 85 | if (SPInput.check("left")) 86 | { 87 | _vel.x -= ACEL; 88 | } else if (SPInput.check("right")) 89 | { 90 | _vel.x += ACEL; 91 | } 92 | 93 | if (SPInput.check("jump") && this.collide("collision", x, y + 1) && _isJumpReleased) 94 | { 95 | _vel.y = -JUMP_SPEED; 96 | _isJumpReleased = false; 97 | } 98 | 99 | if (SPInput.released("jump")) 100 | { 101 | _isJumpReleased = true; 102 | } 103 | } 104 | 105 | private function updateMovement():void 106 | { 107 | //friction 108 | if (!SPInput.check("left") && !SPInput.check("right")) 109 | { 110 | _vel.x -= SP.sign(_vel.x) * FRICTION; 111 | if (Math.abs(_vel.x) <= 0.1) 112 | { 113 | _vel.x = 0; 114 | } 115 | } 116 | 117 | //fall twice as fast if jump key isn't pressed 118 | if (!SPInput.check("jump") && _vel.y < 0) 119 | { 120 | _vel.y += GRAVITY; 121 | } 122 | 123 | //sets max speed 124 | if (Math.abs(_vel.x) > MAX_SPEED) 125 | { 126 | _vel.x = SP.sign(_vel.x) * MAX_SPEED; 127 | } 128 | 129 | //update x and y movement 130 | for (var i:int = 0; i < Math.abs(_vel.x); i += 1) 131 | { 132 | if (!collide("collision", x + SP.sign(_vel.x), y)) 133 | { 134 | x += SP.sign(_vel.x); 135 | if (_isCameraEnabled) 136 | SP.camera.x += SP.sign(_vel.x); 137 | } else 138 | { 139 | _vel.x = 0; 140 | break; 141 | } 142 | } 143 | 144 | for (i = 0; i < Math.abs(_vel.y); i += 1) 145 | { 146 | if (!collide("collision", x, y + (SP.sign(_vel.y)))) 147 | { 148 | y += SP.sign(_vel.y); 149 | if (_isCameraEnabled) 150 | SP.camera.y += SP.sign(_vel.y); 151 | } else 152 | { 153 | _vel.y = 0; 154 | break; 155 | } 156 | } 157 | 158 | _vel.y += GRAVITY; 159 | 160 | } 161 | 162 | private function updateCollision():void 163 | { 164 | if (collide("goal", x, y)) 165 | { 166 | SP.world = LevelController.nextLevel(); 167 | world.remove(this); 168 | } 169 | 170 | } 171 | 172 | private function setupGraphic():void 173 | { 174 | var textureAtlas:TextureAtlas = new TextureAtlas(Texture.fromBitmap(new ExampleAssets.ATLAS_TEXTURE()), XML(new ExampleAssets.ATLAS_DATA())); 175 | var image:Image = new Image(textureAtlas.getTexture("burger")); 176 | addChild(image); 177 | } 178 | 179 | private function updateCamera():void 180 | { 181 | if (!_isCameraEnabled) return; 182 | 183 | SP.camera.focus(this.x, this.y); 184 | 185 | if (SPInput.check(Key.W)) 186 | SP.camera.zoom += 0.01; 187 | else if (SPInput.check(Key.S)) 188 | SP.camera.zoom -= 0.01; 189 | 190 | if (SPInput.check(Key.A)) 191 | SP.camera.rotation -= 0.01; 192 | else if (SPInput.check(Key.D)) 193 | SP.camera.rotation += 0.01; 194 | } 195 | 196 | private function enableCamera():void 197 | { 198 | _isCameraEnabled = true; 199 | SP.camera.x = this.x - 300; 200 | SP.camera.y = this.y - 300; 201 | } 202 | 203 | private function disableCamera():void 204 | { 205 | _isCameraEnabled = false; 206 | SP.camera.reset(); 207 | } 208 | } 209 | 210 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/platformer/worlds/PlatformerLevelOne.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.platformer.worlds 2 | { 3 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 4 | 5 | /** 6 | * ... 7 | * @author Andy Saia 8 | */ 9 | public class PlatformerLevelOne extends PlatformerWorld 10 | { 11 | override public function begin():void 12 | { 13 | super.begin(); 14 | loadLevel(ExampleAssets.LEVEL01); 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/platformer/worlds/PlatformerLevelTwo.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.platformer.worlds 2 | { 3 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 4 | 5 | /** 6 | * ... 7 | * @author Andy Saia 8 | */ 9 | public class PlatformerLevelTwo extends PlatformerWorld 10 | { 11 | override public function begin():void 12 | { 13 | super.begin(); 14 | loadLevel(ExampleAssets.LEVEL02); 15 | } 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/platformer/worlds/PlatformerWorld.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.platformer.worlds 2 | { 3 | import com.saia.starlingPunk.extensions.ogmopunk.OgmoProject; 4 | import com.saia.starlingPunk.SPEntity; 5 | import com.saia.starlingPunk.SPWorld; 6 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 7 | import com.saia.starlingPunkExamples.helpers.ExampleManager; 8 | import com.saia.starlingPunkExamples.platformer.entities.GoalEntity; 9 | import com.saia.starlingPunkExamples.platformer.entities.PlatformerPlayer; 10 | import starling.textures.Texture; 11 | import starling.textures.TextureAtlas; 12 | 13 | 14 | /** 15 | * ... 16 | * @author Andy Saia 17 | */ 18 | public class PlatformerWorld extends SPWorld 19 | { 20 | 21 | public function PlatformerWorld() 22 | { 23 | //flash doesn't compile classes that aren't refrenced in code and OgmoPunk uses the getDefinitionByName Util to 24 | //to create instances of our Entities. If the entites aren't compiled getDefinitionByName will give an error message 25 | //saying that our classes aren't defined... by including these classes into the construction we are telling flash to compile them 26 | PlatformerPlayer; GoalEntity; 27 | } 28 | 29 | override public function begin():void 30 | { 31 | //load the embedded project file 32 | OgmoProject.LoadProject(ExampleAssets.OGMO_PROJECT, this as Class); 33 | var textureAtlas:TextureAtlas = new TextureAtlas(Texture.fromBitmap(new ExampleAssets.ATLAS_TEXTURE()), XML(new ExampleAssets.ATLAS_DATA())); 34 | //before loading the level you must tell OgmoPunk which images to use for the tileset 35 | OgmoProject.createTileSetListFromTextureAtlas("groundTileSet", textureAtlas, ["platformTile", "marioTile"]); 36 | 37 | //display example instructions 38 | ExampleManager.displayText('\ntoggle camera mode by pressing the "space bar"\nzoom in/out using "W/S" and rotate camera using "A/S"'); 39 | super.begin(); 40 | } 41 | 42 | override public function end():void 43 | { 44 | super.end(); 45 | removeAll(); 46 | removeChildren(0, -1, true); 47 | } 48 | 49 | override public function update():void 50 | { 51 | super.update(); 52 | //update example manager 53 | ExampleManager.checkExampleChange(); 54 | } 55 | 56 | //------------------- 57 | // protected methods 58 | //------------------- 59 | 60 | protected function loadLevel(levelData:Class):void 61 | { 62 | var levelLayers:Vector. = OgmoProject.LoadLevel(levelData); 63 | for each (var entity:SPEntity in levelLayers) 64 | { 65 | add(entity); 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/controller/ScoreController.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.controller 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunkExamples.shipShooter.entities.ScoreEntity; 5 | /** 6 | * ... 7 | * @author Andy Saia 8 | */ 9 | public class ScoreController 10 | { 11 | public static var _scoreEntity:ScoreEntity; 12 | 13 | public static function init():void 14 | { 15 | _scoreEntity = new ScoreEntity(); 16 | SP.world.add(_scoreEntity); 17 | } 18 | 19 | public static function increaseScore():void 20 | { 21 | _scoreEntity.addPoint(); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/entities/AlienEntity.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.entities 2 | { 3 | import com.saia.starlingPunk.helpers.SPMath; 4 | import com.saia.starlingPunk.SP; 5 | import com.saia.starlingPunk.SPEntity; 6 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 7 | import starling.display.Image; 8 | 9 | /** 10 | * ... 11 | * @author Andy Saia 12 | */ 13 | public class AlienEntity extends SPEntity 14 | { 15 | private var _speed:Number; 16 | public function AlienEntity() 17 | { 18 | type = "alien"; 19 | } 20 | 21 | //---------- 22 | // overrides 23 | //---------- 24 | 25 | override public function added():void 26 | { 27 | super.added(); 28 | 29 | var image:Image = Image.fromBitmap(new ExampleAssets.ALIEN_TEXTURE()); 30 | addChild(image); 31 | 32 | this.x = SP.width - width; 33 | this.y = Math.random() * SP.height; 34 | 35 | _speed = SPMath.range(3, 7); 36 | } 37 | 38 | override public function removed():void 39 | { 40 | super.removed(); 41 | removeChildren(0, -1, true); 42 | } 43 | 44 | override public function update():void 45 | { 46 | super.update(); 47 | this.x -= _speed; 48 | this.y += Math.cos(x / 30) * 3; 49 | 50 | checkBounds(); 51 | } 52 | 53 | //---------- 54 | // private methods 55 | //---------- 56 | 57 | private function checkBounds():void 58 | { 59 | if (x < -width) 60 | { 61 | world.remove(this); 62 | } 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/entities/BulletEntity.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.entities 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunk.SPEntity; 5 | import com.saia.starlingPunkExamples.shipShooter.controller.ScoreController; 6 | import com.saia.starlingPunkExamples.shipShooter.particles.ExplosionParticles; 7 | import flash.display.BitmapData; 8 | import starling.display.Image; 9 | import starling.textures.Texture; 10 | 11 | /** 12 | * ... 13 | * @author Andy Saia 14 | */ 15 | public class BulletEntity extends SPEntity 16 | { 17 | private var _speed:Number; 18 | public function BulletEntity(x:Number, y:Number) 19 | { 20 | super(x, y, "bullet"); 21 | } 22 | 23 | override public function added():void 24 | { 25 | super.added(); 26 | var bmpData:BitmapData = new BitmapData(16, 4, false, 0x597137); 27 | var img:Image = new Image(Texture.fromBitmapData(bmpData)); 28 | addChild(img); 29 | 30 | _speed = 20; 31 | } 32 | 33 | override public function update():void 34 | { 35 | super.update(); 36 | this.x += _speed; 37 | 38 | checkBounds(); 39 | checkCollision(); 40 | } 41 | 42 | override public function removed():void 43 | { 44 | super.removed(); 45 | removeChildren(0, -1, true); 46 | } 47 | 48 | //---------- 49 | // private methods 50 | //---------- 51 | 52 | private function checkBounds():void 53 | { 54 | if (this.x > SP.width) 55 | { 56 | world.remove(this); 57 | } 58 | } 59 | 60 | private function checkCollision():void 61 | { 62 | var alien:SPEntity = collide("alien", x, y) 63 | if (alien) 64 | { 65 | ScoreController.increaseScore(); 66 | var explosion:ExplosionParticles = new ExplosionParticles(); 67 | explosion.start(x, y); 68 | world.remove(alien); 69 | world.remove(this); 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/entities/PlayerEntity.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.entities 2 | { 3 | import com.saia.starlingPunk.effects.SPEffects; 4 | import com.saia.starlingPunk.SP; 5 | import com.saia.starlingPunk.SPEntity; 6 | import com.saia.starlingPunk.utils.Key; 7 | import com.saia.starlingPunk.utils.SPInput; 8 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 9 | import com.saia.starlingPunkExamples.shipShooter.particles.ExplosionParticles; 10 | import starling.display.Image; 11 | 12 | /** 13 | * ... 14 | * @author Andy Saia 15 | */ 16 | public class PlayerEntity extends SPEntity 17 | { 18 | private var _speed:Number = 5; 19 | private var _isDead:Boolean; 20 | 21 | public function PlayerEntity() 22 | { 23 | type = "player"; 24 | } 25 | 26 | //---------- 27 | // getters and setters 28 | //---------- 29 | 30 | public function get isDead():Boolean 31 | { 32 | return _isDead; 33 | } 34 | 35 | //---------- 36 | // overrides 37 | //---------- 38 | 39 | override public function added():void 40 | { 41 | super.added(); 42 | var image:Image = Image.fromBitmap(new ExampleAssets.SHIP_TEXTURE()); 43 | addChild(image); 44 | 45 | this.x = width; 46 | this.y = SP.halfHeight - height / 2; 47 | _isDead = false; 48 | } 49 | 50 | override public function removed():void 51 | { 52 | super.removed(); 53 | removeChildren(0, -1, true); 54 | _isDead = true; 55 | } 56 | 57 | override public function update():void 58 | { 59 | super.update(); 60 | handleInput(); 61 | checkBounds(); 62 | checkCollision(); 63 | } 64 | 65 | //---------- 66 | // private methods 67 | //---------- 68 | 69 | private function handleInput():void 70 | { 71 | if (SPInput.check(Key.LEFT)) 72 | { 73 | x -= _speed; 74 | } 75 | 76 | if (SPInput.check(Key.RIGHT)) 77 | { 78 | x += _speed; 79 | } 80 | 81 | if (SPInput.check(Key.UP)) 82 | { 83 | y -= _speed; 84 | } 85 | 86 | if (SPInput.check(Key.DOWN)) 87 | { 88 | y += _speed; 89 | } 90 | 91 | if (SPInput.pressed(Key.SPACE)) 92 | { 93 | world.add(new BulletEntity(x + width, y + height * .5)); 94 | } 95 | } 96 | 97 | private function checkBounds():void 98 | { 99 | if (x > SP.width - width) 100 | { 101 | x = SP.width - width; 102 | }else if (x < 0) 103 | { 104 | x = 0; 105 | } 106 | 107 | if (y > SP.height - height) 108 | { 109 | y = SP.height - height; 110 | } else if (y < 0) 111 | { 112 | y = 0; 113 | } 114 | } 115 | 116 | private function checkCollision():void 117 | { 118 | var enemy:SPEntity = collide("alien", x, y); 119 | if (enemy) 120 | { 121 | SPEffects.shake(25, 500); 122 | destroyAllEnemies(); 123 | var restartText:RestartText = new RestartText(); 124 | world.add(restartText); 125 | world.remove(this); 126 | } 127 | } 128 | 129 | private function destroyAllEnemies():void 130 | { 131 | var allEnemies:Vector. = world.getType("alien"); 132 | if (!allEnemies) return; 133 | for each (var enemy:SPEntity in allEnemies) 134 | { 135 | world.remove(enemy); 136 | var explosion:ExplosionParticles = new ExplosionParticles(); 137 | explosion.start(x, y); 138 | } 139 | } 140 | } 141 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/entities/RestartText.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.entities 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunk.SPEntity; 5 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 6 | import starling.text.BitmapFont; 7 | import starling.text.TextField; 8 | import starling.textures.Texture; 9 | import starling.utils.HAlign; 10 | import starling.utils.VAlign; 11 | 12 | /** 13 | * ... 14 | * @author Andy Saia 15 | */ 16 | public class RestartText extends SPEntity 17 | { 18 | 19 | public function RestartText() 20 | { 21 | 22 | } 23 | 24 | //---------- 25 | // overrides 26 | //---------- 27 | 28 | override public function added():void 29 | { 30 | super.added(); 31 | var textField:TextField = createTextField(); 32 | textField.text = "GAME OVER \n PRESS ENTER TO PLAY AGAIN"; 33 | textField.y = SP.halfHeight; 34 | addChild(textField); 35 | } 36 | 37 | override public function removed():void 38 | { 39 | super.removed(); 40 | removeChildren(0, -1, true); 41 | } 42 | 43 | //---------- 44 | // private methods 45 | //---------- 46 | 47 | private function createTextField():TextField 48 | { 49 | var bmpFont:BitmapFont = new BitmapFont(Texture.fromBitmap(new ExampleAssets.BMP_FONT_TEXTURE()), XML(new ExampleAssets.FONT_DATA())); 50 | TextField.registerBitmapFont(bmpFont); 51 | var textfield:TextField = new TextField(SP.width, 100, "", bmpFont.name, 50, 0x597137); 52 | textfield.fontSize = 30; 53 | textfield.hAlign = HAlign.CENTER; 54 | textfield.vAlign = VAlign.TOP; 55 | return textfield; 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/entities/ScoreEntity.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.entities 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunk.SPEntity; 5 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 6 | import starling.text.BitmapFont; 7 | import starling.text.TextField; 8 | import starling.textures.Texture; 9 | import starling.utils.HAlign; 10 | import starling.utils.VAlign; 11 | 12 | /** 13 | * ... 14 | * @author Andy Saia 15 | */ 16 | public class ScoreEntity extends SPEntity 17 | { 18 | private var _textField:TextField; 19 | private var _score:Number; 20 | 21 | public function ScoreEntity() 22 | { 23 | 24 | } 25 | 26 | //---------- 27 | // overrides 28 | //---------- 29 | 30 | override public function added():void 31 | { 32 | super.added(); 33 | _score = 0; 34 | _textField = createTextField(); 35 | addChild(_textField); 36 | var boarder:Number = 15; 37 | this.x = SP.width - width - boarder; 38 | this.y = boarder; 39 | } 40 | 41 | override public function removed():void 42 | { 43 | super.removed(); 44 | removeChildren(0, -1, true); 45 | } 46 | 47 | //---------- 48 | // private methods 49 | //---------- 50 | 51 | private function createTextField():TextField 52 | { 53 | var bmpFont:BitmapFont = new BitmapFont(Texture.fromBitmap(new ExampleAssets.BMP_FONT_TEXTURE()), XML(new ExampleAssets.FONT_DATA())); 54 | TextField.registerBitmapFont(bmpFont); 55 | var textfield:TextField = new TextField(100, 100, _score.toString(), bmpFont.name, 50, 0x597137); 56 | textfield.fontSize = 65; 57 | textfield.hAlign = HAlign.RIGHT; 58 | textfield.vAlign = VAlign.TOP; 59 | return textfield; 60 | } 61 | 62 | //---------- 63 | // public methods 64 | //---------- 65 | 66 | public function addPoint():void 67 | { 68 | _score++; 69 | _textField.text = _score.toString(); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/particles/ExplosionParticles.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.particles 2 | { 3 | import com.saia.starlingPunkExamples.embeds.ExampleAssets; 4 | /** 5 | * ... 6 | * @author Andy Saia 7 | */ 8 | public class ExplosionParticles extends Particles 9 | { 10 | 11 | public function ExplosionParticles() 12 | { 13 | super(XML(new ExampleAssets.PARTICLE_DATA()), new ExampleAssets.PARTICLE_TEXTURE()); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/particles/Particles.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.particles 2 | { 3 | import flash.display.Bitmap; 4 | import starling.core.Starling; 5 | import starling.events.Event; 6 | import starling.extensions.PDParticleSystem; 7 | import starling.textures.Texture; 8 | /** 9 | * ... 10 | * @author Andy Saia 11 | */ 12 | public class Particles 13 | { 14 | private var _particles:PDParticleSystem; 15 | 16 | public function Particles(config:XML, textureAsset:Bitmap) 17 | { 18 | var texture:Texture = Texture.fromBitmap(textureAsset); 19 | _particles = new PDParticleSystem(config, texture); 20 | } 21 | 22 | //---------- 23 | // getters and setters 24 | //---------- 25 | 26 | public function get particles():PDParticleSystem 27 | { 28 | return _particles; 29 | } 30 | 31 | //---------- 32 | // public methods 33 | //---------- 34 | 35 | public function start(x:Number = 0, y:Number = 0 ):void 36 | { 37 | _particles.start(0.1); 38 | _particles.emitterX = x; 39 | _particles.emitterY = y; 40 | 41 | Starling.current.stage.addChild(_particles); 42 | Starling.juggler.add(_particles); 43 | _particles.addEventListener(Event.COMPLETE, onParticleComplete); 44 | } 45 | 46 | //---------- 47 | // event handlers 48 | //---------- 49 | 50 | private function onParticleComplete(e:Event):void 51 | { 52 | _particles.removeEventListeners(); 53 | Starling.juggler.remove(_particles); 54 | _particles.removeFromParent(true); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/com/saia/starlingPunkExamples/shipShooter/worlds/PlayWorld.as: -------------------------------------------------------------------------------- 1 | package com.saia.starlingPunkExamples.shipShooter.worlds 2 | { 3 | import com.saia.starlingPunk.SP; 4 | import com.saia.starlingPunk.SPWorld; 5 | import com.saia.starlingPunk.utils.Key; 6 | import com.saia.starlingPunk.utils.SPInput; 7 | import com.saia.starlingPunkExamples.helpers.ExampleManager; 8 | import com.saia.starlingPunkExamples.shipShooter.controller.ScoreController; 9 | import com.saia.starlingPunkExamples.shipShooter.entities.AlienEntity; 10 | import com.saia.starlingPunkExamples.shipShooter.entities.PlayerEntity; 11 | import flash.display.BitmapData; 12 | import flash.events.TimerEvent; 13 | import flash.utils.Timer; 14 | import starling.display.Image; 15 | import starling.textures.Texture; 16 | 17 | /** 18 | * ... 19 | * @author Andy Saia 20 | */ 21 | public class PlayWorld extends SPWorld 22 | { 23 | private var _enemySpawnTimer:Number; 24 | private var _player:PlayerEntity; 25 | private var _timer:Timer; 26 | public function PlayWorld() 27 | { 28 | } 29 | 30 | //---------- 31 | // overrides 32 | //---------- 33 | 34 | override public function begin():void 35 | { 36 | super.begin(); 37 | createBgFill(); 38 | 39 | _enemySpawnTimer = 500; 40 | _timer = new Timer(_enemySpawnTimer); 41 | _timer.addEventListener(TimerEvent.TIMER, onEnemySpawnTimer); 42 | _timer.start(); 43 | 44 | _player = new PlayerEntity(); 45 | add(_player); 46 | 47 | ScoreController.init(); 48 | 49 | //display example instructions 50 | ExampleManager.displayText(); 51 | } 52 | 53 | override public function end():void 54 | { 55 | super.end(); 56 | _timer.removeEventListener(TimerEvent.TIMER, onEnemySpawnTimer); 57 | _timer.stop(); 58 | _timer = null; 59 | removeAll(); 60 | } 61 | 62 | override public function update():void 63 | { 64 | super.update(); 65 | if (SPInput.pressed(Key.ENTER) && _player.isDead) 66 | { 67 | SP.world = new PlayWorld(); 68 | } 69 | 70 | //update example manager 71 | ExampleManager.checkExampleChange(); 72 | } 73 | 74 | //---------- 75 | // event handlers 76 | //---------- 77 | 78 | private function onEnemySpawnTimer(e:TimerEvent):void 79 | { 80 | spawnEnemy(); 81 | } 82 | 83 | //---------- 84 | // private methods 85 | //---------- 86 | 87 | private function createBgFill():void 88 | { 89 | var bgColor:uint = 0xABCC7D; 90 | var bmpData:BitmapData = new BitmapData(SP.width, SP.height, false, bgColor); 91 | var image:Image = new Image(Texture.fromBitmapData(bmpData)); 92 | addChild(image); 93 | } 94 | 95 | private function spawnEnemy():void 96 | { 97 | var enemy:AlienEntity = new AlienEntity(); 98 | add(enemy); 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /src/media/fonts/bmpFontTexture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/fonts/bmpFontTexture.png -------------------------------------------------------------------------------- /src/media/levels/burger.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/levels/burger.png -------------------------------------------------------------------------------- /src/media/levels/goal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/levels/goal.png -------------------------------------------------------------------------------- /src/media/levels/groundTileSet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/levels/groundTileSet.png -------------------------------------------------------------------------------- /src/media/levels/level01.oel: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1111111111111111111111111 7 | 1000000000000000000000001 8 | 1000000000000000000000001 9 | 1110000000000000000000001 10 | 1000000000000000000000001 11 | 1000000000000000011100001 12 | 1000011111110000000000001 13 | 1000000000000000000000001 14 | 1000000000000000000011111 15 | 1000000000000000000000001 16 | 1000000000000000000000001 17 | 1000000000000000000000001 18 | 1000000000000011111110001 19 | 1000000000000000000000001 20 | 1000000000000000000000001 21 | 1000001111110000000000001 22 | 1000000000000000000000001 23 | 1000000000000000000000001 24 | 1111111111111111111111111 25 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 26 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 27 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 28 | 1,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 29 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 30 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,-1,-1,-1,-1,1 31 | 1,-1,-1,-1,-1,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 32 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 33 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,1 34 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 35 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 36 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 37 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,0,0,0,-1,-1,-1,1 38 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 39 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 40 | 1,-1,-1,-1,-1,-1,0,0,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 41 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 42 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 43 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 44 | -------------------------------------------------------------------------------- /src/media/levels/level02.oel: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 1111111111111111111111111 7 | 1000000000000000000000001 8 | 1000000000000000000000001 9 | 1000000000001111000000001 10 | 1000000000001001000000001 11 | 1000000000001011000000001 12 | 1000000001001000000000001 13 | 1000000001001100000000001 14 | 1000001001001000000000001 15 | 1000001001001001000000001 16 | 1000001001001001001100001 17 | 1000011001001001000100001 18 | 1000001001001001000000001 19 | 1000001001001001000000001 20 | 1000101001001001000000001 21 | 1001101001001001000000001 22 | 1000101001001001000011111 23 | 1000000000000000000010001 24 | 1111111111111111111111111 25 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 26 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 27 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 28 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,1 29 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,1 30 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,0,0,-1,-1,-1,-1,-1,-1,-1,-1,1 31 | 1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 32 | 1,-1,-1,-1,-1,-1,-1,-1,-1,0,-1,-1,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 33 | 1,-1,-1,-1,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1 34 | 1,-1,-1,-1,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,1 35 | 1,-1,-1,-1,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,0,0,-1,-1,-1,-1,1 36 | 1,-1,-1,-1,-1,0,0,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,-1,0,-1,-1,-1,-1,1 37 | 1,-1,-1,-1,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,1 38 | 1,-1,-1,-1,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,1 39 | 1,-1,-1,-1,0,-1,0,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,1 40 | 1,-1,-1,0,0,-1,0,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,-1,-1,-1,-1,-1,-1,1 41 | 1,-1,-1,-1,0,-1,0,-1,-1,0,-1,-1,0,-1,-1,0,-1,-1,-1,-1,0,0,0,0,1 42 | 1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,0,0,0,0,1 43 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 44 | -------------------------------------------------------------------------------- /src/media/levels/marioTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/levels/marioTile.png -------------------------------------------------------------------------------- /src/media/levels/platformTile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/levels/platformTile.png -------------------------------------------------------------------------------- /src/media/levels/platformerProject.oep: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0.0.40 4 | PlatformerExample 5 | 6 | 7 | 8 | 800 9 | 600 10 | 11 | 12 | 800 13 | 600 14 | 15 | 16 | 800 17 | 600 18 | 19 | D:\projects\myRepo\Flash Games\StarlingPunkExample\src\media\levels\platformerProject.oep 20 | Radians 21 | false 22 | 23 | 640 24 | 480 25 | 26 | false 27 | 28 | 29 | 30 | Entities 31 | 32 | 32 33 | 32 34 | 35 | 36 | 1 37 | 1 38 | 39 | 40 | 41 | collision 42 | 43 | 32 44 | 32 45 | 46 | 47 | 1 48 | 1 49 | 50 | 51 | Bitstring 52 | 53 | 54 | ground 55 | 56 | 32 57 | 32 58 | 59 | 60 | 1 61 | 1 62 | 63 | CSV 64 | 65 | 66 | 67 | 68 | groundTileSet 69 | groundTileSet.png 70 | 71 | 32 72 | 32 73 | 74 | 0 75 | 76 | 77 | 78 | 79 | 80 | 32 81 | 32 82 | 83 | 84 | 0 85 | 0 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 32 98 | 32 99 | 100 | 101 | 0 102 | 0 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /src/media/levels/scrollingCamera.oep: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.1.0.4 4 | ScrollingCamera 5 | 6 | 7 | 8 | 5000 9 | 5000 10 | 11 | 12 | 5000 13 | 5000 14 | 15 | 16 | 5000 17 | 5000 18 | 19 | D:\projects\myRepo\Flash Games\StarlingPunkExample\src\media\levels\scrollingCamera.oep 20 | Radians 21 | true 22 | 23 | 800 24 | 600 25 | 26 | true 27 | 28 | 29 | 30 | GroundTiles 31 | 32 | 32 33 | 32 34 | 35 | 36 | 1 37 | 1 38 | 39 | CSV 40 | 41 | 42 | 43 | 44 | groundTileSet 45 | groundTileSet.png 46 | 47 | 32 48 | 32 49 | 50 | 0 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /src/media/levels/tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/levels/tileset.png -------------------------------------------------------------------------------- /src/media/particles/explosion.pex: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /src/media/particles/explosionTexture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/particles/explosionTexture.png -------------------------------------------------------------------------------- /src/media/textures/Alien.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/textures/Alien.png -------------------------------------------------------------------------------- /src/media/textures/PlayerEntity.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/textures/PlayerEntity.png -------------------------------------------------------------------------------- /src/media/textures/Ship.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/textures/Ship.png -------------------------------------------------------------------------------- /src/media/textures/TestShape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/textures/TestShape.png -------------------------------------------------------------------------------- /src/media/textures/textureAtlas.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/textures/textureAtlas.png -------------------------------------------------------------------------------- /src/media/textures/textureAtlas.tps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/textures/textureAtlas.tps -------------------------------------------------------------------------------- /src/media/textures/textureAtlas.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/media/textures/tileset.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/asaia/StarlingPunk/2dd73959aa2f3c7cd478ad67b2a69cf6fa83c8c3/src/media/textures/tileset.png --------------------------------------------------------------------------------