SlideShare a Scribd company logo
Html5 Game + Websocket + Arduino
Andrea D’Ippolito + Giuseppe Modarelli
Html5 game, websocket e arduino
Phaser.io 101
Javascript Game Development Engine
Phaser.io
var game = new Phaser.Game(1200, 600, Phaser.AUTO);
game.state.add('boot', BootState);
game.state.add('preload', PreloadState);
game.state.add('menu', MenuState);
game.state.add('play', PlayState);
game.state.add('finish', FinishState);
game.state.start('boot');
Phaser.io
{
preload: function() {
...
},
create: function() {
...
},
update: function() {
...
}
}
Phaser.io
{
preload: function() {
...
this.load.image('sky', 'assets/sky.png');
this.load.image('cloud1', 'assets/cloud1.png');
this.load.image('cloud2', 'assets/cloud2.png');
this.load.image('ground', 'assets/ground.png');
this.load.image('home', 'assets/home.png');
this.load.image('startButton', 'assets/start.png');
this.load.spritesheet('monk', 'assets/monk.png', 80, 103);
...
},
create: function() {
...
},
update: function() {
...
}
}
credits: Emanuela Oliva. emanuelaoliva.com
Phaser.io
{
preload: function() {
...
},
create: function() {
...
this.player = this.game.add.sprite(560, this.game.world.height - 150, 'monk');
this.game.physics.arcade.enable(this.player);
this.player.body.bounce.y = 0.35;
this.player.body.gravity.y = -15;
this.player.body.collideWorldBounds = true;
this.player.animations.add('left', [3, 4], 10, true);
this.player.animations.add('right', [0, 1], 10, true);
this.cursors = this.game.input.keyboard.createCursorKeys();
this.game.camera.follow(this.player);
...
},
update: function() {
...
}
}
Phaser.io
{
preload: function() {
...
},
create: function() {
...
},
update: function() {
...
if (this.cursors.left.isDown) {
this.player.animations.play('left');
this.player.body.velocity.x = -75;
} else if (this.cursors.right.isDown) {
this.player.animations.play('right');
this.player.body.velocity.y = 75;
} else {
this.player.animations.stop();
this.player.frame = 2;
}
...
}
}
Socket.io 101
Websocket connection for real time pub/sub messaging
Socket.io
var express = require('express');
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
io.on('connection', function(socket) {
socket.on('controls', function(msg) {
socket.broadcast.emit(msg);
});
socket.on('finish', function(msg) {
socket.broadcast.emit('you won');
});
socket.on('controller', function(msg) {
socket.broadcast.emit('controller connected', msg);
});
});
http.listen(3000, function() {
console.log('Listening on port %d', http.address().port);
});
Socket.io
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
</head>
<body>
<button id="left">Turn Left</button><button id="right">Turn Right</button>
<script>
var socket = io();
socket.emit( 'controller', 'HTML5 Gamepad' );
$(function(){
$('#left').click(function() {
socket.emit( 'controls', 'turn left');
});
$('#right').click(function() {
socket.emit( 'controls', 'turn right');
});
});
socket.on( 'you won', function(mgs) {
window.location.href = 'http://www.wearemonk.com' ;
});
</script>
</body>
</html>
Phaser.io + Socket.io
{
preload: function() {
...
},
create: function() {
...
this.socket = io();
var self = this;
this.socket.on('turn left', function(msg) {
self.turnLeft();
});
this.socket.on('turn right', function(msg) {
self.turnRight();
});
...
},
update: function() {
...
}
}
Arduino 101
Sketch Arduino per accendere un led con un bottone
Arduino
Arduino
const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 4; // the number of the LED pin
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input:
}
void loop(){
buttonState = digitalRead(buttonPin); //read the state of the pushbutton
value
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH); // turn LED on:
}
else {
digitalWrite(ledPin, LOW); // turn LED off:
}
}
Noduino 101
Come controllare Arduino con Javascript (grazie a node e websocket)
Accendere un led con bottone
Noduino
var requirejs = require('requirejs');
requirejs.config({nodeRequire: require});
requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial',
'../public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) {
var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger);
Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
var led_4;
board.withLED({pin: 4}, function(err, LED) {
if (err) { return console.log(err); }
led_4 = LED;
led_4.on('on',function(){
setTimeout(function () {
led_4.setOff();
}, 250);
});
});
board.withButton({pin: 3}, function(err, Button) {
if (err) { return console.log(err); }
Button.on('push', function() {
console.log('Button pushed');
led_4.setOn();
});
});
});
});
Noduino
var requirejs = require('requirejs');
var socket = require('socket.io-client')('http://localhost:3000');
requirejs.config({nodeRequire: require});
requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '..
/public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) {
var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger);
Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
var led_4;
board.withLED({pin: 4}, function(err, LED) {
if (err) { return console.log(err); }
led_4 = LED;
led_4.on('on',function(){
setTimeout(function () {
led_4.setOff();
}, 250);
});
});
board.withButton({pin: 3}, function(err, Button) {
if (err) { return console.log(err); }
Button.on('push', function() {
console.log('Button pushed');
led_4.setOn();
socket.emit('controls','turn left');
});
});
});
});
Noduino
var requirejs = require('requirejs');
var socket = require('socket.io-client')('http://localhost:3000');
requirejs.config({nodeRequire: require});
requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '..
/public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) {
var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger);
Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
var led_4;
board.withLED({pin: 4}, function(err, LED) {
[...]
});
board.withButton({pin: 3}, function(err, Button) {
if (err) { return console.log(err); }
Button.on('push', function() {
console.log('Button pushed');
led_4.setOn();
socket.emit('controls','turn left');
});
});
socket.on('you won', function(msg){
console.log("YOU WON");
setInterval(function () {
led_7.blink(250);
led_4.blink(250);
}, 500);
});
});
});
Noduino
var requirejs = require('requirejs');
var socket = require('socket.io-client')('http://localhost:3000');
requirejs.config({nodeRequire: require});
requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '..
/public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) {
var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger);
Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
var board_serial = board.c.boards[0].serial.path;
socket.emit('controller','Arduino: '+board_serial);
var led_4;
board.withLED({pin: 4}, function(err, LED) {
[...]
});
board.withButton({pin: 3}, function(err, Button) {
if (err) { return console.log(err); }
Button.on('push', function() {
console.log('Button pushed');
led_4.setOn();
socket.emit('controls','turn left');
});
});
socket.on('you won', function(msg){
[...]
});
});
});
recap @ wcap
● 404 Game: http://bit.ly/rescuemonk
● Noduino Gamepad: http://bit.ly/noduino-gamepad
● Phaser.io: http://phaser.io
● Socket.io: http://socket.io/
● Arduino: www.arduino.cc
○ Button: http://arduino.cc/en/tutorial/button
● Noduino: http://semu.github.io/noduino/
● Andrea: @adedip / andreadippolito.it
● Giuseppe: @gmodarelli / gmodarelli.com
www.monksoftware.it
info@monksoftware.it
Twitter: @monksoftwareit
Facebook: MONKSoftwareIT
Roma
Via Tirone 11, 00146
+39 06 99291819
Kraków
ul. Rakowicka 11, 30-033
+48 888 565 545

More Related Content

PDF
Html5 game, websocket e arduino
PDF
The Ring programming language version 1.7 book - Part 50 of 196
PDF
Game Development with SDL and Perl
PDF
Game Development using SDL and the PDK
PDF
망고100 보드로 놀아보자 15
PDF
The Ring programming language version 1.6 book - Part 61 of 189
PDF
Rootkit on Linux X86 v2.6
PDF
Videogiochi in PHP 👾
Html5 game, websocket e arduino
The Ring programming language version 1.7 book - Part 50 of 196
Game Development with SDL and Perl
Game Development using SDL and the PDK
망고100 보드로 놀아보자 15
The Ring programming language version 1.6 book - Part 61 of 189
Rootkit on Linux X86 v2.6
Videogiochi in PHP 👾

What's hot (20)

PDF
The Ring programming language version 1.10 book - Part 70 of 212
ODP
SDL2 Game Development VT Code Camp 2013
PDF
Gabriele Lana - The Magic of Elixir
PDF
Cross-platform game engine development with SDL 2.0
PDF
The Ring programming language version 1.4.1 book - Part 15 of 31
PDF
Mdp plus 2.1
PDF
The Ring programming language version 1.5 book - Part 9 of 31
PDF
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
PDF
The Ring programming language version 1.8 book - Part 56 of 202
PDF
Everything About Bluetooth (淺談藍牙 4.0) - Peripheral 篇
PPTX
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
PDF
Introduction to JavaFX 2
PPT
Ubiquitous Language
PDF
JavaFX, because you're worth it
PDF
Flow of events during Media Player creation in Android
PDF
DAHO.AM 2015 - Abusing phones to make the internet of things
PDF
67WS Seminar Event
PDF
First meet with Android Auto
PDF
The Ring programming language version 1.9 book - Part 80 of 210
PDF
The Ring programming language version 1.5.4 book - Part 87 of 185
The Ring programming language version 1.10 book - Part 70 of 212
SDL2 Game Development VT Code Camp 2013
Gabriele Lana - The Magic of Elixir
Cross-platform game engine development with SDL 2.0
The Ring programming language version 1.4.1 book - Part 15 of 31
Mdp plus 2.1
The Ring programming language version 1.5 book - Part 9 of 31
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
The Ring programming language version 1.8 book - Part 56 of 202
Everything About Bluetooth (淺談藍牙 4.0) - Peripheral 篇
Games, AI, and Research - Part 2 Training (FightingICE AI Programming)
Introduction to JavaFX 2
Ubiquitous Language
JavaFX, because you're worth it
Flow of events during Media Player creation in Android
DAHO.AM 2015 - Abusing phones to make the internet of things
67WS Seminar Event
First meet with Android Auto
The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.5.4 book - Part 87 of 185
Ad

Viewers also liked (20)

PDF
HTML5 e Css3 - 1 | WebMaster & WebDesigner
PPT
SMAU 2009 - Scenari futuri del Video-on-the-Web in HTML 5 - Roberto Ellero, ...
ODP
Introduzione a Twitter Bootstrap
PDF
Html5 - Un anno dopo
PDF
HTML5 e Css3 - 4 | WebMaster & WebDesigner
PPTX
Responsive design
ODP
PDF
HTML5 Security
PDF
HTML5 e Css3 - 3 | WebMaster & WebDesigner
PDF
Laboratorio di Web Design Base - 2014/15 - HTML/5
PPT
Introduzione a jQuery
PDF
PDF
Html e Css - 3 | WebMaster & WebDesigner
PPTX
Html5 e css3 nuovi strumenti per un nuovo web
PDF
HTML5 e Css3 - 3 | WebMaster & WebDesigner
PDF
follow-ap DAY 4: HTML5 e jQuery
PPTX
HTML 5 e browser legacy
KEY
HTML5 Forms: Cosa possiamo fare Oggi
PDF
Ancora anatomia, le pagine HTML(5)
PPTX
HTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore Romeo
HTML5 e Css3 - 1 | WebMaster & WebDesigner
SMAU 2009 - Scenari futuri del Video-on-the-Web in HTML 5 - Roberto Ellero, ...
Introduzione a Twitter Bootstrap
Html5 - Un anno dopo
HTML5 e Css3 - 4 | WebMaster & WebDesigner
Responsive design
HTML5 Security
HTML5 e Css3 - 3 | WebMaster & WebDesigner
Laboratorio di Web Design Base - 2014/15 - HTML/5
Introduzione a jQuery
Html e Css - 3 | WebMaster & WebDesigner
Html5 e css3 nuovi strumenti per un nuovo web
HTML5 e Css3 - 3 | WebMaster & WebDesigner
follow-ap DAY 4: HTML5 e jQuery
HTML 5 e browser legacy
HTML5 Forms: Cosa possiamo fare Oggi
Ancora anatomia, le pagine HTML(5)
HTML5 Italy: Mai più CSS, fogli di stile moderni con LESS - Salvatore Romeo
Ad

Similar to Html5 game, websocket e arduino (20)

KEY
Android and Arduio mixed with Breakout js
PDF
Building Droids with JavaScript
PPTX
Bare metal Javascript & GPIO programming in Linux
PDF
Little bits & node.js IOT for beginner
PDF
NodeMCU 0.9 Manual using Arduino IDE
PDF
Nodebot: Arte de controlar arduino com javascript
PDF
Survey_Paper
PPTX
Introduction to Node MCU
PDF
Iot 101
PPTX
Controlling robots using javascript
PDF
02 Sensors and Actuators Understand .pdf
PDF
Hardware Hacking for JavaScript Engineers
PDF
មេរៀនទីd៥ conneeeection with Arduino .pdf
PDF
Arduino Teaching Program
PDF
Webduino introduction
PPTX
Using arduino and raspberry pi for internet of things
PDF
Why use JavaScript in Hardware? GoTo Conf - Berlin
PPTX
Arduino Nodebots (Hackster CascadiaJS Workshop)
PPTX
Arduino Slides With Neopixels
PDF
Raspberry Pi IoT Stacks
Android and Arduio mixed with Breakout js
Building Droids with JavaScript
Bare metal Javascript & GPIO programming in Linux
Little bits & node.js IOT for beginner
NodeMCU 0.9 Manual using Arduino IDE
Nodebot: Arte de controlar arduino com javascript
Survey_Paper
Introduction to Node MCU
Iot 101
Controlling robots using javascript
02 Sensors and Actuators Understand .pdf
Hardware Hacking for JavaScript Engineers
មេរៀនទីd៥ conneeeection with Arduino .pdf
Arduino Teaching Program
Webduino introduction
Using arduino and raspberry pi for internet of things
Why use JavaScript in Hardware? GoTo Conf - Berlin
Arduino Nodebots (Hackster CascadiaJS Workshop)
Arduino Slides With Neopixels
Raspberry Pi IoT Stacks

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Digital-Transformation-Roadmap-for-Companies.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The AUB Centre for AI in Media Proposal.docx
“AI and Expert System Decision Support & Business Intelligence Systems”

Html5 game, websocket e arduino

  • 1. Html5 Game + Websocket + Arduino Andrea D’Ippolito + Giuseppe Modarelli
  • 3. Phaser.io 101 Javascript Game Development Engine
  • 4. Phaser.io var game = new Phaser.Game(1200, 600, Phaser.AUTO); game.state.add('boot', BootState); game.state.add('preload', PreloadState); game.state.add('menu', MenuState); game.state.add('play', PlayState); game.state.add('finish', FinishState); game.state.start('boot');
  • 5. Phaser.io { preload: function() { ... }, create: function() { ... }, update: function() { ... } }
  • 6. Phaser.io { preload: function() { ... this.load.image('sky', 'assets/sky.png'); this.load.image('cloud1', 'assets/cloud1.png'); this.load.image('cloud2', 'assets/cloud2.png'); this.load.image('ground', 'assets/ground.png'); this.load.image('home', 'assets/home.png'); this.load.image('startButton', 'assets/start.png'); this.load.spritesheet('monk', 'assets/monk.png', 80, 103); ... }, create: function() { ... }, update: function() { ... } }
  • 7. credits: Emanuela Oliva. emanuelaoliva.com
  • 8. Phaser.io { preload: function() { ... }, create: function() { ... this.player = this.game.add.sprite(560, this.game.world.height - 150, 'monk'); this.game.physics.arcade.enable(this.player); this.player.body.bounce.y = 0.35; this.player.body.gravity.y = -15; this.player.body.collideWorldBounds = true; this.player.animations.add('left', [3, 4], 10, true); this.player.animations.add('right', [0, 1], 10, true); this.cursors = this.game.input.keyboard.createCursorKeys(); this.game.camera.follow(this.player); ... }, update: function() { ... } }
  • 9. Phaser.io { preload: function() { ... }, create: function() { ... }, update: function() { ... if (this.cursors.left.isDown) { this.player.animations.play('left'); this.player.body.velocity.x = -75; } else if (this.cursors.right.isDown) { this.player.animations.play('right'); this.player.body.velocity.y = 75; } else { this.player.animations.stop(); this.player.frame = 2; } ... } }
  • 10. Socket.io 101 Websocket connection for real time pub/sub messaging
  • 11. Socket.io var express = require('express'); var app = express(); var http = require('http').Server(app); var io = require('socket.io')(http); io.on('connection', function(socket) { socket.on('controls', function(msg) { socket.broadcast.emit(msg); }); socket.on('finish', function(msg) { socket.broadcast.emit('you won'); }); socket.on('controller', function(msg) { socket.broadcast.emit('controller connected', msg); }); }); http.listen(3000, function() { console.log('Listening on port %d', http.address().port); });
  • 12. Socket.io <!doctype html> <html lang="en"> <head> <script type="text/javascript" src="/socket.io/socket.io.js"></script> </head> <body> <button id="left">Turn Left</button><button id="right">Turn Right</button> <script> var socket = io(); socket.emit( 'controller', 'HTML5 Gamepad' ); $(function(){ $('#left').click(function() { socket.emit( 'controls', 'turn left'); }); $('#right').click(function() { socket.emit( 'controls', 'turn right'); }); }); socket.on( 'you won', function(mgs) { window.location.href = 'http://www.wearemonk.com' ; }); </script> </body> </html>
  • 13. Phaser.io + Socket.io { preload: function() { ... }, create: function() { ... this.socket = io(); var self = this; this.socket.on('turn left', function(msg) { self.turnLeft(); }); this.socket.on('turn right', function(msg) { self.turnRight(); }); ... }, update: function() { ... } }
  • 14. Arduino 101 Sketch Arduino per accendere un led con un bottone
  • 16. Arduino const int buttonPin = 3; // the number of the pushbutton pin const int ledPin = 4; // the number of the LED pin int buttonState = 0; // variable for reading the pushbutton status void setup() { pinMode(ledPin, OUTPUT); // initialize the LED pin as an output: pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input: } void loop(){ buttonState = digitalRead(buttonPin); //read the state of the pushbutton value // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); // turn LED on: } else { digitalWrite(ledPin, LOW); // turn LED off: } }
  • 17. Noduino 101 Come controllare Arduino con Javascript (grazie a node e websocket) Accendere un led con bottone
  • 18. Noduino var requirejs = require('requirejs'); requirejs.config({nodeRequire: require}); requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '../public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) { var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger); Noduino.connect(function(err, board) { if (err) { return console.log(err); } var led_4; board.withLED({pin: 4}, function(err, LED) { if (err) { return console.log(err); } led_4 = LED; led_4.on('on',function(){ setTimeout(function () { led_4.setOff(); }, 250); }); }); board.withButton({pin: 3}, function(err, Button) { if (err) { return console.log(err); } Button.on('push', function() { console.log('Button pushed'); led_4.setOn(); }); }); }); });
  • 19. Noduino var requirejs = require('requirejs'); var socket = require('socket.io-client')('http://localhost:3000'); requirejs.config({nodeRequire: require}); requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '.. /public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) { var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger); Noduino.connect(function(err, board) { if (err) { return console.log(err); } var led_4; board.withLED({pin: 4}, function(err, LED) { if (err) { return console.log(err); } led_4 = LED; led_4.on('on',function(){ setTimeout(function () { led_4.setOff(); }, 250); }); }); board.withButton({pin: 3}, function(err, Button) { if (err) { return console.log(err); } Button.on('push', function() { console.log('Button pushed'); led_4.setOn(); socket.emit('controls','turn left'); }); }); }); });
  • 20. Noduino var requirejs = require('requirejs'); var socket = require('socket.io-client')('http://localhost:3000'); requirejs.config({nodeRequire: require}); requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '.. /public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) { var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger); Noduino.connect(function(err, board) { if (err) { return console.log(err); } var led_4; board.withLED({pin: 4}, function(err, LED) { [...] }); board.withButton({pin: 3}, function(err, Button) { if (err) { return console.log(err); } Button.on('push', function() { console.log('Button pushed'); led_4.setOn(); socket.emit('controls','turn left'); }); }); socket.on('you won', function(msg){ console.log("YOU WON"); setInterval(function () { led_7.blink(250); led_4.blink(250); }, 500); }); }); });
  • 21. Noduino var requirejs = require('requirejs'); var socket = require('socket.io-client')('http://localhost:3000'); requirejs.config({nodeRequire: require}); requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '.. /public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) { var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger); Noduino.connect(function(err, board) { if (err) { return console.log(err); } var board_serial = board.c.boards[0].serial.path; socket.emit('controller','Arduino: '+board_serial); var led_4; board.withLED({pin: 4}, function(err, LED) { [...] }); board.withButton({pin: 3}, function(err, Button) { if (err) { return console.log(err); } Button.on('push', function() { console.log('Button pushed'); led_4.setOn(); socket.emit('controls','turn left'); }); }); socket.on('you won', function(msg){ [...] }); }); });
  • 22. recap @ wcap ● 404 Game: http://bit.ly/rescuemonk ● Noduino Gamepad: http://bit.ly/noduino-gamepad ● Phaser.io: http://phaser.io ● Socket.io: http://socket.io/ ● Arduino: www.arduino.cc ○ Button: http://arduino.cc/en/tutorial/button ● Noduino: http://semu.github.io/noduino/ ● Andrea: @adedip / andreadippolito.it ● Giuseppe: @gmodarelli / gmodarelli.com
  • 23. www.monksoftware.it info@monksoftware.it Twitter: @monksoftwareit Facebook: MONKSoftwareIT Roma Via Tirone 11, 00146 +39 06 99291819 Kraków ul. Rakowicka 11, 30-033 +48 888 565 545