Project

General

Profile

Revision 346

added more files

View differences:

proj/src/proj.c
49 49

  
50 50

  
51 51

  
52
static int (singleplayer)(void);
52
#include "singleplayer.h"
53 53
static int (multiplayer)(void);
54
static int (chat)(void);
54
#include "chat.h"
55 55
int(proj_main_loop)(int argc, char *argv[]) {
56 56
    (void)argc; (void)argv;
57 57

  
......
546 546

  
547 547
    return 0;
548 548
}
549

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

  
554
    int r;
555

  
556
    menu_t *main_menu = menu_ctor(font_get_default());
557
    menu_add_item(main_menu, "Campaign");
558
    menu_add_item(main_menu, "Zombies");
559
    menu_add_item(main_menu, "Back");
560

  
561
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
562
    uint8_t last_lb = 0;
563
    struct packet pp;
564
    keys_t *keys = get_key_presses();
565

  
566
    /// loop stuff
567
    int click = 0;
568
    uint64_t int_vector = 0;
569
    int good = true;
570
    while (good) {
571
        /* Get a request message. */
572
        if((r = get_interrupts_vector(&int_vector))) return r;
573
        uint32_t n = 1;
574
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
575
            if (int_vector & n) {
576
                interrupt_handler(i);
577
                switch (i) {
578
                    case TIMER0_IRQ:
579

  
580
                    graph_clear_screen();
581
                    switch(menu_update_state(main_menu, click)){
582
                        case -1: break;
583
                        case  0: campaign(); break;
584
                        case  1: zombies(); break;
585
                        case  2: good = false; break;
586
                    }
587
                    menu_draw(main_menu);
588

  
589
                    click = 0;
590

  
591
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
592
                    sprite_draw(sp_crosshair);
593
                    graph_draw();
594

  
595
                    break;
596
                    case KBC_IRQ:
597
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
598
                    case MOUSE_IRQ:
599
                    if (mouse_get_counter_mouse_ih() >= 3) {
600
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
601
                        update_mouse(&pp);
602
                        if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
603
                        last_lb = keys->lb_pressed;
604
                        mouse_set_counter_mouse_ih(0);
605
                    }
606
                    break;
607
                    case COM1_IRQ: nctp_ih(); break;
608
                }
609
            }
610
        }
611
    }
612

  
613
    return 0;
614
}
615

  
616
static int (campaign)(void){
617

  
618
    int r;
619

  
620
    ent_set_scale(DEFAULT_SCALE);
621
    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
622

  
623
    list_t *shooter_list = list_ctor();
624

  
625
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
626
    gunner_set_spawn(shooter1, 75, 75);
627
    gunner_set_pos(shooter1, 75, 75);
628

  
629
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, GUNNER_PLAYER, 2);
630
    gunner_set_spawn(shooter2, 975, 75);
631
    gunner_set_pos(shooter2, 775, 75);
632

  
633
    list_insert(shooter_list, list_end(shooter_list), shooter1);
634
    list_insert(shooter_list, list_end(shooter_list), shooter2);
635

  
636
    list_t *bullet_list  = list_ctor();
637

  
638
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
639
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
640

  
641
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
642
    uint8_t last_lb = 0;
643
    struct packet pp;
644
    keys_t *keys = get_key_presses();
645

  
646
    /// loop stuff
647
    uint64_t int_vector = 0;
648
    int good = true;
649
    while (good) {
650
        /* Get a request message. */
651
        if((r = get_interrupts_vector(&int_vector))) return r;
652
        uint32_t n = 1;
653
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
654
            if(!good) break;
655
            if (int_vector & n) {
656
                interrupt_handler(i);
657
                switch (i) {
658
                    case TIMER0_IRQ:
659

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

  
663
                    update_game_state(map1, shooter_list, bullet_list);
664

  
665
                    //update_scale();
666
                    double angle = get_mouse_angle(shooter1);
667
                    gunner_set_angle(shooter1, angle - M_PI_2);
668

  
669
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
670
                    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
671

  
672
                    graph_clear_screen();
673
                    map_draw   (map1);
674
                    bullet_draw_list(bullet_list);
675
                    gunner_draw_list(shooter_list);
676

  
677
                    text_draw(in_game_timer->text);
678

  
679
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
680
                    sprite_draw(sp_crosshair);
681
                    graph_draw();
682

  
683
                    break;
684
                    case KBC_IRQ:
685
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
686
                        good = false;
687
                    }
688
                    break;
689
                    case MOUSE_IRQ:
690
                    if (mouse_get_counter_mouse_ih() >= 3) {
691
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
692
                        update_mouse(&pp);
693
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
694
                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
695
                        last_lb = keys->lb_pressed;
696
                        mouse_set_counter_mouse_ih(0);
697

  
698
                    }
699
                    break;
700
                    case COM1_IRQ: nctp_ih(); break;
701
                }
702
            }
703
        }
704
    }
705

  
706
    while(list_size(shooter_list) > 0){
707
        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
708
        gunner_dtor(p);
709
    }
710
    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
711

  
712
    while(list_size(bullet_list) > 0){
713
        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
714
        bullet_dtor(p);
715
    }
716
    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
717

  
718
    text_timer_dtor(in_game_timer); in_game_timer = NULL;
719

  
720
    return SUCCESS;
721
}
722

  
723

  
724

  
725
#define CHAT_MAX_SIZE   75
726
#define CHAT_MAX_NUM    19
727
static text_t      *t_text[CHAT_MAX_NUM] = {NULL};
728
static rectangle_t *r_text               =  NULL;
729
static void chat_process(const uint8_t *p, const size_t sz){
730
    char buffer2[CHAT_MAX_NUM+3];
731
    void *dest = NULL;
732
    hltp_type tp = hltp_interpret(p, sz, &dest);
733
    switch(tp){
734
        case hltp_type_string:
735
        strcpy(buffer2, dest);
736
        strncat(buffer2, " <", 2);
737
        for(size_t i = CHAT_MAX_NUM-1; i; --i)
738
        text_set_string(t_text[i], text_get_string(t_text[i-1]));
739
        text_set_string(t_text[0], buffer2);
740
        for(size_t i = 0; i < CHAT_MAX_NUM; ++i){
741
            if(text_get_string(t_text[i])[0] == '>'){
742
                text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
743
                text_set_halign(t_text[i], text_halign_left);
744
            }else{
745
                text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
746
                text_set_halign(t_text[i], text_halign_right);
747
            }
748
        }
749
        break;
750
        case hltp_type_invalid: break;
751
        case hltp_type_bullet : break;
752
        case hltp_type_host   : break;
753
        case hltp_type_remote : break;
754
    }
755
}
756
static int (chat)(void){
757
    int r;
758

  
759
    nctp_dump();
760
    nctp_set_processor(chat_process);
761

  
762
    struct packet pp;
763

  
764
    char buffer[CHAT_MAX_SIZE] = "";
765
    rectangle_t *r_buffer = NULL; {
766
        r_buffer = rectangle_ctor(0,0,900,70);
767
        rectangle_set_pos(r_buffer, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
768
        (int16_t)(graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2));
769
        rectangle_set_fill_color   (r_buffer, GRAPH_BLACK);
770
        rectangle_set_outline_width(r_buffer, 2);
771
        rectangle_set_outline_color(r_buffer, GRAPH_WHITE);
772
        rectangle_set_fill_trans(r_buffer, GRAPH_TRANSPARENT);
773
    }
774
    text_t      *t_buffer = NULL; {
775
        t_buffer = text_ctor(font_get_default(), "");
776
        text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50,
777
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
778
        text_set_halign(t_buffer, text_halign_left);
779
        text_set_valign(t_buffer, text_valign_center);
780
        text_set_color (t_buffer, TEXT_COLOR);
781
    }
782
    text_t      *t_size   = NULL; {
783
        t_size = text_ctor(font_get_default(), "");
784
        text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5,
785
        rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
786
        text_set_halign(t_size, text_halign_right);
787
        text_set_valign(t_size, text_valign_bottom);
788
        text_set_color (t_size, TEXT_COLOR);
789
        text_set_size  (t_size, 18);
790
        char buffer2[20];
791
        sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
792
        text_set_string(t_size, buffer2);
793
    }
794

  
795
    /** r_text */ {
796
    r_text = rectangle_ctor(0,0,900,550);
797
    rectangle_set_pos(r_text, graph_get_XRes()/2  -rectangle_get_w(r_buffer)/2,
798
    (int16_t)(graph_get_YRes()*0.09));
799
    rectangle_set_fill_color   (r_text, GRAPH_BLACK);
800
    rectangle_set_outline_width(r_text, 2);
801
    rectangle_set_outline_color(r_text, GRAPH_WHITE);
802
    rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT);
803
    }
804
    /** t_text */ {
805
    for(uint16_t i = 0; i < CHAT_MAX_NUM; ++i){
806
        t_text[i] = text_ctor(font_get_default(), " ");
807
        text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
808
        rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i);
809
        text_set_halign(t_text[i], text_halign_left);
810
        text_set_valign(t_text[i], text_valign_bottom);
811
        text_set_color (t_text[i], TEXT_COLOR);
812
    }
813
}
814

  
815
/// loop stuff
816
uint64_t int_vector = 0;
817
int good = true;
818
while (good) {
819
    /* Get a request message. */
820
    if((r = get_interrupts_vector(&int_vector))) return r;
821
    uint32_t n = 1;
822
    for (uint8_t i = 0; i < 32; i++, n <<= 1) {
823
        if (int_vector & n) {
824
            interrupt_handler(i);
825
            switch (i) {
826
                case TIMER0_IRQ:
827
                graph_clear_screen();
828
                sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
829

  
830
                rectangle_draw(r_buffer);
831
                text_draw(t_buffer);
832
                text_draw(t_size);
833

  
834
                rectangle_draw(r_text);
835
                for(size_t j = 0; j < CHAT_MAX_NUM; ++j) text_draw(t_text[j]);
836

  
837
                sprite_draw(sp_crosshair);
838
                graph_draw();
839
                break;
840
                case KBC_IRQ:
841
                if      (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false;
842
                else if (keyboard_get_scancode()[0] == ENTER_MAKE_CODE) {
843
                    hltp_send_string(buffer);
844
                    char buffer2[CHAT_MAX_SIZE+3] = "> ";
845
                    strncat(buffer2, buffer, strlen(buffer));
846
                    for(size_t j = CHAT_MAX_NUM-1; j; --j) text_set_string(t_text[i], text_get_string(t_text[i-1]));
847
                    text_set_string(t_text[0], buffer2);
848
                    for(size_t j = 0; j < CHAT_MAX_NUM; ++j){
849
                        if(text_get_string(t_text[j])[0] == '>'){
850
                            text_set_pos(t_text[j], rectangle_get_x(r_text)+50, text_get_y(t_text[j]));
851
                            text_set_halign(t_text[j], text_halign_left);
852
                        }else{
853
                            text_set_pos(t_text[j], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[j]));
854
                            text_set_halign(t_text[j], text_halign_right);
855
                        }
856
                    }
857
                    buffer[0] = '\0';
858
                } else if(keyboard_get_scancode()[0] == BACKSPACE_MAKE_CODE){
859
                    buffer[strlen(buffer)-1] = '\0';
860
                } else {
861
                    char c = map_makecode(keyboard_get_scancode()[0]);
862
                    if (c == ERROR_CODE) break;
863
                    if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1);
864
                    else                               printf("Char limit exceeded\n");
865
                }
866
                text_set_string(t_buffer, buffer);
867
                char buffer2[20];
868
                sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
869
                text_set_string(t_size, buffer2);
870
                case MOUSE_IRQ:
871
                if (mouse_get_counter_mouse_ih() >= 3) {
872
                    mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
873
                    update_mouse(&pp);
874
                    mouse_set_counter_mouse_ih(0);
875
                }
876
                break;
877
                case COM1_IRQ: nctp_ih(); break;
878
            }
879
        }
880
    }
881
}
882

  
883
rectangle_dtor(r_buffer);
884
text_dtor     (t_buffer);
885

  
886
rectangle_dtor(r_text);
887
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]);
888

  
889
nctp_set_processor(NULL);
890

  
891
return SUCCESS;
892
}
proj/Makefile
9 9
.PATH: ${.CURDIR}/libs/classes/src
10 10
.PATH: ${.CURDIR}/libs/utils/src
11 11

  
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
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
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 15
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED__ -Wall -Wextra -Wshadow -Wunreachable-code #-Weverything -Wno-padded -Wno-unused-macros
16 16

  
17

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

  

Also available in: Unified diff