SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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 212Mahmoud Samir Fayed
 
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)Chris Adamson
 
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 2013Eric Basile
 
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 31Mahmoud Samir Fayed
 
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 184Mahmoud Samir Fayed
 
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.0Leszek Godlewski
 
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 88Mahmoud Samir Fayed
 
Gabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirGabriele Lana - The Magic of Elixir
Gabriele Lana - The Magic of ElixirCodemotion
 
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 AndroidSomenath Mukhopadhyay
 
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 202Mahmoud Samir Fayed
 
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 thingsJan Jongboom
 
5 Cool Things About PLSQL
5 Cool Things About PLSQL5 Cool Things About PLSQL
5 Cool Things About PLSQLConnor McDonald
 
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 210Mahmoud Samir Fayed
 
Matching Game In Java
Matching Game In JavaMatching Game In Java
Matching Game In Javacmkandemir
 
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 185Mahmoud Samir Fayed
 

Was ist angesagt? (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
 

Ähnlich wie 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.pdfudit652068
 
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.pdfhainesburchett26321
 
[가상편] 하드웨어에 생명을 주는 아두이노
[가상편] 하드웨어에 생명을 주는 아두이노[가상편] 하드웨어에 생명을 주는 아두이노
[가상편] 하드웨어에 생명을 주는 아두이노Chiwon Song
 
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...DroidConTLV
 
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 andKellyn Pot'Vin-Gorman
 
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.pdfarchanaemporium
 
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 .docxDIPESH30
 
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 runSunilAcharya37
 
Arduino for Beginners
Arduino for BeginnersArduino for Beginners
Arduino for BeginnersSarwan Singh
 
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.pdfanjandavid
 
Arduino Boot Camp Pitch Slides
Arduino Boot Camp Pitch SlidesArduino Boot Camp Pitch Slides
Arduino Boot Camp Pitch SlidesMithi Sevilla
 
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.pdfrajkumarm401
 
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 .pdfaakarcreations1
 
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 2015Fernando Daciuk
 
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 PlayKyuho Kim
 
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.pdfjyothimuppasani1
 

Ähnlich wie 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
 

Kürzlich hochgeladen

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 

Kürzlich hochgeladen (20)

What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 

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