123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- module graphics.gamelogic;
- import raylib;
- import bindbc.lua;
- import variables;
- import core.stdc.stdlib;
- import core.stdc.time;
- import graphics.engine;
- import scripts.lua;
- import std.stdio;
- import std.conv;
- import graphics.effects;
- import std.string;
- import std.math;
- import dialogs.dialogbox;
- import system.abstraction;
- import system.config;
- import std.file;
- /**
- * this module contains game logic, which was removed from engine.d for better readability.
- */
-
- void gameInit()
- {
- circle = LoadTexture("res/misc/circle.png");
- dialogBackgroundTex = LoadTexture("res/misc/TEX#win_01d.PNG");
- choiceWindowTex = LoadTexture("res/misc/TEX#win_00d.PNG");
- texturesLoaded = true;
- if (WindowShouldClose()) {
- currentGameState = GameState.Exit;
- } else {
- debugWriteln("Game initializing.");
- systemSettings = loadSettingsFromConfigFile();
- }
- }
- void effectsLogic()
- {
- UpdateMusicStream(music);
- if (isCameraMoving) {
- float delta = GetFrameTime() * cameraMoveSpeed;
- camera.target.x += (cameraTargetX - camera.target.x) * delta;
- camera.target.y += (cameraTargetY - camera.target.y) * delta;
- camera.zoom += (cameraTargetZoom - camera.zoom) * delta;
- if (fabs(camera.target.x - cameraTargetX) < 5.0f &&
- fabs(camera.target.y - cameraTargetY) < 5.0f &&
- fabs(camera.zoom - cameraTargetZoom) < 0.5f) {
- isCameraMoving = false;
- }
- }
- playUIAnimation(framesUI);
- }
- void backgroundLogic() {
- if (backgroundFades.length < backgroundTextures.length) {
- backgroundFades.length = backgroundTextures.length;
- }
- for (int i = 0; i < backgroundTextures.length; i++) {
- if (backgroundTextures[i].drawTexture) {
- if (backgroundFades[i].alpha < 1.0f) {
- backgroundFades[i].alpha += GetFrameTime() * backgroundFades[i].fadeSpeed;
- if (backgroundFades[i].alpha > 1.0f) backgroundFades[i].alpha = 1.0f;
- }
- } else {
- if (backgroundFades[i].alpha > 0.0f) {
- backgroundFades[i].alpha -= GetFrameTime() * backgroundFades[i].fadeSpeed;
- if (backgroundFades[i].alpha < 0.0f) backgroundFades[i].alpha = 0.0f;
- }
- }
- if (backgroundFades[i].alpha > 0.0f) {
- float centeredX = backgroundTextures[i].x - (backgroundTextures[i].width * backgroundTextures[i].scale / 2);
- float centeredY = backgroundTextures[i].y - (backgroundTextures[i].height * backgroundTextures[i].scale / 2);
-
- Color tint = Colors.WHITE;
- tint.a = cast(ubyte)(255 * backgroundFades[i].alpha);
-
- DrawTextureEx(backgroundTextures[i].texture,
- Vector2(centeredX, centeredY),
- 0.0,
- backgroundTextures[i].scale,
- tint
- );
- }
- }
- }
- void characterLogic() {
- if (characterFades.length < characterTextures.length) {
- characterFades.length = characterTextures.length;
- }
- for (int i = 0; i < characterTextures.length; i++) {
- if (characterTextures[i].drawTexture) {
- if (characterTextures[i].justDrawn) {
- characterFades[i].alpha = 0.0f;
- characterTextures[i].justDrawn = false;
- }
-
- if (characterFades[i].alpha < 1.0f) {
- characterFades[i].alpha += GetFrameTime() * characterFades[i].fadeSpeed;
- if (characterFades[i].alpha > 1.0f) characterFades[i].alpha = 1.0f;
- }
- } else {
- if (characterFades[i].alpha > 0.0f) {
- characterFades[i].alpha -= GetFrameTime() * characterFades[i].fadeSpeed;
- if (characterFades[i].alpha < 0.0f) {
- characterFades[i].alpha = 0.0f;
- }
- }
- }
- if (characterFades[i].alpha > 0.0f) {
- float centeredX = characterTextures[i].x - (characterTextures[i].width * characterTextures[i].scale / 2);
- float centeredY = characterTextures[i].y - (characterTextures[i].height * characterTextures[i].scale / 2);
-
- Color tint = Colors.WHITE;
- tint.a = cast(ubyte)(255 * characterFades[i].alpha);
-
- DrawTextureEx(characterTextures[i].texture,
- Vector2(centeredX, centeredY),
- 0.0,
- characterTextures[i].scale,
- tint);
- }
- }
- }
- void dialogLogic() {
- if (showDialog) {
- displayDialog(messageGlobal, choices, selectedChoice, choicePage, textFont, &showDialog, typingSpeed,
- dialogColor, circle, dialogBackgroundTex, choiceWindowTex);
- }
- }
|