Browse files

i broke stuffs

  • Loading branch information...
1 parent 9aad6f2 commit 92645c4384887d4544b70e84ac15c64bc35d80f9 Jen Fong-Adwent committed Mar 2, 2012
Showing with 39 additions and 7 deletions.
  1. +2 −2 assets/enemies.json
  2. +1 −0 assets/resources.json
  3. +1 −1 index.html
  4. +35 −4 js/enemy.js
View
4 assets/enemies.json
@@ -1,6 +1,6 @@
[
- {"x": 50, "y": 256, "dir": 3, "speed": 0.25},
- {"type": "momma", "x": 80, "y": 256, "dir": 4, "speed": 0.1},
+ {"x": 50, "y": 256, "dir": 4, "speed": 0.25},
+ {"type": "momma", "x": 80, "y": 256, "dir": 4, "speed": 0.5},
{"x": 150, "y": 256, "dir": 4, "speed": 0.25},
{"x": 200, "y": 256, "dir": 4, "speed": 0.25},
{"x": 200, "y": 200, "dir": 3, "speed": 1.25}
View
1 assets/resources.json
@@ -2,6 +2,7 @@
"images": {
"tileset": "images/game_tiles.png",
"player": "images/hipster.png",
+ "enemy": "images/enemy_1.png",
"bg0": "images/background_level0.png",
"bg1": "images/background_level1.png"
},
View
2 index.html
@@ -8,7 +8,7 @@
<body id="game">
<!-- Background Ambient Loop -->
<audio id="audio" preload="auto" autobuffer loop autoplay>
- <source src="assets/audio/loop.ogg">
+ <source src="assets/audio/loop2.ogg">
</audio>
<!-- Jump sound effect -->
View
39 js/enemy.js
@@ -1,7 +1,9 @@
define(function(require) {
var _ = require('underscore'),
- Entity = require('core/entity'),
util = require('util');
+ loader = require('core/loader'),
+ Entity = require('core/entity'),
+ Tileset = require('core/tileset');
function Enemy(engine, x, y, dir, speed) {
Entity.call(this, engine);
@@ -10,11 +12,40 @@ define(function(require) {
speed: speed,
x: x,
y: y,
- name: 'enemy'
+ name: 'enemy',
+ tileset: new Tileset(loader.get('enemy'), 16, 16, 0, 0, {}),
+ frame: 0,
+ tile: 0,
+ dir: dir,
+ bounding_box: {left: 4, top: 0, right: 11, bottom: 15},
+ vy: 0,
+ standing: false,
+ frame: 0,
+ tile: 0,
+ shooting: false,
+ has_laser: false
});
}
_.extend(Enemy.prototype, Entity.prototype, {
+ anim: function() {
+ this.tile = 2;
+
+ this.frame++;
+ if (this.frame > 7) this.frame = 0;
+ if (this.frame >= 0) {
+ if (this.frame < 4) {
+ this.tile = 0;
+ } else {
+ this.tile = 1;
+ }
+ }
+
+ if (this.dir === util.RIGHT) {
+ this.tile += 4;
+ }
+ },
+
tick: function() {
var dx = 0,
dy = 0;
@@ -42,8 +73,8 @@ define(function(require) {
},
render: function(ctx, x, y) {
- ctx.fillStyle = 'black';
- ctx.fillRect(this.x - x, this.y - y, 16, 16);
+ this.anim();
+ this.tileset.drawTile(ctx, this.tile, this.x - x, this.y - y);
},
collide: function(object) {

0 comments on commit 92645c4

Please sign in to comment.