laneya2

cave exploration game
git clone https://git.ce9e.org/laneya2.git

commit
ce90d27efadfe333a7a6c08980aaad059d26a93a
parent
21f124dd4256d40a40ee4212b7b7fdb21621195a
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2024-10-05 08:24
tweak speed

the old system could result in negative frequencies

in practice, the speed is limited by the keyboard repeat rate. But we
don't know that. A typical value is 30/s

Diffstat

M items.go 2 +-
M monster.go 12 ++++++++----
M player.go 2 +-
M server.go 6 ++++--

4 files changed, 14 insertions, 8 deletions


diff --git a/items.go b/items.go

@@ -16,7 +16,7 @@ type Item struct {
   16    16 	Attack      float64
   17    17 	Defense     float64
   18    18 	LineOfSight int
   19    -1 	Speed       float64
   -1    19 	Speed       int
   20    20 }
   21    21 
   22    22 var Items = map[string]Item{

diff --git a/monster.go b/monster.go

@@ -1,6 +1,9 @@
    1     1 package main
    2     2 
    3    -1 import "time"
   -1     3 import (
   -1     4 	"math"
   -1     5 	"time"
   -1     6 )
    4     7 
    5     8 type Monster struct {
    6     9 	Game    *Game
@@ -11,7 +14,7 @@ type Monster struct {
   11    14 	Health  float64
   12    15 	Attack  float64
   13    16 	Defense float64
   14    -1 	Speed   float64
   -1    17 	Speed   int
   15    18 }
   16    19 
   17    20 type MonsterMessage struct {
@@ -26,7 +29,7 @@ func makeMonster(game *Game, pos Point) *Monster {
   26    29 		Id:      game.createId(),
   27    30 		Rune:    'm',
   28    31 		Pos:     pos,
   29    -1 		Speed:   2,
   -1    32 		Speed:   0,
   30    33 		Attack:  2,
   31    34 		Defense: 0,
   32    35 		Health:  10,
@@ -36,7 +39,8 @@ func makeMonster(game *Game, pos Point) *Monster {
   36    39 }
   37    40 
   38    41 func (monster *Monster) run() {
   39    -1 	timeout := time.Duration(float64(time.Second) / monster.Speed)
   -1    42 	frequency := 2 * math.Pow(1.07, float64(monster.Speed))
   -1    43 	timeout := time.Duration(float64(time.Second) / frequency)
   40    44 	ticker := time.NewTicker(timeout)
   41    45 	defer ticker.Stop()
   42    46 

diff --git a/player.go b/player.go

@@ -20,7 +20,7 @@ type Player struct {
   20    20 	Attack      float64
   21    21 	Defense     float64
   22    22 	LineOfSight uint
   23    -1 	Speed       float64
   -1    23 	Speed       int
   24    24 	Inventory   map[string]uint
   25    25 	Weapon      string
   26    26 	Armor       string

diff --git a/server.go b/server.go

@@ -5,6 +5,7 @@ import (
    5     5 	"flag"
    6     6 	"fmt"
    7     7 	"log"
   -1     8 	"math"
    8     9 	"net"
    9    10 	"net/http"
   10    11 	"os"
@@ -42,7 +43,8 @@ func (player *Player) readPump() {
   42    43 		if timer != nil {
   43    44 			timer.Stop()
   44    45 		}
   45    -1 		timeout := time.Duration(float64(time.Second) / player.Speed)
   -1    46 		frequency := 10 * math.Pow(1.07, float64(player.Speed))
   -1    47 		timeout := time.Duration(float64(time.Second) / frequency)
   46    48 		timer = time.AfterFunc(time.Until(lastTime.Add(timeout)), func() {
   47    49 			lastTime = time.Now()
   48    50 			player.Game.Msg <- PlayerMessage{player, msg}
@@ -109,7 +111,7 @@ func serveWs(w http.ResponseWriter, r *http.Request) {
  109   111 		Attack:      5,
  110   112 		Defense:     0,
  111   113 		LineOfSight: 5,
  112    -1 		Speed:       20,
   -1   114 		Speed:       0,
  113   115 		Inventory:   make(map[string]uint),
  114   116 	}
  115   117 	conn.SetPongHandler(func(string) error {