Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Nivel.cpp
- // Base para juego de plataformas en C++ y Allegro
- #include <vector>
- #include <allegro5/allegro_primitives.h>
- #include "Nivel.h"
- #include "Juego.h"
- namespace {
- // Las plataformas se almacenarán en un vector después de crear el nivel.
- std::vector<Plataforma*> plataformas;
- } // namespace
- void Crear_Nivel(const char *cadena, float& inicio_x, float& inicio_y)
- {
- Destruir_Nivel();
- int x = 0, y = 0;
- // Buscar el jugador y las plataformas en la cadena
- for (const char *pos = cadena; *pos != '\0'; ++pos)
- { if (*pos == 'J')
- { inicio_x = x * 32;
- inicio_y = y * 32;
- }
- else if (*pos == 'X')
- plataformas.push_back(new Plataforma(x * 32, y * 32));
- ++x;
- if (x == TAMANO_NIVEL_X)
- { ++y;
- x = 0;
- }
- }
- }
- void Dibujar_Nivel()
- {
- for (auto i : plataformas)
- al_draw_filled_rectangle(i->x, i->y, i->x + 32, i->y + 32, C_BLANCO);
- }
- void Destruir_Nivel()
- {
- for (auto i : plataformas)
- delete i;
- plataformas.clear();
- }
- Plataforma *Checar_Plataforma(float _x, float _y)
- {
- for (auto i : plataformas)
- { if (bbox_collision(_x, _y, TAMANO_JUGADOR_X, TAMANO_JUGADOR_Y, i->x, i->y
- , 32, 32))
- return i;
- }
- return nullptr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement