-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.c
More file actions
124 lines (119 loc) · 3.02 KB
/
update.c
File metadata and controls
124 lines (119 loc) · 3.02 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include<update.h>
char player_velocity = -1;
#define tile_not_ground(tile) (tile == ' ' || tile == 'O' || tile == '$') // for falling tiles (they can collide with spikes)
#define not_ground(tile) (tile == ' ' || tile == 'O' || tile == '$' || tile == 'V' || tile == '^' || tile == '>' || tile == '<' || tile == '|' || tile == '.') // eww...
#define is_ground(tile) (tile != ' ' && tile != 'O' && tile != '$' && tile != 'V' && tile != '^' && tile != '>' && tile != '<' && tile != '|' && tile != '.')
void update_delay(){
usleep(150000);
}
char interact_level(input* player_input, level* world, unsigned int* position){
char skip = 0;
for(unsigned int block = 0; block < world->l; block++){
char tile = world->data[block];
char next;
char fall;
switch(tile){
case '<':
next = world->data[block-1];
fall = world->data[block-1+world->w];
if(is_ground(next) || not_ground(fall)){
world->data[block] = '>';
break;
}
if(next == '@')
return -1;
world->data[block] = ' ';
world->data[block-1] = '<';
break;
case '>':
if(skip){
skip = 0;
break;
}
next = world->data[block+1];
fall = world->data[block+1+world->w];
if(is_ground(next) || not_ground(fall)){
world->data[block] = '<';
break;
}
if(next == '@')
return -1;
world->data[block] = ' ';
world->data[block+1] = '>';
skip = 1;
break;
case '+':
if(world->data[block-world->w] == '@')
world->data[block] = 'x';
break;
case 'x':
world->data[block] = '-';
break;
case '-':
next = world->data[block+world->w];
if(next == '@'){
world->data[block] = ' ';
return 0; // skip the fram idk
}else
if(tile_not_ground(next)){
world->data[block] = ' ';
world->data[block+world->w] = '-';
}else
world->data[block] = ' ';
break;
case '@':
*position = block;
default:
break;
};
}
return 0;
}
char update_level(input* player_input, level* world){
unsigned int player_position = 0;
char interaction = interact_level(player_input,world,&player_position);
unsigned int new_player = player_position;
if(interaction < 0)
return -1;
// now move the player
char examine = world->data[player_position+world->w];
if(is_ground(examine)){ // refractor please
if(player_input->j){
player_velocity = 1;
player_input->j = 0;
}
}
else if(player_velocity == -1)
new_player += world->w;
if(player_velocity != -1){
player_velocity--;
examine = world->data[new_player-world->w];
if(not_ground(examine)){
new_player -= world->w;
}
}
examine = world->data[new_player+player_input->d];
if(not_ground(examine))
new_player += player_input->d;
// collectables, static spikes, goal post
switch(world->data[new_player]){
case '^':
case 'V':
case '>':
case '<':
return -1;
case 'O':
interaction = 1;
break;
case '$':
interaction = 2;
break;
case '.':
case '|':
return 3;
};
// set tile
world->data[player_position] = ' ';
world->data[new_player] = '@';
return interaction;
}