1
1
Fork 0
Browse Source

display working

thread-physics
alistair 4 years ago
parent
commit
2cdc345e84
  1. 31
      draw.c
  2. 11
      draw.h
  3. 88
      environment.c
  4. 3
      environment.h
  5. 7
      game.c

31
draw.c

@ -287,21 +287,20 @@ double interpolate_h(Vect left, Vect right, double x) { @@ -287,21 +287,20 @@ double interpolate_h(Vect left, Vect right, double x) {
}
void draw_environment(SDL_Renderer * ren, struct environment *scene) {
void **c = scene->colours.items;
struct colour *c1 = c[0];
struct colour *c2 = c[1];
struct colour *c3 = c[2];
struct colour *c4 = c[3];
c1->r = 255;
c2->g = 255;
c3->b = 255;
c4->g = 255;
c4->b = 255;
struct colour c1 = scene->colours.bg;
struct colour c2 = scene->colours.fg1;
struct colour c3 = scene->colours.fg2;
struct colour c4 = scene->colours.fg3;
/*c1->r = 255;*/
/*c2->g = 255;*/
/*c3->b = 255;*/
/*c4->g = 255;*/
/*c4->b = 255;*/
// background colour
SDL_SetRenderDrawColor(ren, c1->r, c1->g, c1->b, 255);
SDL_SetRenderDrawColor(ren, 255, 0, 0, 255);
SDL_SetRenderDrawColor(ren, c1.r, c1.g, c1.b, 255);
/*SDL_SetRenderDrawColor(ren, 255, 0, 0, 255);*/
SDL_Rect rect;
rect.x = 0;
@ -364,15 +363,15 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) { @@ -364,15 +363,15 @@ void draw_environment(SDL_Renderer * ren, struct environment *scene) {
printf("y: %d %d %d %d\n", y0, y1, y2, y3);
// 1. ceil to bg1
SDL_SetRenderDrawColor(ren, c2->r, c2->g, c2->b, 255);
SDL_SetRenderDrawColor(ren, c2.r, c2.g, c2.b, 255);
SDL_RenderDrawLine(ren, x, y0, x, y1);
// 2. bg1 to bg2
SDL_SetRenderDrawColor(ren, c3->r, c3->g, c3->b, 255);
SDL_SetRenderDrawColor(ren, c3.r, c3.g, c3.b, 255);
SDL_RenderDrawLine(ren, x, y1, x, y2);
// 3. bg2 to floor
SDL_SetRenderDrawColor(ren, c4->r, c4->g, c4->b, 255);
SDL_SetRenderDrawColor(ren, c4.r, c4.g, c4.b, 255);
SDL_RenderDrawLine(ren, x, y2, x, y3);
}
}

11
draw.h

@ -9,7 +9,8 @@ @@ -9,7 +9,8 @@
#define SHOWFORCES 0
#include "garbo.h"
#include "game.h"
#include "game.h"
#include "c-colours/colours.h"
typedef enum {
PLAYER
@ -33,4 +34,12 @@ extern Vect viewport_pos; @@ -33,4 +34,12 @@ extern Vect viewport_pos;
extern int width, height;
struct colour_pallete {
struct colour bg;
struct colour fg1;
struct colour fg2;
struct colour fg3;
};
#endif

88
environment.c

@ -1,4 +1,6 @@ @@ -1,4 +1,6 @@
#include "environment.h"
#include "draw.h"
double linear_interpolate(double a0, double a1, double w) {
return (1.0f - w) * a0 + w * a1;
}
@ -33,8 +35,30 @@ double perlin(Vect coordinate) { @@ -33,8 +35,30 @@ double perlin(Vect coordinate) {
return linear_interpolate(ix0, ix1, sy);
}
ArrayList get_colours(int seed) {
struct colour_pallete get_pallete (int seed) {
struct colour base = get_random_color(seed);
struct colour c1 = get_hsv(base);
c1 = get_hsv(base);
struct colour_pallete cols;
c1.l = 0.1;
cols.bg = get_rgb(c1);
c1.l += 0.3;
c1.h += 30;
cols.fg1 = get_rgb(c1);
c1.h += 30;
cols.fg2 = get_rgb(c1);
c1.h += 30;
cols.fg3 = get_rgb(c1);
return cols;
struct colour *adj = get_adjacent(base, 20, 4);
ArrayList l = new_arlst_wfree(4, free);
@ -42,7 +66,10 @@ ArrayList get_colours(int seed) { @@ -42,7 +66,10 @@ ArrayList get_colours(int seed) {
arlst_add(&l, adj + i);
}
return l;
}
int comp(const void *one, const void *two) {
return *(int*)one > *(int*)two;
}
struct environment get_scene_at(Vect coordinate, int seed) {
@ -63,19 +90,64 @@ struct environment get_scene_at(Vect coordinate, int seed) { @@ -63,19 +90,64 @@ struct environment get_scene_at(Vect coordinate, int seed) {
e.ceil = new_arlst_wfree(E_ROOM_TILES, free);
e.bg1 = new_arlst_wfree(E_ROOM_TILES, free);
e.bg2 = new_arlst_wfree(E_ROOM_TILES, free);
e.colours = get_colours(seed);
e.colours = get_pallete(seed);
Vect bit;
bit.y = 100 * seed;
Vect pos;
srand(seed);
Vect node;
node.y = 0;
for (int i = 0; i < E_ROOM_WIDTH; i += E_ROOM_RES) {
bit.x = room_coord.x + i;
double *z = malloc(sizeof(double));
*z = perlin(bit);
bit.y = seed;
node.x = bit.x;
int r1 = 1.5*(rand() % 500) - (rand() % 100);
int r2 = 1.5*(rand() % 200) - (rand() % 200);
int r3 = (rand() % 100) - (rand() % 500);
int r4 = 50;
int r[4] = {r1, r2, r3, r4};
qsort(r, 4, sizeof(int), comp);
node.y += r[0];
// node.y = fmod(perlin(bit), 3000);
Vect *z = malloc(sizeof(Vect));
*z = node;
printf("%f %f\n", bit.x, z->y);
arlst_add(&e.floor, z);
arlst_add(&e.ceil, z + 90);
arlst_add(&e.bg1, z + 20);
arlst_add(&e.bg2, z + 70);
z = malloc(sizeof(Vect));
*z = node;
z->y += r[1];
printf("%f %f\n", bit.x, z->y);
arlst_add(&e.bg1, z);
z = malloc(sizeof(Vect));
*z = node;
z->y += r[2];
printf("%f %f\n", bit.x, z->y);
arlst_add(&e.bg2, z);
z = malloc(sizeof(Vect));
*z = node;
z->y += r[3];
printf("%f %f\n", bit.x, z->y);
arlst_add(&e.ceil, z);
}
init = true;

3
environment.h

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
#include "c-colours/colours.h"
#include "datastructures/datatypes.h"
#include "vect.h"
#include "draw.h"
enum {
E_ROOM_WIDTH = 10000,
@ -15,7 +16,7 @@ struct environment { @@ -15,7 +16,7 @@ struct environment {
ArrayList floor;
ArrayList bg1;
ArrayList bg2;
ArrayList colours;
struct colour_pallete colours;
};
struct environment get_scene_at(Vect coordinate, int seed);

7
game.c

@ -1129,7 +1129,7 @@ void startgame(SDL_Renderer * ren) { @@ -1129,7 +1129,7 @@ void startgame(SDL_Renderer * ren) {
SDL_GetRendererOutputSize(ren, &width, &height);
// player = get_player(200,1300);
player = get_player(0,10);
player = get_player(0,100);
world_thing player_world;
@ -1153,11 +1153,12 @@ double get_abs(double x,double y) { @@ -1153,11 +1153,12 @@ double get_abs(double x,double y) {
void walk_player(int x, int y) {
set_motor_newtons(player.physics, M_PLAYER_WALK, 0, 0);
if (y == -1) {
// turned off special case for going down for TESTing
if (false && y == -1) {
add_motor_newtons(glob_player->physics, M_PLAYER_WALK, 0, 100 * 10 * y);
return;
}
add_motor_newtons(glob_player->physics, M_PLAYER_WALK, 100 *10* x , 100 * y);
add_motor_newtons(glob_player->physics, M_PLAYER_WALK, 100 *5* x , 100 * 5 * y);
}
void handle_input_event(SDL_Event event) {

Loading…
Cancel
Save