Mercurial > hg > Game > Cerium
diff Renderer/test_render/boss1_action.cpp @ 283:15bfacccde99 draft
fix test_render
author | e065746@localhost.localdomain |
---|---|
date | Fri, 05 Jun 2009 16:49:12 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Renderer/test_render/boss1_action.cpp Fri Jun 05 16:49:12 2009 +0900 @@ -0,0 +1,230 @@ +#include "boss1_action.h" + +static void +null_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ +} + +static void +boss1_move_right(SceneGraphPtr node, int screen_w, int screen_h) { + node->xyz[0] += node->stack_xyz[0]; + if(node->xyz[0] > (screen_w - boss_radius_x)) { + node->set_move_collision(boss1_move_left, null_collision); + } +} + +//ボスが左に移動する動作 +static void +boss1_move_left(SceneGraphPtr node, int screen_w, int screen_h) { + node->xyz[0] -= node->stack_xyz[0]; + if(node->xyz[0] < boss_radius_x) { + node->set_move_collision(boss1_move_right, null_collision); + } +} + +static void +player_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + Pad *pad = sgroot->getController(); + + if (pad->left.isPush() + || pad->left.isHold()) { +#if 0 + SceneGraphPtr player_left; + player_left = sgroot->createSceneGraph(PLAYER_L); + player_left->set_move_collision(player_move_left, null_collision); + player_left->xyz[0] = node->xyz[0]; + player_left->xyz[1] = node->xyz[1]; + node->addChild(player_left); + node->flag_drawable = 1; +#endif + node->xyz[0] -= player_speed; + + if (node->xyz[0] - player_radius< 0) { + node->xyz[0] = player_radius; + } + } + + + if (pad->right.isPush() + || pad->right.isHold()) { + node->xyz[0] += player_speed; + + if (node->xyz[0] + player_radius > screen_w) { + node->xyz[0] = screen_w - player_radius; + } + } + + if (pad->up.isPush() + || pad->up.isHold()) { + node->xyz[1] -= player_speed; + + if (node->xyz[1] - player_radius < 0) { + node->xyz[1] = player_radius; + } + } + + if (pad->down.isPush() + || pad->down.isHold()) { + node->xyz[1] += player_speed; + + if (node->xyz[1] + player_radius > screen_h) { + node->xyz[1] = screen_h - player_radius; + } + } + + if (pad->circle.isPush()) { + SceneGraphPtr shot = sgroot->createSceneGraph(P_SHOT1); + shot->set_move_collision(shot_move, shot_collision); + shot->xyz[0] = node->xyz[0]; + shot->xyz[1] = node->xyz[1] - player_radius; + node->addBrother(shot); + } +} + +static void +player_collision(SceneGraphPtr node, int screen_w, int screen_h, + SceneGraphPtr tree) +{ + //自機とボスのx,y座標での距離と2点間の距離 + static float x_distant, y_distant, distance; + //ボスの四角形の四隅の座標 + // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; + + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + + + for (; it->hasNext(BOSS1);) { + it->next(BOSS1); + SceneGraphPtr enemy = it->get(); + + //各変数の初期化 + x_distant = node->xyz[0] - enemy->xyz[0]; + y_distant = node->xyz[1] - enemy->xyz[1]; + + //hypotfで2点間の距離を求める + distance = hypotf(x_distant, y_distant); + + /*四角形と円のcollision + if( (fabs( node->xyz[1] - ( boss_low_y ))) + */ + + //円同士のcollision + if(distance < (player_radius + boss_radius_y)) { + printf("!!!CAUTION!!!\n"); + } + } +} + +static void +shot_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + node->xyz[1] -= shot_speed; + + // 描画領域から抜けたら削除 + if (node->xyz[1] < 0) { + node->remove(); + } +} + +static void +shot_collision(SceneGraphPtr node, int screen_2, int screen_h, + SceneGraphPtr tree) +{ + //自機とボスのx,y座標での距離と2点間の距離 + static float x_distant, y_distant, distance; + //ボスの四角形の四隅の座標 + // static float boss_low_x, boss_low_y, boss_high_x, boss_high_y; + + SceneGraphIteratorPtr it = sgroot->getIterator(tree); + + + for (; it->hasNext(BOSS1);) { + it->next(BOSS1); + SceneGraphPtr enemy = it->get(); + + x_distant = node->xyz[0] - enemy->xyz[0]; + y_distant = node->xyz[1] - enemy->xyz[1]; + + //hypotfで2点間の距離を求める + distance = hypotf(x_distant, y_distant); + + //円同士のcollision + if(distance < boss_radius_y) { + SceneGraphPtr blast = sgroot->createSceneGraph(BLAST1); + + blast->set_move_collision(blast_move, null_collision); + blast->xyz[0] = node->xyz[0]; + blast->xyz[1] = node->xyz[1]; + node->addBrother(blast); + node->remove(); + } + } +} + +static void +blast_move(SceneGraphPtr node, int screen_w, int screen_h) +{ + if(node->sgid > BLAST8) { + SceneGraphPtr blast = sgroot->createSceneGraph(node->sgid - 1); + blast->set_move_collision(blast_move, null_collision); + blast->xyz[0] = node->xyz[0]; + blast->xyz[1] = node->xyz[1]; + node->addBrother(blast); + } + + if (node->sgid == BLAST8) { + node->flag_drawable = 1; + } + + if((node->frame > 1)) { + node->remove(); + } + node->frame += 1; +} + +void +boss1_init(int screen_w, int screen_h) +{ + SceneGraphPtr root; + SceneGraphPtr player; + SceneGraphPtr boss1; + SceneGraphPtr left_parts; + SceneGraphPtr right_parts; + + sgroot->createFromXMLfile("xml_file/boss1.xml"); + sgroot->createFromXMLfile("xml_file/player.xml"); + sgroot->createFromXMLfile("xml_file/p_shot.xml"); + sgroot->createFromXMLfile("xml_file/blast.xml"); + + //rootとなるSceneGraphを生成 + root = sgroot->createSceneGraph(); + + //自機の初期化 + player = sgroot->createSceneGraph(PLAYER); + player->xyz[0] = screen_w/2; + player->xyz[1] = screen_h - player_radius; + root->addChild(player); + + //ボスの初期化 + boss1 = sgroot->createSceneGraph(BOSS1); + boss1->xyz[0] = screen_w/2; + boss1->xyz[1] = boss_radius_y; + // boss1->xyz[2] = first_boss1_depth; + boss1->stack_xyz[0] = first_boss1_speed; + root->addChild(boss1); + + //ボスの左右パーツを追加 + left_parts = sgroot->createSceneGraph(BOSS1_L); + boss1->addChild(left_parts); + right_parts = sgroot->createSceneGraph(BOSS1_R); + boss1->addChild(right_parts); + + //各機体の動きと当たり判定をセット + player->set_move_collision(player_move, player_collision); + boss1->set_move_collision(boss1_move_left, null_collision); + + //仕上げ + sgroot->setSceneData(root); +}