Advanced Stuff Learning by example: Responding to the mouse.

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

Create a Simple Game in Scratch
Events in Alice By Henry Qin, edited by Jenna Hayes under the direction of Professor Susan Rodger Duke University, August 2008.
Mouse Tutorial for Win XP In this tutorial you will learn to: Move the mouse Click and double click Make selections Manage windows Use menus Click the.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
DEVELOPING ICT SKILLS PART -TWO
Getting to know Greenfoot
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Greenfoot Asteroids Mrs. C. Furman August 16, 2010.
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Cosc 5/4730 Game Design. A short game design primer. A game or animation is built on an animation loop. – Instance variables of “objects” are updated.
Painterly Rendering CMPS Assignment 2. OpenGL OpenGL is a cross-language, cross- platform specification defining and API for 2D and 3D graphics.
Wizard Game: Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July
Scratch Understanding some programming techniques using Scratch Resetting, Parallelism and Events.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Do not begin Slide Show. Stay in normal view for now.
Art 315 Lecture 4 Dr. J. Parker AB 606 Today’s class: Programming! We are going to write some simple programs. We will use a tool called GameMaker –It.
Introduction to Scratch!
Locally Edited Animations We will need 3 files to help get us started at
Unit 1 – Improving Productivity Ryan Taroni Instructions ~ 100 words per box.
Greenfoot. Getting Started Open the Greenfoot download site: Select Greenfoot
Spreadsheets in Finance and Forecasting Presentation 9 Macros.
How to use the internet The internet is a wide ranging network that thousands of people use everyday. It is a useful tool in modern society that once one.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
Client Side Programming with JavaScript Why use client side programming? Web sides built on CGI programs can rapidly become overly complicated to maintain,
Comments in Java. When you create a New Project in NetBeans, you'll notice that some text is greyed out, with lots of slashes and asterisks:
Making Python Pretty!. How to Use This Presentation… Download a copy of this presentation to your ‘Computing’ folder. Follow the code examples, and put.
Greenfoot Game Programming Club.
Buttons and Birds: Introduction to Interactive Events in Alice By Henry Qin, edited by Jenna Hayes under the direction of Professor Susan Rodger Duke University,
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
Creating a Historical Tour in Alice By Jenna Hayes May 2010.
Alice 3.0 A Guided Tour Mike R-D YRDSB. Agenda General Walkthrough of Alice 3.0 Loops, Variables, Threads Methods / Properties Arrays Misc.
Lesson 1: Writing a program. Java Java is a programming language Computer cannot understand it, though it can be translated ( compiled ) so a computer.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Learning to Program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
Introduction To Greenfoot
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Getting Started with HTML. HTML  Hyper Text Markup Language  HTML isn’t a program language, its known as a markup language  A Markup language has tags.
What’s on Your Desktop?. Programs on your computer Some programs are standard on most computers for example: Microsoft Word Internet Explorer Microsoft.
Java With NetBeans First Project. Java Are language for this semester is Java The Development Environment is Netbeans.
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Introduction to JavaScript Events Instructor: Sergey Goldman 1.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Introducing Scratch Learning resources for the implementation of the scenario
 Learn the mechanics of using App Inventor to build apps.  Learn how to design an app’s user interface with the App Inventor Designer, and its behavior.
TechKnowlogy Conference August 2, 2011 Using GoogleDocs for Collaboration.
School of Computer Science Space School 2015 Programming a Lunar Lander Game.
Chapter 4 - Finishing the Crab Game
Games Programming in Scratch
Scratch for Interactivity
BIT116: Scripting Lecture 06
Introduction to JavaScript Events
Learning to program with Logo
Loopy Motion Control.
Adding Shapes and Text to Pictures on PowerPoint
The Little Crab Scenario
Some Tips for Using Eclipse
Due Next Monday Assignment 1 Start early
At GMAIL IGOOGLE Most of you have signed up for , but the first half of these slides are here if you want to help others . .
Tonga Institute of Higher Education IT 141: Information Systems
Greenfoot November 8, 2009.
Tonga Institute of Higher Education IT 141: Information Systems
Using Placeholders to Simplify your Methods: Learning Methods, Part 2
Running a Java Program using Blue Jay.
Creating a Simple Game in Scratch
So you want to be a Game Designer
Presentation transcript:

Advanced Stuff Learning by example: Responding to the mouse

Learning by example Programmers often learn by studying examples and experimenting on them We will look at two examples of how to respond to the mouse – We will trying changing them – We will learn to program by examining someone else code – We will learn to respond to the mouse

Look at this scenario Open a web browesr to This is kminttech’s Astroids Mouse Control Try it on the website Click “Open in Greenfoot” to download the file Let’s look around

Asteroids

Getting start You should compile the code and make sure it works on your machine … Go head. Compile and try it.

Getting into the code Open the code for Space Oh my, that’s a lot of member variables. We’ll read the code to understand them

Getting into the code Let’s start with the constructor (how is the world made) It’s nicely organize. Setup is divided into methods with a clear name. Let’s dig in.

Getting into setUpMouse() Where do panel and scroll come from? Both are member variables scroll is a ScrollingListener defined in this class panel is a JPanel and has something to do with the World Google search “java Jpanel” and “java MouseWheelListener”

Getting into setUpMouse() This is setting up something called a “callback” or “listener” When the event, moving the scroll wheel happens, the mouseWheelMoved method is called on the ScrollListener This is how we listen for events The panel is like a window (or part of a window) in Java

Getting into setUpMouse() Next we create an empty image We set it as the cursor image and create something called mouseImage If we look at the mouse image class it doesn’t do anything But each time the world acts we move it to the mouse position Let’s try removing mouseImage to figure out what it does

Getting into setUpMouse() Comment out the addObject and the moving it code Compile and Run the program Doesn’t seem to do anything… How about setCursor??? Comment it out That one seems important Hides the cursor

Getting into setUpMouse() The rest of the constructor creates Objects The ship The asteroids The scoreboard At that is left in space is the code to rotate the ship. Let see it in action!!!

Getting into the act() Click in the whitespace beside setRotation(..) You should get a little stop sign When the program gets here it will stop and we can investigate

Getting into the act() Start the game Do not scroll the mousewheel and game goes on Scroll the wheel and everything stops!

Let’s look at how the ship works Nicely organized again! MouseMove moves the ship to the location of the mouse. Let’s try changing it!

MouseMove() Let’s make it so the ship points to the mouse and accelerates in that direction. Start with the pointing Then the moving

MouseMove() Ok we need to rotate the image… Either in an editor or when we load the image. Load the image and call rotate it, like we did on other days Then make bullet shoot straight

MouseMove() How let’s make it move toward the mouse We will need the Ship to inherit from SmoothMover (to be a smooth mover instead of Actor). When the mouse is far accelerate the ship, and near stop the movement

Lets look at painting Open a web browser to BuilderBoy2005 presents “Advanced Mouse Control” Try the program in the browser Download the program

Mouse Control

Getting start again You should compile the code and make sure it works on your machine … Go head. Compile and try it.

Getting into the world Open world Notice it looks like the previous project was built from this one. They have a lot in common. Here mouse image is used to create a circle where you will draw

Getting into the world Can we change the painting color? Try calling setColor on the mouseImage mouseImage.setColor( new Color(255,255,0) ); Where should we set it? Before drawing the oval What does the mouseWheel do in this program? Can we make it change colors based of if we press a number on the keyboard

Color your world Remember we used Greenfoot.isKeyDown Remember to use Control + space to get an autocomplete list Try the following code

Color your world Now try to add mouse control to your own games Can you make a shoot game with ducks? Popping bubbles? Navigating a maze without touching the slide?

Start your own game project Choose a game that you can work on for the rest of the week Over the rest of the week, we will learn new programming techniques and more about Greenfoot You will be given more time to work on your own idea for a game We will help your idea become reality.