DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
sprite.cpp
1#pragma helper_mask_gpr 0x30
2
3#include "title/sprite.hpp"
4
5#include <libgraph.h>
6#include <libpkt.h>
7#include <libvu0.h>
8
9#include <cmath>
10#include <cstdlib>
11
12#include "mathutil.hpp"
13#include "mglib.hpp"
14#include "texture.hpp"
15#include "title/scfader.hpp"
16#include "title/title.hpp"
17
18/* The rectangle every 2D draw takes, declared here rather than reached through rect.h because the
19 two constructors that header states are not this file's: every rectangle here is built by one
20 that assigns x, y, w and h in that order, and rect.h's assigns them in the other. */
21template <class T>
22class CRect {
23public:
24 T x;
25 T y;
26 T w;
27 T h;
29 CRect() {}
30
31 CRect(T left, T top, T width, T height) {
32 x = left;
33 y = top;
34 w = width;
35 h = height;
36 }
37};
38
39void set2DSprite(sceVif1Packet *packet, CTexture *texture, const CRect<int> &dst, const CRect<int> &src, u_char alpha);
40
42 int i;
43
44 for (i = 0; i < 12; i++) {
45 x[i] = 0.0f;
46 y[i] = 150.0f;
47 }
48
49 angle = 2.57f;
50 started = false;
51}
52
54 int i;
55
56 for (i = 0; i < 12; i++) {
57 x[i] = 0.0f;
58 y[i] = 150.0f;
59 }
60
61 angle = 2.57f;
62 started = false;
63}
64
66 float target_x;
67 float target_y;
68 float target_angle;
69 int i;
70
71 if (started == 0) {
72 started = true;
73 }
74
75 for (i = 0; i < 11; i++) {
76 x[11 - i] = x[10 - i];
77 y[11 - i] = y[10 - i];
78 }
79
80 if (x[0] < 700.0f) {
81 if (x[0] < 700.0f) {
82 target_x = 700.0f;
83 target_y = 94.0f;
84 }
85
86 if (x[0] < 510.0f) {
87 target_x = 510.0f;
88 target_y = 154.0f;
89 }
90
91 if (x[0] < 400.0f) {
92 target_x = 400.0f;
93 target_y = 194.0f;
94 }
95
96 if (x[0] < 320.0f) {
97 target_x = 320.0f;
98 target_y = 154.0f;
99 }
100
101 if (x[0] < 230.0f) {
102 target_x = 250.0f;
103 target_y = 94.0f;
104 }
105
106 if (x[0] < 150.0f) {
107 target_x = 150.0f;
108 target_y = 154.0f;
109 }
110
111 target_angle = (float) atan2(target_x - x[0], target_y - y[0]);
112
113 if (this->angle > target_angle) {
114 this->angle = this->angle - 0.08f;
115 }
116
117 if (this->angle < target_angle) {
118 this->angle += 0.08f;
119 }
120
121 x[0] = x[0] + (float) (sin(this->angle) * 7.5);
122 y[0] = y[0] + (float) (cos(this->angle) * 7.5);
123 }
124}
125
127 int i;
128
129 if (x[0] < 700.0f) {
130 u_char size[5] = {250, 60, 40, 20, 20};
131
132 for (i = 0; i < 5; i++) {
133 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pat01", -1), CRect<int>((int) x[i], (int) (y[i] - 16.0f), 64, 64), CRect<int>(0, 0, 64, 64), (u_char) CFade.Get(rand() % size[i]));
134 }
135
136 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pat02", -1), CRect<int>((int) (8.0f + (x[0] - (float) (rand() % 8))), (int) (y[0] + (float) (rand() % 16)), 16, 16), CRect<int>(0, 0, 32, 32), (u_char) CFade.Get(rand() % 128));
137
138 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pat02", -1), CRect<int>((int) (8.0f + (x[0] - (float) (rand() % 16))), (int) (y[0] + (float) (rand() % 24) - 6.0f), 16, 16), CRect<int>(0, 0, 32, 32), (u_char) CFade.Get(rand() % 128));
139
140 {
141 u_char alpha[11] = {90, 80, 70, 60, 50, 40, 30, 20, 20, 10, 10};
142
143 for (i = 1; i < 12; i++) {
144 set2DSprite(GetVif1Packet(), TexManager.GetTexture("pat02", -1), CRect<int>((int) (8.0f + (x[i] - (float) (rand() % 8))), (int) (4.0f + (y[i] + (float) (rand() % 16))), 8, 8), CRect<int>(0, 0, 32, 32), (u_char) CFade.Get(alpha[i]));
145 }
146 }
147 }
148}
149
151 return started;
152}
Definition op_a.cpp:55
T h
Definition op_a.cpp:60
T y
Definition op_a.cpp:58
T x
Definition op_a.cpp:57
T w
Definition op_a.cpp:59
int Get(int limit)
Definition scfader.cpp:45
void Init()
Definition sprite.cpp:53
float x[12]
Definition sprite.hpp:7
float y[12]
Definition sprite.hpp:8
int Se()
Definition sprite.cpp:150
void Move()
Definition sprite.cpp:65
float angle
Definition sprite.hpp:9
void Draw()
Definition sprite.cpp:126
int started
Definition sprite.hpp:10
CSprite()
Definition sprite.cpp:41