Ball meets Paddle.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Alysa’s Trivia!!! Monkeys tigers Softball
Recap Ball Movement How does ball start its movement initially What happens when it hits the top and bottom What happens when it hits the paddle If you.
Analysis And Algorithms CMSC 201. Search Sometimes, we use the location of a piece of information in a list to store information. If I have the list [4,
FRACTION REVIEW.
SciTech Label Project Water Conservation: High flow vs. Low flow Showerheads by Sarah Kautz University of Chicago, Department of Anthropology.
An Introduction to Addition
How to Draw a Baby Elephant with Simple Shapes Let’s get started! Click here.
Created by L. Henderson. 3 x 4 = 12 factor factor product.
REFERENCES: CHAPTER 8 Object-Oriented Programming (OOP) in Python.
Escape A sticky man adventure using TKINTER python module By: Channing Burgess.
NestedLoops-part31 Nested Loops – part 3 Barb Ericson Georgia Institute of Technology Nov 2009.
Loop Pictures Pepper. Show a picture in your program Add the picture drawing knowledge – import javalib.worldimages.*; – import java.awt.Color; Create.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
How to Create a Videogame By: Connor McCann. Java Java is one of many programming languages Java is used to run web browsers and most PC video games I.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Week 2 Fancy Face, Conditional Execution, Recursive Tree Computer Science I Scott C Johnson Fall
Hey, Ferb, I know what we’re gonna do today! Aims: Use formatted printing. Use the “while” loop. Understand functions. Objectives: All: Understand and.
TWITTER DAY /07/14 LING 3820 & 6820 Natural Language Processing Harry Howard Tulane University.
11 Adding Tomato Targets Session Session Overview  We now have a game which lets a player bounce a piece of cheese on a bread bat  Now we have.
Code reading skills LEVEL GAME.  Skeleton has error messages.  Notice the red lines on right slider. Click… you’ll go to an error.  pieces = levels.getPieces();
OOP Lecture 06. OOP? Stands for object oriented programming. You’ve been using it all along. Anything you use the dot ‘.’ on is an object.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech June 2008.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Week 8 - Friday.  What did we talk about last time?  Static methods.
Getting started with the turtle Find the latest version of this document at
Aquarium Lab Series Developed by Alyce BradyAlyce Brady of Kalamazoo CollegeKalamazoo College.
VG101 RECITATION 8 By TAs. CONTENTS Brief review of class Strategy for assignment 9 Questions about assignment 7, 8.
GAME:IT Junior Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a.
GAME:IT Paddle Ball Objectives: Review skills from Introduction Create a background Add simple object control (up and down) Add how to create a simple.
Functions. functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs.
 Python for-statements can be treated the same as for-each loops in Java Syntax: for variable in listOrstring: body statements Example) x = "string"
5. Animation Let’s Learn Saengthong School, June – August 2016 Teacher: Aj. Andrew Davison, CoE, PSU Hat Yai Campus
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.
: Probability = chance = odds An event is one or more outcomes of an experiment An outcome is the result of a single trial of an experiment.
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.
PHP Condtions and Loops Prepared by Dr. Maher Abuhamdeh.
Python programming - Defining Classes
15. Media (sound effects, music, video)
Adapted from slides by Marty Stepp and Stuart Reges
CSSE 120—Rose Hulman Institute of Technology
Animation & Games Module
CS 115 Lecture 8 Structured Programming; for loops
11. Animation Let's Learn Python and Pygame
Graph Paper Programming
Let’s make a shape…. Move!
The One Where You Scratch
13. Sprites Let's Learn Python and Pygame
Starter 15//2 = 7 (Quotient or Floor) (Modulus) 22%3 =1
Graph Paper Programming
Flooding © 2018.
Scratch – Simple Programming
16. Invaders.
Using the coords function (Coordinates)
Adapted from slides by Marty Stepp and Stuart Reges
Functions as everyday items
Adapted from slides by Marty Stepp and Stuart Reges
Adding a paddle (1) We now have a code, which will run forever and just have a ball bouncing around the screen until we shut down the program. To make.
Let’s Learn 7. Sprites Saengthong School, June – August 2016
More on Functions (Part 2)
14. Pong Let's Learn Python and Pygame
Let’s begin our game!.
11. Animation.
Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg
The Iterative Design Recipe
Creating a Simple Game in Scratch
Lesson 3. Controlling program flow. Loops. Methods. Arrays.
LET’S PLAY JEOPARDY!!.
Week 7 - Friday CS 113.
Presentation transcript:

Ball meets Paddle

Telling the ball when it has hit the paddle If we don’t do anything, the ball will go right through the paddle (oh no!) We need to tell the paddle when it has been hit. We also need to tell the ball when it has hit a wall. We will make code easier to manage by chunking it into smaller pieces and keeping our functions simple.

Change the Ball class __init__ function (1) Pass the paddle object into our ball __init__ function Change the parameters to: def __init__(self, canvas, paddle, color): And Add the following (just below the self.canvas = canvas): self.paddle = paddle

Change the Ball class __init__ function (2) We also need to pass the paddle object into the ball object At the bottom of the program, just before the main loop, change  ball = Ball(canvas, paddle, ‘red’)

hit_paddle Function (1) Adding a code to see of the ball has struck the paddle is more complicated than seeing if the ball has hit a wall, so we will write a new function called hit_paddle to the draw function of the Ball class. First, let’s update the draw function to allow for our new hit_paddle, which we are about to create: Add this just below the (if pos[3] >= seld.canvas_height…) lines: if self.hit_paddle(pos) == True: self.y = -3

hit_paddle function (2) def hit_paddle(self, pos): paddle_pos = self.canvas.coords(self.paddle.id) if pos[2] >= paddle_pos[0] and pos[0] < paddle_pos[2]: if pos[3] >= paddle_pos[1] and pos[3] <= paddle_pos[3]: return True return False