Permalink
Browse files

F shoots something else

  • Loading branch information...
1 parent d0faa56 commit 84538f779f8d5ecdeb1fcca193323e7930a749d2 @davedash davedash committed Mar 2, 2012
Showing with 28 additions and 8 deletions.
  1. BIN assets/audio/grenade.ogg
  2. +5 −0 index.html
  3. +14 −2 js/bullet.js
  4. +1 −1 js/core/keyboardcontrols.js
  5. +8 −5 js/player.js
View
Binary file not shown.
View
@@ -26,6 +26,11 @@
<source src="assets/audio/shoot.ogg">
</audio>
+ <!-- Shooting sound effect -->
+ <audio id="shoot2" preload="auto" autobuffer>
+ <source src="assets/audio/grenade.ogg">
+ </audio>
+
<script data-main="js/game.js" src="js/require.js"></script>
</body>
</html>
View
@@ -3,13 +3,14 @@ define(function(require) {
Entity = require('core/entity'),
util = require('util');
- function Bullet(engine, x, y, speed, dir) {
+ function Bullet(engine, x, y, speed, dir, alt) {
Entity.call(this, engine);
return _.extend(this, {
x: x,
y: y,
speed: speed,
dir: dir,
+ grenade: alt,
bounding_box: {left:0, top:0, right:5, bottom:5}
});
}
@@ -24,13 +25,24 @@ define(function(require) {
bottom: this.y + this.bounding_box.bottom});
if(c.solid) {
this.engine.tilemaps['first'].map[c.y][c.x] = 0;
+ if (this.grenade) {
+ this.engine.tilemaps['first'].map[c.y][c.x+1] = 0;
+ }
return false;
};
},
-
+
render: function(ctx, x, y) {
ctx.fillStyle = 'green';
ctx.fillRect(this.x - x, this.y - y, 5, 5);
+ if (!this.grenade) {
+ ctx.fillStyle = 'green';
+ ctx.fillRect(this.x - x, this.y - y, 2, 2);
+ } else {
+ ctx.fillStyle = 'red';
+ ctx.fillRect(this.x - x, this.y - y, 10, 10);
+
+ }
}
});
@@ -11,7 +11,7 @@ define(['underscore'], function(_) {
'DOWN' : 40,
'A': 68,
'B': 70,
- 'SPACE': 32
+ 'SPACE': 32,
});
this.letter = function(l) {
View
@@ -14,8 +14,6 @@ define(function(require) {
tileset: new Tileset(loader.get('player'), 16, 16, 0, 0, {}),
frame: 0,
tile: 0,
- x: 20,
- y: 16*14,
dir: util.RIGHT,
bounding_box: {left: 4, top: 0, right: 11, bottom: 15},
shooting: false
@@ -77,14 +75,19 @@ define(function(require) {
this.vy = 0;
}
- if(kb.pressed(kb.SPACE)) {
+ if(kb.pressed(kb.SPACE) || kb.pressed(kb.B)) {
this.shooting = true;
+ var alt = kb.pressed(kb.B);
this.engine.add_entity(new Bullet(this.engine,
this.x + (this.dir == util.LEFT ? 0 : 16),
this.y + 8,
1.0,
- this.dir));
- document.getElementById('shoot').play();
+ this.dir, alt));
+ if (alt) {
+ document.getElementById('shoot2').play();
+ } else {
+ document.getElementById('shoot').play();
+ }
} else {
this.shooting = false;
}

0 comments on commit 84538f7

Please sign in to comment.