Chapter 9 Active Objects + Boxball Project Design Animations! What are they? –Snapshots of objects i n different positions –When viewed quickly appear.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

How can Microsoft PowerPoint 2007 help you share information?
Microsoft® Small Basic
1 Drawing C Sc 335 Object-Oriented Programming and Design Rick Mercer.
Written by: Dr. JJ Shepherd
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Building Memory… Day 4 – November 20, Some clean up from last time Applet class can now be run as either an Applet or an Application Made picture.
Recall: Accessing Location Info private Location firstPoint; public void onMousePress( Location pressPt ) { new Text("Pressed", pressPt, canvas ); firstPoint.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Active Objects Animations! What are they? –Snapshots of objects i n different positions –When viewed quickly appear to be moving.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
Games and Simulations O-O Programming in Java The Walker School
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
Introduction to TouchDevelop
Complex objects How might you design a class called NestedRects of graphical objects that look like this? Requirements for the constructor: –Like many.
Overview of our Approach Program Structure –Data, variables, and parameters –Basic control structures (conditionals, loops and Threads) –Class definitions.
Chapter 11 Adding Sound and Video. Chapter 11 Lessons 1.Work with sound 2.Specify synchronization options 3.Modify sounds 4.Use ActionScript with sound.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Teaching Loops Facilitated by introducing simple threads Few interesting loop examples before arrays –Boring calculations –Interaction –Drawing –Animation.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 3 "The games of a.
Java Loops (Java: An Eventful Approach, Ch 7 and 13), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture 16 6 November 2012.
Graphics Concepts CS 2302, Fall /3/20142 Drawing Paths.
Java: An Eventful Approach An innovative approach to teaching Java in CS1 † Recursion Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College † Partially.
Putting Zing into your Classroom with Jing. Why use Flash presentations? Personalize course content Add related concepts Reach various kinds of learners.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Game Maker Terminology
1.  At the end of this slide, student able to:  Object-Oriented Programming  Research on OOP features.  Do a code walkthrough to examine the implementation.
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Session 16 Pinball Game Construction Kit:. Pinball Version 1 Replaced the fire button with a mouse event. Multiple balls can be in the air at once. –Uses.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
Design Studies 20 ‘Show Off’ Project How to make a computer monitor In Google Sketchup By: Liam Jack.
1 GUIs, Layout, Drawing Rick Mercer. 2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces (GUIs)
A Class of Our Own We’ve used many classes: –Location –FilledRect –Color –Text –And More! –But what if we want to make our own class?
CS324e - Elements of Graphics and Visualization Timing Framework.
Graphics Concepts CS 2302, Fall /17/20142 Drawing in Android.
Getting started with What2Learn By the end of this session you will have: Created your What2Learn account Designed your online character Started setting.
UNIT 1 VOCABULARY. INSTRUCTIONS Go to Computer Icon on desktop Click PUBLIC drive Double-Click Homework Folder Double-Click MS folder Find JWARNER folder,
Basics of GUI Programming Chapter 11 and Chapter 22.
Java Working with Numbers (Java: An Eventful Approach, Ch 3), Slides Credit: Bruce, Danyluk and Murtagh CS 120 Lecture October 2012.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
Debugging tools in Flash CIS 126. Debugging Flash provides several tools for testing ActionScript in your SWF files. –The Debugger, lets you find errors.
How to create a basic game in Scratch. The Scratch Stage The Scratch stage is 480 pixels wide and 360 pixels high x increasesx decreases.
Chapter 2 – The Little Crab Program:. Little Crab Scenario Inheritance: The Arrows Denote Hierarchy Crab is an Animal Animal is an Actor Therefore, It.
What About Alice? In Alice, we have seen that we have:  Objects (skater, snowman, snowwoman, camera)  Methods (move, turn, roll, move toward)  Properties.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Teaching Control Structures, using objectdraw Chris Nevison Barbara Wells.
Inventor Studio Animate Positional Representations.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 26, 2009.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
GUI.1 Graphical User Interfaces GUIs. GUI.2 The Plan Components Flat Layouts Hierarchical Layouts Designing a GUI Coding a GUI.
Chapter 4 - Finishing the Crab Game
Chapter 4 - Finishing the Crab Game
MOM! Phineas and Ferb are … Aims:
Kim B. Bruce, Andrea Danyluk & Tom Murtagh Williams College
Eclipse Navigation & Usage.
Chapter 13: Advanced GUIs and Graphics
Project Snake. Project Snake Snake For this project, we’re going to make Snake This includes Making the overall game logic (using a 2D array) Handling.
Introduction to TouchDevelop
Chapter 10 Algorithms.
Chapter 10 Algorithms.
by Pixer and Didney Animation Studios
Let’s begin our game!.
Classes.
Building Java Programs
Chapter 10 Algorithms.
Advanced GUIs and Graphics
Presentation transcript:

Chapter 9 Active Objects + Boxball Project Design Animations! What are they? –Snapshots of objects i n different positions –When viewed quickly appear to be moving

A Virtual Flipbook:

Animating an Object First create an object Then –Move it a little –Pause for the user to see it –Repeat

FallingBall public class FallingBall extends ActiveObject { public FallingBall( Location initialLocation, DrawingCanvas aCanvas ){ canvas = aCanvas; ballGraphic = new FilledOval (initialLocation, SIZE, SIZE, canvas ); start(); } public void run() { while ( ballGraphic.getY() < canvas.getHeight() ) { ballGraphic.move( 0, Y_STEP ); pause( DELAY_TIME ); } ballGraphic.removeFromCanvas(); }

Defining an Active Object define a class that extends ActiveObject ensure the class includes a run method pause occasionally within the run method include start(); usually as the last statement in the constructor

Using Active Objects public class FallingBallController extends WindowController { private FallingBall droppedBall; public void begin() { new Text("Click to make a falling ball…”, INSTR_LOCATION, canvas ); } public void on MouseClick( Location point ) { droppedBall = new FallingBall( point, canvas ); }

What if… We wanted the falling object to look like a raindrop

Image and VisibleImage Classes In the controller class: private Image rainPicture; rainPicture = getImage("raindrop.gif" ); Can be used anywhere: new VisibleImage( rainPicture, 0, canvas.getWidth()/2, canvas );

A Controller Class public class FallingRainPicController extends WindowController { private Image rainPicture; public void begin() { new Text("Click to make a falling raindrop…", INSTR_LOCATION, canvas ); rainPicture = getImage( "raindrop.gif" ); } public void onMouseClick( Location point ) { new FallingRainDrop( rainPicture, point, canvas ); }

A Falling Raindrop public class FallingRainDrop extends ActiveObject { private static final int DELAY_TIME = 33; private static final double Y_SPEED=4; private VisibleImage ballGraphic; private DrawingCanvas canvas; public FallingRainDrop( Image rainPic, Location initialLocation, DrawingCanvas aCanvas ) { canvas = aCanvas; rainGraphic = new VisibleImage( rainPic, initialLocation, canvas ); start(); } public void run() { while ( rainGraphic.getY() < canvas.getHeight() ) { rainGraphic.move( 0, Y_SPEED ); pause ( DELAY_TIME ); } rainGraphic.removeFromCanvas(); }

Active Object Interactions Accomplished with methods and parameters A RainCloud: –RainCloud continuously generates drops –Drops fall and disappear at the bottom

The RainCloud Class public class RainCloud extends ActiveObject { public RainCloud( DrawingCanvas aCanvas, Image aRainPic) { rainPic = aRainPic; canvas = aCanvas; start(); } public void run() { RandomIntGenerator xGenerator = new RandomIntGenerator( 0, canvas.getWidth() ); int dropCount = 0; while ( dropCount < MAX_DROPS ) { new FallingRainDrop( rainPic, new Location( xGenerator.nextValue(), 0 ), canvas); pause( DELAY_TIME ); dropCount++; }

Interactions Between Active and Non-Active Objects An Active Object: –Droplet in the shape of an oval Created at the top of canvas, falls to the bottom A Non-Active Object: –Waterline in the shape of a FilledRect Rises as drops fall

A New Kind of Raindrop 1.Created at the top of the screen 2.Falls to the bottom 3.Raises the waterline

Falling Droplet public class FallingDroplet extends ActiveObject { private FilledOval dropletGraphic; private FilledRect collector; public FallingDroplet( Location initialLocation, DrawingCanvas canvas, FilledRect aCollector ) { dropletGraphic = new FilledOval( initialLocation, SIZE, SIZE, canvas ); collector = aCollector; start(); } public void run() { while ( dropletGraphic.getY() < collector.getY() ) { dropletGraphic.move( 0, Y_STEP ); pause( DELAY_TIME ); } dropletGraphic.removeFromCanvas(); if ( collector.getY() > 0 ) { collector.setHeight( collector.getHeight() + SIZE/4 ); collector.move( 0, -SIZE/4 ); }

Boxball

Classes break problem up Boxball Class: –sets up arena, title, status message "Let's Play" –sets up bar and easy/med/hard buttons –sets up target box –onMouseClick if on easy/med/hard button, moves bar to different level if clickPoint is above bar creates a new Ball

Boxball design, continued Box Class: –manages the FilledRect that is the target –methods to Construct a Box moveBox move to different x-position setSize change the size of the box getLeft retrieve the x position of left side of box getRight retrieve the x position of right side

Box Class examples target = new Box(100, 50, canvas); –creates a new Box at x position 100, width 50 target.setSize(35); –changes width of box to 35 target.setSize(BALL_SIZE*1.5); –width set to 50% larger than ball target.moveBox(); –moves box to a random x position

Boxball Design, continued Ball Class –constructor to create a new Ball remember the canvas in instance variable –run method to animate ball so it drops while ball is above the bottom of the arena, –advance ball by 10 pixels or so –pause 50 milliseconds or so after the ball reaches bottom, check if it is within left and right sides of box

Ball class constructor examples Part 3 – new Ball(BALL_SIZE, point, canvas); ball will be created at point and fall. Part 4 –new Ball(BALL_SIZE, point, target, canvas); ball will also be able to access target to check if within left and right edges Another possibility— –new Ball(BALL_SIZE, point, arena, target, canvas); ball will also be able to access arena to tell when to stop –each new variation has to add actual parameters

Have fun with challenges Check with instructor frequently to stay on track code over weekend for help This is a crucial component to master Reading textbook can help with concepts