Mercurial > hg > Members > kono > tree_dandy2
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Character.c Tue Dec 07 15:39:45 2010 +0900 @@ -0,0 +1,233 @@ +#include <stdio.h> +#include <stdlib.h> +#include "syokika.h" +#include "bool.h" +#include <SDL.h> +#include "SDL_opengl.h" +#include "object.h" +#include "Character.h" +#include "Character_state.h" +#include "count2.h" +#include "tokuten.h" +#include "schedule.h" +#include "sankaku.h" +#include "sgoex.h" +#include "collision.h" +#include "debug.h" + +#include "error.h" + +#define CHARACTER_MAX_POOL_SIZE 2048 + + +const table enemystate[] = ENEMY_STATUS_TABLE; +int filpcount = 0; +int stage = 0; +BOOL tf = FALSE; +static int pool_size; + +int init_chara_list(int num) +{ + if(active_chara_list == NULL) + { + return extend_chara_list_pool(num); + } + return 1; +} + +int +extend_chara_list_pool(int num) +{ + + pool_size = num; + /* + q = (CHARACTER*)malloc(sizeof(CHARACTER)*(num+1)); + + if(!q){ + return 0; + } + + q->next = active_chara_list; + active_chara_list = q; + + q = active_chara_list + 1; + for(q = active_chara_list +1;num-->0;q++) + { + q->next = q+1; + } + q->next = free_chara_list; + free_chara_list = active_chara_list+1; + */ + __debug("task init start"); + + int i; + CHARACTER *q[num]; + + for(i = 0; i<num ; i++) + { + q[i] = (CHARACTER*)malloc(sizeof(CHARACTER)); + q[i]->f = FALSE; + q[i]->state = noaction; + q[i]->collision = noaction; + } + + for(i = 0; i<num-1 ; i++) + { + q[i]->next = q[i+1]; + //q[i]->next->prev = q[i]; + } + + q[num-1]->next = NULL; + active_chara_list = (CHARACTER*)malloc(sizeof(CHARACTER)); + active_chara_list->f = FALSE; + active_chara_list->state = noaction; + active_chara_list->collision = noaction; + active_chara_list->next = q[0]; + //q[0]->prev = active_chara_list; + //active_chara_list->prev = q[num-1]; + //q[num-1]->next = active_chara_list; + CHARACTER *p; + + for(p = active_chara_list->next; p != NULL ; p = p->next) + { + if(p != NULL) + { + __debug("list_test"); + } + } + return 1; + +} + +void TFon() +{ + tf = TRUE; +} + +void TFoff() +{ + tf = FALSE; +} + + +void +Putenemy(int charano, float x, float y, float vx, float vy, + CHARACTER * (*action)(CHARACTER *chara)) +{ + CHARACTER *q; + /* + if(!free_chara_list) + { + pool_size *= 2; + if(pool_size > CHARACTER_MAX_POOL_SIZE) + { + printf("pool_size over\n"); + SDL_Quit(); + exit(1); + } + if (!extend_chara_list_pool(pool_size)) + { + printf("failed to memory allocate\n"); + SDL_Quit(); + exit(1); + } + } + */ + + for(q = active_chara_list->next; q != NULL ;q = q->next) + { + if(q->f == FALSE) + { + break; + } + } + + q->state = action; + q->collision = atari; + q->x = x; + q->y = y; + q->vx = vx; + q->vy = vy; + q->tama = tf; + q->vit = enemystate[charano].p; + q->score = enemystate[charano].sc; + q->charano = enemystate[charano].charano; + q->s = 0; + q->f = TRUE; + //q->state = ALIVE; + //q->group = ENEMY + +} + +CHARACTER * +delete_chara(CHARACTER *p) +{ + /* + CHARACTER * parent = p->prev; + p->state = noaction; + p->prev->next = p->next; + p->next->prev = p->prev; + + p->next = free_chara_list->next; + free_chara_list->next = p; + */ + + CHARACTER *parent = p; + p->f = FALSE; + p->state = noaction; + p->collision = noaction; + return parent; +} + +void state_update() +{ + CHARACTER *p; + for(p = active_chara_list->next; p!= NULL ;p = p->next) + { + p=(*p->state)(p); + } +} + +void collision_detect() +{ + CHARACTER *p; + for(p = active_chara_list->next; p!=NULL;p = p->next) + { + if((p->state != chara_state8) && (p->state != chara_state9)) + { + p=(*p->collision)(p); + } + } +} + +void obj_draw() +{ + CHARACTER *p; + for(p = active_chara_list->next; p!=NULL;p = p->next) + { + if(p->f == TRUE) + { + PutSprite(1, p->x, p->y, p->charano); + } + } +} + +void outofwindow() +{ + CHARACTER *p; + for(p = active_chara_list->next; p!=NULL; p = p->next) + { + if((p->state != chara_state8) && (p->state != chara_state9)) + { + if ((p->y > 964 + 32) + || (p->x > 1688 + 50) + || (p->y < 0 - 128) + || (p->x < 0 - 200)) + { + p->f = FALSE; + p->state = delete_chara; + p->collision = noaction; + } + } + } +}