Programming Games Simulated ballistic motion: cannon ball. Classwork: Final day for midterm project and all projects for first part of class. Homework:

Slides:



Advertisements
Similar presentations
What is Projectile Motion?
Advertisements

HTML5 CANVAS.  Rectangles  Arcs  Lines  Features we won’t look at  Images  Drag and drop  Animation  Widely supported DRAWING PICTURES IN HTML.
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
Visual Basic: ballistics
Programming games More drawing. Text. Radian measure. Faces. Homework: Do your own drawings. Create index.html file. Upload work.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 18 – Macromedia Flash MX 2004: Building an Interactive Game Outline 18.1 Introduction 18.2 Object-Oriented.
IS660Z – Programming Games Using Visual Basic Required session 3 June 16, 2004.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
What is Projectile Motion?
Programming Games Computer science big ideas. Computer Science jargon. Show virtual dog Homework: [Catch up: dice game, credit card or other form.] Plan.
Programming games Flash drawing trick(s). Rock paper scissors. Classwork: Complete rock paper scissors.
Create Interfaces College exercise. Continue HTML5: HTML5 logo, drawing images. Coin toss. Homework: acquire video & audio.
Programming Games Review for midterm. Work session. Homework: Prepare for midterm.
Introduction to TouchDevelop
AIM: How can we describe the path of an object fired horizontally from a height above the ground? DO NOW: A ball rolls off a table top with an initial.
Programming Games Google Map API examples. CSS. Classwork/homework: Catch up. Upload work. Show your [more] complex Google Maps API example. Plan your.
Programming Games Show your simple video. More video examples. Audio. Classwork/Homework: Produce more complex video program.
HTML5 CANVAS. SAVING INFORMATION BETWEEN FUNCTION CALLS.
KeyListener and Keyboard Events Just as we can implement listeners to handle mouse events, we can do the same for keyboard events (keypresses) –to implement.
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
Programming Games Show project. Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Homework: Do your own.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Programming games Flash drawing trick(s). Past due: Your completion of rock-paper-scissors) Classwork: Bouncing ball: read tutorial. Start coding.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Combining Motion and Vector concepts 2D Motion Moving Motion Forward Velocity, Displacement and Acceleration are VECTORS Vectors have magnitude AND direction.
Programming games Registration experiment. Drawing. Equations of motion. Odds and ends. First phase of cannonball due. Preview video, audio. Homework:
Programming Games Preview Video & Audio. Work on cannonball. Homework: finish cannonball!
Programming Games Reprise on drawing on canvas. Jargon (concepts): objects. Demonstrate slingshot. Mouse events. Work on your cannonball. Homework: Finish.
Programming games Show shaking screen, quiz show. Calculations Homework: (Finish basic Javascript Projects) Make proposal. Work on project.
DRILL September 15, 2009 Name three drafting tools used in this class.
Programming games HTML/JavaScript basics Functions, events, forms Classwork: [Show favorite sites.] Coin toss. Homework: GET WEB SPACE. Complete coin toss.
Programming games Show your virtual somethings. Demonstrate Hangman and Black Jack. Show credit card (or other form input & calculation) Homework: [Complete.
Programming games Problems. Schedule Various examples. Homework: rps, bo (don't go back to do this), cannonball, Video or Audio should be complete. Now.
[My] Experiences building games in Visual Basic & Flash Focus on 'cannonball' Jeanine Meyer Math Senior Seminar.
Programming games Context of what we are doing. Drawing on canvas. Homework: [Complete coin toss examples.] Do your own drawings. Upload files to website.
Programming Games Logic. Slide show. Range input. Storage. Datatypes. Binary numbers. Homework: Catch up. This includes uploading projects to your server.
Computer Science I Classes and objects Classwork/Homework: Examine and modify my examples. Make your own.
Programming Games Show your rock-paper-scissors. Demonstrate bouncing ball. Demonstrate and examine Bo the dog. Homework: Modify Bo to make your own.
Programming games Review concepts. Crooked coin toss. Drawing on canvas. Homework: Complete [static] drawings. Upload files to website.
Creating User Interfaces HTML5 video & audio. Role of video and audio. Homework: Complete your own [small/simple] HTML5 video and audio projects.
Computer Science I Share plans for virtual something. Text. Show my virtual dog. Classwork: Plans for your virtual something. Homework: start implementation.
Work and Energy. October 2012.
Programming Games Show slide show (on your site). Bouncing something. Video element. Bouncing video element. Bouncing video drawn on canvas. Bouncing video.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
Computer Science I More class examples. Paths. Jigsaw. Tolerance. Classwork/homework: Your class project. Post proposal for midterm project.
Computer Science I Slingshot example. ProcessingJS example. Review for midterm quiz. Classwork/Homework: study for midterm. Work on midterm project.
Collision testing. learning targets Increase awareness of the struggles that of game development; Recognize computer science elements for game logic;
Programming Games Reprise Credit Cards! Reprise Binary. Overall time limit, setTimeout Homework: [Show virtual something.] Make proposal as reply to my.
Programming games Show work on site. Work on slide show. Timed event for bouncing ball. Homework: [Finish slide show and upload to site.] Acquire a short.
Programming Games Work / finish and show dice game. Extras. Timed events. ftp. index file. Homework: Catch up and do slide show.
Classwork: Examine and enhance falling drop(s) or make your own.
Physics Lesson 6 Projectile Motion
Collision Detection Box-to-Box.
DRILL September 17, 2007 Write answers in complete sentences:
Animated picture changes during motion path (Advanced)
ISC440: Web Programming II Ch14: HTML5 Canvas
Fly-in marquee lights at picture entrance (Intermediate)
Chapter 10 Algorithms.
Bellringer What is the difference between the words vertical and horizontal? What does the word projectile mean? How is one dimensional (1D), two dimensional.
Context of what we are doing.
Programming games Demonstrate cannonball
Programming games Share your plans for your virtual something.
Catchup. Work on project.
Chapter 10 Algorithms.
Projectile Motion Thank you Physics Classroom:
Programming Games Reprise on drawing on canvas. Jargon (concepts): objects. Demonstrate slingshot. Mouse events. Work on animation project. Homework: Finish.
Programming Games Refresher on coordinates. Scaling, translation. HTML5 logo. Refresher on animation. Bouncing ball. Show project. Classwork/Homework:
JavaScript – Let’s Draw!
Vector addition allows us to consider movement in 2-D
Presentation transcript:

Programming Games Simulated ballistic motion: cannon ball. Classwork: Final day for midterm project and all projects for first part of class. Homework: [Start and] Finish bouncing something. Start work on YOUR cannonball.

Bouncing something … in a box –Or something else You can bounce many things. The variables ballx and bally define the location.

What does this do? blob references an Image object with src set to a picture of some roundish squishy thing. Sketch it! ballx = 100; bally = 150; ballvx = 50; ballvy = 80; ballx = ballx+ballvx; bally = bally+ballvy; ctx.clearRect(0,0,1000,800); ctx.drawImage(blob,ballx,bally,100,100);

What does this do? blob references an Image object with src set to a picture of some roundish squishy thing. Sketch it. ballx = 100; bally = 150; ctx.drawImage(blob,ballx,bally,100,100); ballvx = 50; ballvy = 80; ballx = ballx+ballvx; bally = bally+ballvy; ctx.drawImage(blob,ballx,bally,100,100);

NOTE on cannonball No tutorial…. Instead: sequence of programs: go to html5/html5explain.html html5/html5explain.html Study code. Copy code. Make changes to make it your own—need to carry those changes. Also: see chapter 4 in The Essential Guide to HTML5 (on reserve in Library).

Cannonball requirements Display objects (cannon, ball, target, ground) on the screen –Every interval of time, code clears and re- draws on canvas Set up system for drawing a set of objects –Look at the Ball, Picture, Myrectangle, and drawall. –Notice way to draw rectangle at an angle. –use paths (beginPath, arc, fill for the circle), fillRect, drawImage

Bouncing thing vs Cannonball What’s the same –Each interval of time, code erases, makes an adjustment to position values, does checks, re-draws What’s different –Adjustments to position are different –CB: Form input to get input from player –BB: check against walls. CB: Check against ground and check against target

cannonball at angle I made a general facility: the everything array holds references to each object AND information on translation and rotation –Object oriented programming, aka OOP the fire function (see later) uses the angle information set by the player to change the rotation information in the everything array. CAUTION: –assumption is that the player enters angle in degrees. –my code converts angle to radians.

function drawall() {ctx.clearRect(0,0,cwidth,cheight); var i; for (i=0;i<everything.length;i++) { var ob = everything[i]; if (ob[1]) { //need to translate and rotate ctx.save(); ctx.translate(ob[3],ob[4]); ctx.rotate(ob[2]); ctx.translate(-ob[3],-ob[4]); ob[0].draw(); ctx.restore(); } else { ob[0].draw(); }

Cannonball requirements, cont. Produce animated trajectory of ball –animation produced similar to bouncing ball using setInterval –specific path done with calculations simulating effects of gravity initial horizontal and vertical displacements calculated from angle of cannon horizontal displacements stay the same vertical change each interval of time

Cannonball requirements, cont. Check for collisions –ground –target

fire function sets up trajectory function fire() { var angle = Number(document.f.ang.value); var outofcannon = Number(document.f.vo.value); var angleradians = angle*Math.PI/180; horvelocity = outofcannon*Math.cos(angleradians); verticalvel1 = - outofcannon*Math.sin(angleradians); everything[cannonindex][2]= - angleradians; cball.sx = cannonx + cannonlength*Math.cos(angleradians); cball.sy = cannony+cannonht*.5 - cannonlength*Math.sin(angleradians); drawall(); tid = setInterval(change,100);return false; }

change function do calculation to adjust vertical displacement move the ball check if ball hits target –if so, stop animation and substitute the hit target picture for the original picture check if ball has gone beyond the ground (further down the screen) –if so, stop animation draw everything

How to check if point is on/in a rectangle A point has x and y (horizontal and vertical) values. A rectangle has x and y of upper left corner, and width and height values. ((bx>=target.sx) && (bx<=(target.sx+target.swidth)) && (by>=target.sy) && (by<=(target.sy+target.sheight)))

change function function change() { var dx = horvelocity; verticalvel2 = verticalvel1 + gravity; var dy = (verticalvel1 + verticalvel2)*.5; verticalvel1 = verticalvel2; cball.moveit(dx,dy);

//check for hitting target var bx = cball.sx; var by = cball.sy; if ((bx>=target.sx)&&(bx =target.sy)&&(by<=(target.sy+target.sh eight))) { clearInterval(tid); //remove target and insert htarget everything.splice(targetindex,1,[htarget,false]); everything.splice(ballindex,1); drawall();}

//check for getting beyond ground level if (by>=ground.sy) { clearInterval(tid); } drawall(); }

Cannonball requirements, cont. Way for player to input (change) velocity out of cannon and angle of cannon. –form –validation (checking) of input values. This is promised feature of HTML5.

form element in body element Set velocity, angle and fire cannonball. Velocity out of cannon Angle

Aside In programming, you need to distinguish between writing code to Do something define a function to do something Write code to invoke a function (that does something) Set up event handling (arrange to do something AFTER an event occurs)

Diversion Do you always win or at least tie at tic tac toe? What do you do????

Try ictactoe.htmlhttp://faculty.purchase.edu/jeanine.meyer/t ictactoe.html Exercise in patience and arrays

Classwork / homework Get caught up with uploading & index.html –Do not call midterm project ‘midterm project’. Prepare bouncing something Cannonball: –Do look at each preliminary program and make it your own –Prepare your cannonball. can change look, including what is the cannon and what is the ball. When basic program is working, can alter logic.