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.

Slides:



Advertisements
Similar presentations
Multiplying Polynomials
Advertisements

FRACTIONS.
Summer Computing Workshop. Introduction to Variables Variables are used in every aspect of programming. They are used to store data the programmer needs.
Constructor and New Fields // Don't synch draw() with vertical retrace of monitor graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = true;
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
Pong! “The oldest commercially available game in history” Resources created from the video tutorials provided by David Phillips on
Microsoft® Small Basic
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.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
HTML, HTML5 Canvas, JavaScript PART 3 LOOKING MORE CLOSELY AT FULL BLOWN GAME DESIGN A PATTERNED BACKGROUND (CREATED WTIH LOOPS) WITH A MOVING OBJECT CHALLENGES.
Agenda For Feb Finish up Unit 3 Exercises on page Unit 4 Exercises on page 33. Question #2 3. Create a Happy Face Java Applet (due next class).
Locally Edited Animations We will need 3 files to help get us started at
Spiral Rider PAGE 1. Set Up Scene 1.Add Stage-underwater scene 2.Add crab sprite 3.Add two fish sprites PAGE 2.
Peter Andreae Python for Level 3 CS4HS see website: ecs.vuw.ac.nz/Main/PythonForSchools.
Alice Pong Recreating Pong in Alice By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June 2010.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Geometry. The screen where you can see what happens when you play your game is called the STAGE. The SCRIPT BANK is where the types of instructions are.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
Simple Collision Detection By David Yan Under the direction of Professor Susan Rodger and Chari Distler Duke University, June 2015.
BALANCING EQUATIONS NO2 - Balancing equations made easy.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 22 Game Graphics.
Lives and Scoring Games Programming in Scratch. Games Programming in Scratch L2 Lives and Scoring Learning Objectives Define a variable Understand the.
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.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Here is a small example of the puzzle you will be completing today. You will start in the top left corner, and end at the bottom right using 3 different.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
School of Computer Science Space School 2015 Programming a Lunar Lander Game.
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.
Scratch Programming Cards
Error Analysis Logic Errors.
Sound and more Animations
Create a Halloween Computer Game in Scratch
What is a Function Expression?
MOM! Phineas and Ferb are … Aims:
Games Programming in Scratch
Adapted from slides by Marty Stepp and Stuart Reges
Exploring Mathematical Relationships Module 5: Investigation 3
Keyboard Input.
Animation & Games Module
Android Layouts 24 July 2018 S.RENUKADEVI/AP/SCD/ANDROID LAYOUTS 1.

Intro to Programming with Scratch
Paddle Ball! We will begin creating, in steps, a video game similar to ‘brick breaker’ or ‘pong’, were we can move paddles to hit a bouncing ball. I hope.
Learning to program with Logo
Introduction to Object-Oriented Programming
The Canvas.
Graph Paper Programming
Let’s make a shape…. Move!
The One Where You Scratch
Flooding © 2018.
Name: _______________________________
Scratch – Simple Programming
14. Pong.
Using the coords function (Coordinates)
Go to =>
Introduction to TouchDevelop
Breakout in Greenfoot Barb Ericson
14. Pong Let's Learn Python and Pygame
Let’s begin our game!.
Ball meets Paddle.
Creating a Simple Game in Scratch
Scratch Racing.
CoE Software Lab II , Semester 2, Pong.
Presentation transcript:

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 it more of a ‘game’, we will add a paddle and then add some more code to improve the game elements. Let’s begin by adding a Paddle class…

Adding a paddle (2) class Paddle: def __init__(self, canvas, color): self.canvas. = canvas self.id = canvas.create_rectangle(0,0,100,10, fill = color) self.canvas.move(self.id, 200, 300) def draw(self): pass **This is almost EXACTLY like our Ball class, but we are drawing a rectangle instead of an oval. ** we will come back to our draw function later.

Adding a paddle (3) Let’s make some changes in our code. Create an object of the Paddle class Change the main loop to call the paddle’s draw function. paddle = Paddle(canvas, ‘blue’) ** Place this just above the  ball = Ball(canvas, ‘red’) In our main loop paddle.draw( ) # Just below the ball.draw( )

What has happened so far? We have a bouncing ball and a stationary paddle. Much better, but still not a ‘game’. We need to make the paddle move, but more importantly, we need to be able to control the paddle. We will use event bindings, so our left and right arrow keys can control the movement of the paddle.

making the paddle move First, we will add the x object to our __init__ function and a variable for the width of the canvas. Just like we did to our Ball class. Add this to our __init__ function in our Paddle class self.x = 0 self.canvas_width = self.canvas.winfo_width( )

making the paddle move (2) Now we just need the functions for changing the direction. Add these just after the draw function (Paddle class)  def turn_left(self, evt): self.x = -2 def turn_right(self, evt): self.x = 2

making the paddle move (3) We will now bind these functions to the correct keys. In our __init__ function, let’s add the following: self.canvas.bind_all(‘<KeyPress-Left>’, self.turn_left) self.canvas.bind_all(‘<KeyPress-Right>’, self.turn_right)