Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden...

32
GD50 Lecture 2: Breakout Colton Ogden [email protected] David J. Malan [email protected]

Transcript of Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden...

Page 1: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

GD50Lecture 2: Breakout

Colton [email protected]

David J. [email protected]

Page 2: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

http://cdn.cs50.net/2015/x/psets/3/pset3/pset3.html

Page 3: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

● Sprite Sheets● Procedural Layouts● Managing State● Levels● Player Health● Particle Systems● Collision Detection Revisited● Persistent Save Data

Topics

Page 4: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

But first, a demo!

Page 5: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

Our Goal

Page 6: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

Breakout State Flow

StartState

ServeStatePaddleSelectState

VictoryState

HighScoreState

PlayState

GameOverStateEnterHighScoreState

Page 7: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout0 “The Day-0 Update”

Page 8: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

Project Organization

Bad :( Great! :D

Page 9: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout1 “The Quad Update”

Page 10: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

Sprite Sheet

Page 11: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

Quads

Page 12: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout1: New Functions

● love.graphics.newQuad(x, y, width, height, dimensions)○ Specify rectangle boundaries of our Quad and pass in the dimensions

(returned via image:getDimensions on whichever texture we want to make a

Quad for.

● love.graphics.draw(texture, quad, x, y)○ Variant of love.graphics.draw, which we’ve seen, but this time we can pass

in a Quad to draw just the specific part of the texture we want, not the

entire thing!

Page 13: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout2 “The Bounce Update”

Page 14: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout3 “The Brick Update”

Page 15: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout4 “The Collision Update”

Page 16: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

centerDelta

● Take the diff between the ball’s x and the paddle’s center, which is paddle.x + paddle.width / 2 - ball.x; use this to scale the ball’s dx in the negative direction.

● Perform the operation on either side of the paddle based on paddle’s dx; if on the right side, the differential will be negative, so we need to call math.abs to make it positive, then scale it by a positive amount so dx becomes positive.

Paddle Collision

Page 17: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

if left edge of ball is outside brick and dx is positive:

trigger left-side collision

elseif right edge of ball is outside brick and dx is negative:

trigger right-side collision

else if top edge of ball is outside brick:

trigger top-side collision

else

trigger bottom-side collision

Brick Collision (Simple)

Page 18: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

https://github.com/noooway/love2d_arkanoid_tutorial

https://github.com/noooway/love2d_arkanoid_tutorial/wiki/Resolving-Collisions

Alternative Way (Better)

Page 19: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout5 “The Hearts Update”

Page 20: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout6 “The Pretty Colors Update”

Page 21: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout7 “The Tier Update”

Page 22: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout8 “The Particle Update”

Page 23: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout8: New Functions

● love.graphics.newParticleSystem(texture, particles)○ Takes in a particle texture and maximum number of particles we can emit and

creates a particle system we can emit from, update, and render.

More LÖVE particle system functions and info here:

https://love2d.org/wiki/ParticleSystem

Page 24: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout9 “The Progression Update”

Page 25: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout10 “The High Scores Update”

Page 26: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout10: New Functions

● love.filesystem.setIdentity(identity)○ Sets the active subfolder in the default LÖVE save directory for reading and

writing files to.

● love.filesystem.exists(path)○ Check if a file exists in our save directory.

● love.filesystem.write(path, data)○ Writes data, as a string, to the file location at path.

● love.filesystem.lines(path)○ Returns an iterator over the string lines in a file at path, located in our

active identity path.

Page 27: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout11 “The Entry Update”

Page 28: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout12 “The Paddle Select Update”

Page 29: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

breakout13 “The Music Update”

Page 30: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

● Basic Shaders● Anonymous Functions● Tweening● Timers● Solving Matches● Procedural Game Grids● Sprite Art and Palettes

Next Time...

Page 31: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

● Create a Powerup the Player can grab that spawns two additional Balls for the current level.

● Add growing and shrinking to the Paddle when they gain enough points or lose lives (included in the sprite sheet!).

● Add locked blocks and key drops (in the sprite sheet as well) to spice up the level generation.

Assignment 2

Page 32: Lecture 2: Breakout - CS50 CDN · 2018-07-01 · GD50 Lecture 2: Breakout Colton Ogden cogden@cs50.harvard.edu David J. Malan malan@harvard.edu

See you next time!