Created
December 26, 2018 06:27
-
-
Save CrazyPython/b9884107f6672d820b6b0f79c929dedf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// gamemode files would be best in CoffeeScript | |
// real width is 3000 | |
// food was originally 800, food would add an element of dodging | |
// this mode should have the leaderboard disabled on the client | |
// npm install driftless for more accurate timing | |
// also could npm install driftless help make arras faster, by maing gameloop execute more accurately? | |
exports.flagCarriers = [] | |
exports.flagTimes = {[-1] /*blue*/: 5*60, [-3] /*red*/: 5*60} | |
const isFlag = e => e.type === 'flag' | |
/* enact the countdown for the flag carrier's team*/ | |
class flagCarrier_io { | |
constructor(body) { | |
this.body = body; | |
this.acceptsFromTop = true; | |
this.body.health._amount = this.body.health.amount | |
this.intervalCode = setInterval( | |
() => exports.flagTimes[this.body.team] -= 10 | |
, 10) | |
Object.defineProperty(this.body.health, 'amount', { | |
set: v => { | |
this.body.health._amount = v | |
if (v <= 0) { | |
clearInterval(this.intervalCode) | |
} | |
}, | |
get: v => this.body.health._amount | |
}) | |
} | |
think() {} | |
} | |
function makeNewFlag(Entity, Class, room) { | |
let flag = new Entity({x:room.width/2, y: room.height/2}) | |
flag.define(Class.flag) | |
} | |
module.exports.setup = (Entity, Class, room) => { | |
makeNewFlag(Entity, Class, room) | |
} | |
function giveFlag(newOwner, Entity, Class, room, sockets) { | |
newOwner.hasFlag = true | |
newOwner.sendMessage('You have the flag.') | |
console.log(newOwner.label, ':', newOwner.name) | |
sockets.broadcast(newOwner.name + ' captured the flag!') | |
room.topPlayerID = newOwner.id // this way "usurped" messages show | |
const oldDestroy = newOwner.destroy.bind(newOwner) | |
exports.flagCarriers.push(newOwner) | |
newOwner.destroy = function() { | |
// this code should be moved to flagCarrier_io | |
// the variable names inside this closure are a little confusing | |
oldDestroy() | |
exports.flagCarriers.splice(exports.flagCarriers.indexOf(newOwner)) | |
const viableNewOwners = this.killCount.killers.filter(e => e.type === 'tank') | |
if (viableNewOwners.length > 0) { | |
console.log(viableNewOwners[0]) | |
giveFlag(viableNewOwners[0], Entity, Class, room, sockets) | |
} else { | |
newOwner.hasFlag = false | |
let newFlag = new Entity({x:newOwner.x, y:newOwner.y}) | |
newFlag.define(Class.flag) | |
} | |
}.bind(newOwner) | |
newOwner.controllers.push(new flagCarrier_io(newOwner)) | |
} | |
let origType = null | |
module.exports.collide = (me, other, Entity, Class, room, sockets) => { | |
if (!origType) { | |
origType = room.randomType | |
room.randomType = () => origType('norm') | |
} | |
// io_hasFlag | |
let flag, notflag | |
if (me === null || other === null) { | |
return | |
} | |
if (isFlag(other)) { | |
flag = other | |
notflag = me | |
} else if (isFlag(me)) { | |
flag = me | |
notflag = other | |
} else { | |
return | |
} | |
flag.color = 0//9 //13 // gold colored | |
flag.kill() | |
giveFlag(notflag, Entity, Class, room, sockets) | |
} | |
module.exports.shouldBeVisibleOnMinimap = me => { | |
if (me.hasFlag || isFlag(me)) { | |
return true | |
} | |
} | |
module.exports.customizeLeaderboard = defaultLeaderboard => { | |
// make the flag carriers the first ones | |
let leaderboard = defaultLeaderboard | |
for (let flagCarrier of exports.flagCarriers) { | |
if (leaderboard.indexOf(flagCarrier)) | |
leaderboard.splice(leaderboard.indexOf(flagCarrier)) | |
leaderboard.unshift(flagCarrier) | |
} | |
return leaderboard | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment