diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bb8f8a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +projects/ +node_modules/ \ No newline at end of file diff --git a/asdf/TileMapXML.js b/asdf/TileMapXML.js new file mode 100644 index 0000000..e570cd2 --- /dev/null +++ b/asdf/TileMapXML.js @@ -0,0 +1,45 @@ +// XML format must be: +// +// +// ... +// + +class TileMapXML { + constructor(url) { + this.array = []; + this.fetchXMLtoArray(url); + } + + fetchXMLtoArray(url) { + var xhr = new XMLHttpRequest(); + xhr.open('GET', url, false); + xhr.send(null); + + if (xhr.status === 200) { + var children = xhr.responseXML.children[0].children; + for (let index = 0; index < children.length; index++) { + const element = children[index]; + this.array.push({ + name: element.attributes.name.nodeValue, + x: element.attributes.x.nodeValue, + y: element.attributes.y.nodeValue, + width: element.attributes.width.nodeValue, + height: element.attributes.height.nodeValue + }); + } + } else { + console.error('XML file cannot be loaded!') + } + } + + findIndex(attribute, value) { + for (let index = 0; index < this.array.length; index++) { + const element = this.array[index]; + if (element[attribute] == value) { + return index; + } + } + } +} + +export default TileMapXML; \ No newline at end of file diff --git a/asdf/TileSpriteXML.js b/asdf/TileSpriteXML.js new file mode 100644 index 0000000..70d0c63 --- /dev/null +++ b/asdf/TileSpriteXML.js @@ -0,0 +1,13 @@ +import Sprite from "./Sprite.js"; + +class TileSpriteXML extends Sprite { + constructor (texture, xml, index) { + super(texture); + var src = xml.array[index]; + this.imgPos = { x: src['x'], y: src['y'] }; + this.width = src['width']; + this.height = src['height']; + } +} + +export default TileSpriteXML; \ No newline at end of file diff --git a/asdf/controls/MouseControls.js b/asdf/controls/MouseControls.js index ade1795..1ae81f7 100644 --- a/asdf/controls/MouseControls.js +++ b/asdf/controls/MouseControls.js @@ -1,6 +1,6 @@ class MouseControls { constructor(container) { - this.el = container || document.body + this.el = container || document.body; // State this.pos = {x: 0, y: 0}; this.isDown = false; diff --git a/asdf/index.js b/asdf/index.js index ed94465..70d366f 100644 --- a/asdf/index.js +++ b/asdf/index.js @@ -9,9 +9,12 @@ import MouseControls from "./controls/MouseControls.js"; import Sprite from "./Sprite.js"; import TileSprite from "./TileSprite.js"; +import TileSpriteXML from "./TileSpriteXML.js"; import Text from "./Text.js"; import Texture from "./Texture.js"; +import TileMapXML from "./TileMapXML.js"; + export default { CanvasRenderer, Container, @@ -21,6 +24,8 @@ export default { MouseControls, Sprite, TileSprite, + TileMapXML, + TileSpriteXML, Text, Texture }; diff --git a/asdf/renderer/CanvasRenderer.js b/asdf/renderer/CanvasRenderer.js index bea0ef9..1e81cb1 100644 --- a/asdf/renderer/CanvasRenderer.js +++ b/asdf/renderer/CanvasRenderer.js @@ -67,6 +67,15 @@ class CanvasRenderer { 0,0, child.tileW, child.tileH ); + } else if (child.imgPos && child.width && child.height) { + ctx.drawImage( + img, + child.imgPos.x, + child.imgPos.y, + child.width, child.height, + 0,0, + child.width, child.height + ); } else { ctx.drawImage(img, 0, 0); } diff --git a/ctx-test/favicon.png b/ctx-test/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/ctx-test/favicon.png and /dev/null differ diff --git a/ctx-test/index.html b/ctx-test/index.html deleted file mode 100644 index 16a6e72..0000000 --- a/ctx-test/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Game - - - -
- -
- - - diff --git a/ctx-test/lib/KeyControls.js b/ctx-test/lib/KeyControls.js deleted file mode 100644 index 3af4798..0000000 --- a/ctx-test/lib/KeyControls.js +++ /dev/null @@ -1,59 +0,0 @@ -class KeyControls { - constructor() { - this.keys = {}; - // Bind event handlers - document.addEventListener("keydown", e => { - if ([37,38,39,40].indexOf(e.which) >= 0) { - e.preventDefault(); - } - this.keys[e.which] = true; - }, false); - document.addEventListener('keyup', e => { - this.keys[e.which] = false; - }, false); - } - // Handle key actions - get action() { - // Spacebar - return this.keys[32]; - } - - get x () { - // Arrow Left or A (WASD) - if (this.keys[37] || this.keys[65]) { - return -1; - } - // Arrow Right or D (WASD) - if (this.keys[39] || this.keys[68]) { - return 1; - } - return 0; - } - - get y () { - // Arrow Up or W (WASD) - if (this.keys[38] || this.keys[87]) { - return -1; - } - // Arrow Down or S (WASD) - if (this.keys[40] || this.keys[83]) { - return 1; - } - return 0; - } - - key(key, value) { - if (value !== undefined) { - this.keys[key] = value; - } - return this.keys[key]; - } - - reset() { - for (let key in this.keys) { - this.keys[key] = false; - } - } - -} -export default KeyControls; diff --git a/ctx-test/lib/MouseControls.js b/ctx-test/lib/MouseControls.js deleted file mode 100644 index ade1795..0000000 --- a/ctx-test/lib/MouseControls.js +++ /dev/null @@ -1,46 +0,0 @@ -class MouseControls { - constructor(container) { - this.el = container || document.body - // State - this.pos = {x: 0, y: 0}; - this.isDown = false; - this.pressed = false; - this.released = false; - // Handlers - document.addEventListener('mousemove', this.move.bind(this), false); - document.addEventListener('mousedown', this.down.bind(this), false); - document.addEventListener('mouseup', this.up.bind(this), false); - } - - mousePosFromEvent({ clientX, clientY }) { - const { el, pos } = this; - const rect = el.getBoundingClientRect(); - const xr = el.width / el.clientWidth; - const yr = el.height / el.clientHeight; - pos.x = (clientX - rect.left) * xr; - pos.y = (clientY - rect.top) * yr; - } - - move(e) { - this.mousePosFromEvent(e); - } - - down(e) { - this.isDown = true; - this.pressed = true; - this.mousePosFromEvent(e); - } - - up() { - this.isDown = false; - this.released = true; - } - - update() { - this.released = false; - this.pressed = false; - } - - -} -export default MouseControls; diff --git a/ctx-test/package.json b/ctx-test/package.json deleted file mode 100644 index 65687d3..0000000 --- a/ctx-test/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "asdf-ctx-test", - "version": "1.0.0", - "description": "Canvas renderer test", - "main": "index.html", - "directories": { - "lib": "lib" - }, - "scripts": { - "test": "na" - }, - "keywords": [ - "canvas", - "renderer", - "test", - "asdf" - ], - "author": "Arne van Iterson", - "license": "ISC" -} diff --git a/ctx-test/res/images/rc2000.png b/ctx-test/res/images/rc2000.png deleted file mode 100644 index 748dfdb..0000000 Binary files a/ctx-test/res/images/rc2000.png and /dev/null differ diff --git a/ctx-test/res/images/rick.png b/ctx-test/res/images/rick.png deleted file mode 100644 index 3be8d6f..0000000 Binary files a/ctx-test/res/images/rick.png and /dev/null differ diff --git a/ctx-test/res/main.css b/ctx-test/res/main.css deleted file mode 100644 index a127fed..0000000 --- a/ctx-test/res/main.css +++ /dev/null @@ -1,17 +0,0 @@ -body { - background-color: rgba(42, 42, 46, 1); - text-align: center; - - -moz-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; -} -#board { - position: relative; - background-color: #111; - width: 640px; - height: 480px; - margin: auto; - border: 5px solid whitesmoke; -} diff --git a/ctx-test/src/main.js b/ctx-test/src/main.js deleted file mode 100644 index 5bd23c5..0000000 --- a/ctx-test/src/main.js +++ /dev/null @@ -1,34 +0,0 @@ -import asdf from "../../asdf/index.js"; -const { Container, CanvasRenderer, KeyControls, MouseControls, Text, Texture, Sprite } = asdf; - -const canvas = document.querySelector("#board canvas"); -const ctx = canvas.getContext("2d"); -const { width: w, height: h } = canvas; -console.log(canvas); - -// Setup Code - const controls = new KeyControls(); - const mouse = new MouseControls(canvas); - let x = w / 2; - let y = h / 2; - -// Looping Code -function loopme(ms) { - requestAnimationFrame(loopme); - ctx.fillStyle = '#111' - // Game logic code - ctx.save(); - ctx.fillRect(0,0,w,h); - x = mouse.pos.x * 1; - y = mouse.pos.y * 1; - if (mouse.isDown) { - ctx.fillStyle = '#00f' - } else { - ctx.fillStyle = '#f00' - } - ctx.fillRect(x, y, 5, 5); - ctx.fillRect(0, 0, 5, 5); - ctx.restore(); - mouse.update(); -} -requestAnimationFrame(loopme); diff --git a/lib-test/favicon.png b/lib-test/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/lib-test/favicon.png and /dev/null differ diff --git a/lib-test/index.html b/lib-test/index.html deleted file mode 100644 index 99632cd..0000000 --- a/lib-test/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Game - - - -
- -
- - - diff --git a/lib-test/package.json b/lib-test/package.json deleted file mode 100644 index b935148..0000000 --- a/lib-test/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "asdf-lib-test", - "version": "1.0.0", - "description": "Library test", - "main": "index.html", - "directories": { - "lib": "lib" - }, - "scripts": { - "test": "na" - }, - "keywords": [ - "library", - "test", - "asdf" - ], - "author": "Arne van Iterson", - "license": "ISC" -} \ No newline at end of file diff --git a/lib-test/res/images/building.png b/lib-test/res/images/building.png deleted file mode 100644 index 102554d..0000000 Binary files a/lib-test/res/images/building.png and /dev/null differ diff --git a/lib-test/res/images/characters.png b/lib-test/res/images/characters.png deleted file mode 100644 index 432e6c6..0000000 Binary files a/lib-test/res/images/characters.png and /dev/null differ diff --git a/lib-test/res/images/rc2000.png b/lib-test/res/images/rc2000.png deleted file mode 100644 index 748dfdb..0000000 Binary files a/lib-test/res/images/rc2000.png and /dev/null differ diff --git a/lib-test/res/images/rick.png b/lib-test/res/images/rick.png deleted file mode 100644 index 3be8d6f..0000000 Binary files a/lib-test/res/images/rick.png and /dev/null differ diff --git a/lib-test/res/images/spaceship.png b/lib-test/res/images/spaceship.png deleted file mode 100644 index 4b69658..0000000 Binary files a/lib-test/res/images/spaceship.png and /dev/null differ diff --git a/lib-test/res/images/tiles_packed.png b/lib-test/res/images/tiles_packed.png deleted file mode 100644 index ba371cf..0000000 Binary files a/lib-test/res/images/tiles_packed.png and /dev/null differ diff --git a/lib-test/res/main.css b/lib-test/res/main.css deleted file mode 100644 index 9a218f0..0000000 --- a/lib-test/res/main.css +++ /dev/null @@ -1,17 +0,0 @@ -body { - background-color: rgba(42, 42, 46, 1); - text-align: center; - - -moz-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; -} -#board { - position: relative; - background-color: #111; - width: max-content; - height: auto; - margin: auto; - border: 5px solid whitesmoke; -} diff --git a/lib-test/src/main.js b/lib-test/src/main.js deleted file mode 100644 index 423fc2a..0000000 --- a/lib-test/src/main.js +++ /dev/null @@ -1,48 +0,0 @@ -import asdf from "../../asdf/index.js"; -const { Game, Container, CanvasRenderer, math, KeyControls, MouseControls, Text, Texture, Sprite } = asdf; - -const game = new Game(640, 320, false); -const { scene, w, h } = game; - -const buildings = scene.add(new Container()); -const makeRandom = (b, x) => { - b.scale.x = math.randf(1,3); - b.scale.y = math.randf(1,3); - b.pos.x = x; - b.pos.y = h - b.scale.y * 64; -}; - -for (let x = 0; x < 50; x++) { - const b = buildings.add(new Sprite(new Texture("res/images/building.png"))); - makeRandom(b, math.rand(w)); -} - -var rotation = 0; -const ship = new Sprite(new Texture("res/images/spaceship.png")); -ship.pivot = { x: 16, y: 16 }; -scene.add(ship); - - -game.run((dt ,t) => { - ship.update = function(dt, t) { - const {scale} = this; - scale.x = Math.abs(Math.sin(t)) + 1; - scale.y = Math.abs(Math.sin(t)) + 1; - - rotation = rotation + 0.2; - ship.rotation = rotation; - - ship.pos.y = (Math.abs(Math.sin(t))) * 50 + (h / 2) - 16; - ship.pos.x += dt * 50; - if (ship.pos.x > w) { - ship.pos.x = -32; - } - } - - buildings.map(b => { - b.pos.x -= 100 * dt; - if (b.pos.x < -80) { - makeRandom(b,w); - } - }); -}); diff --git a/other/favicon.png b/other/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/other/favicon.png and /dev/null differ diff --git a/other/raindrops/favicon.png b/other/raindrops/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/other/raindrops/favicon.png and /dev/null differ diff --git a/other/raindrops/index.html b/other/raindrops/index.html deleted file mode 100644 index 16a6e72..0000000 --- a/other/raindrops/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Game - - - -
- -
- - - diff --git a/other/raindrops/package.json b/other/raindrops/package.json deleted file mode 100644 index 0b31f98..0000000 --- a/other/raindrops/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "game", - "version": "1.0.0", - "description": "My first game", - "main": "index.html", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Arne van Iterson", - "license": "ISC" -} diff --git a/other/raindrops/res/images/rc2000.png b/other/raindrops/res/images/rc2000.png deleted file mode 100644 index 748dfdb..0000000 Binary files a/other/raindrops/res/images/rc2000.png and /dev/null differ diff --git a/other/raindrops/res/images/rick.png b/other/raindrops/res/images/rick.png deleted file mode 100644 index 3be8d6f..0000000 Binary files a/other/raindrops/res/images/rick.png and /dev/null differ diff --git a/other/raindrops/res/main.css b/other/raindrops/res/main.css deleted file mode 100644 index a127fed..0000000 --- a/other/raindrops/res/main.css +++ /dev/null @@ -1,17 +0,0 @@ -body { - background-color: rgba(42, 42, 46, 1); - text-align: center; - - -moz-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; -} -#board { - position: relative; - background-color: #111; - width: 640px; - height: 480px; - margin: auto; - border: 5px solid whitesmoke; -} diff --git a/other/raindrops/src/main.js b/other/raindrops/src/main.js deleted file mode 100644 index c57a2a9..0000000 --- a/other/raindrops/src/main.js +++ /dev/null @@ -1,30 +0,0 @@ -const canvas = document.querySelector("#board canvas"); -const ctx = canvas.getContext("2d"); -const { width: w, height: h } = canvas; -const center = w / 2; - -// Setup Code - ctx.fillStyle = '#000'; - ctx.globalAlpha = 0.02; - -// Looping Code -function loopme(t) { - requestAnimationFrame(loopme); - - // Logic Code - ctx.save(); - ctx.fillRect(0,0,w,h); - ctx.fillStyle = '#fff'; - ctx.globalAlpha = 1; - - const x = Math.random() * w; - const y = Math.random() * h; - const radius = Math.random() * 10; - - ctx.beginPath(); - ctx.arc(x,y,radius,0,Math.PI * 2) - ctx.fill(); - ctx.restore(); - -} -requestAnimationFrame(loopme); diff --git a/other/snowflakes/index.html b/other/snowflakes/index.html deleted file mode 100644 index 8bc4f73..0000000 --- a/other/snowflakes/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - Game - - - -
- -
- - - diff --git a/other/snowflakes/package.json b/other/snowflakes/package.json deleted file mode 100644 index 0b31f98..0000000 --- a/other/snowflakes/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "game", - "version": "1.0.0", - "description": "My first game", - "main": "index.html", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Arne van Iterson", - "license": "ISC" -} diff --git a/other/snowflakes/res/images/rick.png b/other/snowflakes/res/images/rick.png deleted file mode 100644 index 3be8d6f..0000000 Binary files a/other/snowflakes/res/images/rick.png and /dev/null differ diff --git a/other/snowflakes/res/images/snowflake.png b/other/snowflakes/res/images/snowflake.png deleted file mode 100644 index 4f7c7a7..0000000 Binary files a/other/snowflakes/res/images/snowflake.png and /dev/null differ diff --git a/other/snowflakes/res/main.css b/other/snowflakes/res/main.css deleted file mode 100644 index 4b43f8d..0000000 --- a/other/snowflakes/res/main.css +++ /dev/null @@ -1,10 +0,0 @@ -body { - /* font-family: "Visitor", sans-serif; */ - background-color: rgba(42, 42, 46, 1); -} -#board { - width: 640px; - height: 480px; - margin: auto; - background-color: white; -} diff --git a/other/snowflakes/res/visitor1.ttf b/other/snowflakes/res/visitor1.ttf deleted file mode 100644 index 04ce123..0000000 Binary files a/other/snowflakes/res/visitor1.ttf and /dev/null differ diff --git a/other/snowflakes/src/main.js b/other/snowflakes/src/main.js deleted file mode 100644 index 094b39e..0000000 --- a/other/snowflakes/src/main.js +++ /dev/null @@ -1,23 +0,0 @@ -const canvas = document.querySelector("#board canvas"); -const ctx = canvas.getContext("2d"); -const { width: w, height: h } = canvas; -const center = w / 2; - -ctx.fillStyle = "#111"; -ctx.fillRect(0, 0, w, h); - -const img = new Image(); -img.src = "res/images/snowflake.png"; -img.addEventListener("load", draw, false); - -function draw() { - const { width, height } = img; - - for (let i = 0; i < 100; i++) { - const x = Math.random() * w; - const y = Math.random() * h; - const scale = Math.random(); - - ctx.drawImage(img, x, y, width * scale, height * scale); - } -} diff --git a/other/stars/favicon.png b/other/stars/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/other/stars/favicon.png and /dev/null differ diff --git a/other/stars/index.html b/other/stars/index.html deleted file mode 100644 index 16a6e72..0000000 --- a/other/stars/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Game - - - -
- -
- - - diff --git a/other/stars/package.json b/other/stars/package.json deleted file mode 100644 index 0b31f98..0000000 --- a/other/stars/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "game", - "version": "1.0.0", - "description": "My first game", - "main": "index.html", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Arne van Iterson", - "license": "ISC" -} diff --git a/other/stars/res/main.css b/other/stars/res/main.css deleted file mode 100644 index e93a318..0000000 --- a/other/stars/res/main.css +++ /dev/null @@ -1,14 +0,0 @@ -@font-face { - font-family: 'Visitor'; - src: URL('/data/visitor1.ttf') format('truetype'); -} -body { - /* font-family: "Visitor", sans-serif; */ - background-color: rgba(42, 42, 46, 1); -} -#board { - width: 640px; - height: 480px; - margin: auto; - background-color: white; -} diff --git a/other/stars/src/main.js b/other/stars/src/main.js deleted file mode 100644 index 831d65f..0000000 --- a/other/stars/src/main.js +++ /dev/null @@ -1,17 +0,0 @@ -const canvas = document.querySelector("#board canvas"); -const ctx = canvas.getContext("2d"); -const { width: w, height: h } = canvas; -ctx.fillStyle = "black"; -ctx.fillRect(0, 0, w, h); -ctx.fillStyle = "#555"; - -let x, y, radius; - -for (let i = 0; i < 550; i++) { - x = Math.random() * w; - y = Math.random() * h; - radius = Math.random() * 3; - ctx.beginPath(); - ctx.arc(x, y, radius, 0, Math.PI*2, false); - ctx.fill(); -} diff --git a/other/text/favicon.png b/other/text/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/other/text/favicon.png and /dev/null differ diff --git a/other/text/index.html b/other/text/index.html deleted file mode 100644 index 8bc4f73..0000000 --- a/other/text/index.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - Game - - - -
- -
- - - diff --git a/other/text/package.json b/other/text/package.json deleted file mode 100644 index 0b31f98..0000000 --- a/other/text/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "game", - "version": "1.0.0", - "description": "My first game", - "main": "index.html", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "author": "Arne van Iterson", - "license": "ISC" -} diff --git a/other/text/res/main.css b/other/text/res/main.css deleted file mode 100644 index 4b43f8d..0000000 --- a/other/text/res/main.css +++ /dev/null @@ -1,10 +0,0 @@ -body { - /* font-family: "Visitor", sans-serif; */ - background-color: rgba(42, 42, 46, 1); -} -#board { - width: 640px; - height: 480px; - margin: auto; - background-color: white; -} diff --git a/other/text/res/visitor1.ttf b/other/text/res/visitor1.ttf deleted file mode 100644 index 04ce123..0000000 Binary files a/other/text/res/visitor1.ttf and /dev/null differ diff --git a/other/text/src/main.js b/other/text/src/main.js deleted file mode 100644 index 5a0f875..0000000 --- a/other/text/src/main.js +++ /dev/null @@ -1,30 +0,0 @@ -const canvas = document.querySelector("#board canvas"); -const ctx = canvas.getContext("2d"); -const { width: w, height: h } = canvas; -const center = w / 2; -ctx.fillStyle = "black"; -ctx.font = "20px Visitor"; -ctx.textAlign = "left"; - -function printText(str, l) { - var words = str.split(" "); - var text = ""; - var line = 1; - for (var i = 0; i < words.length; i++) { - console.log(words[i]); - if ((text.split("").length + words[i].split("").length + 1) <= l * line) { - text = text + `${words[i]}`; - if (words[i + 1] != undefined) { - if ((text.split("").length + words[i + 1].split("").length + 1) <= l * line) { - text = text + ` `; - } - } - } else { - text = text + "\n" + `${words[i]}` + " "; - line++; - } - } - console.log(text); -} - -printText("Oh really, are you going to tell me this function is going to cut of the words very awkwardly?", 32); diff --git a/rc2000/favicon.png b/rc2000/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/rc2000/favicon.png and /dev/null differ diff --git a/rc2000/index.html b/rc2000/index.html deleted file mode 100644 index 919c130..0000000 --- a/rc2000/index.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - Game - - - -
- -
-

Rick Clicker 2000. Rick the clicks! - - - diff --git a/rc2000/package.json b/rc2000/package.json deleted file mode 100644 index 4d4bd1b..0000000 --- a/rc2000/package.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "name": "rc2000", - "version": "1.0.0", - "description": "Rick Clicker 2000", - "main": "index.html", - "directories": { - "lib": "lib" - }, - "scripts": { - "test": "na" - }, - "keywords": [ - "DOM", - "Rick Ashley", - "Clicker", - "Game" - ], - "author": "Arne van Iterson", - "license": "ISC" -} \ No newline at end of file diff --git a/rc2000/res/images/rc2000.png b/rc2000/res/images/rc2000.png deleted file mode 100644 index 748dfdb..0000000 Binary files a/rc2000/res/images/rc2000.png and /dev/null differ diff --git a/rc2000/res/images/rick.png b/rc2000/res/images/rick.png deleted file mode 100644 index 3be8d6f..0000000 Binary files a/rc2000/res/images/rick.png and /dev/null differ diff --git a/rc2000/res/main.css b/rc2000/res/main.css deleted file mode 100644 index a39c175..0000000 --- a/rc2000/res/main.css +++ /dev/null @@ -1,28 +0,0 @@ -@font-face { - font-family: 'Visitor'; - src: URL('/data/visitor1.ttf') format('truetype'); -} -body { - font-family: "Visitor", sans-serif; - background-color: rgba(42, 42, 46, 1); - text-align: center; - - -moz-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; -} -#board { - position: relative; - background-color: #8CD; - width: 640px; - height: 480px; - margin: auto; - - background-image: url('images/rc2000.png'); - background-repeat: no-repeat; - background-position: center center; - - border: 5px solid whitesmoke; - border-radius: 8px; -} diff --git a/rc2000/src/main.js b/rc2000/src/main.js deleted file mode 100644 index 50b721a..0000000 --- a/rc2000/src/main.js +++ /dev/null @@ -1,39 +0,0 @@ -let clickers = 50; -let startTime = Date.now(); - -function sync(dom, pos) { - dom.style.left = `${pos.x}px`, - dom.style.top = `${pos.y}px` -}; - -function addClicker() { - const pos = { - x: Math.random() * 500, - y: Math.random() * 300 - }; - const img = new Image(); - img.src = "res/images/rick.png"; - img.style.position = "absolute"; - img.addEventListener("click", removeClicker, false); - - document.querySelector("#board").appendChild(img); - sync(img, pos); -}; - -function removeClicker(e) { - e.target.parentNode.removeChild(e.target); - clickers--; - checkGameOver(); -}; - -function checkGameOver() { - document.querySelector("#remain").innerHTML = clickers; - if (clickers === 0) { - const taken = Math.round((Date.now() - startTime) / 1000) - alert(`De-rick-ed in ${taken} seconds!`) - } -}; - -for (let i = 0; i < clickers; i++) { - addClicker(); -}; diff --git a/shooter/favicon.png b/shooter/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/shooter/favicon.png and /dev/null differ diff --git a/shooter/index.html b/shooter/index.html deleted file mode 100644 index 34330e1..0000000 --- a/shooter/index.html +++ /dev/null @@ -1,20 +0,0 @@ - - - - Game - - - -

SPACEMANIA 2000
-
- -
-
- W
ASD
- Move -
_
- Shoot -
- - - diff --git a/shooter/package.json b/shooter/package.json deleted file mode 100644 index 2d0b66b..0000000 --- a/shooter/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "asdf-shooter", - "version": "1.0.0", - "description": "Spacemania 2000 Shooter Game", - "main": "index.html", - "directories": { - "lib": "lib" - }, - "scripts": { - "test": "na" - }, - "keywords": [ - "shooter", - "spacemania", - "2000", - "game", - "asdf" - ], - "author": "Arne van Iterson", - "license": "ISC" -} \ No newline at end of file diff --git a/shooter/res/fonts/Keycaps Regular.ttf b/shooter/res/fonts/Keycaps Regular.ttf deleted file mode 100644 index 36c5e85..0000000 Binary files a/shooter/res/fonts/Keycaps Regular.ttf and /dev/null differ diff --git a/shooter/res/fonts/keycaps.TTF b/shooter/res/fonts/keycaps.TTF deleted file mode 100644 index cb0f274..0000000 Binary files a/shooter/res/fonts/keycaps.TTF and /dev/null differ diff --git a/shooter/res/fonts/visitor1.ttf b/shooter/res/fonts/visitor1.ttf deleted file mode 100644 index 04ce123..0000000 Binary files a/shooter/res/fonts/visitor1.ttf and /dev/null differ diff --git a/shooter/res/images/baddie.png b/shooter/res/images/baddie.png deleted file mode 100644 index 4fbd753..0000000 Binary files a/shooter/res/images/baddie.png and /dev/null differ diff --git a/shooter/res/images/bg.png b/shooter/res/images/bg.png deleted file mode 100644 index 22b1c9e..0000000 Binary files a/shooter/res/images/bg.png and /dev/null differ diff --git a/shooter/res/images/bullet.png b/shooter/res/images/bullet.png deleted file mode 100644 index 78a7026..0000000 Binary files a/shooter/res/images/bullet.png and /dev/null differ diff --git a/shooter/res/images/spaceship.png b/shooter/res/images/spaceship.png deleted file mode 100644 index 4b69658..0000000 Binary files a/shooter/res/images/spaceship.png and /dev/null differ diff --git a/shooter/res/main.css b/shooter/res/main.css deleted file mode 100644 index ef11a6d..0000000 --- a/shooter/res/main.css +++ /dev/null @@ -1,56 +0,0 @@ -@font-face { - font-family: "Visitor"; - font-style: normal; - src: url("./fonts/visitor1.ttf") format("truetype"); -} -@font-face { - font-family: "KeyCaps"; - font-style: normal; - src: url("./fonts/keycaps.TTF") format("truetype"); -} -.title { - font-family: "Visitor"; - font-size: 40px; - color: white; -} -body { - background-color: rgba(42, 42, 46, 1); - text-align: center; - - -moz-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; -} -#board { - position: relative; - background-color: #111; - width: 640px; - height: auto; - margin: auto; - border: 5px solid whitesmoke; -} -.controls_container { - padding: 20px; - color: white; - text-align: center; - display: grid; - grid-template-areas: - 'control_1 control_2' - 'control_def_1 control_def_2'; - grid-gap: 10px; - width: 300px; - left: calc(50% - 160px); - position: absolute; -} -.control { - font-family: "KeyCaps"; - font-size: 33px; - display: inline-block; - vertical-align: middle; - width: 150px; -} -.control_definition { - font-family: "Visitor"; - width: 150px; -} diff --git a/shooter/src/main.js b/shooter/src/main.js deleted file mode 100644 index 453742d..0000000 --- a/shooter/src/main.js +++ /dev/null @@ -1,178 +0,0 @@ -import asdf from "../../asdf/index.js"; -const { Container, CanvasRenderer, KeyControls, MouseControls, Text, Texture, Sprite } = asdf; - -// Board Setup - const w = 640; - const h = 300; - const renderer = new CanvasRenderer(w, h); - document.querySelector("#board").appendChild(renderer.view); - -// Setup game variables - let dt = 0; - let last = 0; - let lastShot = 0; - let lastSpawn = 0; - let spawnSpeed = 1.0; - let scoreAmount = 0; - let gameOver = false; - -// Setup game objects - const scene = new Container(); - -// Load game textures - const textures = { - background: new Texture("./res/images/bg.png"), - spaceship: new Texture("./res/images/spaceship.png"), - bullet: new Texture("./res/images/bullet.png"), - baddie: new Texture("./res/images/baddie.png") - } - -// Spaceship - const controls = new KeyControls(); - const ship = new Sprite(textures.spaceship); - ship.pos.x = 120; - ship.pos.y = h / 2 - 16; - ship.update = function(dt, t) { - const { pos } = this; - pos.x += controls.x * dt * 300; - pos.y += controls.y * dt * 300; - - if (pos.x < 0) pos.x = 0; - if (pos.x > w - 32) pos.x = w - 32; - if (pos.y < 0) pos.y = 0; - if (pos.y > h - 32) pos.y = h - 32; - } - -// Bullets - const bullets = new Container(); - function fireBullet(x, y) { - const bullet = new Sprite(textures.bullet); - bullet.pos.x = x; - bullet.pos.y = y; - bullet.update = function(dt, t) { - bullet.pos.x += 400 * dt; - } - bullets.add(bullet); - } - -// Bad guys - const baddies = new Container(); - function spawnBaddie(x, y, speed) { - const baddie = new Sprite(textures.baddie); - baddie.pos.x = x; - baddie.pos.y = y; - baddie.update = function(dt) { - this.pos.x += speed * dt; - this.pos.y += Math.sin(this.pos.x / 15) * 1; - }; - baddies.add(baddie); - } - -// Show score - const score = new Text(`${scoreAmount}`, { - font: "15pt Visitor", - fill: "#000000", - align: "left" - }); - score.pos.x = 50; - score.pos.y = 15; - score.update = function() { - if (gameOver) { - score.pos.x = w / 2; - score.pos.y = (h / 3) * 2; - score.text = `Score: ` + `${scoreAmount}`; - score.style.align = "center"; - score.style.font = "24pt Visitor" - } else { - score.text = `${scoreAmount}`; - } - } - -// Gameover - function doGameOver() { - const gameOverMessage = new Text(`Game Over`, { - font: "45pt Visitor", - fill: "#000000", - align: "center" - }); - gameOverMessage.pos.x = w / 2; - gameOverMessage.pos.y = h / 3; - - scene.add(gameOverMessage); - scene.remove(ship); - scene.remove(baddies); - scene.remove(bullets); - gameOver = true; - } - -// Add game objects - scene.add(new Sprite(textures.background)); - scene.add(ship); - scene.add(bullets); - scene.add(baddies); - scene.add(score); - - -// Looping Code -function loopme(ms) { - requestAnimationFrame(loopme); - const t = ms / 1000; - dt = t - last; - last = t; - - // Game logic code - if (controls.action && t - lastShot > 0.15) { - lastShot = t; - fireBullet(ship.pos.x + 24, ship.pos.y + 10); - } - - // Spawn bad guys - if (t - lastSpawn > spawnSpeed) { - lastSpawn = t; - const speed = -50 - (Math.random() * Math.random() * 100); - const position = Math.random() * (h - 24); - spawnBaddie(w, position, speed); - - spawnSpeed = spawnSpeed < 0.05 ? 0.6 : spawnSpeed * 0.97 + 0.001; - } - - // Destroy bullets when they go out of the screen - baddies.children.forEach(baddie => { - bullets.children.forEach(bullet => { - let dx_b = baddie.pos.x + 16 - (bullet.pos.x + 8); - let dy_b = baddie.pos.y + 16 - (bullet.pos.y + 8); - if (Math.sqrt(dx_b * dx_b + dy_b * dy_b) < 24) { - bullet.dead = true; - baddie.dead = true; - if (!gameOver) { - scoreAmount += Math.floor(t); - } - } - - if (bullet.pos.x > w + 20) { - bullet.dead = true; - } - }); - let dx_s = baddie.pos.x + 16 - (ship.pos.x + 16) - let dy_s = baddie.pos.y + 16 - (ship.pos.y + 16) - if (Math.sqrt(dx_s * dx_s + dy_s * dy_s) < 32) { - if (!gameOver) { - doGameOver(); - } - baddie.dead = true; - } - - if (baddie.pos.x < -32) { - if (!gameOver) { - doGameOver(); - } - baddie.dead = true; - } - }); - - - - scene.update(dt, t); - renderer.render(scene); -} -requestAnimationFrame(loopme); diff --git a/tile-test/entities/King.js b/tile-test/entities/King.js deleted file mode 100644 index 180762c..0000000 --- a/tile-test/entities/King.js +++ /dev/null @@ -1,41 +0,0 @@ -import asdf from "../../asdf/index.js"; -const { TileSprite, Texture, math } = asdf; -const texture = new Texture("./res/images/characters.png"); - -class King extends TileSprite { - constructor () { - super(texture, 32, 32); - this.scale = { x: 2, y: 2 }; - - this.rate = 0.1; - this.frames = [ - { x: 0, y: 1 }, - { x: 1, y: 1 }, - { x: 2, y: 1 }, - { x: 3, y: 1 } - ]; - this.curTime = 0; - this.curFrame = math.rand(0, this.frames.length); - this.frame = this.frames[this.curFrame]; - - this.speed = math.rand(20, 100) - this.pos.y = math.rand(-16, 304); - this.pos.x = math.rand(-32, 640); - } - update (dt, t) { - const { rate, frames } = this; - this.curTime += dt; - if (this.curTime > rate) { - this.frame = frames[this.curFrame++ % frames.length]; - this.curTime -= rate; - } - - this.pos.x += (dt * this.speed); - if (this.pos.x > 640 + 32) { - this.pos.y = math.rand(-16, 304); - this.pos.x = -32; - } - } -} - -export default King; \ No newline at end of file diff --git a/tile-test/entities/Snake.js b/tile-test/entities/Snake.js deleted file mode 100644 index 22cb957..0000000 --- a/tile-test/entities/Snake.js +++ /dev/null @@ -1,41 +0,0 @@ -import asdf from "../../asdf/index.js"; -const { TileSprite, Texture, math } = asdf; -const texture = new Texture("./res/images/characters.png"); - -class Snake extends TileSprite { - constructor () { - super(texture, 32, 32); - this.scale = { x: 2, y: 2 }; - - this.rate = 0.1; - this.curTime = 0; - this.curFrame = 0; - this.frames = [ - { x: 0, y: 3 }, - { x: 1, y: 3 }, - { x: 2, y: 3 }, - { x: 3, y: 3 } - ]; - this.frame = this.frames[this.curFrame]; - - this.speed = math.rand(50, 100) - this.pos.y = math.rand(0, 320); - this.pos.x = math.rand(-32, 320); - } - update (dt, t) { - const { rate, frames } = this; - this.curTime += dt; - if (this.curTime > rate) { - this.frame = frames[this.curFrame++ % frames.length]; - this.curTime -= rate; - } - - this.pos.x += (dt * this.speed); - if (this.pos.x > 640 + 32) { - this.pos.y = math.rand(-16, 304); - this.pos.x = -32; - } - } -} - -export default Snake; \ No newline at end of file diff --git a/tile-test/favicon.png b/tile-test/favicon.png deleted file mode 100644 index b353a1c..0000000 Binary files a/tile-test/favicon.png and /dev/null differ diff --git a/tile-test/index.html b/tile-test/index.html deleted file mode 100644 index 99632cd..0000000 --- a/tile-test/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - Game - - - -
- -
- - - diff --git a/tile-test/package.json b/tile-test/package.json deleted file mode 100644 index 2ec5fe9..0000000 --- a/tile-test/package.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "asdf-tile-test", - "version": "1.0.0", - "description": "Spritesheet test", - "main": "index.html", - "directories": { - "lib": "lib" - }, - "scripts": { - "test": "na" - }, - "keywords": [ - "spritesheet", - "opengameart", - "tile", - "test", - "asdf" - ], - "author": "Arne van Iterson", - "license": "ISC" -} \ No newline at end of file diff --git a/tile-test/res/images/building.png b/tile-test/res/images/building.png deleted file mode 100644 index 102554d..0000000 Binary files a/tile-test/res/images/building.png and /dev/null differ diff --git a/tile-test/res/images/characters.png b/tile-test/res/images/characters.png deleted file mode 100644 index 432e6c6..0000000 Binary files a/tile-test/res/images/characters.png and /dev/null differ diff --git a/tile-test/res/images/rc2000.png b/tile-test/res/images/rc2000.png deleted file mode 100644 index 748dfdb..0000000 Binary files a/tile-test/res/images/rc2000.png and /dev/null differ diff --git a/tile-test/res/images/rick.png b/tile-test/res/images/rick.png deleted file mode 100644 index 3be8d6f..0000000 Binary files a/tile-test/res/images/rick.png and /dev/null differ diff --git a/tile-test/res/images/spaceship.png b/tile-test/res/images/spaceship.png deleted file mode 100644 index 4b69658..0000000 Binary files a/tile-test/res/images/spaceship.png and /dev/null differ diff --git a/tile-test/res/images/tiles_packed.png b/tile-test/res/images/tiles_packed.png deleted file mode 100644 index ba371cf..0000000 Binary files a/tile-test/res/images/tiles_packed.png and /dev/null differ diff --git a/tile-test/res/main.css b/tile-test/res/main.css deleted file mode 100644 index 9a218f0..0000000 --- a/tile-test/res/main.css +++ /dev/null @@ -1,17 +0,0 @@ -body { - background-color: rgba(42, 42, 46, 1); - text-align: center; - - -moz-user-select: none; - -webkit-user-select: none; - -ms-user-select: none; - user-select: none; -} -#board { - position: relative; - background-color: #111; - width: max-content; - height: auto; - margin: auto; - border: 5px solid whitesmoke; -} diff --git a/tile-test/src/main.js b/tile-test/src/main.js deleted file mode 100644 index b86719a..0000000 --- a/tile-test/src/main.js +++ /dev/null @@ -1,22 +0,0 @@ -import asdf from "../../asdf/index.js"; -const { Game, Container, CanvasRenderer, math, KeyControls, MouseControls, Text, Texture, Sprite, TileSprite } = asdf; - -const game = new Game(640, 320, true); -const { scene, w, h } = game; - -import King from "../entities/King.js"; -import Snake from "../entities/Snake.js"; - -scene.add(new Snake()); - -for (let index = 0; index < 250; index++) { - scene.add(new King()); -} - -const mouseAim = new MouseControls(); - -game.run((dt ,t) => { - if (mouseAim.isDown) { - console.log('cliccccccccccc'); - } -});