Skip to content

Commit

Permalink
updated protofile
Browse files Browse the repository at this point in the history
  • Loading branch information
pacosw1 committed Apr 27, 2020
1 parent 15271cd commit 5fdc35f
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 62 deletions.
4 changes: 2 additions & 2 deletions entity/Player.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func (p *Player) UpdateMovement(dir *types.Point, v int) {
Y: float64(dir.Y),
}
move = move.Dot(v)
p.Position.X += float32(move.X)
p.Position.Y += float32(move.Y)
p.Position.X = int32((move.X + float64(p.Position.X)))
p.Position.Y = int32((move.Y + float64(p.Position.Y)))

// //normalize rotation
// rotation := p.Rotation.Normalize()
Expand Down
2 changes: 1 addition & 1 deletion entity/Projectile.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
//Projectile stores bullet postion and angle (4 bytes)
type Projectile struct {
Rotation *types.Vector
Position *types.Point
Position *types.Vector
ID uint32
PlayerID uint32
}
Expand Down
81 changes: 41 additions & 40 deletions protobuf/messages.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions protobuf/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ message Message {
}

message Point {
double X = 1;
double Y = 2;
sint32 X = 1;
sint32 Y = 2;
}

message Vector {
double X = 1;
double Y = 2;
float X = 1;
float Y = 2;
}

message Connect {
Expand All @@ -42,7 +42,7 @@ message Player {
}

message Projectile {
Point position = 1;
Vector position = 1;
// Vector rotation = 2;
}

Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *Server) Start() {
s.Simulation = simulation.New(s.GameState, s.EventQueue)
s.Network = network.New(s.EventQueue, s.GameState)

s.Simulation.FPS = 120
s.Simulation.FPS = 144

s.EventQueue.RegisterConnect(s.GameState)
s.EventQueue.RegisterProjectileReady(s.Simulation)
Expand Down
8 changes: 4 additions & 4 deletions simulation/physics.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ func (e *Engine) updateProjectile(projectile *entity.Projectile, ID uint32) {
direction := projectile.Rotation.Normalize()
velocity := direction.Dot(speed)

projectile.Position.X += float32((velocity.X))
projectile.Position.Y += float32((velocity.Y))
projectile.Position.X += (math.Floor(velocity.X*100) / 100)
projectile.Position.Y += (math.Floor(velocity.Y*100) / 100)

x := projectile.Position.X
y := projectile.Position.Y
Expand All @@ -132,8 +132,8 @@ func (e *Engine) checkHit(playerID, projectileID uint32) {
pRadius := 10
ppRadius := 30

dx := float64(projectile.Position.X - player.Position.X)
dy := float64(projectile.Position.Y - player.Position.Y)
dx := float64(projectile.Position.X - float64(player.Position.X))
dy := float64(projectile.Position.Y - float64(player.Position.Y))

distance := math.Sqrt((dx * dx) + dy*dy)
R := float64(pRadius + ppRadius)
Expand Down
6 changes: 3 additions & 3 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func (g *GameState) HandleInput(m *message.NetworkInput) {
Y: player.Rotation.Y,
},
ID: (newID),
Position: &types.Point{
X: player.Position.X,
Y: player.Position.Y,
Position: &types.Vector{
X: float64(player.Position.X),
Y: float64(player.Position.Y),
},
PlayerID: player.ID,
}
Expand Down
8 changes: 4 additions & 4 deletions types/Point.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (

// Point Stores a 2D position
type Point struct {
X float32
Y float32
X int32
Y int32
}

//ToProto pb point to proto
func (p *Point) ToProto() *pb.Point {
return &pb.Point{
X: float64(p.X),
Y: float64(p.Y),
X: (p.X),
Y: (p.Y),
}
}
4 changes: 2 additions & 2 deletions types/Vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func Vector2D(x, y float64) *Vector {
//ToProto t
func (v *Vector) ToProto() *pb.Vector {
return &pb.Vector{
X: v.X,
Y: v.Y,
X: float32(v.X),
Y: float32(v.Y),
}
}

Expand Down

0 comments on commit 5fdc35f

Please sign in to comment.