Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Next #1

Open
wants to merge 5 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/client/client.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ class Client
new Rope(@, obj)
when 'tracker'
new Tracker(@, obj)
when 'teleportation'
new Teleportation(@, obj)

deleteObject: (id) ->
type = @gameObjects[id].type
Expand Down Expand Up @@ -479,6 +481,10 @@ class Client

when 'EMP exploded'
@gameObjects[event.id].wavesEffect()

when 'teleportation'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed?

# Draw scene.
@redraw(@ctxt)

# When a player sent a chat message.
onPlayerMessage: (data)->
Expand Down
5 changes: 4 additions & 1 deletion src/client/create.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ $(document).ready () ->

window.bonusBoxes.push new BonusBox(cell, 'bonus.bonusType.grenade.weight', 'bonusGrenade')
new Tooltip(bonus(7), 'Grenade blablablaaa')


window.bonusBoxes.push new BonusBox(cell, 'bonus.bonusType.teleportation.weight', 'bonusTeleportation')
new Tooltip(bonus(8), 'Teleportation blablablaaa')

new Range(entry('#panel3 > table', 'Drop wait'),
'bonus.waitTime', 1000, 10000, 1000, 5000, ' milliseconds')
new Tooltip(label(3, 2), 'blabla')
Expand Down
15 changes: 15 additions & 0 deletions src/client/spriteManager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ class SpriteManager

return sprite

'teleportation': (sprite, w, h) ->
ctxt = sprite.getContext('2d')
ctxt.fillStyle = 'black'

r = w / Math.sqrt(2) / 2
ctxt.save()
ctxt.translate(sprite.width/2, sprite.height/2)
ctxt.fillRect(-r, -r, r*2, r*2)
ctxt.restore()

return sprite

'grenade': (sprite, w, h) ->
ctxt = sprite.getContext('2d')
ctxt.fillStyle = 'black'
Expand Down Expand Up @@ -178,6 +190,9 @@ class SpriteManager
'bonusMine': (sprite, w, h) ->
@['mine'](sprite, w, h)

'bonusTeleportation': (sprite, w, h) ->
@['teleportation'](sprite, w, h)

'bonusGrenade': (sprite, w, h) ->
@['grenade'](sprite, w, h)

Expand Down
53 changes: 53 additions & 0 deletions src/client/teleportation.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
class Teleportation
constructor: (@client, teleportation) ->
@serverUpdate(teleportation)

@color = @client.gameObjects[@ownerId].color

# Create the sprite.
s = 10*Math.sqrt(2) # The size of the sprite equals the diagonal of the squares forming the sprite.
color = window.utils.color @color
@sprite = @client.spriteManager.get('teleportation', s, s, color)

serverUpdate: (teleportation) ->
utils.deepMerge(teleportation, @)

update: () ->
@clientDelete = @serverDelete

drawHitbox: (ctxt) ->
return if not @hitBox?

ctxt.strokeStyle = 'red'
ctxt.lineWidth = 1.1
utils.strokeCircle(ctxt, @hitBox.x, @hitBox.y, @hitBox.radius)

draw: (ctxt) ->
return if @state is 'exploding' or @state is 'dead'

# Draw the body of the teleportation.
ctxt.save()
ctxt.translate(@pos.x, @pos.y)
ctxt.drawImage(@sprite, [email protected]/2, [email protected]/2)
ctxt.restore()

# Draw the sensor wave when the teleportation is active.
if @state is 'active'
for r in [@radius...0] by -20
ctxt.save()
ctxt.lineWidth = 3
ctxt.strokeStyle = utils.color(@color, 1-r/50)
ctxt.translate(@pos.x, @pos.y)
ctxt.beginPath()
ctxt.arc(0, 0, r, 0, 2*Math.PI, false)
ctxt.stroke()
ctxt.restore()

inView: (offset = {x:0, y:0}) ->
@client.boxInView(@pos.x + offset.x, @pos.y + offset.y, @radius)

teleportationEffect: () ->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When is this used?

#@client.effects.push new TeleportationEffect(@client, @pos, 80, @color, 500)

# Exports
window.Teleportation = Teleportation
21 changes: 21 additions & 0 deletions src/client/teleportationEffect.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class TeleportationEffect
constructor: (@client, @pos, @radius, @color, @duration) ->
@start = @client.now
@end = @start + @duration

update: () ->

deletable: () ->
@client.now > @end

inView: (offset = {x:0, y:0}) ->
@client.boxInView(@pos.x + offset.x, @pos.y + offset.y, @radius)

draw: (ctxt, offset = {x:0, y:0}) ->
ctxt.fillStyle = utils.color(@color, 1-(@client.now-@start)/@duration)
ctxt.beginPath()
ctxt.arc(@pos.x, @pos.y, @radius, 0, 2*Math.PI, false)
ctxt.fill()

# Exports
window.TeleportationEffect = TeleportationEffect
33 changes: 33 additions & 0 deletions src/server/bonusTeleportation.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Teleportation = require('./teleportation').Teleportation

class BonusTeleportation
type: 'teleportation'

constructor: (@game, @bonus) ->
@teleportation = @game.prefs.bonus.teleportation.teleportationCount
@target =
x: 0#@bonus.holder.pos.x
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup needed.

y: 0#@bonus.holder.pos.y

use: () ->
return if @teleportation < 0

# Clean up if there is no more mine.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftovers from copy & paste!

if @teleportation > 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are only two states to the bonus:

  1. Activate 'target'
  2. Drop 'teleportation' object

I'd prefer a boolean instead of a number.

@target =
x: @bonus.holder.pos.x
y: @bonus.holder.pos.y
console.log('avant : target : x='[email protected]+' y='[email protected])
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grr. Don't leave debugging statement when committing please ;)

else
@game.newGameObject (id) =>
dropPos = {x: @bonus.pos.x, y: @bonus.pos.y}
@game.teleportations[id] = new Teleportation(id, @game, @bonus.holder, dropPos, @target)
@bonus.holder.releaseBonus()
@bonus.setState 'dead'

# Decrease teleportation count.
--@teleportation

exports.BonusTeleportation = BonusTeleportation
exports.constructor = BonusTeleportation
exports.type = 'bonusTeleportation'
2 changes: 1 addition & 1 deletion src/server/bullet.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class Bullet extends ChangingObject
@game.events.push
type: 'bullet died'
id: @id

tangible: ->
@state is 'active'

Expand Down
49 changes: 49 additions & 0 deletions src/server/collisions.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ exports.handle = (obj1, obj2) ->
else if exports.collisions[type2]?
exports.collisions[type2](obj2, obj1)

exports.teleportation =
(obj, teleportation) ->
obj.pos.x = teleportation.target.x
obj.pos.y = teleportation.target.y
# Update bounding box position.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't update the object's hitBox as well. For one frame, objects are not hittable where they are drawn in the client.

In addition, obj.pos is not enough to move some objects like bullets. Bullets work in continuous segments and teleportation breaks this continuity. The simplest way around it would be to kill the bullet when it enters the teleporter and recreate it on the other side.

obj.boundingBox.x = obj.pos.x
obj.boundingBox.y = obj.pos.y
obj.game.events.push
type: 'teleportation'
id: obj.id

exports.collisions =
'ship-bonus': (ship, bonus) ->
if bonus.state is 'available'
Expand Down Expand Up @@ -585,3 +596,41 @@ exports.collisions =
shield.cancel()

ddebug "EMP ##{emp.id} cancelled shield ##{shield.id}"

'teleportation-ship': (teleportation, ship) ->
#teleportation of the ship
if teleportation.state is 'active'
exports.teleportation(ship, teleportation)

'teleportation-tracker': (teleportation, tracker) ->
#teleportation of the tracker
if teleportation.state is 'active'
exports.teleportation(tracker, teleportation)

'teleportation-grenade': (teleportation, grenade) ->
#teleportation of the grenade
if teleportation.state is 'active'
exports.teleportation(grenade.teleportation)

'teleportation-bullet': (teleportation, bullet) ->
#teleportation o the bullet
if teleportation.state is 'active'
exports.teleportation(bullet, teleportation)

'teleportation-shield': (teleportation, shield) ->
#teleportation of the ship and of the shield
if teleportation.state is 'active'
exports.teleportation(shield.owner, teleportation)

'teleportation-bonus': (teleportation, bonus) ->
#teleportation of the bonus
if teleportation.state is 'active'
exports.teleportation(bonus, teleportation)

'teleportation-mine': (teleportation, mine) ->
#teleportation of the mine
if teleportation.state is 'active'
exports.teleportation(mine, teleportation)

#no teleportation of moon, planet, and rope
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for planets and moons.

Rope have the same issue as bullets: they are multi-points. Either delete and recreate on the other side, or teleport the whole object. Updating the 'pos' object isn't enough.


1 change: 1 addition & 0 deletions src/server/gameServer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class GameServer

@bullets = {}
@mines = {}
@teleportations = {}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, but doesn't hurt.

@grenades = {}
@EMPs = {}
@trackers = {}
Expand Down
2 changes: 2 additions & 0 deletions src/server/httpServer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ webFiles = {
'/js/client/shield.js',
'/js/client/ship.js',
'/js/client/spriteManager.js',
'/js/client/teleportation.js',
'/js/client/teleportationEffect.js',
'/js/client/tooltip.js',
'/js/client/tracker.js',
'/js/client/trailEffect.js',
Expand Down
31 changes: 29 additions & 2 deletions src/server/prefs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ BonusMine = require './bonusMine'
BonusGrenade = require './bonusGrenade'
BonusTracker = require './bonusTracker'
BonusStealth = require './bonusStealth'
BonusTeleportation = require './bonusTeleportation'
BonusEMP = require './bonusEMP'

class ServerPreferences
Expand Down Expand Up @@ -336,6 +337,26 @@ class GamePreferences
countdown: null
next: null

teleportation:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly cut & paste from Mine. Not everything applies to the teleporter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which? I don't see, for me, all parameters is used.
The wave and the detection radius are used in the files "teleportation" (in the client and in the server).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I precise : not directly in the client

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are only relevant for mines, but I don't think we should reuse the same animation for the teleporter.


# Sensibility radius.
minDetectionRadius: 30
maxDetectionRadius: 50

# Speed of wave.
waveSpeed: 0.5

states:
'inactive':
countdown: 0
next: 'active'
'active':
countdown: 5000
next: 'disapear'
'disapear':
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

countdown: null
next: null

grenade:

radius: 4
Expand Down Expand Up @@ -421,7 +442,10 @@ class GamePreferences
mine:
# Number of held mines.
mineCount: 2


teleportation:
teleportationCount: 1
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless if we use a boolean.


boost:
# Initial speed multiplier.
boostFactor: 2
Expand All @@ -444,7 +468,7 @@ class GamePreferences
weight: 1
grenade:
class: BonusGrenade
weight: 100
weight: 1
tracker:
class: BonusTracker
weight: 1
Expand All @@ -460,6 +484,9 @@ class GamePreferences
stealth:
class: BonusStealth
weight: 1
teleportation:
class: BonusTeleportation
weight: 100
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grr. These are /default/ parameters.


exports.ServerPreferences = ServerPreferences
exports.GamePreferences = GamePreferences
Loading