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.
80 lines
1.9 KiB
80 lines
1.9 KiB
#include "raylib.h"
|
|
#include "stdio.h"
|
|
#include "sprite.h"
|
|
#include "inputHandling.h"
|
|
#include "raymath.h"
|
|
|
|
int main(){
|
|
|
|
InitWindow(800, 450, "basic window");
|
|
|
|
Texture2D texture;
|
|
struct Sprite sprites[100];
|
|
|
|
texture = LoadTexture("assets/amulet.png");
|
|
|
|
int spriteAmount = 0;
|
|
struct Sprite cursorSprite = {&texture, 450, 225};
|
|
|
|
struct InputHandler inputHandler;
|
|
|
|
Camera2D camera = { 0 };
|
|
camera.target = (Vector2){400, 225};
|
|
camera.rotation = 0.0f;
|
|
camera.zoom = 1.0f;
|
|
|
|
addSprite(sprites, &spriteAmount, &texture, 400, 225);
|
|
|
|
SetTargetFPS(60);
|
|
while(!WindowShouldClose()){
|
|
|
|
BeginDrawing();
|
|
|
|
ClearBackground(RAYWHITE);
|
|
|
|
BeginMode2D(camera);
|
|
int i;
|
|
int length = sizeof(sprites)/sizeof(sprites[0]);
|
|
for(i=0; i < spriteAmount; i++){
|
|
DrawSprite(&sprites[i]);
|
|
}
|
|
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
|
|
for(i=0; i < spriteAmount; i++){
|
|
if(sprites[i].clicked){
|
|
Vector2 movement = {sprites[i].destX - sprites->x, sprites[i].destY - sprites->y};
|
|
|
|
if(Vector2Length(movement) < 10.0f){
|
|
inputHandler.clicked = false;
|
|
sprites->clicked = false;
|
|
}
|
|
|
|
movement = Vector2Normalize(movement);
|
|
movement = Vector2Scale(movement, 10);
|
|
sprites->x += movement.x;
|
|
sprites->y += movement.y;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
EndDrawing();
|
|
}
|
|
|
|
CloseWindow();
|
|
|
|
return 0;
|
|
|
|
}
|