├── .gitignore ├── src ├── client │ ├── assets │ │ ├── favicon.ico │ │ ├── fonts │ │ │ ├── Mario.ttf │ │ │ ├── PipeDream.ttf │ │ │ └── PressStart2P.ttf │ │ ├── kirbySplash.png │ │ ├── marioSplash.png │ │ ├── readme │ │ │ ├── game.png │ │ │ ├── gamescreen.png │ │ │ ├── splashpage.png │ │ │ ├── controllers.jpg │ │ │ ├── controllers2.JPG │ │ │ └── megacontroller.png │ │ ├── marioLevel │ │ │ ├── box.png │ │ │ ├── ground.png │ │ │ ├── ledge.png │ │ │ ├── ledge2.png │ │ │ ├── pipe2.png │ │ │ ├── marioStar.png │ │ │ └── MarioLevelBackground.png │ │ ├── megamanSplash.png │ │ ├── pikachuSplash.png │ │ ├── sprites │ │ │ ├── mario2.png │ │ │ ├── megamanNew1.png │ │ │ ├── kirbySprite2.png │ │ │ └── pikachuSprite.png │ │ ├── main_background.png │ │ ├── player_selection2.png │ │ ├── weapons │ │ │ ├── bullet0.png │ │ │ ├── bullet1.png │ │ │ ├── bullet2.png │ │ │ └── bullet3.png │ │ ├── controller │ │ │ ├── left_button.png │ │ │ ├── mario_star.png │ │ │ ├── fire_button2.png │ │ │ ├── fire_button3.png │ │ │ ├── jump_button2.png │ │ │ ├── jump_button3.png │ │ │ ├── right_button.png │ │ │ ├── kirbyController.png │ │ │ ├── marioController.png │ │ │ ├── megamanController.png │ │ │ └── pikachuController.png │ │ ├── sounds │ │ │ ├── SuperMarioBros.mp3 │ │ │ └── Pacman-death-sound.mp3 │ │ └── css │ │ │ └── fonts.css │ ├── css │ │ ├── main.css │ │ └── controller.css │ ├── js │ │ ├── main.js │ │ ├── controller.js │ │ └── chars.js │ ├── layout.html │ ├── controller.html │ └── states │ │ ├── splash.js │ │ ├── gameover.js │ │ ├── game.js │ │ └── menu.js └── server │ ├── routes │ └── index.js │ └── app.js ├── package.json ├── README.md └── gulpfile.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | .DS_Store 3 | npm-debug.log 4 | -------------------------------------------------------------------------------- /src/client/assets/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/favicon.ico -------------------------------------------------------------------------------- /src/client/assets/fonts/Mario.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/fonts/Mario.ttf -------------------------------------------------------------------------------- /src/client/assets/kirbySplash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/kirbySplash.png -------------------------------------------------------------------------------- /src/client/assets/marioSplash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/marioSplash.png -------------------------------------------------------------------------------- /src/client/assets/readme/game.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/readme/game.png -------------------------------------------------------------------------------- /src/client/assets/marioLevel/box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/marioLevel/box.png -------------------------------------------------------------------------------- /src/client/assets/megamanSplash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/megamanSplash.png -------------------------------------------------------------------------------- /src/client/assets/pikachuSplash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/pikachuSplash.png -------------------------------------------------------------------------------- /src/client/assets/sprites/mario2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/sprites/mario2.png -------------------------------------------------------------------------------- /src/client/assets/fonts/PipeDream.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/fonts/PipeDream.ttf -------------------------------------------------------------------------------- /src/client/assets/main_background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/main_background.png -------------------------------------------------------------------------------- /src/client/assets/marioLevel/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/marioLevel/ground.png -------------------------------------------------------------------------------- /src/client/assets/marioLevel/ledge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/marioLevel/ledge.png -------------------------------------------------------------------------------- /src/client/assets/marioLevel/ledge2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/marioLevel/ledge2.png -------------------------------------------------------------------------------- /src/client/assets/marioLevel/pipe2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/marioLevel/pipe2.png -------------------------------------------------------------------------------- /src/client/assets/player_selection2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/player_selection2.png -------------------------------------------------------------------------------- /src/client/assets/readme/gamescreen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/readme/gamescreen.png -------------------------------------------------------------------------------- /src/client/assets/readme/splashpage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/readme/splashpage.png -------------------------------------------------------------------------------- /src/client/assets/weapons/bullet0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/weapons/bullet0.png -------------------------------------------------------------------------------- /src/client/assets/weapons/bullet1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/weapons/bullet1.png -------------------------------------------------------------------------------- /src/client/assets/weapons/bullet2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/weapons/bullet2.png -------------------------------------------------------------------------------- /src/client/assets/weapons/bullet3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/weapons/bullet3.png -------------------------------------------------------------------------------- /src/client/assets/fonts/PressStart2P.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/fonts/PressStart2P.ttf -------------------------------------------------------------------------------- /src/client/assets/readme/controllers.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/readme/controllers.jpg -------------------------------------------------------------------------------- /src/client/assets/readme/controllers2.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/readme/controllers2.JPG -------------------------------------------------------------------------------- /src/client/assets/sprites/megamanNew1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/sprites/megamanNew1.png -------------------------------------------------------------------------------- /src/client/assets/controller/left_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/left_button.png -------------------------------------------------------------------------------- /src/client/assets/controller/mario_star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/mario_star.png -------------------------------------------------------------------------------- /src/client/assets/marioLevel/marioStar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/marioLevel/marioStar.png -------------------------------------------------------------------------------- /src/client/assets/readme/megacontroller.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/readme/megacontroller.png -------------------------------------------------------------------------------- /src/client/assets/sounds/SuperMarioBros.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/sounds/SuperMarioBros.mp3 -------------------------------------------------------------------------------- /src/client/assets/sprites/kirbySprite2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/sprites/kirbySprite2.png -------------------------------------------------------------------------------- /src/client/assets/sprites/pikachuSprite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/sprites/pikachuSprite.png -------------------------------------------------------------------------------- /src/client/assets/controller/fire_button2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/fire_button2.png -------------------------------------------------------------------------------- /src/client/assets/controller/fire_button3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/fire_button3.png -------------------------------------------------------------------------------- /src/client/assets/controller/jump_button2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/jump_button2.png -------------------------------------------------------------------------------- /src/client/assets/controller/jump_button3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/jump_button3.png -------------------------------------------------------------------------------- /src/client/assets/controller/right_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/right_button.png -------------------------------------------------------------------------------- /src/client/assets/controller/kirbyController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/kirbyController.png -------------------------------------------------------------------------------- /src/client/assets/controller/marioController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/marioController.png -------------------------------------------------------------------------------- /src/client/assets/sounds/Pacman-death-sound.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/sounds/Pacman-death-sound.mp3 -------------------------------------------------------------------------------- /src/client/assets/controller/megamanController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/megamanController.png -------------------------------------------------------------------------------- /src/client/assets/controller/pikachuController.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/controller/pikachuController.png -------------------------------------------------------------------------------- /src/client/assets/marioLevel/MarioLevelBackground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KayTV/not-so-super-smash-bros/HEAD/src/client/assets/marioLevel/MarioLevelBackground.png -------------------------------------------------------------------------------- /src/server/routes/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | router.get('/', function(req, res, next) { 5 | res.render('index'); 6 | }); 7 | 8 | module.exports = router; 9 | -------------------------------------------------------------------------------- /src/client/assets/css/fonts.css: -------------------------------------------------------------------------------- 1 | @font-face { 2 | font-family: 'PressStart2P'; 3 | src: url('../fonts/PressStart2P.ttf'); 4 | } 5 | 6 | @font-face { 7 | font-family: 'Mario'; 8 | src: url('../fonts/Mario.ttf'); 9 | } 10 | 11 | @font-face { 12 | font-family: 'PipeDream'; 13 | src: url('../fonts/PipeDream.ttf'); 14 | } 15 | -------------------------------------------------------------------------------- /src/client/css/main.css: -------------------------------------------------------------------------------- 1 | @import url(https://fonts.googleapis.com/css?family=Press+Start+2P); 2 | 3 | body { 4 | padding: 50px; 5 | font-family: 25px "Press Start 2P", "Lucida Grande", Helvetica, Arial, sans-serif; 6 | display: flex; 7 | } 8 | 9 | a { 10 | color: #00B7FF; 11 | } 12 | 13 | canvas { 14 | margin: 0 auto; 15 | } 16 | -------------------------------------------------------------------------------- /src/client/css/controller.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: grey; 3 | /*margin-top: 5%;*/ 4 | font-family: 'Press Start 2P', cursive; 5 | } 6 | 7 | div { 8 | -webkit-touch-callout: none !important; 9 | -webkit-user-select: none 10 | } 11 | 12 | p { 13 | text-align: center; 14 | } 15 | 16 | #picture { 17 | text-align: center; 18 | } 19 | 20 | #picture img { 21 | height: 10%; 22 | width: 10%; 23 | } 24 | 25 | #firePowerUp { 26 | height: 20%; 27 | width: 20%; 28 | } 29 | -------------------------------------------------------------------------------- /src/client/js/main.js: -------------------------------------------------------------------------------- 1 | var socket = io(); 2 | 3 | var game = new Phaser.Game(800, 600, Phaser.AUTO, 'Not-So-Super-Smash'); 4 | 5 | function Main() {} 6 | 7 | Main.prototype = { 8 | preload: function() { 9 | game.load.image('load-bg', 'assets/main_background.png'); 10 | game.load.script('splash', 'states/splash.js'); 11 | }, 12 | create: function() { 13 | game.state.add('Splash', Splash); 14 | game.state.start('Splash'); 15 | } 16 | }; 17 | 18 | game.state.add('Main', Main); 19 | game.state.start('Main'); 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "_example", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./src/server/app.js" 7 | }, 8 | "dependencies": { 9 | "body-parser": "~1.13.2", 10 | "cookie-parser": "~1.3.5", 11 | "debug": "~2.2.0", 12 | "express": "~4.13.1", 13 | "morgan": "~1.6.1", 14 | "phaser": "^2.4.8", 15 | "serve-favicon": "~2.3.0", 16 | "socket.io": "^1.4.6", 17 | "swig": "^1.4.2" 18 | }, 19 | "devDependencies": { 20 | "browser-sync": "2.9.6", 21 | "gulp": "^3.9.0", 22 | "gulp-clean": "^0.3.1", 23 | "gulp-concat": "^2.6.0", 24 | "gulp-connect": "^2.2.0", 25 | "gulp-jshint": "^1.11.2", 26 | "gulp-minify-css": "^1.2.1", 27 | "gulp-nodemon": "^2.0.4", 28 | "gulp-uglify": "^1.4.2", 29 | "jshint-stylish": "^2.0.1", 30 | "run-sequence": "^1.1.4" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/client/layout.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Not So Super Smash Bros 6 | 7 | 8 | 9 | 14 | 15 | 16 | 17 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/client/controller.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | SuperSmash 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 |

Enter Your Game ID:

19 | 20 |
21 | 22 |
23 |
24 | 25 |
26 |
27 | 28 |
29 |
30 | 31 |
32 |
33 | 34 |
35 | 36 |
37 | 38 |
39 | 40 |
41 | 42 |
43 | 44 |
45 | 46 |
47 | 48 |
49 | 50 |
51 | 52 |
53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Not So Super Smash Bros

2 | 3 | Link to Game 4 | 5 |

Details:

6 |

Not So Super Smash Bros is a multiplayer game that mimics the Nintendo game of Super Smash Brothers. This game is built with socket.io and phaser.io. To play this game, you will need a few things:

7 | 12 |

You will then go to the link to the game on your computer and then each person will go to the same link on their phone as well. You will then on your computer click the 'HOST GAME' button and enter in the given number on your phone. Once you have more than one player, you can start the game! Each character has 100 HP points, whoever is the last one standing, wins! Remember to have fun!

13 | 14 |

*** For those of you that are unsure on what Super Smash Brothers is, it is a multiplayer fighting game. You battle against the other people in the game by shooting them with your weapon. The controller that will appear on your phone has 5 buttons, left arrow to move left, right arrow to move right, a jump button, a fire button that allows you to shoot your opponents, and a star button that gives you a power up. The power up will let you shoot in multiple directions.***

15 | 16 |

Star Button

17 |

Star button on your controller is your power up. Once you see your character change color of the game screen, your power up is activated. Press the star button to use it

18 | 19 |

Download

20 |

You must have node and gulp installed in order to download this game

21 |

To Download this game:

22 | 27 | 28 |

Controllers Layout:

29 |
30 | 31 | 32 | 33 |

Individual Controllers:

34 |
35 | 36 | 37 | 38 |

Game Character Screen:

39 |
40 | 41 | 42 | 43 |

Game Screen:

44 |
45 | 46 | 47 | -------------------------------------------------------------------------------- /src/client/js/controller.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function(){ 2 | $('#controls').hide(); 3 | var socket = io(); 4 | var right = false; 5 | var left = false; 6 | var jump = false; 7 | var fire = false; 8 | var player = null; 9 | var firePowerUp = false; 10 | var playerColor; 11 | var colors = ['#bf1313', '#1111bd', '#eac84d', '#11bd13' ]; 12 | var playerPic; 13 | var pic = ['../assets/controller/megamanController.png', '../assets/controller/kirbyController.png', '../assets/controller/pikachuController.png', '../assets/controller/marioController.png']; 14 | 15 | $('#join').on('click', function() { 16 | var gameRoom = $('#user-input').val(); 17 | socket.emit('new-player', {gameRoom: gameRoom}); 18 | 19 | socket.on('invalid-room', function() { 20 | $('#error').html('

Invalid Room

'); 21 | }) 22 | 23 | socket.on('success-join', function(playerNum) { 24 | if( playerNum <= 3) { 25 | console.log("PlayerNum:", playerNum); 26 | player = playerNum; 27 | 28 | playerColor = colors[playerNum]; 29 | playerPic = pic[playerNum]; 30 | $('body').css('background-color', playerColor); 31 | $('#picture').html(''); 32 | 33 | $('#game-room-input').hide(); 34 | $('#error').hide(); 35 | $('#controls').show(); 36 | setInterval(updateGame, 30); 37 | } 38 | }) 39 | socket.on('fail-join', function() { 40 | $('#error').html('

Too many players in room

'); 41 | }) 42 | }) 43 | 44 | document.fullscreenEnabled = document.fullscreenEnabled || document.mozFullScreenEnabled || document.documentElement.webkitRequestFullScreen; 45 | 46 | 47 | $('#move-right').on('touchstart', function(event){ 48 | event.preventDefault(); 49 | right = true; 50 | }); 51 | 52 | $('#move-right').on('touchend', function(event){ 53 | event.preventDefault(); 54 | right = false; 55 | }); 56 | 57 | $('#move-left').on('touchstart', function(event){ 58 | event.preventDefault(); 59 | left = true; 60 | }); 61 | 62 | $('#move-left').on('touchend', function(event){ 63 | event.preventDefault(); 64 | left = false; 65 | }); 66 | 67 | $('#jump').on('touchstart', function(event){ 68 | event.preventDefault(); 69 | jump = true; 70 | }); 71 | 72 | $('#jump').on('touchend', function(event){ 73 | event.preventDefault(); 74 | jump = false; 75 | }); 76 | 77 | $('#fire').on('touchstart', function(event){ 78 | event.preventDefault(); 79 | fire = true; 80 | }); 81 | 82 | $('#fire').on('touchend', function(event){ 83 | event.preventDefault(); 84 | fire = false; 85 | }); 86 | 87 | $('#firePowerUp').on('touchstart', function(event){ 88 | event.preventDefault(); 89 | firePowerUp = true; 90 | }); 91 | 92 | $('#firePowerUp').on('touchend', function(event){ 93 | event.preventDefault() 94 | firePowerUp = false; 95 | }); 96 | 97 | function updateGame() { 98 | // sends game-update to server with the players input and player number 99 | socket.emit('game-update', {right: right, left: left, jump: jump, fire: fire, player: player, firePowerUp: firePowerUp}); 100 | } 101 | }); 102 | -------------------------------------------------------------------------------- /src/client/states/splash.js: -------------------------------------------------------------------------------- 1 | function Splash() {}; 2 | // console.log("splash"); 3 | 4 | Splash.prototype = { 5 | loadScripts: function () { 6 | game.load.script('WebFont', 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.16/webfont.js'); 7 | game.load.script('menu', 'states/menu.js'); 8 | game.load.script('game', 'states/game.js'); 9 | game.load.script('gameover', 'states/gameover.js'); 10 | }, 11 | loadAssets: function () { 12 | // Map assets 13 | game.load.image('sky', 'assets/marioLevel/MarioLevelBackground.png'); 14 | game.load.image('ground', 'assets/marioLevel/ground.png'); 15 | game.load.image('move-box', 'assets/marioLevel/box.png'); 16 | game.load.image('box', 'assets/marioLevel/ledge2.png'); 17 | game.load.image('littlebox', 'assets/marioLevel/box.png'); 18 | game.load.image('pipe', 'assets/marioLevel/pipe2.png'); 19 | 20 | // Menu Assets 21 | game.load.image('menu', 'assets/main_background.png'); 22 | game.load.image('player-selection', 'assets/player_selection2.png'); 23 | 24 | //Character Pictures for Player Selection 25 | game.load.image('select0', 'assets/megamanSplash.png'); 26 | game.load.image('select1', 'assets/kirbySplash.png'); 27 | game.load.image('select2', 'assets/pikachuSplash.png'); 28 | game.load.image('select3', 'assets/marioSplash.png'); 29 | 30 | // Sprite Bullets 31 | game.load.image('bullet0', 'assets/weapons/bullet0.png'); 32 | game.load.image('bullet1', 'assets/weapons/bullet1.png'); 33 | game.load.image('bullet2', 'assets/weapons/bullet2.png'); 34 | game.load.image('bullet3', 'assets/weapons/bullet3.png'); 35 | 36 | // Sprites 37 | game.load.spritesheet('megaman0', 'assets/sprites/megamanNew1.png', 50, 48); 38 | game.load.spritesheet('kirby1', 'assets/sprites/kirbySprite2.png', 23, 22); 39 | game.load.spritesheet('pikachu2', 'assets/sprites/pikachuSprite.png', 30, 30); 40 | game.load.spritesheet('mario3', 'assets/sprites/mario2.png', 24, 38); 41 | 42 | //Audio 43 | game.load.audio('soundDie', 'assets/sounds/Pacman-death-sound.mp3'); 44 | game.load.audio('mainSound', 'assets/sounds/SuperMarioBros.mp3') 45 | 46 | }, 47 | loadFonts: function () { 48 | WebFontConfig = { 49 | custom: { 50 | families: ['PressStart2P', 'Mario', 'PipeDream'], 51 | urls: ['assets/css/fonts.css'] 52 | } 53 | }; 54 | }, 55 | init: function() { 56 | this.status = game.make.text(game.world.centerX, 380, 'Loading...', { 57 | fill: 'blue', 58 | font: '40px Mario'}); 59 | this.status.anchor.setTo(0.5); 60 | }, 61 | preload: function() { 62 | 63 | game.add.sprite(0, 0, 'load-bg'); 64 | game.add.existing(this.status); 65 | 66 | this.loadScripts(); 67 | this.loadAssets(); 68 | this.loadFonts(); 69 | }, 70 | addGameStates: function() { 71 | game.state.add('Menu', Menu); 72 | game.state.add('Game', Game); 73 | game.state.add('GameOver', GameOver); 74 | }, 75 | create: function () { 76 | this.addGameStates(); 77 | this.status.setText('Loading...'); 78 | 79 | setTimeout(function() { 80 | game.state.start('Menu'); 81 | }, 1000); 82 | } 83 | }; 84 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Module Dependencies 3 | */ 4 | 5 | var gulp = require('gulp'); 6 | var jshint = require('gulp-jshint'); 7 | var browserSync = require('browser-sync'); 8 | var reload = browserSync.reload; 9 | var nodemon = require('gulp-nodemon'); 10 | var connect = require('gulp-connect'); 11 | var uglify = require('gulp-uglify'); 12 | var minifyCSS = require('gulp-minify-css'); 13 | var clean = require('gulp-clean'); 14 | var concat = require('gulp-concat'); 15 | var runSequence = require('run-sequence'); 16 | 17 | 18 | /** 19 | * Config 20 | */ 21 | 22 | var paths = { 23 | styles: [ 24 | './src/client/css/*.css', 25 | ], 26 | scripts: [ 27 | './src/client/js/*.js', 28 | ], 29 | server: 30 | './src/server/app.js', 31 | distServer: [ 32 | './dist/server/bin/www' 33 | ] 34 | }; 35 | 36 | var nodemonConfig = { 37 | script: paths.server, 38 | ext: 'html js css', 39 | ignore: ['node_modules'] 40 | }; 41 | 42 | var nodemonDistConfig = { 43 | script: paths.distServer, 44 | ext: 'html js css', 45 | ignore: ['node_modules'] 46 | }; 47 | 48 | 49 | /** 50 | * Gulp Tasks 51 | */ 52 | 53 | gulp.task('lint', function() { 54 | return gulp.src(paths.scripts) 55 | .pipe(jshint()) 56 | .pipe(jshint.reporter('jshint-stylish')); 57 | }); 58 | 59 | gulp.task('browser-sync', ['nodemon'], function(done) { 60 | browserSync({ 61 | proxy: "localhost:3000", // local node app address 62 | port: 5000, // use *different* port than above 63 | notify: true 64 | }, done); 65 | }); 66 | 67 | gulp.task('nodemon', function (cb) { 68 | var called = false; 69 | return nodemon(nodemonConfig) 70 | .on('start', function () { 71 | if (!called) { 72 | called = true; 73 | cb(); 74 | } 75 | }) 76 | .on('restart', function () { 77 | setTimeout(function () { 78 | reload({ stream: false }); 79 | }, 1000); 80 | }); 81 | }); 82 | 83 | gulp.task('watch', function() { 84 | gulp.watch(paths.scripts, ['lint']); 85 | }); 86 | 87 | gulp.task('clean', function() { 88 | gulp.src('./dist/*') 89 | .pipe(clean({force: true})); 90 | }); 91 | 92 | gulp.task('minify-css', function() { 93 | var opts = {comments:true, spare:true}; 94 | gulp.src(paths.styles) 95 | .pipe(minifyCSS(opts)) 96 | .pipe(gulp.dest('./dist/client/css/')); 97 | }); 98 | 99 | gulp.task('minify-js', function() { 100 | gulp.src(paths.scripts) 101 | .pipe(uglify()) 102 | .pipe(gulp.dest('./dist/client/js/')); 103 | }); 104 | 105 | gulp.task('copy-server-files', function () { 106 | gulp.src('./src/server/**/*') 107 | .pipe(gulp.dest('./dist/server/')); 108 | }); 109 | 110 | 111 | gulp.task('connectDist', function (cb) { 112 | var called = false; 113 | return nodemon(nodemonDistConfig) 114 | .on('start', function () { 115 | if (!called) { 116 | called = true; 117 | cb(); 118 | } 119 | }) 120 | .on('restart', function () { 121 | setTimeout(function () { 122 | reload({ stream: false }); 123 | }, 1000); 124 | }); 125 | }); 126 | 127 | 128 | // *** default task *** // 129 | gulp.task('default', ['browser-sync', 'watch'], function(){}); 130 | 131 | // *** build task *** // 132 | gulp.task('build', function() { 133 | runSequence( 134 | ['clean'], 135 | ['lint', 'minify-css', 'minify-js', 'copy-server-files', 'connectDist'] 136 | ); 137 | }); 138 | -------------------------------------------------------------------------------- /src/client/states/gameover.js: -------------------------------------------------------------------------------- 1 | var characters = ['select0', 'select1', 'select2', 'select3']; 2 | var winningPlayer; 3 | var count = 0; 4 | this.winnerText; 5 | 6 | function GameOver () {}; 7 | 8 | GameOver.prototype = { 9 | init: function(winner, playerCount) { 10 | 11 | this.winner = winner; 12 | this.playerCount = playerCount; 13 | 14 | for (var i=0; i < characters.length; i++) { 15 | if (i === winner) { 16 | winningPlayer = characters[i]; 17 | } 18 | } 19 | 20 | this.titleText = game.make.text(game.world.centerX, 90, 'Not-So-Super\n Smash Bros.', { 21 | font: '60px PipeDream', 22 | align: 'center', 23 | }); 24 | this.titleText.addColor('blue', 0); 25 | this.titleText.addColor('black', 3); 26 | this.titleText.addColor('#fbcf08', 4); 27 | this.titleText.addColor('black', 6); 28 | this.titleText.addColor('#E42926', 7); 29 | this.titleText.addColor('#00c600', 12); 30 | this.titleText.addColor('#fbcf08', 18); 31 | this.titleText.anchor.setTo(0.5); 32 | this.titleText.setShadow(5, 5, 'rgba(0, 0, 0, 0.5)', 0); 33 | this.titleText.anchor.setTo(0.5); 34 | 35 | this.winnerText = game.make.text(game.world.centerX, 200, 'The winner is: ' , { 36 | font: '50px PipeDream', 37 | align: 'center', 38 | }); 39 | this.winnerText.anchor.setTo(0.5); 40 | 41 | }, 42 | create: function () { 43 | game.add.sprite(0, 0, 'menu'); 44 | game.add.existing(this.titleText); 45 | game.add.existing(this.winnerText); 46 | // Make sprite dynamic 47 | this.sprite = game.add.sprite(game.world.centerX, game.world.centerY, winningPlayer); 48 | this.sprite.scale.setTo(0.5); 49 | this.sprite.anchor.setTo(0.5); 50 | this.restartGame(); 51 | setInterval(timer, 800); 52 | }, 53 | restartGame: function () { 54 | var text = game.add.text(game.world.centerX, game.world.height * 0.7, 'Rematch?', { 55 | font: '50px PipeDream', 56 | align: 'center', 57 | fill: 'red' 58 | }); 59 | text.anchor.setTo(0.5); 60 | var hoverTrue = function (button) { 61 | button.fill = "#30DEF8"; 62 | button.stroke = "rgba(200, 200, 200, 0.5)"; 63 | }; 64 | var hoverFalse = function (button) { 65 | button.fill = 'red'; 66 | button.stroke = "rgba(0,0,0,0)"; 67 | }; 68 | var onClick = function () { 69 | mainSound.stop(); 70 | game.state.start('Game', true, false, this.playerCount); 71 | }.bind(this); 72 | 73 | text.stroke = "rgba(0,0,0,0)"; 74 | text.strokeThickness = 4; 75 | text.inputEnabled = true; 76 | text.events.onInputUp.add(onClick); 77 | text.events.onInputOver.add(hoverTrue); 78 | text.events.onInputOut.add(hoverFalse); 79 | }, 80 | preload: function () { 81 | 82 | }, 83 | update: function() { 84 | if (count === 0){ 85 | this.winnerText.addColor('red', 0); 86 | } 87 | if (count === 1) { 88 | this.winnerText.addColor('#fbcf08', 0); 89 | } 90 | if (count === 2) { 91 | this.winnerText.addColor('blue', 0); 92 | } 93 | if (count === 3) { 94 | this.winnerText.addColor('#E42926', 0); 95 | } 96 | if (count === 4){ 97 | this.winnerText.addColor('#00c600', 0); 98 | } 99 | } 100 | }; 101 | 102 | function timer () { 103 | if (count === 4) { 104 | count = 0; 105 | } 106 | count += 1; 107 | } 108 | -------------------------------------------------------------------------------- /src/server/app.js: -------------------------------------------------------------------------------- 1 | // *** main dependencies *** // 2 | var express = require('express'); 3 | var path = require('path'); 4 | var favicon = require('serve-favicon'); 5 | var logger = require('morgan'); 6 | var cookieParser = require('cookie-parser'); 7 | var bodyParser = require('body-parser'); 8 | 9 | // *** routes *** // 10 | var routes = require('./routes/index.js'); 11 | 12 | 13 | // *** express instance *** // 14 | var app = express(); 15 | 16 | app.set('port', process.env.PORT || 3000); 17 | 18 | var server = app.listen(app.get('port'), function() { 19 | console.log('Express server listening on port ' + server.address().port); 20 | }); 21 | // *** config middleware *** // 22 | app.use(logger('dev')); 23 | app.use(bodyParser.json()); 24 | app.use(bodyParser.urlencoded({ extended: false })); 25 | app.use(cookieParser()); 26 | app.use(express.static(path.join(__dirname, '../client'))); 27 | 28 | 29 | // *** main routes *** // 30 | app.get('/', function(req, res, next) { 31 | res.sendFile(path.join(__dirname, '../client/', 'layout.html')); 32 | }); 33 | 34 | app.get('/controller', function(req, res) { 35 | //Serve up phone page here. 36 | res.sendFile(path.join(__dirname, '../client', 'controller.html')); 37 | }); 38 | 39 | 40 | // *** SOCKET.IO *** // 41 | var io = require('socket.io').listen(server); 42 | var rooms = {}; 43 | 44 | io.on('connect', function(socket){ 45 | console.log('a user connected'); 46 | 47 | //connect new player to the room 48 | socket.on('new-player', function(data){ 49 | 50 | if (!rooms[data.gameRoom] || rooms[data.gameRoom].started) { 51 | console.log('invalid room'); 52 | socket.emit('invalid-room'); 53 | } else { 54 | console.log("Joined",data.gameRoom) 55 | socket.room = data.gameRoom; 56 | 57 | if (rooms[data.gameRoom].players) { 58 | rooms[data.gameRoom].players++; 59 | console.log("Players:",rooms[data.gameRoom].players) 60 | } else { 61 | rooms[data.gameRoom].players = 1; 62 | console.log("Players:",rooms[data.gameRoom].players) 63 | } 64 | console.log("Phone:", data.gameRoom); 65 | if(rooms[data.gameRoom].players < 5) { 66 | io.sockets.in(rooms[socket.room].id).emit('player-joined', rooms[data.gameRoom].players); 67 | 68 | var playerId = rooms[data.gameRoom].players - 1; 69 | socket.emit('success-join', playerId); 70 | } 71 | else { 72 | socket.emit('fail-join'); 73 | } 74 | if (rooms[data.gameRoom].players >= 1 && rooms[data.gameRoom].players < 5 ) { 75 | io.sockets.in(rooms[socket.room].id).emit('start-game'); 76 | } 77 | else { 78 | console.log('Error'); 79 | } 80 | } 81 | }); 82 | 83 | //updates game while being played 84 | socket.on('game-update', function(data) { 85 | if (rooms[socket.room]) { 86 | io.sockets.in(rooms[socket.room].id).emit('game-update', data); 87 | } 88 | // io.sockets.emit('game-update', data); 89 | }) 90 | 91 | // Check for 'create-game' emit 92 | socket.on('create-game', function(data) { 93 | if(!rooms[data.gameRoom]) { 94 | console.log('Creating game... GameRoom:', data.gameRoom) 95 | rooms[data.gameRoom] = {id: data.viewId}; 96 | rooms[data.gameRoom].started = false; 97 | socket.join(data.viewId); 98 | socket.emit('success-create', data); 99 | } else { 100 | console.log("Shit's broke server-side"); 101 | } 102 | }) 103 | 104 | // Check for 'start-game' emit 105 | socket.on('game-start', function(data) { 106 | console.log('GameRoom:', data.gameRoom); 107 | rooms[data.gameRoom].started = true; 108 | }) 109 | 110 | // Check for 'disconnect emit' 111 | socket.on('disconnect', function(){ 112 | console.log('user disconnected'); 113 | }); 114 | }); 115 | 116 | 117 | module.exports = server; 118 | -------------------------------------------------------------------------------- /src/client/states/game.js: -------------------------------------------------------------------------------- 1 | var players = []; 2 | var inputs = []; 3 | var ground; 4 | var platforms; 5 | var bullets; 6 | var dieSound; 7 | var mainSound; 8 | 9 | function Game () { 10 | this.playerCount; 11 | this.platforms; 12 | } 13 | 14 | 15 | function powerUp () { 16 | for (var i=0; i= 2) { 40 | this.startGameMenu(); 41 | } 42 | }.bind(this)); 43 | socket.on('success-create', function(data) { 44 | this.gameRoom = data.gameRoom; 45 | this.viewId = data.viewId; 46 | this.createMenu = this.addMenu(); 47 | }.bind(this)); 48 | }, 49 | // Function to add the menu to the game world 50 | addMenu: function() { 51 | var style = { 52 | font: '40px PipeDream', 53 | fill: 'blue', 54 | align: 'center', 55 | stroke: 'rgba(0,0,0,0)', 56 | strokeThickness: 4 57 | } 58 | 59 | var directionStyle = { 60 | font: '32px PipeDream', 61 | align: 'center', 62 | } 63 | 64 | var directions = game.add.text(game.world.centerX, 200, 'Directions: Go to this website on your phone, \n click HOST GAME and enter in the Game ID.', directionStyle); 65 | directions.addColor('blue', 0); 66 | directions.anchor.setTo(0.5, 0.5); 67 | 68 | var text = game.make.text(game.world.centerX, game.world.centerY, 'HOST GAME', style); 69 | text.anchor.setTo(0.5, 0.5); 70 | 71 | var hoverTrue = function (button) { 72 | button.fill = 'red'; 73 | button.stroke = 'rgba(200,200,200,0.5)'; 74 | } 75 | 76 | var hoverFalse = function (button) { 77 | button.fill = 'blue'; 78 | button.stroke = 'rgba(0,0,0,0)'; 79 | } 80 | 81 | var onClick = function (button) { 82 | var text = game.add.text(game.world.centerX, game.world.centerY + 15, 'Game ID: ' + this.gameRoom, { 83 | font: '40px PipeDream', 84 | fill: 'blue', 85 | align: 'center', 86 | stroke: 'rgba(0,0,0,0)', 87 | strokeThickness: 4 88 | }); 89 | text.anchor.setTo(0.5, 0.5); 90 | 91 | button.destroy(); 92 | }.bind(this); 93 | 94 | text.stroke = "rgba(0,0,0,0)"; 95 | text.strokeThickness = 4; 96 | text.inputEnabled = true; 97 | text.events.onInputUp.add(onClick); 98 | text.events.onInputOver.add(hoverTrue); 99 | text.events.onInputOut.add(hoverFalse); 100 | game.add.existing(text); 101 | return text; 102 | 103 | }, 104 | createGame: function () { 105 | // Make gameRoom 106 | var tempGameRoom = Math.floor((Math.random() * 100) + 100); 107 | 108 | // Set view ID 109 | var tempViewId = Math.floor((Math.random() * 100) + 100); 110 | 111 | // Emit 'create-game' to backend 112 | socket.emit('create-game', {gameRoom: tempGameRoom, viewId: tempViewId}) 113 | }, 114 | startGameMenu: function () { 115 | var style = { 116 | font: '50px PipeDream', 117 | fill: '#fbcf08', 118 | align: 'center', 119 | } 120 | 121 | var text = game.add.text(game.world.centerX, game.world.centerY - 35, 'Start Match', style); 122 | text.anchor.setTo(0.5,0.5); 123 | text.setShadow(5, 5, 'rgba(0, 0, 0, 0.5)', 0); 124 | 125 | var hoverTrue = function (button) { 126 | button.fill = '#00c600'; 127 | button.stroke = 'rgba(200,200,200,0.5)'; 128 | } 129 | 130 | var hoverFalse = function (button) { 131 | button.fill = '#fbcf08'; 132 | button.stroke = 'rgba(0,0,0,0)'; 133 | } 134 | 135 | var onClick = function () { 136 | socket.emit('game-start', {gameRoom: this.gameRoom}); 137 | game.state.start('Game', true, false, this.playerCount) 138 | }.bind(this); 139 | 140 | text.inputEnabled = true; 141 | text.events.onInputUp.add(onClick); 142 | text.events.onInputOver.add(hoverTrue); 143 | text.events.onInputOut.add(hoverFalse); 144 | 145 | 146 | }, 147 | 148 | addPlayerPic: function() { 149 | 150 | if (this.playerCount === 1) { 151 | this.mainBackground.kill(); 152 | game.stage.backgroundColor = '#6899F8'; 153 | 154 | waitingText = game.add.text(game.world.centerX, game.world.centerY - 25, 'Waiting for more players...', { 155 | font: '35px PipeDream', 156 | align: 'center', 157 | fill: 'red' 158 | }); 159 | waitingText.anchor.setTo(0.5); 160 | game.add.image(10, 320, 'player-selection'); 161 | var mega = game.add.sprite(0, 345, 'select0'); 162 | mega.scale.set(0.8, 0.8); 163 | } 164 | if(this.playerCount === 2) { 165 | var kirb = game.add.sprite(190, 350, 'select1'); 166 | kirb.scale.set(0.8, 0.8); 167 | removeText(); 168 | } 169 | if(this.playerCount === 3) { 170 | var pika = game.add.sprite(385, 350, 'select2'); 171 | pika.scale.set(0.8, 0.8); 172 | } 173 | if (this.playerCount === 4) { 174 | var mar = game.add.sprite(570, 345, 'select3'); 175 | mar.scale.set(0.8, 0.8); 176 | } 177 | 178 | }, 179 | 180 | 181 | preload: function() { 182 | this.playerCount; 183 | }, 184 | 185 | update: function() { 186 | 187 | 188 | } 189 | }; 190 | 191 | function removeText () { 192 | waitingText.destroy(); 193 | } 194 | -------------------------------------------------------------------------------- /src/client/js/chars.js: -------------------------------------------------------------------------------- 1 | var bulletTime = 0; 2 | var colors = [0xffff00, 0xffff00, 0xFF3F00, 0xFFE300] 3 | 4 | 5 | function bulletCollision (character, bullet) { 6 | if (bullet.playerId !== character.playerId && character.health > 0 ) { 7 | bullet.kill(); 8 | character.health -= 10; 9 | character.healthText.text = "P" + character.playerId + " HP:" + character.health; 10 | } 11 | } 12 | 13 | function bulletCollisionPlatform (platform, bullet) { 14 | bullet.kill(); 15 | } 16 | 17 | function resetPowerUp (player) { 18 | setTimeout(function() {player.powerUp = 0;}, 2000); 19 | } 20 | 21 | function Character (controller, platforms, bullets, superBullets, superBullets2, superBullets3) { 22 | var self = this; 23 | this.platforms = platforms; 24 | this.bullets = bullets; 25 | this.superBullets = superBullets; 26 | this.superBullets2 = superBullets2; 27 | this.superBullets3 = superBullets3; 28 | this.fireRate = 100; 29 | this.nextFire = 0; 30 | 31 | var x, y, character, left, right, jump; 32 | switch(controller) { 33 | case 0: 34 | x = 50; 35 | y = game.world.height - 150; 36 | character = 'megaman'; 37 | self.name = character; 38 | left = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 39 | right = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]; 40 | jumpRight = [33]; 41 | jumpLeft = [34]; 42 | // jump is a default below until code is written for jumpLeft and jumpRight 43 | jump = [33]; 44 | fireRight = [25, 26, 24]; 45 | fireLeft = [22, 21, 23]; 46 | fire = [25, 26, 24]; 47 | die = [29, 30, 29, 30, 29, 30]; 48 | stand = [10]; 49 | powerUp = [27]; 50 | scale = 1.5; 51 | xHP = 40; 52 | break; 53 | case 1: 54 | x = 100; 55 | y = game.world.height - 350; 56 | character = 'kirby'; 57 | left = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11]; 58 | right = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; 59 | jump = [10]; 60 | stand = [10]; 61 | fireRight = [21]; 62 | fireLeft = [22]; 63 | fire = [21]; 64 | die = [23, 23, 23, 23, 23, 23]; 65 | powerUp = [21]; 66 | scale = 2.3; 67 | xHP = 230; 68 | break; 69 | case 2: 70 | x = 600; 71 | y = game.world.height - 250; 72 | character = 'pikachu'; 73 | left = [0, 1, 2]; 74 | right = [8, 7, 6]; 75 | jump = [4]; 76 | fire = [11, 12]; 77 | fireRight = [12]; 78 | fireLeft = [13]; 79 | stand = [3]; 80 | powerUp = [5]; 81 | scale = 1.8; 82 | xHP = 430; 83 | die = [4, 4, 4, 4, 4, 4]; 84 | break; 85 | case 3: 86 | x = 600; 87 | y = game.world.height - 550; 88 | character = 'mario'; 89 | left = [0, 1, 2, 3, 5, 6, 7, 0]; 90 | right = [9, 10, 11, 12, 13, 14, 15]; 91 | jump = [17]; 92 | fire = [19, 20]; 93 | fireRight = [19, 20]; 94 | fireLeft = [21, 22]; 95 | die = [23, 23, 23, 23, 23, 23]; 96 | stand = [8]; 97 | powerUp = [19, 20]; 98 | scale = 1.8; 99 | xHP = 630; 100 | break; 101 | } 102 | 103 | // Controller is the index of input array where this chars inputs are stored. 104 | this.controller = controller; 105 | 106 | // Sprites 107 | this.sprite = game.add.sprite(x, y, character + (this.controller)); 108 | this.sprite.animations.add('left', left, 13, true); 109 | this.sprite.animations.add('right', right, 13, true); 110 | this.sprite.animations.add('jump', jump, 13, true); 111 | this.sprite.animations.add('stand', stand, 13, true); 112 | this.sprite.animations.add('fireRight', fireRight, 13, true); 113 | this.sprite.animations.add('fireLeft', fireLeft, 13, true); 114 | this.sprite.animations.add('die', die, 2, false); 115 | this.sprite.animations.add('powerUp', powerUp, 13, true); 116 | this.sprite.playerId = this.controller; 117 | this.sprite.scale.set(scale, scale); 118 | 119 | // Set Sprite health 120 | this.sprite.health = 100; 121 | 122 | // Set Sprite PowerUp 123 | this.sprite.powerUp = 0; 124 | 125 | // Create Sprite HP Text 126 | this.sprite.healthText = game.add.text(xHP, 0, 'P' + (this.controller + 1) + ' HP:' + this.sprite.health, { 127 | font: '17px PressStart2P', 128 | fill: '#000', 129 | align: 'center', 130 | backgroundColor: '#98e800' 131 | }) 132 | 133 | // Enable physics 134 | game.physics.enable(this.sprite, Phaser.Physics.ARCADE); 135 | this.sprite.body.collideWorldBounds = true; 136 | this.sprite.body.bounce.y = 0.2; 137 | this.sprite.body.gravity.y = 300; 138 | 139 | } 140 | 141 | Character.prototype = { 142 | update: function (inputs) { 143 | 144 | 145 | game.physics.arcade.collide(this.sprite, this.platforms); 146 | var standing = this.sprite.body.blocked.down || this.sprite.body.touching.down; 147 | this.sprite.body.velocity.x = 0; 148 | 149 | if (this.sprite.powerUp === 100) { 150 | this.sprite.tint = colors[this.controller]; 151 | } else { 152 | this.sprite.tint = 0xFFFFFF; 153 | } 154 | 155 | // Check sprite health 156 | if (this.sprite.health <= 0) { 157 | dieSound.play(); 158 | dieSound.currentTime = 0.1; 159 | this.sprite.body.moves = false; 160 | inputs[this.controller].fire = false; 161 | this.sprite.animations.play('die', 6, false, true); 162 | } 163 | 164 | else if (this.sprite.powerUp === 100 && inputs[this.controller].firePowerUp === true) { 165 | this.sprite.animations.play('powerUp'); 166 | this.firePowerUp(); 167 | resetPowerUp(this.sprite); 168 | } 169 | 170 | // Default direction to fire 171 | else if (inputs[this.controller].fire === true && this.sprite.body.touching.down) { 172 | this.fireGun(); 173 | } 174 | 175 | // Sprite Movement 176 | else if(inputs[this.controller].left === true) { 177 | this.sprite.body.velocity.x = -150; 178 | this.sprite.animations.play('left'); 179 | } else if (inputs[this.controller].right === true) { 180 | this.sprite.body.velocity.x = 150; 181 | this.sprite.animations.play('right'); 182 | } else if(inputs[this.controller].jump === true) { 183 | this.sprite.animations.play('jump'); 184 | } 185 | else { 186 | this.sprite.animations.stop(); 187 | this.sprite.animations.play('stand'); 188 | } 189 | 190 | if (inputs[this.controller].jump === true && this.sprite.body.touching.down) 191 | { 192 | this.sprite.body.velocity.y = -350; 193 | } 194 | 195 | if (inputs[this.controller].fire === true && inputs[this.controller].right === true) 196 | { 197 | this.sprite.animations.play('fireRight'); 198 | // Maintain movement while firing 199 | this.sprite.body.velocity.x = 150; 200 | this.fireGun(); 201 | } 202 | 203 | if (inputs[this.controller].fire === true && inputs[this.controller].left === true) { 204 | this.fireGun(); 205 | this.sprite.animations.play('fireLeft'); 206 | // Maintain movement while firing 207 | this.sprite.body.velocity.x = -150; 208 | } 209 | }, 210 | fireGun: function() { 211 | 212 | if (game.time.now > this.nextFire) 213 | { 214 | this.nextFire = game.time.now + this.fireRate; 215 | 216 | this.bullet = this.bullets.getFirstExists(false); 217 | console.log(this.bullet); 218 | 219 | this.bullet.playerId = this.controller; 220 | 221 | if (this.controller === 0) { 222 | this.bullet.reset(this.sprite.x + 25, this.sprite.y + 35); 223 | } 224 | if (this.controller === 1) { 225 | this.bullet.reset(this.sprite.x + 25, this.sprite.y + 20); 226 | } 227 | if (this.controller === 2) { 228 | this.bullet.reset(this.sprite.x + 25, this.sprite.y + 20); 229 | } 230 | if (this.controller === 3) { 231 | this.bullet.reset(this.sprite.x + 25, this.sprite.y + 30); 232 | } 233 | if (inputs[this.controller].right === true) { 234 | this.sprite.lastRightFire = 1; 235 | this.sprite.lastLeftFire = 0; 236 | this.bullet.body.velocity.x = 400; 237 | } 238 | else if ( this.sprite.lastLeftFire > this.sprite.lastRightFire && this.sprite.body.velocity.x === 0) { 239 | this.bullet.body.velocity.x = -400; 240 | } 241 | else if (inputs[this.controller].left === true || this.sprite.lastLeftFire > this.sprite.lastRightFire ) { 242 | this.sprite.lastLeftFire = 1; 243 | this.sprite.lastRightFire = 0; 244 | this.bullet.body.velocity.x = -400; 245 | } 246 | else { 247 | this.bullet.body.velocity.x = 400; 248 | } 249 | } 250 | }, 251 | firePowerUp: function () { 252 | if (game.time.now > this.nextFire) 253 | { 254 | this.nextFire = game.time.now + this.fireRate; 255 | 256 | this.superBullet = this.superBullets.getFirstExists(false); 257 | this.superBullet2 = this.superBullets2.getFirstExists(false); 258 | this.superBullet3 = this.superBullets3.getFirstExists(false); 259 | 260 | 261 | this.superBullet.playerId = this.controller; 262 | this.superBullet2.playerId = this.controller; 263 | this.superBullet3.playerId = this.controller; 264 | 265 | if (this.controller === 0) { 266 | this.superBullet.reset(this.sprite.x + 25, this.sprite.y + 35); 267 | this.superBullet2.reset(this.sprite.x + 25, this.sprite.y + 35); 268 | this.superBullet3.reset(this.sprite.x + 25, this.sprite.y + 35); 269 | } 270 | if (this.controller === 1) { 271 | this.superBullet.reset(this.sprite.x + 25, this.sprite.y + 35); 272 | this.superBullet2.reset(this.sprite.x + 25, this.sprite.y + 35); 273 | this.superBullet3.reset(this.sprite.x + 25, this.sprite.y + 35); 274 | } 275 | if (this.controller === 2) { 276 | this.superBullet.reset(this.sprite.x + 25, this.sprite.y + 35); 277 | this.superBullet2.reset(this.sprite.x + 25, this.sprite.y + 35); 278 | this.superBullet3.reset(this.sprite.x + 25, this.sprite.y + 35); 279 | } 280 | if (this.controller === 3) { 281 | this.superBullet.reset(this.sprite.x + 25, this.sprite.y + 35); 282 | this.superBullet2.reset(this.sprite.x + 25, this.sprite.y + 35); 283 | this.superBullet3.reset(this.sprite.x + 25, this.sprite.y + 35); 284 | } 285 | 286 | this.superBullet.body.velocity.x = -400; 287 | this.superBullet.body.velocity.y = -400; 288 | this.superBullet2.body.velocity.x = 400; 289 | this.superBullet2.body.velocity.y = -400; 290 | this.superBullet3.body.velocity.y = -400; 291 | 292 | 293 | } 294 | } 295 | } 296 | --------------------------------------------------------------------------------