view mydandy.cc @ 6:581fa1888e2e

add bullet
author tkaito
date Mon, 07 Jun 2010 18:58:59 +0900
parents 57af5c610b34
children c7c497f1c585
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 shot_move(SceneGraphPtr node, void *sgroot_, int w, int h);
void shot_coll(SceneGraphPtr node, void *sgroot_, int w, int h, SceneGraphPtr tree);

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;
  }
  if (pad->circle.isPush()) {
    SceneGraphPtr shot = sgroot->createSceneGraph("bluebullet");
    shot->set_move_collision(shot_move, shot_coll);
    shot->xyz[0] = node->xyz[0];
    shot->xyz[1] = node->xyz[1] - player_radius;
    node->addBrother(shot);
  }
}

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
shot_move(SceneGraphPtr node, void *sgroot_, int w, int h)
{
  node->xyz[1] -= shot_speed;

  if (node->xyz[1] < 0) {
    node->remove();
  }
}
void
shot_coll(SceneGraphPtr node, void *sgroot_, int w, int h,SceneGraphPtr tree){}

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 gclab = sgroot->getSgid("green_clab");

  for (; it->hasNext(gclab);) {
    it->next(gclab);
    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) < player_radius && sqrt(ddy) < player_radius) {
      gameover_scene(sgroot, w, h);
      //node->remove();
      break;
    }
  }
}