Project

General

Profile

Statistics
| Revision:

root / proj / src / campaign.c @ 348

History | View | Annotate | Download (3.91 KB)

1 347 up20180642
#include <lcom/lcf.h>
2
3
#include "campaign.h"
4
5
#include "proj.h"
6
7
#include "proj_macros.h"
8
#include "proj_func.h"
9
#include "ent.h"
10
#include "interrupts_func.h"
11
#include "graph.h"
12
#include "hltp.h"
13
#include "errors.h"
14
#include <math.h>
15
16
int (campaign)(void){
17
18
    int r;
19
20
    ent_set_scale(DEFAULT_SCALE);
21
    text_timer_t *in_game_timer = text_timer_ctor(font_get_default());
22
23
    list_t *shooter_list = list_ctor();
24
25
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
26
    gunner_set_spawn(shooter1, 75, 75);
27
    gunner_set_pos(shooter1, 75, 75);
28
29
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, GUNNER_PLAYER, 2);
30
    gunner_set_spawn(shooter2, 975, 75);
31
    gunner_set_pos(shooter2, 775, 75);
32
33
    list_insert(shooter_list, list_end(shooter_list), shooter1);
34
    list_insert(shooter_list, list_end(shooter_list), shooter2);
35
36
    list_t *bullet_list  = list_ctor();
37
38
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
39
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
40
41
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
42
    uint8_t last_lb = 0;
43
    struct packet pp;
44
    keys_t *keys = get_key_presses();
45
46
    /// loop stuff
47
    uint64_t int_vector = 0;
48
    int good = true;
49
    while (good) {
50
        /* Get a request message. */
51
        if((r = get_interrupts_vector(&int_vector))) return r;
52
        uint32_t n = 1;
53
        for (uint8_t i = 0; i < 32; i++, n <<= 1) {
54
            if(!good) break;
55
            if (int_vector & n) {
56
                interrupt_handler(i);
57
                switch (i) {
58
                    case TIMER0_IRQ:
59
60
                    if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer);
61
                    update_movement(map1, shooter1, keys, shooter_list);
62
63
                    update_game_state(map1, shooter_list, bullet_list);
64
65
                    //update_scale();
66
                    double angle = get_mouse_angle(shooter1);
67
                    gunner_set_angle(shooter1, angle - M_PI_2);
68
69
                    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
70
                    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
71
72
                    graph_clear_screen();
73
                    map_draw   (map1);
74
                    bullet_draw_list(bullet_list);
75
                    gunner_draw_list(shooter_list);
76
77
                    text_draw(in_game_timer->text);
78
79
                    sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y());
80
                    sprite_draw(sp_crosshair);
81
                    graph_draw();
82
83
                    break;
84
                    case KBC_IRQ:
85
                    if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) {
86
                        good = false;
87
                    }
88
                    break;
89
                    case MOUSE_IRQ:
90
                    if (mouse_get_counter_mouse_ih() >= 3) {
91
                        mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp);
92
                        update_mouse(&pp);
93
                        if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
94
                        shoot_bullet(shooter1, bullet_list, bsp_bullet);
95
                        last_lb = keys->lb_pressed;
96
                        mouse_set_counter_mouse_ih(0);
97
98
                    }
99
                    break;
100
                    case COM1_IRQ: nctp_ih(); break;
101
                }
102
            }
103
        }
104
    }
105
106
    while(list_size(shooter_list) > 0){
107
        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
108
        gunner_dtor(p);
109
    }
110
    if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n");
111
112
    while(list_size(bullet_list) > 0){
113
        bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
114
        bullet_dtor(p);
115
    }
116
    if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n");
117
118
    text_timer_dtor(in_game_timer); in_game_timer = NULL;
119
120
    return SUCCESS;
121
}