Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
2c7dccb
hope we could merge it
Aug 25, 2020
66bf787
refact
Aug 25, 2020
5fb9f90
mx_scale_gate -> mx_play_game, del and move redundant funcs
Aug 25, 2020
ed2ff51
renamed olay game file
Aug 25, 2020
ed5a8c4
Add Menu. Add print in Makefile. @yakim4ik
Aug 25, 2020
3d575ef
prepare to merge menu
Aug 25, 2020
f255126
mrg conf
Aug 25, 2020
a428d78
leaderboard draft
Aug 25, 2020
ec17955
Add Menu, LeaderBoard and game play.
Aug 26, 2020
7be0c17
fonts, printint fetus
Aug 26, 2020
863a9ad
merging leaderboard and fixed btns
Aug 26, 2020
dae9447
Fix main menu and add multi player button.
Aug 26, 2020
08f0eee
Fix some fuction for Multi player.
Aug 26, 2020
65caa3a
score draft
Aug 26, 2020
ac1ff80
merging
Aug 26, 2020
b05c32a
Add MultiPlayer.
Aug 26, 2020
4c1041d
merging
Aug 26, 2020
ae12d29
Make #define for picture, font and music.
Aug 26, 2020
066e019
draft int to str
Aug 26, 2020
c66b76d
@krasovskii added the main page and the red car
Aug 26, 2020
87457b3
Merge branch 'draft' of https://github.com/ucfly/endgame into draft
Aug 26, 2020
c9bbe17
finished int to str
Aug 26, 2020
1dad710
merged
Aug 26, 2020
9fbd264
@krasovskii added red & blue cars
Aug 26, 2020
7681c41
merging
Aug 26, 2020
8a03fb2
Merge branch 'draft' of https://github.com/ucfly/endgame into draft
Aug 26, 2020
2d5439a
del bin
Aug 26, 2020
fa60bff
@tbulyha fix count
Aug 26, 2020
daf0da4
@krasovskii changed cars
Aug 26, 2020
6f091f9
Merge branch 'draft' of https://github.com/ucfly/endgame into draft
Aug 26, 2020
d0bf89d
change menus
Aug 26, 2020
f1025c7
added heart
Aug 26, 2020
4db5dac
mx_manu
Aug 26, 2020
f52ec59
fix mx_menu
Aug 26, 2020
b6945ca
mergin
Aug 26, 2020
62d8844
merging menu
Aug 26, 2020
b68642d
finished hearts, deleted some comments, changed window name
Aug 26, 2020
e6ca5da
fix leaderbord
Aug 26, 2020
6884cd3
Merge branch 'illia' of https://github.com/ucfly/endgame into draft
Aug 26, 2020
cea0244
added animation
Aug 26, 2020
9efb6ff
fixed multic
Aug 26, 2020
40c1e0b
fixed green counter
Aug 26, 2020
9f370d7
travis test
Aug 26, 2020
b968cf2
travis
Aug 26, 2020
3815063
travis
Aug 26, 2020
43779b6
fixed colors
Aug 26, 2020
018da62
added orange car
Aug 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*.swo
main_check.c
.vscode/**/*
./endgame

6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ======== variables ========

# -- files and dirs --
NAME = game
NAME = endgame

INC_DIR = inc
SRC_DIR = src
Expand All @@ -13,7 +13,7 @@ FFLAGS = -F ./resource/frameworks -framework SDL2 -rpath ./resource/frameworks \
-F ./resource/frameworks -framework SDL2_ttf -rpath ./resource/frameworks \
-F ./resource/frameworks -framework SDL2_mixer -rpath ./resource/frameworks \

# INC_FILES = $(wildcard $(INC_DIR)/*.h)
INC_FILES = $(wildcard $(INC_DIR)/*.h)
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)

# -- commands --
Expand All @@ -31,8 +31,10 @@ all: $(NAME)

$(NAME): $(SRC_FILES) $(INC_DIR) $(REC_DIR)
@$(CC) $(C_FLAGS) $(FFLAGS) $(SRC_FILES) -I $(INC_DIR) -o $(NAME)
@printf "\r\33[2K$@\t \033[32;1mcreated\033[0m\n"

uninstall:
@$(RM) $(NAME)
@printf "\r\33[2K$(NAME)\t \033[32;1mdeleted\033[0m\n"

reinstall: uninstall all
Binary file removed game
Binary file not shown.
Binary file removed img/sound_off.png
Binary file not shown.
Binary file removed img/sound_on.png
Binary file not shown.
129 changes: 111 additions & 18 deletions inc/game.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,56 @@
#pragma once

// defines
#define MX_GRAVITY 0.02f
// === defines ===
#define MX_WIND_W 1600
#define MX_WIND_H 1000
#define MX_PLANE_W 300
#define MX_PLANE_H 100
#define MX_RING_L 0

#define MX_GRAVITY 0.02f

#define MX_RING_L 5
#define MX_RING_W 40
#define MX_RING_H 40 +120

#define MX_RANDOM_X ((rand() % (MX_WIND_W + 1 - 0)) +0)
#define MX_RANDOM_Y ((rand() % (MX_WIND_H + 1 - 0)) +0)

#define MX_PLANE_W 300/2
#define MX_PLANE_H 240/2
#define MX_PLANE_ST_X (MX_WIND_W / 2 - MX_PLANE_W / 2)
#define MX_PLANE_ST_Y (MX_WIND_H / 2 - MX_PLANE_H / 2)
// #define MX_PLANE_ST_Y

#define MX_BTN_W 300
#define MX_BTN_H 60
#define MX_BTN_X ((MX_WIND_W - MX_BTN_W) / 2)
#define MX_BTN_Y (MX_WIND_H / 2 - MX_BTN_H)
#define HEART_SIZE 30
#define GAME_LIFE 3

#define MX_R_MENU 0
#define MX_R_GAME 1
#define MX_R_OVER 2
#define MX_R_BOARD 3
#define MX_R_EXIT -1

#define HEART "resource/img/heart.png"
#define HEART_EMPTY "resource/img/heart_empty.png"

#define CIRCLE "resource/img/circles/circle_orange.png"
#define CIRCLE2 "resource/img/circles/circle_green.png"

#define PLANE "resource/img/car_orange.png"
#define PLANE2 "resource/img/car_green.png"

#define BACKGROUND_IMG "resource/img/space_bg.jpg"

#define FONT_MAIN "resource/font/Sansation-Bold.ttf"
#define MUSIC_MENU "resource/audio/space_oddity.mp3"

// colors
#define BLACK {0, 0, 0, 0}
#define WHITE {255, 255, 255, 0}
#define TEAL {10, 128, 128, 0}
#define ORANGE {255, 100, 0, 0}
#define GREEN {144, 178, 71, 0}

// includes
#include <SDL2_image/SDL_image.h>
Expand All @@ -29,47 +68,101 @@
#include <unistd.h>
#include <time.h>

typedef enum e_scenestatus {
MENU_STATE,
GAME_STATE,
GAMEOVER_STATE,
MULTIPLAYER_STATE,
LEADERBOARD_STATE,
EXIT_STATE
} e_scenes;

// structs
// TODO razobratsia s tipami na rayone

typedef struct s_calculation {
int temp;
int dec;
int rem;
int size;
int i;
} t_calculation;

typedef struct s_world {
float x;
float y;
float w;
float h;
float cnt;
int cnt;
float dy;
} t_world;
int dw;
int life;

} t_world;


typedef struct s_state {
// objects
t_world plane;
t_world plane2;
t_world gate;
t_world gate2;
t_world space;
t_world heart;
t_world heart_empty;

// imgs
SDL_Texture *bg;
SDL_Texture *car;
SDL_Texture *gate_img[2];
SDL_Texture *car2;
SDL_Texture *gate_img;
SDL_Texture *gate2_img;
SDL_Texture *heart_img;
SDL_Texture *heart_empty_img;
SDL_Texture *life_img;

SDL_Renderer *renderer;
Mix_Music *bg_music;
TTF_Font *font;

int play;
int exit;

e_scenes status;

} t_state;

// funcs
char *mx_strcpy(char *dst, const char *src);

void mx_do_render(SDL_Renderer *rend, t_state *game);
void mx_do_render_mult(SDL_Renderer *rend, t_state *game);

void mx_play_game(t_state *game);
void mx_play_game_mult(t_state *game);

void mx_load_game(t_state *game);

int mx_strlen(const char *s);
int mx_process_events(SDL_Window *window, t_state *game);
int mx_check_pass(t_state *game);
int mx_check_pass(t_world *gate, t_world *plane);

void mx_err_check(void *target);
void mx_printerr(const char *s);
void mx_do_render(SDL_Renderer *rend, t_state *game);
void mx_scale_gate(t_state *game);
void mx_scale_car(t_state *game, int direction);
void mx_load_game(t_state *game);
void process(t_state *game);
void mx_is_over(t_world *plane);
void mx_scale_car(t_world *plane);
void mx_scale_gate(t_world *gate);
void mx_gravitation (t_world *plane);

char *mx_int_to_str(int n);
void mx_initial_state(t_world *gate, t_world *plane);


e_scenes mx_menu(SDL_Renderer *renderer);
e_scenes mx_leaderboard(SDL_Renderer *renderer);
e_scenes mx_game(SDL_Window *window, t_state *game);
e_scenes mx_multiplayer(SDL_Window *window, t_state *game);
e_scenes mx_gameover(SDL_Renderer *renderer);



void mx_draw_text( SDL_Color color, int x, int y, char *text,
SDL_Renderer *renderer, TTF_Font *font);

Binary file modified resource/audio/space_oddity.mp3
Binary file not shown.
Binary file removed resource/audio/space_sampel.mp3
Binary file not shown.
Binary file added resource/font/Russo_One.ttf
Binary file not shown.
Binary file added resource/font/Sansation-Bold.ttf
Binary file not shown.
Binary file removed resource/img/Car-Back-Red-icon.png
Binary file not shown.
Binary file added resource/img/GameOver.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resource/img/buttons/exit.png
Binary file not shown.
Binary file removed resource/img/buttons/restart.png
Binary file not shown.
Binary file removed resource/img/buttons/resume.png
Binary file not shown.
Binary file removed resource/img/buttons/rocket.png
Binary file not shown.
Binary file removed resource/img/buttons/start.png
Binary file not shown.
Binary file added resource/img/car_blue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/img/car_green.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/img/car_orange.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resource/img/circle.png
Binary file not shown.
Binary file removed resource/img/circle_green .png
Binary file not shown.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file removed resource/img/cropped_car.png
Binary file not shown.
Binary file added resource/img/empty.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/img/empty_back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/img/heart.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resource/img/heart_empty.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed resource/img/main_page1.png
Binary file not shown.
Binary file removed resource/img/minio.bmp
Binary file not shown.
Binary file removed resource/img/new_red_car.png
Diff not rendered.
Binary file removed resource/img/space_car.png
Diff not rendered.
Binary file removed resource/img/star.png
Diff not rendered.
Binary file removed resource/img/starfield_1922x1037.jpg
Diff not rendered.
62 changes: 42 additions & 20 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,71 @@
int main(void) {
t_state game;
SDL_Window *wind = NULL;
SDL_Renderer *rend = NULL;
int quit;
// SDL_Renderer *rend = NULL;
// int quit;

SDL_Init(SDL_INIT_EVERYTHING);
IMG_Init(IMG_INIT_PNG | IMG_INIT_JPG);
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 2048);
SDL_ShowCursor(SDL_DISABLE);
TTF_Init();

if (SDL_Init(SDL_INIT_VIDEO)) {
mx_printerr("ne paluchilos");
exit(1);
}

wind = SDL_CreateWindow("Kuku", SDL_WINDOWPOS_UNDEFINED,
wind = SDL_CreateWindow("πLot", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, MX_WIND_W, MX_WIND_H, 0);

rend = SDL_CreateRenderer(
game.renderer = SDL_CreateRenderer(
wind, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
game.renderer = rend;

mx_load_game(&game);

quit = 0;
srand(time(0));

Mix_PlayMusic(game.bg_music, -1);

while (!quit) {
quit = mx_process_events(wind, &game);
game.status = MENU_STATE;
game.exit = 0;
srand(time(0));

mx_scale_gate(&game);
// mx_collision_detect(rend, &game);
game.play = MX_R_MENU;

process(&game);
while (!game.exit) {

mx_do_render(game.renderer, &game);
switch (game.status) {
case MENU_STATE:
game.status = mx_menu(game.renderer);
break;
case GAME_STATE:
game.status = mx_game(wind, &game);
break;
case GAMEOVER_STATE:
game.status = mx_gameover(game.renderer);
break;
case MULTIPLAYER_STATE:
game.status = mx_multiplayer(wind, &game);
break;
case LEADERBOARD_STATE:
game.status = mx_leaderboard(game.renderer);
break;
case EXIT_STATE:
game.exit = 1;
break;
}
}

SDL_DestroyTexture(game.bg);
SDL_DestroyTexture(game.car);
SDL_DestroyTexture(game.car2);
SDL_DestroyTexture(game.gate_img);
SDL_DestroyTexture(game.gate2_img);
SDL_DestroyTexture(game.heart_img);
SDL_DestroyTexture(game.heart_empty_img);
SDL_DestroyTexture(game.life_img);

SDL_DestroyWindow(wind);
SDL_DestroyRenderer(game.renderer);

IMG_Quit();
TTF_Quit();
Mix_CloseAudio();
TTF_CloseFont(game.font);
SDL_Quit();

return 0;
Expand Down
25 changes: 10 additions & 15 deletions src/mx_check_pass.c
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
#include "game.h"
int mx_check_pass(t_state *game) {
float pl_max_x = game->plane.x + game->plane.w;
float pl_max_y = game->plane.y + game->plane.h;

float gt_in_max_x = game->gate.x - MX_RING_L + game->gate.w - MX_RING_L;
float gt_in_max_y = game->gate.y - MX_RING_L + game->gate.h - MX_RING_L;
int mx_check_pass(t_world *gate, t_world *plane) {
float pl_max_x = plane->x + plane->w;
float pl_max_y = plane->y + plane->h;

if (game->plane.x > game->gate.x && pl_max_x < gt_in_max_x) {
if (game->plane.y > game->gate.y && pl_max_y < gt_in_max_y) {
return -1;
float gt_in_max_x = gate->x - MX_RING_L + gate->w - MX_RING_L;
float gt_in_max_y = gate->y - MX_RING_L + gate->h - MX_RING_L;

if (plane->x > gate->x && pl_max_x < gt_in_max_x) {
if (plane->y > gate->y && pl_max_y < gt_in_max_y) {
return 1;
}
}
return 1;
return -1;
}


// TODO music && sfx
// TODO dying
// TODO wings ???
// TODO consts and responcive scaling
31 changes: 22 additions & 9 deletions src/mx_do_render.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "game.h"

void mx_do_render(SDL_Renderer *rend, t_state *game) {

SDL_SetRenderDrawColor(rend, 4, 21, 66, 1);
SDL_RenderClear(rend);

Expand All @@ -11,19 +10,13 @@ void mx_do_render(SDL_Renderer *rend, t_state *game) {
game->space.h};
SDL_RenderCopy(rend, game->bg, NULL, &bg_rect);

// SDL_SetRenderDrawColor(rend, 25, 50, 200, 255);
// SDL_Rect tor_pb = {game->gate.x + MX_RING_L ,
// game->gate.y + 10,
// game->gate.w - MX_RING_L*2,
// game->gate.h -20};
// SDL_RenderFillRect(rend, &tor_pb);

SDL_SetRenderDrawColor(rend, 25, 50, 200, 255);
SDL_Rect tor_p = {game->gate.x,
game->gate.y,
game->gate.w,
game->gate.h};
SDL_RenderCopy(rend, game->gate_img[0], NULL, &tor_p);
// SDL_RenderFillRect(rend, &tor_p);
SDL_RenderCopy(rend, game->gate_img, NULL, &tor_p);

SDL_SetRenderDrawColor(rend, 250, 50, 20, 0);
SDL_Rect plane_p = {game->plane.x,
Expand All @@ -32,5 +25,25 @@ void mx_do_render(SDL_Renderer *rend, t_state *game) {
game->plane.h};
// SDL_RenderFillRect(rend, &plane_p);
SDL_RenderCopy(rend, game->car, NULL, &plane_p);

for (int i = GAME_LIFE; i > 0; i--) {
int heart_x = HEART_SIZE + HEART_SIZE * i;
game->life_img = (i <= game->plane.life)
? game->heart_img
: game->heart_empty_img;

SDL_Rect heart_p = {heart_x, HEART_SIZE * 2, HEART_SIZE, HEART_SIZE};
SDL_RenderCopy(rend, game->life_img, NULL, &heart_p);
}

SDL_Color score_color = ORANGE;

char *score = mx_int_to_str(game->plane.cnt);
mx_draw_text(score_color, 20, 20, "SCORE: ", game->renderer, game->font);
mx_draw_text(score_color, 120, 20, score, game->renderer, game->font);
free(score);
score = NULL;

SDL_RenderPresent(rend);
}

Loading