This repository has been archived by the owner on Feb 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSTG.cpp
100 lines (88 loc) · 1.92 KB
/
STG.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "STG.h"
using STG::Bullet;
using STG::BulletCon;
using STG::MainCharactor;
using STG::Enemy;
//class STG::Bullet
void Bullet::setSpeed(ftVec2 v)
{
speed = v;
}
void Bullet::update()
{
float deltaT = fountain::getCurSceneDeltaT();
move(speed * deltaT);
}
void Bullet::draw()
{
ftVec2 pos = getPosition();
ftRender::transformBegin(pos.x, pos.y);
ftRender::useColor(color);
ftRender::drawCircle(3.0f);
ftRender::useColor(color);
ftRender::drawCircleEdge(5.0f);
ftRender::transformEnd();
}
void Bullet::setColor(ftColor c)
{
color = c;
}
//class STG::BulletCon
bool BulletCon::willLive(Bullet & b)
{
ftRender::Camera *cam = fountain::getCurSceneCamera();
if (cam != NULL) {
ftRect cr = cam->getCameraRect();
ftVec2 xy = cr.getCenter();
cr.inflate(2, 2);
cr.setCenter(xy);
return cr.collidePoint(b.getPosition());
}
return false;
}
//class STG::MainCharactor
void MainCharactor::init(ftTime::Clock *masterClock)
{
animeTest = ftRender::SubImagePool("resources/image/CommonAttack.png", "resources/image/CommonAttack.sip");
breath = ftAnime::FrameAnime(animeTest, 15.0f);
setCurAnime(&breath);
curAnime->setLoop(true);
speed = ftVec2(0.0, 0.0);
charClock = ftTime::Clock(masterClock);
charClock.init();
curAnime->setMasterClock(&charClock);
curAnime->play();
}
void MainCharactor::setCurAnime(ftAnime::FrameAnime *ca)
{
curAnime = ca;
}
void MainCharactor::attack()
{
Bullet b = Bullet();
b.setPosition(getPosition());
b.setSpeed(ftVec2(0.0, 2000.0));
b.setColor(ftColor("#533"));
bulletCon.add(b);
}
void MainCharactor::setSpeed(ftVec2 v)
{
speed = v;
}
void MainCharactor::update()
{
charClock.tick();
float deltaT = charClock.getDeltaT();
move(speed * deltaT);
bulletCon.update();
curAnime->update();
}
void MainCharactor::draw()
{
bulletCon.draw();
ftVec2 pos = getPosition();
ftRender::transformBegin(pos.x, pos.y);
ftRender::useColor(FT_White);
curAnime->draw();
ftRender::transformEnd();
}