Робота з графікою в SDL: Урок №5: Clickomania | Participants
|
- Statistics
- Participants
- Translate into Ukrainian
- Translation result
- Translated in draft, editing and proof-reading required.
If you do not want to register an account, you can sign in with OpenID.
GFX with SDL: Lesson 5: Clickomania | ||
GFX with SDL: Lesson 5: Clickomania | ||
Hi all! In this tutorial we will build a simple game in SDL called Clickomania. Clickomania is actually a really simple game to build. Our version of the game will consist of a 10x14 grid of balls. When you click (with the mouse) on a ball, that's connected to 2 or more balls, all the connected balls of the same color as the ball you clicked dissapear. And the balls that were above the dissapeared balls will simply fall down. If you manage to clear a row of balls, then the other rows move in to the left from the right. These 4 images illustrate the basic aspects of the game: | Привіт всім! У цьому туторіалі ми створимо просту гру в SDL під назвою Clickomania. Clickomania - це дійсно дуже проста у написанні гра. Наша версія гри буде складатися із сітки розміром 10х14 із кульок. При натисканні (мишею) на кульку, що з'єднана із двома або більше іншими кульками, всі з'єднані кульки того ж кольору, на який натиснули, зникають. А ті, що знаходились вище, просто падають вниз. Якщо вдається очистити одразу рядок кульок, тоді решта рядків зсуваються справа наліво. | |
After clicking one of the purple balls in the yellow region, all of them disappear and the balls that were above them fall down. | Після натискання однієї з пурпуровових кульок в жовтій області, всі вони зникають і кульки, які були над ними падають вниз. | |
When we get rid of the balls in the yellow region the rest move from right to left. Note that the rows of balls move from right to left, not the individual balls themselves. Now let's get to coding the game. | Коли ми позбуваємось кульок в жовтій області, інші будуть рухаються справа наліво. Зверніть увагу на те, що справа наліво рухаються ряди кульок, а не окремі кульки. Тепер давайте перейдемо до написання гри. | |
We first have some #includes and some #defines. | Спочатку ми оголошуємо директиви #include та деякі константи #define | |
#include <stdio.h> | #include <stdio.h> //стандартна біблиіотека вводу/виводу | |
#include <stdlib.h> | ||
#include <stdarg.h> | ||
#include <string.h> | #include <string.h> // бібліотека для роботи з рядками. | |
#include <time.h> | #include <time.h> // бібліотека, яка відповідає за час та рандомні функції. | |
#include <SDL/SDL.h> | #include <SDL/SDL.h> // бібліотека, яка використовується для роботи с SDL | |
Since we'll also use the SDL Font routines (tutorial 4), we'll have to include font.h | Оскільки ми будемо також використовувати SDL шрифти (4 урок), ми повинні включити font.h | |
#include "font.h" | ||
Now come some variables. The first two contain the dimensions of the playfield. They will be set to some values later. | Тепер оголошення деяких змінних. Перші дві містять розміри ігрового поля. Вони будуть встановлені в деяких значенях пізніше. | |
int rows; | ||
int cols; | ||
screen should be obvious. balls contain the images of the 10 possible ball types. font1 and font2 shouldn't be too much to grasp as well. | картина повинна бути очевидною. Кулі містять зображення з 10 можливих типів кульок. font1 і font2 не повинно бути занадто багато, щоб зрозуміти краще. | |
SDL_Surface *screen; // The screen surface | ||
SDL_Surface *balls[10];// The ball images | ||
SDLFont *font1; // 2 fonts | ||
SDLFont *font2; | ||
playf contains the grid of all the balls. We will initalize it later. | в функція playf міститься сітка з всіх кульок. Ми ініціалізуємо її пізніше. | |
char *playf; // The playfield itself | ||
scrwidth and scrheight contain the default width and height of the screen. Later we'll "parse" the command line arguments checking, if the user wants to run this program at some other screen resolution. Depending on the screen resolution, the grid of balls might and might not fully cover the screen when drawn from the screen coordinates o,o. centx and centy tell us from where to start drawing the array of balls. They will be calculated later. | scrwidth та scrheight містить висоту та ширину поля за замовчуванням.Пізніше ми розберемо аргументи командного рядка , якщо користувач схоче запустити цю програму з іншим розширенням екрану. Залежно від розширення екрану, сітка кульок може і не може повністю покрити екран зображувані на екрані координат О, О. centx і centy дають нам знати, де треба починати малювати масив кульок. Це буде розраховано пізніше. |
