Mercurial > hg > Members > kono > tree_dandy2
comparison Character.c @ 0:01387a2e419e
initial version
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 07 Dec 2010 15:39:45 +0900 |
parents | |
children | 8afbbe129730 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:01387a2e419e |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include "syokika.h" | |
4 #include "bool.h" | |
5 #include <SDL.h> | |
6 #include "SDL_opengl.h" | |
7 #include "object.h" | |
8 #include "Character.h" | |
9 #include "Character_state.h" | |
10 #include "count2.h" | |
11 #include "tokuten.h" | |
12 #include "schedule.h" | |
13 #include "sankaku.h" | |
14 #include "sgoex.h" | |
15 #include "collision.h" | |
16 #include "debug.h" | |
17 | |
18 #include "error.h" | |
19 | |
20 #define CHARACTER_MAX_POOL_SIZE 2048 | |
21 | |
22 | |
23 const table enemystate[] = ENEMY_STATUS_TABLE; | |
24 int filpcount = 0; | |
25 int stage = 0; | |
26 BOOL tf = FALSE; | |
27 static int pool_size; | |
28 | |
29 int init_chara_list(int num) | |
30 { | |
31 if(active_chara_list == NULL) | |
32 { | |
33 return extend_chara_list_pool(num); | |
34 } | |
35 return 1; | |
36 } | |
37 | |
38 int | |
39 extend_chara_list_pool(int num) | |
40 { | |
41 | |
42 pool_size = num; | |
43 /* | |
44 q = (CHARACTER*)malloc(sizeof(CHARACTER)*(num+1)); | |
45 | |
46 if(!q){ | |
47 return 0; | |
48 } | |
49 | |
50 q->next = active_chara_list; | |
51 active_chara_list = q; | |
52 | |
53 q = active_chara_list + 1; | |
54 for(q = active_chara_list +1;num-->0;q++) | |
55 { | |
56 q->next = q+1; | |
57 } | |
58 q->next = free_chara_list; | |
59 free_chara_list = active_chara_list+1; | |
60 */ | |
61 __debug("task init start"); | |
62 | |
63 int i; | |
64 CHARACTER *q[num]; | |
65 | |
66 for(i = 0; i<num ; i++) | |
67 { | |
68 q[i] = (CHARACTER*)malloc(sizeof(CHARACTER)); | |
69 q[i]->f = FALSE; | |
70 q[i]->state = noaction; | |
71 q[i]->collision = noaction; | |
72 } | |
73 | |
74 for(i = 0; i<num-1 ; i++) | |
75 { | |
76 q[i]->next = q[i+1]; | |
77 //q[i]->next->prev = q[i]; | |
78 } | |
79 | |
80 q[num-1]->next = NULL; | |
81 active_chara_list = (CHARACTER*)malloc(sizeof(CHARACTER)); | |
82 active_chara_list->f = FALSE; | |
83 active_chara_list->state = noaction; | |
84 active_chara_list->collision = noaction; | |
85 active_chara_list->next = q[0]; | |
86 //q[0]->prev = active_chara_list; | |
87 //active_chara_list->prev = q[num-1]; | |
88 //q[num-1]->next = active_chara_list; | |
89 CHARACTER *p; | |
90 | |
91 for(p = active_chara_list->next; p != NULL ; p = p->next) | |
92 { | |
93 if(p != NULL) | |
94 { | |
95 __debug("list_test"); | |
96 } | |
97 } | |
98 return 1; | |
99 | |
100 } | |
101 | |
102 void TFon() | |
103 { | |
104 tf = TRUE; | |
105 } | |
106 | |
107 void TFoff() | |
108 { | |
109 tf = FALSE; | |
110 } | |
111 | |
112 | |
113 void | |
114 Putenemy(int charano, float x, float y, float vx, float vy, | |
115 CHARACTER * (*action)(CHARACTER *chara)) | |
116 { | |
117 CHARACTER *q; | |
118 /* | |
119 if(!free_chara_list) | |
120 { | |
121 pool_size *= 2; | |
122 if(pool_size > CHARACTER_MAX_POOL_SIZE) | |
123 { | |
124 printf("pool_size over\n"); | |
125 SDL_Quit(); | |
126 exit(1); | |
127 } | |
128 if (!extend_chara_list_pool(pool_size)) | |
129 { | |
130 printf("failed to memory allocate\n"); | |
131 SDL_Quit(); | |
132 exit(1); | |
133 } | |
134 } | |
135 */ | |
136 | |
137 for(q = active_chara_list->next; q != NULL ;q = q->next) | |
138 { | |
139 if(q->f == FALSE) | |
140 { | |
141 break; | |
142 } | |
143 } | |
144 | |
145 q->state = action; | |
146 q->collision = atari; | |
147 q->x = x; | |
148 q->y = y; | |
149 q->vx = vx; | |
150 q->vy = vy; | |
151 q->tama = tf; | |
152 q->vit = enemystate[charano].p; | |
153 q->score = enemystate[charano].sc; | |
154 q->charano = enemystate[charano].charano; | |
155 q->s = 0; | |
156 q->f = TRUE; | |
157 //q->state = ALIVE; | |
158 //q->group = ENEMY | |
159 | |
160 } | |
161 | |
162 CHARACTER * | |
163 delete_chara(CHARACTER *p) | |
164 { | |
165 /* | |
166 CHARACTER * parent = p->prev; | |
167 p->state = noaction; | |
168 p->prev->next = p->next; | |
169 p->next->prev = p->prev; | |
170 | |
171 p->next = free_chara_list->next; | |
172 free_chara_list->next = p; | |
173 */ | |
174 | |
175 CHARACTER *parent = p; | |
176 p->f = FALSE; | |
177 p->state = noaction; | |
178 p->collision = noaction; | |
179 return parent; | |
180 } | |
181 | |
182 void state_update() | |
183 { | |
184 CHARACTER *p; | |
185 for(p = active_chara_list->next; p!= NULL ;p = p->next) | |
186 { | |
187 p=(*p->state)(p); | |
188 } | |
189 } | |
190 | |
191 void collision_detect() | |
192 { | |
193 CHARACTER *p; | |
194 for(p = active_chara_list->next; p!=NULL;p = p->next) | |
195 { | |
196 if((p->state != chara_state8) && (p->state != chara_state9)) | |
197 { | |
198 p=(*p->collision)(p); | |
199 } | |
200 } | |
201 } | |
202 | |
203 void obj_draw() | |
204 { | |
205 CHARACTER *p; | |
206 for(p = active_chara_list->next; p!=NULL;p = p->next) | |
207 { | |
208 if(p->f == TRUE) | |
209 { | |
210 PutSprite(1, p->x, p->y, p->charano); | |
211 } | |
212 } | |
213 } | |
214 | |
215 void outofwindow() | |
216 { | |
217 CHARACTER *p; | |
218 for(p = active_chara_list->next; p!=NULL; p = p->next) | |
219 { | |
220 if((p->state != chara_state8) && (p->state != chara_state9)) | |
221 { | |
222 if ((p->y > 964 + 32) | |
223 || (p->x > 1688 + 50) | |
224 || (p->y < 0 - 128) | |
225 || (p->x < 0 - 200)) | |
226 { | |
227 p->f = FALSE; | |
228 p->state = delete_chara; | |
229 p->collision = noaction; | |
230 } | |
231 } | |
232 } | |
233 } |