Beginner C++ Game Programming Tutorial 11

From Chilipedia
Revision as of 12:22, 11 October 2019 by Ap (Talk | contribs) (Downloads)

Jump to: navigation, search

References are sweet because they let us control our shit from far away. Remember the days when we had to actually get up to change the channel on the TV? Remember TV? Fuck that shit! Also, const correctness is for big dick gangstas that don't give any fucks.

Concepts Taught

  • References
  • Passing by reference
  • const correctness (redux)

Const Correctness

The use of const as a means of communication by code and as method to prevent you and other people from shooting you (your code / themselves) in the dick is something that Chili finds cromulent. For some info on how const makes your code less shitty, check this. If you're still not sold (I happen to like being a human dumpster fire, thank you very much Chili), here is a video showing how using const can make your code a fuck of a lot faster: cool beans.

Video Timestamp Index

  • Intro 0:00
  • Drawing rect function 0:41
  • Creating a Color object 4:32
  • Controlling the rectangle with the mouse 6:46
  • Extending DrawRect function to account for the "flip over" on the x and y, when x1 or y1 < x0 or y0 8:23
  • Test and swap x0,y0 and x1,y1 10:19
  • Shit don't work, references to the rescue! 12:16
  • Making Test and swap work! 17:45
  • Refactoring DrawRect 20:36
  • Poo game: Moving poo drawing code from Game class into Poo class 21:35
  • Process Consumption refactoring (args): passing Dude object by reference 25:48
  • Const correctness: passing by const reference 28:25
  • Const correctness: Making member functions const 30:40
  • Recap 32:01
  • Homework 34:05

Homework

  1. Move the drawing code for Dude from Game into the Dude class.
  2. Make a second DrawRect function that takes a single point (top left corner) and the dimensions as parameters.

The solution is given in this video.

Downloads

See also