view TaskManager/Test/test_render/vacuum.cpp @ 376:4fb99cd5d13f draft

chain.cpp added
author kazz@kazzone.cr.ie.u-ryukyu.ac.jp
date Fri, 31 Jul 2009 18:21:24 +0900
parents 4fad8f9329ac 205e4a4af635
children bdeb7a73285b
line wrap: on
line source

#include <math.h>
#include "vacuum.h"
#include "SceneGraphRoot.h"
#include "SGList.h"
#define ENCOUNT 55
using namespace std;

<<<<<<< local
static void cube_move_left(SceneGraphPtr node, int screen_w, int screen_h);
static void cube_move_right(SceneGraphPtr node, int screen_w, int screen_h);
static void cube_move_idle(SceneGraphPtr node, int screen_w, int screen_h);
static void cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
                           SceneGraphPtr tree);
static void cube_split(SceneGraphPtr root);
=======
static float vacuum_speed = 10.0f;
>>>>>>> other


/*オブジェクト毎にファイルを分けてみた
 *
 *
 */



void
no_move_idle(SceneGraphPtr node, int screen_w, int screen_h)
{

<<<<<<< local
    if (node->xyz[0] < 0) {
        node->set_move_collision(cube_move_right, cube_collision);
    }

    if (node->xyz[1] < 0 || node->xyz[1] > screen_h) {
        node->stack_xyz[1] = -node->stack_xyz[1];
    }

    //node->angle[0] += 2.0f;
    //node->angle[1] += 2.0f * node->stack_xyz[1];
    //node->angle[2] += 2.0f * node->stack_xyz[2];

    if (++node->frame > 60) {
        cube_split(node);
    }
=======
>>>>>>> other
}

void
no_collision_idle(SceneGraphPtr node, int screen_w, int screen_h,SceneGraphPtr tree)
{
<<<<<<< local
    node->xyz[0] += node->stack_xyz[0];
#if 0
    node->xyz[1] -= node->stack_xyz[0] * node->stack_xyz[1];
    node->xyz[2] -= node->stack_xyz[0] * node->stack_xyz[2];
#else
    node->xyz[1] += node->stack_xyz[1];
#endif

    if (node->xyz[0] > screen_w) {
        node->set_move_collision(cube_move_left, cube_collision);
    }
=======
>>>>>>> other

<<<<<<< local
    if (node->xyz[1] < 0 || node->xyz[1] > screen_h) {
        node->stack_xyz[1] = -node->stack_xyz[1];
    }

    //node->angle[0] += 2.0f;
    //node->angle[1] += 2.0f * node->stack_xyz[1];
    //node->angle[2] += 2.0f * node->stack_xyz[2];

    if (++node->frame > 60) {
        cube_split(node);
    }
=======
>>>>>>> other
}

void
vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h,
            SceneGraphPtr tree)
{
    Pad *pad = sgroot->getController();

<<<<<<< local
    if (pad->circle.isPush()) {
        cube_split(node);
=======
    if(node->frame%ENCOUNT == ENCOUNT-1) {
      if(random()%2) {
      add_cubecollision_object(REDCUBE,node,screen_w,screen_h);
      }
      else {
      add_cubecollision_object(ENEMY,node,screen_w,screen_h);
      }
>>>>>>> other
    }

    if (pad->cross.isHold()) {
      SceneGraphIteratorPtr it = sgroot->getIterator(tree);
      collision_red(it,node);
      it = sgroot->getIterator(tree);
      collision_purple(it,node,screen_w,screen_h);
    }

    else if(pad->circle.isHold()) {
      SceneGraphIteratorPtr it = sgroot->getIterator(tree);
      lock_attack(node,it);
    }

}

<<<<<<< local
static void
cube_collision(SceneGraphPtr node, int screen_w, int screen_h,
               SceneGraphPtr tree)
=======
void
lock_attack(SceneGraphPtr node,SceneGraphIteratorPtr it)
>>>>>>> other
{

  SceneGraphPtr enemy;
  SceneGraphPtr near_enemy = NULL;
  float dx,dy,r,range = 100;
  // Pad *pad = sgroot->getController();

  for(;it->hasNext(ENEMY);) {

      it->next(ENEMY);
      enemy = it->get();
      dx = enemy->xyz[0] - node->xyz[0];
      dy = enemy->xyz[1] - node->xyz[1];
      r = sqrt(dx*dx+dy*dy);

      if(range > r && enemy->stack_xyz[2] == 0) {
        range = r;
        near_enemy = enemy;
      }
  }


  if(near_enemy != NULL) {
    /*stack_xyz[2]をlockonフラグとして使うかな?*/
    SceneGraphPtr lockon;
    //    SceneGraphPtr near_enemy_common_move = near_enemy->parent;
    near_enemy->stack_xyz[2] = 1;
    lockon = sgroot->createSceneGraph(LOCK);
    lockon->set_move_collision(no_move_idle,lockon_collision);
    //near_enemy_common_move->addChild(lockon);
    near_enemy->addChild(lockon);
    }

}

<<<<<<< local
static void
vacuum_coll(SceneGraphPtr node, int screen_w, int screen_h,
            SceneGraphPtr tree)
{
    SceneGraphIteratorPtr it = sgroot->getIterator();
    SceneGraphPtr bigm;
    Pad *pad = sgroot->getController();
    float dx, dy, r;
    float q = 0;
=======
void
lockon_collision(SceneGraphPtr node,int w,int h,SceneGraphPtr tree) {
>>>>>>> other

<<<<<<< local
    if (pad->cross.isRelease()) {
        return;
    }
=======
  Pad *pad = sgroot->getController();
  SceneGraphPtr lockon_enemy = node->parent;
>>>>>>> other

  /* node->angle[0] = -lockon_enemy->angle[0];
  node->angle[1] = -lockon_enemy->angle[1];
  node->angle[2] = -lockon_enemy->angle[2];*/

<<<<<<< local
    for (; it->hasNext(MCUBE);) {
        it->next(MCUBE);
        SceneGraphPtr mcube = it->get();
=======
  if(pad->circle.isRelease()) {
    lockon_enemy->remove();
  }
>>>>>>> other

<<<<<<< local
        dx = node->xyz[0] - mcube->xyz[0];
        dy = node->xyz[1] - mcube->xyz[1];

        r = sqrt(dx*dx + dy*dy);

        if (r >= 1) q = 300/r;

        if (r < 50.0f) {
            mcube->remove();
            continue;
        }

        if (dx == 0) {
            if(mcube->xyz[1] > node->xyz[1]) {
                mcube->xyz[1] -= q;
            } else if(mcube->xyz[1] < node->xyz[1]) {
                mcube->xyz[1] += q;
            }
        } else {
            if(mcube->xyz[0] > node->xyz[0]) {
                mcube->xyz[0] -= q*cos(atan(dy/dx));
                mcube->xyz[1] -= q*sin(atan(dy/dx));
                mcube->stack_xyz[0] = -q*cos(atan(dy/dx));
                mcube->stack_xyz[1] = -q*sin(atan(dy/dx));
            } else if(mcube->xyz[0] < mcube->xyz[0]) {
                mcube->xyz[0] += q*cos(atan(dy/dx));
                mcube->xyz[1] += q*sin(atan(dy/dx));
                mcube->stack_xyz[0] = -q*cos(atan(dy/dx));
                mcube->stack_xyz[1] = -q*sin(atan(dy/dx));
            }
        }
    }
=======
>>>>>>> other
}


void
vacuum_move(SceneGraphPtr node , int w, int h)
{
    Pad *pad = sgroot->getController();

<<<<<<< local
    if (pad->right.isHold()) {
        node->xyz[0] += vacuum_speed;
    } else if (pad->left.isHold()) {
        node->xyz[0] -= vacuum_speed;
=======
    if (pad->right.isHold() && w > node->xyz[0]) {
      node->xyz[0] += vacuum_speed;
      node->angle[0] += 2;
    } else if (pad->left.isHold() && 0 < node->xyz[0]) {
      node->xyz[0] -= vacuum_speed;
      node->angle[0] -= 2;
>>>>>>> other
    }

<<<<<<< local
    if (pad->up.isHold()) {
        node->xyz[1] -= vacuum_speed;
    } else if (pad->down.isHold()) {
        node->xyz[1] += vacuum_speed;
=======
    if (pad->up.isHold() && 0 < node->xyz[1]) {
      node->xyz[1] -= vacuum_speed;
      node->angle[1] -= 2;
    } else if (pad->down.isHold() && h > node->xyz[1]) {
      node->xyz[1] += vacuum_speed;
      node->angle[1] += 2;
>>>>>>> other
    }

    if (pad->start.isPush()) {
<<<<<<< local
        node->xyz[0] = w/2;
        node->xyz[1] = h*0.8;
=======
      node->xyz[0] = w/2;
      node->xyz[1] = h*0.8;
>>>>>>> other
    }
}



/*cubeをランダムな場所に生成*/
void
add_cubecollision_object(int id,SceneGraphPtr root,int w,int h)
{
    SceneGraphPtr object;
    SceneGraphPtr common_move;

    common_move = sgroot->createSceneGraph();
    object = sgroot->createSceneGraph(id);
    object->xyz[0] = random()%w;
    object->xyz[1] = random()%h;
    object->set_move_collision(no_move_idle,cube_collision);
    //common_move->addChild(object);
    root->addBrother(object);
}


void
vacuum_init2(int w, int h)
{
    SceneGraphPtr title;

    sgroot->createFromXMLfile("xml_file/gamecube.xml");
    sgroot->createFromXMLfile("xml_file/title.xml");
    sgroot->createFromXMLfile("xml_file/gameover.xml");

    title = sgroot->createSceneGraph(TITLE);
    title->xyz[0] = w/2;
    title->xyz[1] = h/2;
    title->set_move_collision(no_move_idle, title_collision);

    sgroot->setSceneData(title);
}