The open source repository for the action RPG game in development by Sig Productions titled 'Adventures in Lestoria'!
https://forums.lestoria.net
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.5 KiB
70 lines
1.5 KiB
1 year ago
|
#include "util.h"
|
||
1 year ago
|
#include "olcPixelGameEngine.h"
|
||
1 year ago
|
|
||
|
float util::random(float range){
|
||
|
return float(rand())/RAND_MAX*range;
|
||
1 year ago
|
}
|
||
|
|
||
|
vf2d util::pointTo(vf2d posFrom,vf2d posTo){
|
||
|
return geom2d::line(posFrom,posTo).vector().norm();
|
||
1 year ago
|
}
|
||
|
|
||
1 year ago
|
float util::angleTo(vf2d posFrom,vf2d posTo){
|
||
|
return geom2d::line<float>(posFrom,posTo).vector().polar().y;
|
||
|
}
|
||
|
|
||
1 year ago
|
float util::degToRad(float deg){
|
||
|
return deg*(PI/180);
|
||
|
}
|
||
|
|
||
|
float util::radToDeg(float rad){
|
||
|
return rad*57.2957795130823208767;
|
||
1 year ago
|
}
|
||
|
|
||
|
float util::lerp(float n1,float n2,double t){
|
||
|
return n1*(1-t)+n2*t;
|
||
1 year ago
|
}
|
||
|
|
||
|
std::string util::timerStr(float time){
|
||
|
int seconds=int(time);
|
||
|
int hours=seconds/3600;
|
||
|
int minutes=seconds/60;
|
||
|
|
||
|
std::string timeStr="";
|
||
|
if(hours>0){
|
||
|
if(hours<10)timeStr+="0";
|
||
|
timeStr+=std::to_string(hours)+":";
|
||
|
}
|
||
|
|
||
1 year ago
|
if(minutes%60<10)timeStr+="0";
|
||
|
timeStr+=std::to_string(minutes%60)+":";
|
||
1 year ago
|
|
||
1 year ago
|
if(seconds%60<10)timeStr+="0";
|
||
|
timeStr+=std::to_string(seconds%60);
|
||
1 year ago
|
|
||
|
return timeStr;
|
||
1 year ago
|
}
|
||
|
|
||
|
std::string util::WrapText(PixelGameEngine*pge,std::string str,int width,bool proportional,vd2d scale){
|
||
|
std::string newStr;
|
||
|
while (true) {
|
||
|
std::string word;
|
||
|
if (str.find(" ")==std::string::npos) {
|
||
|
word=str;
|
||
|
} else {
|
||
|
word = str.substr(0,str.find(" "));
|
||
|
}
|
||
|
vi2d newSize = vd2d(proportional?pge->GetTextSizeProp(newStr+(newStr.size()>0?" ":"")+word):pge->GetTextSize(newStr+(newStr.size()>0?" ":"")+word))*scale;
|
||
|
if (newSize.x>width) {
|
||
|
newStr+="\n"+word;
|
||
|
} else {
|
||
|
newStr+=(newStr.size()>0?" ":"")+word;
|
||
|
}
|
||
|
if (str.find(" ")==std::string::npos) {
|
||
|
break;
|
||
|
} else {
|
||
|
str.erase(0,str.find(" ")+1);
|
||
|
}
|
||
|
}
|
||
|
return newStr;
|
||
1 year ago
|
}
|