Skip to content

Commit 30ff06b

Browse files
committed
Праска хуй
1 parent e0492ba commit 30ff06b

File tree

5 files changed

+72
-27
lines changed

5 files changed

+72
-27
lines changed

chort.c

+23-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
SDL_Texture *texture_robot[4];
55

66
const char *robot[4] = {"../Sprites/robot1.bmp", "../Sprites/robot2.bmp", "../Sprites/robot1.bmp", "../Sprites/robot3.bmp"};
7+
78
struct chort_t spawn_chort(SDL_Rect base)
89
{
910
struct chort_t chort;
@@ -14,7 +15,7 @@ struct chort_t spawn_chort(SDL_Rect base)
1415
chort.chort.w = dupka + 10;
1516
chort.num = 0;
1617
chort.dead = 0;
17-
chort.speed = 2 /*rand() % 2 + 1*/;
18+
chort.speed = 2;
1819
return chort;
1920
}
2021

@@ -94,7 +95,8 @@ int loadTextureArray(SDL_Renderer* renderer, const char** fileNames, int arraySi
9495
return 0;
9596
}
9697

97-
int update_chort(SDL_Rect castle, struct chort_t *chort, int mousepressed){
98+
int update_chort(SDL_Rect castle, SDL_Renderer *renderer, struct chort_t *chort, int mousepressed)
99+
{
98100
if (chort->dead)
99101
{
100102
return 0;
@@ -105,14 +107,15 @@ int update_chort(SDL_Rect castle, struct chort_t *chort, int mousepressed){
105107
}
106108

107109
SDL_Point mouse;
108-
if (mousepressed) {
110+
if (mousepressed)
111+
{
109112
SDL_GetMouseState(&mouse.x, &mouse.y);
110113
if (contains(chort->chort, mouse))
111114
{
112115
chort->dead = 1;
113-
114116
}
115117
}
118+
116119
SDL_Point kierunek = find_path(castle, chort);
117120
chort->chort.x += kierunek.x * chort->speed;
118121
chort->chort.y += kierunek.y * chort->speed;
@@ -124,11 +127,26 @@ void draw_chort(SDL_Renderer *r, struct chort_t *chort)
124127
{
125128
if (chort->dead)
126129
{
130+
int blood_width = 30;
131+
int blood_height = 30;
132+
133+
int blood_x = chort->chort.x + chort->chort.w / 2 - blood_width / 2;
134+
int blood_y = chort->chort.y + chort->chort.h / 2 - blood_height / 2;
135+
136+
SDL_Rect blood_rect = {blood_x, blood_y, blood_width, blood_height};
137+
138+
SDL_Surface *died = SDL_LoadBMP("../Sprites/oil.bmp");
139+
SDL_Texture *ded = SDL_CreateTextureFromSurface(r, died);
140+
SDL_FreeSurface(died);
141+
SDL_RenderCopy(r, ded, NULL, &blood_rect);
142+
SDL_DestroyTexture(ded);
127143
return;
128144
}
145+
129146
loadTextureArray(r, robot, 4, texture_robot);
130147
SDL_RenderCopy(r, texture_robot[chort->num % 4], NULL, &chort->chort);
131-
for (int i = 0; i < 4; ++i) {
148+
for (int i = 0; i < 4; ++i)
149+
{
132150
SDL_DestroyTexture(texture_robot[i]);
133151
}
134152
chort->num = (chort->num + 1) % 4;

chort.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ int contains(SDL_Rect r, SDL_Point p);
1717

1818
SDL_Point find_path(SDL_Rect castle, struct chort_t * chort);
1919

20-
int update_chort(SDL_Rect castle, struct chort_t *chort, int mousepressed) ;
20+
int update_chort(SDL_Rect castle, SDL_Renderer *renderer, struct chort_t *chort, int mousepressed);
2121

22-
void draw_chort(SDL_Renderer* r, struct chort_t * chort);
22+
void draw_chort(SDL_Renderer *r, struct chort_t *chort);
2323

2424
int loadTextureArray(SDL_Renderer* renderer, const char** fileNames, int arraySize, SDL_Texture** textureArray);
2525

main.c

+23-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <stdio.h>
33
#include <stdlib.h>
44
#include <SDL_image.h>
5-
#include <SDL_ttf.h>
5+
#include <SDL2\SDL_ttf.h>
66
#include "chort.h"
77
#include "man.h"
88

@@ -15,7 +15,7 @@ int MAXCHORTAMOUNT = 32;
1515
unsigned long long timeStart;
1616
unsigned long long timeFromSpawn;
1717

18-
size_t ochko_andreja = 0;
18+
int ochko_andreja = 0;
1919

2020
enum STATE {mainMenu, game, gameOver};
2121

@@ -169,7 +169,7 @@ void drawMainObjects(SDL_Renderer *renderer)
169169

170170
}
171171
char num[255] = {0};
172-
sprintf(num, "%4zu", ochko_andreja);
172+
sprintf(num, "%4i", ochko_andreja);
173173
SDL_Surface* pointsurface = TTF_RenderText_Solid(f, num, (SDL_Color) {255, 255, 255, 0});
174174
SDL_Texture* txt = SDL_CreateTextureFromSurface(renderer, pointsurface);
175175
SDL_Rect r = {700, 0, 100, 50};
@@ -180,14 +180,13 @@ void drawMainObjects(SDL_Renderer *renderer)
180180
}
181181

182182

183-
void drawMainMenu(SDL_Renderer *renderer, SDL_Texture *logo, SDL_Texture *start, SDL_Texture *cat)
183+
void drawMainMenu(SDL_Renderer *renderer, SDL_Texture *logo, SDL_Texture *start)
184184
{
185185
SDL_Rect LogoPos = {200, 10, 480,32};
186186
SDL_RenderCopy(renderer, logo, NULL, &LogoPos);
187187
SDL_Rect StartPos = {160, 100, 480,32};
188188
SDL_RenderCopy(renderer, start, NULL, &StartPos);
189-
SDL_Rect CatPos = {160, 142, 480,480};
190-
SDL_RenderCopy(renderer, cat, NULL, &CatPos);
189+
191190
}
192191

193192
void drawGameOver(SDL_Renderer *renderer, SDL_Texture *gameOver, SDL_Texture *restartScreen)
@@ -260,13 +259,11 @@ int main(int argc, char *argv[])
260259
SDL_Texture *cursorTexture = NULL;
261260
SDL_Texture *logo = NULL;
262261
SDL_Texture *start = NULL;
263-
SDL_Texture *cat = NULL;
264262
SDL_Texture *gameOverScreen = NULL;
265263
SDL_Texture *restarScreen = NULL;
266264
loadTexture(&cursorTexture, renderer, "../Sprites/Coursor.png");
267265
loadTexture(&logo, renderer, "../Sprites/Team Logo.png");
268266
loadTexture(&start, renderer, "../Sprites/StartGame.png");
269-
loadTexture(&cat, renderer, "../Sprites/cat.png");
270267
loadTexture(&gameOverScreen, renderer, "../Sprites/GameOver.png");
271268
loadTexture(&restarScreen, renderer, "../Sprites/PressRToRestart.png");
272269

@@ -285,6 +282,11 @@ int main(int argc, char *argv[])
285282

286283
for (int i = 0; i < man_num; i++) {
287284
if (mane[i].dead && ((rand() % 100) == 0)) {
285+
ochko_andreja -= 2 * 5;
286+
mane[i] = spawn_man(bases, rand() & 4);
287+
}
288+
if (mane[i].is_home && ((rand() % 100) == 0)) {
289+
ochko_andreja += 5;
288290
mane[i] = spawn_man(bases, rand() & 4);
289291
}
290292
}
@@ -318,22 +320,28 @@ int main(int argc, char *argv[])
318320
}
319321

320322

321-
switch (state) {
323+
switch (state)
324+
{
322325
case mainMenu:
323326
//state = game;
324327
SDL_RenderClear(renderer);
325-
drawMainMenu(renderer, logo, start, cat);
328+
drawMainMenu(renderer, logo, start);
326329
drawCoursor(renderer, cursorTexture);
327330
SDL_RenderPresent(renderer);
328331
break;
329332
case game:
330-
for (int i = 0; i < cherti_num; ++i) {
331-
if (update_chort((SDL_Rect) {350, 250, 80, 80}, cherti + i, mouse_pressed))
333+
for (int i = 0; i < cherti_num; ++i)
334+
{
335+
if (update_chort((SDL_Rect) {350, 250, 80, 80}, renderer, cherti + i, mouse_pressed))
336+
{
332337
state = gameOver;
338+
}
333339
}
334-
for (int i = 0; i < man_num; ++i) {
335-
if (update_man((SDL_Rect) {350, 250, 80, 80}, mane + i, mouse_pressed)) {
336-
mane[i].dead = 1;
340+
for (int i = 0; i < man_num; ++i)
341+
{
342+
if (update_man((SDL_Rect) {350, 250, 80, 80}, mane + i, mouse_pressed))
343+
{
344+
//mane[i].dead = 1;
337345
}
338346
}
339347

@@ -367,7 +375,6 @@ int main(int argc, char *argv[])
367375
SDL_DestroyTexture(cursorTexture);
368376
SDL_DestroyTexture(logo);
369377
SDL_DestroyTexture(start);
370-
SDL_DestroyTexture(cat);
371378
SDL_DestroyTexture(gameOverScreen);
372379
SDL_DestroyTexture(restarScreen);
373380
IMG_Quit();

man.c

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include "man.h"
22
#include "chort.h"
3-
#include <stdio.h>
43

54
SDL_Texture *texture_man[4];
65
const char *man[4] = {"../Sprites/man1.bmp", "../Sprites/man2.bmp", "../Sprites/man1.bmp", "../Sprites/man3.bmp"};
@@ -25,13 +24,14 @@ struct man_t spawn_man(SDL_Rect* base, int num)
2524
nextbase = (base + 0);
2625
}
2726

28-
2927
struct man_t mane;
3028
mane.man = base[num];
31-
mane.man.h = 35;
32-
mane.man.w = 55;
29+
int pop = 40 + rand() % 10;
30+
mane.man.h = pop;
31+
mane.man.w = pop + 10;
3332
mane.num = 0;
3433
mane.dead = 0;
34+
mane.is_home = 0;
3535
mane.base = nextbase;
3636
return mane;
3737
}
@@ -78,6 +78,7 @@ int update_man(SDL_Rect castle, struct man_t *mane, int mousepressed)
7878

7979
if(intersect(*mane->base, mane->man))
8080
{
81+
mane->is_home = 1;
8182
return 1;
8283
}
8384

@@ -94,13 +95,31 @@ int update_man(SDL_Rect castle, struct man_t *mane, int mousepressed)
9495
SDL_Point kierunek = find_path_man(mane);
9596
mane->man.x += kierunek.x * 2;
9697
mane->man.y += kierunek.y * 2;
98+
9799
return 0;
98100
}
99101

100102
void draw_man(SDL_Renderer *r, struct man_t *mane)
101103
{
104+
if(mane->is_home)
105+
{
106+
return;
107+
}
102108
if(mane->dead)
103109
{
110+
int blood_width = 30;
111+
int blood_height = 30;
112+
113+
int blood_x = mane->man.x + mane->man.w / 2 - blood_width / 2;
114+
int blood_y = mane->man.y + mane->man.h / 2 - blood_height / 2;
115+
116+
SDL_Rect blood_rect = {blood_x, blood_y, blood_width, blood_height};
117+
118+
SDL_Surface *died = SDL_LoadBMP("../Sprites/blood.bmp");
119+
SDL_Texture *ded = SDL_CreateTextureFromSurface(r, died);
120+
SDL_FreeSurface(died);
121+
SDL_RenderCopy(r, ded, NULL, &blood_rect);
122+
SDL_DestroyTexture(ded);
104123
return;
105124
}
106125
loadTextureArray(r, man, 4, texture_man);

man.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct man_t
77
SDL_Rect man;
88
SDL_bool dead;
99
int num;
10+
int is_home;
1011
SDL_Rect* base;
1112
};
1213

0 commit comments

Comments
 (0)