let s make a web g ame
play

Lets make a web g ame! credit: Photon Storm What will we cover - PowerPoint PPT Presentation

Lets make a web g ame! credit: Photon Storm What will we cover today? The canvas element Phaser, a JavaScript framework Settin g up a local server Makin g an HTML5 pa g e Settin g up Phaser Creatin g a simple g ame


  1. Let’s make a web g ame! credit: Photon Storm

  2. What will we cover today? • The canvas element • Phaser, a JavaScript framework • Settin g up a local server • Makin g an HTML5 pa g e • Settin g up Phaser • Creatin g a simple g ame

  3. What is canvas? A canvas is a rectan g le in your HTML pa g e where you can use JavaScript to draw anythin g you want. credit: Nintendo

  4. credit: Photon Storm

  5. What is Phaser? Phaser is an open source JavaScript framework made for HTML5 g ame developers by HTML5 g ame developers. credit: Photon Storm

  6. What’s a framework? Frameworks help to reduce the amount of time spent reinventin g the wheel. � They come with a lar g e set of tools to help you accomplish tasks faster.

  7. Settin g up a local server credit: Silicon An g le

  8. Local servers Local servers allow you to test websites you’ve pro g rammed without an internet connection. � Phaser requires a server to run for security reasons.

  9. Start your Apache server Open XAMPP and turn on Apache

  10. Makin g an HTML5 pa g e credit: The Matrix

  11. Find htdocs Open your XAMPP folder, then htdocs

  12. Create a folder to work in Name your folder my g ame

  13. Check if it worked! Go to localhost/my g ame

  14. Create a new file in your text editor Save your new file as index.html in your folder

  15. Components of an HTML5 pa g e • <!DOCTYPE html>: tells the browser it is lookin g at an HTML5 pa g e • <html>: be g ins the HTML code • <head>: the area where meta information will be located • <title>: the website title • <body>: the part of the pa g e where the HTML shows up!

  16. Gettin g started with Phaser credit: Photon Storm

  17. Download the latest version g ithub.com/photonstorm/phaser

  18. Move phaser.min.js create a scripts folder & move phaser.min.js there

  19. Create a JavaScript file Save your new file as g ame.js in your scripts folder

  20. Link your files to the HTML

  21. Comment your code 5 minutes after you write code When you come back to it without comments in 3 weeks

  22. Commentin g code is easy • Preface your one-line comment with two slashes (//) • Two line comments require an asterisk and slash on each side (/* */) • Most text editors have shortcuts (like  + /)

  23. Creatin g g ames with JavaScript credit: Jandi Small

  24. Our g ame • Collect the pi g cats! • Enemies switch between dan g erous & safe • If you collect the pi g cats, you win! • If your health g oes down to 0, you lose! • Polish it with start, win, and lose screens

  25. Variables • Variables are useful for storin g data that may chan g e throu g hout the course of your app (e. g . your player’s health) • To create a variable, you have to tell JavaScript: • The name you’re g oin g to refer to it by • The value (information) that the variable contains

  26. Variables • Variables let you refer to the same information many times • If you need to chan g e that information, you only have to do it once � For example, best friends may chan g e but the label stays the same: � var myBestFriend = “Isaiah”; var myBestFriend = “Rebecca”; var myBestFriend = “Aileen”;

  27. Functions • Function: a named section of a pro g ram that does a specific task • Wraps up code in an easy-to-reference way • Parameter: additional information you can g ive the function to chan g e the output

  28. Function structure function fetch(do g ) { run to the ball; pick up the ball; brin g the ball back; }; • Name of the function • Parentheses: Hold any modifiers (also known as ar g uments) • Brackets: What to do in the function • Semicolon: end of line, move onto the next thin g

  29. Calculations + (add) – (subtract) * (multiply) / (divide) var addition = 13 + 22; var division = 100/15;

  30. preload() function

  31. Create assets folder Download & save ima g es from tinyurl.com/clf-html5-2014

  32. create() function

  33. update() function

  34. CREATE UPDATE DRAW

  35. How does positionin g work?

  36. X=0 x=WIDTH y=0 y=HEIGHT

  37. X=0 x=WIDTH y=0 (3,2) y=HEIGHT

  38. How do I move my player?

  39. g ame.input g ame.input.keyboard.createCursorKeys(); + conditional statements

  40. Conditional statements if (squirrel){ console.lo g (“squirrel!”); } else { console.lo g (“bark!”); } � • Check if somethin g is true or false • Provide backup option if necessary

  41. How do we create a bunch of the same objects?

  42. Groups enemies

Recommend


More recommend