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.
92 lines
2.3 KiB
92 lines
2.3 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;
|
|
|
|
Camera2D camera = { 0 };
|
|
camera.target = (Vector2){0, 0};
|
|
camera.rotation = 0.0f;
|
|
camera.zoom = 1.0f;
|
|
|
|
IsometricMap *map = IsometricMapInit(20, 10);
|
|
|
|
SetTargetFPS(60);
|
|
while(!WindowShouldClose()){
|
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
BeginMode2D(camera);
|
|
|
|
IsometricRendererRenderIsometricMap(map);
|
|
|
|
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);
|
|
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;
|
|
|
|
}
|