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.
99 lines
2.6 KiB
99 lines
2.6 KiB
#include "raylib.h"
|
|
#include "stdio.h"
|
|
#include "sprite.h"
|
|
#include "inputHandler.h"
|
|
#include "raymath.h"
|
|
#include "isometricRenderer.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 = {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);
|
|
|
|
SetTargetFPS(60);
|
|
while(!WindowShouldClose()){
|
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
BeginMode2D(camera);
|
|
|
|
IsometricRendererRenderMap(&isometricRenderer, 15);
|
|
|
|
int i;
|
|
//int length = sizeof(sprites)/sizeof(sprites[0]);
|
|
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);
|
|
|
|
/*
|
|
if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)){
|
|
printf("Klick\n");
|
|
SpriteAdd(sprites, &j, &texture, cursor.x + camera.target.x, cursor.y + camera.target.y);
|
|
}
|
|
*/
|
|
|
|
// 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;
|
|
|
|
}
|