Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Video Game Spell System
var spells = {
shield: {
buff: {
type: 'reflect',
duration: 60
},
castTime: 30,
mana: -20
},
fireball:{
projectile: {
type: 'fireball'
},
castTime: 30,
mana: -10
}
}
var buffs = {
reflect: {
duration: 120,
reduceDamage: 1,
reflect: true
}
}
var projectiles = {
fireball: {
duration: 120,
damage: 4
}
}
var player = {
health: 100,
mana: 100,
buffs: [],
casting: 0,//Time left to finish casting spell
castingSpell: undefined;
}
player.cast = function(spell){
if(casting) return;
castingSpell = spell
casting = spells[spell].castTime || 0;
}
player.step = function(){
//reduce cast timer
//Cast on 0
//Reduce buffs timers
//Remove done buffs
//Run buffs
}
player.cast('fireball');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment