Skip to content

Instantly share code, notes, and snippets.

@zeroeth
Last active March 27, 2022 14:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeroeth/8622428 to your computer and use it in GitHub Desktop.
Save zeroeth/8622428 to your computer and use it in GitHub Desktop.
javascript game basics.
var hit_enemy = function(enemy, weapon) {
if(enemy.state == "alive") {
enemy.health = enemy.health - weapon.damage;
console.log("hit!", enemy.health);
if(enemy.health <= 0) {
console.log("it died");
enemy.state = "dead";
}
}
else {
console.log("its already dead");
}
}
var player1 = {name: "bob", health: 40};
var sword = {name: "laser sword", damage: 6};
player1.weapon = sword;
var enemy1 = {name: "skeletor", health: 14, state: "alive"};
hit_enemy(enemy1, player1.weapon);
hit_enemy(enemy1, player1.weapon);
hit_enemy(enemy1, player1.weapon);
hit_enemy(enemy1, player1.weapon);
@erwingame
Copy link

What is this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment