-
Notifications
You must be signed in to change notification settings - Fork 0
/
alletest.lpr
176 lines (145 loc) · 7.39 KB
/
alletest.lpr
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
program alletest;
{
If I ever find out that my next game intended on sale won't end up on TPB on
release day, I'll be seriously offended. Then I'll go, login into my TPB account
and upload torrent of it myself and seed until it has at least 5 seeders except
me. Oh, I'll also announce that on my twitter account @qvear. I don't care if
my sales will drop because of it. I care about players.
Yarr!
- Dariusz "Darkhog" G. Jagielski
}
{$mode objfpc}{$H+}
{$apptype gui}
{$R allegro.res}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes, allegro, sprites, PerlinNoiseUnit, WorldGen, boolUtils,
Tilesets, ChunkUtils, Globals, states, GameObjects, GameStateUnit, Crt;
var lasted,chunklasted,x,y,chunkx:Integer;
TicksInQueue:Integer;
pause:boolean;
WorldGenerator:TWorldGenerator;
Tileset:TTileset;
NeedRefresh:Boolean;
const pausedelay=10;
procedure draw();
begin
{//clearing buffer
al_clear_to_color(buffer,al_makeacol_depth(al_desktop_color_depth,255,255,255,255));
//drawing text
al_textout_centre_ex(buffer,MarioFont,'Press space to generate new chunk',320,25,al_makecol(0,0,0),-1);
al_textout_centre_ex(buffer,MarioFont,'Press Q to quit',320,45,al_makecol(0,0,0),-1);
//comment this line and uncomment next for a (nasty) surprise
//al_masked_blit(perlin,buffer,0,0,300,200,100,100);
al_masked_stretch_blit(perlin,buffer,0,0,18,18,0,0,18*2,18*2);
//al_stretch_sprite(buffer,perlin,0,0,perlin^.w*2,perlin^.h*2);
Chunk.Draw(buffer,0,16*4,Tileset,4,true);
//showing counter animation
//if pause, put indicator of it
if pause then al_textout_centre_ex(buffer,al_font,'Pause',400,580,al_makeacol_depth(al_desktop_color_depth,255,0,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
al_blit(buffer,al_screen,0,0,0,0,800,600); }
end;
{function generate_pixel(x,y:Integer):Integer;
var ChunkDatasize:integer;
begin
ChunkDatasize:=Length(Chunk.Data);
if ((Between(x,-1,ChunkDatasize)) and ((Between(y,-1,ChunkDatasize)))) then begin
if Chunk.Data[x][y]=GROUNDID then result:= al_makecol(117,58,15)
else if Chunk.Data[x][y]=INVINCIBLEBLOCKID then result:=al_makecol(134,197,16)
else if Chunk.Data[x][y]=SPIKEID then result:=al_makecol(255,0,0)
else if Chunk.Data[x][y]=BLOCKID then result:=al_makecol(0,0,255)
else result:=al_makecol(255,0,255);
end;
end; }
procedure update_keyboard();
begin
Dec(lasted);
dec(chunklasted);
if (al_keyboard_needs_poll) then al_poll_keyboard;
if (al_key[AL_KEY_Q]<>0) then quit:=true;
if ((al_key[AL_KEY_P]<>0) and (lasted<=0)) then begin pause:=not pause; lasted:=pausedelay; end;
if not pause then begin
if ((al_key[AL_KEY_SPACE]<>0) and (chunklasted<=0)) then
begin
NeedRefresh:=true;
chunklasted:=pausedelay;
end;
end;
end;
procedure quitfunc();CDECL;
begin
quit:=true;
end;
procedure update();CDECL;
begin
//frame update
Inc(TicksInQueue);
//update_keyboard;
end;
{$R *.res}
begin
Randomize;
//initializing Allegro
if al_init then
begin
//setting up window
al_set_color_depth(al_desktop_color_depth);
al_set_gfx_mode(AL_GFX_AUTODETECT_WINDOWED,SCREENW,SCREENH,SCREENW,SCREENH);
al_set_window_title('Super Heli Land');
al_set_close_button_callback(@quitfunc);
//installing keyboard
al_textout_ex(al_screen,al_font,'Installing keyboard... ',0,0,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
al_install_keyboard;
al_textout_ex(al_screen,al_font,'OK',600,0,al_makeacol_depth(al_desktop_color_depth,0,255,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
//installing timers
al_textout_ex(al_screen,al_font,'Installing timers... ',0,20,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
al_install_timer;
al_textout_ex(al_screen,al_font,'OK',600,20,al_makeacol_depth(al_desktop_color_depth,0,255,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
//installing update timer
al_textout_ex(al_screen,al_font,'Initializing update routine... ',0,40,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
al_install_int_ex(@Update,AL_BPS_TO_TIMER(60));
al_textout_ex(al_screen,al_font,'OK',600,40,al_makeacol_depth(al_desktop_color_depth,0,255,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
//loading settings
al_textout_ex(al_screen,al_font,'Installing sound... ',0,60,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
al_install_sound(AL_DIGI_AUTODETECT,AL_MIDI_AUTODETECT);
al_textout_ex(al_screen,al_font,'OK',600,60,al_makeacol_depth(al_desktop_color_depth,0,255,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
al_textout_ex(al_screen,al_font,'Loading settings... ',0,80,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
LoadOptions('game.opt');
al_textout_ex(al_screen,al_font,'OK',600,80,al_makeacol_depth(al_desktop_color_depth,0,255,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
al_textout_ex(al_screen,al_font,'Loading font... ',0,100,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
MarioFont:=al_load_font('marioland.pcx',nil,nil);
al_textout_ex(al_screen,al_font,'OK',600,100,al_makeacol_depth(al_desktop_color_depth,0,255,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
//loading marioland font
al_textout_ex(al_screen,al_font,'Creating states... ',0,120,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
MainMenuState:=TMainMenuState.Create;
DebugState:=TDebugState.Create;
OptionsState:=TOptionsState.Create;
CurrentState:=MainMenuState;
al_textout_ex(al_screen,al_font,'OK',600,120,al_makeacol_depth(al_desktop_color_depth,0,255,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
//making buffer so screen won't blink
al_textout_ex(al_screen,al_font,'Creating frame buffer... ',0,140,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
buffer:=al_create_bitmap_ex(al_desktop_color_depth,SCREENW,SCREENH);
al_textout_ex(al_screen,al_font,'OK',600,140,al_makeacol_depth(al_desktop_color_depth,0,255,0,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
al_textout_ex(al_screen,al_font,'Starting main loop... ',0,160,al_makeacol_depth(al_desktop_color_depth,128,128,128,255),al_makeacol_depth(al_desktop_color_depth,0,0,0,255));
//main loop
repeat
while TicksInQueue>0 do
begin
if ((CurrentState<>nil) and (not quit)) then CurrentState.Update;
Dec(TicksInQueue);
end;
if not quit then CurrentState.BeforeDraw;
if not quit then CurrentState.Draw;
if not quit then CurrentState.Main;
until quit;
SaveOptions('game.opt');
al_destroy_font(MarioFont);
CurrentState:=nil;
MainMenuState.Free;
OptionsState.Free;
Debugstate.Free;
al_destroy_bitmap(buffer);
end;
end.