vedvid / rawig Goto Github PK
View Code? Open in Web Editor NEWRAWIG (Roguelike Architecture, Written In Go) is ready to modify and expand roguelike architecture.
License: BSD 2-Clause "Simplified" License
RAWIG (Roguelike Architecture, Written In Go) is ready to modify and expand roguelike architecture.
License: BSD 2-Clause "Simplified" License
On (0, 0) everything works fine. On (25, 0) there is slide show.
Add bool "consumable" and "charges" maybe? Then checks for their values, and if consumable is true then charges-- and if charge == 0 then removes from inventory.
So, instead of lots of different fields as now:
type EquipmentComponent struct {
Slot1 *Object
Slot2 *Object
Slot3 *Object
}
Use something different.
At first, I had some ideas (hashmaps, embedded structs, etc) but all of them have major flaws.
func (c *Creature) PickUp(o Objects) bool {
turnSpent := false
for i, v := range o {
if v.X == c.X && v.Y == c.Y && v.Pickable == true {
item := o[i]
c.Inventory = append(c.Inventory, item)
fmt.Println(len(o))
o[i] = o[len(o)-1] // Doesn't it leaks a memory? \/
o = o[:len(o)-1] // It's slice of pointers to struct.
fmt.Println(len(o))
turnSpent = true
break
}
}
return turnSpent
}
After picking item up, len(o) becomes smaller. But item remains on the ground. After another picking up, len(o) is the same as at start of previous call.
It's about pointers?
It should create 360 field surrounding player
So, for example, instead of calling RenderAll(items, monsters, tiles, messages) it would call RenderAll(gameData)
It's related to #29
It should be - due to nature of created graph - as easy as backtracking from start to goal.
So developer won't need to call blt.ClearArea() //print something here// blt.Refresh() blt.Read() all the time (like in PrintMenu() in ui.go currently)
For now:
in ai.go:
func MonstersTakeTurn(b Board, m Monsters) {
for _, v := range m {
if v.DistanceTo(PLAYER) > 1 {
switch v.AIType {
case AIDumb:
v.MoveTowardsDumb()
}
}
}
}
I want to:
ais = map[int]METHODS{
AIDumb: MoveTowardsDumb,
}
func MonstersTakeTurn(b Board, m Monsters) {
for _, v := range m {
if v.DistanceTo(PLAYER) > 1 {
ais[v.AIType]()
}
}
}
I'm working from scratch, and technically this project has nothing to do with Jotaf's work, but his tutorial was my first experience in developing roguelike, and even now, years later, I see influences. So, I'd like to add this info to readme file.
Depends on #29
It won't be saved at all, at least.
Current one have to pass big amount of arguments. Maybe it should accept Properties structs instead?
It doesn't need immediate work - just something to do, when destructible environment feature will be in development.
This issue is answer for doubts during closing #26
For example, now there is code duplication.
p.InventoryMenu() is exactly the same as p.EquipmentMenu() but with different arguments. It should be easy to avoid such a code repetition: PrintInventoryMenu and PrintEquipmentMenu both creates slices of strings using Char of Object; it could be done by general ObjectsToStrings function.
But first, I'd like to have things done and working.
In inventory, with item sub-menu open, I pressed down arrow. Earlier, I pressed right arrow, and menu closed. Itended behaviour: menu remain open.
panic: runtime error: index out of range
goroutine 1 [running, locked to thread]:
main.(*Creature).InventoryActions(0xc000046140, 0xc000075f70, 0x0, 0x4)
D:/Programowanie/golang/projects/src/RAWIG/player.go:131 +0x5bd
main.(*Creature).HandleInventory(0xc000046140, 0xc000075f70, 0x0, 0xa)
D:/Programowanie/golang/projects/src/RAWIG/player.go:115 +0x62
main.(*Creature).InventoryMenu(0xc000046140, 0xc000075f70, 0x462b50)
D:/Programowanie/golang/projects/src/RAWIG/player.go:92 +0xa6
main.Controls(0xc, 0xc000046140, 0xc000068000, 0x1e, 0x1e, 0xc000075f30, 0x2, 0x2, 0xc000075f70, 0x1000001)
D:/Programowanie/golang/projects/src/RAWIG/controls.go:48 +0x73
main.main()
D:/Programowanie/golang/projects/src/RAWIG/main.go:59 +0x61f
Exception 0xc0000005 0x0 0x10 0x7ffef8b66e1e
PC=0x7ffef8b66e1e
runtime: unknown pc 0x7ffef8b66e1e
stack: frame={sp:0x92f4f0, fp:0x0} stack=[0x0,0x92fdf0)
000000000092f3f0: 0000000009a80070 0000000000000001
000000000092f400: 0000000000eb0300 0000000000000000
000000000092f410: 0000000000000190 0000000000000032
000000000092f420: 0000000009ad1c40 00000000026840a0
000000000092f430: 00000000003e0009 0000000000000000
000000000092f440: 0000000009ad1c30 0000000009b11f60
000000000092f450: 0000000000000000 0000000000000001
000000000092f460: 0000000000eb3090 0000000000000006
000000000092f470: 0000000009ad1f60 00007ffef8b65e95
000000000092f480: 0000000000000200 0000000000eb0000
000000000092f490: 0000000000004139 0000000009a80000
000000000092f4a0: 0000000000ef0080 00000000000000c5
000000000092f4b0: 000000000267eca0 000000010000006f
000000000092f4c0: 0000000000000300 0000000000000101
000000000092f4d0: 0000000009b11f60 0000000000004139
000000000092f4e0: 0000000002693c90 00007ffef8bf98a5
000000000092f4f0: <0000000000000000 0000000002677ba0
000000000092f500: 0000000000000430 00000001026e3a50
000000000092f510: 0000000000000000 0000000000000000
000000000092f520: 0000000000000000 0000000000000030
000000000092f530: 0000000000eb30d4 00000000000000c5
000000000092f540: 0000000000000068 0000000000000032
000000000092f550: 0000000002679af0 0000000009ad1c30
000000000092f560: 000000000000001a 0000000005697c60
000000000092f570: 0000000004d3cf40 0000000000000000
000000000092f580: 0000000000000010 0000000077339c6c
000000000092f590: 0000000000000000 000000000000000d
000000000092f5a0: 0000000021000021 0000000000000000
000000000092f5b0: 00000000058a1590 00000000765c5377
000000000092f5c0: 00000000058a1590 0000000000000000
000000000092f5d0: 00000000058a1590 0000000000000000
000000000092f5e0: 0000000069000069 00007ffef64398bc
runtime: unknown pc 0x7ffef8b66e1e
stack: frame={sp:0x92f4f0, fp:0x0} stack=[0x0,0x92fdf0)
000000000092f3f0: 0000000009a80070 0000000000000001
000000000092f400: 0000000000eb0300 0000000000000000
000000000092f410: 0000000000000190 0000000000000032
000000000092f420: 0000000009ad1c40 00000000026840a0
000000000092f430: 00000000003e0009 0000000000000000
000000000092f440: 0000000009ad1c30 0000000009b11f60
000000000092f450: 0000000000000000 0000000000000001
000000000092f460: 0000000000eb3090 0000000000000006
000000000092f470: 0000000009ad1f60 00007ffef8b65e95
000000000092f480: 0000000000000200 0000000000eb0000
000000000092f490: 0000000000004139 0000000009a80000
000000000092f4a0: 0000000000ef0080 00000000000000c5
000000000092f4b0: 000000000267eca0 000000010000006f
000000000092f4c0: 0000000000000300 0000000000000101
000000000092f4d0: 0000000009b11f60 0000000000004139
000000000092f4e0: 0000000002693c90 00007ffef8bf98a5
000000000092f4f0: <0000000000000000 0000000002677ba0
000000000092f500: 0000000000000430 00000001026e3a50
000000000092f510: 0000000000000000 0000000000000000
000000000092f520: 0000000000000000 0000000000000030
000000000092f530: 0000000000eb30d4 00000000000000c5
000000000092f540: 0000000000000068 0000000000000032
000000000092f550: 0000000002679af0 0000000009ad1c30
000000000092f560: 000000000000001a 0000000005697c60
000000000092f570: 0000000004d3cf40 0000000000000000
000000000092f580: 0000000000000010 0000000077339c6c
000000000092f590: 0000000000000000 000000000000000d
000000000092f5a0: 0000000021000021 0000000000000000
000000000092f5b0: 00000000058a1590 00000000765c5377
000000000092f5c0: 00000000058a1590 0000000000000000
000000000092f5d0: 00000000058a1590 0000000000000000
000000000092f5e0: 0000000069000069 00007ffef64398bc
goroutine 1 [running, locked to thread]:
main.(*Creature).InventoryActions(0xc000046140, 0xc000075f70, 0x0, 0x4)
D:/Programowanie/golang/projects/src/RAWIG/player.go:131 +0x5bd
main.(*Creature).HandleInventory(0xc000046140, 0xc000075f70, 0x0, 0xa)
D:/Programowanie/golang/projects/src/RAWIG/player.go:115 +0x62
main.(*Creature).InventoryMenu(0xc000046140, 0xc000075f70, 0x462b50)
D:/Programowanie/golang/projects/src/RAWIG/player.go:92 +0xa6
main.Controls(0xc, 0xc000046140, 0xc000068000, 0x1e, 0x1e, 0xc000075f30, 0x2, 0x2, 0xc000075f70, 0x1000001)
D:/Programowanie/golang/projects/src/RAWIG/controls.go:48 +0x73
main.main()
D:/Programowanie/golang/projects/src/RAWIG/main.go:59 +0x61f
rax 0x0
rbx 0x58a1590
rcx 0x13
rdi 0x0
rsi 0x0
rbp 0x58a1590
rsp 0x92f4f0
r8 0x58a1590
r9 0x0
r10 0x1
r11 0x1
r12 0x0
r13 0x5513710
r14 0x5697c60
r15 0x0
rip 0x7ffef8b66e1e
rflags 0x10206
cs 0x33
fs 0x53
gs 0x2b
in Controls (controls.go):
... takeTurn := false
...
... takeTurn = p.MoveOrAttack
... return takeTurn
in Move (monsters.go):
... takeTurn := false
... if tile is not blocked: do something; else: takeTurn = true
... return takeTurn
Depends on #29
Probably because it's looking for (-1, 0) coords etc
Depends on #29
Intended: start on unexplored map, and turn tiles in fov to always visible
Encountered: tiles are not printed at all
Maybe could I make dungeon features as tiles?
For now, comments are kinda mess. Sometimes they uses multiple sentences, sometimes it's only one, long sentence with lots of ";". It would be more readable if space would be inserted between /* and first word.
Example:
/*RenderWeights is created for debugging purposes;
it clears whole map, and prints Weights of all nodes
of graph, then waits for user input to reset;
it's supposed to be called near the end of
MoveTowardsPath method.*/
would become
/* RenderWeights is created for debugging purposes
It clears whole map and prints Weights of all nodes
of graph, then waits for user input to reset.
It's supposed to be called near the end of
MoveTowardsPath method. */
Currently it does take coords. Maybe it's worth to use interface?
For example, MoveOrAttack and Move and Attack should take similar set of arguments. But now some functions takes coordinations, other uses *Creature, etc.
+I should add monsterData file with monsters declarations, so monsters.go would be just function file, and monster data - data file.
Explicit pointers:
objects := []*Object
turnSpent := Controls(key, player, cells, actors, &objects)
So, it's basically referencing and dereferencing all the time. It may be ugly, but currently I'm using these slices as values mostly, so...
Hidden:
objects := &[]*Object
turnSpent := Controls(key, player, cells, actors, objects)
The difference is that I'm declaring pointer only during declaration&initialization. On the other hand, I still need to dereference slices to range over them, or make indexing. If I would decide to make pointers hidden, probably I'd have to change all passed slices to pointers to slices, because it's going to be hard to track which slice is pointer, and which one is value.
For example, RenderCreatures does sort all Creatures! It's not effective in terms of performance, not elegant (it's rendering function, it should do display work only), and makes whole rendering codebase a bit inconsistent ("range" vs "iterate downwards").
Currently it's global variable []string
Is it worth to implement specified type, like type StringBuffer []string
?
Should I pass global buffer, or change it in-place?
func AddMessage(msg string, msgs []string) { //pass global MessageLog as argument? Or pointer?
//do something with msgs
}
vs
func AddMessage(msg string) {
//do something with global MessageLog
}
So, instead of creating sword that is pickable and equippable, I'd create sword that is Equipment, so it may be picked up and equipped.
Depends on #29
It's defined as enum (bigger than TileLayer), but tiles are not overdisplayed by corpses
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.