- commit
- 817901d5e3c990f8e1b2cee52965abe4e8c92f78
- parent
- 53953138c7716203136acb82667ef3ff1019e42f
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2024-10-05 07:36
convert some stats to float
Diffstat
| M | items.go | 6 | +++--- |
| M | monster.go | 12 | ++++++------ |
| M | player.go | 19 | ++++++++++++------- |
| M | server.go | 2 | +- |
4 files changed, 22 insertions, 17 deletions
diff --git a/items.go b/items.go
@@ -13,10 +13,10 @@ type Item struct {
13 13 Value uint
14 14 Health uint
15 15 HealthTotal uint
16 -1 Attack uint
17 -1 Defense uint
-1 16 Attack float64
-1 17 Defense float64
18 18 LineOfSight int
19 -1 Speed int
-1 19 Speed float64
20 20 }
21 21
22 22 var Items = map[string]Item{
diff --git a/monster.go b/monster.go
@@ -8,10 +8,10 @@ type Monster struct {
8 8 Id int
9 9 Rune rune
10 10 Pos Point
11 -1 Health uint
12 -1 Attack uint
13 -1 Defense uint
14 -1 Speed uint
-1 11 Health float64
-1 12 Attack float64
-1 13 Defense float64
-1 14 Speed float64
15 15 }
16 16
17 17 type MonsterMessage struct {
@@ -36,7 +36,7 @@ func makeMonster(game *Game, pos Point) *Monster {
36 36 }
37 37
38 38 func (monster *Monster) run() {
39 -1 timeout := time.Duration(float32(time.Second) / float32(monster.Speed))
-1 39 timeout := time.Duration(float64(time.Second) / monster.Speed)
40 40 ticker := time.NewTicker(timeout)
41 41 defer ticker.Stop()
42 42
@@ -73,7 +73,7 @@ func (monster *Monster) run() {
73 73 }
74 74 }
75 75
76 -1 func (monster *Monster) TakeDamage(amount uint) {
-1 76 func (monster *Monster) TakeDamage(amount float64) {
77 77 if amount > monster.Health {
78 78 monster.quit <- true
79 79 delete(monster.Game.Monsters, monster)
diff --git a/player.go b/player.go
@@ -1,6 +1,10 @@ 1 1 package main 2 23 -1 import "github.com/gorilla/websocket"-1 3 import ( -1 4 "math" -1 5 -1 6 "github.com/gorilla/websocket" -1 7 ) 4 8 5 9 type Player struct { 6 10 Game *Game @@ -13,10 +17,10 @@ type Player struct { 13 17 Pos Point 14 18 Health uint 15 19 HealthTotal uint16 -1 Attack uint17 -1 Defense uint-1 20 Attack float64 -1 21 Defense float64 18 22 LineOfSight uint19 -1 Speed uint-1 23 Speed float64 20 24 Inventory map[string]uint 21 25 Weapon string 22 26 Armor string @@ -38,7 +42,8 @@ func (player *Player) Flush() { 38 42 } 39 43 } 40 4441 -1 func (player *Player) TakeDamage(amount uint) {-1 45 func (player *Player) TakeDamage(rawAmount float64) { -1 46 amount := uint(math.Round(rawAmount)) 42 47 if amount > player.Health { 43 48 player.quit <- true 44 49 } else { @@ -65,7 +70,7 @@ func (player *Player) ApplyItem(item Item) { 65 70 player.Attack += item.Attack 66 71 player.Defense += item.Defense 67 72 player.LineOfSight = uint(int(player.LineOfSight) + item.LineOfSight)68 -1 player.Speed = uint(int(player.Speed) + item.Speed)-1 73 player.Speed += item.Speed 69 74 } 70 75 71 76 func (player *Player) UnapplyItem(item Item) { @@ -74,7 +79,7 @@ func (player *Player) UnapplyItem(item Item) { 74 79 player.Attack -= item.Attack 75 80 player.Defense -= item.Defense 76 81 player.LineOfSight = uint(int(player.LineOfSight) - item.LineOfSight)77 -1 player.Speed = uint(int(player.Speed) - item.Speed)-1 82 player.Speed -= item.Speed 78 83 } 79 84 80 85 func (player *Player) AddItem(item string, amount uint) {
diff --git a/server.go b/server.go
@@ -42,7 +42,7 @@ func (player *Player) readPump() {
42 42 if timer != nil {
43 43 timer.Stop()
44 44 }
45 -1 timeout := time.Duration(float32(time.Second) / float32(player.Speed))
-1 45 timeout := time.Duration(float64(time.Second) / player.Speed)
46 46 timer = time.AfterFunc(time.Until(lastTime.Add(timeout)), func() {
47 47 lastTime = time.Now()
48 48 player.Game.Msg <- PlayerMessage{player, msg}