-
Notifications
You must be signed in to change notification settings - Fork 1
/
items.h
157 lines (125 loc) · 5.2 KB
/
items.h
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include <vector>
using namespace std;
BITMAP *dis[4];
class items {
public:
// *** Bitmap & allegro assets for items
BITMAP *sprite[12]; // 12 frame animation
// *** Motion variables
double animFrames;
int s_x,s_y; // screen fix;
int x,y, _w, _h; // x,y, height, width
int cx1,cx2,cy1,cy2; // collision params
int b_x,b_y;
int maxFrame; // all enemies frames vary
int value;
int animFrame;
int typ;
bool alive;
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
items(){
// *** initial motion settings
alive = true;
animFrame = 0;
animFrames = 0;
b_x= s_x = 0;
b_y = s_y = 0;
dis[0] = load_bitmap ("assets/items/0/frame1.bmp",workpal);
dis[1] = load_bitmap ("assets/items/0/frame2.bmp",workpal);
dis[2] = load_bitmap ("assets/items/0/frame3.bmp",workpal);
dis[3] = load_bitmap ("assets/items/0/frame4.bmp",workpal);
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
bool loadSprites(int type,int _x,int _y){
typ=type;
maxFrame = 4;
if (type == 1){
// loads Righ stances of sprite
sprite[0] = load_bitmap ("assets/items/1/frame1.bmp",workpal);
sprite[1] = load_bitmap ("assets/items/1/frame2.bmp",workpal);
sprite[2] = load_bitmap ("assets/items/1/frame3.bmp",workpal);
sprite[3] = load_bitmap ("assets/items/1/frame4.bmp",workpal);
x = _x;
y = _y;
}
if (type == 2){
// loads Righ stances of sprite
sprite[0] = load_bitmap ("assets/items/2/frame1.bmp",workpal);
sprite[1] = load_bitmap ("assets/items/2/frame2.bmp",workpal);
sprite[2] = load_bitmap ("assets/items/2/frame3.bmp",workpal);
sprite[3] = load_bitmap ("assets/items/2/frame4.bmp",workpal);
x = _x;
y = _y;
}
if (type == 3){
// loads Righ stances of sprite
sprite[0] = load_bitmap ("assets/items/3/frame1.bmp",workpal);
sprite[1] = load_bitmap ("assets/items/3/frame2.bmp",workpal);
sprite[2] = load_bitmap ("assets/items/3/frame3.bmp",workpal);
sprite[3] = load_bitmap ("assets/items/3/frame4.bmp",workpal);
x = _x;
y = _y;
}
if (type == 4){
// loads Righ stances of sprite
sprite[0] = load_bitmap ("assets/items/4/frame1.bmp",workpal);
sprite[1] = load_bitmap ("assets/items/4/frame2.bmp",workpal);
sprite[2] = load_bitmap ("assets/items/4/frame3.bmp",workpal);
sprite[3] = load_bitmap ("assets/items/4/frame4.bmp",workpal);
x = _x;
y = _y;
}
_w = sprite[0]->w; // height & width
_h = sprite[0]->h;
cx1=0; cx2=_w-1; cy1=0; cy2=_h-1;
}
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
void draw (BITMAP *bmp,int nx,int ny){
animFrames+=.05;
if (animFrames>20) animFrames = 0;
animFrame = ((int)animFrames)%maxFrame;
if (animFrame>6){
animFrame = 0;
}
masked_blit (sprite[animFrame],bmp,
0,0,x - nx,y-ny,
sprite[animFrame]->w,
sprite[animFrame]->h
);
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
vector<items> itemset;
vector<items>::iterator ii;
void load_items(char efile[]){
FILE *fp;
fp = fopen (efile,"r");
if (!fp){
allegro_exit();
cout << "Error opening level files\n";
system ("pause");
}
items en;
int type,x,y;
while ( (fscanf(fp,"%d%d%d",&type,&x,&y))!=EOF ){
en.loadSprites(type,x,y);
itemset.push_back (en);
}
fclose(fp);
}