-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProblema2.c
125 lines (93 loc) · 3.64 KB
/
Problema2.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
#include "raylib.h"
#define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 600
typedef struct {
Vector2 Posicao;
Vector2 Tamanho;
int Municao;
int Vidas;
int Pontos;
bool left;
bool right;
bool up;
bool down;
} Jogador;
void init(Jogador*);
void update(Jogador *jog, Texture2D tanquePlayer, Rectangle sourceRec, Rectangle destRec, Vector2 origin);
void draw(Jogador, Texture2D tanquePlayer, Rectangle sourceRec, Rectangle destRec, Vector2 origin);
int main(void) {
Jogador jog;
InitWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Meu jogador");
init(&jog);
//texturas
Texture2D tanquePlayer = LoadTexture("./public/tanque_player_menor.png");
int frameWidth = tanquePlayer.width;
int frameHeight = tanquePlayer.height;
// Source rectangle (part of the texture to use for drawing)
Rectangle sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight};
// Destination rectangle (screen rectangle where drawing part of texture)
Rectangle destRec = { SCREEN_WIDTH/2.0f, SCREEN_HEIGHT/2.0f, frameWidth*2.0f, frameHeight*2.0f};
// Origin of the texture (rotation/scale point), it's relative to destination rectangle size
Vector2 origin = { (float)frameWidth, (float)frameHeight };
Vector2 Posicao = {(float)SCREEN_WIDTH/2.0f, (float)SCREEN_HEIGHT/2.0f};
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) { // Detect window close button or ESC key
update(&jog, tanquePlayer, sourceRec, destRec, origin);
draw(jog, tanquePlayer, sourceRec, destRec, origin);
}
CloseWindow();
return 0;
}
void init (Jogador *jog){
jog->Posicao = (Vector2) {
(float)SCREEN_WIDTH/2, (float)SCREEN_HEIGHT/2
};
jog->Tamanho = (Vector2){
50, 50
};
}
void update (Jogador *jog, Texture2D tanquePlayer, Rectangle sourceRec, Rectangle destRec, Vector2 origin) {
if (IsKeyDown(KEY_RIGHT) && jog->Posicao.x+jog->Tamanho.x < SCREEN_WIDTH) {
DrawTexturePro(tanquePlayer, sourceRec, destRec, origin, (float)90, RAYWHITE);
jog->Posicao.x = jog->Posicao.x + 3.5;
jog->right = true;
jog->left = false;
jog->up = false;
jog->down = false;
}
else if (IsKeyDown(KEY_LEFT) && jog->Posicao.x >= 0){
DrawTexturePro(tanquePlayer, sourceRec, destRec, origin, (float)270, RAYWHITE);
jog->Posicao.x = jog->Posicao.x - 3.5;
jog->right = false;
jog->left = true;
jog->up = false;
jog->down = false;
}
else if (IsKeyDown(KEY_UP) && jog->Posicao.y >= 0){
DrawTexturePro(tanquePlayer, sourceRec, destRec, origin, (float)0, RAYWHITE);
jog->Posicao.y = jog->Posicao.y - 3.5;
jog->right = false;
jog->left = false;
jog->up = true;
jog->down = false;
}
else if (IsKeyDown(KEY_DOWN) && jog->Posicao.y+jog->Tamanho.y < SCREEN_HEIGHT){
DrawTexturePro(tanquePlayer, sourceRec, destRec, origin, (float)180, RAYWHITE);
jog->Posicao.y = jog->Posicao.y + 3.5;
jog->right = false;
jog->left = false;
jog->up = false;
jog->down = true;
}
else{
DrawTexturePro(tanquePlayer, sourceRec, destRec, origin, (float)90, RAYWHITE);
}
}
void draw (Jogador jog, Texture2D tanquePlayer, Rectangle sourceRec, Rectangle destRec, Vector2 origin) {
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexturePro(tanquePlayer, sourceRec, destRec, origin, (float)90, RAYWHITE);
EndDrawing();
}