Skip to content

Commit

Permalink
Give players a new spell on screen grow
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Jan 9, 2021
1 parent 3bb0b16 commit c34f96a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ Bug / missing feature list:
Bugs:
- Cannot move from magic wood tree to dark citadel
- Players can attack walls?
- Magic wood, make it gift players with a spell sometimes if they are mounted.
- Line of sight calculation seems a bit harsh currently
15 changes: 13 additions & 2 deletions screen/grow.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/bobtfish/mayhem/player"
"github.com/bobtfish/mayhem/rand"
screeniface "github.com/bobtfish/mayhem/screen/iface"
spelliface "github.com/bobtfish/mayhem/spells/iface"
)

const GrowChance = 15
Expand Down Expand Up @@ -76,7 +77,8 @@ func (screen *GrowScreen) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
// FIXME - lots of puke worthy type casting in here, should not need this special casing really....
func (screen *GrowScreen) IterateGrowVanish(ctx screeniface.GameCtx) {
grid := ctx.GetGrid()
for screen.Consider.X < grid.MaxX() && screen.Consider.Y < grid.MaxY() {
for screen.Consider.X <= grid.MaxX() && screen.Consider.Y <= grid.MaxY() {
fmt.Printf("Consider %d x %d\n", screen.Consider.X, screen.Consider.Y)
// If the current tile contains a character
char, ok := grid.GetGameObject(screen.Consider).(*character.Character)
if ok {
Expand Down Expand Up @@ -145,11 +147,20 @@ func (screen *GrowScreen) IterateGrowVanish(ctx screeniface.GameCtx) {
}
}
}
if char.Name == "Magic Wood" {
if char.CarryingPlayer && rand.Intn(9)+1 <= 2 { // 20% chance
screen.Grew = true
grid.GetGameObjectStack(screen.Consider).RemoveTopObject()
grid.PlaceGameObject(screen.Consider, char.BelongsTo) // Put the wizard back down
player := char.BelongsTo
player.Spells = append(player.Spells, spelliface.ChooseSpell())
}
}
}

// Bump tile counter
screen.Consider.X++
if screen.Consider.X == grid.MaxX() {
if screen.Consider.X > grid.MaxX() {
screen.Consider.X = 0
screen.Consider.Y++
}
Expand Down
8 changes: 6 additions & 2 deletions spells/iface/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ func CreateSpell(s Spell) {
AllSpells = append(AllSpells, s)
}

func ChooseSpell() Spell {
idx := rand.Intn(len(AllSpells)-1) + 1
return AllSpells[idx]
}

func ChooseSpells() []Spell {
spells := make([]Spell, 14)
spells[0] = AllSpells[0]
for i := 1; i < 14; i++ {
idx := rand.Intn(len(AllSpells)-1) + 1
spells[i] = AllSpells[idx]
spells[i] = ChooseSpell()
}

for i := 0; i < len(AllSpells); i++ {
Expand Down
5 changes: 2 additions & 3 deletions spellswithscreen/magic_wood.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ func (screen *MagicWoodSpellScreen) Enter(ctx screeniface.GameCtx) {
func (screen *MagicWoodSpellScreen) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
if len(screen.MaybeTiles) == 0 || screen.LaidTiles == 8 {
screen.CleanupFunc()
return &screens.Pause{
NextScreen: screen.NextScreen,
}
// We already paused before reentry
return screen.NextScreen
}

batch := DrawBoard(ctx)
Expand Down

0 comments on commit c34f96a

Please sign in to comment.