From 7e20f7693be642b006fa6c4d65f6da1b00b0621f Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Sun, 3 Mar 2019 03:48:39 +0200 Subject: [PATCH] added starfield --- src/gamescr.c | 33 ++++++++++----- src/starfield.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 src/starfield.c diff --git a/src/gamescr.c b/src/gamescr.c index f2a2ee4..a55f432 100644 --- a/src/gamescr.c +++ b/src/gamescr.c @@ -9,6 +9,9 @@ #include "blocks.h" #include "logger.h" +int init_starfield(void); +void draw_starfield(void); + static int init(void); static void cleanup(void); static void start(void); @@ -84,17 +87,24 @@ static const long level_speed[NUM_LEVELS] = { static const float blkcolor[][4] = { {1.0, 0.65, 0.0, 1}, - {0.16, 1.0, 0.0, 1}, + {0.16, 1.0, 0.4, 1}, {0.65, 0.65, 1.0, 1}, - {1.0, 1.0, 0.0, 1}, + {1.0, 0.9, 0.1, 1}, {0.0, 1.0, 1.0, 1}, {1.0, 0.5, 1.0, 1}, - {1.0, 0.25, 0.0, 1} + {1.0, 0.35, 0.2, 1}, + {0.5, 0.5, 0.5, 1} }; +#define GAMEOVER_FILL_RATE 50 + static int init(void) { + if(init_starfield() == -1) { + return -1; + } + if(!(blkmesh = cmesh_alloc()) || cmesh_load(blkmesh, "data/noisecube.obj") == -1) { error_log("failed to load block mesh\n"); return -1; @@ -116,6 +126,8 @@ static int init(void) static void cleanup(void) { cmesh_free(blkmesh); + cmesh_free(wellmesh); + glDeleteTextures(1, &tex_well); } static void start(void) @@ -149,10 +161,9 @@ static void update(float dtsec) } dt = time_msec - prev_tick; - /* if(gameover) { int i, row = PF_ROWS - gameover; - int *ptr; + unsigned int *ptr; if(dt < GAMEOVER_FILL_RATE) { return; @@ -161,15 +172,14 @@ static void update(float dtsec) if(row >= 0) { ptr = pfield + row * PF_COLS; for(i=0; i +#include +#include +#include +#include +#include "opengl.h" +#include "game.h" +#include "logger.h" + +static unsigned int tex_bolt, tex_star; +static float star_speed = 100.0f; +static float star_depth = 1000.0f; +static float star_size = 0.35f; + +#define STAR_ZOFFS 100.0f +#define STAR_COUNT 4096 +static cgm_vec3 star[STAR_COUNT]; +static float star_lenxy[STAR_COUNT]; + +int init_starfield(void) +{ + int i; + float width; + + if(!(tex_star = img_gltexture_load("data/pimg.png"))) { + error_log("failed to load star texture\n"); + return -1; + } + if(!(tex_bolt = img_gltexture_load("data/bolt.png"))) { + error_log("failed to load star tail texture\n"); + return -1; + } + + width = star_depth / 4.0f; + for(i=0; i