Compare commits
No commits in common. "2a67ab40ee4d10d08edb70cecb21ce7c09486e0e" and "4746f34537c07410f8432f43bcc705cffb28cb1e" have entirely different histories.
2a67ab40ee
...
4746f34537
5 changed files with 4 additions and 42 deletions
|
@ -13,8 +13,5 @@
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"buffer": true
|
"buffer": true
|
||||||
},
|
|
||||||
"appearance": {
|
|
||||||
"grid": "none"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,5 @@
|
||||||
"min": 0,
|
"min": 0,
|
||||||
"max": 1
|
"max": 1
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"appearance": {
|
|
||||||
"grid": [
|
|
||||||
"grid",
|
|
||||||
"checkerboard",
|
|
||||||
"none"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ const handleAngleMagnitude=(x, y, threshold=0, fn=null, clearBuffer=false) => {
|
||||||
const {angle, magnitude}=toAngleMagnitude(x, y);
|
const {angle, magnitude}=toAngleMagnitude(x, y);
|
||||||
|
|
||||||
if(magnitude>threshold) {
|
if(magnitude>threshold) {
|
||||||
let inputs=currentInputs;
|
|
||||||
if(angle>.25 && angle <.75) inputs.right=true;
|
if(angle>.25 && angle <.75) inputs.right=true;
|
||||||
else if(angle>.75 && angle<1.25) inputs.up=true;
|
else if(angle>.75 && angle<1.25) inputs.up=true;
|
||||||
else if(angle>1.25 && angle<1.75) inputs.left=true;
|
else if(angle>1.25 && angle<1.75) inputs.left=true;
|
||||||
|
@ -70,7 +69,7 @@ const handleJoystick=(() => {
|
||||||
!config.touchscreen.buffer
|
!config.touchscreen.buffer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})();
|
});
|
||||||
|
|
||||||
const handleSwipe=(() => {
|
const handleSwipe=(() => {
|
||||||
let center={
|
let center={
|
||||||
|
@ -92,7 +91,7 @@ const handleSwipe=(() => {
|
||||||
!config.touchscreen.buffer
|
!config.touchscreen.buffer
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})();
|
});
|
||||||
|
|
||||||
const handleGamepads={
|
const handleGamepads={
|
||||||
frame: () => {
|
frame: () => {
|
||||||
|
@ -112,7 +111,6 @@ const handleGamepads={
|
||||||
|
|
||||||
const handleEvent=(type, evt) => {
|
const handleEvent=(type, evt) => {
|
||||||
for(let handler of handlers) {
|
for(let handler of handlers) {
|
||||||
console.log(type, handler);
|
|
||||||
let fn=handler[type];
|
let fn=handler[type];
|
||||||
if(fn) fn(evt);
|
if(fn) fn(evt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
const rules=levelList[category].rules || {};
|
const rules=levelList[category].rules || {};
|
||||||
const level=await levels.get(filename);
|
const level=await levels.get(filename);
|
||||||
|
|
||||||
// create the game and attach the callbacks and config
|
// create the game and attach the callbacks
|
||||||
const snek=currentGame=new SnekGame(level, canvas, rules);
|
const snek=currentGame=new SnekGame(level, canvas, rules);
|
||||||
snek.callback=evt => {
|
snek.callback=evt => {
|
||||||
if(evt=='tick') {
|
if(evt=='tick') {
|
||||||
|
@ -114,7 +114,6 @@
|
||||||
handleDeath(snek);
|
handleDeath(snek);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
snek.config=config;
|
|
||||||
|
|
||||||
// setup the DOM
|
// setup the DOM
|
||||||
nav.classList.add('hidden');
|
nav.classList.add('hidden');
|
||||||
|
|
|
@ -104,7 +104,6 @@ class SnekGame {
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
const assets=require('assets');
|
const assets=require('assets');
|
||||||
const config=this.config;
|
|
||||||
|
|
||||||
// clear the canvas, because it's easier than having to deal with everything
|
// clear the canvas, because it's easier than having to deal with everything
|
||||||
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
|
@ -124,31 +123,7 @@ class SnekGame {
|
||||||
this.ctx.fillRect(offsetX+cellSize*this.dimensions[0], 0, offsetX, this.canvas.height);
|
this.ctx.fillRect(offsetX+cellSize*this.dimensions[0], 0, offsetX, this.canvas.height);
|
||||||
this.ctx.fillRect(0, offsetY+cellSize*this.dimensions[1], this.canvas.width, offsetY);
|
this.ctx.fillRect(0, offsetY+cellSize*this.dimensions[1], this.canvas.width, offsetY);
|
||||||
|
|
||||||
// draw a grid/checkerboard if requested
|
// draw our walls
|
||||||
if(config.appearance.grid=='grid') {
|
|
||||||
this.ctx.strokeStyle='rgba(0, 0, 0, 50%)';
|
|
||||||
this.ctx.lineCap='square';
|
|
||||||
this.ctx.lineWidth=1;
|
|
||||||
this.ctx.beginPath();
|
|
||||||
for(let x=1; x<this.dimensions[0]; x++) {
|
|
||||||
this.ctx.moveTo(offsetX+x*cellSize, offsetY);
|
|
||||||
this.ctx.lineTo(offsetX+x*cellSize, this.canvas.height-offsetY);
|
|
||||||
}
|
|
||||||
for(let y=1; y<this.dimensions[1]; y++) {
|
|
||||||
this.ctx.moveTo(offsetX, offsetY+y*cellSize);
|
|
||||||
this.ctx.lineTo(this.canvas.width-offsetX, offsetY+y*cellSize);
|
|
||||||
}
|
|
||||||
this.ctx.stroke();
|
|
||||||
} else if(config.appearance.grid=='checkerboard') {
|
|
||||||
this.ctx.fillStyle='rgba(0, 0, 0, 10%)';
|
|
||||||
for(let x=0; x<this.dimensions[0]; x++) {
|
|
||||||
for(let y=(x+1)%2; y<this.dimensions[1]; y+=2) {
|
|
||||||
this.ctx.fillRect(offsetX+x*cellSize, offsetY+y*cellSize, cellSize, cellSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// draw our tiles
|
|
||||||
const wall=assets.get('wall');
|
const wall=assets.get('wall');
|
||||||
const hole=assets.get('hole');
|
const hole=assets.get('hole');
|
||||||
const fire=assets.get('fire');
|
const fire=assets.get('fire');
|
||||||
|
|
Loading…
Reference in a new issue