Skip to content

Commit

Permalink
16/8/21 5:15 PM
Browse files Browse the repository at this point in the history
  • Loading branch information
eboatwright committed Aug 16, 2021
1 parent 5d480c0 commit d96211f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions builtInComponentsAndSystems/rigidBody.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func (rbs *RigidbodySystem) Update(entity *pearl.Entity, scene *pearl.Scene) {
if rb.Gravity.Y < 0 {
rb.Grounded = rb.CoyoteTime
}
t.Position.Y = tileT.Position.Y + tileBc.Size.Y
t.Position.Y = tileT.Position.Y + tileBc.Size.Y - bc.Offset.Y
}
if rb.Velocity.Y > 0 {
if rb.Gravity.Y > 0 {
rb.Grounded = rb.CoyoteTime
}
t.Position.Y = tileT.Position.Y - bc.Size.Y
t.Position.Y = tileT.Position.Y - bc.Size.Y - bc.Offset.Y
}
rb.Velocity.Y = 0
}
Expand All @@ -91,13 +91,13 @@ func (rbs *RigidbodySystem) Update(entity *pearl.Entity, scene *pearl.Scene) {
if rb.Gravity.X < 0 {
rb.Grounded = rb.CoyoteTime
}
t.Position.X = tileT.Position.X + tileBc.Size.X
t.Position.X = tileT.Position.X + tileBc.Size.X - bc.Offset.X
}
if rb.Velocity.X > 0 {
if rb.Gravity.X > 0 {
rb.Grounded = rb.CoyoteTime
}
t.Position.X = tileT.Position.X - bc.Size.X
t.Position.X = tileT.Position.X - bc.Size.X - bc.Offset.X
}
rb.Velocity.X = 0
}
Expand Down
Binary file modified examples/.DS_Store
Binary file not shown.
Binary file modified examples/2-platformer/.DS_Store
Binary file not shown.
5 changes: 3 additions & 2 deletions examples/2-platformer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ func onStart() {
CollisionType: bicas.LevelCollision,
},
&bicas.BoxCollider {
Size: pearl.Vector2 { 16, 16 },
Offset: pearl.Vector2 { 0, 0 },
Size: pearl.Vector2 { 8, 14 },
Offset: pearl.Vector2 { 4, 2 },
},
&Player {
MoveSpeed: 0.8,
JumpHeight: -8,
JumpCutoff: 0.5,
},
})

Expand Down
13 changes: 11 additions & 2 deletions examples/2-platformer/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
type Player struct {
MoveSpeed float64
JumpHeight float64
JumpCutoff float64
}
func (p *Player) ID() string { return "player" }


type PlayerSystem struct {}

func (ps *PlayerSystem) Update(entity *pearl.Entity, scene *pearl.Scene) {
t := entity.GetComponent("transform").(*bicas.Transform)
rb := entity.GetComponent("rigidbody").(*bicas.Rigidbody)
p := entity.GetComponent("player").(*Player)

Expand All @@ -26,16 +28,23 @@ func (ps *PlayerSystem) Update(entity *pearl.Entity, scene *pearl.Scene) {
[]ebiten.Key { ebiten.KeyD, ebiten.KeyRight },
)

if xInput != 0 {
t.Scale.X = float64(xInput)
}

rb.Velocity.X += float64(xInput) * p.MoveSpeed

if pearl.KeyJustPressed(ebiten.KeyW) || pearl.KeyJustPressed(ebiten.KeyUp) {
if (pearl.KeyJustPressed(ebiten.KeyW) || pearl.KeyJustPressed(ebiten.KeyUp)) && rb.Grounded > 0 {
rb.Grounded = 0
rb.Velocity.Y = p.JumpHeight
}
if (pearl.KeyJustReleased(ebiten.KeyW) || pearl.KeyJustReleased(ebiten.KeyUp)) && rb.Velocity.Y < 0 {
rb.Velocity.Y *= p.JumpCutoff
}
}

func (ps *PlayerSystem) Draw(entity *pearl.Entity, scene *pearl.Scene, screen *ebiten.Image, options *ebiten.DrawImageOptions) {}

func (ps *PlayerSystem) GetRequirements() []string {
return []string { "rigidbody", "player" }
return []string { "transform", "rigidbody", "player" }
}

0 comments on commit d96211f

Please sign in to comment.