-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpvp.c
executable file
·132 lines (120 loc) · 2.61 KB
/
pvp.c
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
/*
** pvp.c for pvp in /u/all/nguyen_7/cu/public/alum-1
**
** Made by julien nguyen-duy
** Login <[email protected]>
**
** Started on Fri Feb 12 12:59:59 2010 julien nguyen-duy
** Last update Sat Feb 13 17:41:44 2010 damien locque
*/
#include "my.h"
#include <SDL/SDL.h>
#include <unistd.h>
static int who_play = 0;
static int win = 0;
t_match *check_space_pvp(t_match *match, int flag)
{
int check;
check = 0;
if (check_list(match) == 1)
{
flag = 1;
return (match);
}
check = init_check(match);
if (is_ok(match, check) == 1)
{
flag = 1;
return (match);
}
flag = burn_select(&match, flag);
if (flag != 0)
{
is_finished(match);
if (who_play == 0)
who_play = 42;
else
who_play = 0;
}
return (match);
}
int aff_win_pvp(t_var var, int in_prog, int who_play)
{
SDL_Event event;
SDL_Rect pos;
pos.x = 0;
pos.y = 0;
if (who_play != 0)
xSDL_BlitSurface(var.winp2, NULL, var.screen, &pos);
else
xSDL_BlitSurface(var.winp1, NULL, var.screen, &pos);
xSDL_Flip(var.screen);
while (in_prog == 1)
{
xSDL_WaitEvent(&event);
if (event.type == SDL_KEYDOWN)
if (event.key.keysym.sym == SDLK_ESCAPE)
in_prog = 42;
}
return (42);
}
int catch_event_pvp(t_match **match, t_var *var,
int in_prog, SDL_Event event)
{
int flag;
flag = 0;
xSDL_WaitEvent(&event);
aff_p1_p2(who_play, var);
if (event.type == SDL_QUIT)
in_prog = 42;
if (event.type == SDL_MOUSEBUTTONDOWN)
if (event.button.button == SDL_BUTTON_LEFT)
(*match) = catch_left_button(&event, (*match));
if (event.type == SDL_KEYDOWN)
{
if (event.key.keysym.sym == SDLK_ESCAPE)
in_prog = 42;
else if (event.key.keysym.sym == SDLK_SPACE)
check_space_pvp((*match), flag);
}
aff_match(var, (*match));
if (win != 0)
in_prog = aff_win_pvp((*var), in_prog, who_play);
xSDL_Flip(var->screen);
is_finished_pvp(*match);
return (in_prog);
}
void wait_event_pvp(t_var var)
{
SDL_Event event;
t_match *match;
int in_prog;
match = NULL;
in_prog = 1;
match = init_match(match);
SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
aff_bwall(&var);
aff_match(&var, match);
xSDL_Flip(var.screen);
while (in_prog == 1)
in_prog = catch_event_pvp(&match, &var, in_prog, event);
aff_match(&var, match);
free_all(match, &var);
SDL_Quit();
exit(EXIT_SUCCESS);
}
int is_finished_pvp(t_match *match)
{
t_match *temp;
temp = match;
while (temp->next != NULL)
{
if (temp->burn == 0)
return (0);
temp = temp->next;
}
if (temp->burn == 0)
return (0);
win = 42;
return (0);
}