Skip to content

Commit

Permalink
FlxSkewedSprite: bigger hd grass graphics (#312)
Browse files Browse the repository at this point in the history
* bigger hd grass graphics

* fix flash
  • Loading branch information
Geokureli authored Jun 13, 2023
1 parent 061ad1e commit cabfd5e
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Effects/FlxSkewedSprite/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="300" height="200" fps="60" background="#000000" hardware="true" vsync="false" />
<window width="600" height="200" fps="60" background="#000000" hardware="true" vsync="false" />

<!--HTML5-specific-->
<window if="html5" resizable="false" />
Expand Down
Binary file modified Effects/FlxSkewedSprite/assets/grass.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 24 additions & 28 deletions Effects/FlxSkewedSprite/source/Grass.hx
Original file line number Diff line number Diff line change
@@ -1,45 +1,41 @@
package;

import flixel.addons.effects.FlxSkewedSprite;
import flixel.FlxG;
import flixel.addons.effects.FlxSkewedSprite;

/**
* @author Zaphod
*/
class Grass extends FlxSkewedSprite
{
public var maxSkew:Float = 30;
public var minSkew:Float = -30;
public var skewSpeed:Float = 15;

var _skewDirection:Int = 1;

public function new(X:Float = 0, Y:Float = 0, Frame:Int = 0, StartSkew:Float = 0)
static public inline var SKEW_MAX = 10;
static public inline var SKEW_MIN = -30;
static public inline var SKEW_FREQ = 1.3;
var time:Float;
public function new(x = 0.0, y = 0.0, frame = 0, timeOffset = 0.0)
{
super(X, Y);

loadGraphic("assets/grass.png", true, 300, 28);
animation.frameIndex = Frame;

this.time = timeOffset * SKEW_FREQ;
super(x, y);

if (frame < 0)
loadGraphic("assets/grass.png");
else
{
loadGraphic("assets/grass.png", true, 600, 56);
animation.frameIndex = frame;
}

origin.set(0, height);
antialiasing = true;
skew.x = StartSkew;
}

override public function update(elapsed:Float):Void
{
super.update(elapsed);

skew.x += _skewDirection * skewSpeed * elapsed;

if (skew.x > maxSkew)
{
skew.x = maxSkew;
_skewDirection = -1;
}
else if (skew.x < minSkew)
{
skew.x = minSkew;
_skewDirection = 1;
}
time += elapsed;

skew.x = SKEW_MIN + (Math.cos(time / SKEW_FREQ * Math.PI) + 1) / 2 * (SKEW_MAX - SKEW_MIN);
}
}
2 changes: 1 addition & 1 deletion Effects/FlxSkewedSprite/source/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class Main extends Sprite
public function new()
{
super();
addChild(new FlxGame(300, 200, PlayState));
addChild(new FlxGame(0, 0, PlayState));
}
}
34 changes: 22 additions & 12 deletions Effects/FlxSkewedSprite/source/PlayState.hx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package;

import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.util.FlxColor;

Expand All @@ -12,18 +13,27 @@ class PlayState extends FlxState
override public function create():Void
{
FlxG.mouse.visible = false;

// Sky-colored background
FlxG.cameras.bgColor = FlxColor.CYAN;

var grassY:Int = FlxG.height - 28;

var grass1:Grass = new Grass(0, grassY, 0, 0);
var grass2:Grass = new Grass(0, grassY, 1, -5);
var grass3:Grass = new Grass(0, grassY, 2, 5);

add(grass1);
add(grass2);
add(grass3);
FlxG.cameras.bgColor = 0xFF4D9BD3;

var bottom = new FlxSprite();
bottom.makeGraphic(FlxG.width, 5, 0xFF161b3a);
bottom.y = FlxG.height - bottom.height;
add(bottom);

var grass:Grass;

// add(grass = new Grass(0, 0, -1, 0));
// grass.y = FlxG.height - grass.height;

add(grass = new Grass(0, 0, 0, 0));
grass.y = bottom.y - grass.height;

add(grass = new Grass(0, 0, 1, -0.2));
grass.y = bottom.y - grass.height;

add(grass = new Grass(0, 0, 2, 0.2));
grass.y = bottom.y - grass.height;
}
}

0 comments on commit cabfd5e

Please sign in to comment.