Full Title: Pong - Lecture 0 - CS50’s Introduction to Game Development 2018
Highlights
We’ll be talking about Delta Time and Velocity, which Delta Time is probablyarguably one of the most important variablesthat we keep track of in any game framework or engine, which is justthe amount of time that’s elapsed since the last frame of executionin our game, measured in LOVE 2D in terms of seconds, fractions of seconds ()
Note: Delta Time is one of the most important variables that we keep track of in any game. It records the amount of time that’s elapsed since the last frame of execution.
Almost everything in Lua aside from basic variables, are tables.A table is essentially a dictionary in Python or an object in JavaScript. ()
Note: Lua is mostly made up of basic variables and tables, which themselves are akin to dictionaries in Python.
it was initiallyintended as a config language, and a— just sort of a glue layer.It’s very good for storing data and code together, almost one in the same ()
Note: Because it was originally designed to store configs, Lua is very good at data storage.
the most fundamental thing we should take a look atis what a game loop is.So a game, fundamentally, is just an infinite loop, like a while true or awhile one.Only in this case, every iteration of that loop we’re doing a set of stepsback to back over and over again.We’re processing input so we’re seeing, has the user pressed
a key on the keyboard, have they touched their joystick,have they moved the mouse, clicked the mouse.If they have, we need to feed that into our update.We need to keep track of that, and then change anything in our game statethat relies upon that input.So we should move our paddles, we should detect collision,we should register all of this, and then whatever has updated,we want to rerender that.We want to render it—render where it’s changed so that we have the—we see on our screen, visually, that things have actuallychanged in our game world and we interact with it,
and we get a sense that we’re using something,interacting with something dynamic ()
Note: The game loop is an infinite loop that processes user input, updates the game state, and re-renders the game to reflect changes in order for the user to interact with the game world dynamically.
love.load is just a function that— given to us by LOVE, LOVE 2D,and we overwrite it.We give it behavior, we tell it what to do.
And LOVE 2D is going to look at it in our main.lua file.If we’re looking at Pong Zero, you’ll see it just has a main.lua file.LOVE 2D expects just a main.lua file, and will run the main.lua file,and you can reference any other file within the directory from that main.luafile.It’s our bootstrap, effectively.We’re going to override love.load with whateverwe want to execute at the very beginning of our application.It’s just a startup function. ()
Note: The “love.load” function is provided by LOVE 2D, and is overwritten by the user in the main.lua file. This is the “bootstrap” of the application, and is executed at the start. It is used to define the behavior of the application.
Love.update(dt) is a very important function.This function takes in a variable called (dt).Love passes it in a function.You’re going to overwrite it with your own behavior,and Love is going to execute this every frame, passing it in delta time,and you can use delta time (dt) in that functionto change your application based upon how much time has passed.
(dt) will always be a fraction of a second, potentially more,depending on how slow your computer is.But, typically, one-sixtieth of a second.And you can scale anything in your game by that amountto get even behavior across all frame rates. ()
Note: The function Love.update(dt) is essential in game development. It takes a variable (dt) and passes it in a function. The user can overwrite it to create their own behavior. Love will execute the function every frame, passing it delta time (dt). Delta time is typically one-sixtieth of a second, and it can be used to scale anything in the game so that it runs evenly across all frame rates.
Love.draw is the other big function amongst—between update and draw.Two of the two, arguably, most important functions.Love.draw is the function that we’re goingto define that has all of our drawing behavior, our rendering behavior in it. ()
Note: Love.draw is an important function in game development which contains all the drawing and rendering behavior of the game. It is one of the two most important functions alongside update.
So love.graphics.setDefaultFilter.This function, the purpose of that, is every time
we have a font or an image in our application,it’s going to be applied a filter by default.So it’s going to by default a bilinear filter.So what’s going to happen, the effect of thatis, basically, whenever we magnify or downscale a texture,it’s going to think that— it’s going to assumethat we want it to be slightly blurred so as to not look too pixilated.Which is good in certain contexts.For higher res 2D game development, that’s good, but as we’re going to see,
that’s not particularly good in the context of retro games.Retro games have a very 2D, crisp, pixilated aesthetic,and we want to preserve that. ()
Note: This function sets a filter that is applied to fonts and images by default. The filter is a bilinear filter which blurs the image when it is scaled up or down. This is good for high resolution 2D game development, but not for retro games which have a 2D, crisp, pixelated aesthetic which needs to be preserved.
We have two rectangles.If this top edge is below this edge, we knowno matter what, they’re not going to inter— they’re not intersecting.There is no way it can because it’s below here.So no matter where it is on the x and the y, if it’s below here,
it’s not a collision.If this edge is on this side of this rectangle,we know, as well, there’s no way those two boxes can overlap.And it applies to every edge as long as it is the opposite edge.So if this edge is below this one, if this edge is above this one,if this edge is on the right, and this edge is on the left,it means that no matter what, those boxes aren’t colliding.So we can simply do four conditions.We can say, if rec1.x is not greater than rec 2.x, plus rec2.width,
and rec1.x plus rec1.width is not less than rec2.x,so if the two edges are not beyond their opposite edges, same thing with the y,and the y plus rec1.height, we know that we have a collision.We know that because we haven’t fulfilled any of those criteria.But we know that if that’s not true, if the—
one of the edges is not beyond the opposite edge, then it’s—we do have a collision.So it is going to be true ()
Note: This text explains how to determine whether two rectangles are colliding by comparing their edges. If the top edge of one rectangle is below the bottom edge of the other rectangle, or the left edge of one rectangle is to the right of the right edge of the other rectangle, then the two rectangles are not intersecting. If none of these conditions are true, then the rectangles are colliding.