-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjogo.c
163 lines (135 loc) · 4.01 KB
/
jogo.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef _STRUCTS_H_
#define _STRUCTS_H_
typedef int bool;
#define true 1
#define false 0
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <allegro5/allegro.h>
#include <allegro5/allegro_primitives.h>
float Distancia(float x1, float x2, float y1, float y2){
return sqrtf(pow((x2 - x1), 2) + pow((y2 -y1), 2));
}
typedef struct Heroi{
const char* nome;
int ataque;
int hp;
int x, y;
int raio;
int deslocamento;
int desx;
int desy;
} Heroi;
void inicializa(Heroi *hero){
hero->nome = "Geraldo orriver";
hero->ataque = 20;
hero->hp = 100;
hero->x = 400;
hero->y = 300;
hero->raio = 20;
hero->deslocamento = 3;
hero->desx = hero->x;
hero->desy = hero->y;
}
void Destino_heroi(Heroi *hero, float destinox, float destinoy){
float taxa = hero->deslocamento/Distancia(hero->x, destinox, hero->y, destinoy);
hero->x += ((destinox-hero->x)*taxa);
hero->y += ((destinoy-hero->y)*taxa);
}
typedef struct Inimigo{
char* nome;
int hp;
int ataque;
} Inimigo;
typedef struct Boss{
char* nome;
int hp;
int ataque;
} Boss;
void draw(Heroi *hero){
al_clear_to_color(al_map_rgb(255,255,255)); //Desenha fundo da tela
if(hero->x <= hero->desx && hero->y <= hero->desy){
hero->x = hero->desx;
hero->y = hero->desy;
}
al_draw_filled_circle(hero->x, hero->y, hero->raio, al_map_rgb(255,0,255)); //Desenha heroi
}
void jogada(bool *fim, Heroi *hero){
//Para futuro uso
}
int main(){
Heroi hero;
ALLEGRO_DISPLAY *tela;
ALLEGRO_EVENT_QUEUE *eventos;
ALLEGRO_TIMER *draw_timer;
int display_w = 800;
int display_h = 600;
float fps = 60.0;
al_init();
tela = al_create_display(display_w,display_h);
eventos = al_create_event_queue();
draw_timer = al_create_timer(1.0/fps);
al_install_keyboard();
al_install_mouse();
al_init_primitives_addon();
al_register_event_source(eventos, al_get_keyboard_event_source());
al_register_event_source(eventos, al_get_mouse_event_source());
al_register_event_source(eventos, al_get_timer_event_source(draw_timer));
al_register_event_source(eventos, al_get_display_event_source(tela));
bool fim = false;
al_start_timer(draw_timer);
ALLEGRO_EVENT evento;
ALLEGRO_KEYBOARD_STATE tec_estado;
ALLEGRO_MOUSE_STATE estado;
//Inimigo inimigo[10];
inicializa(&hero);
//draw(&hero);
while(!fim){
al_wait_for_event(eventos, &evento);
switch(evento.type) {
case ALLEGRO_EVENT_TIMER:
al_get_keyboard_state(&tec_estado);
//jogada(&fim, &hero);
/*
if(al_key_down(&tec_estado, ALLEGRO_KEY_W)){
if(hero.y < 0 + hero.raio)
hero.y = hero.y;
else
hero.y -= 3;
}
if(al_key_down(&tec_estado, ALLEGRO_KEY_S)){
if(hero.y > display_h - hero.raio)
hero.y = hero.y;
else
hero.y += 3;
}
if(al_key_down(&tec_estado, ALLEGRO_KEY_A)){
if(hero.x < 0 + hero.raio)
hero.y = hero.y;
else
hero.x -= 3;
}
if(al_key_down(&tec_estado, ALLEGRO_KEY_D)){
if(hero.x > display_w - hero.raio)
hero.y = hero.y;
else
hero.x += 3;
}*/
Destino_heroi(&hero, estado.x, estado.y);
draw(&hero);
al_flip_display();
break;
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
al_get_mouse_state(&estado);
hero.desx = estado.x;
hero.desy = estado.y;
break;
case ALLEGRO_EVENT_DISPLAY_CLOSE:
fim = true;
break;
}
}
return 0;
}
#endif /*_STRUCTS_H_*/