Generate the world when pressing the play button

As opposed to when the game starts, speeding up the title screen
pull/12/head
Caroline Bell 2020-02-25 16:29:17 -08:00
parent a12ae923d3
commit f096950bbd
2 changed files with 14 additions and 16 deletions

View File

@ -1,5 +1,7 @@
package com.github.halotroop.litecraft; package com.github.halotroop.litecraft;
import java.util.Random;
import com.github.halotroop.litecraft.world.*; import com.github.halotroop.litecraft.world.*;
import com.github.hydos.ginger.engine.api.*; import com.github.hydos.ginger.engine.api.*;
import com.github.hydos.ginger.engine.api.game.*; import com.github.hydos.ginger.engine.api.game.*;
@ -43,15 +45,6 @@ public class Litecraft extends Game
data = new GameData(player, camera, 30); data = new GameData(player, camera, 30);
data.handleGuis = false; data.handleGuis = false;
ginger3D.setup(new MasterRenderer(camera), this); ginger3D.setup(new MasterRenderer(camera), this);
//YeS?
world = new World(0L);
for(int i = 0; i<10;i++) {
for(int k = 0; k<10;k++) {
Chunk exampleManualChunk = world.getChunk(i, -1, k);
exampleManualChunk.setRender(true);
}
}
FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt"); FontType font = new FontType(Loader.loadFontAtlas("candara.png"), "candara.fnt");
ginger3D.setGlobalFont(font); ginger3D.setGlobalFont(font);
@ -65,9 +58,9 @@ public class Litecraft extends Game
playButton.show(data.guis); playButton.show(data.guis);
// GuiTexture title = new GuiTexture(Loader.loadTextureDirectly("/textures/guis/title.png"), new Vector2f(0, 0.8F), new Vector2f(0.25f, 0.1f)); // GuiTexture title = new GuiTexture(Loader.loadTextureDirectly("/textures/guis/title.png"), new Vector2f(0, 0.8F), new Vector2f(0.25f, 0.1f));
// data.guis.add(title); // data.guis.add(title);
//start the game loop
oldWindowWidth = Window.width; oldWindowWidth = Window.width;
oldWindowHeight = Window.height; oldWindowHeight = Window.height;
//start the game loop
ginger3D.startGame(); ginger3D.startGame();
} }
@ -86,8 +79,8 @@ public class Litecraft extends Game
oldWindowWidth = Window.width; oldWindowWidth = Window.width;
oldWindowHeight = Window.height; oldWindowHeight = Window.height;
ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0)); ginger3D.gingerRegister.masterRenderer.renderShadowMap(data.entities, data.lights.get(0));
if (isInWorld) if (this.world != null)
{ ginger3D.renderWithoutTerrain(this, world); } { ginger3D.renderWithoutTerrain(this, this.world); }
ginger3D.renderOverlays(this); ginger3D.renderOverlays(this);
ginger3D.postRender(); ginger3D.postRender();
} }
@ -96,15 +89,13 @@ public class Litecraft extends Game
public void update() public void update()
{ {
data.player.move(null); data.player.move(null);
GUIText text = ginger3D.gingerRegister.texts.get(0);
TextureButton playButton = ginger3D.gingerRegister.guiButtons.get(0); TextureButton playButton = ginger3D.gingerRegister.guiButtons.get(0);
boolean isClicked = playButton.isClicked();
playButton.update(); playButton.update();
if (isClicked) if (playButton.isClicked())
{ {
Window.lockMouse(); Window.lockMouse();
playButton.hide(data.guis); playButton.hide(data.guis);
isInWorld = true; world = new World((long) new Random().nextInt());
} }
} }
} }

View File

@ -12,6 +12,13 @@ public class World implements BlockAccess
public World(long seed) public World(long seed)
{ {
chunks = new Long2ObjectArrayMap<>(); chunks = new Long2ObjectArrayMap<>();
for(int i = 0; i<10;i++) {
for(int k = 0; k<10;k++) {
Chunk exampleManualChunk = this.getChunk(i, -1, k);
exampleManualChunk.setRender(true);
}
}
} }
public Chunk getChunk(int chunkX, int chunkY, int chunkZ) public Chunk getChunk(int chunkX, int chunkY, int chunkZ)