Skip to content

A basic 2D game in which a trantula must eat all the bugs and then exit.

Notifications You must be signed in to change notification settings

maiadegraaf/so_long

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

so_long

A basic 2D game in which a trantula must eat all the bugs and then exit.

I really enjoyed this project, it was the first truely visual project that I've done. This meant the project was quite addictive as everything I added to it made quite a difference. I completed the mandatory part quite quickly but I really wanted to add animations, as well as smooth movements between each tile. This ultimately led to me completely restructuring my project as it quickly became far to slow to loop through the frames while smoothly moving across the window, but the final result meant it was all worth it 😄

Screen Shot 2022-09-27 at 1 07 21 PM

Table of Content:

Game attributes:

The player’s goal is to collect every collectible present on the map, then escape chosing the shortest possible route.

  • The W, A, S, and D or the arrow keys are used to move the main character.
  • The player is able to move in these 4 directions: up, down, left, right.
  • The player cannot move into walls.
  • At every move, the current number of movements is displayed in the shell as well as on the window.
  • The game has a top down, 2D view.
  • ESC exits the game.
  • R resets the game to the starting position.

Sprites and Assets:

The Player:

AnyConv com__0

The Collectibles:

AnyConv com__bug1 AnyConv com__bug2 AnyConv com__bug3

The Exit:

AnyConv com__hovel

The Enemy:

AnyConv com__0(1)

How it works:

The graphics are handled by a library called minilibx (MLX).

1. Parsing the map:

The program takes 1 argument; a map. The parser makes sure the file has the correct .ber filetype. It then uses get_next_line to read through the file, each line is then parsed to determine the location of the walls (1), collectables (C), the players starting position (P), the exit (E), and navicable tiles (0).

For example:

1111111111111
10010000000C1
1000011111001
1P0011E000001
1111111111111

The parser returns an error if the map:

  • doesn't include an exit, collectible, or the players starting position.
  • is not rectangula.
  • is not enclosed by walls.

2. Setting up the game:

The program then takes the information obtained by the parser, initializes all the assets in the correct location and loops through each image in order to correctly place all the asset pixels to an image which is then pushed to the window, through the use of MLX functions. Furthermore this stage also assigns number of enemies, which is randomly assigned based on the number of empty tiles in the game. This means that enemies rarely appear in smaller maps. The enemy starting positions are also determined, which is also random with the exception of walls and on the x and y axis of the player and the exit, as to not make it truly impossible.

3. Waiting for action:

As the MLX library initiates an infinite loop, the game essentially waits for the player to perform one of the actions. The enemys moves independently from the player, and an algorithm determines the direction they move in. If the player presses W, A, S, and D or the arrow keys, the program first checks if the move is possible, and if the player is on a collectible or the exit. The program then stores this information. A seperate loop constantly checks if a move has been made and then alters the location on the image pushed to the window. If the player has consumed all the collectibles and is on the exit the game goes in to end_game mode. Else, if the player gets eaten (ie touched) by an enemy the game goes into game_over mode.

Gameplay:

ezgif com-gif-maker(1) ezgif com-gif-maker

Installation:

Clone the repository

git clone https://github.com/maiadegraaf/so_long.git
cd so_long
make

Usage:

As the bonus part of this project includes some functions not allowed in the mandatory part, I had to seperate my files. As such the mandatory part does not include any enemies.

  • Easy mode: no enemies (mandatory):
    • make
  • Hard mode: *with enemies (bonus):
    • make bonus

Run

The program runs with one arguement, a file with a .ber extention. I have included a bunch of maps in ./maps/

Example:

./so_long maps/maze.ber

About

A basic 2D game in which a trantula must eat all the bugs and then exit.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published