Skip to content

Commit 236a2a0

Browse files
committed
Add sofa 3x3 obstacles in level 2
1 parent 2202ecc commit 236a2a0

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed

resources/sofa_set.png

7.62 KB
Loading

screens/screen_game.c

+33-10
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern int characterIdx;
1313
extern int tauntIdx;
1414

1515
#define MAX_LIVES 20
16-
#define LEVEL_CHANGE_SCORE 100
16+
#define LEVEL_CHANGE_SCORE 400
1717

1818
static double OBSTACLE_PROBABILITY = 0.02;
1919
static Vector2 playerPosition = {0};
@@ -42,6 +42,7 @@ static Texture2D button = {0};
4242
static Camera2D camera = {0};
4343
Texture2D grassland = {0};
4444
Texture2D household = {0};
45+
Texture2D sofaset = {0};
4546

4647
Music oof = {0};
4748
Music gameOST = {0};
@@ -282,14 +283,22 @@ void InitGameScreen(void) {
282283
Image image = LoadImage("resources/char.png");
283284
ImageResizeNN(&image, image.width * 4, image.height * 4);
284285
player = LoadTextureFromImage(image);
286+
UnloadImage(image);
285287

286288
Image grasslandImage = LoadImage("resources/grassland.png");
287289
ImageResizeNN(&grasslandImage, grasslandImage.width * 4, grasslandImage.height * 4);
288290
grassland = LoadTextureFromImage(grasslandImage);
291+
UnloadImage(grasslandImage);
289292

290293
Image householdImage = LoadImage("resources/household.png");
291294
ImageResizeNN(&householdImage, householdImage.width * 4, householdImage.height * 4);
292295
household = LoadTextureFromImage(householdImage);
296+
UnloadImage(householdImage);
297+
298+
Image sofasetImage = LoadImage("resources/sofa_set.png");
299+
ImageResizeNN(&sofasetImage, sofasetImage.width * 4, sofasetImage.height * 4);
300+
sofaset = LoadTextureFromImage(sofasetImage);
301+
UnloadImage(sofasetImage);
293302

294303
playerSpriteWidth = player.width / 10;
295304
playerSpriteHeight = player.height / 20;
@@ -1157,6 +1166,7 @@ void UnloadGameScreen(void) {
11571166
UnloadTexture(button9);
11581167
UnloadTexture(button);
11591168
UnloadTexture(player);
1169+
UnloadTexture(sofaset);
11601170
UnloadMusicStream(oof);
11611171
UnloadMusicStream(gameOST);
11621172
UnloadMusicStream(click);
@@ -1305,16 +1315,29 @@ void DrawObstaclesHome(void) {
13051315
int dy = y - vy * 3;
13061316
assert(dx < 3);
13071317
assert(dy < 3);
1308-
int oj = dx;
1309-
int oi = 18 + dy;
13101318

1311-
Rectangle obstacleRect =
1312-
{.x = 16 * 4 * oj, .y = 16 * 4 * oi, .width = 16 * 4, .height = 16 * 4};
1313-
DrawTextureRec(
1314-
household,
1315-
obstacleRect,
1316-
(Vector2){x * playerSpriteWidth, y * playerSpriteHeight},
1317-
WHITE);
1319+
int choice = rng_u64((uint64_t)vy << 31 | vx) % 5;
1320+
if (choice < 3) {
1321+
int oj = choice * 3 + dx;
1322+
int oi = dy;
1323+
Rectangle obstacleRect =
1324+
{.x = 16 * 4 * oj, .y = 16 * 4 * oi, .width = 16 * 4, .height = 16 * 4};
1325+
DrawTextureRec(
1326+
sofaset,
1327+
obstacleRect,
1328+
(Vector2){x * playerSpriteWidth, y * playerSpriteHeight},
1329+
WHITE);
1330+
} else {
1331+
int oj = dx;
1332+
int oi = 18 + dy;
1333+
Rectangle obstacleRect =
1334+
{.x = 16 * 4 * oj, .y = 16 * 4 * oi, .width = 16 * 4, .height = 16 * 4};
1335+
DrawTextureRec(
1336+
household,
1337+
obstacleRect,
1338+
(Vector2){x * playerSpriteWidth, y * playerSpriteHeight},
1339+
WHITE);
1340+
}
13181341
} else {
13191342
int oi = 23 + obstacleType / 8;
13201343
int oj = obstacleType % 8;

0 commit comments

Comments
 (0)