so://phie

freezo

A retro platform game
git clone git://soophie.de/freezo

blob: c1633a27ab591b0d3af794b83b062f09e1033966 (1796 bytes)[raw]

1#include <stdlib.h>

2

3#include "../include/door.h"

4#include "../include/const.h"

5

6door_t *door_create(pos_t pos) {

7 door_t *door = malloc(sizeof(door_t));

8 door->pos = pos;

9 door->is_locked = true;

10 door->countdown = 0;

11 return door;

12}

13

14void door_update(door_t *door, game_t *game) {

15 (void) game;

16 if (door->countdown > 0) {

17 door->countdown--;

18 }

19}

20

21void door_draw(door_t *door, game_t *game) {

22 if (door->is_locked) {

23 DrawTextureRec(game->assets.tiles, texture_rect(1, 2, TILE_WIDTH, TILE_HEIGHT), (pos_t) { door->pos.x, door->pos.y - TILE_HEIGHT }, WHITE);

24 DrawTextureRec(game->assets.tiles, texture_rect(1, 3, TILE_WIDTH, TILE_HEIGHT), door->pos, WHITE);

25 if (door->countdown > 0) {

26 pos_t lock_pos = {

27 .x = door->pos.x,

28 .y = door->pos.y - 2 * TILE_HEIGHT,

29 };

30 DrawTextureRec(game->assets.tiles, texture_rect(3, 1, TILE_WIDTH, TILE_HEIGHT), lock_pos, WHITE);

31 }

32 }

33 else {

34 DrawTextureRec(game->assets.tiles, texture_rect(2, 2, TILE_WIDTH, TILE_HEIGHT), (pos_t) { door->pos.x, door->pos.y - TILE_HEIGHT }, WHITE);

35 DrawTextureRec(game->assets.tiles, texture_rect(2, 3, TILE_WIDTH, TILE_HEIGHT), door->pos, WHITE);

36 }

37}

38

39void door_free(door_t *door) {

40 free(door);

41}

42

43bool door_unlock(door_t *door, game_t *game) {

44 if (!door->is_locked) {

45 return true;

46 }

47 int enemies_len = 0;

48 bool gates_frozen = true;

49 for (int i = 0; i < game->entities_len; i++) {

50 if(game->entities[i].type == ENTITY_ENEMY) {

51 enemies_len++;

52 }

53 if(game->entities[i].type == ENTITY_GATE) {

54 if (!game->entities[i].gate->frozen) {

55 gates_frozen = false;

56 }

57 }

58 }

59 if (enemies_len == 0 && gates_frozen) {

60 door->is_locked = false;

61 return true;

62 }

63 door->countdown = DOOR_COUNTDOWN;

64 return false;

65}