Skip to content

Instantly share code, notes, and snippets.

@EduardoLopes
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save EduardoLopes/65977c5be66c9ed04a6c to your computer and use it in GitHub Desktop.

Select an option

Save EduardoLopes/65977c5be66c9ed04a6c to your computer and use it in GitHub Desktop.
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.util.FlxRandom;
class Cloud extends FlxSprite
{
public static var COUNT:Int = 0;
public function new (x:Float = 0, y:Float = 0)
{
super(x, y);
loadGraphic(AssetPaths.clouds__png, true, 80, 35);
//spawn();
}
public function spawn():Void
{
velocity.x = -FlxRandom.intRanged(30, 60);
setPosition(FlxRandom.intRanged(FlxG.width, FlxG.width + 150), FlxRandom.intRanged(-10, 50));
animation.frameIndex = FlxRandom.intRanged(FlxG.width, 5);
Cloud.COUNT++;
}
override public function kill():Void
{
super.kill();
Cloud.COUNT--;
}
override public function update():Void
{
super.update();
if(x + width < 0)
{
kill();
//spawn();
}
}
}
Called from /usr/lib/haxe/std/neko/_std/Type.hx line 102
Called from flixel/group/FlxTypedGroup.hx line 244
Called from PlayState.hx line 70
Called from flixel/FlxGame.hx line 583
Called from flixel/FlxGame.hx line 311
Called from openfl/_legacy/events/EventDispatcher.hx line 98
Called from openfl/_legacy/display/DisplayObject.hx line 182
Called from openfl/_legacy/display/DisplayObject.hx line 70
Called from openfl/_legacy/display/DisplayObject.hx line 362
Called from openfl/_legacy/display/DisplayObjectContainer.hx line 373
Called from openfl/_legacy/display/DisplayObject.hx line 423
Called from openfl/_legacy/display/DisplayObjectContainer.hx line 31
Called from Main.hx line 66
Called from Main.hx line 49
Called from openfl/_legacy/events/EventDispatcher.hx line 98
Called from openfl/_legacy/display/DisplayObject.hx line 182
Called from openfl/_legacy/display/DisplayObject.hx line 70
Called from openfl/_legacy/display/DisplayObject.hx line 362
Called from openfl/_legacy/display/DisplayObjectContainer.hx line 373
Called from openfl/_legacy/display/DisplayObject.hx line 423
Called from openfl/_legacy/display/DisplayObjectContainer.hx line 31
Called from Main.hx line 25
Called from /usr/lib/haxe/std/neko/_std/Reflect.hx line 58
Called from ApplicationMain.hx line 101
Called from openfl/_legacy/Lib.hx line 114
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxMath;
import flixel.addons.nape.FlxNapeSprite;
import flixel.addons.nape.FlxNapeState;
import flixel.util.FlxRandom;
import nape.callbacks.CbEvent;
import nape.callbacks.CbType;
import nape.callbacks.InteractionCallback;
import nape.callbacks.InteractionListener;
import nape.callbacks.InteractionType;
import nape.callbacks.PreCallback;
import nape.callbacks.PreFlag;
import nape.callbacks.PreListener;
import flixel.addons.nape.FlxNapeTilemap;
import openfl.Assets;
import flixel.FlxCamera;
import nape.phys.Compound;
import nape.phys.BodyType;
import flixel.util.FlxPoint;
import flixel.util.FlxPath;
import nape.phys.BodyType;
import flixel.util.FlxRandom;
import nape.geom.Vec2;
import nape.phys.Body;
import nape.phys.BodyType;
import nape.shape.Circle;
import nape.shape.Polygon;
import flixel.group.FlxGroup;
import flixel.group.FlxTypedGroup;
/**
* A FlxState which can be used for the actual gameplay.
*/
class PlayState extends FlxNapeState
{
public var clouds:FlxTypedGroup<Cloud>;
/**
* Function that is called up when to state is created to set it up.
*/
override public function create():Void
{
super.create();
napeDebugEnabled = true;
FlxNapeState.space.gravity.setxy(0, 1000);
createWalls(0,0,FlxG.width, FlxG.height);
var background:FlxSprite = new FlxSprite(0, 0);
background.loadGraphic('assets/images/background.png');
add(background);
clouds = new FlxTypedGroup<Cloud>();
add(clouds);
clouds.recycle(Cloud).spawn();
// for (i in 0...5) {
// add(new Cloud());
// }
var fluidBody = new Body(BodyType.STATIC);
var fluidShape = new Polygon(Polygon.rect(0, 100, FlxG.width, FlxG.height - 100));
fluidShape.fluidEnabled = true;
fluidShape.filter.fluidMask = 2;
fluidShape.fluidProperties.density = 2;
fluidShape.fluidProperties.viscosity = 3;
fluidShape.body = fluidBody;
fluidBody.space = FlxNapeState.space;
for (i in 0...20) {
var boxBody = new Body();
boxBody.position.setxy(Math.random() * FlxG.width, Math.random() * 20);
var boxShape = new Polygon(Polygon.box(32, 32));
boxShape.filter.fluidGroup = 2;
boxShape.body = boxBody;
boxShape.body.mass = FlxRandom.intRanged(1,4);
boxBody.space = FlxNapeState.space;
}
var shark:Shark = new Shark(40, 40);
add(shark);
}
/**
* Function that is called when this state is destroyed - you might want to
* consider setting all objects this state uses to null to help garbage collection.
*/
override public function destroy():Void
{
super.destroy();
}
/**
* Function that is called once every frame.
*/
override public function update():Void
{
super.update();
if(Cloud.COUNT < 5)
{
clouds.recycle(Cloud).spawn();
}
// if(FlxG.mouse.justPressed){
// FlxG.resetState();
// }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment