casse-brick latest
Ce projet est réalisé dans le cadre du cours de Programmation Avancée en M1 Informatique de l'université de Strasbourg.
Loading...
Searching...
No Matches
platform.cpp
Go to the documentation of this file.
1//
2// Created by nicolas elfering on 15.04.24.
3//
4
5#include "platform.h"
6
7#include <utility>
8
9PLATFORM::PLATFORM(std::shared_ptr<SDL_Renderer> renderer, int x, int y, int min, int max, int speed) :speed(0),
10 renderer(std::move(renderer)), max_width(max), min_width(min), MovingObject((x-max/8),y,max/4,10,"platform") {
11}
12
13void PLATFORM::input(SDL_KeyboardEvent event,bool up) {
14 switch (event.keysym.scancode) {
15 case 4:
16 speed = up ?0:-10;
17 break;
18 case 7:
19 speed = up?0:10;
20 break;
21 default:
22 break;
23 }
24}
25
26void PLATFORM::render(std::shared_ptr<SDL_Renderer> renderer, SDL_Color color1,SDL_Color color2) {
27 collider->render(renderer,color1,color2);
28}
29
30
32
33 collider->move({static_cast<float>(speed),0});
34}
std::shared_ptr< Collider > collider
The collider associated with the object.
The MovingObject class represents a moving colliding object.
void render(std::shared_ptr< SDL_Renderer > renderer, SDL_Color color1, SDL_Color color2) override
Renders the platform on the screen.
Definition platform.cpp:26
void move() override
Moves the platform horizontally.
Definition platform.cpp:31
PLATFORM(std::shared_ptr< SDL_Renderer > renderer, int x, int y, int min, int max, int speed)
Constructs a new PLATFORM object with specified parameters.
Definition platform.cpp:9
void input(SDL_KeyboardEvent event, bool up)
Handles input events for moving the platform.
Definition platform.cpp:13
int speed
The speed at which the platform moves.
Definition platform.h:24
std::shared_ptr< SDL_Renderer > renderer
A shared pointer to the SDL renderer.
Definition platform.h:25