Advertisement
Guest User

Untitled

a guest
Dec 29th, 2024
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <raylib.h>
  3.  
  4.  
  5. //FUNKCJE
  6.  
  7. int normalize(Vector2 vector) {
  8. return sqrt(vector.x * vector.x + vector.y * vector.y);
  9. }
  10.  
  11. //KLASY
  12.  
  13. class Entity {
  14. public:
  15. //ZMIENNE INT
  16. int size;
  17. int speed;
  18. int hp;
  19. //ZMIENNE WEKTOROWE
  20. Vector2 position;
  21. Vector2 direction = { 0,0 };
  22. //ZMIENNE ABSTRAKCYJNE
  23. Color color;
  24.  
  25. //FUNKCJE
  26. void entityDraw(Vector2 &entityPosition, int entitySize, Color &entityColor) {
  27. DrawCircle(entityPosition.x, entityPosition.y, entitySize, entityColor);
  28. }
  29. };
  30.  
  31. class Player : public Entity {
  32. public:
  33. //ZMIENNE
  34.  
  35. //FUNKCJE
  36. void directionUpdate(Vector2 &direction) {
  37.  
  38. if (IsKeyDown(KEY_A)) {
  39. direction.x = -1;
  40. }
  41. else if (IsKeyDown(KEY_D)) {
  42. direction.x = 1;
  43. }
  44. else if (IsKeyDown(KEY_W)) {
  45. direction.y = -1;
  46. }
  47. else if (IsKeyDown(KEY_S)) {
  48. direction.y = 1;
  49. }
  50. else {
  51. direction = { 0,0 };
  52. }
  53.  
  54. }
  55.  
  56. void entityUpdate(Vector2 &entityPosition, Vector2 &direction, int &entitySpeed) {
  57. directionUpdate(direction);
  58.  
  59. entityPosition.x = (entityPosition.x + speed * normalize(direction));
  60. entityPosition.y = (entityPosition.y + speed * normalize(direction));
  61. }
  62. };
  63.  
  64. //KLASY-ZMIENNE
  65.  
  66. Player player;
  67.  
  68. //MAIN
  69.  
  70.  
  71. int main()
  72. {
  73. //INICJALIZACJA!!!
  74. const int screenWidth = 640;
  75. const int screenHeight = 360;
  76.  
  77. //-Player
  78. player.size = 20;
  79. player.speed = 10;
  80. player.hp = 5;
  81. player.position = Vector2{ screenWidth / 2,screenHeight / 2 };
  82. player.color = BLACK;
  83.  
  84. InitWindow(screenWidth, screenHeight, "Metachromatic");
  85.  
  86. SetTargetFPS(60);
  87.  
  88. //MAIN LOOP GRY!!!
  89. while (!WindowShouldClose()) {
  90. //------------------------------------------------------------------------------------------------------------
  91. //UPDATE
  92.  
  93. player.entityUpdate(player.position, player.direction, player.speed);
  94.  
  95. //DRAW
  96. //DRAW-BEGIN
  97. BeginDrawing();
  98.  
  99. ClearBackground(WHITE);
  100.  
  101. player.entityDraw(player.position, player.size, player.color);
  102. DrawText("JACIE GYACIE DZIALA", screenWidth / 2, screenHeight / 2, 20, LIGHTGRAY);
  103.  
  104. //DRAW-END
  105. EndDrawing();
  106. //------------------------------------------------------------------------------------------------------------
  107. }
  108.  
  109. //DE-INICJALIZACJA
  110. //ZAMYKANIE OKNA GRY
  111. CloseWindow();
  112.  
  113. //KONIEC PROGRAMU
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement