Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <raylib.h>
- //FUNKCJE
- int normalize(Vector2 vector) {
- return sqrt(vector.x * vector.x + vector.y * vector.y);
- }
- //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
- //FUNKCJE
- void directionUpdate(Vector2 &direction) {
- if (IsKeyDown(KEY_A)) {
- direction.x = -1;
- }
- else if (IsKeyDown(KEY_D)) {
- direction.x = 1;
- }
- else if (IsKeyDown(KEY_W)) {
- direction.y = -1;
- }
- else if (IsKeyDown(KEY_S)) {
- direction.y = 1;
- }
- else {
- direction = { 0,0 };
- }
- }
- void entityUpdate(Vector2 &entityPosition, Vector2 &direction, int &entitySpeed) {
- directionUpdate(direction);
- entityPosition.x = (entityPosition.x + speed * normalize(direction));
- entityPosition.y = (entityPosition.y + speed * normalize(direction));
- }
- };
- //KLASY-ZMIENNE
- Player player;
- //MAIN
- int main()
- {
- //INICJALIZACJA!!!
- const int screenWidth = 640;
- const int screenHeight = 360;
- //-Player
- player.size = 20;
- player.speed = 10;
- player.hp = 5;
- player.position = Vector2{ screenWidth / 2,screenHeight / 2 };
- player.color = BLACK;
- InitWindow(screenWidth, screenHeight, "Metachromatic");
- SetTargetFPS(60);
- //MAIN LOOP GRY!!!
- while (!WindowShouldClose()) {
- //------------------------------------------------------------------------------------------------------------
- //UPDATE
- player.entityUpdate(player.position, player.direction, player.speed);
- //DRAW
- //DRAW-BEGIN
- BeginDrawing();
- ClearBackground(WHITE);
- player.entityDraw(player.position, player.size, player.color);
- 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