game types, deathmatch and melee
This commit is contained in:
parent
845db00032
commit
9583de2ffa
42
deathmatch.go
Normal file
42
deathmatch.go
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type deathmatch struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *deathmatch) setup(gg *game) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *deathmatch) gameOver(gg *game) (bool, *GameOver) {
|
||||||
|
over := false
|
||||||
|
var stats *GameOver
|
||||||
|
|
||||||
|
if gg.players_remaining <= 1 && len(gg.players) > 1 {
|
||||||
|
gg.obstacles = GenerateObstacles(gg.obstacle_count, gg.width, gg.height)
|
||||||
|
log.Printf("game %s: game over", gg.id)
|
||||||
|
stats = NewGameOver()
|
||||||
|
|
||||||
|
for p := range gg.players {
|
||||||
|
for _, r := range p.Robots {
|
||||||
|
if r.Health > 0 {
|
||||||
|
log.Printf("Robot %v Survived", r.Id)
|
||||||
|
gg.winners.Lock()
|
||||||
|
gg.winners.m[r.Id] += 1
|
||||||
|
gg.winners.Unlock()
|
||||||
|
stats.Winners = append(stats.Winners, r.Id)
|
||||||
|
}
|
||||||
|
r.reset(gg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
over = true
|
||||||
|
}
|
||||||
|
return over, stats
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *deathmatch) tick(gg *game, payload *Boardstate) {
|
||||||
|
|
||||||
|
}
|
40
game.go
40
game.go
@ -66,6 +66,13 @@ type game struct {
|
|||||||
repair_rate float32
|
repair_rate float32
|
||||||
tick_duration int
|
tick_duration int
|
||||||
winners WinnerMap
|
winners WinnerMap
|
||||||
|
mode GameMode
|
||||||
|
}
|
||||||
|
|
||||||
|
type GameMode interface {
|
||||||
|
setup(g *game)
|
||||||
|
tick(gg *game, payload *Boardstate)
|
||||||
|
gameOver(gg *game) (bool, *GameOver)
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewGame(id string, width, height float32, obstacles, tick, maxPoints int) *game {
|
func NewGame(id string, width, height float32, obstacles, tick, maxPoints int) *game {
|
||||||
@ -91,7 +98,11 @@ func NewGame(id string, width, height float32, obstacles, tick, maxPoints int) *
|
|||||||
tick_duration: tick,
|
tick_duration: tick,
|
||||||
players_remaining: 2,
|
players_remaining: 2,
|
||||||
winners: WinnerMap{m: make(map[string]int)},
|
winners: WinnerMap{m: make(map[string]int)},
|
||||||
|
mode: &melee{respawn: make(map[*Robot]float64)},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.mode.setup(g)
|
||||||
|
|
||||||
log.Printf("NewGame: %+v", g)
|
log.Printf("NewGame: %+v", g)
|
||||||
return g
|
return g
|
||||||
}
|
}
|
||||||
@ -285,11 +296,12 @@ func (g *game) run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UPDATE GAME STATE
|
// UPDATE GAME STATE
|
||||||
if end, data := g.gameOver(); end {
|
if end, data := g.mode.gameOver(g); end {
|
||||||
g.sendGameOver(data)
|
g.sendGameOver(data)
|
||||||
}
|
}
|
||||||
|
|
||||||
g.tick(payload)
|
g.tick(payload)
|
||||||
|
g.mode.tick(g, payload)
|
||||||
|
|
||||||
t1 = time.Now()
|
t1 = time.Now()
|
||||||
if *verbose {
|
if *verbose {
|
||||||
@ -307,32 +319,6 @@ func (g *game) run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *game) gameOver() (bool, *GameOver) {
|
|
||||||
over := false
|
|
||||||
var stats *GameOver
|
|
||||||
|
|
||||||
if g.players_remaining <= 1 && len(g.players) > 1 {
|
|
||||||
g.obstacles = GenerateObstacles(g.obstacle_count, g.width, g.height)
|
|
||||||
log.Printf("game %s: game over", g.id)
|
|
||||||
stats = NewGameOver()
|
|
||||||
|
|
||||||
for p := range g.players {
|
|
||||||
for _, r := range p.Robots {
|
|
||||||
if r.Health > 0 {
|
|
||||||
log.Printf("Robot %v Survived", r.Id)
|
|
||||||
g.winners.Lock()
|
|
||||||
g.winners.m[r.Id] += 1
|
|
||||||
g.winners.Unlock()
|
|
||||||
stats.Winners = append(stats.Winners, r.Id)
|
|
||||||
}
|
|
||||||
r.reset(g)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
over = true
|
|
||||||
}
|
|
||||||
return over, stats
|
|
||||||
}
|
|
||||||
|
|
||||||
func (g *game) sendGameOver(eg *GameOver) {
|
func (g *game) sendGameOver(eg *GameOver) {
|
||||||
log.Printf("sending out game over message: %+v", eg)
|
log.Printf("sending out game over message: %+v", eg)
|
||||||
for p := range g.players {
|
for p := range g.players {
|
||||||
|
39
melee.go
Normal file
39
melee.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
type melee struct {
|
||||||
|
respawn map[*Robot]float64
|
||||||
|
respawn_timer float64
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *melee) setup(gg *game) {
|
||||||
|
g.respawn_timer = 5000
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *melee) gameOver(gg *game) (bool, *GameOver) {
|
||||||
|
return false, &GameOver{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *melee) tick(gg *game, payload *Boardstate) {
|
||||||
|
for p := range gg.players {
|
||||||
|
for _, r := range p.Robots {
|
||||||
|
_, ok := g.respawn[r]
|
||||||
|
if r.Health <= 0 && !ok {
|
||||||
|
g.respawn[r] = g.respawn_timer
|
||||||
|
log.Printf("%v Died, Respawn in %v", r.Name, g.respawn_timer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for r, _ := range g.respawn {
|
||||||
|
g.respawn[r] -= float64(gg.tick_duration)
|
||||||
|
if g.respawn[r] <= 0 {
|
||||||
|
log.Printf("%v Respawned", r.Name)
|
||||||
|
r.reset(gg)
|
||||||
|
delete(g.respawn, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
2
robot.go
2
robot.go
@ -187,7 +187,7 @@ func (r *Robot) checkCollisions(g *game, move_vector v.Vector2d) (bool, v.Point2
|
|||||||
collision, move_collision, translation := v.PolyPolyIntersection(
|
collision, move_collision, translation := v.PolyPolyIntersection(
|
||||||
bot_polygon, move_vector, player_rect)
|
bot_polygon, move_vector, player_rect)
|
||||||
if collision || move_collision {
|
if collision || move_collision {
|
||||||
return true, r.Position.Add(move_vector).Add(translation.Scale(1.2)), bot
|
return true, r.Position.Add(move_vector).Add(translation.Scale(1.1)), bot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user