Coding the player: Part 1
In this section, we will begin to create the controllable player character. We will make the character visible on the screen but will return to the PlayerUpdate
and PlayerGraphics
classes and add keyboard controls and animations.
Create two new classes: PlayerUpdate
, which uses Update
as the base class, and PlayerGraphics
, which uses Graphics
as the base class. After the next two sections, we will have a visible but not fully functioning player character.
Coding the PlayerUpdate class
Let’s start with the PlayerUpdate
class definition. Add the following code to PlayerUpdate.h
:
#pragma once
#include "Update.h"
#include "InputReceiver.h"
#include <SFML/Graphics.hpp>
using namespace sf;
class PlayerUpdate :
public Update
{
private:
const float PLAYER_WIDTH = 20.f;
const float PLAYER_HEIGHT = 16.f;
FloatRect m_Position;
bool* m_IsPaused = nullptr;
float m_Gravity = 165;
float m_RunSpeed...