Mercurial > hg > Members > kono > Cerium
diff TaskManager/Test/test_render/ieshoot.cpp @ 201:b257e27d995c
add SceneGraphIterator
author | gongo@gendarme.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Mon, 26 Jan 2009 16:46:59 +0900 |
parents | eb20274baa7c |
children | 3f4c6a75d7e0 |
line wrap: on
line diff
--- a/TaskManager/Test/test_render/ieshoot.cpp Mon Jan 26 14:27:45 2009 +0900 +++ b/TaskManager/Test/test_render/ieshoot.cpp Mon Jan 26 16:46:59 2009 +0900 @@ -1,9 +1,14 @@ #include "SceneGraphRoot.h" #include "SGList.h" -static const int jiki_speed = 6.0f; -static const int jiki_radius = 32.0f; -static const int tama_speed = 10.0f; +static const float jiki_speed = 6.0f; +static const float jiki_radius = 32.0f; + +static const float tama_speed = 10.0f; +static const float tama_radius = 16.0f; + +static const float boss_radius_x = 64.0f; +static const float boss_radius_y = 128.0f; static void iejiki_collision(SceneGraphPtr node, int screen_w, int screen_h, @@ -13,12 +18,57 @@ static void ietama_collision(SceneGraphPtr node, int screen_w, int screen_h, - SceneGraphPtr tree) + SceneGraphPtr tree) { } static void +ieboss_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + static int damage = 0; + + for (; it->hasNext("IETAMA");) { + it->next("IETAMA"); + SceneGraphPtr tama = it->get(); + + if (node->xyz[0] - boss_radius_x < tama->xyz[0] + tama_radius + && node->xyz[0] + boss_radius_x > tama->xyz[0] - tama_radius + && node->xyz[1] + boss_radius_y > tama->xyz[1] - tama_radius) { + tama->remove(); + + damage++; + } + } + + if (damage > 10) { + node->remove(); + } +} + +static void +ieboss_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + /** + * TODO + * Boss が複数居た場合、これじゃ駄目 + */ + static int x_speed = 5.0f; + + node->xyz[0] += x_speed; + + if (node->xyz[0] - boss_radius_x < 0) { + x_speed = -x_speed; + node->xyz[0] = boss_radius_x; + } else if (node->xyz[0] + boss_radius_x > screen_w) { + x_speed = -x_speed; + node->xyz[0] = screen_w - boss_radius_x; + } +} + +static void ietama_move(SceneGraphPtr node, int screen_w, int screen_h) { node->xyz[1] -= tama_speed; @@ -84,12 +134,24 @@ ieshoot_init(void) { SceneGraphPtr iejiki; + SceneGraphPtr enemy; + SceneGraphPtr back; sgroot->createFromXMLfile("xml_file/iejiki.xml"); sgroot->createFromXMLfile("xml_file/ietama.xml"); + sgroot->createFromXMLfile("xml_file/ieboss.xml"); iejiki = sgroot->createSceneGraph(IEJIKI); iejiki->set_move_collision(iejiki_move, iejiki_collision); - sgroot->setSceneData(iejiki); + enemy = sgroot->createSceneGraph(IEBOSS); + enemy->set_move_collision(ieboss_move, ieboss_collision); + enemy->xyz[1] = boss_radius_y; + + back = sgroot->createSceneGraph(); + + back->addChild(iejiki); + back->addChild(enemy); + + sgroot->setSceneData(back); }