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

From Chilipedia
Jump to: navigation, search
(Created page with "We learn how to control the flow of execution using <code>if</code> statements, we learn about a new variable type called <code>bool</code>, and we learn...")
 
Line 1: Line 1:
We learn how to control the flow of execution using <code>if</code> statements, we learn about a new [[variable]] type called [[variable#bool|<code>bool</code>]], and we learn how to use the [[Chili Framework]] to get [[Keyboard (Chili Framework)|keyboard]] input. All this, plus the dankest memes from 2007.
+
In this tutorial explore the ideas animation in computer graphics and we make the reticle move freely around the screen. Along the way we learn how to add member variables to objects/<code>class</code>es, we learn about .h (header) and .cpp files, we learn about the cruel mortal coil of variables (scope), and I make a joke in very bad taste. All par for the course!
  
 
== Concepts Taught ==
 
== Concepts Taught ==
* <code>if</code> statement
+
* Animation and double buffering
* [[variable#bool|<code>bool</code>]] variable type
+
* Difference between .h and .cpp files
* Using return values from function calls
+
* Adding member variables to a <code>class</code>
* [[Keyboard (Chili Framework)|<code>Keyboard</code>]] (Chili Framework-specific concept)
+
* Variable scope
  
 
== Video Timestamp Index ==
 
== Video Timestamp Index ==
Line 23: Line 23:
  
 
== Homework ==
 
== Homework ==
Using the concepts taught so far, create a program that allows you to position the reticle in one of 9 positions (regular 3x3 grid) by holding the arrow keys, change its color by holding the control key, and change its shape by holding the shift key. The solution is given at the beginning of Tutorial 4.
+
This lesson has three homework problems. Feel free to attempt any or all of them.
 +
# Separate the game logic code from the drawing code. The game logic code should go in the <code>Game::UpdateModel()</code> member function, and the drawing code should remain in <code>Game::ComposeFrame()</code>.
 +
# Change the behavior of the reticle so that it moves at a velocity that is controlled with the arrow keys. This means that the arrow keys don't control direction of movement, but that they control the acceleration.
 +
# Make it so that the acceleration of the reticle is more controllable. How this is accomplished is left up to you. Full marks for using only concepts introduced so far ;)
 +
 
 +
The solutions will be given in a future solution video whose link will be posted here.
  
 
== See also ==
 
== See also ==
* [[Beginner C++ Game Programming Tutorial 4|Next in series (Tutorial 4)]]
+
* [[Beginner C++ Game Programming Tutorial 5|Next in series (Tutorial 5)]]
 
* [[Beginner C++ Game Programming Series]]
 
* [[Beginner C++ Game Programming Series]]

Revision as of 20:53, 14 August 2016

In this tutorial explore the ideas animation in computer graphics and we make the reticle move freely around the screen. Along the way we learn how to add member variables to objects/classes, we learn about .h (header) and .cpp files, we learn about the cruel mortal coil of variables (scope), and I make a joke in very bad taste. All par for the course!

Concepts Taught

  • Animation and double buffering
  • Difference between .h and .cpp files
  • Adding member variables to a class
  • Variable scope

Video Timestamp Index

  • Intro 0:00
  • Homework solution 0:29
  • Sprite origin (base position) 1:30
  • Order of statement execution 5:10
  • Branching (conditional flow control) 6:40
  • if statement / bool type 7:52
  • Keyboard input / objects inside other objects 12:06
  • Function return values 15:55
  • Virtual key codes 17:27
  • if ... else statement 19:33
  • if ... else if chaining 20:35
  • Nesting if statements 22:05
  • Homework assignment 23:48

Homework

This lesson has three homework problems. Feel free to attempt any or all of them.

  1. Separate the game logic code from the drawing code. The game logic code should go in the Game::UpdateModel() member function, and the drawing code should remain in Game::ComposeFrame().
  2. Change the behavior of the reticle so that it moves at a velocity that is controlled with the arrow keys. This means that the arrow keys don't control direction of movement, but that they control the acceleration.
  3. Make it so that the acceleration of the reticle is more controllable. How this is accomplished is left up to you. Full marks for using only concepts introduced so far ;)

The solutions will be given in a future solution video whose link will be posted here.

See also