539
|
1 #include <iostream>
|
|
2 #include <cmath>
|
|
3 #include "SceneGraphRoot.h"
|
|
4 #include "SGList.h"
|
|
5 #include "gaplant.h"
|
|
6 using namespace std;
|
|
7
|
|
8 void
|
|
9 move_right(SceneGraphPtr node)
|
|
10 {
|
|
11 /*cout << "右を押したんだ " << node->angle[2] << "\n";
|
|
12 node->angle[2] -= 1;
|
|
13 if (node->angle[2] < -30) {
|
|
14 node->angle[2] = -30;
|
|
15 }*/
|
|
16 node->xyz[0] += 5;
|
|
17 }
|
|
18
|
|
19 void
|
|
20 move_left(SceneGraphPtr node)
|
|
21 {
|
|
22 /*cout << "左を押したんだ " << node->angle[2] << "\n";
|
|
23 node->angle[1] += 1;
|
|
24 if (node->angle[2] > 30) {
|
|
25 node->angle[2] = 30;
|
|
26 }*/
|
|
27 node->xyz[0] -= 5;
|
|
28 }
|
|
29
|
|
30 void
|
|
31 move_down(SceneGraphPtr node)
|
|
32 {
|
|
33 /*cout << "下だって押したくなる時はある "<< node->angle[0] << "\n";
|
|
34 node->angle[0] += 1;
|
|
35 if (node->angle[0] > -60) {
|
|
36 node->angle[0] = -60;
|
|
37 }*/
|
|
38 node->xyz[1] += 5;
|
|
39 }
|
|
40
|
|
41 void
|
|
42 move_up(SceneGraphPtr node)
|
|
43 {
|
|
44 /*cout << "上を押したんだ "<< node->angle[0] << "\n";
|
|
45 node->angle[0] -= 1;
|
|
46 if (node->angle[0] < -120) {
|
|
47 node->angle[0] = -120;
|
|
48 }*/
|
|
49 node->xyz[1] -= 5;
|
|
50 }
|
|
51
|
|
52 void
|
|
53 gaplant_move(SceneGraphPtr node, int w, int h)
|
|
54 {
|
|
55 Pad *pad = sgroot->getController();
|
|
56
|
|
57 if (pad->right.isHold() || pad->left.isHold() || pad->down.isHold() || pad->up.isHold()) {
|
|
58 if (pad->right.isHold()) {
|
|
59 move_right(node);
|
|
60 } else if (pad->left.isHold()) {
|
|
61 move_left(node);
|
|
62 } else if (pad->down.isHold()) {
|
|
63 move_down(node);
|
|
64 } else if (pad->up.isHold()) {
|
|
65 move_up(node);
|
|
66 }
|
|
67 }
|
|
68
|
|
69 if (pad->cross.isHold() || pad->circle.isHold()) {
|
|
70 if (pad->cross.isHold()) {
|
|
71 node->xyz[2] += 5;
|
|
72 } else if (pad->circle.isHold()) {
|
|
73 node->xyz[2] -= 5;
|
|
74 }
|
|
75 }
|
|
76 }
|
|
77
|
|
78 void
|
|
79 gaplant_coll(SceneGraphPtr node, int w, int h, SceneGraphPtr tree)
|
|
80 {
|
|
81 SceneGraphIteratorPtr it = sgroot->getIterator(tree);
|
|
82 //static int damage = 0;
|
|
83
|
|
84 for (; it->hasNext(Ball);) {
|
|
85 it->next(Ball);
|
|
86 SceneGraphPtr ball = it->get();
|
|
87
|
|
88 double dis_x = node->xyz[0] - ball->xyz[0];
|
|
89 double dis_y = node->xyz[1] - ball->xyz[1];
|
|
90 double dis_z = node->xyz[2] - ball->xyz[2];
|
|
91 double distance = sqrt(dis_x*dis_x + dis_y*dis_y + dis_z*dis_z);
|
|
92
|
|
93 if (distance < CHECK_HIT_RAD + BALL_RAD) {
|
|
94 cout << "今からもっと細かく判定するよ ^q^\n";
|
|
95 ball->remove();
|
|
96 }
|
|
97 }
|
|
98 }
|