view Character.c @ 30:427e1aac0bd7

not run.
author koba <koba@cr.ie.u-ryukyu.ac.jp>
date Fri, 31 Dec 2010 15:50:44 +0900
parents 00c3272a801f
children 39e643fc4f90
line wrap: on
line source

#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"
#include "state_task.h"
#include "Func.h"

#define CHARACTER_MAX_POOL_SIZE 2048

CHARACTER *active_chara_list;
CHARACTER *free_chara_list;



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;
  __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]->task = 0;
      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;

  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

}

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->collision != noaction))
      //	{
	  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;
	    }
	  //	}
    }
}