-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: next
Are you sure you want to change the base?
Next #1
Changes from 2 commits
c7aed4b
7fe56eb
7fc453c
48e5ff9
d6e07a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: () -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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 |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftovers from copy & paste! |
||
if @teleportation > 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since there are only two states to the bonus:
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]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ class GameServer | |
|
||
@bullets = {} | ||
@mines = {} | ||
@teleportations = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused, but doesn't hurt. |
||
@grenades = {} | ||
@EMPs = {} | ||
@trackers = {} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ BonusMine = require './bonusMine' | |
BonusGrenade = require './bonusGrenade' | ||
BonusTracker = require './bonusTracker' | ||
BonusStealth = require './bonusStealth' | ||
BonusTeleportation = require './bonusTeleportation' | ||
BonusEMP = require './bonusEMP' | ||
|
||
class ServerPreferences | ||
|
@@ -336,6 +337,26 @@ class GamePreferences | |
countdown: null | ||
next: null | ||
|
||
teleportation: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly cut & paste from Mine. Not everything applies to the teleporter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Which? I don't see, for me, all parameters is used. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I precise : not directly in the client There was a problem hiding this comment. Choose a reason for hiding this commentThe 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': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo |
||
countdown: null | ||
next: null | ||
|
||
grenade: | ||
|
||
radius: 4 | ||
|
@@ -421,7 +442,10 @@ class GamePreferences | |
mine: | ||
# Number of held mines. | ||
mineCount: 2 | ||
|
||
|
||
teleportation: | ||
teleportationCount: 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Useless if we use a boolean. |
||
|
||
boost: | ||
# Initial speed multiplier. | ||
boostFactor: 2 | ||
|
@@ -444,7 +468,7 @@ class GamePreferences | |
weight: 1 | ||
grenade: | ||
class: BonusGrenade | ||
weight: 100 | ||
weight: 1 | ||
tracker: | ||
class: BonusTracker | ||
weight: 1 | ||
|
@@ -460,6 +484,9 @@ class GamePreferences | |
stealth: | ||
class: BonusStealth | ||
weight: 1 | ||
teleportation: | ||
class: BonusTeleportation | ||
weight: 100 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Grr. These are /default/ parameters. |
||
|
||
exports.ServerPreferences = ServerPreferences | ||
exports.GamePreferences = GamePreferences |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed?