#include <iostream>
#include <Windows.h>
#include <time.h>
#include <stdlib.h>
#include <cmath>
#include <cstdlib>
using namespace std;
//Screen dimensions
const int width = 800, height = 600;
//pixels deimensions
const int dw = 8, dh = 16;
//800/8 100 and 600/16=37.5
// Ü Û ß
struct coord //Structures to strogare Dinosaurs characters
{
int x;
int y;
};
/*/struct part
{
coord peri[93];
char D[93];
};
part car1[2];
*/
void gotoxy(int x, int y) {
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
COORD dwPos;
dwPos.X = x;
dwPos.Y = y;
SetConsoleCursorPosition(hcon, dwPos);
}
void convert(int P[2], float x, float y) //Take the integer part from any value
{
P[0] = int(x) / dw;
P[1] = int(y) / dh;
}
void convert(int P[2], int x, int y) //Take the integer part from any integer
{
P[0] = x / dw;
P[1] = y / dh;
}
void drawpoint(char plane[height / dh][width / dw + 1], int A, int B, char C)//Function to draw the screen
{
B = height / dh - 1 - B;
if (A < 0 || B < 0 || A >= width / dw || B >= height / dh) return;
plane[B][A] = C;
}
class map
{
private:
float n(float x)
{
return 0 ;
}
public:
float f(float x)
{
return (150 * (n(x) + 1.0f) / 2.0f); //75
}
void draw(char plane[height / dh][width / dw + 1])
{
for (int i = 0; i < width / dw; i++)
{
int P[2];
// 75/16= 4.68
int j_start = f(i * dw) / dh;
for (int j = j_start; j >= 0; j--)
{
convert(P, i * dw, j * dh);
drawpoint(plane, P[0], P[1], 'o');
}
convert(P, i * dw, j_start * dh);
drawpoint(plane, P[0], P[1], '#');
}
}
};
int main()
{
map new_map;
char plane[height / dh][width / dw + 1]; //High 37 width 100+1;
for (int i = 0; i < height / dh; i++) {
for (int j = 0; j < width / dw; j++) {
plane[i][width / dw] = '\n'; //when plane width is 100, line break
}
plane[height / dh + 1][width / dw] = '\0'; //Define the end of the heigh
}
while (true)
{
gotoxy(0, 0);
for (int i = 0; i < (height / dh); i++)
{
for (int j = 0; j < (width / dw); j++)
{
plane[i][j] = '*';
}
}
new_map.draw(plane);
puts(plane[0]);
}
return 0;
}
The map should look like this:
"***********************
"***********************
"***********************
"***********************
"***********************
"***********************
"***********************
"***********************
####################################################################
ooooooooooooooooooooooo
ooooooooooooooooooooooo
ooooooooooooooooooooooo
But I get something like this instead:
"***********************
"***********************
"***********************
"***********************
"***********************
"***********************
"***********************
"***********************
#####################################################################
oooooooooooooooooooooooo
oooooooooooooooooooooooo
oooooooooooooooooooooooo
oo╠╠╠╠╠╠╠╠%