forked from SardinhaK/Projetinho
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
139 lines (97 loc) · 3.54 KB
/
main.c
File metadata and controls
139 lines (97 loc) · 3.54 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
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
#include <raylib.h>
#include <stdio.h>
#include <math.h>
// gostasse?
float d2(Vector2 a, Vector2 b) {
return ((a.x - b.x) * (a.x - b.x)) + ((a.y - b.y) * (a.y - b.y));
}
int main() {
SetConfigFlags(FLAG_VSYNC_HINT);
InitWindow(0, 0, "raylib [core] example - mouse input");
if (!IsWindowFullscreen()) ToggleFullscreen();
const int screenWidth = GetScreenWidth();
const int screenHeight = GetScreenHeight();
const float W2 = screenWidth / 2.0f;
const float H2 = screenHeight / 2.0f;
Texture ff_img = LoadTexture("assets/ff.png");
Texture chico_img = LoadTexture("assets/chico1.png");
Sound song = LoadSound("assets/yes-baby.wav");
InitAudioDevice();
SetMasterVolume(0.2f);
int playing = 0;
printf("%f, %f\n", W2, H2);
Vector2 player = {.x = 10.0f, .y = 10.0f};
const float pspeed = 250.0f;
Camera2D camera = {.offset = {screenWidth / 2.0f, screenHeight / 2.0f},
.target = {0},
.rotation = 0,
.zoom = 1};
SetTargetFPS(60);
double time = GetTime();
char buf[500] = {0};
float dprev = 0.0f;
while (!WindowShouldClose() && !IsKeyPressed(KEY_CAPS_LOCK)) {
double delta = GetTime() - time;
time = GetTime();
if (IsKeyDown(KEY_W)) {
player.y -= pspeed * delta;
}
if (IsKeyDown(KEY_S)) {
player.y += pspeed * delta;
}
if (IsKeyDown(KEY_D)) {
player.x += pspeed * delta;
}
if (IsKeyDown(KEY_A)) {
player.x -= pspeed * delta;
}
float camd =
d2(camera.target, (Vector2){.x = player.x, .y = player.y}) / 100.0f;
float dDelta = abs(camd - dprev);
float err = camd + (dDelta * 10.0f);
if (err > 80.0f) {
camera.target.x += ((player.x) - camera.target.x) * 0.005;
camera.target.y += ((player.y) - camera.target.y) * 0.005;
}
dprev = camd;
BeginDrawing();
ClearBackground(RAYWHITE);
sprintf(buf, "%02.02f, cam: (%02.02f, %02.0f2), p (%02.02f, %02.02f)",
err, camera.target.x, camera.target.y, player.x, player.y);
if(playing) DrawText("Yes baby", 10, 50, 15, RED);
DrawText(buf, 10, 10, 20, DARKGRAY);
BeginMode2D(camera);
DrawCircle(0, 0, 10, BLUE);
DrawRectangle(player.x, player.y, 40, 40, RED);
DrawText(
"Este círculo azul é o centro do mundo.\nUse WASD para se "
"movimentar...",
10, 10, 20, DARKGRAY);
DrawText("Este mundo é a sua tela, o código é a sua tinta.", 700, 10,
20, DARKGRAY);
DrawTexture(ff_img, 1400, 100, WHITE);
DrawText("Você pode usar imagens.", 1400, 10,
20, DARKGRAY);
int par = ((int)GetTime())%2;
DrawTextureRec(chico_img, (Rectangle) {256 * par, 0, 256, 256 }, (Vector2){2100, 100}, WHITE);
DrawText("Animações???", 2100, 10,
20, DARKGRAY);
if(!playing && player.x > 1800) {
PlaySound(song);
playing = 1;
}
DrawText("Música?", 2700, 10,
20, DARKGRAY);
DrawText("Projeto de IP OwO", 3200, 10,
40, BLACK);
DrawText("Estamos ansiosos para ver\no que vocês vão criar.", 3200, 70,
30, BLUE);
EndMode2D();
EndDrawing();
}
UnloadTexture(chico_img);
UnloadTexture(ff_img);
CloseAudioDevice();
CloseWindow();
return 0;
}