Last active
June 27, 2022 06:35
-
-
Save Cicolas/808a4b49730ac5bc6bf816ab69b8bd84 to your computer and use it in GitHub Desktop.
cpp console lib
This file contains 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
#include <iostream> | |
#include <stdio.h> | |
#include <conio.h> | |
// #define _WIN32_WINNT 0x0500 | |
#include <windows.h> | |
#include <time.h> | |
#include <locale.h> | |
#include <wincon.h> | |
#include <fstream> | |
#include <string> | |
#include <math.h> | |
#define PI 3.14159265359 | |
#define UP 72 | |
#define DOWN 80 | |
#define LEFT 75 | |
#define RIGHT 77 | |
using namespace std; | |
int lastUpdates[2] = {0, 0}; //click | |
int lastUpdates_[2] = {0, 0}; //mouseMoved | |
#define BLACK 0 | |
#define BLUE 1 | |
#define GREEN 2 | |
#define CYAN 3 | |
#define RED 4 | |
#define MAGENTA 5 | |
#define YELLOW 6 | |
#define LIGHT_GRAY 7 | |
#define DARK_GRAY 8 | |
#define LIGHT_BLUE 9 | |
#define LIGHT_GREEN 10 | |
#define LIGHT_CYAN 11 | |
#define LIGHT_RED 12 | |
#define LIGHT_MAGENTA 13 | |
#define LIGHT_YELLOW 14 | |
#define WHITE 15 | |
////////////////////////////////////////////////////////// | |
void gotoxy(int x, int y){ | |
COORD coord; | |
coord.X = x; | |
coord.Y = y; | |
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); | |
} | |
void setColor(int clr, int backgroud){ | |
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (clr)+16*backgroud); | |
return; | |
} | |
bool colision(char mapa[100][100], int x, int y, string direction){ | |
if(direction == "up"){ | |
if(mapa[(y)-1][x] == ' ' || mapa[(y)-1][x] == '.' || mapa[(y)-1][x] == (char)254){ | |
return true; | |
} | |
}else if(direction == "down"){ | |
if(mapa[(y)+1][x] == ' ' || mapa[(y)+1][x] == '.' || mapa[(y)+1][x] == (char)254){ | |
return true; | |
} | |
}else if(direction == "right"){ | |
if(mapa[(y)][x+1] == ' ' || mapa[(y)][x+1] == '.' || mapa[(y)][x+1] == (char)254){ | |
return true; | |
} | |
}else if(direction == "left"){ | |
if(mapa[(y)][x-1] == ' ' || mapa[(y)][x-1] == '.' || mapa[(y)][x-1] == (char)254){ | |
return true; | |
} | |
}else{ | |
return false; | |
} | |
return false; | |
} | |
POINT mousePos(){ | |
POINT point; | |
GetCursorPos(&point); | |
ScreenToClient(GetConsoleWindow(), &point); | |
return point; | |
} | |
int click(){ //se voltar 0, n�o teve nenhuma altera��o, 1 presionado, 2 soltado | |
lastUpdates[0] = lastUpdates[1]; | |
if((GetKeyState(VK_LBUTTON) & 0x100) != 0){ | |
lastUpdates[1] = 1; | |
}else{ | |
lastUpdates[1] = 0; | |
} | |
if(lastUpdates[0] == 0 && lastUpdates[1] == 1){ | |
return 1; | |
} | |
return 0; | |
} | |
int randomRange(int mn, int mx){ | |
srand(time(NULL)); | |
return (rand()%(mx-mn))+mn; | |
} | |
void setConsolePosition(int x, int y){ | |
HWND consoleWindow = GetConsoleWindow(); | |
SetWindowPos( consoleWindow, 0, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER ); | |
} | |
void clearScr(int x, int y, int w, int h){ | |
for(int j=y; j < h; j++){ | |
gotoxy(x, j); | |
cout << " "; | |
} | |
} | |
void hidecursor(){ | |
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE); | |
CONSOLE_CURSOR_INFO info; | |
info.dwSize = 100; | |
info.bVisible = FALSE; | |
SetConsoleCursorInfo(consoleHandle, &info); | |
} | |
int Other(int value1, int value2, int value){ | |
if(value%2){ | |
return value1; | |
}else{ | |
return value2; | |
} | |
} | |
float Deg2Rad(float v){ | |
return v*PI/180; | |
} | |
float Rad2Deg(float v){ | |
return v*180/PI; | |
} | |
bool mouseMoved(){ | |
lastUpdates_[0] = lastUpdates_[1]; | |
lastUpdates_[1] = mousePos().x+mousePos().y; | |
if(lastUpdates_[0] != lastUpdates_[1]){ | |
return 1; | |
} | |
return 0; | |
} | |
int Neg(int n){ | |
return (n==abs(n))?1:-1; | |
} | |
POINT Rad2Vec(float ang){ | |
POINT a; | |
a.x = cos(ang); | |
a.y = sin(ang); | |
return a; | |
} | |
float getDistance(float x, float y){ | |
return sqrt(x*x+y*y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment