Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <raylib.h>
- #include <raymath.h>
- //MAKRA
- #define SIN(x) sin(x * 3.141592653589 / 180);
- #define COS(x) cos(x * 3.141592653589 / 180);
- //FUNKCJE
- float length(Vector2& distanceVec) {
- return sqrt(distanceVec.x * distanceVec.x + distanceVec.y * distanceVec.y);
- }
- Vector2 normalize(Vector2& distanceVec, float& distanceNum) {
- return { distanceVec.x / distanceNum, distanceVec.y / distanceNum };
- }
- double radiansToDegrees(double radians) {
- return radians * (180.0f / PI);
- }
- double rotate(Vector2& objPosition, Vector2& pointPosition) {
- return atan2(pointPosition.y - objPosition.y, pointPosition.x - objPosition.x);
- }
- //KLASY
- class Entity {
- public:
- //ZMIENNE INT
- int size;
- int speed;
- int hp;
- //ZMIENNE WEKTOROWE
- Vector2 position;
- Vector2 direction = { 0,0 };
- //ZMIENNE ABSTRAKCYJNE
- Color color;
- //FUNKCJE
- void entityDraw(Vector2 &entityPosition, int entitySize, Color &entityColor) {
- DrawCircle(entityPosition.x, entityPosition.y, entitySize, entityColor);
- }
- };
- class Player : public Entity {
- public:
- //ZMIENNE
- bool moving = false;
- int dirHintX;
- int dirHintY;
- //FUNKCJE
- void directionUpdate(Vector2 &direction) {
- dirHintX = 0;
- dirHintY = 0;
- moving = false;
- if (IsKeyDown(KEY_A)) dirHintX -= 1;
- if (IsKeyDown(KEY_D)) dirHintX += 1;
- if (IsKeyDown(KEY_W)) dirHintY -= 1;
- if (IsKeyDown(KEY_S)) dirHintY += 1;
- if (dirHintX != 0 || dirHintY != 0) {
- moving = true;
- }
- direction.x = position.x + dirHintX;
- direction.y = position.y + dirHintY;
- }
- void playerUpdate(Vector2 &entityPosition, Vector2 &direction, int &entitySpeed, bool &isPlayerMoving) {
- directionUpdate(direction);
- Vector2 distanceVec = { direction.x - entityPosition.x, direction.y - entityPosition.y };
- float distanceNum = length(distanceVec);
- Vector2 directionFinal = normalize(distanceVec, distanceNum);
- if (isPlayerMoving == true) {
- entityPosition.x += entitySpeed * directionFinal.x;
- entityPosition.y += entitySpeed * directionFinal.y;
- }
- }
- };
- class Sword : public Entity {
- public:
- //ZMIENNE
- Vector2 pointToRot;
- double angle;
- //FUNKCJE
- void swordDraw(Vector2 &position) {
- Vector2 origin = { 0,0 }; // Środek obrotu
- Rectangle rect = { position.x, position.y, (float)size, (float)(size * 2) }; // Prostokąt miecza
- DrawRectanglePro(rect, origin, angle, BLUE);
- }
- void swordUpdate(Vector2& position, Vector2& destPosition, Vector2 pointPosition, float angle) {
- position = destPosition;
- // Oblicz kąt między graczem a myszką
- angle = rotate(position, pointPosition);
- }
- };
- //KLASY-ZMIENNE
- Player player;
- Sword sword;
- //MAIN
- int main()
- {
- //INICJALIZACJA!!!
- const int screenWidth = 640;
- const int screenHeight = 360;
- //-Player
- player.size = 10;
- player.speed = 8;
- player.hp = 5;
- player.position = Vector2{ screenWidth / 2,screenHeight / 2 };
- player.color = BLACK;
- //-Sword
- sword.size = 15;
- InitWindow(screenWidth, screenHeight, "Metachromatic");
- SetTargetFPS(60);
- //MAIN LOOP GRY!!!
- while (!WindowShouldClose()) {
- //------------------------------------------------------------------------------------------------------------
- //UPDATE
- player.playerUpdate(player.position, player.direction, player.speed, player.moving);
- sword.swordUpdate(sword.position, player.position, GetMousePosition(), sword.angle);
- //DRAW
- //DRAW-BEGIN
- BeginDrawing();
- ClearBackground(WHITE);
- player.entityDraw(player.position, player.size, player.color);
- sword.swordDraw(sword.position);
- DrawText("JACIE GYACIE DZIALA", screenWidth / 2, screenHeight / 2, 20, LIGHTGRAY);
- //DRAW-END
- EndDrawing();
- //------------------------------------------------------------------------------------------------------------
- }
- //DE-INICJALIZACJA
- //ZAMYKANIE OKNA GRY
- CloseWindow();
- //KONIEC PROGRAMU
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement