fdIsland.pas 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. unit fdIsland;
  2. interface
  3. uses
  4. System.SysUtils,
  5. System.Types,
  6. System.UITypes,
  7. System.Classes,
  8. System.Variants,
  9. System.ImageList,
  10. System.Math,
  11. System.Math.Vectors,
  12. System.Inifiles,
  13. FMX.Types,
  14. FMX.Controls,
  15. FMX.Forms,
  16. FMX.Graphics,
  17. FMX.Dialogs,
  18. FMX.ImgList,
  19. FMX.Controls.Presentation,
  20. FMX.StdCtrls,
  21. FMX.Layouts,
  22. FMX.Viewport3D,
  23. FMX.Ani,
  24. FMX.ListBox,
  25. FMX.Controls3D, FMX.Objects3D,
  26. FMX.Objects,
  27. FMX.Types3D, System.IOUtils,
  28. FMX.MaterialSources,
  29. FMX.Edit,
  30. FMX.EditBox,
  31. FMX.SpinBox,
  32. FMX.Effects,
  33. FMX.TabControl, frmSmartphone,
  34. FMX.Filter.Effects,
  35. GBE.Grass,
  36. GBE.PlayerPosition,
  37. GBE.Clouds,
  38. GBE.PlaneExtend,
  39. GBE.Heightmap,
  40. GBE.Joystick,
  41. GBE.Viewport3D;
  42. type
  43. TSceneJeu = (intro, jeu);
  44. TFormIsland = class(TForm)
  45. GBEViewport3D: TGBEViewport3D;
  46. aniPrincipale, aniTexte: TFloatAnimation;
  47. StyleBook: TStyleBook;
  48. ImageListButtons: TImageList;
  49. joyDeplacement, joyOrientation: TGBEJoystick;
  50. GBEPlayerPosition: TGBEPlayerPosition;
  51. tFPS: TTimer;
  52. btnPlayPause, btnSmartphone, btnQuitter: TButton;
  53. GBEHeightmap1: TGBEHeightmap;
  54. lSoleil: TLight;
  55. GBEPlaneExtend1: TGBEPlaneExtend;
  56. GBEClouds1: TGBEClouds;
  57. TextureMaterialSource1, TextureMaterialSource2, TextureMaterialSource3
  58. : TTextureMaterialSource;
  59. recIHM: TRectangle;
  60. palmierModele, modelJoueur: TModel3D;
  61. ColorMaterialSource1: TColorMaterialSource;
  62. textureSol, textureOcean, palmierModeleMat21, palmierModeleMat01,
  63. palmierModeleMat11, modelJoueurMat01: TLightMaterialSource;
  64. Image1, Image2, Image3, Image4: TImage;
  65. Label9, lblCollision: TLabel;
  66. GlowEffect1: TGlowEffect;
  67. dmyMonde, dmyObstacles, dmyArbreForCollisionDetection, dmySoleil: TDummy;
  68. cameraCarte: TCamera;
  69. layBas, layGauche, layIHM: TLayout;
  70. lblFPS: TText;
  71. FillRGBEffect1: TFillRGBEffect;
  72. modelMaison: TModel3D;
  73. dmyMaisonForCollisionDetection: TDummy;
  74. modelMaisonMat11: TLightMaterialSource;
  75. modelMaisonMat01: TLightMaterialSource;
  76. TextureMaterialSource: TTextureMaterialSource;
  77. dmyHerbe: TDummy;
  78. procedure aniPrincipaleProcess(Sender: TObject);
  79. procedure FormCreate(Sender: TObject);
  80. procedure btnOptionAppliquerClick(Sender: TObject);
  81. procedure tFPSTimer(Sender: TObject);
  82. procedure btnPlayPauseClick(Sender: TObject);
  83. procedure Image2Click(Sender: TObject);
  84. procedure btnSmartphoneClick(Sender: TObject);
  85. procedure btnQuitterClick(Sender: TObject);
  86. private
  87. procedure initialisation;
  88. procedure ReprendreJeu;
  89. procedure SauverConfig;
  90. procedure AppliquerConfig;
  91. procedure ChargerConfig;
  92. procedure PauseJeu;
  93. procedure SceneIntroduction;
  94. procedure SceneGame;
  95. procedure ChargerNuages;
  96. procedure ChargerMer;
  97. procedure ChargerVegetation;
  98. procedure ChargerHabitation;
  99. procedure preparationSceneGame;
  100. procedure preparationSceneIntroduction;
  101. procedure AfficherCarte;
  102. procedure SupprimerObstacles;
  103. procedure MettreAJourHauteurs;
  104. procedure PrendrePhoto(Sender: TObject);
  105. procedure genererHerbe(nombre: integer; premiereGeneration: boolean);
  106. procedure gestionHerbe;
  107. public
  108. configFile: string;
  109. FPS, oldDetailsSol, distanceAffichageHerbe: integer;
  110. vitesse, demiDistanceAffichageHerbe: single;
  111. sceneJeu: TSceneJeu;
  112. preparationAFaire, gererHerbe: boolean;
  113. limiteZoneJeuX, limiteZoneJeuY: single;
  114. smartphone: TfSmartphone;
  115. end;
  116. const
  117. tailleJoueur = 0.75; // Player Size for First Person View
  118. vitesseMax = 0.2; // Maximum travel speed
  119. maxHerbe = 100;
  120. var
  121. FormIsland: TFormIsland;
  122. implementation // ------------------------------------------------------------
  123. uses
  124. uGBEUtils3D,
  125. uGBEImageUtils;
  126. {$R *.fmx}
  127. procedure TFormIsland.FormCreate(Sender: TObject);
  128. begin
  129. {$IFDEF ANDROID}
  130. FullScreen := true; // Forcer en plein pour Android
  131. {$ENDIF}
  132. initialisation;
  133. end;
  134. procedure TFormIsland.Image2Click(Sender: TObject);
  135. begin
  136. preparationAFaire := true;
  137. sceneJeu := TSceneJeu.jeu;
  138. end;
  139. procedure TFormIsland.aniPrincipaleProcess(Sender: TObject);
  140. // Boucle principale du jeu
  141. begin
  142. if smartphone.cbFPS.IsChecked then
  143. inc(FPS);
  144. case sceneJeu of
  145. intro:
  146. SceneIntroduction;
  147. jeu:
  148. SceneGame;
  149. end;
  150. end;
  151. procedure TFormIsland.tFPSTimer(Sender: TObject); // Pour calculer le FPS
  152. begin
  153. if btnPlayPause.Tag = 0 then
  154. lblFPS.text := 'Pause'
  155. else
  156. lblFPS.text := FPS.ToString;
  157. FPS := 0;
  158. end;
  159. procedure TFormIsland.initialisation;
  160. begin
  161. randomize;
  162. smartphone := TfSmartphone.Create(layGauche);
  163. smartphone.Parent := layGauche;
  164. smartphone.Align := TAlignLayout.Center;
  165. smartphone.lblHour.text := FormatDateTime('hh:nn', now);
  166. smartphone.btnOptionAppliquer.OnClick := btnOptionAppliquerClick;
  167. smartphone.imgPhoto.OnClick := PrendrePhoto;
  168. smartphone.recGPS.visible := false;
  169. smartphone.recAide.visible := false;
  170. smartphone.recOptions.visible := false;
  171. preparationAFaire := true;
  172. distanceAffichageHerbe := 30;
  173. demiDistanceAffichageHerbe := distanceAffichageHerbe * 0.5;
  174. vitesse := 0;
  175. joyDeplacement.height := 0;
  176. joyOrientation.height := 0;
  177. FPS := 0;
  178. configFile := TPath.GetHomePath + PathDelim + 'demogbe_island.cfg';
  179. sceneJeu := TSceneJeu.intro;
  180. preparationAFaire := true;
  181. ChargerConfig;
  182. SupprimerObstacles;
  183. ChargerVegetation;
  184. ChargerHabitation;
  185. GBEViewport3D.Camera := GBEPlayerPosition.getCamera;
  186. GBEViewport3D.UsingDesignCamera := false;
  187. GBEViewport3D.DoAddView(cameraCarte);
  188. GBEPlayerPosition.Position.Y := GBEHeightmap1.GetHeight
  189. (GBEPlayerPosition.Position.Point) - 1;
  190. textureOcean.Texture := tileImage(textureOcean.Texture, 7, 7);
  191. textureSol.Texture := tileImage(textureSol.Texture, 10, 10);
  192. aniPrincipale.Start;
  193. end;
  194. procedure TFormIsland.ReprendreJeu;
  195. begin
  196. btnPlayPause.ImageIndex := 6;
  197. btnPlayPause.Tag := 1;
  198. if sceneJeu = TSceneJeu.intro then
  199. Image2.HitTest := true;
  200. aniPrincipale.StartFromCurrent := true;
  201. aniPrincipale.Start;
  202. end;
  203. procedure TFormIsland.PauseJeu;
  204. begin
  205. btnPlayPause.ImageIndex := 5;
  206. btnPlayPause.Tag := 0;
  207. aniPrincipale.StopAtCurrent;
  208. end;
  209. procedure TFormIsland.btnOptionAppliquerClick(Sender: TObject);
  210. begin
  211. AppliquerConfig;
  212. ReprendreJeu;
  213. end;
  214. procedure TFormIsland.PrendrePhoto(Sender: TObject);
  215. var
  216. b: TBitmap;
  217. begin
  218. b := TBitmap.Create(width, height); // Création du TBitmap
  219. GBEViewport3D.Context.CopyToBitmap(b, Rect(0, 0, width, height));
  220. // Permet de copier dans le TBitmap ce qui est affiché dans le viewport
  221. smartphone.Image1.visible := true;
  222. smartphone.recPhoto.visible := true;
  223. smartphone.Image3.Bitmap.width := b.width;
  224. smartphone.Image3.Bitmap.height := b.height;
  225. smartphone.Image3.Bitmap.CopyFromBitmap(b);
  226. b.free;
  227. end;
  228. procedure TFormIsland.btnPlayPauseClick(Sender: TObject);
  229. begin
  230. case btnPlayPause.Tag of
  231. 1:
  232. PauseJeu;
  233. 0:
  234. ReprendreJeu;
  235. end;
  236. end;
  237. procedure TFormIsland.btnQuitterClick(Sender: TObject);
  238. begin
  239. close;
  240. end;
  241. procedure TFormIsland.btnSmartphoneClick(Sender: TObject);
  242. begin
  243. if smartphone.Position.X = -layGauche.width - layGauche.Margins.left then
  244. begin
  245. TAnimator.AnimateFloat(smartphone, 'Position.X', 0, 0.5);
  246. FillRGBEffect1.enabled := true;
  247. end
  248. else
  249. begin
  250. TAnimator.AnimateFloat(smartphone, 'Position.X',
  251. -layGauche.width - layGauche.Margins.left, 0.5);
  252. FillRGBEffect1.enabled := false;
  253. end;
  254. end;
  255. procedure TFormIsland.ChargerConfig;
  256. var
  257. ficini: TInifile;
  258. I: integer;
  259. begin
  260. if fileExists(configFile) then
  261. begin
  262. ficini := TInifile.Create(configFile);
  263. smartphone.cbAliasing.ItemIndex := ficini.ReadInteger('OPTIONS',
  264. 'aliasing', 2);
  265. smartphone.cbFPS.IsChecked := ficini.ReadBool('OPTIONS', 'showFPS', false);
  266. if smartphone.cbFPS.IsChecked then
  267. recIHM.width := 192
  268. else
  269. recIHM.width := 144;
  270. smartphone.cbAfficherLignes.IsChecked := ficini.ReadBool('OPTIONS',
  271. 'showLines', false);
  272. case smartphone.cbAliasing.ItemIndex of
  273. 0:
  274. GBEViewport3D.Multisample := TMultisample.None;
  275. 1:
  276. GBEViewport3D.Multisample := TMultisample.TwoSamples;
  277. 2:
  278. GBEViewport3D.Multisample := TMultisample.FourSamples;
  279. end;
  280. smartphone.sbNuages.Value := ficini.ReadFloat('OPTIONS', 'nbnuages', 15);
  281. GBEPlaneExtend1.SubdivisionsWidth := ficini.ReadInteger('OPTIONS',
  282. 'detailsOcean', 30);;
  283. GBEPlaneExtend1.SubdivisionsHeight := ficini.ReadInteger('OPTIONS',
  284. 'detailsOcean', 30);;
  285. case GBEPlaneExtend1.SubdivisionsWidth of
  286. 10:
  287. smartphone.cbDetailsOcean.ItemIndex := 0;
  288. 30:
  289. smartphone.cbDetailsOcean.ItemIndex := 1;
  290. 90:
  291. smartphone.cbDetailsOcean.ItemIndex := 2;
  292. end;
  293. smartphone.cbTasks.IsChecked := ficini.ReadBool('OPTIONS',
  294. 'multitaches', true);
  295. smartphone.cbDetailsSol.ItemIndex := ficini.ReadInteger('OPTIONS',
  296. 'detailsSol', 0);
  297. case smartphone.cbDetailsSol.ItemIndex of
  298. 0:
  299. GBEHeightmap1.loadHeightmapFromResource('heightmap32');
  300. 1:
  301. GBEHeightmap1.loadHeightmapFromResource('heightmap64');
  302. 2:
  303. GBEHeightmap1.loadHeightmapFromResource('heightmap128');
  304. 3:
  305. GBEHeightmap1.loadHeightmapFromResource('heightmap256');
  306. 4:
  307. GBEHeightmap1.loadHeightmapFromResource('heightmap512');
  308. end;
  309. smartphone.cbHerbe.IsChecked := ficini.ReadBool('OPTIONS', 'herbe', true);
  310. ficini.free;
  311. end
  312. else
  313. begin
  314. smartphone.cbAliasing.ItemIndex := 2;
  315. smartphone.cbFPS.IsChecked := false;
  316. smartphone.cbAfficherLignes.IsChecked := false;
  317. GBEPlaneExtend1.SubdivisionsHeight := 30;
  318. GBEPlaneExtend1.SubdivisionsWidth := 30;
  319. smartphone.sbNuages.Value := 15;
  320. smartphone.cbDetailsOcean.ItemIndex := 1;
  321. smartphone.cbDetailsSol.ItemIndex := 0;
  322. GBEHeightmap1.loadHeightmapFromResource('heightmap32');
  323. GBEHeightmap1.Flou := 1;
  324. smartphone.cbTasks.IsChecked := true;
  325. smartphone.cbHerbe.IsChecked := true;
  326. end;
  327. if not(smartphone.cbFPS.IsChecked) then
  328. lblFPS.text := '';
  329. tFPS.enabled := smartphone.cbFPS.IsChecked;
  330. GBEHeightmap1.ShowLines := smartphone.cbAfficherLignes.IsChecked;
  331. GBEPlaneExtend1.ShowLines := smartphone.cbAfficherLignes.IsChecked;
  332. GBEPlaneExtend1.ActiveWaves := smartphone.cbDetailsOcean.ItemIndex > 0;
  333. GBEPlaneExtend1.UseTasks := smartphone.cbTasks.IsChecked;
  334. GBEClouds1.UseTasks := smartphone.cbTasks.IsChecked;
  335. oldDetailsSol := smartphone.cbDetailsSol.ItemIndex;
  336. gererHerbe := smartphone.cbHerbe.IsChecked;
  337. if not(gererHerbe) then
  338. begin
  339. for I := dmyHerbe.ChildrenCount - 1 downto 0 do
  340. dmyHerbe.Children[I].free;
  341. end;
  342. ChargerNuages;
  343. ChargerMer;
  344. end;
  345. procedure TFormIsland.SauverConfig;
  346. var
  347. ficini: TInifile;
  348. begin
  349. ficini := TInifile.Create(configFile);
  350. ficini.WriteInteger('OPTIONS', 'aliasing', smartphone.cbAliasing.ItemIndex);
  351. ficini.WriteBool('OPTIONS', 'showFPS', smartphone.cbFPS.IsChecked);
  352. ficini.WriteBool('OPTIONS', 'showLines',
  353. smartphone.cbAfficherLignes.IsChecked);
  354. ficini.WriteFloat('OPTIONS', 'nbnuages', smartphone.sbNuages.Value);
  355. ficini.WriteBool('OPTIONS', 'multitaches', smartphone.cbTasks.IsChecked);
  356. ficini.WriteBool('OPTIONS', 'herbe', smartphone.cbHerbe.IsChecked);
  357. case smartphone.cbDetailsOcean.ItemIndex of
  358. 0:
  359. ficini.WriteInteger('OPTIONS', 'detailsOcean', 10);
  360. 1:
  361. ficini.WriteInteger('OPTIONS', 'detailsOcean', 30);
  362. 2:
  363. ficini.WriteInteger('OPTIONS', 'detailsOcean', 90);
  364. end;
  365. ficini.WriteInteger('OPTIONS', 'detailsSol',
  366. smartphone.cbDetailsSol.ItemIndex);
  367. ficini.free;
  368. end;
  369. procedure TFormIsland.AppliquerConfig;
  370. var
  371. changerDetailSol: boolean;
  372. begin
  373. changerDetailSol := smartphone.cbDetailsSol.ItemIndex <> oldDetailsSol;
  374. SauverConfig;
  375. ChargerConfig;
  376. if changerDetailSol then
  377. MettreAJourHauteurs;
  378. end;
  379. procedure TFormIsland.MettreAJourHauteurs;
  380. var
  381. I: integer;
  382. begin
  383. for I := 0 to dmyObstacles.ChildrenCount - 1 do
  384. begin // Mise à jour des obstacles
  385. if TControl3D(dmyObstacles.Children[I]).Name = 'dmyMaisonForCollisionDetection'
  386. then
  387. TControl3D(dmyObstacles.Children[I]).Position.Y :=
  388. GBEHeightmap1.GetHeight(TControl3D(dmyObstacles.Children[I])
  389. .Position.Point) + 2.5
  390. else
  391. TControl3D(dmyObstacles.Children[I]).Position.Y :=
  392. GBEHeightmap1.GetHeight(TControl3D(dmyObstacles.Children[I])
  393. .Position.Point);
  394. end;
  395. for I := 0 to dmyHerbe.ChildrenCount - 1 do // Mise à jour de l'herbe
  396. TControl3D(dmyHerbe.Children[I]).Position.Y :=
  397. GBEHeightmap1.GetHeight(TControl3D(dmyHerbe.Children[I]).Position.Point) +
  398. TControl3D(dmyHerbe.Children[I]).height * 0.5;
  399. GBEPlayerPosition.Position.Y := GBEHeightmap1.GetHeight
  400. (GBEPlayerPosition.Position.Point) + tailleJoueur;
  401. modelJoueur.Position.Point := GBEPlayerPosition.Position.Point;
  402. end;
  403. procedure TFormIsland.ChargerNuages;
  404. begin
  405. GBEClouds1.deleteTexturesClouds;
  406. GBEClouds1.addTextureCloud(TextureMaterialSource1);
  407. GBEClouds1.addTextureCloud(TextureMaterialSource2);
  408. GBEClouds1.addTextureCloud(TextureMaterialSource3);
  409. GBEClouds1.NbClouds := Round(smartphone.sbNuages.Value);
  410. GBEClouds1.ActiveWind := true;
  411. end;
  412. procedure TFormIsland.ChargerMer;
  413. begin
  414. GBEPlaneExtend1.Origine := Point3D(GBEPlaneExtend1.width / 2, 0,
  415. GBEPlaneExtend1.height / 2);
  416. GBEPlaneExtend1.Opacity := 0.6;
  417. GBEPlaneExtend1.Amplitude := 5;
  418. GBEPlaneExtend1.Longueur := 1;
  419. end;
  420. procedure TFormIsland.ChargerVegetation;
  421. var
  422. pxObject: TProxyObject;
  423. I: integer;
  424. begin
  425. dmyArbreForCollisionDetection.Position.Point :=
  426. Point3D(180, GBEHeightmap1.GetHeight(Point3D(180, 0, 190)), 190);
  427. for I := 0 to 8 do
  428. begin
  429. pxObject := TProxyObject.Create(nil);
  430. GBEHeightmap1.AddObject(pxObject);
  431. pxObject.SourceObject := dmyArbreForCollisionDetection;
  432. pxObject.width := dmyArbreForCollisionDetection.width;
  433. pxObject.height := dmyArbreForCollisionDetection.height;
  434. pxObject.depth := dmyArbreForCollisionDetection.depth;
  435. pxObject.Locked := true;
  436. pxObject.HitTest := false;
  437. pxObject.Position.Point := Point3D(dmyArbreForCollisionDetection.Position.X
  438. - random(20), 0, dmyArbreForCollisionDetection.Position.Z - random(20));
  439. pxObject.Position.Y := GBEHeightmap1.GetHeight(pxObject.Position.Point);
  440. pxObject.RotationAngle.Y := random(360);
  441. pxObject.Parent := dmyObstacles;
  442. pxObject.Name := 'dmyArbre' + I.ToString;
  443. pxObject.visible := true;
  444. end;
  445. end;
  446. procedure TFormIsland.genererHerbe(nombre: integer;
  447. premiereGeneration: boolean);
  448. var
  449. I: integer;
  450. p: TPoint3D;
  451. begin
  452. for I := 1 to nombre do
  453. begin
  454. with TGBEGrass.Create(nil) do
  455. begin
  456. visible := false;
  457. Parent := dmyHerbe;
  458. if premiereGeneration then
  459. begin
  460. p.X := GBEPlayerPosition.Position.X + demiDistanceAffichageHerbe -
  461. random(distanceAffichageHerbe);
  462. p.Z := GBEPlayerPosition.Position.Z + demiDistanceAffichageHerbe -
  463. random(distanceAffichageHerbe);
  464. end
  465. else
  466. begin
  467. p.X := GBEPlayerPosition.Position.X + joyDeplacement.direction.X *
  468. demiDistanceAffichageHerbe + demiDistanceAffichageHerbe -
  469. random(distanceAffichageHerbe);
  470. p.Z := GBEPlayerPosition.Position.Z + joyDeplacement.direction.Z *
  471. demiDistanceAffichageHerbe + demiDistanceAffichageHerbe -
  472. random(distanceAffichageHerbe);
  473. end;
  474. RotationAngle.Y := random(360);
  475. RotationAngle.X := 180;
  476. MaterialSource := TextureMaterialSource;
  477. width := 0.5;
  478. height := 0.25;
  479. depth := 0;
  480. p.Y := GBEHeightmap1.GetHeight(p) + height * 0.5;
  481. Position.Point := p;
  482. zwrite := true;
  483. visible := true;
  484. temps := 0.1;
  485. end;
  486. end;
  487. end;
  488. procedure TFormIsland.gestionHerbe;
  489. var
  490. I: integer;
  491. distance: TPoint3D;
  492. aFaire: boolean;
  493. begin
  494. gererHerbe := false;
  495. aFaire := dmyHerbe.ChildrenCount = 0;
  496. if smartphone.cbHerbe.IsChecked then
  497. begin
  498. for I := dmyHerbe.ChildrenCount - 1 downto 0 do
  499. begin // Recherche et suppression des herbes trop loin du joueur
  500. distance := TGBEGrass(dmyHerbe.Children[I]).Position.Point -
  501. GBEPlayerPosition.Position.Point;
  502. if (abs(distance.X) > distanceAffichageHerbe) or
  503. (abs(distance.Y) > distanceAffichageHerbe) or
  504. (abs(distance.Z) > distanceAffichageHerbe) then
  505. dmyHerbe.Children[I].free;
  506. end;
  507. genererHerbe(maxHerbe - dmyHerbe.ChildrenCount, aFaire);
  508. // On génére nouvelles herbes
  509. end;
  510. gererHerbe := smartphone.cbHerbe.IsChecked;
  511. end;
  512. procedure TFormIsland.SupprimerObstacles;
  513. begin
  514. dmyArbreForCollisionDetection.Parent := GBEHeightmap1;
  515. // Pour conserver le modelPalmier
  516. dmyMaisonForCollisionDetection.Parent := GBEHeightmap1;
  517. // Pour conserver le modelMaison
  518. dmyObstacles.DeleteChildren; // On supprime tous les obstacles
  519. dmyArbreForCollisionDetection.Parent := dmyObstacles;
  520. // On réaffecte les obstacles "vegetation"
  521. dmyMaisonForCollisionDetection.Parent := dmyObstacles;
  522. // On réaffecte les obstacles "Habitation"
  523. end;
  524. procedure TFormIsland.ChargerHabitation;
  525. begin
  526. dmyMaisonForCollisionDetection.Position.Point :=
  527. Point3D(170, GBEHeightmap1.GetHeight(Point3D(170, 0, 200)) + 2.5, 200);
  528. end;
  529. procedure TFormIsland.AfficherCarte;
  530. begin
  531. smartphone.imgCarte.Bitmap := GBEViewport3D.getBitmapFromView(cameraCarte);
  532. smartphone.imgCarte.Bitmap.Canvas.BeginScene;
  533. smartphone.imgCarte.Bitmap.Canvas.FillEllipse
  534. (RectF((smartphone.imgCarte.Bitmap.width - 30) / 2,
  535. (smartphone.imgCarte.Bitmap.height - 30) / 2,
  536. (smartphone.imgCarte.Bitmap.width + 30) / 2,
  537. (smartphone.imgCarte.Bitmap.height + 30) / 2), 0.8);
  538. smartphone.imgCarte.Bitmap.Canvas.EndScene;
  539. end;
  540. procedure TFormIsland.SceneIntroduction;
  541. begin
  542. if preparationAFaire then
  543. preparationSceneIntroduction;
  544. if smartphone.sbNuages.Value > 0 then
  545. GBEClouds1.moveClouds;
  546. Image3.Position.X := FormIsland.width - Image3.width - 25;
  547. Image3.Position.Y := FormIsland.height - Image3.height - 50;
  548. end;
  549. procedure TFormIsland.SceneGame;
  550. var
  551. resultat: TGBECollisionRetour;
  552. begin
  553. if preparationAFaire then
  554. preparationSceneGame;
  555. if smartphone.sbNuages.Value > 0 then
  556. GBEClouds1.moveClouds;
  557. if gererHerbe then
  558. gestionHerbe;
  559. lblCollision.text := '';
  560. smartphone.lblHour.text := FormatDateTime('hh:nn', now);
  561. if smartphone.recGPS.visible then
  562. AfficherCarte;
  563. if joyDeplacement.Acceleration = 0 then
  564. vitesse := 0
  565. else
  566. begin
  567. if abs(vitesse) <= vitesseMax then
  568. vitesse := vitesse + joyDeplacement.Acceleration / 5000;
  569. GBEPlayerPosition.NextPosition.Position.Point :=
  570. GBEPlayerPosition.Position.Point - joyDeplacement.direction * vitesse;
  571. GBEPlayerPosition.NextPosition.Position.Y :=
  572. GBEHeightmap1.GetHeight(GBEPlayerPosition.Position.Point) + tailleJoueur;
  573. // On controle que la prochaine position est dans l'aire de jeu
  574. if (abs(GBEPlayerPosition.NextPosition.Position.Point.X) < limiteZoneJeuX)
  575. and (abs(GBEPlayerPosition.NextPosition.Position.Point.Z) < limiteZoneJeuY)
  576. then
  577. begin
  578. resultat := DetectionCollisionObstacle(GBEHeightmap1,
  579. GBEPlayerPosition.NextPosition);
  580. if not(resultat.bool) then
  581. begin
  582. GBEPlayerPosition.Position.Point :=
  583. GBEPlayerPosition.NextPosition.Position.Point;
  584. modelJoueur.Position.Point := GBEPlayerPosition.Position.Point;
  585. modelJoueur.RotationAngle.Y := 180 - GBEPlayerPosition.RotationAngle.Y;
  586. end
  587. else
  588. lblCollision.text := 'Collision avec ' + resultat.objet.Name;
  589. end
  590. else
  591. vitesse := 0;
  592. // sinon on ne déplace pas le joueur et on réinitialise sa vitesse de déplacement
  593. end;
  594. end;
  595. procedure TFormIsland.preparationSceneGame;
  596. begin
  597. layBas.Visible := true;
  598. layGauche.Visible := true;
  599. smartphone.Position.x := -layGauche.Width -layGauche.Margins.left;
  600. Image2.Visible := false;
  601. Image3.Visible := false;
  602. Image2.HitTest := false;
  603. aniTexte.Stop;
  604. GBEPlayerPosition.RotationAngle.X := 180;
  605. GBEPlayerPosition.Parent := GBEHeightmap1;
  606. GBEPlayerPosition.TypePosition := TGBETypePosition.thirdPerson;
  607. GBEPlayerPosition.getCamera.Position.Y := -1;
  608. GBEPlayerPosition.getCamera.Position.Z := -4;
  609. GBEPlayerPosition.Position.Point :=
  610. Point3D(180, GBEHeightmap1.GetHeight(Point3D(180, 0, 220)) +
  611. tailleJoueur, 220);
  612. modelJoueur.Position.Point := GBEPlayerPosition.Position.Point;
  613. joyDeplacement.deplacement := Point3D(-1, 0, 1);
  614. limiteZoneJeuX := GBEPlaneExtend1.width * 0.5;
  615. limiteZoneJeuY := GBEPlaneExtend1.height * 0.5;
  616. preparationAFaire := false;
  617. end;
  618. procedure TFormIsland.preparationSceneIntroduction;
  619. begin
  620. layBas.Visible := false;
  621. layGauche.Visible := false;
  622. GBEPlayerPosition.Parent := dmyMonde;
  623. GBEPlayerPosition.Position.Point :=
  624. Point3D(0, GBEHeightmap1.GetHeight(Point3D(0, 0, 0)), 0);
  625. GBEPlayerPosition.TypePosition := TGBETypePosition.thirdPerson;
  626. GBEPlayerPosition.getCamera.Position.Y := -30;
  627. GBEPlayerPosition.getCamera.Position.Z := -320;
  628. Image2.Visible := true;
  629. Image3.Visible := true;
  630. Image2.HitTest := true;
  631. aniTexte.Start;
  632. preparationAFaire := false;
  633. end;
  634. end.