-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathufo.c
More file actions
80 lines (66 loc) · 1.5 KB
/
ufo.c
File metadata and controls
80 lines (66 loc) · 1.5 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
/*
*
*/
#include <stdlib.h>
#include "rpi_lib/image.h"
#include "rpi_lib/drawing.h"
#include "ufo.h"
unsigned int ufo_image_data[2][UFO_HEIGHT] = {
{0x03C0, 0x0FF0, 0x3FFC, 0x6DB6, 0xFFFF, 0x3BDC, 0x1008,},
{0xA425, 0x524A, 0x0810, 0xC003, 0x0810, 0x524A, 0xA425,},
};
unsigned int ufo_explosion_count;
void InitializeUFO(struct UFO* ufo)
{
ufo->x = -50;
ufo->y = -50;
ufo->state = UFO_STATE_DEAD;
LoadImage(&(ufo->image[0]), ufo_image_data[0], UFO_WIDTH, UFO_HEIGHT);
LoadImage(&(ufo->image[1]), ufo_image_data[1], UFO_WIDTH, UFO_HEIGHT);
score = 10;
}
void SetUFO(struct UFO* ufo)
{
ufo->state = UFO_STATE_ALIVE;
if((rand() % 2) == 0){
ufo->dir = UFO_DIR_LEFT;
ufo->x = MAINPANEL_WIDTH + 20;
}else{
ufo->dir = UFO_DIR_RIGHT;
ufo->x = -20;
}
ufo->y = 5;
ufo_explosion_count = 0;
}
void MoveUFO(struct UFO* ufo)
{
if(ufo->state == UFO_STATE_ALIVE){
if(ufo->dir == UFO_DIR_LEFT){
ufo->x -= UFO_SPEED;
if(ufo->x < -20){
ufo->state = UFO_STATE_DEAD;
}
}else{
ufo->x += UFO_SPEED;
if(ufo->x > MAINPANEL_WIDTH + 20){
ufo->state = UFO_STATE_DEAD;
}
}
}else if(ufo->state == UFO_STATE_EXPLOSION){
if(ufo_explosion_count++ > 60){
ufo->state = UFO_STATE_DEAD;
}
}
}
void ExplosionUFO(struct UFO* ufo)
{
ufo->state = UFO_STATE_EXPLOSION;
}
void DrawUFO(struct UFO* ufo)
{
if(ufo->state == UFO_STATE_ALIVE){
DrawImage(ufo->x, ufo->y, &(ufo->image[0]), RED);
}else if(ufo->state == UFO_STATE_EXPLOSION){
DrawImage(ufo->x, ufo->y, &(ufo->image[1]), RED);
}
}