├── assets ├── dahls.png └── player.png ├── README.md ├── index.html ├── js ├── game.js └── done.js └── .gitignore /assets/dahls.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draperunner/phaser-lightning-talk/master/assets/dahls.png -------------------------------------------------------------------------------- /assets/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draperunner/phaser-lightning-talk/master/assets/player.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # phaser-lightning-talk 2 | Code from Lightning Talk held about the Phaser JavaScript framework 3 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | -------------------------------------------------------------------------------- /js/game.js: -------------------------------------------------------------------------------- 1 | var mainState = { 2 | 3 | preload: function() { 4 | 5 | game.load.image('odd', 'assets/player.png'); 6 | }, 7 | 8 | create: function() { 9 | 10 | this.player = game.add.sprite(game.world.centerX, game.world.centerY, 'odd'); 11 | this.player.anchor.setTo(0.5, 0.5); 12 | 13 | game.stage.backgroundColor = "#3366ff"; 14 | 15 | 16 | }, 17 | 18 | update: function() { 19 | 20 | this.player.angle += 1; 21 | 22 | } 23 | 24 | }; 25 | 26 | var game = new Phaser.Game(800, 600, Phaser.Auto, 'gameDiv'); 27 | game.state.add('main', mainState); 28 | game.state.start('main'); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 2 | 3 | *.iml 4 | 5 | ## Directory-based project format: 6 | .idea/ 7 | # if you remove the above rule, at least ignore the following: 8 | 9 | # User-specific stuff: 10 | # .idea/workspace.xml 11 | # .idea/tasks.xml 12 | # .idea/dictionaries 13 | 14 | # Sensitive or high-churn files: 15 | # .idea/dataSources.ids 16 | # .idea/dataSources.xml 17 | # .idea/sqlDataSources.xml 18 | # .idea/dynamic.xml 19 | # .idea/uiDesigner.xml 20 | 21 | # Gradle: 22 | # .idea/gradle.xml 23 | # .idea/libraries 24 | 25 | # Mongo Explorer plugin: 26 | # .idea/mongoSettings.xml 27 | 28 | ## File-based project format: 29 | *.ipr 30 | *.iws 31 | 32 | ## Plugin-specific files: 33 | 34 | # IntelliJ 35 | out/ 36 | 37 | # mpeltonen/sbt-idea plugin 38 | .idea_modules/ 39 | 40 | # JIRA plugin 41 | atlassian-ide-plugin.xml 42 | 43 | # Crashlytics plugin (for Android Studio and IntelliJ) 44 | com_crashlytics_export_strings.xml 45 | crashlytics.properties 46 | crashlytics-build.properties 47 | -------------------------------------------------------------------------------- /js/done.js: -------------------------------------------------------------------------------- 1 | var mainState = { 2 | 3 | preload: function() { 4 | game.load.image('player', 'assets/player.png'); 5 | game.load.image('dahls', 'assets/dahls.png'); 6 | }, 7 | 8 | create: function() { 9 | 10 | game.stage.backgroundColor = "#3366ff"; 11 | 12 | this.player = game.add.sprite(game.world.centerX, game.world.centerY, 'player'); 13 | this.player.anchor.setTo(0.5, 0.5); 14 | 15 | game.physics.arcade.enable(this.player); 16 | 17 | this.beer = game.add.sprite(40, 40, 'dahls'); 18 | game.physics.arcade.enable(this.beer); 19 | 20 | this.cursor = game.input.keyboard.createCursorKeys(); 21 | 22 | this.scoreLabel = game.add.text(20, 20, 'Beers: 1'); 23 | this.score = 0; 24 | 25 | }, 26 | 27 | update: function() { 28 | game.physics.arcade.overlap(this.player, this.beer, this.drinkBeer, null, this); 29 | this.movePlayer(); 30 | this.player.angle += this.score; 31 | }, 32 | 33 | drinkBeer: function() { 34 | var newX = game.rnd.integerInRange(0, game.world.width - 50); 35 | var newY = game.rnd.integerInRange(0, game.world.height - 146); 36 | this.beer.reset(newX, newY); 37 | 38 | this.score += 1; 39 | this.scoreLabel.text = 'Beers: ' + this.score; 40 | 41 | }, 42 | 43 | movePlayer: function() { 44 | if (this.cursor.left.isDown) { 45 | this.player.body.velocity.x = -200; 46 | } 47 | else if (this.cursor.right.isDown) { 48 | this.player.body.velocity.x = 200; 49 | } 50 | else { 51 | this.player.body.velocity.x = 0; 52 | } 53 | if (this.cursor.up.isDown) { 54 | this.player.body.velocity.y = -200; 55 | } 56 | else if (this.cursor.down.isDown) { 57 | this.player.body.velocity.y = 200; 58 | } 59 | else { 60 | this.player.body.velocity.y = 0; 61 | } 62 | } 63 | }; 64 | 65 | var game = new Phaser.Game(800, 600, Phaser.Auto, 'gameDiv'); 66 | game.state.add('main', mainState); 67 | game.state.start('main'); --------------------------------------------------------------------------------