Update 'sfml/mainauto.cpp'
This commit is contained in:
parent
bc735da790
commit
9ca1bdcc00
|
@ -1,13 +1,14 @@
|
|||
#include <SFML/Graphics.hpp>
|
||||
#include <math.h>
|
||||
#include <Main.hpp>
|
||||
|
||||
#define SCREEN_HEIGHT 216
|
||||
#define SCREEN_WIDTH 384
|
||||
#define SCREEN_HEIGHT 224
|
||||
#define SCREEN_WIDTH 396
|
||||
#define GET_POS(x) ((abs(x)+x)/2)
|
||||
#define SEG_WIDTH 70
|
||||
#define CH_Z 9
|
||||
const float CH_H = 4;
|
||||
const float CH_W = 1.3;
|
||||
const float CH_W = 1.65;
|
||||
float CH_HY = 0.80; //0->flat
|
||||
|
||||
sf::Color gray = sf::Color(131, 118, 156);
|
||||
|
@ -15,33 +16,12 @@ sf::Color lightgray = sf::Color(194, 195, 199);
|
|||
sf::Color red = sf::Color(255, 0, 77);
|
||||
sf::Color blue = sf::Color(41, 173, 255);
|
||||
|
||||
struct Road {
|
||||
int height; //number of elements
|
||||
struct Segment* segments; //array of segments
|
||||
int* grid;
|
||||
float playerx;
|
||||
float playery;
|
||||
int width;
|
||||
int segment_height;
|
||||
int starty;
|
||||
int startx;
|
||||
};
|
||||
|
||||
struct Segment {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
int width;
|
||||
int height;
|
||||
sf::Color colour;
|
||||
};
|
||||
|
||||
struct Segment seg(float x, float y, float z, int width, int height, sf::Color colour) {
|
||||
struct Segment segment = { x, y, z, width, height, colour };
|
||||
return segment;
|
||||
}
|
||||
|
||||
void draw_road(sf::RenderWindow* window, struct Road* road, float zm = 2) {
|
||||
void draw_road(sf::RenderWindow* window, struct Road* road) {
|
||||
float s;
|
||||
for (int v = road->height - 1;v >= 0;v--) { //draws each rectangle from furthest to closest
|
||||
s = SEG_WIDTH - road->segments[v].z / (CH_H * CH_W);
|
||||
|
@ -87,7 +67,6 @@ void gen_road(unsigned char* grid, int size, struct Road *road) {
|
|||
float h30 = 20 * (s / SEG_WIDTH);
|
||||
float y31 = road->segments[v-1].y + h30;
|
||||
float h32 = w32 * (s / SEG_WIDTH);
|
||||
printf("%f", (w31 - w30) / -2);
|
||||
road->segments[v++] = seg((w31 - w30) / -2, y31, z, 120, 50, lightgray);
|
||||
road->segments[v++] = seg((w31 - w30) / -2, y31 - h31, z, w32, 70, lightgray);
|
||||
road->segments[v++] = seg( w30, y31 - h31, z, w32, 70, lightgray);
|
||||
|
@ -101,7 +80,7 @@ void gen_road(unsigned char* grid, int size, struct Road *road) {
|
|||
int main() {
|
||||
sf::RenderWindow window(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT), "KraD");
|
||||
struct Road road;
|
||||
road.height = 32;
|
||||
road.height = 64;
|
||||
road.playerx = 0;
|
||||
road.playery = 0;
|
||||
road.width = 100;
|
||||
|
@ -110,7 +89,7 @@ int main() {
|
|||
road.segment_height = 30;
|
||||
road.segments = (struct Segment*)malloc(road.height * sizeof(struct Segment));
|
||||
|
||||
unsigned char grid[] = {0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x14,0x04,0x04,0x03,0x02, 0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00};
|
||||
unsigned char grid[] = {0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x14,0x04,0x04,0x03,0x02, 0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x03,0x04,0x14,0x04,0x04,0x03,0x02, 0x01,0x00,0x00,0x00,0x10,0x00,0x00,0x00,0x00 };
|
||||
gen_road(grid, sizeof(grid), &road);
|
||||
|
||||
sf::Clock clock;
|
||||
|
@ -133,16 +112,14 @@ int main() {
|
|||
}
|
||||
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||
{
|
||||
float mov = 300 * dt;
|
||||
for (int i = 0;i < road.height;i++) {
|
||||
road.segments[i].x -= mov;
|
||||
road.segments[i].x -= 300 * dt;
|
||||
}
|
||||
}
|
||||
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||
{
|
||||
float mov = 300 * dt;
|
||||
for (int i = 0;i < road.height;i++) {
|
||||
road.segments[i].x += mov;
|
||||
road.segments[i].x += 300 * dt;
|
||||
}
|
||||
}
|
||||
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::W))
|
||||
|
|
Loading…
Reference in New Issue