Compare commits

..

3 Commits

Author SHA1 Message Date
9ab80969b9 Starting to add in assets. 2024-12-14 11:32:41 -05:00
2b7bef30fa Added ring/elimination mechanic. 2024-12-14 06:36:45 -05:00
fe428bee12 Multi-target slapping in the house. 2024-12-12 07:42:08 -05:00
13 changed files with 578 additions and 126 deletions

BIN
client/assets/dino_blue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

BIN
client/assets/dino_red.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -0,0 +1,51 @@
package assets
import (
"bytes"
_ "embed"
"image"
"log"
"github.com/hajimehoshi/ebiten/v2"
)
type ImgAssetName string
const (
Green ImgAssetName = "Green"
Blue ImgAssetName = "Blue"
Yellow ImgAssetName = "Yellow"
Red ImgAssetName = "Red"
)
var (
ImageBank map[ImgAssetName]*ebiten.Image
//go:embed dino_blue.png
blue_img []byte
//go:embed dino_green.png
green_img []byte
//go:embed dino_red.png
red_img []byte
//go:embed dino_yellow.png
yellow_img []byte
)
func init() {
ImageBank = make(map[ImgAssetName]*ebiten.Image)
ImageBank[Blue] = LoadImageFatal(blue_img)
ImageBank[Green] = LoadImageFatal(green_img)
ImageBank[Red] = LoadImageFatal(red_img)
ImageBank[Yellow] = LoadImageFatal(yellow_img)
}
func LoadImageFatal(b []byte) *ebiten.Image {
img, _, err := image.Decode(bytes.NewReader(b))
if err != nil {
log.Fatal(err)
}
return ebiten.NewImageFromImage(img)
}

View File

@@ -14,12 +14,14 @@ type Block struct {
position gamedata.Coordinates position gamedata.Coordinates
target gamedata.Coordinates target gamedata.Coordinates
hit bool hit bool
clr color.RGBA
} }
func NewBlock() *Block { func NewBlock() *Block {
return &Block{ return &Block{
Sprite: ebiten.NewImage(20, 20), Sprite: ebiten.NewImage(20, 20),
cycle: 0, cycle: 0,
clr: color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0x00},
} }
} }
@@ -40,11 +42,7 @@ func (b *Block) Update() {
func (b *Block) Draw() { func (b *Block) Draw() {
b.Sprite.Clear() b.Sprite.Clear()
if !b.hit { b.Sprite.Fill(b.clr)
b.Sprite.Fill(color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0x00})
} else {
b.Sprite.Fill(color.RGBA{R: 0x00, G: 0xff, B: 0x00, A: 0xff})
}
} }
func (b *Block) SetPosition(pos gamedata.Coordinates) { func (b *Block) SetPosition(pos gamedata.Coordinates) {
@@ -63,10 +61,10 @@ func (b *Block) GetTargetosition() gamedata.Coordinates {
return b.target return b.target
} }
func (b *Block) SetHit(hit bool) {
b.hit = hit
}
func (b *Block) GetHit() bool { func (b *Block) GetHit() bool {
return b.hit return b.hit
} }
func (b *Block) SetColor(clr color.RGBA) {
b.clr = clr
}

106
client/elements/dino.go Normal file
View File

@@ -0,0 +1,106 @@
package elements
import (
"client/assets"
"client/gamedata"
"image"
"github.com/hajimehoshi/ebiten/v2"
)
const (
dinoWidth = 24
dinoHeight = 24
)
type DinoInfo struct {
DinoAction gamedata.DinoAction
NumCycles int
XOffset int
}
var (
dinoCycleCount = []DinoInfo{
{gamedata.DinoActionIdle, 4, 0},
{gamedata.DinoActionWalk, 6, 4},
{gamedata.DinoActionSlap, 3, 10},
}
)
type Dino struct {
Sprite *ebiten.Image
dinotype gamedata.DinoType
dinoaction gamedata.DinoAction
cycle int
asset *ebiten.Image
left bool
slapping bool
}
func NewDino(dtype gamedata.DinoType) *Dino {
dino := &Dino{
Sprite: ebiten.NewImage(dinoWidth*2, dinoHeight*2),
cycle: 0,
dinotype: dtype,
dinoaction: gamedata.DinoActionIdle,
}
switch dtype {
case gamedata.DinoTypeBlue:
dino.asset = assets.ImageBank[assets.Blue]
case gamedata.DinoTypeGreen:
dino.asset = assets.ImageBank[assets.Green]
case gamedata.DinoTypeRed:
dino.asset = assets.ImageBank[assets.Red]
case gamedata.DinoTypeYellow:
dino.asset = assets.ImageBank[assets.Yellow]
}
return dino
}
func (d *Dino) Update() {
d.cycle++
}
func (d *Dino) Draw() {
d.Sprite.Clear()
idx := d.cycle / 8 % dinoCycleCount[d.dinoaction].NumCycles
x0 := dinoWidth * (idx + dinoCycleCount[d.dinoaction].XOffset)
y0 := 0
x1 := x0 + dinoWidth
y1 := dinoHeight
op := &ebiten.DrawImageOptions{}
if d.left {
op.GeoM.Scale(-1, 1)
op.GeoM.Translate(dinoWidth, 0)
}
op.GeoM.Translate(-dinoWidth/2, -dinoHeight/2)
op.GeoM.Scale(2, 2)
op.GeoM.Translate(dinoWidth, dinoHeight)
d.Sprite.DrawImage(d.asset.SubImage(image.Rect(x0, y0, x1, y1)).(*ebiten.Image), op)
if d.slapping && idx >= dinoCycleCount[d.dinoaction].NumCycles-1 {
d.slapping = false
}
}
func (d *Dino) SetAction(action gamedata.DinoAction) {
if d.slapping {
//wait until we're done slapping
} else {
d.dinoaction = action
if action == gamedata.DinoActionSlap {
d.cycle = 0
d.slapping = true
}
}
}
func (d *Dino) SetLeft(left bool) {
d.left = left
}

View File

@@ -7,6 +7,7 @@ import (
"client/gamedata" "client/gamedata"
"client/pb" "client/pb"
"fmt" "fmt"
"image/color"
"maps" "maps"
"math" "math"
"sync" "sync"
@@ -15,14 +16,18 @@ import (
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil" "github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text/v2" "github.com/hajimehoshi/ebiten/v2/text/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
"golang.org/x/exp/rand" "golang.org/x/exp/rand"
) )
var ( const (
screenWidth = 640 screenWidth = 640
screenHeight = 480 screenHeight = 480
movementLimit = 5 movementLimit = 5
stageRadius = 200
)
var (
namelist = []string{"slappy", "mick", "rodney", "george", "ringo", namelist = []string{"slappy", "mick", "rodney", "george", "ringo",
"robin", "temitry", "evangeline", "ron", "abigail", "lester", "robin", "temitry", "evangeline", "ron", "abigail", "lester",
"maynard", "agnes", "stacey", "wendell", "susanne", "myrtle", "maynard", "agnes", "stacey", "wendell", "susanne", "myrtle",
@@ -37,22 +42,30 @@ func init() {
} }
type ClientData struct { type ClientData struct {
Id int Id int
Address string Address string
Name string Name string
Position gamedata.Coordinates Position gamedata.Coordinates
Hit bool Hit bool
Eliminated bool
} }
type Game struct { type Game struct {
name string name string
blocky *elements.Block blocky *elements.Block
hitblocky *elements.Block hitblocky *elements.Block
elimblocky *elements.Block
gameId int gameId int
realclients map[int]ClientData realclients map[int]ClientData
gameclient *client.Client gameclient *client.Client
cycle int cycle int
mu sync.Mutex mu sync.Mutex
//similar fields that we see in the client list, but for us
eliminated bool
hit bool
dino *elements.Dino
} }
func NewGame() *Game { func NewGame() *Game {
@@ -60,11 +73,15 @@ func NewGame() *Game {
gameclient: client.NewClient(), gameclient: client.NewClient(),
blocky: elements.NewBlock(), blocky: elements.NewBlock(),
hitblocky: elements.NewBlock(), hitblocky: elements.NewBlock(),
elimblocky: elements.NewBlock(),
cycle: 0, cycle: 0,
name: namelist[rand.Intn(len(namelist))], name: namelist[rand.Intn(len(namelist))],
dino: elements.NewDino(gamedata.DinoTypeGreen),
} }
g.hitblocky.SetHit(true) g.blocky.SetColor(color.RGBA{R: 0xff, G: 0x00, B: 0x00, A: 0xff})
g.hitblocky.SetColor(color.RGBA{R: 0x00, G: 0xff, B: 0xff, A: 0xff})
g.elimblocky.SetColor(color.RGBA{R: 0x00, G: 0x00, B: 0xff, A: 0xff})
g.blocky.SetPosition(gamedata.Coordinates{X: float64(screenWidth) / 2, Y: float64(screenHeight) / 2}) g.blocky.SetPosition(gamedata.Coordinates{X: float64(screenWidth) / 2, Y: float64(screenHeight) / 2})
g.blocky.SetTargetPosition(gamedata.Coordinates{X: float64(screenWidth) / 2, Y: float64(screenHeight) / 2}) g.blocky.SetTargetPosition(gamedata.Coordinates{X: float64(screenWidth) / 2, Y: float64(screenHeight) / 2})
@@ -79,6 +96,7 @@ func NewGame() *Game {
func (g *Game) Update() error { func (g *Game) Update() error {
g.blocky.Update() g.blocky.Update()
g.dino.Update()
//g.hitblocky.Update() //g.hitblocky.Update()
g.HandleInput() g.HandleInput()
@@ -93,11 +111,22 @@ func (g *Game) Draw(screen *ebiten.Image) {
g.blocky.Draw() g.blocky.Draw()
g.hitblocky.Draw() g.hitblocky.Draw()
g.elimblocky.Draw()
vector.StrokeCircle(screen, float32(screenWidth)/2, float32(screenHeight)/2, stageRadius, 3, color.White, true)
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(g.blocky.Sprite.Bounds().Dx())/2, -float64(g.blocky.Sprite.Bounds().Dy())/2) op.GeoM.Translate(-float64(g.blocky.Sprite.Bounds().Dx())/2, -float64(g.blocky.Sprite.Bounds().Dy())/2)
op.GeoM.Translate(g.blocky.GetPosition().X, g.blocky.GetPosition().Y) op.GeoM.Translate(g.blocky.GetPosition().X, g.blocky.GetPosition().Y)
screen.DrawImage(g.blocky.Sprite, op) if !g.eliminated {
if !g.hit {
screen.DrawImage(g.blocky.Sprite, op)
} else {
screen.DrawImage(g.hitblocky.Sprite, op)
}
} else {
screen.DrawImage(g.elimblocky.Sprite, op)
}
f2 := &text.GoTextFace{ f2 := &text.GoTextFace{
Source: fonts.LaunchyFont.New, Source: fonts.LaunchyFont.New,
Size: 12, Size: 12,
@@ -113,10 +142,15 @@ func (g *Game) Draw(screen *ebiten.Image) {
op := &ebiten.DrawImageOptions{} op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(g.blocky.Sprite.Bounds().Dx())/2, -float64(g.blocky.Sprite.Bounds().Dy())/2) op.GeoM.Translate(-float64(g.blocky.Sprite.Bounds().Dx())/2, -float64(g.blocky.Sprite.Bounds().Dy())/2)
op.GeoM.Translate(client.Position.X, client.Position.Y) op.GeoM.Translate(client.Position.X, client.Position.Y)
if !client.Hit {
screen.DrawImage(g.blocky.Sprite, op) if client.Eliminated {
screen.DrawImage(g.elimblocky.Sprite, op)
} else { } else {
screen.DrawImage(g.hitblocky.Sprite, op) if !client.Hit {
screen.DrawImage(g.blocky.Sprite, op)
} else {
screen.DrawImage(g.hitblocky.Sprite, op)
}
} }
f2 := &text.GoTextFace{ f2 := &text.GoTextFace{
@@ -128,6 +162,12 @@ func (g *Game) Draw(screen *ebiten.Image) {
text.Draw(screen, client.Name, f2, top) text.Draw(screen, client.Name, f2, top)
} }
g.dino.Draw()
dop := &ebiten.DrawImageOptions{}
dop.GeoM.Translate(-float64(g.dino.Sprite.Bounds().Dx())/2, -float64(g.dino.Sprite.Bounds().Dy())/2)
dop.GeoM.Translate(g.blocky.GetPosition().X, g.blocky.GetPosition().Y)
screen.DrawImage(g.dino.Sprite, dop)
} }
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenwidth, screenheight int) { func (g *Game) Layout(outsideWidth, outsideHeight int) (screenwidth, screenheight int) {
@@ -150,14 +190,20 @@ func (g *Game) HandleServerData(envelope *pb.ServerEnvelope) {
X: client.Coordinates.X, X: client.Coordinates.X,
Y: client.Coordinates.Y, Y: client.Coordinates.Y,
}, },
Hit: client.Hit, Hit: client.Hit,
Eliminated: client.Eliminated,
} }
g.mu.Lock() g.mu.Lock()
g.realclients[int(client.Id)] = update g.realclients[int(client.Id)] = update
g.mu.Unlock() g.mu.Unlock()
} else { } else {
g.blocky.SetHit(client.Hit) g.eliminated = client.Eliminated
g.hit = client.Hit
//this is us
//g.blocky.SetHit(client.Hit)
} }
} }
case *pb.ServerEnvelope_Event: case *pb.ServerEnvelope_Event:
@@ -174,35 +220,48 @@ func (g *Game) HandleServerData(envelope *pb.ServerEnvelope) {
fmt.Println("Server is trying to give us our id: ", payload.Identity.Id) fmt.Println("Server is trying to give us our id: ", payload.Identity.Id)
g.gameId = int(payload.Identity.Id) g.gameId = int(payload.Identity.Id)
case *pb.ServerEnvelope_Gameevent: case *pb.ServerEnvelope_Gameevent:
fmt.Printf("someone slapping! target:%d, instigator:%d isSlap:%d", payload.Gameevent.Target, payload.Gameevent.Instigator, payload.Gameevent.Slap) //fmt.Printf("someone slapping! target:%d, instigator:%d isSlap:%d", payload.Gameevent.Target, payload.Gameevent.Instigator, payload.Gameevent.Slap)
if payload.Gameevent.Target == int32(g.gameId) { switch payload.Gameevent.Event.(type) {
g.mu.Lock() case *pb.GameEvent_Slap:
dx := g.blocky.GetPosition().X - g.realclients[int(payload.Gameevent.Instigator)].Position.X if payload.Gameevent.Target == int32(g.gameId) {
dy := g.blocky.GetPosition().Y - g.realclients[int(payload.Gameevent.Instigator)].Position.Y g.mu.Lock()
g.mu.Unlock() dx := g.blocky.GetPosition().X - g.realclients[int(payload.Gameevent.Instigator)].Position.X
dy := g.blocky.GetPosition().Y - g.realclients[int(payload.Gameevent.Instigator)].Position.Y
g.mu.Unlock()
if dx != 0 { if dx != 0 {
dx = (dx / math.Abs(dx)) * 100 dx = (dx / math.Abs(dx)) * 100
} }
if dy != 0 { if dy != 0 {
dy = (dy / math.Abs(dy)) * 100 dy = (dy / math.Abs(dy)) * 100
} }
if dx == 0 && dy == 0 { if dx == 0 && dy == 0 {
b := rand.Intn(2) b := rand.Intn(2)
if b == 0 { if b == 0 {
dx = 100 dx = 100
dy = 100 dy = 100
} else { } else {
dx = -100 dx = -100
dy = -100 dy = -100
}
} }
}
cpos := gamedata.Coordinates{} cpos := gamedata.Coordinates{}
cpos.X = g.blocky.GetPosition().X + dx cpos.X = g.blocky.GetPosition().X + dx
cpos.Y = g.blocky.GetPosition().Y + dy cpos.Y = g.blocky.GetPosition().Y + dy
g.blocky.SetTargetPosition(cpos) g.blocky.SetTargetPosition(cpos)
}
case *pb.GameEvent_Eliminated:
fmt.Println("someone eliminated...", payload.Gameevent.Target)
/*
g.mu.Lock()
client := g.realclients[int(payload.Gameevent.Target)]
client.Eliminated = true
g.realclients[int(payload.Gameevent.Target)] = client
g.mu.Unlock()
*/
} }
} }
} }
@@ -211,6 +270,7 @@ func (g *Game) HandleInput() {
dx := 0 dx := 0
dy := 0 dy := 0
if ebiten.IsKeyPressed(ebiten.KeyW) { if ebiten.IsKeyPressed(ebiten.KeyW) {
dy = -movementLimit dy = -movementLimit
} }
@@ -219,9 +279,17 @@ func (g *Game) HandleInput() {
} }
if ebiten.IsKeyPressed(ebiten.KeyA) { if ebiten.IsKeyPressed(ebiten.KeyA) {
dx = -movementLimit dx = -movementLimit
g.dino.SetLeft(true)
} }
if ebiten.IsKeyPressed(ebiten.KeyD) { if ebiten.IsKeyPressed(ebiten.KeyD) {
dx = +movementLimit dx = +movementLimit
g.dino.SetLeft(false)
}
if math.Abs(float64(dx)) > 0 || math.Abs(float64(dy)) > 0 {
g.dino.SetAction(gamedata.DinoActionWalk)
} else {
g.dino.SetAction(gamedata.DinoActionIdle)
} }
cpos := g.blocky.GetPosition() cpos := g.blocky.GetPosition()
@@ -231,6 +299,7 @@ func (g *Game) HandleInput() {
if inpututil.IsKeyJustPressed(ebiten.KeySpace) { if inpututil.IsKeyJustPressed(ebiten.KeySpace) {
g.SendSlap() g.SendSlap()
g.dino.SetAction(gamedata.DinoActionSlap)
} }
} }

View File

@@ -1,6 +1,33 @@
package gamedata package gamedata
import "math"
type DinoType int
const (
DinoTypeGreen DinoType = iota
DinoTypeBlue
DinoTypeRed
DinoTypeYellow
DinoTypeMax
)
type DinoAction int
const (
DinoActionIdle DinoAction = iota
DinoActionWalk
DinoActionSlap
DinoActionMax
)
type Coordinates struct { type Coordinates struct {
X float64 `json:"X"` X float64 `json:"X"`
Y float64 `json:"Y"` Y float64 `json:"Y"`
} }
func (c Coordinates) Distance(p Coordinates) float64 {
dx := p.X - c.X
dy := p.Y - c.Y
return math.Sqrt(dx*dx + dy*dy)
}

View File

@@ -132,6 +132,7 @@ type ClientData struct {
Name string `protobuf:"bytes,3,opt,name=Name,proto3" json:"Name,omitempty"` Name string `protobuf:"bytes,3,opt,name=Name,proto3" json:"Name,omitempty"`
Coordinates *Coordinates `protobuf:"bytes,4,opt,name=coordinates,proto3" json:"coordinates,omitempty"` Coordinates *Coordinates `protobuf:"bytes,4,opt,name=coordinates,proto3" json:"coordinates,omitempty"`
Hit bool `protobuf:"varint,5,opt,name=hit,proto3" json:"hit,omitempty"` Hit bool `protobuf:"varint,5,opt,name=hit,proto3" json:"hit,omitempty"`
Eliminated bool `protobuf:"varint,6,opt,name=Eliminated,proto3" json:"Eliminated,omitempty"`
} }
func (x *ClientData) Reset() { func (x *ClientData) Reset() {
@@ -199,6 +200,13 @@ func (x *ClientData) GetHit() bool {
return false return false
} }
func (x *ClientData) GetEliminated() bool {
if x != nil {
return x.Eliminated
}
return false
}
type ClientCoordinates struct { type ClientCoordinates struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -526,7 +534,11 @@ type GameEvent struct {
Instigator int32 `protobuf:"varint,1,opt,name=Instigator,proto3" json:"Instigator,omitempty"` Instigator int32 `protobuf:"varint,1,opt,name=Instigator,proto3" json:"Instigator,omitempty"`
Target int32 `protobuf:"varint,2,opt,name=Target,proto3" json:"Target,omitempty"` Target int32 `protobuf:"varint,2,opt,name=Target,proto3" json:"Target,omitempty"`
Slap bool `protobuf:"varint,3,opt,name=Slap,proto3" json:"Slap,omitempty"` // Types that are assignable to Event:
//
// *GameEvent_Slap
// *GameEvent_Eliminated
Event isGameEvent_Event `protobuf_oneof:"Event"`
} }
func (x *GameEvent) Reset() { func (x *GameEvent) Reset() {
@@ -573,13 +585,43 @@ func (x *GameEvent) GetTarget() int32 {
return 0 return 0
} }
func (m *GameEvent) GetEvent() isGameEvent_Event {
if m != nil {
return m.Event
}
return nil
}
func (x *GameEvent) GetSlap() bool { func (x *GameEvent) GetSlap() bool {
if x != nil { if x, ok := x.GetEvent().(*GameEvent_Slap); ok {
return x.Slap return x.Slap
} }
return false return false
} }
func (x *GameEvent) GetEliminated() bool {
if x, ok := x.GetEvent().(*GameEvent_Eliminated); ok {
return x.Eliminated
}
return false
}
type isGameEvent_Event interface {
isGameEvent_Event()
}
type GameEvent_Slap struct {
Slap bool `protobuf:"varint,3,opt,name=Slap,proto3,oneof"`
}
type GameEvent_Eliminated struct {
Eliminated bool `protobuf:"varint,4,opt,name=Eliminated,proto3,oneof"`
}
func (*GameEvent_Slap) isGameEvent_Event() {}
func (*GameEvent_Eliminated) isGameEvent_Event() {}
type ServerEnvelope struct { type ServerEnvelope struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -694,7 +736,7 @@ var file_clientdata_proto_rawDesc = []byte{
0x74, 0x6f, 0x12, 0x04, 0x6d, 0x61, 0x69, 0x6e, 0x22, 0x29, 0x0a, 0x0b, 0x43, 0x6f, 0x6f, 0x72, 0x74, 0x6f, 0x12, 0x04, 0x6d, 0x61, 0x69, 0x6e, 0x22, 0x29, 0x0a, 0x0b, 0x43, 0x6f, 0x6f, 0x72,
0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x58, 0x18, 0x01, 0x20, 0x01, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x58, 0x18, 0x01, 0x20, 0x01,
0x28, 0x01, 0x52, 0x01, 0x58, 0x12, 0x0c, 0x0a, 0x01, 0x59, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x28, 0x01, 0x52, 0x01, 0x58, 0x12, 0x0c, 0x0a, 0x01, 0x59, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01,
0x52, 0x01, 0x59, 0x22, 0x91, 0x01, 0x0a, 0x0a, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x44, 0x61, 0x52, 0x01, 0x59, 0x22, 0xb1, 0x01, 0x0a, 0x0a, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x44, 0x61,
0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02,
0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x01, 0x28, 0x09, 0x52, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04,
@@ -703,7 +745,9 @@ var file_clientdata_proto_rawDesc = []byte{
0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6f, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6f,
0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69,
0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x68, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x68, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01,
0x28, 0x08, 0x52, 0x03, 0x68, 0x69, 0x74, 0x22, 0x5c, 0x0a, 0x11, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x28, 0x08, 0x52, 0x03, 0x68, 0x69, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x45, 0x6c, 0x69, 0x6d, 0x69,
0x6e, 0x61, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x45, 0x6c, 0x69,
0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, 0x22, 0x5c, 0x0a, 0x11, 0x43, 0x6c, 0x69, 0x65, 0x6e,
0x74, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04,
0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65,
0x12, 0x33, 0x0a, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x18, 0x12, 0x33, 0x0a, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x18,
@@ -729,33 +773,35 @@ var file_clientdata_proto_rawDesc = []byte{
0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02,
0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18,
0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64,
0x22, 0x57, 0x0a, 0x09, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x0a, 0x22, 0x84, 0x01, 0x0a, 0x09, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1e,
0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0a, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01,
0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x16, 0x0a, 0x28, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x16,
0x06, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x54, 0x0a, 0x06, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06,
0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x18, 0x03, 0x20, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x18, 0x03,
0x01, 0x28, 0x08, 0x52, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x22, 0xdd, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x20, 0x01, 0x28, 0x08, 0x48, 0x00, 0x52, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x12, 0x20, 0x0a, 0x0a,
0x72, 0x76, 0x65, 0x72, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x32, 0x0a, 0x08, 0x45, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08,
0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x48, 0x00, 0x52, 0x0a, 0x45, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, 0x42, 0x07,
0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x22, 0xdd, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76,
0x74, 0x69, 0x74, 0x79, 0x48, 0x00, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x65, 0x72, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x32, 0x0a, 0x08, 0x69, 0x64,
0x12, 0x30, 0x0a, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6d,
0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6c, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69,
0x69, 0x65, 0x6e, 0x74, 0x73, 0x48, 0x00, 0x52, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x74, 0x79, 0x48, 0x00, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x30,
0x73, 0x74, 0x12, 0x29, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0a, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x0b, 0x32, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6c, 0x69, 0x65,
0x76, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x6e, 0x74, 0x73, 0x48, 0x00, 0x52, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74,
0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x12, 0x29, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x32, 0x0f, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x65,
0x74, 0x48, 0x00, 0x52, 0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x09, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x09, 0x67,
0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x56, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f,
0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x53, 0x47, 0x5f, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x48,
0x54, 0x59, 0x50, 0x45, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x10, 0x00, 0x00, 0x52, 0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x09, 0x0a, 0x07,
0x12, 0x15, 0x0a, 0x11, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x44, 0x45, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x56, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61,
0x4e, 0x54, 0x49, 0x54, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59,
0x59, 0x50, 0x45, 0x5f, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x53, 0x10, 0x50, 0x45, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x10, 0x00, 0x12, 0x15,
0x02, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x0a, 0x11, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x44, 0x45, 0x4e, 0x54,
0x33, 0x49, 0x54, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50,
0x45, 0x5f, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x53, 0x10, 0x02, 0x42,
0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@@ -811,6 +857,10 @@ func file_clientdata_proto_init() {
(*ClientEnvelope_Coordinates)(nil), (*ClientEnvelope_Coordinates)(nil),
(*ClientEnvelope_Slap)(nil), (*ClientEnvelope_Slap)(nil),
} }
file_clientdata_proto_msgTypes[8].OneofWrappers = []any{
(*GameEvent_Slap)(nil),
(*GameEvent_Eliminated)(nil),
}
file_clientdata_proto_msgTypes[9].OneofWrappers = []any{ file_clientdata_proto_msgTypes[9].OneofWrappers = []any{
(*ServerEnvelope_Identity)(nil), (*ServerEnvelope_Identity)(nil),
(*ServerEnvelope_Broadcast)(nil), (*ServerEnvelope_Broadcast)(nil),

View File

@@ -1,6 +1,14 @@
package gamedata package gamedata
import "math"
type Coordinates struct { type Coordinates struct {
X float64 X float64
Y float64 Y float64
} }
func (c Coordinates) Distance(p Coordinates) float64 {
dx := p.X - c.X
dy := p.Y - c.Y
return math.Sqrt(dx*dx + dy*dy)
}

View File

@@ -132,6 +132,7 @@ type ClientData struct {
Name string `protobuf:"bytes,3,opt,name=Name,proto3" json:"Name,omitempty"` Name string `protobuf:"bytes,3,opt,name=Name,proto3" json:"Name,omitempty"`
Coordinates *Coordinates `protobuf:"bytes,4,opt,name=coordinates,proto3" json:"coordinates,omitempty"` Coordinates *Coordinates `protobuf:"bytes,4,opt,name=coordinates,proto3" json:"coordinates,omitempty"`
Hit bool `protobuf:"varint,5,opt,name=hit,proto3" json:"hit,omitempty"` Hit bool `protobuf:"varint,5,opt,name=hit,proto3" json:"hit,omitempty"`
Eliminated bool `protobuf:"varint,6,opt,name=Eliminated,proto3" json:"Eliminated,omitempty"`
} }
func (x *ClientData) Reset() { func (x *ClientData) Reset() {
@@ -199,6 +200,13 @@ func (x *ClientData) GetHit() bool {
return false return false
} }
func (x *ClientData) GetEliminated() bool {
if x != nil {
return x.Eliminated
}
return false
}
type ClientCoordinates struct { type ClientCoordinates struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -526,7 +534,11 @@ type GameEvent struct {
Instigator int32 `protobuf:"varint,1,opt,name=Instigator,proto3" json:"Instigator,omitempty"` Instigator int32 `protobuf:"varint,1,opt,name=Instigator,proto3" json:"Instigator,omitempty"`
Target int32 `protobuf:"varint,2,opt,name=Target,proto3" json:"Target,omitempty"` Target int32 `protobuf:"varint,2,opt,name=Target,proto3" json:"Target,omitempty"`
Slap bool `protobuf:"varint,3,opt,name=Slap,proto3" json:"Slap,omitempty"` // Types that are assignable to Event:
//
// *GameEvent_Slap
// *GameEvent_Eliminated
Event isGameEvent_Event `protobuf_oneof:"Event"`
} }
func (x *GameEvent) Reset() { func (x *GameEvent) Reset() {
@@ -573,13 +585,43 @@ func (x *GameEvent) GetTarget() int32 {
return 0 return 0
} }
func (m *GameEvent) GetEvent() isGameEvent_Event {
if m != nil {
return m.Event
}
return nil
}
func (x *GameEvent) GetSlap() bool { func (x *GameEvent) GetSlap() bool {
if x != nil { if x, ok := x.GetEvent().(*GameEvent_Slap); ok {
return x.Slap return x.Slap
} }
return false return false
} }
func (x *GameEvent) GetEliminated() bool {
if x, ok := x.GetEvent().(*GameEvent_Eliminated); ok {
return x.Eliminated
}
return false
}
type isGameEvent_Event interface {
isGameEvent_Event()
}
type GameEvent_Slap struct {
Slap bool `protobuf:"varint,3,opt,name=Slap,proto3,oneof"`
}
type GameEvent_Eliminated struct {
Eliminated bool `protobuf:"varint,4,opt,name=Eliminated,proto3,oneof"`
}
func (*GameEvent_Slap) isGameEvent_Event() {}
func (*GameEvent_Eliminated) isGameEvent_Event() {}
type ServerEnvelope struct { type ServerEnvelope struct {
state protoimpl.MessageState state protoimpl.MessageState
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
@@ -694,7 +736,7 @@ var file_clientdata_proto_rawDesc = []byte{
0x74, 0x6f, 0x12, 0x04, 0x6d, 0x61, 0x69, 0x6e, 0x22, 0x29, 0x0a, 0x0b, 0x43, 0x6f, 0x6f, 0x72, 0x74, 0x6f, 0x12, 0x04, 0x6d, 0x61, 0x69, 0x6e, 0x22, 0x29, 0x0a, 0x0b, 0x43, 0x6f, 0x6f, 0x72,
0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x58, 0x18, 0x01, 0x20, 0x01, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x0c, 0x0a, 0x01, 0x58, 0x18, 0x01, 0x20, 0x01,
0x28, 0x01, 0x52, 0x01, 0x58, 0x12, 0x0c, 0x0a, 0x01, 0x59, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x28, 0x01, 0x52, 0x01, 0x58, 0x12, 0x0c, 0x0a, 0x01, 0x59, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01,
0x52, 0x01, 0x59, 0x22, 0x91, 0x01, 0x0a, 0x0a, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x44, 0x61, 0x52, 0x01, 0x59, 0x22, 0xb1, 0x01, 0x0a, 0x0a, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x44, 0x61,
0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x74, 0x61, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02,
0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x01, 0x28, 0x09, 0x52, 0x07, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x12, 0x0a, 0x04,
@@ -703,7 +745,9 @@ var file_clientdata_proto_rawDesc = []byte{
0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6f, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6f, 0x6f,
0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x52, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69,
0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x68, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x10, 0x0a, 0x03, 0x68, 0x69, 0x74, 0x18, 0x05, 0x20, 0x01,
0x28, 0x08, 0x52, 0x03, 0x68, 0x69, 0x74, 0x22, 0x5c, 0x0a, 0x11, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x28, 0x08, 0x52, 0x03, 0x68, 0x69, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x45, 0x6c, 0x69, 0x6d, 0x69,
0x6e, 0x61, 0x74, 0x65, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x45, 0x6c, 0x69,
0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, 0x22, 0x5c, 0x0a, 0x11, 0x43, 0x6c, 0x69, 0x65, 0x6e,
0x74, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x43, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x12, 0x12, 0x0a, 0x04,
0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x4e, 0x61, 0x6d, 0x65,
0x12, 0x33, 0x0a, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x18, 0x12, 0x33, 0x0a, 0x0b, 0x63, 0x6f, 0x6f, 0x72, 0x64, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x73, 0x18,
@@ -729,33 +773,35 @@ var file_clientdata_proto_rawDesc = []byte{
0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02,
0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x18,
0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x43, 0x6f, 0x6e, 0x6e, 0x65, 0x63, 0x74, 0x65, 0x64,
0x22, 0x57, 0x0a, 0x09, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1e, 0x0a, 0x22, 0x84, 0x01, 0x0a, 0x09, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x1e,
0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0a, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01,
0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x16, 0x0a, 0x28, 0x05, 0x52, 0x0a, 0x49, 0x6e, 0x73, 0x74, 0x69, 0x67, 0x61, 0x74, 0x6f, 0x72, 0x12, 0x16,
0x06, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x54, 0x0a, 0x06, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06,
0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x18, 0x03, 0x20, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x18, 0x03,
0x01, 0x28, 0x08, 0x52, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x22, 0xdd, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x20, 0x01, 0x28, 0x08, 0x48, 0x00, 0x52, 0x04, 0x53, 0x6c, 0x61, 0x70, 0x12, 0x20, 0x0a, 0x0a,
0x72, 0x76, 0x65, 0x72, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x32, 0x0a, 0x08, 0x45, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08,
0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x48, 0x00, 0x52, 0x0a, 0x45, 0x6c, 0x69, 0x6d, 0x69, 0x6e, 0x61, 0x74, 0x65, 0x64, 0x42, 0x07,
0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x0a, 0x05, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x22, 0xdd, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x72, 0x76,
0x74, 0x69, 0x74, 0x79, 0x48, 0x00, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x65, 0x72, 0x45, 0x6e, 0x76, 0x65, 0x6c, 0x6f, 0x70, 0x65, 0x12, 0x32, 0x0a, 0x08, 0x69, 0x64,
0x12, 0x30, 0x0a, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x6d,
0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6c, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69,
0x69, 0x65, 0x6e, 0x74, 0x73, 0x48, 0x00, 0x52, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x74, 0x79, 0x48, 0x00, 0x52, 0x08, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x30,
0x73, 0x74, 0x12, 0x29, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0a, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28,
0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x0b, 0x32, 0x10, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x41, 0x6c, 0x6c, 0x43, 0x6c, 0x69, 0x65,
0x76, 0x65, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x6e, 0x74, 0x73, 0x48, 0x00, 0x52, 0x09, 0x62, 0x72, 0x6f, 0x61, 0x64, 0x63, 0x61, 0x73, 0x74,
0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x12, 0x29, 0x0a, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32,
0x32, 0x0f, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x11, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x43, 0x6c, 0x69, 0x65, 0x6e, 0x74, 0x45, 0x76, 0x65,
0x74, 0x48, 0x00, 0x52, 0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x09, 0x6e, 0x74, 0x48, 0x00, 0x52, 0x05, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x2f, 0x0a, 0x09, 0x67,
0x0a, 0x07, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x56, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0f,
0x73, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x53, 0x47, 0x5f, 0x2e, 0x6d, 0x61, 0x69, 0x6e, 0x2e, 0x47, 0x61, 0x6d, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x48,
0x54, 0x59, 0x50, 0x45, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x10, 0x00, 0x00, 0x52, 0x09, 0x67, 0x61, 0x6d, 0x65, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x42, 0x09, 0x0a, 0x07,
0x12, 0x15, 0x0a, 0x11, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x44, 0x45, 0x50, 0x61, 0x79, 0x6c, 0x6f, 0x61, 0x64, 0x2a, 0x56, 0x0a, 0x0b, 0x4d, 0x65, 0x73, 0x73, 0x61,
0x4e, 0x54, 0x49, 0x54, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59,
0x59, 0x50, 0x45, 0x5f, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x53, 0x10, 0x50, 0x45, 0x5f, 0x42, 0x52, 0x4f, 0x41, 0x44, 0x43, 0x41, 0x53, 0x54, 0x10, 0x00, 0x12, 0x15,
0x02, 0x42, 0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x0a, 0x11, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50, 0x45, 0x5f, 0x49, 0x44, 0x45, 0x4e, 0x54,
0x33, 0x49, 0x54, 0x59, 0x10, 0x01, 0x12, 0x18, 0x0a, 0x14, 0x4d, 0x53, 0x47, 0x5f, 0x54, 0x59, 0x50,
0x45, 0x5f, 0x43, 0x4f, 0x4f, 0x52, 0x44, 0x49, 0x4e, 0x41, 0x54, 0x45, 0x53, 0x10, 0x02, 0x42,
0x06, 0x5a, 0x04, 0x2e, 0x2f, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
} }
var ( var (
@@ -811,6 +857,10 @@ func file_clientdata_proto_init() {
(*ClientEnvelope_Coordinates)(nil), (*ClientEnvelope_Coordinates)(nil),
(*ClientEnvelope_Slap)(nil), (*ClientEnvelope_Slap)(nil),
} }
file_clientdata_proto_msgTypes[8].OneofWrappers = []any{
(*GameEvent_Slap)(nil),
(*GameEvent_Eliminated)(nil),
}
file_clientdata_proto_msgTypes[9].OneofWrappers = []any{ file_clientdata_proto_msgTypes[9].OneofWrappers = []any{
(*ServerEnvelope_Identity)(nil), (*ServerEnvelope_Identity)(nil),
(*ServerEnvelope_Broadcast)(nil), (*ServerEnvelope_Broadcast)(nil),

View File

@@ -16,17 +16,21 @@ import (
) )
const ( const (
boxwidth = 20 boxwidth = 20
boxheight = 20
checkRadius = 200
) )
type ClientData struct { type ClientData struct {
Id int Id int
Address string Address string
Name string Name string
Position gamedata.Coordinates Position gamedata.Coordinates
Hit bool Hit bool
Target int Target int
Slapping bool Targets []int
Slapping bool
Eliminated bool
} }
type Server struct { type Server struct {
@@ -124,6 +128,7 @@ func (s *Server) HandleClient(conn net.Conn, id int) {
Address: conn.RemoteAddr().String(), Address: conn.RemoteAddr().String(),
Name: payload.Coordinates.Name, Name: payload.Coordinates.Name,
Position: gamedata.Coordinates{X: payload.Coordinates.Coordinates.X, Y: payload.Coordinates.Coordinates.Y}, Position: gamedata.Coordinates{X: payload.Coordinates.Coordinates.X, Y: payload.Coordinates.Coordinates.Y},
Hit: false,
} }
s.mu.Lock() s.mu.Lock()
@@ -133,23 +138,59 @@ func (s *Server) HandleClient(conn net.Conn, id int) {
dx := client.Position.X - cd.Position.X dx := client.Position.X - cd.Position.X
dy := client.Position.Y - cd.Position.Y dy := client.Position.Y - cd.Position.Y
if math.Abs(dx) < boxwidth && math.Abs(dy) < boxwidth { if math.Abs(dx) < boxwidth && math.Abs(dy) < boxheight {
//collision, mark it //collision, mark it
cd.Hit = true cd.Hit = true
cd.Target = client.Id //cd.Target = client.Id
cd.Targets = append(cd.Targets, client.Id)
} }
} }
} }
p1 := gamedata.Coordinates{
X: cd.Position.X - boxwidth/2,
Y: cd.Position.Y - boxheight/2,
}
p2 := gamedata.Coordinates{
X: cd.Position.X - boxwidth/2,
Y: cd.Position.Y + boxheight/2,
}
p3 := gamedata.Coordinates{
X: cd.Position.X + boxwidth/2,
Y: cd.Position.Y + boxheight/2,
}
p4 := gamedata.Coordinates{
X: cd.Position.X + boxwidth/2,
Y: cd.Position.Y - boxheight/2,
}
circle := gamedata.Coordinates{
X: 640 / 2,
Y: 480 / 2,
}
if circle.Distance(p1) > checkRadius &&
circle.Distance(p2) > checkRadius &&
circle.Distance(p3) > checkRadius &&
circle.Distance(p4) > checkRadius {
fmt.Println("client is OUT ", cd.Id)
cd.Eliminated = true
}
//update the client list //update the client list
s.clientlist[conn] = cd s.clientlist[conn] = cd
s.mu.Unlock() s.mu.Unlock()
//s.CheckElimination(cd)
case *pb.ClientEnvelope_Slap: case *pb.ClientEnvelope_Slap:
if s.clientlist[conn].Target != 0 && s.clientlist[conn].Hit {
s.BroadcastSlap(id, s.clientlist[conn].Target) s.mu.Lock()
} else { slapper := s.clientlist[conn]
fmt.Println("Invalid slap detected.") s.mu.Unlock()
for _, target := range slapper.Targets {
s.BroadcastSlap(id, target)
} }
} }
} }
@@ -207,7 +248,8 @@ func (s *Server) BuildBroadcastMessage() *pb.AllClients {
X: data.Position.X, X: data.Position.X,
Y: data.Position.Y, Y: data.Position.Y,
}, },
Hit: data.Hit, Hit: data.Hit,
Eliminated: data.Eliminated,
} }
result.Clients = append(result.Clients, clientdata) result.Clients = append(result.Clients, clientdata)
} }
@@ -284,12 +326,15 @@ func (s *Server) SendClientEvent(conn net.Conn, id int, connected bool) {
func (s *Server) BroadcastSlap(instigator, target int) { func (s *Server) BroadcastSlap(instigator, target int) {
slap := &pb.GameEvent_Slap{
Slap: true,
}
envelope := &pb.ServerEnvelope{ envelope := &pb.ServerEnvelope{
Payload: &pb.ServerEnvelope_Gameevent{ Payload: &pb.ServerEnvelope_Gameevent{
Gameevent: &pb.GameEvent{ Gameevent: &pb.GameEvent{
Instigator: int32(instigator), Instigator: int32(instigator),
Target: int32(target), Target: int32(target),
Slap: true, Event: slap,
}, },
}, },
} }
@@ -301,3 +346,51 @@ func (s *Server) BroadcastSlap(instigator, target int) {
s.mu.Unlock() s.mu.Unlock()
} }
func (s *Server) CheckElimination(cd ClientData) {
p1 := gamedata.Coordinates{
X: cd.Position.X - boxwidth/2,
Y: cd.Position.Y - boxheight/2,
}
p2 := gamedata.Coordinates{
X: cd.Position.X - boxwidth/2,
Y: cd.Position.Y + boxheight/2,
}
p3 := gamedata.Coordinates{
X: cd.Position.X + boxwidth/2,
Y: cd.Position.Y + boxheight/2,
}
p4 := gamedata.Coordinates{
X: cd.Position.X + boxwidth/2,
Y: cd.Position.Y - boxheight/2,
}
circle := gamedata.Coordinates{
X: 640 / 2,
Y: 480 / 2,
}
if circle.Distance(p1) > checkRadius &&
circle.Distance(p2) > checkRadius &&
circle.Distance(p3) > checkRadius &&
circle.Distance(p4) > checkRadius {
fmt.Println("client is OUT ", cd.Id)
elim := &pb.GameEvent_Eliminated{
Eliminated: true,
}
envelope := &pb.ServerEnvelope{
Payload: &pb.ServerEnvelope_Gameevent{
Gameevent: &pb.GameEvent{
Target: int32(cd.Id),
Event: elim,
},
},
}
s.mu.Lock()
for conn := range s.clientlist {
s.SendMessage(conn, envelope)
}
s.mu.Unlock()
}
}