annotate Renderer/Test/bullet_action.cc @ 639:91d03774c407 draft

fix
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 19 Nov 2009 18:45:24 +0900
parents 4c5264373c51
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
539
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <math.h>
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "SceneGraphRoot.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "SGList.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include "hit_judge.h"
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #define PI M_PI
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 int i = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 void
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 bullet_init(SceneGraphPtr bullet, SceneGraphPtr player)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 bullet->xyz[0] = player->xyz[0];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 bullet->xyz[1] = player->xyz[1];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 bullet->xyz[2] = player->xyz[2];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 bullet->angle[0] = player->angle[0];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 bullet->angle[1] = player->angle[1];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 bullet->angle[2] = player->angle[2];
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 void
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 bluebullet_move(SceneGraphPtr node, int screen_w, int screen_h)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 double a = (node->angle[2]+90)*PI/180;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 double b = (node->angle[0]+90)*PI/180;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 double y = sin(a);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 double x = cos(a);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 double z = -cos(b);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 node->xyz[0] += x * 5;//x軸方向
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 node->xyz[1] += y * 5;//y軸方向
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 node->xyz[2] += z * 5;//z軸方向
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 void
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 bullet_collision(SceneGraphPtr node, int screen_w, int screen_h, SceneGraphPtr tree)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 //static int damage = 0;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 for (; it->hasNext(E_PLANE);) {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 it->next(E_PLANE);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 SceneGraphPtr enemy = it->get();
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 int judge = square_judge(node, enemy);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 if(judge == HIT)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 //node->set_move_collision(null_move, bullet_collision);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50 //E_PLANE->set_move_collision(null_move, enemy_collision);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 enemy->remove();
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 node->remove();
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 //printf("hit!!!\n");
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54 //bullet_delete(node, scene_graph);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
56 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
57
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
58 if(node->xyz[1] > 100)
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
59 {
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
60 node->remove();
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
61 //scene_graph->delete_object(node, node->next,node->prev);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
62 //i -= 1;
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
63 //printf("bullet_delete:残り弾数=%d\n",i);
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
64 }
3bc98f6d31ff Reorganization..
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
65 }