Difference between revisions of "Beginner C++ Game Programming Tutorial 5"

From Chilipedia
Jump to: navigation, search
(Solution Errata)
(Download Links)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Comparison and Boolean logic operators. Operators galore! Make <code>if</code> statements great again! Let the <code>int</code> dick measuring contests begin!
+
Comparison and Boolean logic operators. Operators galore! Make <code>if</code> statements great again! Let the <code>int</code> dick measuring contests begin! Also, collision detection between rectangles, which is useful for stuff.
  
 
== Concepts Taught ==
 
== Concepts Taught ==
Line 5: Line 5:
 
* Boolean operators (<code>&&</code>, <code>||</code>, <code>!</code>)
 
* Boolean operators (<code>&&</code>, <code>||</code>, <code>!</code>)
 
* Using parentheses to change order of evaluation (effectively changing what an operator works on)
 
* Using parentheses to change order of evaluation (effectively changing what an operator works on)
 +
* Collision (overlap) detection of rectangular regions (in the homework)
  
 
== Video Timestamp Index ==
 
== Video Timestamp Index ==
Coming soon!
+
* Intro [https://www.youtube.com/watch?v=UREKHWvg9ko&t=0m0s 0:00]
 +
* A few remarks on drawing pixels outside window bounds [https://www.youtube.com/watch?v=UREKHWvg9ko&t=1m19s 1:19]
 +
* Debug configuration, assertion failures [https://www.youtube.com/watch?v=UREKHWvg9ko&t=2m4s 2:04]
 +
* Comparison operators [https://www.youtube.com/watch?v=UREKHWvg9ko&t=3m11s 3:11]
 +
* Logical operators [https://www.youtube.com/watch?v=UREKHWvg9ko&t=12m41s 12:41]
 +
* Homework [https://www.youtube.com/watch?v=UREKHWvg9ko&t=19m0s 19:00]
  
 
== Homework ==
 
== Homework ==
 
Draw two targeting boxes, one controlled with the arrow keys and one stationary, and have the color of the mobile targeting box change whenever the targeting boxes overlap.
 
Draw two targeting boxes, one controlled with the arrow keys and one stationary, and have the color of the mobile targeting box change whenever the targeting boxes overlap.
  
The solution will be given in a future video.
+
The solution is given in [https://youtu.be/Uxca1CD5ifk this video].
  
=== Solution Errata ===
+
== Download Links ==
Read the below only after attempting the problem yourself.
+
* [https://planetchili.net/downloads/apworks/5/Beginner%20Tutorial%205%20Code.zip Tutorial 5 Code]
 
+
* [https://planetchili.net/downloads/apworks/5/Beginner%20Tutorial%205%20HW%20Code.zip Tutorial 5 Homework Solution Code]
<div class="mw-collapsed mw-collapsible" style="align:left">
+
In the solution ([https://youtu.be/4vc8riKxPUg?t=3m32s 3:32]), Chili declares (in <code>Game</code>) a <code>bool</code> variable <code>controlIsPressed</code> to signal that the shape should be changed. First of all, the key being pressed is the SHIFT key, so this is confusing.
+
 
+
Secondly, a better name for this variable would have been <code>isBoxMode</code>, since the drawing code doesn't really care what key was actually pressed, all it wants to know is what shape it should be drawing. This doesn't affect the behavior of the program in any way, but it makes it more logically coherent.
+
</div>
+
  
 
== See also ==
 
== See also ==
 
* [[Beginner C++ Game Programming Tutorial 6|Next in series (Tutorial 6)]]
 
* [[Beginner C++ Game Programming Tutorial 6|Next in series (Tutorial 6)]]
 
* [[Beginner C++ Game Programming Series]]
 
* [[Beginner C++ Game Programming Series]]

Latest revision as of 12:55, 12 October 2019

Comparison and Boolean logic operators. Operators galore! Make if statements great again! Let the int dick measuring contests begin! Also, collision detection between rectangles, which is useful for stuff.

Concepts Taught

  • Comparison operators (>, <, ==, >=, <=, !=)
  • Boolean operators (&&, ||, !)
  • Using parentheses to change order of evaluation (effectively changing what an operator works on)
  • Collision (overlap) detection of rectangular regions (in the homework)

Video Timestamp Index

  • Intro 0:00
  • A few remarks on drawing pixels outside window bounds 1:19
  • Debug configuration, assertion failures 2:04
  • Comparison operators 3:11
  • Logical operators 12:41
  • Homework 19:00

Homework

Draw two targeting boxes, one controlled with the arrow keys and one stationary, and have the color of the mobile targeting box change whenever the targeting boxes overlap.

The solution is given in this video.

Download Links

See also