Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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

4 changes: 3 additions & 1 deletion 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 Down Expand Up @@ -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 added endgame
Binary file not shown.
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.
81 changes: 65 additions & 16 deletions inc/game.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,38 @@
#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 150
#define MX_BTN_X ((MX_WIND_W - MX_BTN_W) / 2)
#define MX_BTN_Y (MX_WIND_H / 2 - MX_BTN_H)
#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

// colors
#define TEAL {10, 128, 128, 0}
#define ORANGE {255, 100, 0, 0}

// includes
#include <SDL2_image/SDL_image.h>
Expand All @@ -29,47 +50,75 @@
#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_world {
float x;
float y;
float w;
float h;
float cnt;
int cnt;
float dy;
} t_world;
int dw;
char *hello;
int life;

} t_world;


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

// imgs
SDL_Texture *bg;
SDL_Texture *car;
SDL_Texture *gate_img[2];
SDL_Texture *car2;
SDL_Texture *gate_img;
SDL_Texture *gate2_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);

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

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_play_game(t_state *game);
void mx_load_game(t_state *game);
void process(t_state *game);


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/Sansation-Bold.ttf
Binary file not shown.
Binary file modified resource/frameworks/SDL2_image.framework/Versions/A/SDL2_image
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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 added resource/img/button.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/buttons/button.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/buttons/cursor.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/buttons/exit_hover.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/buttons/restart_hover.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/buttons/resume_hover.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/buttons/start_hover.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_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 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 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/end_game.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/game_background/Background1.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/game_background/Background2.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/game_background/Background3.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/main_page.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 modified resource/img/space_car.png
Binary file added resource/img/space_car2.png
Binary file added resource/img/space_car_.png
59 changes: 40 additions & 19 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +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);
TTF_Init();

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

wind = SDL_CreateWindow("Kuku", 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);
// printf("GAME OWER!!!");
break;
case MULTIPLAYER_STATE:
game.status = mx_multiplayer(wind, &game);
// printf("GAME OWER!!!");
break;
case LEADERBOARD_STATE:
game.status = mx_leaderboard(game.renderer);
// printf("LEADERBOARD!!!");
break;
case EXIT_STATE:
game.exit = 1;
printf("EXIT");
break;
}
printf("\n kuku: %d", game.exit);
}

SDL_DestroyTexture(game.bg);
SDL_DestroyTexture(game.car);
SDL_DestroyTexture(game.gate_img);
SDL_DestroyWindow(wind);
SDL_DestroyRenderer(game.renderer);

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

system("leaks -q game");
return 0;
}
21 changes: 0 additions & 21 deletions src/mx_check_pass.c

This file was deleted.

23 changes: 12 additions & 11 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,26 +10,28 @@ 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,
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,
game->plane.y,
game->plane.w,
game->plane.h};
// SDL_RenderFillRect(rend, &plane_p);
SDL_RenderFillRect(rend, &plane_p);
SDL_RenderCopy(rend, game->car, NULL, &plane_p);

// TTF_CloseFont(game->font);

SDL_Color score_color = ORANGE;
mx_draw_text(score_color, 20, 20, "SCORE: ", game->renderer, game->font);
mx_draw_text(score_color, 120, 20, game->plane.hello, game->renderer,
game->font);

SDL_RenderPresent(rend);
}
14 changes: 14 additions & 0 deletions src/mx_draw_text.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "game.h"

void mx_draw_text(SDL_Color color, int x, int y, char *text,
SDL_Renderer *renderer, TTF_Font *font) {
SDL_Surface *text_surface = TTF_RenderText_Solid(font, text, color);
SDL_Texture *textureGameName =
SDL_CreateTextureFromSurface(renderer, text_surface);
SDL_Rect text_rect = {x, y, 1, 1};
SDL_QueryTexture(textureGameName, NULL, NULL, &text_rect.w, &text_rect.h);
SDL_RenderCopy(renderer, textureGameName, NULL, &text_rect);
SDL_FreeSurface(text_surface);
text_surface = 0;
SDL_DestroyTexture(textureGameName);
}
9 changes: 0 additions & 9 deletions src/mx_err_check.c

This file was deleted.

Loading