-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial proof of concept - super sloppy, but it works
- Loading branch information
1 parent
2255254
commit 3a49cd5
Showing
8 changed files
with
248 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var port = process.env.PORT || 3000; | ||
var connect = require('connect'); | ||
var serveStatic = require('serve-static'); | ||
var server = connect().use(serveStatic(__dirname)).listen(port); | ||
|
||
|
||
// Connect to arduino | ||
var arduinoReady = false; | ||
var firmata = require('firmata'); | ||
var board = new firmata.Board('/dev/tty.usbmodem1411', function(){ | ||
isReady = true; | ||
board.pinMode(9,board.MODES.SERVO); | ||
}); | ||
|
||
|
||
// Handle socket events | ||
var io = require('socket.io')(server); | ||
|
||
io.on('connection', function(socket){ | ||
socket.on('hide-platform', function(){ | ||
if(arduinoReady) | ||
board.servoWrite(9,50); | ||
}); | ||
|
||
socket.on('show-platform', function(){ | ||
if(arduinoReady) | ||
board.servoWrite(9,25); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ "height":5, | ||
"layers":[ | ||
{ | ||
"data":[0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 8, 0, 0, 0, 0, 0, 0], | ||
"height":5, | ||
"name":"Tile Layer 1", | ||
"opacity":1, | ||
"type":"tilelayer", | ||
"visible":true, | ||
"width":5, | ||
"x":0, | ||
"y":0 | ||
}], | ||
"orientation":"orthogonal", | ||
"properties": | ||
{ | ||
|
||
}, | ||
"tileheight":50, | ||
"tilesets":[ | ||
{ | ||
"firstgid":1, | ||
"image":"..\/..\/..\/..\/Desktop\/starstruck 2\/tiles-1.png", | ||
"imageheight":64, | ||
"imagewidth":272, | ||
"margin":0, | ||
"name":"tiles-1", | ||
"properties": | ||
{ | ||
|
||
}, | ||
"spacing":0, | ||
"tileheight":16, | ||
"tilewidth":16 | ||
}], | ||
"tilewidth":50, | ||
"version":1, | ||
"width":5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ "height":5, | ||
"layers":[ | ||
{ | ||
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 0, 8, 0, 0, 0, 0, 0, 0], | ||
"height":5, | ||
"name":"Tile Layer 1", | ||
"opacity":1, | ||
"type":"tilelayer", | ||
"visible":true, | ||
"width":5, | ||
"x":0, | ||
"y":0 | ||
}], | ||
"orientation":"orthogonal", | ||
"properties": | ||
{ | ||
|
||
}, | ||
"tileheight":50, | ||
"tilesets":[ | ||
{ | ||
"firstgid":1, | ||
"image":"..\/..\/..\/..\/Desktop\/starstruck 2\/tiles-1.png", | ||
"imageheight":64, | ||
"imagewidth":272, | ||
"margin":0, | ||
"name":"tiles-1", | ||
"properties": | ||
{ | ||
|
||
}, | ||
"spacing":0, | ||
"tileheight":16, | ||
"tilewidth":16 | ||
}], | ||
"tilewidth":50, | ||
"version":1, | ||
"width":5 | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>hello phaser!</title> | ||
<script src='vendor/phaser/build/phaser.min.js'></script> | ||
<script src="/socket.io/socket.io.js"></script> | ||
<script src='index.js'></script> | ||
</head> | ||
<body style='padding:150px; background-color:black; margin: 150px;'> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
var socket = io(); | ||
|
||
var map; | ||
var layer; | ||
var player; | ||
var facing = 'left'; | ||
var jumpTimer = 0; | ||
var platformLayer; | ||
var outieLayer; | ||
var cursors; | ||
var jumpButton; | ||
var outieIsHidden = true; | ||
|
||
var preload = function(){ | ||
game.load.tilemap('platforms', 'assets/platforms.json', null, Phaser.Tilemap.TILED_JSON); | ||
game.load.tilemap('outie', 'assets/outie.json', null, Phaser.Tilemap.TILED_JSON); | ||
game.load.image('tiles-1', 'assets/tiles-1.png'); | ||
game.load.spritesheet('dude', 'assets/dude.png', 32, 48); | ||
}; | ||
|
||
|
||
var hidePlatform = function(){ | ||
socket.emit('hide-platform'); | ||
outieLayer.visible = false; | ||
}; | ||
|
||
var showPlatform = function(){ | ||
socket.emit('show-platform'); | ||
outieLayer.visible = true; | ||
}; | ||
|
||
|
||
var create = function(){ | ||
game.physics.startSystem(Phaser.Physics.ARCADE); | ||
game.stage.backgroundColor = '#000000'; | ||
|
||
game.physics.arcade.gravity.y = 250; | ||
|
||
player = game.add.sprite(32, 32, 'dude'); | ||
game.physics.enable(player, Phaser.Physics.ARCADE); | ||
|
||
player.body.bounce.y = 0.2; | ||
player.body.collideWorldBounds = true; | ||
player.body.setSize(20, 32, 5, 16); | ||
|
||
player.animations.add('left', [0, 1, 2, 3], 10, true); | ||
player.animations.add('turn', [4], 20, true); | ||
player.animations.add('right', [5, 6, 7, 8], 10, true); | ||
|
||
var platformMap = game.add.tilemap('platforms'); | ||
var outieMap = game.add.tilemap('outie'); | ||
platformMap.setCollisionByExclusion([ 13, 14, 15, 16, 46, 47, 48, 49, 50, 51 ]); | ||
outieMap.setCollisionByExclusion([ 13, 14, 15, 16, 46, 47, 48, 49, 50, 51 ]); | ||
platformMap.addTilesetImage('tiles-1'); | ||
outieMap.addTilesetImage('tiles-1'); | ||
|
||
platformLayer = platformMap.createLayer('Tile Layer 1'); | ||
outieLayer = outieMap.createLayer('Tile Layer 1'); | ||
platformLayer.debug=true; | ||
outieLayer.debug=true; | ||
outieLayer.visible = false; | ||
|
||
game.camera.follow(player); | ||
|
||
cursors = game.input.keyboard.createCursorKeys(); | ||
jumpButton = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); | ||
|
||
|
||
setInterval(function(){ | ||
outieIsHidden = !outieIsHidden; | ||
|
||
if(outieIsHidden) | ||
hidePlatform(); | ||
else | ||
showPlatform(); | ||
|
||
}, 5000); | ||
}; | ||
|
||
|
||
var update = function() { | ||
if(outieIsHidden) | ||
game.physics.arcade.collide(player, platformLayer); | ||
else | ||
game.physics.arcade.collide(player, outieLayer); | ||
|
||
player.body.velocity.x = 0; | ||
|
||
if (cursors.left.isDown){ | ||
player.body.velocity.x = -150; | ||
|
||
if (facing != 'left'){ | ||
player.animations.play('left'); | ||
facing = 'left'; | ||
} | ||
} else if (cursors.right.isDown){ | ||
player.body.velocity.x = 150; | ||
|
||
if (facing != 'right'){ | ||
player.animations.play('right'); | ||
facing = 'right'; | ||
} | ||
} else { | ||
if (facing != 'idle') { | ||
player.animations.stop(); | ||
|
||
if (facing == 'left') | ||
player.frame = 0; | ||
else | ||
player.frame = 5; | ||
|
||
facing = 'idle'; | ||
} | ||
} | ||
|
||
if (jumpButton.isDown && player.body.onFloor() && game.time.now > jumpTimer){ | ||
player.body.velocity.y = -250; | ||
jumpTimer = game.time.now + 750; | ||
} | ||
}; | ||
|
||
|
||
var game = new Phaser.Game( | ||
800, 600, Phaser.CANVAS, 'bizarrio', | ||
{ preload: preload, create: create, update: update } | ||
); |