Project

General

Profile

Revision 305

working on zombies

View differences:

proj/include/ent.h
12 12
double (ent_get_YLength)(void);
13 13

  
14 14
typedef enum {
15
    gunner_meelee,
16
    gunner_ranged,
17
    gunner_player
15
    gunner_melee  = BIT(0),
16
    gunner_ranged = BIT(1),
17
    gunner_player = BIT(2),
18
    gunner_follow = BIT(3)
18 19
} gunner_type;
19 20

  
20 21
struct gunner;
proj/include/proj_macros.h
26 26
#define HIGHLIGHT_COLOR         0x404040
27 27
#define DELIMITER_COLOR         0x404040
28 28

  
29
#define MEELEE_RANGE    150
30
#define MEELEE_DAMAGE   1
29
#define MELEE_RANGE    150
30
#define MELEE_DAMAGE   1
31 31

  
32 32
#endif /* end of include guard: PROJ_MACROS_H_INCLUDED */
proj/src/proj.c
125 125
        if (is_ipc_notify(ipc_status)) { /* received notification */
126 126
            switch (_ENDPOINT_P(msg.m_source)) {
127 127
                case HARDWARE: /* hardware interrupt notification */
128
                    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
129
                        if (msg.m_notify.interrupts & n) {
130
                            interrupt_handler(i);
131
                            switch (i) {
128
                for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
129
                    if (msg.m_notify.interrupts & n) {
130
                        interrupt_handler(i);
131
                        switch (i) {
132 132
                            case TIMER0_IRQ:
133 133

  
134
                                graph_clear_screen();
135
                                switch(menu_update_state(main_menu, click)){
136
                                    case -1: break;
137
                                    case  0: singleplayer(); break; //campaign(); break;
138
                                    case  1: break;
139
                                    case  2: chat(); break;
140
                                    case  3: good = false; break;
141
                                }
142
                                menu_draw(main_menu);
134
                            graph_clear_screen();
135
                            switch(menu_update_state(main_menu, click)){
136
                                case -1: break;
137
                                case  0: singleplayer(); break; //campaign(); break;
138
                                case  1: break;
139
                                case  2: chat(); break;
140
                                case  3: good = false; break;
141
                            }
142
                            menu_draw(main_menu);
143 143

  
144
                                click = 0;
144
                            click = 0;
145 145

  
146
                                sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
147
                                sprite_draw(sp_crosshair);
148
                                graph_draw();
146
                            sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
147
                            sprite_draw(sp_crosshair);
148
                            graph_draw();
149 149

  
150
                                break;
150
                            break;
151 151
                            case KBC_IRQ:
152
                                if ((scancode[0]) == ESC_BREAK_CODE) good = false;
152
                            if ((scancode[0]) == ESC_BREAK_CODE) good = false;
153 153
                            case MOUSE_IRQ:
154
                                if (counter_mouse_ih >= 3) {
155
                                    mouse_parse_packet(packet_mouse_ih, &pp);
156
                                    update_mouse(&pp);
157
                                    if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
158
                                    last_lb = keys->lb_pressed;
159
                                    counter_mouse_ih = 0;
160
                                }
161
                                break;
154
                            if (counter_mouse_ih >= 3) {
155
                                mouse_parse_packet(packet_mouse_ih, &pp);
156
                                update_mouse(&pp);
157
                                if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
158
                                last_lb = keys->lb_pressed;
159
                                counter_mouse_ih = 0;
160
                            }
161
                            break;
162 162
                            case COM1_IRQ: nctp_ih(); break;
163
                            }
164 163
                        }
165 164
                    }
165
                }
166 166

  
167
                    break;
167
                break;
168 168
                default:
169
                    break; /* no other notifications expected: do nothing */
169
                break; /* no other notifications expected: do nothing */
170 170
            }
171 171
        } else { /* received standart message, not a notification */
172 172
            /* no standart message expected: do nothing */
......
185 185
    // Unsubscribe interrupts
186 186
    if (unsubscribe_all()) {
187 187
        if (cleanup())
188
            printf("%s: failed to cleanup.\n", __func__);
188
        printf("%s: failed to cleanup.\n", __func__);
189 189
        return 1;
190 190
    }
191 191

  
......
224 224
            if (int_vector & n) {
225 225
                interrupt_handler(i);
226 226
                switch (i) {
227
                case TIMER0_IRQ:
227
                    case TIMER0_IRQ:
228 228

  
229 229
                    graph_clear_screen();
230 230
                    switch(menu_update_state(main_menu, click)){
......
242 242
                    graph_draw();
243 243

  
244 244
                    break;
245
                case KBC_IRQ:
245
                    case KBC_IRQ:
246 246
                    if ((scancode[0]) == ESC_BREAK_CODE) good = false;
247
                case MOUSE_IRQ:
247
                    case MOUSE_IRQ:
248 248
                    if (counter_mouse_ih >= 3) {
249 249
                        mouse_parse_packet(packet_mouse_ih, &pp);
250 250
                        update_mouse(&pp);
......
253 253
                        counter_mouse_ih = 0;
254 254
                    }
255 255
                    break;
256
                case COM1_IRQ: nctp_ih(); break;
256
                    case COM1_IRQ: nctp_ih(); break;
257 257
                }
258 258
            }
259 259
        }
......
285 285
    list_t *bullet_list  = list_ctor();
286 286

  
287 287
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
288
                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
288
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
289 289

  
290
   //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
291
   uint8_t last_lb = 0;
292
   struct packet pp;
293
   keys_t *keys = get_key_presses();
290
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
291
    uint8_t last_lb = 0;
292
    struct packet pp;
293
    keys_t *keys = get_key_presses();
294 294

  
295 295
    /// loop stuff
296 296
    uint32_t int_vector = 0;
......
299 299
        /* Get a request message. */
300 300
        if((r = get_interrupts_vector(&int_vector))) return r;
301 301
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
302
           if (int_vector & n) {
303
               interrupt_handler(i);
304
               switch (i) {
305
               case TIMER0_IRQ:
302
            if (int_vector & n) {
303
                interrupt_handler(i);
304
                switch (i) {
305
                    case TIMER0_IRQ:
306 306

  
307
                   if (no_interrupts % 60 == 0) timer_update(in_game_timer);
308
                   update_movement(map1, shooter1, keys, shooter_list);
307
                    if (no_interrupts % 60 == 0) timer_update(in_game_timer);
308
                    update_movement(map1, shooter1, keys, shooter_list);
309 309

  
310
                   update_game_state(map1, shooter_list, bullet_list);
310
                    update_game_state(map1, shooter_list, bullet_list);
311 311

  
312
                   //update_scale();
313
                   double angle = get_mouse_angle(shooter1);
314
                   gunner_set_angle(shooter1, angle - M_PI_2);
312
                    //update_scale();
313
                    double angle = get_mouse_angle(shooter1);
314
                    gunner_set_angle(shooter1, angle - M_PI_2);
315 315

  
316
                   ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
317
                                  gunner_get_y(shooter1)-ent_get_YLength()/2.0);
316
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
317
                    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
318 318

  
319
                   graph_clear_screen();
320
                   map_draw   (map1);
321
                   bullet_draw_list(bullet_list);
322
                   gunner_draw_list(shooter_list);
319
                    graph_clear_screen();
320
                    map_draw   (map1);
321
                    bullet_draw_list(bullet_list);
322
                    gunner_draw_list(shooter_list);
323 323

  
324
                   text_draw(in_game_timer->text);
324
                    text_draw(in_game_timer->text);
325 325

  
326
                   sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
327
                   sprite_draw(sp_crosshair);
328
                   graph_draw();
326
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
327
                    sprite_draw(sp_crosshair);
328
                    graph_draw();
329 329

  
330
                   break;
331
               case KBC_IRQ:
332
                   if ((scancode[0]) == ESC_BREAK_CODE) {
333
                       good = false;
334
                       // reset game
335
                       while(list_size(bullet_list) > 0){
336
                           bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
337
                           bullet_dtor(p);
338
                       }
339
                       list_node_t *it = list_begin(shooter_list);
340
                       while (it != list_end(shooter_list)) {
341
                           gunner_t *p = *(gunner_t**)list_node_val(it);
342
                           get_random_spawn(map1, p);
343
                           gunner_set_curr_health(p, gunner_get_health(p));
344
                           it = list_node_next(it);
345
                       }
346
                       timer_reset(in_game_timer);
347
                   }
348
                   break;
349
               case MOUSE_IRQ:
350
                   if (counter_mouse_ih >= 3) {
351
                       mouse_parse_packet(packet_mouse_ih, &pp);
352
                       update_mouse(&pp);
353
                       if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
354
                           shoot_bullet(shooter1, bullet_list, bsp_bullet);
355
                       last_lb = keys->lb_pressed;
356
                       counter_mouse_ih = 0;
330
                    break;
331
                    case KBC_IRQ:
332
                    if ((scancode[0]) == ESC_BREAK_CODE) {
333
                        good = false;
334
                        // reset game
335
                        while(list_size(bullet_list) > 0){
336
                            bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
337
                            bullet_dtor(p);
338
                        }
339
                        list_node_t *it = list_begin(shooter_list);
340
                        while (it != list_end(shooter_list)) {
341
                            gunner_t *p = *(gunner_t**)list_node_val(it);
342
                            get_random_spawn(map1, p);
343
                            gunner_set_curr_health(p, gunner_get_health(p));
344
                            it = list_node_next(it);
345
                        }
346
                        timer_reset(in_game_timer);
347
                    }
348
                    break;
349
                    case MOUSE_IRQ:
350
                    if (counter_mouse_ih >= 3) {
351
                        mouse_parse_packet(packet_mouse_ih, &pp);
352
                        update_mouse(&pp);
353
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
354
                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
355
                        last_lb = keys->lb_pressed;
356
                        counter_mouse_ih = 0;
357 357

  
358
                   }
359
                   break;
360
               case COM1_IRQ: nctp_ih(); break;
361
               }
362
           }
358
                    }
359
                    break;
360
                    case COM1_IRQ: nctp_ih(); break;
361
                }
362
            }
363 363
        }
364 364
    }
365 365

  
......
393 393
    list_t *shooter_list = list_ctor();
394 394

  
395 395
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
396
    gunner_set_spawn(shooter1, 75, 75);
397
    gunner_set_pos(shooter1, 75, 75);
396
    gunner_set_spawn(shooter1, 980, 790);
397
    gunner_set_pos(shooter1, 980, 790);
398 398

  
399 399
    list_insert(shooter_list, list_end(shooter_list), shooter1);
400 400

  
401 401
    list_t *bullet_list  = list_ctor();
402 402

  
403 403
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
404
                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
404
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
405 405

  
406
   //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
407
   uint8_t last_lb = 0;
408
   struct packet pp;
409
   keys_t *keys = get_key_presses();
406
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
407
    uint8_t last_lb = 0;
408
    struct packet pp;
409
    keys_t *keys = get_key_presses();
410 410

  
411 411
    /// loop stuff
412 412
    uint32_t int_vector = 0;
......
420 420
        if((r = get_interrupts_vector(&int_vector))) return r;
421 421
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
422 422
            if (int_vector & n) {
423
               interrupt_handler(i);
424
               switch (i) {
425
               case TIMER0_IRQ: //printf("L463\n");
423
                interrupt_handler(i);
424
                switch (i) {
425
                    case TIMER0_IRQ:
426
                    if (no_interrupts % 60 == 0) timer_update(in_game_timer);
426 427

  
427
                   if (no_interrupts % 60 == 0) timer_update(in_game_timer);//printf("L465\n");
428
                   update_movement(map1, shooter1, keys, shooter_list);//printf("L466\n");
428
                    clock_t t1, t2;
429
                    t1 = clock();
429 430

  
430
                   update_game_state(map1, shooter_list, bullet_list);//printf("L468\n");
431
                    update_movement(map1, shooter1, keys, shooter_list);
431 432

  
432
                   if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
433
                       good = false;
434
                       dead = true;
435
                       break;
436
                   } //printf("L489\n");
433
                    update_game_state(map1, shooter_list, bullet_list);
437 434

  
438
                   //update_scale();
439
                   double angle = get_mouse_angle(shooter1);//printf("L471\n");
440
                   gunner_set_angle(shooter1, angle - M_PI_2); //printf("L472\n");
435
                    if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
436
                        good = false;
437
                        dead = true;
438
                        break;
439
                    }
441 440

  
442
                   ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
443
                                  gunner_get_y(shooter1)-ent_get_YLength()/2.0);
441
                    double angle = get_mouse_angle(shooter1);
442
                    gunner_set_angle(shooter1, angle - M_PI_2);
444 443

  
445
                   while(list_size(shooter_list) < ZOMBIES_NUM){
446
                       gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_meelee, 3);
447
                       gunner_set_health(zombie, health);
448
                       gunner_set_curr_health(zombie, health);
449
                       health *= ZOMBIE_HEALTH_FACTOR;
450
                       get_random_spawn(map1, zombie);
451
                       list_push_back(shooter_list, zombie);
452
                   } //printf("L484\n");
444
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
445
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
453 446

  
454
                   graph_clear_screen();
455
                   map_draw   (map1);
456
                   bullet_draw_list(bullet_list);
457
                   gunner_draw_list(shooter_list);
447
                    while(list_size(shooter_list) < ZOMBIES_NUM){
448
                        gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_melee | gunner_follow, 3);
449
                        gunner_set_health(zombie, health);
450
                        gunner_set_curr_health(zombie, health);
451
                        health *= ZOMBIE_HEALTH_FACTOR;
452
                        get_random_spawn(map1, zombie);
453
                        list_push_back(shooter_list, zombie);
454
                    }
458 455

  
459
                   text_draw(in_game_timer->text);
456
                    graph_clear_screen();
457
                    map_draw   (map1);
458
                    bullet_draw_list(bullet_list);
459
                    gunner_draw_list(shooter_list);
460 460

  
461
                   sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
462
                   sprite_draw(sp_crosshair);
463
                   graph_draw(); //printf("L508\n");
461
                    text_draw(in_game_timer->text);
464 462

  
465
                   break;
466
               case KBC_IRQ:
467
                   if ((scancode[0]) == ESC_BREAK_CODE) {
468
                       good = false;
469
                       // reset game
470
                       while(list_size(bullet_list) > 0){
471
                           bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
472
                           bullet_dtor(p);
473
                       }
474
                       list_node_t *it = list_begin(shooter_list);
475
                       while (it != list_end(shooter_list)) {
476
                           gunner_t *p = *(gunner_t**)list_node_val(it);
477
                           get_random_spawn(map1, p);
478
                           gunner_set_curr_health(p, gunner_get_health(p));
479
                           it = list_node_next(it);
480
                       }
481
                       timer_reset(in_game_timer);
482
                   }
483
                   break;
484
               case MOUSE_IRQ:
485
                   if (counter_mouse_ih >= 3) {
486
                       mouse_parse_packet(packet_mouse_ih, &pp);
487
                       update_mouse(&pp);
488
                       if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
489
                           shoot_bullet(shooter1, bullet_list, bsp_bullet);
490
                       last_lb = keys->lb_pressed;
491
                       counter_mouse_ih = 0;
463
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
464
                    sprite_draw(sp_crosshair);
465
                    graph_draw();
492 466

  
493
                   }
494
                   break;
495
               case COM1_IRQ: nctp_ih(); break;
496
               }
497
           }
498
       }
467
                    t2 = clock();
468
                    printf("%d microseconds\n", t2-t1);
469

  
470
                    break;
471
                    case KBC_IRQ:
472
                    if ((scancode[0]) == ESC_BREAK_CODE) {
473
                        good = false;
474
                        // reset game
475
                        while(list_size(bullet_list) > 0){
476
                            bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
477
                            bullet_dtor(p);
478
                        }
479
                        list_node_t *it = list_begin(shooter_list);
480
                        while (it != list_end(shooter_list)) {
481
                            gunner_t *p = *(gunner_t**)list_node_val(it);
482
                            get_random_spawn(map1, p);
483
                            gunner_set_curr_health(p, gunner_get_health(p));
484
                            it = list_node_next(it);
485
                        }
486
                        timer_reset(in_game_timer);
487
                    }
488
                    break;
489
                    case MOUSE_IRQ:
490
                    if (counter_mouse_ih >= 3) {
491
                        mouse_parse_packet(packet_mouse_ih, &pp);
492
                        update_mouse(&pp);
493
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
494
                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
495
                        last_lb = keys->lb_pressed;
496
                        counter_mouse_ih = 0;
497

  
498
                    }
499
                    break;
500
                    case COM1_IRQ: nctp_ih(); break;
501
                }
502
            }
503
        }
499 504
    }
500 505

  
501 506
    while(list_size(shooter_list) > 0){
......
529 534
    hltp_type tp = hltp_interpret(p, sz, &dest);
530 535
    switch(tp){
531 536
        case hltp_type_string:
532
            strcpy(buffer2, dest);
533
            strncat(buffer2, " <", 2);
534
            for(size_t i = CHAT_MAX_NUM-1; i; --i)
535
                text_set_text(t_text[i], text_get_string(t_text[i-1]));
536
            text_set_text(t_text[0], buffer2);
537
            for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
538
                if(text_get_string(t_text[i])[0] == '>'){
539
                    text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
540
                    text_set_halign(t_text[i], text_halign_left);
541
                }else{
542
                    text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
543
                    text_set_halign(t_text[i], text_halign_right);
544
                }
537
        strcpy(buffer2, dest);
538
        strncat(buffer2, " <", 2);
539
        for(size_t i = CHAT_MAX_NUM-1; i; --i)
540
        text_set_text(t_text[i], text_get_string(t_text[i-1]));
541
        text_set_text(t_text[0], buffer2);
542
        for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
543
            if(text_get_string(t_text[i])[0] == '>'){
544
                text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
545
                text_set_halign(t_text[i], text_halign_left);
546
            }else{
547
                text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
548
                text_set_halign(t_text[i], text_halign_right);
545 549
            }
546
            break;
550
        }
551
        break;
547 552
        default: break;
548 553
    }
549 554
}
......
559 564
    rectangle_t *r_buffer = NULL; {
560 565
        r_buffer = rectangle_ctor(0,0,900,70);
561 566
        rectangle_set_pos(r_buffer, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
562
                                    graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2);
567
        graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2);
563 568
        rectangle_set_fill_color   (r_buffer, GRAPH_BLACK);
564 569
        rectangle_set_outline_width(r_buffer, 2);
565 570
        rectangle_set_outline_color(r_buffer, GRAPH_WHITE);
......
568 573
    text_t      *t_buffer = NULL; {
569 574
        t_buffer = text_ctor(consolas, "");
570 575
        text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50,
571
                               rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
576
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
572 577
        text_set_halign(t_buffer, text_halign_left);
573 578
        text_set_valign(t_buffer, text_valign_center);
574 579
        text_set_color (t_buffer, TEXT_COLOR);
......
576 581
    text_t      *t_size   = NULL; {
577 582
        t_size = text_ctor(consolas, "");
578 583
        text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5,
579
                             rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
584
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
580 585
        text_set_halign(t_size, text_halign_right);
581 586
        text_set_valign(t_size, text_valign_bottom);
582 587
        text_set_color (t_size, TEXT_COLOR);
......
587 592
    }
588 593

  
589 594
    /** r_text */ {
590
        r_text = rectangle_ctor(0,0,900,550);
591
        rectangle_set_pos(r_text, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
592
                                  graph_get_YRes()*0.09);
593
        rectangle_set_fill_color   (r_text, GRAPH_BLACK);
594
        rectangle_set_outline_width(r_text, 2);
595
        rectangle_set_outline_color(r_text, GRAPH_WHITE);
596
        rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT);
597
    }
598
    /** t_text */ {
599
        for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
600
            t_text[i] = text_ctor(consolas, " ");
601
            text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
602
                                       rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
603
            text_set_halign(t_text[i], text_halign_left);
604
            text_set_valign(t_text[i], text_valign_bottom);
605
            text_set_color (t_text[i], TEXT_COLOR);
606
        }
607
    }
595
    r_text = rectangle_ctor(0,0,900,550);
596
    rectangle_set_pos(r_text, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
597
    graph_get_YRes()*0.09);
598
    rectangle_set_fill_color   (r_text, GRAPH_BLACK);
599
    rectangle_set_outline_width(r_text, 2);
600
    rectangle_set_outline_color(r_text, GRAPH_WHITE);
601
    rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT);
602
}
603
/** t_text */ {
604
for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
605
    t_text[i] = text_ctor(consolas, " ");
606
    text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
607
    rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
608
    text_set_halign(t_text[i], text_halign_left);
609
    text_set_valign(t_text[i], text_valign_bottom);
610
    text_set_color (t_text[i], TEXT_COLOR);
611
}
612
}
608 613

  
609
    /// loop stuff
610
    uint32_t int_vector = 0;
611
    int good = true;
612
    while (good) {
613
        /* Get a request message. */
614
        if((r = get_interrupts_vector(&int_vector))) return r;
615
        for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
616
            if (int_vector & n) {
617
                interrupt_handler(i);
618
                switch (i) {
614
/// loop stuff
615
uint32_t int_vector = 0;
616
int good = true;
617
while (good) {
618
    /* Get a request message. */
619
    if((r = get_interrupts_vector(&int_vector))) return r;
620
    for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) {
621
        if (int_vector & n) {
622
            interrupt_handler(i);
623
            switch (i) {
619 624
                case TIMER0_IRQ:
620
                    graph_clear_screen();
621
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
625
                graph_clear_screen();
626
                sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
622 627

  
623
                    rectangle_draw(r_buffer);
624
                    text_draw(t_buffer);
625
                    text_draw(t_size);
628
                rectangle_draw(r_buffer);
629
                text_draw(t_buffer);
630
                text_draw(t_size);
626 631

  
627
                    rectangle_draw(r_text);
628
                    for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_draw(t_text[i]);
632
                rectangle_draw(r_text);
633
                for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_draw(t_text[i]);
629 634

  
630
                    sprite_draw(sp_crosshair);
631
                    graph_draw();
632
                    break;
635
                sprite_draw(sp_crosshair);
636
                graph_draw();
637
                break;
633 638
                case KBC_IRQ:
634
                    if      (scancode[0] == ESC_BREAK_CODE) good = false;
635
                    else if (scancode[0] == ENTER_MAKE_CODE) {
636
                        hltp_send_string(buffer);
637
                        char buffer2[CHAT_MAX_SIZE+3] = "> ";
638
                        strncat(buffer2, buffer, strlen(buffer));
639
                        for(size_t i = CHAT_MAX_NUM-1; i; --i)
640
                            text_set_text(t_text[i], text_get_string(t_text[i-1]));
641
                        text_set_text(t_text[0], buffer2);
642
                        for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
643
                            if(text_get_string(t_text[i])[0] == '>'){
644
                                text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
645
                                text_set_halign(t_text[i], text_halign_left);
646
                            }else{
647
                                text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
648
                                text_set_halign(t_text[i], text_halign_right);
649
                            }
639
                if      (scancode[0] == ESC_BREAK_CODE) good = false;
640
                else if (scancode[0] == ENTER_MAKE_CODE) {
641
                    hltp_send_string(buffer);
642
                    char buffer2[CHAT_MAX_SIZE+3] = "> ";
643
                    strncat(buffer2, buffer, strlen(buffer));
644
                    for(size_t i = CHAT_MAX_NUM-1; i; --i)
645
                    text_set_text(t_text[i], text_get_string(t_text[i-1]));
646
                    text_set_text(t_text[0], buffer2);
647
                    for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
648
                        if(text_get_string(t_text[i])[0] == '>'){
649
                            text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
650
                            text_set_halign(t_text[i], text_halign_left);
651
                        }else{
652
                            text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
653
                            text_set_halign(t_text[i], text_halign_right);
650 654
                        }
651
                        buffer[0] = '\0';
652
                    } else if(scancode[0] == BACKSPACE_MAKE_CODE){
653
                        buffer[strlen(buffer)-1] = '\0';
654
                    } else {
655
                        char c = map_makecode(scancode[0]);
656
                        if (c == ERROR_CODE) break;
657
                        if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1);
658
                        else                               printf("Char limit exceeded\n");
659 655
                    }
660
                    text_set_text(t_buffer, buffer);
661
                    char buffer2[20];
662
                    sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
663
                    text_set_text(t_size, buffer2);
656
                    buffer[0] = '\0';
657
                } else if(scancode[0] == BACKSPACE_MAKE_CODE){
658
                    buffer[strlen(buffer)-1] = '\0';
659
                } else {
660
                    char c = map_makecode(scancode[0]);
661
                    if (c == ERROR_CODE) break;
662
                    if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1);
663
                    else                               printf("Char limit exceeded\n");
664
                }
665
                text_set_text(t_buffer, buffer);
666
                char buffer2[20];
667
                sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
668
                text_set_text(t_size, buffer2);
664 669
                case MOUSE_IRQ:
665
                    if (counter_mouse_ih >= 3) {
666
                        mouse_parse_packet(packet_mouse_ih, &pp);
667
                        update_mouse(&pp);
668
                        counter_mouse_ih = 0;
669
                    }
670
                    break;
670
                if (counter_mouse_ih >= 3) {
671
                    mouse_parse_packet(packet_mouse_ih, &pp);
672
                    update_mouse(&pp);
673
                    counter_mouse_ih = 0;
674
                }
675
                break;
671 676
                case COM1_IRQ: nctp_ih(); break;
672
                }
673 677
            }
674 678
        }
675 679
    }
680
}
676 681

  
677
    rectangle_dtor(r_buffer);
678
    text_dtor     (t_buffer);
682
rectangle_dtor(r_buffer);
683
text_dtor     (t_buffer);
679 684

  
680
    rectangle_dtor(r_text);
681
    for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]);
685
rectangle_dtor(r_text);
686
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]);
682 687

  
683
    nctp_set_processor(NULL);
688
nctp_set_processor(NULL);
684 689

  
685
    return SUCCESS;
690
return SUCCESS;
686 691
}
proj/src/proj_func.c
130 130
        /// Advance iterator if necessary
131 131
        bullet_it = list_node_next(bullet_it);
132 132
    }
133
    /// MEELEE
133
    /// MELEE
134 134
    list_node_t *it1 = list_begin(shooter_list);
135 135
    while(it1 != list_end(shooter_list)){
136 136
        gunner_t *s1 = *list_node_val(it1);
137
        if(gunner_get_type(s1) != gunner_meelee){ it1 = list_node_next(it1); continue; }
137
        if(!(gunner_get_type(s1) & gunner_melee)){ it1 = list_node_next(it1); continue; }
138 138
        list_node_t *it2 = list_begin(shooter_list);
139 139
        while(it2 != list_end(shooter_list)){
140 140
            gunner_t *s2 = *list_node_val(it2);
141
            if(s1 != s2 && gunner_distance(s1, s2) < MEELEE_RANGE)
142
                gunner_set_curr_health(s2, gunner_get_curr_health(s2) - MEELEE_DAMAGE);
141
            if(s1 != s2 && gunner_distance(s1, s2) < MELEE_RANGE)
142
                gunner_set_curr_health(s2, gunner_get_curr_health(s2) - MELEE_DAMAGE);
143 143
            if(gunner_get_curr_health(s2) <= 0){
144 144
                list_node_t *aux = list_node_next(it2);
145 145
                gunner_dtor(list_erase(shooter_list, it2));
proj/Makefile
12 12
SRCS= proj.c list.c queue.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c uart.c hltp.c makecode_map.c menu.c
13 13
IPATHS=-I./include -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_
15
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO -D __LCOM_OPTIMIZED_
16 16

  
17 17

  
18 18
DPADD += ${LIBLCF}

Also available in: Unified diff