This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.pas
113 lines (84 loc) · 2.38 KB
/
main.pas
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
unit main;
{$mode objfpc}{$H+}
interface
uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls, uplayground, ugamesignals, signal, utils;
type
{ TForm1 }
TForm1 = class(TForm)
Image1: TImage;
playground: oPlayground;
Timer1: TTimer;
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure redraw(si: oSignal);
procedure Tick(Sender: TObject);
procedure controls(si: oSignal);
private
{ private declarations }
autoanim: boolean;
_flipleft: boolean;
_flipright : boolean;
public
{ public declarations }
end;
var Form1: TForm1;
implementation
{$R *.lfm}
procedure TForm1.FormCreate(Sender: TObject);
var s: oSignal;
begin
verbosity(0);
autoanim := true;
_flipleft := false;
_flipright := false;
playground := oPlayground.create();
s := RedrawSignal.create(self);
playground.getDispatcher().bind(s, @self.redraw);
s.free();
s := NanoTickSignal.create(self, 0, 0);
playground.getDispatcher().bind(s, @self.controls);
s.free();
playground.redraw();
//playground.tick();
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
//playground.tick();
//autoanim := not autoanim;
d(12, 'form', 'key pressed: ' + s(key));
case key of
32: playground.plungPull();
37: _flipleft := true;
39: _flipright := true;
27: playground.getDispatcher().emit(DeathSignal.create(self));
56: playground.init();
end;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
case key of
32: playground.plungRelease();
37: _flipleft := false;
39: _flipright := false;
end;
end;
procedure TForm1.redraw(si: oSignal);
var sig: RedrawSignal;
begin
sig := si as RedrawSignal;
d(5, 'form', 'Updating image');
Image1.Canvas.FillRect(0, 0, 440, 490);
sig.bm.draw(Image1.Canvas, 0, 0, true);
end;
procedure TForm1.Tick(Sender: TObject);
begin
if autoanim then playground.tick();
end;
procedure TForm1.controls(si: oSignal);
begin
if _flipleft then playground.flipLeft();
if _flipright then playground.flipRight();
end;
end.