Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

uses GraphABC, Timers; const MaxDots = 100; // Максимальное количество точек PlayerSize…

  1. User

    uses GraphABC, Timers;

    const MaxDots = 100; // Максимальное количество точек PlayerSize = 10; // Размер игрока DotSize = 5; // Размер точек ScreenWidth = 800; // Ширина экрана ScreenHeight = 600; // Высота экрана

    type Dot = record x, y, size: Integer; color: Color; end;

    var player: Dot; dots: array [1..MaxDots] of Dot; dotCount: Integer;

    procedure Init; begin Randomize; player.x := ScreenWidth div 2; player.y := ScreenHeight div 2; player.size := PlayerSize; player.color := clLightCyan; dotCount := MaxDots; for var i := 1 to dotCount do begin dots[i].x := Random(ScreenWidth); dots[i].y := Random(ScreenHeight); dots[i].size := DotSize; dots[i].color := clLightGreen; end; end;

    procedure DrawPlayer; begin SetPenColor(player.color); SetBrushColor(player.color); Circle(player.x, player.y, player.size); end;

    procedure DrawDots; begin for var i := 1 to dotCount do begin SetPenColor(dots[i].color); SetBrushColor(dots[i].color); Circle(dots[i].x, dots[i].y, dots[i].size); end; end;

    procedure UpdatePlayerPosition; begin if IsKeyDown(VK_W) then player.y := player.y - 5; if IsKeyDown(VK_A) then player.x := player.x - 5; if IsKeyDown(VK_S) then player.y := player.y + 5; if IsKeyDown(VK_D) then player.x := player.x + 5; end;

    function CheckCollision(dot1, dot2: Dot): Boolean; var dist: Double; begin dist := Sqrt(Sqr(dot1.x - dot2.x) + Sqr(dot1.y - dot2.y)); Result := dist < dot1.size + dot2.size; end;

    procedure CheckCollisions; begin for var i := 1 to dotCount do begin if CheckCollision(player, dots[i]) then begin // Когда игрок "съедает" точку, она исчезает и его размер увеличивается dots[i].x := -1; dots[i].y := -1; Inc(player.size); end; end; end;

    procedure DrawGame; begin ClearWindow; DrawPlayer; DrawDots; end;

    begin Init; SetWindowSize(ScreenWidth, ScreenHeight); LockDrawing; repeat UpdatePlayerPosition; CheckCollisions; DrawGame; Sleep(10); until IsKeyDown(VK_Escape); // Выход из игры при нажатии клавиши Esc end.

  2. Assistant

    This program is a simple game where you control a player (represented by a circle) using the W, A, S, D keys and try to collect all the dots on the screen by colliding with them. When the player collides with a dot, the dot disappears and the player's size increases. The game ends when the player presses the Escape key.

    The program uses the GraphABC library to display graphics and the Timers library to control the game loop. The game logic is implemented in procedures and functions which are called from the main loop.

    Here's a breakdown of the program's structure:

    • The program begins by defining some constants such as the maximum number of dots, player size, dot size, screen width, and screen height.

    • Next, the program defines a record type called Dot, which represents a dot on the screen. It has fields for x and y coordinates, size, and color.

    • The program then declares global variables for the player dot, an array of dots, and the number of dots.

    • The Init procedure is called at the beginning of the program to initialize the game state. It sets the player's initial position, size, and color, initializes the dots array with random positions, sizes, and colors, and sets the dotCount variable to the maximum number of dots.

    • The DrawPlayer procedure is responsible for drawing the player dot on the screen using the SetPenColor and SetBrushColor functions to set the color and the Circle function to draw a circle.

    • The DrawDots procedure iterates over the dots array and draws each dot on the screen using the same functions as DrawPlayer.

    • The UpdatePlayerPosition procedure is called in each game loop iteration and updates the player's position based on the keyboard input. It checks if the W, A, S, or D keys are pressed using the IsKeyDown function and updates the player's x and y coordinates accordingly.

    • The CheckCollision function takes two dots as parameters and checks if they are colliding by calculating the distance between their centers and comparing it to the sum of their sizes.

    • The CheckCollisions procedure is called in each game loop iteration and checks if the player is colliding with any of the dots. If a collision is detected, the dot is "eaten" by setting its coordinates to (-1, -1) and the player's size is increased.

    • The DrawGame procedure is called in each game loop iteration and is responsible for clearing the window, drawing the player, and drawing the dots.

    • The main part of the program begins by calling the Init procedure, setting the window size, and entering a loop that continues until the Escape key is pressed. In each iteration of the loop, the player's position is updated, collisions are checked, the game is drawn to the screen, and there is a small delay using the Sleep function to control the game speed.