upd gitignore, add snowflakes

This commit is contained in:
nullifiedcat 2017-04-28 19:16:58 +03:00
parent fd5555d380
commit 69aa47e39b
10 changed files with 156 additions and 1 deletions

2
.gitignore vendored
View File

@ -1,5 +1,5 @@
*.d
*.o
!res/
/bin/*
!res/bin/*
/core

BIN
res/bin/snowflake.o Normal file

Binary file not shown.

BIN
res/snowflake.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 220 B

View File

@ -21,6 +21,7 @@
#include <atomic>
#include <cmath>
#include <iomanip>
#include <list>
#include <fstream>
#include <set>
#include <unordered_map>

102
src/gui/ncc/Background.cpp Normal file
View File

@ -0,0 +1,102 @@
/*
* Background.cpp
*
* Created on: Apr 28, 2017
* Author: nullifiedcat
*/
#include "Menu.hpp"
namespace menu { namespace ncc {
Background::Background() : CBaseWidget("nc_background"), snowflake_texture(&_binary_snowflake_start, 16, 16) {
SetSize(draw::width, draw::height);
}
static CatVar snowflake_chance(CV_INT, "gui_snowflake_chance", "10", "Snowflake Spawn Rate", "Defines snowflake spawn rate (HAS TO BE NONZERO!)", 1.0f, 100.0f);
static CatVar snowflake_pack_size(CV_INT, "gui_snowflake_pack_size", "10", "Snowflake Max Pack", "Defines max snowflake spawn pack size (HAS TO BE NONZERO!)", 1.0f, 100.0f);
static CatVar snowflake_safe(CV_INT, "gui_snowflake_safe_zone", "100", "Snowflake Safe Zone", "Defines snowflake safe zone (they will decay after reaching that point)", 0.0f, 400.0f);
static CatVar snowflake_gravity(CV_FLOAT, "gui_snowflake_gravity", "0.9", "Snowflake Gravity", "Defines snowflake gravity (HAS TO BE NONZERO!)", 0.01f, 5.0f);
static CatVar snowflake_jittering(CV_INT, "gui_snowflake_jittering", "2", "Snowflake Jittering", "Defines snowflake jittering amount", 0.0f, 10.0f);
static CatVar snowflake_jittering_chance(CV_INT, "gui_snowflake_jittering_chance", "60", "Snowflake Jittering Rate", "Defines snowflake jittering rate (HAS TO BE NONZERO!)", 1.0f, 20.0f);
void Background::Update() {
Snowflake* current = list;
while (current) {
Snowflake* next = current->next;
current->Update();
if (current->dead) {
KillSnowflake(current);
}
current = next;
}
if (!(rand() % (int)snowflake_chance)) {
for (int i = 0; i < rand() % (int)snowflake_pack_size; i++) MakeSnowflake();
}
}
Background::~Background() {
Snowflake* current = list;
while (current) {
Snowflake* next = current->next;
delete current;
current = next;
}
}
void Background::Draw(int x, int y) {
if (!snowflake_texture.id) {
snowflake_texture.Load();
}
Snowflake* current = list;
while (current) {
Snowflake* next = current->next;
if (!current->show_in) {
int color = colors::white;
if (current->y > (int)snowflake_safe) {
color = colors::Create(255, 255, 255, ((int)snowflake_safe + 255) - current->y);
}
snowflake_texture.Draw((int)current->x, (int)current->y, 16, 16, color);
}
current = next;
}
}
void Background::MakeSnowflake() {
Snowflake* flake = new Snowflake();
flake->x = RandFloatRange(0, draw::width);
flake->y = 3 - (rand() % 6);
flake->dead = false;
flake->next = nullptr;
flake->show_in = rand() % 4;
if (list_tail)
list_tail->next = flake;
flake->prev = list_tail;
list_tail = flake;
if (!list) {
list = flake;
}
}
void Background::KillSnowflake(Snowflake* flake) {
if (list_tail == flake) {
list_tail = flake->prev;
}
if (list == flake) {
list = flake->next;
}
if (flake->prev) flake->prev->next = flake->next;
if (flake->next) flake->next->prev = flake->prev;
delete flake;
}
void Background::Snowflake::Update() {
if (show_in) show_in--;
if (!(rand() % (int)(snowflake_jittering_chance))) {
x += (rand() % 2) ? (int)snowflake_jittering : -(int)snowflake_jittering;
}
y += (float)snowflake_gravity;
if (y > (int)snowflake_safe + 255) dead = true;
}
}}

View File

@ -0,0 +1,42 @@
/*
* Background.hpp
*
* Created on: Apr 28, 2017
* Author: nullifiedcat
*/
#ifndef BACKGROUND_HPP_
#define BACKGROUND_HPP_
#include "Menu.hpp"
extern unsigned char _binary_snowflake_start;
namespace menu { namespace ncc {
class Background : public CBaseWidget {
public:
struct Snowflake {
float x, y;
int show_in { 0 };
bool dead { false };
Snowflake* next { nullptr };
Snowflake* prev { nullptr };
void Update();
};
public:
Background();
~Background();
virtual void Draw(int x, int y) override;
virtual void Update() override;
void MakeSnowflake();
void KillSnowflake(Snowflake* flake);
public:
Texture snowflake_texture;
Snowflake* list { nullptr };
Snowflake* list_tail { nullptr };
};
}}
#endif /* BACKGROUND_HPP_ */

View File

@ -81,6 +81,8 @@ void ItemVariable::OnKeyPress(ButtonCode_t key, bool repeat) {
}
}
if (change < 1.0f && catvar.type == CV_INT) change = 1.0f;
if ((catvar.type == CV_SWITCH && key == ButtonCode_t::MOUSE_FIRST) || key == ButtonCode_t::MOUSE_WHEEL_UP) {
Change(change);
} else if (key == ButtonCode_t::MOUSE_WHEEL_DOWN) {

View File

@ -439,6 +439,12 @@ static const std::string list_tf2 = R"(
"GUI" [
"GUI Settings"
"logo"
"gui_snowflake_chance"
"gui_snowflake_pack_size"
"gui_snowflake_safe_zone"
"gui_snowflake_gravity"
"gui_snowflake_jittering"
"gui_snowflake_jittering_chance"
"gui_color_b"
"gui_color_g"
"gui_color_r"

View File

@ -23,6 +23,7 @@
#include "Radar.hpp"
#include "Root.hpp"
#include "Tooltip.hpp"
#include "Background.hpp"
#include "Logo.hpp"
namespace menu { namespace ncc {

View File

@ -35,6 +35,7 @@ void Root::Setup() {
tooltip = new Tooltip();
Logo* logo = new Logo();
logo->SetOffset(draw::width / 2 - 288, 25);
AddChild(new Background());
AddChild(logo);
AddChild(tooltip);
AddChild(&menu::ncc::MainList());