1.0.0
This commit is contained in:
parent
37e0d7f66f
commit
0d8f19e284
|
@ -0,0 +1,2 @@
|
|||
node_modules/
|
||||
app.js
|
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) <year> <copyright holders>
|
||||
Copyright (c) 2021 Alexander Popov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en-us">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>jsKeyPressed</title>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="app" width="320" height="240">
|
||||
Canvas not available.
|
||||
</canvas>
|
||||
|
||||
<script type="text/javascript" src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,67 @@
|
|||
let canvas = null;
|
||||
let context = null;
|
||||
let cW = null;
|
||||
let cH = null;
|
||||
|
||||
let pressedKeys = {};
|
||||
|
||||
window.onload = function() {
|
||||
'use strict';
|
||||
|
||||
canvas = document.getElementById('app');
|
||||
context = canvas.getContext('2d');
|
||||
cW = canvas.width;
|
||||
cH = canvas.height;
|
||||
|
||||
window.requestAnimationFrame(GameLoop);
|
||||
}
|
||||
|
||||
window.onkeyup = function(e) { pressedKeys[e.code] = false; }
|
||||
window.onkeydown = function(e) { pressedKeys[e.code] = true; }
|
||||
|
||||
function GameLoop(timeStamp) {
|
||||
'use strict';
|
||||
|
||||
Update();
|
||||
Draw();
|
||||
|
||||
window.requestAnimationFrame(GameLoop);
|
||||
}
|
||||
|
||||
function Draw() {
|
||||
'use strict';
|
||||
|
||||
// clean context
|
||||
context.fillStyle = '#999999';
|
||||
context.fillRect(0, 0, cW, cH);
|
||||
|
||||
context.fillStyle = '#ffffff';
|
||||
if(pressedKeys['KeyW']) {
|
||||
context.fillStyle = '#ff0000';
|
||||
}
|
||||
context.fillRect(cW / 2 - 25, 100, 50, 50); // W
|
||||
|
||||
context.fillStyle = '#ffffff';
|
||||
if(pressedKeys['KeyA']) {
|
||||
context.fillStyle = '#ff0000';
|
||||
}
|
||||
context.fillRect(cW / 2 - 75, 150, 50, 50); // A
|
||||
|
||||
context.fillStyle = '#ffffff';
|
||||
if(pressedKeys['KeyS']) {
|
||||
context.fillStyle = '#ff0000';
|
||||
}
|
||||
context.fillRect(cW / 2 - 25, 150, 50, 50); // S
|
||||
|
||||
context.fillStyle = '#ffffff';
|
||||
if(pressedKeys['KeyD']) {
|
||||
context.fillStyle = '#ff0000';
|
||||
}
|
||||
context.fillRect(cW / 2 + 25, 150, 50, 50); // D
|
||||
}
|
||||
|
||||
function Update() {
|
||||
'use strict';
|
||||
|
||||
//
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"name": "jskeypressed",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "./js/index.js",
|
||||
"scripts": {
|
||||
"start": "webpack serve",
|
||||
"build": "webpack --mode=production",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "gitea@iiiypuk.me:iiiypuk/jsKeyPressed.git"
|
||||
},
|
||||
"author": "Alexander Popov",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"webpack": "^5.45.1",
|
||||
"webpack-cli": "^4.7.2",
|
||||
"webpack-dev-server": "^3.11.2"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
const path = require('path');
|
||||
|
||||
module.exports = {
|
||||
mode: 'development',
|
||||
entry: './js/index.js',
|
||||
output: {
|
||||
path: path.resolve(__dirname, './'),
|
||||
filename: 'app.js',
|
||||
},
|
||||
devServer: {
|
||||
contentBase: path.join(__dirname, './'),
|
||||
compress: false,
|
||||
port: 55555,
|
||||
},
|
||||
};
|
Loading…
Reference in New Issue