aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
blob: 658bcd47f842202163b378bee1f20bfa5d9dfcaf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include <iostream>
#include <vector>

#include "umath/vec2.h"

#include "graphics/graphics.h"
#include "commands/commands.h"
#include "timing/timing.h"
#include "game/entity.h"
#include "game/ground.h"
#include "game/playercontrol.h"
#include "game/gst.h"
#include "game/tile.h"
#include "game/load.h"

// state representation
/*
    ground matrix
    . tile: {
        name
        range bonus
        travel cost
        defence bonus
        sight penalty
    }
    units list
    . unit: {
        name
        type
        attack
        defence
        life
        move points
        sight
        (morale?)
        ability list
        . abilities: [ ]
    }
    builds
    . build: {
        same as unit
        trainees list
    }
    tech
    resources (food, gold)
    trade bonus
*/

int main () {
    Graphics graphics (900, 600);
    Commands_sdl com;
    timing_sdl timing (60);
    
    Player_control control;
    
    float ts = 16;
    Gst gst (15,15);
    
    load_json(gst);
    
    gst.players.emplace_back(255, 0, 0, 0);
    gst.players[0].res = std::vector<float> { 1500, 1500 };
    gst.players.emplace_back(0, 0, 255, 1);
    gst.players[1].res = std::vector<float> { 1500, 1500 };
    
    gst.ground.tiles[1] = 1;
    gst.ground.tiles[8] = 1;
    gst.ground.tiles[11] = 2;
    gst.ground.tiles[12] = 2;
    for (int i=0; i<2000; i+=37) {
        gst.ground.tiles[i%(gst.ground.sizex*gst.ground.sizey)] = 2;
        gst.ground.tiles[(i+1)%(gst.ground.sizex*gst.ground.sizey)] = 2;
    }
    for (int i=0; i<2000; i+=71) {
        gst.ground.tiles[i%(gst.ground.sizex*gst.ground.sizey)] = 1;
    }
    
    gst.ground.resources.emplace_back(gst.ground.at(3, 4), Resource::Type::gold);
    gst.ground.resources.emplace_back(gst.ground.at(4, 4), Resource::Type::food);
    
    
    
    gst.entities.emplace_back(5, 1, gst.get_info("Town Center"), 0);
    gst.entities.emplace_back(6, 1, gst.get_info("Barracks"), 0);
    gst.entities.emplace_back(5, 0, gst.get_info("Stable"), 0);
    gst.entities.emplace_back(1, 1, gst.get_info("Villager"), 0);
    gst.entities.emplace_back(2, 1, gst.get_info("Light Cavalry"), 0);
    gst.entities.emplace_back(10, 10, gst.get_info("Villager"), 1);
    gst.entities.emplace_back(1, 5, gst.get_info("Villager"), 1);
    gst.entities.emplace_back(2, 5, gst.get_info("Militia"), 1);
    gst.entities.emplace_back(0, 0, gst.get_info("Scout Cavalry"), 0);
    gst.entities.emplace_back(1, 0, gst.get_info("Persian War Elephants"), 0);
    gst.entities.emplace_back(0, 1, gst.get_info("Scorpions"), 1);
    gst.entities.emplace_back(1, 2, gst.get_info("Archers"), 1);
    
    View view (vec2 { (float)graphics.resx, (float)graphics.resy });
    
    vec2 mouselast { 0, 0 };
    
    while(true) {
        if (com.process_events()) break;
        if (com.resx != -1) { 
            graphics.change_res(com.resx, com.resy); 
            view.res = vec2 { (float)com.resx, (float)com.resy };
        }
        vec2 mousepos { (float)com.mx, (float)com.my };
        vec2 mousedelta { mousepos };
        mousedelta -= mouselast;
        
        if (com.mclick[1]) {
            graphics.cam.pos += mousedelta;
        }
        
        mouselast = vec2 { (float)com.mx, (float)com.my };
        
        timing.process();
        while (timing.check_process()) {
            com.process_clicks();
            // input detection
            // turn fsm or ai
            // turn tick calculations
            /*
                economy
                tech
                upgrades
                win condition
            */ 
            view.process(gst, graphics.cam.pos, mousepos, com.mheld);
            if (com.check_key(SDL_SCANCODE_ESCAPE)) {
                view.back = 1;
            }
            
            control.process(gst, view);
            com.process_keys();
        }
        if (timing.check_render()) {
            graphics.render(gst, view);
            graphics.present();
        }
    }
	return 0;
}