diff --git a/Assets/Sheet.xcf b/Assets/Sheet.xcf index 2a0f138..a2aa245 100644 Binary files a/Assets/Sheet.xcf and b/Assets/Sheet.xcf differ diff --git a/TODO.md b/TODO.md new file mode 100644 index 0000000..f22a8c0 --- /dev/null +++ b/TODO.md @@ -0,0 +1,42 @@ +# Project To Do list + +## Short Term + - [] Kill socket when browser closes/inactive. + - [] Make client get textures from single sprite sheet + +## Mid Term + - [] Implement Rooms with different games on server + - [] Add room selection menu on client + - [] Implement Players + - [] Player Names + - [] Player Colors + - [] Prevent Duplicate player info +## Long Term + - [] Power and money system for players + - [] Add land ownership + - [] Land Claiming + - [] Difficulty to claim hills and seas + - [] Create bouy flag sprite + - [] Make differentiation between land owned by different players + - [] System to have animated widgets overtop of the canvas. + - [] Explosion + - [] Selection cursor + - [] Color for different land status (claimed/open/unclaimable) + - [] Create spites for classes of buildings for economy. + - [x] Factory + - [x] Farmland/town + - [] Fishing area + - [] Building selection menu +## Longer Term + + - [] Add tests to ensure features act as they should + - [] Handle player death/leaving + - [] Dead player's resources go to killer with some tax. + - [] Leaving player's resources go to player +## Finishing Touches + - [] Sounds + - [] Graphics Redo + - [] Fancy webpage decorations + +## Maybe + - [] Chat diff --git a/index.js b/index.js index bba5be2..f55f727 100644 --- a/index.js +++ b/index.js @@ -1,9 +1,61 @@ -var noise = require('noisejs'); -var express = require('express'); +var express = require('express'); +const worldgen = require("./worldgen.js") +const util = require("./util.js") const gridSize = [18, 18]; const perlinScale = 3; -var world = generateWorld(); + +class Player { + constructor(id, color) { + this.id = id; + this.color = color; + } +} + +class Game { + constructor() { + this.players = []; + this.world = worldgen.generateWorld(gridSize, perlinScale); + } + + addPlayer(id) { + var color + switch(util.randomNumber(1,4)) { + case 1: + color = "red"; + break; + + case 2: + color = "aquamarine"; + break; + + case 3: + color = "green"; + break; + + case 4: + color = "yellow"; + break; + } + const player = new Player(id, color); + this.players.push(player); + } + + removePlayer(id) { + this.players = this.players.filter(obj => obj.id != id); + console.log("removed player - " + id) + } + + getPlayerByID(id) { + console.log(this.players) + console.log(id) + const player = this.players.filter(obj => obj.id == id)[0] + return player + } + +} +var game = new Game(); + var app = express() //Static resources server app.use(express.static(__dirname + '/www/'));var server = app.listen(8082, function () { @@ -14,66 +66,36 @@ app.use(express.static(__dirname + '/www/'));var server = app.listen(8082, funct var io = require('socket.io')(server);/* Connection events */ io.on('connection', function(client) { console.log('User connected'); - client.on('joinGame', function(tank){ - console.log(client.id + ' joined the game'); - // client.emit('addTank', { id: tank.id, type: tank.type, isLocal: true, x: initX, y: initY, hp: TANK_INIT_HP }); - // client.broadcast.emit('addTank', { id: tank.id, type: tank.type, isLocal: false, x: initX, y: initY, hp: TANK_INIT_HP} ); - // game.addTank({ id: tank.id, type: tank.type, hp: TANK_INIT_HP}); - client.emit('gameVars', {gridSize: gridSize, world: world}) + client.on('disconnect', function(){ + console.log(client.id + ' disconnected.') + game.removePlayer(client.id) + client.broadcast.emit('playerList', game.players) + }) + + client.on('joinGame', function(tank){ + game.addPlayer(client.id); + console.log(client.id + ' joined the game'); + client.emit('gameVars', {gridSize: gridSize, world: game.world}) + client.broadcast.emit('playerList', game.players) + client.emit('playerList', game.players) + }) + client.on('leaveGame', function(tank){ + console.log(client.id + ' disconnected.') + game.removePlayer(client.id) + client.broadcast.emit('playerList', game.players) }) client.on('clickCanvas', function(data){ const xu = data.tilePosition[0] const yu = data.tilePosition[1] - world[xu][yu].structure = data.structure - client.broadcast.emit('sync',{world: world}) - client.emit('sync',{world: world}) + game.world[xu][yu].structure = data.structure + game.world[xu][yu].owner = game.getPlayerByID(client.id).color; + // console.log(world[xu][yu].owner = game.getPlayerbyID(client.id)) + + client.broadcast.emit('sync',{world: game.world}) + client.emit('sync',{world: game.world}) }) }); - - - - - function randomNumber(min, max) { - return Math.floor(Math.random() * (max - min) + min); - } - - function generateWorld(){ - let x, y = 0 - - let tempWorld = Array.from(Array(gridSize[0]), () => new Array(gridSize[1])); - for (x = 0; x < gridSize[0]; x++){ - for (y = 0; y < gridSize[1]; y++){ - tempWorld[x][y] = {type: 0, structure: 0} - } - } - - noise.seed(Math.random()) - for(x = 0; x < gridSize[0]; x++){ - for(y = 0; y < gridSize[1]; y++){ - - var value = (noise.perlin2(x/perlinScale, y/perlinScale))*10; - if (value >= -3) { - tempWorld[x][y].type = 0 - } else if (value < -3) { - tempWorld[x][y].type = 1 - } - if (value > 1.4) { - tempWorld[x][y].type = 2 - } - - } - } - for (i = 0; i < gridSize[0]*gridSize[1]/15; i){ - x = randomNumber(0,gridSize[0]); - y = randomNumber(0,gridSize[1]); - if (tempWorld[x][y].type != 1) { - i++; - tempWorld[x][y].structure = 1 - } - } - return tempWorld; - } diff --git a/util.js b/util.js new file mode 100644 index 0000000..b3f9e1a --- /dev/null +++ b/util.js @@ -0,0 +1,5 @@ +function randomNumber(min, max) { + return Math.floor(Math.random() * (max - min) + min); +} + +module.exports = {randomNumber} diff --git a/worldgen.js b/worldgen.js new file mode 100644 index 0000000..e41ef1e --- /dev/null +++ b/worldgen.js @@ -0,0 +1,40 @@ +var noise = require('noisejs'); +const util = require("./util.js") + +function generateWorld(gridSize, perlinScale){ + let x, y = 0 + + let tempWorld = Array.from(Array(gridSize[0]), () => new Array(gridSize[1])); + for (x = 0; x < gridSize[0]; x++){ + for (y = 0; y < gridSize[1]; y++){ + tempWorld[x][y] = {type: 0, structure: 0, owner: null} + } + } + + noise.seed(Math.random()) + for(x = 0; x < gridSize[0]; x++){ + for(y = 0; y < gridSize[1]; y++){ + + var value = (noise.perlin2(x/perlinScale, y/perlinScale))*10; + if (value >= -3) { + tempWorld[x][y].type = 0 + } else if (value < -3) { + tempWorld[x][y].type = 1 + } + if (value > 1.4) { + tempWorld[x][y].type = 2 + } + + } + } + for (i = 0; i < gridSize[0]*gridSize[1]/15; i){ + x = util.randomNumber(0,gridSize[0]); + y = util.randomNumber(0,gridSize[1]); + if (tempWorld[x][y].type != 1) { + i++; + tempWorld[x][y].structure = 1 + } + } + return tempWorld; +} +module.exports = { generateWorld }; diff --git a/www/index.html b/www/index.html index f74ec17..7bf2e98 100644 --- a/www/index.html +++ b/www/index.html @@ -9,12 +9,18 @@
Info
$0
+Info
$0