Added temperature to the player and added moisture

This commit is contained in:
jsrobson10 2020-06-26 15:11:40 +10:00
parent 4b527a0db0
commit 4f7b499217
13 changed files with 314 additions and 172 deletions

View File

@ -28,13 +28,14 @@ public class DisplayLighting
int x, y;
private int getID(int x, int y) {
return (x + y * w) * 3 + 1;
return (x + y * w) * 4 + 1;
}
}
private static int lighting_last_x = 0;
private static int lighting_last_y = 0;
private static boolean lighting_dirty = false;
private static boolean lighting_new = false;
public static int lightmap;
private static Lighting lighting;
@ -49,6 +50,7 @@ public class DisplayLighting
private synchronized static void setLighting(Lighting lighting) {
DisplayLighting.lighting = lighting;
lighting_new = true;
}
public DisplayLighting() {
@ -255,6 +257,23 @@ public class DisplayLighting
}
}
if(lighting_new)
{
for(int i=0;i<lighting.p.length/4;i++)
{
int x = i % lighting.w;
int y = i / lighting.w;
Vec2i tpos = new Vec2i(x + lighting.x * 16, y + lighting.y * 16);
// Store light level data from the image
layer.setDaylightLevel(lighting.p[i+0], tpos);
layer.setLightLevel(lighting.p[i+1], tpos);
}
lighting_new = false;
}
ByteBuffer pixels_b = BufferUtils.createByteBuffer(pixels.length);
for(int i=0;i<pixels.length;i++) {
@ -266,8 +285,8 @@ public class DisplayLighting
if(lighting_last_x != lighting.w || lighting_last_y != lighting.h)
{
GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGB,
lighting.w, lighting.h, 0, GL33.GL_RGB, GL33.GL_UNSIGNED_BYTE, pixels_b);
GL33.glTexImage2D(GL33.GL_TEXTURE_2D, 0, GL33.GL_RGBA,
lighting.w, lighting.h, 0, GL33.GL_RGBA, GL33.GL_UNSIGNED_BYTE, pixels_b);
lighting_last_x = lighting.w;
lighting_last_y = lighting.h;
@ -275,7 +294,7 @@ public class DisplayLighting
else {
GL33.glTexSubImage2D(GL33.GL_TEXTURE_2D, 0, 0, 0,
lighting.w, lighting.h, GL33.GL_RGB, GL33.GL_UNSIGNED_BYTE, pixels_b);
lighting.w, lighting.h, GL33.GL_RGBA, GL33.GL_UNSIGNED_BYTE, pixels_b);
}
GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
@ -306,11 +325,11 @@ public class DisplayLighting
int x = nl.get("x").getInteger();
int y = nl.get("y").getInteger();
float[] pixels = new float[width*height*3];
float[] pixels = new float[width*height*4];
for(int i=0;i<width*height;i++) {
pixels[i*3+0] = light[i*2+0];
pixels[i*3+1] = light[i*2+1];
pixels[i*4+0] = light[i*2+0];
pixels[i*4+1] = light[i*2+1];
}
Lighting lighting = new Lighting();
@ -323,9 +342,15 @@ public class DisplayLighting
Layer layer = Main.world.getLayer();
for(int x2=0;x2<lighting.w;x2++) {
for(int y2=0;y2<lighting.h;y2++) {
double temp = layer.layergen.getTemperatureStatic(layer, new Vec2d(x2 + lighting.x * 16, y2 + lighting.y * 16));
pixels[(x2 + y2 * lighting.w) * 3 + 2] = (float)temp;
for(int y2=0;y2<lighting.h;y2++)
{
int i = (x2 + y2 * lighting.w) * 4;
// Send temperature and humidity data to the image
pixels[i+2] = (float)layer.layergen.getTemperatureStatic(
layer, new Vec2d(x2 + lighting.x * 16, y2 + lighting.y * 16));
pixels[i+3] = (float)layer.layergen.getHumidity(
layer, new Vec2d(x2 + lighting.x * 16, y2 + lighting.y * 16));
}
}

View File

@ -67,8 +67,10 @@ public class DisplayRenderUI
{
ModelGui model_health_f = Models.UI_HEALTH_FG;
ModelGui model_health_b = Models.UI_HEALTH_BG;
ModelGui model_temperature = Models.UI_TEMPERATURE;
ModelGui model_water = Models.UI_WATER;
Matrix4 matrix = Matrix4.translate(-model_health_f.getWidth() / 2, -8, 0);
Matrix4 matrix = Matrix4.translate(-(79 * 15.0) / 160, -9.5 + (1.5 * 17) / 16, 0);
model_health_b.setModel(matrix);
model_health_b.render();
@ -81,7 +83,28 @@ public class DisplayRenderUI
model_health_f.setModel(matrix);
model_health_f.render();
double temperature = MathHelpers.smoothStep(Main.player.getTemperature());
double hydration = MathHelpers.squared(1 - Main.player.getHydration());
GL33.glUniform2f(Main.window.glsl_tex_cut, 0, 0);
GL33.glUniform4f(Main.window.glsl_color,
(float)temperature, (float)temperature * 0.25f, 1 - (float)temperature, 1);
matrix = Matrix4.translate(-(9 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0);
model_temperature.setModel(matrix);
model_temperature.render();
GL33.glUniform4f(Main.window.glsl_color,
(float)hydration, (float)hydration * 0.25f, 1 - (float)hydration, 1);
matrix = Matrix4.translate((1 * 0.75) / 8, -9.5 + (1.5 * 17) / 16, 0);
model_water.setModel(matrix);
model_water.render();
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
}
}

View File

@ -42,6 +42,8 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
private int bullet_frequency = 0;
private double health_max = 1000;
private double health = health_max;
private double temperature = 0.5;
private double hydration = 1;
public boolean dead = false;
public boolean in_animation = false;
@ -72,6 +74,8 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
defence_level = nl.get("defence_level").getInteger();
gun_level = nl.get("gun_level").getInteger();
angle = nl.get("angle").getDouble();
temperature = nl.get("temperature").getDouble();
hydration = nl.get("hydration").getDouble();
}
public int getAmmo() {
@ -90,6 +94,8 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
nl.set("defence_level", BdfObject.withInteger(defence_level));
nl.set("gun_level", BdfObject.withInteger(gun_level));
nl.set("angle", BdfObject.withDouble(angle));
nl.set("temperature", BdfObject.withDouble(temperature));
nl.set("hydration", BdfObject.withDouble(hydration));
}
public EntityPlayer() {
@ -182,6 +188,13 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
// Call super
super.tick(chunk, layer);
System.out.println(chunk.getLightLevel(pos.toInt()) * 0.8);
double temp_diff = MathHelpers.biggest(
layer.layergen.getTemperatureDynamic(layer, pos),
chunk.getLightLevel(pos.toInt()) * 0.8) - temperature;
temperature += temp_diff / 1000;
// Rotate left
if(MOVE_LEFT) {
this.angle -= 1;
@ -341,4 +354,12 @@ public class EntityPlayer extends Entity implements EntityAlive, EntityInventory
public Model getModel() {
return moving ? PLAYER_MOVING : PLAYER_STILL;
}
public double getTemperature() {
return temperature;
}
public double getHydration() {
return hydration;
}
}

View File

@ -75,6 +75,8 @@ public class Models
public static final ModelGui UI_DEFENCE_LEVEL = new ModelGui(Resources.ATLAS.get("/gui/shield.png"));
public static final ModelGui UI_GUN_LEVEL = new ModelGui(Resources.ATLAS.get("/gui/gun.png"));
public static final ModelGui UI_TEMPERATURE = new ModelGui(Resources.ATLAS.get("/gui/temperature.png"), new Vec2d(0.75, 0.75));
public static final ModelGui UI_WATER = new ModelGui(Resources.ATLAS.get("/gui/water.png"), new Vec2d(0.75, 0.75));
public static final ModelItem ITEM_EMPTY = ModelItem.createEmpty();
public static final ModelItem ITEM_GRAPPLING_HOOK = new ModelItem(Resources.ATLAS.get("/item/grappling_hook.png"));

View File

@ -18,6 +18,7 @@ public abstract class LayerGen implements IMap2D<Chunk>
public abstract void generateChunk(Chunk chunk, Layer layer, Random rand, Vec2i pos);
public abstract double getTemperatureStatic(Layer layer, Vec2d pos);
public abstract double getTemperatureDynamic(Layer layer, Vec2d pos);
public abstract double getHumidity(Layer layer, Vec2d pos);
public abstract void spawnEntities(Layer layer, Random rand);
public abstract TileState getTileDestroyed();
public abstract ColorRange getLightLevel();

View File

@ -124,5 +124,10 @@ public class LayerGenBossArena extends LayerGen implements LayerGenRememberPlaye
public double getTemperatureDynamic(Layer layer, Vec2d pos) {
return 0.8;
}
@Override
public double getHumidity(Layer layer, Vec2d pos) {
return 0;
}
}

View File

@ -20,6 +20,39 @@ import projectzombie.world.layer.Layer;
public class LayerGenCaves extends LayerGen
{
@Override
public double getTemperatureStatic(Layer layer, Vec2d pos)
{
// Get the noise generator
OpenSimplexNoise terrain_noise = layer.noise_gens[0];
return MathHelpers.map(terrain_noise.eval(pos.x/64.0, pos.y/64.0), -1, 1, 0, 0.6);
}
@Override
public double getTemperatureDynamic(Layer layer, Vec2d pos) {
return getTemperatureStatic(layer, pos);
}
@Override
public double getHumidity(Layer layer, Vec2d pos)
{
// Get the noise generator
OpenSimplexNoise terrain_noise = layer.noise_gens[1];
return MathHelpers.map(terrain_noise.eval(pos.x/64.0, pos.y/64.0), -1, 1, 0.3, 0.8);
}
@Override
public void init(Layer layer) {
super.init(layer);
Random rand = new Random(layer.seed);
layer.noise_gens = new OpenSimplexNoise[] {
new OpenSimplexNoise(rand.nextLong()),
new OpenSimplexNoise(rand.nextLong())
};
}
@Override
public void generateChunk(Chunk chunk, Layer layer, Random rand, Vec2i c_pos)
{
@ -79,6 +112,18 @@ public class LayerGenCaves extends LayerGen
if(chunk.getBackTile(chest_pos).tile == getTileDestroyed().tile) {
chunk.setFrontTile(new TileState(Tiles.CHEST, 1), chest_pos);
}
// Spawn entities
Entity zombie = new EntityZombie(new Vec2d(
chunk.c_pos.x * 16 + RandomHelpers.randrange(rand, 0, 16),
chunk.c_pos.y * 16 + RandomHelpers.randrange(rand, 0, 16)));
if(
chunk.getBackTile(new Vec2i((int)zombie.pos.x,
(int)zombie.pos.y)).tile == getTileDestroyed().tile
) {
chunk.spawnEntity(zombie);
}
}
@Override
@ -119,14 +164,6 @@ public class LayerGenCaves extends LayerGen
return new ColorRange(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0));
}
@Override
public double getTemperatureStatic(Layer layer, Vec2d pos) {
return 0.5;
}
@Override
public double getTemperatureDynamic(Layer layer, Vec2d pos) {
return 0.5;
}
}

View File

@ -38,14 +38,23 @@ public class LayerGenEarth extends LayerGen
return MathHelpers.map(terrain_noise.eval(pos.x/64.0, pos.y/64.0), -1, 1, light, 0.5 + light);
}
@Override
public double getHumidity(Layer layer, Vec2d pos)
{
// Get the noise generator
OpenSimplexNoise terrain_noise = layer.noise_gens[1];
return MathHelpers.map(terrain_noise.eval(pos.x/64.0, pos.y/64.0), -1, 1, 0, 1);
}
@Override
public void init(Layer layer) {
super.init(layer);
Random rand = new Random(layer.lseed);
Random rand = new Random(layer.seed);
layer.noise_gens = new OpenSimplexNoise[] {
new OpenSimplexNoise(rand.nextLong()),
new OpenSimplexNoise(rand.nextLong())
};
}

View File

@ -170,5 +170,10 @@ public class LayerGenLavaCaves extends LayerGen
public double getTemperatureDynamic(Layer layer, Vec2d pos) {
return 0.7;
}
@Override
public double getHumidity(Layer layer, Vec2d pos) {
return 0;
}
}

View File

@ -20,8 +20,10 @@ uniform vec2 lightmap_size;
uniform vec2 tex_cut;
uniform vec4 color;
vec3 color_grass_min = vec3(0.05, 0.8, 0);
vec3 color_grass_max = vec3(1, 0.6, 0);
vec3 color_grass_hot_wet = vec3(0.05, 0.8, 0);
vec3 color_grass_hot_dry = vec3(1, 0.6, 0);
vec3 color_grass_cold_wet = vec3(0.075, 0.533, 0.047);
vec3 color_grass_cold_dry = vec3(0.812, 0.761, 0);
float map(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
@ -45,6 +47,14 @@ float smoothStep(float a) {
return a * a * (3 - 2 * a);
}
float interpolate2(float x, float y, float v00, float v01, float v10, float v11) {
return (v00 * x + v10 * (1 - x)) * y + (v01 * x + v11 * (1 - x)) * (1 - y);
}
vec3 interpolate2RGB(float x, float y, vec3 v00, vec3 v01, vec3 v10, vec3 v11) {
return (v00 * x + v10 * (1 - x)) * y + (v01 * x + v11 * (1 - x)) * (1 - y);
}
void main()
{
vec4 light = texture(lightmap, vec2(
@ -54,10 +64,12 @@ void main()
vec3 light_day = mapVec(scaleLight(light.r), 0, 1, lighting_day_low, lighting_day_high);
vec3 light_src = vec3(1, 1, 1) * (scaleLight(light.g) - abs(pLightMapPos.y) * 0.1);
vec4 color_white = vec4(1, 1, 1, 1);
vec4 color_grass = vec4(mapVec(smoothStep(light.b), 0, 1, color_grass_min, color_grass_max), 1);
vec4 color_grass = vec4(interpolate2RGB(
smoothStep(light.b), smoothStep(light.a),
color_grass_cold_dry, color_grass_hot_dry,
color_grass_cold_wet, color_grass_hot_wet), 1);
FragColor = texture(atlas, pTexture) * (mod(int(pFlags / 4), 2) == 1 ? color_grass : color_white) *
FragColor = texture(atlas, pTexture) * (mod(int(pFlags / 4), 2) == 1 ? color_grass : vec4(1,1,1,1)) *
color * vec4(biggest(light_day, light_src), 1);
discard(FragColor.a == 0 || (pPos.x > tex_cut.y && tex_cut.x > 0.5));

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

View File

@ -1,157 +1,159 @@
./text/char_question.png
./text/char_l_a.png
./text/char_u_j.png
./text/char_l_u.png
./text/char_u_s.png
./text/char_l_s.png
./text/char_plus.png
./text/char_l_e.png
./text/char_7.png
./text/char_minus.png
./text/char_u_r.png
./text/char_u_l.png
./text/char_obracket.png
./text/char_u_m.png
./text/char_l_t.png
./text/char_percent.png
./text/char_l_y.png
./text/char_0.png
./text/char_4.png
./text/char_l_r.png
./text/char_l_m.png
./text/char_cbracket.png
./text/char_u_g.png
./text/char_u_q.png
./text/char_u_i.png
./text/char_l_w.png
./text/char_l_v.png
./text/char_fslash.png
./text/char_u_p.png
./text/char_gthan.png
./text/char_8.png
./text/char_unknown.png
./text/char_u_n.png
./text/char_l_i.png
./text/char_u_y.png
./text/char_l_p.png
./text/char_lthan.png
./text/char_l_g.png
./text/char_bslash.png
./text/char_1.png
./text/char_u_z.png
./text/char_l_f.png
./text/char_u_w.png
./text/char_9.png
./text/char_l_x.png
./text/char_l_o.png
./text/char_equals.png
./text/char_l_d.png
./text/char_dollar.png
./text/char_hashtag.png
./text/char_l_q.png
./text/char_u_o.png
./text/char_6.png
./text/char_u_d.png
./text/char_u_e.png
./text/char_exclamation.png
./text/char_vertical.png
./text/char_u_k.png
./text/char_u_c.png
./text/char_l_n.png
./text/char_u_b.png
./text/char_u_f.png
./text/char_l_h.png
./text/char_l_k.png
./text/char_u_t.png
./text/char_3.png
./text/char_u_v.png
./text/char_u_h.png
./text/char_u_a.png
./text/char_l_b.png
./text/char_underscore.png
./text/char_u_x.png
./text/char_comma.png
./text/char_l_l.png
./text/char_5.png
./text/char_colon.png
./text/char_l_z.png
./text/char_space.png
./text/char_2.png
./text/char_l_j.png
./text/char_fullstop.png
./text/char_l_c.png
./text/char_u_u.png
./tile/rock.png
./tile/ladder.png
./tile/water.png
./tile/ladder_up.png
./tile/cactus4.png
./tile/cactus2.png
./tile/dirt.png
./tile/wall.png
./tile/tree_base.png
./tile/cactus1.png
./tile/tunnel_down.png
./tile/stone.png
./tile/snow.png
./tile/boss_portal.png
./tile/sand.png
./tile/lantern.png
./tile/chest.png
./tile/cactus3.png
./tile/lava.png
./tile/tree_leaves.png
./tile/lava_flow.png
./tile/snow_pile.png
./tile/grass.png
./tile/rock_sandstone.png
./list.txt
./player/player_white_front_moving.png
./player/player_white_back_moving.png
./player/player_black_back_moving.png
./player/player_black_back_still.png
./item/rock.png
./item/ammo_box.png
./item/shield_upgrade.png
./item/grappling_hook.png
./item/health_potion.png
./item/gun_upgrade.png
./player/player_white_back_still.png
./player/player_white_front_still.png
./player/player_black_front_moving.png
./player/player_black_front_still.png
./particle/smoke_trail.png
./particle/water.png
./particle/smoke_0.png
./particle/smoke_1.png
./particle/blood.png
./particle/lava.png
./particle/bullet.png
./particle/smoke_2.png
./particle/smoke_4.png
./particle/smoke_3.png
./particle/smoke_5.png
./gui/health_empty.png
./gui/button_hover.png
./gui/button_normal.png
./gui/hotbar.png
./gui/health_full.png
./gui/hotbar_selected.png
./gui/shield.png
./player/player_black_back_moving.png
./player/player_black_back_still.png
./player/player_white_back_moving.png
./player/player_white_front_moving.png
./gui/water.png
./gui/gun.png
./tile/cactus4.png
./tile/dirt.png
./tile/lantern.png
./tile/wall.png
./tile/cactus2.png
./tile/rock.png
./tile/water.png
./tile/stone.png
./tile/tree_leaves.png
./tile/ladder_up.png
./tile/lava_flow.png
./tile/grass.png
./tile/chest.png
./tile/lava.png
./tile/snow.png
./tile/rock_sandstone.png
./tile/cactus1.png
./tile/tunnel_down.png
./tile/snow_pile.png
./tile/boss_portal.png
./tile/ladder.png
./tile/sand.png
./tile/tree_base.png
./tile/cactus3.png
./entity/flare.png
./entity/grappling_hook.png
./entity/zombie_back_moving.png
./entity/tnt.png
./gui/health_empty.png
./gui/hotbar_selected.png
./gui/health_full.png
./gui/temperature.png
./gui/hotbar.png
./gui/button_normal.png
./gui/shield.png
./gui/button_hover.png
./text/char_bslash.png
./text/char_dollar.png
./text/char_l_w.png
./text/char_u_d.png
./text/char_u_t.png
./text/char_space.png
./text/char_l_x.png
./text/char_l_k.png
./text/char_6.png
./text/char_unknown.png
./text/char_comma.png
./text/char_obracket.png
./text/char_u_w.png
./text/char_7.png
./text/char_l_f.png
./text/char_vertical.png
./text/char_plus.png
./text/char_u_a.png
./text/char_9.png
./text/char_u_k.png
./text/char_u_n.png
./text/char_percent.png
./text/char_u_m.png
./text/char_exclamation.png
./text/char_1.png
./text/char_l_q.png
./text/char_l_z.png
./text/char_l_h.png
./text/char_u_c.png
./text/char_l_g.png
./text/char_l_s.png
./text/char_fullstop.png
./text/char_u_j.png
./text/char_l_m.png
./text/char_l_t.png
./text/char_u_v.png
./text/char_colon.png
./text/char_l_i.png
./text/char_l_y.png
./text/char_u_l.png
./text/char_u_e.png
./text/char_5.png
./text/char_2.png
./text/char_3.png
./text/char_l_p.png
./text/char_fslash.png
./text/char_l_u.png
./text/char_u_f.png
./text/char_u_u.png
./text/char_l_e.png
./text/char_l_l.png
./text/char_u_g.png
./text/char_u_q.png
./text/char_u_b.png
./text/char_l_o.png
./text/char_minus.png
./text/char_l_v.png
./text/char_lthan.png
./text/char_u_s.png
./text/char_equals.png
./text/char_8.png
./text/char_underscore.png
./text/char_u_x.png
./text/char_0.png
./text/char_l_d.png
./text/char_l_c.png
./text/char_l_j.png
./text/char_u_z.png
./text/char_u_h.png
./text/char_hashtag.png
./text/char_gthan.png
./text/char_cbracket.png
./text/char_u_i.png
./text/char_question.png
./text/char_u_o.png
./text/char_u_y.png
./text/char_l_r.png
./text/char_l_b.png
./text/char_l_a.png
./text/char_l_n.png
./text/char_u_p.png
./text/char_u_r.png
./text/char_4.png
./entity/armored_zombie_back_moving.png
./entity/armored_zombie_front_moving.png
./entity/dummy.png
./entity/armored_zombie_front_still.png
./entity/armored_zombie_back_still.png
./entity/zombie_front_moving.png
./entity/boss1/boss_walking_firing.png
./entity/zombie_front_still.png
./entity/tnt.png
./entity/flare.png
./entity/boss1/boss_walking.png
./entity/boss1/boss_firing.png
./entity/boss1/boss_still.png
./entity/boss1/boss_walking.png
./entity/boss1/boss_walking_firing.png
./entity/armored_zombie_back_still.png
./entity/armored_zombie_front_moving.png
./entity/grappling_hook.png
./entity/zombie_back_still.png
./entity/zombie_front_still.png
./item/grappling_hook.png
./item/gun_upgrade.png
./item/shield_upgrade.png
./item/rock.png
./item/ammo_box.png
./item/health_potion.png
./entity/dummy.png
./entity/zombie_back_moving.png
./entity/armored_zombie_front_still.png
./entity/zombie_front_moving.png
./particle/smoke_1.png
./particle/water.png
./particle/blood.png
./particle/smoke_3.png
./particle/smoke_4.png
./particle/smoke_2.png
./particle/smoke_0.png
./particle/bullet.png
./particle/lava.png
./particle/smoke_trail.png
./particle/smoke_5.png