commit bb41a130ba8f45fdcc8a01a8ac39d59e8ce498b5 Author: Jose Date: Mon Oct 30 14:10:21 2017 -0400 Shift from Game-Design diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a457bbb --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +.gradle +/build/ +/run/ +/out/ +*.DS_STORE +*.iml +*.ipr +*.launch +*.iws +.idea/workspace.xml +screenshots +/.idea/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Cache of project +.gradletasknamecache + +# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898 +# gradle/wrapper/gradle-wrapper.properties +settings.properties +.idea/misc.xml diff --git a/CREDITS.md b/CREDITS.md new file mode 100644 index 0000000..3df8662 --- /dev/null +++ b/CREDITS.md @@ -0,0 +1,7 @@ +The sounds have been sourced from [OpenGameArt](https://opengameart.org/content/512-sound-effects-8-bit-style) + + +The textures have been sourced from [itch.io](https://0x72.itch.io/16x16-dungeon-tileset) + + +**100%** of the code that I did not write has been sourced with a comment *preceeding* the code \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f8b7e30 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# Game-Design diff --git a/assets/icon/icon16.png b/assets/icon/icon16.png new file mode 100644 index 0000000..0415a2e Binary files /dev/null and b/assets/icon/icon16.png differ diff --git a/assets/icon/icon32.png b/assets/icon/icon32.png new file mode 100644 index 0000000..774bd84 Binary files /dev/null and b/assets/icon/icon32.png differ diff --git a/assets/justabit.ttf b/assets/justabit.ttf new file mode 100644 index 0000000..783357b Binary files /dev/null and b/assets/justabit.ttf differ diff --git a/assets/sounds/damage/damage_hit1.wav b/assets/sounds/damage/damage_hit1.wav new file mode 100644 index 0000000..e8df0f0 Binary files /dev/null and b/assets/sounds/damage/damage_hit1.wav differ diff --git a/assets/sounds/damage/damage_hit10.wav b/assets/sounds/damage/damage_hit10.wav new file mode 100644 index 0000000..ce525b9 Binary files /dev/null and b/assets/sounds/damage/damage_hit10.wav differ diff --git a/assets/sounds/damage/damage_hit2.wav b/assets/sounds/damage/damage_hit2.wav new file mode 100644 index 0000000..7559fda Binary files /dev/null and b/assets/sounds/damage/damage_hit2.wav differ diff --git a/assets/sounds/damage/damage_hit3.wav b/assets/sounds/damage/damage_hit3.wav new file mode 100644 index 0000000..f528321 Binary files /dev/null and b/assets/sounds/damage/damage_hit3.wav differ diff --git a/assets/sounds/damage/damage_hit4.wav b/assets/sounds/damage/damage_hit4.wav new file mode 100644 index 0000000..0d7a020 Binary files /dev/null and b/assets/sounds/damage/damage_hit4.wav differ diff --git a/assets/sounds/damage/damage_hit5.wav b/assets/sounds/damage/damage_hit5.wav new file mode 100644 index 0000000..17aa07e Binary files /dev/null and b/assets/sounds/damage/damage_hit5.wav differ diff --git a/assets/sounds/damage/damage_hit6.wav b/assets/sounds/damage/damage_hit6.wav new file mode 100644 index 0000000..ec66ca3 Binary files /dev/null and b/assets/sounds/damage/damage_hit6.wav differ diff --git a/assets/sounds/damage/damage_hit7.wav b/assets/sounds/damage/damage_hit7.wav new file mode 100644 index 0000000..9ec9fd5 Binary files /dev/null and b/assets/sounds/damage/damage_hit7.wav differ diff --git a/assets/sounds/damage/damage_hit8.wav b/assets/sounds/damage/damage_hit8.wav new file mode 100644 index 0000000..d9bca44 Binary files /dev/null and b/assets/sounds/damage/damage_hit8.wav differ diff --git a/assets/sounds/damage/damage_hit9.wav b/assets/sounds/damage/damage_hit9.wav new file mode 100644 index 0000000..885a780 Binary files /dev/null and b/assets/sounds/damage/damage_hit9.wav differ diff --git a/assets/sounds/damage/player_hit1.wav b/assets/sounds/damage/player_hit1.wav new file mode 100644 index 0000000..54f5eb1 Binary files /dev/null and b/assets/sounds/damage/player_hit1.wav differ diff --git a/assets/sounds/damage/player_hit2.wav b/assets/sounds/damage/player_hit2.wav new file mode 100644 index 0000000..80c5e12 Binary files /dev/null and b/assets/sounds/damage/player_hit2.wav differ diff --git a/assets/sounds/death/bat_death.wav b/assets/sounds/death/bat_death.wav new file mode 100644 index 0000000..25cbca4 Binary files /dev/null and b/assets/sounds/death/bat_death.wav differ diff --git a/assets/sounds/death/dark_mage_death.wav b/assets/sounds/death/dark_mage_death.wav new file mode 100644 index 0000000..7786710 Binary files /dev/null and b/assets/sounds/death/dark_mage_death.wav differ diff --git a/assets/sounds/death/flame_death.wav b/assets/sounds/death/flame_death.wav new file mode 100644 index 0000000..efa2898 Binary files /dev/null and b/assets/sounds/death/flame_death.wav differ diff --git a/assets/sounds/death/gut_eater_death.wav b/assets/sounds/death/gut_eater_death.wav new file mode 100644 index 0000000..f593f55 Binary files /dev/null and b/assets/sounds/death/gut_eater_death.wav differ diff --git a/assets/sounds/death/ice_monster_death.wav b/assets/sounds/death/ice_monster_death.wav new file mode 100644 index 0000000..47e410a Binary files /dev/null and b/assets/sounds/death/ice_monster_death.wav differ diff --git a/assets/sounds/death/oozer_death.wav b/assets/sounds/death/oozer_death.wav new file mode 100644 index 0000000..d17f547 Binary files /dev/null and b/assets/sounds/death/oozer_death.wav differ diff --git a/assets/sounds/death/orc_death.wav b/assets/sounds/death/orc_death.wav new file mode 100644 index 0000000..bbe2cc9 Binary files /dev/null and b/assets/sounds/death/orc_death.wav differ diff --git a/assets/sounds/death/player_death.wav b/assets/sounds/death/player_death.wav new file mode 100644 index 0000000..23392da Binary files /dev/null and b/assets/sounds/death/player_death.wav differ diff --git a/assets/sounds/death/rock_monster_death.wav b/assets/sounds/death/rock_monster_death.wav new file mode 100644 index 0000000..08ba3f8 Binary files /dev/null and b/assets/sounds/death/rock_monster_death.wav differ diff --git a/assets/sounds/death/zombie_death.wav b/assets/sounds/death/zombie_death.wav new file mode 100644 index 0000000..2e255ba Binary files /dev/null and b/assets/sounds/death/zombie_death.wav differ diff --git a/assets/sounds/environment/level_up.wav b/assets/sounds/environment/level_up.wav new file mode 100644 index 0000000..12c114a Binary files /dev/null and b/assets/sounds/environment/level_up.wav differ diff --git a/assets/sounds/menu/menu sounds.zip b/assets/sounds/menu/menu sounds.zip new file mode 100644 index 0000000..8aac53d Binary files /dev/null and b/assets/sounds/menu/menu sounds.zip differ diff --git a/assets/sounds/menu/move.wav b/assets/sounds/menu/move.wav new file mode 100644 index 0000000..bc520a3 Binary files /dev/null and b/assets/sounds/menu/move.wav differ diff --git a/assets/sounds/menu/select.wav b/assets/sounds/menu/select.wav new file mode 100644 index 0000000..acc6ffa Binary files /dev/null and b/assets/sounds/menu/select.wav differ diff --git a/assets/sounds/player_jump.wav b/assets/sounds/player_jump.wav new file mode 100644 index 0000000..f7162b2 Binary files /dev/null and b/assets/sounds/player_jump.wav differ diff --git a/assets/sounds/sword_slash.wav b/assets/sounds/sword_slash.wav new file mode 100644 index 0000000..8048298 Binary files /dev/null and b/assets/sounds/sword_slash.wav differ diff --git a/assets/textures/entity/bat.png b/assets/textures/entity/bat.png new file mode 100644 index 0000000..a864b45 Binary files /dev/null and b/assets/textures/entity/bat.png differ diff --git a/assets/textures/entity/dark_mage.png b/assets/textures/entity/dark_mage.png new file mode 100644 index 0000000..9cd877b Binary files /dev/null and b/assets/textures/entity/dark_mage.png differ diff --git a/assets/textures/entity/flame.png b/assets/textures/entity/flame.png new file mode 100644 index 0000000..de90ab7 Binary files /dev/null and b/assets/textures/entity/flame.png differ diff --git a/assets/textures/entity/gut_eater.png b/assets/textures/entity/gut_eater.png new file mode 100644 index 0000000..44f5a41 Binary files /dev/null and b/assets/textures/entity/gut_eater.png differ diff --git a/assets/textures/entity/ice_monster.png b/assets/textures/entity/ice_monster.png new file mode 100644 index 0000000..db56968 Binary files /dev/null and b/assets/textures/entity/ice_monster.png differ diff --git a/assets/textures/entity/oozer.png b/assets/textures/entity/oozer.png new file mode 100644 index 0000000..6cb8b69 Binary files /dev/null and b/assets/textures/entity/oozer.png differ diff --git a/assets/textures/entity/orc.png b/assets/textures/entity/orc.png new file mode 100644 index 0000000..fd1ba7d Binary files /dev/null and b/assets/textures/entity/orc.png differ diff --git a/assets/textures/entity/player.png b/assets/textures/entity/player.png new file mode 100644 index 0000000..2d01aa8 Binary files /dev/null and b/assets/textures/entity/player.png differ diff --git a/assets/textures/entity/projectile/bullet.png b/assets/textures/entity/projectile/bullet.png new file mode 100644 index 0000000..64bf439 Binary files /dev/null and b/assets/textures/entity/projectile/bullet.png differ diff --git a/assets/textures/entity/projectile/potato.png b/assets/textures/entity/projectile/potato.png new file mode 100644 index 0000000..849489f Binary files /dev/null and b/assets/textures/entity/projectile/potato.png differ diff --git a/assets/textures/entity/rock_monster.png b/assets/textures/entity/rock_monster.png new file mode 100644 index 0000000..a706a09 Binary files /dev/null and b/assets/textures/entity/rock_monster.png differ diff --git a/assets/textures/entity/zombie.png b/assets/textures/entity/zombie.png new file mode 100644 index 0000000..51e4bc3 Binary files /dev/null and b/assets/textures/entity/zombie.png differ diff --git a/assets/textures/environment/exit.png b/assets/textures/environment/exit.png new file mode 100644 index 0000000..c023fea Binary files /dev/null and b/assets/textures/environment/exit.png differ diff --git a/assets/textures/environment/grass.png b/assets/textures/environment/grass.png new file mode 100644 index 0000000..e250a38 Binary files /dev/null and b/assets/textures/environment/grass.png differ diff --git a/assets/textures/environment/house.png b/assets/textures/environment/house.png new file mode 100644 index 0000000..57763b7 Binary files /dev/null and b/assets/textures/environment/house.png differ diff --git a/assets/textures/environment/menu.png b/assets/textures/environment/menu.png new file mode 100644 index 0000000..60126df Binary files /dev/null and b/assets/textures/environment/menu.png differ diff --git a/assets/textures/environment/sky.png b/assets/textures/environment/sky.png new file mode 100644 index 0000000..c3176bf Binary files /dev/null and b/assets/textures/environment/sky.png differ diff --git a/assets/textures/environment/wall.png b/assets/textures/environment/wall.png new file mode 100644 index 0000000..18435d2 Binary files /dev/null and b/assets/textures/environment/wall.png differ diff --git a/assets/textures/environment/wall_decor_1.png b/assets/textures/environment/wall_decor_1.png new file mode 100644 index 0000000..44f3cbb Binary files /dev/null and b/assets/textures/environment/wall_decor_1.png differ diff --git a/assets/textures/environment/wall_decor_2.png b/assets/textures/environment/wall_decor_2.png new file mode 100644 index 0000000..c0eadf0 Binary files /dev/null and b/assets/textures/environment/wall_decor_2.png differ diff --git a/assets/textures/environment/wall_decor_3.png b/assets/textures/environment/wall_decor_3.png new file mode 100644 index 0000000..37f5eb4 Binary files /dev/null and b/assets/textures/environment/wall_decor_3.png differ diff --git a/assets/textures/environment/wall_decor_4.png b/assets/textures/environment/wall_decor_4.png new file mode 100644 index 0000000..666944b Binary files /dev/null and b/assets/textures/environment/wall_decor_4.png differ diff --git a/assets/textures/environment/well.png b/assets/textures/environment/well.png new file mode 100644 index 0000000..e37ac0d Binary files /dev/null and b/assets/textures/environment/well.png differ diff --git a/assets/textures/err.png b/assets/textures/err.png new file mode 100644 index 0000000..b4f0679 Binary files /dev/null and b/assets/textures/err.png differ diff --git a/assets/textures/items/broad_sword.png b/assets/textures/items/broad_sword.png new file mode 100644 index 0000000..c4c3070 Binary files /dev/null and b/assets/textures/items/broad_sword.png differ diff --git a/assets/textures/items/dagger.png b/assets/textures/items/dagger.png new file mode 100644 index 0000000..108804a Binary files /dev/null and b/assets/textures/items/dagger.png differ diff --git a/assets/textures/items/fist.png b/assets/textures/items/fist.png new file mode 100644 index 0000000..2c0ee39 Binary files /dev/null and b/assets/textures/items/fist.png differ diff --git a/assets/textures/items/great_sword.png b/assets/textures/items/great_sword.png new file mode 100644 index 0000000..99a80a1 Binary files /dev/null and b/assets/textures/items/great_sword.png differ diff --git a/assets/textures/items/heart.png b/assets/textures/items/heart.png new file mode 100644 index 0000000..ce6d6af Binary files /dev/null and b/assets/textures/items/heart.png differ diff --git a/assets/textures/items/potato_gun.png b/assets/textures/items/potato_gun.png new file mode 100644 index 0000000..84a1d15 Binary files /dev/null and b/assets/textures/items/potato_gun.png differ diff --git a/assets/textures/items/refined_sword.png b/assets/textures/items/refined_sword.png new file mode 100644 index 0000000..d5ad07a Binary files /dev/null and b/assets/textures/items/refined_sword.png differ diff --git a/assets/textures/items/rusty_sword.png b/assets/textures/items/rusty_sword.png new file mode 100644 index 0000000..b8f7909 Binary files /dev/null and b/assets/textures/items/rusty_sword.png differ diff --git a/assets/textures/items/wooden_sword.png b/assets/textures/items/wooden_sword.png new file mode 100644 index 0000000..3871c6a Binary files /dev/null and b/assets/textures/items/wooden_sword.png differ diff --git a/assets/tileset.png b/assets/tileset.png new file mode 100644 index 0000000..4b519d9 Binary files /dev/null and b/assets/tileset.png differ diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..f7c0d86 --- /dev/null +++ b/build.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/libs/AppleJavaExtensions.jar b/libs/AppleJavaExtensions.jar new file mode 100644 index 0000000..160d62b Binary files /dev/null and b/libs/AppleJavaExtensions.jar differ diff --git a/libs/asm-debug-all.jar b/libs/asm-debug-all.jar new file mode 100644 index 0000000..d5aa15e Binary files /dev/null and b/libs/asm-debug-all.jar differ diff --git a/libs/ibxm.jar b/libs/ibxm.jar new file mode 100644 index 0000000..619d26e Binary files /dev/null and b/libs/ibxm.jar differ diff --git a/libs/jinput.jar b/libs/jinput.jar new file mode 100644 index 0000000..7c2b6b0 Binary files /dev/null and b/libs/jinput.jar differ diff --git a/libs/jogg-0.0.7.jar b/libs/jogg-0.0.7.jar new file mode 100644 index 0000000..ecb0260 Binary files /dev/null and b/libs/jogg-0.0.7.jar differ diff --git a/libs/jorbis-0.0.15.jar b/libs/jorbis-0.0.15.jar new file mode 100644 index 0000000..4cf51f9 Binary files /dev/null and b/libs/jorbis-0.0.15.jar differ diff --git a/libs/laf-plugin-7.2.1.jar b/libs/laf-plugin-7.2.1.jar new file mode 100644 index 0000000..82b0252 Binary files /dev/null and b/libs/laf-plugin-7.2.1.jar differ diff --git a/libs/laf-widget-7.2.1.jar b/libs/laf-widget-7.2.1.jar new file mode 100644 index 0000000..0371eb1 Binary files /dev/null and b/libs/laf-widget-7.2.1.jar differ diff --git a/libs/log4j-api-2.0-beta9.jar b/libs/log4j-api-2.0-beta9.jar new file mode 100644 index 0000000..051b6d2 Binary files /dev/null and b/libs/log4j-api-2.0-beta9.jar differ diff --git a/libs/lwjgl-debug.jar b/libs/lwjgl-debug.jar new file mode 100644 index 0000000..feb3d22 Binary files /dev/null and b/libs/lwjgl-debug.jar differ diff --git a/libs/lwjgl.jar b/libs/lwjgl.jar new file mode 100644 index 0000000..82294e1 Binary files /dev/null and b/libs/lwjgl.jar differ diff --git a/libs/lwjgl_test.jar b/libs/lwjgl_test.jar new file mode 100644 index 0000000..708bf1d Binary files /dev/null and b/libs/lwjgl_test.jar differ diff --git a/libs/lwjgl_util.jar b/libs/lwjgl_util.jar new file mode 100644 index 0000000..97911ab Binary files /dev/null and b/libs/lwjgl_util.jar differ diff --git a/libs/lwjgl_util_applet.jar b/libs/lwjgl_util_applet.jar new file mode 100644 index 0000000..f6ba4b7 Binary files /dev/null and b/libs/lwjgl_util_applet.jar differ diff --git a/libs/lzma.jar b/libs/lzma.jar new file mode 100644 index 0000000..d383dc0 Binary files /dev/null and b/libs/lzma.jar differ diff --git a/libs/natives-linux.jar b/libs/natives-linux.jar new file mode 100644 index 0000000..a543ee0 Binary files /dev/null and b/libs/natives-linux.jar differ diff --git a/libs/natives-mac.jar b/libs/natives-mac.jar new file mode 100644 index 0000000..220012b Binary files /dev/null and b/libs/natives-mac.jar differ diff --git a/libs/natives-windows.jar b/libs/natives-windows.jar new file mode 100644 index 0000000..2fb036f Binary files /dev/null and b/libs/natives-windows.jar differ diff --git a/libs/slick-util.jar b/libs/slick-util.jar new file mode 100644 index 0000000..10b552a Binary files /dev/null and b/libs/slick-util.jar differ diff --git a/libs/substance-7.2.1.jar b/libs/substance-7.2.1.jar new file mode 100644 index 0000000..20428dd Binary files /dev/null and b/libs/substance-7.2.1.jar differ diff --git a/libs/trident-7.2.1.jar b/libs/trident-7.2.1.jar new file mode 100644 index 0000000..54fb614 Binary files /dev/null and b/libs/trident-7.2.1.jar differ diff --git a/natives/OpenAL32.dll b/natives/OpenAL32.dll new file mode 100644 index 0000000..1f69e94 Binary files /dev/null and b/natives/OpenAL32.dll differ diff --git a/natives/OpenAL64.dll b/natives/OpenAL64.dll new file mode 100644 index 0000000..6f2a2fe Binary files /dev/null and b/natives/OpenAL64.dll differ diff --git a/natives/jinput-dx8.dll b/natives/jinput-dx8.dll new file mode 100644 index 0000000..6d27ad5 Binary files /dev/null and b/natives/jinput-dx8.dll differ diff --git a/natives/jinput-dx8_64.dll b/natives/jinput-dx8_64.dll new file mode 100644 index 0000000..6730589 Binary files /dev/null and b/natives/jinput-dx8_64.dll differ diff --git a/natives/jinput-raw.dll b/natives/jinput-raw.dll new file mode 100644 index 0000000..ce1d162 Binary files /dev/null and b/natives/jinput-raw.dll differ diff --git a/natives/jinput-raw_64.dll b/natives/jinput-raw_64.dll new file mode 100644 index 0000000..3d2b3ad Binary files /dev/null and b/natives/jinput-raw_64.dll differ diff --git a/natives/justabit.ttf b/natives/justabit.ttf new file mode 100644 index 0000000..783357b Binary files /dev/null and b/natives/justabit.ttf differ diff --git a/natives/libjinput-linux.so b/natives/libjinput-linux.so new file mode 100644 index 0000000..3cdc439 Binary files /dev/null and b/natives/libjinput-linux.so differ diff --git a/natives/libjinput-linux64.so b/natives/libjinput-linux64.so new file mode 100644 index 0000000..de1ee5f Binary files /dev/null and b/natives/libjinput-linux64.so differ diff --git a/natives/libjinput-osx.dylib b/natives/libjinput-osx.dylib new file mode 100644 index 0000000..59a3eab Binary files /dev/null and b/natives/libjinput-osx.dylib differ diff --git a/natives/liblwjgl.dylib b/natives/liblwjgl.dylib new file mode 100644 index 0000000..a6083b9 Binary files /dev/null and b/natives/liblwjgl.dylib differ diff --git a/natives/liblwjgl.so b/natives/liblwjgl.so new file mode 100644 index 0000000..ba6e7f6 Binary files /dev/null and b/natives/liblwjgl.so differ diff --git a/natives/liblwjgl64.so b/natives/liblwjgl64.so new file mode 100644 index 0000000..8ed0992 Binary files /dev/null and b/natives/liblwjgl64.so differ diff --git a/natives/libopenal.so b/natives/libopenal.so new file mode 100644 index 0000000..0a3a619 Binary files /dev/null and b/natives/libopenal.so differ diff --git a/natives/libopenal64.so b/natives/libopenal64.so new file mode 100644 index 0000000..e0693c0 Binary files /dev/null and b/natives/libopenal64.so differ diff --git a/natives/lwjgl.dll b/natives/lwjgl.dll new file mode 100644 index 0000000..e6c97d9 Binary files /dev/null and b/natives/lwjgl.dll differ diff --git a/natives/lwjgl64.dll b/natives/lwjgl64.dll new file mode 100644 index 0000000..2c8b93e Binary files /dev/null and b/natives/lwjgl64.dll differ diff --git a/natives/openal.dylib b/natives/openal.dylib new file mode 100644 index 0000000..3c6d0f7 Binary files /dev/null and b/natives/openal.dylib differ diff --git a/src/Defaults.java b/src/Defaults.java new file mode 100644 index 0000000..2b78b7d --- /dev/null +++ b/src/Defaults.java @@ -0,0 +1,27 @@ +/** + * @author Jose Stovall + * A launcher class in the default package which runs the main game + * Also handles copying and setting LWJGL Natives + */ + +import edu.utc.gamedev.Game; +import edu.utc.gamedev.Util.FileUtils; +import org.newdawn.slick.util.ResourceLoader; + +import java.io.File; + +public class Defaults +{ + public static void main(String[] args) + { + // Copies the natives folder FROM the compiled jar if it doesn't exist + if (!(new File("natives").exists())) + { + FileUtils.copyResourcesRecursively(ResourceLoader.getResource("natives"), new File("natives")); + } + + // Sets the LWJGL Libraries path to the natives folder + System.setProperty("org.lwjgl.librarypath", new File("natives").getAbsolutePath()); + new Game(); + } +} diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..7d87ddb --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Defaults + diff --git a/src/edu/utc/gamedev/Entity/Entity.java b/src/edu/utc/gamedev/Entity/Entity.java new file mode 100644 index 0000000..c8e6f7f --- /dev/null +++ b/src/edu/utc/gamedev/Entity/Entity.java @@ -0,0 +1,21 @@ +package edu.utc.gamedev.Entity; + +import org.lwjgl.util.Rectangle; + +public abstract class Entity +{ + public void update(float delta) + { + } + + public void draw() + { + } + + public Rectangle getHitBox() + { + return null; + } +} + + diff --git a/src/edu/utc/gamedev/Entity/Item/EntityHeart.java b/src/edu/utc/gamedev/Entity/Item/EntityHeart.java new file mode 100644 index 0000000..0546959 --- /dev/null +++ b/src/edu/utc/gamedev/Entity/Item/EntityHeart.java @@ -0,0 +1,66 @@ +package edu.utc.gamedev.Entity.Item; + +import edu.utc.gamedev.Item.ItemHeart; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Scene.SceneLevel; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.util.Rectangle; + +public class EntityHeart extends EntityItem +{ + private SceneLevel scene = SceneManager.getInstance().getScene(); + + public EntityHeart(int x, int y) + { + super(new ItemHeart(), x, y); + this.box = new Rectangle(x, y, sprite.getTextureWidth(), sprite.getTextureHeight()); + state = State.IDLE; + } + + @Override + public void update(float delta) + { + // Handle hitbox intersection + if (scene.getPlayer() != null && this.box.intersects(scene.getPlayer().getHitBox())) + { + scene.getPlayer().damage(-10F); + scene.getEntityManager().removeEntity(this); + } + if (Helper.getTime() - spawnTime >= 9000) + { + scene.getEntityManager().removeEntity(this); + } + + int motion = 1; + if (state != State.IDLE && Helper.getTime() - lastMoved < 256) + return; + lastMoved = Helper.getTime(); + switch (state) + { + case FALLING: + box.translate(0, motion); + if (box.getY() >= (Display.getHeight() - (box.getHeight()))) + { + box.setY(Display.getHeight() - (box.getHeight())); + state = State.RISING; + } + break; + case RISING: + box.translate(0, -motion); + if (box.getY() <= (Display.getHeight() - (box.getHeight() * 1.05))) + { + state = State.FALLING; + } + break; + case IDLE: + box.translate(0, motion * 4); + if (box.getY() >= (Display.getHeight() - (box.getHeight()))) + { + box.setY(Display.getHeight() - (box.getHeight())); + state = State.RISING; + } + break; + } + } +} \ No newline at end of file diff --git a/src/edu/utc/gamedev/Entity/Item/EntityItem.java b/src/edu/utc/gamedev/Entity/Item/EntityItem.java new file mode 100644 index 0000000..2917495 --- /dev/null +++ b/src/edu/utc/gamedev/Entity/Item/EntityItem.java @@ -0,0 +1,119 @@ +package edu.utc.gamedev.Entity.Item; + +import edu.utc.gamedev.Entity.Entity; +import edu.utc.gamedev.Item.Item; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; + +public class EntityItem extends Entity +{ + protected Item actualItem; + protected Rectangle box; + protected Texture sprite; + protected float wr, hr; + protected State state; + protected long spawnTime; + protected long lastMoved; + protected int lifespan; + + public EntityItem(Item item, int x, int y, int lifespan) + { + this.actualItem = item; + sprite = Helper.loadTexture("items/" + item.getIconString()); + this.box = new Rectangle(x, y, 64, (64 * sprite.getImageHeight() / sprite.getImageWidth())); + this.box.setY(y - box.getHeight()); + this.wr = 1.0f * sprite.getImageWidth() / sprite.getTextureWidth(); + this.hr = 1.0f * sprite.getImageHeight() / sprite.getTextureHeight(); + this.state = State.IDLE; + this.spawnTime = Helper.getTime(); + this.lifespan = lifespan; + } + + public EntityItem(Item item, int x, int y) + { + this(item, x, y, 9000); + } + + @Override + public void draw() + { + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + GL11.glColor3f(1F, 1F, 1F); + GL11.glBegin(GL11.GL_QUADS); + + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(wr, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(wr, hr); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, hr); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + @Override + public void update(float delta) + { + // Handle hitbox intersection + if (SceneManager.getInstance().getScene().getPlayer() != null && this.box.intersects(SceneManager.getInstance().getScene().getPlayer().getHitBox())) + { + SceneManager.getInstance().getScene().getPlayer().setHeldItem(this.actualItem.setCursor()); + SceneManager.getInstance().getScene().getEntityManager().removeEntity(this); + } + if (this.lifespan > 0 && Helper.getTime() - spawnTime >= this.lifespan) + { + SceneManager.getInstance().getScene().getEntityManager().removeEntity(this); + } + + int motion = 1; + if (state != State.IDLE && Helper.getTime() - lastMoved < 256) + return; + lastMoved = Helper.getTime(); + switch (state) + { + case FALLING: + box.translate(0, motion); + if (box.getY() >= (Display.getHeight() - (box.getHeight()))) + { + box.setY(Display.getHeight() - (box.getHeight())); + state = State.RISING; + } + break; + case RISING: + box.translate(0, -motion); + if (box.getY() <= (Display.getHeight() - (box.getHeight() * 1.05))) + { + state = State.FALLING; + } + break; + case IDLE: + box.translate(0, motion * 4); + if (box.getY() >= (Display.getHeight() - (box.getHeight()))) + { + box.setY(Display.getHeight() - (box.getHeight())); + state = State.RISING; + } + break; + } + } + + public enum State + { + FALLING, RISING, IDLE + } +} diff --git a/src/edu/utc/gamedev/Entity/Living/EntityLiving.java b/src/edu/utc/gamedev/Entity/Living/EntityLiving.java new file mode 100644 index 0000000..9e3857a --- /dev/null +++ b/src/edu/utc/gamedev/Entity/Living/EntityLiving.java @@ -0,0 +1,66 @@ +package edu.utc.gamedev.Entity.Living; + +import edu.utc.gamedev.Entity.Entity; +import edu.utc.gamedev.Manager.SceneManager; +import org.lwjgl.opengl.GL11; + +public abstract class EntityLiving extends Entity +{ + public float getHealth() + { + return 0F; + } + + public float getMaxHealth() + { + return 0F; + } + + + public void damage(float amount) + { + + } + + public void drawHealth() + { + float amtToDraw = getHealth() / getMaxHealth(); + + float x = (float) this.getHitBox().getX(); + float y = (float) this.getHitBox().getY() - 12; + float w = (float) this.getHitBox().getWidth(); + float h = 6F; + + GL11.glColor3f(0F, 0F, 0F); + GL11.glBegin(GL11.GL_QUADS); + + GL11.glVertex2f(x, y); + GL11.glVertex2f(x + w, y); + GL11.glVertex2f(x + w, y + h); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + + w = this.getHitBox().getWidth() * amtToDraw; + + float rAmt = Math.abs((amtToDraw * 255F - 255F) / 255F); + float gAmt = amtToDraw; + + GL11.glColor3f(rAmt, gAmt, 0); + GL11.glBegin(GL11.GL_QUADS); + + GL11.glVertex2f(x, y); + GL11.glVertex2f(x + w, y); + GL11.glVertex2f(x + w, y + h); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + } + + public void kill() + { + SceneManager.getInstance().getScene().getEntityManager().removeEntity(this); + } +} + + diff --git a/src/edu/utc/gamedev/Entity/Living/EntityMonster.java b/src/edu/utc/gamedev/Entity/Living/EntityMonster.java new file mode 100644 index 0000000..bf87556 --- /dev/null +++ b/src/edu/utc/gamedev/Entity/Living/EntityMonster.java @@ -0,0 +1,366 @@ +package edu.utc.gamedev.Entity.Living; + +import edu.utc.gamedev.Entity.Item.EntityHeart; +import edu.utc.gamedev.Manager.AudioManager; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Scene.SceneLevel; +import edu.utc.gamedev.Tile.Dungeon.TilePlatform; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; + +import java.util.Random; + +import static edu.utc.gamedev.Entity.Living.EntityMonster.State.HIT; + +public class EntityMonster extends EntityLiving +{ + private final float GRAVITY = 3F; + private State state; + private Rectangle box; + private Texture sprite; + private boolean flip; + private long lastDamagedTime; + private Type variant; + private float health; + private float wr, hr; + private float motionMultiplier; + private StartingSide start; + private State lastState; + private SceneLevel scene = SceneManager.getInstance().getScene(); + + public EntityMonster(Type variant) + { + this.sprite = Helper.loadTexture("entity/" + variant.getResourceName()); + Random rand = scene.rand(); + int xSpawn; + if (rand.nextInt(2) == 0) + { + start = StartingSide.RIGHT; + xSpawn = (Display.getWidth() + rand.nextInt(256)); + } + else + { + start = StartingSide.LEFT; + xSpawn = (0 - rand.nextInt(256)); + } + this.box = new Rectangle(xSpawn, (Display.getHeight() - (sprite.getImageHeight())), (int) variant.getWidth(), (int) (variant.getWidth() * sprite.getImageHeight() / sprite.getImageWidth())); + this.flip = (xSpawn <= 0); + this.wr = 1.0f * sprite.getImageWidth() / sprite.getTextureWidth(); + this.hr = 1.0f * sprite.getImageHeight() / sprite.getTextureHeight(); + this.state = State.RIGHT; + this.variant = variant; + this.health = variant.getStartingHealth(); + } + + @Override + public void update(float delta) + { + int motion = (int) (variant.getSpeed() * delta); + int verticalMotion = (int) (motion * motionMultiplier); + int horizontalMotion = (int) (verticalMotion * 1.25); + // Handle directional punching properly + if (SceneManager.getInstance().getScene().getPlayer() != null && SceneManager.getInstance().getScene().getPlayer().getHitBox().getX() > box.getX()) + { + horizontalMotion *= -1; + } + box.setY(variant == Type.BAT ? Display.getHeight() - (box.getHeight() * 5) : Display.getHeight() - box.getHeight()); + + switch (state) + { + case IDLE: + + if (start == StartingSide.RIGHT) + { + state = State.RIGHT; + } + else + { + state = State.LEFT; + } + break; + case RIGHT: + box.translate(motion, 0); + if (box.getX() > (Display.getWidth() - box.getWidth())) + { + flip = false; + state = State.LEFT; + } + break; + case LEFT: + box.translate(-motion, 0); + if (box.getX() <= 0) + { + state = State.RIGHT; + flip = true; + } + break; + case HIT: + // Make large creatures sink into the ground when hit, instead of fly into the air + if (this.variant.width > 64F) + { + box.translate(horizontalMotion, verticalMotion); + } + else + { + box.translate(horizontalMotion, -verticalMotion); + } + // Normalize locations to prevent glitchy monsters + if (box.getX() < 0) + { + box.setX(0); + } + if (box.getX() + box.getWidth() > Display.getWidth()) + { + box.setX(Display.getWidth() - box.getWidth()); + } + // Apply Motion! + if (verticalMotion <= 0) + { + state = State.FALLING; + } + else + { + motionMultiplier -= 0.25F; + } + break; + case FALLING: + box.translate(horizontalMotion, verticalMotion); + // Normalize locations to prevent glitchy monsters + if (box.getX() < 0) + { + box.setX(0); + } + if (box.getX() + box.getWidth() > Display.getWidth()) + { + box.setX(Display.getWidth() - box.getWidth()); + } + // Apply Motion! + if (getEntityPlatform() != null) + { + // Fixes the player's feet being past the platform + box.setY(getEntityPlatform().getHitBox().getY() - (box.getHeight())); + state = lastState; + } + else + { + if (motionMultiplier < GRAVITY) + { + motionMultiplier += 0.25F; + } + } + break; + } + if (scene.getPlayer() != null && box.intersects(scene.getPlayer().getHitBox())) + { + if (scene.getPlayer().getState() != EntityPlayer.State.DEAD && scene.getPlayer().getState() != EntityPlayer.State.STUNNED) + { + scene.getPlayer().damage(variant.getDamageToPlayer()); + } + } + } + + public TilePlatform getEntityPlatform() + { + if (SceneManager.getInstance().getScene() instanceof SceneLevel) + { + for (TilePlatform t : SceneManager.getInstance().getScene().getTileManager().getPlatforms()) + { + if (t.entityStanding(this)) + { + return t; + } + } + } + return null; + } + + public long getLastDamagedTime() + { + return lastDamagedTime; + } + + public void setInvulnerableTime() + { + lastDamagedTime = Helper.getTime(); + } + + @Override + public void draw() + { + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + GL11.glColor3f(1F, 1F, 1F); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + GL11.glBegin(GL11.GL_QUADS); + + if (state == HIT) + { + GL11.glColor3f(180 / 255F, 0F, 3 / 255F); + } + if (flip) + { + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(wr, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(wr, hr); + GL11.glVertex2f(x, y + h); + + GL11.glTexCoord2f(0F, hr); + GL11.glVertex2f(x + w, y + h); + } + else + { + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(wr, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(wr, hr); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, hr); + GL11.glVertex2f(x, y + h); + } + + GL11.glEnd(); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + @Override + public float getMaxHealth() + { + return variant.startingHealth; + } + + @Override + public Rectangle getHitBox() + { + return box; + } + + @Override + public void kill() + { + // Monsters have a 25% chance of dropping a heart only if the player needs it + if (scene.rand().nextInt(4) == 0 && scene.getPlayer().getHealth() <= 10F) + { + scene.getEntityManager().addEntity(new EntityHeart(box.getX() + (box.getWidth() / 2), box.getY())); + } + + scene.getEntityManager().removeEntity(this); + } + + @Override + public void damage(float amount) + { + // Don't allow entities to be damaged multiple times + if (state == State.HIT || state == State.FALLING) + { + return; + } + health -= amount; + if (health > 0F) + { + AudioManager.getInstance().play("damage_hit" + (scene.rand().nextInt(10) + 1)); + lastState = state; + motionMultiplier = GRAVITY; + state = HIT; + } + else + { + kill(); + AudioManager.getInstance().play(variant.getResourceName() + "_death"); + } + } + + public float getHealth() + { + return health; + } + + public State getState() + { + return state; + } + + public void setState(State s) + { + state = s; + } + + public enum State + { + IDLE, LEFT, RIGHT, HIT, FALLING + } + + public enum StartingSide + { + LEFT, RIGHT + } + + public enum Type + { + ORC(0.25F, 20F, 1F, 92F, "orc"), + GUT_EATER(0.15F, 40F, 1.5F, 192F, "gut_eater"), + BAT(0.75F, 1F, 0.25F, 48F, "bat"), + ZOMBIE(0.15F, 18F, 0.75F, 64F, "zombie"), + FLAME(1F, 2F, 0.5F, 30F, "flame"), + ROCK_MONSTER(0.2F, 20F, 0.4F, 60F, "rock_monster"), + ICE_MONSTER(0.65F, 10F, 0.5F, 48F, "ice_monster"), + DARK_MAGE(0.5F, 14F, 0.75F, 64F, "dark_mage"), + OOZER(0.15F, 32F, 0.8F, 40F, "oozer"); + + private final float speed; + private final float startingHealth; + private final float damageToPlayer; + private final float width; + private final String resourceName; + + Type(float speed, float health, float damage, float width, String resourceName) + { + this.speed = speed; + this.startingHealth = health; + this.damageToPlayer = damage; + this.resourceName = resourceName; + this.width = width; + } + + public float getSpeed() + { + return speed; + } + + public float getStartingHealth() + { + return startingHealth; + } + + public float getDamageToPlayer() + { + return damageToPlayer; + } + + public String getResourceName() + { + return resourceName; + } + + public float getWidth() + { + return width; + } + } +} + + diff --git a/src/edu/utc/gamedev/Entity/Living/EntityPlayer.java b/src/edu/utc/gamedev/Entity/Living/EntityPlayer.java new file mode 100644 index 0000000..8f89d5a --- /dev/null +++ b/src/edu/utc/gamedev/Entity/Living/EntityPlayer.java @@ -0,0 +1,311 @@ +package edu.utc.gamedev.Entity.Living; + +import edu.utc.gamedev.Item.Item; +import edu.utc.gamedev.Item.ItemFist; +import edu.utc.gamedev.Manager.AudioManager; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Scene.SceneLevel; +import edu.utc.gamedev.Tile.Dungeon.TilePlatform; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.LWJGLException; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; + +public class EntityPlayer extends EntityLiving +{ + private final float GRAVITY = 3.5F; + private Rectangle box; + private Texture sprite; + private float speed; + private State state; + private boolean flip; + private long stunTime; + private float health; + private float maxHealth; + private float motionMultiplier; + private float wr, hr; + private Item heldItem; + + public EntityPlayer(int x, int y) + { + sprite = Helper.loadTexture("entity/player"); + box = new Rectangle(x, y, 32, (32 * sprite.getImageHeight() / sprite.getImageWidth())); + this.wr = 1.0f * sprite.getImageWidth() / sprite.getTextureWidth(); + this.hr = 1.0f * sprite.getImageHeight() / sprite.getTextureHeight(); + this.state = State.FALLING; + this.flip = false; + this.health = 20F; + this.maxHealth = 20F; + this.speed = .6F; + this.heldItem = new ItemFist().setCursor(); + } + + public EntityPlayer() + { + this(0, 0); + } + + + @Override + public float getMaxHealth() + { + return this.maxHealth; + } + + @Override + public void update(float delta) + { + int motion = (int) (this.speed * delta); + int verticalMotion = (int) (motion * motionMultiplier); + if (Keyboard.isKeyDown(Keyboard.KEY_A) && this.box.getX() > 0 && !(this.state == State.STUNNED)) + { + this.flip = true; + box.translate(-motion, 0); + } + if (Keyboard.isKeyDown(Keyboard.KEY_D) && this.box.getX() <= (Display.getWidth() - box.getWidth()) && !(this.state == State.STUNNED)) + { + this.flip = false; + box.translate(motion, 0); + } + + // Fix the player from being off the screen at any time + if (this.box.getX() < 0 || this.box.getX() > Display.getWidth()) + { + this.box.setX(0); + } + if (this.box.getY() < 0 || this.box.getY() > Display.getHeight()) + { + this.box.setY(Display.getHeight() - this.box.getHeight()); + } + + + switch (state) + { + case IDLE: + motionMultiplier = 0.0F; + if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) + { + AudioManager.getInstance().play("player_jump"); + motionMultiplier = GRAVITY; + state = State.JUMPING; + } + // Makes our player fall off of platforms + else if (getPlayerPlatform() == null) + { + state = State.FALLING; + } + break; + case JUMPING: + box.translate(0, -verticalMotion); + if (verticalMotion <= 0) + { + state = State.FALLING; + } + else + { + motionMultiplier -= 0.25F; + } + break; + case FALLING: + box.translate(0, verticalMotion); + if (getPlayerPlatform() != null) + { + // Fixes the player's feet being past the platform + box.setY(getPlayerPlatform().getHitBox().getY() - (box.getHeight())); + state = State.IDLE; + } + else + { + if (motionMultiplier < GRAVITY) + { + motionMultiplier += 0.25F; + } + } + break; + case STUNNED: + if (Helper.getTime() - this.stunTime > (40 * delta)) + { + if (getPlayerPlatform() == null) + { + this.state = State.FALLING; + } + else + { + this.state = State.IDLE; + } + } + break; + case DEAD: + kill(); + break; + } + if (!Mouse.isCreated() || this.heldItem == null) + { + return; + } + while (Mouse.next()) + { + + if ((!this.heldItem.limitUseDistance() && Mouse.getEventButtonState())) + { + this.heldItem.onUse(); + } + if (Mouse.getEventButtonState() && Math.abs(this.box.getX() - Mouse.getX()) < 384) + { + if (Math.abs(this.box.getY() - (Display.getHeight() - Mouse.getY())) < 192) + { + this.heldItem.onUse(); + } + } + } + } + + @Override + public void draw() + { + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + GL11.glColor3f(255F, 255F, 255F); + GL11.glBegin(GL11.GL_QUADS); + + // So that the player renders red when hurt: + if (this.state == State.STUNNED) + { + GL11.glColor3f(.8F, 0F, 0F); + } + if (this.flip) + { + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(wr, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(wr, hr); + GL11.glVertex2f(x, y + h); + + GL11.glTexCoord2f(0F, hr); + GL11.glVertex2f(x + w, y + h); + } + else + { + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(wr, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(wr, hr); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, hr); + GL11.glVertex2f(x, y + h); + } + + GL11.glEnd(); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + @Override + public void kill() + { + if (SceneManager.getInstance().getScene() instanceof SceneLevel) + { + ((SceneLevel) SceneManager.getInstance().getScene()).setPlayer(null); + } + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } + + public State getState() + { + return this.state; + } + + @Override + public float getHealth() + { + return this.health; + } + + @Override + public void damage(float amount) + { + this.health -= amount; + + // Normalize health; player should have no more than 20 health + if (this.health > maxHealth) + this.health = maxHealth; + + // Do nothing else if we're just "healing" + if (amount <= 0) + return; + + if (this.health > 0F) + { + this.stunTime = Helper.getTime(); + this.state = State.STUNNED; + AudioManager.getInstance().play("player_hit" + (SceneManager.getInstance().getScene().rand().nextInt(2) + 1)); + } + else + { + this.state = State.DEAD; + AudioManager.getInstance().play("player_death"); + } + } + + public Item getHeldItem() + { + return this.heldItem; + } + + public void setHeldItem(Item item) + { + if (item == null) + { + this.heldItem = null; + try + { + Mouse.setNativeCursor(null); + } + catch (LWJGLException lwjglEx) + { + return; + } + } + this.heldItem = item; + } + + public TilePlatform getPlayerPlatform() + { + if (SceneManager.getInstance().getScene() instanceof SceneLevel) + { + for (TilePlatform t : SceneManager.getInstance().getScene().getTileManager().getPlatforms()) + { + if (t.entityStanding(this)) + { + return t; + } + } + } + return null; + } + + public enum State + { + IDLE, JUMPING, FALLING, STUNNED, DEAD + } +} diff --git a/src/edu/utc/gamedev/Entity/Projectile/EntityPotatoProjectile.java b/src/edu/utc/gamedev/Entity/Projectile/EntityPotatoProjectile.java new file mode 100644 index 0000000..fb9a9f3 --- /dev/null +++ b/src/edu/utc/gamedev/Entity/Projectile/EntityPotatoProjectile.java @@ -0,0 +1,117 @@ +package edu.utc.gamedev.Entity.Projectile; + +import edu.utc.gamedev.Entity.Living.EntityMonster; +import edu.utc.gamedev.Entity.Entity; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Scene.SceneLevel; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Rectangle; +import org.lwjgl.util.vector.Vector2f; +import org.newdawn.slick.opengl.Texture; + +public class EntityPotatoProjectile extends Entity +{ + private Vector2f vel; + private Rectangle box; + private float speed = 4f; + private boolean flip; + private float wr, hr; + private Texture sprite; + private SceneLevel scene = SceneManager.getInstance().getScene(); + + public EntityPotatoProjectile(int x, int y, Vector2f vel, boolean flip) + { + sprite = Helper.loadTexture("entity/projectile/potato"); + this.box = new Rectangle(x, y, 32, (32 * sprite.getImageHeight() / sprite.getImageWidth())); + this.wr = 1.0f * sprite.getImageWidth() / sprite.getTextureWidth(); + this.hr = 1.0f * sprite.getImageHeight() / sprite.getTextureHeight(); + this.vel = new Vector2f(); + vel.normalise(this.vel); + this.flip = flip; + } + + @Override + public void update(float delta) + { + // Handle off-screen projectiles + if (speed <= 0 || box.getX() < 0 || box.getX() > Display.getWidth() || box.getY() < 0 || box.getY() > Display.getHeight()) + { + scene.getProjectileManager().removeProjectile(this); + return; + } + if (speed > 0) + { + box.translate((int) (delta * speed * vel.getX()), (int) ((delta * speed * vel.getY()))); + Vector2f.add(vel, new Vector2f(0, .1f), vel); + } + // Collision for potatoes + for (Entity e : scene.getEntityManager().getEntities()) + { + if (!(e instanceof EntityMonster)) + continue; + + if (this.box.intersects(e.getHitBox())) + { + EntityMonster m = (EntityMonster) e; + m.damage(10F); + m.setState(EntityMonster.State.HIT); + scene.getProjectileManager().removeProjectile(this); + break; + } + } + } + + @Override + public void draw() + { + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + GL11.glColor3f(1F, 1F, 1F); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + GL11.glBegin(GL11.GL_QUADS); + + if (this.flip) + { + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(wr, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(wr, hr); + GL11.glVertex2f(x, y + h); + + GL11.glTexCoord2f(0F, hr); + GL11.glVertex2f(x + w, y + h); + } + else + { + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(wr, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(wr, hr); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, hr); + GL11.glVertex2f(x, y + h); + } + + GL11.glEnd(); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } +} diff --git a/src/edu/utc/gamedev/Game.java b/src/edu/utc/gamedev/Game.java new file mode 100644 index 0000000..6ead41a --- /dev/null +++ b/src/edu/utc/gamedev/Game.java @@ -0,0 +1,240 @@ +package edu.utc.gamedev; + +import edu.utc.gamedev.Entity.Living.EntityMonster; +import edu.utc.gamedev.Manager.AudioManager; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Manager.ScreenshotManager; +import edu.utc.gamedev.Scene.Dungeon; +import edu.utc.gamedev.Scene.Menu; +import edu.utc.gamedev.Scene.Scene; +import edu.utc.gamedev.Util.Config; +import org.lwjgl.LWJGLException; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.DisplayMode; +import org.lwjgl.opengl.GL11; +import org.newdawn.slick.opengl.PNGDecoder; +import org.newdawn.slick.util.ResourceLoader; + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.ByteBuffer; + +public class Game +{ + private static Game instance; + public Config config; + public ScreenshotManager screenshotManager; + public SceneManager sceneManager; + private boolean fullscreen; + + public Game() + { + instance = this; + this.config = new Config(); + this.screenshotManager = new ScreenshotManager(); + this.fullscreen = false; + this.sceneManager = new SceneManager(); + initGL(); + initAudio(); + initGame(); + } + + public static Game getInstance() + { + return instance; + } + + public void initGame() + { + Menu gameMenu = new Menu(); + gameMenu.addItem("Play", new Dungeon()); + gameMenu.addSpecial("Exit", Menu.DO_EXIT); + + Scene currScene = gameMenu; + + while (currScene.go()) + { + currScene = currScene.nextScene(); + + if (currScene == null) + { + currScene = gameMenu; + } + } + + AudioManager.getInstance().destroy(); + Display.destroy(); + } + + public void initGL() + { + setDisplayMode(this.config.resolutionWidth, this.config.resolutionHeight, fullscreen); + Display.setTitle("Crawl 'n Brawl"); + // Centers the window + Display.setLocation((Toolkit.getDefaultToolkit().getScreenSize().width / 2) - (this.config.resolutionWidth / 2), + (Toolkit.getDefaultToolkit().getScreenSize().height / 2) - (this.config.resolutionHeight / 2)); + + initIcon(); + + try + { + Display.create(); + } + catch (LWJGLException e) + { + System.out.println("Caught an LWJGL exception when creating the display. Quitting.."); + System.out.println(e.getMessage()); + System.exit(0); + } + + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glClearColor(0F, 0F, 0F, 0.0f); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glViewport(0, 0, this.config.resolutionWidth, this.config.resolutionHeight); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0, this.config.resolutionWidth, this.config.resolutionHeight, 0, 1, -1); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + } + + /** + * SOURCE: http://wiki.lwjgl.org/wiki/LWJGL_Basics_5_(Fullscreen).html + * + * @param width The width of the display required + * @param height The height of the display required + * @param fullscreen True if we want fullscreen mode + */ + public void setDisplayMode(int width, int height, boolean fullscreen) + { + if ((Display.getDisplayMode().getWidth() == width) && (Display.getDisplayMode().getHeight() == height) && (Display.isFullscreen() == fullscreen)) + return; + + try + { + org.lwjgl.opengl.DisplayMode targetDisplayMode = null; + + if (fullscreen) + { + org.lwjgl.opengl.DisplayMode[] modes = Display.getAvailableDisplayModes(); + int freq = 0; + + for (int i = 0; i < modes.length; i++) + { + org.lwjgl.opengl.DisplayMode current = modes[i]; + + if ((current.getWidth() == width) && (current.getHeight() == height)) + { + if ((targetDisplayMode == null) || (current.getFrequency() >= freq)) + { + if ((targetDisplayMode == null) || (current.getBitsPerPixel() > targetDisplayMode.getBitsPerPixel())) + { + targetDisplayMode = current; + freq = targetDisplayMode.getFrequency(); + } + } + + if ((current.getBitsPerPixel() == Display.getDesktopDisplayMode().getBitsPerPixel()) && (current.getFrequency() == Display.getDesktopDisplayMode().getFrequency())) + { + targetDisplayMode = current; + break; + } + } + } + } + else + { + targetDisplayMode = new DisplayMode(width, height); + } + + if (targetDisplayMode == null) + { + System.out.println("Failed to find value mode: " + width + "x" + height + " fs=" + fullscreen); + return; + } + + Display.setDisplayMode(targetDisplayMode); + Display.setFullscreen(fullscreen); + // Stupid LWJGL stuff. Thanks Ellpeck! + Display.setResizable(false); + Display.setResizable(true); + Display.setVSyncEnabled(true); + } + catch (LWJGLException e) + { + System.err.println("Unable to setup mode " + width + "x" + height + " fullscreen=" + fullscreen + e); + } + } + + /** + * SOURCE: http://forum.lwjgl.org/index.php?topic=3422.0 + * + * @return The ByteBuffer of the PNG located at the passed URL + */ + private ByteBuffer loadIcon(URL url) throws IOException + { + System.out.println("Loaded icon " + url.getPath().replace("/C:/", "C:/")); + InputStream is = url.openStream(); + try + { + PNGDecoder decoder = new PNGDecoder(is); + ByteBuffer buffer = ByteBuffer.allocateDirect(decoder.getWidth() * decoder.getHeight() * 4); + decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.RGBA); + buffer.flip(); + return buffer; + } + finally + { + is.close(); + } + } + + public void initIcon() + { + try + { + Display.setIcon(new ByteBuffer[]{ + loadIcon(ResourceLoader.getResource("assets/icon/icon16.png".replace("/", File.separator))), + loadIcon(ResourceLoader.getResource("assets/icon/icon32.png".replace("/", File.separator))), + }); + } + catch (IOException e) + { + System.out.println("Icon file not found; using default."); + Display.setIcon(new ByteBuffer[]{}); + } + } + + public void initAudio() + { + try + { + AudioManager.getInstance().loadSample("sword_slash", "assets/sounds/sword_slash.wav".replace("/", File.separator)); + AudioManager.getInstance().loadSample("player_jump", "assets/sounds/player_jump.wav".replace("/", File.separator)); + AudioManager.getInstance().loadSample("player_death", "assets/sounds/death/player_death.wav".replace("/", File.separator)); + AudioManager.getInstance().loadSample("level_up", "assets/sounds/environment/level_up.wav".replace("/", File.separator)); + for (int i = 1; i <= 2; i++) + { + AudioManager.getInstance().loadSample("player_hit" + i, "assets/sounds/damage/player_hit" + i + ".wav".replace("/", File.separator)); + } + for (int i = 1; i <= 10; i++) + { + AudioManager.getInstance().loadSample("damage_hit" + i, "assets/sounds/damage/damage_hit" + i + ".wav".replace("/", File.separator)); + } + for (int i = 0; i < EntityMonster.Type.values().length; i++) + { + AudioManager.getInstance().loadSample(EntityMonster.Type.values()[i].getResourceName() + "_death", "assets/sounds/death/".replace("/", File.separator) + EntityMonster.Type.values()[i].getResourceName() + "_death.wav"); + } + AudioManager.getInstance().loadSample("menu_move", "assets/sounds/menu/move.wav".replace("/", File.separator)); + AudioManager.getInstance().loadSample("menu_select", "assets/sounds/menu/select.wav".replace("/", File.separator)); + } + catch (IOException e) + { + System.out.println("Audio file not found; some sounds may not work correctly"); + System.out.println(e.getMessage()); + } + } +} diff --git a/src/edu/utc/gamedev/Item/Item.java b/src/edu/utc/gamedev/Item/Item.java new file mode 100644 index 0000000..725c287 --- /dev/null +++ b/src/edu/utc/gamedev/Item/Item.java @@ -0,0 +1,113 @@ +package edu.utc.gamedev.Item; + +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.BufferUtils; +import org.lwjgl.LWJGLException; +import org.lwjgl.input.Cursor; +import org.lwjgl.input.Mouse; +import org.newdawn.slick.util.ResourceLoader; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.IntBuffer; + +public class Item +{ + private final String iconString; + public int textureWidth; + public int textureHeight; + + public Item(String resourceFile) + { + this.iconString = resourceFile; + } + + public int getCooldownTime() + { + return 40; + } + + public String getIconString() + { + return this.iconString; + } + + + /** + * @throws LWJGLException if the cursor cannot be created or changed + * @throws IOException if the cursor file cannot be found + *

+ * Changes the cursor to a little sword! + * SOURCE: https://goo.gl/Boi1AP + */ + public Item setCursor() + { + + InputStream stream = ResourceLoader.getResourceAsStream("assets/textures/items/".replace("/", File.separator) + iconString + ".png"); + BufferedImage cursorImg; + try + { + cursorImg = ImageIO.read(stream); + Mouse.create(); + } + catch (IOException e) + { + try + { + cursorImg = ImageIO.read(ResourceLoader.getResourceAsStream(Helper.errTexture())); + } + catch (IOException whatTheFuck) + { + throw new RuntimeException(whatTheFuck); + } + } + catch (LWJGLException e) + { + System.err.println("There was an issue creating the mouse"); + System.err.println(e.getMessage()); + return this; + } + + textureWidth = cursorImg.getWidth(); + textureHeight = cursorImg.getHeight(); + + int rgbData[] = new int[textureWidth * textureHeight]; + + for (int i = 0; i < rgbData.length; i++) + { + int x = i % textureWidth; + int y = textureHeight - 1 - i / textureWidth; // this will also flip the image vertically + + rgbData[i] = cursorImg.getRGB(x, y); + } + + IntBuffer buffer = BufferUtils.createIntBuffer(textureWidth * textureHeight); + buffer.put(rgbData); + buffer.rewind(); + + try + { + Cursor cursor = new Cursor(textureWidth, textureHeight, 2, textureHeight - 2, 1, buffer, null); + Mouse.setNativeCursor(cursor); + } + catch (LWJGLException e) + { + System.err.println("There was an issue setting the custom mouse cursor"); + System.err.println(e.getMessage()); + } + + return this; + } + + public void onUse() + { + } + + public boolean limitUseDistance() + { + return true; + } +} diff --git a/src/edu/utc/gamedev/Item/ItemFist.java b/src/edu/utc/gamedev/Item/ItemFist.java new file mode 100644 index 0000000..39d1e7d --- /dev/null +++ b/src/edu/utc/gamedev/Item/ItemFist.java @@ -0,0 +1,49 @@ +package edu.utc.gamedev.Item; + +import edu.utc.gamedev.Entity.Living.EntityMonster; +import edu.utc.gamedev.Entity.Entity; +import edu.utc.gamedev.Entity.Living.EntityPlayer; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.Display; +import org.lwjgl.util.Rectangle; + +public class ItemFist extends Item +{ + + public ItemFist() + { + super("fist"); + } + + public int getCooldownTime() + { + return 1000; + } + + @Override + public void onUse() + { + if (SceneManager.getInstance().getScene().getPlayer() == null || SceneManager.getInstance().getScene().getPlayer().getState() == EntityPlayer.State.STUNNED) + return; + + int mouseX = Mouse.getX(); + int mouseY = Display.getHeight() - Mouse.getY(); + + Rectangle attackRect = new Rectangle(mouseX, mouseY, textureWidth, textureHeight); + + for (Entity e : SceneManager.getInstance().getScene().getEntityManager().getEntities()) + { + if (e instanceof EntityMonster) + { + EntityMonster m = (EntityMonster) e; + if (m.getHitBox().intersects(attackRect) && m.getState() != EntityMonster.State.HIT && Helper.getTime() - m.getLastDamagedTime() > getCooldownTime()) + { + m.damage(2F); + ((EntityMonster) e).setState(EntityMonster.State.HIT); + } + } + } + } +} diff --git a/src/edu/utc/gamedev/Item/ItemHeart.java b/src/edu/utc/gamedev/Item/ItemHeart.java new file mode 100644 index 0000000..cc6a1c2 --- /dev/null +++ b/src/edu/utc/gamedev/Item/ItemHeart.java @@ -0,0 +1,16 @@ +package edu.utc.gamedev.Item; + +public class ItemHeart extends Item +{ + public ItemHeart() + { + super("heart"); + } + + + @Override + public Item setCursor() + { + return this; + } +} diff --git a/src/edu/utc/gamedev/Item/ItemPotatoGun.java b/src/edu/utc/gamedev/Item/ItemPotatoGun.java new file mode 100644 index 0000000..76c6237 --- /dev/null +++ b/src/edu/utc/gamedev/Item/ItemPotatoGun.java @@ -0,0 +1,53 @@ +package edu.utc.gamedev.Item; + +import edu.utc.gamedev.Entity.Living.EntityPlayer; +import edu.utc.gamedev.Entity.Projectile.EntityPotatoProjectile; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.Display; +import org.lwjgl.util.Rectangle; +import org.lwjgl.util.vector.Vector2f; + +public class ItemPotatoGun extends Item +{ + private long lastShot; + + public ItemPotatoGun() + { + super("potato_gun"); + } + + @Override + public void onUse() + { + if (SceneManager.getInstance().getScene().getPlayer().getState() == EntityPlayer.State.STUNNED) + return; + + if (Helper.getTime() - lastShot > getCooldownTime()) + { + Rectangle r = SceneManager.getInstance().getScene().getPlayer().getHitBox(); + int mx = Mouse.getX(); + int my = Display.getHeight() - Mouse.getY(); + + int bx = r.getX() + (r.getWidth() / 2); + int by = r.getY() + 8; + + Vector2f vel = new Vector2f(mx - bx, my - by); + SceneManager.getInstance().getScene().getProjectileManager().addProjectile(new EntityPotatoProjectile(bx, by, vel, (my < r.getY()))); + lastShot = Helper.getTime(); + } + } + + @Override + public int getCooldownTime() + { + return 240; + } + + @Override + public boolean limitUseDistance() + { + return false; + } +} diff --git a/src/edu/utc/gamedev/Item/Sword/ItemBroadSword.java b/src/edu/utc/gamedev/Item/Sword/ItemBroadSword.java new file mode 100644 index 0000000..e39478f --- /dev/null +++ b/src/edu/utc/gamedev/Item/Sword/ItemBroadSword.java @@ -0,0 +1,9 @@ +package edu.utc.gamedev.Item.Sword; + +public class ItemBroadSword extends ItemSword +{ + public ItemBroadSword() + { + super(6F, "broad_sword"); + } +} diff --git a/src/edu/utc/gamedev/Item/Sword/ItemDagger.java b/src/edu/utc/gamedev/Item/Sword/ItemDagger.java new file mode 100644 index 0000000..0092d02 --- /dev/null +++ b/src/edu/utc/gamedev/Item/Sword/ItemDagger.java @@ -0,0 +1,9 @@ +package edu.utc.gamedev.Item.Sword; + +public class ItemDagger extends ItemSword +{ + public ItemDagger() + { + super(2.5F, "dagger"); + } +} diff --git a/src/edu/utc/gamedev/Item/Sword/ItemGreatSword.java b/src/edu/utc/gamedev/Item/Sword/ItemGreatSword.java new file mode 100644 index 0000000..5404e02 --- /dev/null +++ b/src/edu/utc/gamedev/Item/Sword/ItemGreatSword.java @@ -0,0 +1,9 @@ +package edu.utc.gamedev.Item.Sword; + +public class ItemGreatSword extends ItemSword +{ + public ItemGreatSword() + { + super(8F, "great_sword"); + } +} diff --git a/src/edu/utc/gamedev/Item/Sword/ItemRefinedSword.java b/src/edu/utc/gamedev/Item/Sword/ItemRefinedSword.java new file mode 100644 index 0000000..b7f5359 --- /dev/null +++ b/src/edu/utc/gamedev/Item/Sword/ItemRefinedSword.java @@ -0,0 +1,9 @@ +package edu.utc.gamedev.Item.Sword; + +public class ItemRefinedSword extends ItemSword +{ + public ItemRefinedSword() + { + super(5F, "refined_sword"); + } +} diff --git a/src/edu/utc/gamedev/Item/Sword/ItemRustySword.java b/src/edu/utc/gamedev/Item/Sword/ItemRustySword.java new file mode 100644 index 0000000..d37140a --- /dev/null +++ b/src/edu/utc/gamedev/Item/Sword/ItemRustySword.java @@ -0,0 +1,9 @@ +package edu.utc.gamedev.Item.Sword; + +public class ItemRustySword extends ItemSword +{ + public ItemRustySword() + { + super(4F, "rusty_sword"); + } +} diff --git a/src/edu/utc/gamedev/Item/Sword/ItemSword.java b/src/edu/utc/gamedev/Item/Sword/ItemSword.java new file mode 100644 index 0000000..3c01ffa --- /dev/null +++ b/src/edu/utc/gamedev/Item/Sword/ItemSword.java @@ -0,0 +1,54 @@ +package edu.utc.gamedev.Item.Sword; + +import edu.utc.gamedev.Entity.Living.EntityMonster; +import edu.utc.gamedev.Entity.Entity; +import edu.utc.gamedev.Entity.Living.EntityPlayer; +import edu.utc.gamedev.Item.Item; +import edu.utc.gamedev.Manager.AudioManager; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.Display; +import org.lwjgl.util.Rectangle; + +public abstract class ItemSword extends Item +{ + private float damage; + + public ItemSword(float damage, String resourceFile) + { + super(resourceFile); + this.damage = damage; + } + + @Override + public void onUse() + { + if (SceneManager.getInstance().getScene().getPlayer().getState() == EntityPlayer.State.STUNNED) + return; + int mouseX = Mouse.getX(); + int mouseY = Display.getHeight() - Mouse.getY(); + + Rectangle attackRect = new Rectangle(mouseX, mouseY, textureWidth, textureHeight); + + for (Entity e : SceneManager.getInstance().getScene().getEntityManager().getEntities()) + { + if (e instanceof EntityMonster) + { + EntityMonster m = (EntityMonster) e; + if (m.getHitBox().intersects(attackRect) && m.getState() != EntityMonster.State.HIT && Helper.getTime() - m.getLastDamagedTime() > getCooldownTime()) + { + AudioManager.getInstance().play("sword_slash"); + m.damage(damage); + m.setState(EntityMonster.State.HIT); + } + } + } + } + + @Override + public int getCooldownTime() + { + return 800; + } +} diff --git a/src/edu/utc/gamedev/Item/Sword/ItemWoodenSword.java b/src/edu/utc/gamedev/Item/Sword/ItemWoodenSword.java new file mode 100644 index 0000000..60f50d7 --- /dev/null +++ b/src/edu/utc/gamedev/Item/Sword/ItemWoodenSword.java @@ -0,0 +1,9 @@ +package edu.utc.gamedev.Item.Sword; + +public class ItemWoodenSword extends ItemSword +{ + public ItemWoodenSword() + { + super(3F, "wooden_sword"); + } +} diff --git a/src/edu/utc/gamedev/Manager/AudioManager.java b/src/edu/utc/gamedev/Manager/AudioManager.java new file mode 100644 index 0000000..d73c471 --- /dev/null +++ b/src/edu/utc/gamedev/Manager/AudioManager.java @@ -0,0 +1,174 @@ +package edu.utc.gamedev.Manager; + +/** + * @author Craig Tanis + *

+ * Code obtained from https://github.com/ctanis/cpsc3520_fa17/blob/master/pongy/src/AudioManager.java + */ + +import edu.utc.gamedev.Game; +import org.lwjgl.openal.AL; +import org.newdawn.slick.openal.Audio; +import org.newdawn.slick.openal.AudioLoader; +import org.newdawn.slick.openal.SoundStore; +import org.newdawn.slick.util.ResourceLoader; + +import java.io.IOException; +import java.util.HashMap; + + +/** + * A utility class for caching sounds from files and enabling the + * straightforward triggering of those sounds (samples and loops) + */ +public class AudioManager +{ + private static AudioManager instance; + private HashMap sounds; + + private AudioManager() + { + sounds = new HashMap(); + } + + /** + * @return the singleton AudioManager instance + */ + public static AudioManager getInstance() + { + if (instance == null) instance = new AudioManager(); + return instance; + } + + /** + * load a one-shot sample + * + * @param name identifier for loaded sound + * @param path path to file + */ + public void loadSample(String name, String path) throws IOException + { + // extract file extension + String mode = path.substring(path.lastIndexOf('.') + 1).toUpperCase(); + + Audio tmp = AudioLoader.getAudio(mode, ResourceLoader.getResourceAsStream(path)); + sounds.put(name, new AudioWrapper(AudioType.SAMPLE, tmp)); + } + + /** + * load a looping music track + * + * @param name identifier for loaded sound + * @param path path to file + */ + public void loadLoop(String name, String path) throws IOException + { + // extract file extension + String mode = path.substring(path.lastIndexOf('.') + 1).toUpperCase(); + + Audio tmp = AudioLoader.getStreamingAudio(mode, ResourceLoader.getResource(path)); + sounds.put(name, new AudioWrapper(AudioType.LOOP, tmp)); + } + + /** + * get sound associated with name identifier + * + * @param name the loaded sound identifier + */ + public AudioWrapper get(String name) + { + return sounds.get(name); + } + + /** + * play sound associated with name identifier + * + * @param name the loaded sound identifier + */ + public void play(String name) + { + sounds.get(name).play(); + } + + /** + * play sound associated with name identifier + * + * @param name the loaded sound identifier + * @param vol volume of sound (0.0 to 1.0) + */ + public void play(String name, float vol) + { + sounds.get(name).play(vol); + } + + /** + * call this once per frame + */ + public void update() + { + SoundStore.get().poll(0); + } + + /** + * call this to clean up + */ + public void destroy() + { + AL.destroy(); + } + + + private enum AudioType + { + LOOP, SAMPLE + } + + /** + * A handle on a loaded audio object, to play the same sound repeatedly + * without having to look it up + */ + public class AudioWrapper + { + private Audio sound; + private AudioType type; + + private AudioWrapper(AudioType t, Audio a) + { + type = t; + sound = a; + } + + /** + * play this sound at config's volume + */ + public void play() + { + play(Game.getInstance().config.volume); + } + + /** + * Play this sound + * + * @param vol value between 0.0 and 1.0 to specify relative volume of sound + * if volume is 0, sound is not played + */ + public void play(float vol) + { + // prevents the sound from being played if sound is "off" + if (vol <= 0F) + return; + + switch (type) + { + case LOOP: + sound.playAsMusic(1.0f, vol, true); + break; + + case SAMPLE: + sound.playAsSoundEffect(1.0f, vol, false); + break; + } + } + + } +} diff --git a/src/edu/utc/gamedev/Manager/EntityManager.java b/src/edu/utc/gamedev/Manager/EntityManager.java new file mode 100644 index 0000000..d0f199b --- /dev/null +++ b/src/edu/utc/gamedev/Manager/EntityManager.java @@ -0,0 +1,72 @@ +package edu.utc.gamedev.Manager; + +import edu.utc.gamedev.Entity.Entity; +import edu.utc.gamedev.Entity.Living.EntityLiving; +import edu.utc.gamedev.Entity.Living.EntityMonster; + +import java.util.ConcurrentModificationException; +import java.util.LinkedList; + +public class EntityManager +{ + private LinkedList entities; + + public EntityManager() + { + entities = new LinkedList<>(); + } + + public void drawAll() + { + for (Entity e : entities) + { + e.draw(); + if (e instanceof EntityLiving) + { + ((EntityLiving) e).drawHealth(); + } + } + } + + public void updateAll(float delta) + { + try + { + for (Entity e : entities) + { + e.update(delta); + } + } + catch (ConcurrentModificationException e) + { + // We do nothing because nothing can be done ¯\_(ツ)_/¯ + } + } + + public void addEntity(Entity e) + { + entities.add(e); + } + + public void removeEntity(Entity e) + { + entities.remove(e); + } + + public LinkedList getEntities() + { + return this.entities; + } + + public boolean allMonstersDead() + { + for (Entity e : entities) + { + if (e instanceof EntityMonster) + { + return false; + } + } + return true; + } +} diff --git a/src/edu/utc/gamedev/Manager/ProjectileManager.java b/src/edu/utc/gamedev/Manager/ProjectileManager.java new file mode 100644 index 0000000..2a8726f --- /dev/null +++ b/src/edu/utc/gamedev/Manager/ProjectileManager.java @@ -0,0 +1,54 @@ +package edu.utc.gamedev.Manager; + +import edu.utc.gamedev.Entity.Projectile.EntityPotatoProjectile; + +import java.util.ConcurrentModificationException; +import java.util.LinkedList; + +public class ProjectileManager +{ + private LinkedList projectiles; + + public ProjectileManager() + { + projectiles = new LinkedList<>(); + } + + public void drawAll() + { + for (EntityPotatoProjectile e : projectiles) + { + e.draw(); + } + } + + public void updateAll(float delta) + { + try + { + for (EntityPotatoProjectile e : projectiles) + { + e.update(delta); + } + } + catch (ConcurrentModificationException e) + { + // We do nothing because nothing can be done ¯\_(ツ)_/¯ + } + } + + public void addProjectile(EntityPotatoProjectile e) + { + projectiles.add(e); + } + + public void removeProjectile(EntityPotatoProjectile e) + { + projectiles.remove(e); + } + + public LinkedList getProjectiles() + { + return this.projectiles; + } +} diff --git a/src/edu/utc/gamedev/Manager/SceneManager.java b/src/edu/utc/gamedev/Manager/SceneManager.java new file mode 100644 index 0000000..2988d29 --- /dev/null +++ b/src/edu/utc/gamedev/Manager/SceneManager.java @@ -0,0 +1,32 @@ +package edu.utc.gamedev.Manager; + + +import edu.utc.gamedev.Scene.SceneLevel; + +public class SceneManager +{ + private static SceneManager instance; + private SceneLevel currentSceneLevel; + + public SceneManager() + { + this.currentSceneLevel = null; + instance = this; + } + + public static SceneManager getInstance() + { + return instance; + } + + public SceneLevel getScene() + { + return this.currentSceneLevel; + } + + public void setScene(SceneLevel s) + { + this.currentSceneLevel = s; + } + +} diff --git a/src/edu/utc/gamedev/Manager/ScreenshotManager.java b/src/edu/utc/gamedev/Manager/ScreenshotManager.java new file mode 100644 index 0000000..e0a8ef3 --- /dev/null +++ b/src/edu/utc/gamedev/Manager/ScreenshotManager.java @@ -0,0 +1,81 @@ +package edu.utc.gamedev.Manager; + +import org.lwjgl.BufferUtils; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class ScreenshotManager +{ + private File screenshotsFolder; + + public ScreenshotManager() + { + screenshotsFolder = new File(System.getProperty("user.dir") + File.separator + "screenshots"); + } + + + public File getScreenshotsFolder() + { + return this.screenshotsFolder; + } + + public void setScreenshotsFolder(File newFolder) + { + this.screenshotsFolder = newFolder; + } + + /** + * SOURCE: http://wiki.lwjgl.org/wiki/Taking_Screen_Shots.html + */ + public void takeScreenshot() + { + GL11.glReadBuffer(GL11.GL_FRONT); + int width = Display.getDisplayMode().getWidth(); + int height = Display.getDisplayMode().getHeight(); + int bpp = 4; + ByteBuffer buffer = BufferUtils.createByteBuffer(width * height * bpp); + GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); + + if (!this.screenshotsFolder.exists()) + { + this.screenshotsFolder.mkdir(); + } + + String format = "png"; + long timestamp = System.currentTimeMillis(); + SimpleDateFormat dateFormat = new SimpleDateFormat("MMM-dd-yyyy HH mm ss"); + Date resultdate = new Date(timestamp); + File file = new File(this.screenshotsFolder.getAbsolutePath() + File.separator + dateFormat.format(resultdate) + "." + format); + System.out.println(file.getAbsolutePath()); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + + for (int x = 0; x < width; x++) + { + for (int y = 0; y < height; y++) + { + int i = (x + (width * y)) * bpp; + int r = buffer.get(i) & 0xFF; + int g = buffer.get(i + 1) & 0xFF; + int b = buffer.get(i + 2) & 0xFF; + image.setRGB(x, height - (y + 1), (0xFF << 24) | (r << 16) | (g << 8) | b); + } + } + + try + { + ImageIO.write(image, format, file); + } + catch (IOException e) + { + System.out.println("Error capturing screenshot"); + } + } +} diff --git a/src/edu/utc/gamedev/Manager/TileManager.java b/src/edu/utc/gamedev/Manager/TileManager.java new file mode 100644 index 0000000..a900ef3 --- /dev/null +++ b/src/edu/utc/gamedev/Manager/TileManager.java @@ -0,0 +1,87 @@ +package edu.utc.gamedev.Manager; + +import edu.utc.gamedev.Tile.ITile; +import edu.utc.gamedev.Tile.Dungeon.TileDecoration; +import edu.utc.gamedev.Tile.Dungeon.TilePlatform; + +import java.util.LinkedList; + +public class TileManager +{ + private LinkedList tiles; + private LinkedList decorations; + private LinkedList platforms; + + public TileManager() + { + tiles = new LinkedList<>(); + decorations = new LinkedList<>(); + platforms = new LinkedList<>(); + } + + public void drawAll() + { + for (ITile t : tiles) + { + t.draw(); + } + for (TileDecoration t : decorations) + { + t.draw(); + } + for (TilePlatform t : platforms) + { + t.draw(); + t.update(); + } + } + + public void addTile(ITile t) + { + if (t instanceof TileDecoration) + { + this.decorations.add((TileDecoration) t); + } + else if (t instanceof TilePlatform) + { + this.platforms.add((TilePlatform) t); + } + else + { + this.tiles.add(t); + } + } + + public void addAll(Iterable tiles) + { + for (ITile t : tiles) + { + this.addTile(t); + } + } + + public void removeTile(ITile t) + { + this.tiles.remove(t); + } + + public void removeDecoration(TileDecoration t) + { + this.decorations.remove(t); + } + + public LinkedList getDecorations() + { + return (LinkedList) this.decorations.clone(); + } + + public void clearDecorations() + { + this.decorations.clear(); + } + + public LinkedList getPlatforms() + { + return (LinkedList) this.platforms.clone(); + } +} diff --git a/src/edu/utc/gamedev/Scene/Dungeon.java b/src/edu/utc/gamedev/Scene/Dungeon.java new file mode 100644 index 0000000..59a6a2c --- /dev/null +++ b/src/edu/utc/gamedev/Scene/Dungeon.java @@ -0,0 +1,297 @@ +package edu.utc.gamedev.Scene; + +import edu.utc.gamedev.Entity.Item.EntityItem; +import edu.utc.gamedev.Entity.Living.EntityMonster; +import edu.utc.gamedev.Entity.Living.EntityPlayer; +import edu.utc.gamedev.Game; +import edu.utc.gamedev.Item.*; +import edu.utc.gamedev.Item.Sword.*; +import edu.utc.gamedev.Manager.*; +import edu.utc.gamedev.Tile.*; +import edu.utc.gamedev.Tile.TileBackground; +import edu.utc.gamedev.Tile.Dungeon.TileDecoration; +import edu.utc.gamedev.Tile.Dungeon.TileExit; +import edu.utc.gamedev.Util.FileUtils; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Color; +import org.newdawn.slick.TrueTypeFont; +import org.newdawn.slick.opengl.TextureImpl; +import org.newdawn.slick.util.ResourceLoader; + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.Random; + +public class Dungeon extends SceneLevel +{ + private static Dungeon instance; + public EntityPlayer player; + public EntityManager entityManager; + public ProjectileManager projectileManager; + public TileManager tileManager; + public Random rand = new Random(); + private TileBackground background; + private TilePlatformGround ground; + private int level, maxLevels; + private TrueTypeFont levelFont; + private TileExit exit; + + public Dungeon() + { + this(new EntityPlayer(), 1); + } + + public Dungeon(EntityPlayer player, int level) + { + SceneManager.getInstance().setScene(this); + + // Update variables and such + instance = this; + + // Managers + this.entityManager = new EntityManager(); + this.projectileManager = new ProjectileManager(); + this.tileManager = new TileManager(); + + // Player + this.player = player; + this.entityManager.addEntity(this.player); + this.level = level; + this.maxLevels = 1; + + initFont(); + initScene(); + } + +// public static Living getInstance() +// { +// return instance; +// } + + public void initFont() + { + try + { + File font = new File("natives/justabit.ttf".replace("/", File.separator)).getAbsoluteFile(); + if (!font.exists()) + { + System.out.println("Font did not exist; copying..."); + FileUtils.copyStream(ResourceLoader.getResourceAsStream("assets/justabit.ttf"), new File("natives/justabit.ttf".replace("/", File.separator))); + } + + Font awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(32F); + levelFont = new TrueTypeFont(awtFont, false); + } + catch (IOException | FontFormatException e) + { + levelFont = new TrueTypeFont(new Font("Arial", Font.PLAIN, 32), false); + } + } + + public void initScene() + { + // Tiles + Color c = Helper.getRandomColor(); + background = new TileBackground("wall").changeColor(c); + ground = new TilePlatformGround(); + exit = new TileExit().setColor(c); + tileManager.addTile(this.background); + for (int i = 0; i < rand.nextInt(3) + 1; i++) + { + tileManager.addTile(new TileDecoration("wall_decor_", 4).changeColor(c)); + } + if (this.level % 5 == 0) + { + if (getItemAtStage(level / 5) != null) + { + AudioManager.getInstance().play("level_up"); + entityManager.addEntity(new EntityItem(getItemAtStage(level / 5), Display.getWidth() / 2, Display.getHeight() - 32, -1)); + } + } + + tileManager.addTile(ground); + tileManager.addTile(new TilePlatformBase()); + + spawnMonsters(); + } + + public Item getItemAtStage(int stage) + { + switch (stage) + { + case 1: + return new ItemDagger(); + case 2: + return new ItemWoodenSword(); + case 3: + return new ItemRustySword(); + case 4: + return new ItemRefinedSword(); + case 5: + return new ItemBroadSword(); + case 6: + return new ItemGreatSword(); + case 7: + return new ItemPotatoGun(); + default: + return null; + } + } + + @Override + public Scene nextScene() + { + // Progress to the next level! + if (entityManager.allMonstersDead() && player.getHitBox().intersects(exit.getHitBox())) + { + // If the next level is less than level + if (level + 1 <= maxLevels) + { + return new Dungeon(player, level + 1); + } + else + { + return new Surface(player); + } + } + + Menu menu = new Menu(); + if (player == null || player.getState() == EntityPlayer.State.DEAD) + { + menu.addItem("Play Again", new Dungeon()); + } + else + { + menu.addItem("Resume", this); + } + menu.addSpecial("Exit", Menu.DO_EXIT); + + return menu; + + } + + + public TileBackground getBackground() + { + return background; + } + + @Override + public boolean drawFrame(float delta) + { + entityManager.updateAll(delta); + projectileManager.updateAll(delta); + + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); + + tileManager.drawAll(); + if (entityManager.allMonstersDead()) + { + exit.draw(); + } + entityManager.drawAll(); + projectileManager.drawAll(); + + + // I use F2 for screenshots based on other games I've enjoyed + if (Keyboard.isKeyDown(Keyboard.KEY_F2)) + { + Game.getInstance().screenshotManager.takeScreenshot(); + } + + // I use F11 for fullscreen for the same reason! + if (Keyboard.isKeyDown(Keyboard.KEY_F11)) + { + if (Display.isFullscreen()) + { + Game.getInstance().setDisplayMode(Game.getInstance().config.resolutionWidth, Game.getInstance().config.resolutionHeight, false); + } + else + { + Game.getInstance().setDisplayMode(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height, true); + } + Display.setResizable(true); + GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); + } + + // Screen resize handler + if (Display.wasResized()) + { + GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); + } + + TextureImpl.bindNone(); + int rem = (maxLevels - level) + 1; + + levelFont.drawString(1, 0, (rem + (rem == 1 ? " level" : " levels") + " from the surface")); + + if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) + { + return false; + } + if (entityManager.allMonstersDead()) + { + if (player.getHitBox().intersects(exit.getHitBox())) + { + if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) + { + return false; + } + } + } + return player != null; + } + + /** + * Spawns a quantity of monsters directly corresponding to the level the player is at + */ + public void spawnMonsters() + { + int variants = EntityMonster.Type.values().length; + + for (int i = 0; i < this.level; i++) + { + entityManager.addEntity(new EntityMonster(EntityMonster.Type.values()[rand.nextInt(variants)])); + } + } + + @Override + public EntityPlayer getPlayer() + { + return this.player; + } + + @Override + public void setPlayer(EntityPlayer p) + { + this.player = p; + } + + @Override + public TileManager getTileManager() + { + return this.tileManager; + } + + @Override + public EntityManager getEntityManager() + { + return this.entityManager; + } + + @Override + public ProjectileManager getProjectileManager() + { + return this.projectileManager; + } +} diff --git a/src/edu/utc/gamedev/Scene/Menu.java b/src/edu/utc/gamedev/Scene/Menu.java new file mode 100644 index 0000000..8bdab95 --- /dev/null +++ b/src/edu/utc/gamedev/Scene/Menu.java @@ -0,0 +1,226 @@ +package edu.utc.gamedev.Scene; + +import edu.utc.gamedev.Game; +import edu.utc.gamedev.Manager.AudioManager; +import edu.utc.gamedev.Tile.TileBackground; +import edu.utc.gamedev.Util.FileUtils; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.newdawn.slick.Color; +import org.newdawn.slick.TrueTypeFont; +import org.newdawn.slick.opengl.TextureImpl; +import org.newdawn.slick.util.ResourceLoader; + +import java.awt.*; +import java.awt.font.TextAttribute; +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; + +public class Menu extends Scene +{ + public static final int DO_EXIT = 0; + private List items; + private int currItem; + private long lastChanged; + private TileBackground bg; + private TrueTypeFont menuFont; + private TrueTypeFont selectedFont; + private TrueTypeFont titleFont; + + public Menu() + { + items = new LinkedList<>(); + lastChanged = Helper.getTime(); + bg = new TileBackground("menu"); + HashMap titleAttributes = new HashMap<>(); + titleAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + + HashMap selectedAttributes = new HashMap<>(); + selectedAttributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); + + try + { + File font = new File("natives/justabit.ttf".replace("/", File.separator)).getAbsoluteFile(); + if (!font.exists()) + { + System.out.println("Font did not exist; copying..."); + FileUtils.copyStream(ResourceLoader.getResourceAsStream("assets/justabit.ttf"), new File("natives/justabit.ttf".replace("/", File.separator))); + } + + Font awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(titleAttributes).deriveFont(64F); + titleFont = new TrueTypeFont(awtFont, false); + + awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(selectedAttributes).deriveFont(Font.BOLD).deriveFont(52F); + selectedFont = new TrueTypeFont(awtFont, false); + + awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(40F); + menuFont = new TrueTypeFont(awtFont, false); + } + catch (IOException | FontFormatException e) + { + titleFont = new TrueTypeFont(new Font("Arial", Font.PLAIN, 64).deriveFont(titleAttributes).deriveFont(64F), false); + selectedFont = new TrueTypeFont(new Font("Arial", Font.BOLD, 52).deriveFont(selectedAttributes).deriveFont(Font.BOLD).deriveFont(52F), false); + menuFont = new TrueTypeFont(new Font("Arial", Font.PLAIN, 40).deriveFont(40F), false); + } + } + + // reset menu + public void clear() + { + items.clear(); + } + + public void addItem(String label, Scene s) + { + items.add(new Item(label, s)); + } + + public void addSpecial(String label, int tag) + { + items.add(new Special(label, tag)); + } + + public Scene nextScene() + { + return items.get(currItem).scene; + } + + public boolean drawFrame(float delta) + { + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); + + bg.draw(); + + while (Keyboard.next()) + { + if (Keyboard.getEventKeyState()) // key was pressed + { + switch (Keyboard.getEventKey()) + { + case Keyboard.KEY_W: + AudioManager.getInstance().play("menu_move"); + currItem--; + if (currItem < 0) + { + currItem += items.size(); // go to end + } + break; + case Keyboard.KEY_UP: + AudioManager.getInstance().play("menu_move"); + currItem--; + if (currItem < 0) + { + currItem += items.size(); // go to end + } + break; + case Keyboard.KEY_S: + AudioManager.getInstance().play("menu_move"); + currItem = (currItem + 1) % items.size(); + break; + case Keyboard.KEY_DOWN: + AudioManager.getInstance().play("menu_move"); + currItem = (currItem + 1) % items.size(); + break; + case Keyboard.KEY_RETURN: + AudioManager.getInstance().play("menu_select"); + Item item = items.get(currItem); + if (item instanceof Special) + { + switch (((Special) item).tag) + { + case DO_EXIT: + exit(); + break; + } + } + return false; + case Keyboard.KEY_F2: + Game.getInstance().screenshotManager.takeScreenshot(); + break; + case Keyboard.KEY_F11: + if (Display.isFullscreen()) + { + Game.getInstance().setDisplayMode(Game.getInstance().config.resolutionWidth, Game.getInstance().config.resolutionHeight, false); + } + else + { + Game.getInstance().setDisplayMode(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height, true); + } + Display.setResizable(true); + GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); + break; + } + } + } + + // Screen resize handler + if (Display.wasResized()) + { + GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); + } + + float spacing = Display.getHeight() / (items.size() + 4); + float offset = 2 * spacing; + + TextureImpl.bindNone(); + titleFont.drawString((Display.getWidth() / 2) - (titleFont.getWidth("Crawl 'n Brawl") / 2), 64F, "Crawl 'n Brawl", new Color(0, 123, 124)); + + for (int i = 0; i < items.size(); i++) + { + if (i == currItem) + { + TextureImpl.bindNone(); + + selectedFont.drawString(Display.getWidth() / 2 - (selectedFont.getWidth(items.get(i).label) / 2), offset, items.get(i).label, new Color(85, 124, 0)); + } + else + { + TextureImpl.bindNone(); + menuFont.drawString(Display.getWidth() / 2 - (menuFont.getWidth(items.get(i).label) / 2), offset, items.get(i).label, new Color(74, 91, 37)); + } + + offset += spacing; + } + + // font binds a texture, so let's turn it off.. + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + + return true; + } + + + // a menu item: label and associated Scene to jump to + private static class Item + { + public String label; + public Scene scene; + + public Item(String label, Scene s) + { + this.label = label; + this.scene = s; + } + } + + private static class Special extends Item + { + public int tag; + + public Special(String label, int tag) + { + super(label, null); + this.tag = tag; + } + } +} diff --git a/src/edu/utc/gamedev/Scene/Scene.java b/src/edu/utc/gamedev/Scene/Scene.java new file mode 100644 index 0000000..be7e204 --- /dev/null +++ b/src/edu/utc/gamedev/Scene/Scene.java @@ -0,0 +1,53 @@ +package edu.utc.gamedev.Scene; + +import edu.utc.gamedev.Game; +import edu.utc.gamedev.Manager.AudioManager; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; + +public abstract class Scene +{ + private boolean doExit = false; + + // return false if the game should be quit + public abstract boolean drawFrame(float delta); + + // null typically means Game should load menu + public Scene nextScene() + { + return null; + } + + protected void exit() + { + doExit = true; + } + + // returns false when game should be exited + public boolean go() + { + long lastloop = Helper.getTime(); + + boolean keepGoing = true; + do + { + Display.sync(Game.getInstance().config.targetFPS); + long now = Helper.getTime(); + long delta = now - lastloop; + lastloop = now; + + keepGoing = drawFrame(delta); + + // UPDATE DISPLAY + Display.update(); + AudioManager.getInstance().update(); + + if (Display.isCloseRequested() || doExit) + { + return false; + } + } while (keepGoing); + + return true; + } +} diff --git a/src/edu/utc/gamedev/Scene/SceneLevel.java b/src/edu/utc/gamedev/Scene/SceneLevel.java new file mode 100644 index 0000000..62a83e6 --- /dev/null +++ b/src/edu/utc/gamedev/Scene/SceneLevel.java @@ -0,0 +1,32 @@ +package edu.utc.gamedev.Scene; + +import edu.utc.gamedev.Entity.Living.EntityPlayer; +import edu.utc.gamedev.Manager.EntityManager; +import edu.utc.gamedev.Manager.ProjectileManager; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Manager.TileManager; + +import java.util.Random; + +public abstract class SceneLevel extends Scene +{ + public SceneLevel() + { + SceneManager.getInstance().setScene(this); + } + + public abstract EntityPlayer getPlayer(); + + public abstract void setPlayer(EntityPlayer player); + + public abstract TileManager getTileManager(); + + public abstract EntityManager getEntityManager(); + + public abstract ProjectileManager getProjectileManager(); + + public Random rand() + { + return new Random(); + } +} diff --git a/src/edu/utc/gamedev/Scene/Surface.java b/src/edu/utc/gamedev/Scene/Surface.java new file mode 100644 index 0000000..17d48c8 --- /dev/null +++ b/src/edu/utc/gamedev/Scene/Surface.java @@ -0,0 +1,228 @@ +package edu.utc.gamedev.Scene; + +import edu.utc.gamedev.Entity.Living.EntityPlayer; +import edu.utc.gamedev.Game; +import edu.utc.gamedev.Manager.EntityManager; +import edu.utc.gamedev.Manager.ProjectileManager; +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Manager.TileManager; +import edu.utc.gamedev.Tile.ITile; +import edu.utc.gamedev.Tile.Surface.TileGrass; +import edu.utc.gamedev.Tile.Surface.TileHouse; +import edu.utc.gamedev.Tile.Surface.TileWell; +import edu.utc.gamedev.Tile.TileBackground; +import edu.utc.gamedev.Tile.TilePlatformGround; +import edu.utc.gamedev.Util.FileUtils; +import org.lwjgl.input.Keyboard; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.newdawn.slick.TrueTypeFont; +import org.newdawn.slick.opengl.TextureImpl; +import org.newdawn.slick.util.ResourceLoader; + +import java.awt.*; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +public class Surface extends SceneLevel +{ + + private EntityPlayer player; + private TileManager tileManager; + private TileBackground background; + private TilePlatformGround ground; + private TrueTypeFont levelFont; + private EntityManager entityManager; + private ITile house, well; + private ProjectileManager projectileManager; + + public Surface(EntityPlayer player) + { + SceneManager.getInstance().setScene(this); + + // Managers + this.tileManager = new TileManager(); + this.entityManager = new EntityManager(); + this.projectileManager = new ProjectileManager(); + + // Player + this.player = player; + + // House + this.house = new TileHouse(); + this.well = new TileWell(); + this.player.getHitBox().setX(well.getHitBox().getX() + well.getHitBox().getWidth() + 32); + this.player.getHitBox().setY(Display.getHeight() - this.player.getHitBox().getHeight()); + + initFont(); + initScene(); + } + + + public void initFont() + { + try + { + File font = new File("natives/justabit.ttf".replace("/", File.separator)).getAbsoluteFile(); + if (!font.exists()) + { + System.out.println("Font did not exist; copying..."); + FileUtils.copyStream(ResourceLoader.getResourceAsStream("assets/justabit.ttf"), new File("natives/justabit.ttf".replace("/", File.separator))); + } + + Font awtFont = Font.createFont(Font.TRUETYPE_FONT, font).deriveFont(32F); + levelFont = new TrueTypeFont(awtFont, false); + } + catch (IOException | FontFormatException e) + { + levelFont = new TrueTypeFont(new Font("Arial", Font.PLAIN, 32), false); + } + } + + public void initScene() + { + // Tiles + background = new TileBackground("sky"); + ground = new TilePlatformGround(); + tileManager.addTile(ground); + tileManager.addTile(background); + tileManager.addAll(populateGrass()); + tileManager.addTile(house); + tileManager.addTile(well); + entityManager.addEntity(player); + player.setHeldItem(null); + } + + private ArrayList populateGrass() + { + int x = 0; + ArrayList ret = new ArrayList<>(); + TileGrass grassTemp; + while (x < Toolkit.getDefaultToolkit().getScreenSize().width) + { + grassTemp = new TileGrass(x); + ret.add(grassTemp); + x += grassTemp.getHitBox().getWidth(); + } + return ret; + } + + @Override + public Scene nextScene() + { + if (player != null && player.getHitBox().intersects(well.getHitBox())) + { + return new Dungeon(); + } + Menu menu = new Menu(); + if (player == null || player.getState() == EntityPlayer.State.DEAD) + { + menu.addItem("Play Again", new Dungeon()); + } + else + { + menu.addItem("Resume", this); + } + menu.addSpecial("Exit", Menu.DO_EXIT); + + return menu; + } + + + @Override + public boolean drawFrame(float delta) + { + entityManager.updateAll(delta); + projectileManager.updateAll(delta); + + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); + + tileManager.drawAll(); + entityManager.drawAll(); + projectileManager.drawAll(); + + // I use F2 for screenshots based on other games I've enjoyed + if (Keyboard.isKeyDown(Keyboard.KEY_F2)) + { + Game.getInstance().screenshotManager.takeScreenshot(); + } + + // I use F11 for fullscreen for the same reason! + if (Keyboard.isKeyDown(Keyboard.KEY_F11)) + { + if (Display.isFullscreen()) + { + Game.getInstance().setDisplayMode(Game.getInstance().config.resolutionWidth, Game.getInstance().config.resolutionHeight, false); + } + else + { + Game.getInstance().setDisplayMode(Toolkit.getDefaultToolkit().getScreenSize().width, Toolkit.getDefaultToolkit().getScreenSize().height, true); + } + Display.setResizable(true); + GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); + } + + // Screen resize handler + if (Display.wasResized()) + { + GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0, Display.getWidth(), Display.getHeight(), 0, 1, -1); + } + + TextureImpl.bindNone(); + levelFont.drawString(1, 0, ("Surface")); + + if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) + { + return false; + } + if (player.getHitBox().intersects(house.getHitBox())) + { + entityManager.removeEntity(player); + player = null; + return false; + } + if (player.getHitBox().intersects(well.getHitBox())) + { + return false; + } + return true; + } + + + @Override + public EntityPlayer getPlayer() + { + return this.player; + } + + @Override + public void setPlayer(EntityPlayer p) + { + this.player = p; + } + + @Override + public TileManager getTileManager() + { + return this.tileManager; + } + + @Override + public EntityManager getEntityManager() + { + return this.entityManager; + } + + @Override + public ProjectileManager getProjectileManager() + { + return this.projectileManager; + } +} diff --git a/src/edu/utc/gamedev/Tile/Dungeon/TileDecoration.java b/src/edu/utc/gamedev/Tile/Dungeon/TileDecoration.java new file mode 100644 index 0000000..0f0b508 --- /dev/null +++ b/src/edu/utc/gamedev/Tile/Dungeon/TileDecoration.java @@ -0,0 +1,103 @@ +package edu.utc.gamedev.Tile.Dungeon; + +import edu.utc.gamedev.Manager.SceneManager; +import edu.utc.gamedev.Scene.Dungeon; +import edu.utc.gamedev.Scene.Scene; +import edu.utc.gamedev.Tile.ITile; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Color; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; + +import java.io.File; +import java.util.Random; + + +public class TileDecoration implements ITile +{ + private Texture sprite; + private Rectangle box; + private Color color; + + public TileDecoration(String spriteName, int numberOfVariants) + { + Random rand = new Random(); + if (numberOfVariants > 0) + { + + int spriteVariant = numberOfVariants > 1 ? rand.nextInt(numberOfVariants) + 1 : 1; + sprite = Helper.loadTexture("environment/".replace("/", File.separator) + spriteName + spriteVariant); + } + else + { + sprite = Helper.loadTexture("environment/".replace("/", File.separator) + spriteName); + } + int xLoc = rand.nextInt(Display.getWidth() / sprite.getTextureWidth()) * sprite.getTextureWidth(); + int yLoc = rand.nextInt(Display.getHeight() / sprite.getTextureHeight()) * sprite.getTextureHeight(); + this.box = new Rectangle(xLoc, yLoc, sprite.getTextureWidth(), sprite.getTextureHeight()); + this.color = new Color(255, 255, 255); + } + + @Override + public void draw() + { + Scene s = SceneManager.getInstance().getScene(); + if (!(s instanceof Dungeon)) + { + return; + } + Dungeon dungeon = (Dungeon) s; + int scaleFactor = (dungeon.getBackground().getHitBox().getWidth() / 1024); + this.box.setWidth(sprite.getTextureWidth() * scaleFactor); + this.box.setHeight(sprite.getTextureHeight() * scaleFactor); + + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + + GL11.glColor3f(color.getRed() / 255F, (float) color.getGreen() / 255F, (float) color.getBlue() / 255F); + + // Allows the background to scale w/o blurring + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + GL11.glBegin(GL11.GL_QUADS); + + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(1F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(1F, 1F); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, 1F); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + /** + * @param c the color overlay to apply to the background + *

+ * Changes the background GL color to the specified color + */ + public TileDecoration changeColor(Color c) + { + this.color = c; + return this; + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } +} diff --git a/src/edu/utc/gamedev/Tile/Dungeon/TileExit.java b/src/edu/utc/gamedev/Tile/Dungeon/TileExit.java new file mode 100644 index 0000000..fa640ad --- /dev/null +++ b/src/edu/utc/gamedev/Tile/Dungeon/TileExit.java @@ -0,0 +1,79 @@ +package edu.utc.gamedev.Tile.Dungeon; + +import edu.utc.gamedev.Tile.ITile; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Color; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; + +import java.io.File; + + +public class TileExit implements ITile +{ + + private Texture sprite; + private Rectangle box; + private Color color; + + public TileExit() + { + sprite = Helper.loadTexture("environment/exit".replace("/", File.separator)); + this.box = new Rectangle(0, Display.getHeight() - sprite.getTextureHeight(), sprite.getTextureWidth(), sprite.getTextureHeight()); + color = new Color(255, 255, 255); + } + + + @Override + public void draw() + { + if(this.box.getY() != Display.getHeight() - this.box.getHeight()) + { + this.box.setY(Display.getHeight() - this.box.getHeight()); + } + + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + + GL11.glColor3f(color.getRed() / 255F, (float) color.getGreen() / 255F, (float) color.getBlue() / 255F); + + // Allows the background to scale w/o blurring + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + GL11.glBegin(GL11.GL_QUADS); + + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(1F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(1F, 1F); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, 1F); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } + + public TileExit setColor(Color c) + { + this.color = c; + return this; + } +} diff --git a/src/edu/utc/gamedev/Tile/Dungeon/TilePlatform.java b/src/edu/utc/gamedev/Tile/Dungeon/TilePlatform.java new file mode 100644 index 0000000..5e7d467 --- /dev/null +++ b/src/edu/utc/gamedev/Tile/Dungeon/TilePlatform.java @@ -0,0 +1,23 @@ +package edu.utc.gamedev.Tile.Dungeon; + +import edu.utc.gamedev.Entity.Entity; +import edu.utc.gamedev.Tile.ITile; +import org.lwjgl.util.Rectangle; + +public abstract class TilePlatform implements ITile +{ + @Override + public abstract void draw(); + + @Override + public abstract Rectangle getHitBox(); + + public abstract void update(); + + public boolean entityStanding(Entity e) + { + Rectangle entityHitBox = new Rectangle(e.getHitBox().getX(), e.getHitBox().getY(), e.getHitBox().getWidth(), e.getHitBox().getHeight()); + entityHitBox.translate(0, 1); + return entityHitBox.intersects(getHitBox()); + } +} diff --git a/src/edu/utc/gamedev/Tile/ITile.java b/src/edu/utc/gamedev/Tile/ITile.java new file mode 100644 index 0000000..16e0d00 --- /dev/null +++ b/src/edu/utc/gamedev/Tile/ITile.java @@ -0,0 +1,10 @@ +package edu.utc.gamedev.Tile; + +import org.lwjgl.util.Rectangle; + +public interface ITile +{ + void draw(); + + Rectangle getHitBox(); +} diff --git a/src/edu/utc/gamedev/Tile/Surface/TileGrass.java b/src/edu/utc/gamedev/Tile/Surface/TileGrass.java new file mode 100644 index 0000000..09da2f9 --- /dev/null +++ b/src/edu/utc/gamedev/Tile/Surface/TileGrass.java @@ -0,0 +1,68 @@ +package edu.utc.gamedev.Tile.Surface; + +import edu.utc.gamedev.Tile.ITile; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; + +import java.io.File; + + +public class TileGrass implements ITile +{ + private Texture sprite; + private Rectangle box; + public TileGrass(int x) + { + sprite = Helper.loadTexture("environment/grass".replace("/", File.separator)); + this.box = new Rectangle(x, 0, sprite.getTextureWidth(), sprite.getTextureHeight()); + this.box.setY(Display.getHeight() - this.box.getHeight()); + } + + @Override + public void draw() + { + if (this.box.getY() != Display.getHeight() - this.box.getHeight()) + { + this.box.setY(Display.getHeight() - this.box.getHeight()); + } + + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + + GL11.glColor3f(255F, 255F, 255F); + + // Allows the background to scale w/o blurring + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + GL11.glBegin(GL11.GL_QUADS); + + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(1F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(1F, 1F); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, 1F); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } +} diff --git a/src/edu/utc/gamedev/Tile/Surface/TileHouse.java b/src/edu/utc/gamedev/Tile/Surface/TileHouse.java new file mode 100644 index 0000000..a97cccb --- /dev/null +++ b/src/edu/utc/gamedev/Tile/Surface/TileHouse.java @@ -0,0 +1,67 @@ +package edu.utc.gamedev.Tile.Surface; + +import edu.utc.gamedev.Tile.ITile; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; + +public class TileHouse implements ITile +{ + private Rectangle box; + private Texture sprite; + + public TileHouse() + { + sprite = Helper.loadTexture("environment/house"); + box = new Rectangle(0, 0, sprite.getTextureWidth(), sprite.getTextureHeight()); + + } + + @Override + public void draw() + { + if (box.getX() != (Display.getWidth() - box.getWidth()) - 32) + { + box.setX((Display.getWidth() - box.getWidth()) - 32); + } + if (box.getY() != (Display.getHeight() - box.getHeight())) + { + box.setY(Display.getHeight() - box.getHeight()); + } + + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + + GL11.glColor3f(255F, 255F, 255F); + + GL11.glBegin(GL11.GL_QUADS); + + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(1F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(1F, 1F); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, 1F); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } +} diff --git a/src/edu/utc/gamedev/Tile/Surface/TileWell.java b/src/edu/utc/gamedev/Tile/Surface/TileWell.java new file mode 100644 index 0000000..29d222b --- /dev/null +++ b/src/edu/utc/gamedev/Tile/Surface/TileWell.java @@ -0,0 +1,67 @@ +package edu.utc.gamedev.Tile.Surface; + +import edu.utc.gamedev.Tile.ITile; +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; + +public class TileWell implements ITile +{ + private Rectangle box; + private Texture sprite; + + public TileWell() + { + sprite = Helper.loadTexture("environment/well"); + box = new Rectangle(0, 0, sprite.getTextureWidth(), sprite.getTextureHeight()); + + } + + @Override + public void draw() + { + if (box.getX() != 32) + { + box.setX(32); + } + if (box.getY() != (Display.getHeight() - box.getHeight())) + { + box.setY(Display.getHeight() - box.getHeight()); + } + + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + + GL11.glColor3f(255F, 255F, 255F); + + GL11.glBegin(GL11.GL_QUADS); + + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(1F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(1F, 1F); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, 1F); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } +} diff --git a/src/edu/utc/gamedev/Tile/TileBackground.java b/src/edu/utc/gamedev/Tile/TileBackground.java new file mode 100644 index 0000000..f254b23 --- /dev/null +++ b/src/edu/utc/gamedev/Tile/TileBackground.java @@ -0,0 +1,105 @@ +package edu.utc.gamedev.Tile; + +import edu.utc.gamedev.Util.Helper; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Color; +import org.lwjgl.util.Rectangle; +import org.newdawn.slick.opengl.Texture; +import org.newdawn.slick.opengl.TextureLoader; +import org.newdawn.slick.util.ResourceLoader; + +import java.io.File; +import java.io.IOException; + +public class TileBackground implements ITile +{ + private Texture sprite; + private Rectangle box; + private Color color; + + public TileBackground(String spriteName) + { + sprite = Helper.loadTexture("environment/" + spriteName); + this.box = new Rectangle(0, 0, sprite.getImageWidth(), sprite.getImageHeight()); + this.color = new Color(255, 255, 255); + } + + @Override + public void draw() + { + this.box.setWidth(normalizeDimension(Display.getWidth())); + this.box.setHeight(box.getWidth()); + + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, sprite.getTextureID()); + GL11.glColor3f(color.getRed() / 255F, (float) color.getGreen() / 255F, (float) color.getBlue() / 255F); + + // Allows the background to scale w/o blurring + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + GL11.glBegin(GL11.GL_QUADS); + + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(1F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(1F, 1F); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, 1F); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } + + public void setSprite(String spriteName) + { + Texture temp = sprite; + try + { + temp = TextureLoader.getTexture("png", ResourceLoader.getResourceAsStream("assets/textures/entity/".replace("/", File.separator) + spriteName + ".png")); + } + catch (IOException e) + { + System.err.println("Image not found, not changing"); + } + sprite = temp; + } + + public int normalizeDimension(float dirty) + { + int i = 0; + while (Math.pow(2, i) < dirty) + { + i++; + } + return (int) Math.pow(2, i); + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } + + /** + * @param c the color overlay to apply to the background + *

+ * Changes the background GL color to the specified color + */ + public TileBackground changeColor(Color c) + { + this.color = c; + return this; + } + +} diff --git a/src/edu/utc/gamedev/Tile/TilePlatformBase.java b/src/edu/utc/gamedev/Tile/TilePlatformBase.java new file mode 100644 index 0000000..2b3fae3 --- /dev/null +++ b/src/edu/utc/gamedev/Tile/TilePlatformBase.java @@ -0,0 +1,72 @@ +package edu.utc.gamedev.Tile; + +import edu.utc.gamedev.Tile.Dungeon.TilePlatform; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.Rectangle; + +public class TilePlatformBase extends TilePlatform +{ + public Rectangle box; + int w, h, x, y; + + public TilePlatformBase() + { + super(); + + this.w = 96; + this.h = 8; + this.x = Display.getWidth() / 2 - (w / 2); + this.y = Display.getHeight() - 96; + this.box = new Rectangle(x, y, w, h); + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } + + @Override + public void update() + { + if (this.box.getX() != (Display.getWidth() / 2 - (w / 2)) || this.box.getY() != (Display.getHeight() - 96)) + { + this.x = Display.getWidth() / 2 - (w / 2); + this.y = Display.getHeight() - 96; + this.box.setLocation(x, y); + } + } + + @Override + public void draw() + { + float x = (float) box.getX(); + float y = (float) box.getY(); + float w = (float) box.getWidth(); + float h = (float) box.getHeight(); + + GL11.glColor3f(1F, 1F, 1F); + + // Allows the background to scale w/o blurring + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + GL11.glBegin(GL11.GL_QUADS); + + GL11.glTexCoord2f(0F, 0F); + GL11.glVertex2f(x, y); + + GL11.glTexCoord2f(1F, 0F); + GL11.glVertex2f(x + w, y); + + GL11.glTexCoord2f(1F, 1F); + GL11.glVertex2f(x + w, y + h); + + GL11.glTexCoord2f(0F, 1F); + GL11.glVertex2f(x, y + h); + + GL11.glEnd(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); + } +} diff --git a/src/edu/utc/gamedev/Tile/TilePlatformGround.java b/src/edu/utc/gamedev/Tile/TilePlatformGround.java new file mode 100644 index 0000000..e5c2958 --- /dev/null +++ b/src/edu/utc/gamedev/Tile/TilePlatformGround.java @@ -0,0 +1,35 @@ +package edu.utc.gamedev.Tile; + +import edu.utc.gamedev.Tile.Dungeon.TilePlatform; +import org.lwjgl.opengl.Display; +import org.lwjgl.util.Rectangle; + +public class TilePlatformGround extends TilePlatform +{ + private Rectangle box; + + public TilePlatformGround() + { + this.box = new Rectangle(0, Display.getHeight(), Display.getWidth(), 4); + } + + @Override + public void update() + { + // Update the bounding box so that it stays aligned with the display as it moves / resizes + this.box.setY(Display.getHeight()); + this.box.setWidth(Display.getWidth()); + } + + @Override + public void draw() + { + // Nothing to do here; no sense in drawing the ground, honestly... we don't see it + } + + @Override + public Rectangle getHitBox() + { + return this.box; + } +} diff --git a/src/edu/utc/gamedev/Util/Config.java b/src/edu/utc/gamedev/Util/Config.java new file mode 100644 index 0000000..50015dd --- /dev/null +++ b/src/edu/utc/gamedev/Util/Config.java @@ -0,0 +1,81 @@ +package edu.utc.gamedev.Util; + +/** + * @author: Jose Stovall + *

+ * Config files were learned on my own back when I was Googling stuff previously for my own personal projects + * That being said: this file was written on my own, but how I learned it previous was via Google. + */ + +import java.io.*; +import java.util.Properties; + +public class Config +{ + public int resolutionWidth; + public int resolutionHeight; + public int targetFPS; + public float volume; + + public Config() + { + loadConfig(); + } + + public void loadConfig() + { + try + { + File configFile = new File("settings.properties"); + FileReader reader = new FileReader(configFile); + Properties props = new Properties(); + props.load(reader); + + String[] resolutions = props.getProperty("windowed_resolution", "800x600").split("x"); + this.resolutionWidth = Integer.parseInt(resolutions[0]); + this.resolutionHeight = Integer.parseInt(resolutions[1]); + this.targetFPS = Integer.parseInt(props.getProperty("target_FPS", "100")); + this.volume = Integer.parseInt(props.getProperty("volume", "100")) / 100F; // divide by one hundred because users understand 0 -> 100 better than 0.0 -> 1.0 + + reader.close(); + } + catch (FileNotFoundException fnfex) + { + try + { + createConfig(); + } + catch (IOException e) + { + System.out.println("Everything went wrong with the config. Do you have read/write perms for this folder?"); + } + } + // TODO: Properly handle these exceptions.. + catch (IOException ioEx) + { + } + catch (NullPointerException npe) + { + } + } + + public void createConfig() throws IOException + { + File configFile = new File("settings.properties"); + + Properties props = new Properties(); + props.setProperty("windowed_resolution", "800x600"); + props.setProperty("target_FPS", "100"); + props.setProperty("volume", "100"); + + String[] resolutions = props.getProperty("windowed_resolution", "800x600").split("x"); + this.resolutionWidth = Integer.parseInt(resolutions[0]); + this.resolutionHeight = Integer.parseInt(resolutions[1]); + this.targetFPS = Integer.parseInt(props.getProperty("target_FPS", "100")); + this.volume = Integer.parseInt(props.getProperty("volume", "100")) / 100F; // divide by one hundred because users understand 0->100 better than 0.0 to 1.0 + + FileWriter writer = new FileWriter(configFile); + props.store(writer, "game settings"); + writer.close(); + } +} \ No newline at end of file diff --git a/src/edu/utc/gamedev/Util/FileUtils.java b/src/edu/utc/gamedev/Util/FileUtils.java new file mode 100644 index 0000000..3649e75 --- /dev/null +++ b/src/edu/utc/gamedev/Util/FileUtils.java @@ -0,0 +1,171 @@ +package edu.utc.gamedev.Util; + + +import java.io.*; +import java.net.JarURLConnection; +import java.net.URL; +import java.net.URLConnection; +import java.util.Enumeration; +import java.util.jar.JarEntry; +import java.util.jar.JarFile; + +/** + * SOURCE: https://stackoverflow.com/a/3348150 + */ +public class FileUtils +{ + public static boolean copyFile(final File toCopy, final File destFile) + { + try + { + return FileUtils.copyStream(new FileInputStream(toCopy), new FileOutputStream(destFile)); + } + catch (final FileNotFoundException e) + { + e.printStackTrace(); + } + return false; + } + + private static boolean copyFilesRecusively(final File toCopy, final File destDir) + { + assert destDir.isDirectory(); + + if (!toCopy.isDirectory()) + { + return FileUtils.copyFile(toCopy, new File(destDir, toCopy.getName())); + } + else + { + final File newDestDir = new File(destDir, toCopy.getName()); + if (!newDestDir.exists() && !newDestDir.mkdir()) + { + return false; + } + for (final File child : toCopy.listFiles()) + { + if (!FileUtils.copyFilesRecusively(child, newDestDir)) + { + return false; + } + } + } + return true; + } + + public static boolean copyJarResourcesRecursively(final File destDir, final JarURLConnection jarConnection) throws IOException + { + + final JarFile jarFile = jarConnection.getJarFile(); + + for (final Enumeration e = jarFile.entries(); e.hasMoreElements(); ) + { + final JarEntry entry = e.nextElement(); + if (entry.getName().startsWith(jarConnection.getEntryName())) + { + final String filename = removeStart(entry.getName(), // + jarConnection.getEntryName()); + + final File f = new File(destDir, filename); + if (!entry.isDirectory()) + { + final InputStream entryInputStream = jarFile.getInputStream(entry); + if (!FileUtils.copyStream(entryInputStream, f)) + { + return false; + } + entryInputStream.close(); + } + else + { + if (!FileUtils.ensureDirectoryExists(f)) + { + throw new IOException("Could not create directory: " + f.getAbsolutePath()); + } + } + } + } + return true; + } + + public static boolean copyResourcesRecursively(final URL originUrl, final File destination) + { + try + { + final URLConnection urlConnection = originUrl.openConnection(); + if (urlConnection instanceof JarURLConnection) + { + return FileUtils.copyJarResourcesRecursively(destination, + (JarURLConnection) urlConnection); + } + else + { + return FileUtils.copyFilesRecusively(new File(originUrl.getPath()), + destination); + } + } + catch (final IOException e) + { + e.printStackTrace(); + } + return false; + } + + public static boolean copyStream(final InputStream is, final File f) + { + try + { + return FileUtils.copyStream(is, new FileOutputStream(f)); + } + catch (final FileNotFoundException e) + { + e.printStackTrace(); + } + return false; + } + + private static boolean copyStream(final InputStream is, final OutputStream os) + { + try + { + final byte[] buf = new byte[1024]; + + int len; + while ((len = is.read(buf)) > 0) + { + os.write(buf, 0, len); + } + is.close(); + os.close(); + return true; + } + catch (final IOException e) + { + e.printStackTrace(); + } + return false; + } + + private static boolean ensureDirectoryExists(final File f) + { + return f.exists() || f.mkdir(); + } + + public static String removeStart(String str, String remove) + { + if (isEmpty(str) || isEmpty(remove)) + { + return str; + } + if (str.startsWith(remove)) + { + return str.substring(remove.length()); + } + return str; + } + + public static boolean isEmpty(CharSequence cs) + { + return cs == null || cs.length() == 0; + } +} \ No newline at end of file diff --git a/src/edu/utc/gamedev/Util/Helper.java b/src/edu/utc/gamedev/Util/Helper.java new file mode 100644 index 0000000..4fd10ed --- /dev/null +++ b/src/edu/utc/gamedev/Util/Helper.java @@ -0,0 +1,50 @@ +package edu.utc.gamedev.Util; + +import org.lwjgl.Sys; +import org.lwjgl.util.Color; +import org.newdawn.slick.opengl.Texture; +import org.newdawn.slick.opengl.TextureLoader; +import org.newdawn.slick.util.ResourceLoader; + +import java.io.File; +import java.io.IOException; +import java.util.Random; + +public class Helper +{ + public static long getTime() + { + return (Sys.getTime() * 1000) / Sys.getTimerResolution(); + } + + public static String errTexture() + { + return "assets/textures/err.png".replace("/", File.separator); + } + + public static Color getRandomColor() + { + Random rand = new Random(); + return new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); + } + + public static Texture loadTexture(String str) + { + String location = ("assets/textures/" + str + ".png").replace("/", File.separator); + try + { + return TextureLoader.getTexture("png", ResourceLoader.getResourceAsStream(location)); + } + catch (IOException e) + { + try + { + return TextureLoader.getTexture("png", ResourceLoader.getResourceAsStream(errTexture())); + } + catch (IOException f) + { + throw new RuntimeException(f); + } + } + } +}