From d186d4da6e8b24d5659b4b9f7fc42a189c205be6 Mon Sep 17 00:00:00 2001 From: ccubed Date: Wed, 3 Apr 2024 18:18:55 -0400 Subject: [PATCH] Continuing Work --- .gitignore | 3 +- game/config.go | 1 + game/entities.go | 128 +++++++++++++++++++++++++++++++++++++++++++++++ game/logic.go | 39 +++++++++++++++ ui/theme.go | 83 ++++++++++++++++++++++++++++++ ultralight.go | 2 +- 6 files changed, 254 insertions(+), 2 deletions(-) create mode 100644 game/config.go create mode 100644 game/entities.go create mode 100644 game/logic.go create mode 100644 ui/theme.go diff --git a/.gitignore b/.gitignore index 2d28b5a..af5d751 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,5 @@ build/* go.work # Ignore fonts for now -*.otf \ No newline at end of file +*.otf +*.ttf \ No newline at end of file diff --git a/game/config.go b/game/config.go new file mode 100644 index 0000000..10634a4 --- /dev/null +++ b/game/config.go @@ -0,0 +1 @@ +package game \ No newline at end of file diff --git a/game/entities.go b/game/entities.go new file mode 100644 index 0000000..6de952f --- /dev/null +++ b/game/entities.go @@ -0,0 +1,128 @@ +package game + +// Attributes +type stat struct { + name string + short string + value int +} + +type attributes struct { + health stat + strength stat + endurance stat + dexterity stat + wisdom stat + intelligence stat +} + +// Levels +type level struct { + experience int + points int +} + +// Inventory +type Item struct { + name string + id int + drop int +} + +type Slot struct { + amount int + content Item +} + +// Player and Non Player Characters +type Player struct { + name string + levels []level + money int + stats attributes + inventory []Slot +} + +type Enemy struct { + name string + stats attributes + loot []Item + money int +} + +// Initialization Functions +func makeAttributes() attributes { + return attributes{ + health: stat{ + name: "Health", + short: "HP", + value: 10, + }, + strength: stat{ + name: "Strength", + short: "Str", + value: 1, + }, + endurance: stat{ + name: "Endurance", + short: "End", + value: 1, + }, + dexterity: stat{ + name: "Dexterity", + short: "Dex", + value: 1, + }, + wisdom: stat{ + name: "Wisdom", + short: "Wis", + value: 1, + }, + intelligence: stat{ + name: "Intelligence", + short: "Int", + value: 1, + }, + } +} + +func makeLevelTable() []level { + var ourLevels = make([]level, 0, 10) + + for i := 0; i < 11; i++ { + var baseXP int = 100 + var ourPoints int = 0 + + if i > 0 && i%2 == 0 { + ourPoints = 5 + } else if i > 0 && i%2 == 1 { + ourPoints = 4 + } + + ourLevels = append(ourLevels, level{ + experience: baseXP*i, + points: ourPoints, + }) + } + + return ourLevels +} + +func MakeNewPlayer(playerName string) Player { + return Player{ + name: playerName, + levels: makeLevelTable(), + money: 0, + stats: makeAttributes(), + inventory: make([]Slot, 0, 15), + } +} + +func MakeNewEnemy(enemyName string) Enemy { + return Enemy{ + name: enemyName, + stats: makeAttributes(), + loot: make([]Item, 0, 5), + money: 0, + } +} \ No newline at end of file diff --git a/game/logic.go b/game/logic.go new file mode 100644 index 0000000..fbe298f --- /dev/null +++ b/game/logic.go @@ -0,0 +1,39 @@ +package game + +import ( + "git.vertinext.com/roryejinn/Ultralight/game" + "strings" + "math/rand/v2" +) + +func (p *Player) AdjustStats(which string, newvalue int) *Player { + switch strings.ToLower(which) { + case "strength","str": + p.stats.strength.value = newvalue + case "endurance","end": + p.stats.endurance.value = newvalue + p.stats.health.value = 5 + (5*newvalue) + case "wisdom","wis": + p.stats.wisdom.value = newvalue + case "intelligence","int": + p.stats.intelligence.value = newvalue + case "dexterity","dex": + p.stats.dexterity.value = newvalue + } + return p +} + +func (p *Player) AdjustMoney(adjustment int) *Player { + p.money += adjustment + return p +} + +func (i Item) GetAmount() int { + chance := rand.IntN(100)+1 + + if chance <= i.drop { + return 2 + } else { + return 1 + } +} \ No newline at end of file diff --git a/ui/theme.go b/ui/theme.go new file mode 100644 index 0000000..514df4a --- /dev/null +++ b/ui/theme.go @@ -0,0 +1,83 @@ +package ui + +import ( + "github.com/charmbracelet/lipgloss" +) + +// base - background +// surface - not active popups, inputs, etc +// overlay - active popups, inputs ,etc +// muted - ignored, not needed +// subtle - inactive tabs, items, etc +// text - text color +// err - errors +// info - informational messages +// cyan, green, blue, magenta - accessory colors for styling + +type rosepine struct { + base lipgloss.AdaptiveColor + surface lipgloss.AdaptiveColor + overlay lipgloss.AdaptiveColor + muted lipgloss.AdaptiveColor + subtle lipgloss.AdaptiveColor + text lipgloss.AdaptiveColor + err lipgloss.AdaptiveColor + info lipgloss.AdaptiveColor + cyan lipgloss.AdaptiveColor + green lipgloss.AdaptiveColor + blue lipgloss.AdaptiveColor + magenta lipgloss.AdaptiveColor +} + +func MakeTheme() rosepine { + return rosepine{ + base: lipgloss.AdaptiveColor{ + Light:"#faf4ed", + Dark:"#232136", + }, + surface: lipgloss.AdaptiveColor{ + Light:"#fffaf3", + Dark:"#2a273f", + }, + overlay: lipgloss.AdaptiveColor{ + Light:"#f2e9e1", + Dark:"#393552", + }, + muted: lipgloss.AdaptiveColor{ + Light:"#9893a5", + Dark:"#6e6a86", + }, + subtle: lipgloss.AdaptiveColor{ + Light:"#797593", + Dark:"#908caa", + }, + text: lipgloss.AdaptiveColor{ + Light:"#575279", + Dark:"#e0def4", + }, + err: lipgloss.AdaptiveColor{ + Light:"#b4637a", + Dark:"#eb6f92", + }, + info: lipgloss.AdaptiveColor{ + Light:"#ea9d34", + Dark:"#f6c177", + }, + cyan: lipgloss.AdaptiveColor{ + Light:"#d7827e", + Dark:"#ea9a97", + }, + green: lipgloss.AdaptiveColor{ + Light:"#286983", + Dark:"#3e8fb0", + }, + blue: lipgloss.AdaptiveColor{ + Light:"#56949f", + Dark:"#9ccfd8", + }, + magenta: lipgloss.AdaptiveColor{ + Light:"#907aa9", + Dark:"#c4a7e7", + }, + } +} \ No newline at end of file diff --git a/ultralight.go b/ultralight.go index 0fdd031..16eac04 100644 --- a/ultralight.go +++ b/ultralight.go @@ -38,7 +38,7 @@ func (m model) View() string { } func main() { - fonts, err := crt.LoadFaces("FiraMonoNerdFont-Regular.otf", "FiraMonoNerdFont-Bold.otf", "FiraMonoNerdFont-Medium.otf", crt.GetFontDPI(), 16.0) + fonts, err := crt.LoadFaces("assets/fonts/IosevkaTerm-Extended.ttf", "assets/fonts/IosevkaTerm-ExtendedBold.ttf", "assets/fonts/IosevkaTerm-ExtendedMedium.ttf", crt.GetFontDPI(), 16.0) if err != nil { panic(err) }