Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Showing with 63 additions and 2 deletions.
  1. +23 −0 assets/maps.json
  2. +9 −0 js/core/engine.js
  3. +0 −1 js/core/entity.js
  4. +29 −0 js/door.js
  5. +2 −1 js/player.js
View
23 assets/maps.json
@@ -2,9 +2,32 @@
"first": {
"map": [[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,5,0,0,0,0],[0,0,0,0,0,0,5,0,6,6,6,6,5,0,0,0,0,0,0,0,0,0,0,0],[0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0],[0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,1,1,1,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,5,0,0,0,0,0,0,0,0,0,0,0,3,3,3,3,0,0,0,0,4,0],[0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,3,0,0,0,0,0],[0,6,6,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,4,0,0,0],[0,5,6,0,0,0,0,0,0,4,0,0,5,0,0,0,0,3,3,6,6,0,0,0],[0,0,0,6,0,0,0,0,4,4,0,0,0,0,0,0,3,3,0,0,0,0,4,0],[0,0,0,0,0,0,0,4,4,4,0,0,0,0,0,0,0,0,0,0,0,4,0,0],[0,0,0,0,0,0,4,4,4,0,0,0,0,1,0,0,0,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
}
}
View
9 js/core/engine.js
@@ -8,6 +8,7 @@ define(function(require) {
Player = require('player'),
Enemy = require('enemy'),
Momma = require('momma'),
+ Door = require('door'),
Sounds = require('core/sounds'),
Tileset = require('core/tileset'),
Tilemap = require('core/tilemap'),
@@ -90,11 +91,15 @@ define(function(require) {
// Load tilemaps
var maps = loader.get('maps');
+ var engine = this;
_.each(maps, function(map, id) {
self.tilemaps[id] = new Tilemap(self, self.tileset, map);
_.each(map.backgrounds, function(bg, bid) {
self.tilemaps[id].backgrounds[bid] = loader.get(bg);
});
+ if (map.door) {
+ engine.add_entity(new Door(engine, map.door.x, map.door.y));
+ }
});
document.getElementById('game').appendChild(this.canvas);
@@ -111,6 +116,10 @@ define(function(require) {
}
},
+ levelup: function() {
+ console.log("this run .enterLevel(this.level+1)");
+ },
+
// Process one frame of behavior.
tick: function() {
var neartree = this.neartree;
View
1 js/core/entity.js
@@ -12,7 +12,6 @@ define(function(require) {
_.extend(Entity.prototype, {
tick: function() {
- throw 'not implemented';
},
render: function(ctx, x, y) {
View
29 js/door.js
@@ -0,0 +1,29 @@
+define(function(require) {
+ var _ = require('underscore'),
+ Entity = require('core/entity'),
+ util = require('util');
+
+ function Door(engine, x, y) {
+ Entity.call(this, engine);
+ return _.extend(this, {
+ x: x,
+ y: y,
+ bounding_box: {left:0, top:0, right:5, bottom:5}
+ });
+ }
+
+ _.extend(Door.prototype, Entity.prototype, {
+ render: function(ctx, x, y) {
+ ctx.fillStyle = 'red';
+ ctx.fillRect(this.x - x, this.y - y, 10, 10);
+ },
+
+ collide: function(obj) {
+ if (obj.name == 'player') {
+ this.engine.levelup()
+ }
+ }
+ });
+
+ return Door;
+});
View
3 js/player.js
@@ -22,6 +22,7 @@ define(function(require) {
health: 3,
taking_damage: false,
_taking_damage_frame: 8
+ name: 'player'
});
}
@@ -97,7 +98,7 @@ define(function(require) {
engine.play("assets/audio/jump.ogg");
this.num_jumps++;
this.vy = -3;
- }
+ }
if (kb.pressed(kb.SPACE) || kb.pressed(kb.B)) {
this.shooting = true;

No commit comments for this range

Something went wrong with that request. Please try again.