add code
This commit is contained in:
parent
27574bfff9
commit
114e2bbc44
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
|
15
README.md
15
README.md
@ -1 +1,14 @@
|
||||
pirate
|
||||
# Pirate
|
||||
NodeJs Multiplayer Mini Game
|
||||
|
||||
2. get the ALL the code: git clone this repo
|
||||
3. go to dir and run: "npm install" in the cloned dir
|
||||
2. start the server: node server.js
|
||||
3. visit: http://serverIP:8080
|
||||
4. Be RDY and then start the Game
|
||||
5. move with arrow keys on your keyboard!
|
||||
6. visit http://serverIP:8080 from multible pcs for multiplayer (if a player join, restart the game!)
|
||||
|
||||
----------------------------
|
||||
|
||||
LICENCE: MIT
|
||||
|
61
css/main.css
Normal file
61
css/main.css
Normal file
@ -0,0 +1,61 @@
|
||||
.sprite {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.water {
|
||||
background: url(../img/ground_tiles.png) 192px 254px;
|
||||
}
|
||||
|
||||
.ground {
|
||||
background: url(../img/ground_tiles.png) 640px 541px;
|
||||
}
|
||||
|
||||
.groundBottomLeft {
|
||||
background: url(../img/ground_tiles.png) 288px 382px;
|
||||
}
|
||||
|
||||
.groundLeft {
|
||||
background: url(../img/ground_tiles.png) 288px 414px;
|
||||
}
|
||||
|
||||
.groundTopLeft {
|
||||
background: url(../img/ground_tiles.png) 288px 445px;
|
||||
}
|
||||
|
||||
.groundTopRight {
|
||||
background: url(../img/ground_tiles.png) 224px 443px;
|
||||
}
|
||||
|
||||
.groundTop {
|
||||
background: url(../img/ground_tiles.png) 256px 445px;
|
||||
}
|
||||
|
||||
.groundRight {
|
||||
background: url(../img/ground_tiles.png) 224px 414px;
|
||||
}
|
||||
|
||||
.groundBottomRight {
|
||||
background: url(../img/ground_tiles.png) 224px 382px;
|
||||
}
|
||||
|
||||
.groundBottom {
|
||||
background: url(../img/ground_tiles.png) 254px 381px;
|
||||
}
|
||||
|
||||
.corner_wg1 {
|
||||
background: url(../img/ground_tiles.png) 192px 445px;
|
||||
}
|
||||
|
||||
.corner_wg2 {
|
||||
background: url(../img/ground_tiles.png) 160px 445px;
|
||||
}
|
||||
|
||||
.corner_wg3 {
|
||||
background: url(../img/ground_tiles.png) 160px 413px;
|
||||
}
|
||||
|
||||
.corner_wg4 {
|
||||
background: url(../img/ground_tiles.png) 192px 413px;
|
||||
}
|
BIN
img/ground_tiles.png
Normal file
BIN
img/ground_tiles.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 222 KiB |
BIN
img/plain.png
Normal file
BIN
img/plain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 152 B |
22
index.html
Normal file
22
index.html
Normal file
@ -0,0 +1,22 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<!-- Required meta tags always come first -->
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<!-- <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /> -->
|
||||
<link rel="stylesheet" href="./css/main.css">
|
||||
</head>
|
||||
<body style="overflow:hidden;">
|
||||
Pirate!!!
|
||||
<div id="map">
|
||||
|
||||
</div>
|
||||
|
||||
<!-- jQuery and co -->
|
||||
<script src="./js/jquery.min.js"></script>
|
||||
<script src="./js/socket.io-1.3.5.js"></script>
|
||||
<script src="./js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
5
js/jquery.min.js
vendored
Normal file
5
js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
40
js/main.js
Normal file
40
js/main.js
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
var socket = io();
|
||||
|
||||
socket.on('connect', function () {
|
||||
console.log("connect!");
|
||||
socket.emit("getmap", 100, 100);
|
||||
});
|
||||
|
||||
socket.on('getmap', function (map) {
|
||||
console.log(map);
|
||||
var domMap = $("#map");
|
||||
|
||||
domMap.empty();
|
||||
for(var w=0;w<map.length;w++) {
|
||||
for(var h=0;h<map[w].length;h++) {
|
||||
var spClass = "ground";
|
||||
if(map[w][h]=="0")
|
||||
spClass = "water";
|
||||
else if(map[w][h]=="1")
|
||||
spClass = "groundBottom";
|
||||
else if(map[w][h]=="2")
|
||||
spClass = "groundTop";
|
||||
else if(map[w][h]=="3")
|
||||
spClass = "groundLeft";
|
||||
else if(map[w][h]=="4")
|
||||
spClass = "groundRight";
|
||||
else if(map[w][h]=="5")
|
||||
spClass = "groundBottomRight";
|
||||
else if(map[w][h]=="6")
|
||||
spClass = "groundBottomLeft";
|
||||
else if(map[w][h]=="7")
|
||||
spClass = "groundTopRight";
|
||||
else if(map[w][h]=="8")
|
||||
spClass = "groundTopLeft";
|
||||
else if(map[w][h]=="9")
|
||||
spClass = "corner_wg1";
|
||||
domMap.append('<img style="top:'+(w*32)+'px; left:'+(h*32)+'px" src="./img/plain.png" class="sprite '+spClass+'">');
|
||||
}
|
||||
}
|
||||
});
|
3
js/socket.io-1.3.5.js
Normal file
3
js/socket.io-1.3.5.js
Normal file
File diff suppressed because one or more lines are too long
29
package.json
Normal file
29
package.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "MazeRaze",
|
||||
"version": "0.0.0",
|
||||
"description": "A small brower based maze game",
|
||||
"main": "server.js",
|
||||
"dependencies": {
|
||||
"express": "~4.13.3",
|
||||
"socket.io": "~1.3.6",
|
||||
"fs": "~0.0.2"
|
||||
},
|
||||
"devDependencies": {},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"start": "node server.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/cracker0dks/MazeRaze.git"
|
||||
},
|
||||
"keywords": [
|
||||
"maze",
|
||||
"nodejs"
|
||||
],
|
||||
"author": "cracker",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/cracker0dks/MazeRaze/issues"
|
||||
}
|
||||
}
|
166
s_map.js
Normal file
166
s_map.js
Normal file
@ -0,0 +1,166 @@
|
||||
module.exports = {
|
||||
generateMap: function(width, height) {
|
||||
var map = [];
|
||||
for(var w=0;w<width;w++) {
|
||||
map[w] = [];
|
||||
for(var h=0;h<height;h++) {
|
||||
//make border
|
||||
if(w<=0 || h<=0 || w>=width-1 || h>=height-1) {
|
||||
map[w][h] = "0";
|
||||
} else {
|
||||
map[w][h] = "0";
|
||||
p = 1;
|
||||
if(map[w-1][h]=="#")
|
||||
p+=43;
|
||||
if(map[w][h-1]=="#")
|
||||
p+=43;
|
||||
if(rand(p))
|
||||
map[w][h] = "#";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//preprocessing
|
||||
|
||||
|
||||
for(i=0;i<2;i++) { //Reduce little ilands
|
||||
for(var w=0;w<width;w++) {
|
||||
for(var h=0;h<height;h++) {
|
||||
if(map[w][h]=="#") {
|
||||
var waterCnt = 0;
|
||||
if(map[w-1][h]=="0")
|
||||
waterCnt++;
|
||||
if(map[w+1][h]=="0")
|
||||
waterCnt++;
|
||||
if(map[w][h-1]=="0")
|
||||
waterCnt++;
|
||||
if(map[w][h+1]=="0")
|
||||
waterCnt++;
|
||||
if(map[w-1][h-1]=="0")
|
||||
waterCnt++;
|
||||
if(map[w-1][h+1]=="0")
|
||||
waterCnt++;
|
||||
if(map[w+1][h-1]=="0")
|
||||
waterCnt++;
|
||||
if(map[w+1][h+1]=="0")
|
||||
waterCnt++;
|
||||
|
||||
if(waterCnt > 4)
|
||||
map[w][h] = "0";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
for(i=0;i<4;i++) { //expand all islands
|
||||
var orgMap = [];
|
||||
for(var w=0;w<width;w++) {
|
||||
orgMap[w] = [];
|
||||
for(var h=0;h<height;h++) {
|
||||
orgMap[w][h] = map[w][h];
|
||||
}
|
||||
}
|
||||
|
||||
for(var w=0;w<width;w++) {
|
||||
for(var h=0;h<height;h++) {
|
||||
if(orgMap[w][h]=="#" && !(w<=0 || h<=0 || w>=width-1 || h>=height-1)) {
|
||||
map[w-1][h]="#"
|
||||
map[w+1][h]="#"
|
||||
map[w][h-1]="#"
|
||||
map[w][h+1]="#"
|
||||
map[w-1][h-1]="#"
|
||||
map[w-1][h+1]="#"
|
||||
map[w+1][h-1]="#"
|
||||
map[w+1][h+1]="#"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0;i<4;i++) { //fill water holes
|
||||
for(var w=0;w<width;w++) {
|
||||
for(var h=0;h<height;h++) {
|
||||
if(map[w][h]=="0" && !(w<=0 || h<=0 || w>=width-1 || h>=height-1)) {
|
||||
var groundCtn = 0;
|
||||
if(map[w-1][h]=="#")
|
||||
groundCtn++;
|
||||
if(map[w+1][h]=="#")
|
||||
groundCtn++;
|
||||
if(map[w][h-1]=="#")
|
||||
groundCtn++;
|
||||
if(map[w][h+1]=="#")
|
||||
groundCtn++;
|
||||
if(map[w-1][h-1]=="#")
|
||||
groundCtn++;
|
||||
if(map[w-1][h+1]=="#")
|
||||
groundCtn++;
|
||||
if(map[w+1][h-1]=="#")
|
||||
groundCtn++;
|
||||
if(map[w+1][h+1]=="#")
|
||||
groundCtn++;
|
||||
|
||||
if(groundCtn > 5)
|
||||
map[w][h] = "#";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* groundtypes
|
||||
g = ground w = water
|
||||
*/
|
||||
|
||||
|
||||
//Set ground type
|
||||
for(var w=0;w<width;w++) {
|
||||
for(var h=0;h<height;h++) {
|
||||
if(map[w][h]=="0" && !(w<=0 || h<=0 || w>=width-1 || h>=height-1)) {
|
||||
if(map[w+1][h]=="#") {
|
||||
map[w][h] = "1";
|
||||
}
|
||||
if(map[w-1][h]=="#") {
|
||||
map[w][h] = "2";
|
||||
}
|
||||
|
||||
if(map[w][h-1]=="#") {
|
||||
map[w][h] = "3";
|
||||
}
|
||||
|
||||
if(map[w][h+1]=="#") {
|
||||
map[w][h] = "4";
|
||||
}
|
||||
|
||||
if(map[w][h+1]=="#" && map[w+1][h]=="#") {
|
||||
map[w][h] = "5";
|
||||
}
|
||||
|
||||
if(map[w][h-1]=="#" && map[w+1][h]=="#") {
|
||||
map[w][h] = "6";
|
||||
}
|
||||
|
||||
if(map[w][h+1]=="#" && map[w-1][h]=="#") {
|
||||
map[w][h] = "7";
|
||||
}
|
||||
|
||||
if(map[w][h-1]=="#" && map[w-1][h]=="#") {
|
||||
map[w][h] = "8";
|
||||
}
|
||||
|
||||
if(map[w-1][h-1]=="#") {
|
||||
map[w][h] = "9";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
};
|
||||
|
||||
function rand(p) {
|
||||
if(p > Math.random()*100)
|
||||
return true;
|
||||
return false;
|
||||
}
|
34
server.js
Normal file
34
server.js
Normal file
@ -0,0 +1,34 @@
|
||||
var PORT = 8080;
|
||||
var gameMode = true;
|
||||
|
||||
var allSockets = [];
|
||||
var userCnt = 0;
|
||||
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
app.use(express.static(__dirname + '/'));
|
||||
var server = require('http').Server(app);
|
||||
var io = require('socket.io')(server);
|
||||
var map = require("./s_map.js");
|
||||
|
||||
server.listen(PORT);
|
||||
|
||||
console.log("Pirate running on port:"+PORT);
|
||||
console.log();
|
||||
io.on('connection', function(socket){
|
||||
userCnt++;
|
||||
console.log("New user", socket.id);
|
||||
allSockets[socket.id] = socket;
|
||||
|
||||
socket.on('disconnect', function () {
|
||||
userCnt--;
|
||||
console.log("User Disconnected:", socket.id);
|
||||
});
|
||||
|
||||
socket.on('getmap', function (width, hight) {
|
||||
var newmap = map.generateMap(width,hight);
|
||||
//console.log("getmap",newmap);
|
||||
socket.emit("getmap", newmap);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user