Skip to content

Commit

Permalink
Add a load of things I'm using for reference
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Jul 18, 2020
1 parent 50ff76f commit f8e92a9
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 103 deletions.
13 changes: 13 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
https://web.archive.org/web/19991006003843/http://www.gre.ac.uk/~bm10/chaos/rules.txt

https://www.giantbomb.com/chaos-the-battle-of-wizards/3030-9342/

http://rk.nvg.ntnu.no/sinclair/instructions/chaos.html

https://web.archive.org/web/20160214004030/http://www.zxsoftware.co.uk/Data/Spectrum/C/instructions/Chaos.txt

https://www.gameinformer.com/b/features/archive/2014/02/25/what-makes-chaos-the-battle-of-wizards-a-classic.aspx

https://chaosremakes.fandom.com/wiki/Comments_on_Chaos


3 changes: 2 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Bug / missing feature list:
Tree spells
Castle/Citadel spells
Mounts
Killing wizards
Killing wizard animation
Nicer end screen
Combat spells
Law/Chaos rating doing anything + being global
Board inspect character
Expand Down
76 changes: 30 additions & 46 deletions screen/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"

"github.com/bobtfish/mayhem/fx"
"github.com/bobtfish/mayhem/logical"
"github.com/bobtfish/mayhem/movable"
"github.com/bobtfish/mayhem/render"
Expand Down Expand Up @@ -55,62 +54,47 @@ func (screen *EngagedAttack) Step(ss pixel.Picture, win *pixelgl.Window) GameScr

type DoAttack struct {
*WithBoard
Fx *fx.Fx
AttackerV logical.Vec
DefenderV logical.Vec
PlayerIdx int
MovedCharacters map[movable.Movable]bool
}

func (screen *DoAttack) Enter(ss pixel.Picture, win *pixelgl.Window) {
ClearScreen(ss, win)
fmt.Printf("Enter DoAttack screen, place fx\n")
fx := fx.FxAttack()
screen.Fx = fx
screen.WithBoard.Grid.PlaceGameObject(screen.DefenderV, fx)
}
func (screen *DoAttack) Enter(ss pixel.Picture, win *pixelgl.Window) {}

func (screen *DoAttack) Step(ss pixel.Picture, win *pixelgl.Window) GameScreen {
batch := screen.WithBoard.DrawBoard(ss, win)
batch.Draw(win)

// Run animation till attack is finished
if screen.Fx.RemoveMe() {

// Work out what happened. This is overly simple, but equivalent to what the original game does :)
defender := screen.WithBoard.Grid.GetGameObject(screen.DefenderV)
defenceRating := defender.(movable.Attackable).GetDefence() + rand.Intn(9)
attacker := screen.WithBoard.Grid.GetGameObject(screen.AttackerV)
attackRating := attacker.(movable.Attackerable).GetCombat() + rand.Intn(9)

fmt.Printf("Attack rating %d defence rating %d\n", attackRating, defenceRating)
if attackRating > defenceRating {
// If the defender can be killed, kill them. Otherwise remove them
ob, corpsable := defender.(movable.Corpseable)
fmt.Printf("Defender is %T corpsable %v ob %T(%v)\n", defender, corpsable, ob, ob)
makesCorpse := corpsable && ob.CanMakeCorpse()
if makesCorpse {
fmt.Printf("make corpse\n")
ob.MakeCorpse()
} else {
fmt.Printf("remove defender as no corpse\n")
died := screen.WithBoard.Grid.GetGameObjectStack(screen.DefenderV).RemoveTopObject()
if KillIfPlayer(died, screen.WithBoard.Grid) {
if WeHaveAWinner(screen.WithBoard.Players) {
return &WinnerScreen{
WithBoard: screen.WithBoard,
}
// Work out what happened. This is overly simple, but equivalent to what the original game does :)
defender := screen.WithBoard.Grid.GetGameObject(screen.DefenderV)
defenceRating := defender.(movable.Attackable).GetDefence() + rand.Intn(9)
attacker := screen.WithBoard.Grid.GetGameObject(screen.AttackerV)
attackRating := attacker.(movable.Attackerable).GetCombat() + rand.Intn(9)

fmt.Printf("Attack rating %d defence rating %d\n", attackRating, defenceRating)
if attackRating > defenceRating {
// If the defender can be killed, kill them. Otherwise remove them
ob, corpsable := defender.(movable.Corpseable)
fmt.Printf("Defender is %T corpsable %v ob %T(%v)\n", defender, corpsable, ob, ob)
makesCorpse := corpsable && ob.CanMakeCorpse()
if makesCorpse {
fmt.Printf("make corpse\n")
ob.MakeCorpse()
} else {
fmt.Printf("remove defender as no corpse\n")
died := screen.WithBoard.Grid.GetGameObjectStack(screen.DefenderV).RemoveTopObject()
if KillIfPlayer(died, screen.WithBoard.Grid) {
if WeHaveAWinner(screen.WithBoard.Players) {
return &WinnerScreen{
WithBoard: screen.WithBoard,
}
}
}

doCharacterMove(screen.AttackerV, screen.DefenderV, screen.WithBoard.Grid)
}
return &MoveFindCharacterScreen{
WithBoard: screen.WithBoard,
PlayerIdx: screen.PlayerIdx,
MovedCharacters: screen.MovedCharacters,
}

doCharacterMove(screen.AttackerV, screen.DefenderV, screen.WithBoard.Grid)
}
return &MoveFindCharacterScreen{
WithBoard: screen.WithBoard,
PlayerIdx: screen.PlayerIdx,
MovedCharacters: screen.MovedCharacters,
}
return screen
}
51 changes: 23 additions & 28 deletions screen/castspell.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"

"github.com/bobtfish/mayhem/fx"
"github.com/bobtfish/mayhem/grid"
"github.com/bobtfish/mayhem/logical"
"github.com/bobtfish/mayhem/player"
Expand Down Expand Up @@ -37,11 +36,9 @@ func NextSpellCastOrMove(playerIdx int, players []*player.Player, grid *grid.Gam
}
}
return &Pause{
WaitFor: &WaitFor{
Skip: skipPause,
Grid: grid,
NextScreen: nextScreen,
},
Skip: skipPause,
Grid: grid,
NextScreen: nextScreen,
}
}

Expand Down Expand Up @@ -137,10 +134,13 @@ func (screen *TargetSpellScreen) AnimateAndCast() GameScreen {
if anim != nil {
screen.WithBoard.Grid.PlaceGameObject(target, anim)
}
return &DoSpellCast{
WithBoard: screen.WithBoard,
PlayerIdx: screen.PlayerIdx,
Fx: anim,
return &WaitForFx{
NextScreen: &DoSpellCast{
WithBoard: screen.WithBoard,
PlayerIdx: screen.PlayerIdx,
},
Grid: screen.WithBoard.Grid,
Fx: anim,
}
}

Expand All @@ -149,7 +149,6 @@ func (screen *TargetSpellScreen) AnimateAndCast() GameScreen {

type DoSpellCast struct {
*WithBoard
Fx *fx.Fx
PlayerIdx int
}

Expand All @@ -159,22 +158,18 @@ func (screen *DoSpellCast) Enter(ss pixel.Picture, win *pixelgl.Window) {
func (screen *DoSpellCast) Step(ss pixel.Picture, win *pixelgl.Window) GameScreen {
batch := screen.WithBoard.DrawBoard(ss, win)
batch.Draw(win)
// Wait until the spell animation is finished
if screen.Fx == nil || screen.Fx.RemoveMe() {
// Fx for spell cast finished
// Work out what happened :)
targetVec := screen.WithBoard.CursorPosition
fmt.Printf("About to call player CastSpell method\n")
success := screen.Players[screen.PlayerIdx].CastSpell(targetVec, screen.WithBoard.Grid)
fmt.Printf("Finished player CastSpell method\n")
if success {
fmt.Printf("Spell Succeeds\n")
render.NewTextDrawer(ss).DrawText("Spell Succeeds", logical.V(0, 0), win)
} else {
fmt.Printf("Spell failed\n")
render.NewTextDrawer(ss).DrawText("Spell Failed", logical.V(0, 0), win)
}
return NextSpellCastOrMove(screen.PlayerIdx, screen.Players, screen.Grid, false)
// Fx for spell cast finished
// Work out what happened :)
targetVec := screen.WithBoard.CursorPosition
fmt.Printf("About to call player CastSpell method\n")
success := screen.Players[screen.PlayerIdx].CastSpell(targetVec, screen.WithBoard.Grid)
fmt.Printf("Finished player CastSpell method\n")
if success {
fmt.Printf("Spell Succeeds\n")
render.NewTextDrawer(ss).DrawText("Spell Succeeds", logical.V(0, 0), win)
} else {
fmt.Printf("Spell failed\n")
render.NewTextDrawer(ss).DrawText("Spell Failed", logical.V(0, 0), win)
}
return screen
return NextSpellCastOrMove(screen.PlayerIdx, screen.Players, screen.Grid, false)
}
12 changes: 5 additions & 7 deletions screen/grow.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ func (screen *GrowScreen) Step(ss pixel.Picture, win *pixelgl.Window) GameScreen
firstAlivePlayerIdx := NextPlayerIdx(-1, screen.WithBoard.Players)
fmt.Printf("First alive player index %d\n", firstAlivePlayerIdx)
return &Pause{
WaitFor: &WaitFor{
Grid: screen.WithBoard.Grid,
NextScreen: &TurnMenuScreen{
Players: screen.WithBoard.Players,
Grid: screen.WithBoard.Grid,
PlayerIdx: firstAlivePlayerIdx,
},
Grid: screen.WithBoard.Grid,
NextScreen: &TurnMenuScreen{
Players: screen.WithBoard.Players,
Grid: screen.WithBoard.Grid,
PlayerIdx: firstAlivePlayerIdx,
},
}
}
Expand Down
19 changes: 13 additions & 6 deletions screen/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/faiface/pixel"
"github.com/faiface/pixel/pixelgl"

"github.com/bobtfish/mayhem/fx"
"github.com/bobtfish/mayhem/grid"
"github.com/bobtfish/mayhem/logical"
"github.com/bobtfish/mayhem/movable"
Expand Down Expand Up @@ -234,12 +235,18 @@ func DoAttackMaybe(from, to logical.Vec, playerIdx int, withBoard *WithBoard, mo
fmt.Printf("Target square is attackable\n")
if !ob.CheckBelongsTo(withBoard.Players[playerIdx]) {
fmt.Printf("Target square belongs to a different player do attack\n")
return &DoAttack{
AttackerV: from,
DefenderV: to,
WithBoard: withBoard,
PlayerIdx: playerIdx,
MovedCharacters: movedCharacters,
fx := fx.FxAttack()
withBoard.Grid.PlaceGameObject(to, fx)
return &WaitForFx{
NextScreen: &DoAttack{
AttackerV: from,
DefenderV: to,
WithBoard: withBoard,
PlayerIdx: playerIdx,
MovedCharacters: movedCharacters,
},
Grid: withBoard.Grid,
Fx: fx,
}, true
}
}
Expand Down
41 changes: 26 additions & 15 deletions screen/waitfor.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package screen

import (
"fmt"
"time"

"github.com/faiface/pixel"
Expand All @@ -14,13 +15,14 @@ import (
type WaitFor struct {
NextScreen GameScreen
Grid *grid.GameGrid
Skip bool
FinishedF func() bool
}

func (screen *WaitFor) Enter(ss pixel.Picture, win *pixelgl.Window) {}

func (screen *WaitFor) Step(ss pixel.Picture, win *pixelgl.Window) GameScreen {
if screen.Skip {
if screen.FinishedF() {
fmt.Printf("Waitfor Skip to next screen\n")
return screen.NextScreen
}
if screen.Grid != nil {
Expand All @@ -30,29 +32,38 @@ func (screen *WaitFor) Step(ss pixel.Picture, win *pixelgl.Window) GameScreen {
}

type Pause struct {
*WaitFor
Started time.Time
NextScreen GameScreen
Grid *grid.GameGrid
Skip bool
}

func (screen *Pause) Enter(ss pixel.Picture, win *pixelgl.Window) {
screen.Started = time.Now()
}
func (screen *Pause) Enter(ss pixel.Picture, win *pixelgl.Window) {}

func (screen *Pause) Step(ss pixel.Picture, win *pixelgl.Window) GameScreen {
if screen.Started.Add(time.Second).Before(time.Now()) {
screen.WaitFor.Skip = true
started := time.Now()
return &WaitFor{
NextScreen: screen.NextScreen,
Grid: screen.Grid,
FinishedF: func() bool {
return screen.Skip || started.Add(time.Second).Before(time.Now())
},
}
return screen.WaitFor.Step(ss, win)
}

type WaitForFx struct {
Fx *fx.Fx
*WaitFor
Fx *fx.Fx
NextScreen GameScreen
Grid *grid.GameGrid
}

func (screen *WaitForFx) Enter(ss pixel.Picture, win *pixelgl.Window) {}

func (screen *WaitForFx) Step(ss pixel.Picture, win *pixelgl.Window) GameScreen {
if screen.Fx.RemoveMe() {
screen.WaitFor.Skip = true
return &WaitFor{
NextScreen: screen.NextScreen,
Grid: screen.Grid,
FinishedF: func() bool {
return screen.Fx == nil || screen.Fx.RemoveMe()
},
}
return screen.WaitFor.Step(ss, win)
}

0 comments on commit f8e92a9

Please sign in to comment.