Skip to content

Commit

Permalink
add: lazarus core/samples
Browse files Browse the repository at this point in the history
  • Loading branch information
turborium committed Dec 23, 2022
1 parent 1b683ca commit 4608046
Show file tree
Hide file tree
Showing 107 changed files with 3,277 additions and 3,161 deletions.
8 changes: 4 additions & 4 deletions examples/core/Core.groupproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<Projects Include="core_2d_camera\core_2d_camera.dproj">
<Dependencies/>
</Projects>
<Projects Include="core_2d_camera_mose_zoom\core_2d_camera_mouse_zoom.dproj">
<Projects Include="core_2d_camera_mouse_zoom\core_2d_camera_mouse_zoom.dproj">
<Dependencies/>
</Projects>
<Projects Include="core_2d_camera_platformer\core_2d_camera_platformer.dproj">
Expand Down Expand Up @@ -132,13 +132,13 @@
<MSBuild Projects="core_2d_camera\core_2d_camera.dproj" Targets="Make"/>
</Target>
<Target Name="core_2d_camera_mouse_zoom">
<MSBuild Projects="core_2d_camera_mose_zoom\core_2d_camera_mouse_zoom.dproj"/>
<MSBuild Projects="core_2d_camera_mouse_zoom\core_2d_camera_mouse_zoom.dproj"/>
</Target>
<Target Name="core_2d_camera_mouse_zoom:Clean">
<MSBuild Projects="core_2d_camera_mose_zoom\core_2d_camera_mouse_zoom.dproj" Targets="Clean"/>
<MSBuild Projects="core_2d_camera_mouse_zoom\core_2d_camera_mouse_zoom.dproj" Targets="Clean"/>
</Target>
<Target Name="core_2d_camera_mouse_zoom:Make">
<MSBuild Projects="core_2d_camera_mose_zoom\core_2d_camera_mouse_zoom.dproj" Targets="Make"/>
<MSBuild Projects="core_2d_camera_mouse_zoom\core_2d_camera_mouse_zoom.dproj" Targets="Make"/>
</Target>
<Target Name="core_2d_camera_platformer">
<MSBuild Projects="core_2d_camera_platformer\core_2d_camera_platformer.dproj"/>
Expand Down
92 changes: 92 additions & 0 deletions examples/core/core_2d_camera/backup/core_2d_camera.lpi
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?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="core_2d_camera"/>
<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>
<Units>
<Unit>
<Filename Value="core_2d_camera.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="core_2d_camera_src.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="../../../raylib/raylib.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="../../../raylib/raymath.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="../../../raylib/rlgl.pas"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../../../raylib"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Conditionals Value="// libs
if TargetOS = &apos;darwin&apos; then
begin
LinkerOptions += &apos; ../../output/osx/libraylib.420.dylib -rpath @executable_path/&apos;;
OutputDir := &apos;../../output/osx/&apos;;
end;
if TargetOS = &apos;win64&apos; then
begin
OutputDir := &apos;../../output/win64/&apos;;
end;
if TargetOS = &apos;win32&apos; then
begin
OutputDir := &apos;../../output/win32/&apos;;
end;"/>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2Set"/>
</Debugging>
<Options>
<PassLinkerOptions Value="True"/>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>
157 changes: 4 additions & 153 deletions examples/core/core_2d_camera/core_2d_camera.dpr
Original file line number Diff line number Diff line change
@@ -1,163 +1,15 @@
(*******************************************************************************************
*
* raylib [core] example - 2d camera
*
* Example originally created with raylib 1.5, last time updated with raylib 3.0
*
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
* BSD-like license that allows static linking with closed source software
*
* Copyright (c) 2016-2022 Ramon Santamaria (@raysan5)
*
********************************************************************************************)
program core_2d_camera;

{$IFDEF FPC}{$MODE DELPHIUNICODE}{$ENDIF}
{$APPTYPE CONSOLE}

{$R *.res}

uses
SysUtils,
raylib in '..\..\..\raylib\raylib.pas';

const
MAX_BUILDINGS = 100;

//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
procedure Main();
const
ScreenWidth = 800;
ScreenHeight = 450;
var
Player: TRectangle;
Camera: TCamera2D;
Buildings: array [0..MAX_BUILDINGS - 1] of TRectangle;
BuildColors: array [0..MAX_BUILDINGS - 1] of TColor;
Spacing: Integer;
I: Integer;

begin
// Initialization
//---------------------------------------------------------------------------------------------
SetConfigFlags(FLAG_WINDOW_HIGHDPI or FLAG_MSAA_4X_HINT);
InitWindow(ScreenWidth, ScreenHeight, UTF8String('raylib [core] example - 2d camera'));

Player := TRectangle.Create(400, 280, 40, 40);

Spacing := 0;

SetRandomSeed(9);
for I := 0 to MAX_BUILDINGS - 1 do
begin
Buildings[I].Width := GetRandomValue(50, 200);
Buildings[I].Height := GetRandomValue(100, 800);
Buildings[I].Y := ScreenHeight - 130.0 - Buildings[I].Height;
Buildings[I].X := -6000.0 + Spacing;

Spacing := Spacing + Trunc(Buildings[I].Width);

BuildColors[I] := TColor.Create(GetRandomValue(200, 240), GetRandomValue(200, 240), GetRandomValue(200, 250), 255);
end;

Camera := Default(TCamera2D);
Camera.Target := TVector2.Create(Player.X + 20.0, Player.Y + 20.0);
Camera.Offset := TVector2.Create(ScreenWidth / 2.0, ScreenHeight / 2.0);
Camera.Rotation := 0.0;
Camera.Zoom := 1.0;

SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//---------------------------------------------------------------------------------------------

// Main game loop
while not WindowShouldClose() do // Detect window close button or ESC key
begin
// Update
//-------------------------------------------------------------------------------------------
// Player movement
if IsKeyDown(KEY_RIGHT) then
Player.X := Player.X + 2
else if IsKeyDown(KEY_LEFT) then
Player.X := Player.X - 2;

// Camera target follows player
Camera.Target := TVector2.Create(Player.X + 20, Player.Y + 20);

// Camera rotation controls
if IsKeyDown(KEY_A) then
Camera.Rotation := Camera.Rotation - 1
else if IsKeyDown(KEY_S) then
Camera.Rotation := Camera.Rotation + 1;

// Limit camera rotation to 80 degrees (-40 to 40)
if Camera.Rotation > 40 then
Camera.Rotation := 40
else if Camera.Rotation < -40 then
Camera.Rotation := -40;

// Camera zoom controls
Camera.Zoom := Camera.Zoom + (GetMouseWheelMove() * 0.05);

if Camera.Zoom > 3.0 then
Camera.Zoom := 3.0
else if Camera.Zoom < 0.05 then
Camera.Zoom := 0.05;

// Camera reset (zoom and rotation)
if IsKeyPressed(KEY_R) then
begin
Camera.Zoom := 1.0;
Camera.Rotation := 0.0;
end;
//-------------------------------------------------------------------------------------------

// Draw
//-------------------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

BeginMode2D(Camera);

DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY);

for I := 0 to MAX_BUILDINGS - 1 do
DrawRectangleRec(Buildings[I], BuildColors[I]);

DrawRectangleRec(Player, RED);

DrawLine(Trunc(Camera.Target.X), -ScreenHeight * 10, Trunc(Camera.Target.X), ScreenHeight * 10, GREEN);
DrawLine(-ScreenWidth * 10, Trunc(Camera.Target.Y), ScreenWidth * 10, Trunc(Camera.Target.Y), GREEN);

EndMode2D();

DrawText(UTF8String('SCREEN AREA'), 640, 10, 20, RED);

DrawRectangle(0, 0, ScreenWidth, 5, RED);
DrawRectangle(0, 5, 5, ScreenHeight - 10, RED);
DrawRectangle(ScreenWidth - 5, 5, 5, ScreenHeight - 10, RED);
DrawRectangle(0, ScreenHeight - 5, ScreenWidth, 5, RED);

DrawRectangle(10, 10, 250, 113, Fade(SKYBLUE, 0.5));
DrawRectangleLines(10, 10, 250, 113, BLUE);

DrawText(UTF8String('Free 2d camera controls:'), 20, 20, 10, BLACK);
DrawText(UTF8String('- Right/Left to move Offset'), 40, 40, 10, DARKGRAY);
DrawText(UTF8String('- Mouse Wheel to Zoom in-out'), 40, 60, 10, DARKGRAY);
DrawText(UTF8String('- A / S to Rotate'), 40, 80, 10, DARKGRAY);
DrawText(UTF8String('- R to reset Zoom and Rotation'), 40, 100, 10, DARKGRAY);

EndDrawing();
//-------------------------------------------------------------------------------------------
end;

// De-Initialization
//---------------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//---------------------------------------------------------------------------------------------
end;
raylib in '..\..\..\raylib\raylib.pas',
raymath in '..\..\..\raylib\raymath.pas',
rlgl in '..\..\..\raylib\rlgl.pas',
core_2d_camera_src in 'core_2d_camera_src.pas';

begin
try
Expand All @@ -167,4 +19,3 @@ begin
Writeln(E.ClassName, ': ', E.Message);
end;
end.

7 changes: 5 additions & 2 deletions examples/core/core_2d_camera/core_2d_camera.dproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Base>True</Base>
<AppType>Console</AppType>
<Config Condition="'$(Config)'==''">Debug</Config>
<FrameworkType>None</FrameworkType>
<MainSource>core_2d_camera.dpr</MainSource>
<Platform Condition="'$(Platform)'==''">Win32</Platform>
<ProjectGuid>{F3AF60F8-DA40-4963-A924-D39864AC97DC}</ProjectGuid>
<ProjectGuid>{F3AF60F8-DA40-4963-B747-000000000001}</ProjectGuid>
<ProjectVersion>19.4</ProjectVersion>
<TargetedPlatforms>3</TargetedPlatforms>
</PropertyGroup>
Expand Down Expand Up @@ -92,6 +92,9 @@
<MainSource>MainSource</MainSource>
</DelphiCompile>
<DCCReference Include="..\..\..\raylib\raylib.pas"/>
<DCCReference Include="..\..\..\raylib\raymath.pas"/>
<DCCReference Include="..\..\..\raylib\rlgl.pas"/>
<DCCReference Include="core_2d_camera_src.pas"/>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
Expand Down
Loading

0 comments on commit 4608046

Please sign in to comment.