lotsa fixes:
- fixed obstacle collision and death on obstacle spike - moved player move into separate loop after other collision checks are done - fixed level setup, generation and selection - added test levels for obstacles
This commit is contained in:
parent
646b227b8e
commit
f696660ccd
17
assets/levels/00-deadly-obstacles.lvl
Normal file
17
assets/levels/00-deadly-obstacles.lvl
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
Description: test obstacles
|
||||||
|
Background: background-lila
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#######
|
||||||
|
# v #
|
||||||
|
# #
|
||||||
|
#> S <#
|
||||||
|
# #
|
||||||
|
# ^ #
|
||||||
|
#######
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
17
assets/levels/01-friendly-obstacles.lvl
Normal file
17
assets/levels/01-friendly-obstacles.lvl
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
Description: test obstacles
|
||||||
|
Background: background-lila
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#######
|
||||||
|
# ^ #
|
||||||
|
# #
|
||||||
|
#< S >#
|
||||||
|
# #
|
||||||
|
#^ v#
|
||||||
|
#######
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -128,8 +128,8 @@ func InitTiles() TileRegistry {
|
|||||||
'+': NewTileObstacle("obstacle-star", config.All),
|
'+': NewTileObstacle("obstacle-star", config.All),
|
||||||
'^': NewTileObstacle("obstacle-north", config.North),
|
'^': NewTileObstacle("obstacle-north", config.North),
|
||||||
'v': NewTileObstacle("obstacle-south", config.South),
|
'v': NewTileObstacle("obstacle-south", config.South),
|
||||||
'<': NewTileObstacle("obstacle-east", config.East),
|
'<': NewTileObstacle("obstacle-west", config.West),
|
||||||
'>': NewTileObstacle("obstacle-west", config.West),
|
'>': NewTileObstacle("obstacle-east", config.East),
|
||||||
'*': NewTileParticle([]string{
|
'*': NewTileParticle([]string{
|
||||||
//"particle-ring-1",
|
//"particle-ring-1",
|
||||||
"particle-ring-2",
|
"particle-ring-2",
|
||||||
|
|||||||
@ -72,9 +72,9 @@ func (position *Position) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (position *Position) Move(velocity *Velocity, speed *Speed) {
|
func (position *Position) Move(velocity *Velocity, speed *Speed) {
|
||||||
if velocity.Direction != 0 {
|
// if velocity.Direction != 0 {
|
||||||
slog.Debug("moving", "velocity", velocity, "speed", speed)
|
// slog.Debug("moving", "velocity", velocity, "speed", speed)
|
||||||
}
|
// }
|
||||||
position.Update(
|
position.Update(
|
||||||
position.X+(velocity.Data.X*speed.Value),
|
position.X+(velocity.Data.X*speed.Value),
|
||||||
position.Y+(velocity.Data.Y*speed.Value),
|
position.Y+(velocity.Data.Y*speed.Value),
|
||||||
|
|||||||
@ -50,6 +50,8 @@ func (scene *AboutScene) ResetNext() {
|
|||||||
scene.Next = scene.Whoami
|
scene.Next = scene.Whoami
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scene *AboutScene) SetLevel(level int) {}
|
||||||
|
|
||||||
func (scene *AboutScene) Clearscreen() bool {
|
func (scene *AboutScene) Clearscreen() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ func NewGame(width, height, cellsize, startlevel int, startscene SceneName) *Gam
|
|||||||
game.Scenes[Menu] = NewMenuScene(game)
|
game.Scenes[Menu] = NewMenuScene(game)
|
||||||
game.Scenes[About] = NewAboutScene(game)
|
game.Scenes[About] = NewAboutScene(game)
|
||||||
game.Scenes[Popup] = NewPopupScene(game)
|
game.Scenes[Popup] = NewPopupScene(game)
|
||||||
//game.Scenes[Play] = NewLevelScene(game, startlevel)
|
game.Scenes[Play] = NewLevelScene(game, startlevel)
|
||||||
game.Scenes[Select] = NewSelectScene(game)
|
game.Scenes[Select] = NewSelectScene(game)
|
||||||
|
|
||||||
game.CurrentScene = startscene
|
game.CurrentScene = startscene
|
||||||
@ -94,7 +94,8 @@ func (game *Game) Update() error {
|
|||||||
|
|
||||||
if next == Play {
|
if next == Play {
|
||||||
// fresh setup of actual level every time we enter the play scene
|
// fresh setup of actual level every time we enter the play scene
|
||||||
game.Scenes[Play] = NewLevelScene(game, gameobserver.CurrentLevel)
|
//game.Scenes[Play] = NewLevelScene(game, gameobserver.CurrentLevel)
|
||||||
|
game.Scenes[Play].SetLevel(gameobserver.CurrentLevel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// make sure we stay on the selected scene
|
// make sure we stay on the selected scene
|
||||||
|
|||||||
@ -18,10 +18,10 @@ type LevelScene struct {
|
|||||||
|
|
||||||
// Implements the actual playing Scene
|
// Implements the actual playing Scene
|
||||||
func NewLevelScene(game *Game, startlevel int) Scene {
|
func NewLevelScene(game *Game, startlevel int) Scene {
|
||||||
scene := &LevelScene{CurrentLevel: startlevel, Whoami: Play, Next: Play, Game: game}
|
scene := &LevelScene{Whoami: Play, Next: Play, Game: game}
|
||||||
|
|
||||||
scene.GenerateLevels(game)
|
scene.GenerateLevels(game)
|
||||||
scene.Levels[scene.CurrentLevel].SetupGrid(game)
|
scene.SetLevel(startlevel)
|
||||||
|
|
||||||
return scene
|
return scene
|
||||||
}
|
}
|
||||||
@ -34,6 +34,11 @@ func (scene *LevelScene) GenerateLevels(game *Game) {
|
|||||||
scene.Game.Levels = scene.Levels
|
scene.Game.Levels = scene.Levels
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scene *LevelScene) SetLevel(level int) {
|
||||||
|
scene.CurrentLevel = level
|
||||||
|
scene.Levels[scene.CurrentLevel].SetupGrid(scene.Game)
|
||||||
|
}
|
||||||
|
|
||||||
// Interface methods
|
// Interface methods
|
||||||
func (scene *LevelScene) SetNext(next SceneName) {
|
func (scene *LevelScene) SetNext(next SceneName) {
|
||||||
scene.Next = next
|
scene.Next = next
|
||||||
@ -53,7 +58,6 @@ func (scene *LevelScene) Clearscreen() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (scene *LevelScene) Update() error {
|
func (scene *LevelScene) Update() error {
|
||||||
|
|
||||||
scene.Levels[scene.CurrentLevel].Update()
|
scene.Levels[scene.CurrentLevel].Update()
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
@ -37,6 +37,8 @@ func (scene *MenuScene) ResetNext() {
|
|||||||
scene.Next = scene.Whoami
|
scene.Next = scene.Whoami
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scene *MenuScene) SetLevel(level int) {}
|
||||||
|
|
||||||
func (scene *MenuScene) SetNext(next SceneName) {
|
func (scene *MenuScene) SetNext(next SceneName) {
|
||||||
slog.Debug("select setnext", "next", next)
|
slog.Debug("select setnext", "next", next)
|
||||||
scene.Next = next
|
scene.Next = next
|
||||||
|
|||||||
@ -58,6 +58,8 @@ func (scene *NextlevelScene) Update() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scene *NextlevelScene) SetLevel(level int) {}
|
||||||
|
|
||||||
func (scene *NextlevelScene) Draw(screen *ebiten.Image) {
|
func (scene *NextlevelScene) Draw(screen *ebiten.Image) {
|
||||||
background := assets.Assets["background-popup"]
|
background := assets.Assets["background-popup"]
|
||||||
|
|
||||||
|
|||||||
@ -41,6 +41,8 @@ func (scene *PopupScene) SetNext(next SceneName) {
|
|||||||
scene.Next = next
|
scene.Next = next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scene *PopupScene) SetLevel(level int) {}
|
||||||
|
|
||||||
func (scene *PopupScene) Clearscreen() bool {
|
func (scene *PopupScene) Clearscreen() bool {
|
||||||
// both level_scene AND the popup must not clear to get an actual popup
|
// both level_scene AND the popup must not clear to get an actual popup
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -26,6 +26,7 @@ type Scene interface {
|
|||||||
ResetNext()
|
ResetNext()
|
||||||
Clearscreen() bool
|
Clearscreen() bool
|
||||||
Update() error
|
Update() error
|
||||||
|
SetLevel(int)
|
||||||
Draw(screen *ebiten.Image)
|
Draw(screen *ebiten.Image)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,6 +3,7 @@ package game
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
"log/slog"
|
||||||
"openquell/assets"
|
"openquell/assets"
|
||||||
"openquell/gameui"
|
"openquell/gameui"
|
||||||
"openquell/observers"
|
"openquell/observers"
|
||||||
@ -31,6 +32,8 @@ func NewSelectScene(game *Game) Scene {
|
|||||||
return scene
|
return scene
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scene *SelectScene) SetLevel(level int) {}
|
||||||
|
|
||||||
func (scene *SelectScene) GetNext() SceneName {
|
func (scene *SelectScene) GetNext() SceneName {
|
||||||
return scene.Next
|
return scene.Next
|
||||||
}
|
}
|
||||||
@ -79,6 +82,7 @@ func (scene *SelectScene) SetupUI() {
|
|||||||
levels = append(levels, LevelEntry{Id: id, Name: scene.Game.Levels[id].Name})
|
levels = append(levels, LevelEntry{Id: id, Name: scene.Game.Levels[id].Name})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slog.Debug("levels", "levels", levels)
|
||||||
buttonImage, err := gameui.LoadButtonImage()
|
buttonImage, err := gameui.LoadButtonImage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@ -36,6 +36,8 @@ func (scene *WelcomeScene) ResetNext() {
|
|||||||
scene.Next = scene.Whoami
|
scene.Next = scene.Whoami
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (scene *WelcomeScene) SetLevel(level int) {}
|
||||||
|
|
||||||
func (scene *WelcomeScene) Clearscreen() bool {
|
func (scene *WelcomeScene) Clearscreen() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -52,7 +52,7 @@ func (system *ObstacleSystem) Update() {
|
|||||||
playerposition := (*Position)(system.World.Get(player, posID))
|
playerposition := (*Position)(system.World.Get(player, posID))
|
||||||
playervelocity := (*Velocity)(system.World.Get(player, veloID))
|
playervelocity := (*Velocity)(system.World.Get(player, veloID))
|
||||||
|
|
||||||
ok, newpos := playerposition.Intersects(obsposition, playervelocity)
|
ok, newpos := obsposition.Intersects(playerposition, playervelocity)
|
||||||
if ok {
|
if ok {
|
||||||
slog.Debug("bumped into obstacle", "obstacle", obstacle)
|
slog.Debug("bumped into obstacle", "obstacle", obstacle)
|
||||||
|
|
||||||
|
|||||||
@ -36,7 +36,7 @@ func (system PlayerSystem) Update() error {
|
|||||||
query := system.Selector.Query(system.World)
|
query := system.Selector.Query(system.World)
|
||||||
|
|
||||||
for query.Next() {
|
for query.Next() {
|
||||||
playerposition, velocity, _, _, speed := query.Get()
|
playerposition, velocity, _, _, _ := query.Get()
|
||||||
|
|
||||||
if !velocity.Moving() {
|
if !velocity.Moving() {
|
||||||
switch {
|
switch {
|
||||||
@ -71,14 +71,19 @@ func (system PlayerSystem) Update() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
playerposition.Move(velocity, speed)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
system.Particle.Update()
|
system.Particle.Update() // may set player position
|
||||||
system.Obstacle.Update()
|
system.Obstacle.Update()
|
||||||
system.Collectible.Update()
|
system.Collectible.Update()
|
||||||
|
|
||||||
|
query = system.Selector.Query(system.World)
|
||||||
|
for query.Next() {
|
||||||
|
// move player after obstacle or collectible updates
|
||||||
|
playerposition, velocity, _, _, speed := query.Get()
|
||||||
|
playerposition.Move(velocity, speed)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user