-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFairy.cpp
More file actions
78 lines (71 loc) · 1.46 KB
/
Fairy.cpp
File metadata and controls
78 lines (71 loc) · 1.46 KB
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
#include "stdafx.h"
#include "Fairy.h"
#include "Level.h"
#include "Extras/utilities.h"
#include <cmath>
Fairy::Fairy(Level* l,float x_,float y_) : Actor(l,x_,y_,20,30) {
val=0;
dir=1;
central_y=y;
angle0=atan2((100+30.0),(470-30))+8*3.1415926535;
angle=angle0;
#ifndef COMPILE_NO_SF
texture=getGraphic("Fairy1");
fairy.setOrigin(width/2,height/2);
fairy.setScale(-1,1);
#endif
}
void Fairy::act() {
if (val==-1) {}
else if (val==0) {
if (fabs(y-central_y)>=30)
dir*=-1;
y+=dir*1;
}
else if (val==1) {
x+=3;
y = central_y-(x+width)*(x+width)/400;
fairy.setScale(-1,1);
if (getY2()<0) {
level->sendEvent(MISCE_2,this);
}
}
else if (val==2) {
y+=3;
fairy.setScale(-1,1);
if (getY1()>600)
level->sendEvent(KILL,this);
}
else if (val==3) {
angle-=3.1415926535/36;
float mag = sqrt(130*130+470*470.0)/angle0;
float r = mag*angle;
x = r*cos(angle)+500;
y = r*sin(angle)+100;
if (angle<0) {
central_y=y;
val=0;
}
fairy.setScale(1,1);
}
else {
std::cerr<<"FAIRY FAIL\n\n";
throw "DO NOT HAVE THIS CODE";
}
}
#ifndef COMPILE_NO_SF
void Fairy::render(sf::RenderWindow& window) {
fairy.setTexture(texture);
fairy.setPosition(getX1()+width,getY1()+height);
window.draw(fairy);
}
#endif
void Fairy::turnOn(int i) {
val=i;
y=central_y;
}
void Fairy::kill() {
val=-1;
texture=getGraphic("GrayFairy");
fairy.setRotation(-45);
}