better placing
This commit is contained in:
parent
1952708e9f
commit
164c39e079
2 changed files with 24 additions and 25 deletions
18
js/motion.js
18
js/motion.js
|
@ -1,5 +1,9 @@
|
|||
let keys = [];
|
||||
let vel = [0, 0];
|
||||
let posM = [0,0];
|
||||
let r = document.querySelector('canvas').getBoundingClientRect();
|
||||
let x = r.x + r.width / 2;
|
||||
let y = r.y + r.height / 2;
|
||||
|
||||
let id = '';
|
||||
|
||||
|
@ -7,8 +11,8 @@ function down(e) {
|
|||
let k = e.key.toLowerCase();
|
||||
keys[k] = true;
|
||||
|
||||
if (k == 'r') game.placeBlock(6);
|
||||
if (k == 'f') game.placeBlock(5);
|
||||
if (k == 'r') game.placeBlock(6,false,posM[0],posM[1]);
|
||||
if (k == 'f') game.placeBlock(5,false,posM[0],posM[1]);
|
||||
};
|
||||
|
||||
function up(e) {
|
||||
|
@ -27,7 +31,15 @@ function move() {
|
|||
game.camera[1] -= vel[1] * 1.8;
|
||||
}
|
||||
|
||||
function mouse(e) {
|
||||
posM[0] = game.camera[0] + (e.pageX - x) / r.width * document.querySelector('canvas').width;
|
||||
posM[0] -= tileSize / 2;
|
||||
posM[1] = game.camera[1] + (e.pageY - y) / r.height * document.querySelector('canvas').height;
|
||||
posM[1] -= tileSize / 2;
|
||||
}
|
||||
|
||||
setInterval(move, 10);
|
||||
|
||||
window.addEventListener('keydown', down);
|
||||
window.addEventListener('keyup', up);
|
||||
window.addEventListener('keyup', up);
|
||||
window.addEventListener('mousemove', mouse);
|
Loading…
Add table
Add a link
Reference in a new issue