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 perlinScale = 3;
|
||||
var express = require('express');
|
||||
log.setMode(0)
|
||||
log.setMode(0);
|
||||
process.title = "Server"
|
||||
setInterval(function(){ updateInfo()},5000)
|
||||
|
||||
|
@ -29,6 +29,7 @@ class Server {
|
|||
if (game === undefined && create) {
|
||||
this.addGame(name);
|
||||
// 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 game
|
||||
|
@ -55,11 +56,18 @@ class Server {
|
|||
}
|
||||
|
||||
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);
|
||||
if (game.addPlayer(id, nick) == false) {
|
||||
this.removeGame(game)
|
||||
return client.illegalAction(20)
|
||||
}
|
||||
|
||||
client.join(game.name)
|
||||
client.game = game;
|
||||
return true
|
||||
|
@ -144,7 +152,7 @@ io.on('connection', function(client) {
|
|||
client.emit('inGame', true)
|
||||
})
|
||||
client.on('leaveGame', function(tank){
|
||||
log.log(celient.id + ' disconnected.')
|
||||
log.log(client.id + ' disconnected.')
|
||||
client.game.removePlayer(client.id)
|
||||
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 xu = util.clamp(data.tilePosition[0], 0, gridSize[0])
|
||||
const yu = util.clamp(data.tilePosition[1], 0, gridSize[1])
|
||||
|
||||
if (!Number.isInteger(xu) || !Number.isInteger(yu)) return client.illegalAction(23)
|
||||
|
||||
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 { ctx, hctx } from './html.js';
|
||||
import { game } from '../game/game.js'
|
||||
import * as animation from './visualLoop.js'
|
||||
|
||||
export function render() {
|
||||
renderTiles()
|
||||
|
@ -14,7 +15,7 @@ export function renderTiles() { // DRAW THE IMAGE TO THE CANVAS.
|
|||
const tileSize = game.tileSize;
|
||||
for(x = 0; x < gridSize[0]; x++){
|
||||
for(y = 0; y < gridSize[1]; y++){
|
||||
const xu = x*tileSize;
|
||||
const xu = x*tileSize + animation.get();
|
||||
const yu = y*tileSize;
|
||||
const tempWorld = game.world;
|
||||
// Draw buildings
|
||||
|
@ -43,6 +44,7 @@ export function renderTiles() { // DRAW THE IMAGE TO THE CANVAS.
|
|||
break;
|
||||
case (4):
|
||||
ctx.drawImage(tileArray[34], xu,yu)
|
||||
|
||||
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 {render} from "/scripts/display/draw.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 function joinGame(data){
|
||||
|
@ -26,33 +29,27 @@ socket.on('disconnect', function(data){
|
|||
|
||||
socket.on('illegalAction', function(data){
|
||||
let action
|
||||
illegalAction(data)
|
||||
switch (data) {
|
||||
case 1:
|
||||
action = "You must be in game to do this."
|
||||
changeScene("mainmenu");
|
||||
game.reset();
|
||||
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){
|
||||
console.log(data)
|
||||
|
||||
});
|
||||
|
||||
socket.on('inGame', function(data){
|
||||
if (!game.status) {changeScene("game")}
|
||||
game.status = true;
|
||||
animation.start();
|
||||
})
|
||||
|
||||
socket.on('sync', function (sync){
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { render } from './display/draw.js';
|
||||
import './display/draw.js';
|
||||
import './game/game.js'
|
||||
import './interface/mainmenu/menu.js'
|
||||
import "/scripts/net/netcode.js"
|
||||
|
|
Loading…
Reference in a new issue