Skip to content

Commit

Permalink
crash
Browse files Browse the repository at this point in the history
  • Loading branch information
sechshelme committed Jan 29, 2023
1 parent 8e1ba56 commit a529d49
Show file tree
Hide file tree
Showing 13 changed files with 751 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lazyfoo.net/24_-_Calculating_Frame_Rate/Project1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
end;

timeText := '';
WriteStr(timeText, 'Average Frames Per Second ', avgFPS:10:2);
WriteStr(timeText, 'Average Frames Per Second ', avgFPS: 10: 2);
if not gFPSTextTexture.LoadFromRenderedText(gFont, timeText, textColor) then begin
WriteLn('Unable to render FPS texture !');
end;
Expand Down
6 changes: 2 additions & 4 deletions lazyfoo.net/26_-_Motion/Project1.pas
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
capTimer, fpsTimer: TLTimer;
myDot: Tdot;

timeText: string;
avgFPS: single;
frameTicks: uint32;

function init: boolean;
Expand Down Expand Up @@ -73,7 +71,7 @@
var
sucess: boolean = True;
begin
gDotTexture.LoadFromFile('dot.bmp');
gDotTexture.LoadFromFile('dot.bmp', $FF, $FF, $FF);
if gDotTexture = nil then begin
WriteLn('Failed to load dot texture! SDL_ttf Error: ');
sucess := False;
Expand Down Expand Up @@ -125,7 +123,7 @@

myDot.move;

SDL_SetRenderDrawColor(gRenderer, $FF, $FF, $FF, $FF);
SDL_SetRenderDrawColor(gRenderer, $00, $9F, $00, $FF);
SDL_RenderClear(gRenderer);

myDot.render(gDotTexture);
Expand Down
5 changes: 2 additions & 3 deletions lazyfoo.net/26_-_Motion/dot.pas
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ interface
Tdot = class(TObject)
private
widht, Height, mPosX, mPosY, mVelX, mVelY: integer;

public
const
DOT_WIDTH = 20;
DOT_HEIGHT = 20;
DOT_VEL = 10;
constructor Create(Awidht, Aheigth: integer);
procedure HandleEvent(e: TSDL_Event);
procedure HandleEvent(var e: TSDL_Event);
procedure move;
procedure render(tex: TLTexture);
end;
Expand All @@ -39,7 +38,7 @@ constructor Tdot.Create(Awidht, Aheigth: integer);
Height := Aheigth;
end;

procedure Tdot.HandleEvent(e: TSDL_Event);
procedure Tdot.HandleEvent(var e: TSDL_Event);
begin
case e.type_ of
SDL_KEYDOWN: begin
Expand Down
76 changes: 76 additions & 0 deletions lazyfoo.net/27_-_Collision_Detection/Project1.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="Project1"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="SDL2_Package"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="Project1.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="ltexture.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="LTexture"/>
</Unit>
<Unit>
<Filename Value="dot.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="Project1"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../units"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>
145 changes: 145 additions & 0 deletions lazyfoo.net/27_-_Collision_Detection/Project1.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
program Project1;

// https://github.com/PascalGameDevelopment/SDL2-for-Pascal

uses
sdl2,
sdl2_image,
ctypes,
LTexture,
LTimer,
dot;

const
Screen_Widht = 640;
Screen_Height = 480;
Screen_FPS = 60;
Screen_Tick_Per_Frame = 1000 div Screen_FPS;

var
gWindow: PSDL_Window;
gRenderer: PSDL_Renderer;

quit: boolean = False;
e: TSDL_Event;

gDotTexture: TLTexture;
capTimer, fpsTimer: TLTimer;
myDot: Tdot;

frameTicks: uint32;
wall:TSDL_Rect = (x: 300; y: 40; w: 40; h: 400);

function init: boolean;
var
sucess: boolean = True;
imgFlags: cint32 = 0;
begin
sucess := True;
if SDL_Init(SDL_INIT_VIDEO) < 0 then begin
WriteLn('SDL could not initialize! SDL_Error: ', SDL_GetError);
sucess := False;
end else begin
gWindow := SDL_CreateWindow('SDL Tuorial', SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Screen_Widht, Screen_Height, SDL_WINDOW_SHOWN);
if gWindow = nil then begin
WriteLn('Window could not be created! SDL_Error: ', SDL_GetError);
sucess := False;
end else begin
gRenderer := SDL_CreateRenderer(gWindow, -1, SDL_RENDERER_ACCELERATED);
if gRenderer = nil then begin
WriteLn('Renderer could not be created! SDL Error: ', SDL_GetError);
sucess := False;
end else begin
SDL_SetRenderDrawColor(gRenderer, $FF, $FF, $FF, $FF);

if (IMG_Init(imgFlags) and imgFlags) <> 0 then begin
WriteLn('SDL_image could not initialize! SDL_image Error: ', IMG_GetError);
sucess := False;
end;

end;
end;
end;
Result := sucess;

gDotTexture := TLTexture.Create(gRenderer);
fpsTimer := TLTimer.Create;
capTimer := TLTimer.Create;
myDot := Tdot.Create(Screen_Widht, Screen_Height);
end;

function loadMedia: boolean;
var
sucess: boolean = True;
begin
gDotTexture.LoadFromFile('dot.bmp',$FF,$FF,$FF);
if gDotTexture = nil then begin
WriteLn('Failed to load dot texture! SDL_ttf Error: ');
sucess := False;
end;

Result := sucess;
end;

procedure Close;
begin
gDotTexture.Free;
fpsTimer.Free;
capTimer.Free;
myDot.Free;

SDL_DestroyRenderer(gRenderer);
SDL_DestroyWindow(gWindow);
gWindow := nil;
gRenderer := nil;

IMG_Quit;
SDL_Quit;
end;

begin
if not init then begin
WriteLn('Failed to initialize');
end else begin
if not loadMedia then begin
WriteLn('Failed to load media');
end else begin
fpsTimer.start;
while not quit do begin
while SDL_PollEvent(@e) <> 0 do begin
case e.type_ of
SDL_KEYDOWN: begin
case e.key.keysym.sym of
SDLK_ESCAPE: begin
quit := True;
end;
end;
end;
SDL_QUITEV: begin
quit := True;
end;
end;
myDot.HandleEvent(e);
end;

myDot.move(wall);

SDL_SetRenderDrawColor(gRenderer, $00, $80, $00, $FF);
SDL_RenderClear(gRenderer);

SDL_SetRenderDrawColor(gRenderer, $80, $40, $00, $FF);
SDL_RenderFillRect(gRenderer, @wall);

myDot.render(gDotTexture);

SDL_RenderPresent(gRenderer);

frameTicks := capTimer.getTicks;
if frameTicks < Screen_Tick_Per_Frame then begin
SDL_Delay(Screen_Tick_Per_Frame - frameTicks);
end;
end;
end;
end;
Close;
end.
Binary file added lazyfoo.net/27_-_Collision_Detection/dot.bmp
Binary file not shown.
Loading

0 comments on commit a529d49

Please sign in to comment.