1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 23 Game Graphics II.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

GAME:IT Junior Learning Game Maker: The Control Tab.
Sprites A sprite is a 2D image or animation that is integrated into a larger scene. Originally, sprites were created by special hardware that would super-impose.
In this tutorial, we are going to create: A race car that the user can control with the arrow keys for direction and speed. A simulated road with a striped.
Chapter 5: Objects and Classes class Point(Object): def __init__(x, y): self.x = initx self.y = inity def move(dx, dy): x += dx; y += dy; p = Point(10,
1 Data Structures CSCI 132, Spring 2014 Lecture 8 Implementing Queues.
Wombats Creating Games with Greenfoot The Walker School – Games and Simulations
1 Inheritance. 2 One class inherits from another if it describes a specialized subset of objects Terminology: inheritschild class subclass –the class.
Week 9 Writing Games with Pygame Special thanks to Scott Shawcroft, Ryan Tucker, and Paul Beck for their work on these slides. Except where otherwise noted,
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
1 Evan Korth New York University Inheritance and Polymorphism Professor Evan Korth New York University.
Week 9 Generalization, inheritance, class hierarchy and graphics.
Computer Science I Inheritance Professor Evan Korth New York University.
Binary Search Trees Section Trees Trees are efficient Many algorithms can be performed on trees in O(log n) time. Searching for elements.
LO: Learn how to develop your game further to include interactions with the device.
GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
Escape A sticky man adventure using TKINTER python module By: Channing Burgess.
Guide to Programming with Python
I210 review (for final exam) Fall 2011, IUB. What’s in the Final Exam Multiple Choice (5) Short Answer (5) Program Completion (3) Note: A single-sided.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
GAME:IT Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell.
User Input and Collisions COSC 315 Fall 2014 Bridget M. Blodgett.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 2 "The games of a.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Computer Science 111 Fundamentals of Programming I Model/View/Controller and Data model design.
Learning Unity. Getting Unity
Game Maker Terminology
Java Graphics Graphical Components as objects. Graphics A Component is ◦A rectangular region of a computer screen ◦A graphical entity ◦Can sometimes contains.
CSE 380 – Computer Game Programming GUIs for Games.
Game Maker – Getting Started What is Game Maker?.
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
Guide to Programming with Python Week 15 Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Lesson 2: Reading a program. Remember: from yesterday We learned about… Precise language is needed to program Actors and Classes Methods – step by step.
Application development with Java Lecture 21. Inheritance Subclasses Overriding Object class.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Action Script 12 "The games of a people.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 25 Game Graphics--Text and Animation.
Unit 6 Motion – Air Hockey Evangel College S.2 ICT.
How to find the intersection of two lines graphically using the TI-83
Game Maker Evil Clutches.
By JerryDean Smith Chad Adams Karl Mullner.  The rectangle needs to be a ogre.ManualObject -this is done to create the rectangle and gives it special.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
This computer science resource was developed through a collaboration between IBM Corporation and CSTA. 1 Lesson 2: Pong Class Design.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 22 Game Graphics.
PyGame - Unit 4 PyGame Unit – Object Oriented Programming OOP.
11. Skier Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Index Background Costumes Making object walk smoothly Controlling an object with the keyboard Control an object with the mouse Changing costume when hit.
Event Binding Make something to react when something happens to it, like pressing a key, it’s called event binding. Events: things that occur while a program.
13. Sprites. Outline 1.Game Things in Pygame (again) 2.The Pygame sprite Module 3.The Sprite Class 4.Groups of Sprites 5.Types of Collision Detection.
Building a rocks and spaceship game with Pygame Zero
MOM! Phineas and Ferb are … Aims:
Complex Conditionals Human languages are ambiguous
Lecture 12 Inheritance.
Week 8 Classes and Objects
Collision Detection Box-to-Box.
12 Data abstraction Packages and encapsulation
Road Map Inheritance Class hierarchy Overriding methods Constructors
Advanced Java Programming
13. Sprites Let's Learn Python and Pygame
Using the coords function (Coordinates)
Breakout in Greenfoot Barb Ericson
Let’s Learn 7. Sprites Saengthong School, June – August 2016
Fundamentals of Programming I Windows, Labels, and Command Buttons
Building Java Programs
CoE Software Lab II 1. Pygame Intro , Semester 2,
CoE Software Lab II , Semester 2, Sprites.
Presentation transcript:

1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 23 Game Graphics II

2 Class Inheritance In python, we can create new classes from existing classes using inheritance. The new class is called the child or subclass. The existing class is called the parent or superclass. The child class inherits everything (both properties and methods) from the parent class. The child class is specialized by adding new methods and/or properties, or modifying methods inherited from the parent class.

3 Inheritance Hierarchy among vehicles vehicle wheeled vehicleboat bicyclecar four-door two-door Every car is a wheeled vehicle.

4 Inheritance for Sprites The Sprite class is defined in the games module of livewires. It is referenced as: games.Sprite( ) Some properties of the Sprite class are: image, width, height, x, y, dx, dy, left, right, top, bottom, etc. Some methods of the Sprite class are: get_image( ), set_image(new_image), get_x( ), set_x(new_x) get_y( ), set_y(new_y), update( ), etc.

5 The Pizza Class The Pizza class inherits from the Sprite class: class Pizza(games.Sprite): def update(self ): if self.right > games.screen.width or self.left < 0: self.dx = -self.dx if self.bottom > games.screen.height or self.top < 0: self.dy = - self.dy The Pizza class will have all the properties and methods of the Sprite class. The new update( ) method will override the Sprite update method.

6 General form of Class inheritance In general, the form for creating a child class from a parent class is as follows: class childClassName(parentClassName): #Properties and method definitions go here.

7 The mouse class The games module provides a mouse class. Properties of the mouse class: games.mouse.xthe x position of the mouse games.mouse.ythe y position of the mouse games.mouse.is_visibleIf true, the cursor is visible. If false, the cursor is invisible Methods of the mouse class: games.mouse.get_x( ) Returns the x position of the mouse games.mouse.set_x(new_x) Sets the x position to new_x games.mouse.get_y( ) Returns the y position of the mouse games.mouse.set_y(new_y) Sets the y position to new_y games.mouse.is_pressed(button_number) Returns true if the button is pressed.

8 A Mouse-controlled Sprite Use the update function to move a sprite with the mouse: class Pan(games.Sprite): def update(self): self.x = games.mouse.x self.y = games.mouse.y... #add to main program: pan_image = games.load_image("pan.bmp") the_pan = Pan(image = pan_image, x = games.mouse.x, y = games.mouse.y) games.screen.add(the_pan)

9 Other useful mouse properties Make the cursor invisible with: games.mouse.is_visible = False Keep the cursor within the screen limits: games.screen.event_grab = True Notes: If using event_grab, need to end program with the Escape key After mainloop( ), reset games.mouse.is_visible = True Leave the cursor visible while debugging program.

10 Detecting Collisions To detect a collision, we will write a function, check_collide( ), in the Pan class to check for overlap with other sprites. We will then modify the update( ) function of the Pan class to call check_collide( ) def check_collide(self): for the_pizza in self.overlapping_sprites: pizza.handle_collide( ) def update(self): self.x = games.mouse.x self.y = games.mouse.y self.check_collide( )

11 Writing handle_collide Because we want the Pizza to do something when the pan hits it, we will add the function handle_collide( ) to the Pizza class: class Pizza(games.Sprite): #update function here... def handle_collide(self): #Move pizza to new random position in the screen self.x = random.randrange(games.screen.width) self.y = random.randrange(games.screen.height)