Project

General

Profile

Revision 308

multiplayer serial structs

View differences:

proj/include/ent.h
73 73
int16_t (map_get_height)  (const map_t *p);
74 74
int (map_make_dijkstra)(map_t *p, uint16_t x, uint16_t y);
75 75
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull);
76
double (distance_gunners)(const gunner_t *shooter1, const gunner_t *shooter2);
76 77
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2);
77 78
void   (map_draw)(map_t *p);
78 79

  
proj/src/ent.c
339 339
    return distance <= shooter_radius+bullet_radius;
340 340
}
341 341

  
342
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2) {
343
    double shooter1_radius = max(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0;
342
double (distance_gunners)(const gunner_t *shooter1, const gunner_t *shooter2) {
344 343
    double shooter1_x = gunner_get_x(shooter1);
345 344
    double shooter1_y = gunner_get_y(shooter1);
346 345

  
347
    double shooter2_radius = max(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0;
348 346
    double shooter2_x = gunner_get_x(shooter2);
349 347
    double shooter2_y = gunner_get_y(shooter2);
350 348

  
351 349
    double dx = shooter1_x - shooter2_x;
352 350
    double dy = shooter1_y - shooter2_y;
353
    double distance = sqrt(dx*dx + dy*dy);
351
    return sqrt(dx*dx + dy*dy);
352
}
353

  
354
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2) {
355
    double shooter1_radius = max(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0;
356
    double shooter2_radius = max(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0;
357
    double distance = distance_gunners(shooter1, shooter2);
354 358
    return distance <= shooter1_radius+shooter2_radius;
355 359
}
356 360

  
proj/src/proj.c
60 60
sprite_t             *sp_crosshair  = NULL;
61 61

  
62 62
static int (singleplayer)(void);
63
//static int (multiplayer)(void);
63 64
static int (chat)(void);
64 65
int(proj_main_loop)(int argc, char *argv[]) {
65 66

  
......
179 180
    return 0;
180 181
}
181 182

  
183
typedef struct __attribute__((packed)) {
184
    // player 1
185
    double player1_x;
186
    double player1_y;
187
    double player1_health;
188
    double player1_current_health;
189

  
190
    // player 2
191
    double player2_x;
192
    double player2_y;
193
    double player2_health;
194
    double player2_current_health;
195

  
196
    // bullets
197
    size_t no_bullets;
198
    double *bullets_x;
199
    double *bullets_y;
200
    double *bullets_vx;
201
    double *bullets_vy;
202
    bool   *bullet_shooter; // 0 for player 1, otherwise 1 for player 2
203
} host_info;
204

  
205
typedef struct __attribute__((packed)) {
206
    keys_t client_keys_pressed;
207
    int32_t client_mouse_x;
208
    int32_t client_mouse_y;
209
    size_t bullets_shot;
210
    double *bullets_x;
211
    double *bullets_y;
212
} client_info;
213
/*
214
static void host_to_client_process(const uint8_t *p, const size_t sz) {
215

  
216
}
217

  
218
static void client_to_host_process(const uint8_t *p, const size_t sz) {
219
}
220

  
221
static int (multiplayer)(void) {
222

  
223
    //int r;
224

  
225
    ent_set_scale(DEFAULT_SCALE);
226
    //text_timer_t *in_game_timer = timer_ctor(consolas);
227

  
228
    list_t *shooter_list = list_ctor();
229

  
230
    gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
231
    gunner_set_spawn(shooter1, 75, 75);
232

  
233
    gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n");
234
    gunner_set_spawn(shooter2, 975, 75);
235

  
236
    list_insert(shooter_list, list_end(shooter_list), shooter1);
237
    list_insert(shooter_list, list_end(shooter_list), shooter2);
238

  
239
    do {
240
        get_random_spawn(map1, shooter1, shooter_list);
241
        get_random_spawn(map1, shooter2, shooter_list);
242
    } while (distance_gunners(shooter1, shooter2) < 700);
243

  
244
    list_t *bullet_list  = list_ctor();
245

  
246
    ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
247
    gunner_get_y(shooter1)-ent_get_YLength()/2.0);
248

  
249
    //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
250
    uint8_t last_lb = 0;
251
    struct packet pp;
252
    keys_t *keys = get_key_presses();
253

  
254
    /// loop stuff
255
    uint32_t int_vector = 0;
256
    int good = true;
257

  
258
    // incomplete
259

  
260
    return 0;
261
}*/
262

  
182 263
static int (campaign)(void);
183 264
static int (zombies)(void);
184 265
static int (singleplayer)(void) {

Also available in: Unified diff