Add support for fixed object geometry

also updated config file
This commit is contained in:
Stephen McQuay 2014-04-26 23:05:53 -07:00
parent 961cf5d7da
commit c9dfa27320
5 changed files with 54 additions and 10 deletions

View File

@ -1,7 +1,13 @@
{
"tick": 66,
"timescale": 1.0,
"width": 1600,
"height": 1100,
"obstacle": 20
"width": 1000,
"height": 500,
"obstacles": [
[100, 300, 200, 400],
[100, 100, 200, 200],
[400, 150, 600, 350],
[800, 300, 900, 400],
[800, 100, 900, 200]
]
}

View File

@ -64,6 +64,7 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
requested_game_name := c.Idg.Hash()
width, height := float64(c.Conf.Width), float64(c.Conf.Height)
obstacleCount := 0
obstacles := []Obstacle{}
maxPoints := c.Conf.MaxPoints
mode := "deathmatch"
@ -90,6 +91,7 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
width = float64(cfg.Width)
height = float64(cfg.Height)
obstacleCount = cfg.ObstacleCount
obstacles = cfg.Obstacles
maxPoints = cfg.MaxPoints
mode = cfg.Mode
}
@ -98,7 +100,27 @@ func (c *Controller) StartGame(w http.ResponseWriter, req *http.Request) {
if g == nil {
log.Printf("Game '%s' non-existant; making it now", requested_game_name)
var err error
g, err = NewGame(requested_game_name, width, height, obstacleCount, c.Conf.Tick, maxPoints, mode)
g, err = NewGame(
requested_game_name,
width,
height,
c.Conf.Tick,
maxPoints,
mode,
)
g.obstacleCount = obstacleCount
g.obstacles = obstacles
g.defaultObstacles = obstacles
if len(g.defaultObstacles) == 0 {
g.obstacles = GenerateObstacles(
g.obstacleCount,
g.width,
g.height,
)
} else {
g.obstacles = c.Conf.Obstacles
}
if err != nil {
log.Printf("problem creating game: %s: %s", requested_game_name, err)
b, _ := json.Marshal(NewFailure("game creation failure"))

View File

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

View File

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

View File

@ -177,11 +177,22 @@ func (c *Controller) AddPlayer(ws *websocket.Conn) {
gid.Id,
float64(c.Conf.Width),
float64(c.Conf.Height),
c.Conf.ObstacleCount,
c.Conf.Tick,
c.Conf.MaxPoints,
"",
)
game.defaultObstacles = c.Conf.Obstacles
game.obstacleCount = c.Conf.ObstacleCount
log.Printf("%t", len(game.defaultObstacles) == 0)
if len(game.defaultObstacles) == 0 {
game.obstacles = GenerateObstacles(
game.obstacleCount,
game.width,
game.height,
)
} else {
game.obstacles = c.Conf.Obstacles
}
if err != nil {
log.Printf("problem creating game: %s", gid.Id)
websocket.JSON.Send(ws, NewFailure("game creation error"))