migratiune

This commit is contained in:
Your Name 2025-02-26 23:13:56 +01:00
commit bd1b818369
21 changed files with 6198 additions and 0 deletions

85
CFactor.h Normal file
View File

@ -0,0 +1,85 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"
#include <iostream>
void Update(float dt);
void Draw();
void __DrawFromMain(){Draw();} // beacuse the engine has a Draw function already
void ClearScreen();
class Example : public olc::PixelGameEngine
{
public:
Example()
{
sAppName = "CFactor - powered by Fundatia iOSiF";
}
public:
bool OnUserCreate() override
{
// Called once at the start, so create things here
return true;
}
bool OnUserUpdate(float fElapsedTime) override
{
ClearScreen();
Update(fElapsedTime);
__DrawFromMain();
return true;
}
};
Example demo;
//
const int ScreenWidth = 800;
const int ScreenHeight = 600;
void StartWindow()
{
if (demo.Construct(ScreenWidth, ScreenHeight, 1, 1))
{
demo.Start();
}
}
//COLORS
const olc::Pixel RED = olc::Pixel(255,0,0);
const olc::Pixel GREEN = olc::Pixel(0,255,0);
const olc::Pixel BLUE = olc::Pixel(0,0,255);
const olc::Pixel WHITE = olc::Pixel(255,255,255);
const olc::Pixel BLACK = olc::Pixel(0,0,0);
const olc::Pixel GRAY = olc::Pixel(80,80,80);
const olc::Pixel YELLOW = olc::Pixel(255,255,0);
const olc::Pixel CYAN = olc::Pixel(0,255,255);
const olc::Pixel MAGENTA = olc::Pixel(255,0,255);
void PutPixel(int x, int y, olc::Pixel color)
{
demo.Draw(x,y,color);
}
void PutPixel(int x, int y, char r, char b, char g)
{
PutPixel(x, y, olc::Pixel(r,g,b));
}
void FillCircle(int x, int y, int radius, olc::Pixel color)
{
demo.FillCircle(x,y,radius,color);
}
void FillRectangle(int left, int top, int right, int bottom, olc::Pixel color)
{
demo.FillRect(left,top,right-left,bottom-top,color);
}
void ClearScreen()
{
demo.FillRect(0,0,ScreenWidth,ScreenHeight,BLACK);
}

9
Makefile Normal file
View File

@ -0,0 +1,9 @@
LIBRARIES = -framework OpenGL -framework GLUT -lpng -framework Carbon
HOMEBREW_INCLUDE = /opt/homebrew/include
HOMEBREW_LIB = /opt/homebrew/lib
EXE = MyExecutableName
all:
clang++ -arch arm64 -std=c++17 -mmacosx-version-min=10.15 -Wall $(LIBRARIES) -Isrc -I${HOMEBREW_INCLUDE} -L${HOMEBREW_LIB} main.cpp -o $(EXE)
clean:
-rm $(EXE)

BIN
MyExecutableName Executable file

Binary file not shown.

48
Particle.h Normal file
View File

@ -0,0 +1,48 @@
#pragma once
#include "Point.h"
#include <random>
#include <cmath>
#include <time.h>
#include <iostream>
typedef olc::Pixel Color;
class Particle: public Point //particula e evident derivata din punct
{
private:
public://din moment ce nu am nici o variabila privata e clar ca am grsit codul dpdv conceptual da nu mai schimb nimic momentan
Color c;
bool touchedFPoint=false;
Particle(float in_x,float in_y)
{
mass=1;//vom considera intotdeauna masa unei particule 1 //pentru formula de la fizica
position.x=in_x;
position.y=in_y;
}
Color getColor() //getterele is sugestive
{
return c;
}
const float GetX()
{
return position.x;
}
const float GetY()
{
return position.y;
}
const Vec2 GetPosition()
{
return position;
}
void changeColor(int r,int g,int b)//si asta e clar ce face
{
c = Color(r,g,b);
}
bool operator==(Particle &other) //un operator acm inutil dar il folosesc undeva asa ca o las asa nu mare nimeni
{
return ((position.x==other.GetX()) && (position.y==other.GetY()));
}
};

1
Point Normal file
View File

@ -0,0 +1 @@

15
Point.h Normal file
View File

@ -0,0 +1,15 @@
#pragma once //make the virtual class
#include "Vec2.h"
class Point{///clasa virtuala din care deriva toate punctele din joc
private:///clasa e cam gresita dpdv logic pt ca nu are nici un membru privat...
public:
Vec2 position; ///positia pct
int mass;///masa pct
virtual const float GetX()=0;///gettere obisnuite
virtual const float GetY()=0;
virtual const Vec2 GetPosition()=0;
};

30
ReflectedParticle.h Normal file
View File

@ -0,0 +1,30 @@
///!!!!!NU MAI FOLOSESC CLASA ASTA,AM GASIT O SOLUTIE MAI ELEGANTA!!!!
/*#pragma once
#include "Particle.h"
class ReflectedParticle:focalPoint
{
Color c{255,255,255};
int particleLifeSpan=3;//cat de mult dureaza pana dispare
time_t creationT,now;
ReflectedParticle(Vec2 start_Pos)
{
position=start_Pos;
time (&creationT);
}
//TO USE DESTRUCTOR LATER
bool checkIfNeedsToBeDestructed()
{
time(&now);
int dif=creationT-now;
if(dif>particleLifeSpan)
return true;
return false;
}
void destructParticle()
{
position={9999,9999};
}
};
*/

21
Settings.h Normal file
View File

@ -0,0 +1,21 @@
#pragma once
struct Settings // Where i keep track of the settings
{//Numele sunt sugestive
int nr_particule;
int redValue;
int greenValue;
int blueValue;
int focalPointAttraction;
//constructotul la fel
Settings(int nrPart,int rVal,int gVal,int bVal,int fPointAttraction)
:
nr_particule(nrPart),
redValue(rVal),
greenValue(gVal),
blueValue(bVal),
focalPointAttraction(fPointAttraction)
{}
};

92
Vec2.h Normal file
View File

@ -0,0 +1,92 @@
#pragma once
#include <cmath>
template<typename T>
class Vec2_
{
public:
Vec2_() = default;
Vec2_(T x_in, T y_in)
:
x(x_in),
y(y_in)
{
}
template<typename S>
explicit Vec2_(const Vec2_<S>& src)
:
x((T)src.x),
y((T)src.y)
{
}
bool operator==(const Vec2_& rhs) const
{
return x == rhs.x && y == rhs.y;
}
bool operator!=(const Vec2_& rhs) const
{
return !(*this == rhs);
}
Vec2_ operator+(const Vec2_& rhs) const
{
return Vec2_(x + rhs.x, y + rhs.y);
}
Vec2_& operator+=(const Vec2_& rhs)
{
return *this = *this + rhs;
}
Vec2_ operator*(T rhs) const
{
return Vec2_(x * rhs, y * rhs);
}
Vec2_& operator*=(T rhs)
{
return *this = *this * rhs;
}
Vec2_ operator-(const Vec2_& rhs) const
{
return Vec2_(x - rhs.x, y - rhs.y);
}
Vec2_& operator-=(const Vec2_& rhs)
{
return *this = *this - rhs;
}
T GetLength() const
{
return (T)std::sqrt(GetLengthSq());
}
T GetLengthSq() const
{
return x * x + y * y;
}
Vec2_& Normalize()
{
return *this = GetNormalized();
}
Vec2_ GetNormalized() const
{
const T len = GetLength();
if (len != (T)0 )
{
return *this * ( (T)1 / len);
}
return *this;
}
public:
T x;
T y;
};
typedef Vec2_<float> Vec2;
typedef Vec2_<int> Vei2;

BIN
bin/Debug/fas.exe Normal file

Binary file not shown.

48
fas.cbp Normal file
View File

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="fas" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/fas" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/fas" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="Particle.h" />
<Unit filename="Point.h" />
<Unit filename="Settings.h" />
<Unit filename="Vec2.h" />
<Unit filename="focalPoint.h" />
<Unit filename="main.cpp" />
<Extensions>
<code_completion />
<envvars />
<debugger />
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>

66
fas.depend Normal file
View File

@ -0,0 +1,66 @@
# depslib dependency file v1.0
1555841986 source:d:\fas\main.cpp
"CFactor.h"
<vector>
<random>
<cmath>
"Particle.h"
"focalPoint.h"
<algorithm>
<initializer_list>
"Settings.h"
1555799767 d:\fas\cfactor.h
"olcPixelGameEngine.h"
<iostream>
1555799761 d:\fas\olcpixelgameengine.h
"olcPixelGameEngine.h"
<windows.h>
<gdiplus.h>
<GL/gl.h>
<GL/gl.h>
<GL/glx.h>
<X11/X.h>
<X11/Xlib.h>
<png.h>
<cmath>
<cstdint>
<string>
<iostream>
<streambuf>
<chrono>
<vector>
<list>
<thread>
<atomic>
<condition_variable>
<fstream>
<map>
<functional>
<algorithm>
"olcPixelGameEngine.h"
1555667246 source:d:\fas\focalpoint.cpp
1555667233 source:d:\fas\particle.cpp
1555842385 d:\fas\particle.h
"Point.h"
<random>
<cmath>
<time.h>
<iostream>
1555842771 d:\fas\focalpoint.h
"Point.h"
"Particle.h"
1555689766 d:\fas\vec2.h
<cmath>
1555842533 d:\fas\point.h
"Vec2.h"
1555842115 d:\fas\settings.h

35
fas.layout Normal file
View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="Settings.h" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="232" topLine="0" />
</Cursor>
</File>
<File name="focalPoint.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2333" topLine="50" />
</Cursor>
</File>
<File name="Point.h" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="324" topLine="0" />
</Cursor>
</File>
<File name="Vec2.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="0" topLine="54" />
</Cursor>
</File>
<File name="Particle.h" open="0" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1104" topLine="26" />
</Cursor>
</File>
<File name="main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="1" zoom_2="0">
<Cursor>
<Cursor1 position="3248" topLine="70" />
</Cursor>
</File>
</CodeBlocks_layout_file>

72
focalPoint.h Normal file
View File

@ -0,0 +1,72 @@
#pragma once
#include "Point.h"
#include "Particle.h"
class focalPoint: public Point{ ///tot derivata din point
private:
public:
focalPoint(float in_x,float in_y,int in_mass)
{
position.x=in_x;
position.y=in_y;
mass=in_mass; ///masa e forta de atractie basically
}
const float GetX() ///gettere obisnuite si obligatorii
{
return position.x;
}
const float GetY()
{
return position.y;
}
const Vec2 GetPosition()
{
return position;
}
void Update(float new_x,float new_y) ///since we work with the mouse, in fiecare frame fac update la pozitia actuala a fp based on the mouse position/
{
position.x=new_x;
position.y=new_y;
}
void AtrractParticle(Particle& p) //aici e big deal, atrag o particula folosind formula atractiei de la fizica.if u curious google it its eztofind
{
// old speed adjusting method speed+=0.5f;OLD//SolutieDeTaraniDaMerge
//Physics shit right there below
///ZONA UNDE CALCULEZ DISTANTA
Vec2 distance=position-p.position;
///ZONA UNDE CALCULEZ FORTA FORTA
Vec2 force=distance;
force.Normalize();
float strenght=(mass*p.mass)/(distance.GetLength()*distance.GetLength());//FORMULA ATRACTIEI DE LA FIZICA G*MASS1*MASS2/DISTANTA LA PATRAT. IN CAZUL MEU NU MAI CONSIDER ATRACTIA GRAVITATIONALA ,DOAR MASELE OBIECTELOR
force*=strenght;
///ZONA UNDE CALCULEZ DIRECTIA
Vec2 direction=(position-p.position);
direction=direction.GetNormalized();
///ZONA UNDE FAC UPDATE LA POZITIA PARTICULEI
Vec2 velocity=direction;
Vec2 acceleration=force;//formula la fizica e force/mass dar particula mea are masa unu asa ca nu ma complic
velocity+=acceleration;
if(p.touchedFPoint) ///aici arunc particulele care au atins fp ul int directia opusa fata de unde au venit
{
strenght*=rand()%ScreenWidth;//a random constant used for the pullback force
force*=strenght;
Vec2 acceleration=force;
velocity-=acceleration;///ca sa mergem in directia opusa
}
p.position+=velocity; //update positionbby
///ZONA UNDE TESTEZ DACA ESTE IN ZONA FP-ului pt a-l reflecta obiectul
if(distance.GetLength()<=0.1f)
p.touchedFPoint=true;
}
};

91
main.cpp Normal file
View File

@ -0,0 +1,91 @@
/*THINGS TO ADD:
PARTICLE MOVEMENT TO USE SPEED INSTEAD OF ++///check
IMPLEMENT THE SLIDER
IMPLEMENT A PARTICLE COUNTER
USE DYNAMIC MEMORY
USE VEC2 CLASS//check
MAKE THEM reflect FAST AFTER TOUCHING THE POINT
*/
#include "CFactor.h"
#include <vector>
#include <random>
#include <cmath>
#include "Particle.h"
#include "focalPoint.h"
#include <algorithm>
#include <initializer_list>
#include "Settings.h"
using namespace std;
///Nush unde sa le declar asa ca le scriu aici global aca o sa avem nevoie de ele oricum
std::vector<Particle>particule;//container in care tin toate particulele de pe ecran
Settings Sett(150000,255,255,255,1000);//setari initiale ale jocului
focalPoint f(demo.GetMouseX(),demo.GetMouseY(),Sett.focalPointAttraction);//unde initializez point to follow in fct de pozitia mouseului
void Start()
{
//just the usual generate random thing
std::default_random_engine generator;
std::uniform_int_distribution<int> Xdistribution(0,2*ScreenWidth);
std::uniform_int_distribution<int> Ydistribution(0,2*ScreenHeight);
//aici umplem vectorul cu nr initial de particule din settings
auto StartParticleNumber=Sett.nr_particule;
while(StartParticleNumber)
{
Particle p(Xdistribution(generator),Ydistribution(generator));//generam random o pozitie
particule.push_back(p);//o adaugam in vector
StartParticleNumber--;//scadem din settings numarul de particule
}
}
void Update(float dt)
{
f.Update(demo.GetMouseX(),demo.GetMouseY());//la fiecare frame facem update la pozitia focal-poitului
for(int i=0; i<particule.size(); i++)
{
f.AtrractParticle(particule[i]);
/*if(particule[i].touchedFPoint) ///NOT USING THIS BUT I M KEEPING IT(THAT WHAT SHE SAID) BECAUSE IT MADE ME TOO HAPPY TO JUST DUMP IT
{
///WHAT THE HELL IT WORKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!
particule[i].ResetPosition({rand()%(2*ScreenWidth),rand()%(2*ScreenHeight)});
particule[i].touchedFPoint=false;
}*/
auto DetermineDistance=[](Vec2 lhs,Vec2 rhs)->float///aici calculez shadeul. lambda e pt distanta dintre 2 pct pe care o folosesc la forumula finala
{
float deltax=(rhs.x-lhs.x)*(rhs.x-lhs.x);
float deltay=(rhs.y-lhs.y)*(rhs.y-lhs.y);
return sqrt(deltax+deltay);
};
float h= DetermineDistance(Vec2(0,0),Vec2(ScreenWidth,ScreenHeight));//diagonala ecranului,cea mai mare distanta care poate fi gasita pe un ecran.
float d=DetermineDistance(particule[i].GetPosition(),f.GetPosition());//apelam domnisoara lambda
float rat=d/h;//color ratio->rezulatul e ratie care determina distanta particulei relativ la pozitia fP ului. determina o nunata in timp real
particule[i].changeColor(Sett.redValue*rat,Sett.greenValue*rat,255-Sett.blueValue*rat*sin(rat));//just doodling around to get a nice shade
}
Draw();
}
void Draw()
{
for(int i=0; i<particule.size(); i++) //desenam particulele
PutPixel(particule[i].GetX(),particule[i].GetY(),particule[i].getColor());
}
int main()
{
Start();
StartWindow();
return 0;
}

BIN
main.exe Normal file

Binary file not shown.

BIN
main.o Normal file

Binary file not shown.

BIN
obj/Debug/Particle.o Normal file

Binary file not shown.

BIN
obj/Debug/focalPoint.o Normal file

Binary file not shown.

BIN
obj/Debug/main.o Normal file

Binary file not shown.

5585
olcPixelGameEngine.h Executable file

File diff suppressed because it is too large Load Diff