Last active
August 6, 2019 15:25
-
-
Save Geokureli/a512eca5a905626a5e0a5f8a92adc695 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package; | |
| import flixel.FlxG; | |
| import flixel.math.FlxRect; | |
| import flixel.addons.display.FlxSliceSprite; | |
| using flixel.util.FlxSpriteUtil; | |
| class Main extends openfl.display.Sprite | |
| { | |
| public function new () | |
| { | |
| super(); | |
| addChild(new flixel.FlxGame(160, 160, State, 1, 60, 60, true, false)); | |
| } | |
| } | |
| class State extends flixel.FlxState | |
| { | |
| inline static var LEFT = 2; | |
| inline static var CENTER = 1; | |
| inline static var RIGHT = 3; | |
| // how wide and high the actual sliceSprite is | |
| inline static var SIZE = LEFT + CENTER + RIGHT; | |
| // padding on the source bitmap | |
| inline static var GUTTER = 2; | |
| // rate of shrink, per frame | |
| inline static var SPEED = 3; | |
| var pellet:FlxSliceSprite; | |
| override public function create () | |
| { | |
| super.create(); | |
| var graphic = FlxG.bitmap.create(SIZE + GUTTER, SIZE + GUTTER, 0x0); | |
| pellet = new FlxSliceSprite | |
| ( graphic | |
| , FlxRect.get(LEFT, 0, CENTER, SIZE) | |
| , FlxG.width | |
| , SIZE | |
| , FlxRect.get(0, 0, SIZE, SIZE) | |
| ); | |
| pellet.drawRect(1, 0, SIZE - 2, 1); //top | |
| pellet.drawRect(SIZE - 1, 1, 1, SIZE - 2); //right | |
| pellet.drawRect(1, SIZE - 1, SIZE - 2, 1); //bottom | |
| pellet.drawRect(0, 1, 1, SIZE - 2); //left | |
| //center | |
| pellet.drawRect(1, 1, SIZE - 2, SIZE - 2, 0xFF0080f0); | |
| add(pellet); | |
| } | |
| override function update(elapsed:Float) | |
| { | |
| super.update(elapsed); | |
| if (!FlxG.keys.pressed.SPACE) | |
| { | |
| if (pellet.width - SPEED <= SIZE) | |
| pellet.width = FlxG.width; | |
| else | |
| pellet.width -= SPEED; | |
| // pellet.y++; | |
| // if (pellet.y + SIZE > FlxG.height) | |
| // pellet.y = 0; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment