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.

120 lines
3.6 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 texture;
texture = LoadTexture("assets/amulet.png");
List *sprites = ListInit();
//ListPrintForward(sprites);
Sprite cursorSprite = {&texture, 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 = -1;
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);
IsometricMap **layers = (IsometricMap **) malloc(10*sizeof(IsometricMap *));
layers[0] = IsometricMapInit(50, 80, 0);
layers[1] = IsometricMapInit(20, 20, 1);
layers[2] = IsometricMapInit(15, 10, 2);
SetTargetFPS(60);
while(!WindowShouldClose()){
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode2D(camera);
//IsometricRendererRenderIsometricMap(map, &inputHandler);
//IsometricRendererRenderIsometricMap(Layer1, &inputHandler);
//IsometricRendererRenderIsometricMap(Layer2, &inputHandler);
//IsometricRendererRenderIsometricMap(Layer3, &inputHandler);
//IsometricRendererRenderIsometricMap(Layer4, &inputHandler);
IsometricRendererRenderIsometricMap(layers, &inputHandler);
ListDrawAllSprites(sprites);
EndMode2D();
// Moving cursor Sprite to Mouse Pos and drawing it
cursorSprite.x = inputHandler.cursorPos.x - texture.width / 2;
cursorSprite.y = inputHandler.cursorPos.y - texture.height / 2;
DrawSprite(&cursorSprite);
// User Input Handling
mouseInput(&inputHandler, sprites, &texture, &camera, layers);
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;
}
}
current = current->next;
}
EndDrawing();
}
CloseWindow();
return 0;
}