0% found this document useful (0 votes)
16 views23 pages

Quick Game Development With /: Vittorio Romeo

CCP on presentation of ball wall collision game written in c++
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views23 pages

Quick Game Development With /: Vittorio Romeo

CCP on presentation of ball wall collision game written in c++
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

Quick game development with

C++11/C++14

Vittorio Romeo
http://vittorioromeo.info
[email protected]
About myself
● Computer Science student
at the University of Messina
● Autodidact programmer
● Interests:
– Software development
– Gaming and game-
development
– C++ and its evolution
– Open-source software
– Sharing my knowledge

Vittorio Romeo
http://vittorioromeo.info
[email protected]
About this talk
● Introductory part:
– Game development: why?
● Why C++?
● Why C++11/C++14?
● Live coding part:
– Preparation: goals,
compilers, resources
– Live coding: development
analysis/walkthrough of a
complete playable simple
game

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Goals of this talk
● Encouraging
everyone to try game
development
● Demonstrating how
C++ and its newer
standards make
game development a
breeze

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Game development:
all-around development experience
Game development: why?
● Game development Mechanics
Design Style and feel
– Requires knowledge
Story and concept
and skills in multiple

Game development
areas Engine and
architecture

– Involves the Implementation Scripting and


customization
programmer with the Porting
and distribution
community
– Touches a vast Graphics
number of specific Resources Music
programming topics Sounds

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Game development: why C++?
● Efficient: zero-cost
abstractions and “low-
level” code
● Portable: standard-
compliant code can
target many
architectures
● Widespread: huge
number of libraries and
resources available

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Game development:
why C++11/C++14?
● Convenience, safety and expressiveness
– Initializer lists and uniform initialization
– auto, range-based for loops
– Lambdas, variadic templates, decltype factory functions
– override, final, enum class, explicit, nullptr
– default, delete
● Memory management (!)
– std::unique_ptr, std::shared_ptr, offsetof entity management
● Possible performance improvements
– constexpr, std::move, noexcept
● Other improvements/additions
– Multithreading library facilities
– std::tuple, variadic macros, <random>, <chrono> game loop timing
– Generic lambdas, lambda capture expression
– auto functions, relaxed constexpr, std::tuple::get<...>

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Let's get started, then!
Live coding: what is our goal?
● Our goal is creating an
arkanoid/breakout
clone almost from
scratch.
● Step by step, I'll
demonstrate how easy
it is to create a playable
game, in around 200
lines of code.

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Live coding: what compiler?
● C++11 support is mandatory
– g++ 4.7.2 or clang++ 3.0 (or newer) fully support the
C++11 standard
● Some C++14 features will be used
– clang++ 3.4 fully supports the C++14 standard
– g++ 4.9 supports all the C++14 features we'll be using
● Standard compliance information
– http://gcc.gnu.org/projects/cxx1y.html
– http://clang.llvm.org/cxx_status.html

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Live coding: SFML library
● To interface ourselves
with the input, audio,
graphics components
of our computer and our
operating system we'll
use the SFML 2.1
open-source C++
library available at
http://sfml-dev.org

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Live coding: code and resources
● You can download the code and the
resources that are going to be used here:
– http://github.com/SuperV1234/cppcon2014

● The SFML 2.1 library is available here:


– http://sfml-dev.org

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: game loop
● The game loop is a
continuously running Input
loop (until the end of
the game)
– 1. Get input Update
– 2. Update game logic
– 3. Draw game entities
Draw

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: coordinate system
● SFML's coordinate system sets the origin in
the top-left corner of the window.
X

(0, 0) (width, 0)

(0, height) (width, height)

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: ball movement
● By adding a velocity vector to the ball's
position every frame, the ball appears to move.

l ocity
ve

l ocity
ve

l ocity
ve

update update update

time
Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: ball vs window collision

By checking if one of the ball's coordinates is greater or lower than
the window's bounds, we can determine if the ball is outside the
window.
X

ball.x + (ball.width / 2)

window.width

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: AABB vs AABB collision
(top, left) (top, right)

(top, left) (top, right)

vertical overlap
(bottom - top)

(bottom, left) (bottom, right)

(bottom, left) (bottom, right)

horizontal overlap
(right - left)

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: ball vs paddle collision
● Depending on where the paddle was hit, we set
the ball's X velocity towards the left or the right.

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: ball vs brick collision
● We need to change the ball's velocity depending
on the direction the brick was hit from.

overlapRight

overlapLeft
Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: class hierarchy
● This is the final class hierarchy of our game
objects.

Entity Rectangle Circle


(base) (mix-in) (mix-in)

Paddle Brick Ball

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Info: game architecture
● This is the final code architecture of our game
classes.
Game
Manager
Entities

Grouped entities

Vittorio Romeo
http://vittorioromeo.info
[email protected]
Thanks!

Vittorio Romeo
http://vittorioromeo.info
[email protected]

You might also like