Compare commits

..

106 Commits
v0.1 ... master

Author SHA1 Message Date
josua 197a753558 Made the UI easier to see after post-processing and added a slight
"darkness" effect around the corners of the screen
2020-12-15 15:54:07 +11:00
jsrobson10 2057d78cd0 Made the tile selection box transparent, fixed some syntax errors in the
shaders, and improved break particles.
2020-10-21 13:32:32 +11:00
jsrobson10 01a86a5a1e Fixed some peter planning 2020-10-20 11:25:38 +11:00
jsrobson10 8489503192 Made some small tweaks to fog and tile indicators 2020-10-20 11:21:27 +11:00
jsrobson10 8f3c65633e Merge branch 'master' of ssh://git@onewaycoding.com:8000/jsrobson10/ProjectZombie.git 2020-10-20 10:36:23 +11:00
jsrobson10 51c5e52057 Added wood walls, fixed some collision detection, added lines and tile
break indicators for the user, added an indicator to tell the user when
they can use a certain tile.
2020-10-20 10:36:00 +11:00
josua 69eacab225 Fixed buffers to work in newer versions of java 2020-10-04 23:11:25 +11:00
jsrobson10 6ef6277148 Adding wood walls, fully implemented wood floors 2020-09-24 14:22:46 +10:00
jsrobson10 02355bfedc Added a queue to the saving system to prevent world corruption from
chunks saving without the player. This also removes possibility for a
saving based duplication glitch. Started adding more wood items.
2020-09-22 12:11:40 +10:00
josua 8ca2fe6b91 Added more textures 2020-09-22 09:18:05 +10:00
jsrobson10 9394ae9ac1 Added more ores, fixed light based heat sources 2020-09-16 17:22:02 +10:00
jsrobson10 1e1cc5fb5b Sync workspace with server 2020-09-15 19:58:53 +10:00
josua ce06e1bb53 Made bdf use the .gz file ending to say its gzip 2020-09-10 12:30:23 +10:00
josua 76fce435b1 Made chunk saving asynchronous, added auto saving and asynchronous
saving, seperated chunks into their own files, made chunks unload to a
file instead of to memory, fixed a lighting based performance bug.
2020-08-27 23:49:55 +10:00
jsrobson10 c5e36b6f79 Improved world gen and made the main menu demo world not re-generate 2020-08-27 14:27:30 +10:00
josua a6b8edcd67 Made temperature/humidity generate on world gen 2020-08-27 09:12:57 +10:00
jsrobson10 877c5371a0 Started making chunks asynchronous 2020-08-26 20:07:23 +10:00
josua 0cbb9c8551 Started working on better world gen 2020-08-26 11:02:26 +10:00
jsrobson10 5de32258ca Added timers and specific item based checks for items 2020-08-25 19:31:17 +10:00
jsrobson10 70d7faaf98 Started adding timers and torches 2020-08-25 12:11:15 +10:00
jsrobson10 25314cfebb Made the lighting thread safe 2020-08-20 12:08:39 +10:00
jsrobson10 7c176bbcde Removed the worker process and replaced it with worker threads.
Updated binary data format.
2020-08-19 14:02:43 +10:00
josua e08cdf66fc Added more tools, resources, added blast furnace, clay pot, started
adding metals, ores, improved water indicator.
2020-08-11 11:12:03 +10:00
jsrobson10 6ee17375a6 Made solid tile collision correction velocity based 2020-08-07 16:40:31 +10:00
josua 20b1dac4a6 Added tile entities, tile/entity placement guides, started working on
campfires
2020-08-07 13:58:29 +10:00
jsrobson10 d5815eef50 Fixed item info on hover, changed item meta to a modifier system. 2020-08-05 18:25:46 +10:00
josua 6e69fe2fcd Created a working crafting GUI 2020-08-05 12:45:00 +10:00
jsrobson10 505a09a4ff Adding recipe cards 2020-08-04 16:01:07 +10:00
josua 261ba8c69b Started working on a recipe card object 2020-07-29 11:18:53 +10:00
jsrobson10 d88b0946b5 Added a way to craft stuff 2020-07-28 18:33:05 +10:00
josua af72420f9d Fixed issues with inventory hover and picking up inventory items 2020-07-28 13:15:18 +10:00
jsrobson10 c60d03428d Added recipe init function 2020-07-27 12:50:34 +10:00
josua 507e1ada0e Added a save menu, fixed issues with loading from saves, updated to BDF
3, started working on a crafting system.
2020-07-27 11:13:24 +10:00
jsrobson10 fdf5fad146 Renamed alot of GUI stuff for consistancy, worked on saves GUI, added
vsync setting.
2020-07-23 14:22:12 +10:00
josua 96eb85d55a Working on save cards and better culling options 2020-07-23 11:00:39 +10:00
jsrobson10 16b04a62ba Started adding a proper save menu 2020-07-22 19:39:11 +10:00
josua 2946a7ec9e Added shadow quality setting, updated the BDF to fix boolean 2020-07-22 11:07:47 +10:00
jsrobson10 96a0f0fdb9 Added rain texture 2020-07-21 14:25:30 +10:00
jsrobson10 c4250dcfff Turned down the blood abit 2020-07-21 14:25:22 +10:00
josua 3cf6f0cc1e Added optimisations to the shadow renderer and added fog 2020-07-21 09:26:20 +10:00
jsrobson10 5bd3984997 Added shadows 2020-07-20 16:14:54 +10:00
josua ff3bb85d7c Created an inventory,
more resources (logs, acorns, flint, hemp, sandstone, snow),
optimised items and bullets,
started setting up possibility for shadow mapping and/or reflections,
improved models (trees, cacti, hemp, rocks),
added optimizations for particles,
started working on better player models,
fixed issues with the font.
2020-07-16 00:26:50 +10:00
jsrobson10 135d6ef185 Added wind, fixed some issues with particles 2020-07-05 09:30:21 +10:00
josua fe1f97f248 Removed lots of unused code 2020-07-01 12:37:04 +10:00
josua 55ea5e6c55 Fixed lighting graphical issues 2020-06-30 10:11:08 +10:00
josua afd16a7389 Started fixing floating point errors in the shaders, optimised particles and path finding 2020-06-29 12:44:02 +10:00
josua 3838754611 Added dynamic break particles, improved the particle system 2020-06-27 22:01:57 +10:00
jsrobson10 4f7b499217 Added temperature to the player and added moisture 2020-06-26 15:11:40 +10:00
josua 4b527a0db0 Added temperature 2020-06-25 12:42:29 +10:00
jsrobson10 321d07ceb6 Updated the math library to use faster math functions, started working
on biomes and temperature
2020-06-24 17:06:49 +10:00
josua a0d6d87dcf Made dynamic lighting smoother 2020-06-24 11:07:41 +10:00
jsrobson10 0ee4243011 Started making lighting more efficient 2020-06-23 16:56:32 +10:00
josua ecfb03d62d Fixed issues with smooth lighting and added dynamic lighting. Fixed
issues with spawning and fixed issues with expensive pathfinding.
2020-06-22 23:35:29 +10:00
jsrobson10 7ffa6c1023 Fixed text rendering, added more conditions to recalculate lighting. 2020-06-22 15:56:52 +10:00
josua 4f9cb191c4 Added smooth lighting 2020-06-22 12:22:11 +10:00
jsrobson10 878410abbf Started working on the worker for lighting 2020-06-21 18:48:01 +10:00
josua 0098d22927 Started working on multi-processing 2020-06-18 12:49:38 +10:00
jsrobson10 01d221c94a Started work on lighting 2020-06-17 18:25:17 +10:00
jsrobson10 8c29c924f6 Removed some bdf files and added them to gitignore 2020-06-17 10:59:19 +10:00
josua 3b612fc61d Fixed button collision detection 2020-06-17 10:54:51 +10:00
jsrobson10 7b8de0fa63 Started working on buttons 2020-06-16 16:24:29 +10:00
josua eacf39f27b Got some gui working 2020-06-16 10:06:55 +10:00
jsrobson10 b483234d9c Actually got some gui stuff rendering 2020-06-15 15:14:47 +10:00
josua b553923a3d Created a functional world renderer 2020-06-15 10:56:52 +10:00
josua 95bd4df7ef Actually got something rendering 2020-06-13 17:26:40 +10:00
jsrobson10 7dbe75a497 Changed how animated textures work,
continuing on working on fixing the renderer.
2020-06-12 18:34:05 +10:00
josua 9e6ef227cc Started changing the graphics from old opengl to opengl core profile 2020-06-10 11:18:43 +10:00
josua 400746b88a Sync workspace with server 2020-06-02 11:30:03 +10:00
josua 3c9b7a23e9 Redid lighting and made it asyncronous 2020-03-13 22:02:16 +11:00
josua d24f9296a5 Redid the games lighting and made it asyncronous. 2020-03-13 22:01:28 +11:00
josua 5aa5a6a989 Removed the built in updator script 2019-12-06 13:47:56 +11:00
josua fe759d7b28 Added controller support to the GUI buttons 2019-12-06 13:17:47 +11:00
josua 7ca1d80e6a Fixed checkMouseHover reliability issues 2019-12-06 11:41:39 +11:00
josua b2f26fd838 Changed the window name "Catalyst Survival" to "Project Zombie" 2019-12-05 13:45:11 +11:00
josua 5f83236d3b Added some optimisations (removed unused imports and variables) 2019-12-05 13:43:06 +11:00
josua b8d6f2720b Added an animated main menu 2019-12-05 13:21:46 +11:00
josua 9584f7c882 Started adding buttons, better menus 2019-12-04 19:53:54 +11:00
josua f26416a6d5 Changed name (again) from "Catalyst Survival" to "Project Zombie", added
basic tickrate changing functionality
2019-11-18 08:52:04 +11:00
josua 25e4123d7a Changed the games name from "ShooterGame" to "Catalyst Survival" 2019-11-16 16:16:14 +11:00
josua 1fe8670169 Made portals unbreakable, made the boss immune to knockback, fixed
support/crashing issues with other controllers.
2019-10-21 09:17:45 +11:00
josua 4a53342a73 Added fullscreen toggles, improved keyboard controls (made new ones),
added a mouse visibility option for menus
2019-10-16 10:58:33 +11:00
josua 868b3481ee Made smoke particles disappear gradually 2019-10-15 13:20:21 +11:00
josua 40a0c6474d Added respawning and a death screen 2019-10-15 12:43:33 +11:00
josua ace02dbddf Changed gun sounds, made particles more efficient. 2019-10-14 14:06:48 +11:00
josua 90c7707e5a Created a more efficient rotation function 2019-09-27 12:24:49 +10:00
josua 3a25f34520 Improved efficiency with multiple particles with constant velocity 2019-09-25 13:49:52 +10:00
josua bc43eade55 Fixed texture scaling issues, changed the UI due to the change in
scaling. Made rocks block light.
2019-09-22 21:09:35 +10:00
josua ef6fe56c89 Improved the controls; made them more changable and fixed issues with
the keyboard and the controller being used together to cheat (fast speed
and fast gun)
2019-09-22 10:55:00 +10:00
Josua Robson d88b433b11 Merge branch 'save' of jsrobson10/ShooterGame into master 2019-09-21 16:33:41 +10:00
josua 1acd28662c Updated the boss textures 2019-09-21 16:30:45 +10:00
josua 4b9ee51690 Add a position parameter to the entity 2019-09-21 16:30:19 +10:00
josua d4426b8b3c Created a functional boss fight 2019-09-21 12:54:26 +10:00
josua 26d55ab6ca Added a boss fight and the grappling hook. 2019-09-20 12:32:48 +10:00
josua 51ece50ac0 Added day/night cycle 2019-09-17 11:42:43 +10:00
josua 85728d450b Added extra items (light sources), added random tile ticks, added more
debug tools, changed how the world works.
2019-09-16 14:35:09 +10:00
josua 54b6262813 Fixed lighting, lava caves, harder enemies, stronger upgrades. 2019-09-13 13:44:44 +10:00
josua b672a176b8 Changed RGB light to a single brightness value to save resources. 2019-09-11 14:14:03 +10:00
josua b15b396935 Started adding RGB light sources, cleaned up some code for faded tiles. 2019-09-10 12:37:31 +10:00
josua 888e359f9c Gave rendering access to the tilestate instead of the meta 2019-09-04 17:06:27 +10:00
josua a1488570d9 Hotbar now displays item names and info 2019-09-03 13:11:12 +10:00
josua 1343535933 Cleaned unused imports 2019-09-03 12:42:33 +10:00
josua e48d0cfc6c Made items throwable by the player, fixed issues with bullets and chunk
borders.
2019-09-02 14:36:18 +10:00
josua 121c6f10eb Added deaths, added breaking particles 2019-08-31 14:32:28 +10:00
josua 745305e2f3 Fixed player deaths, added breaking particles 2019-08-31 14:32:09 +10:00
josua 44a6cedf3a Added items, started working on break particles 2019-08-31 11:01:47 +10:00
josua bb13aaa09f Added ammo 2019-08-29 09:44:07 +10:00
686 changed files with 22172 additions and 12782 deletions

44
.classpath Normal file → Executable file
View File

@ -1,9 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/binary-data-format-v1.3.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/binary-data-format-v3.0.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/GlEngine.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/mainloop.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/LWJGL"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-javadoc.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-natives-linux.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-natives-macos.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-natives-windows.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-glfw-sources.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-natives-linux.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-natives-macos.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-natives-windows.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-javadoc.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-natives-linux.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-natives-macos.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-natives-windows.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-openal-sources.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-javadoc.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-natives-linux.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-natives-macos.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-natives-windows.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengles-sources.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-javadoc.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-natives-linux.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-natives-macos.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-natives-windows.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-opengl-sources.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-javadoc.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-natives-linux.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-natives-macos.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-natives-windows.jar"/>
<classpathentry kind="lib" path="/home/josua/code/Java Libraries/lwjgl-3.2.2-lightweight/lwjgl-stb-sources.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>

2
.gitignore vendored Normal file → Executable file
View File

@ -1 +1,3 @@
/bin/
/run/
hs_err_pid*

2
.project Normal file → Executable file
View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ShooterGame</name>
<name>ProjectZombie</name>
<comment></comment>
<projects>
</projects>

0
.settings/org.eclipse.jdt.core.prefs Normal file → Executable file
View File

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

153
src/projectzombie/Main.java Executable file
View File

@ -0,0 +1,153 @@
package projectzombie;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import bdf.types.BdfReader;
import gl_engine.MathHelpers;
import mainloop.manager.MainloopManager;
import projectzombie.audio.AudioEngine;
import projectzombie.audio.AudioSources;
import projectzombie.display.DisplayStatsEventHandler;
import projectzombie.display.DisplayWindow;
import projectzombie.entity.EntityEventHandler;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Entities;
import projectzombie.init.ItemModifiers;
import projectzombie.init.Items;
import projectzombie.init.LayerGenerators;
import projectzombie.init.Recipes;
import projectzombie.init.Resources;
import projectzombie.init.Sounds;
import projectzombie.init.Tasks;
import projectzombie.init.Tiles;
import projectzombie.input.JoystickCallback;
import projectzombie.input.KeyCallback;
import projectzombie.mainloop.MainloopEventHandler;
import projectzombie.menu.Menu;
import projectzombie.menu.MenuMain;
import projectzombie.settings.Cheats;
import projectzombie.settings.Environment;
import projectzombie.settings.Settings;
import projectzombie.time.GameTimer;
import projectzombie.time.NoSleep;
import projectzombie.util.SaveSystem;
import projectzombie.worker.WorkerTasks;
import projectzombie.worker.WorkerLighting;
import projectzombie.world.World;
import projectzombie.world.chunk.ChunkEventHandler;
public class Main
{
public static BdfReader bdf_saves;
public static Clipboard clipboard;
public static MainloopManager mainloop;
public static DisplayWindow window;
public static EntityPlayer player;
public static World world;
public static AudioEngine audio;
public static Random rand = new Random();
public static Menu menu;
public static WorkerLighting workerLighting;
public static WorkerTasks[] workerChunks;
public static boolean game_paused = false;
public static boolean running = true;
public static int tickrate = 10;
public static void main(String[] args) throws IOException
{
try
{
Environment.init(args);
File global_dir = new File(Environment.gdir);
// Make this directory if it doesn't exist
if(!global_dir.isDirectory())
{
if(global_dir.exists()) {
global_dir.delete();
}
global_dir.mkdirs();
}
Runtime runtime = Runtime.getRuntime();
int cores = runtime.availableProcessors();
clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
workerLighting = new WorkerLighting();
workerLighting.start();
int workers = cores - 2;
if(workers < 1) {
workers = 1;
}
workerChunks = new WorkerTasks[workers];
for(int i=0;i<workerChunks.length;i++) {
workerChunks[i] = new WorkerTasks();
workerChunks[i].start();
}
MathHelpers.init();
Settings.init();
Cheats.init(args);
Items.init();
ItemModifiers.init();
Entities.init();
Tasks.init();
Tiles.init();
LayerGenerators.init();
Recipes.init();
bdf_saves = SaveSystem.readBDF("./saves.bdf.gz");
// Create the display
window = new DisplayWindow();
window.init();
// Load the resources
Resources.loadResources();
// Initialize the sound engine
audio = new AudioEngine();
audio.init();
// Initialise the sounds
AudioSources.init();
Sounds.init();
// Initialize the gamepad
JoystickCallback.JOYSTICK_CALLBACK.init();
// Create the mainloop
mainloop = new MainloopManager(MainloopEventHandler.MAINLOOP_EVENT_HANDLER);
mainloop.register(DisplayStatsEventHandler.DISPLAY_STATS_EVENT_HANDLER);
mainloop.register(MainloopEventHandler.MAINLOOP_EVENT_HANDLER);
mainloop.register(EntityEventHandler.ENTITY_EVENT_HANDLER);
mainloop.register(ChunkEventHandler.CHUNK_EVENT_HANDLER);
mainloop.register(JoystickCallback.JOYSTICK_CALLBACK);
mainloop.register(new KeyCallback());
mainloop.register(new GameTimer());
mainloop.register(new NoSleep());
mainloop.register(window);
// Start the mainloop
menu = new MenuMain();
mainloop.start();
}
finally
{
// Kill the worker threads
running = false;
}
}
}

View File

@ -1,15 +1,18 @@
package shootergame.audio;
package projectzombie.audio;
import static org.lwjgl.openal.ALC11.*;
import static org.lwjgl.openal.AL11.*;
import static org.lwjgl.openal.ALC10.ALC_DEFAULT_DEVICE_SPECIFIER;
import static org.lwjgl.openal.ALC10.alcCloseDevice;
import static org.lwjgl.openal.ALC10.alcCreateContext;
import static org.lwjgl.openal.ALC10.alcDestroyContext;
import static org.lwjgl.openal.ALC10.alcGetString;
import static org.lwjgl.openal.ALC10.alcMakeContextCurrent;
import static org.lwjgl.openal.ALC10.alcOpenDevice;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.ALC;
import org.lwjgl.openal.ALCCapabilities;
import org.lwjgl.openal.ALCapabilities;
import shootergame.util.math.vec.Vec3d;
public class AudioEngine
{
String deviceName;

View File

@ -1,44 +1,47 @@
package shootergame.audio;
package projectzombie.audio;
import static org.lwjgl.openal.AL10.AL_BUFFER;
import static org.lwjgl.openal.AL10.AL_FORMAT_MONO16;
import static org.lwjgl.openal.AL10.AL_FORMAT_STEREO16;
import static org.lwjgl.openal.AL10.AL_GAIN;
import static org.lwjgl.openal.AL10.AL_POSITION;
import static org.lwjgl.openal.AL10.alBufferData;
import static org.lwjgl.openal.AL10.alGenBuffers;
import static org.lwjgl.openal.AL10.alSource3f;
import static org.lwjgl.openal.AL10.alSourcePlay;
import static org.lwjgl.openal.AL10.alSourceStop;
import static org.lwjgl.openal.AL10.alSourcef;
import static org.lwjgl.openal.AL10.alSourcei;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.AL11;
import org.lwjgl.openal.ALC10;
import org.lwjgl.stb.STBVorbis;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.libc.LibCStdlib;
import static org.lwjgl.openal.AL10.AL_BUFFER;
import static org.lwjgl.openal.AL10.AL_GAIN;
import static org.lwjgl.openal.AL10.AL_POSITION;
import static org.lwjgl.openal.AL10.alSource3f;
import static org.lwjgl.openal.AL10.alSourcePlay;
import static org.lwjgl.openal.AL10.alSourcef;
import static org.lwjgl.openal.AL10.alSourcei;
import static org.lwjgl.openal.AL11.*;
import shootergame.Main;
import shootergame.display.Camera;
import shootergame.resources.Resource;
import shootergame.util.math.MathHelpers;
import shootergame.util.math.vec.Vec2d;
import shootergame.util.math.vec.Vec3d;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.display.Camera;
import projectzombie.resources.Resource;
public class AudioObject
{
double volume;
int bufferPointer;
Resource resource;
boolean error;
int channels;
int sample_rate;
int output;
public AudioObject(Resource resource)
public AudioObject(Resource resource, double volume)
{
// Store the argument values
this.resource = resource;
this.volume = volume;
this.error = false;
}
public void init()
@ -52,6 +55,11 @@ public class AudioObject
ByteBuffer resource_buffer = resource.getByteBuffer();
ShortBuffer audio = STBVorbis.stb_vorbis_decode_memory(resource_buffer, channels_buf, sample_rate_buf);
if(audio == null) {
error = true;
return;
}
// Get the channels and the sample rate
channels = channels_buf.get();
sample_rate = sample_rate_buf.get();
@ -66,6 +74,7 @@ public class AudioObject
// Send the data to OpenAL
bufferPointer = alGenBuffers();
alBufferData(bufferPointer, format, audio, sample_rate);
// Free some c buffers
@ -75,28 +84,20 @@ public class AudioObject
public void play(Vec3d pos, double volume)
{
// Get the player pos
Vec2d p_pos = Main.player.pos;
if(error) {
return;
}
// Convert the angle to radians
double angle_r = Math.toRadians(Main.player.angle + 90);
// Calculate the translation
double x = ( pos.x - p_pos.x );
double y = ( pos.y - p_pos.y );
double z = pos.z;
// Calculate the rotation
Vec2d rotated = MathHelpers.rotate2(new Vec2d(x, y), angle_r);
x = rotated.x;
y = rotated.y;
// Calculate the position relative to the player
Matrix4 matrix = Camera.camera.matrix;
Vec3d vec = Matrix4.multiply(matrix, pos.subtract(Main.player.getPos())).multiply(0.125);
// Play the sound with a new source
int source = AudioSources.getSource();
alSourceStop(source);
alSourcei(source, AL_BUFFER, bufferPointer);
alSourcef(source, AL_GAIN, (float)volume);
alSource3f(source, AL_POSITION, (float)x, (float)y, (float)z);
alSourcef(source, AL_GAIN, (float)(volume * this.volume));
alSource3f(source, AL_POSITION, (float)vec.x, (float)vec.y, (float)vec.z);
alSourcePlay(source);
}
}

View File

@ -1,9 +1,8 @@
package shootergame.audio;
package projectzombie.audio;
import java.util.Random;
import shootergame.resources.Resource;
import shootergame.util.math.vec.Vec3d;
import gl_engine.vec.Vec3d;
public class AudioRandom extends AudioObject
{
@ -11,7 +10,7 @@ public class AudioRandom extends AudioObject
private static Random rand = new Random();
public AudioRandom(AudioObject ... audioObjects) {
super(null);
super(null, 0);
// Set the specified parameters
this.audioObjects = audioObjects;

View File

@ -1,10 +1,9 @@
package shootergame.audio;
package projectzombie.audio;
import static org.lwjgl.openal.AL10.alGenSources;
import java.nio.IntBuffer;
import java.util.ArrayList;
import static org.lwjgl.openal.AL11.*;
public class AudioSources
{
static ArrayList<Integer> sources = new ArrayList<Integer>();

View File

@ -0,0 +1,47 @@
package projectzombie.display;
import gl_engine.MathHelpers;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.world.chunk.Chunk;
public class Camera
{
public double x, y;
public double angle = 45;
public Matrix4 matrix;
public Matrix4 projection;
public Matrix4 projection_sun;
public static Camera camera;
public Camera(int w, int h)
{
matrix = Matrix4.identity();
Vec3d pos = Main.player.getPos();
angle = Main.player.angle;
x = pos.x - 0.5;
y = pos.z - 0.5;
matrix = Matrix4.multiply(matrix, Matrix4.rotate(angle + 180, 0, 1, 0));
matrix = Matrix4.multiply(matrix, Matrix4.rotate(-45, 1, 0, 0));
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, 0, -16));
projection = Matrix4.projection((double)w / (double)h, 45, 0.1, Chunk.RENDER_DISTANCE*16+32);
projection = Matrix4.multiply(matrix, projection);
double time = Main.world.getLayer().layergen.getSunPosition();
projection_sun = Matrix4.identity();
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(angle + 180, 0, 1, 0));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.translate(0, 0, 8));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(-angle - 180, 0, 1, 0));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(20, 0, 0, 1));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.rotate(-time, 1, 0, 0));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.translate(0, 0, -(16*Chunk.RENDER_DISTANCE+16)));
projection_sun = Matrix4.multiply(projection_sun, Matrix4.scale(new Vec3d(1.0/20.0, 1.0/20.0, -1.0/(32*Chunk.RENDER_DISTANCE+32))));
}
}

View File

@ -0,0 +1,345 @@
package projectzombie.display;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL33;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import projectzombie.Main;
import projectzombie.entity.Entity;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.util.TileState;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.chunk.ChunkEventHandler;
import projectzombie.world.layer.Layer;
public class DisplayLighting
{
private static class Lighting {
float[] p;
int w, h;
int x, y;
private int getID(int x, int y) {
return (x + y * w) * 3;
}
}
private static int lighting_last_x = 0;
private static int lighting_last_y = 0;
private static boolean lighting_dirty = false;
public static int lightmap;
private static AtomicBoolean lighting_new = new AtomicBoolean(false);
private static AtomicReference<Lighting> lighting = new AtomicReference<DisplayLighting.Lighting>();
public static void setDirty() {
lighting_dirty = true;
}
private static Lighting getLighting() {
return lighting.get();
}
private static void setLighting(Lighting lighting) {
DisplayLighting.lighting.set(lighting);
lighting_new.set(true);
}
public DisplayLighting() {
lightmap = GL33.glGenTextures();
}
public static void update()
{
if(Camera.camera == null) return;
if(!ChunkEventHandler.loaded) return;
Layer layer = Main.world.getLayer();
EntityPlayer player = Main.player;
Vec2d ppos = player.getPos().xz();
boolean dirty = lighting_dirty;
if(!dirty)
{
for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++) {
Vec2i cpos = new Vec2i(
cx + MathHelpers.floor(ppos.x / 16),
cy + MathHelpers.floor(ppos.y / 16));
Chunk chunk = layer.chunks.get(cpos);
if(chunk.isLightDirty()) {
chunk.resetLightDirty();
dirty = true;
}
}
}
}
if(!dirty) {
return;
}
lighting_dirty = false;
int size = (Chunk.RENDER_DISTANCE * 2 + 1) * 16;
float[] lights = new float[size * size * 2];
for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++)
{
Vec2i cpos = new Vec2i(
cx + MathHelpers.floor(ppos.x / 16),
cy + MathHelpers.floor(ppos.y / 16));
Chunk chunk = layer.chunks.get(cpos);
for(int x=0;x<16;x++) {
for(int y=0;y<16;y++)
{
Vec2i tpos = new Vec2i(x, y);
int tid = tpos.getId(Chunk.CHUNK_SIZE);
TileState ft = chunk.getFrontTile(tid);
TileState bt = chunk.getBackTile(tid);
float transparency = (float)MathHelpers.biggest(
ft.tile.getLightDissipation(ft),
bt.tile.getLightDissipation(bt));
float lightSrc = (float)MathHelpers.biggest(
ft.tile.getLightLevel(ft, tpos),
bt.tile.getLightLevel(bt, tpos));
int id = ((cx * 16 + x + Chunk.RENDER_DISTANCE * 16) +
(cy * 16 + y + Chunk.RENDER_DISTANCE * 16) * size) * 2;
lights[id+0] = lightSrc;
lights[id+1] = transparency;
}
}
}
}
Main.workerLighting.processLighting(lights, size, size,
MathHelpers.floor(ppos.x / 16.0) - Chunk.RENDER_DISTANCE,
MathHelpers.floor(ppos.y / 16.0) - Chunk.RENDER_DISTANCE);
}
private static void calculateLight(Layer layer, Lighting lighting, float[] pixels, int x, int y, float level)
{
if(x < 0 || y < 0 || x >= lighting.w || y >= lighting.h || level <= 0) {
return;
}
int id = lighting.getID(x, y);
float level_current = pixels[id];
Vec2i tpos = new Vec2i(x + lighting.x * 16, y + lighting.y * 16);
int tid = tpos.getId(Chunk.CHUNK_SIZE);
if(level_current >= level) {
return;
}
pixels[id] = level;
Chunk chunk = layer.getChunk(tpos);
TileState ft = chunk.getFrontTile(tid);
TileState bt = chunk.getBackTile(tid);
float dissipation = (float)Math.max(ft.tile.getLightDissipation(ft), bt.tile.getLightDissipation(bt));
float level_next = level - dissipation;
int[] adjacent = new int[] {
x+1, y+0,
x+0, y+1,
x-1, y-0,
x-0, y-1,
};
for(int i=0;i<8;i+=2) {
calculateLight(layer, lighting, pixels, adjacent[i], adjacent[i+1], level_next);
}
}
private static void calculateEntityLighting(Layer layer, Lighting lighting, Entity entity, float[] pixels)
{
if(!entity.emitsLight) {
return;
}
double level = entity.getLightLevel();
if(level <= 0) {
return;
}
if(level > 1) {
level = 1;
}
int[] positions = {
0, 0,
1, 0,
1, 1,
0, 1
};
Vec2d epos = entity.getPos().xz();
for(int i=0;i<positions.length;i+=2)
{
int x = (int)Math.round(epos.x) - positions[i+0];
int y = (int)Math.round(epos.y) - positions[i+1];
Vec2i lpos = new Vec2i(x, y).subtract(new Vec2i(lighting.x * 16, lighting.y * 16));
if(lpos.x < 0 || lpos.y < 0 || lpos.x >= lighting.w || lpos.y >= lighting.h) {
continue;
}
int id = lighting.getID(lpos.x, lpos.y);
float level_current = pixels[id];
Vec2i tpos = new Vec2i(x, y);
int tid = tpos.getId(Chunk.CHUNK_SIZE);
if(level_current >= level) {
continue;
}
Chunk chunk = layer.getChunk(tpos);
TileState ft = chunk.getFrontTile(tid);
TileState bt = chunk.getBackTile(tid);
double dissipation = Math.max(ft.tile.getLightDissipation(ft), bt.tile.getLightDissipation(bt));
double level2 = level - dissipation * (Math.abs(x + 0.5 - epos.x) + Math.abs(y + 0.5 - epos.y));
calculateLight(layer, lighting, pixels, lpos.x, lpos.y, (float)level2);
}
}
public static void updateLighting()
{
Lighting lighting = getLighting();
Layer layer = Main.world.getLayer();
if(lighting_new.getAndSet(false))
{
for(int i=0;i<lighting.p.length/3;i++)
{
int i3 = i*3;
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.setLightLevel(lighting.p[i3+0], tpos);
// Store temperature and humidity data
lighting.p[i3+1] = (float)layer.getTemperature(new Vec2i(x + lighting.x * 16, y + lighting.y * 16));
lighting.p[i3+2] = (float)layer.getHumidity(new Vec2i(x + lighting.x * 16, y + lighting.y * 16));
}
}
// Copy the pixels
float[] pixels = new float[lighting.p.length];
for(int i=0;i<pixels.length;i++) {
pixels[i] = lighting.p[i];
}
Vec2d ppos = Main.player.getPos().xz();
calculateEntityLighting(layer, lighting, Main.player, pixels);
for(int cx=-Chunk.RENDER_DISTANCE;cx<=Chunk.RENDER_DISTANCE;cx++) {
for(int cy=-Chunk.RENDER_DISTANCE;cy<=Chunk.RENDER_DISTANCE;cy++)
{
Vec2i cpos = new Vec2i(
cx + MathHelpers.floor(ppos.x / 16),
cy + MathHelpers.floor(ppos.y / 16));
Chunk chunk = layer.chunks.get(cpos);
for(Entity entity : chunk.entities) {
calculateEntityLighting(layer, lighting, entity, pixels);
}
}
}
ByteBuffer pixels_b = BufferUtils.createByteBuffer(pixels.length);
for(int i=0;i<pixels.length;i++) {
pixels_b.put(i, (byte)(pixels[i]*255));
}
// Update the texture
GL33.glBindTexture(GL33.GL_TEXTURE_2D, lightmap);
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);
lighting_last_x = lighting.w;
lighting_last_y = lighting.h;
}
else {
GL33.glTexSubImage2D(GL33.GL_TEXTURE_2D, 0, 0, 0,
lighting.w, lighting.h, GL33.GL_RGB, GL33.GL_UNSIGNED_BYTE, pixels_b);
}
GL33.glGenerateMipmap(GL33.GL_TEXTURE_2D);
// Set the texture location data
GL33.glUniform2f(Main.window.glsl_lightmap_size, lighting.w, lighting.h);
if(Camera.camera != null) {
GL33.glUniform2f(Main.window.glsl_lightmap_offset,
(float)(lighting.x * 16 - Camera.camera.x - 0.5),
(float)(lighting.y * 16 - Camera.camera.y - 0.5));
}
}
public static void clearLighting()
{
Lighting lighting = new Lighting();
lighting.p = new float[3];
lighting.w = 1;
lighting.h = 1;
lighting.x = 0;
lighting.y = 0;
setLighting(lighting);
}
public static void updateLighting(float[] light, int x, int y, int width, int height)
{
float[] pixels = new float[width*height*3];
for(int i=0;i<width*height;i++) {
pixels[i*3] = light[i*2];
}
Lighting lighting = new Lighting();
lighting.p = pixels;
lighting.w = width;
lighting.h = height;
lighting.x = x;
lighting.y = y;
setLighting(lighting);
}
}

View File

@ -0,0 +1,178 @@
package projectzombie.display;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glViewport;
import java.nio.ByteBuffer;
import org.lwjgl.opengl.GL33;
import gl_engine.matrix.Matrix4;
import projectzombie.Main;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.settings.SettingQuality;
import projectzombie.util.ColorRange;
import projectzombie.world.chunk.ChunkEventHandler;
import projectzombie.world.layer.layergen.LayerGen;
public class DisplayRender
{
public static int shadow_fbo;
public static int shadow_depth;
public static int shadow_size;
private static SettingQuality shadow_quality;
public static SettingQuality setShadowQuality(SettingQuality quality)
{
int size;
switch(quality)
{
case LOWEST:
size = 1024;
break;
case LOW:
size = 2048;
break;
case MEDIUM:
size = 4096;
break;
case HIGH:
size = 8192;
break;
case EXTREME:
size = 16384;
break;
default:
size = 2048;
quality = SettingQuality.LOW;
break;
}
if(Main.window != null && size > Main.window.texture_max_size) {
quality = SettingQuality.LOWEST;
size = 1024;
}
shadow_size = size;
shadow_quality = quality;
return quality;
}
public static SettingQuality getShadowQuality() {
return shadow_quality;
}
public static void updateShadowQuality()
{
GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, shadow_fbo);
GL33.glDeleteTextures(shadow_depth);
shadow_depth = generateDepthTexture(shadow_size, shadow_size);
}
private static int generateDepthTexture(int width, int height)
{
int depth = GL33.glGenTextures();
GL33.glBindTexture(GL33.GL_TEXTURE_2D, depth);
GL33.glTexImage2D(
GL33.GL_TEXTURE_2D, 0, GL33.GL_DEPTH_COMPONENT32, width, height,
0, GL33.GL_DEPTH_COMPONENT, GL33.GL_FLOAT, (ByteBuffer) null);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MIN_FILTER, GL33.GL_LINEAR);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_MAG_FILTER, GL33.GL_LINEAR);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_WRAP_S, GL33.GL_CLAMP_TO_BORDER);
GL33.glTexParameteri(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_WRAP_T, GL33.GL_CLAMP_TO_BORDER);
GL33.glTexParameterfv(GL33.GL_TEXTURE_2D, GL33.GL_TEXTURE_BORDER_COLOR, new float[] {1, 1, 1, 1});
GL33.glFramebufferTexture(GL33.GL_FRAMEBUFFER, GL33.GL_DEPTH_ATTACHMENT, depth, 0);
return depth;
}
public static void init()
{
shadow_fbo = GL33.glGenFramebuffers();
GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, shadow_fbo);
GL33.glDrawBuffer(GL33.GL_NONE);
GL33.glReadBuffer(GL33.GL_NONE);
shadow_depth = generateDepthTexture(shadow_size, shadow_size);
}
public static void render(int w, int h)
{
// Setup GL and clear the colour
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, w, h);
GL33.glEnable(GL33.GL_DEPTH_TEST);
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
ColorRange range = Main.world.getLayer().layergen.getLightLevel();
GL33.glUniform3f(Main.window.glsl_day_low, (float)range.min.x, (float)range.min.y, (float)range.min.z);
GL33.glUniform3f(Main.window.glsl_day_high, (float)range.max.x, (float)range.max.y, (float)range.max.z);
if(Main.menu.doGameRender)
{
if(ChunkEventHandler.loaded)
{
EntityPlayer player = Main.player;
Camera camera = new Camera(w, h);
Camera.camera = camera;
Matrix4 rotated = Matrix4.rotate(-camera.angle, 0, 1, 0);
Matrix4 billboard = Matrix4.multiply(Matrix4.rotate(-45, 1, 0, 0), rotated);
Main.window.environmentRenderer.use();
GL33.glUniformMatrix4fv(Main.window.glsl_camera, true, Camera.camera.matrix.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_billboard, true, billboard.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_rotated, true, rotated.getArray());
GL33.glUniformMatrix4fv(Main.window.glsl_projection_sun, true, Camera.camera.projection_sun.getArray());
GL33.glUniform1i(Main.window.glsl_time, (int)((System.currentTimeMillis() / 10) % 1000));
GL33.glUniform1i(Main.window.glsl_do_lighting, 1);
Main.world.markPoolDirty();
LayerGen layergen = Main.world.getLayer().layergen;
//double sunPosition = MathHelpers.mod(layergen.getSunPosition(), 360);
if(layergen.hasSun() /*&& sunPosition > 0 && sunPosition < 180*/ && shadow_size != 1)
{
// Set up the suns frame buffer
GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, shadow_fbo);
glClear(GL_DEPTH_BUFFER_BIT);
// Set up the suns perspective
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true,
Camera.camera.projection_sun.getArray());
GL33.glUniform1i(Main.window.glsl_mode, 1);
// Render from the suns perspective
glViewport(0, 0, shadow_size, shadow_size);
Main.world.render(camera);
// Set back to the players frame buffer
GL33.glBindFramebuffer(GL33.GL_FRAMEBUFFER, 0);
glViewport(0, 0, w, h);
}
// Set to the players perspective and render
GL33.glUniform1i(Main.window.glsl_mode, 0);
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, camera.projection.getArray());
Main.world.render(camera);
player.chunk = Main.world.getLayer().getChunk(player.getPos().xz());
GL33.glUniform1i(Main.window.glsl_do_lighting, 0);
}
}
}
}

View File

@ -0,0 +1,227 @@
package projectzombie.display;
import java.text.DecimalFormat;
import org.lwjgl.opengl.GL33;
import gl_engine.MathHelpers;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.init.Models;
import projectzombie.inventory.Inventory;
import projectzombie.model.Model;
import projectzombie.model.ModelGui;
import projectzombie.text.Text;
import projectzombie.util.ItemStack;
import projectzombie.util.gl.GlHelpers;
import projectzombie.world.chunk.ChunkEventHandler;
import projectzombie.world.layer.Layer;
public class DisplayRenderUI
{
public static boolean showFPS = false;
public static boolean debug = false;
public static int guiScale = 2;
public static Matrix4 camera, projection;
private static float calculateGreen(double a) {
return (float)(-2 * a * (a - 1) + 0.25 * a * a);
}
public static void renderGameGui()
{
{
Matrix4 matrix = Matrix4.translate(-Models.UI_ITEM_SLOTS.getWidth() / 2, -9.5, 0);
Inventory inventory = Main.player.getInventory();
int slot = Main.player.inventory_hand;
double offset = Models.UI_ITEM_SLOTS.getWidth() / 10;
Matrix4 matrix_slot = Matrix4.multiply(matrix, Matrix4.translate(offset * slot, 0, 0));
Models.UI_ITEM_SLOTS.setModel(matrix);
Models.UI_ITEM_SLOTS.render();
Models.UI_ACTIVE_SLOT.setModel(matrix_slot);
Models.UI_ACTIVE_SLOT.render();
for(int i = 0; i < 10; i++)
{
ItemStack stack = inventory.getItem(i);
if(stack.isEmpty()) {
continue;
}
Model model_item = stack.item.getModel(stack).getGuiModel();
double item_offset = (Models.UI_ACTIVE_SLOT.getHeight() - model_item.getHeight()) / 2;
Matrix4 matrix_item = Matrix4.multiply(matrix, Matrix4.translate(i * offset + item_offset, item_offset, 0));
model_item.setModel(matrix_item);
model_item.render();
double damage = stack.item.getDamage(stack);
if(damage > 0)
{
Matrix4 matrix_damage = Matrix4.multiply(matrix_item, Matrix4.translate(0, -0.85 / 16, 0));
matrix_damage = Matrix4.multiply(Matrix4.scale(new Vec3d(damage * 0.85, 0.85 / 16, 0)), matrix_damage);
GL33.glUniform4f(Main.window.glsl_color,
1 - (float)MathHelpers.squared(1 - damage),
1 - (float)MathHelpers.squared(damage), 0, 1);
Models.UI_PIXEL_WHITE.setModel(matrix_damage);
Models.UI_PIXEL_WHITE.render();
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
}
if(stack.count > 1)
{
Matrix4 matrix_text = Matrix4.multiply(matrix, Matrix4.translate(i * offset + 0.25, 0.28125, 0));
matrix_text = Matrix4.multiply(Matrix4.scale(new Vec3d(0.4, 0.4, 0.4)), matrix_text);
Text.render("" + stack.count, matrix_text);
}
}
}
{
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;
{
double offset = -(79 * 15.0) / 160;
matrix = Matrix4.translate(offset, -9.5 + (1.5 * 17) / 16, 0);
model_health_b.setModel(matrix);
model_health_b.render();
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 1);
GL33.glUniform4f(Main.window.glsl_discard_coords, -10, -10, (float)MathHelpers.map(
Main.player.getHealth(),
0, Main.player.maxHealth(),
offset, offset + model_health_f.getWidth()), 10);
model_health_f.setModel(matrix);
model_health_f.render();
}
double temperature = MathHelpers.smoothStep(Main.player.getTemperature());
double hydration = MathHelpers.smoothStep(1 - Main.player.getHydration());
{
Vec2d offset = new Vec2d((1 * 0.75) / 8, -9.5 + (1.5 * 17) / 16);
matrix = Matrix4.translate(offset.x, offset.y, 0);
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
GL33.glUniform4f(Main.window.glsl_color, 0.65f, 0.65f, 0.65f, 1);
model_water.setModel(matrix);
model_water.render();
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 1);
GL33.glUniform4f(Main.window.glsl_discard_coords,
(float)offset.x, (float)offset.y,
(float)(offset.x + model_water.getWidth()),
(float)(offset.y + model_water.getHeight() * Main.player.getHydration()));
GL33.glUniform4f(Main.window.glsl_color,
(float)hydration * 0.75f, calculateGreen(hydration), 1 - (float)hydration, 1);
model_water.render();
GL33.glUniform1i(Main.window.glsl_do_discard_coords, 0);
}
{
GL33.glUniform4f(Main.window.glsl_color,
(float)temperature, calculateGreen(temperature), 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, 1, 1, 1, 1);
}
}
public static void render()
{
DecimalFormat dec = new DecimalFormat("0.####");
camera = Matrix4.identity();
projection = Matrix4.scale(new Vec3d(0.1/GlHelpers.getAspectRatio(), 0.1, 1));
GL33.glUniform3f(Main.window.glsl_day_low, 1, 1, 1);
GL33.glUniform3f(Main.window.glsl_day_high, 1, 1, 1);
GL33.glUniformMatrix4fv(Main.window.glsl_projection, true, projection.getArray());
GL33.glDisable(GL33.GL_DEPTH_TEST);
if(Main.menu.doGameRender && Main.menu.showIngameGUI && ChunkEventHandler.loaded) {
renderGameGui();
}
double aspect = (double)Main.window.getWidth() / (double)Main.window.getHeight();
Matrix4 matrix = Matrix4.scale(new Vec3d(0.35, 0.35, 0.35));
matrix = Matrix4.multiply(matrix, Matrix4.translate(-10 * aspect, 9.5, 0));
if(showFPS) {
float fps = DisplayStatsEventHandler.fps;
if(fps >= 120) {
GL33.glUniform4f(Main.window.glsl_color, 0, 1, 0, 1);
} else if(fps >= 60) {
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 0, 1);
} else {
GL33.glUniform4f(Main.window.glsl_color, 1, 0, 0, 1);
}
Text.render("Fps: " + DisplayStatsEventHandler.fps, matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
}
if(debug) {
Layer layer = Main.world.getLayer();
Vec3d pos = Main.player.getPos();
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 0, 1);
if(ChunkEventHandler.loaded)
{
Text.render("temperature: " + dec.format(
layer.getTemperature(Main.player.getPos().xz().toInt())), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
Text.render("humidity: " + dec.format(
layer.getHumidity(Main.player.getPos().xz().toInt())), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
Text.render("x: "+dec.format(pos.x), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
Text.render("y: "+dec.format(pos.y), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.35, 0));
Text.render("z: "+dec.format(pos.z), matrix);
matrix = Matrix4.multiply(matrix, Matrix4.translate(0, -0.7, 0));
}
}
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
// Render the loaded menu
Main.menu.render();
}
}

View File

@ -1,7 +1,7 @@
package shootergame.display;
package projectzombie.display;
import mainloop.task.IMainloopTask;
import shootergame.mainloop.MainloopEventHandler;
import projectzombie.Main;
public class DisplayStatsEventHandler implements IMainloopTask
{
@ -22,9 +22,9 @@ public class DisplayStatsEventHandler implements IMainloopTask
@Override
public void MainLoopUpdate()
{
// Set the fps from mspf every second
long mspf = MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf;
fps = (int)(1000 / mspf);
// Display the fps
fps = DisplayWindow.fps;
DisplayWindow.fps = 0;
}

View File

@ -0,0 +1,371 @@
package projectzombie.display;
import java.nio.IntBuffer;
import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL33;
import gl_engine.graphics.GraphicsHelpers;
import gl_engine.graphics.GraphicsShader;
import mainloop.task.IMainloopTask;
import projectzombie.Main;
import projectzombie.init.Resources;
import projectzombie.input.CursorEnterCallback;
import projectzombie.input.CursorPosCallback;
import projectzombie.input.JoystickCallback;
import projectzombie.input.KeyCallback;
import projectzombie.input.KeyCharCallback;
import projectzombie.input.MouseButtonCallback;
import projectzombie.input.ScrollWheelCallback;
import projectzombie.mainloop.MainloopEventHandler;
import projectzombie.menu.MenuSettings;
import projectzombie.settings.Settings;
public class DisplayWindow implements IMainloopTask
{
public static boolean fullscreen;
public static boolean vsync;
private long window;
private long monitor;
private int width;
private int height;
private boolean mouseVisibility_last = false;
public int texture_max_size;
public static int fps = 0;
public GraphicsShader environmentRenderer;
public GraphicsShader effectRenderer;
public int effect_vao;
public int glsl_mist;
public int glsl_color;
public int glsl_contrast;
public int glsl_discard_coords;
public int glsl_do_discard_coords;
public int glsl_do_lighting;
public int glsl_do_texture;
public int glsl_model;
public int glsl_camera;
public int glsl_projection;
public int glsl_projection_sun;
public int glsl_rotated;
public int glsl_billboard;
public int glsl_mode;
public int glsl_time;
public int glsl_day_low;
public int glsl_day_high;
public int glsl_lightmap_offset;
public int glsl_lightmap_size;
public int glsl_effect_time;
public int glsl_effect_red;
public int glsl_effect_vortex;
public int glsl_effect_vsnow;
public int glsl_effect_red_freq;
public int glsl_effect_chill;
public static void setVSync(boolean status)
{
vsync = status;
GLFW.glfwSwapInterval(vsync ? 1 : 0);
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return this.height;
}
void setWidth(int w) {
width = w;
}
void setHeight(int h) {
height = h;
}
public void init()
{
// Initialize GLFW
if(!GLFW.glfwInit()) {
throw new RuntimeException("Failed to initialize GLFW");
}
// Get the monitor size
IntBuffer w = BufferUtils.createIntBuffer(1);
IntBuffer h = BufferUtils.createIntBuffer(1);
monitor = GLFW.glfwGetPrimaryMonitor();
GLFW.glfwGetMonitorPhysicalSize(monitor, w, h);
width = w.get()*4;
height = h.get()*4;
//GLFW.glfwWindowHint(GLFW.GLFW_DOUBLEBUFFER, GLFW.GLFW_FALSE);
// Create the window
window = GraphicsHelpers.initWindow("Project Zombie", width, height, fullscreen ? monitor : 0);
// Make the context current
GLFW.glfwMakeContextCurrent(this.window);
// Set the key handlers
GLFW.glfwSetCursorPosCallback(this.window, new CursorPosCallback());
GLFW.glfwSetCharCallback(this.window, new KeyCharCallback());
GLFW.glfwSetCursorEnterCallback(this.window, new CursorEnterCallback());
GLFW.glfwSetMouseButtonCallback(this.window, new MouseButtonCallback());
GLFW.glfwSetKeyCallback(this.window, new KeyCallback());
GLFW.glfwSetJoystickCallback(JoystickCallback.JOYSTICK_CALLBACK);
GLFW.glfwSetScrollCallback(this.window, new ScrollWheelCallback());
// Make the cursor invisible
GLFW.glfwSetInputMode(this.window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
setVSync(vsync);
// Show the window
//GLFW.glfwShowWindow(this.window);
environmentRenderer = new GraphicsShader("/resources/shader/environmentRenderer");
environmentRenderer.use();
glsl_mist = GL33.glGetUniformLocation(environmentRenderer.program, "mist");
glsl_model = GL33.glGetUniformLocation(environmentRenderer.program, "model");
glsl_camera = GL33.glGetUniformLocation(environmentRenderer.program, "camera");
glsl_rotated = GL33.glGetUniformLocation(environmentRenderer.program, "rotated");
glsl_projection = GL33.glGetUniformLocation(environmentRenderer.program, "projection");
glsl_projection_sun = GL33.glGetUniformLocation(environmentRenderer.program, "projection_sun");
glsl_time = GL33.glGetUniformLocation(environmentRenderer.program, "time");
glsl_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "discard_coords");
glsl_do_discard_coords = GL33.glGetUniformLocation(environmentRenderer.program, "do_discard_coords");
glsl_do_lighting = GL33.glGetUniformLocation(environmentRenderer.program, "do_lighting");
glsl_do_texture = GL33.glGetUniformLocation(environmentRenderer.program, "do_texture");
glsl_color = GL33.glGetUniformLocation(environmentRenderer.program, "color");
glsl_contrast = GL33.glGetUniformLocation(environmentRenderer.program, "contrast");
glsl_billboard = GL33.glGetUniformLocation(environmentRenderer.program, "billboard");
glsl_mode = GL33.glGetUniformLocation(environmentRenderer.program, "mode");
glsl_day_low = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_day_low");
glsl_day_high = GL33.glGetUniformLocation(environmentRenderer.program, "lighting_day_high");
glsl_lightmap_offset = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap_offset");
glsl_lightmap_size = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap_size");
int glsl_atlas = GL33.glGetUniformLocation(environmentRenderer.program, "atlas");
int glsl_lightmap = GL33.glGetUniformLocation(environmentRenderer.program, "lightmap");
int glsl_depthmap = GL33.glGetUniformLocation(environmentRenderer.program, "depthmap");
GL33.glUniform1i(glsl_atlas, 0);
GL33.glUniform1i(glsl_lightmap, 1);
GL33.glUniform1i(glsl_depthmap, 2);
effectRenderer = new GraphicsShader("/resources/shader/effectRenderer");
effectRenderer.use();
glsl_effect_time = GL33.glGetUniformLocation(effectRenderer.program, "time");
glsl_effect_red = GL33.glGetUniformLocation(effectRenderer.program, "red");
glsl_effect_vsnow = GL33.glGetUniformLocation(effectRenderer.program, "vsnow");
glsl_effect_vortex = GL33.glGetUniformLocation(effectRenderer.program, "vortex");
glsl_effect_red_freq = GL33.glGetUniformLocation(effectRenderer.program, "red_freq");
glsl_effect_chill = GL33.glGetUniformLocation(effectRenderer.program, "chill");
//GL33.glUniform1i(GL33.glGetUniformLocation(effectRenderer.program, "shadowMap"), 2);
effect_vao = GL33.glGenVertexArrays();
GL33.glBindVertexArray(effect_vao);
int effect_vbo = GL33.glGenBuffers();
GL33.glBindBuffer(GL33.GL_ARRAY_BUFFER, effect_vbo);
GL33.glBufferData(GL33.GL_ARRAY_BUFFER, new float[] {
-1, -1,
-1, 1,
1, 1,
-1, -1,
1, -1,
1, 1,
}, GL33.GL_STATIC_DRAW);
GL33.glVertexAttribPointer(0, 2, GL33.GL_FLOAT, false, Float.BYTES * 2, 0);
GL33.glEnableVertexAttribArray(0);
int[] ptr = new int[1];
GL33.glGetIntegerv(GL33.GL_MAX_TEXTURE_SIZE, ptr);
texture_max_size = ptr[0];
System.out.println("Max texture size: " + texture_max_size);
DisplayRender.init();
}
public void render()
{
// Set the framebuffer size
int w[] = {0};
int h[] = {0};
GLFW.glfwGetFramebufferSize(this.window, w, h);
width = w[0];
height = h[0];
environmentRenderer.use();
DisplayLighting.updateLighting();
GL33.glUniform1f(glsl_mist, 1f/256f);
GL33.glUniform1i(glsl_do_texture, 1);
if(Main.player.getHydration() < 0.2) {
GL33.glUniform1f(glsl_contrast, (float)(0.2 - Main.player.getHydration()) * 1.6f);
} else {
GL33.glUniform1f(glsl_contrast, 0);
}
// Bind the texture atlas
GL33.glActiveTexture(GL33.GL_TEXTURE0);
Resources.ATLAS.bind();
// Bind the lightmap
GL33.glActiveTexture(GL33.GL_TEXTURE1);
GL33.glBindTexture(GL33.GL_TEXTURE_2D, DisplayLighting.lightmap);
// Bind the shadow depth map
GL33.glActiveTexture(GL33.GL_TEXTURE2);
GL33.glBindTexture(GL33.GL_TEXTURE_2D, DisplayRender.shadow_depth);
// Render everything
DisplayRender.render(w[0], h[0]);
// Use the effect shader
effectRenderer.use();
// Bind the shadow depth map
GL33.glActiveTexture(GL33.GL_TEXTURE0);
GL33.glBindTexture(GL33.GL_TEXTURE_2D, DisplayRender.shadow_depth);
// Send extra data to the shader
if(!Main.player.dead && Main.menu.doGameloop) {
GL33.glUniform1i(glsl_effect_time, (int)System.currentTimeMillis());
}
if(Main.player.getHydration() < 0.2) {
GL33.glUniform1f(glsl_effect_vsnow, (float)(0.2 - Main.player.getHydration()));
GL33.glUniform1f(glsl_effect_vortex, (float)(0.2 - Main.player.getHydration()) / 10);
} else {
GL33.glUniform1f(glsl_effect_vsnow, 0);
GL33.glUniform1f(glsl_effect_vortex, 0);
}
double player_health = Main.player.getHealth() / Main.player.maxHealth();
if(player_health < 0.25) {
GL33.glUniform1f(glsl_effect_red, (float)Math.min(2 * (0.25 - player_health), 0.5));
GL33.glUniform1i(glsl_effect_red_freq, 20);
} else {
GL33.glUniform1f(glsl_effect_red, 0);
}
if(Main.player.getTemperature() < 0.3) {
GL33.glUniform1f(glsl_effect_chill, (float)(0.3 - Main.player.getTemperature()) / 3 * 10);
} else {
GL33.glUniform1f(glsl_effect_chill, 0);
}
// Draw a quad to the whole screen for the effects
GL33.glBindVertexArray(effect_vao);
GL33.glDrawArrays(GL33.GL_TRIANGLES, 0, 6);
environmentRenderer.use();
DisplayLighting.updateLighting();
GL33.glUniform1i(glsl_do_texture, 1);
// Bind the texture atlas
GL33.glActiveTexture(GL33.GL_TEXTURE0);
Resources.ATLAS.bind();
// Render the user interface
DisplayRenderUI.render();
// Swap the framebuffers and poll events
GLFW.glfwSwapBuffers(window);
GLFW.glfwPollEvents();
fps += 1;
}
public void toggleFullscreen()
{
// Exit fullscreen if the window is in fullscreen
if(fullscreen)
{
fullscreen = false;
GLFW.glfwSetWindowMonitor(window, 0, 1, 1, width, height, GLFW.GLFW_DONT_CARE);
}
// Enter fullscreen if the window is windowed
else
{
// Get the monitor size
IntBuffer w = BufferUtils.createIntBuffer(1);
IntBuffer h = BufferUtils.createIntBuffer(1);
GLFW.glfwGetMonitorPhysicalSize(monitor, w, h);
width = w.get()*4;
height = h.get()*4;
// Enter fullscreen mode
fullscreen = true;
GLFW.glfwSetWindowMonitor(window, monitor, 0, 0, width, height, GLFW.GLFW_DONT_CARE);
}
// Update the settings file
Settings.update();
if(Main.menu instanceof MenuSettings) {
((MenuSettings) Main.menu).buttonFullscreen.setText(
"Fullscreen: " + (fullscreen ? "On" : "Off"));
}
}
public void setMouseVisibility(boolean status) {
if(status != mouseVisibility_last) {
mouseVisibility_last = status;
if(status) {
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_NORMAL);
} else {
GLFW.glfwSetInputMode(window, GLFW.GLFW_CURSOR, GLFW.GLFW_CURSOR_HIDDEN);
}
}
}
public boolean shouldClose() {
return GLFW.glfwWindowShouldClose(window);
}
public void makeContextCurrent() {
GLFW.glfwMakeContextCurrent(window);
}
@Override
public boolean MainLoopDelay(long millis) {
return millis > MainloopEventHandler.MAINLOOP_EVENT_HANDLER.mspf;
}
@Override
public boolean MainLoopRepeat() {
return true;
}
@Override
public void MainLoopUpdate() {
this.render();
}
public void setTitle(String string) {
GLFW.glfwSetWindowTitle(window, string);
}
}

View File

@ -0,0 +1,55 @@
package projectzombie.display.bossbar;
import java.util.ArrayList;
public class BossBars
{
private static final ArrayList<IBossBar> bossbars = new ArrayList<IBossBar>();
public static void register(IBossBar bossbar) {
bossbars.add(bossbar);
}
public static void clear() {
bossbars.clear();
}
public static void render()
{
/*TextureReference health_fg = Models.UI_HEALTH_FG;
TextureReference health_bg = Models.UI_HEALTH_BG;
ArrayList<IBossBar> toRemove = new ArrayList<IBossBar>();
double s = GlHelpers.getScale() / 10.0;
// Render the boss bars
int i = 0;
for(IBossBar bossbar : bossbars)
{
double max_health = bossbar.maxHealth();
double a = 1 - (bossbar.getHealth() / max_health);
GlHelpers.begin();
health_bg.texCoord(0, 1); GlHelpers.vertex2(-4*s, 8.5*s - i);
health_bg.texCoord(0, 0); GlHelpers.vertex2(-4*s, 9.0*s - i);
health_bg.texCoord(1, 0); GlHelpers.vertex2(4*s, 9.0*s - i);
health_bg.texCoord(1, 1); GlHelpers.vertex2(4*s, 8.5*s - i);
health_fg.texCoord(0, 1); GlHelpers.vertex2(-4*s, 8.5*s - i);
health_fg.texCoord(0, 0); GlHelpers.vertex2(-4*s, 9.0*s - i);
health_fg.texCoord(1-a, 0); GlHelpers.vertex2(4*s-a*8*s, 9.0*s - i);
health_fg.texCoord(1-a, 1); GlHelpers.vertex2(4*s-a*8*s, 8.5*s - i);
GlHelpers.end();
i += 1;
if(!bossbar.displayBossBar()) {
toRemove.add(bossbar);
}
}
for(IBossBar bossbar : toRemove) {
bossbars.remove(bossbar);
}*/
}
}

View File

@ -0,0 +1,9 @@
package projectzombie.display.bossbar;
import projectzombie.entity.EntityAlive;
public interface IBossBar extends EntityAlive
{
public String getName();
public boolean displayBossBar();
}

View File

@ -0,0 +1,389 @@
package projectzombie.entity;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Random;
import projectzombie.util.ClassBdf;
import projectzombie.util.TileState;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.init.Entities;
import projectzombie.model.IModel;
import projectzombie.tiles.Tile;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public abstract class Entity implements ClassBdf
{
public double hitbox = 1;
public boolean isSolid = false;
public Chunk chunk;
private TileState tile_front;
private TileState tile_back;
protected static final Random rand = new Random();
public boolean emitsLight = false;
private boolean isDead = false;
protected boolean hasGravity = true;
private Vec3d pos;
private Vec3d velocity;
public abstract IModel getModel();
public boolean isDead() {
return isDead;
}
public Vec3d getPos() {
return pos;
}
public void setPos(Vec3d pos) {
this.pos = pos;
}
public Vec3d getVelocity() {
return velocity;
}
public void setVelocity(Vec3d velocity) {
this.velocity = velocity;
}
protected double getTilesLightDissipation() {
if(chunk == null) return 0;
TileState tsf = chunk.getFrontTile(pos.xz().toInt());
TileState tsb = chunk.getBackTile(pos.xz().toInt());
return MathHelpers.biggest(
tsf.tile.getLightDissipation(tsf),
tsb.tile.getLightDissipation(tsb));
}
protected double getLightWithHeight(double light) {
double height = Math.abs(getVelocity().y) + 1;
return light - (this.getTilesLightDissipation() * height);
}
public int getID() {
for(int i=0;i<Entities.ENTITIES.size();i++) {
Class<? extends Entity> ec = Entities.ENTITIES.get(i);
if(ec == this.getClass()) {
return i;
}
}
return -1;
}
public static Entity loadEntity(BdfObject bdf)
{
try
{
// Load the entity id
BdfNamedList nl = bdf.getNamedList();
int id = nl.get("id").getInteger();
// Send back null if the id is out of range
if(id < 0 || id >= Entities.ENTITIES.size()) {
System.out.println("Warning: Invalid ID detected: " + id);
return null;
}
// Get the class and the constructor
Class<? extends Entity> ecl = Entities.ENTITIES.get(id);
Constructor<? extends Entity> econ = ecl.getConstructor(BdfObject.class);
// Send back the new entity
return econ.newInstance(bdf);
}
catch(
NoSuchMethodException |
SecurityException |
InstantiationException |
IllegalAccessException |
IllegalArgumentException |
InvocationTargetException e)
{
e.printStackTrace();
// Send null if there was an issue
return null;
}
}
public Entity(Vec3d pos, Vec3d velocity)
{
// Store the specified values
this.velocity = velocity.copy();
this.pos = pos.copy();
}
protected Entity() {
}
@Override
public void BdfClassLoad(BdfObject bdf) {
BdfNamedList nl = bdf.getNamedList();
pos = new Vec3d(nl.get("pos"));
velocity = new Vec3d(nl.get("velocity"));
hitbox = nl.get("hitbox").getDouble();
isSolid = nl.get("isSolid").getBoolean();
emitsLight = nl.get("emitsLight").getBoolean();
hasGravity = nl.get("hasGravity").getBoolean();
}
@Override
public void BdfClassSave(BdfObject bdf)
{
// Get the ID and return if its invalid (entity can't be saved)
int id = getID();
if(id == -1) return;
BdfNamedList nl = bdf.getNamedList();
nl.set("id", bdf.newObject().setInteger(getID()));
BdfObject pos_bdf = bdf.newObject();
pos.BdfClassSave(pos_bdf);
BdfObject velocity_bdf = bdf.newObject();
velocity.BdfClassSave(velocity_bdf);
nl.set("pos", pos_bdf);
nl.set("velocity", velocity_bdf);
nl.set("hitbox", bdf.newObject().setDouble(hitbox));
nl.set("isSolid", bdf.newObject().setBoolean(isSolid));
nl.set("emitsLight", bdf.newObject().setBoolean(emitsLight));
nl.set("hasGravity", bdf.newObject().setBoolean(hasGravity));
}
public void tick(Chunk chunk, Layer layer)
{
//speed = 1;
//angle = MathHelpers.mod(angle, 360);
if(chunk == null) chunk = layer.getChunk(pos.xz());
this.chunk = chunk;
Vec2i tpos = pos.xz().toInt();
boolean pos_is_legal = moveIsLegal(pos.xz());
tile_back = chunk.getBackTile(tpos);
tile_front = chunk.getFrontTile(tpos);
if(velocity.x != 0 || velocity.y != 0 || velocity.z != 0)
{
Vec3d new_pos = pos.add(velocity);
double slipperiness = Math.max(
tile_back.tile.getSlipperiness(tile_back),
tile_front.tile.getSlipperiness(tile_front));
if(isSolid) {
if(moveIsLegal(new Vec2d(new_pos.x, pos.z)) || !pos_is_legal) {
pos.x = new_pos.x;
} else {
velocity.x *= -0.25;
}
if(moveIsLegal(new Vec2d(pos.x, new_pos.z)) || !pos_is_legal) {
pos.z = new_pos.z;
} else {
velocity.z *= -0.25;
}
} else {
pos.x = new_pos.x;
pos.z = new_pos.z;
}
if(new_pos.y > 0) {
pos.y = new_pos.y;
} else if(pos.y >= 0) {
velocity.y *= -0.25;
velocity.x *= slipperiness;
velocity.z *= slipperiness;
pos.y = 0;
}
}
if(hasGravity) {
velocity.y -= MathHelpers.FallSpeed;
}
if(isSolid)
{
moveAwayFromSolidEntities(layer);
if(pos.y <= 0) {
tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back);
tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front);
}
// Move the player out of a solid area
if(!pos_is_legal)
{
Vec2i collision_pos = pos.xz().toInt();
Vec2d direction = pos.xz().subtract(collision_pos.toDouble()).subtract(0.5);
// Do this to prevent division by zero, just move in an arbitrary direction
if(direction.x == 0 && direction.y == 0) {
push(new Vec3d(0.1, 0, 0));
}
else {
push(direction.multiply(0.1).xny());
}
}
}
}
protected void moveAwayFromSolidEntities(Layer layer)
{
if(isSolid)
{
for(Entity e : layer.getNearbyEntities(pos.xz(), hitbox))
{
if(e.isSolid && e != this)
{
double distance = pos.distance(e.pos);
double angle = MathHelpers.atan2(e.pos.z - pos.z, e.pos.x - pos.x);
Vec3d vec_push = MathHelpers.moveTowards2(distance == 0 ? 1 : (0.5 / distance), angle).xny();
push(vec_push.multiply(-0.125));
}
}
}
}
public void push(Vec3d vec)
{
if(pos.y <= 0)
{
Layer layer = Main.world.getLayer();
Vec2i tpos = pos.xz().toInt();
tile_back = layer.getBackTile(tpos);
tile_front = layer.getFrontTile(tpos);
double slipperiness = Math.max(
tile_back.tile.getSlipperiness(tile_back),
tile_front.tile.getSlipperiness(tile_front));
double resistance = Math.max(
tile_back.tile.getResistance(tile_back),
tile_front.tile.getResistance(tile_front));
velocity = velocity.add(vec.multiply((1 - slipperiness) * (1 - resistance)));
}
else
{
velocity = velocity.add(vec);
}
}
public void kill() {
chunk.killEntity(this);
isDead = true;
}
public boolean activateTile(Vec2i tpos)
{
// Get the tile position and the layer
Layer layer = Main.world.getLayer();
TileState tile_front = layer.getFrontTile(tpos);
TileState tile_back = layer.getBackTile(tpos);
// Activate both tiles
return (
tile_front.tile.onActivated(layer, tpos, this, tile_front) ||
tile_back.tile.onActivated(layer, tpos, this, tile_back));
}
public void activateSteppedOnTile()
{
// Get the tile position and the layer
Layer layer = Main.world.getLayer();
Vec2i tpos = new Vec2i(MathHelpers.floor(pos.x)+0, MathHelpers.floor(pos.z)+0);
// Activate both tiles
tile_front.tile.onWalkedOn(chunk, layer, tpos, this, tile_front);
tile_back.tile.onWalkedOn(chunk, layer, tpos, this, tile_back);
}
private boolean moveIsLegal(Vec2d pos)
{
Layer layer = Main.world.getLayer();
// Is this entity solid
if(isSolid)
{
final Vec2i[] positions = {
new Vec2i(-1, -1),
new Vec2i(1, -1),
new Vec2i(1, 1),
new Vec2i(-1, 1),
new Vec2i(1, 0),
new Vec2i(0, 1),
new Vec2i(-1, 0),
new Vec2i(0, -1),
new Vec2i(0, 0),
};
for(Vec2i tpos_offset : positions)
{
// Check the tile the player is standing on
Vec2i tpos = new Vec2i(
MathHelpers.floor(pos.x) + tpos_offset.x,
MathHelpers.floor(pos.y) + tpos_offset.y);
TileState tile_back = layer.getBackTile(tpos);
TileState tile_front = layer.getFrontTile(tpos);
{
// Get the tile
Tile t = tile_back.tile;
// Check the tiles hitbox if the tile is solid
if(t.tileSolid)
{
// Is the entity in the tiles hitbox
Vec2d check = pos.subtract(tpos.toDouble());
if(t.inHitbox(tile_back, check)) {
return false;
}
}
}
{
// Get the front tile
Tile t = tile_front.tile;
// Check the tiles hitbox if the tile is solid
if(t.tileSolid)
{
// Is the entity in the tiles hitbox
Vec2d check = pos.subtract(tpos.toDouble());
if(t.inHitbox(tile_front, check)) {
return false;
}
}
}
}
}
// Send back true if everything passes
return true;
}
public double getLightLevel() {
return 0;
}
}

View File

@ -0,0 +1,21 @@
package projectzombie.entity;
import projectzombie.world.layer.Layer;
public interface EntityAlive
{
public void addHealth(double amount);
public double getHealth();
public void resetHealth();
public void clearHealth();
public double maxHealth();
public void setHealth(double health);
public int bloodParticles();
public void addDamage(double amount);
public void addFireDamage(double amount);
public void addBlastDamage(double amount);
public default void onDeath(Layer layer) {
}
}

View File

@ -0,0 +1,265 @@
package projectzombie.entity;
import java.util.Random;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.display.bossbar.BossBars;
import projectzombie.display.bossbar.IBossBar;
import projectzombie.init.Items;
import projectzombie.init.Models;
import projectzombie.init.Tiles;
import projectzombie.items.modifier.ItemModifierMeta;
import projectzombie.model.Model;
import projectzombie.time.GameTimer;
import projectzombie.util.ItemStack;
import projectzombie.util.math.random.OpenSimplexNoise;
import projectzombie.util.math.random.RandomHelpers;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class EntityBoss extends Entity implements IBossBar, EntityKillWithParticles
{
private boolean moving = false;
private boolean firing = false;
private double max_health = 25000;
private double health = max_health;
private int bullet_frequency = 0;
private int spawn_frequency = 0;
private double time = 0;
private OpenSimplexNoise noise_gun;
private OpenSimplexNoise noise_walk;
private OpenSimplexNoise noise_spawn;
protected OpenSimplexNoise noise_target_x;
protected OpenSimplexNoise noise_target_y;
private long seed;
public EntityBoss(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
health = nl.get("health").getDouble();
bullet_frequency = nl.get("bullet_freq").getInteger();
spawn_frequency = nl.get("spawn_frq").getInteger();
this.isSolid = true;
this.hitbox = 2;
long seed = nl.get("seed").getLong();
Random rand = new Random(seed);
this.noise_gun = new OpenSimplexNoise(rand.nextLong());
this.noise_walk = new OpenSimplexNoise(rand.nextLong());
this.noise_spawn = new OpenSimplexNoise(rand.nextLong());
this.noise_target_x = new OpenSimplexNoise(rand.nextLong());
this.noise_target_y = new OpenSimplexNoise(rand.nextLong());
BossBars.register(this);
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("health", bdf.newObject().setDouble(health));
nl.set("bullet_freq", bdf.newObject().setInteger(bullet_frequency));
nl.set("spawn_freq", bdf.newObject().setInteger(spawn_frequency));
nl.set("seed", bdf.newObject().setLong(seed));
}
public EntityBoss(Vec3d pos, Vec3d velocity) {
super(pos, velocity);
this.isSolid = true;
this.hitbox = 2;
long seed = rand.nextLong();
Random rand = new Random(seed);
this.noise_gun = new OpenSimplexNoise(rand.nextLong());
this.noise_walk = new OpenSimplexNoise(rand.nextLong());
this.noise_spawn = new OpenSimplexNoise(rand.nextLong());
this.noise_target_x = new OpenSimplexNoise(rand.nextLong());
this.noise_target_y = new OpenSimplexNoise(rand.nextLong());
BossBars.register(this);
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
Vec3d bpos = getPos();
Vec3d ppos = Main.player.getPos();
double angle = Math.atan2(
bpos.x - ppos.x + noise_target_x.eval(
time*2, ppos.x/25, ppos.z/25)*10,
bpos.z - ppos.z + noise_target_y.eval(
time*2, ppos.x/25, ppos.z/25)*10);
angle = Math.toDegrees(angle) + 180;
if(this.noise_spawn.eval(GameTimer.getTime() / 500.0, 0) > 0.2) {
if(spawn_frequency == 0) {
int r = 2, m = 1000;
Vec2d zombie_pos = new Vec2d(
RandomHelpers.randrange(rand, -r*m, r*m)/(double)m,
RandomHelpers.randrange(rand, -r*m, r*m)/(double)m);
Vec2i zombie_tpos = zombie_pos.toInt();
if(
layer.getBackTile(zombie_tpos).tile == layer.layergen.getTileDestroyed(layer, zombie_tpos).tile &&
layer.getFrontTile(zombie_tpos).tile == Tiles.VOID) {
layer.spawnEntity(new EntityZombie(bpos.add(zombie_pos.xny()), getVelocity()));
}
spawn_frequency = 50;
}
spawn_frequency -= 1;
}
if(this.noise_gun.eval(GameTimer.getTime() / 500.0, 0) > 0 && !Main.player.dead && !Main.player.in_animation) {
if(bullet_frequency == 0) {
chunk.spawnEntity(new EntityBullet(bpos, bpos.subtract(ppos).normalize(), this, 20, 1000));
bullet_frequency = 10;
}
bullet_frequency -= 1;
}
if(this.noise_gun.eval(GameTimer.getTime() / 500.0, 0) > -0.2) {
this.firing = true;
}
else {
this.firing = false;
}
if(this.noise_walk.eval(GameTimer.getTime() / 500.0, 0) > -0.4) {
this.moveTowards(angle);
this.moving = true;
}
else {
this.moving = false;
}
// Increase time
time += 0.001;
}
@Override
public void addHealth(double amount) {
this.health += amount;
}
@Override
public void addDamage(double amount) {
this.health -= amount;
}
@Override
public void addFireDamage(double amount) {
}
@Override
public void addBlastDamage(double amount) {
addDamage(amount);
}
@Override
public double getHealth() {
return health;
}
@Override
public void resetHealth() {
this.health = max_health;
}
@Override
public void clearHealth() {
this.health = 0;
}
@Override
public double maxHealth() {
return max_health;
}
@Override
public void setHealth(double health) {
this.health = health;
}
@Override
public int bloodParticles() {
return 5;
}
@Override
public String getName() {
return "Final Boss";
}
@Override
public boolean displayBossBar() {
return health >= 0;
}
public void moveTowards(double angle) {
this.push(MathHelpers.moveTowards2(0.04, Math.toRadians(angle)).xny());
}
@Override
public void onDeath(Layer layer) {
IBossBar.super.onDeath(layer);
/*
Drop some powerful loot
*/
// Spawn the loot
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack(
Items.HEALTH_POTION, RandomHelpers.randrange(rand, 20), new ItemModifierMeta(50))));
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack(
Items.AMMO, RandomHelpers.randrange(rand, 200), new ItemModifierMeta(50))));
layer.spawnEntity(new EntityItem(getPos(), getVelocity(), new ItemStack(
Items.GRAPPLING_HOOK, 1, new ItemModifierMeta(2))));
}
@Override
protected void moveAwayFromSolidEntities(Layer layer) {
}
@Override
public void killWithParticles() {
// TODO Auto-generated method stub
}
@Override
public Model getModel()
{
if(moving && firing) {
return Models.ENTITY_BOSS_WALKING_AND_FIRING;
} else if(moving) {
return Models.ENTITY_BOSS_WALKING;
} else if(firing) {
return Models.ENTITY_BOSS_FIRING;
} else {
return Models.ENTITY_BOSS_IDLE;
}
}
}

View File

@ -0,0 +1,156 @@
package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d;
import projectzombie.entity.particle.ParticleBlood;
import projectzombie.init.Resources;
import projectzombie.init.Sounds;
import projectzombie.tiles.Tile;
import projectzombie.tiles.TileBulletBreakable;
import projectzombie.util.math.random.RandomHelpers;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class EntityBullet extends EntityParticle
{
private static final TextureRef3D BULLET = Resources.ATLAS.get("/particle/bullet.png");
private int time = 0;
private Entity parent;
private double damage;
public EntityBullet(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
time = nl.get("time").getInteger();
damage = nl.get("damage").getDouble();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("time", bdf.newObject().setInteger(time));
nl.set("damage", bdf.newObject().setDouble(damage));
}
public EntityBullet(Vec3d pos, Vec3d velocity, Entity parent, double damage, int despawn_time) {
super(pos, velocity);
// Store some specified values
this.parent = parent;
this.damage = damage;
this.time = despawn_time;
this.hasGravity = false;
// Play the gun sound
Sounds.GUN.play(pos, 2);
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
chunk = layer.getChunk(getPos().xz());
// Is the bullets new position intersecting a solid object
{
// Get the position of the tile the bullet is over
Vec2i tpos = getPos().xz().toInt();
// Get the foreground tile and the background tile
Tile tile_f = chunk.getFrontTile(tpos).tile;
Tile tile_b = chunk.getBackTile(tpos).tile;
// Is the tile solid and has the bullet crashed into it
if(tile_f.tileSolid) {
if(getPos().xz().squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_f.tileHitbox)
{
// Break the block
if(tile_f instanceof TileBulletBreakable && RandomHelpers.randrange(rand,
((TileBulletBreakable)tile_f).getBulletBreakChance()) == 0) {
chunk.breakFrontTile(tpos);
}
// Delete the bullet
kill();
}
} if(tile_b.tileSolid) {
if(getPos().xz().squareDistance(new Vec2d(tpos.x + 0.5, tpos.y + 0.5)) < tile_b.tileHitbox)
{
// Break the block
if(tile_f instanceof TileBulletBreakable && RandomHelpers.randrange(rand,
((TileBulletBreakable)tile_f).getBulletBreakChance()) == 0) {
chunk.breakBackTile(tpos);
}
// Delete the bullet
kill();
}
}
}
// Loop over the nearby entities
for(Entity e : layer.getNearbyEntities(getPos().xz(), 1))
{
// Is this entity alive and not the parent
if(e instanceof EntityAlive && e != parent && e.getPos().squareDistance(this.getPos()) < e.hitbox)
{
// Get the alive entity
EntityAlive ea = (EntityAlive)e;
// Spawn some blood particles
chunk.spawnEntity(new ParticleBlood(getPos(), e.getVelocity().add(getVelocity()).divide(8)));
// Knock the entity back abit
e.push(getVelocity());
Vec3d pos = getPos();
// Play the hit noise
Sounds.HIT.play(new Vec3d(pos.x, pos.y, pos.z), 1);
// Harm the entity
ea.addDamage(damage);
// Kill the bullet
chunk.killEntity(this);
return;
}
}
// Decrease time
time -= 1;
if(time <= 0) {
chunk.killEntity(this);
}
}
@Override
public int getParticleCount() {
return 1;
}
@Override
public boolean shouldKillParticle() {
return false;
}
@Override
public EntityParticlePart getParticleAt(int id) {
return new EntityParticlePart(BULLET, getPos(), 0.1, 0b1000);
}
}

View File

@ -0,0 +1,98 @@
package projectzombie.entity;
import bdf.types.BdfArray;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.vec.Vec3d;
import projectzombie.init.Models;
import projectzombie.model.Model;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class EntityContainer extends Entity implements EntityHoldsEntities
{
private Entity[] entities;
public EntityContainer(BdfObject bdf) {
BdfClassLoad(bdf);
}
public EntityContainer(Vec3d pos, Vec3d velocity, Entity[] entities) {
super(pos, velocity);
this.entities = entities;
}
@Override
public Model getModel() {
return Models.EMPTY;
}
@Override
public Entity[] getEntities() {
return this.entities;
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
int dead = 0;
for(Entity entity : entities)
{
if(entity == null || entity.isDead()) {
dead += 1;
continue;
}
entity.tick(chunk, layer);
}
if(dead == entities.length - 1) {
kill();
}
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
BdfArray array = nl.get("entities").getArray();
entities = new Entity[array.size()];
for(int i=0;i<entities.length;i++)
{
Entity entity = Entity.loadEntity(array.get(i));
if(entity != null) {
entities[i] = entity;
}
}
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
BdfArray array = bdf.newArray();
nl.set("entities", bdf.newObject().setArray(array));
for(int i=0;i<entities.length;i++)
{
Entity e = entities[i];
if(e == null || e.getID() == -1) {
continue;
}
BdfObject e_bdf = bdf.newObject();
e.BdfClassSave(e_bdf);
array.add(e_bdf);
}
}
}

View File

@ -0,0 +1,78 @@
package projectzombie.entity;
import bdf.types.BdfObject;
import gl_engine.vec.Vec3d;
import projectzombie.init.Models;
import projectzombie.model.Model;
public class EntityDummy extends Entity implements EntityAlive
{
public EntityDummy(BdfObject bdf) {
BdfClassLoad(bdf);
}
public EntityDummy(Vec3d pos, Vec3d velocity) {
super(pos, velocity);
this.hitbox = 0.5;
this.isSolid = true;
}
@Override
public void addHealth(double amount) {
}
@Override
public void addDamage(double amount) {
int l = 4;
amount = amount / (l / 2.5 + 1);
System.out.println("Dummy Damage Aount: "+amount);
}
@Override
public void addFireDamage(double amount) {
int l = 4;
amount = amount / (l / 2.5 + 1);
System.out.println("Dummy Fire Damage Aount: "+amount);
}
@Override
public void addBlastDamage(double amount) {
int l = 4;
amount = amount / (l / 2.5 + 1);
System.out.println("Dummy Blast Damage Aount: "+amount);
}
@Override
public double getHealth() {
return 100;
}
@Override
public void resetHealth() {
}
@Override
public void clearHealth() {
}
@Override
public double maxHealth() {
return 100;
}
@Override
public void setHealth(double health) {
}
@Override
public int bloodParticles() {
return 5;
}
@Override
public Model getModel() {
return Models.ENTITY_DUMMY;
}
}

View File

@ -1,26 +1,16 @@
package shootergame.entity;
import java.util.ArrayList;
import java.util.Random;
package projectzombie.entity;
import mainloop.task.IMainloopTask;
import shootergame.Main;
import shootergame.init.Entities;
import shootergame.mainloop.MainloopEventHandler;
import shootergame.util.math.map.Map2DElement;
import shootergame.util.math.random.RandomHelpers;
import shootergame.world.chunk.Chunk;
import shootergame.world.layer.Layer;
import projectzombie.Main;
import projectzombie.world.chunk.ChunkEventHandler;
public class EntityEventHandler implements IMainloopTask
{
public static final EntityEventHandler ENTITY_EVENT_HANDLER = new EntityEventHandler();
private Random rand = new Random();
@Override
public boolean MainLoopDelay(long millis) {
return millis > 10;
return millis > Main.tickrate;
}
@Override
@ -31,6 +21,12 @@ public class EntityEventHandler implements IMainloopTask
@Override
public void MainLoopUpdate()
{
Main.menu.update();
if(!Main.menu.doGameloop || !ChunkEventHandler.loaded) {
return;
}
// Update the world and spawn random entities
Main.world.tickEntities();
Main.world.spawnRandomEntities();

View File

@ -0,0 +1,162 @@
package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.entity.particle.ParticleBlood;
import projectzombie.entity.particle.ParticleSmoke;
import projectzombie.init.Models;
import projectzombie.init.Sounds;
import projectzombie.init.Tiles;
import projectzombie.model.Model;
import projectzombie.util.TileState;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class EntityExplosion extends Entity
{
private double damage;
private int radius;
public EntityExplosion(BdfObject bdf) {
BdfClassLoad(bdf);
}
public EntityExplosion(Vec3d pos, int radius, double damage) {
super(pos, new Vec3d(0, 0, 0));
this.damage = damage;
this.radius = radius;
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
damage = nl.get("damage").getDouble();
radius = nl.get("radius").getInteger();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("damage", bdf.newObject().setDouble(damage));
nl.set("radius", bdf.newObject().setInteger(radius));
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
boolean killed_entities = false;
Vec2d pos = getPos().xz();
// Kill all the nearby entities
for(Entity e : layer.getNearbyEntities(pos, radius))
{
// Is this entity alive
if(e instanceof EntityAlive)
{
EntityAlive ea = (EntityAlive)e;
// Remove some health from the entity based on were the entity is
killed_entities = true;
double distance = e.getPos().distance(getPos());
if(distance == 0) {
ea.addBlastDamage(damage);
}
else {
ea.addBlastDamage(damage / distance);
}
}
}
int multiplier = killed_entities ? 2 : 1;
Entity[] entities = new Entity[(int)(Math.PI * radius * radius) * multiplier];
int upto = 0;
// Loop over the tiles around the tnt
for(int ex=-radius;ex<radius;ex++) {
for(int ey=-radius;ey<radius;ey++)
{
// Calculate the distance from the explosion centre
double distance = Math.sqrt(ex*ex + ey*ey);
// Is the point within the distance from the explosion centre
if(distance < radius)
{
// Get the actual tile position
double px = ex + pos.x;
double py = ey + pos.y;
// Get the layer
Layer l = Main.world.getLayer();
// Get the front and back tile
Vec2i tpos = new Vec2i(MathHelpers.floor(px), MathHelpers.floor(py));
TileState bts = l.getBackTile(tpos);
TileState fts = l.getFrontTile(tpos);
// Is this tile the same as the "empty" tile
TileState ets = l.layergen.getTileDestroyed(layer, tpos);
// Set the tiles
if(!bts.tile.unbreakable) {
l.setBackTile(ets, tpos);
//if(fts.tile instanceof IHasTexture)
//l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), bts, 1));
}
if(!fts.tile.unbreakable) {
l.setFrontTile(Tiles.VOID.getDefaultState(), tpos);
//if(fts.tile instanceof IHasTexture)
//l.spawnEntity(new ParticleBreak(new Vec2d(tpos.x+rand.nextDouble(), tpos.y+rand.nextDouble()), fts, 1));
}
if(upto + multiplier > entities.length) {
continue;
}
Vec3d spos = new Vec3d(px, 0, py);
Vec3d svel;
if(distance == 0) {
svel = MathHelpers.moveTowards2(0.01, Math.random() * MathHelpers.TWO_PI).xny();
} else {
svel = spos.xz().subtract(pos).divide(distance * 100).xny();
}
// Spawn some blood if entities were killed
if(killed_entities)
entities[upto + 1] = new ParticleBlood(new Vec3d(px, 0, py), new Vec3d(0, 0, 0), 1);
// Spawn some smoke
entities[upto] = new ParticleSmoke(spos, svel);
upto += multiplier;
}
}
}
layer.spawnEntity(new EntityContainer(getPos(), getVelocity(), entities));
// Play the explosion sound
Sounds.EXPLOSION.play(new Vec3d(pos.x, 0, pos.y), 1);
// Kill the explosion entity
kill();
}
@Override
public Model getModel() {
return null;
}
}

View File

@ -0,0 +1,36 @@
package projectzombie.entity;
import bdf.types.BdfObject;
import gl_engine.vec.Vec3d;
import projectzombie.init.Models;
import projectzombie.model.Model;
import projectzombie.world.layer.Layer;
public class EntityFlare extends EntityTnt
{
public EntityFlare(BdfObject bdf) {
super(bdf);
}
@Override
protected void explode(Layer layer) {
}
public EntityFlare(Vec3d pos, Vec3d velocity, double angle) {
super(pos, velocity, angle, 0, 0);
this.explode_time = 2000;
this.emitsLight = true;
}
@Override
public double getLightLevel() {
return 1;
}
@Override
public Model getModel() {
return active ? Models.ENTITY_FLARE : null;
}
}

View File

@ -0,0 +1,108 @@
package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.init.Models;
import projectzombie.model.Model;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
import projectzombie.world.layer.layergen.LayerGenRememberPlayerPos;
public class EntityGrapplingHook extends Entity
{
private int layerId;
private double height;
private Entity entity;
public EntityGrapplingHook(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
layerId = nl.get("layer").getInteger();
height = nl.get("height").getDouble();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("layer", bdf.newObject().setInteger(layerId));
nl.set("height", bdf.newObject().setDouble(height));
}
public EntityGrapplingHook(Vec3d pos, int layerId, Entity entity) {
super(pos, new Vec3d(0, 0, 0));
this.layerId = layerId;
this.height = -16;
this.entity = entity;
if(entity instanceof EntityPlayer) {
EntityPlayer ep = (EntityPlayer)entity;
ep.in_animation = true;
}
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
if(height >= -8)
{
Vec3d epos = entity.getPos();
double h = epos.y;
epos.y += 0.02;
if(entity instanceof EntityPlayer) {
EntityPlayer ep = (EntityPlayer)entity;
ep.moving = true;
}
if(h >= 8)
{
epos.y = 0;
Main.world.setLayer(layerId);
if(layer.layergen.destroyOnLeave) {
Main.world.removeLayer(layerId);
}
if(entity instanceof EntityPlayer)
{
EntityPlayer ep = (EntityPlayer)entity;
ep.in_animation = false;
ep.moving = false;
}
if(layer.layergen instanceof LayerGenRememberPlayerPos) {
LayerGenRememberPlayerPos lgrpp = (LayerGenRememberPlayerPos)layer.layergen;
entity.setPos(lgrpp.getPlayerPos());
}
kill();
return;
}
}
else {
height += 0.05;
}
}
@Override
public Model getModel() {
return Models.ENTITY_GRAPPLING_HOOK;
}
}

View File

@ -0,0 +1,7 @@
package projectzombie.entity;
import projectzombie.inventory.IInventoryArmor;
public interface EntityHasArmor {
public IInventoryArmor getInventoryArmor();
}

View File

@ -0,0 +1,7 @@
package projectzombie.entity;
import projectzombie.inventory.IInventoryClothing;
public interface EntityHasClothing {
public IInventoryClothing getInventoryClothing();
}

View File

@ -0,0 +1,8 @@
package projectzombie.entity;
import projectzombie.inventory.IInventory;
public interface EntityHasInventory
{
public IInventory getInventory();
}

View File

@ -0,0 +1,8 @@
package projectzombie.entity;
import projectzombie.task.Task;
public interface EntityHasTasks
{
public void addTask(Task task);
}

View File

@ -0,0 +1,6 @@
package projectzombie.entity;
public interface EntityHoldsEntities
{
public Entity[] getEntities();
}

View File

@ -0,0 +1,134 @@
package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec3d;
import projectzombie.model.ModelItem;
import projectzombie.util.ItemStack;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class EntityItem extends EntityParticle
{
private ItemStack stack;
private int pickup_time = 200;
private long age = 0;
public EntityItem(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
stack = new ItemStack(nl.get("stack"));
pickup_time = nl.get("pickup").getInteger();
age = nl.get("age").getLong();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
stack.BdfClassSave(nl.get("stack"));
nl.set("pickup", bdf.newObject().setInteger(pickup_time));
nl.set("age", bdf.newObject().setLong(age));
}
public EntityItem(Vec3d pos, Vec3d velocity, ItemStack stack, double angle) {
super(pos, velocity);
this.emitsLight = true;
this.stack = stack;
push(MathHelpers.moveTowards2(0.05, angle).xny().add(new Vec3d(0, 0.1, 0)));
}
public EntityItem(Vec3d pos, Vec3d velocity, ItemStack stack) {
this(pos, velocity, stack, rand.nextDouble() * MathHelpers.TWO_PI);
}
@Override
public double getLightLevel() {
if(stack.isEmpty()) return 0;
return getLightWithHeight(stack.item.getLightLevel(stack));
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
age += 1;
pickup_time -= 1;
// Merge nearby stacks
for(Entity e : layer.getNearbyEntities(getPos().xz(), 2))
{
if(e instanceof EntityItem && e != this) {
EntityItem ei = (EntityItem) e;
if(
ei.stack.stackEquals(this.stack) &&
ei.stack.count + this.stack.count <= this.stack.item.max &&
ei.age > this.age
) {
if(ei.getPos().squareDistance(getPos()) < 0.1) {
this.pickup_time = 200;
this.stack.count += ei.stack.count;
setPos(ei.getPos().divide(2).add(getPos().divide(2)));
setVelocity(ei.getVelocity().divide(2).add(getVelocity().divide(2)));
ei.kill();
}
else {
push(ei.getPos().subtract(getPos()).normalize().multiply(0.001));
}
}
}
if(pickup_time <= 0 && e instanceof EntityHasInventory)
{
if(e.getPos().squareDistance(getPos()) < 0.5) {
stack.item.onPickedUp(stack, layer, chunk, e);
} else {
push(e.getPos().subtract(getPos()).normalize().multiply(0.05));
}
}
}
// Kill this entity if the stack is empty
if(stack.isEmpty()) {
kill();
return;
}
}
@Override
public boolean shouldKillParticle() {
return false;
}
@Override
public EntityParticlePart getParticleAt(int id) {
ModelItem model = stack.item.getModel(stack);
EntityParticlePart particle = new EntityParticlePart(model.tex, getPos().add(new Vec3d(0, 0.25, 0)), 0.5, 0b1000);
particle.animationSize = model.animationSize;
particle.animationSpeed = model.animationSpeed;
return particle;
}
@Override
public int getParticleCount() {
return 1;
}
}

View File

@ -0,0 +1,6 @@
package projectzombie.entity;
public interface EntityKillWithParticles
{
public void killWithParticles();
}

View File

@ -0,0 +1,38 @@
package projectzombie.entity;
import bdf.types.BdfObject;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.model.IModel;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public abstract class EntityParticle extends Entity
{
public abstract int getParticleCount();
public abstract EntityParticlePart getParticleAt(int id);
protected EntityParticle() {
}
public EntityParticle(Vec3d pos, Vec3d velocity) {
super(pos, velocity);
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
// Kill the particle if the player can't see it to reduce lag
if(shouldKillParticle()) this.kill();
}
public boolean shouldKillParticle() {
return Main.player.getPos().squareDistance(getPos()) > Chunk.RENDER_DISTANCE * 16;
}
@Override
public IModel getModel() {
return null;
}
}

View File

@ -0,0 +1,29 @@
package projectzombie.entity;
import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec3d;
public class EntityParticlePart
{
public int animationSize = 1;
public int animationSpeed = 1;
public TextureRef3D tex;
public double size;
public Vec3d pos;
public int flags;
public double getFade() {
return 1;
}
public boolean isFlat() {
return false;
}
public EntityParticlePart(TextureRef3D tex, Vec3d pos, double size, int flags) {
this.tex = tex;
this.pos = pos;
this.size = size;
this.flags = flags;
}
}

View File

@ -0,0 +1,105 @@
package projectzombie.entity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d;
import projectzombie.entity.particle.ParticleSmokeTrail;
import projectzombie.init.Models;
import projectzombie.model.Model;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class EntityTnt extends Entity implements EntityHoldsEntities
{
protected boolean active = true;
protected int explode_time;
private int explode_radius;
private double explode_damage;
private ParticleSmokeTrail smoke_particles;
@Override
public Entity[] getEntities() {
return new Entity[] {smoke_particles};
}
public EntityTnt(BdfObject bdf) {
smoke_particles = new ParticleSmokeTrail(this);
BdfClassLoad(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
BdfNamedList explode = nl.get("explosion").getNamedList();
explode_time = explode.get("time").getInteger();
explode_radius = explode.get("radius").getInteger();
explode_damage = explode.get("damage").getDouble();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
BdfNamedList explode = nl.get("explosion").getNamedList();
explode.set("time", bdf.newObject().setInteger(explode_time));
explode.set("radius", bdf.newObject().setInteger(explode_radius));
explode.set("damage", bdf.newObject().setDouble(explode_damage));
}
public EntityTnt(Vec3d pos, Vec3d velocity, double angle, int explode_radius, double explode_damage) {
super(pos, velocity.add(new Vec3d(0, 0.1, 0)));
Vec2d v = MathHelpers.moveTowards2(0.05, Math.toRadians(angle));
velocity = velocity.add(new Vec3d(v.x, v.y, 0.01));
this.explode_radius = explode_radius;
this.explode_damage = explode_damage;
this.smoke_particles = new ParticleSmokeTrail(this);
// Set to 2.5 seconds
this.explode_time = 250;
}
protected void explode(Layer layer)
{
layer.spawnEntity(new EntityExplosion(getPos(), explode_radius, explode_damage));
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
smoke_particles.tick(chunk, layer);
if(!active)
{
if(smoke_particles.noMoreParticles()) {
kill();
}
return;
}
// Explode if it is time for the tnt to blow up
explode_time -= 1;
if(explode_time < 0) {
smoke_particles.stopParticles();
active = false;
explode(layer);
}
}
@Override
protected void moveAwayFromSolidEntities(Layer layer) {
}
@Override
public Model getModel() {
return active ? Models.ENTITY_TNT : null;
}
}

View File

@ -0,0 +1,230 @@
package projectzombie.entity;
import java.util.Random;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.init.Models;
import projectzombie.model.Model;
import projectzombie.util.math.astar.AStar;
import projectzombie.util.math.astar.AStarSearcher;
import projectzombie.util.math.random.OpenSimplexNoise;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class EntityZombie extends Entity implements EntityAlive, EntityKillWithParticles
{
protected OpenSimplexNoise noise_movement;
protected OpenSimplexNoise noise_gun_fire;
protected OpenSimplexNoise noise_gun_angle;
protected OpenSimplexNoise noise_target_x;
protected OpenSimplexNoise noise_target_y;
protected long seed;
protected double time;
protected double health_max = 100;
protected double health = health_max;
protected int gun_interval = 0;
protected int gun_level = 0;
private Vec3d walk_to;
private int walk_scan_cooldown = 0;
private boolean can_see_player = false;
protected boolean crossUnwalkable = false;
private int walking_for = 0;
public EntityZombie(BdfObject bdf)
{
// Set some settings
hitbox = 0.5;
isSolid = true;
BdfClassLoad(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
health_max = nl.get("max_health").getDouble();
health = nl.get("health").getDouble();
gun_interval = nl.get("gun_interval").getInteger();
gun_level = nl.get("gun_level").getInteger();
seed = nl.get("seed").getLong();
Random rand = new Random(seed);
noise_movement = new OpenSimplexNoise(rand.nextLong());
noise_gun_fire = new OpenSimplexNoise(rand.nextLong());
noise_gun_angle = new OpenSimplexNoise(rand.nextLong());
noise_target_x = new OpenSimplexNoise(rand.nextLong());
noise_target_y = new OpenSimplexNoise(rand.nextLong());
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("max_health", bdf.newObject().setDouble(health_max));
nl.set("health", bdf.newObject().setDouble(health));
nl.set("gun_interval", bdf.newObject().setInteger(gun_interval));
nl.set("gun_level", bdf.newObject().setInteger(gun_level));
nl.set("seed", bdf.newObject().setLong(seed));
}
public EntityZombie(Vec3d pos, Vec3d velocity) {
super(pos, velocity);
seed = rand.nextLong();
Random rand = new Random(seed);
noise_movement = new OpenSimplexNoise(rand.nextLong());
noise_gun_fire = new OpenSimplexNoise(rand.nextLong());
noise_gun_angle = new OpenSimplexNoise(rand.nextLong());
noise_target_x = new OpenSimplexNoise(rand.nextLong());
noise_target_y = new OpenSimplexNoise(rand.nextLong());
time = 0;
// Set some settings
hitbox = 0.5;
isSolid = true;
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
//System.out.println(walk_direction != null ? (walk_direction.x + ", " + walk_direction.y + ": " + pos.toInt().x + ", " + pos.toInt().y) : "null");
if(walk_to == null) {
walk_scan_cooldown -= 1;
}
double player_distance = getPos().squareDistance(Main.player.getPos());
// Only pathfind if in range of the player
if(player_distance < 16)
{
if(
(walk_to != null && getPos().toInt().equal(walk_to.toInt()) &&
player_distance > 2) || walk_scan_cooldown < 1 || walking_for > 200)
{
AStar astar = new AStar(getPos().xz().toInt(), 16, new AStarSearcher(layer));
Vec2i path[] = astar.getPath(Main.player.getPos().xz().toInt());
walk_scan_cooldown = 100;
walking_for = 0;
if(path != null && path.length > 1) {
walk_to = new Vec3d(path[0].x, 0, path[0].y);
} else {
walk_to = null;
}
can_see_player = (path != null);
}
// Walk towards the player
if(walk_to != null)
{
push(walk_to.subtract(getPos()).normalize().multiply(0.064));
walking_for += 1;
}
if(can_see_player && noise_gun_fire.eval(time, 0) > 0 && !Main.player.dead && !Main.player.in_animation)
{
gun_interval += 1;
gun_interval %= 10;
if(gun_interval == 0)
{
// Fire the gun
int d = (int)(1 + gun_level / 5.0);
Vec3d bullet_velocity = getVelocity().add(Main.player.getPos().subtract(getPos())).normalize().multiply(0.2);
Vec3d bullet_pos = getPos().add(new Vec3d(0, 0.4, 0));
Main.world.getLayer().spawnEntity(new EntityBullet(bullet_pos, bullet_velocity, this, 20*d*d, 60));
}
}
}
// Despawn
if(player_distance > 128) {
kill();
}
// Increase time
time += 0.001;
}
@Override
public Model getModel() {
return Models.ENTITY_ZOMBIE_F;
}
@Override
public void addHealth(double amount) {
health += amount;
}
@Override
public void addDamage(double amount) {
health -= amount;
}
@Override
public void addBlastDamage(double amount) {
addDamage(amount);
}
@Override
public void addFireDamage(double amount) {
addDamage(amount);
}
@Override
public double getHealth() {
return health;
}
@Override
public void resetHealth() {
health = health_max;
}
@Override
public void clearHealth() {
health = 0;
}
@Override
public double maxHealth() {
return health_max;
}
@Override
public void setHealth(double health) {
this.health = health;
}
@Override
public int bloodParticles() {
return 12;
}
@Override
public void killWithParticles() {
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,33 @@
package projectzombie.entity;
import bdf.types.BdfObject;
import gl_engine.vec.Vec3d;
import projectzombie.init.Models;
import projectzombie.model.Model;
public class EntityZombieArmored extends EntityZombie
{
public EntityZombieArmored(BdfObject bdf) {
super(bdf);
}
public EntityZombieArmored(Vec3d pos, Vec3d velocity) {
super(pos, velocity);
this.health_max *= 5;
this.health = this.health_max;
this.gun_level = 3;
this.crossUnwalkable = true;
}
@Override
public int bloodParticles() {
return 6;
}
@Override
public Model getModel() {
return Models.ENTITY_ZOMBIE_F_ARMORED;
}
}

View File

@ -0,0 +1,21 @@
package projectzombie.entity.particle;
import gl_engine.vec.Vec3d;
import projectzombie.init.Models;
public class ParticleBlood extends ParticleBreak
{
public ParticleBlood(Vec3d pos, Vec3d velocity, int size) {
super(pos, velocity, Models.PARTICLE_BLOOD, size, 0.25);
}
public ParticleBlood(Vec3d pos, Vec3d velocity) {
this(pos, velocity, 20);
}
@Override
public double getParticleSize() {
return 0.05;
}
}

View File

@ -0,0 +1,184 @@
package projectzombie.entity.particle;
import java.util.Random;
import gl_engine.MathHelpers;
import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.entity.EntityParticle;
import projectzombie.entity.EntityParticlePart;
import projectzombie.model.IModel;
import projectzombie.model.Model;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ParticleBreak extends EntityParticle
{
protected static final Random rand = new Random();
protected class Break extends EntityParticlePart
{
public Vec3d velocity;
public boolean moving;
public Break(TextureRef3D tex, Vec3d pos, Vec3d velocity, boolean moving, double size, int flags) {
super(tex, pos, size, flags);
this.velocity = velocity;
this.moving = moving;
}
@Override
public boolean isFlat() {
return isStill(this);
}
@Override
public double getFade() {
return getParticleFade();
}
}
protected Break[] particles;
protected int still, time;
protected double still_ypos;
protected double getParticleFade() {
return time / 1000.0;
}
public double getParticleSize() {
return 0.1;
}
protected double getParticleSpeed() {
return 0.01;
}
public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model) {
this(pos, velocity, model, 100, 0.05);
}
public ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count) {
this(pos, velocity, model, count, 0.05);
}
protected ParticleBreak(Vec3d pos, Vec3d velocity, IModel model, int count, double velocity_up_multiplier) {
super(new Vec3d(pos.x, 0, pos.z), new Vec3d(0, 0, 0));
if(pos.squareDistance(Main.player.getPos()) > 32) {
count = 0;
}
this.hasGravity = false;
double model_height = getHeight(model);
float[] verticies = model.getVerticies();
if(model_height > 1) {
count *= model_height;
}
if(model.getSize() == 0) {
count = 0;
}
particles = new Break[count];
for(int i=0;i<particles.length;i++)
{
int[] tex_id = {0};
TextureRef3D ref = model.getRandomChunk(tex_id);
Break particle = new Break(ref,
pos.add(new Vec3d(0, rand.nextDouble() * model_height, 0)),
velocity.multiply(rand.nextDouble()).add(
MathHelpers.moveTowards2(getParticleSpeed(), rand.nextDouble() * MathHelpers.TWO_PI).xny().add(
new Vec3d(0, rand.nextDouble() * velocity_up_multiplier, 0))), true, getParticleSize(),
((int)verticies[tex_id[0] * Model.SIZE + Model.SIZE - 1] & 0b0110) | 0b1000);
particles[i] = particle;
}
still_ypos = 1/256.0;
time = 1000;
still = 0;
}
protected double getHeight(IModel model) {
return model.getHeight();
}
protected void onAllStill() {
if(time < 0) {
onAllDead();
}
}
protected void onAllDead() {
kill();
}
protected boolean isStill(Break particle) {
return particle.pos.y <= still_ypos;
}
protected void onStill(Break particle) {
particle.moving = false;
particle.pos.y = still_ypos;
particle.flags &= 0b0110;
still += 1;
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
if(isDead()) {
return;
}
time -= 1;
if(still == particles.length) {
onAllStill();
return;
}
for(int i=0;i<particles.length;i++)
{
Break particle = particles[i];
if(!particle.moving) {
continue;
}
if(isStill(particle)) {
onStill(particle);
continue;
}
particle.velocity.y -= MathHelpers.FallSpeed;
particle.pos = particle.pos.add(particle.velocity);
}
}
@Override
public IModel getModel() {
return null;
}
@Override
public int getParticleCount() {
return particles.length;
}
@Override
public EntityParticlePart getParticleAt(int id) {
return particles[id];
}
}

View File

@ -0,0 +1,24 @@
package projectzombie.entity.particle;
import gl_engine.vec.Vec3d;
import projectzombie.init.Models;
public class ParticleLava extends ParticleBreak
{
public ParticleLava(Vec3d pos, Vec3d velocity) {
this(pos, velocity, 100);
}
public ParticleLava(Vec3d pos, Vec3d velocity, int count) {
super(pos, velocity, Models.TILE_LAVA, count, 0.1);
this.still_ypos = -1;
}
@Override
protected boolean isStill(Break particle) {
return particle.pos.y <= -1;
}
}

View File

@ -0,0 +1,43 @@
package projectzombie.entity.particle;
import gl_engine.vec.Vec3d;
import projectzombie.entity.EntityParticle;
import projectzombie.entity.EntityParticlePart;
import projectzombie.init.Models;
import projectzombie.model.Model;
import projectzombie.util.math.random.RandomHelpers;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ParticleSmoke extends EntityParticle
{
private Model model;
public ParticleSmoke(Vec3d pos, Vec3d velocity) {
super(pos.add(new Vec3d(
RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5, 0,
RandomHelpers.randrange(rand, 1000)/1000.0 - 0.5)),
velocity.add(new Vec3d(0, (rand.nextDouble() + 0.5) / 100, 0)));
hasGravity = false;
model = Models.PARTICLE_SMOKE_RANDOM.getModel();
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
setVelocity(getVelocity().multiply(new Vec3d(0.995, 1, 0.995)));
}
@Override
public int getParticleCount() {
return 1;
}
@Override
public EntityParticlePart getParticleAt(int id) {
return new EntityParticlePart(model.getTextures()[0], getPos(), 1, 0b1000);
}
}

View File

@ -0,0 +1,133 @@
package projectzombie.entity.particle;
import gl_engine.MathHelpers;
import gl_engine.texture.TextureRef3D;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d;
import projectzombie.entity.Entity;
import projectzombie.entity.EntityParticle;
import projectzombie.entity.EntityParticlePart;
import projectzombie.init.Models;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class ParticleSmokeTrail extends EntityParticle
{
protected class SmokeTrail extends EntityParticlePart
{
Vec3d velocity;
int time;
SmokeTrail(TextureRef3D tex, Vec3d pos, Vec3d velocity) {
super(tex, pos.add(new Vec3d(0, 0.5, 0)), 0, 0b1000);
time = 500;
this.velocity = velocity;
}
boolean isDead() {
return time <= 0;
}
void update()
{
if(time <= 0) {
return;
}
time -= 1;
pos = pos.add(velocity);
size = time / 10000.0;
}
@Override
public double getFade() {
return 0.5;
}
}
private Entity parent;
private int dead;
private boolean generating_particles = true;
private SmokeTrail[] particles;
public ParticleSmokeTrail(Entity parent) {
this(parent, 1000);
}
private ParticleSmokeTrail(Entity parent, int size) {
super(parent.getPos(), new Vec3d(0, 0, 0));
dead = size;
particles = new SmokeTrail[size];
this.parent = parent;
}
@Override
public void tick(Chunk chunk, Layer layer) {
super.tick(chunk, layer);
setPos(parent.getPos());
Vec3d wind = layer.layergen.getWind(layer, getPos().xz());
for(int i=0;i<particles.length;i++)
{
if(particles[i] == null) {
continue;
}
if(particles[i].isDead()) {
particles[i] = null;
dead += 1;
continue;
}
particles[i].update();
}
if(!generating_particles) {
return;
}
for(int i=0;i<particles.length;i++) {
if(particles[i] == null)
{
int[] tex_id = {0};
TextureRef3D tex = Models.PARTICLE_SMOKE_TRAIL.getRandomChunk(tex_id);
particles[i] = new SmokeTrail(tex, parent.getPos().copy(),
parent.getVelocity().add(MathHelpers.moveTowards3(0.01, new Vec2d(
rand.nextDouble() * MathHelpers.TWO_PI,
rand.nextDouble() * MathHelpers.PI - MathHelpers.HALF_PI)))
.add(wind).multiply(0.5));
dead -= 1;
break;
}
}
}
public void stopParticles() {
generating_particles = false;
}
public boolean noMoreParticles() {
return dead == particles.length;
}
@Override
public int getParticleCount() {
return particles.length;
}
@Override
public EntityParticlePart getParticleAt(int id) {
return particles[id];
}
}

View File

@ -0,0 +1,39 @@
package projectzombie.entity.particle;
import gl_engine.vec.Vec3d;
import projectzombie.init.Models;
import projectzombie.model.IModel;
public class ParticleWater extends ParticleBreak
{
public ParticleWater(Vec3d pos, Vec3d velocity) {
this(pos, velocity, 1);
}
public ParticleWater(Vec3d pos, Vec3d velocity, int count) {
super(pos, velocity, Models.PARTICLE_WATER, count, 0.04);
still_ypos = -1;
}
@Override
public boolean isDead() {
return still == particles.length;
}
@Override
protected double getHeight(IModel model) {
return 0.5;
}
@Override
protected double getParticleSpeed() {
return 0.05;
}
@Override
protected double getParticleFade() {
return 0.5;
}
}

View File

@ -0,0 +1,557 @@
package projectzombie.entity.player;
import java.util.ArrayList;
import org.lwjgl.opengl.GL33;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.MathHelpers;
import gl_engine.matrix.Matrix4;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d;
import projectzombie.Main;
import projectzombie.display.DisplayLighting;
import projectzombie.entity.Entity;
import projectzombie.entity.EntityAlive;
import projectzombie.entity.EntityHasArmor;
import projectzombie.entity.EntityHasClothing;
import projectzombie.entity.EntityHasInventory;
import projectzombie.entity.EntityHasTasks;
import projectzombie.entity.EntityItem;
import projectzombie.entity.particle.ParticleBreak;
import projectzombie.init.Items;
import projectzombie.init.Models;
import projectzombie.init.Tiles;
import projectzombie.inventory.Inventory;
import projectzombie.inventory.InventoryArmor;
import projectzombie.inventory.InventoryClothing;
import projectzombie.items.ItemTool;
import projectzombie.items.modifier.ItemModifierMeta;
import projectzombie.model.Model;
import projectzombie.model.ModelPlayer;
import projectzombie.settings.Cheats;
import projectzombie.task.Task;
import projectzombie.task.TaskDeathScreen;
import projectzombie.tiles.TileSapling;
import projectzombie.util.ItemStack;
import projectzombie.util.TileState;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class EntityPlayer extends Entity implements
EntityAlive, EntityHasInventory, EntityHasArmor, EntityHasClothing, EntityHasTasks
{
public boolean MOVE_FORWARD = false;
public boolean MOVE_BACKWARD = false;
public boolean MOVE_LEFT = false;
public boolean MOVE_RIGHT = false;
public boolean moving = false;
public ModelPlayer MODEL = Models.ENTITY_PLAYER_W;
private double health_max = 1000;
private double health = health_max;
private double temperature = 0.5;
private double hydration = 1;
private double break_progress = 0;
private Vec2i break_pos = new Vec2i(0, 0);
public boolean dead = false;
public boolean in_animation = false;
public int attackedCooldown = 0;
private int particle_spawn_cooldown = 0;
private ArrayList<Task> tasks;
private Inventory inventory;
private InventoryArmor armor;
private InventoryClothing clothing;
public int inventory_hand = 0;
public double angle;
private Vec2i last_chunk;
public EntityPlayer(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
health = nl.get("health").getDouble();
dead = nl.get("dead").getBoolean();
inventory = new Inventory(nl.get("inventory"));
armor = new InventoryArmor(nl.get("armor"));
clothing = new InventoryClothing(nl.get("clothing"));
angle = nl.get("angle").getDouble();
temperature = nl.get("temperature").getDouble();
hydration = nl.get("hydration").getDouble();
inventory_hand = nl.get("hand").getInteger();
attackedCooldown = nl.get("attackedCooldown").getInteger();
tasks = new ArrayList<Task>();
Task[] tasks = Task.loadTasks(this, nl.get("tasks"));
for(int i=0;i<tasks.length;i++) {
this.tasks.add(tasks[i]);
}
if(hydration > 1) {
hydration = 1;
}
}
public int getAmmo() {
return inventory.getItemCount(new ItemStack(Items.AMMO, 1));
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("health", bdf.newObject().setDouble(health));
nl.set("dead", bdf.newObject().setBoolean(dead));
inventory.BdfClassSave(nl.get("inventory"));
armor.BdfClassSave(nl.get("armor"));
clothing.BdfClassSave(nl.get("clothing"));
nl.set("angle", bdf.newObject().setDouble(angle));
nl.set("temperature", bdf.newObject().setDouble(temperature));
nl.set("hydration", bdf.newObject().setDouble(hydration));
nl.set("tasks", Task.saveTasks(bdf.newObject(), tasks.toArray(new Task[0])));
nl.set("hand", bdf.newObject().setInteger(inventory_hand));
nl.set("attackedCooldown", bdf.newObject().setInteger(attackedCooldown));
}
public EntityPlayer() {
super(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0));
this.angle = 45;
// Set some settings
hitbox = 0.5;
isSolid = true;
emitsLight = true;
tasks = new ArrayList<Task>();
// Create the inventory
inventory = new Inventory(42);
armor = new InventoryArmor();
clothing = new InventoryClothing();
}
@Override
public double getLightLevel()
{
ItemStack item = inventory.getItem(inventory_hand);
if(!item.isEmpty()) {
return getLightWithHeight(item.item.getLightLevel(item));
}
return 0;
}
@Override
public void tick(Chunk chunk, Layer layer)
{
chunk = layer.getChunk(getPos().xz());
if(chunk != null && chunk.c_pos != null && (last_chunk == null || !chunk.c_pos.equal(last_chunk))) {
last_chunk = chunk.c_pos;
DisplayLighting.setDirty();
}
// Handle player deaths
if(health <= 0 && !dead)
{
chunk.spawnEntity(new ParticleBreak(getPos(), getVelocity(), getModel()));
if(Cheats.god_mode) {
this.resetHealth();
}
else {
dead = true;
health = 0;
addTask(new TaskDeathScreen(this));
}
}
for(int i=0;i<tasks.size();i++) {
Task task = tasks.get(i);
if(task.isDone()) {
tasks.remove(i);
i -= 1;
} else {
task.update();
}
}
// Is the player dead or in an animation
if(dead || in_animation) return;
// Call super
super.tick(chunk, layer);
if(attackedCooldown > 0) {
attackedCooldown -= 1;
}
double temp_diff = MathHelpers.biggest(
layer.layergen.getTemperature(layer, getPos().xz()),
chunk.getLightLevel(getPos().xz().toInt()) * 0.6) - temperature;
temperature += temp_diff / 1000;
hydration -= MathHelpers.smoothStep(Math.abs(temperature - 0.4) * 0.75 + 0.1) / 4000;
if(temperature < 0.3) {
health -= 2 * (0.3 - temperature);
resetAttackTimer();
}
else if(temperature > 0.7) {
health -= 4 * (temperature - 0.7);
resetAttackTimer();
}
else if(attackedCooldown == 0 && health < health_max) {
health += 0.1;
}
if(hydration <= 0) {
hydration = 0;
health -= 0.1;
resetAttackTimer();
}
// Rotate left
if(MOVE_LEFT) {
this.angle -= 1;
}
// Rotate right
if(MOVE_RIGHT) {
this.angle += 1;
}
this.angle = MathHelpers.mod(this.angle, 360);
// Move forward
if(MOVE_FORWARD) {
this.moveTowards(this.angle);
}
// Move backward
if(MOVE_BACKWARD) {
this.moveTowards(this.angle + 180);
}
}
@Override
public void kill()
{
// Is god mode inactive; kill the player
if(Cheats.god_mode) {
return;
}
chunk.spawnEntity(new ParticleBreak(getPos(), getVelocity(), getModel()));
dead = true;
}
public void moveTowards(double angle, double speed) {
if(dead || in_animation) return;
super.push(MathHelpers.moveTowards2(speed, Math.toRadians(angle)).xny());
}
public void moveTowards(double angle) {
this.moveTowards(angle, 0.08);
}
public void leftClick() {
if(dead || in_animation) return;
Layer layer = Main.world.getLayer();
ItemStack is = inventory.getItem(inventory_hand);
Vec2d place_pos = getPos().xz().add(MathHelpers.moveTowards2(0.5, Math.toRadians(angle)));
if(is.isEmpty() || !is.item.onPlayerLeftClick(is, Main.world.getLayer(), this, place_pos))
{
boolean isTool = !is.isEmpty() && is.item instanceof ItemTool;
ItemTool tool = isTool ? (ItemTool) is.item : null;
double speed = isTool ? ((ItemTool) is.item).toolSpeed(is) : 1;
Vec2i pos = place_pos.toInt();
for(int ti=0;ti<2;ti++)
{
TileState ts;
if(ti == 0) {
ts = layer.getFrontTile(pos);
} else {
ts = layer.getBackTile(pos);
}
if(ts.tile.canTileBreak(ts, is, tool))
{
break_progress += speed;
if(!pos.equal(break_pos)) {
break_progress = 0;
break_pos = pos;
}
particle_spawn_cooldown += 1;
if(particle_spawn_cooldown > 10) {
particle_spawn_cooldown -= 10;
layer.spawnEntity(new ParticleBreak(
new Vec3d(pos.x + 0.5, 0, pos.y + 0.5),
new Vec3d(0, 0, 0), ts.tile.getModel(ts.meta), 2));
}
if(break_progress > ts.tile.hardness)
{
ItemStack[] stacks = ts.tile.getTileDrops(ts);
for(ItemStack stack : stacks) {
layer.spawnEntity(new EntityItem(
pos.toDouble().add(new Vec2d(0.5, 0.5)).xny(),
new Vec3d(0, 0, 0), stack));
}
if(ts.tile.doBreak(layer, chunk, ts, pos)) {
if(ti == 0) {
layer.breakFrontTile(pos);
} else {
layer.breakBackTile(pos);
}
}
break_progress = 0;
if(tool != null) {
tool.toolOnUse(is);
}
}
break;
}
}
}
}
public void rightClick() {
if(dead || in_animation) return;
ItemStack is = inventory.getItem(inventory_hand);
Vec2d movement = MathHelpers.moveTowards2(1, Math.toRadians(angle));
Vec2d place_pos = getPos().xz().add(movement);
if(!activateTile(getPos().xz().add(movement.multiply(0.5)).toInt()) && !is.isEmpty()) {
is.item.onPlayerRightClick(is, Main.world.getLayer(), this, place_pos);
}
}
@Override
public void addHealth(double amount) {
health += amount;
if(health > health_max) health = health_max;
}
@Override
public void addDamage(double amount) {
health -= amount;
resetAttackTimer();
}
public void resetAttackTimer() {
attackedCooldown = 3000; // Don't heal for 30 seconds
}
@Override
public void addFireDamage(double amount) {
addDamage(amount);
}
@Override
public void addBlastDamage(double amount) {
addDamage(amount);
}
@Override
public double getHealth() {
return health;
}
@Override
public void resetHealth() {
health = health_max;
}
@Override
public void clearHealth() {
health = 0;
}
@Override
public double maxHealth() {
return health_max;
}
@Override
public void setHealth(double health) {
this.health = health;
}
@Override
public Inventory getInventory() {
return inventory;
}
public void dropItem()
{
ItemStack i = inventory.getItem(inventory_hand);
if(!i.isEmpty())
{
ItemStack stack = i.copy();
stack.count = 1;
EntityItem e = new EntityItem(getPos(), getVelocity(), stack, Math.toRadians(angle));
Main.world.getLayer().spawnEntity(e);
i.count -= 1;
}
}
public void render()
{
Layer layer = Main.world.getLayer();
Model model = getModel();
model.setModel(Matrix4.translate(0, getPos().y, 0));
model.render();
ItemStack holding = inventory.getItem(inventory_hand);
Vec2d place_pos = getPos().xz().add(MathHelpers.moveTowards2(0.5, Math.toRadians(angle)));
Vec3d ppos = getPos();
{
boolean isTool = !holding.isEmpty() && holding.item instanceof ItemTool;
ItemTool tool = isTool ? (ItemTool) holding.item : null;
Vec2i pos = place_pos.toInt();
for(int ti=0;ti<2;ti++)
{
TileState ts;
if(ti == 0) {
ts = layer.getFrontTile(pos);
} else {
ts = layer.getBackTile(pos);
}
if(ts.tile.canTileBreak(ts, holding, tool) || ts.tile.canUse(ts))
{
Models.TILE_BORDER.setModel(Matrix4.translate(
new Vec3d(pos.x - ppos.x, 0, pos.y - ppos.z)));
Models.TILE_BORDER.render();
break;
}
}
}
if(holding != null && !holding.isEmpty())
{
Model model_place = holding.item.getPlaceModel(holding);
Model model_spawn = holding.item.getSpawnModel(holding);
Vec2d pos = ppos.xz().add(MathHelpers.moveTowards2(1, Math.toRadians(angle)));
boolean render_place_model = model_place != null &&
holding.item.showPlaceModel(layer, pos.toInt(), holding);
if(render_place_model || model_spawn != null)
{
GL33.glUniform4f(Main.window.glsl_color, 0.5f, 0.75f, 0.5f, 1);
}
if(render_place_model)
{
model_place.setModel(Matrix4.translate(new Vec3d(
MathHelpers.floor(pos.x) + 0.5 - ppos.x, 0.00390625,
MathHelpers.floor(pos.y) + 0.5 - ppos.z)));
model_place.render();
}
if(model_spawn != null)
{
model_spawn.setModel(Matrix4.translate(pos.x - ppos.x, 0, pos.y - ppos.z));
model_spawn.render();
}
if(render_place_model || model_spawn != null)
{
GL33.glUniform4f(Main.window.glsl_color, 1, 1, 1, 1);
}
}
}
@Override
public int bloodParticles() {
return 12;
}
@Override
public Model getModel() {
return moving ? MODEL.model_back_moving : MODEL.model_back_still;
}
public double getTemperature() {
return temperature;
}
public double getHydration() {
return hydration;
}
public void setInAnimation(boolean status)
{
in_animation = status;
hasGravity = !status;
isSolid = !status;
moving = status;
}
@Override
public void addTask(Task task) {
tasks.add(task);
}
public void rehydrate()
{
hydration += 0.001;
if(hydration > 1) {
hydration = 1;
}
}
@Override
public InventoryClothing getInventoryClothing() {
return clothing;
}
@Override
public InventoryArmor getInventoryArmor() {
return armor;
}
}

View File

@ -0,0 +1,19 @@
package projectzombie.entity.tileentity;
import gl_engine.vec.Vec2i;
import gl_engine.vec.Vec3d;
import projectzombie.entity.Entity;
import projectzombie.init.Models;
import projectzombie.model.IModel;
public abstract class TileEntity extends Entity
{
public TileEntity() {
super(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0));
}
@Override
public IModel getModel() {
return null;
}
}

View File

@ -0,0 +1,265 @@
package projectzombie.entity.tileentity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.vec.Vec2i;
import projectzombie.Main;
import projectzombie.init.Items;
import projectzombie.init.Tiles;
import projectzombie.inventory.Inventory;
import projectzombie.items.ItemBurnable;
import projectzombie.items.ItemSmeltable;
import projectzombie.items.ItemSmeltable;
import projectzombie.items.ItemFlint;
import projectzombie.items.ItemSmeltable;
import projectzombie.items.modifier.ItemModifierDamage;
import projectzombie.menu.MenuInventoryStorage;
import projectzombie.menu.gui.GUIItemSlotGetter;
import projectzombie.util.ItemStack;
import projectzombie.util.TileState;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class TileEntityBlastFurnace extends TileEntity
{
private ItemStack burning;
private Inventory inventory;
private int next_level;
private int burn_time;
private int cook_time;
private int cook_slot;
private int level;
public TileEntityBlastFurnace(BdfObject bdf) {
BdfClassLoad(bdf);
}
public TileEntityBlastFurnace(Vec2i pos) {
inventory = new Inventory(8);
burning = ItemStack.getEmpty();
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
inventory = new Inventory(nl.get("inventory"));
burning = new ItemStack(nl.get("burning"));
burn_time = nl.get("burnTime").getInteger();
cook_time = nl.get("cookTime").getInteger();
cook_slot = nl.get("cookSlot").getInteger();
next_level = nl.get("nextLevel").getInteger();
level = nl.get("level").getInteger();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
inventory.BdfClassSave(nl.get("inventory"));
burning.BdfClassSave(nl.get("burning"));
nl.set("burnTime", bdf.newObject().setInteger(burn_time));
nl.set("cookTime", bdf.newObject().setInteger(cook_time));
nl.set("cookSlot", bdf.newObject().setInteger(cook_slot));
nl.set("nextLevel", bdf.newObject().setInteger(next_level));
nl.set("level", bdf.newObject().setInteger(level));
}
private void updateTile() {
chunk.setFrontTile(new TileState(Tiles.BLAST_FURNACE, (byte)level), getPos().xz().toInt());
}
private void checkForFuel()
{
for(int i=0;i<inventory.getSlotCount();i++)
{
ItemStack stack = inventory.getItem(i);
if(stack.isEmpty()) {
continue;
}
if(stack.item instanceof ItemBurnable)
{
stack.count -= 1;
burning = stack.copy();
burning.count = 1;
burn_time = ((ItemBurnable)stack.item).getBurnTime(burning);
if(level < 4)
{
level = 4;
updateTile();
Vec2i tpos = getPos().xz().toInt();
if(chunk.getBackTile(tpos).tile == Tiles.GRASS) {
chunk.setBackTile(Tiles.GRASS_BURNT.getDefaultState(), tpos);
}
}
break;
}
}
}
@Override
public void tick(Chunk chunk, Layer layer)
{
super.tick(chunk, layer);
// Check for fuel if the fuel has run out
if(burning.isEmpty())
{
// Check for fuel and possibly add it if its available
checkForFuel();
if(!burning.isEmpty()) {
next_level = 1600;
}
}
// Check if there is fuel
// This could have changed since
// the last check for fuel
if(!burning.isEmpty())
{
burn_time -= 1;
if(burn_time < 0)
{
burn_time = 0;
burning.count = 0;
for(ItemStack stack : ((ItemBurnable)burning.item).getBurnProducts(burning)) {
inventory.addItem(stack);
}
checkForFuel();
}
}
if(level > 0)
{
ItemStack stack = inventory.getItem(cook_slot);
// Check for cookable items if things aren't being cooked
if(stack.isEmpty() || !(stack.item instanceof ItemSmeltable))
{
cook_time = 1600;
for(int i=0;i<inventory.getSlotCount();i++)
{
ItemStack check = inventory.getItem(i);
if(check.isEmpty()) {
continue;
}
if(check.item instanceof ItemSmeltable) {
cook_slot = i;
cook_time = 1600;
break;
}
}
}
// Cook the item thats currently being cooked
// and process them if they have finished cooking.
// Make sure any non-cookable items don't get cooked.
stack = inventory.getItem(cook_slot);
if(!stack.isEmpty() && stack.item instanceof ItemSmeltable)
{
cook_time -= 1;
if(cook_time < 0)
{
stack.count -= 1;
cook_time = 1600;
ItemStack[] result = ((ItemSmeltable)stack.item).getSmeltProducts(stack);
for(int i=0;i<result.length;i++) {
inventory.addItem(result[i]);
}
}
}
}
next_level -= 1;
// Make the fire burn brighter/darker based on whether there is fuel or not
if(next_level < 0)
{
if(burning.isEmpty())
{
next_level = 200;
level -= 1;
if(level < 0) {
level = 0;
}
else {
updateTile();
}
}
else
{
next_level = 1600;
level += 1;
if(level > 16) {
level = 16;
}
else {
updateTile();
}
}
}
}
public Inventory getInventory() {
return inventory;
}
public void onOpened() {
Main.menu = new MenuInventoryStorage(Main.menu, inventory, new GUIItemSlotGetter() {
@Override
public void setItemStack(ItemStack stack) {
}
@Override
public boolean isAllowed(ItemStack stack)
{
if(stack.item instanceof ItemBurnable) {
return true;
}
if(stack.item instanceof ItemSmeltable) {
return true;
}
return false;
}
@Override
public ItemStack getItemStack() {
return null;
}
});
}
}

View File

@ -0,0 +1,264 @@
package projectzombie.entity.tileentity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.vec.Vec2i;
import projectzombie.Main;
import projectzombie.init.Items;
import projectzombie.init.Tiles;
import projectzombie.inventory.Inventory;
import projectzombie.items.ItemBurnable;
import projectzombie.items.ItemCookable;
import projectzombie.items.ItemFlint;
import projectzombie.items.ItemSmeltable;
import projectzombie.items.modifier.ItemModifierDamage;
import projectzombie.menu.MenuInventoryStorage;
import projectzombie.menu.gui.GUIItemSlotGetter;
import projectzombie.util.ItemStack;
import projectzombie.util.TileState;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class TileEntityCampfire extends TileEntity
{
private ItemStack burning;
private Inventory inventory;
private int next_level;
private int burn_time;
private int cook_time;
private int cook_slot;
private int level;
public TileEntityCampfire(BdfObject bdf) {
BdfClassLoad(bdf);
}
public TileEntityCampfire(Vec2i pos) {
inventory = new Inventory(8);
burning = ItemStack.getEmpty();
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
inventory = new Inventory(nl.get("inventory"));
burning = new ItemStack(nl.get("burning"));
burn_time = nl.get("burnTime").getInteger();
cook_time = nl.get("cookTime").getInteger();
cook_slot = nl.get("cookSlot").getInteger();
next_level = nl.get("nextLevel").getInteger();
level = nl.get("level").getInteger();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
inventory.BdfClassSave(nl.get("inventory"));
burning.BdfClassSave(nl.get("burning"));
nl.set("burnTime", bdf.newObject().setInteger(burn_time));
nl.set("cookTime", bdf.newObject().setInteger(cook_time));
nl.set("cookSlot", bdf.newObject().setInteger(cook_slot));
nl.set("nextLevel", bdf.newObject().setInteger(next_level));
nl.set("level", bdf.newObject().setInteger(level));
}
private void updateTile() {
chunk.setFrontTile(new TileState(Tiles.CAMPFIRE, (byte)level), getPos().xz().toInt());
}
private void checkForFuel()
{
for(int i=0;i<inventory.getSlotCount();i++)
{
ItemStack stack = inventory.getItem(i);
if(stack.isEmpty()) {
continue;
}
if(stack.item instanceof ItemBurnable)
{
stack.count -= 1;
burning = stack.copy();
burning.count = 1;
burn_time = ((ItemBurnable)stack.item).getBurnTime(burning);
if(level < 4)
{
level = 4;
updateTile();
Vec2i tpos = getPos().xz().toInt();
if(chunk.getBackTile(tpos).tile == Tiles.GRASS) {
chunk.setBackTile(Tiles.GRASS_BURNT.getDefaultState(), tpos);
}
}
break;
}
}
}
@Override
public void tick(Chunk chunk, Layer layer)
{
super.tick(chunk, layer);
// Check for fuel if the fuel has run out
if(burning.isEmpty())
{
// Check for fuel and possibly add it if its available
checkForFuel();
if(!burning.isEmpty()) {
next_level = 1600;
}
}
// Check if there is fuel
// This could have changed since
// the last check for fuel
if(!burning.isEmpty())
{
burn_time -= 1;
if(burn_time < 0)
{
burn_time = 0;
burning.count = 0;
for(ItemStack stack : ((ItemBurnable)burning.item).getBurnProducts(burning)) {
inventory.addItem(stack);
}
checkForFuel();
}
}
if(level > 0)
{
ItemStack stack = inventory.getItem(cook_slot);
// Check for cookable items if things aren't being cooked
if(stack.isEmpty() || !(stack.item instanceof ItemCookable))
{
cook_time = 1600;
for(int i=0;i<inventory.getSlotCount();i++)
{
ItemStack check = inventory.getItem(i);
if(check.isEmpty()) {
continue;
}
if(check.item instanceof ItemCookable) {
cook_slot = i;
cook_time = 1600;
break;
}
}
}
// Cook the item thats currently being cooked
// and process them if they have finished cooking.
// Make sure any non-cookable items don't get cooked.
stack = inventory.getItem(cook_slot);
if(!stack.isEmpty() && stack.item instanceof ItemCookable)
{
cook_time -= 1;
if(cook_time < 0)
{
stack.count -= 1;
cook_time = 1600;
ItemStack[] result = ((ItemCookable)stack.item).getCookProducts(stack);
for(int i=0;i<result.length;i++) {
inventory.addItem(result[i]);
}
}
}
}
next_level -= 1;
// Make the fire burn brighter/darker based on whether there is fuel or not
if(next_level < 0)
{
if(burning.isEmpty())
{
next_level = 200;
level -= 1;
if(level < 0) {
level = 0;
}
else {
updateTile();
}
}
else
{
next_level = 1600;
level += 1;
if(level > 16) {
level = 16;
}
else {
updateTile();
}
}
}
}
public Inventory getInventory() {
return inventory;
}
public void onOpened() {
Main.menu = new MenuInventoryStorage(Main.menu, inventory, new GUIItemSlotGetter() {
@Override
public void setItemStack(ItemStack stack) {
}
@Override
public boolean isAllowed(ItemStack stack)
{
if(stack.item instanceof ItemBurnable) {
return true;
}
if(stack.item instanceof ItemCookable) {
return true;
}
return false;
}
@Override
public ItemStack getItemStack() {
return null;
}
});
}
}

View File

@ -0,0 +1,42 @@
package projectzombie.entity.tileentity;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import projectzombie.util.ItemStack;
public class TileEntityClayPot extends TileEntity
{
private double volume;
public TileEntityClayPot(double volume) {
this.volume = volume;
}
public TileEntityClayPot(BdfObject bdf) {
BdfClassLoad(bdf);
}
public double getVolume() {
return volume;
}
public void setVolume(double volume) {
this.volume = volume;
}
@Override
public void BdfClassLoad(BdfObject bdf) {
super.BdfClassLoad(bdf);
BdfNamedList nl = bdf.getNamedList();
volume = nl.get("volume").getDouble();
}
@Override
public void BdfClassSave(BdfObject bdf) {
super.BdfClassSave(bdf);
BdfNamedList nl = bdf.getNamedList();
nl.set("volume", bdf.newObject().setDouble(volume));
}
}

View File

@ -0,0 +1,57 @@
package projectzombie.init;
import java.util.ArrayList;
import bdf.types.BdfObject;
import projectzombie.entity.Entity;
import projectzombie.entity.EntityBoss;
import projectzombie.entity.EntityBullet;
import projectzombie.entity.EntityContainer;
import projectzombie.entity.EntityDummy;
import projectzombie.entity.EntityExplosion;
import projectzombie.entity.EntityFlare;
import projectzombie.entity.EntityGrapplingHook;
import projectzombie.entity.EntityItem;
import projectzombie.entity.EntityTnt;
import projectzombie.entity.EntityZombie;
import projectzombie.entity.EntityZombieArmored;
import projectzombie.entity.player.EntityPlayer;
import projectzombie.entity.tileentity.TileEntityBlastFurnace;
import projectzombie.entity.tileentity.TileEntityCampfire;
import projectzombie.entity.tileentity.TileEntityClayPot;
public class Entities
{
public static final ArrayList<Class<? extends Entity>> ENTITIES = new ArrayList<>();
private static void register(Class<? extends Entity> e)
{
try {
e.getConstructor(BdfObject.class);
} catch (NoSuchMethodException | SecurityException err) {
err.printStackTrace();
System.exit(1);
}
ENTITIES.add(e);
}
public static void init()
{
register(EntityZombie.class);
register(EntityZombieArmored.class);
register(EntityTnt.class);
register(EntityItem.class);
register(EntityGrapplingHook.class);
register(EntityFlare.class);
register(EntityExplosion.class);
register(EntityDummy.class);
register(EntityBullet.class);
register(EntityBoss.class);
register(EntityPlayer.class);
register(EntityContainer.class);
register(TileEntityCampfire.class);
register(TileEntityBlastFurnace.class);
register(TileEntityClayPot.class);
}
}

View File

@ -0,0 +1,39 @@
package projectzombie.init;
import java.util.ArrayList;
import bdf.types.BdfObject;
import projectzombie.items.modifier.ItemModifier;
import projectzombie.items.modifier.ItemModifierDamage;
import projectzombie.items.modifier.ItemModifierFluidStorage;
import projectzombie.items.modifier.ItemModifierMeta;
import projectzombie.items.modifier.ItemModifierTimer;
import projectzombie.items.modifier.ItemModifierTimerPaused;
import projectzombie.items.modifier.ItemModifierWater;
public class ItemModifiers
{
public static final ArrayList<Class<? extends ItemModifier>> MODIFIERS = new ArrayList<>();
private static void register(Class<? extends ItemModifier> m)
{
try {
m.getConstructor(BdfObject.class);
} catch (NoSuchMethodException | SecurityException err) {
err.printStackTrace();
System.exit(1);
}
MODIFIERS.add(m);
}
public static void init()
{
register(ItemModifierMeta.class);
register(ItemModifierDamage.class);
register(ItemModifierFluidStorage.class);
register(ItemModifierWater.class);
register(ItemModifierTimer.class);
register(ItemModifierTimerPaused.class);
}
}

120
src/projectzombie/init/Items.java Executable file
View File

@ -0,0 +1,120 @@
package projectzombie.init;
import java.util.ArrayList;
import projectzombie.items.Item;
import projectzombie.items.ItemAcorn;
import projectzombie.items.ItemAmmo;
import projectzombie.items.ItemAsh;
import projectzombie.items.ItemBlastFurnace;
import projectzombie.items.ItemCampfire;
import projectzombie.items.ItemCharcoal;
import projectzombie.items.ItemClayPot;
import projectzombie.items.ItemClayPotWet;
import projectzombie.items.ItemCoal;
import projectzombie.items.ItemEmpty;
import projectzombie.items.ItemFlare;
import projectzombie.items.ItemFlint;
import projectzombie.items.ItemFlintHatchet;
import projectzombie.items.ItemGrapplingHook;
import projectzombie.items.ItemHealthPotion;
import projectzombie.items.ItemHempSeed;
import projectzombie.items.ItemInfestation;
import projectzombie.items.ItemLantern;
import projectzombie.items.ItemLog;
import projectzombie.items.ItemMetal;
import projectzombie.items.ItemOre;
import projectzombie.items.ItemPlantFibre;
import projectzombie.items.ItemRock;
import projectzombie.items.ItemStoneHatchet;
import projectzombie.items.ItemStonePick;
import projectzombie.items.ItemStoneShovel;
import projectzombie.items.ItemTnt;
import projectzombie.items.ItemTorch;
import projectzombie.items.ItemWoodPlanks;
import projectzombie.items.ItemWoodWall;
import projectzombie.items.ItemWorkbench;
import projectzombie.items.spawner.ItemSpawnDummy;
import projectzombie.items.spawner.ItemSpawnZombie;
public class Items
{
public static ArrayList<Item> items = new ArrayList<Item>();
private static void register(Item item) {
item.id = items.size();
items.add(item);
}
public static void init()
{
register(EMPTY);
register(AMMO);
register(HEALTH_POTION);
register(TNT);
register(LANTERN);
register(FLARE);
register(GRAPPLING_HOOK);
register(SPAWN_ZOMBIE);
register(SPAWN_DUMMY);
register(ROCK);
register(FLINT);
register(LOG);
register(ACORN);
register(PLANT_FIBRE);
register(HEMP_SEED);
register(AMMO);
register(INFESTATION);
register(FLINT_HATCHET);
register(CAMPFIRE);
register(CHARCOAL);
register(ASH);
register(WORKBENCH);
register(STONE_HATCHET);
register(STONE_PICK);
register(STONE_SHOVEL);
register(METAL);
register(ORE);
register(BLAST_FURNACE);
register(CLAY_POT);
register(CLAY_POT_WET);
register(TORCH);
register(COAL);
register(WOOD_PLANKS);
register(WOOD_WALL);
}
public static final Item AMMO = new ItemAmmo();
public static final Item HEALTH_POTION = new ItemHealthPotion();
public static final Item EMPTY = new ItemEmpty();
public static final Item TNT = new ItemTnt();
public static final Item LANTERN = new ItemLantern();
public static final Item FLARE = new ItemFlare();
public static final Item GRAPPLING_HOOK = new ItemGrapplingHook();
public static final Item SPAWN_ZOMBIE = new ItemSpawnZombie();
public static final Item SPAWN_DUMMY = new ItemSpawnDummy();
public static final Item ROCK = new ItemRock();
public static final Item FLINT = new ItemFlint();
public static final Item LOG = new ItemLog();
public static final Item ACORN = new ItemAcorn();
public static final Item HEMP_SEED = new ItemHempSeed();
public static final Item PLANT_FIBRE = new ItemPlantFibre();
public static final Item CAMPFIRE = new ItemCampfire();
public static final Item FLINT_HATCHET = new ItemFlintHatchet();
public static final Item INFESTATION = new ItemInfestation();
public static final Item CHARCOAL = new ItemCharcoal();
public static final Item ASH = new ItemAsh();
public static final Item WORKBENCH = new ItemWorkbench();
public static final Item STONE_SHOVEL = new ItemStoneShovel();
public static final Item STONE_PICK = new ItemStonePick();
public static final Item STONE_HATCHET = new ItemStoneHatchet();
public static final Item METAL = new ItemMetal();
public static final Item ORE = new ItemOre();
public static final Item BLAST_FURNACE = new ItemBlastFurnace();
public static final Item CLAY_POT = new ItemClayPot();
public static final Item CLAY_POT_WET = new ItemClayPotWet();
public static final Item TORCH = new ItemTorch();
public static final Item COAL = new ItemCoal();
public static final Item WOOD_PLANKS = new ItemWoodPlanks();
public static final Item WOOD_WALL = new ItemWoodWall();
}

View File

@ -0,0 +1,46 @@
package projectzombie.init;
import java.util.ArrayList;
import projectzombie.world.layer.layergen.LayerGen;
import projectzombie.world.layer.layergen.LayerGenBossArena;
import projectzombie.world.layer.layergen.LayerGenCaves;
import projectzombie.world.layer.layergen.LayerGenEarth;
import projectzombie.world.layer.layergen.LayerGenLavaCaves;
public class LayerGenerators
{
private static final ArrayList<LayerGen> lgens = new ArrayList<LayerGen>();
private static void register(LayerGen lg) {
lg.id = lgens.size();
lgens.add(lg);
}
public static void init()
{
register(EARTH);
register(CAVES);
register(LAVA_CAVES);
register(BOSS_ARENA);
}
public static LayerGen loadFromID(int id) {
return lgens.get(id);
}
public static int getLGID(LayerGen lg) {
for(int i=0;i<lgens.size();i++) {
LayerGen lgi = lgens.get(i);
if(lgi == lg) {
return i;
}
}
return -1;
}
public static final LayerGen EARTH = new LayerGenEarth();
public static final LayerGen CAVES = new LayerGenCaves();
public static final LayerGen LAVA_CAVES = new LayerGenLavaCaves();
public static final LayerGen BOSS_ARENA = new LayerGenBossArena();
}

View File

@ -0,0 +1,10 @@
package projectzombie.init;
import projectzombie.world.layer.Layer;
public class Layers
{
public static Layer EARTH;
public static Layer CAVES;
public static Layer LAVA_CAVES;
}

View File

@ -0,0 +1,243 @@
package projectzombie.init;
import gl_engine.vec.Vec2d;
import projectzombie.model.Model;
import projectzombie.model.ModelBox;
import projectzombie.model.ModelCactus;
import projectzombie.model.ModelChunkBorder;
import projectzombie.model.ModelCross;
import projectzombie.model.ModelEmpty;
import projectzombie.model.ModelGrass;
import projectzombie.model.ModelGui;
import projectzombie.model.ModelItem;
import projectzombie.model.ModelPlayer;
import projectzombie.model.ModelRandom;
import projectzombie.model.ModelRock;
import projectzombie.model.ModelTallGrass;
import projectzombie.model.ModelTile;
import projectzombie.model.ModelTileBorder;
import projectzombie.model.ModelTree;
import projectzombie.model.ModelTreeSnow;
import projectzombie.model.ModelVertical;
import projectzombie.model.ModelWall;
public class Models
{
public static final Model EMPTY = new ModelEmpty();
public static final Model TILE_MISSING = new ModelTile(Resources.TEX_EMPTY);
public static final Model TILE_BORDER = new ModelTileBorder();
public static final Model TILE_TALL_GRASS = new ModelTallGrass();
public static final Model TILE_GRASS = new ModelGrass();
public static final Model TILE_TREE = new ModelTree();
public static final Model TILE_TREE_SNOW = new ModelTreeSnow();
public static final Model TILE_CAMPFIRE_LIT = new ModelCross(Resources.ATLAS.get("/tile/campfire_lit.png"), 4, 20);
public static final Model TILE_CAMPFIRE_UNLIT = new ModelCross(Resources.ATLAS.get("/tile/campfire_unlit.png"));
public static final Model TILE_BLAST_FURNACE = new ModelBox(Resources.ATLAS.get("/tile/blast_furnace.png"));
public static final Model TILE_WORKBENCH = new ModelBox(Resources.ATLAS.get("/tile/workbench.png"));
public static final Model TILE_CLAY_POT_EMPTY = new ModelBox(Resources.ATLAS.get("/tile/clay_pot_empty.png"));
public static final Model TILE_CLAY_POT_WATER_1 = new ModelBox(Resources.ATLAS.get("/tile/clay_pot_water_1.png"));
public static final Model TILE_CLAY_POT_WATER_2 = new ModelBox(Resources.ATLAS.get("/tile/clay_pot_water_2.png"));
public static final Model TILE_CLAY_POT_WATER_3 = new ModelBox(Resources.ATLAS.get("/tile/clay_pot_water_3.png"));
public static final Model TILE_SAPLING_1 = new ModelCross(Resources.ATLAS.get("/tile/sapling1.png"));
public static final Model TILE_SAPLING_2 = new ModelCross(Resources.ATLAS.get("/tile/sapling2.png"));
public static final Model TILE_SAPLING_3 = new ModelCross(Resources.ATLAS.get("/tile/sapling3.png"));
public static final Model TILE_SAPLING_4 = new ModelCross(Resources.ATLAS.get("/tile/sapling4.png"));
public static final Model TILE_CACTUS_1 = new ModelCactus(Resources.ATLAS.get("/tile/cactus1.png"), 0.5);
public static final Model TILE_CACTUS_2 = new ModelCactus(Resources.ATLAS.get("/tile/cactus2.png"), 1.0);
public static final Model TILE_CACTUS_3 = new ModelCactus(Resources.ATLAS.get("/tile/cactus3.png"), 1.5);
public static final Model TILE_CACTUS_4 = new ModelCactus(Resources.ATLAS.get("/tile/cactus4.png"), 2.0);
public static final Model[] TILE_HEMP = new Model[] {
new ModelBox(Resources.ATLAS.get("/tile/hemp1.png")),
new ModelBox(Resources.ATLAS.get("/tile/hemp2.png")),
new ModelBox(Resources.ATLAS.get("/tile/hemp3.png")),
new ModelBox(Resources.ATLAS.get("/tile/hemp4.png")),
new ModelBox(Resources.ATLAS.get("/tile/hemp5.png"), new Vec2d(1, 2)),
new ModelBox(Resources.ATLAS.get("/tile/hemp6.png"), new Vec2d(1, 2)),
new ModelBox(Resources.ATLAS.get("/tile/hemp7.png"), new Vec2d(1, 2)),
new ModelBox(Resources.ATLAS.get("/tile/hemp8.png"), new Vec2d(1, 2)),
};
public static final Model TILE_SNOW = new ModelTile(Resources.ATLAS.get("/tile/snow.png"));
public static final Model TILE_ICE = new ModelTile(Resources.ATLAS.get("/tile/ice.png"));
public static final Model TILE_ICE_WALL = new ModelTile(Resources.ATLAS.get("/tile/ice_wall.png"));
public static final Model TILE_SANDSTONE = new ModelTile(Resources.ATLAS.get("/tile/sandstone.png"));
public static final Model TILE_SANDSTONE_WALL = new ModelTile(Resources.ATLAS.get("/tile/sandstone_wall.png"));
public static final Model TILE_GRASS_INFESTED = new ModelTile(Resources.ATLAS.get("/tile/grass_infested.png"));
public static final Model TILE_GRASS_BURNT = new ModelTile(Resources.ATLAS.get("/tile/grass_burnt.png"));
public static final Model TILE_SAND = new ModelTile(Resources.ATLAS.get("/tile/sand.png"));
public static final Model TILE_STONE = new ModelTile(Resources.ATLAS.get("/tile/stone.png"));
public static final Model TILE_DIRT = new ModelTile(Resources.ATLAS.get("/tile/dirt.png"));
public static final Model TILE_ROCK = new ModelRock(Resources.ATLAS.get("/tile/rock.png"));
public static final Model TILE_ROCK_ICE = new ModelRock(Resources.ATLAS.get("/tile/rock_ice.png"));
public static final Model TILE_ROCK_SANDSTONE = new ModelRock(Resources.ATLAS.get("/tile/rock_sandstone.png"));
public static final Model TILE_LADDER = new ModelVertical(Resources.ATLAS.get("/tile/ladder.png"));
public static final Model TILE_PORTAL = new ModelTile(Resources.ATLAS.get("/tile/tunnel_down.png"));
public static final Model TILE_WALL = new ModelTile(Resources.ATLAS.get("/tile/wall.png"));
public static final Model TILE_LADDER_UP = new ModelVertical(Resources.ATLAS.get("/tile/ladder_up.png"), new Vec2d(1, 16));
public static final Model TILE_CHEST = new ModelVertical(Resources.ATLAS.get("/tile/chest.png"));
public static final Model TILE_BOSS_PORTAL = new ModelVertical(Resources.ATLAS.get("/tile/boss_portal.png"), new Vec2d(2, 2));
public static final Model TILE_WATER = new ModelTile(Resources.ATLAS.get("/tile/water.png"), 16, 10);
public static final Model TILE_LAVA = new ModelTile(Resources.ATLAS.get("/tile/lava.png"), 16, 50);
public static final Model TILE_LAVA_FLOW = new ModelTile(Resources.ATLAS.get("/tile/lava_flow.png"), 16, 50);
public static final Model TILE_LANTERN = new ModelVertical(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
public static final Model TILE_ROCK_IRON = new ModelRock(Resources.ATLAS.get("/tile/rock_iron.png"));
public static final Model TILE_ROCK_GOLD = new ModelRock(Resources.ATLAS.get("/tile/rock_gold.png"));
public static final Model TILE_ROCK_TIN = new ModelRock(Resources.ATLAS.get("/tile/rock_tin.png"));
public static final Model TILE_ROCK_COPPER = new ModelRock(Resources.ATLAS.get("/tile/rock_copper.png"));
public static final Model TILE_ROCK_COAL = new ModelRock(Resources.ATLAS.get("/tile/rock_coal.png"));
public static final Model TILE_ROCK_URANIUM = new ModelRock(Resources.ATLAS.get("/tile/rock_uranium.png"));
public static final Model TILE_WOOD_FLOOR = new ModelTile(Resources.ATLAS.get("/tile/wood_floor.png"));
public static final Model TILE_WOOD_SNOW_FLOOR = new ModelTile(Resources.ATLAS.get("/tile/wood_snow_floor.png"));
public static final Model[] TILE_WOOD_WALL = ModelWall.rotationArray(
Resources.ATLAS.get("/tile/wood_wall_front.png"),
Resources.ATLAS.get("/tile/wood_wall_top.png"),
Resources.ATLAS.get("/tile/wood_wall_side.png"));
public static final Model[] TILE_WOOD_SNOW_WALL = ModelWall.rotationArray(
Resources.ATLAS.get("/tile/wood_snow_wall_front.png"),
Resources.ATLAS.get("/tile/wood_snow_wall_top.png"),
Resources.ATLAS.get("/tile/wood_snow_wall_side.png"));
public static final Model ENTITY_BOSS_IDLE = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_still.png"), new Vec2d(4, 4));
public static final Model ENTITY_BOSS_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_firing.png"), new Vec2d(4, 4), 4, 50);
public static final Model ENTITY_BOSS_WALKING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking.png"), new Vec2d(4, 4), 4, 50);
public static final Model ENTITY_BOSS_WALKING_AND_FIRING = new ModelVertical(Resources.ATLAS.get("/entity/boss1/boss_walking_firing.png"), new Vec2d(4, 4), 4, 50);
public static final Model ENTITY_TNT = new ModelVertical(Resources.ATLAS.get("/entity/tnt.png"), new Vec2d(0.5, 0.5));
public static final Model ENTITY_FLARE = new ModelVertical(Resources.ATLAS.get("/entity/flare.png"), new Vec2d(0.5, 0.5));
public static final Model ENTITY_DUMMY = new ModelVertical(Resources.ATLAS.get("/entity/dummy.png"));
public static final Model ENTITY_GRAPPLING_HOOK = new ModelVertical(Resources.ATLAS.get("/entity/grappling_hook.png"));
public static final Model PARTICLE_BLOOD = new ModelVertical(Resources.ATLAS.get("/particle/blood.png"), new Vec2d(1, 1));
public static final Model PARTICLE_WATER = new ModelVertical(Resources.ATLAS.get("/particle/water.png"), new Vec2d(1, 1));
public static final Model PARTICLE_SMOKE_TRAIL = new ModelVertical(Resources.ATLAS.get("/particle/smoke_trail.png"), new Vec2d(1, 1));
public static final ModelRandom PARTICLE_SMOKE_RANDOM = new ModelRandom(
new ModelVertical(Resources.ATLAS.get("/particle/smoke_0.png")),
new ModelVertical(Resources.ATLAS.get("/particle/smoke_1.png")),
new ModelVertical(Resources.ATLAS.get("/particle/smoke_2.png")),
new ModelVertical(Resources.ATLAS.get("/particle/smoke_3.png")),
new ModelVertical(Resources.ATLAS.get("/particle/smoke_4.png")),
new ModelVertical(Resources.ATLAS.get("/particle/smoke_5.png")));
public static final ModelGui UI_PIXEL_WHITE = new ModelGui(Resources.ATLAS.get("/gui/pixel_white.png"));
public static final ModelGui UI_PIXEL_BLACK = new ModelGui(Resources.ATLAS.get("/gui/pixel_black.png"));
public static final ModelGui UI_BUTTON = new ModelGui(Resources.ATLAS.get("/gui/button_normal.png"), new Vec2d(12, 1.5));
public static final ModelGui UI_BUTTON_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_hover.png"), new Vec2d(12, 1.5));
public static final ModelGui UI_BUTTON_DELETE = new ModelGui(Resources.ATLAS.get("/gui/button_delete.png"), new Vec2d(1.875, 1.875));
public static final ModelGui UI_BUTTON_DELETE_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_delete_hover.png"), new Vec2d(1.875, 1.875));
public static final ModelGui UI_BUTTON_PLAY = new ModelGui(Resources.ATLAS.get("/gui/button_play.png"), new Vec2d(1.875, 1.875));
public static final ModelGui UI_BUTTON_PLAY_HOVER = new ModelGui(Resources.ATLAS.get("/gui/button_play_hover.png"), new Vec2d(1.875, 1.875));
public static final ModelGui UI_LABEL = new ModelGui(Resources.ATLAS.get("/gui/label.png"), new Vec2d(24, 3));
public static final ModelGui UI_LABEL_RECIPE = new ModelGui(Resources.ATLAS.get("/gui/label_recipe.png"), new Vec2d(12, 3));
public static final ModelGui UI_TEXT_BOX = new ModelGui(Resources.ATLAS.get("/gui/text_box.png"), new Vec2d(12, 1.5));
public static final ModelGui UI_TEXT_CURSOR = new ModelGui(Resources.ATLAS.get("/gui/text_cursor.png"), 2, 50);
public static final ModelGui UI_SELECTION_BOX_WIDE = new ModelGui(Resources.ATLAS.get("/gui/selection_box_wide.png"), new Vec2d(24, 12));
public static final ModelGui UI_SELECTION_BOX_CRAFTING = new ModelGui(Resources.ATLAS.get("/gui/selection_box_crafting.png"), new Vec2d(12, 12));
public static final ModelGui UI_SELECTION_BOX_STORAGE = new ModelGui(Resources.ATLAS.get("/gui/selection_box_storage.png"), new Vec2d(12, 12));
public static final ModelGui UI_ITEM_SLOT_STORAGE = new ModelGui(Resources.ATLAS.get("/gui/item_slot_storage.png"), new Vec2d(1.5, 1.5));
public static final ModelGui UI_HEALTH_FG = new ModelGui(Resources.ATLAS.get("/gui/health_full.png"), new Vec2d(6, 0.375));
public static final ModelGui UI_HEALTH_BG = new ModelGui(Resources.ATLAS.get("/gui/health_empty.png"), new Vec2d(6, 0.375));
public static final ModelGui UI_ITEM_SLOTS = new ModelGui(Resources.ATLAS.get("/gui/hotbar.png"), new Vec2d(15, 1.5));
public static final ModelGui UI_ACTIVE_SLOT = new ModelGui(Resources.ATLAS.get("/gui/hotbar_selected.png"), new Vec2d(1.5, 1.5));
public static final ModelGui UI_INVENTORY = new ModelGui(Resources.ATLAS.get("/gui/inventory.png"), new Vec2d(12, 12));
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 ModelGui UI_ITEM_HOVER = new ModelGui(Resources.ATLAS.get("/gui/pixel_black.png")).setOpacity(0.25);
public static final ModelGui UI_TEXT_BG = new ModelGui(Resources.ATLAS.get("/gui/pixel_white.png")).setColor(0.5f, 0.5f, 0.5f);
public static final ModelGui UI_STONE_BG = new ModelGui(Resources.ATLAS.get("/tile/stone.png"));
public static final ModelItem UI_SLOT_ARMOR_HELMET = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_helmet.png"));
public static final ModelItem UI_SLOT_ARMOR_CHEST = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_chest.png"));
public static final ModelItem UI_SLOT_ARMOR_LEGS = new ModelItem(Resources.ATLAS.get("/gui/slot_armor_legs.png"));
public static final ModelItem UI_SLOT_CLOTHING_SHIRT = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_shirt.png"));
public static final ModelItem UI_SLOT_CLOTHING_PANTS = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_pants.png"));
public static final ModelItem UI_SLOT_CLOTHING_BOOTS = new ModelItem(Resources.ATLAS.get("/gui/slot_clothing_boots.png"));
public static final ModelItem ITEM_EMPTY = ModelItem.createEmpty();
public static final ModelItem ITEM_MISSING = new ModelItem(Resources.TEX_EMPTY);
public static final ModelItem ITEM_CAMPFIRE = new ModelItem(Resources.ATLAS.get("/tile/campfire_unlit.png"));
public static final ModelItem ITEM_BLAST_FURNACE = new ModelItem(Resources.ATLAS.get("/item/blast_furnace.png"));
public static final ModelItem ITEM_WORKBENCH = new ModelItem(Resources.ATLAS.get("/item/workbench.png"));
public static final ModelItem ITEM_GRAPPLING_HOOK = new ModelItem(Resources.ATLAS.get("/item/grappling_hook.png"));
public static final ModelItem ITEM_HEALTH_POTION = new ModelItem(Resources.ATLAS.get("/item/health_potion.png"));
public static final ModelItem ITEM_AMMO_BOX = new ModelItem(Resources.ATLAS.get("/item/ammo_box.png"));
public static final ModelItem ITEM_TNT = new ModelItem(Resources.ATLAS.get("/entity/tnt.png"));
public static final ModelItem ITEM_FLARE = new ModelItem(Resources.ATLAS.get("/entity/flare.png"));
public static final ModelItem ITEM_LANTERN = new ModelItem(Resources.ATLAS.get("/tile/lantern.png"), 4, 5);
public static final ModelItem ITEM_TORCH_LIT = new ModelItem(Resources.ATLAS.get("/item/torch_lit.png"), 4, 50);
public static final ModelItem ITEM_TORCH_UNLIT = new ModelItem(Resources.ATLAS.get("/item/torch_unlit.png"));
public static final ModelItem ITEM_CLAY_POT_WET = new ModelItem(Resources.ATLAS.get("/item/clay_pot_wet.png"));
public static final ModelItem ITEM_CLAY_POT_EMPTY = new ModelItem(Resources.ATLAS.get("/item/clay_pot_empty.png"));
public static final ModelItem ITEM_CLAY_POT_WATER_1 = new ModelItem(Resources.ATLAS.get("/item/clay_pot_water1.png"));
public static final ModelItem ITEM_CLAY_POT_WATER_2 = new ModelItem(Resources.ATLAS.get("/item/clay_pot_water2.png"));
public static final ModelItem ITEM_CLAY_POT_WATER_3 = new ModelItem(Resources.ATLAS.get("/item/clay_pot_water3.png"));
public static final ModelItem ITEM_FLINT_HATCHET = new ModelItem(Resources.ATLAS.get("/item/flint_hatchet.png"));
public static final ModelItem ITEM_STONE_HATCHET = new ModelItem(Resources.ATLAS.get("/item/stone_hatchet.png"));
public static final ModelItem ITEM_STONE_PICK = new ModelItem(Resources.ATLAS.get("/item/stone_pick.png"));
public static final ModelItem ITEM_STONE_SHOVEL = new ModelItem(Resources.ATLAS.get("/item/stone_shovel.png"));
public static final ModelItem ITEM_ORE_IRON = new ModelItem(Resources.ATLAS.get("/item/ore_iron.png"));
public static final ModelItem ITEM_ORE_COPPER = new ModelItem(Resources.ATLAS.get("/item/ore_copper.png"));
public static final ModelItem ITEM_ORE_TIN = new ModelItem(Resources.ATLAS.get("/item/ore_tin.png"));
public static final ModelItem ITEM_ORE_GOLD = new ModelItem(Resources.ATLAS.get("/item/ore_gold.png"));
public static final ModelItem ITEM_SPAWN_ZOMBIE = new ModelItem(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10);
public static final ModelItem ITEM_SPAWN_DUMMY = new ModelItem(Resources.ATLAS.get("/entity/dummy.png"));
public static final ModelItem ITEM_ROCK = new ModelItem(Resources.ATLAS.get("/item/rock.png"));
public static final ModelItem ITEM_SNOW_PILE = new ModelItem(Resources.ATLAS.get("/item/snow_pile.png"));
public static final ModelItem ITEM_SANDSTONE = new ModelItem(Resources.ATLAS.get("/item/sandstone.png"));
public static final ModelItem ITEM_FLINT = new ModelItem(Resources.ATLAS.get("/item/flint.png"));
public static final ModelItem ITEM_CLAY = new ModelItem(Resources.ATLAS.get("/item/clay.png"));
public static final ModelItem ITEM_IRON = new ModelItem(Resources.ATLAS.get("/item/iron.png"));
public static final ModelItem ITEM_COPPER = new ModelItem(Resources.ATLAS.get("/item/copper.png"));
public static final ModelItem ITEM_TIN = new ModelItem(Resources.ATLAS.get("/item/tin.png"));
public static final ModelItem ITEM_GOLD = new ModelItem(Resources.ATLAS.get("/item/gold.png"));
public static final ModelItem ITEM_SLAG = new ModelItem(Resources.ATLAS.get("/item/slag.png"));
public static final ModelItem ITEM_COAL = new ModelItem(Resources.ATLAS.get("/item/coal.png"));
public static final ModelItem ITEM_PLANT_FIBRE = new ModelItem(Resources.ATLAS.get("/item/plant_fibre.png"));
public static final ModelItem ITEM_HEMP_SEED = new ModelItem(Resources.ATLAS.get("/item/hemp_seed.png"));
public static final ModelItem ITEM_ACORN = new ModelItem(Resources.ATLAS.get("/item/acorn.png"));
public static final ModelItem ITEM_LOG = new ModelItem(Resources.ATLAS.get("/item/log.png"));
public static final ModelItem ITEM_LOG_SNOW = new ModelItem(Resources.ATLAS.get("/item/log_snow.png"));
public static final ModelItem ITEM_CHARCOAL = new ModelItem(Resources.ATLAS.get("/item/charcoal.png"));
public static final ModelItem ITEM_ASH = new ModelItem(Resources.ATLAS.get("/item/ash.png"));
public static final ModelItem ITEM_WOOD_WALL = new ModelItem(Resources.ATLAS.get("/item/wood_wall.png"));
public static final ModelItem ITEM_WOOD_SNOW_WALL = new ModelItem(Resources.ATLAS.get("/item/wood_snow_wall.png"));
public static final ModelItem ITEM_WOOD_PLANKS = new ModelItem(Resources.ATLAS.get("/item/wood_planks.png"));
public static final ModelItem ITEM_WOOD_SNOW_PLANKS = new ModelItem(Resources.ATLAS.get("/item/wood_snow_planks.png"));
// Player varients
public static final ModelPlayer ENTITY_PLAYER_W = new ModelPlayer(
Resources.ATLAS.get("/player/player_white_back_still.png"),
Resources.ATLAS.get("/player/player_white_back_moving.png"),
Resources.ATLAS.get("/player/player_white_front_still.png"),
Resources.ATLAS.get("/player/player_white_front_moving.png"));
public static final ModelPlayer ENTITY_PLAYER_B = new ModelPlayer(
Resources.ATLAS.get("/player/player_black_back_still.png"),
Resources.ATLAS.get("/player/player_black_back_moving.png"),
Resources.ATLAS.get("/player/player_black_front_still.png"),
Resources.ATLAS.get("/player/player_black_front_moving.png"));
public static final Model ENTITY_ZOMBIE_B = new ModelVertical(Resources.ATLAS.get("/entity/zombie_back_moving.png"), 4, 10);
public static final Model ENTITY_ZOMBIE_F = new ModelVertical(Resources.ATLAS.get("/entity/zombie_front_moving.png"), 4, 10);
public static final Model ENTITY_ZOMBIE_B_ARMORED = new ModelVertical(Resources.ATLAS.get("/entity/armored_zombie_back_moving.png"), 4, 10);
public static final Model ENTITY_ZOMBIE_F_ARMORED = new ModelVertical(Resources.ATLAS.get("/entity/armored_zombie_front_moving.png"), 4, 10);
public static final ModelChunkBorder CHUNK_BORDER = new ModelChunkBorder();
}

View File

@ -0,0 +1,138 @@
package projectzombie.init;
import java.util.ArrayList;
import projectzombie.inventory.Crafting;
import projectzombie.inventory.recipe.Recipe;
import projectzombie.inventory.recipe.RecipeBasic;
import projectzombie.items.modifier.ItemModifierDamage;
import projectzombie.items.modifier.ItemModifierMeta;
import projectzombie.util.ItemStack;
public class Recipes
{
public static ArrayList<Recipe> recipies;
public static Recipe[] getCraftableRecipies(Crafting tool)
{
int size = 0;
for(Recipe recipe : recipies) {
size += recipe.canCraft(tool) ? 1 : 0;
}
int upto = 0;
Recipe[] craftable_recipies = new Recipe[size];
for(Recipe recipe : recipies)
{
if(recipe.canCraft(tool)) {
craftable_recipies[upto] = recipe;
upto += 1;
}
}
return craftable_recipies;
}
public static void init()
{
recipies = new ArrayList<Recipe>();
// Basic crafting items
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 1),
}, new Crafting[] {
Crafting.BASIC,
}, new ItemStack(Items.WOOD_PLANKS, 2)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 2),
}, new Crafting[] {
Crafting.BASIC,
}, new ItemStack(Items.WOOD_WALL, 1)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.FLINT, 2),
new ItemStack(Items.PLANT_FIBRE, 5),
}, new Crafting[] {
Crafting.BASIC,
}, new ItemStack(Items.FLINT_HATCHET, 1)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 12),
new ItemStack(Items.ROCK, 8, new ItemModifierMeta(0)),
}, new Crafting[] {
Crafting.BASIC,
}, new ItemStack(Items.CAMPFIRE, 1)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 16),
new ItemStack(Items.ROCK, 4, new ItemModifierMeta(0)),
new ItemStack(Items.PLANT_FIBRE, 8),
}, new Crafting[] {
Crafting.BASIC,
}, new ItemStack(Items.WORKBENCH, 1)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 1),
new ItemStack(Items.COAL, 1),
new ItemStack(Items.PLANT_FIBRE, 2),
}, new Crafting[] {
Crafting.BASIC,
}, new ItemStack(Items.TORCH, 1)));
// Workbench items
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 4),
new ItemStack(Items.ROCK, 3, new ItemModifierMeta(0)),
new ItemStack(Items.PLANT_FIBRE, 3),
}, new Crafting[] {
Crafting.WOODEN_WORKBENCH,
}, new ItemStack(Items.STONE_PICK, 1)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 4),
new ItemStack(Items.ROCK, 2, new ItemModifierMeta(0)),
new ItemStack(Items.PLANT_FIBRE, 3),
}, new Crafting[] {
Crafting.WOODEN_WORKBENCH,
}, new ItemStack(Items.STONE_SHOVEL, 1)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.LOG, 4),
new ItemStack(Items.ROCK, 3, new ItemModifierMeta(0)),
new ItemStack(Items.PLANT_FIBRE, 3),
}, new Crafting[] {
Crafting.WOODEN_WORKBENCH,
}, new ItemStack(Items.STONE_HATCHET, 1)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.ROCK, 8, new ItemModifierMeta(3)),
}, new Crafting[] {
Crafting.WOODEN_WORKBENCH,
}, new ItemStack(Items.CLAY_POT_WET, 1)));
recipies.add(new RecipeBasic(
new ItemStack[] {
new ItemStack(Items.ROCK, 32, new ItemModifierMeta(3)),
}, new Crafting[] {
Crafting.WOODEN_WORKBENCH,
}, new ItemStack(Items.BLAST_FURNACE, 1)));
}
}

View File

@ -0,0 +1,65 @@
package projectzombie.init;
import gl_engine.texture.TextureAtlas3D;
import gl_engine.texture.TextureRef3D;
import projectzombie.resources.Resource;
public class Resources
{
public static void loadResources()
{
ATLAS = TextureAtlas3D.loadAll("/resources/texture/list.txt");
ATLAS.generate();
TEX_EMPTY = ATLAS.get("");
GUN_OGG_0.load();
GUN_OGG_1.load();
GUN_OGG_2.load();
GUN_OGG_3.load();
GUN_OGG_4.load();
GUN_OGG_5.load();
GUN_OGG_6.load();
GUN_OGG_7.load();
GUN_OGG_8.load();
GUN_OGG_9.load();
HIT_OGG_0.load();
HIT_OGG_1.load();
HIT_OGG_2.load();
WALK_STONE_0.load();
WALK_STONE_1.load();
WALK_STONE_2.load();
WALK_STONE_3.load();
EXPLOSION_OGG.load();
FUSE_OGG.load();
}
public static TextureAtlas3D ATLAS;
public static TextureRef3D TEX_EMPTY;
public static final Resource GUN_OGG_0 = new Resource("/sound/gun0.ogg");
public static final Resource GUN_OGG_1 = new Resource("/sound/gun1.ogg");
public static final Resource GUN_OGG_2 = new Resource("/sound/gun2.ogg");
public static final Resource GUN_OGG_3 = new Resource("/sound/gun3.ogg");
public static final Resource GUN_OGG_4 = new Resource("/sound/gun4.ogg");
public static final Resource GUN_OGG_5 = new Resource("/sound/gun5.ogg");
public static final Resource GUN_OGG_6 = new Resource("/sound/gun6.ogg");
public static final Resource GUN_OGG_7 = new Resource("/sound/gun7.ogg");
public static final Resource GUN_OGG_8 = new Resource("/sound/gun8.ogg");
public static final Resource GUN_OGG_9 = new Resource("/sound/gun9.ogg");
public static final Resource HIT_OGG_0 = new Resource("/sound/hit0.ogg");
public static final Resource HIT_OGG_1 = new Resource("/sound/hit1.ogg");
public static final Resource HIT_OGG_2 = new Resource("/sound/hit2.ogg");
public static final Resource WALK_STONE_0 = new Resource("/sound/walk_stone_0.ogg");
public static final Resource WALK_STONE_1 = new Resource("/sound/walk_stone_1.ogg");
public static final Resource WALK_STONE_2 = new Resource("/sound/walk_stone_2.ogg");
public static final Resource WALK_STONE_3 = new Resource("/sound/walk_stone_3.ogg");
public static final Resource EXPLOSION_OGG = new Resource("/sound/explosion.ogg");
public static final Resource FUSE_OGG = new Resource("/sound/fuse.ogg");
}

View File

@ -1,7 +1,7 @@
package shootergame.init;
package projectzombie.init;
import shootergame.audio.AudioObject;
import shootergame.audio.AudioRandom;
import projectzombie.audio.AudioObject;
import projectzombie.audio.AudioRandom;
public class Sounds
{
@ -25,27 +25,27 @@ public class Sounds
EXPLOSION.init();
}
public static final AudioObject GUN_0 = new AudioObject(Resources.GUN_OGG_0);
public static final AudioObject GUN_1 = new AudioObject(Resources.GUN_OGG_1);
public static final AudioObject GUN_2 = new AudioObject(Resources.GUN_OGG_2);
public static final AudioObject GUN_3 = new AudioObject(Resources.GUN_OGG_3);
public static final AudioObject GUN_4 = new AudioObject(Resources.GUN_OGG_4);
public static final AudioObject GUN_5 = new AudioObject(Resources.GUN_OGG_5);
public static final AudioObject GUN_6 = new AudioObject(Resources.GUN_OGG_6);
public static final AudioObject GUN_7 = new AudioObject(Resources.GUN_OGG_7);
public static final AudioObject GUN_8 = new AudioObject(Resources.GUN_OGG_8);
public static final AudioObject GUN_9 = new AudioObject(Resources.GUN_OGG_9);
public static final AudioObject GUN_0 = new AudioObject(Resources.GUN_OGG_0, 1);
public static final AudioObject GUN_1 = new AudioObject(Resources.GUN_OGG_1, 1);
public static final AudioObject GUN_2 = new AudioObject(Resources.GUN_OGG_2, 1);
public static final AudioObject GUN_3 = new AudioObject(Resources.GUN_OGG_3, 1);
public static final AudioObject GUN_4 = new AudioObject(Resources.GUN_OGG_4, 1);
public static final AudioObject GUN_5 = new AudioObject(Resources.GUN_OGG_5, 1);
public static final AudioObject GUN_6 = new AudioObject(Resources.GUN_OGG_6, 1);
public static final AudioObject GUN_7 = new AudioObject(Resources.GUN_OGG_7, 1);
public static final AudioObject GUN_8 = new AudioObject(Resources.GUN_OGG_8, 1);
public static final AudioObject GUN_9 = new AudioObject(Resources.GUN_OGG_9, 1);
public static final AudioObject GUN = new AudioRandom(
GUN_0,GUN_1,GUN_2,GUN_3,GUN_4,
GUN_5,GUN_6,GUN_7,GUN_8,GUN_9);
public static final AudioObject HIT_0 = new AudioObject(Resources.HIT_OGG_0);
public static final AudioObject HIT_1 = new AudioObject(Resources.HIT_OGG_1);
public static final AudioObject HIT_2 = new AudioObject(Resources.HIT_OGG_2);
public static final AudioObject HIT_0 = new AudioObject(Resources.HIT_OGG_0, 1);
public static final AudioObject HIT_1 = new AudioObject(Resources.HIT_OGG_1, 1);
public static final AudioObject HIT_2 = new AudioObject(Resources.HIT_OGG_2, 1);
public static final AudioObject HIT = new AudioRandom(
HIT_0, HIT_1, HIT_2);
public static final AudioObject EXPLOSION = new AudioObject(Resources.EXPLOSION_OGG);
public static final AudioObject EXPLOSION = new AudioObject(Resources.EXPLOSION_OGG, 10);
}

View File

@ -0,0 +1,34 @@
package projectzombie.init;
import java.util.ArrayList;
import bdf.types.BdfObject;
import projectzombie.entity.Entity;
import projectzombie.task.Task;
import projectzombie.task.TaskDeathScreen;
import projectzombie.task.TaskLadderDown;
import projectzombie.task.TaskLadderUp;
public class Tasks
{
public static final ArrayList<Class<? extends Task>> TASKS = new ArrayList<>();
private static void register(Class<? extends Task> t)
{
try {
t.getConstructor(Entity.class, BdfObject.class);
} catch (NoSuchMethodException | SecurityException err) {
err.printStackTrace();
System.exit(1);
}
TASKS.add(t);
}
public static void init()
{
register(TaskLadderDown.class);
register(TaskLadderUp.class);
register(TaskDeathScreen.class);
}
}

133
src/projectzombie/init/Tiles.java Executable file
View File

@ -0,0 +1,133 @@
package projectzombie.init;
import java.util.ArrayList;
import projectzombie.tiles.Tile;
import projectzombie.tiles.TileBlastFurnace;
import projectzombie.tiles.TileBossPortal;
import projectzombie.tiles.TileCactus;
import projectzombie.tiles.TileCampfire;
import projectzombie.tiles.TileChest;
import projectzombie.tiles.TileClayPot;
import projectzombie.tiles.TileCoal;
import projectzombie.tiles.TileDirt;
import projectzombie.tiles.TileGrass;
import projectzombie.tiles.TileGrassBurnt;
import projectzombie.tiles.TileGrassInfested;
import projectzombie.tiles.TileHemp;
import projectzombie.tiles.TileIce;
import projectzombie.tiles.TileIceWall;
import projectzombie.tiles.TileLadder;
import projectzombie.tiles.TileLadderUp;
import projectzombie.tiles.TileLantern;
import projectzombie.tiles.TileLava;
import projectzombie.tiles.TileLavaFlow;
import projectzombie.tiles.TileOre;
import projectzombie.tiles.TilePortalDown;
import projectzombie.tiles.TileRock;
import projectzombie.tiles.TileSand;
import projectzombie.tiles.TileSandstone;
import projectzombie.tiles.TileSandstoneWall;
import projectzombie.tiles.TileSapling;
import projectzombie.tiles.TileSnow;
import projectzombie.tiles.TileStone;
import projectzombie.tiles.TileTallGrass;
import projectzombie.tiles.TileTree;
import projectzombie.tiles.TileVoid;
import projectzombie.tiles.TileWall;
import projectzombie.tiles.TileWater;
import projectzombie.tiles.TileWoodFloor;
import projectzombie.tiles.TileWoodWall;
import projectzombie.tiles.TileWorkbench;
public class Tiles
{
public static ArrayList<Tile> tiles = new ArrayList<Tile>();
private static void register(Tile tile)
{
int id = tiles.size();
if(id > Short.MAX_VALUE) {
throw new RuntimeException("Too many tiles registered. Maximum tiles: " + Short.MAX_VALUE);
}
tile.id = (short)id;
tiles.add(tile);
}
public static void init() {
register(VOID);
register(GRASS);
register(SNOW);
register(SAND);
register(STONE);
register(DIRT);
register(TREE);
register(CACTUS);
register(ROCK);
register(LAVA);
register(WATER);
register(LAVA_FLOW);
register(LADDER);
register(PORTAL_DOWN);
register(WALL);
register(LADDER_UP);
register(CHEST);
register(LANTERN);
register(BOSS_PORTAL);
register(ICE);
register(ICE_WALL);
register(SANDSTONE);
register(SANDSTONE_WALL);
register(GRASS_INFESTED);
register(TALL_GRASS);
register(SAPLING);
register(CAMPFIRE);
register(GRASS_BURNT);
register(WORKBENCH);
register(BLAST_FURNACE);
register(CLAY_POT);
register(ORE);
register(COAL);
register(WOOD_FLOOR);
register(WOOD_WALL);
}
public static final Tile GRASS = new TileGrass();
public static final Tile SNOW = new TileSnow();
public static final Tile SAND = new TileSand();
public static final Tile STONE = new TileStone();
public static final Tile DIRT = new TileDirt();
public static final Tile CACTUS = new TileCactus();
public static final Tile TREE = new TileTree();
public static final Tile VOID = new TileVoid();
public static final Tile ROCK = new TileRock();
public static final Tile LAVA = new TileLava();
public static final Tile WATER = new TileWater();
public static final Tile LAVA_FLOW = new TileLavaFlow();
public static final Tile LADDER = new TileLadder();
public static final Tile PORTAL_DOWN = new TilePortalDown();
public static final Tile WALL = new TileWall();
public static final Tile LADDER_UP = new TileLadderUp();
public static final Tile CHEST = new TileChest();
public static final Tile LANTERN = new TileLantern();
public static final Tile BOSS_PORTAL = new TileBossPortal();
public static final Tile ICE = new TileIce();
public static final Tile ICE_WALL = new TileIceWall();
public static final Tile SANDSTONE = new TileSandstone();
public static final Tile SANDSTONE_WALL = new TileSandstoneWall();
public static final Tile GRASS_INFESTED = new TileGrassInfested();
public static final Tile TALL_GRASS = new TileTallGrass();
public static final Tile SAPLING = new TileSapling();
public static final Tile HEMP = new TileHemp();
public static final Tile CAMPFIRE = new TileCampfire();
public static final Tile GRASS_BURNT = new TileGrassBurnt();
public static final Tile WORKBENCH = new TileWorkbench();
public static final Tile BLAST_FURNACE = new TileBlastFurnace();
public static final Tile CLAY_POT = new TileClayPot();
public static final Tile ORE = new TileOre();
public static final Tile COAL = new TileCoal();
public static final Tile WOOD_FLOOR = new TileWoodFloor();
public static final Tile WOOD_WALL = new TileWoodWall();
}

View File

@ -1,4 +1,4 @@
package shootergame.input;
package projectzombie.input;
import org.lwjgl.glfw.GLFWCursorEnterCallbackI;

View File

@ -0,0 +1,41 @@
package projectzombie.input;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWCursorPosCallbackI;
import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.util.gl.GlHelpers;
public class CursorPosCallback implements GLFWCursorPosCallbackI
{
public static double mx, my;
public static Vec2d getCursorPos() {
return new Vec2d(mx, my);
}
@Override
public void invoke(long window, double x, double y)
{
Main.window.setMouseVisibility(!Main.menu.keepMouse);
InputMode.Controller = false;
int wx = Main.window.getWidth();
int wy = Main.window.getHeight();
mx = (x / Main.window.getWidth() * 20 - 10) * GlHelpers.getAspectRatio();
my = -y / Main.window.getHeight() * 20 + 10;
if(!Main.menu.keepMouse) {
return;
}
x = (x / wx - 0.5);
y = (y / wy - 0.5);
Main.menu.input.camera(true, x * 60);
GLFW.glfwSetCursorPos(window, wx / 2, wy / 2);
}
}

View File

@ -0,0 +1,24 @@
package projectzombie.input;
class GameInput
{
static boolean activateItem_last = false;
static boolean activateTile_last = false;
static boolean dropItem_last = false;
static boolean move_last = false;
static boolean hotbar_l = false;
static boolean hotbar_r = false;
static boolean startButton_last = false;
static boolean backButton_last = false;
static boolean activate_last = false;
static boolean moveLeft = false;
static boolean moveRight = false;
static boolean moveUp = false;
static boolean moveDown = false;
static boolean buttonL = false;
static boolean buttonR = false;
}

View File

@ -0,0 +1,5 @@
package projectzombie.input;
public class InputMode {
public static boolean Controller = false;
}

View File

@ -0,0 +1,279 @@
package projectzombie.input;
import static projectzombie.input.GameInput.activateItem_last;
import static projectzombie.input.GameInput.activate_last;
import static projectzombie.input.GameInput.backButton_last;
import static projectzombie.input.GameInput.dropItem_last;
import static projectzombie.input.GameInput.hotbar_l;
import static projectzombie.input.GameInput.hotbar_r;
import static projectzombie.input.GameInput.moveDown;
import static projectzombie.input.GameInput.moveUp;
import static projectzombie.input.GameInput.move_last;
import static projectzombie.input.GameInput.startButton_last;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWJoystickCallbackI;
import mainloop.task.IMainloopTask;
import projectzombie.Main;
import projectzombie.input.types.Input;
public class JoystickCallback implements GLFWJoystickCallbackI, IMainloopTask
{
public static final JoystickCallback JOYSTICK_CALLBACK = new JoystickCallback();
private ArrayList<Integer> connections = new ArrayList<Integer>();
@Override
public void invoke(int jid, int event)
{
// Gamepad connect
if(event == GLFW.GLFW_CONNECTED)
{
// Log the event and add the connection
System.out.println("Gamepad "+jid+" connected");
connections.add(jid);
}
// Gamepad disconnect
else if(event == GLFW.GLFW_DISCONNECTED)
{
// Log the event and remove the connection
System.out.println("Gamepad "+jid+" disconnected");
connections.remove((Object) jid);
}
}
public void init()
{
// Loop over all the gamepads
for(int i=0;i<=GLFW.GLFW_JOYSTICK_LAST;i++)
{
// Is this gamepad present; add the gamepad
if(GLFW.glfwJoystickPresent(i)) {
if(GLFW.glfwJoystickIsGamepad(i)) {
System.out.println("Gamepad "+i+" connected");
connections.add(i);
}
}
}
}
@Override
public boolean MainLoopDelay(long millis) {
return millis > Main.tickrate;
}
@Override
public boolean MainLoopRepeat() {
return true;
}
private float combineJoystickAxis(float a, float b)
{
if(b > 0.3 || b < -0.3) a += b;
return a;
}
@Override
public void MainLoopUpdate()
{
// Gamepad properties
float left_x = 0;
float left_y = 0;
float left_trigger = 0;
float right_x = 0;
float right_y = 0;
float right_trigger = 0;
boolean left_stick_button = false;
boolean right_stick_button = false;
boolean button_a = false;
boolean button_b = false;
boolean button_x = false;
boolean button_y = false;
boolean button_start = false;
boolean button_back = false;
boolean button_home = false;
boolean dpad_up = false;
boolean dpad_down = false;
boolean dpad_left = false;
boolean dpad_right = false;
boolean shoulder_left = false;
boolean shoulder_right = false;
int jid2 = 0;
try {
// Loop over all the connected gamepads
for(int jid : connections)
{
// Get all the axes
jid2 = jid;
FloatBuffer axes = GLFW.glfwGetJoystickAxes(jid);
// Store all the axes data
left_x = combineJoystickAxis(left_x, axes.get(0));
left_y = combineJoystickAxis(left_y, axes.get(1));
right_x = combineJoystickAxis(right_x, axes.get(3));
right_y = combineJoystickAxis(right_y, axes.get(4));
left_trigger = combineJoystickAxis(left_trigger, axes.get(2));
right_trigger = combineJoystickAxis(right_trigger, axes.get(5));
// Get all the buttons
ByteBuffer buttons = GLFW.glfwGetJoystickButtons(jid);
// Store all the button data
button_a = buttons.get(0) == 1 || button_a;
button_b = buttons.get(1) == 1 || button_b;
button_x = buttons.get(2) == 1 || button_x;
button_y = buttons.get(3) == 1 || button_y;
shoulder_left = buttons.get(4) == 1 || shoulder_left;
shoulder_right = buttons.get(5) == 1 || shoulder_right;
button_back = buttons.get(6) == 1 || button_back;
button_start = buttons.get(7) == 1 || button_start;
button_home = buttons.get(8) == 1 || button_home;
left_stick_button = buttons.get(9) == 1 || left_stick_button;
right_stick_button = buttons.get(10) == 1 || right_stick_button;
dpad_left = buttons.get(11) == 1 || dpad_left;
dpad_right = buttons.get(12) == 1 || dpad_right;
dpad_up = buttons.get(13) == 1 || dpad_up;
dpad_down = buttons.get(14) == 1 || dpad_down;
}
}
catch(Exception e) {
connections.remove((Object) jid2);
System.err.println("Removed controller "+jid2+" due to "+e.toString());
}
Input input = Main.menu.input;
// Is the left stick moved into a position (movement stick)
if((left_x > 0.3 || left_x < -0.3 || left_y > 0.3 || left_y < -0.3) && !moveUp && !moveDown)
{
// Get the the angle
double angle = Math.toDegrees(Math.atan2(left_y, left_x)) + 90;
input.move(true, angle);
move_last = true;
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
}
// Set the players moving to false
else if(move_last && !moveUp && !moveDown) {
move_last = false;
input.move(false, 0);
}
// Is the right x axis stick moved into a position (camera stick)
if(right_x > 0.3 || right_x < -0.3) {
input.camera(true, right_x);
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
}
// Gun trigger
if(right_trigger > 0.3) {
input.fire(true);
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
}
// Item trigger
if(left_trigger > 0.3) {
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
input.itemAction(true);
}
else {
activateItem_last = false;
}
if(shoulder_left) {
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
if(!hotbar_l) {
hotbar_l = true;
input.hotbarShift(true, -1);
}
}
else if(hotbar_l) {
hotbar_l = false;
}
if(shoulder_right) {
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
if(!hotbar_r) {
hotbar_r = true;
input.hotbarShift(true, 1);
}
}
else if(hotbar_r) {
hotbar_r = false;
}
// Activate button (A Button)
if(button_a) {
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
if(!activate_last) {
input.activate(true);
activate_last = true;
}
}
else if(activate_last) {
activate_last = false;
input.activate(false);
}
// Drop item
if(button_b) {
InputMode.Controller = true;
Main.window.setMouseVisibility(false);
if(!dropItem_last) {
input.itemDrop(true);
dropItem_last = true;
}
}
else if(dropItem_last) {
dropItem_last = false;
}
// Back button
if(button_b) {
if(!backButton_last) {
input.back(true);
backButton_last = true;
}
}
else if(backButton_last) {
backButton_last = false;
}
// Pause the game
if(button_start) {
Main.window.setMouseVisibility(false);
InputMode.Controller = true;
if(!startButton_last) {
startButton_last = true;
input.pause(true);
}
}
else if(startButton_last) {
startButton_last = false;
}
}
}

View File

@ -0,0 +1,240 @@
package projectzombie.input;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_0;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_1;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_2;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_3;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_4;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_5;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_6;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_7;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_8;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_9;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_A;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_D;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_E;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_ESCAPE;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_F11;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_LEFT_CONTROL;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_Q;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_RIGHT_CONTROL;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_S;
import static org.lwjgl.glfw.GLFW.GLFW_KEY_W;
import static org.lwjgl.glfw.GLFW.GLFW_RELEASE;
import static projectzombie.input.GameInput.backButton_last;
import static projectzombie.input.GameInput.buttonL;
import static projectzombie.input.GameInput.buttonR;
import static projectzombie.input.GameInput.moveDown;
import static projectzombie.input.GameInput.moveLeft;
import static projectzombie.input.GameInput.moveRight;
import static projectzombie.input.GameInput.moveUp;
import static projectzombie.input.GameInput.move_last;
import org.lwjgl.glfw.GLFWKeyCallbackI;
import gl_engine.vec.Vec2d;
import mainloop.task.IMainloopTask;
import projectzombie.Main;
import projectzombie.input.types.Input;
public class KeyCallback implements GLFWKeyCallbackI, IMainloopTask
{
private boolean itemDrop_last = false;
private boolean esc_last = false;
private boolean fullscreen_last = false;
private boolean buttonL_last = false;
private boolean buttonR_last = false;
private boolean inventory_last = false;
private boolean lctrl_pressed = false;
private boolean rctrl_pressed = false;
@Override
public void invoke(long window, int key, int scancode, int action, int mods)
{
Input input = Main.menu.input;
boolean pressed = ! ( action == GLFW_RELEASE );
InputMode.Controller = false;
if(key == GLFW_KEY_LEFT_CONTROL) {
lctrl_pressed = pressed;
}
if(key == GLFW_KEY_RIGHT_CONTROL) {
rctrl_pressed = pressed;
}
if(key == GLFW_KEY_W) {
moveUp = pressed;
}
if(key == GLFW_KEY_S) {
moveDown = pressed;
}
if(key == GLFW_KEY_A) {
moveLeft = pressed;
}
if(key == GLFW_KEY_D) {
moveRight = pressed;
}
if(pressed)
{
input.key(key);
if(lctrl_pressed || rctrl_pressed) {
input.keyCtrl(key);
}
if(key == GLFW_KEY_1) {
input.hotbarGoto(true, 0);
}
if(key == GLFW_KEY_2) {
input.hotbarGoto(true, 1);
}
if(key == GLFW_KEY_3) {
input.hotbarGoto(true, 2);
}
if(key == GLFW_KEY_4) {
input.hotbarGoto(true, 3);
}
if(key == GLFW_KEY_5) {
input.hotbarGoto(true, 4);
}
if(key == GLFW_KEY_6) {
input.hotbarGoto(true, 5);
}
if(key == GLFW_KEY_7) {
input.hotbarGoto(true, 6);
}
if(key == GLFW_KEY_8) {
input.hotbarGoto(true, 7);
}
if(key == GLFW_KEY_9) {
input.hotbarGoto(true, 8);
}
if(key == GLFW_KEY_0) {
input.hotbarGoto(true, 9);
}
}
if(key == GLFW_KEY_Q) {
if(pressed) {
if(!itemDrop_last) {
itemDrop_last = true;
input.itemDrop(true);
}
}
else if(itemDrop_last) {
itemDrop_last = false;
}
}
if(key == GLFW_KEY_E) {
if(pressed) {
if(!inventory_last) {
inventory_last = true;
}
}
else if(inventory_last) {
inventory_last = false;
input.openInventory();
}
}
if(key == GLFW_KEY_ESCAPE) {
if(pressed) {
if(!esc_last) {
esc_last = true;
input.pause(true);
}
}
else if(esc_last) {
esc_last = false;
}
if(pressed) {
if(!backButton_last) {
backButton_last = true;
input.back(true);
}
}
else if(backButton_last) {
backButton_last = false;
}
}
if(key == GLFW_KEY_F11) {
if(pressed) {
if(!fullscreen_last) {
fullscreen_last = true;
Main.window.toggleFullscreen();
}
} else if(fullscreen_last) {
fullscreen_last = false;
}
}
}
@Override
public boolean MainLoopDelay(long millis) {
return millis > Main.tickrate;
}
@Override
public boolean MainLoopRepeat() {
return true;
}
@Override
public void MainLoopUpdate()
{
Input input = Main.menu.input;
Vec2d move_point = new Vec2d(0, 0);
if(moveUp) {
move_point.x += 1;
}
if(moveDown) {
move_point.x -= 1;
}
if(moveLeft) {
move_point.y += 1;
}
if(moveRight) {
move_point.y -= 1;
}
if(move_point.x != 0 || move_point.y != 0) {
move_last = true;
double angle = Math.toDegrees(Math.atan2(move_point.y, move_point.x));
input.move(true, angle);
}
if(buttonL) {
buttonL_last = true;
input.fire(true);
}
else if(buttonL_last) {
buttonL_last = false;
input.fire(false);
}
if(buttonR) {
buttonR_last = true;
input.itemAction(true);
}
else if(buttonR_last) {
buttonR_last = false;
input.itemAction(false);
}
}
}

View File

@ -0,0 +1,16 @@
package projectzombie.input;
import org.lwjgl.glfw.GLFWCharCallbackI;
import projectzombie.Main;
public class KeyCharCallback implements GLFWCharCallbackI
{
@Override
public void invoke(long window, int character) {
InputMode.Controller = false;
Main.menu.input.type((char)(character));
}
}

View File

@ -0,0 +1,23 @@
package projectzombie.input;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWMouseButtonCallbackI;
public class MouseButtonCallback implements GLFWMouseButtonCallbackI
{
@Override
public void invoke(long window, int button, int action, int mods)
{
InputMode.Controller = false;
if(button == GLFW.GLFW_MOUSE_BUTTON_LEFT) {
GameInput.buttonL = action == 1;
}
if(button == GLFW.GLFW_MOUSE_BUTTON_RIGHT) {
GameInput.buttonR = action == 1;
}
}
}

View File

@ -0,0 +1,22 @@
package projectzombie.input;
import org.lwjgl.glfw.GLFWScrollCallbackI;
import projectzombie.Main;
public class ScrollWheelCallback implements GLFWScrollCallbackI
{
@Override
public void invoke(long window, double x, double y)
{
InputMode.Controller = false;
if(y > 0) {
Main.menu.input.hotbarShift(true, 1);
} if(y < 0) {
Main.menu.input.hotbarShift(true, -1);
}
}
}

View File

@ -0,0 +1,21 @@
package projectzombie.input.types;
import gl_engine.vec.Vec2d;
public interface Input
{
public void type(char character);
public void move(boolean state, double angle);
public void fire(boolean state);
public void camera(boolean state, double amount);
public void itemAction(boolean state);
public void itemDrop(boolean state);
public void pause(boolean state);
public void hotbarGoto(boolean state, int pos);
public void hotbarShift(boolean state, int amount);
public void back(boolean state);
public void activate(boolean state);
public void openInventory();
public void key(int key);
public void keyCtrl(int key);
}

View File

@ -0,0 +1,97 @@
package projectzombie.input.types;
import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.menu.gui.GUI;
import projectzombie.util.gl.GlHelpers;
public class InputGUI implements Input
{
private GUI gui;
private boolean gunStateLast = false;
private boolean actionStateLast = false;
public InputGUI(GUI gui) {
this.gui = gui;
}
public GUI getGUI() {
return gui;
}
@Override
public void move(boolean state, double angle) {
this.gui.onMove(state, angle);
}
@Override
public void fire(boolean state) {
if(state) {
gunStateLast = true;
}
else if(gunStateLast) {
gunStateLast = false;
gui.onMouseClick();
}
}
@Override
public void camera(boolean state, double amount) {}
@Override
public void itemAction(boolean state) {
if(state) {
actionStateLast = true;
}
else if(actionStateLast) {
actionStateLast = false;
gui.onRightClick();
}
}
@Override
public void itemDrop(boolean state) {}
@Override
public void pause(boolean state) {}
@Override
public void hotbarGoto(boolean state, int pos) {}
@Override
public void hotbarShift(boolean state, int amount) {
gui.onScroll(amount);
}
@Override
public void back(boolean state) {
gui.onBack();
}
@Override
public void activate(boolean state) {
gui.onActivate();
}
@Override
public void openInventory() {
}
@Override
public void type(char character) {
gui.type(character);
}
@Override
public void key(int key) {
gui.keyPress(key);
}
@Override
public void keyCtrl(int key) {
gui.keyPressCtrl(key);
}
}

View File

@ -0,0 +1,12 @@
package projectzombie.input.types;
public interface InputGUITextBox {
public void onBackspace();
public void onDelete();
public void onPressed(char character);
public void onMoveCursor(int direction);
public void setFocus(boolean focus);
public void onPaste();
public void onHome();
public void onEnd();
}

View File

@ -0,0 +1,100 @@
package projectzombie.input.types;
import gl_engine.MathHelpers;
import gl_engine.vec.Vec2d;
import projectzombie.Main;
import projectzombie.inventory.Crafting;
import projectzombie.inventory.Inventory;
import projectzombie.menu.MenuGamePause;
import projectzombie.menu.MenuInventory;
import projectzombie.menu.MenuInventoryBasic;
import projectzombie.menu.MenuInventoryStorage;
import projectzombie.menu.gui.GUIItemSlotGetter;
import projectzombie.util.ItemStack;
import projectzombie.world.chunk.ChunkEventHandler;
public class InputGame implements Input
{
@Override
public void move(boolean state, double angle)
{
if(state)
{
// Move the player in the left sticks angle
if(ChunkEventHandler.loaded) {
Main.player.moveTowards(angle + Main.player.angle);
}
// Set the players moving to true
Main.player.moving = true;
}
else {
Main.player.moving = false;
}
}
@Override
public void fire(boolean state) {
Main.player.leftClick();
}
@Override
public void camera(boolean state, double amount) {
Main.player.angle -= amount;
}
@Override
public void itemAction(boolean state) {
Main.player.rightClick();
}
@Override
public void itemDrop(boolean state) {
Main.player.dropItem();
}
@Override
public void pause(boolean state) {
Main.menu = new MenuGamePause();
Main.game_paused = true;
}
@Override
public void hotbarGoto(boolean state, int pos) {
Main.player.inventory_hand = pos;
}
@Override
public void hotbarShift(boolean state, int amount) {
Main.player.inventory_hand += amount;
Main.player.inventory_hand = MathHelpers.mod(Main.player.inventory_hand, 10);
}
@Override
public void back(boolean state) {
}
@Override
public void activate(boolean state) {
}
@Override
public void openInventory() {
Main.menu = new MenuInventoryBasic(Main.menu, Crafting.BASIC);
}
@Override
public void type(char character) {
}
@Override
public void key(int key) {
}
@Override
public void keyCtrl(int key) {
}
}

View File

@ -0,0 +1,5 @@
package projectzombie.inventory;
public enum Crafting {
BASIC, WOODEN_WORKBENCH
}

View File

@ -0,0 +1,15 @@
package projectzombie.inventory;
import projectzombie.util.ItemStack;
public interface IInventory
{
public int getSlotCount();
public ItemStack getItem(int slot);
public void addItem(ItemStack stack);
public void setItem(ItemStack stack, int slot);
public ItemStack removeItem(int slot);
public void removeItem(ItemStack stack);
}

View File

@ -0,0 +1,14 @@
package projectzombie.inventory;
import projectzombie.util.ItemStack;
public interface IInventoryArmor
{
public ItemStack getHelmet();
public ItemStack getChest();
public ItemStack getLeggings();
public void setHelmet(ItemStack stack);
public void setChest(ItemStack stack);
public void setLeggings(ItemStack stack);
}

View File

@ -0,0 +1,14 @@
package projectzombie.inventory;
import projectzombie.util.ItemStack;
public interface IInventoryClothing
{
public ItemStack getShirt();
public ItemStack getPants();
public ItemStack getBoots();
public void setShirt(ItemStack stack);
public void setPants(ItemStack stack);
public void setBoots(ItemStack stack);
}

View File

@ -0,0 +1,170 @@
package projectzombie.inventory;
import projectzombie.util.ClassBdf;
import projectzombie.util.ItemStack;
import bdf.types.BdfArray;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
import gl_engine.vec.Vec2d;
import gl_engine.vec.Vec3d;
import projectzombie.entity.EntityItem;
import projectzombie.items.Item;
import projectzombie.items.modifier.ItemModifier;
import projectzombie.world.chunk.Chunk;
import projectzombie.world.layer.Layer;
public class Inventory implements IInventory, ClassBdf
{
protected ItemStack[] items;
public Inventory(int size)
{
items = new ItemStack[size];
for(int i=0;i<size;i++) {
items[i] = ItemStack.getEmpty();
}
}
@Override
public ItemStack getItem(int slot) {
return items[slot];
}
@Override
public int getSlotCount() {
return items.length;
}
@Override
public void setItem(ItemStack stack, int slot) {
items[slot] = stack;
}
@Override
public ItemStack removeItem(int slot) {
ItemStack stack = items[slot];
items[slot] = ItemStack.getEmpty();
return stack;
}
public int getItemCount(ItemStack item)
{
int count = 0;
for(ItemStack check : items) {
if(check.stackAbstractEquals(item) && !check.isEmpty()) {
count += check.count;
}
}
return count;
}
public void addItem(ItemStack stack)
{
if(stack.isEmpty()) {
return;
}
for(ItemStack check : items)
{
if(stack.stackEquals(check) && !check.isEmpty())
{
if(check.count + stack.count > check.item.max) {
stack.count = (check.count + stack.count) - check.item.max;
check.count = check.item.max;
}
else {
check.count += stack.count;
stack.count = 0;
return;
}
}
}
for(ItemStack check : items)
{
if(check.isEmpty())
{
ItemModifier[] modifiers = new ItemModifier[stack.modifiers.length];
for(int i=0;i<modifiers.length;i++) {
modifiers[i] = stack.modifiers[i].copy();
}
check.item = stack.item;
check.count = stack.count;
check.modifiers = modifiers;
stack.count = 0;
return;
}
}
}
public void dropInventory(Layer layer, Chunk chunk, Vec3d pos, Vec3d velocity)
{
for(int i=0;i<items.length;i++)
{
if(!items[i].isEmpty())
{
chunk.spawnEntity(new EntityItem(pos, velocity, items[i]));
items[i] = ItemStack.getEmpty();
}
}
}
public void removeItem(ItemStack stack)
{
for(ItemStack check : items) {
if(check.stackAbstractEquals(stack) && !stack.isEmpty())
{
if(check.count < stack.count) {
stack.count -= check.count;
check.count = 0;
}
else {
check.count -= stack.count;
stack.count = 0;
return;
}
}
}
}
@Override
public void BdfClassLoad(BdfObject bdf)
{
BdfNamedList nl = bdf.getNamedList();
items = new ItemStack[nl.get("size").getInteger()];
BdfArray array = nl.get("items").getArray();
for(int i=0;i<items.length;i++) {
items[i] = new ItemStack(array.get(i));
}
}
@Override
public void BdfClassSave(BdfObject bdf)
{
BdfNamedList nl = bdf.getNamedList();
nl.set("size", bdf.newObject().setInteger(items.length));
BdfArray array = nl.get("items").getArray();
for(ItemStack stack : items) {
BdfObject stack_bdf = bdf.newObject();
stack.BdfClassSave(stack_bdf);
array.add(stack_bdf);
}
}
public Inventory(BdfObject bdf) {
BdfClassLoad(bdf);
}
}

View File

@ -0,0 +1,69 @@
package projectzombie.inventory;
import projectzombie.util.ClassBdf;
import projectzombie.util.ItemStack;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
public class InventoryArmor implements ClassBdf, IInventoryArmor
{
private ItemStack helmet, chest, leggings;
public InventoryArmor() {
helmet = ItemStack.getEmpty();
chest = ItemStack.getEmpty();
leggings = ItemStack.getEmpty();
}
public InventoryArmor(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public ItemStack getHelmet() {
return helmet;
}
@Override
public ItemStack getChest() {
return chest;
}
@Override
public ItemStack getLeggings() {
return leggings;
}
@Override
public void setHelmet(ItemStack stack) {
helmet = stack;
}
@Override
public void setChest(ItemStack stack) {
chest = stack;
}
@Override
public void setLeggings(ItemStack stack) {
leggings = stack;
}
@Override
public void BdfClassLoad(BdfObject bdf) {
BdfNamedList nl = bdf.getNamedList();
helmet = new ItemStack(nl.get("helmet"));
chest = new ItemStack(nl.get("chest"));
leggings = new ItemStack(nl.get("leggings"));
}
@Override
public void BdfClassSave(BdfObject bdf) {
BdfNamedList nl = bdf.newNamedList();
helmet.BdfClassSave(nl.get("helmet"));
chest.BdfClassSave(nl.get("chest"));
leggings.BdfClassSave(nl.get("leggings"));
bdf.setNamedList(nl);
}
}

View File

@ -0,0 +1,68 @@
package projectzombie.inventory;
import projectzombie.util.ClassBdf;
import projectzombie.util.ItemStack;
import bdf.types.BdfNamedList;
import bdf.types.BdfObject;
public class InventoryClothing implements ClassBdf, IInventoryClothing
{
private ItemStack shirt, pants, boots;
public InventoryClothing() {
shirt = ItemStack.getEmpty();
pants = ItemStack.getEmpty();
boots = ItemStack.getEmpty();
}
public InventoryClothing(BdfObject bdf) {
BdfClassLoad(bdf);
}
@Override
public ItemStack getShirt() {
return shirt;
}
@Override
public ItemStack getPants() {
return pants;
}
@Override
public ItemStack getBoots() {
return boots;
}
@Override
public void setShirt(ItemStack stack) {
shirt = stack;
}
@Override
public void setPants(ItemStack stack) {
pants = stack;
}
@Override
public void setBoots(ItemStack stack) {
boots = stack;
}
@Override
public void BdfClassLoad(BdfObject bdf) {
BdfNamedList nl = bdf.getNamedList();
shirt = new ItemStack(nl.get("shirt"));
pants = new ItemStack(nl.get("pants"));
boots = new ItemStack(nl.get("boots"));
}
@Override
public void BdfClassSave(BdfObject bdf) {
BdfNamedList nl = bdf.newNamedList();
shirt.BdfClassSave(nl.get("shirt"));
pants.BdfClassSave(nl.get("pants"));
boots.BdfClassSave(nl.get("boots"));
bdf.setNamedList(nl);
}
}

Some files were not shown because too many files have changed in this diff Show More