summaryrefslogtreecommitdiffstats
path: root/apps/game_falldown/platform.cpp
blob: 810f4693a71505c78ed0b59baf4abaccf65a1914 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "platform.hpp"

Platform::Platform() {
    m_position_y = DISPLAY_HEIGHT-1;
    m_speed = 1;

    create_tiles();
}

Platform::Platform(int y, int speed) {
    m_position_y = y;
    m_speed = speed;

    create_tiles();
}

void Platform::create_tiles() {
    // example of platform creation
    for (size_t i = 1; i < m_tiles_solid.size(); i += 2) {
        m_tiles_solid.set(i);
    }
}

void Platform::update() {
    m_position_y -= m_speed * 1;
}

void Platform::draw(Api *app_api) {
    // display_draw_line(int x1, int y1, int x2, int y2, int bRender);
    // for each tile
    // FIXME: Is broken
    int position_x = 0;
    for (size_t i = 0; i < m_tiles_solid.size(); ++i) {
        if (m_tiles_solid[i]) {
            int tile_start_x = PLATFORM_TILE_SIZE * i;
            int tile_end_x = tile_start_x + PLATFORM_TILE_SIZE;

            app_api->display_draw_line(tile_start_x, m_position_y, tile_end_x, m_position_y, 1);
        }
    }
}