Latest Code Download
Added 2020-06-17 16:18:39 +0000 UTCHey everyone!
As I mentioned in the post above, here is the latest code for my city-builder game:
https://drive.google.com/file/d/16QSvK_t3g3unVkaq6xgsavQEa50VsCPW/view?usp=sharing
All the new stuff to do with pathfinding can be found in the thinmatrix.cityBuilderGame.roads.paths package and other new entity code is in thinmatrix.cityBuilderGame.entities.
Here's a quick video showing how to set it up in Eclipse:
https://www.dropbox.com/s/jxl92yn8p776fq0/How%20to%20set%20up%20engine.wmv?dl=0
although to run it you'll now need to run the thinmatrix.cityBuilderGame.main.MainApp class, as opposed to the test class shown in the video.
Thanks as always!
Karl
Comments
Awesome. I'm glad you like it. To be honest, there are not a lot of benefits on the changes to the MyFile class. It's more about simplifying the code since you don't have to care about passing the path when instantiating it. I was mostly trying to illustrate how you can use the clazz.getResourceAsStream(name) or clazz.getResource(name) methods to find files in the same package/folder that the class resides. To simplify it even more, you can even get rid of the MyFile abstraction and have those properties as File instances. Then, you can use your FileUtils implementation to open a BufferedReader for them. Anyways, don't get sidetracked by this. It's not that important. I'm just trying to give something back, since I'm learning a lot from going thru you code and seeing how you structure your game.
2020-07-20 15:48:33 +0000 UTCThanks, I've fixed that now :)
ThinMatrix
2020-07-20 08:21:59 +0000 UTCI've never actually used Maven before but a few people have suggested it now, so I'll look into it.
ThinMatrix
2020-07-20 08:21:51 +0000 UTCThanks this is very useful :) Could you tell me though, what are the benefits of those changes to the MyFile class?
ThinMatrix
2020-07-20 08:20:49 +0000 UTCYeah. I suggest the same too. Shouldn't be hard to make the conversion if you make some changes like I'm suggesting bellow.
2020-07-19 20:00:48 +0000 UTCHey Karl, Just trying to give back a little bit here. I noticed a few things on how you load files in the game and I have a couple suggestions there. 1. Change the MyFile implementation to load the glsl files using the classloader. ``` public class MyFile { private final Class clazz; private final String name; public MyFile(Class clazz, String name) { this.clazz = clazz; this.name = name; } public InputStream getInputStream() { return clazz.getResourceAsStream(name); } public URL getUrl(){ return clazz.getResource(name); } public BufferedReader getReader() throws Exception { try { InputStreamReader isr = new InputStreamReader(getInputStream()); return new BufferedReader(isr); } catch (Exception e) { System.err.println("Couldn't get reader for " + name); throw e; } } @Override public String toString() { return "MyFile [clazz=" + clazz + ", name=" + name + "]"; } } ``` 2. You should be able to do the same for loading resource files. Just declare your res folder as a source folder on eclipse. That will pull all those files inside your compiled classes folder. Then, you can load them from the classpath like the above. ``` public class EngineFiles { public static final File RES_FOLDER = new File(EngineFiles.class.getResource("/").getFile()); public static final File ERROR_FOLDER = new File("."); public static final File GUI_FOLDER = new File(EngineFiles.class.getResource("/GUIs").getFile()); public static final File ICON_FOLDER = new File(EngineFiles.class.getResource("/windowIcon").getFile()); public static final File DEFAULT_FONT_ATLAS = new File(EngineFiles.class.getResource("/fonts/default.png").getFile()); public static final File DEFAULT_FONT_META = new File(EngineFiles.class.getResource("/fonts/default.fnt").getFile()); public static final File LANG_FILE = new File(EngineFiles.class.getResource("/languageFile.csv").getFile()); } ```
2020-07-19 19:47:19 +0000 UTCHey Karl. I’ve been going thru your videos and source code and I could not be more impressed. It’s so cool to see a properly implemented game in Java. I’ve been a Java developer for quite some time, but never worked with games. That being said, I’ve been thinking on some contributions to the code and I wonder if you have any plans to open it for that. Thanks for sharing your work and the videos. Mario
2020-07-19 13:41:22 +0000 UTCAnd while I'm here, have you ever thought of building with maven?
2020-07-14 12:14:26 +0000 UTCAlso a null check before calling `tile.isEmpty()` in BuildingPlacer.update() would be good idea as `getPickedTile()` can return null.
2020-07-14 12:08:56 +0000 UTCYeah, Faced the same issue here. Found this reference: https://github.com/memononen/nanovg/issues/422
2020-07-14 08:19:49 +0000 UTCAh, thanks for letting me know about this!
ThinMatrix
2020-07-14 07:01:12 +0000 UTC