Coder Social home page Coder Social logo

vedvid / rawig Goto Github PK

View Code? Open in Web Editor NEW
15.0 5.0 2.0 572 KB

RAWIG (Roguelike Architecture, Written In Go) is ready to modify and expand roguelike architecture.

License: BSD 2-Clause "Simplified" License

Go 100.00%
roguelike roguelike-game roguelike-architecture roguelike-engine roguelike-library

rawig's People

Contributors

adam-weiler avatar trayo avatar vedvid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rawig's Issues

After finishing menuses, polish Inventory and Equipment

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.

Think about messages buffer

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  
}  

equipment implementation ideas

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.

Clean rendering functions

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").

Use map of methods instead of switch-case for ai handling

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]()
		}
	}
}

Crash with invalid input (new inventory system introduced in 3688c57aa6b09194351d05bb94dfb3c86bc8f479 )

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

Consumables with multiple uses

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.

Better and unified comment style.

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. */

Keep declaring objects, creatures and board as []*T, or start to use *[]*T? Also, keep pointers "explicit" or make them hidden?

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.

Handle "takeTurn"

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

Can't remove Object from Objects by PickUp method of Creature

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?

Wrong layer of corpses

It's defined as enum (bigger than TileLayer), but tiles are not overdisplayed by corpses

add info about roguebasin python + libtcod tutorial by Jotaf

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.

Clean move / attack code

For example, MoveOrAttack and Move and Attack should take similar set of arguments. But now some functions takes coordinations, other uses *Creature, etc.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.