diff 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 diff
--- a/mydandy.cc	Sun Jun 06 06:47:45 2010 +0900
+++ b/mydandy.cc	Mon Jun 07 02:16:02 2010 +0900
@@ -1,37 +1,23 @@
 #include "game_scene01.h"
 
-void def_angle(SceneGraphPtr node, void *sgroot_, int w, int h);
-void left_angle(SceneGraphPtr node, void *sgroot_, int w, int h);
-void right_angle(SceneGraphPtr node, void *sgroot_, int w, int h);
+void change_angle(SceneGraphPtr node);
+void collision_obj(SceneGraphIteratorPtr it,SceneGraphPtr node ,int w, int h, void *sgroot);
 
 void
-dandy_move(SceneGraphPtr node, void *sgroot_, int w, int h)
+mydandy_move(SceneGraphPtr node, void *sgroot_, int w, int h)
 {
   SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
   Pad *pad = sgroot->getController();
 
-  /* 左右の移動 */  
-  if (pad->right.isPush() && w > node->xyz[0]) {
-    right_angle(node, sgroot, w, h);
-  } else if (pad->left.isPush() && 0 < node->xyz[0]) {
-    left_angle(node, sgroot, w, h);
-  } else {
-    //def_angle(node, sgroot, w, h);
-  }
   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->right.isRelease()) {
-    
-  } else if(pad->left.isRelease()) {
-
-  }  
-  /* 上下の移動 */
   if (pad->up.isHold() && 0 < node->xyz[1]) {
     node->xyz[1] -= 10.0f;
-    //def_angle(node, sgroot, w, h);
   } else if (pad->down.isHold() && h > node->xyz[1]) {
     node->xyz[1] += 10.0f;
   }
@@ -39,63 +25,81 @@
 }
 
 void
-dandy_collision(SceneGraphPtr node, void *sgroot_, int w, int h,SceneGraphPtr tree)
+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;
+  }
 
 }
-
-/* 時機や敵機のオブジェクトや何やらを作成してsetSceneDataまで */
-
 void
-def_angle(SceneGraphPtr node, void *sgroot_, int w, int h) 
+rtdandy_move(SceneGraphPtr node, void *sgroot_, int w, int h)
 {
+  SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
+  Pad *pad = sgroot->getController();
 
-  SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;      
-  SceneGraphPtr dandy = sgroot->createSceneGraph("mydandy");
-  SceneGraphPtr back = sgroot->createSceneGraph(); 
-  
-  dandy->xyz[0] = node->xyz[0];
-  dandy->xyz[1] = node->xyz[1];
-  
-  dandy->set_move_collision(dandy_move, dandy_collision);
-  
-  back->addChild(dandy);  
-  sgroot->setSceneData(back);
+  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
-right_angle(SceneGraphPtr node, void *sgroot_, int w, int h) 
+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_;
-  SceneGraphPtr rtdandy;
-  SceneGraphPtr back = sgroot->createSceneGraph();
+  float dx, dy,ddx,ddy;
+  int g_clab = sgroot->getSgid("green_clab");
 
-  rtdandy = sgroot->createSceneGraph("rt-dandy");
+  for (; it->hasNext(g_clab);) {
+    it->next(g_clab);
+    SceneGraphPtr obj = it->get();
 
-  rtdandy->xyz[0] = node->xyz[0];
-  rtdandy->xyz[1] = node->xyz[1];
-  
-  rtdandy->set_move_collision(dandy_move, dandy_collision);
-  back->addChild(rtdandy);
-  
-  sgroot->setSceneData(back);
-  rtdandy->xyz[0] += 1.0f;
+    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;
+    }
+  }
 }
-void
-left_angle(SceneGraphPtr node, void *sgroot_, int w, int h) 
-{
-  SceneGraphRoot *sgroot = (SceneGraphRoot *)sgroot_;
-  SceneGraphPtr ltdandy;
-  SceneGraphPtr back = sgroot->createSceneGraph();
-
-  ltdandy = sgroot->createSceneGraph("lt-dandy");
-
-  ltdandy->xyz[0] = node->xyz[0];
-  ltdandy->xyz[1] = node->xyz[1];
-  
-  ltdandy->set_move_collision(dandy_move, dandy_collision);
-  back->addChild(ltdandy);  
-  
-  sgroot->setSceneData(back);
-  ltdandy->xyz[0] -= 1.0f;
-}