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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298 | TForm1 *Form1;
//------------------------------- Black Jump / Source C++ by lanky ---------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
bool Szukaj(char *path)
{
WIN32_FIND_DATA findData;
if (FindFirstFileA(path, &findData) != INVALID_HANDLE_VALUE) return true;
return false;
}
void reset()
{
Form1->Image2->Top = 360;
Form1->Image2->Left = 700;
Start = clock();
}
void ruch_enemy()
{
if (MAP[Obrazek[i]->Left+10][Obrazek[i]->Top+25] == 0 && ENEMY[i]) Obrazek[i]->Left += 2; else
{
ENEMY[i] = False;
if (MAP[Obrazek[i]->Left+10-3][Obrazek[i]->Top+21] == 0)
Obrazek[i]->Left -= 2; else ENEMY[i] = True;
}
}
void kolizja()
{
for (int i=1; i<=ILE; i++) // kolizja enemy
{
if (Obrazek[i]->Left >= Form1->Image2->Left+20 || Obrazek[i]->Left+20 <= Form1->Image2->Left
|| Obrazek[i]->Top >= Form1->Image2->Top+20 || Obrazek[i]->Top+20 <= Form1->Image2->Top);
else
reset();
}
if (X1 == 255 || X2 == 255 || Y1 == 255 || Y2 == 255) reset(); // kolizja playera
if (X1 == RGB(0,255,0) || X2 == RGB(0,255,0) || Y1 == RGB(0,255,0) || Y2 == RGB(0,255,0))
{
Form1->Timer1->Enabled = False;
Stop = clock();
Czas = ((double) (Stop - Start)) / CLOCKS_PER_SEC;
Finish_Czas += Czas;
Form1->Label2->Caption = Finish_Czas;
Form1->Caption = Czas;
Form1->Button1->Visible = True;
Form1->Button2->Visible = True;
Form1->Button1->Caption = "Next Level >>";
BMP->Free();
for (int i=1; i<= ILE; i++) Obrazek[i]->Free();
}
}
void TForm1::buduj(int x, int y)
{
ILE++;
Obrazek[ILE] = new TImage(this);
Obrazek[ILE]->Parent = Form1;
Obrazek[ILE]->Width =20;
Obrazek[ILE]->Height = 20;
Obrazek[ILE]->Top = y;
Obrazek[ILE]->Left = x;
Obrazek[ILE]->Picture->LoadFromFile("enemy.bmp");
while (TEMP[Obrazek[ILE]->Left][Obrazek[ILE]->Top] != 0) Obrazek[ILE]->Top +=1; // spadek enemy do podłogi
Obrazek[ILE]->Top -= 20; // i podwyzszenie enemy o jego wysokosc
ENEMY[ILE] = True; // gdy enemy true to zaczyna isc w prawo
}
void skasuj(int x, int y)
{
int oldy = y;
BMP->Canvas->Pixels[x][y] = RGB(255,255,255) ;
while (true)
{
if (GetPixel(BMP->Canvas->Handle,x,y+1) == RGB(0,0,255)) y++ ; else
if (GetPixel(BMP->Canvas->Handle,x+1,y) == RGB(0,0,255))
{
y = oldy;
x++ ;
} else break;
BMP->Canvas->Pixels[x][y] = RGB(255,255,255) ; // niebieski zalej bialym
}
GetPixel(BMP->Canvas->Handle,x,y);
}
void poza()
{
X1 = MAP[Form1->Image2->Left][Form1->Image2->Top];
X2 = MAP[Form1->Image2->Left+20][Form1->Image2->Top];
Y1 = MAP[Form1->Image2->Left][Form1->Image2->Top+20];
Y2 = MAP[Form1->Image2->Left+20][Form1->Image2->Top+20];
}
void spadek()
{
if (Y1 != 0 && Y2 != 0)
{
Form1->Image2->Top += 4;
SPAD = True;
} else SPAD = False;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Finish_Map = atoi(Edit2->Text.c_str());
if (Finish_Map < 1)
{
ShowMessage("Wpisz minimum 1");
LVL = 0;
return;
}
Form1->DoubleBuffered = True;
LVL++;
for (int i=1; i <= Finish_Map; i++)
{
char buffer[34];
itoa (i,buffer,10);
if (Szukaj(buffer));
else
{
string inf = "Nie znalazłem mapy: ";
stringstream ss;
ss << inf << buffer;
ShowMessage(ss.str().c_str());
LVL = 0;
return;
}
}
if (LVL > Finish_Map)
{
std::stringstream info;
info << "Koniec Gry. Twój wynik to: " << Finish_Czas;
//string omg = info.str();
//ShowMessage(omg.c_str());
ShowMessage(info.str().c_str());
ShowMessage("Black Jumper® by Legenda. |Upc@Poczta.fm|");
Application->Terminate();
return; // jak exit w delphi ;)
}
ILE = 0;
GO = 0;
BMP = new Graphics::TBitmap();
BMP->LoadFromFile(LVL);
Form1->Caption = "Black Jumper";
Form1->Label3->Caption = LVL;
GORA = False;
DOL = False;
PRAWY = False;
LEWY = False;
for(int x= 0; x<= 799; x++)
for(int y= 0; y<=499; y++)
TEMP[x][y] = GetPixel(BMP->Canvas->Handle,x,y);
for(int x= 0; x<= 799; x++)
for(int y= 0; y<=499; y++)
{
MAP[x][y] = GetPixel(BMP->Canvas->Handle,x,y);
if (MAP[x][y] == RGB(0,0,255)) // niebieski
{
skasuj(x,y);
buduj(x,y); // dynamic component image for enemy
}
}
Image1->Picture->Graphic = BMP;
Button1->Visible = False;
Button2->Visible = False;
Edit2->Visible = False;
reset();
//ShowMessage(ILE);
Timer1->Enabled = True;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
switch(Key)
{
case VK_UP : // strzalka w gore
if (SPAD == False) GORA = True;
break;
case VK_DOWN : // dol
DOL = True;
break;
case VK_RIGHT : // prawo
PRAWY = True;
break;
case VK_LEFT : //lewo
LEWY = True;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
switch(Key)
{
//case VK_UP : // strzalka w gore
//GORA = False;
//break;
case VK_DOWN : // dol
DOL = False;
break;
case VK_RIGHT : // prawo
PRAWY = False;
break;
case VK_LEFT : //lewo
LEWY = False;
break;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
//Image1->Canvas->Pen->Color = 250;
//Image1->Canvas->MoveTo(Obrazek[1]->Left+10,Obrazek[1]->Top-10);
//Image1->Canvas->LineTo(Obrazek[1]->Left+10,Obrazek[1]->Top+25);
ruch_enemy();
poza(); // x1,x2,y1,y2 bohatera
kolizja();
if (GORA)
{
Image2->Top += -4;
GO++ ;
if (GO >= 25)
{
GORA = False;
GO = 0;
}
}
if (GORA == False) spadek();
if (LEWY) Image2->Left += -2; else if (PRAWY) Image2->Left += 2;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Edit2KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
set<Word> licz; //deklaracja zbioru licz
for(int i=48; i<=57; i++) licz.insert(i);
if (licz.find(Key)== licz.end())
{
ShowMessage("Tylko liczby [1..100]");
String ok;
ok = Edit2->Text.c_str();
ok = ok.SetLength(ok.Length()-1);
Edit2->Text = ok.c_str();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
GroupBox1->Visible = False;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
ShowMessage("Mapy możesz zrobić w zwykłym Paintcie Windowsa");
GroupBox1->Visible = True;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
ShowMessage("Black Jumper® by lanky. |upc@poczta.fm|");
}
//---------------------------------------------------------------------------
|