사용자 도구

사이트 도구


raylib:tetris:gettingstarted
gettingstarted

문서의 이전 판입니다!


시작하기

테트리스 만들기를 시작하려고 한다.

아예 스크래치 상태부터 만들려고 한다.

따라서 아주 간단한 상태부터 시작할 예정이다. 조금씩 만들어 보자

시작 파일

1. main.cpp

윈도우 창에 텍스트만 나오게 하는 간단한 Hello world 파일을 시작파일로 하자

Raylib에서 윈도우 창을 만들고 드로잉을 하는 간단한 보일러플레이트는 다음과 같다. 이를 시작파일로 할 것이다.

"main.cpp"
#include "raylib.h"
 
/* This is created by Dongkun Lee. Korean Attorney in Law. 
First Created at 12/28/2025
*/
 
 
/* -------------------------------------------------------------
// Program main entry point
--------------------------------------------------------------- */
int main(void)
{
    // Initialization
    const int screenWidth = 500;
    const int screenHeight = 600;  // Cell Size is 30px. and There are 20 grid horizontally. 
 
    InitWindow(screenWidth, screenHeight, "Tetris - Hello!");
 
    Image icon = LoadImage("icon/seodang.png");
    SetWindowIcon(icon);
 
    SetTargetFPS(60);    
 
    // Main game loop
    while (WindowShouldClose() == false)    // Detect window close button or ESC key
    {
        // Draw
        //----------------------------------------
        BeginDrawing();
 
            ClearBackground(RAYWHITE);
            DrawText("Hello There", 190, 200, 20, MAROON);  
 
        EndDrawing();
        //---------------------------------------
 
    }
 
    // De-Initialization
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------
 
    return 0;
}

2. Makefile

Makefile은 다음과 같이 만들었다.

"Makefile
#Project Name
PROJECT 	?= tetris
# Define required raylib variables
RAYLIB_PATH        ?= ./lib
 
# Define include path 
INCLUDE_PATH        ?= ./include
 
# Define compiler path on Windows
COMPILER_PATH      ?= C:/raylib/w64devkit/bin
# Build mode for project: DEBUG or RELEASE
BUILD_MODE            ?= RELEASE
 
# Define default C compiler: gcc
# NOTE: define g++ compiler if using C++
CC = g++
 
# Define default make program: Mingw32-make
MAKE = mingw32-make $(PROJECT)
# Compile option
CFLAGS += -Wall -std=c++14 -D_DEFAULT_SOURCE -Wno-missing-braces 
 
ifeq ($(BUILD_MODE),DEBUG)
    CFLAGS += -g -O0
else
    CFLAGS += -s -O1
endif
 
# Define include paths for required headers
# NOTE: Several external required libraries (stb and others)
INCLUDE_PATHS = -I. -I$(INCLUDE_PATH) 
 
# Define library paths containing required libs.
LDFLAGS = -L. -L$(RAYLIB_PATH)  
 
# Define any libraries required on linking
# if you want to link libraries (libname.so or libname.a), use the -lname
LDLIBS = -lraylib -lgdi32 -lwinmm 
 
# Define all source files required
SRC_DIR = .
OBJ_DIR = obj
 
 
# Default target entry
# NOTE: We call this Makefile target or Makefile.Android target
all:
	$(MAKE)
 
$(OBJ_DIR)/main.o : main.cpp
	@mkdir -p obj
	$(CC)  -c main.cpp $(CFLAGS) $(INCLUDE_PATHS) -o $@
 
 
#Icon file path
ICON += icon/seodang_res.o
 
 
#목적 파일 만들기
OBJS =  $(OBJ_DIR)/main.o
 
 
#컴파일
tetris : $(OBJS)
	$(CC) $(CFLAGS)  $(OBJS) -o $(PROJECT) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) $(ICON)

앞으로 배우면서 모든 의존성을 확인하기 위하여 라이브러리(lib)와 헤더파일(include)을 프로젝트 폴더 하단에 위치했음을 눈여겨 보자.

또한 윈도우 실행파일의 아이콘도 같이 컴파일하게 했음을 눈여겨 보자.

다음 번에는 그리드 개념을 배우도록 할 것이다.

참고

1. 시작 파일

전체 시작파일은 다음 첨부파일과 같다.

Tetris Getting Started 파일

2. 아이콘 만들기

3. VS Code 설정파일

너무 편하게 하면 코딩 실력이 늘지 않을 것이다. 또한 Makefile을 만드는데에 익숙해질 필요도 있다.

따라서 VS Code 설정파일은 위의 첨부파일에는 없다. VS Code 설정파일을 만드는 방법은 Raylib를 위한 VS Code 설정하기를 참고하자

로그인하면 댓글을 남길 수 있습니다.

raylib/tetris/gettingstarted.1766927805.txt.gz · 마지막으로 수정됨: 저자 이거니맨