Presentation is loading. Please wait.

Presentation is loading. Please wait.

Game Design Practicum (CMPS 179) Summer 2012 Classes and Objects and the Canvas UC Santa Cruz CMPS 179 – Game Design Practicum courses.soe.ucsc.edu/courses/cmps179/Summer12/01.

Similar presentations


Presentation on theme: "Game Design Practicum (CMPS 179) Summer 2012 Classes and Objects and the Canvas UC Santa Cruz CMPS 179 – Game Design Practicum courses.soe.ucsc.edu/courses/cmps179/Summer12/01."— Presentation transcript:

1 Game Design Practicum (CMPS 179) Summer 2012 Classes and Objects and the Canvas UC Santa Cruz CMPS 179 – Game Design Practicum courses.soe.ucsc.edu/courses/cmps179/Summer12/01 kecompto@ucsc.edu 28 June, 2012

2 UC SANTA CRUZ Community  Remember that you are part of a community…

3 UC SANTA CRUZ Reminder  "If you qualify for classroom accommodations because of a disability, please submit your Accommodation Authorization Letter from the Disability Resource Center (DRC) to me during my office hours or by appointment, preferably within the first week of the Summer Session. Contact DRC by phone at 831-459-2089 ordrc@ucsc.edu for more information."831-459-2089drc@ucsc.edu

4 UC SANTA CRUZ Community  Remember that you are part of a community…  A community that the rest of the world is very excited about

5 UC SANTA CRUZ Community Beginning web developers Mobile and web application developers Web 2.0 business analysts, futurists, and investors Sociologists and economists Game designers You are here

6 UC SANTA CRUZ Resources  The Web Ahead – a web development podcast  http://5by5.tv/webahead/ http://5by5.tv/webahead/  TechCrunch – an insider look at the business behind Web 2.0  http://techcrunch.com/ http://techcrunch.com/  Hacker News – Reddit for people programming the web  http://news.ycombinator.com/ http://news.ycombinator.com/

7 UC SANTA CRUZ Resources  AngelHack  “Jump start your startup at AngelHack's national hackathon competition, where you can win $75,000 in prizes and hack your way into meeting top angel investors and national media.”  StartupBus  “StartupBus, a multi-city Wi-Fi-enabled roadtrip to the South by Southwest Interactive conference with the goal of developing and launching startups by the time the travelers arrive in Austin, fired up the engines on its biggest year ever this week.”  SuperHappyDevHouse  “is a non-exclusive event intended for creative and curious people interested in technology. We're about knowledge sharing, technology exploration, and ad-hoc collaboration. Come to have fun, build things, learn things, and meet new people. It's called hacker culture, and we're here to encourage it.”

8 UC SANTA CRUZ Resources  Y Combinator – the preeminent incubator for web and technology startups  http://news.ycombinator.com/ http://news.ycombinator.com/  “In 2005, Y Combinator developed a new model of startup funding. Twice a year we invest a small amount of money (average $18k) in a large number of startups (currently 82). The startups move to Silicon Valley for 3 months, during which we work intensively with them to get the company into the best possible shape and refine their pitch to investors. Each cycle culminates in Demo Day, when the startups present to a large audience of investors. But YC doesn't end on Demo Day. We and the YC alumni network continue to help founders for the life of their company, and beyond.Demo Day  Since 2005 we've funded over 460 startups, including Loopt, Reddit, Clustrix, Wufoo,Scribd, Xobni, Omgpop, Weebly, Songkic k, Disqus, Dropbox, ZumoDrive, Justin.tv,Heroku, A Thinking Ape, Machine Zone, Posterous, Airbnb, Heyzap, Cloudkick,DailyBooth, WePay, Bump, Stripe, Ca rWoo, MixPanel, Cardpool, Optimizely, AeroFS,E la Carte, and Hipmunk.”LooptRedditClustrixWufooScribdXobniOmgpopWeeblySongkic kDisqusDropboxZumoDriveJustin.tvHerokuA Thinking ApeMachine ZonePosterousAirbnbHeyzapCloudkickDailyBoothWePayBumpStripeCa rWooMixPanelCardpoolOptimizelyAeroFSE la CarteHipmunk

9 UC SANTA CRUZ Resources  YetiZen – A new incubator for games companies  http://yetizen.com/category/yetizen/accelerator-program/ http://yetizen.com/category/yetizen/accelerator-program/  “The YetiZen Accelerator Program is focused entirely on game studio and emerging platform startups. We help game startups build and strengthen their business models, marketing strategies, and market position while simultaneously connecting them with our network of seed partners, angels and VCs. These companies are also given access to incredible partnership deals to accelerate their user acquisition and distribution.”  LOOK FOR: who are they funding, and why?  LOOK FOR: more incubators like this following the success of Y Combinator

10 UC SANTA CRUZ Moving from JSFiddle to Aptana Create or add all the resources (CSS, frameworks, and.js files)  You can just drag them into the project’s folder on the sidebar

11 UC SANTA CRUZ Moving from JSFiddle to Aptana …html… <script type= "text/javascript" src="jquery-1.7.2.min.js"> <script type= "text/javascript" src="zebra.js"> …html…

12 UC SANTA CRUZ Moving from JSFiddle to Aptana …html… <script type= "text/javascript" src="jquery-1.7.2.min.js"> <script type= "text/javascript" src="zebra.js"> …html… Be sure to put this first! The next.js file needs to be able to refer to it

13 UC SANTA CRUZ Moving from JSFiddle to Aptana JSFiddle JavaScript is wrapped inside a function that only runs once the page is loaded. This keeps it from running the JavaScript too early, which might result in the JS not being able to locate elements that haven’t loaded yet. So wrap the JavaScript in a function like this: $(document).ready(function() { // do something } Or window.onload = function() {}

14 UC SANTA CRUZ Quick Canvas Introduction How do you draw with JavaScript? Where do the graphics come from?

15 UC SANTA CRUZ Quick Canvas Introduction How do you draw with JavaScript? HTML5: Canvas!

16 UC SANTA CRUZ Quick Canvas Introduction How do you draw with JavaScript? HTML5: Canvas! Canvas Context

17 UC SANTA CRUZ Quick Canvas Introduction var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); Canvas Context

18 UC SANTA CRUZ Quick Canvas Introduction  Tutorial: drawing to the canvas  Create an object in the HTML   Draw something to the scene by getting the canvas and context var canvas = document.getElementById("myCanvas"); var context = canvas.getContext("2d"); context.beginPath(); context.moveTo(100, 150); context.lineTo(450, 50); context.stroke(); Achievement: Use a loop to create multiple lines. Does it matter where you put the stroke() command?

19 UC SANTA CRUZ Quick Canvas Introduction Animation is … tricky  Clear the canvas Unless the shapes you'll be drawing fill the complete canvas (for instance a backdrop image), you need to clear any shapes that have been drawn previously. The easiest way to do this is using theclearRect method.  Save the canvas state If you're changing any setting (styles, transformations, etc) which affect the canvas state and want to make sure the original state is used each time a frame is drawn, you need to save it.  Draw animated shapes The step where you do the actual frame rendering.  Restore the canvas state If you've saved the state, restore it before drawing a new frame. From: https://developer.mozilla.org/en/Canvas_tutorial/Basic_animations

20 UC SANTA CRUZ Quick Canvas Introduction Processing.js – all the power of Processing, Paper.js – great 2D animation graphics, more interaction-focussed than Processing Raphael – SVG graphics, runs on older browsers Web-Drawing Throwdown: Paper.js Vs. Processing.js Vs. Raphael

21 UC SANTA CRUZ Objects What’s an object?

22 UC SANTA CRUZ Objects Zebra name: someName legs: 4 speed:10 action: eatGrass

23 UC SANTA CRUZ Objects testZebra = { name:“Zippy", legs:4, speed:16 };

24 UC SANTA CRUZ Objects testZebra = { name:“Zippy", legs:4, speed:16 }; Why does this look familiar?

25 UC SANTA CRUZ Objects testZebra = { name:“Zippy", legs:4, speed:16 }; JSON { "text":"@twitterapi http:\/\/tinyurl.com\/ctrefg", "to_user_id":396524, "to_user":"TwitterAPI", "from_user":"jkoum", "metadata": { "result_type":"popular", "recent_retweets": 109….. CSS body { color: purple; background-color: #d8da3d } ul { background-image: url(smallPic.jpg); background-repeat: repeat-y; color: green; }

26 UC SANTA CRUZ Objects testZebra = { name:“Zippy", legs:4, speed:16 }; testZebra.name + testZebra.speed = “Zippy16”

27 UC SANTA CRUZ Objects  Tutorial: make a zebra  Create an object zebra with some properties  Create some console.log() statements to test the contents of the object Achievement: for (p : zebra) { // do something } Will do something with each property in “zebra” Use it to print all the properties and their values.

28 UC SANTA CRUZ Objects What is an object? Objects are “hash tables” of “key-value” pairs

29 UC SANTA CRUZ Objects How else can you refer to properties? zebra.name = “Zippy”; zebra[‘name’] = “Zippy”;

30 UC SANTA CRUZ Objects  Tutorial: add to the zebra  Add a property to the zebra AFTER you have created it.  Create a list of properties [“homesOwned”, “netWorth”, “collegeDegrees”]  Add them all to the zebra and set them all to 0. Achievement: Add a property to the zebra that is a function That function can be run later with “zebra.myFxn.call(zebra, grass);”

31 UC SANTA CRUZ Objects Creating many Zebras function Zebra(name) { this.name = name; this.legs = 4; this.speed = 10; }

32 UC SANTA CRUZ Objects Creating many Zebras function Zebra(name) { this.name = name; this.legs = 4; this.speed = 10; this.x = Math.random(100); this.y = Math.random(100); }

33 UC SANTA CRUZ Objects  Tutorial: an array of zebras  Create an empty array of zebras  Add some zebras to it using myArray.push(newElement); Achievement: Start with an array of Zebra names Create a zebra for every element in the array function Zebra(name) { this.name = name; this.legs = 4; this.speed = 10; this.x = Math.random(100); this.y = Math.random(100); }

34 UC SANTA CRUZ Objects  Tutorial: drawing zebras  In the constructor function, add a function that takes a context object  And uses it to draw a circle at the zebra’s location  Create a loop that draws each zebra. Achievement: Figure out how to make a black and white circle, rotated randomly ctx.beginPath(); ctx.arc(75, 75, 10, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); ctx.beginPath(); ctx.arc(75, 75, 10, 0, Math.PI*2, true); ctx.closePath(); ctx.fill();

35 UC SANTA CRUZ HW  Code Academy  Create an account and go through “JavaScript Fundamentals”  http://www.codecademy.com/tracks/javascript http://www.codecademy.com/tracks/javascript  No need to do the “Projects” section  By Tuesday, you *MUST* have uploaded your RPG to a website. We will look at them on Tuesday in class  Practice your new JavaScript skills by adding  Some way to lose  Some way to win


Download ppt "Game Design Practicum (CMPS 179) Summer 2012 Classes and Objects and the Canvas UC Santa Cruz CMPS 179 – Game Design Practicum courses.soe.ucsc.edu/courses/cmps179/Summer12/01."

Similar presentations


Ads by Google