SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
Html5 Game + Websocket + Arduino
Andrea D’Ippolito + Giuseppe Modarelli
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
● 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212The Ring programming language version 1.10 book - Part 70 of 212
The Ring programming language version 1.10 book - Part 70 of 212
 
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
Core Audio in iOS 6 (CocoaConf Chicago, March 2013)
 
SDL2 Game Development VT Code Camp 2013
SDL2 Game Development VT Code Camp 2013SDL2 Game Development VT Code Camp 2013
SDL2 Game Development VT Code Camp 2013
 
The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5 book - Part 9 of 31The Ring programming language version 1.5 book - Part 9 of 31
The Ring programming language version 1.5 book - Part 9 of 31
 
The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184The Ring programming language version 1.5.3 book - Part 46 of 184
The Ring programming language version 1.5.3 book - Part 46 of 184
 
Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0Cross-platform game engine development with SDL 2.0
Cross-platform game engine development with SDL 2.0
 
Introduction to JavaFX 2
Introduction to JavaFX 2Introduction to JavaFX 2
Introduction to JavaFX 2
 
The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88The Ring programming language version 1.3 book - Part 36 of 88
The Ring programming language version 1.3 book - Part 36 of 88
 
Gabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirGabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of Elixir
 
Flow of events during Media Player creation in Android
Flow of events during Media Player creation in AndroidFlow of events during Media Player creation in Android
Flow of events during Media Player creation in Android
 
The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202The Ring programming language version 1.8 book - Part 56 of 202
The Ring programming language version 1.8 book - Part 56 of 202
 
JavaFX, because you're worth it
JavaFX, because you're worth itJavaFX, because you're worth it
JavaFX, because you're worth it
 
67WS Seminar Event
67WS Seminar Event67WS Seminar Event
67WS Seminar Event
 
Ubiquitous Language
Ubiquitous LanguageUbiquitous Language
Ubiquitous Language
 
DAHO.AM 2015 - Abusing phones to make the internet of things
DAHO.AM 2015 - Abusing phones to make the internet of thingsDAHO.AM 2015 - Abusing phones to make the internet of things
DAHO.AM 2015 - Abusing phones to make the internet of things
 
5 Cool Things About PLSQL
5 Cool Things About PLSQL5 Cool Things About PLSQL
5 Cool Things About PLSQL
 
The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210The Ring programming language version 1.9 book - Part 80 of 210
The Ring programming language version 1.9 book - Part 80 of 210
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Java
 
The Ring programming language version 1.5.4 book - Part 87 of 185
The Ring programming language version 1.5.4 book - Part 87 of 185The Ring programming language version 1.5.4 book - Part 87 of 185
The Ring programming language version 1.5.4 book - Part 87 of 185
 
J2 me 07_5
J2 me 07_5J2 me 07_5
J2 me 07_5
 

Similar a Html5 game, websocket e arduino

Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
udit652068
 
Need help writing the code for a basic java tic tac toe game Tic.pdf
Need help writing the code for a basic java tic tac toe game Tic.pdfNeed help writing the code for a basic java tic tac toe game Tic.pdf
Need help writing the code for a basic java tic tac toe game Tic.pdf
hainesburchett26321
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
archanaemporium
 
Lab_5.txt.rtfLab_05Design an application that reads the .docx
Lab_5.txt.rtfLab_05Design an application that reads the .docxLab_5.txt.rtfLab_05Design an application that reads the .docx
Lab_5.txt.rtfLab_05Design an application that reads the .docx
DIPESH30
 
robotics presentation for a club you run
robotics presentation for a club you runrobotics presentation for a club you run
robotics presentation for a club you run
SunilAcharya37
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
anjandavid
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
rajkumarm401
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdf
aakarcreations1
 
Hello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdfHello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdf
jyothimuppasani1
 

Similar a Html5 game, websocket e arduino (20)

Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
Need help writing the code for a basic java tic tac toe game Tic.pdf
Need help writing the code for a basic java tic tac toe game Tic.pdfNeed help writing the code for a basic java tic tac toe game Tic.pdf
Need help writing the code for a basic java tic tac toe game Tic.pdf
 
[가상편] 하드웨어에 생명을 주는 아두이노
[가상편] 하드웨어에 생명을 주는 아두이노[가상편] 하드웨어에 생명을 주는 아두이노
[가상편] 하드웨어에 생명을 주는 아두이노
 
Arduino Workshop 2011.05.31
Arduino Workshop 2011.05.31Arduino Workshop 2011.05.31
Arduino Workshop 2011.05.31
 
Connecting your phone and home with firebase and android things - James Cogga...
Connecting your phone and home with firebase and android things - James Cogga...Connecting your phone and home with firebase and android things - James Cogga...
Connecting your phone and home with firebase and android things - James Cogga...
 
Programming simple games with a raspberry pi and
Programming simple games with a raspberry pi andProgramming simple games with a raspberry pi and
Programming simple games with a raspberry pi and
 
I dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdfI dont know what is wrong with this roulette program I cant seem.pdf
I dont know what is wrong with this roulette program I cant seem.pdf
 
Lab_5.txt.rtfLab_05Design an application that reads the .docx
Lab_5.txt.rtfLab_05Design an application that reads the .docxLab_5.txt.rtfLab_05Design an application that reads the .docx
Lab_5.txt.rtfLab_05Design an application that reads the .docx
 
robotics presentation for a club you run
robotics presentation for a club you runrobotics presentation for a club you run
robotics presentation for a club you run
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for Beginners
 
This is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdfThis is Java,I am currently stumped on how to add a scoreboard for.pdf
This is Java,I am currently stumped on how to add a scoreboard for.pdf
 
Arduino Boot Camp Pitch Slides
Arduino Boot Camp Pitch SlidesArduino Boot Camp Pitch Slides
Arduino Boot Camp Pitch Slides
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
 
Why am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdfWhy am I getting an out of memory error and no window of my .pdf
Why am I getting an out of memory error and no window of my .pdf
 
WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015WordPress Realtime - WordCamp São Paulo 2015
WordPress Realtime - WordCamp São Paulo 2015
 
R tist
R tistR tist
R tist
 
Praktek ARDUINO
Praktek ARDUINOPraktek ARDUINO
Praktek ARDUINO
 
Gatcha for developers
Gatcha for developersGatcha for developers
Gatcha for developers
 
S Console, Multi-Screen and Group Play
S Console, Multi-Screen and Group PlayS Console, Multi-Screen and Group Play
S Console, Multi-Screen and Group Play
 
Hello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdfHello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdf
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 

Html5 game, websocket e arduino

  • 1. Html5 Game + Websocket + Arduino Andrea D’Ippolito + Giuseppe Modarelli
  • 2.
  • 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 ● 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