Skip to content

Commit

Permalink
Merge pull request #13 from kensonjohnson/inventory
Browse files Browse the repository at this point in the history
Setup Inventory Panel
  • Loading branch information
kensonjohnson authored Sep 11, 2024
2 parents 3067a7e + b98aee1 commit 7180b04
Show file tree
Hide file tree
Showing 55 changed files with 1,297 additions and 670 deletions.
54 changes: 54 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
set quiet := true

MAIN_PACKAGE_PATH := "."
BINARY_NAME := "rougelike-demo"

[private]
help:
just --list --unsorted

_confirm:
echo -n 'Are you sure? [y/N] ' && read ans && [ $${ans:-N} = y ]

# Run dev server
dev:
go run . -debug

# Run all Go test files
test:
go test -v -race -buildvcs ./...

# Prepare and audit code, then push to Git Remote
push: tidy audit no-dirty
git push

# Verify and Vet all Go files in project
audit:
go mod verify
go vet ./...

[private]
no-dirty:
git diff --exit-code

# Run formatter and tidy over all Go files in project
tidy:
go fmt ./...
go mod tidy -v

# Build for current OS/Arch
build:
# Include additional build steps, like TypeScript, SCSS or Tailwind compilation here...
go build -o=/tmp/bin/{{ BINARY_NAME }} {{ MAIN_PACKAGE_PATH }}

# Build for current OS/Arch and run the resulting binary
run: build
/tmp/bin/{{ BINARY_NAME }}

# Matrix build for all OS/Architectures
production-deploy: _confirm tidy audit
GOOS=darwin GOARCH=arm64 go build -ldflags='-s' -o=/tmp/bin/macos_arm64/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
GOOS=windows GOARCH=amd64 go build -ldflags='-s' -o=/tmp/bin/windows_amd64/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
GOOS=windows GOARCH=arm go build -ldflags='-s' -o=/tmp/bin/windows_arm/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
GOOS=windows GOARCH=arm64 go build -ldflags='-s' -o=/tmp/bin/windows_arm64/${BINARY_NAME} ${MAIN_PACKAGE_PATH}
# Include additional deployment steps here...
101 changes: 0 additions & 101 deletions Makefile

This file was deleted.

14 changes: 6 additions & 8 deletions archetype/armor.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package archetype

import (
"github.com/kensonjohnson/roguelike-game-go/archetype/tags"
"github.com/kensonjohnson/roguelike-game-go/component"
"github.com/kensonjohnson/roguelike-game-go/items/armors"
"github.com/kensonjohnson/roguelike-game-go/items"
"github.com/yohamta/donburi"
)

var ArmorTag = donburi.NewTag("armor")

func CreateNewArmor(world donburi.World, armorId armors.ArmorId) *donburi.Entry {
armorData := armors.Data[armorId]
entry := CreateNewItem(world, int(armorId), armorData.Name, armorData.Sprite)
func CreateNewArmor(world donburi.World, armorData items.ArmorData) *donburi.Entry {
entry := CreateNewItem(world, &armorData.ItemData)

// Mark as an armor
entry.AddComponent(ArmorTag)
entry.AddComponent(tags.ArmorTag)

// Add defense data
entry.AddComponent(component.Defense)
Expand All @@ -27,5 +25,5 @@ func CreateNewArmor(world donburi.World, armorId armors.ArmorId) *donburi.Entry
}

func IsArmor(entry *donburi.Entry) bool {
return entry.HasComponent(ArmorTag)
return entry.HasComponent(tags.ArmorTag)
}
34 changes: 19 additions & 15 deletions archetype/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,22 @@ package archetype

import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/kensonjohnson/roguelike-game-go/archetype/tags"
"github.com/kensonjohnson/roguelike-game-go/component"
"github.com/kensonjohnson/roguelike-game-go/config"
"github.com/kensonjohnson/roguelike-game-go/internal/logger"
"github.com/kensonjohnson/roguelike-game-go/internal/config"
"github.com/setanarut/kamera/v2"
"github.com/yohamta/donburi"
)

var CameraTag = donburi.NewTag("camera")

func CreateNewCamera(world donburi.World) {
var entry *donburi.Entry
var ok bool
if entry, ok = PlayerTag.First(world); !ok {
logger.ErrorLogger.Panic("CreateNewCamera failed: Player not found")
}
playerPosition := component.Position.Get(entry)

entry = world.Entry(world.Create(
CameraTag,
entry := world.Entry(world.Create(
tags.CameraTag,
component.Camera,
))

cameraData := &component.CameraData{
MainCamera: kamera.NewCamera(
float64((playerPosition.X*config.TileWidth)+config.TileWidth/2),
float64((playerPosition.Y*config.TileHeight)+config.TileHeight/2),
0, 0,
config.ScreenWidth*config.TileWidth,
(config.ScreenHeight-config.UIHeight)*config.TileHeight,
),
Expand All @@ -45,3 +35,17 @@ func CreateNewCamera(world donburi.World) {

component.Camera.Set(entry, cameraData)
}

func ReplaceCamera(world donburi.World, playerX, playerY float64) {
entry := tags.CameraTag.MustFirst(world)
camera := component.Camera.Get(entry)
camera.MainCamera = kamera.NewCamera(
playerX, playerY,
config.ScreenWidth*config.TileWidth,
(config.ScreenHeight-config.UIHeight)*config.TileHeight,
)
camera.MainCamera.Lerp = true
camera.MainCamera.ZoomFactor = 100
camera.MainCamera.ShakeOptions.MaxShakeAngle = 0
camera.MainCamera.ShakeOptions.Decay = 0.5
}
14 changes: 6 additions & 8 deletions archetype/consumable.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package archetype

import (
"github.com/kensonjohnson/roguelike-game-go/archetype/tags"
"github.com/kensonjohnson/roguelike-game-go/component"
"github.com/kensonjohnson/roguelike-game-go/items/consumables"
"github.com/kensonjohnson/roguelike-game-go/items"
"github.com/yohamta/donburi"
)

var ConsumableTag = donburi.NewTag("consumable")
func CreateNewConsumable(world donburi.World, consumableData items.ConsumableData) *donburi.Entry {

func CreateNewConsumable(world donburi.World, consumablesId consumables.ConsumablesId) *donburi.Entry {
consumableData := consumables.Data[consumablesId]

entry := CreateNewItem(world, int(consumablesId), consumableData.Name, consumableData.Sprite)
entry := CreateNewItem(world, &consumableData.ItemData)

// Mark as a consumable
entry.AddComponent(ConsumableTag)
entry.AddComponent(tags.ConsumableTag)

// Add heal data
entry.AddComponent(component.Heal)
Expand All @@ -27,5 +25,5 @@ func CreateNewConsumable(world donburi.World, consumablesId consumables.Consumab
}

func IsConsumable(entry *donburi.Entry) bool {
return entry.HasComponent(ConsumableTag)
return entry.HasComponent(tags.ConsumableTag)
}
29 changes: 14 additions & 15 deletions archetype/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,43 @@ package archetype
import (
"errors"

"github.com/hajimehoshi/ebiten/v2"
"github.com/kensonjohnson/roguelike-game-go/archetype/tags"
"github.com/kensonjohnson/roguelike-game-go/component"
"github.com/kensonjohnson/roguelike-game-go/items"
"github.com/yohamta/donburi"
)

func CreateNewItem(world donburi.World, itemId int, itemName string, itemImage *ebiten.Image) *donburi.Entry {
item := world.Entry(world.Create(
component.ItemId,
func CreateNewItem(world donburi.World, itemData *items.ItemData) *donburi.Entry {
entry := world.Entry(world.Create(
tags.ItemTag,
component.Name,
component.Sprite,
))

id := component.ItemIdData{
Id: itemId,
}
component.ItemId.SetValue(item, id)

name := component.NameData{
Value: itemName,
Value: itemData.Name,
}
component.Name.SetValue(item, name)
component.Name.SetValue(entry, name)

sprite := component.SpriteData{
Image: itemImage,
Image: itemData.Sprite,
}
component.Sprite.SetValue(item, sprite)
component.Sprite.SetValue(entry, sprite)

return item
return entry
}

func isItem(entry *donburi.Entry) bool {
return entry.HasComponent(component.ItemId)
return entry.HasComponent(tags.ItemTag)
}

func PlaceItemInWorld(entry *donburi.Entry, x, y int, discoverable bool) error {
if !isItem(entry) {
return errors.New("entry is not an Item Entity")
}

entry.AddComponent(tags.PickupTag)

entry.AddComponent(component.Position)
position := component.PositionData{
X: x,
Expand All @@ -59,6 +57,7 @@ func PlaceItemInWorld(entry *donburi.Entry, x, y int, discoverable bool) error {
}

func RemoveItemFromWorld(entry *donburi.Entry) {
entry.RemoveComponent(tags.PickupTag)
entry.RemoveComponent(component.Position)
if entry.HasComponent(component.Discoverable) {
entry.RemoveComponent(component.Discoverable)
Expand Down
Loading

0 comments on commit 7180b04

Please sign in to comment.