mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-06-29 19:05:26 +08:00
Sample game. Easing methods. Colors.
This commit is contained in:
8
SampleGame/BeefProj.toml
Normal file
8
SampleGame/BeefProj.toml
Normal file
@ -0,0 +1,8 @@
|
||||
FileVersion = 1
|
||||
Dependencies = {corlib = "*", SDL2 = "*", Strawberry = "*"}
|
||||
|
||||
[Project]
|
||||
Name = "SampleGame"
|
||||
TargetType = "BeefGUIApplication"
|
||||
StartupObject = "Strawberry.Sample.Program"
|
||||
DefaultNamespace = "Strawberry.Sample"
|
5
SampleGame/BeefSpace.toml
Normal file
5
SampleGame/BeefSpace.toml
Normal file
@ -0,0 +1,5 @@
|
||||
FileVersion = 1
|
||||
Projects = {SampleGame = {Path = "."}, Strawberry = {Path = ".."}, SDL2 = "*"}
|
||||
|
||||
[Workspace]
|
||||
StartupProject = "SampleGame"
|
218
SampleGame/BeefSpace_User.toml
Normal file
218
SampleGame/BeefSpace_User.toml
Normal file
@ -0,0 +1,218 @@
|
||||
FileVersion = 1
|
||||
LastConfig = "Debug"
|
||||
LastPlatform = "Win64"
|
||||
RecentFilesList = ["c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Static\\Ease.bf", "c:\\Program Files\\BeefLang\\BeefLibs\\corlib\\src\\Action.bf", "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\MovingJumpThru.bf", "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\Player.bf", "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Struct\\Color.bf", "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\Level.bf", "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Physics\\JumpThru.bf", "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Components\\Timer.bf", "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Physics\\Actor.bf", "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Physics\\Solid.bf"]
|
||||
|
||||
[MainWindow]
|
||||
X = 64
|
||||
Y = 64
|
||||
Width = 1200
|
||||
Height = 1024
|
||||
ShowKind = "Maximized"
|
||||
|
||||
[MainDockingFrame]
|
||||
Type = "DockingFrame"
|
||||
SplitType = 2
|
||||
|
||||
[[MainDockingFrame.DockedWidgets]]
|
||||
RequestedWidth = 500.0
|
||||
RequestedHeight = 350.0
|
||||
SizePriority = 350.0
|
||||
Type = "DockingFrame"
|
||||
SplitType = 1
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets]]
|
||||
RequestedWidth = 350.0
|
||||
RequestedHeight = 350.0
|
||||
Type = "TabbedView"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
Active = true
|
||||
TabLabel = "Workspace"
|
||||
TabWidth = 111.7143
|
||||
Type = "ProjectPanel"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets]]
|
||||
IsFillWidget = true
|
||||
Permanent = true
|
||||
RequestedWidth = 150.0
|
||||
RequestedHeight = 150.0
|
||||
SizePriority = 150.0
|
||||
DefaultDocumentsTabbedView = true
|
||||
Type = "TabbedView"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Action.bf"
|
||||
TabWidth = 89.14286
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Program Files\\BeefLang\\BeefLibs\\corlib\\src\\Action.bf"
|
||||
ProjectName = "corlib"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
Active = true
|
||||
TabLabel = "Ease.bf"
|
||||
TabWidth = 78.85714
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Static\\Ease.bf"
|
||||
CursorPos = 206
|
||||
ProjectName = "Strawberry"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "MovingJumpThru.bf"
|
||||
TabWidth = 151.4286
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\MovingJumpThru.bf"
|
||||
CursorPos = 406
|
||||
ProjectName = "SampleGame"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Color.bf"
|
||||
TabWidth = 83.42857
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Struct\\Color.bf"
|
||||
CursorPos = 588
|
||||
ProjectName = "Strawberry"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Timer.bf"
|
||||
TabWidth = 85.14286
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Components\\Timer.bf"
|
||||
CursorPos = 530
|
||||
VertPos = 130.0
|
||||
ProjectName = "Strawberry"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Actor.bf"
|
||||
TabWidth = 82.85714
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Physics\\Actor.bf"
|
||||
CursorPos = 2066
|
||||
VertPos = 2522.0
|
||||
ProjectName = "Strawberry"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "JumpThru.bf"
|
||||
TabWidth = 109.1429
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Physics\\JumpThru.bf"
|
||||
CursorPos = 1409
|
||||
VertPos = 1430.0
|
||||
ProjectName = "Strawberry"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Solid.bf"
|
||||
TabWidth = 81.71429
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\src\\Physics\\Solid.bf"
|
||||
CursorPos = 174
|
||||
ProjectName = "Strawberry"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Controls.bf"
|
||||
TabWidth = 90.57143
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\Controls.bf"
|
||||
CursorPos = 433
|
||||
ProjectName = "SampleGame"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Player.bf"
|
||||
TabWidth = 76.85714
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\Player.bf"
|
||||
CursorPos = 2419
|
||||
VertPos = 2180.5
|
||||
ProjectName = "SampleGame"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Level.bf"
|
||||
TabWidth = 72.85714
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\Level.bf"
|
||||
CursorPos = 190
|
||||
ProjectName = "SampleGame"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "SampleGame.bf"
|
||||
TabWidth = 118.0
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\SampleGame.bf"
|
||||
CursorPos = 169
|
||||
ProjectName = "SampleGame"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Program.bf"
|
||||
TabWidth = 92.28571
|
||||
Type = "SourceViewPanel"
|
||||
FilePath = "c:\\Users\\Matt\\Documents\\Projects\\Strawberry\\SampleGame\\src\\Program.bf"
|
||||
CursorPos = 166
|
||||
ProjectName = "SampleGame"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets]]
|
||||
RequestedWidth = 437.0
|
||||
RequestedHeight = 327.0
|
||||
Type = "DockingFrame"
|
||||
SplitType = 1
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets]]
|
||||
RequestedWidth = 437.0
|
||||
RequestedHeight = 437.0
|
||||
SizePriority = 2558.0
|
||||
Type = "TabbedView"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
Active = true
|
||||
TabLabel = "Memory"
|
||||
TabWidth = 98.0
|
||||
Type = "MemoryPanel"
|
||||
AutoResize = "Auto_Mul8"
|
||||
RequestedWidth = 300.0
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Watch"
|
||||
TabWidth = 84.28571
|
||||
Type = "WatchPanel"
|
||||
Columns = [{Width = 200.0}, {Width = 200.0}, {Width = 200.0}]
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Auto"
|
||||
TabWidth = 76.28571
|
||||
Type = "AutoWatchPanel"
|
||||
Columns = [{Width = 200.0}, {Width = 200.0}, {Width = 200.0}]
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets]]
|
||||
RequestedWidth = 437.0
|
||||
RequestedHeight = 437.0
|
||||
SizePriority = 2558.0
|
||||
Type = "TabbedView"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Find Results"
|
||||
TabWidth = 114.5714
|
||||
Type = "FindResultsPanel"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Threads"
|
||||
TabWidth = 94.0
|
||||
Type = "ThreadPanel"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Call Stack"
|
||||
TabWidth = 102.0
|
||||
Type = "CallStackPanel"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
TabLabel = "Immediate"
|
||||
TabWidth = 109.4286
|
||||
Type = "ImmediatePanel"
|
||||
|
||||
[[MainDockingFrame.DockedWidgets.DockedWidgets.Tabs]]
|
||||
Active = true
|
||||
TabLabel = "Output"
|
||||
TabWidth = 88.85714
|
||||
Type = "OutputPanel"
|
||||
|
||||
[DebuggerDisplayTypes.""]
|
||||
IntDisplayType = "Default"
|
||||
MmDisplayType = "Default"
|
22
SampleGame/src/Controls.bf
Normal file
22
SampleGame/src/Controls.bf
Normal file
@ -0,0 +1,22 @@
|
||||
namespace Strawberry.Sample
|
||||
{
|
||||
static public class Controls
|
||||
{
|
||||
static public VirtualAxis MoveX;
|
||||
static public VirtualButton Jump;
|
||||
|
||||
static public void Init()
|
||||
{
|
||||
Jump = new VirtualButton()
|
||||
.AddKey(.Space)
|
||||
.AddKey(.X)
|
||||
.AddButton(0, .A)
|
||||
.PressBuffer(0.1f);
|
||||
|
||||
MoveX = new VirtualAxis()
|
||||
.AddKeys(.Left, .Right, .TakeNewer)
|
||||
.AddButtons(0, .DpadLeft, .DpadRight, .TakeNewer)
|
||||
.AddAxis(0, .LeftX, 0.3f);
|
||||
}
|
||||
}
|
||||
}
|
13
SampleGame/src/Level.bf
Normal file
13
SampleGame/src/Level.bf
Normal file
@ -0,0 +1,13 @@
|
||||
namespace Strawberry.Sample
|
||||
{
|
||||
public class Level : Scene
|
||||
{
|
||||
public this()
|
||||
{
|
||||
Add(new Player(.(50, 50)));
|
||||
Add(new Solid(.(0, 168), .(0, 0, 320, 12)));
|
||||
Add(new JumpThru(.(200, 132), 48));
|
||||
Add(new MovingJumpThru(.(136, 100), 32, .(124, 140), 2f));
|
||||
}
|
||||
}
|
||||
}
|
50
SampleGame/src/MovingJumpThru.bf
Normal file
50
SampleGame/src/MovingJumpThru.bf
Normal file
@ -0,0 +1,50 @@
|
||||
namespace Strawberry.Sample
|
||||
{
|
||||
public class MovingJumpThru : JumpThru
|
||||
{
|
||||
private Point moveFrom;
|
||||
private Point moveTo;
|
||||
private float moveTime;
|
||||
|
||||
private float movingLerp;
|
||||
private bool movingPositive;
|
||||
|
||||
public this(Point pos, int width, Point moveTo, float moveTime)
|
||||
: base(pos, width)
|
||||
{
|
||||
moveFrom = Position;
|
||||
this.moveTo = moveTo;
|
||||
this.moveTime = moveTime;
|
||||
|
||||
movingLerp = 0;
|
||||
movingPositive = true;
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (movingPositive)
|
||||
{
|
||||
movingLerp += Time.Delta / moveTime;
|
||||
if (movingLerp >= 1)
|
||||
{
|
||||
movingLerp = 1;
|
||||
movingPositive = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
movingLerp -= Time.Delta / moveTime;
|
||||
if (movingLerp <= 0)
|
||||
{
|
||||
movingLerp = 0;
|
||||
movingPositive = true;
|
||||
}
|
||||
}
|
||||
|
||||
let target = Vector.Lerp(moveFrom, moveTo, Ease.CubeInOut(movingLerp));
|
||||
MoveTo(target);
|
||||
}
|
||||
}
|
||||
}
|
108
SampleGame/src/Player.bf
Normal file
108
SampleGame/src/Player.bf
Normal file
@ -0,0 +1,108 @@
|
||||
using System;
|
||||
|
||||
namespace Strawberry.Sample
|
||||
{
|
||||
public class Player : Actor
|
||||
{
|
||||
public Vector Speed;
|
||||
|
||||
private Timer tJumpGrace;
|
||||
private Timer tVarJump;
|
||||
|
||||
public this(Point pos)
|
||||
: base(pos)
|
||||
{
|
||||
Hitbox = Rect(-4, -8, 8, 8);
|
||||
|
||||
Add(tJumpGrace = new Timer());
|
||||
Add(tVarJump = new Timer());
|
||||
}
|
||||
|
||||
public override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
const float coyoteTime = 0.1f; // Time after leaving a ledge when you can still jump
|
||||
const float varJumpTime = 0.2f; // Time after jumping that you can hold the jump button to continue gaining upward speed
|
||||
const float jumpSpeed = -160;
|
||||
const float jumpXBoost = 30; // If left or right is held at the moment of a jump, this horizontal speed boost is applied
|
||||
const float maxFall = 160;
|
||||
const float gravity = 1000;
|
||||
const float halfGravThreshold = 40; // Halves gravity at the peak of a jump, if the jump button is held
|
||||
const float maxRun = 100;
|
||||
const float runAccel = 800;
|
||||
const float runAccelAirMult = 0.8f; // Gives you slightly less control of horizontal motion in the air
|
||||
|
||||
let onGround = GroundCheck();
|
||||
if (onGround)
|
||||
tJumpGrace.Value = coyoteTime;
|
||||
|
||||
//Vertical Control
|
||||
{
|
||||
//Jumping
|
||||
if (tJumpGrace && Controls.Jump.Pressed)
|
||||
{
|
||||
Controls.Jump.ClearPressBuffer();
|
||||
tJumpGrace.Clear();
|
||||
tVarJump.Value = varJumpTime;
|
||||
Speed.Y = jumpSpeed;
|
||||
Speed.X += jumpXBoost * Controls.MoveX.Valuei;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Gravity
|
||||
{
|
||||
float mult;
|
||||
if (Controls.Jump.Check && Math.Abs(Speed.Y) <= halfGravThreshold)
|
||||
mult = 0.5f;
|
||||
else
|
||||
mult = 1;
|
||||
|
||||
Speed.Y = Calc.Approach(Speed.Y, maxFall, gravity * mult * Time.Delta);
|
||||
}
|
||||
|
||||
//Variable Jumping
|
||||
if (tVarJump)
|
||||
{
|
||||
if (Controls.Jump.Check)
|
||||
Speed.Y = jumpSpeed;
|
||||
else
|
||||
tVarJump.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Horizontal Control
|
||||
{
|
||||
float accel = runAccel;
|
||||
if (!onGround)
|
||||
accel *= runAccelAirMult;
|
||||
|
||||
Speed.X = Calc.Approach(Speed.X, Controls.MoveX.Valuei * maxRun, accel * Time.Delta);
|
||||
}
|
||||
|
||||
//Resolve Speed
|
||||
MoveX(Speed.X * Time.Delta, scope => OnCollideX);
|
||||
MoveY(Speed.Y * Time.Delta, scope => OnCollideY);
|
||||
}
|
||||
|
||||
private void OnCollideX(Collision col)
|
||||
{
|
||||
Speed.X = 0;
|
||||
ZeroRemainderX();
|
||||
}
|
||||
|
||||
private void OnCollideY(Collision col)
|
||||
{
|
||||
Speed.Y = 0;
|
||||
ZeroRemainderY();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
base.Draw();
|
||||
|
||||
DrawHitbox(.Red);
|
||||
}
|
||||
}
|
||||
}
|
14
SampleGame/src/Program.bf
Normal file
14
SampleGame/src/Program.bf
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Strawberry.Sample
|
||||
{
|
||||
static public class Program
|
||||
{
|
||||
static public int Main(String[] args)
|
||||
{
|
||||
let game = scope SampleGame();
|
||||
game.Run();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
14
SampleGame/src/SampleGame.bf
Normal file
14
SampleGame/src/SampleGame.bf
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
|
||||
namespace Strawberry.Sample
|
||||
{
|
||||
public class SampleGame : Game
|
||||
{
|
||||
public this()
|
||||
: base("Strawberry Sample Game!", 320, 180, 3)
|
||||
{
|
||||
Controls.Init();
|
||||
Scene = new Level();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user