Created
May 5, 2022 12:24
-
-
Save alexmaryin/441f43a6aa6b97e30d642cf742162669 to your computer and use it in GitHub Desktop.
starfield_cpp_1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Star | |
{ | |
float x, y, z, radius, brightness, viewX, viewY; | |
Star() { newStar(); } | |
void newStar() | |
{ | |
x = viewX = std::experimental::randint(0, WIDTH) - H_WIDTH; | |
y = viewY = std::experimental::randint(0, HEIGHT) - H_HEIGHT; | |
z = 256; | |
brightness = 0.0; | |
radius = 1.0; | |
} | |
bool isOffScreen() | |
{ | |
return z <= 0 || viewX <= -H_WIDTH || viewY <= -H_HEIGHT || viewX >= H_WIDTH || viewY >= H_HEIGHT; | |
} | |
void processStar() | |
{ | |
viewX = std::round(x * 256 / z); | |
viewY = std::round(y * 256 / z); | |
z -= speed; | |
radius += radius_delta; | |
if (isOffScreen()) { newStar(); } | |
if (brightness < 256) { brightness += 0.15; } | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment