Com DEPLOY NA WEB!
Nesse vídeo fizemos uma animação com C++ e Raylib similar a essa que mostramos há um tempo atrás.
No final fizemos o DEPLOY na WEB.
Assista ao Vídeo
Códigos criado no vídeo
solarsystem.hpp
#pragma once
#include "raylib.h"
#include
#include
#include
class SolarSystem {
const float sun_size = 60.f;
Vector2 window, center;
std::vector planet_radius, planet_sizes,
planet_velocities, planet_angle;
std::vector colors;
const float moon_size = 5, moon_radius = 30,
moon_velocity = 10;
float moon_angle;
int earth_pos;
bool fullscreen;
public:
SolarSystem();
void run();
};
solarsystem.cpp
#include "solarsystem.hpp"
SolarSystem::SolarSystem(){
window = {1920, 1080};
InitWindow(window.x, window.y, "Solar System");
SetTargetFPS(60);
center = {GetScreenWidth() / 2.f, GetScreenHeight() / 2.f};
planet_radius = {80, 110, 165, 225, 310, 430, 515, 565};
planet_velocities = {1.607f, 1.174f, 1.f, 0.802f, 0.434f, 0.323f, 0.228f, 0.182f};
planet_sizes = {10, 15, 20, 18, 60, 55, 25, 22};
colors = {
{115, 147, 179, 255},
{255, 87, 51, 255},
{30, 144, 255, 255},
{178, 34, 34, 255},
{210, 105, 30, 255},
{220, 20, 60, 255},
{72, 209, 204, 255},
{65, 105, 225, 255}
};
planet_angle.assign(8, 0);
moon_angle = {0};
for(size_t i = 0; i < planet_sizes.size();++i){
if(planet_sizes[i] == 20){
earth_pos = i;
}
}
fullscreen = {false};
}
void SolarSystem::run(){
while (!WindowShouldClose()){
if(IsKeyPressed(KEY_F11)){
fullscreen = !fullscreen;
if(fullscreen){
int monitor = GetCurrentMonitor();
SetWindowSize(GetMonitorWidth(monitor), GetMonitorHeight(monitor));
ToggleFullscreen();
}else{
ToggleFullscreen();
SetWindowSize(window.x, window.y);
}
}
for(size_t i = 0; i < planet_radius.size(); ++i){
planet_angle[i] += planet_velocities[i] * 0.02f;
}
moon_angle += moon_velocity * 0.009f;
BeginDrawing();
ClearBackground(BLACK);
DrawCircleV(center, sun_size, YELLOW);
for(size_t i = 0; i < planet_radius.size(); ++i){
DrawRing(center, planet_radius[i] - 1, planet_radius[i] + 1, 0, 360, 100, Color{60, 60, 60, 255});
Vector2 planet_pos = {
center.x + std::cos(planet_angle[i]) * planet_radius[i],
center.y + std::sin(planet_angle[i]) * planet_radius[i]
};
DrawCircleV(planet_pos, planet_sizes[i], colors[i]);
if((int)i == earth_pos){
DrawRing(planet_pos, moon_radius - 1, moon_radius + 1, 0, 360, 100, Color{60, 60, 60, 255});
Vector2 moon_pos = {
planet_pos.x + std::cos(moon_angle) * moon_radius,
planet_pos.y + std::sin(moon_angle) * moon_radius,
};
DrawCircleV(moon_pos, moon_size, WHITE);
}
}
EndDrawing();
}
CloseWindow();
}
main.cpp
#include "solarsystem.hpp"
int main(){
auto obj = std::make_unique();
obj->run();
return 0;
}
build.ter
auto flags = "-g -Wall -Werror -Wpedantic -fsanitize=address"
flags = "-O3 -ffast-math"
auto build = "g++ " + flags + " *.cpp -lraylib -lGL -lm -lpthread -ldl -lrt -lX11"
output(build)
exec(build)
exec("./a.out >/dev/null")
Links úteis
- 👑 Aprenda a criar sua própria linguagem de programação
- ✅ Aprenda Criação de Games com C++ e SFML
- ✅ Pacote Promocional C++
- ✅ Aprenda C++ e Qt
- ✅ Conheça nossos Cursos
- 🎁 Todos os Cursos na Udemy
- Rodando na Web
- https://terminalroot.com.br/2021/04/sistema-solar-feito-com-html-css-e-javascript-puro.html
- https://terminalroot.com.br/2022/11/crie-jogos-para-windows-linux-e-web-com-raylib-c-cpp.html
- https://terminalroot.com.br/2024/11/como-instalar-raylib-com-suporte-para-web.html
- https://github.com/terroo/terlang
👀 Veja também:)
- 🔗 Como 'hackear' a linguagem de programação Ter/Terlang
- 🔗 Os 10 Melhores Livros de Programação de Todos os Tempos
- 🔗 10 livros sobre Inteligência Artificial para Programadores
- 🔗 Conheça 8 flags para melhorar drasticamente a velocidade do seu software
- 🔗 Como Automatizar Criptografia com script C++
- 🔗 5 Extensões para VSCode independente da Linguagem de Programação
- 🔗 7 Exemplos de Uso do PowerShell
- 🔗 Série Go: Uma abordagem sobre a Linguagem de Programação Golang)