view Character.c @ 70:cee55c8365e9 default tip

fix
author Kazuma
date Thu, 19 May 2016 18:52:26 +0900
parents 2c85322348cf
children 2e123c4bf5ca
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]->dt1 = 0;
      q[i]->dt2 = 0;
      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;
}


static int global_id = 0;


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->chara_id = global_id;
  ++global_id;
  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
  if (q->tama == FALSE) {
    printf("F%d:   [%d] x=%f  y=%f  vx=%f  vy=%f  CREATE\n", filpcount, q->chara_id, q->x, q->y, q->vx, q->vy);
  }
}

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->tama = TRUE;
	      p->state = delete_chara;
	      p->collision = noaction;
	    }
	}
    }
}