├── .actionScriptProperties
├── .gitignore
├── .project
├── .settings
└── org.eclipse.core.resources.prefs
├── CHANGELOG.md
├── LICENSE.md
├── README.md
├── media
├── fonts
│ └── bitmap
│ │ ├── fontRegular.fnt
│ │ ├── fontRegular.png
│ │ ├── fontScoreLabel.fnt
│ │ ├── fontScoreLabel.png
│ │ ├── fontScoreValue.fnt
│ │ └── fontScoreValue.png
├── graphics
│ ├── bgLayer1.jpg
│ ├── bgWelcome.jpg
│ ├── mySpritesheet.png
│ └── mySpritesheet.xml
├── particles
│ ├── particleCoffee.pex
│ ├── particleMushroom.pex
│ └── texture.png
└── sounds
│ ├── bgGame.mp3
│ ├── bgWelcome.mp3
│ ├── coffee.mp3
│ ├── eat.mp3
│ ├── hit.mp3
│ ├── hurt.mp3
│ ├── lose.mp3
│ └── mushroom.mp3
└── src
├── Assets.as
├── Fonts.as
├── Game.as
├── GameConstants.as
├── HungryHero1-app.xml
├── HungryHero1.as
├── ParticleAssets.as
├── Sounds.as
├── com
└── hsharma
│ └── hungryHero
│ ├── customObjects
│ └── Font.as
│ ├── events
│ └── NavigationEvent.as
│ ├── gameElements
│ ├── BgLayer.as
│ ├── GameBackground.as
│ ├── Hero.as
│ ├── Item.as
│ ├── Obstacle.as
│ └── Particle.as
│ ├── objectPools
│ ├── PoolItem.as
│ ├── PoolObstacle.as
│ └── PoolParticle.as
│ ├── screens
│ ├── InGame.as
│ └── Welcome.as
│ └── ui
│ ├── GameOverContainer.as
│ ├── HUD.as
│ ├── PauseButton.as
│ └── SoundButton.as
└── icons
├── icon_114.png
├── icon_128.png
├── icon_16.png
├── icon_29.png
├── icon_32.png
├── icon_36.png
├── icon_48.png
├── icon_512.png
├── icon_57.png
└── icon_72.png
/.actionScriptProperties:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
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 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
--------------------------------------------------------------------------------
/.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 |
11 | # OS X folders
12 | .DS_Store
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hungry-Hero
4 |
5 |
6 |
7 |
8 |
9 | com.adobe.flexbuilder.project.flexbuilder
10 |
11 |
12 |
13 |
14 | com.adobe.flexbuilder.project.apollobuilder
15 |
16 |
17 |
18 |
19 |
20 | com.adobe.flexide.project.multiplatform.multiplatformasnature
21 | com.adobe.flexide.project.multiplatform.multiplatformnature
22 | com.adobe.flexbuilder.project.apollonature
23 | com.adobe.flexbuilder.project.actionscriptnature
24 |
25 |
26 |
27 | [source path] PrimaryFeather-Starling-Extension-Particle-System-583807c-src
28 | 2
29 | /Users/hsharma/Documents/DATA/Current/Work/SDK/Starling Extensions/Particles/PrimaryFeather-Starling-Extension-Particle-System-583807c/src
30 |
31 |
32 | [source path] starling-src
33 | 2
34 | /Users/hsharma/Documents/DATA/Current/Work/SDK/Starling/PrimaryFeather-Starling-Framework-64579fd/starling/src
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.core.resources.prefs:
--------------------------------------------------------------------------------
1 | #Tue Oct 23 15:10:43 GMT+05:30 2012
2 | eclipse.preferences.version=1
3 | encoding/=utf-8
4 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Hungry Hero Game: Changelog
2 | ===========================
3 |
4 | Version 1.0
5 | -----------
6 |
7 | * First version of the source.
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | Simplified BSD License
2 | ======================
3 |
4 | Copyright (C) 2012 Hemanth Sharma (www.hsharma.com)
5 | All rights reserved.
6 |
7 | Redistribution and use in source and binary forms, with or without
8 | modification, are permitted provided that the following conditions are met:
9 |
10 | 1. Redistributions of source code must retain the above copyright notice, this
11 | list of conditions and the following disclaimer.
12 | 2. Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 |
27 | The views and conclusions contained in the software and documentation are those
28 | of the authors and should not be interpreted as representing official policies,
29 | either expressed or implied, of the FreeBSD Project.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Hungry Hero Game
2 | ================
3 |
4 |
5 | Usage
6 | ---
7 |
8 | Please __DO NOT__ use the graphic assets in any commercial projects. Use them for learning purpose only.
9 |
10 | The ActionScript source code of this project is __FREE__. You can redistribute and/or modify it in accordance with the terms of the accompanying __Simplified BSD__ License Agreement.
11 |
12 | Overview
13 | ---
14 |
15 | Hungry Hero is an open source Flash game built on [__Starling Framework__](http://www.gamua.com/starling).
16 |
17 | This game is built to give developers an idea of how a typical Starling based game looks like.
18 | The basic idea is to showcase how easy it is to build a Stage3D game, giving your games the
19 | power of GPU rendering or Hardware acceleration.
20 |
21 | Some of the features & highlights this game showcases: -
22 |
23 | * Textures
24 | * Animation using the Juggler
25 | * Texture Atlas or Sprite Sheets
26 | * Parallax Background
27 | * Mouse/Touch Interaction
28 | * Collision/Hit Detection
29 | * Object Pooling
30 | * Bitmap Fonts
31 | * Starling Extension: [Particle System](https://github.com/PrimaryFeather/Starling-Extension-Particle-System)
32 |
33 | Though this project is developed considering the size of Apple iPad 1 & 2, with basic changes to the configuration files, it can be made to run on any device that supports Adobe AIR/Flash and is developed with "One code, multi-screen" in mind.
34 |
35 | Play the Game
36 | ---
37 |
38 | Play the game on - [__Hungry Hero Website__](http://www.hungryherogame.com)
39 |
40 | Video Tutorials
41 | ---
42 |
43 | Learn to build this game from scratch through the video series: - [__Starting with Starling__](http://www.hsharma.com/tutorials/?series=starting-with-starling)
44 |
45 | Supporting Frameworks & Libraries
46 | ---
47 |
48 | Please download the following frameworks & libraries for this game to compile: -
49 |
50 | * [__Starling Framework__](https://github.com/PrimaryFeather/Starling-Framework) - Commit from Oct 28 2012 or newer is recommended.
51 |
52 | * [__Particle System Extension__](https://github.com/PrimaryFeather/Starling-Extension-Particle-System) - Commit from Oct 24 2012 or newer is recommended.
53 |
54 | Concept, Design & Development
55 | ---
56 |
57 | __Hemanth Sharma__ (http://www.hsharma.com)
58 |
--------------------------------------------------------------------------------
/media/fonts/bitmap/fontRegular.fnt:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/media/fonts/bitmap/fontRegular.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/fonts/bitmap/fontRegular.png
--------------------------------------------------------------------------------
/media/fonts/bitmap/fontScoreLabel.fnt:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/media/fonts/bitmap/fontScoreLabel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/fonts/bitmap/fontScoreLabel.png
--------------------------------------------------------------------------------
/media/fonts/bitmap/fontScoreValue.fnt:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/media/fonts/bitmap/fontScoreValue.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/fonts/bitmap/fontScoreValue.png
--------------------------------------------------------------------------------
/media/graphics/bgLayer1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/graphics/bgLayer1.jpg
--------------------------------------------------------------------------------
/media/graphics/bgWelcome.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/graphics/bgWelcome.jpg
--------------------------------------------------------------------------------
/media/graphics/mySpritesheet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/graphics/mySpritesheet.png
--------------------------------------------------------------------------------
/media/graphics/mySpritesheet.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
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 |
--------------------------------------------------------------------------------
/media/particles/particleCoffee.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 |
--------------------------------------------------------------------------------
/media/particles/particleMushroom.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 |
--------------------------------------------------------------------------------
/media/particles/texture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/particles/texture.png
--------------------------------------------------------------------------------
/media/sounds/bgGame.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/sounds/bgGame.mp3
--------------------------------------------------------------------------------
/media/sounds/bgWelcome.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/sounds/bgWelcome.mp3
--------------------------------------------------------------------------------
/media/sounds/coffee.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/sounds/coffee.mp3
--------------------------------------------------------------------------------
/media/sounds/eat.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/sounds/eat.mp3
--------------------------------------------------------------------------------
/media/sounds/hit.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/sounds/hit.mp3
--------------------------------------------------------------------------------
/media/sounds/hurt.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/sounds/hurt.mp3
--------------------------------------------------------------------------------
/media/sounds/lose.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/sounds/lose.mp3
--------------------------------------------------------------------------------
/media/sounds/mushroom.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/media/sounds/mushroom.mp3
--------------------------------------------------------------------------------
/src/Assets.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package
15 | {
16 | import flash.display.Bitmap;
17 | import flash.utils.Dictionary;
18 |
19 | import starling.textures.Texture;
20 | import starling.textures.TextureAtlas;
21 |
22 | /**
23 | * This class holds all embedded textures, fonts and sounds and other embedded files.
24 | * By using static access methods, only one instance of the asset file is instantiated. This
25 | * means that all Image types that use the same bitmap will use the same Texture on the video card.
26 | *
27 | * @author hsharma
28 | *
29 | */
30 | public class Assets
31 | {
32 | /**
33 | * Texture Atlas
34 | */
35 | [Embed(source="../media/graphics/mySpritesheet.png")]
36 | public static const AtlasTextureGame:Class;
37 |
38 | [Embed(source="../media/graphics/mySpritesheet.xml", mimeType="application/octet-stream")]
39 | public static const AtlasXmlGame:Class;
40 |
41 | /**
42 | * Background Assets
43 | */
44 | [Embed(source="../media/graphics/bgLayer1.jpg")]
45 | public static const BgLayer1:Class;
46 |
47 | [Embed(source="../media/graphics/bgWelcome.jpg")]
48 | public static const BgWelcome:Class;
49 |
50 | /**
51 | * Texture Cache
52 | */
53 | private static var gameTextures:Dictionary = new Dictionary();
54 | private static var gameTextureAtlas:TextureAtlas;
55 |
56 | /**
57 | * Returns the Texture atlas instance.
58 | * @return the TextureAtlas instance (there is only oneinstance per app)
59 | */
60 | public static function getAtlas():TextureAtlas
61 | {
62 | if (gameTextureAtlas == null)
63 | {
64 | var texture:Texture = getTexture("AtlasTextureGame");
65 | var xml:XML = XML(new AtlasXmlGame());
66 | gameTextureAtlas=new TextureAtlas(texture, xml);
67 | }
68 |
69 | return gameTextureAtlas;
70 | }
71 |
72 | /**
73 | * Returns a texture from this class based on a string key.
74 | *
75 | * @param name A key that matches a static constant of Bitmap type.
76 | * @return a starling texture.
77 | */
78 | public static function getTexture(name:String):Texture
79 | {
80 | if (gameTextures[name] == undefined)
81 | {
82 | var bitmap:Bitmap = new Assets[name]();
83 | gameTextures[name]=Texture.fromBitmap(bitmap);
84 | }
85 |
86 | return gameTextures[name];
87 | }
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/src/Fonts.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package
15 | {
16 | import com.hsharma.hungryHero.customObjects.Font;
17 |
18 | import starling.text.BitmapFont;
19 | import starling.text.TextField;
20 | import starling.textures.Texture;
21 |
22 | /**
23 | * This class embeds the bitmap fonts used in the game.
24 | *
25 | * @author hsharma
26 | *
27 | */
28 | public class Fonts
29 | {
30 | /**
31 | * Regular font used for UI.
32 | */
33 | [Embed(source="../media/fonts/bitmap/fontRegular.png")]
34 | public static const Font_Regular:Class;
35 |
36 | [Embed(source="../media/fonts/bitmap/fontRegular.fnt", mimeType="application/octet-stream")]
37 | public static const XML_Regular:Class;
38 |
39 | /**
40 | * Font for score label.
41 | */
42 | [Embed(source="../media/fonts/bitmap/fontScoreLabel.png")]
43 | public static const Font_ScoreLabel:Class;
44 |
45 | [Embed(source="../media/fonts/bitmap/fontScoreLabel.fnt", mimeType="application/octet-stream")]
46 | public static const XML_ScoreLabel:Class;
47 |
48 | /**
49 | * Font for score value.
50 | */
51 | [Embed(source="../media/fonts/bitmap/fontScoreValue.png")]
52 | public static const Font_ScoreValue:Class;
53 |
54 | [Embed(source="../media/fonts/bitmap/fontScoreValue.fnt", mimeType="application/octet-stream")]
55 | public static const XML_ScoreValue:Class;
56 |
57 | /**
58 | * Font objects.
59 | */
60 | private static var Regular:BitmapFont;
61 | private static var ScoreLabel:BitmapFont;
62 | private static var ScoreValue:BitmapFont;
63 |
64 | /**
65 | * Returns the BitmapFont (texture + xml) instance's fontName property (there is only oneinstance per app).
66 | * @return String
67 | */
68 | public static function getFont(_fontStyle:String):Font
69 | {
70 | if (Fonts[_fontStyle] == undefined)
71 | {
72 | var texture:Texture = Texture.fromBitmap(new Fonts["Font_" + _fontStyle]());
73 | var xml:XML = XML(new Fonts["XML_" + _fontStyle]());
74 | Fonts[_fontStyle] = new BitmapFont(texture, xml);
75 | TextField.registerBitmapFont(Fonts[_fontStyle]);
76 | }
77 |
78 | return new Font(Fonts[_fontStyle].name, Fonts[_fontStyle].size);
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/Game.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package
15 | {
16 | import com.hsharma.hungryHero.events.NavigationEvent;
17 | import com.hsharma.hungryHero.screens.InGame;
18 | import com.hsharma.hungryHero.screens.Welcome;
19 | import com.hsharma.hungryHero.ui.SoundButton;
20 |
21 | import flash.media.SoundMixer;
22 |
23 | import starling.display.Sprite;
24 | import starling.events.Event;
25 |
26 | /**
27 | * This class is the primary Starling Sprite based class
28 | * that triggers the different screens.
29 | *
30 | * @author hsharma
31 | *
32 | */
33 | public class Game extends Sprite
34 | {
35 | /** Screen - Welcome or Main Menu. */
36 | private var screenWelcome:Welcome;
37 |
38 | /** Screen - InGame. */
39 | private var screenInGame:InGame;
40 |
41 | /** Sound / Mute button. */
42 | private var soundButton:SoundButton;
43 |
44 | public function Game()
45 | {
46 | super();
47 |
48 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
49 | }
50 |
51 | /**
52 | * On Game class added to stage.
53 | * @param event
54 | *
55 | */
56 | private function onAddedToStage(event:Event):void
57 | {
58 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
59 |
60 | // Initialize screens.
61 | initScreens();
62 | }
63 |
64 | /**
65 | * Initialize screens.
66 | *
67 | */
68 | private function initScreens():void
69 | {
70 | this.addEventListener(NavigationEvent.CHANGE_SCREEN, onChangeScreen);
71 |
72 | // InGame screen.
73 | screenInGame = new InGame();
74 | screenInGame.addEventListener(NavigationEvent.CHANGE_SCREEN, onInGameNavigation);
75 | this.addChild(screenInGame);
76 |
77 | // Welcome screen.
78 | screenWelcome = new Welcome();
79 | this.addChild(screenWelcome);
80 |
81 | // Create and add Sound/Mute button.
82 | soundButton = new SoundButton();
83 | soundButton.x = int(soundButton.width * 0.5);
84 | soundButton.y = int(soundButton.height * 0.5);
85 | soundButton.addEventListener(Event.TRIGGERED, onSoundButtonClick);
86 | this.addChild(soundButton)
87 |
88 | // Initialize the Welcome screen by default.
89 | screenWelcome.initialize();
90 | }
91 |
92 | /**
93 | * On navigation from different screens.
94 | * @param event
95 | *
96 | */
97 | private function onInGameNavigation(event:NavigationEvent):void
98 | {
99 | switch (event.params.id)
100 | {
101 | case "mainMenu":
102 | screenWelcome.initialize();
103 | break;
104 | case "about":
105 | screenWelcome.initialize();
106 | screenWelcome.showAbout();
107 | break;
108 | }
109 | }
110 |
111 | /**
112 | * On click of the sound/mute button.
113 | * @param event
114 | *
115 | */
116 | private function onSoundButtonClick(event:Event = null):void
117 | {
118 | if (Sounds.muted)
119 | {
120 | Sounds.muted = false;
121 |
122 | if (screenWelcome.visible) Sounds.sndBgMain.play(0, 999);
123 | else if (screenInGame.visible) Sounds.sndBgGame.play(0, 999);
124 |
125 | soundButton.showUnmuteState();
126 | }
127 | else
128 | {
129 | Sounds.muted = true;
130 | SoundMixer.stopAll();
131 |
132 | soundButton.showMuteState();
133 | }
134 | }
135 |
136 | /**
137 | * On change of screen.
138 | * @param event
139 | *
140 | */
141 | private function onChangeScreen(event:NavigationEvent):void
142 | {
143 | switch (event.params.id)
144 | {
145 | case "play":
146 | screenWelcome.disposeTemporarily();
147 | screenInGame.initialize();
148 | break;
149 | }
150 | }
151 | }
152 | }
--------------------------------------------------------------------------------
/src/GameConstants.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package
15 | {
16 | /**
17 | * This class holds all the constant values used during game play.
18 | * Modifying certain properties of this class could result in
19 | * slightly varied behavior in the game, e.g., hero's lives or speed.
20 | *
21 | * @author hsharma
22 | *
23 | */
24 | public class GameConstants
25 | {
26 | // Player's states - what is the player doing? -------------
27 |
28 | public static const GAME_STATE_IDLE:int = 0;
29 | public static const GAME_STATE_FLYING:int = 1;
30 | public static const GAME_STATE_OVER:int = 2;
31 |
32 | // Hero's graphic states - what is the position/animation of hero?
33 |
34 | public static const HERO_STATE_IDLE:int = 0;
35 | public static const HERO_STATE_FLYING:int = 1;
36 | public static const HERO_STATE_HIT:int = 2;
37 | public static const HERO_STATE_FALL:int = 3;
38 |
39 | // Food item types -----------------------------------------
40 |
41 | public static const ITEM_TYPE_1:int = 1;
42 | public static const ITEM_TYPE_2:int = 2;
43 | public static const ITEM_TYPE_3:int = 3;
44 | public static const ITEM_TYPE_4:int = 4;
45 | public static const ITEM_TYPE_5:int = 5;
46 |
47 | /** Special Item - Coffee. */
48 | public static const ITEM_TYPE_COFFEE:int = 6;
49 |
50 | /** Special Item - Mushroom. */
51 | public static const ITEM_TYPE_MUSHROOM:int = 7;
52 |
53 | // Obstacle types ------------------------------------------
54 |
55 | /** Obstacle - Aeroplane. */
56 | public static const OBSTACLE_TYPE_1:int = 1;
57 |
58 | /** Obstacle - Space Ship. */
59 | public static const OBSTACLE_TYPE_2:int = 2;
60 |
61 | /** Obstacle - Airship. */
62 | public static const OBSTACLE_TYPE_3:int = 3;
63 |
64 | /** Obstacle - Helicopter. */
65 | public static const OBSTACLE_TYPE_4:int = 4;
66 |
67 | // Particle types ------------------------------------------
68 |
69 | /** Particle - Sparkle. */
70 | public static const PARTICLE_TYPE_1:int = 1;
71 |
72 | /** Particle - Wind Force. */
73 | public static const PARTICLE_TYPE_2:int = 2;
74 |
75 | // Hero properties -----------------------------------------
76 |
77 | /** Hero's initial spare lives. */
78 | public static const HERO_LIVES:int = 5;
79 |
80 | /** Hero's minimum speed. */
81 | public static const HERO_MIN_SPEED:Number = 650;
82 |
83 | /** Hero's maximum speed when had coffee. */
84 | public static const HERO_MAX_SPEED:Number = 1400;
85 |
86 | /** Movement speed - game/player/items/obstacles speed. */
87 | public static const GRAVITY:Number = 10;
88 |
89 | // Obstacle properties -------------------------------------
90 |
91 | /** Obstacle frequency. */
92 | public static const OBSTACLE_GAP:Number = 1200;
93 |
94 | /** Obstacle speed. */
95 | public static const OBSTACLE_SPEED:Number = 300;
96 | }
97 | }
--------------------------------------------------------------------------------
/src/HungryHero1-app.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
15 |
16 |
18 | HungryHero1
19 |
20 |
21 | HungryHero1
22 |
23 |
25 | Hungry Hero
26 |
27 |
30 | 1.0.0
31 |
32 |
33 |
34 |
35 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 | [This value will be overwritten by Flash Builder in the output app.xml]
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 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 | landscape
113 | direct
114 | false
115 | true
116 | true
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
138 |
139 | icons/icon_16.png
140 | icons/icon_32.png
141 | icons/icon_36.png
142 | icons/icon_48.png
143 | icons/icon_57.png
144 | icons/icon_72.png
145 | icons/icon_114.png
146 | icons/icon_128.png
147 | icons/icon_512.png
148 |
149 |
150 |
153 |
154 |
155 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
204 |
205 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
246 |
247 |
249 |
250 |
251 |
252 |
253 |
255 |
256 |
257 |
258 |
259 |
261 |
262 |
263 |
264 |
265 | ]]>
266 |
267 |
268 | UIPrerenderedIcon
270 |
271 | UIDeviceFamily
272 |
273 | 2
274 |
275 | ]]>
276 | high
277 |
278 |
279 |
--------------------------------------------------------------------------------
/src/HungryHero1.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package
15 | {
16 | import flash.display.Sprite;
17 | import flash.events.Event;
18 |
19 | import starling.core.Starling;
20 |
21 | /**
22 | * SWF meta data defined for iPad 1 & 2 in landscape mode.
23 | */
24 | [SWF(frameRate="60", width="1024", height="768", backgroundColor="0x000000")]
25 |
26 | /**
27 | * This is the main class of the project.
28 | *
29 | * @author hsharma
30 | *
31 | */
32 | public class HungryHero1 extends Sprite
33 | {
34 | /** Starling object. */
35 | private var myStarling:Starling;
36 |
37 | public function HungryHero1()
38 | {
39 | super();
40 |
41 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
42 | }
43 |
44 | /**
45 | * On added to stage.
46 | * @param event
47 | *
48 | */
49 | protected function onAddedToStage(event:Event):void
50 | {
51 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
52 |
53 | // Initialize Starling object.
54 | myStarling = new Starling(Game, stage);
55 |
56 | // Define basic anti aliasing.
57 | myStarling.antiAliasing = 1;
58 |
59 | // Show statistics for memory usage and fps.
60 | myStarling.showStats = true;
61 |
62 | // Position stats.
63 | myStarling.showStatsAt("left", "bottom");
64 |
65 | // Start Starling Framework.
66 | myStarling.start();
67 | }
68 | }
69 | }
--------------------------------------------------------------------------------
/src/ParticleAssets.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package
15 | {
16 | /**
17 | * This class holds all particle files.
18 | *
19 | * @author hsharma
20 | *
21 | */
22 | public class ParticleAssets
23 | {
24 | /**
25 | * Particle
26 | */
27 | [Embed(source="../media/particles/particleCoffee.pex", mimeType="application/octet-stream")]
28 | public static var ParticleCoffeeXML:Class;
29 |
30 | [Embed(source="../media/particles/particleMushroom.pex", mimeType="application/octet-stream")]
31 | public static var ParticleMushroomXML:Class;
32 |
33 | [Embed(source="../media/particles/texture.png")]
34 | public static var ParticleTexture:Class;
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Sounds.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package
15 | {
16 | import flash.media.Sound;
17 |
18 | /**
19 | * This class holds all the sound embeds and objects that are used in the game.
20 | *
21 | * @author hsharma
22 | *
23 | */
24 | public class Sounds
25 | {
26 | /**
27 | * Embedded sound files.
28 | */
29 | [Embed(source="../media/sounds/bgGame.mp3")]
30 | public static const SND_BG_GAME:Class;
31 |
32 | [Embed(source="../media/sounds/bgWelcome.mp3")]
33 | public static const SND_BG_MAIN:Class;
34 |
35 | [Embed(source="../media/sounds/eat.mp3")]
36 | public static const SND_EAT:Class;
37 |
38 | [Embed(source="../media/sounds/coffee.mp3")]
39 | public static const SND_COFFEE:Class;
40 |
41 | [Embed(source="../media/sounds/mushroom.mp3")]
42 | public static const SND_MUSHROOM:Class;
43 |
44 | [Embed(source="../media/sounds/hit.mp3")]
45 | public static const SND_HIT:Class;
46 |
47 | [Embed(source="../media/sounds/hurt.mp3")]
48 | public static const SND_HURT:Class;
49 |
50 | [Embed(source="../media/sounds/lose.mp3")]
51 | public static const SND_LOSE:Class;
52 |
53 | /**
54 | * Initialized Sound objects.
55 | */
56 | public static var sndBgMain:Sound = new Sounds.SND_BG_MAIN() as Sound;
57 | public static var sndBgGame:Sound = new Sounds.SND_BG_GAME() as Sound;
58 | public static var sndEat:Sound = new Sounds.SND_EAT() as Sound;
59 | public static var sndCoffee:Sound = new Sounds.SND_COFFEE() as Sound;
60 | public static var sndMushroom:Sound = new Sounds.SND_MUSHROOM() as Sound;
61 | public static var sndHit:Sound = new Sounds.SND_HIT() as Sound;
62 | public static var sndHurt:Sound = new Sounds.SND_HURT() as Sound;
63 | public static var sndLose:Sound = new Sounds.SND_LOSE() as Sound;
64 |
65 | /**
66 | * Sound mute status.
67 | */
68 | public static var muted:Boolean = false;
69 | }
70 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/customObjects/Font.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.customObjects
15 | {
16 | /**
17 | * This class stores the properties of a font -
18 | * Font Name
19 | * Font Size
20 | * Font Color
21 | *
22 | * @author hsharma
23 | *
24 | */
25 | public final class Font
26 | {
27 | private var _fontName:String;
28 | private var _fontSize:uint;
29 | private var _fontColor:uint;
30 |
31 | public function Font(fontName:String, fontSize:uint, fontColor:uint = 0xffffff)
32 | {
33 | this.fontName = fontName;
34 | this.fontSize = fontSize;
35 | this.fontColor = fontColor;
36 | }
37 |
38 | /**
39 | * Font Color.
40 | * @return
41 | *
42 | */
43 | public function get fontColor():uint
44 | {
45 | return _fontColor;
46 | }
47 |
48 | public function set fontColor(value:uint):void
49 | {
50 | _fontColor = value;
51 | }
52 |
53 | /**
54 | * Font Size.
55 | * @return
56 | *
57 | */
58 | public function get fontSize():uint
59 | {
60 | return _fontSize;
61 | }
62 |
63 | public function set fontSize(value:uint):void
64 | {
65 | _fontSize = value;
66 | }
67 |
68 | /**
69 | * Font Name.
70 | * @return
71 | *
72 | */
73 | public function get fontName():String
74 | {
75 | return _fontName;
76 | }
77 |
78 | public function set fontName(value:String):void
79 | {
80 | _fontName = value;
81 | }
82 | }
83 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/events/NavigationEvent.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.events
15 | {
16 | import starling.events.Event;
17 |
18 | /**
19 | * This class defines custom events for navigation in the game.
20 | * @author hsharma
21 | *
22 | */
23 | public class NavigationEvent extends Event
24 | {
25 | /** Change of a screen. */
26 | public static const CHANGE_SCREEN:String = "changeScreen";
27 |
28 | /** Custom object to pass parameters to the screens. */
29 | public var params:Object;
30 |
31 | public function NavigationEvent(type:String, _params:Object, bubbles:Boolean=false)
32 | {
33 | super(type, bubbles);
34 | params = _params;
35 | }
36 | }
37 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/gameElements/BgLayer.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.gameElements
15 | {
16 | import starling.display.BlendMode;
17 | import starling.display.Image;
18 | import starling.display.Sprite;
19 | import starling.events.Event;
20 |
21 | /**
22 | * This class defines each of background layers used in the InGame screen.
23 | *
24 | * @author hsharma
25 | *
26 | */
27 | public class BgLayer extends Sprite
28 | {
29 | /** Layer identification. */
30 | private var _layer:int;
31 |
32 | /** Primary image. */
33 | private var image1:Image;
34 |
35 | /** Secondary image. */
36 | private var image2:Image;
37 |
38 | /** Parallax depth - used to decide speed of the animation. */
39 | private var _parallaxDepth:Number;
40 |
41 | public function BgLayer(_layer:int)
42 | {
43 | super();
44 |
45 | this._layer = _layer;
46 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
47 | }
48 |
49 | /**
50 | * On added to stage.
51 | * @param event
52 | *
53 | */
54 | private function onAddedToStage(event:Event):void
55 | {
56 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
57 |
58 | if (_layer == 1)
59 | {
60 | image1 = new Image(Assets.getTexture("BgLayer" + _layer));
61 | image1.blendMode = BlendMode.NONE;
62 | image2 = new Image(Assets.getTexture("BgLayer" + _layer));
63 | image2.blendMode = BlendMode.NONE;
64 | }
65 | else
66 | {
67 | image1 = new Image(Assets.getAtlas().getTexture("bgLayer" + _layer));
68 | image2 = new Image(Assets.getAtlas().getTexture("bgLayer" + _layer));
69 | }
70 |
71 | image1.x = 0;
72 | image1.y = stage.stageHeight - image1.height;
73 |
74 | image2.x = image2.width;
75 | image2.y = image1.y;
76 |
77 | this.addChild(image1);
78 | this.addChild(image2);
79 | }
80 |
81 | /**
82 | * Parallax depth.
83 | *
84 | */
85 | public function get parallaxDepth():Number { return _parallaxDepth; }
86 | public function set parallaxDepth(value:Number):void { _parallaxDepth = value; }
87 | }
88 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/gameElements/GameBackground.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.gameElements
15 | {
16 | import starling.display.Sprite;
17 | import starling.events.Event;
18 |
19 | /**
20 | * This class defines the whole InGame background containing multiple background layers.
21 | *
22 | * @author hsharma
23 | *
24 | */
25 | public class GameBackground extends Sprite
26 | {
27 | /**
28 | * Different layers of the background.
29 | */
30 |
31 | private var bgLayer1:BgLayer;
32 | private var bgLayer2:BgLayer;
33 | private var bgLayer3:BgLayer;
34 | private var bgLayer4:BgLayer;
35 |
36 | /** Current speed of animation of the background. */
37 | private var _speed:Number = 0;
38 |
39 | /** State of the game. */
40 | private var _state:int;
41 |
42 | /** Game paused? */
43 | private var _gamePaused:Boolean = false;
44 |
45 | public function GameBackground()
46 | {
47 | super();
48 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
49 | }
50 |
51 | /**
52 | * On added to stage.
53 | * @param event
54 | *
55 | */
56 | private function onAddedToStage(event:Event):void
57 | {
58 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
59 |
60 | bgLayer1 = new BgLayer(1);
61 | bgLayer1.parallaxDepth = 0.02;
62 | this.addChild(bgLayer1);
63 |
64 | bgLayer2 = new BgLayer(2);
65 | bgLayer2.parallaxDepth = 0.2;
66 | this.addChild(bgLayer2);
67 |
68 | bgLayer3 = new BgLayer(3);
69 | bgLayer3.parallaxDepth = 0.5;
70 | this.addChild(bgLayer3);
71 |
72 | bgLayer4 = new BgLayer(4);
73 | bgLayer4.parallaxDepth = 1;
74 | this.addChild(bgLayer4);
75 |
76 | // Start animating the background.
77 | this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
78 | }
79 |
80 | /**
81 | * On every frame, animate each layer based on its parallax depth and hero's speed.
82 | * @param event
83 | *
84 | */
85 | private function onEnterFrame(event:Event):void
86 | {
87 | if (!gamePaused)
88 | {
89 | // Background 1 - Sky
90 | bgLayer1.x -= Math.ceil(_speed * bgLayer1.parallaxDepth);
91 | // Hero flying left
92 | if (bgLayer1.x > 0) bgLayer1.x = -stage.stageWidth;
93 | // Hero flying right
94 | if (bgLayer1.x < -stage.stageWidth ) bgLayer1.x = 0;
95 |
96 | // Background 2 - Hills
97 | bgLayer2.x -= Math.ceil(_speed * bgLayer2.parallaxDepth);
98 | // Hero flying left
99 | if (bgLayer2.x > 0) bgLayer2.x = -stage.stageWidth;
100 | // Hero flying right
101 | if (bgLayer2.x < -stage.stageWidth ) bgLayer2.x = 0;
102 |
103 | // Background 3 - Buildings
104 | bgLayer3.x -= Math.ceil(_speed * bgLayer3.parallaxDepth);
105 | // Hero flying left
106 | if (bgLayer3.x > 0) bgLayer3.x = -stage.stageWidth;
107 | // Hero flying right
108 | if (bgLayer3.x < -stage.stageWidth ) bgLayer3.x = 0;
109 |
110 | // Background 4 - Trees
111 | bgLayer4.x -= Math.ceil(_speed * bgLayer4.parallaxDepth);
112 | // Hero flying left
113 | if (bgLayer4.x > 0) bgLayer4.x = -stage.stageWidth;
114 | // Hero flying right
115 | if (bgLayer4.x < -stage.stageWidth ) bgLayer4.x = 0;
116 | }
117 | }
118 |
119 | /**
120 | * Game paused?
121 | * @return
122 | *
123 | */
124 | public function get gamePaused():Boolean { return _gamePaused; }
125 | public function set gamePaused(value:Boolean):void { _gamePaused = value; }
126 |
127 | /**
128 | *
129 | * State of the game.
130 | *
131 | */
132 | public function get state():int { return _state; }
133 | public function set state(value:int):void { _state = value; }
134 |
135 | /**
136 | * Speed of the hero.
137 | *
138 | */
139 | public function get speed():Number { return _speed; }
140 | public function set speed(value:Number):void { _speed = value; }
141 | }
142 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/gameElements/Hero.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.gameElements
15 | {
16 | import starling.core.Starling;
17 | import starling.display.MovieClip;
18 | import starling.display.Sprite;
19 | import starling.events.Event;
20 |
21 | /**
22 | * This class is the hero character.
23 | *
24 | * @author hsharma
25 | *
26 | */
27 | public class Hero extends Sprite
28 | {
29 | /** Hero character animation. */
30 | private var heroArt:MovieClip;
31 |
32 | /** State of the hero. */
33 | private var _state:int;
34 |
35 | public function Hero()
36 | {
37 | super();
38 |
39 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
40 | }
41 |
42 | /**
43 | * On added to stage.
44 | * @param event
45 | *
46 | */
47 | private function onAddedToStage(event:Event):void
48 | {
49 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
50 |
51 | // Set the game state to idle.
52 | this.state = GameConstants.GAME_STATE_IDLE;
53 |
54 | // Initialize hero art and hit area.
55 | createHeroArt();
56 | }
57 |
58 | /**
59 | * Create hero art/visuals.
60 | *
61 | */
62 | private function createHeroArt():void
63 | {
64 | heroArt = new MovieClip(Assets.getAtlas().getTextures("fly_"), 20);
65 | heroArt.x = Math.ceil(-heroArt.width/2);
66 | heroArt.y = Math.ceil(-heroArt.height/2);
67 | starling.core.Starling.juggler.add(heroArt);
68 | this.addChild(heroArt);
69 | }
70 |
71 | /**
72 | * State of the hero.
73 | * @return
74 | *
75 | */
76 | public function get state():int { return _state; }
77 | public function set state(value:int):void { _state = value; }
78 |
79 | /**
80 | * Set hero animation speed.
81 | * @param speed
82 | *
83 | */
84 | public function setHeroAnimationSpeed(speed:int):void {
85 | if (speed == 0) heroArt.fps = 20;
86 | else heroArt.fps = 60;
87 | }
88 |
89 | override public function get width():Number
90 | {
91 | if (heroArt) return heroArt.texture.width;
92 | else return NaN;
93 | }
94 |
95 | override public function get height():Number
96 | {
97 | if (heroArt) return heroArt.texture.height;
98 | else return NaN;
99 | }
100 | }
101 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/gameElements/Item.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.gameElements
15 | {
16 | import starling.display.Image;
17 | import starling.display.Sprite;
18 |
19 | /**
20 | * This class represents the food items.
21 | *
22 | * @author hsharma
23 | *
24 | */
25 | public class Item extends Sprite
26 | {
27 | /** Food item type. */
28 | private var _foodItemType:int;
29 |
30 | /** Food item visuals. */
31 | private var itemImage:Image;
32 |
33 | public function Item(_foodItemType:int)
34 | {
35 | super();
36 |
37 | this.foodItemType = _foodItemType;
38 | }
39 |
40 | /**
41 | * Set the type of food item (visuals) to show.
42 | * @param value
43 | *
44 | */
45 | public function set foodItemType(value:int):void
46 | {
47 | _foodItemType = value;
48 |
49 | if (itemImage == null)
50 | {
51 | // If the item is created for the first time.
52 | itemImage = new Image(Assets.getAtlas().getTexture("item" + _foodItemType));
53 | itemImage.width = Assets.getAtlas().getTexture("item" + _foodItemType).width;
54 | itemImage.height = Assets.getAtlas().getTexture("item" + _foodItemType).height;
55 | itemImage.x = -itemImage.width/2;
56 | itemImage.y = -itemImage.height/2;
57 | this.addChild(itemImage);
58 | }
59 | else
60 | {
61 | // If the item is reused.
62 | itemImage.texture = Assets.getAtlas().getTexture("item" + _foodItemType);
63 | itemImage.width = Assets.getAtlas().getTexture("item" + _foodItemType).width;
64 | itemImage.height = Assets.getAtlas().getTexture("item" + _foodItemType).height;
65 | itemImage.x = -itemImage.width/2;
66 | itemImage.y = -itemImage.height/2;
67 | }
68 | }
69 |
70 | /**
71 | * Return the type of food item this object is visually representing.
72 | * @return
73 | *
74 | */
75 | public function get foodItemType():int
76 | {
77 | return _foodItemType;
78 | }
79 | }
80 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/gameElements/Obstacle.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.gameElements
15 | {
16 | import starling.core.Starling;
17 | import starling.display.Image;
18 | import starling.display.MovieClip;
19 | import starling.display.Sprite;
20 | import starling.utils.deg2rad;
21 |
22 | /**
23 | * This class defines the obstacles in the game.
24 | *
25 | * @author hsharma
26 | *
27 | */
28 | public class Obstacle extends Sprite
29 | {
30 | /** Type of the obstacle. */
31 | private var _type:int;
32 |
33 | /** Speed of the obstacle. */
34 | private var _speed:int;
35 |
36 | /** Distance after which the obstacle should appear on screen. */
37 | private var _distance:int;
38 |
39 | /** Look out sign status. */
40 | private var _showLookOut:Boolean;
41 |
42 | /** Has the hero already collided with the obstacle? */
43 | private var _alreadyHit:Boolean;
44 |
45 | /** Vertical position of the obstacle. */
46 | private var _position:String;
47 |
48 | /** Hit area of the obstacle. */
49 | private var _hitArea:Image;
50 |
51 | /** Visual art of the obstacle (static). */
52 | private var obstacleImage:Image;
53 |
54 | /** Visual art of the obstacle (animated). */
55 | private var obstacleAnimation:MovieClip;
56 |
57 | /** Visual art of the crashed obstacle. */
58 | private var obstacleCrashImage:Image;
59 |
60 | /** Look out sign animation. */
61 | private var lookOutAnimation:MovieClip;
62 |
63 | public function Obstacle(_type:int, _distance:int, _lookOut:Boolean = true, _speed:int = 0)
64 | {
65 | super();
66 |
67 | this.type = _type;
68 | this._distance = _distance;
69 | this._showLookOut = _lookOut;
70 | this._speed = _speed;
71 |
72 | _alreadyHit = false;
73 | }
74 |
75 | /**
76 | * Create the art of the obstacle based on - animation/image and new/reused object.
77 | *
78 | */
79 | private function createObstacleArt():void
80 | {
81 | // Animated obstacle.
82 | if (_type == GameConstants.OBSTACLE_TYPE_4)
83 | {
84 | // If this is the first time the object is being used.
85 | if (obstacleAnimation == null)
86 | {
87 | obstacleAnimation = new MovieClip(Assets.getAtlas().getTextures("obstacle" + _type + "_0"), 10);
88 | this.addChild(obstacleAnimation);
89 | Starling.juggler.add(obstacleAnimation);
90 | }
91 | else
92 | {
93 | // If this object is being reused. (Last time also this object was an animation).
94 | obstacleAnimation.visible = true;
95 | Starling.juggler.add(obstacleAnimation);
96 | }
97 |
98 | obstacleAnimation.x = 0;
99 | obstacleAnimation.y = 0;
100 | }
101 | else
102 | {
103 | // Static obstacle.
104 |
105 | // If this is the first time the object is being used.
106 | if (obstacleImage == null)
107 | {
108 | obstacleImage = new Image(Assets.getAtlas().getTexture("obstacle" + _type));
109 | this.addChild(obstacleImage);
110 | }
111 | else
112 | {
113 | // If this object is being reused.
114 | obstacleImage.texture = Assets.getAtlas().getTexture("obstacle" + _type);
115 | obstacleImage.visible = true;
116 | }
117 |
118 | obstacleImage.readjustSize();
119 | obstacleImage.x = 0;
120 | obstacleImage.y = 0;
121 | }
122 | }
123 |
124 | /**
125 | * Create the crash art of the obstacle based on - animation/image and new/reused object.
126 | *
127 | */
128 | private function createObstacleCrashArt():void
129 | {
130 | if (obstacleCrashImage == null)
131 | {
132 | // If this is the first time the object is being used.
133 | obstacleCrashImage = new Image(Assets.getAtlas().getTexture(("obstacle" + _type + "_crash")));
134 | this.addChild(obstacleCrashImage);
135 | }
136 | else
137 | {
138 | // If this object is being reused.
139 | obstacleCrashImage.texture = Assets.getAtlas().getTexture("obstacle" + _type + "_crash");
140 | }
141 |
142 | // Hide the crash image by default.
143 | obstacleCrashImage.visible = false;
144 | }
145 |
146 | /**
147 | * Create the look out animation.
148 | *
149 | */
150 | private function createLookOutAnimation():void
151 | {
152 | if (lookOutAnimation == null)
153 | {
154 | // If this is the first time the object is being used.
155 | lookOutAnimation = new MovieClip(Assets.getAtlas().getTextures("watchOut_"), 10);
156 | this.addChild(lookOutAnimation);
157 | Starling.juggler.add(lookOutAnimation);
158 | }
159 | else
160 | {
161 | // If this object is being reused.
162 | lookOutAnimation.visible = true;
163 | Starling.juggler.add(lookOutAnimation);
164 | }
165 |
166 | // Reset the positioning of look-out animation based on the new obstacle type.
167 | if (_type == GameConstants.OBSTACLE_TYPE_4)
168 | {
169 | lookOutAnimation.x = -lookOutAnimation.texture.width;
170 | lookOutAnimation.y = obstacleAnimation.y + (obstacleAnimation.texture.height * 0.5) - (obstacleAnimation.texture.height * 0.5);
171 | }
172 | else
173 | {
174 | lookOutAnimation.x = -lookOutAnimation.texture.width;
175 | lookOutAnimation.y = obstacleImage.y + (obstacleImage.texture.height * 0.5) - (lookOutAnimation.texture.height * 0.5);
176 | }
177 |
178 | lookOutAnimation.visible = false;
179 | }
180 |
181 | /**
182 | * If reusing, hide previous animation/image, based on what is necessary this time.
183 | *
184 | */
185 | private function hidePreviousInstance():void
186 | {
187 | // If this item is being reused and was an animation the last time, remove it from juggler.
188 | // Only don't remove it if it is an animation this time as well.
189 | if (obstacleAnimation != null && _type != GameConstants.OBSTACLE_TYPE_4)
190 | {
191 | obstacleAnimation.visible = false;
192 | Starling.juggler.remove(obstacleAnimation);
193 | }
194 |
195 | // If this item is being reused and was an image the last time, hide it.
196 | if (obstacleImage != null) obstacleImage.visible = false;
197 | }
198 |
199 | /**
200 | * Set the art, crash art, hit area and Look Out animation based on the new obstacle type.
201 | * @param value
202 | *
203 | */
204 | public function get type():int { return _type; }
205 | public function set type(value:int):void {
206 | _type = value;
207 |
208 | resetForReuse();
209 |
210 | // If reusing, hide previous animation/image, based on what is necessary this time.
211 | hidePreviousInstance();
212 |
213 | // Create Obstacle Art.
214 | createObstacleArt();
215 |
216 | // Create the Crash Art.
217 | createObstacleCrashArt();
218 |
219 | // Create look-out animation.
220 | createLookOutAnimation();
221 | }
222 |
223 | /**
224 | * Look out sign status.
225 | *
226 | */
227 | public function get lookOut():Boolean { return _showLookOut; }
228 | public function set lookOut(value:Boolean):void
229 | {
230 | _showLookOut = value;
231 |
232 | if (lookOutAnimation)
233 | {
234 | if (value)
235 | {
236 | lookOutAnimation.visible = true;
237 | }
238 | else
239 | {
240 | lookOutAnimation.visible = false;
241 | Starling.juggler.remove(lookOutAnimation);
242 | }
243 | }
244 | }
245 |
246 | /**
247 | * Has the hero collided with the obstacle?
248 | *
249 | */
250 | public function get alreadyHit():Boolean { return _alreadyHit; }
251 | public function set alreadyHit(value:Boolean):void
252 | {
253 | _alreadyHit = value;
254 |
255 | if (value)
256 | {
257 | obstacleCrashImage.visible = true;
258 | if (_type == GameConstants.OBSTACLE_TYPE_4)
259 | {
260 | obstacleAnimation.visible = false;
261 | }
262 | else
263 | {
264 | obstacleImage.visible = false;
265 | Starling.juggler.remove(obstacleAnimation);
266 | }
267 | }
268 | }
269 |
270 | /**
271 | * Speed of the obstacle.
272 | *
273 | */
274 | public function get speed():int { return _speed; }
275 | public function set speed(value:int):void { _speed = value; }
276 |
277 | /**
278 | * Distance after which the obstacle should appear on screen.
279 | *
280 | */
281 | public function get distance():int { return _distance; }
282 | public function set distance(value:int):void { _distance = value; }
283 |
284 | /**
285 | * Vertical position of the obstacle.
286 | *
287 | */
288 | public function get position():String { return _position; }
289 | public function set position(value:String):void { _position = value; }
290 |
291 | public function get hitArea():Image { return _hitArea; }
292 |
293 | /**
294 | * Width of the texture that defines the image of this Sprite.
295 | */
296 | override public function get width():Number {
297 | if (obstacleImage) return obstacleImage.texture.width;
298 | else return 0;
299 | }
300 |
301 | /**
302 | * Height of the texture that defines the image of this Sprite.
303 | */
304 | override public function get height():Number
305 | {
306 | if (obstacleImage) return obstacleImage.texture.height;
307 | else return 0;
308 | }
309 |
310 | /**
311 | * Reset the obstacle object for reuse.
312 | *
313 | */
314 | public function resetForReuse():void
315 | {
316 | this.alreadyHit = false;
317 | this.lookOut = true;
318 | this.rotation = deg2rad(0);
319 | }
320 | }
321 | }
322 |
323 |
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/gameElements/Particle.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.gameElements
15 | {
16 | import starling.display.Image;
17 | import starling.display.Sprite;
18 |
19 | /**
20 | * This class represents the particles that appear around hero for various power-ups.
21 | * These particles use the Particle Systems extension for Starling Framework.
22 | *
23 | * @author hsharma
24 | *
25 | */
26 | public class Particle extends Sprite
27 | {
28 | /** Type of particle. */
29 | private var _type:int;
30 |
31 | /** Speed X of the particle. */
32 | private var _speedX:Number;
33 |
34 | /** Speed Y of the particle. */
35 | private var _speedY:Number;
36 |
37 | /** Spin value of the particle. */
38 | private var _spin:Number;
39 |
40 | /** Texture of the particle. */
41 | private var particleImage:Image;
42 |
43 | public function Particle(_type:int)
44 | {
45 | super();
46 |
47 | this._type = _type;
48 |
49 | switch(_type)
50 | {
51 | case GameConstants.PARTICLE_TYPE_1:
52 | particleImage = new Image(Assets.getAtlas().getTexture("particleEat"));
53 | break;
54 | case GameConstants.PARTICLE_TYPE_2:
55 | particleImage = new Image(Assets.getAtlas().getTexture("particleWindForce"));
56 | break;
57 | }
58 |
59 | particleImage.x = particleImage.width/2;
60 | particleImage.y = particleImage.height/2;
61 | this.addChild(particleImage);
62 | }
63 |
64 | /**
65 | * Speed X of the particle.
66 | *
67 | */
68 | public function get speedX():Number { return _speedX; }
69 | public function set speedX(value:Number):void { _speedX = value; }
70 |
71 | /**
72 | * Speed Y of the particle.
73 | *
74 | */
75 | public function get speedY():Number { return _speedY; }
76 | public function set speedY(value:Number):void { _speedY = value; }
77 |
78 | /**
79 | * Spin value of the particle.
80 | *
81 | */
82 | public function get spin():Number { return _spin; }
83 | public function set spin(value:Number):void { _spin = value; }
84 | }
85 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/objectPools/PoolItem.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.objectPools {
15 | import com.hsharma.hungryHero.gameElements.Item;
16 |
17 | /**
18 | * This class handles the Object Pooling for food items.
19 | *
20 | * @author hsharma
21 | *
22 | */
23 | public class PoolItem {
24 |
25 | /** Minimum size of the pool. */
26 | private var _minSize:int;
27 |
28 | /** Maximum size of the pool. */
29 | private var _maxSize:int;
30 |
31 | /** Current size of the pool (list). */
32 | public var size:int = 0;
33 |
34 | /** Function to be called when the object is to be created. */
35 | public var create:Function;
36 |
37 | /** Function to be called when the object is to be cleaned. */
38 | public var clean:Function;
39 |
40 | /** Checked in objects count. */
41 | public var length:int = 0;
42 |
43 | /** Objects in the pool. */
44 | private var list:Vector.- = new Vector.
- ();
45 |
46 | /** If this pool has been disposed. */
47 | private var disposed:Boolean = false;
48 |
49 | /**
50 | * @param create This is the Function which should return a new Object to populate the Object pool
51 | * @param clean This Function will recieve the Object as a param and is used for cleaning the Object ready for reuse
52 | * @param minSize The initial size of the pool on Pool construction
53 | * @param maxSize The maximum possible size for the Pool
54 | *
55 | */
56 |
57 | public function PoolItem(create:Function, clean:Function = null, minSize:int = 50, maxSize:int = 200)
58 | {
59 | this.create = create;
60 | this.clean = clean;
61 | this.minSize = minSize;
62 | this.maxSize = maxSize;
63 |
64 | // Create minimum number of objects now. Later in run-time, if required, more objects will be created < maximum number.
65 | for(var i:int = 0;i < minSize; i++) add();
66 | }
67 |
68 | /**
69 | * Add new objects and check-in to the pool.
70 | *
71 | */
72 | private function add():void
73 | {
74 | list[length++] = create();
75 | size++;
76 | }
77 |
78 | /**
79 | * Sets the minimum size for the Pool.
80 | *
81 | */
82 | public function set minSize(num:int):void
83 | {
84 | _minSize = num;
85 | if(_minSize > _maxSize) _maxSize = _minSize;
86 | if(_maxSize < list.length) list.splice(_maxSize, 1);
87 | size = list.length;
88 | }
89 |
90 | /**
91 | * Gets the minimum size for the Pool.
92 | *
93 | */
94 | public function get minSize():int
95 | {
96 | return _minSize;
97 | }
98 |
99 | /**
100 | * Sets the maximum size for the Pool.
101 | *
102 | */
103 | public function set maxSize(num:int):void
104 | {
105 | _maxSize = num;
106 | if(_maxSize < list.length) list.splice(_maxSize, 1);
107 | size = list.length;
108 | if(_maxSize < _minSize) _minSize = _maxSize;
109 | }
110 |
111 | /**
112 | * Returns the maximum size for the Pool.
113 | *
114 | */
115 | public function get maxSize():int
116 | {
117 | return _maxSize;
118 | }
119 |
120 | /**
121 | * Checks out an Object from the pool.
122 | *
123 | */
124 | public function checkOut():Item
125 | {
126 | if(length == 0) {
127 | if(size < maxSize) {
128 | size++;
129 | return create();
130 | } else {
131 | return null;
132 | }
133 | }
134 |
135 | return list[--length];
136 | }
137 |
138 | /**
139 | * Checks the Object back into the Pool.
140 | * @param item The Object you wish to check back into the Object Pool.
141 | *
142 | */
143 | public function checkIn(item:Item):void
144 | {
145 | if(clean != null) clean(item);
146 | list[length++] = item;
147 | }
148 |
149 | /**
150 | * Disposes the Pool ready for GC.
151 | *
152 | */
153 | public function dispose():void
154 | {
155 | if(disposed) return;
156 |
157 | disposed = true;
158 |
159 | create = null;
160 | clean = null;
161 | list = null;
162 | }
163 | }
164 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/objectPools/PoolObstacle.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.objectPools
15 | {
16 | import com.hsharma.hungryHero.gameElements.Obstacle;
17 |
18 | /**
19 | * This class handles the Object Pooling for the obstacles.
20 | *
21 | * @author hsharma
22 | *
23 | */
24 | public class PoolObstacle {
25 |
26 | /** Minimum size of the pool. */
27 | private var _minSize:int;
28 |
29 | /** Maximum size of the pool. */
30 | private var _maxSize:int;
31 |
32 | /** Current size of the pool (list). */
33 | public var size:int = 0;
34 |
35 | /** Function to be called when the object is to be created. */
36 | public var create:Function;
37 |
38 | /** Function to be called when the object is to be cleaned. */
39 | public var clean:Function;
40 |
41 | /** Checked in objects count. */
42 | public var length:int = 0;
43 |
44 | /** Objects in the pool. */
45 | private var list:Vector. = new Vector.();
46 |
47 | /** If this pool has been disposed. */
48 | private var disposed:Boolean = false;
49 |
50 | /**
51 | * @param create This is the Function which should return a new Object to populate the Object pool
52 | * @param clean This Function will recieve the Object as a param and is used for cleaning the Object ready for reuse
53 | * @param minSize The initial size of the pool on Pool construction
54 | * @param maxSize The maximum possible size for the Pool
55 | *
56 | */
57 |
58 | public function PoolObstacle(create:Function, clean:Function = null, minSize:int = 50, maxSize:int = 200)
59 | {
60 | this.create = create;
61 | this.clean = clean;
62 | this.minSize = minSize;
63 | this.maxSize = maxSize;
64 |
65 | // Create minimum number of objects now. Later in run-time, if required, more objects will be created < maximum number.
66 | for(var i:int = 0;i < minSize; i++) add();
67 | }
68 |
69 | /**
70 | * Add new objects and check-in to the pool.
71 | *
72 | */
73 | private function add():void
74 | {
75 | list[length++] = create();
76 | size++;
77 | }
78 |
79 | /**
80 | * Sets the minimum size for the Pool.
81 | *
82 | */
83 | public function set minSize(num:int):void
84 | {
85 | _minSize = num;
86 | if(_minSize > _maxSize) _maxSize = _minSize;
87 | if(_maxSize < list.length) list.splice(_maxSize, 1);
88 | size = list.length;
89 | }
90 |
91 | /**
92 | * Gets the minimum size for the Pool.
93 | *
94 | */
95 | public function get minSize():int
96 | {
97 | return _minSize;
98 | }
99 |
100 | /**
101 | * Sets the maximum size for the Pool.
102 | *
103 | */
104 | public function set maxSize(num:int):void
105 | {
106 | _maxSize = num;
107 | if(_maxSize < list.length) list.splice(_maxSize, 1);
108 | size = list.length;
109 | if(_maxSize < _minSize) _minSize = _maxSize;
110 | }
111 |
112 | /**
113 | * Returns the maximum size for the Pool.
114 | *
115 | */
116 | public function get maxSize():int
117 | {
118 | return _maxSize;
119 | }
120 |
121 | /**
122 | * Checks out an Object from the pool.
123 | *
124 | */
125 | public function checkOut():Obstacle
126 | {
127 | if(length == 0) {
128 | if(size < maxSize) {
129 | size++;
130 | return create();
131 | } else {
132 | return null;
133 | }
134 | }
135 |
136 | return list[--length];
137 | }
138 |
139 | /**
140 | * Checks the Object back into the Pool.
141 | * @param item The Object you wish to check back into the Object Pool.
142 | *
143 | */
144 | public function checkIn(item:Obstacle):void
145 | {
146 | if(clean != null) clean(item);
147 | list[length++] = item;
148 | }
149 |
150 | /**
151 | * Disposes the Pool ready for GC.
152 | *
153 | */
154 | public function dispose():void
155 | {
156 | if(disposed) return;
157 |
158 | disposed = true;
159 |
160 | create = null;
161 | clean = null;
162 | list = null;
163 | }
164 | }
165 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/objectPools/PoolParticle.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.objectPools
15 | {
16 | import com.hsharma.hungryHero.gameElements.Particle;
17 |
18 | /**
19 | * This class handles the Object Pooling for the Particles.
20 | *
21 | * @author hsharma
22 | *
23 | */
24 | public class PoolParticle {
25 |
26 | /** Minimum size of the pool. */
27 | private var _minSize:int;
28 |
29 | /** Maximum size of the pool. */
30 | private var _maxSize:int;
31 |
32 | /** Current size of the pool (list). */
33 | public var size:int = 0;
34 |
35 | /** Function to be called when the object is to be created. */
36 | public var create:Function;
37 |
38 | /** Function to be called when the object is to be cleaned. */
39 | public var clean:Function;
40 |
41 | /** Checked in objects count. */
42 | public var length:int = 0;
43 |
44 | /** Objects in the pool. */
45 | private var list:Vector. = new Vector.();
46 |
47 | /** If this pool has been disposed. */
48 | private var disposed:Boolean = false;
49 |
50 | /**
51 | * @param create This is the Function which should return a new Object to populate the Object pool
52 | * @param clean This Function will recieve the Object as a param and is used for cleaning the Object ready for reuse
53 | * @param minSize The initial size of the pool on Pool construction
54 | * @param maxSize The maximum possible size for the Pool
55 | *
56 | */
57 |
58 | public function PoolParticle(create:Function, clean:Function = null, minSize:int = 50, maxSize:int = 200)
59 | {
60 | this.create = create;
61 | this.clean = clean;
62 | this.minSize = minSize;
63 | this.maxSize = maxSize;
64 |
65 | // Create minimum number of objects now. Later in run-time, if required, more objects will be created < maximum number.
66 | for(var i:int = 0;i < minSize; i++) add();
67 | }
68 |
69 | /**
70 | * Add new objects and check-in to the pool.
71 | *
72 | */
73 | private function add():void
74 | {
75 | list[length++] = create();
76 | size++;
77 | }
78 |
79 | /**
80 | * Sets the minimum size for the Pool.
81 | *
82 | */
83 | public function set minSize(num:int):void
84 | {
85 | _minSize = num;
86 | if(_minSize > _maxSize) _maxSize = _minSize;
87 | if(_maxSize < list.length) list.splice(_maxSize, 1);
88 | size = list.length;
89 | }
90 |
91 | /**
92 | * Gets the minimum size for the Pool.
93 | *
94 | */
95 | public function get minSize():int
96 | {
97 | return _minSize;
98 | }
99 |
100 | /**
101 | * Sets the maximum size for the Pool.
102 | *
103 | */
104 | public function set maxSize(num:int):void
105 | {
106 | _maxSize = num;
107 | if(_maxSize < list.length) list.splice(_maxSize, 1);
108 | size = list.length;
109 | if(_maxSize < _minSize) _minSize = _maxSize;
110 | }
111 |
112 | /**
113 | * Returns the maximum size for the Pool.
114 | *
115 | */
116 | public function get maxSize():int
117 | {
118 | return _maxSize;
119 | }
120 |
121 | /**
122 | * Checks out an Object from the pool.
123 | *
124 | */
125 | public function checkOut():Particle
126 | {
127 | if(length == 0) {
128 | if(size < maxSize) {
129 | size++;
130 | return create();
131 | } else {
132 | return null;
133 | }
134 | }
135 |
136 | return list[--length];
137 | }
138 |
139 | /**
140 | * Checks the Object back into the Pool.
141 | * @param item The Object you wish to check back into the Object Pool.
142 | *
143 | */
144 | public function checkIn(item:Particle):void
145 | {
146 | if(clean != null) clean(item);
147 | list[length++] = item;
148 | }
149 |
150 | /**
151 | * Disposes the Pool ready for GC.
152 | *
153 | */
154 | public function dispose():void
155 | {
156 | if(disposed) return;
157 |
158 | disposed = true;
159 |
160 | create = null;
161 | clean = null;
162 | list = null;
163 | }
164 | }
165 | }
166 |
167 |
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/screens/InGame.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.screens
15 | {
16 | import com.hsharma.hungryHero.events.NavigationEvent;
17 | import com.hsharma.hungryHero.gameElements.GameBackground;
18 | import com.hsharma.hungryHero.gameElements.Hero;
19 | import com.hsharma.hungryHero.gameElements.Item;
20 | import com.hsharma.hungryHero.gameElements.Obstacle;
21 | import com.hsharma.hungryHero.gameElements.Particle;
22 | import com.hsharma.hungryHero.objectPools.PoolItem;
23 | import com.hsharma.hungryHero.objectPools.PoolObstacle;
24 | import com.hsharma.hungryHero.objectPools.PoolParticle;
25 | import com.hsharma.hungryHero.ui.GameOverContainer;
26 | import com.hsharma.hungryHero.ui.HUD;
27 | import com.hsharma.hungryHero.ui.PauseButton;
28 |
29 | import flash.geom.Rectangle;
30 | import flash.media.SoundMixer;
31 | import flash.utils.getTimer;
32 |
33 | import starling.animation.Tween;
34 | import starling.core.Starling;
35 | import starling.display.Button;
36 | import starling.display.Sprite;
37 | import starling.events.Event;
38 | import starling.events.Touch;
39 | import starling.events.TouchEvent;
40 | import starling.extensions.PDParticleSystem;
41 | import starling.textures.Texture;
42 | import starling.utils.deg2rad;
43 | import starling.utils.rad2deg;
44 |
45 | /**
46 | * This class contains the complete code of the game mechanics.
47 | *
48 | * @author hsharma
49 | *
50 | */
51 | public class InGame extends Sprite
52 | {
53 | /** Game background object. */
54 | private var bg:GameBackground;
55 |
56 | /** Hero character. */
57 | private var hero:Hero;
58 |
59 | /** Time calculation for animation. */
60 | private var timePrevious:Number;
61 | private var timeCurrent:Number;
62 | private var elapsed:Number;
63 |
64 | // ------------------------------------------------------------------------------------------------------------
65 | // GAME INTERACTION
66 | // ------------------------------------------------------------------------------------------------------------
67 |
68 | /** Hero's current X position. */
69 | private var heroX:int;
70 |
71 | /** Hero's current Y position. */
72 | private var heroY:int;
73 |
74 | /** Game interaction area. */
75 | private var gameArea:Rectangle;
76 |
77 | /** Is game rendering through hardware or software? */
78 | private var isHardwareRendering:Boolean;
79 |
80 | /** Is game currently in paused state? */
81 | private var gamePaused:Boolean = false;
82 |
83 | /** Items pool with a maximum cap for reuse of items. */
84 | private var itemsPool:PoolItem;
85 |
86 | /** Obstacles pool with a maximum cap for reuse of items. */
87 | private var obstaclesPool:PoolObstacle;
88 |
89 | /** Eat Particles pool with a maximum cap for reuse of items. */
90 | private var eatParticlesPool:PoolParticle;
91 |
92 | /** Wind Particles pool with a maximum cap for reuse of items. */
93 | private var windParticlesPool:PoolParticle;
94 |
95 | /** Player state. */
96 | private var gameState:int;
97 |
98 | /** Player's fly speed. */
99 | private var playerSpeed:Number;
100 |
101 | /** Player's total height travelled. */
102 | private var scoreDistance:Number = 0;
103 |
104 | /** How much to shake the camera when the player hits the obstacle? */
105 | private var cameraShake:Number;
106 |
107 | /** Total items collected. */
108 | private var scoreItems:int = 0;
109 |
110 | /** Obstacle count - to track the frequency of obstacles. */
111 | private var obstacleGapCount:Number = 0;
112 |
113 | /** The power of obstacle after it is hit. */
114 | private var hitObstacle:Number = 0;
115 |
116 | /** Lives Count. */
117 | private var lives:int;
118 |
119 | /** How long have we had a coffee item. */
120 | private var coffee:Number = 0;
121 |
122 | /** How long have we had a mushroom item. */
123 | private var mushroom:Number = 0;
124 |
125 | /** Collision detection for hero vs items. */
126 | private var heroItem_xDist:Number;
127 | private var heroItem_yDist:Number;
128 | private var heroItem_sqDist:Number;
129 |
130 | /** Collision detection for hero vs obstacles. */
131 | private var heroObstacle_xDist:Number;
132 | private var heroObstacle_yDist:Number;
133 | private var heroObstacle_sqDist:Number;
134 |
135 | // ------------------------------------------------------------------------------------------------------------
136 | // ITEM GENERATION
137 | // ------------------------------------------------------------------------------------------------------------
138 |
139 | /** Current pattern of food items - 0 = horizontal, 1 = vertical, 2 = zigzag, 3 = random, 4 = special item. */
140 | private var pattern:int;
141 |
142 | /** Current y position of the item in the pattern. */
143 | private var patternPosY:int;
144 |
145 | /** How far away are the patterns created vertically. */
146 | private var patternStep:int;
147 |
148 | /** Direction of the pattern creation - used only for zigzag. */
149 | private var patternDirection:int;
150 |
151 | /** Gap between each item in the pattern horizontally. */
152 | private var patternGap:Number;
153 |
154 | /** Pattern gap counter. */
155 | private var patternGapCount:Number;
156 |
157 | /** How far should the player fly before the pattern changes. */
158 | private var patternChange:Number;
159 |
160 | /** How long are patterns created verticaly? */
161 | private var patternLength:Number;
162 |
163 | /** A trigger used if we want to run a one-time command in a pattern. */
164 | private var patternOnce:Boolean;
165 |
166 | /** Y position for the entire pattern - Used for vertical pattern only. */
167 | private var patternPosYstart:Number;
168 |
169 | // ------------------------------------------------------------------------------------------------------------
170 | // ANIMATION
171 | // ------------------------------------------------------------------------------------------------------------
172 |
173 | /** Items to animate. */
174 | private var itemsToAnimate:Vector.
- ;
175 |
176 | /** Total number of items. */
177 | private var itemsToAnimateLength:uint = 0;
178 |
179 | /** Obstacles to animate. */
180 | private var obstaclesToAnimate:Vector.;
181 |
182 | /** Obstacles to animate - array length. */
183 | private var obstaclesToAnimateLength:uint = 0;
184 |
185 | /** Wind particles to animate. */
186 | private var windParticlesToAnimate:Vector.;
187 |
188 | /** Wind particles to animate - array length. */
189 | private var windParticlesToAnimateLength:uint = 0;
190 |
191 | /** Eat particles to animate. */
192 | private var eatParticlesToAnimate:Vector.;
193 |
194 | /** Eat particles to animate - array length. */
195 | private var eatParticlesToAnimateLength:uint = 0;
196 |
197 | // ------------------------------------------------------------------------------------------------------------
198 | // TOUCH INTERACTION
199 | // ------------------------------------------------------------------------------------------------------------
200 |
201 | /** Touch X position of the mouse/finger. */
202 | private var touchX:Number;
203 |
204 | /** Touch Y position of the mouse/finger. */
205 | private var touchY:Number;
206 |
207 | /** To keep track of Touch interaction. */
208 | private var touch:Touch;
209 |
210 | // ------------------------------------------------------------------------------------------------------------
211 | // PARTICLES
212 | // ------------------------------------------------------------------------------------------------------------
213 |
214 | /** Particles for Coffee. */
215 | public static var particleCoffee:PDParticleSystem;
216 |
217 | /** Particles for Mushroom. */
218 | public static var particleMushroom:PDParticleSystem;
219 |
220 | // ------------------------------------------------------------------------------------------------------------
221 | // HUD
222 | // ------------------------------------------------------------------------------------------------------------
223 |
224 | /** HUD Container. */
225 | private var hud:HUD;
226 |
227 | // ------------------------------------------------------------------------------------------------------------
228 | // INTERFACE OBJECTS
229 | // ------------------------------------------------------------------------------------------------------------
230 |
231 | /** GameOver Container. */
232 | private var gameOverContainer:GameOverContainer;
233 |
234 | /** Pause button. */
235 | private var pauseButton:PauseButton;
236 |
237 | /** Kick Off button in the beginning of the game .*/
238 | private var startButton:Button;
239 |
240 | /** Tween object for game over container. */
241 | private var tween_gameOverContainer:Tween;
242 |
243 | // ------------------------------------------------------------------------------------------------------------
244 | // METHODS
245 | // ------------------------------------------------------------------------------------------------------------
246 |
247 | public function InGame()
248 | {
249 | super();
250 |
251 | // Is hardware rendering?
252 | isHardwareRendering = Starling.context.driverInfo.toLowerCase().indexOf("software") == -1;
253 |
254 | this.visible = false;
255 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
256 | }
257 |
258 | /**
259 | * On added to stage.
260 | * @param event
261 | *
262 | */
263 | private function onAddedToStage(event:Event):void
264 | {
265 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
266 |
267 | drawGame();
268 | drawHUD();
269 | drawGameOverScreen();
270 | }
271 |
272 | /**
273 | * Draw game elements - background, hero, particles, pause button, start button and items (in pool).
274 | *
275 | */
276 | private function drawGame():void
277 | {
278 | // Draw background.
279 | bg = new GameBackground();
280 | this.addChild(bg);
281 |
282 | // Is hardware rendering, draw particles.
283 | if (isHardwareRendering)
284 | {
285 | particleCoffee = new PDParticleSystem(XML(new ParticleAssets.ParticleCoffeeXML()), Texture.fromBitmap(new ParticleAssets.ParticleTexture()));
286 | Starling.juggler.add(particleCoffee);
287 |
288 | particleMushroom = new PDParticleSystem(XML(new ParticleAssets.ParticleMushroomXML()), Texture.fromBitmap(new ParticleAssets.ParticleTexture()));
289 | Starling.juggler.add(particleMushroom);
290 |
291 | this.addChild(particleCoffee);
292 | this.addChild(particleMushroom);
293 | }
294 |
295 | // Draw hero.
296 | hero = new Hero();
297 | this.addChild(hero);
298 |
299 | // Pause button.
300 | pauseButton = new PauseButton();
301 | pauseButton.x = pauseButton.width * 2;
302 | pauseButton.y = pauseButton.height * 0.5;
303 | pauseButton.addEventListener(Event.TRIGGERED, onPauseButtonClick);
304 | this.addChild(pauseButton);
305 |
306 | // Start button.
307 | startButton = new Button(Assets.getAtlas().getTexture("startButton"));
308 | startButton.fontColor = 0xffffff;
309 | startButton.x = stage.stageWidth/2 - startButton.width/2;
310 | startButton.y = stage.stageHeight/2 - startButton.height/2;
311 | startButton.addEventListener(Event.TRIGGERED, onStartButtonClick);
312 | this.addChild(startButton);
313 |
314 | // Initialize items-to-animate vector.
315 | itemsToAnimate = new Vector.
- ();
316 | itemsToAnimateLength = 0;
317 |
318 | // Create items, add them to pool and place them outside the stage area.
319 | createFoodItemsPool();
320 |
321 | // Initialize obstacles-to-animate vector.
322 | obstaclesToAnimate = new Vector.();
323 | obstaclesToAnimateLength = 0;
324 |
325 | // Create obstacles pool.
326 | createObstaclesPool();
327 |
328 | // Initialize particles-to-animate vectors.
329 | eatParticlesToAnimate = new Vector.();
330 | eatParticlesToAnimateLength = 0;
331 | windParticlesToAnimate = new Vector.();
332 | windParticlesToAnimateLength = 0;
333 |
334 | // Create Eat Particle and Wind Particle pools and place them outside the stage area.
335 | createEatParticlePool();
336 | createWindParticlePool();
337 |
338 | // Create items, add them to pool and place them outside the stage area.
339 | createFoodItemsPool();
340 | }
341 |
342 | /**
343 | * On click of pause button.
344 | * @param event
345 | *
346 | */
347 | private function onPauseButtonClick(event:Event):void
348 | {
349 | event.stopImmediatePropagation();
350 |
351 | // Pause or unpause the game.
352 | if (gamePaused) gamePaused = false;
353 | else gamePaused = true;
354 |
355 | // Pause the background animation too.
356 | bg.gamePaused = gamePaused;
357 | }
358 |
359 | /**
360 | * Draw Heads Up Display.
361 | *
362 | */
363 | private function drawHUD():void
364 | {
365 | hud = new HUD();
366 | this.addChild(hud);
367 | }
368 |
369 | /**
370 | * Draw game over screen.
371 | *
372 | */
373 | private function drawGameOverScreen():void
374 | {
375 | gameOverContainer = new GameOverContainer();
376 | gameOverContainer.addEventListener(NavigationEvent.CHANGE_SCREEN, playAgain);
377 | this.addChild(gameOverContainer);
378 | }
379 |
380 | /**
381 | * Play again, when clicked on play again button in Game Over screen.
382 | *
383 | */
384 | private function playAgain(event:NavigationEvent):void
385 | {
386 | if (event.params.id == "playAgain")
387 | {
388 | tween_gameOverContainer = new Tween(gameOverContainer, 1);
389 | tween_gameOverContainer.fadeTo(0);
390 | tween_gameOverContainer.onComplete = gameOverFadedOut;
391 | Starling.juggler.add(tween_gameOverContainer);
392 | }
393 | }
394 |
395 | /**
396 | * Create food items pool by passing the create and clean methods/functions to the Pool.
397 | *
398 | */
399 | private function createFoodItemsPool():void
400 | {
401 | itemsPool = new PoolItem(foodItemCreate, foodItemClean);
402 | }
403 |
404 | /**
405 | * Create food item objects and add to display list.
406 | * Also called from the Pool class while creating minimum number of objects & run-time objects < maximum number.
407 | * @return Food item that was created.
408 | *
409 | */
410 | private function foodItemCreate():Item
411 | {
412 | var foodItem:Item = new Item(Math.ceil(Math.random() * 5));
413 | foodItem.x = stage.stageWidth + foodItem.width * 2;
414 | this.addChild(foodItem);
415 |
416 | return foodItem;
417 | }
418 |
419 | /**
420 | * Clean the food items before reusing from the pool. Called from the pool.
421 | * @param item
422 | *
423 | */
424 | private function foodItemClean(item:Item):void
425 | {
426 | item.x = stage.stageWidth + 100;
427 | }
428 |
429 | /**
430 | * Create obstacles pool by passing the create and clean methods/functions to the Pool.
431 | *
432 | */
433 | private function createObstaclesPool():void
434 | {
435 | obstaclesPool = new PoolObstacle(obstacleCreate, obstacleClean, 4, 10);
436 | }
437 |
438 | /**
439 | * Create obstacle objects and add to display list.
440 | * Also called from the Pool class while creating minimum number of objects & run-time objects < maximum number.
441 | * @return Obstacle that was created.
442 | *
443 | */
444 | private function obstacleCreate():Obstacle
445 | {
446 | var obstacle:Obstacle = new Obstacle(Math.ceil(Math.random() * 4), Math.random() * 1000 + 1000);
447 | obstacle.x = stage.stageWidth + obstacle.width * 2;
448 | this.addChild(obstacle);
449 |
450 | return obstacle;
451 | }
452 |
453 | /**
454 | * Clean the obstacles before reusing from the pool. Called from the pool.
455 | * @param obstacle
456 | *
457 | */
458 | private function obstacleClean(obstacle:Obstacle):void
459 | {
460 | obstacle.x = stage.stageWidth + obstacle.width * 2;
461 | }
462 |
463 | /**
464 | * Create Eat Particle Pool.
465 | *
466 | */
467 | private function createEatParticlePool():void
468 | {
469 | eatParticlesPool = new PoolParticle(eatParticleCreate, eatParticleClean, 20, 30);
470 | }
471 |
472 | /**
473 | * Create eat particl objects and add to display list.
474 | * Also called from the Pool class while creating minimum number of objects & run-time objects < maximum number.
475 | * @return Eat particle that was created.
476 | *
477 | */
478 | private function eatParticleCreate():Particle
479 | {
480 | var eatParticle:Particle = new Particle(GameConstants.PARTICLE_TYPE_1);
481 | eatParticle.x = stage.stageWidth + eatParticle.width * 2;
482 | this.addChild(eatParticle);
483 |
484 | return eatParticle;
485 | }
486 |
487 | /**
488 | * Clean the eat particles before reusing from the pool. Called from the pool.
489 | * @param eatParticle
490 | *
491 | */
492 | private function eatParticleClean(eatParticle:Particle):void
493 | {
494 | eatParticle.x = stage.stageWidth + eatParticle.width * 2;
495 | }
496 |
497 | /**
498 | * Create Wind Particle Pool.
499 | *
500 | */
501 | private function createWindParticlePool():void
502 | {
503 | windParticlesPool = new PoolParticle(windParticleCreate, windParticleClean, 10, 30);
504 | }
505 |
506 | /**
507 | * Create eat particl objects and add to display list.
508 | * Also called from the Pool class while creating minimum number of objects & run-time objects < maximum number.
509 | * @return Eat particle that was created.
510 | *
511 | */
512 | private function windParticleCreate():Particle
513 | {
514 | var windParticle:Particle = new Particle(GameConstants.PARTICLE_TYPE_2);
515 | windParticle.x = stage.stageWidth + windParticle.width * 2;
516 | this.addChild(windParticle);
517 |
518 | return windParticle;
519 | }
520 |
521 | /**
522 | * Clean the eat particles before reusing from the pool. Called from the pool.
523 | * @param windParticle
524 | *
525 | */
526 | private function windParticleClean(windParticle:Particle):void
527 | {
528 | windParticle.x = stage.stageWidth + windParticle.width * 2;
529 | }
530 |
531 | /**
532 | * Initialize the game.
533 | *
534 | */
535 | public function initialize():void
536 | {
537 | // Dispose screen temporarily.
538 | disposeTemporarily();
539 |
540 | this.visible = true;
541 |
542 | // Calculate elapsed time.
543 | this.addEventListener(Event.ENTER_FRAME, calculateElapsed);
544 |
545 | // Play screen background music.
546 | if (!Sounds.muted) Sounds.sndBgGame.play(0, 999);
547 |
548 | // Define game area.
549 | gameArea = new Rectangle(0, 100, stage.stageWidth, stage.stageHeight - 250);
550 |
551 | // Define lives.
552 | lives = GameConstants.HERO_LIVES;
553 |
554 | // Reset hit, camera shake and player speed.
555 | hitObstacle = 0;
556 | cameraShake = 0;
557 | playerSpeed = 0;
558 |
559 | // Reset score and distance travelled.
560 | scoreItems = 0;
561 | scoreDistance = 0;
562 |
563 | // Reset item pattern styling.
564 | pattern = 1;
565 | patternPosY = gameArea.top;
566 | patternStep = 15;
567 | patternDirection = 1;
568 | patternGap = 20;
569 | patternGapCount = 0;
570 | patternChange = 100;
571 | patternLength = 50;
572 | patternOnce = true;
573 |
574 | // Reset coffee and mushroom power.
575 | coffee = 0;
576 | mushroom = 0;
577 |
578 | // Reset game state to idle.
579 | gameState = GameConstants.GAME_STATE_IDLE;
580 |
581 | // Hero's initial position
582 | hero.x = -stage.stageWidth;
583 | hero.y = stage.stageHeight/2;
584 |
585 | // Reset hero's state to idle.
586 | hero.state = GameConstants.HERO_STATE_IDLE;
587 |
588 | // Reset touch interaction values to hero's position.
589 | touchX = hero.x;
590 | touchY = hero.y;
591 |
592 | // Reset hud values and text fields.
593 | hud.foodScore = 0;
594 | hud.distance = 0;
595 | hud.lives = lives;
596 |
597 | // Reset background's state to idle.
598 | bg.state = GameConstants.GAME_STATE_IDLE;
599 |
600 | // Reset game paused states.
601 | gamePaused = false;
602 | bg.gamePaused = false;
603 |
604 | // Reset background's state to idle.
605 | bg.state = GameConstants.GAME_STATE_IDLE;
606 |
607 | // Reset background speed.
608 | bg.speed = 0;
609 |
610 | // Hide the pause button since the game isn't started yet.
611 | pauseButton.visible = false;
612 |
613 | // Show start button.
614 | startButton.visible = true;
615 | }
616 |
617 | /**
618 | * Dispose screen temporarily.
619 | *
620 | */
621 | private function disposeTemporarily():void
622 | {
623 | SoundMixer.stopAll();
624 |
625 | gameOverContainer.visible = false;
626 |
627 | if (this.hasEventListener(Event.ENTER_FRAME)) this.removeEventListener(Event.ENTER_FRAME, calculateElapsed);
628 |
629 | if (this.hasEventListener(TouchEvent.TOUCH)) this.removeEventListener(TouchEvent.TOUCH, onTouch);
630 |
631 | if (this.hasEventListener(Event.ENTER_FRAME)) this.removeEventListener(Event.ENTER_FRAME, onGameTick);
632 | }
633 |
634 | /**
635 | * On start button click.
636 | * @param event
637 | *
638 | */
639 | private function onStartButtonClick(event:Event):void
640 | {
641 | // Play coffee sound for button click.
642 | if (!Sounds.muted) Sounds.sndCoffee.play();
643 |
644 | // Hide start button.
645 | startButton.visible = false;
646 |
647 | // Show pause button since the game is started.
648 | pauseButton.visible = true;
649 |
650 | // Launch hero.
651 | launchHero();
652 | }
653 |
654 | /**
655 | * Launch hero.
656 | *
657 | */
658 | private function launchHero():void
659 | {
660 | playerSpeed = 0;
661 |
662 | // Touch interaction
663 | this.addEventListener(TouchEvent.TOUCH, onTouch);
664 |
665 | // Game tick
666 | this.addEventListener(Event.ENTER_FRAME, onGameTick);
667 | }
668 |
669 | /**
670 | * On interaction with game - mouse move (web) or touch drag (devices).
671 | * @param event
672 | *
673 | */
674 | private function onTouch(event:TouchEvent):void
675 | {
676 | touch = event.getTouch(stage);
677 |
678 | touchX = touch.globalX;
679 | touchY = touch.globalY;
680 | }
681 |
682 | /**
683 | * Game Tick - every frame of the game.
684 | * @param event
685 | *
686 | */
687 | private function onGameTick(event:Event):void
688 | {
689 | // If not paused, tick the game.
690 | if (!gamePaused)
691 | {
692 | // If no touch co-ordinates, reset touchX and touchY (for touch screen devices).
693 | if (isNaN(touchX))
694 | {
695 | touchX = stage.stageWidth * 0.5;
696 | touchY = stage.stageHeight * 0.5;
697 | }
698 |
699 | // If hardware rendering, set the particle emitter's x and y.
700 | if (isHardwareRendering)
701 | {
702 | particleCoffee.emitterX = hero.x + hero.width * 0.5 * 0.5;
703 | particleCoffee.emitterY = hero.y;
704 |
705 | particleMushroom.emitterX = hero.x + hero.width * 0.5 * 0.5;
706 | particleMushroom.emitterY = hero.y;
707 | }
708 |
709 | switch(gameState)
710 | {
711 | // Before game starts.
712 | case GameConstants.GAME_STATE_IDLE:
713 | // Take off.
714 | if (hero.x < stage.stageWidth * 0.5 * 0.5)
715 | {
716 | hero.x += ((stage.stageWidth * 0.5 * 0.5 + 10) - hero.x) * 0.05;
717 | hero.y -= (hero.y - touchY) * 0.1;
718 |
719 | playerSpeed += (GameConstants.HERO_MIN_SPEED - playerSpeed) * 0.05;
720 | bg.speed = playerSpeed * elapsed;
721 | }
722 | else
723 | {
724 | gameState = GameConstants.GAME_STATE_FLYING;
725 | hero.state = GameConstants.HERO_STATE_FLYING;
726 | }
727 |
728 | // Rotate hero based on mouse position.
729 | if ((-(hero.y - touchY) * 0.2) < 30 && (-(hero.y - touchY) * 0.2) > -30) hero.rotation = deg2rad(-(hero.y - touchY) * 0.2);
730 |
731 | // Limit the hero's rotation to < 30.
732 | if (rad2deg(hero.rotation) > 30 ) hero.rotation = rad2deg(30);
733 | if (rad2deg(hero.rotation) < -30 ) hero.rotation = -rad2deg(30);
734 |
735 | // Confine the hero to stage area limit
736 | if (hero.y > gameArea.bottom - hero.height * 0.5)
737 | {
738 | hero.y = gameArea.bottom - hero.height * 0.5;
739 | hero.rotation = deg2rad(0);
740 | }
741 | if (hero.y < gameArea.top + hero.height * 0.5)
742 | {
743 | hero.y = gameArea.top + hero.height * 0.5;
744 | hero.rotation = deg2rad(0);
745 | }
746 | break;
747 |
748 | // When game is in progress.
749 | case GameConstants.GAME_STATE_FLYING:
750 |
751 | // If drank coffee, fly faster for a while.
752 | if (coffee > 0)
753 | {
754 | playerSpeed += (GameConstants.HERO_MAX_SPEED - playerSpeed) * 0.2;
755 | }
756 |
757 | // If not hit by obstacle, fly normally.
758 | if (hitObstacle <= 0)
759 | {
760 | hero.y -= (hero.y - touchY) * 0.1;
761 |
762 | // If hero is flying extremely fast, create a wind effect and show force field around hero.
763 | if (playerSpeed > GameConstants.HERO_MIN_SPEED + 100)
764 | {
765 | createWindForce();
766 | // Animate hero faster.
767 | hero.setHeroAnimationSpeed(1);
768 | }
769 | else
770 | {
771 | // Animate hero normally.
772 | hero.setHeroAnimationSpeed(0);
773 | }
774 |
775 | // Rotate hero based on mouse position.
776 | if ((-(hero.y - touchY) * 0.2) < 30 && (-(hero.y - touchY) * 0.2) > -30) hero.rotation = deg2rad(-(hero.y - touchY) * 0.2);
777 |
778 | // Limit the hero's rotation to < 30.
779 | if (rad2deg(hero.rotation) > 30 ) hero.rotation = rad2deg(30);
780 | if (rad2deg(hero.rotation) < -30 ) hero.rotation = -rad2deg(30);
781 |
782 | // Confine the hero to stage area limit
783 | if (hero.y > gameArea.bottom - hero.height * 0.5)
784 | {
785 | hero.y = gameArea.bottom - hero.height * 0.5;
786 | hero.rotation = deg2rad(0);
787 | }
788 | if (hero.y < gameArea.top + hero.height * 0.5)
789 | {
790 | hero.y = gameArea.top + hero.height * 0.5;
791 | hero.rotation = deg2rad(0);
792 | }
793 | }
794 | else
795 | {
796 | // Hit by obstacle
797 |
798 | if (coffee <= 0)
799 | {
800 | // Play hero animation for obstacle hit.
801 | if (hero.state != GameConstants.HERO_STATE_HIT)
802 | {
803 | hero.state = GameConstants.HERO_STATE_HIT;
804 | }
805 |
806 | // Move hero to center of the screen.
807 | hero.y -= (hero.y - (gameArea.top + gameArea.height)/2) * 0.1;
808 |
809 | // Spin the hero.
810 | if (hero.y > stage.stageHeight * 0.5) hero.rotation -= deg2rad(hitObstacle * 2);
811 | else hero.rotation += deg2rad(hitObstacle * 2);
812 | }
813 |
814 | // If hit by an obstacle.
815 | hitObstacle--;
816 |
817 | // Camera shake.
818 | cameraShake = hitObstacle;
819 | shakeAnimation(null);
820 | }
821 |
822 | // If we have a mushroom, reduce the value of the power.
823 | if (mushroom > 0) mushroom -= elapsed;
824 |
825 | // If we have a coffee, reduce the value of the power.
826 | if (coffee > 0) coffee -= elapsed;
827 |
828 | playerSpeed -= (playerSpeed - GameConstants.HERO_MIN_SPEED) * 0.01;
829 |
830 | // Create food items.
831 | setFoodItemsPattern();
832 | createFoodItemsPattern();
833 |
834 | // Create obstacles.
835 | initObstacle();
836 |
837 | // Store the hero's current x and y positions (needed for animations below).
838 | heroX = hero.x;
839 | heroY = hero.y;
840 |
841 | // Animate elements.
842 | animateFoodItems();
843 | animateObstacles();
844 | animateEatParticles();
845 | animateWindParticles();
846 |
847 | // Set the background's speed based on hero's speed.
848 | bg.speed = playerSpeed * elapsed;
849 |
850 | // Calculate maximum distance travelled.
851 | scoreDistance += (playerSpeed * elapsed) * 0.1;
852 | hud.distance = Math.round(scoreDistance);
853 |
854 | break;
855 |
856 | // Game over.
857 | case GameConstants.GAME_STATE_OVER:
858 |
859 | for(var i:uint = 0; i < itemsToAnimateLength; i++)
860 | {
861 | if (itemsToAnimate[i] != null)
862 | {
863 | // Dispose the item temporarily.
864 | disposeItemTemporarily(i, itemsToAnimate[i]);
865 | }
866 | }
867 |
868 | for(var j:uint = 0; j < obstaclesToAnimateLength; j++)
869 | {
870 | if (obstaclesToAnimate[j] != null)
871 | {
872 | // Dispose the obstacle temporarily.
873 | disposeObstacleTemporarily(j, obstaclesToAnimate[j]);
874 | }
875 | }
876 |
877 | for(var m:uint = 0; m < eatParticlesToAnimateLength; m++)
878 | {
879 | if (eatParticlesToAnimate[m] != null)
880 | {
881 | // Dispose the eat particle temporarily.
882 | disposeEatParticleTemporarily(m, eatParticlesToAnimate[m]);
883 | }
884 | }
885 |
886 | for(var n:uint = 0; n < windParticlesToAnimateLength; n++)
887 | {
888 | if (windParticlesToAnimate[n] != null)
889 | {
890 | // Dispose the wind particle temporarily.
891 | disposeWindParticleTemporarily(n, windParticlesToAnimate[n]);
892 | }
893 | }
894 |
895 | // Spin the hero.
896 | hero.rotation -= deg2rad(30);
897 |
898 | // Make the hero fall.
899 |
900 | // If hero is still on screen, push him down and outside the screen. Also decrease his speed.
901 | // Checked for +width below because width is > height. Just a safe value.
902 | if (hero.y < stage.stageHeight + hero.width)
903 | {
904 | playerSpeed -= playerSpeed * elapsed;
905 | hero.y += stage.stageHeight * elapsed;
906 | }
907 | else
908 | {
909 | // Once he moves out, reset speed to 0.
910 | playerSpeed = 0;
911 |
912 | // Stop game tick.
913 | this.removeEventListener(Event.ENTER_FRAME, onGameTick);
914 |
915 | // Game over.
916 | gameOver();
917 | }
918 |
919 | // Set the background's speed based on hero's speed.
920 | bg.speed = Math.floor(playerSpeed * elapsed);
921 |
922 | break;
923 | }
924 | }
925 | }
926 |
927 | /**
928 | * Create wind force particle.
929 | *
930 | */
931 | private function createWindForce():void
932 | {
933 | // Create a wind particle.
934 | var windToTrack:Particle = windParticlesPool.checkOut();
935 |
936 | // Place the object randomly along hte screen.
937 | windToTrack.x = stage.stageWidth;
938 | windToTrack.y = Math.random() * stage.stageHeight;
939 |
940 | // Set the scale of the wind object randomly.
941 | windToTrack.scaleX = windToTrack.scaleY = Math.random() * 0.5 + 0.5;
942 |
943 | // Animate the wind particle.
944 | windParticlesToAnimate[windParticlesToAnimateLength++] = windToTrack;
945 | }
946 |
947 | /**
948 | * Set food items pattern.
949 | *
950 | */
951 | private function setFoodItemsPattern():void
952 | {
953 | // If hero has not travelled the required distance, don't change the pattern.
954 | if (patternChange > 0)
955 | {
956 | patternChange -= playerSpeed * elapsed;
957 | }
958 | else
959 | {
960 | // If hero has travelled the required distance, change the pattern.
961 | if ( Math.random() < 0.7 )
962 | {
963 | // If random number is < normal item chance (0.7), decide on a random pattern for items.
964 | pattern = Math.ceil(Math.random() * 4);
965 | }
966 | else
967 | {
968 | // If random number is > normal item chance (0.3), decide on a random special item.
969 | pattern = Math.ceil(Math.random() * 2) + 9;
970 | }
971 |
972 | if (pattern == 1)
973 | {
974 | // Vertical Pattern
975 | patternStep = 15;
976 | patternChange = Math.random() * 500 + 500;
977 | }
978 | else if (pattern == 2)
979 | {
980 | // Horizontal Pattern
981 | patternOnce = true;
982 | patternStep = 40;
983 | patternChange = patternGap * Math.random() * 3 + 5;
984 | }
985 | else if (pattern == 3)
986 | {
987 | // ZigZag Pattern
988 | patternStep = Math.round(Math.random() * 2 + 2) * 10;
989 | if ( Math.random() > 0.5 )
990 | {
991 | patternDirection *= -1;
992 | }
993 | patternChange = Math.random() * 800 + 800;
994 | }
995 | else if (pattern == 4)
996 | {
997 | // Random Pattern
998 | patternStep = Math.round(Math.random() * 3 + 2) * 50;
999 | patternChange = Math.random() * 400 + 400;
1000 | }
1001 | else
1002 | {
1003 | patternChange = 0;
1004 | }
1005 | }
1006 | }
1007 |
1008 | /**
1009 | * Create food pattern after hero travels for some distance.
1010 | *
1011 | */
1012 | private function createFoodItemsPattern():void
1013 | {
1014 | // Create a food item after we pass some distance (patternGap).
1015 | if (patternGapCount < patternGap )
1016 | {
1017 | patternGapCount += playerSpeed * elapsed;
1018 | }
1019 | else if (pattern != 0)
1020 | {
1021 | // If there is a pattern already set.
1022 | patternGapCount = 0;
1023 |
1024 | // Reuse and configure food item.
1025 | reuseAndConfigureFoodItem();
1026 | }
1027 | }
1028 |
1029 | /**
1030 | * Create a food item - called by createPattern()
1031 | *
1032 | */
1033 | private function reuseAndConfigureFoodItem():void
1034 | {
1035 | var itemToTrack:Item;
1036 |
1037 | switch (pattern)
1038 | {
1039 | case 1:
1040 | // Horizonatl, creates a single food item, and changes the position of the pattern randomly.
1041 | if (Math.random() > 0.9)
1042 | {
1043 | // Set a new random position for the item, making sure it's not too close to the edges of the screen.
1044 | patternPosY = Math.floor(Math.random() * (gameArea.bottom - gameArea.top + 1)) + gameArea.top;
1045 | }
1046 |
1047 | // Checkout item from pool and set the type of item.
1048 | itemToTrack = itemsPool.checkOut();
1049 | itemToTrack.foodItemType = Math.ceil(Math.random() * 5);
1050 |
1051 | // Reset position of item.
1052 | itemToTrack.x = stage.stageWidth + itemToTrack.width;
1053 | itemToTrack.y = patternPosY;
1054 |
1055 | // Mark the item for animation.
1056 | itemsToAnimate[itemsToAnimateLength++] = itemToTrack;
1057 | break;
1058 |
1059 | case 2:
1060 | // Vertical, creates a line of food items that could be the height of the entire screen or just a small part of it.
1061 | if (patternOnce == true)
1062 | {
1063 | patternOnce = false;
1064 |
1065 | // Set a random position not further than half the screen.
1066 | patternPosY = Math.floor(Math.random() * (gameArea.bottom - gameArea.top + 1)) + gameArea.top;
1067 |
1068 | // Set a random length not shorter than 0.4 of the screen, and not longer than 0.8 of the screen.
1069 | patternLength = (Math.random() * 0.4 + 0.4) * stage.stageHeight;
1070 | }
1071 |
1072 | // Set the start position of the food items pattern.
1073 | patternPosYstart = patternPosY;
1074 |
1075 | // Create a line based on the height of patternLength, but not exceeding the height of the screen.
1076 | while (patternPosYstart + patternStep < patternPosY + patternLength && patternPosYstart + patternStep < stage.stageHeight * 0.8)
1077 | {
1078 | // Checkout item from pool and set the type of item.
1079 | itemToTrack = itemsPool.checkOut();
1080 | itemToTrack.foodItemType = Math.ceil(Math.random() * 5);
1081 |
1082 | // Reset position of item.
1083 | itemToTrack.x = stage.stageWidth + itemToTrack.width;
1084 | itemToTrack.y = patternPosYstart;
1085 |
1086 | // Mark the item for animation.
1087 | itemsToAnimate[itemsToAnimateLength++] = itemToTrack;
1088 |
1089 | // Increase the position of the next item based on patternStep.
1090 | patternPosYstart += patternStep;
1091 | }
1092 | break;
1093 |
1094 | case 3:
1095 | // ZigZag, creates a single item at a position, and then moves bottom
1096 | // until it hits the edge of the screen, then changes its direction and creates items
1097 | // until it hits the upper edge.
1098 |
1099 | // Switch the direction of the food items pattern if we hit the edge.
1100 | if (patternDirection == 1 && patternPosY > gameArea.bottom - 50)
1101 | {
1102 | patternDirection = -1;
1103 | }
1104 | else if ( patternDirection == -1 && patternPosY < gameArea.top )
1105 | {
1106 | patternDirection = 1;
1107 | }
1108 |
1109 | if (patternPosY >= gameArea.top && patternPosY <= gameArea.bottom)
1110 | {
1111 | // Checkout item from pool and set the type of item.
1112 | itemToTrack = itemsPool.checkOut();
1113 | itemToTrack.foodItemType = Math.ceil(Math.random() * 5);
1114 |
1115 | // Reset position of item.
1116 | itemToTrack.x = stage.stageWidth + itemToTrack.width;
1117 | itemToTrack.y = patternPosY;
1118 |
1119 | // Mark the item for animation.
1120 | itemsToAnimate[itemsToAnimateLength++] = itemToTrack;
1121 |
1122 | // Increase the position of the next item based on patternStep and patternDirection.
1123 | patternPosY += patternStep * patternDirection;
1124 | }
1125 | else
1126 | {
1127 | patternPosY = gameArea.top;
1128 | }
1129 |
1130 | break;
1131 |
1132 | case 4:
1133 | // Random, creates a random number of items along the screen.
1134 | if (Math.random() > 0.3)
1135 | {
1136 | // Choose a random starting position along the screen.
1137 | patternPosY = Math.floor(Math.random() * (gameArea.bottom - gameArea.top + 1)) + gameArea.top;
1138 |
1139 | // Place some items on the screen, but don't go past the screen edge
1140 | while (patternPosY + patternStep < gameArea.bottom)
1141 | {
1142 | // Checkout item from pool and set the type of item.
1143 | itemToTrack = itemsPool.checkOut();
1144 | itemToTrack.foodItemType = Math.ceil(Math.random() * 5);
1145 |
1146 | // Reset position of item.
1147 | itemToTrack.x = stage.stageWidth + itemToTrack.width;
1148 | itemToTrack.y = patternPosY;
1149 |
1150 | // Mark the item for animation.
1151 | itemsToAnimate[itemsToAnimateLength++] = itemToTrack;
1152 |
1153 | // Increase the position of the next item by a random value.
1154 | patternPosY += Math.round(Math.random() * 100 + 100);
1155 | }
1156 | }
1157 | break;
1158 |
1159 | case 10:
1160 | // Coffee, this item gives you extra speed for a while, and lets you break through obstacles.
1161 |
1162 | // Set a new random position for the item, making sure it's not too close to the edges of the screen.
1163 | patternPosY = Math.floor(Math.random() * (gameArea.bottom - gameArea.top + 1)) + gameArea.top;
1164 |
1165 | // Checkout item from pool and set the type of item.
1166 | itemToTrack = itemsPool.checkOut();
1167 | itemToTrack.foodItemType = Math.ceil(Math.random() * 2) + 5;
1168 |
1169 | // Reset position of item.
1170 | itemToTrack.x = stage.stageWidth + itemToTrack.width;
1171 | itemToTrack.y = patternPosY;
1172 |
1173 | // Mark the item for animation.
1174 | itemsToAnimate[itemsToAnimateLength++] = itemToTrack;
1175 | break;
1176 |
1177 | case 11:
1178 | // Mushroom, this item makes all the food items fly towards the hero for a while.
1179 |
1180 | // Set a new random position for the food item, making sure it's not too close to the edges of the screen.
1181 | patternPosY = Math.floor(Math.random() * (gameArea.bottom - gameArea.top + 1)) + gameArea.top;
1182 |
1183 | // Checkout item from pool and set the type of item.
1184 | itemToTrack = itemsPool.checkOut();
1185 | itemToTrack.foodItemType = Math.ceil(Math.random() * 2) + 5;
1186 |
1187 | // Reset position of item.
1188 | itemToTrack.x = stage.stageWidth + itemToTrack.width;
1189 | itemToTrack.y = patternPosY;
1190 |
1191 | // Mark the item for animation.
1192 | itemsToAnimate[itemsToAnimateLength++] = itemToTrack;
1193 |
1194 | break;
1195 | }
1196 | }
1197 |
1198 | /**
1199 | * Move all the food items that are in itemsToAnimate vector.
1200 | *
1201 | */
1202 | private function animateFoodItems():void
1203 | {
1204 | var itemToTrack:Item;
1205 |
1206 | for(var i:uint = 0;i 0 && itemToTrack.foodItemType <= GameConstants.ITEM_TYPE_5)
1214 | {
1215 | // Move the item towards the player.
1216 | itemToTrack.x -= (itemToTrack.x - heroX) * 0.2;
1217 | itemToTrack.y -= (itemToTrack.y - heroY) * 0.2;
1218 | }
1219 | else
1220 | {
1221 | // If hero hasn't eaten a mushroom,
1222 | // Move the items normally towards the left.
1223 | itemToTrack.x -= playerSpeed * elapsed;
1224 | }
1225 |
1226 | // If the item passes outside the screen on the left, remove it (check-in).
1227 |
1228 | if (itemToTrack.x < -80 || gameState == GameConstants.GAME_STATE_OVER)
1229 | {
1230 | disposeItemTemporarily(i, itemToTrack);
1231 | }
1232 | else
1233 | {
1234 | // Collision detection - Check if the hero eats a food item.
1235 | heroItem_xDist = itemToTrack.x - heroX;
1236 | heroItem_yDist = itemToTrack.y - heroY;
1237 | heroItem_sqDist = heroItem_xDist * heroItem_xDist + heroItem_yDist * heroItem_yDist;
1238 |
1239 | if (heroItem_sqDist < 5000)
1240 | {
1241 | // If hero eats an item, add up the score.
1242 | if (itemToTrack.foodItemType <= GameConstants.ITEM_TYPE_5)
1243 | {
1244 | scoreItems += itemToTrack.foodItemType;
1245 | hud.foodScore = scoreItems;
1246 | if (!Sounds.muted) Sounds.sndEat.play();
1247 | }
1248 | else if (itemToTrack.foodItemType == GameConstants.ITEM_TYPE_COFFEE)
1249 | {
1250 | // If hero drinks coffee, add up the score.
1251 | scoreItems += 1;
1252 |
1253 | // How long does coffee power last? (in seconds)
1254 | coffee = 5;
1255 | if (isHardwareRendering) particleCoffee.start(coffee);
1256 |
1257 | if (!Sounds.muted) Sounds.sndCoffee.play();
1258 | }
1259 | else if (itemToTrack.foodItemType == GameConstants.ITEM_TYPE_MUSHROOM)
1260 | {
1261 | // If hero eats a mushroom, add up the score.
1262 | scoreItems += 1;
1263 |
1264 | // How long does mushroom power last? (in seconds)
1265 | mushroom = 4;
1266 | if (isHardwareRendering) particleMushroom.start(mushroom);
1267 |
1268 | if (!Sounds.muted) Sounds.sndMushroom.play();
1269 | }
1270 |
1271 | // Create an eat particle at the position of the food item that was eaten.
1272 | createEatParticle(itemToTrack);
1273 |
1274 | // Dispose the food item.
1275 | disposeItemTemporarily(i, itemToTrack);
1276 | }
1277 | }
1278 | }
1279 | }
1280 | }
1281 |
1282 | /**
1283 | * Dispose the item temporarily. Check-in the item into pool (will get cleaned) and reduce the "number of items" by 1.
1284 | * @param animateId
1285 | * @param item
1286 | *
1287 | */
1288 | private function disposeItemTemporarily(animateId:uint, item:Item):void
1289 | {
1290 | itemsToAnimate.splice(animateId, 1);
1291 | itemsToAnimateLength--;
1292 |
1293 | item.x = stage.stageWidth + item.width * 2;
1294 |
1295 | itemsPool.checkIn(item);
1296 | }
1297 |
1298 | /**
1299 | * Dispose the obstacle temporarily. Check-in into pool (will get cleaned) and reduce the vector length by 1.
1300 | * @param animateId
1301 | * @param obstacle
1302 | *
1303 | */
1304 | private function disposeObstacleTemporarily(animateId:uint, obstacle:Obstacle):void
1305 | {
1306 | obstaclesToAnimate.splice(animateId, 1);
1307 | obstaclesToAnimateLength--;
1308 | obstaclesPool.checkIn(obstacle);
1309 | }
1310 |
1311 | /**
1312 | * Dispose the eat particle temporarily. Check-in into pool (will get cleaned) and reduce the vector length by 1.
1313 | * @param animateId
1314 | * @param particle
1315 | *
1316 | */
1317 | private function disposeEatParticleTemporarily(animateId:uint, particle:Particle):void
1318 | {
1319 | eatParticlesToAnimate.splice(animateId, 1);
1320 | eatParticlesToAnimateLength--;
1321 | eatParticlesPool.checkIn(particle);
1322 | }
1323 |
1324 | /**
1325 | * Dispose the wind particle temporarily. Check-in into pool (will get cleaned) and reduce the vector length by 1.
1326 | * @param animateId
1327 | * @param particle
1328 | *
1329 | */
1330 | private function disposeWindParticleTemporarily(animateId:uint, particle:Particle):void
1331 | {
1332 | windParticlesToAnimate.splice(animateId, 1);
1333 | windParticlesToAnimateLength--;
1334 | windParticlesPool.checkIn(particle);
1335 | }
1336 |
1337 | /**
1338 | * Create an obstacle after hero has travelled a certain distance.
1339 | *
1340 | */
1341 | private function initObstacle():void
1342 | {
1343 | // Create an obstacle after hero travels some distance (obstacleGap).
1344 | if (obstacleGapCount < GameConstants.OBSTACLE_GAP)
1345 | {
1346 | obstacleGapCount += playerSpeed * elapsed;
1347 | }
1348 | else if (obstacleGapCount != 0)
1349 | {
1350 | obstacleGapCount = 0;
1351 |
1352 | // Create any one of the obstacles.
1353 | createObstacle(Math.ceil(Math.random() * 4), Math.random() * 1000 + 1000);
1354 | }
1355 | }
1356 |
1357 | /**
1358 | * Create the obstacle object based on the type indicated and make it appear based on the distance passed.
1359 | * @param _type
1360 | * @param _distance
1361 | *
1362 | */
1363 | private function createObstacle(_type:int = 1, _distance:Number = 0):void
1364 | {
1365 | // Create a new obstacle.
1366 | var obstacle:Obstacle = obstaclesPool.checkOut();
1367 | obstacle.type = _type;
1368 | obstacle.distance = _distance;
1369 | obstacle.x = stage.stageWidth;
1370 |
1371 | // For only one of the obstacles, make it appear in either the top or bottom of the screen.
1372 | if (_type <= GameConstants.OBSTACLE_TYPE_3)
1373 | {
1374 | // Place it on the top of the screen.
1375 | if (Math.random() > 0.5)
1376 | {
1377 | obstacle.y = gameArea.top;
1378 | obstacle.position = "top";
1379 | }
1380 | else
1381 | {
1382 | // Or place it in the bottom of the screen.
1383 | obstacle.y = gameArea.bottom - obstacle.height;
1384 | obstacle.position = "bottom";
1385 | }
1386 | }
1387 | else
1388 | {
1389 | // Otherwise, if it's any other obstacle type, put it somewhere in the middle of the screen.
1390 | obstacle.y = Math.floor(Math.random() * (gameArea.bottom-obstacle.height - gameArea.top + 1)) + gameArea.top;
1391 | obstacle.position = "middle";
1392 | }
1393 |
1394 | // Set the obstacle's speed.
1395 | obstacle.speed = GameConstants.OBSTACLE_SPEED;
1396 |
1397 | // Set look out mode to true, during which, a look out text appears.
1398 | obstacle.lookOut = true;
1399 |
1400 | // Animate the obstacle.
1401 | obstaclesToAnimate[obstaclesToAnimateLength++] = obstacle;
1402 | }
1403 |
1404 | /**
1405 | * Animate obstacles marked for animation.
1406 | *
1407 | */
1408 | private function animateObstacles():void
1409 | {
1410 | if (!gamePaused)
1411 | {
1412 | var obstacleToTrack:Obstacle;
1413 | var heroRect:Rectangle;
1414 | var obstacleRect:Rectangle;
1415 |
1416 | for (var i:uint = 0; i < obstaclesToAnimateLength ; i ++)
1417 | {
1418 | obstacleToTrack = obstaclesToAnimate[i];
1419 |
1420 | // If the distance is still more than 0, keep reducing its value, without moving the obstacle.
1421 | if (obstacleToTrack.distance > 0 )
1422 | {
1423 | obstacleToTrack.distance -= playerSpeed * elapsed;
1424 | }
1425 | else
1426 | {
1427 | // Otherwise, move the obstacle based on hero's speed, and check if he hits it.
1428 |
1429 | // Remove the look out sign.
1430 | if (obstacleToTrack.lookOut == true )
1431 | {
1432 | obstacleToTrack.lookOut = false;
1433 | }
1434 |
1435 | // Move the obstacle based on hero's speed.
1436 | obstacleToTrack.x -= (playerSpeed + obstacleToTrack.speed) * elapsed;
1437 | }
1438 |
1439 | // If the obstacle passes beyond the screen, remove it.
1440 | if (obstacleToTrack.x < -obstacleToTrack.width || gameState == GameConstants.GAME_STATE_OVER)
1441 | {
1442 | disposeObstacleTemporarily(i, obstacleToTrack);
1443 | }
1444 |
1445 | // Collision detection - Check if hero collides with any obstacle.
1446 | heroObstacle_xDist = obstacleToTrack.x - heroX;
1447 | heroObstacle_yDist = obstacleToTrack.y - heroY;
1448 | heroObstacle_sqDist = heroObstacle_xDist * heroObstacle_xDist + heroObstacle_yDist * heroObstacle_yDist;
1449 |
1450 | if (heroObstacle_sqDist < 5000 && !obstacleToTrack.alreadyHit)
1451 | {
1452 | obstacleToTrack.alreadyHit = true;
1453 |
1454 | if (!Sounds.muted) Sounds.sndHit.play();
1455 |
1456 | if (coffee > 0)
1457 | {
1458 | // If hero has a coffee item, break through the obstacle.
1459 | if (obstacleToTrack.position == "bottom") obstacleToTrack.rotation = deg2rad(100);
1460 | else obstacleToTrack.rotation = deg2rad(-100);
1461 |
1462 | // Set hit obstacle value.
1463 | hitObstacle = 30;
1464 |
1465 | // Reduce hero's speed
1466 | playerSpeed *= 0.8;
1467 | }
1468 | else
1469 | {
1470 | if (obstacleToTrack.position == "bottom") obstacleToTrack.rotation = deg2rad(70);
1471 | else obstacleToTrack.rotation = deg2rad(-70);
1472 |
1473 | // Otherwise, if hero doesn't have a coffee item, set hit obstacle value.
1474 | hitObstacle = 30;
1475 |
1476 | // Reduce hero's speed.
1477 | playerSpeed *= 0.5;
1478 |
1479 | // Play hurt sound.
1480 | if (!Sounds.muted) Sounds.sndHurt.play();
1481 |
1482 | // Update lives.
1483 | lives--;
1484 |
1485 | if (lives <= 0)
1486 | {
1487 | lives = 0;
1488 | endGame();
1489 | }
1490 |
1491 | hud.lives = lives;
1492 | }
1493 | }
1494 |
1495 | // If the game has ended, remove the obstacle.
1496 | if (gameState == GameConstants.GAME_STATE_OVER)
1497 | {
1498 | disposeObstacleTemporarily(i, obstacleToTrack);
1499 | }
1500 | }
1501 | }
1502 | }
1503 |
1504 | /**
1505 | * End game.
1506 | *
1507 | */
1508 | private function endGame():void
1509 | {
1510 | this.x = 0;
1511 | this.y = 0;
1512 |
1513 | // Set Game Over state so all obstacles and items can remove themselves.
1514 | gameState = GameConstants.GAME_STATE_OVER;
1515 | }
1516 |
1517 | /**
1518 | * Game Over - called when hero falls out of screen and when Game Over data should be displayed.
1519 | *
1520 | */
1521 | private function gameOver():void
1522 | {
1523 | this.setChildIndex(gameOverContainer, this.numChildren-1);
1524 | gameOverContainer.initialize(scoreItems, Math.round(scoreDistance));
1525 |
1526 | tween_gameOverContainer = new Tween(gameOverContainer, 1);
1527 | tween_gameOverContainer.fadeTo(1);
1528 | Starling.juggler.add(tween_gameOverContainer);
1529 | }
1530 |
1531 | private function shakeAnimation(event:Event):void
1532 | {
1533 | // Animate quake effect, shaking the camera a little to the sides and up and down.
1534 | if (cameraShake > 0)
1535 | {
1536 | cameraShake -= 0.1;
1537 | // Shake left right randomly.
1538 | this.x = int(Math.random() * cameraShake - cameraShake * 0.5);
1539 | // Shake up down randomly.
1540 | this.y = int(Math.random() * cameraShake - cameraShake * 0.5);
1541 | }
1542 | else if (x != 0)
1543 | {
1544 | // If the shake value is 0, reset the stage back to normal.
1545 | // Reset to initial position.
1546 | this.x = 0;
1547 | this.y = 0;
1548 | }
1549 | }
1550 |
1551 | /**
1552 | * Create an eat particle when an item is collected.
1553 | * @param itemToTrack
1554 | * @param count
1555 | *
1556 | */
1557 | private function createEatParticle(itemToTrack:Item, count:int = 2):void
1558 | {
1559 | var eatParticleToTrack:Particle;
1560 |
1561 | while (count > 0)
1562 | {
1563 | count--;
1564 |
1565 | // Create eat particle object.
1566 | eatParticleToTrack = eatParticlesPool.checkOut();
1567 |
1568 | if (eatParticleToTrack)
1569 | {
1570 | // Set the position of the particle object with a random offset.
1571 | eatParticleToTrack.x = itemToTrack.x + Math.random() * 40 - 20;
1572 | eatParticleToTrack.y = itemToTrack.y - Math.random() * 40;
1573 |
1574 | // Set the speed of a particle object.
1575 | eatParticleToTrack.speedY = Math.random() * 10 - 5;
1576 | eatParticleToTrack.speedX = Math.random() * 2 + 1;
1577 |
1578 | // Set the spinning speed of the particle object.
1579 | eatParticleToTrack.spin = Math.random() * 20 - 5;
1580 |
1581 | // Set the scale of the eat particle.
1582 | eatParticleToTrack.scaleX = eatParticleToTrack.scaleY = Math.random() * 0.3 + 0.3;
1583 |
1584 | // Animate the eat particle.
1585 | eatParticlesToAnimate[eatParticlesToAnimateLength++] = eatParticleToTrack;
1586 | }
1587 | }
1588 | }
1589 |
1590 | /**
1591 | * Animate the wind particles that are marked animatable.
1592 | *
1593 | */
1594 | private function animateWindParticles():void
1595 | {
1596 | var windToTrack:Particle;
1597 |
1598 | for(var i:uint = 0;i < windParticlesToAnimateLength;i++)
1599 | {
1600 | // Create wind particle.
1601 | windToTrack = windParticlesToAnimate[i];
1602 |
1603 | if (windToTrack)
1604 | {
1605 | // Move the wind based on its scale.
1606 | windToTrack.x -= 100 * windToTrack.scaleX;
1607 |
1608 | // If the wind particle goes off screen, remove it.
1609 | if (windToTrack.x < -windToTrack.width || gameState == GameConstants.GAME_STATE_OVER)
1610 | {
1611 | disposeWindParticleTemporarily(i, windToTrack);
1612 | }
1613 | }
1614 | }
1615 | }
1616 |
1617 | /**
1618 | * Animate the eat particles that are marked animatable.
1619 | *
1620 | */
1621 | private function animateEatParticles():void
1622 | {
1623 | var eatParticleToTrack:Particle;
1624 |
1625 | for(var i:uint = 0;i < eatParticlesToAnimateLength;i++)
1626 | {
1627 | eatParticleToTrack = eatParticlesToAnimate[i];
1628 |
1629 | if (eatParticleToTrack)
1630 | {
1631 | eatParticleToTrack.scaleX -= 0.03;
1632 |
1633 | // Make the eat particle get smaller.
1634 | eatParticleToTrack.scaleY = eatParticleToTrack.scaleX;
1635 | // Move it horizontally based on speedX.
1636 | eatParticleToTrack.y -= eatParticleToTrack.speedY;
1637 | // Reduce the horizontal speed.
1638 | eatParticleToTrack.speedY -= eatParticleToTrack.speedY * 0.2;
1639 | // Move it vertically based on speedY.
1640 | eatParticleToTrack.x += eatParticleToTrack.speedX;
1641 | // Reduce the vertical speed.
1642 | eatParticleToTrack.speedX--;
1643 |
1644 | // Rotate the eat particle based on spin.
1645 | eatParticleToTrack.rotation += deg2rad(eatParticleToTrack.spin);
1646 | // Increase the spinning speed.
1647 | eatParticleToTrack.spin *= 1.1;
1648 |
1649 | // If the eat particle is small enough, remove it.
1650 | if (eatParticleToTrack.scaleY <= 0.02)
1651 | {
1652 | disposeEatParticleTemporarily(i, eatParticleToTrack);
1653 | }
1654 | }
1655 | }
1656 | }
1657 |
1658 | /**
1659 | * On game over screen faded out.
1660 | *
1661 | */
1662 | private function gameOverFadedOut():void
1663 | {
1664 | gameOverContainer.visible = false;
1665 | initialize();
1666 | }
1667 |
1668 | /**
1669 | * Calculate elapsed time.
1670 | * @param event
1671 | *
1672 | */
1673 | private function calculateElapsed(event:Event):void
1674 | {
1675 | // Set the current time as the previous time.
1676 | timePrevious = timeCurrent;
1677 |
1678 | // Get teh new current time.
1679 | timeCurrent = getTimer();
1680 |
1681 | // Calcualte the time it takes for a frame to pass, in milliseconds.
1682 | elapsed = (timeCurrent - timePrevious) * 0.001;
1683 | }
1684 | }
1685 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/screens/Welcome.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.screens
15 | {
16 | import com.hsharma.hungryHero.customObjects.Font;
17 | import com.hsharma.hungryHero.events.NavigationEvent;
18 |
19 | import flash.media.SoundMixer;
20 | import flash.net.URLRequest;
21 | import flash.net.navigateToURL;
22 |
23 | import starling.animation.Transitions;
24 | import starling.animation.Tween;
25 | import starling.core.Starling;
26 | import starling.display.BlendMode;
27 | import starling.display.Button;
28 | import starling.display.Image;
29 | import starling.display.Sprite;
30 | import starling.events.Event;
31 | import starling.text.TextField;
32 | import starling.utils.HAlign;
33 | import starling.utils.VAlign;
34 |
35 | /**
36 | * This is the welcome or main menu class for the game.
37 | *
38 | * @author hsharma
39 | *
40 | */
41 | public class Welcome extends Sprite
42 | {
43 | /** Background image. */
44 | private var bg:Image;
45 |
46 | /** Game title. */
47 | private var title:Image;
48 |
49 | /** Play button. */
50 | private var playBtn:Button;
51 |
52 | /** About button. */
53 | private var aboutBtn:Button;
54 |
55 | /** Hero artwork. */
56 | private var hero:Image;
57 |
58 | /** About text field. */
59 | private var aboutText:TextField;
60 |
61 | /** hsharma.com button. */
62 | private var hsharmaBtn:Button;
63 |
64 | /** Starling Framework button. */
65 | private var starlingBtn:Button;
66 |
67 | /** Back button. */
68 | private var backBtn:Button;
69 |
70 | /** Screen mode - "welcome" or "about". */
71 | private var screenMode:String;
72 |
73 | /** Current date. */
74 | private var _currentDate:Date;
75 |
76 | /** Font - Regular text. */
77 | private var fontRegular:Font;
78 |
79 | /** Hero art tween object. */
80 | private var tween_hero:Tween;
81 |
82 | public function Welcome()
83 | {
84 | super();
85 | this.visible = false;
86 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
87 | }
88 |
89 | /**
90 | * On added to stage.
91 | * @param event
92 | *
93 | */
94 | private function onAddedToStage(event:Event):void
95 | {
96 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
97 |
98 | drawScreen();
99 | }
100 |
101 | /**
102 | * Draw all the screen elements.
103 | *
104 | */
105 | private function drawScreen():void
106 | {
107 | // GENERAL ELEMENTS
108 |
109 | bg = new Image(Assets.getTexture("BgWelcome"));
110 | bg.blendMode = BlendMode.NONE;
111 | this.addChild(bg);
112 |
113 | title = new Image(Assets.getAtlas().getTexture(("welcome_title")));
114 | title.x = 600;
115 | title.y = 65;
116 | this.addChild(title);
117 |
118 | // WELCOME ELEMENTS
119 |
120 | hero = new Image(Assets.getAtlas().getTexture("welcome_hero"));
121 | hero.x = -hero.width;
122 | hero.y = 130;
123 | this.addChild(hero);
124 |
125 | playBtn = new Button(Assets.getAtlas().getTexture("welcome_playButton"));
126 | playBtn.x = 640;
127 | playBtn.y = 340;
128 | playBtn.addEventListener(Event.TRIGGERED, onPlayClick);
129 | this.addChild(playBtn);
130 |
131 | aboutBtn = new Button(Assets.getAtlas().getTexture("welcome_aboutButton"));
132 | aboutBtn.x = 460;
133 | aboutBtn.y = 460;
134 | aboutBtn.addEventListener(Event.TRIGGERED, onAboutClick);
135 | this.addChild(aboutBtn);
136 |
137 | // ABOUT ELEMENTS
138 | fontRegular = Fonts.getFont("Regular");
139 |
140 | aboutText = new TextField(480, 600, "", fontRegular.fontName, fontRegular.fontSize, 0xffffff);
141 | aboutText.text = "Hungry Hero is a free and open source game built on Adobe Flash using Starling Framework.\n\nhttp://www.hungryherogame.com\n\n" +
142 | " The concept is very simple. The hero is pretty much always hungry and you need to feed him with food." +
143 | " You score when your Hero eats food.\n\nThere are different obstacles that fly in with a \"Look out!\"" +
144 | " caution before they appear. Avoid them at all costs. You only have 5 lives. Try to score as much as possible and also" +
145 | " try to travel the longest distance.";
146 | aboutText.x = 60;
147 | aboutText.y = 230;
148 | aboutText.hAlign = HAlign.CENTER;
149 | aboutText.vAlign = VAlign.TOP;
150 | aboutText.height = aboutText.textBounds.height + 30;
151 | this.addChild(aboutText);
152 |
153 | hsharmaBtn = new Button(Assets.getAtlas().getTexture("about_hsharmaLogo"));
154 | hsharmaBtn.x = aboutText.x;
155 | hsharmaBtn.y = aboutText.bounds.bottom;
156 | hsharmaBtn.addEventListener(Event.TRIGGERED, onHsharmaBtnClick);
157 | this.addChild(hsharmaBtn);
158 |
159 | starlingBtn = new Button(Assets.getAtlas().getTexture("about_starlingLogo"));
160 | starlingBtn.x = aboutText.bounds.right - starlingBtn.width;
161 | starlingBtn.y = aboutText.bounds.bottom;
162 | starlingBtn.addEventListener(Event.TRIGGERED, onStarlingBtnClick);
163 | this.addChild(starlingBtn);
164 |
165 | backBtn = new Button(Assets.getAtlas().getTexture("about_backButton"));
166 | backBtn.x = 660;
167 | backBtn.y = 350;
168 | backBtn.addEventListener(Event.TRIGGERED, onAboutBackClick);
169 | this.addChild(backBtn);
170 | }
171 |
172 | /**
173 | * On back button click from about screen.
174 | * @param event
175 | *
176 | */
177 | private function onAboutBackClick(event:Event):void
178 | {
179 | if (!Sounds.muted) Sounds.sndCoffee.play();
180 |
181 | initialize();
182 | }
183 |
184 | /**
185 | * On credits click on hsharma.com image.
186 | * @param event
187 | *
188 | */
189 | private function onHsharmaBtnClick(event:Event):void
190 | {
191 | navigateToURL(new URLRequest("http://www.hsharma.com/"), "_blank");
192 | }
193 |
194 | /**
195 | * On credits click on Starling Framework image.
196 | * @param event
197 | *
198 | */
199 | private function onStarlingBtnClick(event:Event):void
200 | {
201 | navigateToURL(new URLRequest("http://www.gamua.com/starling"), "_blank");
202 | }
203 |
204 | /**
205 | * On play button click.
206 | * @param event
207 | *
208 | */
209 | private function onPlayClick(event:Event):void
210 | {
211 | this.dispatchEvent(new NavigationEvent(NavigationEvent.CHANGE_SCREEN, {id: "play"}, true));
212 |
213 | if (!Sounds.muted) Sounds.sndCoffee.play();
214 | }
215 |
216 | /**
217 | * On about button click.
218 | * @param event
219 | *
220 | */
221 | private function onAboutClick(event:Event):void
222 | {
223 | if (!Sounds.muted) Sounds.sndMushroom.play();
224 | showAbout();
225 | }
226 |
227 | /**
228 | * Show about screen.
229 | *
230 | */
231 | public function showAbout():void
232 | {
233 | screenMode = "about";
234 |
235 | hero.visible = false;
236 | playBtn.visible = false;
237 | aboutBtn.visible = false;
238 |
239 | aboutText.visible = true;
240 | hsharmaBtn.visible = true;
241 | starlingBtn.visible = true;
242 | backBtn.visible = true;
243 | }
244 |
245 | /**
246 | * Initialize welcome screen.
247 | *
248 | */
249 | public function initialize():void
250 | {
251 | disposeTemporarily();
252 |
253 | this.visible = true;
254 |
255 | // If not coming from about, restart playing background music.
256 | if (screenMode != "about")
257 | {
258 | if (!Sounds.muted) Sounds.sndBgMain.play(0, 999);
259 | }
260 |
261 | screenMode = "welcome";
262 |
263 | hero.visible = true;
264 | playBtn.visible = true;
265 | aboutBtn.visible = true;
266 |
267 | aboutText.visible = false;
268 | hsharmaBtn.visible = false;
269 | starlingBtn.visible = false;
270 | backBtn.visible = false;
271 |
272 | hero.x = -hero.width;
273 | hero.y = 100;
274 |
275 | tween_hero = new Tween(hero, 4, Transitions.EASE_OUT);
276 | tween_hero.animate("x", 80);
277 | Starling.juggler.add(tween_hero);
278 |
279 | this.addEventListener(Event.ENTER_FRAME, floatingAnimation);
280 | }
281 |
282 | /**
283 | * Animate floating objects.
284 | * @param event
285 | *
286 | */
287 | private function floatingAnimation(event:Event):void
288 | {
289 | _currentDate = new Date();
290 | hero.y = 130 + (Math.cos(_currentDate.getTime() * 0.002)) * 25;
291 | playBtn.y = 340 + (Math.cos(_currentDate.getTime() * 0.002)) * 10;
292 | aboutBtn.y = 460 + (Math.cos(_currentDate.getTime() * 0.002)) * 10;
293 | }
294 |
295 | /**
296 | * Dispose objects temporarily.
297 | *
298 | */
299 | public function disposeTemporarily():void
300 | {
301 | this.visible = false;
302 |
303 | if (this.hasEventListener(Event.ENTER_FRAME)) this.removeEventListener(Event.ENTER_FRAME, floatingAnimation);
304 |
305 | if (screenMode != "about") SoundMixer.stopAll();
306 | }
307 | }
308 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/ui/GameOverContainer.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.ui
15 | {
16 | import com.hsharma.hungryHero.customObjects.Font;
17 | import com.hsharma.hungryHero.events.NavigationEvent;
18 |
19 | import starling.display.Button;
20 | import starling.display.Quad;
21 | import starling.display.Sprite;
22 | import starling.events.Event;
23 | import starling.text.TextField;
24 | import starling.utils.VAlign;
25 |
26 | public class GameOverContainer extends Sprite
27 | {
28 | /** Background image. */
29 | private var bg:Quad;
30 |
31 | /** Message text field. */
32 | private var messageText:TextField;
33 |
34 | /** Score container. */
35 | private var scoreContainer:Sprite;
36 |
37 | /** Score display - distance. */
38 | private var distanceText:TextField;
39 |
40 | /** Score display - score. */
41 | private var scoreText:TextField;
42 |
43 | /** Play again button. */
44 | private var playAgainBtn:Button;
45 |
46 | /** Main Menu button. */
47 | private var mainBtn:Button;
48 |
49 | /** About button. */
50 | private var aboutBtn:Button;
51 |
52 | /** Font - score display. */
53 | private var fontScore:Font;
54 |
55 | /** Font - message display. */
56 | private var fontMessage:Font;
57 |
58 | /** Score value - distance. */
59 | private var _distance:int;
60 |
61 | /** Score value - score. */
62 | private var _score:int;
63 |
64 | public function GameOverContainer()
65 | {
66 | super();
67 |
68 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
69 | }
70 |
71 | /**
72 | * On added to stage.
73 | * @param event
74 | *
75 | */
76 | private function onAddedToStage(event:Event):void
77 | {
78 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
79 |
80 | drawGameOver();
81 | }
82 |
83 | /**
84 | * Draw game over screen.
85 | *
86 | */
87 | private function drawGameOver():void
88 | {
89 | // Get fonts for text display.
90 | fontMessage = Fonts.getFont("ScoreValue");
91 | fontScore = Fonts.getFont("ScoreLabel");
92 |
93 | // Background quad.
94 | bg = new Quad(stage.stageWidth, stage.stageHeight, 0x000000);
95 | bg.alpha = 0.75;
96 | this.addChild(bg);
97 |
98 | // Message text field.
99 | messageText = new TextField(stage.stageWidth, stage.stageHeight * 0.5, "HERO WAS KILLED!", fontMessage.fontName, fontMessage.fontSize, 0xf3e75f);
100 | messageText.vAlign = VAlign.TOP;
101 | messageText.height = messageText.textBounds.height;
102 | messageText.y = (stage.stageHeight * 20)/100;
103 | this.addChild(messageText);
104 |
105 | // Score container.
106 | scoreContainer = new Sprite();
107 | scoreContainer.y = (stage.stageHeight * 40)/100;
108 | this.addChild(scoreContainer);
109 |
110 | distanceText = new TextField(stage.stageWidth, 100, "DISTANCE TRAVELLED: 0000000", fontScore.fontName, fontScore.fontSize, 0xffffff);
111 | distanceText.vAlign = VAlign.TOP;
112 | distanceText.height = distanceText.textBounds.height;
113 | scoreContainer.addChild(distanceText);
114 |
115 | scoreText = new TextField(stage.stageWidth, 100, "SCORE: 0000000", fontScore.fontName, fontScore.fontSize, 0xffffff);
116 | scoreText.vAlign = VAlign.TOP;
117 | scoreText.height = scoreText.textBounds.height;
118 | scoreText.y = distanceText.bounds.bottom + scoreText.height * 0.5;
119 | scoreContainer.addChild(scoreText);
120 |
121 | // Navigation buttons.
122 | mainBtn = new Button(Assets.getAtlas().getTexture("gameOver_mainButton"));
123 | mainBtn.y = (stage.stageHeight * 70)/100;
124 | mainBtn.addEventListener(Event.TRIGGERED, onMainClick);
125 | this.addChild(mainBtn);
126 |
127 | playAgainBtn = new Button(Assets.getAtlas().getTexture("gameOver_playAgainButton"));
128 | playAgainBtn.y = mainBtn.y + mainBtn.height * 0.5 - playAgainBtn.height * 0.5;
129 | playAgainBtn.addEventListener(Event.TRIGGERED, onPlayAgainClick);
130 | this.addChild(playAgainBtn);
131 |
132 | aboutBtn = new Button(Assets.getAtlas().getTexture("gameOver_aboutButton"));
133 | aboutBtn.y = playAgainBtn.y + playAgainBtn.height * 0.5 - aboutBtn.height * 0.5;
134 | aboutBtn.addEventListener(Event.TRIGGERED, onAboutClick);
135 | this.addChild(aboutBtn);
136 |
137 | mainBtn.x = stage.stageWidth * 0.5 - (mainBtn.width + playAgainBtn.width + aboutBtn.width + 30) * 0.5;
138 | playAgainBtn.x = mainBtn.bounds.right + 10;
139 | aboutBtn.x = playAgainBtn.bounds.right + 10;
140 | }
141 |
142 | /**
143 | * On play-again button click.
144 | * @param event
145 | *
146 | */
147 | private function onPlayAgainClick(event:Event):void
148 | {
149 | if (!Sounds.muted) Sounds.sndMushroom.play();
150 |
151 | this.dispatchEvent(new NavigationEvent(NavigationEvent.CHANGE_SCREEN, {id: "playAgain"}));
152 | }
153 |
154 | /**
155 | * On main menu button click.
156 | * @param event
157 | *
158 | */
159 | private function onMainClick(event:Event):void
160 | {
161 | if (!Sounds.muted) Sounds.sndMushroom.play();
162 |
163 | this.dispatchEvent(new NavigationEvent(NavigationEvent.CHANGE_SCREEN, {id: "mainMenu"}, true));
164 | }
165 |
166 | /**
167 | * On about button click.
168 | * @param event
169 | *
170 | */
171 | private function onAboutClick(event:Event):void
172 | {
173 | if (!Sounds.muted) Sounds.sndMushroom.play();
174 |
175 | this.dispatchEvent(new NavigationEvent(NavigationEvent.CHANGE_SCREEN, {id: "about"}, true));
176 | }
177 |
178 | /**
179 | * Initialize Game Over container.
180 | * @param _score
181 | * @param _distance
182 | *
183 | */
184 | public function initialize(_score:int, _distance:int):void
185 | {
186 | this._distance = _distance;
187 | this._score = _score;
188 |
189 | distanceText.text = "DISTANCE TRAVELLED: " + this._distance.toString();
190 | scoreText.text = "SCORE: " + this._score.toString();
191 |
192 | this.alpha = 0;
193 | this.visible = true;
194 | }
195 |
196 | /**
197 | * Score.
198 | * @return
199 | *
200 | */
201 | public function get score():int { return _score; }
202 |
203 | /**
204 | * Distance.
205 | * @return
206 | *
207 | */
208 | public function get distance():int { return _distance; }
209 | }
210 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/ui/HUD.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.ui
15 | {
16 | import com.hsharma.hungryHero.customObjects.Font;
17 |
18 | import starling.display.Sprite;
19 | import starling.events.Event;
20 | import starling.text.TextField;
21 | import starling.utils.HAlign;
22 | import starling.utils.VAlign;
23 |
24 | /**
25 | * This class handles the Heads Up Display for the game.
26 | *
27 | * @author hsharma
28 | *
29 | */
30 | public class HUD extends Sprite
31 | {
32 | /** Lives left. */
33 | private var _lives:int;
34 |
35 | /** Distance travelled. */
36 | private var _distance:int;
37 |
38 | /** Food items score. */
39 | private var _foodScore:int;
40 |
41 | /** Lives icon. */
42 | private var livesLabel:TextField;
43 |
44 | /** Lives TextField. */
45 | private var livesText:TextField;
46 |
47 | /** Distance icon. */
48 | private var distanceLabel:TextField;
49 |
50 | /** Distance TextField. */
51 | private var distanceText:TextField;
52 |
53 | /** Food Score icon. */
54 | private var foodScoreLabel:TextField;
55 |
56 | /** Food Score TextField. */
57 | private var foodScoreText:TextField;
58 |
59 | /** Font for score label. */
60 | private var fontScoreLabel:Font;
61 |
62 | /** Font for score value. */
63 | private var fontScoreValue:Font;
64 |
65 | public function HUD()
66 | {
67 | super();
68 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
69 | }
70 |
71 | /**
72 | * On added to stage.
73 | * @param event
74 | *
75 | */
76 | private function onAddedToStage(event:Event):void
77 | {
78 | // Get fonts for score labels and values.
79 | fontScoreLabel = Fonts.getFont("ScoreLabel");
80 | fontScoreValue = Fonts.getFont("ScoreValue");
81 |
82 | // Lives label
83 | livesLabel = new TextField(150, 20, "L I V E S", fontScoreLabel.fontName, fontScoreLabel.fontSize, 0xffffff);
84 | livesLabel.hAlign = HAlign.RIGHT;
85 | livesLabel.vAlign = VAlign.TOP;
86 |
87 | livesLabel.x = 150;
88 | livesLabel.y = 5;
89 | this.addChild(livesLabel);
90 |
91 | // Lives
92 | livesText = new TextField(150, 75, "5", fontScoreValue.fontName, fontScoreValue.fontSize, 0xffffff);
93 | livesText.hAlign = HAlign.RIGHT;
94 | livesText.vAlign = VAlign.TOP;
95 | livesText.width = livesLabel.width;
96 |
97 | livesText.x = int(livesLabel.x + livesLabel.width - livesText.width);
98 | livesText.y = livesLabel.y + livesLabel.height;
99 | this.addChild(livesText);
100 |
101 | // Distance label
102 | distanceLabel = new TextField(150, 20, "D I S T A N C E", fontScoreLabel.fontName, fontScoreLabel.fontSize, 0xffffff);
103 | distanceLabel.hAlign = HAlign.RIGHT;
104 | distanceLabel.vAlign = VAlign.TOP;
105 |
106 | distanceLabel.x = int(stage.stageWidth - distanceLabel.width - 10);
107 | distanceLabel.y = 5;
108 | this.addChild(distanceLabel);
109 |
110 | // Distance
111 | distanceText = new TextField(150, 75, "0", fontScoreValue.fontName, fontScoreValue.fontSize, 0xffffff);
112 | distanceText.hAlign = HAlign.RIGHT;
113 | distanceText.vAlign = VAlign.TOP;
114 | distanceText.width = distanceLabel.width;
115 |
116 | distanceText.x = int(distanceLabel.x + distanceLabel.width - distanceText.width);
117 | distanceText.y = distanceLabel.y + distanceLabel.height;
118 | this.addChild(distanceText);
119 |
120 | // Score label
121 | foodScoreLabel = new TextField(150, 20, "S C O R E", fontScoreLabel.fontName, fontScoreLabel.fontSize, 0xffffff);
122 | foodScoreLabel.hAlign = HAlign.RIGHT;
123 | foodScoreLabel.vAlign = VAlign.TOP;
124 |
125 | foodScoreLabel.x = int(distanceLabel.x - foodScoreLabel.width - 50);
126 | foodScoreLabel.y = 5;
127 | this.addChild(foodScoreLabel);
128 |
129 | // Score
130 | foodScoreText = new TextField(150, 75, "0", fontScoreValue.fontName, fontScoreValue.fontSize, 0xffffff);
131 | foodScoreText.hAlign = HAlign.RIGHT;
132 | foodScoreText.vAlign = VAlign.TOP;
133 | foodScoreText.width = foodScoreLabel.width;
134 |
135 | foodScoreText.x = int(foodScoreLabel.x + foodScoreLabel.width - foodScoreText.width);
136 | foodScoreText.y = foodScoreLabel.y + foodScoreLabel.height;
137 | this.addChild(foodScoreText);
138 | }
139 |
140 | /**
141 | * Lives left.
142 | * @return
143 | *
144 | */
145 | public function get lives():int { return _lives; }
146 | public function set lives(value:int):void
147 | {
148 | _lives = value;
149 | livesText.text = _lives.toString();
150 | }
151 |
152 | /**
153 | * Distance travelled.
154 | * @return
155 | *
156 | */
157 | public function get distance():int { return _distance; }
158 | public function set distance(value:int):void
159 | {
160 | _distance = value;
161 | distanceText.text = _distance.toString();
162 | }
163 |
164 | /**
165 | * Food items score.
166 | * @return
167 | *
168 | */
169 | public function get foodScore():int { return _foodScore; }
170 | public function set foodScore(value:int):void
171 | {
172 | _foodScore = value;
173 | foodScoreText.text = _foodScore.toString();
174 | }
175 |
176 | /**
177 | * Add leading zeros to the score numbers.
178 | * @param value
179 | * @return
180 | *
181 | */
182 | private function addZeros(value:int):String {
183 | var ret:String = String(value);
184 | while (ret.length < 7) {
185 | ret = "0" + ret;
186 | }
187 | return ret;
188 | }
189 | }
190 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/ui/PauseButton.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.ui
15 | {
16 | import flash.display.BitmapData;
17 |
18 | import starling.display.Button;
19 | import starling.display.Image;
20 | import starling.events.Event;
21 | import starling.textures.Texture;
22 |
23 | /**
24 | * This class is the pause button for the in-game screen.
25 | *
26 | * @author hsharma
27 | *
28 | */
29 | public class PauseButton extends Button
30 | {
31 | /** Pause button image. */
32 | private var pauseImage:Image;
33 |
34 | public function PauseButton()
35 | {
36 | super(Texture.fromBitmapData(new BitmapData(Assets.getAtlas().getTexture("pauseButton").width, Assets.getAtlas().getTexture("pauseButton").height, true, 0)));
37 |
38 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
39 | }
40 |
41 | /**
42 | * On added to stage.
43 | * @param event
44 | *
45 | */
46 | private function onAddedToStage(event:Event):void
47 | {
48 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
49 |
50 | // Pause Image
51 | pauseImage = new Image(Assets.getAtlas().getTexture("pauseButton"));
52 | this.addChild(pauseImage);
53 | }
54 | }
55 | }
--------------------------------------------------------------------------------
/src/com/hsharma/hungryHero/ui/SoundButton.as:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Hungry Hero Game
4 | * http://www.hungryherogame.com
5 | *
6 | * Copyright (c) 2012 Hemanth Sharma (www.hsharma.com). All rights reserved.
7 | *
8 | * This ActionScript source code is free.
9 | * You can redistribute and/or modify it in accordance with the
10 | * terms of the accompanying Simplified BSD License Agreement.
11 | *
12 | */
13 |
14 | package com.hsharma.hungryHero.ui
15 | {
16 | import flash.display.BitmapData;
17 |
18 | import starling.core.Starling;
19 | import starling.display.Button;
20 | import starling.display.Image;
21 | import starling.display.MovieClip;
22 | import starling.events.Event;
23 | import starling.textures.Texture;
24 |
25 | /**
26 | * This class is the sound/mute button.
27 | *
28 | * @author hsharma
29 | *
30 | */
31 | public class SoundButton extends Button
32 | {
33 | /** Animation shown when sound is playing. */
34 | private var mcUnmuteState:MovieClip;
35 |
36 | /** Image shown when the sound is muted. */
37 | private var imageMuteState:Image;
38 |
39 | public function SoundButton()
40 | {
41 | super(Texture.fromBitmapData(new BitmapData(Assets.getAtlas().getTexture("soundOff").width, Assets.getAtlas().getTexture("soundOff").height, true, 0)));
42 |
43 | this.addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
44 | }
45 |
46 | /**
47 | * On added to stage.
48 | * @param event
49 | *
50 | */
51 | private function onAddedToStage(event:Event):void
52 | {
53 | this.removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
54 |
55 | setButtonTextures();
56 | showUnmuteState();
57 | }
58 |
59 | /**
60 | * Set textures for button states.
61 | *
62 | */
63 | private function setButtonTextures():void
64 | {
65 | // Normal state - image
66 | mcUnmuteState = new MovieClip(Assets.getAtlas().getTextures("soundOn"), 3);
67 | Starling.juggler.add(mcUnmuteState);
68 | this.addChild(mcUnmuteState);
69 |
70 | // Selected state - animation
71 | imageMuteState = new Image(Assets.getAtlas().getTexture("soundOff"));
72 | this.addChild(imageMuteState);
73 | }
74 |
75 | /**
76 | * Show Off State - Show the mute symbol (sound is muted).
77 | *
78 | */
79 | public function showUnmuteState():void
80 | {
81 | mcUnmuteState.visible = true;
82 | imageMuteState.visible = false;
83 | }
84 |
85 | /**
86 | * Show On State - Show the unmute animation (sound is playing).
87 | *
88 | */
89 | public function showMuteState():void
90 | {
91 | mcUnmuteState.visible = false;
92 | imageMuteState.visible = true;
93 | }
94 | }
95 | }
--------------------------------------------------------------------------------
/src/icons/icon_114.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_114.png
--------------------------------------------------------------------------------
/src/icons/icon_128.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_128.png
--------------------------------------------------------------------------------
/src/icons/icon_16.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_16.png
--------------------------------------------------------------------------------
/src/icons/icon_29.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_29.png
--------------------------------------------------------------------------------
/src/icons/icon_32.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_32.png
--------------------------------------------------------------------------------
/src/icons/icon_36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_36.png
--------------------------------------------------------------------------------
/src/icons/icon_48.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_48.png
--------------------------------------------------------------------------------
/src/icons/icon_512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_512.png
--------------------------------------------------------------------------------
/src/icons/icon_57.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_57.png
--------------------------------------------------------------------------------
/src/icons/icon_72.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hsharma-design/Hungry-Hero/2c709d936989fdcefd971209a980d311ca59aca4/src/icons/icon_72.png
--------------------------------------------------------------------------------