Skip to content

JeongRon/42_so_long

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

10 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

42_so_long / 2D Game ํ”„๋กœ๊ทธ๋žจ ๋งŒ๋“ค๊ธฐ ๐ŸŽˆ


0. Introduction

  • This project is a very small 2D game.

  • The playerโ€™s goal is to collect every collectible present on the map, then escape

  • Library : MiniLibX (school graphical library)

    • This library was developed internally and includes basic necessary tools to open a window, create images and deal with keyboard and mouse events.
  • Skills : window management, event handling, colors, textures, and so forth.

ScreenShot

map

HOW TO USE ?

  1. git clone repository
  2. type this command in terminal : make
  3. execute so_long file in terminal : ./so_long maps/valid_42.ber


1. so_long ๊ตฌ์ƒ

  1. mainํ•จ์ˆ˜ ์‹คํ–‰ ์‹œ, argc argv๋ฅผ ํ†ตํ•ด map ํŒŒ์ผ๊ฒฝ๋กœ ์ •๋ณด ์ฃผ๊ธฐ
        ./so_long maps/big_map.ber
    • ๋งต ํ•˜๋‚˜๋งŒ ์ž…๋ ฅ ๋ฐ›์•˜๋Š”์ง€ ํ™•์ธ (ac = 2)
    • ํ™•์žฅ์ž .ber์ธ์ง€ ํ™•์ธ (av[1] ํ™•์ธ)
    • ์ฃผ์–ด์ง„ ๊ฒฝ๋กœ์— ์œ„์น˜ํ•œ map ํŒŒ์ผ ์˜คํ”ˆํ•ด์„œ ์˜ค๋ฅ˜ ์—†๋Š”์ง€ ์ฒดํฌ
  2. fd๋ฅผ readํ•ด์„œ 1์ฐจ์› ๋ฐฐ์—ด ๋งŒ๋“ค๊ธฐ
    • ๋งŒ๋“œ๋Š” ๋„์ค‘, map์— ๋Œ€ํ•œ ๊ทœ์น™ ์–ด๊ธ‹๋‚˜๋Š” ๊ฒƒ ์žˆ๋Š”์ง€ ํ™•์ธ
    /* 
    ์˜ˆ์™ธ ์‚ฌํ•ญ ์ฒ˜๋ฆฌ ํ•  ๊ฒƒ๋“ค
        1. ์ด์ƒํ•œ ๋ฌธ์ž ๋‚˜์˜ฌ ์‹œ ์ฒ˜๋ฆฌ, 
        2. ์ถœ๊ตฌ ํ•˜๋‚˜์ธ์ง€ ํ™•์ธ, 
        3. ์‹œ์ž‘ ์ง€์  ํ•˜๋‚˜์ธ์ง€ ํ™•์ธ, 
        4. ์ˆ˜์ง‘ํ’ˆ 0๊ฐœ์ธ์ง€ ํ™•์ธ, 
        5. ์ง€๋„๊ฐ€ ์ง์‚ฌ๊ฐํ˜•์ธ์ง€ ํ™•์ธ
        6. ์ง€๋„๊ฐ€ ๋ฒฝ์œผ๋กœ ๋‘˜๋Ÿฌ์‹ธ์—ฌ ์žˆ์ง€ ์•Š์€ ๊ฒฝ์šฐ 
        7. ์ง€๋„์— ์œ ํšจํ•œ ๊ฒฝ๋กœ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ (์ž…๊ตฌ -> ์ˆ˜์ง‘ํ’ˆ ๋ชจ๋‘ GET -> ์ถœ๊ตฌ)) 
    */
  3. ๋งŒ๋“  1์ฐจ์› ๋ฐฐ์—ด์„ mlxํ•ด์„œ map ๋งŒ๋“ค๊ธฐ
  4. key ๋ˆ„๋ฅผ ๋•Œ ๋งˆ๋‹ค ๋ฐ›๊ณ  -> ๋ณ€๊ฒฝ -> ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ธฐ

2. so_long ๊ตฌํ˜„

so_long.c

  • int main(int ac, char **av)
    1. so_long ์ค€๋น„๋‹จ๊ณ„
      • int check_ac_av(int ac, char *av)
      • void initialize_map_info(t_check_map *info)
    2. so_long ๋งต ์ฝ๊ธฐ๋‹จ๊ณ„
      • char *read_map(int fd, t_check_map *info)
    3. so_long ๋งต ์ฒดํฌ๋‹จ๊ณ„
      • int check_map_cnt(t_check_map *info)
      • int check_map_wall(char *map, t_check_map info, int index)
      • int check_map_dfs(char *map, t_check_map *info)
    4. so_long mlx ๋‹จ๊ณ„
      • void run_mlx(t_check_map *map)

(1) so_long_ready.c (์ค€๋น„๋‹จ๊ณ„)

  • int check_ac_av(int ac, char *av)
    • ac, av ์•Œ๋งž๊ฒŒ ์™”๋Š”์ง€ ์ฒดํฌํ•˜๋Š” ํ•จ์ˆ˜
  • void initialize_map_info(t_check_map *info)
    • map_info ๊ตฌ์กฐ์ฒด ์ดˆ๊ธฐํ™”ํ•˜๋Š” ํ•จ์ˆ˜

(2) so_long_read.c (์ง€๋„ ์ฝ๊ธฐ๋‹จ๊ณ„)

  • char *read_map(int fd, t_check_map *info)
    • map์„ readํ•ด์„œ 1์ฐจ์› ๋ฐฐ์—ด๋กœ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜๋กœ ์ €๋ฒˆ ๊ณผ์ œ์—์„œ ๋งŒ๋“  GNL์„ ํ™œ์šฉ
      • get_next_line.c / get_next_line_utils.c (GNL ์ฝ”๋“œ)

(3) so_long_check.c (์ง€๋„ ์ฒดํฌ๋‹จ๊ณ„)

  • int check_map_cnt(t_check_map *info)
    • 'C' ์ˆ˜์ง‘ํ’ˆ์ด 1๊ฐœ ์ด์ƒ์ธ์ง€, 'E' ์ถœ๊ตฌ๊ฐ€ 1๊ฐœ์ธ์ง€, 'P' ์ถœ๋ฐœ์ ์ด 1๊ฐœ์ธ์ง€ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜
  • int check_map_wall(char *map, t_check_map info, int index)
    • ์ง€๋„๊ฐ€ '1' ๋ฒฝ์œผ๋กœ ๋‘˜๋Ÿฌ์‹ธ์—ฌ ์žˆ๋Š”์ง€ ํ™•์ธ ํ•˜๋Š” ํ•จ์ˆ˜
  • int check_map_dfs(char *map, t_check_map *info)
    • ['P' ์ถœ๋ฐœ -> 'C' ๋ชจ๋“  ์ˆ˜์ง‘ํ’ˆ -> 'E' ์ถœ๊ตฌ] ๊ณผ์ •์ด ์ด๋ฃจ์–ด์งˆ ์ˆ˜ ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ํ•จ์ˆ˜

(4) so_long_screen.c / so_long_event.c (mlx ๋‹จ๊ณ„)

  • void run_mlx(t_check_map *map)
    • mlx๋ฅผ ์‹คํ–‰ ๋ฐ ์œ ์ง€ ์‹œํ‚ค๋Š” ํ•จ์ˆ˜
  • ๊ฒŒ์ž„ ์‹œ์ž‘ ๋ฐ ํ™”๋ฉด ๋„์šฐ๋Š” ์ฝ”๋“œ : so_long_screen.c ํŒŒ์ผ์— ๋ถ„๋ฅ˜
  • ๊ฒŒ์ž„ ์‹คํ–‰ ์ค‘, ์ด๋ฒคํŠธ ๋ฐœ์ƒ ์‹œ ์ฒ˜๋ฆฌํ•ด์•ผ ํ•  ์ฝ”๋“œ : so_long_event.c ํŒŒ์ผ์— ๋ถ„๋ฅ˜

About

2D Game ๋งŒ๋“ค๊ธฐ ๐ŸŽˆ

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published