Skip to content
This repository has been archived by the owner on Nov 13, 2020. It is now read-only.

Feature/levels #59

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions assets/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@
"id": 0,
"quantity": 1
},
"block_player": false,
"block_npc": false,
"block_player": true,
"block_npc": true,
"replaceable": false,
"becomes": 8,
"threshold": 0,
Expand Down Expand Up @@ -387,8 +387,8 @@
"id": 4,
"quantity": 1
},
"block_player": false,
"block_npc": false,
"block_player": true,
"block_npc": true,
"replaceable": false,
"becomes": 8,
"threshold": 0,
Expand All @@ -415,8 +415,8 @@
"id": 5,
"quantity": 1
},
"block_player": false,
"block_npc": false,
"block_player": true,
"block_npc": true,
"replaceable": false,
"becomes": 8,
"threshold": 0,
Expand All @@ -443,8 +443,8 @@
"id": 6,
"quantity": 1
},
"block_player": false,
"block_npc": false,
"block_player": true,
"block_npc": true,
"replaceable": false,
"becomes": 8,
"threshold": 0,
Expand All @@ -471,8 +471,8 @@
"id": 7,
"quantity": 1
},
"block_player": false,
"block_npc": false,
"block_player": true,
"block_npc": true,
"replaceable": false,
"becomes": 8,
"threshold": 0,
Expand All @@ -499,8 +499,8 @@
"id": 8,
"quantity": 1
},
"block_player": false,
"block_npc": false,
"block_player": true,
"block_npc": true,
"replaceable": false,
"becomes": 8,
"threshold": 0,
Expand Down
91 changes: 54 additions & 37 deletions assets/scripts/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ window.app = {
'/assets/tilesets/terrain-32x32.png',
app.graphics.tilesets.terrain
),
app.environment.downloadTiles(),
app.environment.downloadMap()
app.environment.downloadTiles()
).done(function() {
app.initialize();
});
Expand All @@ -36,25 +35,29 @@ window.app = {
app.network.connectSocket();
app.audio.initialize();
app.persistence.load() || app.persistence.createNewPlayer();
app.graphics.viewport.update();
app.player.regenerateHearts();
app.player.inventory.render();
app.chat.initialize();
app.network.bindEvents();
app.network.send.join(app.player.name);
app.initializeKeybindings();
app.persistence.startAutoSave();
app.graphics.startAnimation();
app.graphics.hearts.draw();
app.chat.message('Help', 'Type /help for some help', 'help');
app.chat.message('Help', 'Use the WASD keys to move around', 'help');

setTimeout(function() {
app.network.send.move(app.player.coordinates, app.player.direction);
app.network.send.character(app.player.name, app.player.picture);
}, 500);
$.when(
app.environment.downloadMap(app.player.levelName)
).done(function() {
app.graphics.viewport.update();
app.player.regenerateHearts();
app.player.inventory.render();
app.chat.initialize();
app.network.bindEvents();
app.network.send.join(app.player.name, app.player.levelName);
app.initializeKeybindings();
app.persistence.startAutoSave();
app.graphics.startAnimation();
app.graphics.hearts.draw();
app.chat.message('Help', 'Type /help for some help', 'help');
app.chat.message('Help', 'Use the WASD keys to move around', 'help');

setTimeout(function() {
app.network.send.move(app.player.coordinates, app.player.direction);
app.network.send.character(app.player.name, app.player.picture);
}, 500);

$('#controls .button').tipsy({fade: false, gravity: 's', html: true});
$('#controls .button').tipsy({fade: false, gravity: 's', html: true});
});
},

environment: {
Expand Down Expand Up @@ -202,10 +205,10 @@ window.app = {
});
},

downloadMap: function() {
return $.get('/map').pipe(function(data) {
app.chat.message('Client', 'Map data done.', 'client');
app.environment.map.data = data;
downloadMap: function(levelName) {
return $.get('/map/' + levelName).pipe(function(data) {
app.chat.message('Client', 'Map data done (' + levelName + ').', 'client');
app.environment.map.data = data.data;
return true;
});
},
Expand All @@ -223,6 +226,7 @@ window.app = {
direction: 's',
speed: 150,


// Attempts to move the character in the direction we specify
move: function(d) {
// if nothing is passed in or anything not acceptable is passed in do nothing
Expand Down Expand Up @@ -601,6 +605,7 @@ window.app = {
location: app.player.coordinates,
name: app.player.name,
picture: app.player.picture,
levelName: app.player.levelName
}));
},

Expand All @@ -612,6 +617,7 @@ window.app = {
app.player.coordinates = persistentData.location;
app.player.name = persistentData.name;
app.player.picture = persistentData.picture;
app.player.levelName = persistentData.levelName;
app.chat.message('Client', 'Loaded your saved character', 'client');
return true;
}
Expand All @@ -624,6 +630,7 @@ window.app = {
app.player.coordinates = {x: 100, y: 100};
app.player.name = 'Anon' + Math.floor(Math.random() * 8999 + 1000);
app.player.picture = Math.floor(Math.random() * 8) + 1;
app.player.levelName = '1';
app.chat.message('Client', 'Creating a character for the first time', 'client');
},

Expand Down Expand Up @@ -693,44 +700,58 @@ window.app = {
app.network.socket.emit('chat', {
name: app.player.name,
message: message,
priority: 0
priority: 0,
levelName: app.player.levelName
});
},
// Player moves to a new location
move: function(coords, direction) {
app.network.socket.emit('character info', {
x: coords.x,
y: coords.y,
direction: direction
direction: direction,
levelName: app.player.levelName
});
},
// Player builds a tile or mines a tile
terraform: function(x, y, tile) {
app.network.socket.emit('terraform', {
x: x,
y: y,
tile: tile
tile: tile,
levelName: app.player.levelName
});
},
// Player dies
death: function(name, method) {
app.network.socket.emit('chat', {
name: name,
message: message,
priority: 'server'
priority: 'server',
levelName: app.player.levelName
});
},
// Player changes either their name or their picture
character: function(name, picture) {
app.network.socket.emit('character info', {
name: name,
picture: picture
picture: picture,
levelName: app.player.levelName
});
},

join: function(name) {
// Enter/leave room
join: function(name, levelName) {
app.network.socket.emit('join', {
name: name
name: name,
levelName: levelName,
data: app.player
});
},
unjoin: function(name, levelName) {
app.network.socket.emit('unjoin', {
name: name,
levelName: levelName
});
}
},
Expand All @@ -746,20 +767,15 @@ window.app = {
});

socket.on('disconnect', function(data) {
app.chat.message('Server', 'Disconnected', 'server');
});

socket.on('leave', function(data) {
app.players.remove(data.session);
app.chat.message(data.name || 'unknown', "Player Disconnected", 'server');
});

socket.on('terraform', function (data) {
app.environment.map.data[data.x][data.y] = data.tile;
});

socket.on('character info', function(data) {
if (socket.socket.sessionid == data.dession) return;
if (socket.socket.sessionid == data.session) return;
app.players.update(data);
});

Expand Down Expand Up @@ -994,6 +1010,7 @@ window.app = {
},

initialize: function() {
$(document).on('keydown keyup', '#message-input', function(e) { e.stopPropagation(); });
$('#message-box form').submit(function(event) {
event.preventDefault();
var message = app.chat.$input.val();
Expand Down
5 changes: 5 additions & 0 deletions assets/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ body {
padding: 0;
color: #fff;
}
html, body {
height: 100%;
height: 100vh;
overflow: hidden;
}
#page {
text-align: center;
margin: 0 auto;
Expand Down
5 changes: 2 additions & 3 deletions lib/corruption.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ var Corruption = function() {
if (!socket) {
socket = io.sockets;
}

socket.emit('event corruption', {
socket.to(map.levelName).emit('event corruption', {
map: self.data
});
};
Expand Down Expand Up @@ -67,7 +66,7 @@ var Corruption = function() {
};

self.execute = function() {
handle = setInterval(loop, interval);
//handle = setInterval(loop, interval);
loop();
};
};
Expand Down
11 changes: 7 additions & 4 deletions lib/daynight.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var DayNight = function() {
socket = io.sockets;
}

socket.emit('event time', {
socket.to(map.levelName).emit('event time', {
time: current
});
};
Expand All @@ -57,12 +57,14 @@ var DayNight = function() {
if (Math.random() < 1/4000) {
map.data[x][y] = [4, 20]; // tree, 20 health
new_trees++;
map.dirty = true;
}
break;
case 1: // dirt
if (Math.random() < 1/5) {
map.data[x][y][0] = 0; // grass
new_grass++;
map.dirty = true;
}
break;
case 3: // water
Expand All @@ -75,6 +77,7 @@ var DayNight = function() {
if (tile == 0 || tile == 1) { // if this is a grass or dirt tile
map.data[x+xx][y+yy][0] = 2; // make it sand
new_sand++;
map.dirty = true;
}
}
}
Expand All @@ -87,22 +90,22 @@ var DayNight = function() {
logger.info("New Grass", new_grass);
logger.info("New Sand", new_sand);

io.sockets.emit('event bigterraform', {});
io.sockets.to(map.levelName).emit('event bigterraform', {});
}

if (current >= CYCLE) {
current = 0;
}

io.sockets.emit('event time', {
io.sockets.to(map.levelName).emit('event time', {
time: current
});

logger.debug("Event", "Time: " + current + ":00");
};

self.execute = function() {
handle = setInterval(loop, INTERVAL);
//handle = setInterval(loop, INTERVAL);
loop();
};
};
Expand Down
5 changes: 3 additions & 2 deletions lib/earthquake.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,13 @@ var Earthquake = function() {

remaining--;
}
io.sockets.emit('event earthquake', { });
io.sockets.to(map.levelName).emit('event earthquake', { });
logger.debug("Event", "Earthquake");
};

self.execute = function() {
handle = setInterval(loop, interval);
loop();
//handle = setInterval(loop, interval);
};
};

Expand Down
Loading