-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
146 lines (116 loc) · 5.17 KB
/
main.cpp
File metadata and controls
146 lines (116 loc) · 5.17 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
140
141
142
143
144
#include "FishManager.h"
#include "player.h"
#include "raylib.h"
#include <cmath>
#include <iostream>
#define WINDOW_WIDTH 1280
#define WINDOW_HEIGHT 720
#define WORLD_WIDTH 4000
#define WORLD_HEIGHT 4000
#define CAMERA_MIN 0.05
#define CAMERA_MAX 70000
#define PLAYER_MOD 0.3
#define SHRIMP_MOD 0.75
#define BASS_MOD 0.5
#define LEVIATHAN_MOD 0.4
// Draws the ocean floor graphic
void DrawOceanFloor() {
constexpr float step = 5.0f;
constexpr float amplitude = 40.0f;
constexpr float frequency = 0.01f;
for (int i = 0; i < 4250; i += step) {
const float x = static_cast<float>(i);
const float y = 200 + WORLD_HEIGHT + sinf(i * frequency) * amplitude;
DrawLineEx({x, y}, {x, y-250}, 5.0f, WHITE);
}
}
Rectangle RawTextureSize(const Texture2D &texture) {
return Rectangle(0, 0, texture.width, texture.height);
}
Rectangle FinalTextureSize(const Texture2D &texture, const float mod, Vector2 position) {
return Rectangle(position.x, position.y, static_cast<float>(texture.width) * mod, static_cast<float>(texture.height) * mod);
}
Vector2 textureCenter(const Texture2D &texture, const float mod) {
return Vector2(texture.width * mod / 2.0f, texture.height * mod / 2.0f);
}
int main() {
// Initialize
// Initialize Window
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "Cpp_Sample");
// Initialize Assets
Image icon = LoadImage("assets/icon.png");
Texture2D angler = LoadTexture("assets/player.png");
Texture2D shrimp = LoadTexture("assets/shrimp.png");
Texture2D bass = LoadTexture("assets/bass.png");
Texture2D leviathan_head = LoadTexture("assets/levia_head.png");
Texture2D leviathan_body = LoadTexture("assets/levia_body.png");
Texture2D leviathan_tail = LoadTexture("assets/levia_tail.png");
Rectangle shrimpSize = RawTextureSize(shrimp);
Rectangle bassSize = RawTextureSize(bass);
Rectangle leviathanHeadSize = RawTextureSize(leviathan_head);
Rectangle leviathanBodySize = RawTextureSize(leviathan_body);
Rectangle leviathanTailSize = RawTextureSize(leviathan_tail);
SetWindowIcon(icon);
UnloadImage(icon);
// Initialize objects
Player player(WORLD_WIDTH, WORLD_HEIGHT);
FishManager manager(WORLD_WIDTH, WORLD_HEIGHT);
// Initialize camera
Camera2D camera = { 0 };
camera.target = textureCenter(angler, 0.2f);
camera.offset = { WINDOW_WIDTH / 2.0f, WINDOW_HEIGHT / 2.0f };
camera.rotation = 0.0f;
camera.zoom = 0.75f;
SetTargetFPS(120);
// Game loop
while (!WindowShouldClose()) {
// Update
const float deltaTime = GetFrameTime();
player.Update(camera, deltaTime);
manager.Update();
/*camera.zoom += (GetMouseWheelMove()*0.05f);
if (camera.zoom > CAMERA_MAX) camera.zoom = CAMERA_MAX;
else if (camera.zoom < CAMERA_MIN) camera.zoom = CAMERA_MIN;*/
// Flip player sprite if facing right
Rectangle playerRect = RawTextureSize(angler);
if (std::abs(player.rotation) > 90) {
playerRect.height = - playerRect.height;
}
// Draw
BeginDrawing();
ClearBackground(BLACK);
// Draw world space
BeginMode2D(camera);
// Draw world box
// DrawRectangle(0, 0, WORLD_WIDTH, WORLD_HEIGHT, RED);
// Draw player
DrawTexturePro(angler, playerRect, FinalTextureSize(angler, PLAYER_MOD, player.position), textureCenter(angler, PLAYER_MOD), player.rotation, WHITE);
//Draw NPCs
std::vector<std::unique_ptr<Fish>>& allNPCs = manager.GetAllNPCs();
// Draw shrimp
for (int i = 0; i < 100; i++) {
DrawTexturePro(shrimp, shrimpSize, FinalTextureSize(shrimp, SHRIMP_MOD, allNPCs[i]->position), textureCenter(shrimp, SHRIMP_MOD), allNPCs[i]->rotation, WHITE);
}
// Draw bass
for (int i = 100; i < 125; i++) {
DrawTexturePro(bass, bassSize, FinalTextureSize(bass, BASS_MOD, allNPCs[i]->position), textureCenter(bass, BASS_MOD), allNPCs[i]->rotation, WHITE);
}
// Draw leviathan
DrawTexturePro(leviathan_tail, leviathanTailSize, FinalTextureSize(leviathan_tail, LEVIATHAN_MOD, allNPCs[130]->position), textureCenter(leviathan_tail, LEVIATHAN_MOD), allNPCs[130]->rotation, WHITE);
for (int i = 126; i < 130; i++) {
DrawTexturePro(leviathan_body, leviathanBodySize, FinalTextureSize(leviathan_body, LEVIATHAN_MOD, allNPCs[i]->position), textureCenter(leviathan_body, LEVIATHAN_MOD), allNPCs[i]->rotation, WHITE);
}
DrawTexturePro(leviathan_head, leviathanHeadSize, FinalTextureSize(leviathan_head, LEVIATHAN_MOD, allNPCs[125]->position), textureCenter(leviathan_head, LEVIATHAN_MOD), allNPCs[125]->rotation, WHITE);
// Draw floor
DrawOceanFloor();
EndMode2D();
EndDrawing();
}
UnloadTexture(angler);
UnloadTexture(shrimp);
UnloadTexture(bass);
UnloadTexture(leviathan_head);
UnloadTexture(leviathan_body);
UnloadTexture(leviathan_tail);
CloseWindow();
}