Guide to Programming with Python Week 15 Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.

Slides:



Advertisements
Similar presentations
Games in Python – the easy way
Advertisements

Introduction to Macromedia Director 8.5 – Lingo
Using Multimedia on the Web Enhancing a Web Site with Sound, Video, and Applets.
CNIT 132 – Week 9 Multimedia. Working with Multimedia Bandwidth is a measure of the amount of data that can be sent through a communication pipeline each.
Asteroids Games and Simulations O-O Programming in Java The Walker School The Walker School – Games and Simulations
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
This game is loosely based on the Whack-A- Mole arcade game.  Each game starts with 45 seconds of play.  Moles randomly pop out of holes on the landscape.
How do games work? Game Workshop July 4, Parts Sprites/pictures Map/background Music/sounds Player character Enemies Objects.
SCA Introduction to Multimedia
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Key Applications Module Lesson 12 — Word Essentials
The audacious program Audacity Audacity might be worth a look. Suggest... Audacity is an easy to use audio production and mixing program, which enables.
GAME:IT Junior Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Guide to Programming with Python
Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0 Key Abstractions in Game Maker Foundations of Interactive Game Design Prof. Jim Whitehead.
GREENFOOT CLUB RESOURCES Brian Cullen – Rossett School
GAME:IT Bouncing Ball Objectives: Create Sprites Create Sounds Create Objects Create Room Program simple game.
Game Maker Day 2 Making a Maze Game.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 23 Game Graphics II.
Art 315 Lecture 5 Dr. J. Parker AB 606. Last time … We wrote our first program. We used a tool called GameMaker. The program we wrote causes a ball to.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
SuperChair Productions proudly presents… PYGAME © 2006 SuperChair Productions. All rights reserved.
GAME:IT Helicopter Objectives: Review skills in making directional sprites Create objects that shoot and destroy for points Create random enemies on the.
Game Maker Terminology
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 9 "The games of a.
PowerPoint Practice Exercise 1 1.Save this file in your AV-TECH Folder as PowerPoint Practice Exercise 1. 2.Open this file in PowerPoint. 3.Edit each slide.
Sprites Actions/Particles/Sound Revisit the 'flying saucer' sprite: Again add it to the game Implement Chipmunk Physics collision feedback with missiles.
Guide to Programming with Python Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game.
A skills approach © 2012 The McGraw-Hill Companies, Inc. All rights reserved. powerpoint 2010 Chapter 4 Managing and Delivering Presentations.
Carlotta Eaton New River Community College 1 Game Maker Demonstration Carlotta Eaton Professor of Information Technology New River Community College IT.
JAZLER SHOW2 JAZLER SHOW2 AUTOMATION SOFTWARE. EASY PLAYBACK JAZLER SHOW2 AUTOMATION SOFTWARE Jazler Show is a program that lets you load audio files.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 9 "The games of a people reveal.
Game Maker Galactic Mail Advanced Group: Complete Galactic Mail, then start developing an independent project.
Adding a wave file to a slide Adding a wave file to a slide (1 of 7) 1. Click on Insert. 2. Click Movies and Sounds. 3. Click Sound from file
Warlords Patrick Levoshko SE 558 – Multiplayer Game Design.
JDS5 Training Guide. On Start Up you will see this screen click the OK button Click OK.
C++ for Engineers and Scientists Second Edition Chapter 7 Completing the Basics.
Today we are learning to: Understand how actions and events control our game. Completing the catch the clown game – making a room – adding music Gather.
Zack Russ.   A simple platform game using pygame.  Player collects jewels and progresses through the levels. A Platformer.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Game Project 1 Homage to Pong. Project Rules: The primary project is Pong, the design and development of which will be discussed in detail here. If you.
Motivates, interests and engages. Teaches problem solving skills. Allows for creativity and imagination. Demonstrates project design. Encourages teamwork.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 25 Game Graphics--Text and Animation.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Starting Out with Games & Graphics in C++ Tony Gaddis Chapter 8 The.
Galactic Mail Part 2. Winning and Losing Exploding Asteroids Including Scoring Adding Levels And more.
Game Maker Evil Clutches.
1 CSC 221: Computer Programming I Fall 2009 Introduction to programming in Scratch  animation sprites  motion, control & sensing  costume changes 
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.
Computer Programming with Scratch JAOIT 8. Scratch Scratch is a programming language that makes it easy to create your own interactive stories, animations,
The Stingray Example Program CMT3311. Stingray - an example 2D game May be useful as a simple case study Most 2D games need to solve generic problems.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 11 "The games of a people reveal.
Introducing Scratch Learning resources for the implementation of the scenario
Key Applications Module Lesson 12 — Word Essentials Computer Literacy BASICS.
9. Media (sound effects, music, video) 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.
Review Scene Management (Scene, Layer, Director) Sounds Menus Sprites & Actions.
Index Background Costumes Making object walk smoothly Controlling an object with the keyboard Control an object with the mouse Changing costume when hit.
Intro CS – Keyboard and mouse input Lesson Plan 7.
Sprites (Images) and Sounds
Sound and more Animations
Intro CS – Keyboard and mouse input
Game Engines By James Tedder.
Review Scene Management (Scene, Layer, Director) Sounds Menus
I Can’t Hear You! Sound Get out your notes.
CSC 221: Introduction to Programming Fall 2018
Primary School Computing
Chapter 7 The Game Loop and Animation
Presentation transcript:

Guide to Programming with Python Week 15 Chapter Twelve Sound, Animation, and Program Development: The Astrocrash Game

Objectives  Read the keyboard  Play sound files & music files  Create animations  Develop a program by writing progressively more complete versions of it Guide to Programming with Python2

The Astrocrash Game Figure 12.1: Sample run of the Astrocrash game The player controls a spaceship and blasts asteroids. Guide to Programming with Python3

Reading the Keyboard  We know from the pizza chef game about reading the mouse (games.mouse.x & games.mouse.y)  Reading keystrokes is different from string input through raw_input() function  games module has facilities for reading individual keystrokes for typical game input Guide to Programming with Python4

Testing for Keystrokes class Ship(games.Sprite): """ A moving ship. """ def update(self): """ Move ship based on keys pressed. """ if games.keyboard.is_pressed(games.K_w): self.y -= 1 if games.keyboard.is_pressed(games.K_s): self.y += 1 if games.keyboard.is_pressed(games.K_a): self.x -= 1 if games.keyboard.is_pressed(games.K_d): self.x += 1 5 The reading key program: read_key.py

Testing for Keystrokes (continued)  games module has set of key constants –All begin with games.K_ –Alphabetic keys end in lowercase key letter K_a for A –Numeric keys end in number K_1 for 1 –Complete list of keyboard constants in Appendix A Guide to Programming with Python6

Rotate a Sprite class Ship(games.Sprite): """ A rotating ship. """ def update(self): """ Rotate based on keys pressed. """ if games.keyboard.is_pressed(games.K_RIGHT): self.angle += 1 if games.keyboard.is_pressed(games.K_LEFT): self.angle -= 1 if games.keyboard.is_pressed(games.K_1): self.angle = 0 if games.keyboard.is_pressed(games.K_2): self.angle = 90 if games.keyboard.is_pressed(games.K_3): self.angle = 180 if games.keyboard.is_pressed(games.K_4): self.angle = 270 7

Creating an Animation  Animation: A sequence of images (frames) displayed in succession  Frame: A single image in a sequence of images for an animation  Animation class for animations Guide to Programming with Python8

The Explosion Program Guide to Programming with Python9 Shown in succession, the nine frames look like an explosion.

Program the Explosion (Animation) explosion_files = ["explosion1.bmp", "explosion2.bmp", "explosion3.bmp", "explosion4.bmp", "explosion5.bmp", "explosion6.bmp", "explosion7.bmp", "explosion8.bmp", "explosion9.bmp"] explosion = games.Animation(images=explosion_files, x=games.screen.width/2, y=games.screen.height/2, n_repeats = 0, repeat_interval = 5) games.screen.add(explosion) 10

More on Animation Class  Animation class derived from Sprite  Animation constructor takes list of image file names as strings or a list of image objects  n_repeats number of times animation displayed –0 means loop forever  repeat_interval delay between images –Increase number for slower animation –Decrease number for faster animation Guide to Programming with Python11

Working with Sound and Music (Differently)  Sound and Music –Load –Play –Loop –Stop Guide to Programming with Python12

Working with Sounds  Can create sound object by loading a WAV file  The WAV format is great for sound effects missile_sound = games.load_sound("missile.wav") missile_sound.play()  load_sound() function –Takes a string for name of the sound file, returns sound object –Can only load WAV files  play() method plays sound once  Playing a sound –Requires at least one open sound channel –Takes up one of the eight available sound channels –Has no effect if all eight sound channels are in use 13

Looping a Sound missile_sound.play(-1)  play() can take value for looping  Value is number of additional times sound should be played after initial playing  Pass -1 to loop forever Guide to Programming with Python14

Stopping a Sound missile_sound.stop()  stop() method stops sound on all channels it’s playing  Calling stop() while sound not playing will not produce error Guide to Programming with Python15

Working with Music  Music is handled somewhat differently than sound  Only one music channel  Don’t create a new object for each music file; instead, access a single object to load, play, and stop music  Music channel accepts many different types of sound files, including WAV, OGG, MP3, and MIDI Guide to Programming with Python16

Loading/Playing Music games.music.load("theme.mid") games.music.play() #compared to the sound! #missile_sound = games.load_sound("missile.wav") #missile_sound.play()  music object has methods to load, play, and stop the single music track  Loading music track replaces current track  play() plays currently loaded music –If pass no value to play(), music plays once –If pass a number, additional times sound should be played after initial playing –Pass -1 to loop forever 17

Stopping Music games.music.stop()  stop() method stops music from playing  Calling stop() while music not playing will not produce error Guide to Programming with Python18

Planning the Astrocrash Game  Write progressively more complete versions  List details –Features –Classes –Assets Guide to Programming with Python19

Game Features  Ship rotate and thrust based on keystrokes  Ship fire missiles based on a keystroke  Asteroids float at different velocities on the screen; smaller asteroids generally have higher velocities than larger ones  Ship, missiles, and asteroids “wrap around” screen  Missile collides with ship or asteroid, both destroyed and produce explosion  Ship collides with asteroid, both destroyed and produce explosion  Large asteroid destroyed, two medium asteroids produced Guide to Programming with Python20

Game Features (continued)  Medium asteroid destroyed, two small asteroids produced  Small asteroid destroyed, no new asteroids produced  Ship destroyed, game over  Player earns points for asteroids destroyed; smaller asteroids worth more than larger ones  Player’s score displayed in upper-right corner of screen  All asteroids destroyed, larger wave of asteroids produced Guide to Programming with Python21

Game Classes  Ship  Missile  Asteroid  Explosion Guide to Programming with Python22

Game Assets  Image file for ship  Image file for missiles  Three image files, one for each size of asteroid  Series of image files for explosion  Sound file for thrusting of ship  Sound file for firing of missile  Sound file for explosion  Music file for the theme Guide to Programming with Python23

Creating Asteroids  The Astrocrash01 Program –Create eight asteroids at random locations –Velocity of asteroid is random; smaller asteroids have potential to move faster than larger ones –Could have chosen to start differently (with player ship, for example) –Key is to build progressively more complete versions Guide to Programming with Python24

Rotating the Ship  The Astrocrash02 Program –Create ship at center of the screen –Player can rotate ship –Player presses Right Arrow key, ship rotates clockwise –Player presses Left Arrow key, ship rotates counterclockwise Guide to Programming with Python25

Moving the Ship  The Astrocrash03 Program –Player presses Up Arrow to engage ship’s engine; applies thrust to ship in facing-direction –Engaging engine produces sound effect Guide to Programming with Python26

Firing Missiles  The Astrocrash04 Program –Player presses the spacebar, fires missile –Missile created in front of ship’s cannon and flies off in direction ship facing –Omit collision detection for now –Problem: if player holds down the spacebar, stream of missiles pours out at rate of 50/second –Fix problem in future version Guide to Programming with Python27

Controlling the Missile Fire Rate  The Astrocrash05 Program –Limit fire rate by creating countdown that forces delay between missile firings –Once the countdown ends, player can fire again Guide to Programming with Python28

Handling Collisions  The Astrocrash06 Program –Missile collides with other object, destroys self and other –Ship collides with asteroid, destroys self and asteroid –Asteroids passive; don’t want overlapping asteroids to destroy each other –Asteroids destroyed can produce new asteroids –Problem: because asteroids initially generated at random locations, possible for one to be created on top of ship, destroying ship just as program begins –Fix problem in future version Guide to Programming with Python29

Adding Explosions  The Astrocrash07 Program –Add explosions as result of collisions –Remove redundant code Guide to Programming with Python30

Adding Levels, Scorekeeping, and Theme Music  The Astrocrash08 Program –Add levels; when player destroys all asteroids, a new, more plentiful batch produced –Add scorekeeping functionality –Add theme music –Reorganize some code Guide to Programming with Python31

Summary  keyboard object provides access to keyboard –keyboard.is_pressed() tests if specific key is being pressed –games module defines set of key constants  Animation is a subclass of Sprite for graphics objects that are series of images shown in succession  Working with sounds and music  Astrocrash games –After creating design, writing progressively more complete versions of program is one strategy for large projects –Astrocrash written in eight successively more complete versions 32

Useful Links  Online image editing tools –  I love wavs – Guide to Programming with Python33