| 20 |
|
|
| 21 |
TDirs = set of TDir; |
TDirs = set of TDir; |
| 22 |
|
|
| 23 |
TChar = class(TObject) |
TBeem = class(TObject) |
| 24 |
private |
private |
| 25 |
FX: integer; |
FX: integer; |
| 26 |
FY: integer; |
FY: integer; |
| 27 |
FDir: TDirs; |
FSpeed: integer; |
| 28 |
public |
public |
| 29 |
constructor Create; |
constructor Create; |
| 30 |
property X: integer read FX write FX; |
property X: integer read FX write FX; |
| 31 |
property Y: integer read FY write FY; |
property Y: integer read FY write FY; |
| 32 |
|
property Speed: integer read FSpeed write FSpeed; |
| 33 |
|
end; |
| 34 |
|
|
| 35 |
|
TChar = class(TBeem) |
| 36 |
|
private |
| 37 |
|
FDir: TDirs; |
| 38 |
|
procedure Clear; |
| 39 |
|
public |
| 40 |
|
constructor Create; |
| 41 |
property Dir: TDirs read FDir write FDir; |
property Dir: TDirs read FDir write FDir; |
| 42 |
end; |
end; |
| 43 |
|
|
| 69 |
property Visible: Boolean read FVisible write FVisible; |
property Visible: Boolean read FVisible write FVisible; |
| 70 |
end; |
end; |
| 71 |
|
|
| 72 |
|
TAtack = record |
| 73 |
|
Interval: integer; |
| 74 |
|
Count: integer; |
| 75 |
|
end; |
| 76 |
|
|
| 77 |
TForm1 = class(TForm) |
TForm1 = class(TForm) |
| 78 |
PaintBox1: TPaintBox; |
PaintBox1: TPaintBox; |
| 79 |
Image1: TImage; |
Image1: TImage; |
| 94 |
Length: integer; |
Length: integer; |
| 95 |
Enemy: integer; |
Enemy: integer; |
| 96 |
List: TList; |
List: TList; |
| 97 |
|
Beem: Boolean; |
| 98 |
|
Atack: TList; |
| 99 |
|
Count: integer; |
| 100 |
|
function CheckCross: Boolean; |
| 101 |
|
procedure GameOver; |
| 102 |
end; |
end; |
| 103 |
|
|
| 104 |
var |
var |
| 105 |
Form1: TForm1; |
Form1: TForm1; |
| 106 |
Char1: TChar; |
Char1: TChar; |
| 107 |
|
Param: TAtack = (Interval: 0; Count: 5); |
| 108 |
|
|
| 109 |
implementation |
implementation |
| 110 |
|
|
| 213 |
Clear; |
Clear; |
| 214 |
end; |
end; |
| 215 |
|
|
| 216 |
|
function TForm1.CheckCross: Boolean; |
| 217 |
|
var |
| 218 |
|
s: TEnemy; |
| 219 |
|
t: TBeem; |
| 220 |
|
i, j: integer; |
| 221 |
|
begin |
| 222 |
|
for i := List.Count - 1 downto 0 do |
| 223 |
|
begin |
| 224 |
|
s := List[i]; |
| 225 |
|
if (Char1.X < s.X + Size) and (Char1.X + Size > s.X) and |
| 226 |
|
(Char1.Y < s.Y + Size) and (Char1.Y + Size > s.Y) then |
| 227 |
|
begin |
| 228 |
|
result := true; |
| 229 |
|
List.Delete(i); |
| 230 |
|
s.Free; |
| 231 |
|
Char1.Clear; |
| 232 |
|
end; |
| 233 |
|
end; |
| 234 |
|
for i := Atack.Count - 1 downto 0 do |
| 235 |
|
begin |
| 236 |
|
t := Atack[i]; |
| 237 |
|
for j := List.Count - 1 downto 0 do |
| 238 |
|
begin |
| 239 |
|
s := List[j]; |
| 240 |
|
if (t.X < s.X + Size) and (t.X + Size > s.X) and (t.Y < s.Y + Size) and |
| 241 |
|
(t.Y + Size > s.Y) then |
| 242 |
|
begin |
| 243 |
|
Atack.Delete(i); |
| 244 |
|
t.Free; |
| 245 |
|
List.Delete(j); |
| 246 |
|
s.Free; |
| 247 |
|
break; |
| 248 |
|
end; |
| 249 |
|
end; |
| 250 |
|
end; |
| 251 |
|
end; |
| 252 |
|
|
| 253 |
procedure TForm1.FormCreate(Sender: TObject); |
procedure TForm1.FormCreate(Sender: TObject); |
| 254 |
begin |
begin |
| 255 |
Char1 := TChar.Create; |
Char1 := TChar.Create; |
| 256 |
List := TList.Create; |
List := TList.Create; |
| 257 |
|
Atack := TList.Create; |
| 258 |
ClientWidth := Wid * Size; |
ClientWidth := Wid * Size; |
| 259 |
ClientHeight := Hei * Size; |
ClientHeight := Hei * Size; |
| 260 |
Enemy := 10; |
Enemy := 10; |
| 261 |
|
Count := 5; |
| 262 |
end; |
end; |
| 263 |
|
|
| 264 |
procedure TForm1.FormDestroy(Sender: TObject); |
procedure TForm1.FormDestroy(Sender: TObject); |
| 265 |
var |
var |
| 266 |
s: TEnemy; |
s: TEnemy; |
| 267 |
|
t: TChar; |
| 268 |
i: integer; |
i: integer; |
| 269 |
begin |
begin |
| 270 |
for i := 0 to List.Count - 1 do |
for i := 0 to List.Count - 1 do |
| 272 |
s := List[i]; |
s := List[i]; |
| 273 |
s.Free; |
s.Free; |
| 274 |
end; |
end; |
| 275 |
|
for i := 0 to Atack.Count - 1 do |
| 276 |
|
begin |
| 277 |
|
t := Atack[i]; |
| 278 |
|
end; |
| 279 |
List.Free; |
List.Free; |
| 280 |
|
Atack.Free; |
| 281 |
end; |
end; |
| 282 |
|
|
| 283 |
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; |
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; |
| 284 |
Shift: TShiftState); |
Shift: TShiftState); |
| 285 |
begin |
begin |
| 286 |
case KeyChar of |
case KeyChar of |
| 287 |
|
'q': |
| 288 |
|
Beem := true; |
| 289 |
'a': |
'a': |
| 290 |
Char1.Dir := Char1.Dir + [TDir.Left]; |
Char1.Dir := Char1.Dir + [TDir.Left]; |
| 291 |
'd': |
'd': |
| 301 |
Shift: TShiftState); |
Shift: TShiftState); |
| 302 |
begin |
begin |
| 303 |
case KeyChar of |
case KeyChar of |
| 304 |
|
'q': |
| 305 |
|
Beem := false; |
| 306 |
'a': |
'a': |
| 307 |
Char1.Dir := Char1.Dir - [TDir.Left]; |
Char1.Dir := Char1.Dir - [TDir.Left]; |
| 308 |
'd': |
'd': |
| 314 |
end; |
end; |
| 315 |
end; |
end; |
| 316 |
|
|
| 317 |
|
procedure TForm1.GameOver; |
| 318 |
|
begin |
| 319 |
|
dec(Count); |
| 320 |
|
if Count = 0 then |
| 321 |
|
Timer1.Enabled := false; |
| 322 |
|
end; |
| 323 |
|
|
| 324 |
procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas); |
procedure TForm1.PaintBox1Paint(Sender: TObject; Canvas: TCanvas); |
| 325 |
var |
var |
| 326 |
s: TEnemy; |
s: TEnemy; |
| 327 |
|
t: TBeem; |
| 328 |
i: integer; |
i: integer; |
| 329 |
begin |
begin |
| 330 |
Canvas.DrawBitmap(Image1.Bitmap, RectF(0, 0, Image1.Bitmap.Width, |
Canvas.DrawBitmap(Image1.Bitmap, RectF(0, 0, Image1.Bitmap.Width, |
| 337 |
Canvas.DrawBitmap(Image2.Bitmap, RectF(Size, 0, 2 * Size, Size), |
Canvas.DrawBitmap(Image2.Bitmap, RectF(Size, 0, 2 * Size, Size), |
| 338 |
RectF(s.X, s.Y, s.X + Size, s.Y + Size), 1); |
RectF(s.X, s.Y, s.X + Size, s.Y + Size), 1); |
| 339 |
end; |
end; |
| 340 |
|
for i := 0 to Atack.Count - 1 do |
| 341 |
|
begin |
| 342 |
|
t := Atack[i]; |
| 343 |
|
Canvas.DrawBitmap(Image2.Bitmap, RectF(2 * Size, 0, 3 * Size, Size), |
| 344 |
|
RectF(t.X, t.Y, t.X + Size, t.Y + Size), 1); |
| 345 |
|
end; |
| 346 |
Canvas.DrawBitmap(Image2.Bitmap, RectF(0, 0, Size, Size), |
Canvas.DrawBitmap(Image2.Bitmap, RectF(0, 0, Size, Size), |
| 347 |
RectF(Char1.X, Char1.Y, Char1.X + Size, Char1.Y + Size), 1); |
RectF(Char1.X, Char1.Y, Char1.X + Size, Char1.Y + Size), 1); |
| 348 |
end; |
end; |
| 351 |
var |
var |
| 352 |
i: integer; |
i: integer; |
| 353 |
s: TEnemy; |
s: TEnemy; |
| 354 |
|
t: TBeem; |
| 355 |
X: Boolean; |
X: Boolean; |
| 356 |
begin |
begin |
| 357 |
X := false; |
X := false; |
| 358 |
if Length < Image1.Bitmap.Height - Hei * Size then |
if Length <= Image1.Bitmap.Height - Hei * Size then |
| 359 |
begin |
begin |
| 360 |
inc(Length); |
inc(Length); |
| 361 |
if Length >= Enemy then |
if Length >= Enemy then |
| 374 |
end; |
end; |
| 375 |
end; |
end; |
| 376 |
end; |
end; |
| 377 |
end; |
end |
| 378 |
|
else |
| 379 |
|
Length := 0; |
| 380 |
for i := 0 to List.Count - 1 do |
for i := 0 to List.Count - 1 do |
| 381 |
begin |
begin |
| 382 |
s := List[i]; |
s := List[i]; |
| 410 |
Char1.Y := Char1.Y - 1; |
Char1.Y := Char1.Y - 1; |
| 411 |
if Down in Char1.Dir then |
if Down in Char1.Dir then |
| 412 |
Char1.Y := Char1.Y + 1; |
Char1.Y := Char1.Y + 1; |
| 413 |
|
for i := Atack.Count - 1 downto 0 do |
| 414 |
|
begin |
| 415 |
|
t := Atack[i]; |
| 416 |
|
t.Y := t.Y - t.Speed; |
| 417 |
|
if (t.Y + Size) < 0 then |
| 418 |
|
begin |
| 419 |
|
Atack.Delete(i); |
| 420 |
|
t.Free; |
| 421 |
|
end; |
| 422 |
|
end; |
| 423 |
|
if Beem = true then |
| 424 |
|
if (Param.Interval = 0) and (Atack.Count < Param.Count) then |
| 425 |
|
begin |
| 426 |
|
Atack.Add(TBeem.Create); |
| 427 |
|
Param.Interval := 10; |
| 428 |
|
end; |
| 429 |
|
if Param.Interval > 0 then |
| 430 |
|
dec(Param.Interval); |
| 431 |
PaintBox1.Repaint; |
PaintBox1.Repaint; |
| 432 |
|
if CheckCross = true then |
| 433 |
|
GameOver; |
| 434 |
end; |
end; |
| 435 |
|
|
| 436 |
function TEnemy.HardSearch: Boolean; |
function TEnemy.HardSearch: Boolean; |
| 438 |
i, j: integer; |
i, j: integer; |
| 439 |
begin |
begin |
| 440 |
inc(FIndex); |
inc(FIndex); |
| 441 |
result:=false; |
result := false; |
| 442 |
for i := 0 to Wid - 1 do |
for i := 0 to Wid - 1 do |
| 443 |
for j := 0 to Hei - 1 do |
for j := 0 to Hei - 1 do |
| 444 |
if FFlightData[i, j] = Index then |
if FFlightData[i, j] = Index then |
| 476 |
AX := AX + 1; |
AX := AX + 1; |
| 477 |
AY := AY + 1; |
AY := AY + 1; |
| 478 |
end |
end |
| 479 |
else if HardSearch = false then |
else |
| 480 |
Clear; |
begin |
| 481 |
|
dec(FIndex); |
| 482 |
|
if HardSearch = false then |
| 483 |
|
Clear; |
| 484 |
|
end; |
| 485 |
end; |
end; |
| 486 |
|
|
| 487 |
{ TChar } |
{ TChar } |
| 488 |
|
|
| 489 |
constructor TChar.Create; |
procedure TChar.Clear; |
| 490 |
begin |
begin |
| 491 |
X := Wid * Size div 2; |
X := Wid * Size div 2; |
| 492 |
Y := (Hei - 1) * Size; |
Y := (Hei - 1) * Size; |
| 493 |
end; |
end; |
| 494 |
|
|
| 495 |
|
constructor TChar.Create; |
| 496 |
|
begin |
| 497 |
|
Clear; |
| 498 |
|
end; |
| 499 |
|
|
| 500 |
|
{ TBeem } |
| 501 |
|
|
| 502 |
|
constructor TBeem.Create; |
| 503 |
|
begin |
| 504 |
|
FX := Char1.X; |
| 505 |
|
FY := Char1.Y - Size; |
| 506 |
|
FSpeed := 8; |
| 507 |
|
end; |
| 508 |
|
|
| 509 |
end. |
end. |