view mydandy.cc @ 5:57af5c610b34

iroiro add
author tkaito
date Mon, 07 Jun 2010 02:16:02 +0900
parents dca6d5d2ef46
children 581fa1888e2e
line wrap: on
line source

#include "game_scene01.h"

void change_angle(SceneGraphPtr node);
void collision_obj(SceneGraphIteratorPtr it,SceneGraphPtr node ,int w, int h, void *sgroot);

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

  if (pad->right.isHold() && w > node->xyz[0]) {
    node->xyz[2] = 100000.0f;
    node->xyz[0] += 10.0f;
  } else if (pad->left.isHold() && 0 < node->xyz[0]) {
    node->xyz[2] = 100000.0f;
    node->xyz[0] -= 10.0f;
  }
  if (pad->up.isHold() && 0 < node->xyz[1]) {
    node->xyz[1] -= 10.0f;
  } else if (pad->down.isHold() && h > node->xyz[1]) {
    node->xyz[1] += 10.0f;
  }

}

void
ltdandy_move(SceneGraphPtr node, void *sgroot_, int w, int h)
{
  SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
  Pad *pad = sgroot->getController();
  if (pad->right.isHold() && w > node->xyz[0]) {
    node->xyz[2] = 100000.0f;
    node->xyz[0] += 10.0f;
  } else if (pad->left.isHold() && 0 < node->xyz[0]) {
    node->xyz[2] = 0.0f;
    node->xyz[0] -= 10.0f;
  }
  if (pad->up.isHold() && 0 < node->xyz[1]) {
    node->xyz[1] -= 10.0f;
  } else if (pad->down.isHold() && h > node->xyz[1]) {
    node->xyz[1] += 10.0f;
  }

}
void
rtdandy_move(SceneGraphPtr node, void *sgroot_, int w, int h)
{
  SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
  Pad *pad = sgroot->getController();

  if (pad->right.isHold() && w > node->xyz[0]) {
    node->xyz[2] = 0.0f;
    node->xyz[0] += 10.0f;
  } else if (pad->left.isHold() && 0 < node->xyz[0]) {
    node->xyz[2] = 100000.0f;
    node->xyz[0] -= 10.0f;
  }
  if (pad->up.isHold() && 0 < node->xyz[1]) {
    node->xyz[1] -= 10.0f;
  } else if (pad->down.isHold() && h > node->xyz[1]) {
    node->xyz[1] += 10.0f;
  }

}

void
ldandy_move(SceneGraphPtr node, void *sgroot_, int w, int h){}
void
rdandy_move(SceneGraphPtr node, void *sgroot_, int w, int h){}

void
mydandy_coll(SceneGraphPtr node, void *sgroot_, int w, int h,SceneGraphPtr tree)
{
  SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
  SceneGraphIteratorPtr it = sgroot->getIterator(tree);
  collision_obj(it, node, w, h, sgroot);
}

void
dandy_coll(SceneGraphPtr node, void *sgroot_, int w, int h,SceneGraphPtr tree){}

void
collision_obj(SceneGraphIteratorPtr it,SceneGraphPtr node ,int w, int h, void *sgroot_)
{
  SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
  float dx, dy,ddx,ddy;
  int g_clab = sgroot->getSgid("green_clab");

  for (; it->hasNext(g_clab);) {
    it->next(g_clab);
    SceneGraphPtr obj = it->get();

    dx = node->xyz[0] - obj->xyz[0];
    dy = node->xyz[1] - obj->xyz[1];
    ddx = dx*dx;
    ddy = dy*dy;

    if(sqrt(ddx) < 10 && sqrt(ddy) < 10) {
      gameover_scene(sgroot, w, h);
      node->remove();
      break;
    }
  }
}