aboutsummaryrefslogtreecommitdiff
path: root/src/pipe.c
blob: ff9656d6bfc922982cf37efce405ec7cffddf4f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "pipe.h"
#include "defines.h"

inline void pipe_init(Pipe *pipe) {
  set_sprite_tile(pipe->sprite_ids[PIPE_TILE_TOP_LEFT],
                  PIPE_TILE_START + CAP_LEFT);
  set_sprite_prop(pipe->sprite_ids[PIPE_TILE_TOP_LEFT], S_FLIPY);

  set_sprite_tile(pipe->sprite_ids[PIPE_TILE_TOP_MIDDLE],
                  PIPE_TILE_START + CAP_MIDDLE);
  set_sprite_prop(pipe->sprite_ids[PIPE_TILE_TOP_MIDDLE], S_FLIPY);

  set_sprite_tile(pipe->sprite_ids[PIPE_TILE_TOP_RIGHT],
                  PIPE_TILE_START + CAP_LEFT);
  set_sprite_prop(pipe->sprite_ids[PIPE_TILE_TOP_RIGHT], S_FLIPX | S_FLIPY);

  set_sprite_tile(pipe->sprite_ids[PIPE_TILE_BOTTOM_LEFT],
                  PIPE_TILE_START + CAP_LEFT);

  set_sprite_tile(pipe->sprite_ids[PIPE_TILE_BOTTOM_MIDDLE],
                  PIPE_TILE_START + CAP_MIDDLE);

  set_sprite_tile(pipe->sprite_ids[PIPE_TILE_BOTTOM_RIGHT],
                  PIPE_TILE_START + CAP_LEFT);
  set_sprite_prop(pipe->sprite_ids[PIPE_TILE_BOTTOM_RIGHT], S_FLIPX);

  for (UINT8 i = 6; i < 16; i++) {
    set_sprite_tile(pipe->sprite_ids[i], PIPE_TILE_START + MAIN_LEFT);
  }
  for (UINT8 i = 16; i < 26; i++) {
    set_sprite_tile(pipe->sprite_ids[i], PIPE_TILE_START + MAIN_MIDDLE);
  }
  for (UINT8 i = 26; i < 36; i++) {
    set_sprite_tile(pipe->sprite_ids[i], PIPE_TILE_START + MAIN_LEFT);
    set_sprite_prop(pipe->sprite_ids[i], S_FLIPX);
  }
}

inline void pipe_scroll_horizontal(Pipe *pipe, ScreenCoordinate x) {
  pipe->x += x;
  for (UINT8 i = 36; i != 0; i--) {
    scroll_sprite(pipe->sprite_ids[i - 1], x, 0);
  }
}

inline void pipe_move_gap_height(Pipe *pipe, UINT8 gap_height) {
  pipe->height_of_gap = gap_height;
  for (UINT8 i = 0; i < gap_height; i++) {
    move_sprite(pipe->sprite_ids[i + 4], pipe->x, i * TILE_SIZE);
    move_sprite(pipe->sprite_ids[i + 14], pipe->x + TILE_SIZE, i * TILE_SIZE);
    move_sprite(pipe->sprite_ids[i + 24], pipe->x + TILE_SIZE + TILE_SIZE,
                i * TILE_SIZE);
  }
  move_sprite(pipe->sprite_ids[PIPE_TILE_TOP_LEFT], pipe->x,
              gap_height * TILE_SIZE);
  move_sprite(pipe->sprite_ids[PIPE_TILE_TOP_MIDDLE], pipe->x + TILE_SIZE,
              gap_height * TILE_SIZE);
  move_sprite(pipe->sprite_ids[PIPE_TILE_TOP_RIGHT],
              pipe->x + TILE_SIZE + TILE_SIZE, gap_height * TILE_SIZE);

  move_sprite(pipe->sprite_ids[PIPE_TILE_BOTTOM_LEFT], pipe->x,
              (gap_height + pipe->gap_skip) * TILE_SIZE);
  move_sprite(pipe->sprite_ids[PIPE_TILE_BOTTOM_MIDDLE], pipe->x + TILE_SIZE,
              (gap_height + pipe->gap_skip) * TILE_SIZE);
  move_sprite(pipe->sprite_ids[PIPE_TILE_BOTTOM_RIGHT],
              pipe->x + TILE_SIZE + TILE_SIZE,
              (gap_height + pipe->gap_skip) * TILE_SIZE);

  for (UINT8 i = gap_height; i < (16 - pipe->gap_skip); i++) {
    move_sprite(pipe->sprite_ids[i + 4], pipe->x,
                (i + pipe->gap_skip + 1) * TILE_SIZE);
    move_sprite(pipe->sprite_ids[i + 14], pipe->x + TILE_SIZE,
                (i + pipe->gap_skip + 1) * TILE_SIZE);
    move_sprite(pipe->sprite_ids[i + 24], pipe->x + TILE_SIZE + TILE_SIZE,
                (i + pipe->gap_skip + 1) * TILE_SIZE);
  }
}

inline void pipe_hide(Pipe *pipe) {
  pipe->x += 0;
  for (UINT8 i = 36; i != 0; i--) {
    move_sprite(pipe->sprite_ids[i - 1], 0, 0);
  }
}