Skip to content

Commit

Permalink
Colors everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
bobtfish committed Dec 24, 2022
1 parent e46ef45 commit 851691b
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 136 deletions.
4 changes: 4 additions & 0 deletions render/sprite.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ func GetColor(r, g, b int) color.Color {
}
return pixel.RGB(float64(r)/255, float64(g)/255, float64(b)/255)
}

func ColorWhite() color.Color {
return GetColor(255, 255, 255)
}
6 changes: 1 addition & 5 deletions render/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ import (

var textMap map[string]logical.Vec

func (sd SpriteDrawer) DrawTextColor(text string, win logical.Vec, color color.Color, target pixel.Target) {
func (sd SpriteDrawer) DrawText(text string, win logical.Vec, color color.Color, target pixel.Target) {
for _, c := range text {
sd.GetSprite(textMap[string(c)]).DrawColorMask(target, sd.GetSpriteMatrix(win), color)
win.X++
}
}

func (sd SpriteDrawer) DrawText(text string, win logical.Vec, target pixel.Target) {
sd.DrawTextColor(text, win, GetColor(255, 255, 255), target)
}

func init() {
textMap = map[string]logical.Vec{
" ": logical.V(1, 40),
Expand Down
12 changes: 6 additions & 6 deletions screen/attack.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func (screen *RangedCombat) Step(ctx screeniface.GameCtx) screeniface.GameScreen
attackDistance := attackPosition.Distance(characterLocation)
if attackDistance > 0 { // You can't ranged attack yourself
if attackDistance > attackRange {
textBottomColor("Out of range", render.GetColor(247, 247, 0), ss, batch)
textBottom("Out of range", render.GetColor(247, 247, 0), ss, batch)
screen.OutOfRange = true
} else {
if !grid.HaveLineOfSight(characterLocation, attackPosition) {
textBottomColor("No line of sight", render.GetColor(0, 233, 233), ss, batch)
textBottom("No line of sight", render.GetColor(0, 233, 233), ss, batch)
screen.OutOfRange = true
} else {
return &AnimateRangedAttack{
Expand Down Expand Up @@ -196,7 +196,7 @@ func (screen *DoRangedAttack) Step(ctx screeniface.GameCtx) screeniface.GameScre
}
}
} else {
textBottomColor("Undead - Cannot be attacked", render.GetColor(0, 244, 244), ss, win)
textBottom("Undead - Cannot be attacked", render.GetColor(0, 244, 244), ss, win)
needPause = true
}
}
Expand All @@ -223,15 +223,15 @@ func (screen *EngagedAttack) Enter(ctx screeniface.GameCtx) {
win := ctx.GetWindow()
ss := ctx.GetSpriteSheet()
fmt.Printf("In engaged attack state\n")
textBottomColor("Engaged to enemy", render.GetColor(247, 247, 0), ss, win)
textBottom("Engaged to enemy", render.GetColor(247, 247, 0), ss, win)
}

func (screen *EngagedAttack) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
win := ctx.GetWindow()
ss := ctx.GetSpriteSheet()
batch := DrawBoard(ctx)
if screen.ClearMsg {
textBottom("", ss, batch)
textBottom("", render.ColorWhite(), ss, batch)
}

direction := captureDirectionKey(win)
Expand All @@ -248,7 +248,7 @@ func (screen *EngagedAttack) Step(ctx screeniface.GameCtx) screeniface.GameScree
}
if as.IllegalUndeadAttack {
screen.ClearMsg = false
textBottomColor("Undead - Cannot be attacked", render.GetColor(0, 244, 244), ss, win)
textBottom("Undead - Cannot be attacked", render.GetColor(0, 244, 244), ss, win)
}
}

Expand Down
4 changes: 2 additions & 2 deletions screen/castspell.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type TargetSpellScreen struct {
func (screen *TargetSpellScreen) Enter(ctx screeniface.GameCtx) {
win := ctx.GetWindow()
ss := ctx.GetSpriteSheet()
textBottom("", ss, win) // clear bottom bar
textBottomColor("", render.ColorWhite(), ss, win) // clear bottom bar
}

func (screen *TargetSpellScreen) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand Down Expand Up @@ -215,7 +215,7 @@ func (screen *DoSpellCast) Step(ctx screeniface.GameCtx) screeniface.GameScreen
if !screen.CastBefore {
if (canCastMore && castsRemaining > 0) || success {
fmt.Printf("Spell Succeeds\n")
textBottom("Spell Succeeds", ss, batch)
textBottomColor("Spell Succeeds", render.ColorWhite(), ss, batch)
ctx.AdjustLawRating(spell.GetLawRating())
} else {
fmt.Printf("Spell failed\n")
Expand Down
145 changes: 73 additions & 72 deletions screen/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/faiface/pixel/pixelgl"

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

Expand All @@ -14,15 +15,15 @@ func (screen *HelpScreenMenu) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" Help screen", logical.V(0, 9), win)
td.DrawText("1. Keys", logical.V(9, 7), win)
td.DrawText("2. Spells", logical.V(9, 6), win)
td.DrawText("3. Combat", logical.V(9, 5), win)
td.DrawText("4. Undead", logical.V(9, 4), win)
td.DrawText("5. Mounts", logical.V(9, 3), win)
td.DrawText("6. Victory", logical.V(9, 2), win)
td.DrawText(" Help screen", logical.V(0, 9), render.ColorWhite(), win)
td.DrawText("1. Keys", logical.V(9, 7), render.ColorWhite(), win)
td.DrawText("2. Spells", logical.V(9, 6), render.ColorWhite(), win)
td.DrawText("3. Combat", logical.V(9, 5), render.ColorWhite(), win)
td.DrawText("4. Undead", logical.V(9, 4), render.ColorWhite(), win)
td.DrawText("5. Mounts", logical.V(9, 3), render.ColorWhite(), win)
td.DrawText("6. Victory", logical.V(9, 2), render.ColorWhite(), win)

textBottom("Press Keys 1-6 or 0 to return", ss, win)
textBottomColor("Press Keys 1-6 or 0 to return", render.ColorWhite(), ss, win)
}

func (screen *HelpScreenMenu) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand Down Expand Up @@ -59,16 +60,16 @@ func (screen *HelpScreenKeys) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" Keys", logical.V(0, 9), win)
td.DrawText("AQWEDCXZ - Move in direction", logical.V(0, 7), win)
td.DrawText("S - Select creature/wizard", logical.V(0, 6), win)
td.DrawText("K - Cancel movement/attack", logical.V(0, 5), win)
td.DrawText("I - Show information on", logical.V(0, 4), win)
td.DrawText(" creature", logical.V(0, 3), win)
td.DrawText("1-8 - Highlight creations of", logical.V(0, 2), win)
td.DrawText(" player # 1-8", logical.V(0, 1), win)
td.DrawText("0 - End turn", logical.V(0, 0), win)
textBottom(" Press any key to continue", ss, win)
td.DrawText(" Keys", logical.V(0, 9), render.ColorWhite(), win)
td.DrawText("AQWEDCXZ - Move in direction", logical.V(0, 7), render.ColorWhite(), win)
td.DrawText("S - Select creature/wizard", logical.V(0, 6), render.ColorWhite(), win)
td.DrawText("K - Cancel movement/attack", logical.V(0, 5), render.ColorWhite(), win)
td.DrawText("I - Show information on", logical.V(0, 4), render.ColorWhite(), win)
td.DrawText(" creature", logical.V(0, 3), render.ColorWhite(), win)
td.DrawText("1-8 - Highlight creations of", logical.V(0, 2), render.ColorWhite(), win)
td.DrawText(" player # 1-8", logical.V(0, 1), render.ColorWhite(), win)
td.DrawText("0 - End turn", logical.V(0, 0), render.ColorWhite(), win)
textBottomColor(" Press any key to continue", render.ColorWhite(), ss, win)
}

func (screen *HelpScreenKeys) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand All @@ -86,16 +87,16 @@ func (screen *HelpScreenSpells) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" Spells", logical.V(0, 9), win)
td.DrawText(" Spells", logical.V(0, 9), render.ColorWhite(), win)
// #
td.DrawText("Select a spell then use", logical.V(0, 7), win)
td.DrawText("direction keys to choose", logical.V(0, 6), win)
td.DrawText("where to cast it.", logical.V(0, 5), win)
td.DrawText("Press S to cast.", logical.V(0, 4), win)
td.DrawText("Illusions always succeed but", logical.V(0, 3), win)
td.DrawText("can be disbelieved by others.", logical.V(0, 2), win)
td.DrawText(" ^=law *=chaos -=neutral", logical.V(0, 0), win)
textBottom(" Press any key to continue", ss, win)
td.DrawText("Select a spell then use", logical.V(0, 7), render.ColorWhite(), win)
td.DrawText("direction keys to choose", logical.V(0, 6), render.ColorWhite(), win)
td.DrawText("where to cast it.", logical.V(0, 5), render.ColorWhite(), win)
td.DrawText("Press S to cast.", logical.V(0, 4), render.ColorWhite(), win)
td.DrawText("Illusions always succeed but", logical.V(0, 3), render.ColorWhite(), win)
td.DrawText("can be disbelieved by others.", logical.V(0, 2), render.ColorWhite(), win)
td.DrawText(" ^=law *=chaos -=neutral", logical.V(0, 0), render.ColorWhite(), win)
textBottomColor(" Press any key to continue", render.ColorWhite(), ss, win)
}

func (screen *HelpScreenSpells) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand All @@ -113,16 +114,16 @@ func (screen *HelpScreenCombat) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" Combat", logical.V(0, 9), win)
td.DrawText(" Combat", logical.V(0, 9), render.ColorWhite(), win)
// #
td.DrawText("Move next to another creature", logical.V(0, 7), win)
td.DrawText("to engage them in combat.", logical.V(0, 6), win)
td.DrawText("Flying creatures can attack", logical.V(0, 5), win)
td.DrawText("remotely without engagement.", logical.V(0, 4), win)
td.DrawText("If adjacent next turn you may", logical.V(0, 3), win)
td.DrawText("remain engaged or may be able", logical.V(0, 2), win)
td.DrawText("to break away.", logical.V(0, 1), win)
textBottom(" Press any key to continue", ss, win)
td.DrawText("Move next to another creature", logical.V(0, 7), render.ColorWhite(), win)
td.DrawText("to engage them in combat.", logical.V(0, 6), render.ColorWhite(), win)
td.DrawText("Flying creatures can attack", logical.V(0, 5), render.ColorWhite(), win)
td.DrawText("remotely without engagement.", logical.V(0, 4), render.ColorWhite(), win)
td.DrawText("If adjacent next turn you may", logical.V(0, 3), render.ColorWhite(), win)
td.DrawText("remain engaged or may be able", logical.V(0, 2), render.ColorWhite(), win)
td.DrawText("to break away.", logical.V(0, 1), render.ColorWhite(), win)
textBottomColor(" Press any key to continue", render.ColorWhite(), ss, win)
}

func (screen *HelpScreenCombat) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand All @@ -141,17 +142,17 @@ func (screen *HelpScreenCombatRanged) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" Ranged Combat", logical.V(0, 9), win)
td.DrawText(" Ranged Combat", logical.V(0, 9), render.ColorWhite(), win)
// #
td.DrawText("Some characters have ranged", logical.V(0, 7), win)
td.DrawText("combat.", logical.V(0, 6), win)
td.DrawText("This always happens after", logical.V(0, 5), win)
td.DrawText("movement (K to skip movement)", logical.V(0, 4), win)
td.DrawText("Target is selected with", logical.V(0, 3), win)
td.DrawText("direction keys, press S to", logical.V(0, 2), win)
td.DrawText("fire. Target must be in line", logical.V(0, 1), win)
td.DrawText("of sight.", logical.V(0, 0), win)
textBottom(" Press any key to continue", ss, win)
td.DrawText("Some characters have ranged", logical.V(0, 7), render.ColorWhite(), win)
td.DrawText("combat.", logical.V(0, 6), render.ColorWhite(), win)
td.DrawText("This always happens after", logical.V(0, 5), render.ColorWhite(), win)
td.DrawText("movement (K to skip movement)", logical.V(0, 4), render.ColorWhite(), win)
td.DrawText("Target is selected with", logical.V(0, 3), render.ColorWhite(), win)
td.DrawText("direction keys, press S to", logical.V(0, 2), render.ColorWhite(), win)
td.DrawText("fire. Target must be in line", logical.V(0, 1), render.ColorWhite(), win)
td.DrawText("of sight.", logical.V(0, 0), render.ColorWhite(), win)
textBottomColor(" Press any key to continue", render.ColorWhite(), ss, win)
}

func (screen *HelpScreenCombatRanged) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand All @@ -169,16 +170,16 @@ func (screen *HelpScreenUndead) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" Undead", logical.V(0, 9), win)
td.DrawText(" Undead", logical.V(0, 9), render.ColorWhite(), win)
// #
td.DrawText("Some characters are undead.", logical.V(0, 7), win)
td.DrawText("They can only be attacked by", logical.V(0, 6), win)
td.DrawText("other undead characters or", logical.V(0, 5), win)
td.DrawText("magic weapons.", logical.V(0, 4), win)
td.DrawText("The raise dead spell will", logical.V(0, 2), win)
td.DrawText("turn a corpse into an undead", logical.V(0, 1), win)
td.DrawText("creature.", logical.V(0, 0), win)
textBottom(" Press any key to continue", ss, win)
td.DrawText("Some characters are undead.", logical.V(0, 7), render.ColorWhite(), win)
td.DrawText("They can only be attacked by", logical.V(0, 6), render.ColorWhite(), win)
td.DrawText("other undead characters or", logical.V(0, 5), render.ColorWhite(), win)
td.DrawText("magic weapons.", logical.V(0, 4), render.ColorWhite(), win)
td.DrawText("The raise dead spell will", logical.V(0, 2), render.ColorWhite(), win)
td.DrawText("turn a corpse into an undead", logical.V(0, 1), render.ColorWhite(), win)
td.DrawText("creature.", logical.V(0, 0), render.ColorWhite(), win)
textBottomColor(" Press any key to continue", render.ColorWhite(), ss, win)
}

func (screen *HelpScreenUndead) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand All @@ -197,17 +198,17 @@ func (screen *HelpScreenMounts) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" Mounts", logical.V(0, 9), win)
td.DrawText(" Mounts", logical.V(0, 9), render.ColorWhite(), win)
// #
td.DrawText("Some characters can be ridden", logical.V(0, 7), win)
td.DrawText("by wizards. Simply move your", logical.V(0, 6), win)
td.DrawText("wizard onto the creature to", logical.V(0, 5), win)
td.DrawText("mount it.", logical.V(0, 4), win)
td.DrawText("This allows faster movement", logical.V(0, 3), win)
td.DrawText("and your wizard cannot be", logical.V(0, 2), win)
td.DrawText("killed unless their mount is", logical.V(0, 1), win)
td.DrawText("killed first.", logical.V(0, 0), win)
textBottom(" Press any key to continue", ss, win)
td.DrawText("Some characters can be ridden", logical.V(0, 7), render.ColorWhite(), win)
td.DrawText("by wizards. Simply move your", logical.V(0, 6), render.ColorWhite(), win)
td.DrawText("wizard onto the creature to", logical.V(0, 5), render.ColorWhite(), win)
td.DrawText("mount it.", logical.V(0, 4), render.ColorWhite(), win)
td.DrawText("This allows faster movement", logical.V(0, 3), render.ColorWhite(), win)
td.DrawText("and your wizard cannot be", logical.V(0, 2), render.ColorWhite(), win)
td.DrawText("killed unless their mount is", logical.V(0, 1), render.ColorWhite(), win)
td.DrawText("killed first.", logical.V(0, 0), render.ColorWhite(), win)
textBottomColor(" Press any key to continue", render.ColorWhite(), ss, win)
}

func (screen *HelpScreenMounts) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand All @@ -225,14 +226,14 @@ func (screen *HelpScreenVictory) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" Victory", logical.V(0, 9), win)
td.DrawText(" Victory", logical.V(0, 9), render.ColorWhite(), win)
// #
td.DrawText("To win the game, simply kill", logical.V(0, 7), win)
td.DrawText("all the other wizards.", logical.V(0, 6), win)
td.DrawText("When a player is killed, all", logical.V(0, 4), win)
td.DrawText("of their creations will also", logical.V(0, 3), win)
td.DrawText("vanish.", logical.V(0, 2), win)
textBottom(" Press any key to continue", ss, win)
td.DrawText("To win the game, simply kill", logical.V(0, 7), render.ColorWhite(), win)
td.DrawText("all the other wizards.", logical.V(0, 6), render.ColorWhite(), win)
td.DrawText("When a player is killed, all", logical.V(0, 4), render.ColorWhite(), win)
td.DrawText("of their creations will also", logical.V(0, 3), render.ColorWhite(), win)
td.DrawText("vanish.", logical.V(0, 2), render.ColorWhite(), win)
textBottomColor(" Press any key to continue", render.ColorWhite(), ss, win)
}

func (screen *HelpScreenVictory) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand Down
25 changes: 13 additions & 12 deletions screen/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/faiface/pixel/pixelgl"

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

Expand All @@ -19,11 +20,11 @@ func (screen *InitialScreen) Enter(ctx screeniface.GameCtx) {
ss := ctx.GetSpriteSheet()
ClearScreen(ss, win)
td := TextDrawer(ss)
td.DrawText(" MAYHEM - Remake of Chaos", logical.V(0, 9), win)
td.DrawText(" By bobtfish", logical.V(0, 8), win)
td.DrawText("How many wizards?", logical.V(0, 6), win)
td.DrawText("(Press 2 to 8)", logical.V(0, 5), win)
textBottom(" Press H for help", ss, win)
td.DrawTextColor(" MAYHEM - Remake of Chaos", logical.V(0, 9), render.ColorWhite(), win)
td.DrawTextColor(" By bobtfish", logical.V(0, 8), render.ColorWhite(), win)
td.DrawTextColor("How many wizards?", logical.V(0, 6), render.ColorWhite(), win)
td.DrawTextColor("(Press 2 to 8)", logical.V(0, 5), render.ColorWhite(), win)
textBottomColor(" Press H for help", render.ColorWhite(), ss, win)
}

func (screen *InitialScreen) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
Expand All @@ -36,10 +37,10 @@ func (screen *InitialScreen) Step(ctx screeniface.GameCtx) screeniface.GameScree
c := captureNumKey(win)
if c >= 2 && c <= 8 {
td := TextDrawer(ss)
td.DrawText(fmt.Sprintf("%d", c), logical.V(18, 6), win)
td.DrawText("Level of computer wizards?", logical.V(0, 3), win)
td.DrawText("(Press 1 to 8)", logical.V(0, 2), win)
textBottom("", ss, win)
td.DrawTextColor(fmt.Sprintf("%d", c), logical.V(18, 6), render.ColorWhite(), win)
td.DrawTextColor("Level of computer wizards?", logical.V(0, 3), render.ColorWhite(), win)
td.DrawTextColor("(Press 1 to 8)", logical.V(0, 2), render.ColorWhite(), win)
textBottomColor("", render.ColorWhite(), ss, win)
return &ComputerDifficultyScreen{WizardCount: c}
}
return screen
Expand All @@ -49,16 +50,16 @@ func (screen *ComputerDifficultyScreen) Enter(ctx screeniface.GameCtx) {
win := ctx.GetWindow()
ss := ctx.GetSpriteSheet()
td := TextDrawer(ss)
td.DrawText("Level of computer wizards?", logical.V(0, 3), win)
td.DrawText("(Press 1 to 8)", logical.V(0, 2), win)
td.DrawTextColor("Level of computer wizards?", logical.V(0, 3), render.ColorWhite(), win)
td.DrawTextColor("(Press 1 to 8)", logical.V(0, 2), render.ColorWhite(), win)
}

func (screen *ComputerDifficultyScreen) Step(ctx screeniface.GameCtx) screeniface.GameScreen {
ss := ctx.GetSpriteSheet()
win := ctx.GetWindow()
c := captureNumKey(win)
if c >= 1 && c <= 8 {
TextDrawer(ss).DrawText(fmt.Sprintf("%d", c), logical.V(27, 3), win)
TextDrawer(ss).DrawTextColor(fmt.Sprintf("%d", c), logical.V(27, 3), render.ColorWhite(), win)
return &PlayerNameScreen{
PlayersScreen: PlayersScreen{
WizardCount: screen.WizardCount,
Expand Down
Loading

0 comments on commit 851691b

Please sign in to comment.