From d4bdf73a2d9947fe4784d2e96037cf13e72506e8 Mon Sep 17 00:00:00 2001 From: rofl256 Date: Fri, 30 Jun 2017 02:19:44 +0200 Subject: [PATCH] add moving guy and fix some bugs --- css/main.css | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++ js/main.js | 33 +++++++++++++++--- server.js | 2 +- 3 files changed, 126 insertions(+), 5 deletions(-) diff --git a/css/main.css b/css/main.css index a975ce9..ec9fe77 100644 --- a/css/main.css +++ b/css/main.css @@ -49,6 +49,102 @@ transform-origin: 0; } +.guy1-0-0 { + background: url(../img/guy_sprite.png) 0px 0px; +} + +.guy1-0-1 { + background: url(../img/guy_sprite.png) -32px 0px; +} + +.guy1-0-2 { + background: url(../img/guy_sprite.png) -64px 0px; +} + +.guy0--1-0 { + background: url(../img/guy_sprite.png) 0px -32px; +} + +.guy0--1-1 { + background: url(../img/guy_sprite.png) -32px -32px; +} + +.guy0--1-2 { + background: url(../img/guy_sprite.png) -64px -32px; +} + +.guy0-1-0 { + background: url(../img/guy_sprite.png) 0px 192px; +} + +.guy0-1-1 { + background: url(../img/guy_sprite.png) -32px 192px; +} + +.guy0-1-2 { + background: url(../img/guy_sprite.png) -64px 192px; +} + +.guy-1-0-0 { + background: url(../img/guy_sprite.png) 0px 160px; +} + +.guy-1-0-1 { + background: url(../img/guy_sprite.png) -32px 160px; +} + +.guy-1-0-2 { + background: url(../img/guy_sprite.png) -64px 160px; +} + +.guy-1--1-0 { + background: url(../img/guy_sprite.png) -96px 224px; +} + +.guy-1--1-1 { + background: url(../img/guy_sprite.png) -128px 224px; +} + +.guy-1--1-2 { + background: url(../img/guy_sprite.png) -160px 224px; +} + +.guy-1-1-0 { + background: url(../img/guy_sprite.png) -96px 160px; +} + +.guy-1-1-1 { + background: url(../img/guy_sprite.png) -128px 160px; +} + +.guy-1-1-2 { + background: url(../img/guy_sprite.png) -160px 160px; +} + +.guy1-1-0 { + background: url(../img/guy_sprite.png) -96px -64px; +} + +.guy1-1-1 { + background: url(../img/guy_sprite.png) -128px -64px; +} + +.guy1-1-2 { + background: url(../img/guy_sprite.png) -160px -64px; +} + +.guy1--1-0 { + background: url(../img/guy_sprite.png) -96px 0px; +} + +.guy1--1-1 { + background: url(../img/guy_sprite.png) -128px 0px; +} + +.guy1--1-2 { + background: url(../img/guy_sprite.png) -160px 0px; +} + html { -webkit-transform: scale(1.5); transform: scale(2); diff --git a/js/main.js b/js/main.js index c108534..b6bde93 100644 --- a/js/main.js +++ b/js/main.js @@ -47,23 +47,35 @@ socket.on('getmap', function (conent) { }); function addNewPlayer(player, id) { - if($("#"+id).length==0) - $("body").append('
'); + if($("#"+id).length==0) { + var modeClass = "default_ship"; + var modeImg = "./img/default_ship.png"; + if(player["mode"]==1) { + var modeClass = "guy"; + var modeImg = "./img/plain.png"; + } + $("body").append('
'); + } } var oldmapX = null; var oldmapY = null; - +var picStep = 0; +var cnt = 0; socket.on('setpos', function (allPlayers) { window.requestAnimationFrame(function() { for(var id in allPlayers) { var player = allPlayers[id]; var playerElement = $("#"+id); + var playerImg = playerElement.find("img"); for(var i in player["special"]) { if(i == "modechange") { if(player["mode"] == 0) { //ship playerElement.find("img").attr("src","./img/default_ship.png"); + playerImg.removeClass (function (index, className) { + return (className.match (/(^|\s)guy\S+/g) || []).join(' '); + }); playerElement.find("img").removeClass("guy"); playerElement.find("img").addClass("default_ship"); } else { //land @@ -138,8 +150,21 @@ socket.on('setpos', function (allPlayers) { left2right = 1; } var angle = 0; - if(player["mode"] == 0) { + if(player["mode"] == 0) { //ship var angle = Math.atan2(top2Btn, left2right); + } else { //land + cnt++; + if(cnt%3==0) + picStep++; + if(picStep >= 3) + picStep = 0; + console.log(top2Btn+"-"+left2right) + if(!playerImg.hasClass("guy"+top2Btn+"-"+left2right+"-"+picStep)) { + playerImg.removeClass (function (index, className) { + return (className.match (/(^|\s)guy\S+/g) || []).join(' '); + }); + playerImg.addClass("guy"+top2Btn+"-"+left2right+"-"+picStep); + } } playerElement.css({"top":player["y"],"left":player["x"], "-webkit-transform" : "rotate("+angle+"rad)"}); } diff --git a/server.js b/server.js index 068de63..6def022 100644 --- a/server.js +++ b/server.js @@ -64,7 +64,7 @@ io.on('connection', function(socket){ socket.on('actionKey', function (key) { var groundUnder = getGroundUnderPlayer(player["x"], player["y"]); if(player["mode"] == 0) { //ship - if(groundUnder>=0) { //its nearly land + if(groundUnder>=1) { //its nearly land player["mode"] = 1; player["special"]["modechange"] = true; }