CSE 190 M Flash Sessions Session 3 Alex Miller, Spring 2011.

Slides:



Advertisements
Similar presentations
1What is the Stage. 2How do you open a panel in Flash
Advertisements

AS3: Events & Listeners eventListeners in ActionScript 3.
IS660Z Programming Games Using Visual Basic Overview of Cannonball.
Visual Basic: ballistics
Microsoft® Small Basic
 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.
Roy McElmurry. ActionScript : an object-oriented programming language similar to JavaScript MXML : A flavor of XML that helps simplify user interface.
CIS Game Design I Sprite Sheets Blake Farrugia 10/10/2011.
1 Flash Actionscript Animation. 2 Introduction to Sprites We will now look at implementing Sprites in Flash. We should know enough after this to create.
Sketchify Tutorial Exercises sketchify.sf.net Željko Obrenović
SM1205 Interactivity Topic 11: Motion Tracking Part III Spring 2010SCM-CityU1.
Windows 8 Windows Phone 8 Web Mobile … and WakeUpAndCode.com.
Physics Simple – Pong Medium – Rigid bodies F = ma Circles, spheres, rectangles for collisions Complex – Fluids, clothings, explosions, hair.
INTRODUCTION TO SCRATCH. About Me Resources Scratch Website Learn Scratch Washington-Lee Computer.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Animations Flash ActionScript Introduction to Thomas Lövgren
CSE 380 – Computer Game Programming AI & Collision Strategy Erin Catto’s Box2D.
Chapter 3 Working with Symbols and Interactivity.
Game Design Creating a game called PING Phase 3: Steps for building basic game.
Introduction to TouchDevelop
By Mr. Lee. Backgrounds The image that appears in the background (duh!). This might be a horizon, or clouds, trees and rainbows in the distance If you’re.
Set 7: Events and Animation IT452 Advanced Web and Internet Systems.
CSE 380 – Computer Game Programming Sprite Animation
VIDEO GAME PROGRAMMING Video Game Programming Junior – DigiPutt INSTRUCTOR TEACHER’S ASSISTANT.
© 2011 Delmar, Cengage Learning Chapter 9 Introduction to ActionScript 3.0.
Enhancing JavaScript Using Application Programming Interfaces (APIs)
VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell.
 2008 Pearson Education, Inc. All rights reserved Adobe ® Flash ® CS3: Building an Interactive Game.
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
Programming Games Simulated ballistic motion: cannon ball. Classwork: Final day for midterm project and all projects for first part of class. Homework:
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 8 "The games of a people reveal.
Art 315 Lecture 5 Dr. J. Parker AB 606. Last time … We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 8 "The games of a.
Programming games Flash drawing trick(s). Past due: Your completion of rock-paper-scissors) Classwork: Bouncing ball: read tutorial. Start coding.
Programming games Reflection Bouncing things, Memory Server-side: Survey. ActionScript 2 examples. Homework: Finish Video or Audio. Post proposal for your.
Lab 6: event & input intro User Interface Lab: GUI Lab Oct. 2 nd, 2013.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Mouse Events & Keyboard Inputs Flash ActionScript Introduction to Thomas Lövgren
Catch the Clown Tutorial Tech Camp Fall 2008 Colorado School of Mines.
Game Maker Terminology
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 6 "The games of a people reveal.
Event JavaScript's interaction with HTML is handled through events that occur when the user or browser manipulates a page. When the page loads, that is.
ActionScript 3 Using Sound Related Classes by Martin Stanhope The University of Bolton.
CS324e - Elements of Graphics and Visualization Timing Framework.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 6 "The games of a.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Unit 6 Motion – Air Hockey Evangel College S.2 ICT.
XP Tutorial 3 Creating Animations. XP New Perspectives on Macromedia Flash MX Elements of Animation Layers are used to organize the content of.
Game Maker Evil Clutches.
CSE 190 M Flash Sessions Session 2 Alex Miller, Spring 2011.
Construct 2 Game Development for Kids Platformer Tutorial: Part 1 Shahed Chowdhuri.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 22 Game Graphics.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
Choose Sprite. Add collision event for object and add score action. Set your score to plus 100 and check relative.
Game 4: Pac Man Tutorial. New events/actions to learn: Animated sprites Change instances – allows you to change objects into other objects. Change sprites.
Sprite sets. project of the week: bubble popper o objects appear from the bottom and slide up o player needs to avoid objects to earn points (objects.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
THE MOUSE Left Click THE MOUSE Right Click.
Collision Theory and Logic
Collision Theory and Logic
Background Shapes & Collision Resolution (Top-down and Side-scrolling)
Macromedia Flash Tutorial
The horizontal and vertical components of a projectile in motion depend upon the initial velocity. True False.
Actionscript Session 2 Roy McElmurry.
Flash & ActionScript Syntax is similar to JavaScript
Programming games Classes and objects (used for Jigsaw, Bouncing stuff, other projects) Homework: Complete cannonball. Video or Audio. Your own project.
Week 6: Time and triggers!
Programming games Demonstrate cannonball
CSC 221: Introduction to Programming Fall 2018
Presentation transcript:

CSE 190 M Flash Sessions Session 3 Alex Miller, Spring 2011

Game Programming!!!! (Finally)

Games  Write Sprite classes for all of the objects in our game.  Update all of the game objects every frame (ENTER_FRAME).  Have event listeners for mouse clicks / key presses.  Store state about the game (Is the game running or paused? How many points does the player have?)

Events  Just like events in JavaScript  Allows us to process mouse clicks and key presses. EventDescription MouseEvent.MOUSE_DOWN MouseEvent.MOUSE_UP Triggered when mouse is pressed/unpressed. KeyboardEvent.KEY_DOWN KeyboardEvent.KEY_UP Triggered when key is pressed/unpressed. Event.ENTER_FRAME Triggered multiple times a second. Event.ADDED_TO_STAGE Event.REMOVED_FROM_STAGE Triggered when Sprite is added/removed from the display list (using addChild/removeChild). Event.RESIZE Triggered when movie is resized.

Events Mouse Clicks package { import flash.display.Sprite; import flash.events.MouseEvent; public class ClickProgram extends Sprite { public function ClickProgram() { var myCar:Car = new Car(); addChild(myCar); myCar.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); } private function onMouseDown(e:MouseEvent):void { // code that runs on mouse click } }}

Events Mouse Clicks package { import flash.display.Sprite; import flash.events.MouseEvent; public class ClickProgram extends Sprite { public function ClickProgram() { var myCar:Car = new Car(); addChild(myCar); myCar.addEventListener(MouseEvent.MOUSE_DOWN, function() { // code that runs on mouse click }); } }} A slightly different way:

Events Key Presses package { import flash.display.Sprite; import flash.events.KeyboardEvent; public class KeyProgram extends Sprite { public function KeyProgram() { stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown); } private function onKeyDown(e:MouseEvent):void { // code that runs on key press } }}

Events Key Presses import flash.ui.Keyboard;... private function onKeyDown(e:KeyboardEvent):void { if (e.keyCode == Keyboard.LEFT) { // code that runs when left key is pressed } else if (e.keyCode == Keyboard.A) { // code that runs when “A” key is pressed }} How do we know what key is pressed?

Collision No collision Collision var dx:Number = s1.x - s2.x; var dy:Number = s1.y - s2.y; var dist:Number = Math.sqrt(dx*dx + dy*dy); var rad1:Number = s1.width / 2; var rad2:Number = s2.width / 2; if (dist <= rad1 + rad2) { // collide! } Circles

Timer import flash.utils.Timer; import flash.events.TimerEvent;... // create a new timer that “ticks” every 1000 milliseconds var myTimer:Timer = new Timer(1000);myTimer.addEventListener(TimerEvent.TIMER, function() { // code that runs every tick });

Text Fields var textFormat:TextFormat = new TextFormat();textFormat.size = 24; var myTextField:TextField = new TextField();myTextField.x = 10; myTextField.y = 20;myTextField.width = 100; myTextField.defaultTextFormat = textFormat;addChild(myTextField); myTextField.text = “Hello World!”

More Collision if (p.x > rect.x && p.x < rect.x + rect.width && p.y > rect.y && p.y < rect.y + rect.height) { // collide! } Point vs. Rectangle

More Collision Collision Reaction  End the game  hero dies, game is paused  easy!  Bounce  easy for vertically or horizontally aligned objects, just reverse vx or vy  hard for circles or complex shapes  Place one colliding object directly outside the other  it’s doable for point vs. rectangle, but very difficult for everything else  You can also use a physics library for more realistic collisions: When two things collide, we could: box2d: AWESOME box2d video tutorials:

Motion & Animation Common strategies  Math.sin() can be used for oscillating or circular motion. Tweener: // every frame: theta += 0.1; mySprite.x = Math.sin(theta) * 100;  Cos/sin functions are useful for spring and gravity effects / following points.  If you add to position every frame, you get constant velocity.  If you add to velocity every frame, you get constant acceleration.  For advanced animation, check out the Tweener library:

Other resources  A couple common game libraries:    Books: Books:    Tutorials:  