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.
96 lines
2.5 KiB
96 lines
2.5 KiB
#include "raylib.h"
|
|
#include "stdio.h"
|
|
#include <stdlib.h>
|
|
#include "sprite.h"
|
|
#include "inputHandler.h"
|
|
#include "raymath.h"
|
|
#include "isometricRenderer.h"
|
|
#include "isometricMap.h"
|
|
|
|
int main(){
|
|
|
|
InitWindow(800, 450, "basic window");
|
|
|
|
Texture2D texture;
|
|
Sprite sprites[100];
|
|
|
|
texture = LoadTexture("assets/amulet.png");
|
|
|
|
Texture2D isometricTexture = LoadTexture("assets/grass.png");
|
|
IsometricRenderer *isometricRenderer = (IsometricRenderer *) malloc(sizeof(IsometricRenderer));
|
|
isometricRenderer->texture = &isometricTexture;
|
|
|
|
int spriteAmount = 0;
|
|
Sprite cursorSprite = {&texture, 450, 225};
|
|
|
|
InputHandler inputHandler;
|
|
|
|
Camera2D camera = { 0 };
|
|
camera.target = (Vector2){0, 0};
|
|
camera.rotation = 0.0f;
|
|
camera.zoom = 1.0f;
|
|
|
|
SpriteAdd(sprites, &spriteAmount, &texture, 0, 0);
|
|
|
|
IsometricMap *map = IsometricMapInit(20, 10);
|
|
|
|
SetTargetFPS(60);
|
|
while(!WindowShouldClose()){
|
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
BeginMode2D(camera);
|
|
|
|
IsometricRendererRenderIsometricMap(map);
|
|
|
|
int i;
|
|
for(i=0; i < spriteAmount; i++){
|
|
DrawTexture(*sprites[i].texture, sprites[i].x, sprites[i].y, WHITE);
|
|
}
|
|
|
|
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, &spriteAmount, &texture, &camera);
|
|
keyboardInput(&inputHandler, &camera);
|
|
|
|
// Sprites move towards their destination
|
|
float movementSpeed = 10.0f;
|
|
for(i=0; i < spriteAmount; i++){
|
|
if(sprites[i].hasDestination == 1){
|
|
Vector2 movement = {sprites[i].destX - (sprites + i)->x, sprites[i].destY - (sprites + i)->y};
|
|
|
|
if(Vector2Length(movement) < movementSpeed){
|
|
(sprites + i)->hasDestination = 0;
|
|
(sprites + i)->x = (sprites + i)->destX;
|
|
(sprites + i)->y = (sprites + i)->destY;
|
|
}
|
|
else{
|
|
movement = Vector2Normalize(movement);
|
|
movement = Vector2Scale(movement, movementSpeed);
|
|
(sprites + i)->x += movement.x;
|
|
(sprites + i)->y += movement.y;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
EndDrawing();
|
|
}
|
|
|
|
CloseWindow();
|
|
|
|
return 0;
|
|
|
|
}
|