You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
148 lines
4.8 KiB
148 lines
4.8 KiB
#include "raylib.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include "sprite.h"
|
|
#include "Input/inputHandler.h"
|
|
#include "raymath.h"
|
|
#include "List/list.h"
|
|
#include "IsometricMap/isometricRenderer.h"
|
|
#include "IsometricMap/isometricMap.h"
|
|
|
|
int main(){
|
|
|
|
InitWindow(800, 450, "basic window");
|
|
Texture2D amulet;
|
|
amulet = LoadTexture("assets/amulet.png");
|
|
|
|
Image worker1flip = LoadImage("assets/worker/worker-1.png");
|
|
ImageFlipHorizontal(&worker1flip);
|
|
Image worker2flip = LoadImage("assets/worker/worker-2.png");
|
|
ImageFlipHorizontal(&worker2flip);
|
|
Image worker3flip = LoadImage("assets/worker/worker-3.png");
|
|
ImageFlipHorizontal(&worker3flip);
|
|
|
|
Texture2D worker[8];
|
|
worker[6] = LoadTexture("assets/worker/worker-0.png");
|
|
worker[5] = LoadTexture("assets/worker/worker-1.png");
|
|
worker[7] = LoadTextureFromImage(worker1flip);
|
|
worker[4] = LoadTexture("assets/worker/worker-2.png");
|
|
worker[0] = LoadTextureFromImage(worker2flip);
|
|
worker[3] = LoadTexture("assets/worker/worker-3.png");
|
|
worker[1] = LoadTextureFromImage(worker3flip);
|
|
worker[2] = LoadTexture("assets/worker/worker-4.png");
|
|
|
|
Texture2D cursorTextures[2];
|
|
cursorTextures[0] = LoadTexture("assets/cursor.gif");
|
|
cursorTextures[1] = LoadTexture("assets/cursor_down.gif");
|
|
|
|
List *sprites = ListInit();
|
|
//ListPrintForward(sprites);
|
|
|
|
Sprite cursorSprite = {&(cursorTextures[0]), 450, 225};
|
|
|
|
InputHandler inputHandler;
|
|
inputHandler.pressed = 0;
|
|
inputHandler.rectStart.x = 0;
|
|
inputHandler.rectStart.y = 0;
|
|
inputHandler.cursorPos.x = 0;
|
|
inputHandler.cursorPos.y = 0;
|
|
inputHandler.selectedTile.x = 0;
|
|
inputHandler.selectedTile.y = 0;
|
|
inputHandler.selectedLayer = 0;
|
|
inputHandler.cursorTextures = cursorTextures;
|
|
inputHandler.cursorSprite = &cursorSprite;
|
|
|
|
Camera2D camera = { 0 };
|
|
camera.target = (Vector2){0, 0};
|
|
camera.rotation = 0.0f;
|
|
camera.zoom = 1.0f;
|
|
|
|
// TODO -> Isometric Map Array for multiple Layers
|
|
// -> Make only most upper layer selectable
|
|
// take selected Tile, if that tile has one above select a tile in the upper layer
|
|
IsometricMap *map = IsometricMapInit(50, 80, 0);
|
|
IsometricMap *Layer1 = IsometricMapInit(20, 20, 1);
|
|
IsometricMap *Layer2 = IsometricMapInit(15, 15, 2);
|
|
IsometricMap *Layer3 = IsometricMapInit(10, 10, 3);
|
|
IsometricMap *Layer4 = IsometricMapInit(4, 4, 4);
|
|
|
|
IsometricMapAddTile(Layer4, 2, 2, 1);
|
|
|
|
// Hides the operating systems own cursor
|
|
HideCursor();
|
|
SetTargetFPS(60);
|
|
while(!WindowShouldClose()){
|
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
BeginMode2D(camera);
|
|
|
|
IsometricRendererRenderIsometricMap(map, &inputHandler);
|
|
IsometricRendererRenderIsometricMap(Layer1, &inputHandler);
|
|
IsometricRendererRenderIsometricMap(Layer2, &inputHandler);
|
|
IsometricRendererRenderIsometricMap(Layer3, &inputHandler);
|
|
IsometricRendererRenderIsometricMap(Layer4, &inputHandler);
|
|
|
|
ListDrawAllSprites(sprites);
|
|
|
|
EndMode2D();
|
|
|
|
// Moving cursor Sprite to Mouse Pos and drawing it
|
|
cursorSprite.x = inputHandler.cursorPos.x;
|
|
cursorSprite.y = inputHandler.cursorPos.y;
|
|
DrawSprite(&cursorSprite);
|
|
|
|
// User Input Handling
|
|
mouseInput(&inputHandler, sprites, worker+4, &camera, map);
|
|
keyboardInput(&inputHandler, &camera);
|
|
|
|
// Sprites move towards their destination
|
|
float movementSpeed = 10.0f;
|
|
Node *current = sprites->head;
|
|
|
|
while (current != 0){
|
|
if(current->data.hasDestination == 1){
|
|
Vector2 movement = {
|
|
current->data.destX - current->data.x,
|
|
current->data.destY - current->data.y
|
|
};
|
|
|
|
if(Vector2Length(movement) < movementSpeed){
|
|
current->data.hasDestination = 0;
|
|
current->data.x = current->data.destX;
|
|
current->data.y = current->data.destY;
|
|
}
|
|
else{
|
|
movement = Vector2Normalize(movement);
|
|
movement = Vector2Scale(movement, movementSpeed);
|
|
current->data.x += movement.x;
|
|
current->data.y += movement.y;
|
|
|
|
// Change sprite according to direction
|
|
Vector2 nullvektor = {0,0};
|
|
float f = Vector2Angle(movement, nullvektor);
|
|
printf("Angle: %f\n", f);
|
|
f /= 3.14;
|
|
f *= 3.5;
|
|
f += 3.5;
|
|
int index = (int) f;
|
|
current->data.texture = worker + index;
|
|
}
|
|
}
|
|
|
|
current = current->next;
|
|
}
|
|
|
|
DrawFPS(GetScreenWidth() - 95, 10);
|
|
|
|
EndDrawing();
|
|
}
|
|
|
|
CloseWindow();
|
|
|
|
return 0;
|
|
|
|
}
|