mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Some sample game work (still broken)
This commit is contained in:
parent
11732daf5d
commit
d3bf09f173
|
@ -6,7 +6,8 @@ namespace Strawberry.Sample
|
||||||
|
|
||||||
public this()
|
public this()
|
||||||
{
|
{
|
||||||
Add(new Player(.(50, 50)));
|
Add(Player.Create(.(50, 50)));
|
||||||
|
|
||||||
Add(new OldSolid(.(0, 168), .(0, 0, 320, 12)));
|
Add(new OldSolid(.(0, 168), .(0, 0, 320, 12)));
|
||||||
Add(new OldJumpThru(.(200, 132), 48));
|
Add(new OldJumpThru(.(200, 132), 48));
|
||||||
Add(new MovingJumpThru(.(136, 100), 32, .(124, 140), 2f));
|
Add(new MovingJumpThru(.(136, 100), 32, .(124, 140), 2f));
|
||||||
|
|
|
@ -2,20 +2,36 @@ using System;
|
||||||
|
|
||||||
namespace Strawberry.Sample
|
namespace Strawberry.Sample
|
||||||
{
|
{
|
||||||
public class Player : Component, IUpdate
|
public class Player : Component, IUpdate, IDraw
|
||||||
{
|
{
|
||||||
|
static public Entity Create(Point pos)
|
||||||
|
{
|
||||||
|
let e = new Entity(pos);
|
||||||
|
|
||||||
|
e.Add(new Player());
|
||||||
|
let hitbox = e.Add(new Hitbox(-4, -8, 16, 16));
|
||||||
|
e.Add(new Physics(hitbox));
|
||||||
|
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
public Vector Speed;
|
public Vector Speed;
|
||||||
|
|
||||||
|
private Physics physics;
|
||||||
private Timer tJumpGrace;
|
private Timer tJumpGrace;
|
||||||
private Timer tVarJump;
|
private Timer tVarJump;
|
||||||
|
|
||||||
public this(Point pos)
|
public override void Added()
|
||||||
: base(pos)
|
|
||||||
{
|
{
|
||||||
Hitbox = Rect(-4, -8, 16, 16);
|
base.Added();
|
||||||
|
|
||||||
Add(tJumpGrace = new Timer());
|
tJumpGrace = Entity.Add(new Timer());
|
||||||
Add(tVarJump = new Timer());
|
tVarJump = Entity.Add(new Timer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Awake()
|
||||||
|
{
|
||||||
|
physics = Entity.First<Physics>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
|
@ -31,7 +47,7 @@ namespace Strawberry.Sample
|
||||||
const float runAccel = 800;
|
const float runAccel = 800;
|
||||||
const float runAccelAirMult = 0.8f; // Gives you slightly less control of horizontal motion in the air
|
const float runAccelAirMult = 0.8f; // Gives you slightly less control of horizontal motion in the air
|
||||||
|
|
||||||
let onGround = GroundCheck();
|
let onGround = physics.GroundCheck();
|
||||||
if (onGround)
|
if (onGround)
|
||||||
tJumpGrace.Value = coyoteTime;
|
tJumpGrace.Value = coyoteTime;
|
||||||
|
|
||||||
|
@ -80,28 +96,25 @@ namespace Strawberry.Sample
|
||||||
}
|
}
|
||||||
|
|
||||||
//Resolve Speed
|
//Resolve Speed
|
||||||
MoveX(Speed.X * Time.Delta, scope => OnCollideX);
|
physics.MoveX(Speed.X * Time.Delta, scope => OnCollideX);
|
||||||
MoveY(Speed.Y * Time.Delta, scope => OnCollideY);
|
physics.MoveY(Speed.Y * Time.Delta, scope => OnCollideY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCollideX(Collision col)
|
private void OnCollideX(Collision col)
|
||||||
{
|
{
|
||||||
Speed.X = 0;
|
Speed.X = 0;
|
||||||
ZeroRemainderX();
|
physics.ZeroRemainderX();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCollideY(Collision col)
|
private void OnCollideY(Collision col)
|
||||||
{
|
{
|
||||||
Speed.Y = 0;
|
Speed.Y = 0;
|
||||||
ZeroRemainderY();
|
physics.ZeroRemainderY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Draw()
|
public void Draw()
|
||||||
{
|
{
|
||||||
base.Draw();
|
physics.Hitbox.DebugDraw();
|
||||||
|
|
||||||
DrawHitboxOutline(.Green);
|
|
||||||
Game.Batcher.Tex(Assets.Textures["test"], X - 4, Y - 8);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user