Sample game. Easing methods. Colors.

This commit is contained in:
Matt Thorson
2020-05-08 21:05:29 -07:00
parent 786b692a3f
commit 12ea2e43bc
18 changed files with 545 additions and 20 deletions

View File

@ -26,11 +26,13 @@ namespace Strawberry
public float Value
{
[Inline]
get
{
return value;
}
[Inline]
set
{
this.value = Math.Max(0, value);
@ -38,6 +40,13 @@ namespace Strawberry
}
}
[Inline]
public void Clear()
{
value = 0;
Active = false;
}
public override void Update()
{
if (value > 0)
@ -54,5 +63,10 @@ namespace Strawberry
}
}
}
static public implicit operator bool(Timer timer)
{
return timer.value > 0;
}
}
}

View File

@ -77,8 +77,6 @@ namespace Strawberry
let hit = First<Solid>(.(sign, 0));
if (hit != null)
{
ZeroRemainderX();
let c = Collision(
Point.Right * sign,
Math.Abs(amount),
@ -110,8 +108,6 @@ namespace Strawberry
if (hit != null)
{
ZeroRemainderY();
let c = Collision(
Point.Right * sign,
Math.Abs(amount),

View File

@ -35,6 +35,32 @@ namespace Strawberry
}
}
[Inline]
public void Move(Vector amount)
{
MoveX(amount.X);
MoveY(amount.Y);
}
[Inline]
public void MoveToX(float x)
{
MoveX(x - (X + remainder.X));
}
[Inline]
public void MoveToY(float y)
{
MoveY(y - (Y + remainder.Y));
}
[Inline]
public void MoveTo(Vector target)
{
MoveToX(target.X);
MoveToY(target.Y);
}
public abstract void MoveExactX(int amount);
public abstract void MoveExactY(int amount);
public abstract List<Actor> GetRiders(List<Actor> into);

View File

@ -6,14 +6,7 @@ namespace Strawberry
public this(Point position, int width)
: base(position)
{
Hitbox = Rect(0, 0, width, 6);
}
public override void Update()
{
base.Update();
MoveY(-10 * Time.Delta);
Hitbox = Rect(0, 0, width, 2);
}
public override void MoveExactX(int amount)
@ -80,7 +73,7 @@ namespace Strawberry
public override void Draw()
{
DrawHitbox(.(255, 255, 255, 255));
DrawHitbox(.LightGray);
}
}
}

View File

@ -10,13 +10,6 @@ namespace Strawberry
Hitbox = hitbox;
}
public override void Update()
{
base.Update();
MoveY(0.1f);
}
public override List<Actor> GetRiders(List<Actor> into)
{
for (var a in Scene.All<Actor>(scope List<Actor>))

36
src/Static/Ease.bf Normal file
View File

@ -0,0 +1,36 @@
using System;
namespace Strawberry
{
static public class Ease
{
public delegate float Easer(float t);
static public float CubeIn(float t)
{
return t * t * t;
}
static public float CubeOut(float t)
{
return Invert(t, scope => CubeIn);
}
static public float CubeInOut(float t)
{
return Follow(t, scope => CubeIn, scope => CubeOut);
}
[Inline]
static public float Invert(float t, Easer easer)
{
return 1 - easer(1 - t);
}
[Inline]
static public float Follow(float t, Easer a, Easer b)
{
return (t <= 0.5f) ? a(t * 2) / 2 : b(t * 2 - 1) / 2 + 0.5f;
}
}
}

View File

@ -13,6 +13,9 @@ namespace Strawberry
static public readonly Color Cyan = 0xFF00FFFF;
static public readonly Color Magenta = 0xFFFF00FF;
static public readonly Color Yellow = 0x00FFFFFF;
static public readonly Color DarkGray = 0x3F3F3FFF;
static public readonly Color Gray = 0x7F7F7FFF;
static public readonly Color LightGray = 0xBFBFBFFF;
public uint8 R;
public uint8 G;

View File

@ -51,6 +51,16 @@ namespace Strawberry
return Point((int)Math.Round(X), (int)Math.Round(Y));
}
static public Vector Lerp(Vector a, Vector b, float t)
{
if (t == 0)
return a;
else if (t == 1)
return b;
else
return a + (b - a) * t;
}
public override void ToString(String strBuffer)
{
strBuffer.Set("Vector [ ");