From d3bf09f173bdbbbf9dbb902753efd92ce7ca72d4 Mon Sep 17 00:00:00 2001 From: Maddy Thorson Date: Wed, 22 Dec 2021 16:57:20 -0800 Subject: [PATCH] Some sample game work (still broken) --- SampleGame/src/Level.bf | 3 ++- SampleGame/src/Player.bf | 45 ++++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/SampleGame/src/Level.bf b/SampleGame/src/Level.bf index 6ad8e46..429d50c 100644 --- a/SampleGame/src/Level.bf +++ b/SampleGame/src/Level.bf @@ -6,7 +6,8 @@ namespace Strawberry.Sample public this() { - Add(new Player(.(50, 50))); + Add(Player.Create(.(50, 50))); + Add(new OldSolid(.(0, 168), .(0, 0, 320, 12))); Add(new OldJumpThru(.(200, 132), 48)); Add(new MovingJumpThru(.(136, 100), 32, .(124, 140), 2f)); diff --git a/SampleGame/src/Player.bf b/SampleGame/src/Player.bf index bf2d4ee..8201370 100644 --- a/SampleGame/src/Player.bf +++ b/SampleGame/src/Player.bf @@ -2,20 +2,36 @@ using System; 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; + private Physics physics; private Timer tJumpGrace; private Timer tVarJump; - public this(Point pos) - : base(pos) + public override void Added() { - Hitbox = Rect(-4, -8, 16, 16); + base.Added(); - Add(tJumpGrace = new Timer()); - Add(tVarJump = new Timer()); + tJumpGrace = Entity.Add(new Timer()); + tVarJump = Entity.Add(new Timer()); + } + + public override void Awake() + { + physics = Entity.First(); } public void Update() @@ -31,7 +47,7 @@ namespace Strawberry.Sample const float runAccel = 800; 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) tJumpGrace.Value = coyoteTime; @@ -80,28 +96,25 @@ namespace Strawberry.Sample } //Resolve Speed - MoveX(Speed.X * Time.Delta, scope => OnCollideX); - MoveY(Speed.Y * Time.Delta, scope => OnCollideY); + physics.MoveX(Speed.X * Time.Delta, scope => OnCollideX); + physics.MoveY(Speed.Y * Time.Delta, scope => OnCollideY); } private void OnCollideX(Collision col) { Speed.X = 0; - ZeroRemainderX(); + physics.ZeroRemainderX(); } private void OnCollideY(Collision col) { Speed.Y = 0; - ZeroRemainderY(); + physics.ZeroRemainderY(); } - public override void Draw() + public void Draw() { - base.Draw(); - - DrawHitboxOutline(.Green); - Game.Batcher.Tex(Assets.Textures["test"], X - 4, Y - 8); + physics.Hitbox.DebugDraw(); } } }