Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calc rotation #290

Merged
merged 9 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Performance/PixelPerfectCollision/Project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<!-- ____________________________ Window Settings ___________________________ -->

<!--These window settings apply to all targets-->
<window width="640" height="400" fps="60" background="#000000" hardware="true" vsync="false" />
<window width="640" height="400" fps="60" background="#222034" hardware="true" vsync="false" />

<!--HTML5-specific-->
<window if="html5" resizable="false" />
Expand Down
Binary file modified Performance/PixelPerfectCollision/assets/alien.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
59 changes: 59 additions & 0 deletions Performance/PixelPerfectCollision/source/Alien.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;

class Alien extends DemoSprite
{
var collides:Bool = false;

public function new()
{
super();

// set dance dance interstellar animations
loadGraphic("assets/alien.png", true);
/*
* WebGL has trouble displaying large number of sprites with dynamic coloring,
* so we switch bewteen two similar animations with different colors.
*/
var fps = FlxG.random.int(6, 10);
animation.add("dance_off", [0, 1, 0, 2], fps);
animation.add("dance_on", [3, 4, 3, 5], fps);
animation.play("dance_off"); // dance!
}

/**
* Randomize position, scrollFactor, velocity and alpha.
*/
public function randomize()
{
var ran = FlxG.random;
x = ran.int(0, Std.int(FlxG.width - width)) + FlxG.camera.scroll.x;
y = ran.int(0, Std.int(FlxG.height - height)) + FlxG.camera.scroll.y;
alpha = ran.float(0.1, 1.0);
scrollFactor.x = alpha;
// negate the x-offset caused from scrollFactor
x += FlxG.camera.scroll.x * (scrollFactor.x - 1);
velocity.set(-ran.float(5, 25), 0);

// Neat tweening effect for new aliens appearing
var toY = y;
y = (y < FlxG.height / 2) ? -20 : FlxG.height + 20;
FlxTween.tween(this, {y: toY}, 1.0, { ease: FlxEase.expoOut, startDelay: ran.float() * 0.5 });
}

/**
* Switches the between the red/white color to show whether an overlap is occurring.
* @param value
*/
override function setCollides(value:Bool)
{
if (value != collides)
{
collides = value;
var frame = animation.curAnim.curFrame;
animation.play("dance_" + (collides ? "on" : "off"), false, false, frame);
}
}
}
66 changes: 66 additions & 0 deletions Performance/PixelPerfectCollision/source/DemoSprite.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import flixel.FlxG;
import flixel.FlxObject;
import flixel.FlxSprite;
import flixel.math.FlxRect;

class DemoSprite extends FlxSprite
{
public function new (x = 0.0, y = 0.0)
{
super(x, y);
}

/**
* Switches the between the red/white color to show whether an overlap is occurring.
*/
public function setCollides(value:Bool)
{
color = value ? 0xFFac3232 : 0xFF6abe30;
}

public function resetAngle()
{
angle = 0;
angularVelocity = 0;
}

public function resetScale()
{
scale.set(1, 1);
}

public function randomAngle()
{
angle = FlxG.random.float() * 360;
angularVelocity = FlxG.random.float(50, 100);
}

public function randomScale()
{
scale.x = FlxG.random.float(0.5, 2.0);
scale.y = scale.x;
}

#if debug
override function draw()
{
// For debugging
// drawDebugScreenBounds();

super.draw();
}

function drawDebugScreenBounds()
{
for (camera in cameras)
{
var rect = getScreenBounds(camera);
var gfx = beginDrawDebug(camera);
// fill static graphics object with square shape
gfx.lineStyle(1, 0x0000ff, 0.5);
gfx.drawRect(rect.x, rect.y, rect.width, rect.height);
endDrawDebug(camera);
}
}
#end
}
Loading