Skip to content

Commit

Permalink
Calc rotation (#290)
Browse files Browse the repository at this point in the history
* messing around with pixel perfect check

* beauty changes

* debug drawing

* disable origin

* delete TestState

* remove whoopsies

* remove offset/origin stuff

* remove debug info
  • Loading branch information
Geokureli authored Jan 21, 2022
1 parent 02470a7 commit 5324226
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 148 deletions.
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

0 comments on commit 5324226

Please sign in to comment.