Project

General

Profile

Revision 345

reorganizing

View differences:

proj.c
6 6
#include "proj_macros.h"
7 7
#include "proj_func.h"
8 8

  
9
#include "kbc.h"
10
#include "timer.h"
11
#include "keyboard.h"
12
#include "mouse.h"
13 9
#include "graph.h"
14 10
#include "menu.h"
15 11
#include "rtc.h"
......
18 14
#include "makecode_map.h"
19 15

  
20 16
#include "graph.h"
21
#include "sprite.h"
17

  
22 18
#include "rectangle.h"
23 19
#include "font.h"
24
#include "ent.h"
25 20

  
26 21
#include "crosshair.h"
27 22
#include "shooter.h"
......
35 30

  
36 31
#include "list.h"
37 32

  
33
#include "proj.h"
34

  
38 35
int main(int argc, char* argv[]) {
39 36

  
40 37
    lcf_set_language("EN-US");
......
50 47
    return 0;
51 48
}
52 49

  
53
static basic_sprite_t       *bsp_crosshair = NULL;
54
static basic_sprite_t       *bsp_shooter   = NULL;
55
static basic_sprite_t       *bsp_zombie    = NULL;
56
static basic_sprite_t       *bsp_pistol    = NULL;
57
static basic_sprite_t       *bsp_nothing   = NULL;
58
static basic_sprite_t       *bsp_bullet    = NULL;
59
static map_t                *map1          = NULL;
60
static sprite_t             *sp_crosshair  = NULL;
61 50

  
51

  
62 52
static int (singleplayer)(void);
63 53
static int (multiplayer)(void);
64 54
static int (chat)(void);
......
278 268
    nctp_set_processor(multiplayer_process);
279 269

  
280 270
    ent_set_scale(DEFAULT_SCALE);
281
    text_timer_t *in_game_timer = timer_ctor(font_get_default());
271
    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
282 272

  
283 273
    list_t *shooter_list = list_ctor();
284 274

  
......
323 313
                interrupt_handler(i);
324 314
                switch (i) {
325 315
                    case TIMER0_IRQ:
326
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
316
                    if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer);
327 317
                    update_movement(map1, shooter1, keys, shooter_list);
328 318
                    update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list);
329 319

  
......
409 399

  
410 400
    nctp_set_processor(NULL);
411 401

  
412
    timer_dtor(in_game_timer); in_game_timer = NULL;
402
    text_timer_dtor(in_game_timer); in_game_timer = NULL;
413 403

  
414 404
    return 0;
415 405
}
......
420 410
    nctp_set_processor(multiplayer_process);
421 411

  
422 412
    ent_set_scale(DEFAULT_SCALE);
423
    text_timer_t *in_game_timer = timer_ctor(font_get_default());
413
    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
424 414

  
425 415
    list_t *shooter_list = list_ctor();
426 416

  
......
458 448
                interrupt_handler(i);
459 449
                switch (i) {
460 450
                    case TIMER0_IRQ:
461
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
451
                    if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer);
462 452

  
463 453
                    double angle = get_mouse_angle(shooter1) - M_PI_2;
464 454

  
......
552 542

  
553 543
    nctp_set_processor(NULL);
554 544

  
555
    timer_dtor(in_game_timer); in_game_timer = NULL;
545
    text_timer_dtor(in_game_timer); in_game_timer = NULL;
556 546

  
557 547
    return 0;
558 548
}
559 549

  
560 550
static int (campaign)(void);
561
static int (zombies)(void);
551
#include "zombies.h"
562 552
static int (singleplayer)(void) {
563 553

  
564 554
    int r;
......
628 618
    int r;
629 619

  
630 620
    ent_set_scale(DEFAULT_SCALE);
631
    text_timer_t *in_game_timer = timer_ctor(font_get_default());
621
    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
632 622

  
633 623
    list_t *shooter_list = list_ctor();
634 624

  
......
667 657
                switch (i) {
668 658
                    case TIMER0_IRQ:
669 659

  
670
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
660
                    if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer);
671 661
                    update_movement(map1, shooter1, keys, shooter_list);
672 662

  
673 663
                    update_game_state(map1, shooter_list, bullet_list);
......
725 715
    }
726 716
    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
727 717

  
728
    timer_dtor(in_game_timer); in_game_timer = NULL;
718
    text_timer_dtor(in_game_timer); in_game_timer = NULL;
729 719

  
730 720
    return SUCCESS;
731 721
}
732 722

  
733
#define ZOMBIES_NUM             5
734
#define ZOMBIE_HEALTH_FACTOR    1.1
735
static int (zombies)(void){
736 723

  
737
    int r;
738 724

  
739
    ent_set_scale(DEFAULT_SCALE);
740
    text_timer_t *in_game_timer = timer_ctor(font_get_default());
741

  
742
    list_t *shooter_list = list_ctor();
743

  
744
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
745
    gunner_set_spawn(shooter1, 980, 790);
746
    gunner_set_pos(shooter1, 980, 790);
747

  
748
    list_insert(shooter_list, list_end(shooter_list), shooter1);
749

  
750
    list_t *bullet_list  = list_ctor();
751

  
752
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
753
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
754

  
755
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
756
    uint8_t last_lb = 0;
757
    struct packet pp;
758
    keys_t *keys = get_key_presses();
759

  
760
    /// loop stuff
761
    uint64_t int_vector = 0;
762
    int good = true;
763
    int dead = false;
764

  
765
    int health = 50;
766

  
767
    map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
768

  
769
    while (good && !dead) {
770
        /* Get a request message. */
771
        if((r = get_interrupts_vector(&int_vector))) return r;
772
        uint32_t n = 1;
773
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
774
            if(!good || dead) break;
775
            if (int_vector & n) {
776
                interrupt_handler(i);
777
                switch (i) {
778
                    case TIMER0_IRQ:
779
                    if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer);
780
                    if (timer_get_no_interrupts() %  6 == 0){
781
                        map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1));
782
                    }
783

  
784
                    update_movement(map1, shooter1, keys, shooter_list);
785

  
786
                    update_game_state(map1, shooter_list, bullet_list);
787

  
788
                    if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
789
                        good = false;
790
                        dead = true;
791
                        break;
792
                    }
793

  
794
                    double angle = get_mouse_angle(shooter1);
795
                    gunner_set_angle(shooter1, angle - M_PI_2);
796

  
797
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
798
                                   gunner_get_y(shooter1)-ent_get_YLength()/2.0);
799

  
800
                    while(list_size(shooter_list) < ZOMBIES_NUM+1){
801
                        gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, GUNNER_MELEE | GUNNER_FOLLOW, 3);
802
                        gunner_set_health(zombie, health);
803
                        gunner_set_curr_health(zombie, health);
804
                        health *= ZOMBIE_HEALTH_FACTOR;
805
                        get_random_spawn(map1, zombie, shooter_list);
806
                        list_push_back(shooter_list, zombie);
807
                    }
808

  
809
                    graph_clear_screen();
810
                    map_draw   (map1);
811
                    bullet_draw_list(bullet_list);
812
                    gunner_draw_list(shooter_list);
813

  
814
                    text_draw(in_game_timer->text);
815

  
816
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
817
                    sprite_draw(sp_crosshair);
818
                    graph_draw();
819

  
820
                    break;
821
                    case KBC_IRQ:
822
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
823
                        good = false;
824
                    }
825
                    break;
826
                    case MOUSE_IRQ:
827
                    if (mouse_get_counter_mouse_ih() >= 3) {
828
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
829
                        update_mouse(&pp);
830
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
831
                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
832
                        last_lb = keys->lb_pressed;
833
                        mouse_set_counter_mouse_ih(0);
834

  
835
                    }
836
                    break;
837
                    case COM1_IRQ: nctp_ih(); break;
838
                }
839
            }
840
        }
841
    }
842

  
843
    while(list_size(shooter_list) > 0){
844
        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
845
        gunner_dtor(p);
846
    }
847
    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
848

  
849
    while(list_size(bullet_list) > 0){
850
        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
851
        bullet_dtor(p);
852
    }
853
    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
854

  
855
    if(dead){
856
        printf("YOU DIED\n");
857
    }
858

  
859
    timer_dtor(in_game_timer); in_game_timer = NULL;
860

  
861
    return SUCCESS;
862
}
863

  
864 725
#define CHAT_MAX_SIZE   75
865 726
#define CHAT_MAX_NUM    19
866 727
static text_t      *t_text[CHAT_MAX_NUM] = {NULL};

Also available in: Unified diff