Skip to content

Commit

Permalink
Woohoo, lightning works
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Jan 1, 2021
1 parent a50f743 commit 08cdbde
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 135 deletions.
7 changes: 4 additions & 3 deletions character/character.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/bobtfish/mayhem/render"
screeniface "github.com/bobtfish/mayhem/screen/iface"
"github.com/bobtfish/mayhem/spells"
spelliface "github.com/bobtfish/mayhem/spells/iface"
)

// Abstract character that can be created
Expand Down Expand Up @@ -67,7 +68,7 @@ func LoadCharacterTemplates() {
fmt.Printf("Character spell %s has no 'base_casting_chance', setting chance to 100\n", v.Name)
v.BaseCastingChance = 100
}
spells.CreateSpell(CharacterSpell{
spelliface.CreateSpell(CharacterSpell{
Name: v.Name,
LawRating: v.LawChaos,
CastingChance: v.BaseCastingChance,
Expand All @@ -93,7 +94,7 @@ func LoadCharacterTemplates() {

// We know that the spells array is initialised now, add the disbelieve spell
// This is done here as character depends on spells, and so we can't have spell depend on character
spells.AllSpells[0] = DisbelieveSpell{spells.ASpell{
spelliface.AllSpells[0] = DisbelieveSpell{spells.ASpell{
Name: "Disbelieve",
LawRating: 0,
Reuseable: true,
Expand Down Expand Up @@ -127,7 +128,7 @@ type CharacterSpell struct {
}

// Spell interface begin
func (s CharacterSpell) TakeOverScreen(grid *grid.GameGrid, cleanup func(), nextScreen screeniface.GameScreen, source, target logical.Vec) screeniface.GameScreen {
func (s CharacterSpell) TakeOverScreen(ctx screeniface.GameCtx, cleanupFunc func(), nextScreen screeniface.GameScreen, playeerIdx int, target logical.Vec) screeniface.GameScreen {
return nil
}
func (s CharacterSpell) GetName() string {
Expand Down
2 changes: 1 addition & 1 deletion game/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +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)
fmt.Printf("New screen %T %+v\n", newScreen, newScreen)
newScreen.Enter(gw)
return newScreen
}
Expand Down
4 changes: 1 addition & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ import (
screeniface "github.com/bobtfish/mayhem/screen/iface"

_ "github.com/bobtfish/mayhem/otherspells"
_ "github.com/bobtfish/mayhem/spellswithscreen"
)

// _ "github.com/bobtfish/mayhem/spellswithscreen"
//)

func loadSpriteSheet() io.Reader {
data, err := base64.StdEncoding.DecodeString(sprite_sheet_base64)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions otherspells/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/bobtfish/mayhem/player"
"github.com/bobtfish/mayhem/rand"
"github.com/bobtfish/mayhem/spells"
spelliface "github.com/bobtfish/mayhem/spells/iface"
)

type OtherSpell struct {
Expand All @@ -23,7 +24,7 @@ func (s OtherSpell) DoCast(illusion bool, target logical.Vec, grid *grid.GameGri
}

func init() {
spells.CreateSpell(OtherSpell{
spelliface.CreateSpell(OtherSpell{
ASpell: spells.ASpell{
Name: "Raise Dead",
LawRating: -1,
Expand All @@ -43,7 +44,7 @@ func init() {
return true, nil
},
})
spells.CreateSpell(OtherSpell{
spelliface.CreateSpell(OtherSpell{
ASpell: spells.ASpell{
Name: "Subversion",
CastingChance: 100,
Expand All @@ -63,7 +64,7 @@ func init() {
return false, nil
},
})
spells.CreateSpell(OtherSpell{
spelliface.CreateSpell(OtherSpell{
ASpell: spells.ASpell{ // 1 chance only, makes creatures belonging to player explode
Name: "Vengeance",
CastingChance: 80,
Expand All @@ -74,7 +75,7 @@ func init() {
return ExplodeCreatures(target, grid)
},
})
spells.CreateSpell(OtherSpell{
spelliface.CreateSpell(OtherSpell{
ASpell: spells.ASpell{ // 1 chance only, doesn't kill player - makes their creatures explode maybe?
Name: "Decree",
CastingChance: 80,
Expand All @@ -86,7 +87,7 @@ func init() {
return ExplodeCreatures(target, grid)
},
})
spells.CreateSpell(OtherSpell{
spelliface.CreateSpell(OtherSpell{
ASpell: spells.ASpell{ // 3 tries, doesn't kill player - makes their creatures explode
Name: "Dark Power",
CastingChance: 50,
Expand All @@ -99,7 +100,7 @@ func init() {
return ExplodeCreatures(target, grid)
},
})
spells.CreateSpell(OtherSpell{
spelliface.CreateSpell(OtherSpell{
ASpell: spells.ASpell{ // 3 tries, doesn't kill player - makes their creatures explode
Name: "Justice",
CastingChance: 50,
Expand Down
6 changes: 3 additions & 3 deletions player/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/bobtfish/mayhem/fx"
"github.com/bobtfish/mayhem/logical"
"github.com/bobtfish/mayhem/rand"
"github.com/bobtfish/mayhem/spells"
spelliface "github.com/bobtfish/mayhem/spells/iface"
)

func NewPlayer() Player {
Expand All @@ -18,14 +18,14 @@ func NewPlayer() Player {
MagicResistance: rand.Intn(2) + 6, // 6-8
Movement: 1,
ChosenSpell: -1,
Spells: spells.ChooseSpells(),
Spells: spelliface.ChooseSpells(),
Alive: true,
}
}

type Player struct {
Name string
Spells []spells.Spell
Spells []spelliface.Spell
HumanPlayer bool
CharacterIcon logical.Vec
ChosenSpell int
Expand Down
33 changes: 13 additions & 20 deletions player/spell.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/bobtfish/mayhem/grid"
"github.com/bobtfish/mayhem/logical"
"github.com/bobtfish/mayhem/spells"
spelliface "github.com/bobtfish/mayhem/spells/iface"
)

type PlayerSpell struct {
Expand All @@ -17,35 +18,27 @@ type PlayerSpell struct {
}

func (s PlayerSpell) CanCast(target grid.GameObject) bool {
_, ok := target.(*Player)
return ok
// CanCast is never called, as CastRange is 0
return true
}

func (s PlayerSpell) DoCast(illusion bool, target logical.Vec, grid *grid.GameGrid, castor grid.GameObject) (bool, *fx.Fx) {
if illusion {
panic("PlayerSpells should never be illusions")
}
tile := grid.GetGameObject(target)
player, isPlayer := tile.(*Player)
// Player spells are always on the castor, and the target vec could be the thing they're riding, so just
// use the castor
player, isPlayer := castor.(*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
}

// Setup all the player spells.
func init() {
spells.CreateSpell(PlayerSpell{
spelliface.CreateSpell(PlayerSpell{
ASpell: spells.ASpell{
Name: "Magic Armour",
LawRating: 1,
Expand All @@ -58,7 +51,7 @@ func init() {
p.Defence += 4
},
})
spells.CreateSpell(PlayerSpell{
spelliface.CreateSpell(PlayerSpell{
ASpell: spells.ASpell{
Name: "Magic Shield",
LawRating: 1,
Expand All @@ -71,7 +64,7 @@ func init() {
p.Defence += 2
},
})
spells.CreateSpell(PlayerSpell{
spelliface.CreateSpell(PlayerSpell{
ASpell: spells.ASpell{
Name: "Magic Knife",
LawRating: 1,
Expand All @@ -84,7 +77,7 @@ func init() {
p.HasMagicWeapon = true
},
})
spells.CreateSpell(PlayerSpell{
spelliface.CreateSpell(PlayerSpell{
ASpell: spells.ASpell{
Name: "Magic Sword",
LawRating: 1,
Expand All @@ -97,7 +90,7 @@ func init() {
p.HasMagicWeapon = true
},
})
spells.CreateSpell(PlayerSpell{
spelliface.CreateSpell(PlayerSpell{
ASpell: spells.ASpell{
Name: "Magic Bow",
LawRating: 1,
Expand All @@ -110,7 +103,7 @@ func init() {
p.RangedCombat = 3
},
})
spells.CreateSpell(PlayerSpell{
spelliface.CreateSpell(PlayerSpell{
ASpell: spells.ASpell{
Name: "Shadow Form",
CastingChance: 80,
Expand All @@ -122,7 +115,7 @@ func init() {
}
},
})
spells.CreateSpell(PlayerSpell{
spelliface.CreateSpell(PlayerSpell{
ASpell: spells.ASpell{
Name: "Magic Wings",
CastingChance: 60,
Expand Down
4 changes: 2 additions & 2 deletions screen/castspell.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ func (screen *DoSpellCast) Step(ctx screeniface.GameCtx) screeniface.GameScreen
nextScreen := NextSpellCastOrMove(screen.PlayerIdx, ctx, false)

// FIXME
/*takeOver := spell.TakeOverScreen(screen.WithCursor.Grid, cleanupFunc, nextScreen, p.BoardPosition, targetVec)
takeOver := spell.TakeOverScreen(ctx, cleanupFunc, nextScreen, screen.PlayerIdx, screen.Target)
if takeOver != nil {
return takeOver
}*/
}

// Do the spell cast here
var success bool
Expand Down
7 changes: 4 additions & 3 deletions screen/turnmenu.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import (
"github.com/bobtfish/mayhem/player"
screeniface "github.com/bobtfish/mayhem/screen/iface"
"github.com/bobtfish/mayhem/spells"
spelliface "github.com/bobtfish/mayhem/spells/iface"
)

type ExamineOneSpellScreen struct {
Spell spells.Spell
Spell spelliface.Spell
ReturnScreen screeniface.GameScreen
}

Expand Down Expand Up @@ -55,7 +56,7 @@ func (screen *SpellListScreen) Enter(ctx screeniface.GameCtx) {
}
spell := screen.Player.Spells[i]
td.DrawTextColor(
fmt.Sprintf("%s%s%s", intToChar(i), spells.LawRatingSymbol(spell), spell.GetName()),
fmt.Sprintf("%s%s%s", intToChar(i), spelliface.LawRatingSymbol(spell), spell.GetName()),
logical.V(mod, 8-(i/2)),
spells.CastingChanceColor(spell.GetCastingChance(ctx.GetLawRating())),
win,
Expand All @@ -68,7 +69,7 @@ func (screen *SpellListScreen) Enter(ctx screeniface.GameCtx) {
// Begin Examine Spells list screen
type ExamineSpellsScreen struct {
SpellListScreen
SpellToExamine *spells.Spell
SpellToExamine *spelliface.Spell
}

//func (screen *ExamineSpellsScreen) Enter(ctx screeniface.GameCtx) {
Expand Down
16 changes: 10 additions & 6 deletions spells/iface/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/bobtfish/mayhem/fx"
"github.com/bobtfish/mayhem/grid"
"github.com/bobtfish/mayhem/logical"

screeniface "github.com/bobtfish/mayhem/screen/iface"
)

type Spell interface {
Expand All @@ -21,6 +23,8 @@ type Spell interface {
IsReuseable() bool
CastFx() *fx.Fx
NeedsLineOfSight() bool

TakeOverScreen(screeniface.GameCtx, func(), screeniface.GameScreen, int, logical.Vec) screeniface.GameScreen
}

func LawRatingSymbol(s Spell) string {
Expand Down Expand Up @@ -52,11 +56,11 @@ func ChooseSpells() []Spell {
idx := rand.Intn(len(AllSpells)-1) + 1
spells[i] = AllSpells[idx]
}
/*
for i := 0; i < len(AllSpells); i++ {
if AllSpells[i].GetName() == "Magic Bolt" {
spells[1] = AllSpells[i]
}
}*/

for i := 0; i < len(AllSpells); i++ {
if AllSpells[i].GetName() == "Magic Bolt" {
spells[1] = AllSpells[i]
}
}
return spells
}
9 changes: 5 additions & 4 deletions spells/lawspells.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/bobtfish/mayhem/fx"
"github.com/bobtfish/mayhem/grid"
"github.com/bobtfish/mayhem/logical"
spelliface "github.com/bobtfish/mayhem/spells/iface"
)

type LawSpell struct {
Expand All @@ -15,25 +16,25 @@ func (s LawSpell) DoCast(illusion bool, target logical.Vec, grid *grid.GameGrid,
}

func init() {
CreateSpell(LawSpell{ASpell{
spelliface.CreateSpell(LawSpell{ASpell{
Name: "Law-1",
CastingChance: 100,
LawRating: 4,
NoCastFx: true,
}})
CreateSpell(LawSpell{ASpell{
spelliface.CreateSpell(LawSpell{ASpell{
Name: "Law-2",
CastingChance: 60,
LawRating: 8,
NoCastFx: true,
}})
CreateSpell(LawSpell{ASpell{
spelliface.CreateSpell(LawSpell{ASpell{
Name: "Chaos-1",
CastingChance: 80,
LawRating: -4,
NoCastFx: true,
}})
CreateSpell(LawSpell{ASpell{
spelliface.CreateSpell(LawSpell{ASpell{
Name: "Chaos-2",
CastingChance: 60,
LawRating: -8,
Expand Down
Loading

0 comments on commit 08cdbde

Please sign in to comment.