Animations are now possible
Need new sprite system to accomodate for it though()
This commit is contained in:
parent
90f73caefe
commit
c89f24a2a7
13
index.js
13
index.js
|
@ -4,7 +4,7 @@ const log = require("./log.js")
|
||||||
const gridSize = [18, 18];
|
const gridSize = [18, 18];
|
||||||
const perlinScale = 3;
|
const perlinScale = 3;
|
||||||
var express = require('express');
|
var express = require('express');
|
||||||
log.setMode(0)
|
log.setMode(0);
|
||||||
process.title = "Server"
|
process.title = "Server"
|
||||||
setInterval(function(){ updateInfo()},5000)
|
setInterval(function(){ updateInfo()},5000)
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ class Server {
|
||||||
if (game === undefined && create) {
|
if (game === undefined && create) {
|
||||||
this.addGame(name);
|
this.addGame(name);
|
||||||
// Oh no.... This cant be good code.
|
// Oh no.... This cant be good code.
|
||||||
|
// Coming back to it two months later. Horrible, but I don't know how to fix it. Maybe I'll leave it as an ancient artifact.
|
||||||
return this.getGameByName(name);
|
return this.getGameByName(name);
|
||||||
}
|
}
|
||||||
return game
|
return game
|
||||||
|
@ -55,11 +56,18 @@ class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
joinClientToGame(room, nick, id, client) {
|
joinClientToGame(room, nick, id, client) {
|
||||||
|
if (this.getAllIDs().includes(id)) {
|
||||||
|
return client.illegalAction(22)
|
||||||
|
}
|
||||||
|
if (nick.length > 9) {
|
||||||
|
return client.illegalAction(21)
|
||||||
|
}
|
||||||
const game = this.getGameByName(room, true);
|
const game = this.getGameByName(room, true);
|
||||||
if (game.addPlayer(id, nick) == false) {
|
if (game.addPlayer(id, nick) == false) {
|
||||||
this.removeGame(game)
|
this.removeGame(game)
|
||||||
return client.illegalAction(20)
|
return client.illegalAction(20)
|
||||||
}
|
}
|
||||||
|
|
||||||
client.join(game.name)
|
client.join(game.name)
|
||||||
client.game = game;
|
client.game = game;
|
||||||
return true
|
return true
|
||||||
|
@ -144,7 +152,7 @@ io.on('connection', function(client) {
|
||||||
client.emit('inGame', true)
|
client.emit('inGame', true)
|
||||||
})
|
})
|
||||||
client.on('leaveGame', function(tank){
|
client.on('leaveGame', function(tank){
|
||||||
log.log(celient.id + ' disconnected.')
|
log.log(client.id + ' disconnected.')
|
||||||
client.game.removePlayer(client.id)
|
client.game.removePlayer(client.id)
|
||||||
io.to(client.game.name).emit('playerList', client.game.players)
|
io.to(client.game.name).emit('playerList', client.game.players)
|
||||||
})
|
})
|
||||||
|
@ -155,6 +163,7 @@ io.on('connection', function(client) {
|
||||||
const room = client.game.name
|
const room = client.game.name
|
||||||
const xu = util.clamp(data.tilePosition[0], 0, gridSize[0])
|
const xu = util.clamp(data.tilePosition[0], 0, gridSize[0])
|
||||||
const yu = util.clamp(data.tilePosition[1], 0, gridSize[1])
|
const yu = util.clamp(data.tilePosition[1], 0, gridSize[1])
|
||||||
|
|
||||||
if (!Number.isInteger(xu) || !Number.isInteger(yu)) return client.illegalAction(23)
|
if (!Number.isInteger(xu) || !Number.isInteger(yu)) return client.illegalAction(23)
|
||||||
|
|
||||||
client.game.world[xu][yu].structure = data.structure
|
client.game.world[xu][yu].structure = data.structure
|
||||||
|
|
|
@ -3,6 +3,7 @@ import {tileArray} from './tileRenderer.js';
|
||||||
import { cursor } from '../interface/game/mouse.js'
|
import { cursor } from '../interface/game/mouse.js'
|
||||||
import { ctx, hctx } from './html.js';
|
import { ctx, hctx } from './html.js';
|
||||||
import { game } from '../game/game.js'
|
import { game } from '../game/game.js'
|
||||||
|
import * as animation from './visualLoop.js'
|
||||||
|
|
||||||
export function render() {
|
export function render() {
|
||||||
renderTiles()
|
renderTiles()
|
||||||
|
@ -14,7 +15,7 @@ export function renderTiles() { // DRAW THE IMAGE TO THE CANVAS.
|
||||||
const tileSize = game.tileSize;
|
const tileSize = game.tileSize;
|
||||||
for(x = 0; x < gridSize[0]; x++){
|
for(x = 0; x < gridSize[0]; x++){
|
||||||
for(y = 0; y < gridSize[1]; y++){
|
for(y = 0; y < gridSize[1]; y++){
|
||||||
const xu = x*tileSize;
|
const xu = x*tileSize + animation.get();
|
||||||
const yu = y*tileSize;
|
const yu = y*tileSize;
|
||||||
const tempWorld = game.world;
|
const tempWorld = game.world;
|
||||||
// Draw buildings
|
// Draw buildings
|
||||||
|
@ -43,6 +44,7 @@ export function renderTiles() { // DRAW THE IMAGE TO THE CANVAS.
|
||||||
break;
|
break;
|
||||||
case (4):
|
case (4):
|
||||||
ctx.drawImage(tileArray[34], xu,yu)
|
ctx.drawImage(tileArray[34], xu,yu)
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
30
www/scripts/display/visualLoop.js
Normal file
30
www/scripts/display/visualLoop.js
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import {render } from "./draw.js"
|
||||||
|
var RUNNING = false
|
||||||
|
var animationStage = 0;
|
||||||
|
export function start() {
|
||||||
|
if (!RUNNING) {
|
||||||
|
RUNNING = true
|
||||||
|
loop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function stop() {
|
||||||
|
RUNNING = false
|
||||||
|
}
|
||||||
|
|
||||||
|
export function get() {
|
||||||
|
return animationStage
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loop() {
|
||||||
|
if (RUNNING === true)
|
||||||
|
setTimeout(function(){
|
||||||
|
if (animationStage < 2) {
|
||||||
|
animationStage = animationStage + 1;
|
||||||
|
} else {
|
||||||
|
animationStage = 0;
|
||||||
|
}
|
||||||
|
render()
|
||||||
|
loop();
|
||||||
|
}, (250));
|
||||||
|
}
|
29
www/scripts/interface/common/illegalaction.js
Normal file
29
www/scripts/interface/common/illegalaction.js
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
export function illegalAction(data) {
|
||||||
|
let action
|
||||||
|
|
||||||
|
switch (data) {
|
||||||
|
case 1:
|
||||||
|
action = "You must be in game to do this."
|
||||||
|
break;
|
||||||
|
case 20:
|
||||||
|
action = "That name is already taken."
|
||||||
|
break;
|
||||||
|
case 21:
|
||||||
|
action = "That name is too long."
|
||||||
|
break;
|
||||||
|
case 22:
|
||||||
|
action = "You are already in a game."
|
||||||
|
break;
|
||||||
|
case 23:
|
||||||
|
action = "Invalid Placement location."
|
||||||
|
break;
|
||||||
|
case 100:
|
||||||
|
action = "Malformed Packet"
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
action = "Unknown action."
|
||||||
|
}
|
||||||
|
console.log(`Illegal Action. ${action}`)
|
||||||
|
alert(`Illegal Action, ${action}`)
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,9 @@ import * as status from "/scripts/net/status.js"
|
||||||
import {game} from "/scripts/game/game.js"
|
import {game} from "/scripts/game/game.js"
|
||||||
import {render} from "/scripts/display/draw.js"
|
import {render} from "/scripts/display/draw.js"
|
||||||
import { changeScene } from "/scripts/interface/scene.js"
|
import { changeScene } from "/scripts/interface/scene.js"
|
||||||
|
import { illegalAction } from "/scripts/interface/common/illegalaction.js"
|
||||||
|
import * as animation from '../display/visualLoop.js'
|
||||||
|
|
||||||
export var socket = io.connect(env.IP_ADDRESS);
|
export var socket = io.connect(env.IP_ADDRESS);
|
||||||
|
|
||||||
export function joinGame(data){
|
export function joinGame(data){
|
||||||
|
@ -26,33 +29,27 @@ socket.on('disconnect', function(data){
|
||||||
|
|
||||||
socket.on('illegalAction', function(data){
|
socket.on('illegalAction', function(data){
|
||||||
let action
|
let action
|
||||||
|
illegalAction(data)
|
||||||
switch (data) {
|
switch (data) {
|
||||||
case 1:
|
case 1:
|
||||||
action = "You must be in game to do this."
|
action = "You must be in game to do this."
|
||||||
changeScene("mainmenu");
|
changeScene("mainmenu");
|
||||||
game.reset();
|
game.reset();
|
||||||
break;
|
break;
|
||||||
case 20:
|
|
||||||
action = "That name is already taken."
|
|
||||||
break;
|
|
||||||
case 23:
|
|
||||||
action = "Invalid Placement location."
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
action = "Unknown action."
|
|
||||||
|
|
||||||
}
|
}
|
||||||
console.log(`Illegal Action. ${action}`)
|
|
||||||
alert(`Illegal Action, ${action}`)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('playerList', function(data){
|
socket.on('playerList', function(data){
|
||||||
console.log(data)
|
console.log(data)
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('inGame', function(data){
|
socket.on('inGame', function(data){
|
||||||
if (!game.status) {changeScene("game")}
|
if (!game.status) {changeScene("game")}
|
||||||
game.status = true;
|
game.status = true;
|
||||||
|
animation.start();
|
||||||
})
|
})
|
||||||
|
|
||||||
socket.on('sync', function (sync){
|
socket.on('sync', function (sync){
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { render } from './display/draw.js';
|
import './display/draw.js';
|
||||||
import './game/game.js'
|
import './game/game.js'
|
||||||
import './interface/mainmenu/menu.js'
|
import './interface/mainmenu/menu.js'
|
||||||
import "/scripts/net/netcode.js"
|
import "/scripts/net/netcode.js"
|
||||||
|
|
Loading…
Reference in a new issue