-
Notifications
You must be signed in to change notification settings - Fork 2
/
asteroid.c
75 lines (65 loc) · 1.39 KB
/
asteroid.c
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
#include "asteroid.h"
/*
Cria a estrutura do asteroide
parameters: void
return: ASTEROID
*/
ASTEROID *createAsteroid(unsigned short x, unsigned short y){
ASTEROID *asteroid = (ASTEROID*) calloc(1, sizeof(ASTEROID));
if(asteroid){
asteroid->body = 2;
asteroid->position = createPosition();
asteroid->position->x = x;
asteroid->position->y = y;
}
return asteroid;
}
/*
Renderiza asteroide na tela
parameters: void
return: void
*/
void renderAsteroid(ASTEROID *asteroid){
if(asteroid){
gotoXY(asteroid->position->x, asteroid->position->y);
printf("%c", asteroid->body);
}
}
/*
Função que limpa o asteroide da tela
parameters: ASTEROID *asteroid
return: void
*/
void clearAsteroid(ASTEROID *asteroid){
if(asteroid){
gotoXY(asteroid->position->x, asteroid->position->y);
printf(" ");
}
}
/*
Atualiza posição do asteroide
parameters: void
return: bool
*/
bool updateAsteroid(ASTEROID *asteroid, unsigned short height){
if(asteroid){
clearAsteroid(asteroid);
asteroid->position->y++;
renderAsteroid(asteroid);
return (asteroid->position->y >= height);
}
return false;
}
/*
Limpa o console
parameters: unsigned short width, unsigned short height
return: void
*/
void clearConsole(unsigned short width, unsigned short height){
for(unsigned short l = 0; l < width; l++){
for(unsigned short c = 0; c < height; c++){
gotoXY(l, c);
printf(" ");
}
}
}