/
spaceship.c
60 lines (45 loc) · 1.67 KB
/
spaceship.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
#include <stdio.h>
#include <stdlib.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
#include <allegro5/allegro_image.h>
#include "spaceship.h"
void inicializa_spaceship( SPACESHIP* spaceship, int x, int y )
{
inicializa_bitmap_spaceship(spaceship);
spaceship->altura_spaceship = DISPLAY_HEIGHT/8;//al_get_bitmap_height(spaceship->bitmap);
spaceship->largura_spaceship = DISPLAY_WIDTH/19;//al_get_bitmap_width(spaceship->bitmap);
spaceship->posicao_x = x - spaceship->largura_spaceship;
spaceship->posicao_y = y - spaceship->altura_spaceship;
spaceship->min_x = spaceship->posicao_x + DELTA_X;
spaceship->max_x = spaceship->posicao_x - DELTA_X;
spaceship->min_y = spaceship->posicao_y + DELTA_Y;
spaceship->min_y = spaceship->posicao_y;
}
void finaliza_spaceship( SPACESHIP* spaceship )
{
al_destroy_bitmap( spaceship->bitmap );
}
void desenha_spaceship( SPACESHIP* spaceship )
{
al_draw_scaled_bitmap(spaceship->bitmap,
0, 0, al_get_bitmap_width(spaceship->bitmap), al_get_bitmap_height(spaceship->bitmap),
spaceship->posicao_x, spaceship->posicao_y, DISPLAY_WIDTH/19, DISPLAY_HEIGHT/8 , 0 );
}
void inicializa_bitmap_spaceship(SPACESHIP* spaceship)
{
spaceship->bitmap = al_load_bitmap("imagens/spaceship3.png");
if( spaceship->bitmap == NULL)
{
puts( "Erro ao carregar o arquivo imagens/tank.png");
exit(0);
}
}
void move_spaceship( SPACESHIP* spaceship, int delta_x, int delta_y )
{
spaceship->posicao_x += delta_x;
spaceship->posicao_y += delta_y;
spaceship->min_x = spaceship->posicao_x + DELTA_X;
spaceship->max_x = spaceship->posicao_x - DELTA_X;
spaceship->min_y = spaceship->posicao_x + DELTA_Y;
}