The NEW Pong Game V13.2.1
An interesting implemnettaion of the pong game
Loading...
Searching...
No Matches
Letter Class Reference

Represents a letter in the storytime game mode. More...

#include <letter.hpp>

Public Member Functions

bool collision_check (float ball_pos_x, float ball_pos_y, float ball_radius) const
 Checks if the ball collides with the letter.
 
float get_pos_x () const
 Gets the X position of the letter.
 
float get_pos_y () const
 Gets the Y position of the letter.
 
 Letter (int index, float startX, float startY, float velocity, SDL_Renderer *renderer, TTF_Font *font)
 Constructor for Letter class.
 
void next_letter ()
 Advances to the next letter in the current word.
 
void next_word ()
 Advances to the next word in the words array.
 
void render (SDL_Renderer *renderer)
 Renders the letter on screen.
 
void reset_word (int n)
 Resets word and letter indices.
 
void update_letter (float time, int screen_height, User *player1, User *player2, float ball_pos_x, float ball_pos_y, float ball_radius)
 Updates the letter position and checks for collisions.
 
 ~Letter ()
 Destructor for Letter class.
 

Private Attributes

int current_letter_index
 
int current_word_index
 
TTF_Font * font
 
int height
 
char letter
 
std::vector< char > lettersAtBottom
 
SDL_Renderer * renderer
 
float speed
 
SDL_Texture * texture
 
int width
 
std::string word
 
std::vector< std::string > words = {"Polytech", "Sorbonne", "2025"}
 
float x
 
float y
 

Detailed Description

Represents a letter in the storytime game mode.

This class handles the display and interaction of letters that move across the screen in the story mode. Players can collect these letters by hitting them with the ball.

Constructor & Destructor Documentation

◆ Letter()

Letter::Letter ( int index,
float startX,
float startY,
float velocity,
SDL_Renderer * renderer,
TTF_Font * font )

Constructor for Letter class.

Parameters
indexInitial index for word and letter selection
startXStarting X position
startYStarting Y position
velocityMovement speed
rendererSDL renderer to use
fontTTF font to use

Initializes a letter with position, speed, and selects the initial word and letter

Parameters
indexInitial index for word and letter selection
startXStarting X position
startYStarting Y position
velocityMovement speed
rendererSDL renderer to use
fontTTF font to use

◆ ~Letter()

Letter::~Letter ( )

Destructor for Letter class.

Cleans up the texture resource

Member Function Documentation

◆ collision_check()

bool Letter::collision_check ( float ball_pos_x,
float ball_pos_y,
float ball_radius ) const

Checks if the ball collides with the letter.

Parameters
ball_pos_xBall's X position
ball_pos_yBall's Y position
ball_radiusBall's radius
Returns
true if collision detected, false otherwise

◆ get_pos_x()

float Letter::get_pos_x ( ) const

Gets the X position of the letter.

Returns
Current X coordinate

◆ get_pos_y()

float Letter::get_pos_y ( ) const

Gets the Y position of the letter.

Returns
Current Y coordinate

◆ next_letter()

void Letter::next_letter ( )

Advances to the next letter in the current word.

Creates a new texture for the next letter or moves to next word if needed

◆ next_word()

void Letter::next_word ( )

Advances to the next word in the words array.

◆ render()

void Letter::render ( SDL_Renderer * renderer)

Renders the letter on screen.

Parameters
rendererSDL renderer to use for drawing

◆ reset_word()

void Letter::reset_word ( int n)

Resets word and letter indices.

Parameters
nNew index to set

◆ update_letter()

void Letter::update_letter ( float time,
int screen_height,
User * player1,
User * player2,
float ball_pos_x,
float ball_pos_y,
float ball_radius )

Updates the letter position and checks for collisions.

Parameters
timeTime delta since last update
screen_heightWindow height for boundary checking
player1Pointer to first player
player2Pointer to second player
ball_pos_xBall's X position
ball_pos_yBall's Y position
ball_radiusBall's radius

Member Data Documentation

◆ current_letter_index

int Letter::current_letter_index
private

Index of current letter in the current word

◆ current_word_index

int Letter::current_word_index
private

Index of current word in the words array

◆ font

TTF_Font* Letter::font
private

TTF font for rendering text

◆ height

int Letter::height
private

Dimensions of the letter texture

◆ letter

char Letter::letter
private

Current letter being displayed

◆ lettersAtBottom

std::vector<char> Letter::lettersAtBottom
private

Letters collected at the bottom of screen

◆ renderer

SDL_Renderer* Letter::renderer
private

SDL renderer reference

◆ speed

float Letter::speed
private

Movement speed of the letter

◆ texture

SDL_Texture* Letter::texture
private

Texture for rendering the letter

◆ width

int Letter::width
private

◆ word

std::string Letter::word
private

Current word being displayed

◆ words

std::vector<std::string> Letter::words = {"Polytech", "Sorbonne", "2025"}
private

Words to display letter by letter

◆ x

float Letter::x
private

◆ y

float Letter::y
private

Position of the letter


The documentation for this class was generated from the following files: