Skip to content

Commit

Permalink
Merge pull request #14 from kensonjohnson/info-window
Browse files Browse the repository at this point in the history
Info window
  • Loading branch information
kensonjohnson authored Sep 27, 2024
2 parents 7180b04 + 1ab19e1 commit 2ff9750
Show file tree
Hide file tree
Showing 28 changed files with 1,095 additions and 342 deletions.
6 changes: 6 additions & 0 deletions archetype/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ func CreateNewItem(world donburi.World, itemData *items.ItemData) *donburi.Entry
tags.ItemTag,
component.Name,
component.Sprite,
component.Description,
))

name := component.NameData{
Expand All @@ -26,6 +27,11 @@ func CreateNewItem(world donburi.World, itemData *items.ItemData) *donburi.Entry
}
component.Sprite.SetValue(entry, sprite)

description := component.DescriptionData{
Value: itemData.Description,
}
component.Description.SetValue(entry, description)

return entry
}

Expand Down
21 changes: 21 additions & 0 deletions archetype/monster.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,24 @@ func CreateMonster(world donburi.World, level *component.LevelData, room engine.
defense := component.Defense.Get(equipment.Armor)
component.Defense.SetValue(monster, *defense)
}

func RemoveMonster(entry *donburi.Entry, world donburi.World) {
equipment := component.Equipment.Get(entry)

if equipment.Armor != nil {
equipment.Armor.Remove()
}
if equipment.Weapon != nil {
equipment.Weapon.Remove()
}
if equipment.Sheild != nil {
equipment.Sheild.Remove()
}
if equipment.Gloves != nil {
equipment.Gloves.Remove()
}
if equipment.Boots != nil {
equipment.Boots.Remove()
}
entry.Remove()
}
9 changes: 8 additions & 1 deletion archetype/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/kensonjohnson/roguelike-game-go/archetype/tags"
"github.com/kensonjohnson/roguelike-game-go/assets"
"github.com/kensonjohnson/roguelike-game-go/component"
"github.com/kensonjohnson/roguelike-game-go/internal/engine"
"github.com/kensonjohnson/roguelike-game-go/items"
"github.com/norendren/go-fov/fov"
"github.com/yohamta/donburi"
Expand Down Expand Up @@ -62,8 +63,14 @@ func CreateNewPlayer(
component.Equipment.SetValue(player, equipment)

// Setup inventory
inventory := component.NewInventory(30)
inventory := component.NewInventory(28)
component.Inventory.SetValue(player, inventory)
if engine.Debug.On() {
inventory.AddItem(CreateNewValuable(world, items.Valuables.Alcohol))
inventory.AddItem(CreateNewConsumable(world, items.Consumables.Apple))
inventory.AddItem(CreateNewConsumable(world, items.Consumables.HealthPotion))
inventory.AddItem(CreateNewConsumable(world, items.Consumables.Bread))
}

wallet := component.WalletData{}
component.Wallet.SetValue(player, wallet)
Expand Down
48 changes: 0 additions & 48 deletions archetype/ui.go

This file was deleted.

4 changes: 4 additions & 0 deletions archetype/valuable.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func CreateNewValuable(world donburi.World, valuableData *items.ValuableData) *d
return entry
}

func IsValuable(entry *donburi.Entry) bool {
return entry.HasComponent(tags.ValuableTag)
}

func CreateCoins(world donburi.World, valuableData *items.ValuableData) *donburi.Entry {
entry := CreateNewValuable(world, valuableData)

Expand Down
16 changes: 9 additions & 7 deletions assets/efs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ var (
ChestClosed *ebiten.Image

// UI
UIPanel *ebiten.Image
UIPanelWithMinimap *ebiten.Image
UICorner *ebiten.Image
KenneyMiniFont *text.GoTextFace
KenneyMiniSquaredFont *text.GoTextFace
KenneyPixelFont *text.GoTextFace

// Icons
Heart *ebiten.Image

// Characters
Player *ebiten.Image
Skelly *ebiten.Image
Expand Down Expand Up @@ -151,10 +151,6 @@ func init() {
/*-----------------------
---------- UI -----------
-----------------------*/
UIPanel = mustLoadImage("images/ui/UIPanel.png")
UIPanelWithMinimap = mustLoadImage("images/ui/UIPanelWithMinimap.png")
UICorner = mustLoadImage("images/ui/UICorner.png")

kenneyMiniFontBytes, err := assetsFS.ReadFile("fonts/KenneyMini.ttf")
if err != nil {
log.Panic(err)
Expand All @@ -173,6 +169,12 @@ func init() {
// For some reason, the KenneyPixel shows up as half the size of the other fonts.
KenneyPixelFont.Size = float64(config.FontSize) * 1.5

/*-----------------------
--------- Fonts ---------
-----------------------*/

Heart = mustLoadImage("images/icons/heart.png")

/*-----------------------
------ Characters -------
-----------------------*/
Expand Down
Binary file added assets/images/icons/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/images/ui/UICorner.png
Binary file not shown.
Binary file removed assets/images/ui/UIPanel.png
Binary file not shown.
Binary file removed assets/images/ui/UIPanelWithMinimap.png
Binary file not shown.
9 changes: 9 additions & 0 deletions component/description.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package component

import "github.com/yohamta/donburi"

type DescriptionData struct {
Value string
}

var Description = donburi.NewComponentType[DescriptionData]()
34 changes: 26 additions & 8 deletions component/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package component

import (
"errors"
"iter"
"log"

"github.com/kensonjohnson/roguelike-game-go/archetype/tags"
"github.com/yohamta/donburi"
)

type InventoryData struct {
Items []*donburi.Entry
items []*donburi.Entry
capacity int
holding int
}
Expand All @@ -18,7 +19,7 @@ var Inventory = donburi.NewComponentType[InventoryData]()

func NewInventory(capacity int) InventoryData {
return InventoryData{
Items: make([]*donburi.Entry, capacity),
items: make([]*donburi.Entry, capacity),
capacity: capacity,
holding: 0,
}
Expand All @@ -31,8 +32,8 @@ func (i *InventoryData) GetCapacityInfo() (holding, capacity int) {
func (i *InventoryData) IncreaseCapacityByAmount(amount int) {
i.capacity += amount
newStorage := make([]*donburi.Entry, i.capacity)
copy(newStorage, i.Items)
i.Items = newStorage
copy(newStorage, i.items)
i.items = newStorage
}

func (i *InventoryData) DecreaseCapacityByAmount(amount int) error {
Expand All @@ -43,6 +44,13 @@ func (i *InventoryData) DecreaseCapacityByAmount(amount int) error {
return nil
}

func (i *InventoryData) GetItem(index int) (*donburi.Entry, error) {
if index < 0 || index >= i.capacity {
return nil, errors.New("Index out of range")
}
return i.items[index], nil
}

func (i *InventoryData) AddItem(item *donburi.Entry) error {
if i.holding >= i.capacity {
return errors.New("inventory full")
Expand All @@ -54,7 +62,7 @@ func (i *InventoryData) AddItem(item *donburi.Entry) error {

var targetIndex = -1

for index, element := range i.Items {
for index, element := range i.items {
if element == nil {
targetIndex = index
break
Expand All @@ -65,14 +73,24 @@ func (i *InventoryData) AddItem(item *donburi.Entry) error {
return errors.New("failed to find empty index for item")
}

i.Items[targetIndex] = item
i.items[targetIndex] = item
return nil
}

func (i *InventoryData) RemoveItem(index int) error {
if index >= i.capacity {
if index < 0 || index >= i.capacity {
log.Panic("index out of range in RemoveItem. Recieved: ", index)
}
i.Items[index] = nil
i.items[index] = nil
return nil
}

func (i *InventoryData) Iter() iter.Seq2[int, *donburi.Entry] {
return func(yield func(int, *donburi.Entry) bool) {
for index, entry := range i.items {
if !yield(index, entry) {
return
}
}
}
}
30 changes: 0 additions & 30 deletions component/ui.go

This file was deleted.

3 changes: 3 additions & 0 deletions component/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ var Wallet = donburi.NewComponentType[WalletData]()

func (w *WalletData) AddAmount(amount int) {
w.Amount += amount
if w.Amount > 99999 {
w.Amount = 99999
}
}

func (w *WalletData) SubtractAmount(amount int) {
Expand Down
4 changes: 1 addition & 3 deletions internal/colors/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ package colors
import "image/color"

var (
Transparent = color.RGBA{}
Black = color.RGBA{0, 0, 0, 255}
White = color.RGBA{255, 255, 255, 255}
Blue = color.RGBA{0, 0, 255, 255}
CornflowerBlue = color.RGBA{100, 149, 237, 255}
DeepSkyBlue = color.RGBA{0, 191, 255, 255}
Green = color.RGBA{0, 128, 0, 255}
Lime = color.RGBA{0, 255, 0, 255}
Brown = color.RGBA{165, 42, 42, 255}
Smudgy = color.RGBA{71, 45, 60, 255}
Peru = color.RGBA{205, 133, 63, 255}
Gray = color.RGBA{128, 128, 128, 255}
LightGray = color.RGBA{211, 211, 211, 255}
Expand Down
21 changes: 21 additions & 0 deletions internal/engine/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package engine

type debug struct {
on bool
}

var Debug = &debug{
on: false,
}

func (d *debug) TurnOn() {
d.on = true
}

func (d *debug) TurnOff() {
d.on = false
}

func (d *debug) On() bool {
return d.on
}
13 changes: 12 additions & 1 deletion internal/engine/random.go → internal/engine/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package engine

import (
"crypto/rand"
"math"
"math/big"
)

Expand All @@ -17,7 +18,17 @@ func GetDiceRoll(num int) int {
return int(x.Int64()) + 1
}

// Returns a number between low and high, inclusive.
// Returns a number between low and high, inclusive
func GetRandomBetween(low, high int) int {
return GetDiceRoll(high-low) + low
}

// Converts degrees to radians
func DegreesToRadians(degrees int) float64 {
return float64(degrees) * math.Pi / 180
}

// Normalize value between 0 and 1
func Normalize(value, max int) float32 {
return 1 - float32(value)/float32(max)
}
Loading

0 comments on commit 2ff9750

Please sign in to comment.