https://github.com/andezion/gnomerush
This is my small project where I want to finally try out all the features of the SDL Framework!
https://github.com/andezion/gnomerush
game gnome knight middle-earth pixel-art sdl2 sdl2-image
Last synced: about 1 month ago
JSON representation
This is my small project where I want to finally try out all the features of the SDL Framework!
- Host: GitHub
- URL: https://github.com/andezion/gnomerush
- Owner: Andezion
- License: gpl-3.0
- Created: 2024-09-01T18:27:09.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-01-16T19:46:19.000Z (4 months ago)
- Last Synced: 2025-02-15T02:42:26.024Z (3 months ago)
- Topics: game, gnome, knight, middle-earth, pixel-art, sdl2, sdl2-image
- Language: C
- Homepage:
- Size: 49 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GnomeRush
There is my little project, where I've tried to use all abilities of SDL framework.
## Table of contents
* [General info](#general-info)
* [Gameplay](#gameplay)
* [Inspiration](#inspiration)
* [Technologies](#technologies)
* [Features](#features)
* [Setup](#setup)
---
## General info
After many hours spent reading The Hobbit, The Witcher and Lord of the Rings, I decided to play out my fantasy and put it to code. So, I'm proud to show you my medieval-themed wandering game. Mages, knights, dwarves and more! Explore, check it out and find out!
I wrote the game in pure C, using SDL, based on the base. Music, graphics, plot and so on - all my own!
---
## Gameplay
Now I will show you what you can do in my game- There you can read some info about the game, sadly at this point I don't add pretty much to read, but it will appear in the nearest future!
https://github.com/Andezion/GnomeRush/assets/e25fb870-4614-41b1-ac73-63d7981098cb- There you can try to play for the wizard! I still don't add some features and gameplays moment, but at least you can test some of them!
https://github.com/Andezion/GnomeRush/assets/9c4b5083-9af3-4b22-b81a-de36cf62488chttps://github.com/Andezion/GnomeRush/assets/9cb022f7-0d73-4a2f-920e-d81195b7ed90
- And there you can try yourself as a knight!
https://github.com/Andezion/GnomeRush/assets/f4ab9419-9439-42c0-92da-b556da106dc0https://github.com/Andezion/GnomeRush/assets/641ad646-5dec-4b54-a93c-bf9bcca93e51
- If you want to end your game you will see something like that
https://github.com/Andezion/GnomeRush/assets/b50f2018-39f5-488e-b810-cde454b764c0---
## Inspiration
- Crawly The Gnome
- Stopiaż z Bałut
- Project Dupa
---
## Technologies
Project created with:
* SDL for most features
* SDL_mixer for music
* SDL_image for correcting photoes
* SDL_ttf for text usage
* Photoshop for editing photoes
* Tavern music and beer
---
## Features
First we declare some important constants, window size and player position.The interesting thing is that the level switching is done via the enum construct, which makes it much easier to switch from one screen to another:
```
typedef enum
{
MENU,
WIKI,
PICK,
GAME,
TEST,
OVER
} GameState;
```Next comes a very long and crookedly done initialisation of photos, texts, sounds and objects, and of course all this should have been put out separately and more beautifully, but! I didn't do it :(
Then again the declaration of variables for our character's animations and finally the algorithm for generating the background. Initially we create a table, filling it with values that are later responsible for a certain colour:
```
int table[100][60] = { 0 };for(int i = 0; i < 100; i += 4)
{
int temp = -2 + rand() % 4;
int effective_height = max_height + temp;
for(int j = 0; j < 60; j += 4)
{
int value = 1 + rand() % 4;for (int bi = 0; bi < 4 && i + bi < 100; bi++)
{
for (int bj = 0; bj < 4 && j + bj < 60; bj++)
{
if (j + bj < effective_height)
{
table[i + bi][j + bj] = 0;
}
else
{
table[i + bi][j + bj] = value;
}
}
}
}
}
```Once the game loop starts, we just handle some keystroke events moving the player, changing and scrolling animations.
Then, depending on the player's action, we initialise our variables indicating running, standing, attacking or whatever, so that we can understand what animation we should include.Then we clear the window and start displaying our windows, which are stored in our enum, via switch. Then we play the desired animation, and the cycle repeats while we play.
Then we clear all arrays, because in SDL it is not done automatically )).
Now about the file handler_of_screen.c,
function that draws the background, we divide the whole screen into small squares, which, depending on the value in the table, we fill with a certain colour.
The most important, the function that loads textures into the array, we run through all the frames of the animation, trying to load the file and convert it into a texture that we can already show:
```
int loadTextureArray(SDL_Renderer* renderer, const char** fileNames, int arraySize, SDL_Texture** textureArray)
{
for(int i = 0; i < arraySize; i++)
{
SDL_Surface* surface = SDL_LoadBMP(fileNames[i]);
if (surface == NULL)
{
printf("Error loading image %d: %s\n", i, SDL_GetError());
SDL_DestroyRenderer(renderer);
return 1;
}
textureArray[i] = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
if (textureArray[i] == NULL)
{
printf("Error creating texture for image %d: %s\n", i, SDL_GetError());
SDL_DestroyRenderer(renderer);
return 1;
}
}
return 0;
}
```
Next are the functions of drawing different screens, there is nothing unusual there, at the end we have a function that checks the intersection of two objects:
```
int is_intersects(SDL_Rect rect1, SDL_Rect rect2, int pick)
{
if (pick == 0)
{
if (rect2.x >= rect1.x - 130 && rect2.x <= rect1.x)
{
return 1;
}
}
else if(pick == 1)
{
if(rect2.x >= rect1.x && rect2.x <= rect1.x + 140)
{
return 1;
}
}
return 0;
}
```
All in all, this is an ending---
## Setup
Just download the recent release