Skip to content

Commit

Permalink
More cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Dec 31, 2020
1 parent 29a4f46 commit 8177cd7
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
3 changes: 3 additions & 0 deletions game/window.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package game

import (
"fmt"

"github.com/bobtfish/mayhem/grid"
"github.com/bobtfish/mayhem/player"
screeniface "github.com/bobtfish/mayhem/screen/iface"
Expand Down Expand Up @@ -52,6 +54,7 @@ func (gw *Window) Update(screen screeniface.GameScreen) screeniface.GameScreen {
newScreen := screen.Step(gw)
gw.Window.Update()
if newScreen != screen {
fmt.Printf("New screen %T %V", newScreen, newScreen)
newScreen.Enter(gw)
return newScreen
}
Expand Down
9 changes: 9 additions & 0 deletions player/spell.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ func (s PlayerSpell) DoCast(illusion bool, target logical.Vec, grid *grid.GameGr
tile := grid.GetGameObject(target)
player, isPlayer := tile.(*Player)
if !isPlayer {
// FIXME - bug here if a player is mounted!
panic(fmt.Sprintf("Player spell '%s' cast on non player - should never happen", s.Name))
/*rideable, isRideable := tile.(*movable.Rideable)
if !isRideable
panic(fmt.Sprintf("Player spell '%s' cast on non player - should never happen", s.Name))
}
player = rideable.GetRider();
if player == nil {
panic(fmt.Sprintf("Player spell '%s' cast on non player - should never happen", s.Name))
}*/
}
s.MutateFunc(player)
return true, nil
Expand Down
5 changes: 4 additions & 1 deletion screen/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

type RangedCombat struct {
*WithCursor
WithCursor
PlayerIdx int
Character movable.Movable
MovedCharacters map[movable.Movable]bool
Expand All @@ -29,6 +29,7 @@ func (screen *RangedCombat) Enter(ctx screeniface.GameCtx) {
fmt.Printf("In ranged combat state\n")
screen.DisplayRange = true
screen.WithCursor.CursorSprite = CursorRangedAttack
screen.WithCursor.CursorPosition = screen.Character.GetBoardPosition()
}

func (screen *RangedCombat) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand All @@ -39,6 +40,7 @@ func (screen *RangedCombat) Step(ctx screeniface.GameCtx) screeniface.GameScreen
attackRange := attacker.GetAttackRange()
if attackRange == 0 || win.JustPressed(pixelgl.Key0) || win.JustPressed(pixelgl.KeyK) { // No ranged combat
return &MoveFindCharacterScreen{
WithCursor: WithCursor{CursorPosition: screen.WithCursor.CursorPosition},
PlayerIdx: screen.PlayerIdx,
MovedCharacters: screen.MovedCharacters,
}
Expand Down Expand Up @@ -137,6 +139,7 @@ func (screen *DoRangedAttack) Step(ctx screeniface.GameCtx) screeniface.GameScre
return &Pause{
Skip: !needPause,
NextScreen: &MoveFindCharacterScreen{
WithCursor: WithCursor{CursorPosition: screen.AttackPosition},
PlayerIdx: screen.PlayerIdx,
MovedCharacters: screen.MovedCharacters,
},
Expand Down
2 changes: 2 additions & 0 deletions screen/castspell.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func (screen *DisplaySpellCastScreen) Step(ctx screeniface.GameCtx) screeniface.
win := ctx.GetWindow()
players := ctx.(*game.Window).GetPlayers()
thisPlayer := players[screen.PlayerIdx]
batch := DrawBoard(ctx)
batch.Draw(win)
if (thisPlayer.ChosenSpell < 0) || win.JustPressed(pixelgl.Key0) {
return NextSpellCastOrMove(screen.PlayerIdx, ctx, true)
}
Expand Down
2 changes: 1 addition & 1 deletion screen/examineboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type ExamineBoardScreen struct {
MainMenu screeniface.GameScreen
*WithCursor
WithCursor
}

func (screen *ExamineBoardScreen) Enter(ctx screeniface.GameCtx) {
Expand Down
7 changes: 4 additions & 3 deletions screen/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ func (screen *MoveAnnounceScreen) Step(ctx screeniface.GameCtx) screeniface.Game
// any other key displays the cursor
if win.JustPressed(pixelgl.KeyS) || captureDirectionKey(win) != logical.ZeroVec() {
return &MoveFindCharacterScreen{
WithCursor: &WithCursor{CursorPosition: players[screen.PlayerIdx].BoardPosition},
WithCursor: WithCursor{CursorPosition: players[screen.PlayerIdx].BoardPosition},
PlayerIdx: screen.PlayerIdx,
}
}
return screen
}

type MoveFindCharacterScreen struct {
*WithCursor
WithCursor
PlayerIdx int
MovedCharacters map[movable.Movable]bool
}
Expand Down Expand Up @@ -453,7 +453,7 @@ func (screen *MoveGroundCharacterScreen) MoveGroundCharacterScreenFinished() scr
}

type MoveFlyingCharacterScreen struct {
*WithCursor
WithCursor
PlayerIdx int
Character movable.Movable
OutOfRange bool
Expand All @@ -467,6 +467,7 @@ func (screen *MoveFlyingCharacterScreen) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
screen.WithCursor.CursorSprite = CursorFly
screen.WithCursor.CursorPosition = screen.Character.GetBoardPosition()
fmt.Printf("Enter move flying character screen for player %d\n", screen.PlayerIdx+1)
screen.DisplayRange = true // Set this to start to suppress cursor till we move it
}
Expand Down
13 changes: 1 addition & 12 deletions screen/waitfor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,27 @@ import (
"time"

"github.com/bobtfish/mayhem/fx"
"github.com/bobtfish/mayhem/grid"
"github.com/bobtfish/mayhem/render"
screeniface "github.com/bobtfish/mayhem/screen/iface"
)

type WaitFor struct {
NextScreen screeniface.GameScreen
Grid *grid.GameGrid
FinishedF func() bool
}

func (screen *WaitFor) Enter(ctx screeniface.GameCtx) {}

func (screen *WaitFor) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
win := ctx.GetWindow()
ss := ctx.GetSpriteSheet()
if screen.FinishedF() {
//fmt.Printf("Waitfor Skip to next screen\n")
return screen.NextScreen
}
if screen.Grid != nil {
screen.Grid.DrawBatch(render.NewSpriteDrawer(ss).WithOffset(render.GameBoardV())).Draw(win)
}
DrawBoard(ctx).Draw(ctx.GetWindow())
return screen
}

type Pause struct {
NextScreen screeniface.GameScreen
Grid *grid.GameGrid
Skip bool
For time.Duration
}
Expand All @@ -47,7 +39,6 @@ func (screen *Pause) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
started := time.Now()
return &WaitFor{
NextScreen: screen.NextScreen,
Grid: screen.Grid,
FinishedF: func() bool {
return screen.Skip || started.Add(screen.For).Before(time.Now())
},
Expand All @@ -57,15 +48,13 @@ func (screen *Pause) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
type WaitForFx struct {
Fx *fx.Fx
NextScreen screeniface.GameScreen
Grid *grid.GameGrid
}

func (screen *WaitForFx) Enter(ctx screeniface.GameCtx) {}

func (screen *WaitForFx) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
return &WaitFor{
NextScreen: screen.NextScreen,
Grid: screen.Grid,
FinishedF: func() bool {
return screen.Fx == nil || screen.Fx.RemoveMe()
},
Expand Down

0 comments on commit 8177cd7

Please sign in to comment.