Skip to content

Commit

Permalink
cycle de vie des cases opérationnel, changement couleur, évenements, …
Browse files Browse the repository at this point in the history
…changement d'images
  • Loading branch information
DeveloppeurPascal committed Jan 8, 2023
1 parent c77078f commit 6fe454b
Show file tree
Hide file tree
Showing 10 changed files with 7,559 additions and 27 deletions.
24 changes: 19 additions & 5 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,27 @@

* sur écran Credits, les liens fonctionnent-ils sur toutes les plateformes ?

* click on GameGrid : put actual color, move grid, get cell color
* choose color
* move screen during the game
* game loop (life cycle of colors on grid)

* save/restore a game

* assets license : "pause button svg" from https://materialdesignicons.com/icon/pause

* images "alert" sur les cases à récolter selon le cycle de vie de la case (nouvelle, à récolter, mourante)


* récolte des cases mures
* contamination
* déplacement du viewport
* zoom / dezoom

* centrer l'inventaire dans sa zone


0-soleil
1-poubelle recyclable => Dead
2-recyclage => Compost
3-pouce dans la main
4-jeune pouce => Planted
5-smiley bof => Rotten
6-arbre => Mature
7-panier
9-recyclage feuille
4 changes: 3 additions & 1 deletion src/Project1.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ uses
cButton in 'cButton.pas' {cadButton: TFrame},
FMX.DzHTMLText in '..\Libraries\DzHTMLText\FMX.DzHTMLText.pas',
uGameData in 'uGameData.pas',
cInventoryItem in 'cInventoryItem.pas' {cadInventoryItem: TFrame};
cInventoryItem in 'cInventoryItem.pas' {cadInventoryItem: TFrame},
udmLDJam52_Icones_AS303523361 in 'udmLDJam52_Icones_AS303523361.pas' {dmLDJam52_Icones_AS303523361: TDataModule};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TfrmMain, frmMain);
Application.CreateForm(TdmLDJam52_Icones_AS303523361, dmLDJam52_Icones_AS303523361);
Application.Run;
end.
5 changes: 5 additions & 0 deletions src/Project1.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,11 @@
<FormType>fmx</FormType>
<DesignClass>TFrame</DesignClass>
</DCCReference>
<DCCReference Include="udmLDJam52_Icones_AS303523361.pas">
<Form>dmLDJam52_Icones_AS303523361</Form>
<FormType>dfm</FormType>
<DesignClass>TDataModule</DesignClass>
</DCCReference>
<BuildConfiguration Include="Base">
<Key>Base</Key>
</BuildConfiguration>
Expand Down
6 changes: 4 additions & 2 deletions src/cInventoryItem.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ object cadInventoryItem: TcadInventoryItem
Margins.Left = 5.000000000000000000
Margins.Top = 5.000000000000000000
Margins.Bottom = 5.000000000000000000
Position.X = 5.000000000000000000
Position.Y = 5.000000000000000000
Size.Width = 320.000000000000000000
Size.Height = 0.000000000000000000
Size.Height = 284.000000000000000000
Size.PlatformDefault = False
OnClick = FrameClick
OnResize = FrameResize
Expand All @@ -13,7 +15,7 @@ object cadInventoryItem: TcadInventoryItem
Locked = True
HitTest = False
Size.Width = 320.000000000000000000
Size.Height = 0.000000000000000000
Size.Height = 284.000000000000000000
Size.PlatformDefault = False
end
object ItemCountBackground: TEllipse
Expand Down
2 changes: 1 addition & 1 deletion src/cInventoryItem.pas
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function TcadInventoryItem.GetCount: integer;
function TcadInventoryItem.GetGameItem: tgameitem;
begin
result := tgameitem.Create;
result.State := TGameItemState.first; // TODO : à compléter
result.State := TGameItemState.planted;
if assigned(FInventoryItem) then
result.Color := FInventoryItem.Color
else
Expand Down
5 changes: 5 additions & 0 deletions src/fMain.fmx
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,9 @@ object frmMain: TfrmMain
TabOrder = 0
end
end
object GameLoop: TTimer
OnTimer = GameLoopTimer
Left = 304
Top = 224
end
end
70 changes: 67 additions & 3 deletions src/fMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ TfrmMain = class(TForm)
btnPauseGame: TRectangle;
btnPauseGameSVG: TPath;
GameGrid: TImage;
GameLoop: TTimer;
procedure FormCreate(Sender: TObject);
procedure animHideScreenFinish(Sender: TObject);
procedure animShowScreenFinish(Sender: TObject);
Expand All @@ -60,6 +61,7 @@ TfrmMain = class(TForm)
procedure GameGridTap(Sender: TObject; const Point: TPointF);
procedure GameGridMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure GameLoopTimer(Sender: TObject);
private
{ Déclarations privées }
DisplayedScreen: TLayout;
Expand All @@ -69,6 +71,8 @@ TfrmMain = class(TForm)
procedure SelectInventoryItem(Sender: TObject);
procedure UnSelectInventoryItem(Sender: TObject);
procedure ClickOnGameGrid(X, Y: Single);
procedure GameItemStateChanged(Sender: TObject);
procedure GameItemColorChanged(Sender: TObject);
public
{ Déclarations publiques }
procedure DisplayScreen(ScreenToDisplay: TGameScreen);
Expand All @@ -89,7 +93,7 @@ implementation

{$R *.fmx}

uses uGameData;
uses uGameData, udmLDJam52_Icones_AS303523361;

procedure TfrmMain.animHideScreenFinish(Sender: TObject);
begin
Expand Down Expand Up @@ -192,7 +196,11 @@ procedure TfrmMain.ClickOnGameGrid(X, Y: Single);
else
begin
// nothing at this position
Grid.SetItem(col, row, SelectedInventoryItem.GetGameItem);
var
item := SelectedInventoryItem.GetGameItem;
Grid.SetItem(col, row, item);
item.onstatechange := GameItemStateChanged;
item.OnColorChange := GameItemColorChanged;
SelectedInventoryItem.Count := SelectedInventoryItem.Count - 1;
RefreshGameGrid; // TODO : draw only this cell, not the grid
end;
Expand Down Expand Up @@ -368,6 +376,28 @@ procedure TfrmMain.GameGridTap(Sender: TObject; const Point: TPointF);
ClickOnGameGrid(Point.X, Point.Y);
end;

procedure TfrmMain.GameItemColorChanged(Sender: TObject);
var
item: tgameitem;
begin
if not(Sender is tgameitem) then
exit;

RefreshGameGrid; // TODO : refresh only this element if its displayed
end;

procedure TfrmMain.GameItemStateChanged(Sender: TObject);
var
item: tgameitem;
begin
if not(Sender is tgameitem) then
exit;

item := Sender as tgameitem;

// TODO : à compléter
end;

procedure TfrmMain.InitCreditScreen;
begin
ScreenCreditContent.margins.top := GameTitle.Position.Y + GameTitle.Height +
Expand Down Expand Up @@ -408,9 +438,13 @@ procedure TfrmMain.InitGameStart(ContinuePreviousGame: boolean);
GridViewportX := CGameGridWidth div 2;
GridViewportY := CGameGridHeight div 2;

// Show the game grid
RefreshGameGrid;

// TODO : à compléter

// Last operation : starting the game loop
GameLoop.enabled := true;
end;

procedure TfrmMain.InitGameText;
Expand Down Expand Up @@ -454,11 +488,13 @@ procedure TfrmMain.RefreshGameGrid;
var
NbCol, NbRow: integer;
GameData: tgamedata;
item: TGameItem;
item: tgameitem;
GridCanvas: tcanvas;
X, Y, w, h: Single;
bmpscale: Single;
i, j: integer;
bmp: tbitmap;
s: tsizef;
begin
if not GameStarted then
exit;
Expand Down Expand Up @@ -490,6 +526,23 @@ procedure TfrmMain.RefreshGameGrid;
GridCanvas.Fill.Color := item.Color;
GridCanvas.Fill.Kind := TBrushKind.Solid;
GridCanvas.FillRect(trectf.Create(X, Y, X + w, Y + h), 1);
s := tsizef.Create(2 * w / 3, 2 * h / 3);
case item.State of
TGameItemState.Planted:
bmp := dmLDJam52_Icones_AS303523361.ImageList.Bitmap(s, 4);
TGameItemState.Mature:
bmp := dmLDJam52_Icones_AS303523361.ImageList.Bitmap(s, 6);
TGameItemState.Rotten:
bmp := dmLDJam52_Icones_AS303523361.ImageList.Bitmap(s, 5);
TGameItemState.Dead:
bmp := dmLDJam52_Icones_AS303523361.ImageList.Bitmap(s, 1);
TGameItemState.compost:
bmp := dmLDJam52_Icones_AS303523361.ImageList.Bitmap(s, 2);
else
raise exception.Create('No icon for this item state.');
end;
GridCanvas.DrawBitmap(bmp, bmp.boundsf, trectf.Create(X, Y, X + w,
Y + h), 1);// TODO : add margin to destination
end;
end;
finally
Expand All @@ -506,6 +559,17 @@ procedure TfrmMain.SelectInventoryItem(Sender: TObject);
SelectedInventoryItem := (Sender as TcadInventoryItem);
end;

procedure TfrmMain.GameLoopTimer(Sender: TObject);
begin
if not GameStarted then
begin
GameLoop.enabled := false;
exit;
end;

tgamedata.Current.ExecGameLoop;
end;

procedure TfrmMain.UnSelectInventoryItem(Sender: TObject);
begin
if (Sender is TcadInventoryItem) and
Expand Down
Loading

0 comments on commit 6fe454b

Please sign in to comment.