Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Pixels & Tactics

Amber Feng
October 07, 2015
9.5k

Pixels & Tactics

Adventures of building a 2D tactics RPG in the browser!

Amber Feng

October 07, 2015
Tweet

Transcript

  1. Crafty.c("Walkable", { Walkable: function(speed) { this.addComponent("Collision"); this.bind("EnterFrame", function() { if

    (paused()) return; if (obstacle() || outOfBounds()) return; // Move the sprite this.playAnimation(this.direction); this.move(this.direction, speed); })
  2. Crafty.c("StrollingEntity", { StrollingEntity: function() { this.direction = randomDirection(); this.bind("EnterFrame", function()

    { // Possibly change direction if (chanceToSwitchDirection()) { this.direction = randomDirection(); } } } });
  3. Crafty.c("AggroEntity", { AggroEntity: function(player) { this.direction = randomDirection(); this.bind("EnterFrame", function()

    { if (playerInRange()) { this.direction = toPlayer(player); } else if (chanceToSwitchDirection()) { // Change direction this.direction = randomDirection(); } } } });
  4. var Fox = function() { this.hp = 10; this.damage =

    10; } var WaterFairy = function() { this.hp = 4; this.damage = 6; } var fox = new Fox(); var waterFairy = new WaterFairy();
  5. var Monster = function(attrs) { // Set attrs } var

    fox = new Monster({ hp: 4, damage: 6 });