Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
};
// mock document
Konva.document = {
createElement: function() {},
documentElement: {
addEventListener: function() {}
}
};
// make some global injections
global.requestAnimationFrame = cb => {
setImmediate(cb);
};
// create canvas in Node env
Konva.Util.createCanvasElement = () => {
const node = new canvas.Canvas();
node.style = {};
return node;
};
// create canvas in Node env
Konva.Util.createImageElement = () => {
const node = new canvas.Image();
node.style = {};
return node;
};
// _checkVisibility use dom element, in node we can skip it
Konva.Stage.prototype._checkVisibility = () => {};
module.exports = Konva;
// this.lightSize * this.paintWidth / this.width,
// 0, Math.PI * 2,
// );
// gameMap.ctx.fill();
// gameMap.ctx.globalAlpha = 1;
// gameMap.ctx.beginPath();
// gameMap.ctx.arc(this.paintX, this.paintY, this.paintWidth / 2, 0, Math.PI * 2);
// gameMap.ctx.fill();
// }
return (
};
// make some global injections
global.requestAnimationFrame = cb => {
setImmediate(cb);
};
// create canvas in Node env
Konva.Util.createCanvasElement = () => {
const node = new canvas.Canvas();
node.style = {};
return node;
};
// create canvas in Node env
Konva.Util.createImageElement = () => {
const node = new canvas.Image();
node.style = {};
return node;
};
// _checkVisibility use dom element, in node we can skip it
Konva.Stage.prototype._checkVisibility = () => {};
module.exports = Konva;
x: 0,
y: 0,
width: window.innerWidth,
height: window.innerHeight,
},
},
players: [],
foods: [],
leaderboard: [],
player: {
username: 'undefined',
points: [],
id: -1,
x: window.innerWidth / 2,
y: window.innerHeight / 2,
fillColor: Konva.Util.getRandomColor(),
},
};
export default (state = initialState, action) => {
switch (action.type) {
case WEBSOCKET_CONNECT:
return {
...state,
player: {
...state.player,
username: action.username,
},
};
case WEBSOCKET_REGISTER_SUCCESS:
return {
players: [...action.players],
player: {
...(player ? player : state.player),
},
};
}
case ADD_COLORED_RECT:
return {
...state,
entities: [
...state.entities,
{
x: Math.random() * window.innerWidth,
y: Math.random() * window.innerHeight,
color: Konva.Util.getRandomColor(),
},
],
};
default:
return state;
}
};
setTimeout(() => {
this.setState({ color: Konva.Util.getRandomColor() })
}, 1000)
}
constructor(...args) {
super(...args);
this.state = {
color: Konva.Util.getRandomColor(),
ballX: 100,
ballY: 100,
ballSpeedX: 10,
ballSpeedY: 10,
paddleX: 700,
paddleY: window.innerHeight - 50,
visaible: true,
};
this.draw = this.draw.bind(this);
this.movePaddleRight = this.movePaddleRight.bind(this);
this.movePaddleLeft = this.movePaddleLeft.bind(this);
}