diff --git a/css/index.css b/css/index.css
new file mode 100644
index 0000000..b514637
--- /dev/null
+++ b/css/index.css
@@ -0,0 +1,5 @@
+html, body {
+ margin: 0;
+ padding: 0;
+ overflow: hidden;
+}
\ No newline at end of file
diff --git a/index.html b/index.html
index 476f894..9ebef7c 100644
--- a/index.html
+++ b/index.html
@@ -3,6 +3,7 @@
+
Game
diff --git a/main.js b/main.js
index 19d3c86..c9c9e78 100644
--- a/main.js
+++ b/main.js
@@ -1,4 +1,4 @@
-const { app, BrowserWindow } = require('electron')
+const { app, BrowserWindow, ipcMain } = require('electron')
const path = require('path')
function createWindow () {
@@ -6,10 +6,20 @@ function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
+ backgroundColor: '#111',
+ resizable: false,
+ frame: true,
webPreferences: {
nodeIntegration: true
}
- })
+ });
+
+ ipcMain.on('resize', function (event, window) {
+ win.setSize( window.w, window.h);
+ });
+
+ // Remove alt menu
+ win.removeMenu();
// and load the index.html of the app.
win.loadFile(path.join('index.html'))
diff --git a/res/placeholder.png b/res/placeholder.png
new file mode 100644
index 0000000..506387a
Binary files /dev/null and b/res/placeholder.png differ
diff --git a/src/entities/player.js b/src/entities/player.js
index 3ff6bcd..456de15 100644
--- a/src/entities/player.js
+++ b/src/entities/player.js
@@ -4,9 +4,11 @@ const { math, KeyControls, Texture, Sprite, TileSprite } = asdf;
var texture = new Texture('./res/player.png');
class Player extends TileSprite {
- constructor(keys) {
+ constructor(keys, window) {
super(texture, 24, 24);
- this.scale = { x: 3, y: 3 };
+ this.scale = { x: 2, y: 2 };
+
+ this.window = window;
// Rate walking = 0.4
// Rate running = 0.08
@@ -23,11 +25,12 @@ class Player extends TileSprite {
this.curFrame = 0;
this.frame = this.frames[this.curFrame];
- this.pos.x = (640 / 2) - (24 * this.scale.x / 2);
- this.pos.y = (320 / 2) - (24 * this.scale.y / 2);
+ this.pos.x = (this.window.w / 2) - (24 * this.scale.x / 2);
+ this.pos.y = (this.window.h / 2) - (24 * this.scale.y / 2);
this.keys = keys;
}
+
update(dt, t) {
const { rate, frames } = this;
this.curTime += dt;
diff --git a/src/index.js b/src/index.js
index 9bf382d..4d12c34 100644
--- a/src/index.js
+++ b/src/index.js
@@ -1,19 +1,32 @@
+const { ipcRenderer } = require('electron')
+
var asdf = require('asdf-games');
const { Game, Container, math, KeyControls, MouseControls, Text, Texture, TileMap, Sprite, TileSprite } = asdf;
-const game = new Game(640, 320, true);
+const window = { w: 640, h: 320 };
+
+const game = new Game(window.w, window.h, true);
+ipcRenderer.send('resize', window);
+
const { scene, w, h } = game;
+var Player = require("./src/entities/player.js")
+var Level = require("./src/levels/level.js")
+
const mouseAim = new MouseControls();
const keys = new KeyControls();
-var Player = require("./src/entities/player.js")
-var player = new Player(keys);
+var player = new Player(keys, window);
+var level = new Level(window, keys, player);
+scene.add(level);
scene.add(player);
game.run((dt ,t) => {
if (mouseAim.isDown) {
console.log('cliccccccccccc');
}
+
+ // Check gamestate
+ // TODO
});
\ No newline at end of file
diff --git a/src/levels/level.js b/src/levels/level.js
new file mode 100644
index 0000000..f34a062
--- /dev/null
+++ b/src/levels/level.js
@@ -0,0 +1,44 @@
+var asdf = require("asdf-games");
+const { math, KeyControls, Texture, Sprite, TileSprite, TileMap } = asdf;
+
+const texture = new Texture('./res/placeholder.png');
+
+const levelSize = { w: 640, h: 320 };
+var levelData = [];
+
+for (let index = 0; index < ((levelSize.w / 32) * (levelSize.h / 32)); index++) {
+ levelData.push({ x: 0, y: 0 });
+}
+
+class Level extends TileMap {
+ constructor (window, keys, player) {
+ super(levelData, levelSize.w / 32, levelSize.h / 32, 32, 32, texture);
+ this.pos.x = (window.w / 2) - (levelSize.w / 2);
+ this.pos.y = (window.h / 2) - (levelSize.h / 2);
+
+ this.keys = keys;
+ this.player = player
+ }
+
+ update(dt, t) {
+ // Change walking direction
+ if (this.keys.x == -1) {
+ // Left
+ this.pos.x = this.pos.x + dt * (1 / this.player.rate) * 10;
+ }
+ if (this.keys.x == 1) {
+ // Right
+ this.pos.x = this.pos.x - dt * (1 / this.player.rate) * 10;
+ }
+ if (this.keys.y == -1) {
+ // Down
+ this.pos.y = this.pos.y + dt * (1 / this.player.rate) * 10;
+ }
+ if (this.keys.y == 1) {
+ // Up
+ this.pos.y = this.pos.y - dt * (1 / this.player.rate) * 10;
+ }
+ }
+}
+
+module.exports = Level;
\ No newline at end of file