Project

General

Profile

Revision 376

scoreboards zombies done

View differences:

proj/src/project/include/scoreboards.h
57 57
 */
58 58
void (check_new_score)(highscores_t *p, int score, int time_played);
59 59
/**
60
 * @brief Updates highscores text.
61
 * @param p     Pointer to highscores.
62
 */
63
void (highscores_update_text)(highscores_t *p);
64
/**
65
 * @brief highscore menu state.
66
 *
67
 * This function allows to check if the mouse is hovering over the back button, and knowing
68
 * if it was clicked.
69
 * @param   menu    Pointer to highscore
70
 * @param   click   0 if mouse right button is clicked, other value otherwise
71
 * @return  return 0 if back option is clicked else -1
72
 */
73
int (highscore_update_state)(highscores_t *p, int click);
74
/**
75
 * @brief Draw highscore on screen buffer.
76
 * @param   p    Pointer to highscores to be drawn
77
 */
78
void (highscores_draw)(highscores_t *p);
79
/**
60 80
 * @brief Destruct menu.
61 81
 * @param   p   Pointer to menu to destruct
62 82
 */
proj/src/project/include/zombies.h
22 22
 * @brief Zombies ranking.
23 23
 * @param zombies_highscore Highscores.
24 24
 */
25
void (zombies_ranking)(highscores_t *zombie_highscore);
25
int (zombies_ranking)(highscores_t *zombie_highscore);
26 26

  
27 27
/**
28 28
 * @}
proj/src/project/src/scoreboards.c
11 11

  
12 12
#define MAX_HIGHSCORES   3 /** @brief Number of scores saved */
13 13

  
14
static const int W  = 400;
15
static const int H  = 80;
16
static const int W1 = 200;
17
static const int H1 = 60;
18
static const int H2 = 100;
19

  
14 20
struct  score_info {
15 21
    int day;
16 22
    int month;
......
28 34
    const font_t *fnt;
29 35
    rectangle_t *r[(MAX_HIGHSCORES+1)*3 + 1];
30 36
    text_t      *t[(MAX_HIGHSCORES+1)*3 + 1];
31
    rectangle_t *frame;
32 37
};
33 38

  
34 39
score_info_t* (score_ctor)(int score, int time_played){
......
75 80
    }
76 81
    fclose(f);
77 82

  
83
    ret->fnt = fnt;
84
    const uint16_t Wtotal = (MAX_HIGHSCORES+1)*W1;
85
    const uint16_t Htotal = (uint16_t)((MAX_HIGHSCORES+1)*H1);
86
    int16_t xi = graph_get_XRes()/2-Wtotal/2+W1/2;
87
    int16_t x = xi;
88
    int16_t y = graph_get_YRes()/2-Htotal/2-H1/2;
89

  
90
    {
91
        rectangle_t *r = rectangle_ctor(x, y, W1, H1);
92
        text_t      *t = text_ctor(ret->fnt, "Date");
93
        rectangle_set_fill_color   (r, GRAPH_BLACK);
94
        rectangle_set_outline_width(r, -2);
95
        rectangle_set_outline_color(r, GRAPH_WHITE);
96

  
97
        text_set_pos(t, x + W1/2, y + H1/2);
98
        text_set_valign(t, text_valign_center);
99
        text_set_halign(t, text_halign_center);
100
        text_set_color (t, TEXT_COLOR);
101
        ret->r[0] = r;
102
        ret->t[0] = t;
103

  
104
        x+=W1;
105

  
106
        r = rectangle_ctor(x, y, W1, H1);
107
        t = text_ctor(ret->fnt, "Score");
108
        rectangle_set_fill_color   (r, GRAPH_BLACK);
109
        rectangle_set_outline_width(r, -2);
110
        rectangle_set_outline_color(r, GRAPH_WHITE);
111

  
112
        text_set_pos(t, x + W1/2, y + H1/2);
113
        text_set_valign(t, text_valign_center);
114
        text_set_halign(t, text_halign_center);
115
        text_set_color (t, TEXT_COLOR);
116
        ret->r[1] = r;
117
        ret->t[1] = t;
118

  
119
        x+=W1;
120

  
121
        r = rectangle_ctor(x, y, W1, H1);
122
        t = text_ctor(ret->fnt, "Time Played");
123
        rectangle_set_fill_color   (r, GRAPH_BLACK);
124
        rectangle_set_outline_width(r, -2);
125
        rectangle_set_outline_color(r, GRAPH_WHITE);
126

  
127
        text_set_pos(t, x + W1/2, y + H1/2);
128
        text_set_valign(t, text_valign_center);
129
        text_set_halign(t, text_halign_center);
130
        text_set_color (t, TEXT_COLOR);
131
        ret->r[2] = r;
132
        ret->t[2] = t;
133

  
134

  
135
        x = xi;
136
    }
137
    y+= H1;
138

  
139
     for (int i = 0; i < MAX_HIGHSCORES*3; i++) {
140
         rectangle_t *r = rectangle_ctor(x, y, W1, H1);
141
         text_t      *t = text_ctor(ret->fnt, "");
142
         rectangle_set_fill_color   (r, GRAPH_BLACK);
143
         rectangle_set_outline_width(r, -2);
144
         rectangle_set_outline_color(r, GRAPH_WHITE);
145

  
146
         text_set_pos(t, x + W1/2, y + H1/2);
147
         text_set_valign(t, text_valign_center);
148
         text_set_halign(t, text_halign_center);
149
         text_set_color (t, TEXT_COLOR);
150

  
151
         x += W1;
152
         ret->r[MAX_HIGHSCORES + i] = r;
153
         ret->t[MAX_HIGHSCORES + i] = t;
154
         if ((i+1) % 3 == 0) {
155
             x = xi;
156
             y += H1;
157
         }
158
     }
159
     y += H2;
160
     x = graph_get_XRes()/2-W/2;
161
     {
162
         rectangle_t *r = rectangle_ctor(x, y, W, H);
163
         text_t      *t = text_ctor(ret->fnt, "Back");
164
         rectangle_set_fill_color   (r, GRAPH_BLACK);
165
         rectangle_set_outline_width(r, -2);
166
         rectangle_set_outline_color(r, GRAPH_WHITE);
167

  
168
         text_set_pos(t, x + W/2, y + H/2);
169
         text_set_valign(t, text_valign_center);
170
         text_set_halign(t, text_halign_center);
171
         text_set_color (t, TEXT_COLOR);
172
         ret->r[(MAX_HIGHSCORES+1)*3] = r;
173
         ret->t[(MAX_HIGHSCORES+1)*3] = t;
174
     }
175

  
176
     highscores_update_text(ret);
177

  
78 178
    return ret;
79 179
}
80 180

  
181
void (highscores_update_text)(highscores_t *p) {
182
    for (int i = 0; i < MAX_HIGHSCORES; i++) {
183
        char buffer[20];
184
        score_info_t *score = p->highscores[i];
185
        sprintf(buffer, "%02d/%02d/%02d %02d:%02d:%02d",
186
                    (score->day), (score->month), (score->year),
187
                    (score->hour), (score->month), (score->sec));
188

  
189

  
190
        text_set_string(p->t[MAX_HIGHSCORES + i*3], buffer);
191
        sprintf(buffer, "%d", score->score);
192
        text_set_string(p->t[MAX_HIGHSCORES + i*3+1], buffer);
193
        sprintf(buffer, "%d", score->time_played);
194
        text_set_string(p->t[MAX_HIGHSCORES + i*3+2], buffer);
195
    }
196
}
197

  
198
int (highscore_update_state)(highscores_t *p, int click) {
199
    if(!click) return -1;
200
    if (rectangle_collide_point(p->r[(MAX_HIGHSCORES+1)*3], *get_mouse_X(), *get_mouse_Y()))
201
        return 0;
202
    return -1;
203
}
204

  
205
void (highscores_draw)(highscores_t *p) {
206
    for(size_t i = 0; i < (MAX_HIGHSCORES+1)*3; ++i){
207
        rectangle_draw(p->r[i]);
208
        text_draw     (p->t[i]);
209
    }
210
    int x = *get_mouse_X(), y = *get_mouse_Y();
211
    if(rectangle_collide_point(p->r[(MAX_HIGHSCORES+1)*3], x, y))
212
        rectangle_set_fill_color(p->r[(MAX_HIGHSCORES+1)*3], HIGHLIGHT_COLOR);
213

  
214
    rectangle_draw(p->r[(MAX_HIGHSCORES+1)*3]);
215
    text_draw     (p->t[(MAX_HIGHSCORES+1)*3]);
216
    rectangle_set_fill_color(p->r[(MAX_HIGHSCORES+1)*3], GRAPH_BLACK);
217
}
218

  
81 219
void (check_new_score)(highscores_t *p, int score, int time_played){
82 220
    score_info_t *new_score = score_ctor(score, time_played);
83 221
    if (new_score == NULL) return;
proj/src/project/src/zombies.c
153 153
    return SUCCESS;
154 154
}
155 155

  
156
void (zombies_ranking)(highscores_t *zombies_highscore) {
156
int (zombies_ranking)(highscores_t *zombies_highscore) {
157 157

  
158
    int r;
159

  
160
    text_t *title     = text_ctor(font_get_default(), "Zombies Ranking");
161
    text_set_color(title, TEXT_COLOR);
162
    text_set_size(title, 70);
163
    text_set_pos(title, graph_get_XRes()/2, graph_get_YRes()*0.17);
164
    text_set_valign(title, text_valign_center);
165
    text_set_halign(title, text_halign_center);
166

  
167
    highscores_update_text(zombies_highscore);
168

  
169
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
170
    uint8_t last_lb = 0;
171
    struct packet pp;
172
    keys_t *keys = get_key_presses();
173

  
174
    /// loop stuff
175
    int click = 0;
176
    uint64_t int_vector = 0;
177
    int good = true;
178
    while (good) {
179
        /* Get a request message. */
180
        if((r = get_interrupts_vector(&int_vector))) return r;
181
        uint32_t n = 1;
182
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
183
            if (int_vector & n) {
184
                interrupt_handler(i);
185
                switch (i) {
186
                    case TIMER0_IRQ:
187

  
188
                    graph_clear_screen();
189
                    switch(highscore_update_state(zombies_highscore, click)){
190
                        case -1: break;
191
                        case  0: good = false; break;
192
                    }
193
                    highscores_draw(zombies_highscore);
194
                    text_draw(title);
195

  
196
                    click = 0;
197

  
198
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
199
                    sprite_draw(sp_crosshair);
200
                    graph_draw();
201

  
202
                    break;
203
                    case KBC_IRQ:
204
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
205
                    case MOUSE_IRQ:
206
                    if (mouse_get_counter_mouse_ih() >= 3) {
207
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
208
                        update_mouse(&pp);
209
                        if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
210
                        last_lb = keys->lb_pressed;
211
                        mouse_set_counter_mouse_ih(0);
212
                    }
213
                    break;
214
                    case COM1_IRQ: nctp_ih(); break;
215
                }
216
            }
217
        }
218
    }
219

  
220
    text_dtor(title);
221
    return 0;
158 222
}
proj/src/Makefile
12 12
SRCS= list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c fast_math.c xpm_utils.c rtc.c uart.c makecode_map.c menu.c proj_func.c rectangle.c font.c ent.c proj.c hltp.c zombies.c campaign.c singleplayer.c chat.c scoreboards.c
13 13
IPATHS=-I./project/include -I./libs -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm
14 14

  
15
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED__ -Wall -Wextra -Wshadow -Wunreachable-code #-Weverything -Wno-padded -Wno-unused-macros
15
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO -D __LCOM_OPTIMIZED__ -Wall -Wextra -Wshadow -Wunreachable-code #-Weverything -Wno-padded -Wno-unused-macros
16 16

  
17 17
DPADD += ${LIBLCF}
18 18
LDADD += -llcf

Also available in: Unified diff