Skip to content

Commit

Permalink
Fix temporarily weird snake movement
Browse files Browse the repository at this point in the history
  • Loading branch information
iiegor committed Apr 25, 2016
1 parent 0ae7e79 commit 323d95e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 17 deletions.
7 changes: 7 additions & 0 deletions src/entities/sector.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports =
class Sector
###
Section: Construction
###
constructor: (@foods) ->
# ..
15 changes: 10 additions & 5 deletions src/messages/direction.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ exports.build = (id, direction) ->
## Append message type
b += message.writeInt8 b, arr, type

## Append id
## Append snake id
b += message.writeInt16 b, arr, id

## Append position values
b += message.writeInt8 b, arr, direction
b += message.writeInt8 b, arr, 71
b += message.writeInt8 b, arr, 104
###
Append position values
@todo Sending this makes conflict with the normal movement
of the snake. Probably due to a bad calculation of the direction parameters.
b += message.writeInt8 b, arr, direction.angle
b += message.writeInt8 b, arr, direction.x
b += message.writeInt8 b, arr, direction.y
###

arr
32 changes: 21 additions & 11 deletions src/messages/snake.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,43 @@ exports.build = (snake) ->
b += message.writeInt8 b, arr, 0

b += message.writeInt8 b, arr, type

## Append snake id
b += message.writeInt16 b, arr, snake.id

## Append snake stop param
b += message.writeInt24 b, arr, snake.D

## Append unknown
b += message.writeInt8 b, arr, 0

## Append possible angles of the snake
b += message.writeInt24 b, arr, snake.X

## Append snake speed
b += message.writeInt16 b, arr, snake.speed
b += message.writeInt24 b, arr, 0.028860630325116536 * 16777215

## Unkown
b += message.writeInt24 b, arr, 0

## Append snake skin
b += message.writeInt8 b, arr, snake.skin

## Append spawn body positions
b += message.writeInt24 b, arr, snake.body.x
b += message.writeInt24 b, arr, snake.body.y

## Append name
b += message.writeInt8 b, arr, nameLength
b += message.writeString b, arr, snake.name

message.writeString b, arr, snake.name

index = b + nameLength
message.writeInt24 index, arr, snake.head.x
message.writeInt24 index + 3, arr, snake.head.y
index += 6
b += message.writeInt24 b, arr, snake.head.x
b += message.writeInt24 b, arr, snake.head.y

i = 0
while i < snake.parts.length
message.writeInt8 index, arr, snake.parts[i].x
message.writeInt8 index + 1, arr, snake.parts[i].y

index += 2
b += message.writeInt8 b, arr, snake.parts[i].x
b += message.writeInt8 b, arr, snake.parts[i].y

i++

Expand Down
2 changes: 1 addition & 1 deletion src/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Server
conn.snake.body.x += Math.cos((Math.PI / 180) * conn.snake.direction.angle) * 170
conn.snake.body.y += Math.sin((Math.PI / 180) * conn.snake.direction.angle) * 170

@broadcast directionMessage.build(conn.snake.direction.angle)
@broadcast directionMessage.build(conn.snake.id, conn.snake.direction)
@broadcast movementMessage.build(conn.snake.id, conn.snake.direction.x, conn.snake.direction.y)

# Pong
Expand Down

0 comments on commit 323d95e

Please sign in to comment.