Created
January 29, 2016 18:09
-
-
Save yassu/7e84c7fcafe5b3d40244 to your computer and use it in GitHub Desktop.
with bugs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enchant(); | |
var CELL_LENGTH = 32; | |
window.onload = function() { | |
var core = new Core(350, 320); | |
core.fps = 30; | |
core.preload("chara1.png"); | |
core.preload("map0.png"); | |
core.onload = function() { | |
var mob = Class.create(Sprite, { | |
move: function(vec) { | |
this.x += vec[0]; | |
this.y += vec[1]; | |
} | |
getAround: function(map) { | |
var around_cells = []; | |
if (this.y > 0) { | |
around_cells.push(map[x][y - 1]); | |
} | |
if (this.x > 0) { | |
around_cells.push(maps[x - 1][y]); | |
} | |
if (this.x < maps[0].length() - 1) { | |
around_cells.push(maps[x + 1][y]); | |
} | |
if (this.y < maps.length() - 1) { | |
around_cells.push(maps[x][y + 1]); | |
} | |
return around_cells; | |
} | |
}); | |
var bear = new Sprite(32, 32); | |
bear.image = core.assets["chara1.png"]; | |
bear.x = CELL_LENGTH; | |
bear.y = CELL_LENGTH; | |
var left = 20; | |
var leftLabel = new Label(left); | |
leftLabel.x = 330; | |
leftLabel.y = 10; | |
bear.addEventListener('enterframe', function() { | |
this.frame = this.age % 3; | |
if (this.frame % 30 == 0) { | |
if (core.input.right && !map.hitTest(this.x + CELL_LENGTH, this.y)) { | |
this.x += CELL_LENGTH; | |
left -= 1; | |
} | |
if (core.input.left && !map.hitTest(this.x - CELL_LENGTH, this.y)) { | |
this.x -= CELL_LENGTH; | |
left -= 1; | |
} | |
if (core.input.down && !map.hitTest(this.x, this.y + CELL_LENGTH)) { | |
this.y += CELL_LENGTH; | |
left -= 1; | |
} | |
if (core.input.up && !map.hitTest(this.x, this.y - CELL_LENGTH)) { | |
this.y -= CELL_LENGTH; | |
left -= 1; | |
} | |
} | |
leftLabel.text = left; | |
if (map.checkTile(this.x, this.y) == 14) { | |
leftLabel.text = "成"; | |
core.stop(); | |
} | |
if (left == 0) { | |
leftLabel.text = "死"; | |
core.stop(); | |
} | |
}); | |
var map = new Map(CELL_LENGTH, CELL_LENGTH); // Map(セルの高さ, セルの幅) | |
map.image = core.assets['map0.png']; | |
map.loadData( | |
[ | |
[7, 7, 7, 7, 7, 7, 7, 7, 7, 7], | |
[7, 13, 0, 0, 0, 0, 0, 0, 0, 7], | |
[7, 0, 0, 0, 0, 0, 0, 0, 0, 7], | |
[7, 0, 0, 0, 0, 0, 0, 0, 0, 7], | |
[7, 0, 0, 0, 0, 0, 0, 0, 0, 7], | |
[7, 0, 0, 0, 0, 0, 0, 0, 0, 7], | |
[7, 0, 0, 0, 0, 0, 0, 0, 0, 7], | |
[7, 0, 0, 0, 0, 0, 0, 0, 0, 7], | |
[7, 0, 0, 0, 0, 0, 0, 0, 14, 7], | |
[7, 7, 7, 7, 7, 7, 7, 7, 7, 7], | |
] | |
); | |
map.collisionData = | |
[ | |
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], | |
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1], | |
[1, 1, 1, 1, 1, 1, 1, 1, 1, 1], | |
] | |
core.rootScene.addChild(map); | |
core.rootScene.addChild(leftLabel); | |
core.rootScene.addChild(bear); | |
}; | |
core.start(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment