Parcourir la source

Add support for fixed object geometry

also updated config file
Stephen McQuay il y a 5 ans
Parent
révision
c9dfa27320
5 fichiers modifiés avec 54 ajouts et 10 suppressions
  1. 9
    3
      config/server.json
  2. 23
    1
      control.go
  3. 7
    1
      deathmatch.go
  4. 3
    4
      game.go
  5. 12
    1
      protocol.go

+ 9
- 3
config/server.json Voir le fichier

@@ -1,7 +1,13 @@
1 1
 {
2 2
 	"tick": 66,
3 3
 	"timescale": 1.0,
4
-	"width": 1600,
5
-	"height": 1100,
6
-	"obstacle": 20
4
+	"width": 1000,
5
+	"height": 500,
6
+	"obstacles": [
7
+        [100, 300, 200, 400],
8
+        [100, 100, 200, 200],
9
+        [400, 150, 600, 350],
10
+        [800, 300, 900, 400],
11
+        [800, 100, 900, 200]
12
+    ]
7 13
 }

+ 23
- 1
control.go Voir le fichier

@@ -64,6 +64,7 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
64 64
 	requested_game_name := c.Idg.Hash()
65 65
 	width, height := float64(c.Conf.Width), float64(c.Conf.Height)
66 66
 	obstacleCount := 0
67
+	obstacles := []Obstacle{}
67 68
 	maxPoints := c.Conf.MaxPoints
68 69
 	mode := "deathmatch"
69 70
 
@@ -90,6 +91,7 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
90 91
 		width = float64(cfg.Width)
91 92
 		height = float64(cfg.Height)
92 93
 		obstacleCount = cfg.ObstacleCount
94
+		obstacles = cfg.Obstacles
93 95
 		maxPoints = cfg.MaxPoints
94 96
 		mode = cfg.Mode
95 97
 	}
@@ -98,7 +100,27 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
98 100
 	if g == nil {
99 101
 		log.Printf("Game '%s' non-existant; making it now", requested_game_name)
100 102
 		var err error
101
-		g, err = NewGame(requested_game_name, width, height, obstacleCount, c.Conf.Tick, maxPoints, mode)
103
+		g, err = NewGame(
104
+			requested_game_name,
105
+			width,
106
+			height,
107
+			c.Conf.Tick,
108
+			maxPoints,
109
+			mode,
110
+		)
111
+		g.obstacleCount = obstacleCount
112
+		g.obstacles = obstacles
113
+		g.defaultObstacles = obstacles
114
+		if len(g.defaultObstacles) == 0 {
115
+			g.obstacles = GenerateObstacles(
116
+				g.obstacleCount,
117
+				g.width,
118
+				g.height,
119
+			)
120
+		} else {
121
+			g.obstacles = c.Conf.Obstacles
122
+		}
123
+
102 124
 		if err != nil {
103 125
 			log.Printf("problem creating game: %s: %s", requested_game_name, err)
104 126
 			b, _ := json.Marshal(NewFailure("game creation failure"))

+ 7
- 1
deathmatch.go Voir le fichier

@@ -17,7 +17,13 @@ func (g *deathmatch) gameOver(gg *Game) (bool, *GameOver) {
17 17
 	var stats *GameOver
18 18
 
19 19
 	if gg.players_remaining <= 1 && len(gg.players) > 1 {
20
-		gg.obstacles = GenerateObstacles(gg.obstacle_count, gg.width, gg.height)
20
+		if len(gg.defaultObstacles) == 0 {
21
+			gg.obstacles = GenerateObstacles(
22
+				gg.obstacleCount,
23
+				gg.width,
24
+				gg.height,
25
+			)
26
+		}
21 27
 		log.Printf("game %s: game over", gg.id)
22 28
 		stats = NewGameOver()
23 29
 

+ 3
- 4
game.go Voir le fichier

@@ -59,8 +59,9 @@ type Game struct {
59 59
 	players           map[*Player]bool
60 60
 	projectiles       map[*Projectile]bool
61 61
 	splosions         map[*Splosion]bool
62
+	defaultObstacles  []Obstacle
62 63
 	obstacles         []Obstacle
63
-	obstacle_count    int
64
+	obstacleCount     int
64 65
 	register          chan *Player
65 66
 	unregister        chan *Player
66 67
 	turn              int
@@ -87,7 +88,7 @@ type GameMode interface {
87 88
 }
88 89
 
89 90
 // NewGame Poplulates a Game struct and starts the bandwidth calculator.
90
-func NewGame(id string, width, height float64, obstacles, tick, maxPoints int, mode string) (*Game, error) {
91
+func NewGame(id string, width, height float64, tick, maxPoints int, mode string) (*Game, error) {
91 92
 	bw, err := bandwidth.NewBandwidth(
92 93
 		[]int{1, 10, 60},
93 94
 		1*time.Second,
@@ -102,8 +103,6 @@ func NewGame(id string, width, height float64, obstacles, tick, maxPoints int, m
102 103
 		unregister:        make(chan *Player, maxPlayer),
103 104
 		projectiles:       make(map[*Projectile]bool),
104 105
 		splosions:         make(map[*Splosion]bool),
105
-		obstacles:         GenerateObstacles(obstacles, width, height),
106
-		obstacle_count:    obstacles,
107 106
 		players:           make(map[*Player]bool),
108 107
 		turn:              0,
109 108
 		width:             width,

+ 12
- 1
protocol.go Voir le fichier

@@ -177,11 +177,22 @@ func (c *Controller) AddPlayer(ws *websocket.Conn) {
177 177
 			gid.Id,
178 178
 			float64(c.Conf.Width),
179 179
 			float64(c.Conf.Height),
180
-			c.Conf.ObstacleCount,
181 180
 			c.Conf.Tick,
182 181
 			c.Conf.MaxPoints,
183 182
 			"",
184 183
 		)
184
+		game.defaultObstacles = c.Conf.Obstacles
185
+		game.obstacleCount = c.Conf.ObstacleCount
186
+		log.Printf("%t", len(game.defaultObstacles) == 0)
187
+		if len(game.defaultObstacles) == 0 {
188
+			game.obstacles = GenerateObstacles(
189
+				game.obstacleCount,
190
+				game.width,
191
+				game.height,
192
+			)
193
+		} else {
194
+			game.obstacles = c.Conf.Obstacles
195
+		}
185 196
 		if err != nil {
186 197
 			log.Printf("problem creating game: %s", gid.Id)
187 198
 			websocket.JSON.Send(ws, NewFailure("game creation error"))

Chargement…
Annuler
Enregistrer