Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.43 KB | None | 0 0
  1. [{"id":"b1b3ebe7.a06498","type":"ibmiot in","z":"fc352090.50f96","authentication":"apiKey","apiKey":"b2811b5b.18a588","inputType":"evt","deviceId":"kinectDeviceOVI","applicationId":"","deviceType":"kinectDeviceType","eventType":"kinectEvent","commandType":"","format":"json","name":"IBM IoT Input","service":"registered","allDevices":false,"allApplications":"","allDeviceTypes":true,"allEvents":true,"allCommands":"","allFormats":true,"qos":0,"x":283.75,"y":423.5,"wires":[["d4cc26c1.a26778"]]},{"id":"e482cccb.f029e","type":"ibmiot in","z":"fc352090.50f96","authentication":"boundService","apiKey":"","inputType":"appsts","deviceId":"","applicationId":"","deviceType":"+","eventType":"+","commandType":"","format":"json","name":"IBM IoT App Initialize Context","service":"registered","allDevices":false,"allApplications":false,"allDeviceTypes":true,"allEvents":true,"allCommands":false,"allFormats":false,"qos":"0","x":381.75,"y":138.5,"wires":[["e0f792bd.6e9ac"]]},{"id":"6843b45f.ee415c","type":"comment","z":"fc352090.50f96","name":"Context Definition","info":"","x":624.75,"y":92.5,"wires":[]},{"id":"e0f792bd.6e9ac","type":"function","z":"fc352090.50f96","name":"Global Configure ","func":"\n/**\n * Funci�n que inicializa todas las propiedades de la aplicaci�n\n **/\nfunction InitializeConfigure() {\n this.context.global.set(\"isDebug\",false);\n this.context.global.set(\"timeDelay\",2000);\n this.context.global.set(\"numPackets\",1);\n this.context.global.set(\"numPacketsDebug\",1);\n return msg;\n}\n\n\nInitializeConfigure();","outputs":1,"noerr":0,"x":625.9642333984375,"y":138.85715293884277,"wires":[[]]},{"id":"d4cc26c1.a26778","type":"switch","z":"fc352090.50f96","name":"Validate Packet","property":"payload","propertyType":"msg","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"true","outputs":2,"x":476.7499809265137,"y":569.5000438690186,"wires":[[],["c3bd0788.12f368"]]},{"id":"d36b2bc3.b89d98","type":"function","z":"fc352090.50f96","name":"Deserializacion Body Parts","func":"function toDecimal(input, decimals){\n var res = parseFloat(Math.round(input * 100) / 100).toFixed(decimals);\n //node.warn(res);\n return res;\n}\n\nnode.warn(msg.payload)\nvar obj = msg.payload;\nvar user = obj.user;\nvar size = user.length;\n//node.warn(size);\nvar numDecimals = this.context.global.get(\"numDecimals\");\nvar users = [];\nif (user) {\n for (var i = 0; i < user.length; i++)\n {\n var bodypart = context.global.get(\"bodyPartSelect\");\n //node.warn(bodypart);\n //node.warn(user)\n if (user[i])\n var body = user[i].bodyParts;\n //node.warn(body);\n var myBodyParts = [];\n if(body){\n\n body.forEach(\n function(p){\n\n var item;\n if(p.name == \"Neck\") {\n\n p.positions[0].x = toDecimal(p.positions[0].x, numDecimals);\n p.positions[0].y = toDecimal(p.positions[0].y, numDecimals);\n p.positions[0].z = toDecimal(p.positions[0].z, numDecimals);\n\n item = p;\n item.userId = i+1;\n // node.warn(item);\n //node.send(item);\n }\n else if (p.name == \"WristLeft\"){\n p.positions[0].x = toDecimal(p.positions[0].x, numDecimals);\n p.positions[0].y = toDecimal(p.positions[0].y, numDecimals);\n p.positions[0].z = toDecimal(p.positions[0].z, numDecimals);\n\n item = p;\n item.userId = i+1;\n // node.warn(item);\n //node.send(item);\n }\n else if (p.name == \"WristRight\"){\n p.positions[0].x = toDecimal(p.positions[0].x, numDecimals);\n p.positions[0].y = toDecimal(p.positions[0].y, numDecimals);\n p.positions[0].z = toDecimal(p.positions[0].z, numDecimals);\n\n item = p;\n item.userId = i+1;\n // node.warn(item);\n //node.send(item);\n }\n if (item){\n myBodyParts.push(item);\n }\n }\n );\n }\n var userElement = {\"id\": i+1, parts: myBodyParts};\n users.push(userElement)\n }\n msg.users = users;\n return msg;\n}\n","outputs":1,"noerr":0,"x":742.8743743896484,"y":430.29601287841797,"wires":[["5b5f1cc7.809b04","529f1fe1.a3ddf"]],"outputLabels":["string"]},{"id":"5b5f1cc7.809b04","type":"function","z":"fc352090.50f96","name":"Usuario 0","func":"var users = msg.users;\n\nmsg.user = users[0];\nreturn msg;","outputs":1,"noerr":0,"x":973.0760269165039,"y":593.8403778076172,"wires":[["f174e6d.e566118"]]},{"id":"529f1fe1.a3ddf","type":"function","z":"fc352090.50f96","name":"Usuario 1","func":"var users = msg.users;\n\nmsg.user = users[1];\nreturn msg;","outputs":1,"noerr":0,"x":967.9311790466309,"y":249.23088836669922,"wires":[["f174e6d.e566118"]]},{"id":"f174e6d.e566118","type":"function","z":"fc352090.50f96","name":"Untitled Theme 1","func":"var user = msg.user;\nvar wristLeft = user.parts[1];\nvar wristRight = user.parts[2];\nvar neck = msg.user.parts[0];\n//node.warn(user)\nvar mediumWristles = {x: (parseFloat(wristLeft.positions[0].x) + parseFloat(wristRight.positions[0].x)) / 2, y: (parseFloat(wristLeft.positions[0].y) + parseFloat(wristRight.positions[0].y)) / 2}\nnode.warn(mediumWristles)\nvar neck = { x: (parseFloat(neck.positions[0].x)), y:(parseFloat(neck.positions[0].y)) }\n//node.warn(neck)\nvar distance = { x: mediumWristles.x - neck.x, y: mediumWristles.y - neck.y };\n\n\nvar userDistance = { userId: user.id, distance: distance };\nmsg.userDistance = userDistance;\n//node.warn(msg.userDistance)\nreturn msg;","outputs":1,"noerr":0,"x":1166.9308166503906,"y":404.54981994628906,"wires":[["70cec7c7.194708"]]},{"id":"30c7d918.e324b6","type":"function","z":"fc352090.50f96","name":"Chargue","func":"var userDistance = msg.userDistance;\nvar idealPoint = {x: 0.0, y: 0.2}\nvar difference = {x: idealPoint.x - userDistance.distance.x, y: idealPoint.y - userDistance.distance.y}\nvar distance = {name: \"Charge\", distance: Math.sqrt(Math.pow(difference.x,2) + Math.pow(difference.y,2)), userId: userDistance.userId}\n\nif(distance.distance < msg.parts.distance)\n msg.parts = distance;\nnode.warn(\"Charge: \" + userDistance.userId + \" : \" + distance)\n\nreturn msg;","outputs":1,"noerr":0,"x":1431.4308395385742,"y":586.8745021820068,"wires":[["75209bff.c4c7b4"]]},{"id":"7f8f3c4b.578da4","type":"function","z":"fc352090.50f96","name":"Shoot","func":"var userDistance = msg.userDistance;\nvar idealPointLeft = {x: -0.5, y: 0.0}\nvar idealPointRight = {x: 0.5, y: 0.0}\n\nvar differenceLeft = {x: idealPointLeft.x - userDistance.distance.x, y: idealPointLeft.y - userDistance.distance.y}\nvar differenceRight = {x: idealPointRight.x - userDistance.distance.x, y: idealPointRight.y - userDistance.distance.y}\n\nvar distanceLeft = Math.sqrt(Math.pow(differenceLeft.x,2) + Math.pow(differenceLeft.y,2))\nvar distanceRight = Math.sqrt(Math.pow(differenceRight.x,2) + Math.pow(differenceRight.y,2))\n\nvar distance = {name: \"Shoot\", distance: Math.min(distanceLeft, distanceRight), userId: userDistance.userId}\n\nif(distance.distance < msg.parts.distance)\n msg.parts = distance;\nnode.warn(\"Shoot: \" + userDistance.userId + \" : \" + distance)\nreturn msg;","outputs":1,"noerr":0,"x":1428.0886573791504,"y":403.04408264160156,"wires":[["30c7d918.e324b6"]]},{"id":"70cec7c7.194708","type":"function","z":"fc352090.50f96","name":"Shield","func":"var userDistance = msg.userDistance;\nvar idealPoint = {x: 0.0, y: 0.0}\nvar difference = {x: idealPoint.x - userDistance.distance.x, y: idealPoint.y - userDistance.distance.y}\nvar distance = {name: \"Shield\", distance: Math.sqrt(Math.pow(difference.x,2) + Math.pow(difference.y,2)), userId: userDistance.userId}\n\nmsg.parts = distance;\nnode.warn(\"Shield \" + userDistance.userId + \" : \" + distance)\n\n\nreturn msg;","outputs":1,"noerr":0,"x":1367.7552947998047,"y":211.3715476989746,"wires":[["7f8f3c4b.578da4"]]},{"id":"c3bd0788.12f368","type":"function","z":"fc352090.50f96","name":"Throttling","func":"var packetId = msg.payload.packetID;\n\n//if(packetId % this.context.global.get(\"numPacketsDebug\") == 0) \n // node.warn(packetId);\n\nif(packetId % 100 == 0) \n return node.send(msg);\n\n\n\n","outputs":1,"noerr":0,"x":497.76737213134766,"y":427.2882604598999,"wires":[["d36b2bc3.b89d98"]]},{"id":"3b2913d9.c6bf0c","type":"function","z":"fc352090.50f96","name":"Wait for all tasks to finish","func":"context.data = context.data || new Object();\nnode.warn(msg)\nswitch (msg.parts.name) {\n case \"Shield\":\n context.data.shield = msg.parts.distance;\n msg = null;\n break;\n case \"Shoot\":\n context.data.shoot = msg.parts.distance;\n msg = null;\n break;\n case \"Charge\":\n context.data.charge = msg.parts.distance;\n msg = null;\n break;\n default:\n msg = null;\n \tbreak;\n}\n\nnode.warn(context.data)\n\n\nif(context.data.shield < context.data.shoot && context.data.shield < context.data.charge){\n var result = {userId: msg.parts.userId, action: \"Shield\"};\n}\n\nelse if(context.data.shoot < context.data.charge){\n var result = {userId: msg.parts.userId, action: \"Shoot\"};\n}\nelse {\n var result = {userId: msg.parts.userId, action: \"Charge\"};\n}\n\nreturn result;\n\n","outputs":1,"noerr":0,"x":1629.7673568725586,"y":129.51042556762695,"wires":[[]]},{"id":"75209bff.c4c7b4","type":"function","z":"fc352090.50f96","name":"","func":"node.warn(msg.parts)\nnode.warn(msg)\nmsg.payload.parts = msg.parts\nreturn msg;","outputs":1,"noerr":0,"x":1609.9410552978516,"y":592.5903091430664,"wires":[["2b18c51b.28107a"]]},{"id":"5f42d946.22daf8","type":"template","z":"fc352090.50f96","name":"","field":"payload","fieldType":"msg","format":"html","syntax":"mustache","template":"<html>\n\n<head>\n <style>\n body{\n background: url(https://s3.envato.com/files/165244545/background.jpg);\n }\n canvas {\n height: 100%;\n width: 49%;\n border: 1px solid #000000;\n }\n </style>\n</head>\n\n<body>\n <img id=\"fondo\" src=\"https://s3.envato.com/files/165244545/background.jpg\" style=\"display: none\"/>\n <img id=\"bullet\" src=\"https://image.flaticon.com/icons/png/128/224/224679.png\" style=\"display:none\" />\n <img id=\"heart\" src=\" https://images.emojiterra.com/emojione/v3/128px/2764.png\" style=\"display:none\" />\n <canvas id=\"player1\"></canvas>\n <canvas id=\"player2\"></canvas>\n <button onclick=\"reloadPlayer1()\">Recargar</button>\n <button onclick=\"hitPlayer2()\">Disparar al jugador 2</button>\n <button onclick=\"player1Shoot()\">Disparar</button>\n \n \n\n\n <script>\n \n var loc = window.location;\n console.log(loc);\n if (loc.protocol === \"https:\") { wsUri = \"wss:\"; }\n // This needs to point to the web socket in the Node-RED flow\n // ... in this case it's ws/simple\n wsUri += \"//\" + loc.host + loc.pathname.replace(\"page\",\"ws/socket\");\n let ws = new WebSocket(wsUri);\n ws.onmessage = function(s) {\n console.log(s)\n }\n\n //let socket = new WebSocket('wss://hackathon-jorge.mybluemix.net/socket', {secure: true})\n //socket.onmessage = function(s) {\n // alert('hey')\n //}\n let canvas1 = document.getElementById(\"player1\");\n let canvas2 = document.getElementById(\"player2\");\n let bullet = document.getElementById(\"bullet\");\n\n let ctx1 = canvas1.getContext(\"2d\");\n let ctx2 = canvas2.getContext(\"2d\");\n\n\n\n let game = new Game(canvas1, canvas2);\n game.play();\n\n function reloadPlayer1(){\n game.player1.reload();\n game.update();\n }\n\n function hitPlayer2(){\n game.player2.hitted();\n game.update();\n }\n\n function player1Shoot(){\n game.player1.shoot();\n game.update();\n }\n\n function Game(canvas1, canvas2) {\n this.player1 = new Player(canvas1);\n this.player2 = new Player(canvas2);\n\n this.play = function () {\n //while(this.player1.isAlive() && this.player2.isAlive()){\n this.update();\n }\n\n this.update = function(){\n this.player1.show();\n this.player2.show();\n }\n }\n\n\n function Player(canvas) {\n this.bullets = [new Bullet(0), new Bullet(20), new Bullet(40)];\n this.lifes = [new Life(canvas.width-50), new Life(canvas.width-100), new Life(canvas.width-150)];\n this.ctx = canvas.getContext(\"2d\");\n \n this.show = function(){\n for(let bullet of this.bullets){\n bullet.show(this.ctx);\n } \n\n console.log(this.lifes)\n for(let life of this.lifes){\n life.show(this.ctx)\n }\n }\n\n this.show();\n\n this.hitted = function () {\n if(this.lifes.length <= 0){\n alert(\"Has perdido\");\n return;\n }\n this.lifes[this.lifes.length-1].remove(this.ctx);\n this.lifes.splice(this.lifes.length-1, 1);\n this.show();\n }\n\n this.reload = function () {\n if (this.bullets.length >= 5)\n return;\n\n this.bullets.push(new Bullet(this.bullets.length * 20))\n this.show();\n }\n\n this.shoot = function(){\n if(this.bullets.length <= 0){\n alert(\"No tienes balas\");\n return;\n }\n this.bullets[this.bullets.length-1].remove(this.ctx);\n this.bullets.splice(this.bullets.length-1, 1);\n this.show();\n }\n this.isAlive = function () {\n return this.lifes > 0;\n }\n }\n\n\n function Bullet(x) {\n this.x = x;\n this.y = 5;\n this.bulletImg = document.getElementById(\"bullet\");\n\n\n this.show = function(ctx){\n ctx.drawImage(this.bulletImg, this.x, this.y, this.bulletImg.width * 0.3, this.bulletImg.height * 0.1);\n }\n\n this.remove = function(ctx){\n let img = ctx.createImageData(this.bulletImg.width * 0.3, this.bulletImg.height * 0.1);\n for(let i=img.data.length; --i>=0;){\n img.data[i] = 0;\n }\n ctx.putImageData(img, this.x, this.y);\n }\n }\n\n function Life(x){\n this.x = x;\n this.y = 5;\n this.heartImg = document.getElementById(\"heart\");\n\n this.show = function(ctx){\n ctx.drawImage(this.heartImg, this.x, this.y, this.heartImg.width * 0.3, this.heartImg.height * 0.1);\n }\n\n this.remove = function(ctx){\n let img = ctx.createImageData(this.heartImg.width * 0.3, this.heartImg.height * 0.1);\n for(let i=img.data.length; --i>=0;){\n img.data[i] = 0;\n }\n ctx.putImageData(img, this.x, this.y);\n }\n }\n\n </script>\n</body>\n\n\n</html>","output":"str","x":1540.9343032836914,"y":738.5661449432373,"wires":[["5152d75c.6fb718"]]},{"id":"738e7b00.0e5454","type":"http in","z":"fc352090.50f96","name":"","url":"/page","method":"get","upload":false,"swaggerDoc":"","x":1236.25,"y":715,"wires":[["5f42d946.22daf8"]]},{"id":"5152d75c.6fb718","type":"http response","z":"fc352090.50f96","name":"","statusCode":"","headers":{},"x":1720.0000228881836,"y":745.0000104904175,"wires":[]},{"id":"2b18c51b.28107a","type":"websocket out","z":"fc352090.50f96","name":"socket","server":"19ad7f49.36ec61","client":"","x":1793.7500267028809,"y":583.7500095367432,"wires":[]},{"id":"28eb81b2.306f6e","type":"debug","z":"fc352090.50f96","name":"","active":true,"console":"false","complete":"data","x":1757.38671875,"y":675.1796875,"wires":[]},{"id":"88d63169.2726","type":"websocket in","z":"fc352090.50f96","name":"","server":"19ad7f49.36ec61","client":"","x":1603.3828125,"y":679.828125,"wires":[["28eb81b2.306f6e"]]},{"id":"b2811b5b.18a588","type":"ibmiot","z":"","name":"iot key Hackathon","keepalive":"60","serverName":"","cleansession":true,"appId":"","shared":true},{"id":"19ad7f49.36ec61","type":"websocket-listener","z":"","path":"/ws/socket","wholemsg":"false"}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement