Difference between revisions of "Intermediate C++ Game Programming Tutorial 12"
From Chilipedia
(Created page with "In this tutorial Chili shows us an example of how to create a class for an animated sprite, and how to use a collection of these animated sprites to create a walking character...") |
m (Text replacement - "http://www.planetchili.net/" to "https://www.planetchili.net/") |
||
| (24 intermediate revisions by 2 users not shown) | |||
| Line 4: | Line 4: | ||
* Animated sprite class design | * Animated sprite class design | ||
* Walking character class design | * Walking character class design | ||
| + | |||
| + | == Notes == | ||
| + | The technique we use of storing a reference to <code>Surface</code> in each <code>Animation</code> object will work for now, but it will cause us a pain in the dick in the future when we start using our characters in containers like <code>std::vector</code>. The reason for this is because you cannot assign a reference to refer something else after it has been bound, and so the compiler cannot generate copy assign for us by default. We will fix this problem when it becomes an issue for us (in the Action RPG Project). | ||
== Video Timestamp Index == | == Video Timestamp Index == | ||
| − | [https://youtu.be/ | + | [https://youtu.be/KXn7-5zg3J4 Tutorial 12] |
| + | * Introducing the <code>Character</code> and <code>Animation</code> classes [https://youtu.be/KXn7-5zg3J4?t=0m20s 0:20] | ||
| + | * Creating header file for the <code>Animation</code> class [https://youtu.be/KXn7-5zg3J4?t=0m49s 0:49] | ||
| + | * Implementing the <code>Animation</code> class [https://youtu.be/KXn7-5zg3J4?t=3m30s 3:30], constructor implementation at [https://youtu.be/KXn7-5zg3J4?t=5m15s 5:15] | ||
| + | * Copy the FrameTimer class used in earlier tutorials [https://youtu.be/KXn7-5zg3J4?t=7m35s 7:35] | ||
| + | * Give it a test run: have an animated sprite follow the cursor [https://youtu.be/KXn7-5zg3J4?t=8m00s 8:00] | ||
| + | * Creating header file for the <code>Character</code> class [https://youtu.be/KXn7-5zg3J4?t=11m05s 11:05] | ||
| + | * Using an <code>enum class</code>, namecode the different animation sequences [https://youtu.be/KXn7-5zg3J4?t=11m49s 11:49] | ||
| + | * Implementing the <code>Character</code> class [https://youtu.be/KXn7-5zg3J4?t=13m08s 13:08] | ||
| + | * Add an operator in the <code>Vec2</code> class that applies explicit conversion (cast) of a float position pair into an int position pair [https://youtu.be/KXn7-5zg3J4?t=17m20s 17:20] | ||
| + | * Create the <code>SetDirection</code> function that sets the direction of motion and the animation sequence [https://youtu.be/KXn7-5zg3J4?t=18m24s 18:24] | ||
| + | * Test the <code>Character</code> class by applying it in the <code>Game</code> class [https://youtu.be/KXn7-5zg3J4?t=20m48s 20:48] | ||
| + | * Disclaimer for the approach presented in this tutorial [https://youtu.be/KXn7-5zg3J4?t=23m42s 23:42] | ||
== Source Code == | == Source Code == | ||
| Line 12: | Line 27: | ||
== Download Materials == | == Download Materials == | ||
| − | * [ | + | * [https://www.planetchili.net/downloads/I12-Images.zip Tutorial Images] |
== Homework == | == Homework == | ||
Latest revision as of 13:26, 5 May 2022
In this tutorial Chili shows us an example of how to create a class for an animated sprite, and how to use a collection of these animated sprites to create a walking character class.
Contents
Topics Covered
- Animated sprite class design
- Walking character class design
Notes
The technique we use of storing a reference to Surface in each Animation object will work for now, but it will cause us a pain in the dick in the future when we start using our characters in containers like std::vector. The reason for this is because you cannot assign a reference to refer something else after it has been bound, and so the compiler cannot generate copy assign for us by default. We will fix this problem when it becomes an issue for us (in the Action RPG Project).
Video Timestamp Index
- Introducing the
CharacterandAnimationclasses 0:20 - Creating header file for the
Animationclass 0:49 - Implementing the
Animationclass 3:30, constructor implementation at 5:15 - Copy the FrameTimer class used in earlier tutorials 7:35
- Give it a test run: have an animated sprite follow the cursor 8:00
- Creating header file for the
Characterclass 11:05 - Using an
enum class, namecode the different animation sequences 11:49 - Implementing the
Characterclass 13:08 - Add an operator in the
Vec2class that applies explicit conversion (cast) of a float position pair into an int position pair 17:20 - Create the
SetDirectionfunction that sets the direction of motion and the animation sequence 18:24 - Test the
Characterclass by applying it in theGameclass 20:48 - Disclaimer for the approach presented in this tutorial 23:42
Source Code
Download Materials
Homework
None!