-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e1ba56
commit a529d49
Showing
13 changed files
with
751 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Oops, something went wrong.