diff options
author | davidovski <david@davidovski.xyz> | 2024-04-22 08:27:52 +0100 |
---|---|---|
committer | davidovski <david@davidovski.xyz> | 2024-04-22 08:27:52 +0100 |
commit | c1b9a2cb21df181b140a449223e3bf650ab1ec68 (patch) | |
tree | bcecc05a589053503237677005f6a13e4269dd17 /objects.go | |
parent | 9af752349c40be745d1296d95675916f95977890 (diff) |
create main gameplay loop
Diffstat (limited to 'objects.go')
-rw-r--r-- | objects.go | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -134,6 +134,20 @@ func (object * GameObject) Collide(other *GameObject) bool { return ! ( minX2 >= maxX1 || maxX2 <= minX1 || minY2 >= maxY1 || maxY2 <= minY1) } +func (object * GameObject) Jump() { + if object.onGround { + object.vy += -jumpHeight + } +} + +func (object * GameObject) MoveLeft() { + object.vx = -playerSpeed +} +func (object * GameObject) MoveRight() { + object.vx = playerSpeed +} + + func (object * GameObject) ToRect() image.Rectangle { width := object.image.Bounds().Dx() height := object.image.Bounds().Dy() @@ -177,6 +191,10 @@ func NewExit(game *Game, x, y float32) *GameObject{ exit := NewObject(game, x, y) exit.image = tilesImage.SubImage(image.Rect(0, 16, 32, 48)).(*ebiten.Image) + exit.onCollideUp = OnCollideExit + exit.onCollideDown = OnCollideExit + exit.onCollideLeft = OnCollideExit + exit.onCollideRight = OnCollideExit return exit } @@ -218,6 +236,13 @@ func NewLeftSpike(game *Game, x, y float32) *GameObject{ return spike } +func OnCollideExit(this, other *GameObject) bool { + if other == this.game.player { + this.game.EndLevel() + } + return false +} + func OnCollideSpring(this, other *GameObject) bool { other.vy -= SPRING_FORCE other.onGround = true @@ -226,7 +251,7 @@ func OnCollideSpring(this, other *GameObject) bool { func OnCollideSpike(this, other *GameObject) bool { if other == this.game.player { - other.game.ResetAll() + other.game.KillPlayer() } return true } |