diff --git a/.gitignore b/.gitignore index 6143e53..5cf39ff 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +bin +/bin/ + # Compiled class file *.class diff --git a/README.md b/README.md index 7b09e48..6b024a2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,34 @@ # Nihilne -another old abandoned game of mine, ~2015 +another old abandoned game of mine + +*DISCONTINUED*: 2015 + +------------------------------ + +This was my pride and joy for a while. Huge open world survival game +meant to be some kind of blend between a few of my favorite childhood +games. Unfortunately it never passed its steam greenlight and got abandoned. + + +Features: + +* Massive open world, with random generation. +* Lots of items, a few mobs ~ both friendly and hostile +* Camera angle can be rotated left/right 45 degree angles +* Combat +* Day/Night cycle +* Item Construction +* Structure Construction +* Seasons - (rudimentary) + +This was made during my freshman year of college as a way for me to learn +programming in a more concrete way. I don't regret putting in the time I did. + +Screenshots below: +--------------------------------------- + +![Image](res/screenshots/screenshot1.jpg) + +![Image](res/screenshots/screenshot2.jpg) + +![Image](res/screenshots/mainscreen.png) diff --git a/dev/LOGO.ico b/dev/LOGO.ico new file mode 100755 index 0000000..54ae6a4 Binary files /dev/null and b/dev/LOGO.ico differ diff --git a/dev/LOGO.png b/dev/LOGO.png new file mode 100755 index 0000000..6c6022a Binary files /dev/null and b/dev/LOGO.png differ diff --git a/dev/numbers-on-map.png b/dev/numbers-on-map.png new file mode 100755 index 0000000..3e68bea Binary files /dev/null and b/dev/numbers-on-map.png differ diff --git a/dev/pyxeledit/Misc/item_icons.pyxel b/dev/pyxeledit/Misc/item_icons.pyxel new file mode 100755 index 0000000..1a30b77 Binary files /dev/null and b/dev/pyxeledit/Misc/item_icons.pyxel differ diff --git a/dev/pyxeledit/Mobs/goblins.pyxel b/dev/pyxeledit/Mobs/goblins.pyxel new file mode 100755 index 0000000..34c94d2 Binary files /dev/null and b/dev/pyxeledit/Mobs/goblins.pyxel differ diff --git a/dev/pyxeledit/Mobs/rabbits.pyxel b/dev/pyxeledit/Mobs/rabbits.pyxel new file mode 100755 index 0000000..be1aeff Binary files /dev/null and b/dev/pyxeledit/Mobs/rabbits.pyxel differ diff --git a/dev/pyxeledit/Player/attacks.pyxel b/dev/pyxeledit/Player/attacks.pyxel new file mode 100755 index 0000000..9d24abc Binary files /dev/null and b/dev/pyxeledit/Player/attacks.pyxel differ diff --git a/dev/pyxeledit/Player/axe_chops.pyxel b/dev/pyxeledit/Player/axe_chops.pyxel new file mode 100755 index 0000000..462a00e Binary files /dev/null and b/dev/pyxeledit/Player/axe_chops.pyxel differ diff --git a/dev/pyxeledit/Player/get-hits and death.pyxel b/dev/pyxeledit/Player/get-hits and death.pyxel new file mode 100755 index 0000000..0e4c52e Binary files /dev/null and b/dev/pyxeledit/Player/get-hits and death.pyxel differ diff --git a/dev/pyxeledit/Player/idles and walks.pyxel b/dev/pyxeledit/Player/idles and walks.pyxel new file mode 100755 index 0000000..5e8d3f1 Binary files /dev/null and b/dev/pyxeledit/Player/idles and walks.pyxel differ diff --git a/dev/pyxeledit/Player/mines.pyxel b/dev/pyxeledit/Player/mines.pyxel new file mode 100755 index 0000000..06fb2ea Binary files /dev/null and b/dev/pyxeledit/Player/mines.pyxel differ diff --git a/dev/screenshots/lighting - 4-30.png b/dev/screenshots/lighting - 4-30.png new file mode 100755 index 0000000..779f5a8 Binary files /dev/null and b/dev/screenshots/lighting - 4-30.png differ diff --git a/res/data/actionTexts.nihil b/res/data/actionTexts.nihil new file mode 100755 index 0000000..88a5ea8 --- /dev/null +++ b/res/data/actionTexts.nihil @@ -0,0 +1,13 @@ +drop +store +retrieve +equip +unequip +eat +cook +attack +pick up +harvest +chop +mine +pick diff --git a/res/data/itemTexts.nihil b/res/data/itemTexts.nihil new file mode 100755 index 0000000..6532382 --- /dev/null +++ b/res/data/itemTexts.nihil @@ -0,0 +1,15 @@ +grass +flowers +crude axe +logs +crude pickaxe +rocks +sticks +fire +ashes +torch +rabbit carcass +rabbit foot +rot +bones +goblin spear diff --git a/res/data/itemTextsCapitalized.nihil b/res/data/itemTextsCapitalized.nihil new file mode 100755 index 0000000..9121194 --- /dev/null +++ b/res/data/itemTextsCapitalized.nihil @@ -0,0 +1,15 @@ +Grass +Flowers +Crude Axe +Logs +Crude Pickaxe +Rocks +Sticks +Fire +Ashes +Torch +Rabbit Carcass +Rabbit Foot +Rot +Bones +Goblin Spear diff --git a/res/data/mapsdata.nihil b/res/data/mapsdata.nihil new file mode 100755 index 0000000..2e6a8ed Binary files /dev/null and b/res/data/mapsdata.nihil differ diff --git a/res/fonts/gregorian.ttf b/res/fonts/gregorian.ttf new file mode 100755 index 0000000..a1cccff Binary files /dev/null and b/res/fonts/gregorian.ttf differ diff --git a/res/fonts/ponderosa.ttf b/res/fonts/ponderosa.ttf new file mode 100755 index 0000000..89eab2d Binary files /dev/null and b/res/fonts/ponderosa.ttf differ diff --git a/res/saving/settings.nihil b/res/saving/settings.nihil new file mode 100755 index 0000000..e5fd50e Binary files /dev/null and b/res/saving/settings.nihil differ diff --git a/res/screenshots/mainscreen.png b/res/screenshots/mainscreen.png new file mode 100644 index 0000000..829729c Binary files /dev/null and b/res/screenshots/mainscreen.png differ diff --git a/res/screenshots/screenshot1.jpg b/res/screenshots/screenshot1.jpg new file mode 100755 index 0000000..9170958 Binary files /dev/null and b/res/screenshots/screenshot1.jpg differ diff --git a/res/screenshots/screenshot2.jpg b/res/screenshots/screenshot2.jpg new file mode 100644 index 0000000..6a53cc6 Binary files /dev/null and b/res/screenshots/screenshot2.jpg differ diff --git a/res/spritesheets/hud sheets/HUDsheet.nihil b/res/spritesheets/hud sheets/HUDsheet.nihil new file mode 100755 index 0000000..1ceace8 Binary files /dev/null and b/res/spritesheets/hud sheets/HUDsheet.nihil differ diff --git a/res/spritesheets/hud sheets/constructionsheet.nihil b/res/spritesheets/hud sheets/constructionsheet.nihil new file mode 100755 index 0000000..2cf7d82 Binary files /dev/null and b/res/spritesheets/hud sheets/constructionsheet.nihil differ diff --git a/res/spritesheets/hud sheets/secondaryhudsheet.nihil b/res/spritesheets/hud sheets/secondaryhudsheet.nihil new file mode 100755 index 0000000..5323d03 Binary files /dev/null and b/res/spritesheets/hud sheets/secondaryhudsheet.nihil differ diff --git a/res/spritesheets/menu sheets/menubuttonsheet.nihil b/res/spritesheets/menu sheets/menubuttonsheet.nihil new file mode 100755 index 0000000..2861713 Binary files /dev/null and b/res/spritesheets/menu sheets/menubuttonsheet.nihil differ diff --git a/res/spritesheets/menu sheets/settingsbuttonsheet.nihil b/res/spritesheets/menu sheets/settingsbuttonsheet.nihil new file mode 100755 index 0000000..f35fc21 Binary files /dev/null and b/res/spritesheets/menu sheets/settingsbuttonsheet.nihil differ diff --git a/res/spritesheets/menu sheets/splashsheet.nihil b/res/spritesheets/menu sheets/splashsheet.nihil new file mode 100755 index 0000000..ed57fd8 Binary files /dev/null and b/res/spritesheets/menu sheets/splashsheet.nihil differ diff --git a/res/spritesheets/misc sheets/itemiconsheet.nihil b/res/spritesheets/misc sheets/itemiconsheet.nihil new file mode 100755 index 0000000..0320271 Binary files /dev/null and b/res/spritesheets/misc sheets/itemiconsheet.nihil differ diff --git a/res/spritesheets/mob sheets/goblinsheet.nihil b/res/spritesheets/mob sheets/goblinsheet.nihil new file mode 100755 index 0000000..36792ac Binary files /dev/null and b/res/spritesheets/mob sheets/goblinsheet.nihil differ diff --git a/res/spritesheets/mob sheets/rabbitsheet.nihil b/res/spritesheets/mob sheets/rabbitsheet.nihil new file mode 100755 index 0000000..3017b58 Binary files /dev/null and b/res/spritesheets/mob sheets/rabbitsheet.nihil differ diff --git a/res/spritesheets/player items sheets/CRUDE AXE/crudeaxeattacksheet.nihil b/res/spritesheets/player items sheets/CRUDE AXE/crudeaxeattacksheet.nihil new file mode 100755 index 0000000..53d7564 Binary files /dev/null and b/res/spritesheets/player items sheets/CRUDE AXE/crudeaxeattacksheet.nihil differ diff --git a/res/spritesheets/player items sheets/CRUDE AXE/crudeaxechopsheet.nihil b/res/spritesheets/player items sheets/CRUDE AXE/crudeaxechopsheet.nihil new file mode 100755 index 0000000..4de03f5 Binary files /dev/null and b/res/spritesheets/player items sheets/CRUDE AXE/crudeaxechopsheet.nihil differ diff --git a/res/spritesheets/player items sheets/CRUDE AXE/crudeaxegethitsheet.nihil b/res/spritesheets/player items sheets/CRUDE AXE/crudeaxegethitsheet.nihil new file mode 100755 index 0000000..ac482a3 Binary files /dev/null and b/res/spritesheets/player items sheets/CRUDE AXE/crudeaxegethitsheet.nihil differ diff --git a/res/spritesheets/player items sheets/CRUDE AXE/crudeaxesheet.nihil b/res/spritesheets/player items sheets/CRUDE AXE/crudeaxesheet.nihil new file mode 100755 index 0000000..c6382a7 Binary files /dev/null and b/res/spritesheets/player items sheets/CRUDE AXE/crudeaxesheet.nihil differ diff --git a/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxeattacksheet.nihil b/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxeattacksheet.nihil new file mode 100755 index 0000000..1efb3d7 Binary files /dev/null and b/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxeattacksheet.nihil differ diff --git a/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxegethitsheet.nihil b/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxegethitsheet.nihil new file mode 100755 index 0000000..e6fdd84 Binary files /dev/null and b/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxegethitsheet.nihil differ diff --git a/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxeminesheet.nihil b/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxeminesheet.nihil new file mode 100755 index 0000000..081826f Binary files /dev/null and b/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxeminesheet.nihil differ diff --git a/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxesheet.nihil b/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxesheet.nihil new file mode 100755 index 0000000..eeff399 Binary files /dev/null and b/res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxesheet.nihil differ diff --git a/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspearattacksheet.nihil b/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspearattacksheet.nihil new file mode 100755 index 0000000..30b2ac8 Binary files /dev/null and b/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspearattacksheet.nihil differ diff --git a/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspeargethitsheet.nihil b/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspeargethitsheet.nihil new file mode 100755 index 0000000..e05eb2e Binary files /dev/null and b/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspeargethitsheet.nihil differ diff --git a/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspearsheet.nihil b/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspearsheet.nihil new file mode 100755 index 0000000..829e825 Binary files /dev/null and b/res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspearsheet.nihil differ diff --git a/res/spritesheets/player items sheets/TORCH/torchgethitsheet.nihil b/res/spritesheets/player items sheets/TORCH/torchgethitsheet.nihil new file mode 100755 index 0000000..66ab495 Binary files /dev/null and b/res/spritesheets/player items sheets/TORCH/torchgethitsheet.nihil differ diff --git a/res/spritesheets/player items sheets/TORCH/torchwalkidlesheet.nihil b/res/spritesheets/player items sheets/TORCH/torchwalkidlesheet.nihil new file mode 100755 index 0000000..36aad2f Binary files /dev/null and b/res/spritesheets/player items sheets/TORCH/torchwalkidlesheet.nihil differ diff --git a/res/spritesheets/player sheets/baseplayerattacksheet.nihil b/res/spritesheets/player sheets/baseplayerattacksheet.nihil new file mode 100755 index 0000000..fda3a9b Binary files /dev/null and b/res/spritesheets/player sheets/baseplayerattacksheet.nihil differ diff --git a/res/spritesheets/player sheets/playeraxesheet.nihil b/res/spritesheets/player sheets/playeraxesheet.nihil new file mode 100755 index 0000000..29c3de0 Binary files /dev/null and b/res/spritesheets/player sheets/playeraxesheet.nihil differ diff --git a/res/spritesheets/player sheets/playerdeathsheet.nihil b/res/spritesheets/player sheets/playerdeathsheet.nihil new file mode 100755 index 0000000..943470c Binary files /dev/null and b/res/spritesheets/player sheets/playerdeathsheet.nihil differ diff --git a/res/spritesheets/player sheets/playerminesheet.nihil b/res/spritesheets/player sheets/playerminesheet.nihil new file mode 100755 index 0000000..a3ba5ba Binary files /dev/null and b/res/spritesheets/player sheets/playerminesheet.nihil differ diff --git a/res/spritesheets/player sheets/playersheet.nihil b/res/spritesheets/player sheets/playersheet.nihil new file mode 100755 index 0000000..e731bea Binary files /dev/null and b/res/spritesheets/player sheets/playersheet.nihil differ diff --git a/res/spritesheets/world sheets/bouldersheet.nihil b/res/spritesheets/world sheets/bouldersheet.nihil new file mode 100755 index 0000000..10be1af Binary files /dev/null and b/res/spritesheets/world sheets/bouldersheet.nihil differ diff --git a/res/spritesheets/world sheets/debrissheet.nihil b/res/spritesheets/world sheets/debrissheet.nihil new file mode 100755 index 0000000..a67dfe3 Binary files /dev/null and b/res/spritesheets/world sheets/debrissheet.nihil differ diff --git a/res/spritesheets/world sheets/flowersheet.nihil b/res/spritesheets/world sheets/flowersheet.nihil new file mode 100755 index 0000000..a81100a Binary files /dev/null and b/res/spritesheets/world sheets/flowersheet.nihil differ diff --git a/res/spritesheets/world sheets/grasssheet.nihil b/res/spritesheets/world sheets/grasssheet.nihil new file mode 100755 index 0000000..3863937 Binary files /dev/null and b/res/spritesheets/world sheets/grasssheet.nihil differ diff --git a/res/spritesheets/world sheets/oceantilesheet.nihil b/res/spritesheets/world sheets/oceantilesheet.nihil new file mode 100755 index 0000000..7dcb60d Binary files /dev/null and b/res/spritesheets/world sheets/oceantilesheet.nihil differ diff --git a/res/spritesheets/world sheets/saplingsheet.nihil b/res/spritesheets/world sheets/saplingsheet.nihil new file mode 100755 index 0000000..b7af853 Binary files /dev/null and b/res/spritesheets/world sheets/saplingsheet.nihil differ diff --git a/res/spritesheets/world sheets/structuresheet.nihil b/res/spritesheets/world sheets/structuresheet.nihil new file mode 100755 index 0000000..5fffb71 Binary files /dev/null and b/res/spritesheets/world sheets/structuresheet.nihil differ diff --git a/res/spritesheets/world sheets/tilesheet.nihil b/res/spritesheets/world sheets/tilesheet.nihil new file mode 100755 index 0000000..d1c06a6 Binary files /dev/null and b/res/spritesheets/world sheets/tilesheet.nihil differ diff --git a/res/spritesheets/world sheets/treesheet.nihil b/res/spritesheets/world sheets/treesheet.nihil new file mode 100755 index 0000000..abf272a Binary files /dev/null and b/res/spritesheets/world sheets/treesheet.nihil differ diff --git a/scripts/mob_scripts/goblin_ai.py b/scripts/mob_scripts/goblin_ai.py new file mode 100755 index 0000000..997ddf2 --- /dev/null +++ b/scripts/mob_scripts/goblin_ai.py @@ -0,0 +1,90 @@ +###################################################################### +# NOTE: This was the first mob I wrote in Python / Jython. # +# It is excessively commented to provide a reference for other # +# Mobs to be written. # +# # +# 88 88 88 # +# 88 88 "" # +# 88 88 # +# ,adPPYb,d8 ,adPPYba, 88,dPPYba, 88 88 8b,dPPYba, # +# a8" `Y88 a8" "8a 88P' "8a 88 88 88P' `"8a # +# 8b 88 8b d8 88 d8 88 88 88 88 # +# "8a, ,d88 "8a, ,a8" 88b, ,a8" 88 88 88 88 # +# `"YbbdP"Y8 `"YbbdP"' 8Y"Ybbd8"' 88 88 88 88 # +# aa, ,88 # +# "Y8bbdP" # +# # +###################################################################### + +def __goblin_tick__(g): + ### RUN ALL THE ANIMATIONS + g.runAnimations() + + # IF NOT ALIVE, DO AFTER DEATH + if not g.alive(): + __goblin_after_death__(g) + return + + # DISCOVER + if not g.getDiscoveredStatus(): return + + ## IF HEALTH IS ABOVE THE MAX HEALTH, CLAMP + g.normalizeHealth() + + ### IF THE GET HIT TIMER IS POSITIVE, START DECREMENTING IT + g.getHitClock() + + ### COLLISION + g.collision() + + ### POSITION + g.updatePosition() + + ## IDLE ANIMATIONS (idles, walks) + __goblin_idle__(g) + + ### IF IS ALREADY FIGHTING, THEN TICK HIS ATTACK SEQUENCE WITH RUNNING SPEED + if g.inCombat: g.attackSequence(g.runningSpeed) + ## IF NOT ALREADY FIGHTING, AND AGGRO-RADIUS INTERSECTS THE PLAYER, START FIGHTING + elif Utils.intersects(g.center, g.aggroRadius, Player.center): g.startAttackSequence() + + # run bug fixes + g.allBugFixes() + +def __goblin_idle__(g): + ## ONLY WORK IF *NOT* IN COMBAT / RUNNING AWAY + if g.collided or g.runningAway or g.inCombat: return + + ## SUBTRACT FROM ANIMATION TIMER IF DOING IDLE ANIMATION + if g.currentAnimation != ANIMATION.idleWalk: g.idleAnimationTimer -= 1 + + ## SUBTRACT FROM IDLE WALK DISTANCE IF IDLE WALKING + elif g.currentAnimation == ANIMATION.idleWalk: g.distanceToMove -= Utils.pythagoras(g.velX, g.velY) + + ## IF WALKING AROUND, AND HIS DISTANCE IS UP: + if g.distanceToMove <= 0 and g.currentAnimation == ANIMATION.idleWalk: + ### CHANCE OF CONTINUING ON WALKING INSTEAD OF IDLING + if Utils.rand.nextInt(8) == 0: g.idleMove(g.walkingSpeed) + else: #### ELSE SET HIM GOING TO A RANDOM IDLE ANIMATION + g.idleAnimationTimer = Utils.rand.nextInt(200) + 100 + g.velX = g.velY = 0 + if Utils.COIN_FLIP(): g.currentAnimation = ANIMATION.idle1 + else: g.currentAnimation = ANIMATION.idle2 + + ### IF ANIMATION DOES NOT EQUAL IDLE WALK AND THE IDLE ANIMATION TIMER IS UP, SET HIM WALKING + if g.currentAnimation != ANIMATION.idleWalk and g.idleAnimationTimer <= 0: g.idleMove(g.walkingSpeed) + + ### IF GOBLIN IS OUTSIDE OF HIS HOME BUT ISNT COMBAT OR WALKING + if not g.home.contains(g.center): + g.currentAnimation = ANIMATION.idleWalk ## some mobs may have a run animation + ## IF SO FAR AWAY, RUN HOME, ELSE JUST WALK HOME + if(g.center.distance(g.home.center) > 5000): g.goHome(g.runningSpeed) + else: g.goHome(g.walkingSpeed) + +def __goblin_after_death__(g): + ## SUBTRACT FROM DESTROYING TIMER + g.destroyingTimer -= 1 + + ## IF THE TIMER IS UP, DESTROY! + if g.destroyingTimer < 0: g.destroy() + diff --git a/scripts/other/inventory.py b/scripts/other/inventory.py new file mode 100755 index 0000000..d48d1c2 --- /dev/null +++ b/scripts/other/inventory.py @@ -0,0 +1,124 @@ +##### NOTE, ALWAYS CALL ' CHANGE SETTINGS ' AFTER EVERY METHOD +##### THIS HELPS FIX THE BUGGY GUI SYSTEM + +##### NOTE: YOU NEED TO IMPORT * FROM ItemIDs INTERFACE! + +#################################################### +# _____ _ # +# |_ _| | | # +# | | _ ____ _____ _ __ | |_ ___ _ __ _ _ # +# | | | '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | # +# _| |_| | | \ V / __/ | | | || (_) | | | |_| | # +# |_____|_| |_|\_/ \___|_| |_|\__\___/|_| \__, | # +# __/ | # +# |___/ # +#################################################### + + +############### ADDING AND REMOVING ITEMS ####################### +def drop_item(itemId, quantity, durability, slotNumber): + #Make sure items can be dropped: + for i in Player.inventorySlots: + if i.itemId == itemId and i.quantity <= 0: return + + #Create new dropped item to be shown on ground + DroppedItem.dropItemsWithOffsetAsStack(itemId, quantity, 10, Player.center.x, Player.center.y, durability) + + # Remove the item from the inventory + remove_item_with_slot_number(itemId, quantity, slotNumber) + + Inventory.changeSettings() + +def remove_item(itemId, quantity): + for slot in Player.inventorySlots: + if slot.itemId == itemId: + temp = slot.quantity + slot.quantity -= quantity + quantity -= temp + slot.mouseClicked = 0 + + if slot.quantity <= 0: slot.itemId = slot.quantity = slot.durability = 0 + + # if the amount of things to remove has been satisfied + if quantity <= 0: break + Inventory.changeSettings() + +def remove_item_with_slot_number(itemId, quantity, slotNumber): + for i in Player.inventorySlots: + if i.slotNumber == slotNumber: + if i.itemId == itemId: + i.quantity -= quantity + i.mouseClicked = False + if i.quantity <= 0: i.itemId = i.quantity = i.durability = 0 + break + + Inventory.changeSettings() + +def remove_equipment(itemId, quantity, slotNumber): + for i in Player.equipmentSlots: + if i.slotNumber == slotNumber: + if i.itemId == itemId: + i.quantity -= quantity + + #### FOR LIGHTS, TORCHES etc + if i.itemId == TORCH: Player.playerLights.remove(Player.torchLight) + + if i.quantity <= 0: i.itemId = i.quantity = 0 + + i.durability = 0 + i.mouseClicked = False + break + + Inventory.changeSettings() + +def add_item(itemId, quantity, durability): + # CANT ADD ITEM IF THE INVEN IS FULL + if inventory_is_full(itemId, quantity): return + + # IF THE ITEM IS STACKABLE, RUN THIS LOOP + if InvenHelper.isStackable(itemId): + for i in Player.inventorySlots: + if i.itemId == itemId and (i.quantity + quantity) <= InvenHelper.getStackableAmount(itemId): + i.mouseClicked = False + i.quantity += quantity + Inventory.changeSettings() + return + + # IF THE ITEM IS NOT STACKABLE, OR FAILED THE ABOVE LOOP, RUN THIS LOOP + for i in Player.inventorySlots: + if(i.itemId == 0): + i.mouseClicked = False + i.itemId = itemId + i.quantity = quantity + i.durability = durability + i.equippable = InvenHelper.isEquippable(itemId) + Inventory.changeSettings() + return + +############### END ADDING AND REMOVING ITEMS ################################################################# + +################ MISC ################################################################################## + +def inventory_is_full(itemId, quantity): + if InvenHelper.isStackable(itemId): # IF ITEM IS STACKABLE, RUN THIS LOOP + for slot in Player.inventorySlots: + # CHECK IF THE (QUANTITY + THE ADDED QUANTITY) IS <= THE MAX QUANTITY + WOULD_BE_QUANTITY = slot.quantity + quantity + if slot.itemId == itemId and WOULD_BE_QUANTITY <= InvenHelper.getStackableAmount(itemId): return False + + # IF IT IS NOT STACKABLE, OR THE ITEM FAILED THE FIRST LOOP, RUN THIS LOOP + for slot in Player.inventorySlots: + if slot.itemId == NULL_ITEM: return False + + # IF NONE OF THE ABOVE CONDITIONS COULD BE MET, THE INVENTORY MUST BE FULL + return True + +def inventory_contains(itemId, quantity): + count = 0 + for slot in Player.inventorySlots: + if slot.itemId == itemId: count += slot.quantity + return count >= quantity + +############## END MISC ####################################################################################### + + \ No newline at end of file diff --git a/src/_texture/loader/TextureLoader.java b/src/_texture/loader/TextureLoader.java new file mode 100755 index 0000000..20ea956 --- /dev/null +++ b/src/_texture/loader/TextureLoader.java @@ -0,0 +1,145 @@ +package _texture.loader; + +import javax.swing.JOptionPane; + +import fileIO.textures.worldgen.BoulderTextures; +import fileIO.textures.worldgen.DebrisTextures; +import fileIO.textures.worldgen.FlowerTextures; +import fileIO.textures.worldgen.SaplingTextures; +import fileIO.textures.worldgen.TallGrassTextures; +import fileIO.textures.worldgen.TileTextures; +import fileIO.textures.worldgen.TreeTextures; +import items.DroppedItemIconTextures; +import items.ItemIconTextures; +import textures.hud.HUDTextures; +import textures.hud.SecondaryHUDTextures; +import textures.hud.constructionmenu.BaseConstructionMenu; +import textures.menu.MenuButtonTextures; +import textures.menu.MenuSplashSheetTextures; +import textures.mobs.goblin.GoblinTextures; +import textures.mobs.rabbit.RabbitDeathTextures; +import textures.mobs.rabbit.RabbitIdleEatGroundTextures; +import textures.mobs.rabbit.RabbitIdleWalkTextures; +import textures.mobs.rabbit.RabbitRunAwayTextures; +import textures.mobs.rabbit.RabbitSleepTextures; +import textures.player.BasePlayerGetHitAndDeath; +import textures.player.PlayerAxeChopTextures; +import textures.player.PlayerIdleTextures; +import textures.player.PlayerMineTextures; +import textures.player.PlayerWalkTextures; +import textures.player.attacks.BasePlayerAttackTextures; +import textures.player.attacks.CrudeAxeAttackTextures; +import textures.player.attacks.CrudePickAxeAttackTextures; +import textures.player.items.crudeaxe.CrudeAxeChopTextures; +import textures.player.items.crudeaxe.CrudeAxeGetHitTextures; +import textures.player.items.crudeaxe.CrudeAxeIdleTextures; +import textures.player.items.crudeaxe.CrudeAxeWalkTextures; +import textures.player.items.crudepickaxe.CrudePickAxeGetHitTextures; +import textures.player.items.crudepickaxe.CrudePickaxeIdleTextures; +import textures.player.items.crudepickaxe.CrudePickaxeMineTextures; +import textures.player.items.crudepickaxe.CrudePickaxeWalkTextures; +import textures.player.items.goblinspear.GoblinSpearTextures; +import textures.player.items.torch.TorchGetHitTextures; +import textures.player.items.torch.TorchIdleTextures; +import textures.player.items.torch.TorchWalkTextures; +import textures.settings.SettingsTextures; +import textures.structures.StructuresTextures; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class TextureLoader { + + public static void initSplashSheet() { + MenuSplashSheetTextures.getTextures(Utils.loadImage("/splashsheet.nihil")); + } + + public static void init() { + final long then = System.nanoTime(); + + try{ + //textures.mobs.rabbit + RabbitIdleWalkTextures.getTextures(Utils.loadImage("/rabbitsheet.nihil")); + RabbitIdleEatGroundTextures.getTextures(Utils.loadImage("/rabbitsheet.nihil")); + RabbitRunAwayTextures.getTextures(Utils.loadImage("/rabbitsheet.nihil")); + RabbitSleepTextures.getTextures(Utils.loadImage("/rabbitsheet.nihil")); + RabbitDeathTextures.getTextures(Utils.loadImage("/rabbitsheet.nihil")); + + // textures.mobs.goblin + GoblinTextures.getTextures(Utils.loadImage("/goblinsheet.nihil")); + + // textures.structures + StructuresTextures.getTextures(Utils.loadImage("/structuresheet.nihil")); + + // textures.worldgen + BoulderTextures.getTextures(Utils.loadImage("/bouldersheet.nihil")); + DebrisTextures.getTextures(Utils.loadImage("/debrissheet.nihil")); + FlowerTextures.getTextures(Utils.loadImage("/flowersheet.nihil")); + TallGrassTextures.getTextures(Utils.loadImage("/grasssheet.nihil")); + TreeTextures.getTextures(Utils.loadImage("/treesheet.nihil")); + SaplingTextures.getTextures(Utils.loadImage("/saplingsheet.nihil")); + + // Tiles + TileTextures.getTextures(Utils.loadImage("/tilesheet.nihil")); + TileTextures.getOceanTextures(Utils.loadImage("/oceantilesheet.nihil")); + + // textures.hud + HUDTextures.getTextures(Utils.loadImage("/HUDsheet.nihil")); + SecondaryHUDTextures.getTextures(Utils.loadImage("/secondaryhudsheet.nihil")); + BaseConstructionMenu.getTextures(Utils.loadImage("/constructionsheet.nihil")); + + // textures.items + ItemIconTextures.getTextures(Utils.loadImage("/itemiconsheet.nihil")); + DroppedItemIconTextures.getTextures(); + + // textures.player + PlayerIdleTextures.getTextures(Utils.loadImage("/playersheet.nihil")); + PlayerWalkTextures.getTextures(Utils.loadImage("/playersheet.nihil")); + PlayerAxeChopTextures.getTextures(Utils.loadImage("/playeraxesheet.nihil")); + PlayerMineTextures.getTextures(Utils.loadImage("/playerminesheet.nihil")); + BasePlayerGetHitAndDeath.getTextures(Utils.loadImage("/playerdeathsheet.nihil")); + + // textures.player.attacks + BasePlayerAttackTextures.getTextures(Utils.loadImage("/baseplayerattacksheet.nihil")); + CrudeAxeAttackTextures.getTextures(Utils.loadImage("/crudeaxeattacksheet.nihil")); + CrudePickAxeAttackTextures.getTextures(Utils.loadImage("/crudepickaxeattacksheet.nihil")); + + // textures.player.items.crudeaxe + CrudeAxeIdleTextures.getTextures(Utils.loadImage("/crudeaxesheet.nihil")); + CrudeAxeWalkTextures.getTextures(Utils.loadImage("/crudeaxesheet.nihil")); + CrudeAxeChopTextures.getTextures(Utils.loadImage("/crudeaxechopsheet.nihil")); + CrudeAxeGetHitTextures.getTextures(Utils.loadImage("/crudeaxegethitsheet.nihil")); + + // textures.player.items.crudepickaxe + CrudePickaxeIdleTextures.getTextures(Utils.loadImage("/crudepickaxesheet.nihil")); + CrudePickaxeWalkTextures.getTextures(Utils.loadImage("/crudepickaxesheet.nihil")); + CrudePickaxeMineTextures.getTextures(Utils.loadImage("/crudepickaxeminesheet.nihil")); + CrudePickAxeGetHitTextures.getTextures(Utils.loadImage("/crudepickaxegethitsheet.nihil")); + + // textures.player.items.torch + TorchIdleTextures.getTextures(Utils.loadImage("/torchwalkidlesheet.nihil")); + TorchWalkTextures.getTextures(Utils.loadImage("/torchwalkidlesheet.nihil")); + TorchGetHitTextures.getTextures(Utils.loadImage("/torchgethitsheet.nihil")); + + // textures.player.items.goblinspear + GoblinSpearTextures.getIdlesWalksTextures(Utils.loadImage("/goblinspearsheet.nihil")); + GoblinSpearTextures.getAttackTextures(Utils.loadImage("/goblinspearattacksheet.nihil")); + GoblinSpearTextures.getHitsTextures(Utils.loadImage("/goblinspeargethitsheet.nihil")); + + + // textures.settings + SettingsTextures.getTextures(Utils.loadImage("/settingsbuttonsheet.nihil")); + + // textures.menu + MenuButtonTextures.getTextures(Utils.loadImage("/menubuttonsheet.nihil")); + MenuSplashSheetTextures.getTextures(Utils.loadImage("/splashsheet.nihil")); + } catch (Exception e) { + e.printStackTrace(); + JOptionPane.showMessageDialog(null, "Failed to load game textures. Yell at the developer."); System.exit(1); + } + + System.out.println("Textures loaded. Time Taken: " + Utils.df.format((System.nanoTime() - then) / Utils.second) + " seconds"); + } +} diff --git a/src/_texture/loader/Textures.java b/src/_texture/loader/Textures.java new file mode 100755 index 0000000..2b2792e --- /dev/null +++ b/src/_texture/loader/Textures.java @@ -0,0 +1,64 @@ +package _texture.loader; + +import java.awt.image.BufferedImage; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class Textures { + + public static final BufferedImage[] + // MENU + menuButtonSheet = new BufferedImage[10], + settingsButtonSheet = new BufferedImage[54], + splashSheet = new BufferedImage[2], + + // HUD + hudSheet = new BufferedImage[11], + secondaryHUDSheet = new BufferedImage[45], + baseConstructionSheet = new BufferedImage[20], + lightingSheet = new BufferedImage[5], + + // ITEMS + itemIconSheet = new BufferedImage[150], + droppedItemIconSheet = new BufferedImage[itemIconSheet.length], /* store scaled versions of itemIconSheet here */ + + // BASE PLAYER ANIMATIONS + playerSheet = new BufferedImage[80], + basePlayerAxeSheet = new BufferedImage[32], + basePlayerPickaxeSheet = new BufferedImage[32], + basePlayerGetHitAndDeath = new BufferedImage[40], + + // PLAYER ATTACK ANIMATIONS + basePlayerAttackSheet = new BufferedImage[32], + crudeAxeAttackSheet = new BufferedImage[32], + crudePickAxeAttackSheet = new BufferedImage[32], + + // ITEMS + crudeAxeSheet = new BufferedImage[88], + crudeAxeChopSheet = new BufferedImage[32], + + crudePickaxeSheet = new BufferedImage[88], + crudePickaxeMineSheet = new BufferedImage[32], + + torchSheet = new BufferedImage[88], + + goblinSpearSheet = new BufferedImage[120], + + // Structures + structureSheet = new BufferedImage[100], + + // Mobs + rabbitSheet = new BufferedImage[144], + goblinSheet = new BufferedImage[200], + + // WORLD GEN + tileSheet = new BufferedImage[50], + treeSheet = new BufferedImage[10], + boulderSheet = new BufferedImage[10], + debrisSheet = new BufferedImage[10], + flowerSheet = new BufferedImage[16], + grassSheet = new BufferedImage[14], + saplingSheet = new BufferedImage[7]; +} diff --git a/src/animations/PlayerAnimationSequence.java b/src/animations/PlayerAnimationSequence.java new file mode 100755 index 0000000..ee5031e --- /dev/null +++ b/src/animations/PlayerAnimationSequence.java @@ -0,0 +1,141 @@ +package animations; + +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; + +import interfaces.Directions; +import player.Player; +import utils.Animation; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerAnimationSequence implements Directions { + + public final Animation[] idles, walks, axeChops, mines; + public final BufferedImage[] getHits; + + public PlayerAnimationSequence(Animation[] idles, Animation[] walks, Animation[] axeChops, Animation[] mines, BufferedImage[] getHits) { + this.idles = idles; + this.walks = walks; + this.axeChops = axeChops; + this.mines = mines; + this.getHits = getHits; + } + +/************************ RUNS *********************************************/ + + public final void runIdle() { + switch(Player.facing){ + case NORTH: idles[0].runAnimation(); break; + case NORTHEAST: idles[1].runAnimation(); break; + case EAST: idles[2].runAnimation(); break; + case SOUTHEAST: idles[3].runAnimation(); break; + case SOUTH: idles[4].runAnimation(); break; + case SOUTHWEST: idles[5].runAnimation(); break; + case WEST: idles[6].runAnimation(); break; + case NORTHWEST: idles[7].runAnimation(); break; + } + } + + public final void runWalk() { + switch(Player.facing){ + case NORTH: walks[0].runAnimation(); break; + case NORTHEAST: walks[1].runAnimation(); break; + case EAST: walks[2].runAnimation(); break; + case SOUTHEAST: walks[3].runAnimation(); break; + case SOUTH: walks[4].runAnimation(); break; + case SOUTHWEST: walks[5].runAnimation(); break; + case WEST: walks[6].runAnimation(); break; + case NORTHWEST: walks[7].runAnimation(); break; + } + } + + public final void runChop() { + switch(Player.facing){ + case NORTH: axeChops[0].runAnimation(); break; + case NORTHEAST: axeChops[1].runAnimation(); break; + case EAST: axeChops[2].runAnimation(); break; + case SOUTHEAST: axeChops[3].runAnimation(); break; + case SOUTH: axeChops[4].runAnimation(); break; + case SOUTHWEST: axeChops[5].runAnimation(); break; + case WEST: axeChops[6].runAnimation(); break; + case NORTHWEST: axeChops[7].runAnimation(); break; + } + } + + public final void runMine() { + switch(Player.facing){ + case NORTH: mines[0].runAnimation(); break; + case NORTHEAST: mines[1].runAnimation(); break; + case EAST: mines[2].runAnimation(); break; + case SOUTHEAST: mines[3].runAnimation(); break; + case SOUTH: mines[4].runAnimation(); break; + case SOUTHWEST: mines[5].runAnimation(); break; + case WEST: mines[6].runAnimation(); break; + case NORTHWEST: mines[7].runAnimation(); break; + } + } + +/************************* END RUNS *******************************************/ + +/******************** RENDERS **********************************************/ + public final void renderIdle(final Graphics2D g2d) { + switch(Player.facing){ + case NORTH: idles[0].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case NORTHEAST: idles[1].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case EAST: idles[2].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTHEAST: idles[3].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTH: idles[4].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTHWEST: idles[5].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case WEST: idles[6].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case NORTHWEST: idles[7].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + } + } + + public final void renderWalk(final Graphics2D g2d) { + switch(Player.facing){ + case NORTH: walks[0].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case NORTHEAST: walks[1].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case EAST: walks[2].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTHEAST: walks[3].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTH: walks[4].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTHWEST: walks[5].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case WEST: walks[6].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case NORTHWEST: walks[7].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + } + } + + public final void renderChop(final Graphics2D g2d) { + switch(Player.facing){ + case NORTH: axeChops[0].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case NORTHEAST: axeChops[1].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case EAST: axeChops[2].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTHEAST: axeChops[3].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTH: axeChops[4].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTHWEST: axeChops[5].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case WEST: axeChops[6].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case NORTHWEST: axeChops[7].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + } + } + + public final void renderMine(final Graphics2D g2d) { + switch(Player.facing){ + case NORTH: mines[0].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case NORTHEAST: mines[1].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case EAST: mines[2].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTHEAST: mines[3].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTH: mines[4].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case SOUTHWEST: mines[5].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case WEST: mines[6].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + case NORTHWEST: mines[7].drawAnimation(g2d, Player.pos.x - Player.width/2, Player.pos.y - Player.height / 2); break; + } + } + + public final void renderGetHit(final Graphics2D g2d) { + g2d.drawImage(getHits[Player.facing - 1], (int)(Player.pos.x - Player.width/2), (int)(Player.pos.y - Player.height/2), null); + } + +/********************************************************************/ +} diff --git a/src/animations/PlayerAnimationUtils.java b/src/animations/PlayerAnimationUtils.java new file mode 100755 index 0000000..4034f8b --- /dev/null +++ b/src/animations/PlayerAnimationUtils.java @@ -0,0 +1,115 @@ +package animations; + +import engine.Game; +import engine.Handler; +import hud.inventory.InvenHelper; +import interfaces.Directions; +import interfaces.ItemIDs; +import interfaces.PlayerAnimationIDs; +import player.Player; +import utils.Animation; +import utils.Point2f; +import utils.Utils; +import world.Boulder; +import world.Tree; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerAnimationUtils implements Directions, PlayerAnimationIDs, ItemIDs { + + private static int TEMP_ANIMATION; + + public final static void calc() { + + // --------- GET HIT ------------------ // + if(Player.getHitTimer > 0) { + Player.getHitTimer--; + TEMP_ANIMATION = Player.currentAnimation; + Player.currentAnimation = GET_HIT; + return; + } else if(Player.getHitTimer == 0) { + Player.getHitTimer--; + Player.currentAnimation = TEMP_ANIMATION; + return; + } + // -------- END GET HIT --------------- // + + if (Player.treeCollided && Player.using && InvenHelper.isAxe(Player.equipmentSlots[HAND_SLOT].itemId)) { + Player.currentAnimation = AXE_CHOP; + + for(final Tree i : Handler.trees) /* find which tree is being chopped and orient player towards it */ + if(i.playerCollided){ + Player.facing = determineFacing(Player.center, i.center, Player.radius); + break; + } + } + + else if (Player.boulderCollided && Player.using && InvenHelper.isPickaxe(Player.equipmentSlots[HAND_SLOT].itemId)) { + Player.currentAnimation = MINE_ROCK; + + for(final Boulder i : Handler.boulders) /* find which tree is being chopped and orient player towards it */ + if(i.playerCollided){ + Player.facing = determineFacing(Player.center, i.center, Player.radius); + break; + } + } + + else if (Player.velX != 0 || Player.velY != 0) Player.currentAnimation = WALK; + else if (Player.velX == 0 && Player.velY == 0) Player.currentAnimation = IDLE; + } + + + // NO IDEA IF THIS NEEDS TO BE SYNCHRONIZED, I HAD IT BEFORE, DONT KNOW WHY + // TOOK IT OFF, NOT NOTICING ANYTHING WRONG YET. MAY STILL NEED IT. BEWARE. + public final static void resetAll(){ +// Player.animate = false; // NO FKN IDEA WHY I HAD THIS EITHER, MAY NEED IT IDK + resetIdles(); resetWalking(); resetAxeChops(); resetPickaxeMines(); +// Player.animate = true; + } + + public final static void resetIdles(){ + for(final Animation i : PlayerAnimations.base.idles) i.restartAnimation(); + for(final Animation i : PlayerAnimations.crudeAxe.idles) i.restartAnimation(); + for(final Animation i : PlayerAnimations.crudePickaxe.idles) i.restartAnimation(); + for(final Animation i : PlayerAnimations.torch.idles) i.restartAnimation(); + for(final Animation i : PlayerAnimations.goblinSpear.idles) i.restartAnimation(); + } + + public final static void resetWalking(){ + for(final Animation i : PlayerAnimations.base.walks) i.restartAnimation(); + for(final Animation i : PlayerAnimations.crudeAxe.walks) i.restartAnimation(); + for(final Animation i : PlayerAnimations.crudePickaxe.walks) i.restartAnimation(); + for(final Animation i : PlayerAnimations.torch.walks) i.restartAnimation(); + for(final Animation i : PlayerAnimations.goblinSpear.walks) i.restartAnimation(); + } + + public final static void resetAxeChops(){ + for(final Animation i : PlayerAnimations.base.axeChops) i.restartAnimation(); + for(final Animation i : PlayerAnimations.crudeAxe.axeChops) i.restartAnimation(); + } + + public final static void resetPickaxeMines(){ + for(final Animation i : PlayerAnimations.base.mines) i.restartAnimation(); + for(final Animation i : PlayerAnimations.crudePickaxe.mines) i.restartAnimation(); + } + + public final static int determineFacing(final Point2f point1, final Point2f point2, final float p1Radius){ + final Point2f p1 = Utils.rotatePoint(new Point2f(point1.x, point1.y), Utils._45*(Game.rotation - 1)); + final Point2f p2 = Utils.rotatePoint(new Point2f(point2.x, point2.y), Utils._45*(Game.rotation - 1)); + + if(p2.x - p1Radius > p1.x && p2.y - p1Radius > p1.y) return SOUTHEAST; + else if(p2.x - p1Radius > p1.x && p2.y + p1Radius < p1.y) return NORTHEAST; + else if(p2.x - p1Radius > p1.x) return EAST; + + else if(p2.x + p1Radius < p1.x && p2.y + p1Radius < p1.y) return NORTHWEST; + else if(p2.x + p1Radius < p1.x && p2.y - p1Radius > p1.y) return SOUTHWEST; + else if(p2.x + p1Radius < p1.x) return WEST; + + else if(p2.y - p1Radius > p1.y) return SOUTH; + else if(p2.y + p1Radius < p1.y) return NORTH; + else return NORTH; + } + +} diff --git a/src/animations/PlayerAnimations.java b/src/animations/PlayerAnimations.java new file mode 100755 index 0000000..c1558fd --- /dev/null +++ b/src/animations/PlayerAnimations.java @@ -0,0 +1,272 @@ +package animations; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Animation; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerAnimations { + +/******************* PLAYER DEATH *************************************************************************/ + private static final int DEATH_ANIMATION_SPEED = 16; + public static final Animation[] deaths = { + new Animation(DEATH_ANIMATION_SPEED, Textures.basePlayerGetHitAndDeath[8], Textures.basePlayerGetHitAndDeath[9], Textures.basePlayerGetHitAndDeath[10], Textures.basePlayerGetHitAndDeath[11]), + new Animation(DEATH_ANIMATION_SPEED, Textures.basePlayerGetHitAndDeath[12], Textures.basePlayerGetHitAndDeath[13], Textures.basePlayerGetHitAndDeath[14], Textures.basePlayerGetHitAndDeath[15]), + new Animation(DEATH_ANIMATION_SPEED, Textures.basePlayerGetHitAndDeath[16], Textures.basePlayerGetHitAndDeath[17], Textures.basePlayerGetHitAndDeath[18], Textures.basePlayerGetHitAndDeath[19]), + new Animation(DEATH_ANIMATION_SPEED, Textures.basePlayerGetHitAndDeath[20], Textures.basePlayerGetHitAndDeath[21], Textures.basePlayerGetHitAndDeath[22], Textures.basePlayerGetHitAndDeath[23]), + new Animation(DEATH_ANIMATION_SPEED, Textures.basePlayerGetHitAndDeath[24], Textures.basePlayerGetHitAndDeath[25], Textures.basePlayerGetHitAndDeath[26], Textures.basePlayerGetHitAndDeath[27]), + new Animation(DEATH_ANIMATION_SPEED, Textures.basePlayerGetHitAndDeath[28], Textures.basePlayerGetHitAndDeath[29], Textures.basePlayerGetHitAndDeath[30], Textures.basePlayerGetHitAndDeath[31]), + new Animation(DEATH_ANIMATION_SPEED, Textures.basePlayerGetHitAndDeath[32], Textures.basePlayerGetHitAndDeath[33], Textures.basePlayerGetHitAndDeath[34], Textures.basePlayerGetHitAndDeath[35]), + new Animation(DEATH_ANIMATION_SPEED, Textures.basePlayerGetHitAndDeath[36], Textures.basePlayerGetHitAndDeath[37], Textures.basePlayerGetHitAndDeath[38], Textures.basePlayerGetHitAndDeath[39]), + }; +/****************** END PLAYER DEATH *************************************************************************/ + +/**************** ANIMATION RATES *****************************************************************************/ + private static final int IDLE_ANIMATION_SPEED = 16, WALKS_ANIMATION_SPEED = 5, AXE_CHOP_RATE = 12, PICKAXE_MINE_ANIMATION_RATE = 14; +/*************** END ANIMATION RATES *************************************************************************/ + + +/** ~~~~~~~~~~~~~~~~~~ BASE PLAYER ANIMATIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + public final static PlayerAnimationSequence base = new PlayerAnimationSequence( + // IDLES + new Animation[] { + new Animation(IDLE_ANIMATION_SPEED, Textures.playerSheet[4], Textures.playerSheet[5], Textures.playerSheet[6], Textures.playerSheet[7]), + new Animation(IDLE_ANIMATION_SPEED, Textures.playerSheet[20], Textures.playerSheet[21], Textures.playerSheet[22],Textures.playerSheet[23]), + new Animation(IDLE_ANIMATION_SPEED, Textures.playerSheet[12], Textures.playerSheet[13], Textures.playerSheet[14], Textures.playerSheet[15]), + new Animation(IDLE_ANIMATION_SPEED, Textures.playerSheet[28], Textures.playerSheet[29], Textures.playerSheet[30], Textures.playerSheet[31]), + new Animation(IDLE_ANIMATION_SPEED, Textures.playerSheet[0], Textures.playerSheet[1], Textures.playerSheet[2], Textures.playerSheet[3]), + new Animation(IDLE_ANIMATION_SPEED, Textures.playerSheet[24], Textures.playerSheet[25], Textures.playerSheet[26], Textures.playerSheet[27]), + new Animation(IDLE_ANIMATION_SPEED, Textures.playerSheet[8], Textures.playerSheet[9], Textures.playerSheet[10], Textures.playerSheet[11]), + new Animation(IDLE_ANIMATION_SPEED, Textures.playerSheet[16], Textures.playerSheet[17], Textures.playerSheet[18], Textures.playerSheet[19]) + }, + // WALKS + new Animation[] { + new Animation(WALKS_ANIMATION_SPEED, Textures.playerSheet[38], Textures.playerSheet[39], Textures.playerSheet[40], Textures.playerSheet[41], Textures.playerSheet[42], Textures.playerSheet[43]), + new Animation(WALKS_ANIMATION_SPEED, Textures.playerSheet[62], Textures.playerSheet[63], Textures.playerSheet[64], Textures.playerSheet[65], Textures.playerSheet[66], Textures.playerSheet[67]), + new Animation(WALKS_ANIMATION_SPEED, Textures.playerSheet[50], Textures.playerSheet[51], Textures.playerSheet[52], Textures.playerSheet[53], Textures.playerSheet[54], Textures.playerSheet[55]), + new Animation(WALKS_ANIMATION_SPEED, Textures.playerSheet[74], Textures.playerSheet[75], Textures.playerSheet[76], Textures.playerSheet[77], Textures.playerSheet[78], Textures.playerSheet[79]), + new Animation(WALKS_ANIMATION_SPEED, Textures.playerSheet[32], Textures.playerSheet[33], Textures.playerSheet[34], Textures.playerSheet[35], Textures.playerSheet[36], Textures.playerSheet[37]), + new Animation(WALKS_ANIMATION_SPEED, Textures.playerSheet[68], Textures.playerSheet[69], Textures.playerSheet[70], Textures.playerSheet[71], Textures.playerSheet[72], Textures.playerSheet[73]), + new Animation(WALKS_ANIMATION_SPEED, Textures.playerSheet[44], Textures.playerSheet[45], Textures.playerSheet[46], Textures.playerSheet[47], Textures.playerSheet[48], Textures.playerSheet[49]), + new Animation(WALKS_ANIMATION_SPEED, Textures.playerSheet[56], Textures.playerSheet[57], Textures.playerSheet[58], Textures.playerSheet[59], Textures.playerSheet[60], Textures.playerSheet[61]) + }, + // AXE CHOPS + new Animation[] { + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[4],Textures.basePlayerAxeSheet[5],Textures.basePlayerAxeSheet[6],Textures.basePlayerAxeSheet[7]), + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[20],Textures.basePlayerAxeSheet[21],Textures.basePlayerAxeSheet[22],Textures.basePlayerAxeSheet[23]), + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[12],Textures.basePlayerAxeSheet[13],Textures.basePlayerAxeSheet[14],Textures.basePlayerAxeSheet[15]), + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[28],Textures.basePlayerAxeSheet[29],Textures.basePlayerAxeSheet[30],Textures.basePlayerAxeSheet[31]), + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[0],Textures.basePlayerAxeSheet[1],Textures.basePlayerAxeSheet[2],Textures.basePlayerAxeSheet[3]), + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[24],Textures.basePlayerAxeSheet[25],Textures.basePlayerAxeSheet[26],Textures.basePlayerAxeSheet[27]), + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[8],Textures.basePlayerAxeSheet[9],Textures.basePlayerAxeSheet[10],Textures.basePlayerAxeSheet[11]), + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[16],Textures.basePlayerAxeSheet[17],Textures.basePlayerAxeSheet[18],Textures.basePlayerAxeSheet[19]), + new Animation(AXE_CHOP_RATE, Textures.basePlayerAxeSheet[28],Textures.basePlayerAxeSheet[29],Textures.basePlayerAxeSheet[30],Textures.basePlayerAxeSheet[31]), + }, + // MINES + new Animation[] { + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[4],Textures.basePlayerPickaxeSheet[5],Textures.basePlayerPickaxeSheet[6],Textures.basePlayerPickaxeSheet[7]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[20],Textures.basePlayerPickaxeSheet[21],Textures.basePlayerPickaxeSheet[22],Textures.basePlayerPickaxeSheet[23]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[12],Textures.basePlayerPickaxeSheet[13],Textures.basePlayerPickaxeSheet[14],Textures.basePlayerPickaxeSheet[15]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[28],Textures.basePlayerPickaxeSheet[29],Textures.basePlayerPickaxeSheet[30],Textures.basePlayerPickaxeSheet[31]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[0],Textures.basePlayerPickaxeSheet[1],Textures.basePlayerPickaxeSheet[2],Textures.basePlayerPickaxeSheet[3]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[24],Textures.basePlayerPickaxeSheet[25],Textures.basePlayerPickaxeSheet[26],Textures.basePlayerPickaxeSheet[27]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[8],Textures.basePlayerPickaxeSheet[9],Textures.basePlayerPickaxeSheet[10],Textures.basePlayerPickaxeSheet[11]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[16],Textures.basePlayerPickaxeSheet[17],Textures.basePlayerPickaxeSheet[18],Textures.basePlayerPickaxeSheet[19]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.basePlayerPickaxeSheet[28],Textures.basePlayerPickaxeSheet[29],Textures.basePlayerPickaxeSheet[30],Textures.basePlayerPickaxeSheet[31]), + }, + // GET HITS + new BufferedImage[] { + Textures.basePlayerGetHitAndDeath[0], + Textures.basePlayerGetHitAndDeath[1], + Textures.basePlayerGetHitAndDeath[2], + Textures.basePlayerGetHitAndDeath[3], + Textures.basePlayerGetHitAndDeath[4], + Textures.basePlayerGetHitAndDeath[5], + Textures.basePlayerGetHitAndDeath[6], + Textures.basePlayerGetHitAndDeath[7] + } + ); +/** ~~~~~~~~~~~~~~~~~~~~~~ END BASE PLAYER ANIMATIONS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ + + public final static PlayerAnimationSequence crudeAxe = new PlayerAnimationSequence( + new Animation[] { + new Animation(IDLE_ANIMATION_SPEED, Textures.crudeAxeSheet[4], Textures.crudeAxeSheet[5], Textures.crudeAxeSheet[6], Textures.crudeAxeSheet[7]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudeAxeSheet[20], Textures.crudeAxeSheet[21], Textures.crudeAxeSheet[22],Textures.crudeAxeSheet[23]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudeAxeSheet[12], Textures.crudeAxeSheet[13], Textures.crudeAxeSheet[14], Textures.crudeAxeSheet[15]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudeAxeSheet[28], Textures.crudeAxeSheet[29], Textures.crudeAxeSheet[30], Textures.crudeAxeSheet[31]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudeAxeSheet[0], Textures.crudeAxeSheet[1], Textures.crudeAxeSheet[2], Textures.crudeAxeSheet[3]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudeAxeSheet[24], Textures.crudeAxeSheet[25], Textures.crudeAxeSheet[26], Textures.crudeAxeSheet[27]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudeAxeSheet[8], Textures.crudeAxeSheet[9], Textures.crudeAxeSheet[10], Textures.crudeAxeSheet[11]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudeAxeSheet[16], Textures.crudeAxeSheet[17], Textures.crudeAxeSheet[18], Textures.crudeAxeSheet[19]) + }, + + new Animation[] { + new Animation(WALKS_ANIMATION_SPEED, Textures.crudeAxeSheet[38], Textures.crudeAxeSheet[39], Textures.crudeAxeSheet[40], Textures.crudeAxeSheet[41], Textures.crudeAxeSheet[42], Textures.crudeAxeSheet[43]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudeAxeSheet[62], Textures.crudeAxeSheet[63], Textures.crudeAxeSheet[64], Textures.crudeAxeSheet[65], Textures.crudeAxeSheet[66], Textures.crudeAxeSheet[67]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudeAxeSheet[50], Textures.crudeAxeSheet[51], Textures.crudeAxeSheet[52], Textures.crudeAxeSheet[53], Textures.crudeAxeSheet[54], Textures.crudeAxeSheet[55]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudeAxeSheet[74], Textures.crudeAxeSheet[75], Textures.crudeAxeSheet[76], Textures.crudeAxeSheet[77], Textures.crudeAxeSheet[78], Textures.crudeAxeSheet[79]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudeAxeSheet[32], Textures.crudeAxeSheet[33], Textures.crudeAxeSheet[34], Textures.crudeAxeSheet[35], Textures.crudeAxeSheet[36], Textures.crudeAxeSheet[37]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudeAxeSheet[68], Textures.crudeAxeSheet[69], Textures.crudeAxeSheet[70], Textures.crudeAxeSheet[71], Textures.crudeAxeSheet[72], Textures.crudeAxeSheet[73]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudeAxeSheet[44], Textures.crudeAxeSheet[45], Textures.crudeAxeSheet[46], Textures.crudeAxeSheet[47], Textures.crudeAxeSheet[48], Textures.crudeAxeSheet[49]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudeAxeSheet[56], Textures.crudeAxeSheet[57], Textures.crudeAxeSheet[58], Textures.crudeAxeSheet[59], Textures.crudeAxeSheet[60], Textures.crudeAxeSheet[61]) + }, + + new Animation[] { + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[4],Textures.crudeAxeChopSheet[5],Textures.crudeAxeChopSheet[6],Textures.crudeAxeChopSheet[7]), + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[20],Textures.crudeAxeChopSheet[21],Textures.crudeAxeChopSheet[22],Textures.crudeAxeChopSheet[23]), + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[12],Textures.crudeAxeChopSheet[13],Textures.crudeAxeChopSheet[14],Textures.crudeAxeChopSheet[15]), + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[28],Textures.crudeAxeChopSheet[29],Textures.crudeAxeChopSheet[30],Textures.crudeAxeChopSheet[31]), + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[0],Textures.crudeAxeChopSheet[1],Textures.crudeAxeChopSheet[2],Textures.crudeAxeChopSheet[3]), + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[24],Textures.crudeAxeChopSheet[25],Textures.crudeAxeChopSheet[26],Textures.crudeAxeChopSheet[27]), + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[8],Textures.crudeAxeChopSheet[9],Textures.crudeAxeChopSheet[10],Textures.crudeAxeChopSheet[11]), + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[16],Textures.crudeAxeChopSheet[17],Textures.crudeAxeChopSheet[18],Textures.crudeAxeChopSheet[19]), + new Animation(AXE_CHOP_RATE, Textures.crudeAxeChopSheet[20],Textures.crudeAxeChopSheet[21],Textures.crudeAxeChopSheet[22],Textures.crudeAxeChopSheet[23]), + }, + null, + // GET HITS + new BufferedImage[] { + Textures.crudeAxeSheet[80], + Textures.crudeAxeSheet[81], + Textures.crudeAxeSheet[82], + Textures.crudeAxeSheet[83], + Textures.crudeAxeSheet[84], + Textures.crudeAxeSheet[85], + Textures.crudeAxeSheet[86], + Textures.crudeAxeSheet[87] + } + ); + + public final static PlayerAnimationSequence crudePickaxe = new PlayerAnimationSequence( + new Animation[] { + new Animation(IDLE_ANIMATION_SPEED, Textures.crudePickaxeSheet[4], Textures.crudePickaxeSheet[5], Textures.crudePickaxeSheet[6], Textures.crudePickaxeSheet[7]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudePickaxeSheet[20], Textures.crudePickaxeSheet[21], Textures.crudePickaxeSheet[22],Textures.crudePickaxeSheet[23]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudePickaxeSheet[12], Textures.crudePickaxeSheet[13], Textures.crudePickaxeSheet[14], Textures.crudePickaxeSheet[15]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudePickaxeSheet[28], Textures.crudePickaxeSheet[29], Textures.crudePickaxeSheet[30], Textures.crudePickaxeSheet[31]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudePickaxeSheet[0], Textures.crudePickaxeSheet[1], Textures.crudePickaxeSheet[2], Textures.crudePickaxeSheet[3]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudePickaxeSheet[24], Textures.crudePickaxeSheet[25], Textures.crudePickaxeSheet[26], Textures.crudePickaxeSheet[27]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudePickaxeSheet[8], Textures.crudePickaxeSheet[9], Textures.crudePickaxeSheet[10], Textures.crudePickaxeSheet[11]), + new Animation(IDLE_ANIMATION_SPEED, Textures.crudePickaxeSheet[16], Textures.crudePickaxeSheet[17], Textures.crudePickaxeSheet[18], Textures.crudePickaxeSheet[19]) + }, + + new Animation[] { + new Animation(WALKS_ANIMATION_SPEED, Textures.crudePickaxeSheet[38], Textures.crudePickaxeSheet[39], Textures.crudePickaxeSheet[40], Textures.crudePickaxeSheet[41], Textures.crudePickaxeSheet[42], Textures.crudePickaxeSheet[43]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudePickaxeSheet[62], Textures.crudePickaxeSheet[63], Textures.crudePickaxeSheet[64], Textures.crudePickaxeSheet[65], Textures.crudePickaxeSheet[66], Textures.crudePickaxeSheet[67]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudePickaxeSheet[50], Textures.crudePickaxeSheet[51], Textures.crudePickaxeSheet[52], Textures.crudePickaxeSheet[53], Textures.crudePickaxeSheet[54], Textures.crudePickaxeSheet[55]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudePickaxeSheet[74], Textures.crudePickaxeSheet[75], Textures.crudePickaxeSheet[76], Textures.crudePickaxeSheet[77], Textures.crudePickaxeSheet[78], Textures.crudePickaxeSheet[79]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudePickaxeSheet[32], Textures.crudePickaxeSheet[33], Textures.crudePickaxeSheet[34], Textures.crudePickaxeSheet[35], Textures.crudePickaxeSheet[36], Textures.crudePickaxeSheet[37]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudePickaxeSheet[68], Textures.crudePickaxeSheet[69], Textures.crudePickaxeSheet[70], Textures.crudePickaxeSheet[71], Textures.crudePickaxeSheet[72], Textures.crudePickaxeSheet[73]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudePickaxeSheet[44], Textures.crudePickaxeSheet[45], Textures.crudePickaxeSheet[46], Textures.crudePickaxeSheet[47], Textures.crudePickaxeSheet[48], Textures.crudePickaxeSheet[49]), + new Animation(WALKS_ANIMATION_SPEED, Textures.crudePickaxeSheet[56], Textures.crudePickaxeSheet[57], Textures.crudePickaxeSheet[58], Textures.crudePickaxeSheet[59], Textures.crudePickaxeSheet[60], Textures.crudePickaxeSheet[61]) + }, + + null, + + new Animation[] { + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[4],Textures.crudePickaxeMineSheet[5],Textures.crudePickaxeMineSheet[6],Textures.crudePickaxeMineSheet[7]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[20],Textures.crudePickaxeMineSheet[21],Textures.crudePickaxeMineSheet[22],Textures.crudePickaxeMineSheet[23]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[12],Textures.crudePickaxeMineSheet[13],Textures.crudePickaxeMineSheet[14],Textures.crudePickaxeMineSheet[15]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[28],Textures.crudePickaxeMineSheet[29],Textures.crudePickaxeMineSheet[30],Textures.crudePickaxeMineSheet[31]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[0],Textures.crudePickaxeMineSheet[1],Textures.crudePickaxeMineSheet[2],Textures.crudePickaxeMineSheet[3]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[24],Textures.crudePickaxeMineSheet[25],Textures.crudePickaxeMineSheet[26],Textures.crudePickaxeMineSheet[27]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[8],Textures.crudePickaxeMineSheet[9],Textures.crudePickaxeMineSheet[10],Textures.crudePickaxeMineSheet[11]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[16],Textures.crudePickaxeMineSheet[17],Textures.crudePickaxeMineSheet[18],Textures.crudePickaxeMineSheet[19]), + new Animation(PICKAXE_MINE_ANIMATION_RATE, Textures.crudePickaxeMineSheet[20],Textures.crudePickaxeMineSheet[21],Textures.crudePickaxeMineSheet[22],Textures.crudePickaxeMineSheet[23]), + }, + + // GET HITS + new BufferedImage[] { + Textures.crudePickaxeSheet[80], + Textures.crudePickaxeSheet[81], + Textures.crudePickaxeSheet[82], + Textures.crudePickaxeSheet[83], + Textures.crudePickaxeSheet[84], + Textures.crudePickaxeSheet[85], + Textures.crudePickaxeSheet[86], + Textures.crudePickaxeSheet[87] + } + ); + + public static final PlayerAnimationSequence torch = new PlayerAnimationSequence( + new Animation[] { + new Animation(IDLE_ANIMATION_SPEED, Textures.torchSheet[4], Textures.torchSheet[5], Textures.torchSheet[6], Textures.torchSheet[7]), + new Animation(IDLE_ANIMATION_SPEED, Textures.torchSheet[20], Textures.torchSheet[21], Textures.torchSheet[22],Textures.torchSheet[23]), + new Animation(IDLE_ANIMATION_SPEED, Textures.torchSheet[12], Textures.torchSheet[13], Textures.torchSheet[14], Textures.torchSheet[15]), + new Animation(IDLE_ANIMATION_SPEED, Textures.torchSheet[28], Textures.torchSheet[29], Textures.torchSheet[30], Textures.torchSheet[31]), + new Animation(IDLE_ANIMATION_SPEED, Textures.torchSheet[0], Textures.torchSheet[1], Textures.torchSheet[2], Textures.torchSheet[3]), + new Animation(IDLE_ANIMATION_SPEED, Textures.torchSheet[24], Textures.torchSheet[25], Textures.torchSheet[26], Textures.torchSheet[27]), + new Animation(IDLE_ANIMATION_SPEED, Textures.torchSheet[8], Textures.torchSheet[9], Textures.torchSheet[10], Textures.torchSheet[11]), + new Animation(IDLE_ANIMATION_SPEED, Textures.torchSheet[16], Textures.torchSheet[17], Textures.torchSheet[18], Textures.torchSheet[19]) + }, + + new Animation[] { + new Animation(WALKS_ANIMATION_SPEED, Textures.torchSheet[38], Textures.torchSheet[39], Textures.torchSheet[40], Textures.torchSheet[41], Textures.torchSheet[42], Textures.torchSheet[43]), + new Animation(WALKS_ANIMATION_SPEED, Textures.torchSheet[62], Textures.torchSheet[63], Textures.torchSheet[64], Textures.torchSheet[65], Textures.torchSheet[66], Textures.torchSheet[67]), + new Animation(WALKS_ANIMATION_SPEED, Textures.torchSheet[50], Textures.torchSheet[51], Textures.torchSheet[52], Textures.torchSheet[53], Textures.torchSheet[54], Textures.torchSheet[55]), + new Animation(WALKS_ANIMATION_SPEED, Textures.torchSheet[74], Textures.torchSheet[75], Textures.torchSheet[76], Textures.torchSheet[77], Textures.torchSheet[78], Textures.torchSheet[79]), + new Animation(WALKS_ANIMATION_SPEED, Textures.torchSheet[32], Textures.torchSheet[33], Textures.torchSheet[34], Textures.torchSheet[35], Textures.torchSheet[36], Textures.torchSheet[37]), + new Animation(WALKS_ANIMATION_SPEED, Textures.torchSheet[68], Textures.torchSheet[69], Textures.torchSheet[70], Textures.torchSheet[71], Textures.torchSheet[72], Textures.torchSheet[73]), + new Animation(WALKS_ANIMATION_SPEED, Textures.torchSheet[44], Textures.torchSheet[45], Textures.torchSheet[46], Textures.torchSheet[47], Textures.torchSheet[48], Textures.torchSheet[49]), + new Animation(WALKS_ANIMATION_SPEED, Textures.torchSheet[56], Textures.torchSheet[57], Textures.torchSheet[58], Textures.torchSheet[59], Textures.torchSheet[60], Textures.torchSheet[61]) + }, + + null, + null, + // GET HITS + new BufferedImage[] { + Textures.torchSheet[80], + Textures.torchSheet[81], + Textures.torchSheet[82], + Textures.torchSheet[83], + Textures.torchSheet[84], + Textures.torchSheet[85], + Textures.torchSheet[86], + Textures.torchSheet[87] + } + ); + + private static int a = 0; + public static final PlayerAnimationSequence goblinSpear = new PlayerAnimationSequence( + new Animation[] { + new Animation(IDLE_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(IDLE_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(IDLE_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(IDLE_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(IDLE_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(IDLE_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(IDLE_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(IDLE_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]) + }, + + new Animation[] { + new Animation(WALKS_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(WALKS_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(WALKS_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(WALKS_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(WALKS_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(WALKS_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(WALKS_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]), + new Animation(WALKS_ANIMATION_SPEED, Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++], Textures.goblinSpearSheet[a++]) + }, + + null, + null, + // GET HITS // NOTE: the + 32 is because i put the attack textures before get hits on this one by accident + new BufferedImage[] { + Textures.goblinSpearSheet[a++ + 32], + Textures.goblinSpearSheet[a++ + 32], + Textures.goblinSpearSheet[a++ + 32], + Textures.goblinSpearSheet[a++ + 32], + Textures.goblinSpearSheet[a++ + 32], + Textures.goblinSpearSheet[a++ + 32], + Textures.goblinSpearSheet[a++ + 32], + Textures.goblinSpearSheet[a++ + 32] + } + ); + + + +} diff --git a/src/animations/PlayerAttackAnimations.java b/src/animations/PlayerAttackAnimations.java new file mode 100755 index 0000000..7857b1e --- /dev/null +++ b/src/animations/PlayerAttackAnimations.java @@ -0,0 +1,66 @@ +package animations; + +import _texture.loader.Textures; +import utils.Animation; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerAttackAnimations { + + private static final int BASE_ATTACK_SPEED = 7; + + + public static final Animation[] basePlayerAttack = new Animation[] { + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[4],Textures.basePlayerAttackSheet[5],Textures.basePlayerAttackSheet[6],Textures.basePlayerAttackSheet[7]), + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[20],Textures.basePlayerAttackSheet[21],Textures.basePlayerAttackSheet[22],Textures.basePlayerAttackSheet[23]), + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[12],Textures.basePlayerAttackSheet[13],Textures.basePlayerAttackSheet[14],Textures.basePlayerAttackSheet[15]), + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[28],Textures.basePlayerAttackSheet[29],Textures.basePlayerAttackSheet[30],Textures.basePlayerAttackSheet[31]), + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[0],Textures.basePlayerAttackSheet[1],Textures.basePlayerAttackSheet[2],Textures.basePlayerAttackSheet[3]), + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[24],Textures.basePlayerAttackSheet[25],Textures.basePlayerAttackSheet[26],Textures.basePlayerAttackSheet[27]), + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[8],Textures.basePlayerAttackSheet[9],Textures.basePlayerAttackSheet[10],Textures.basePlayerAttackSheet[11]), + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[16],Textures.basePlayerAttackSheet[17],Textures.basePlayerAttackSheet[18],Textures.basePlayerAttackSheet[19]), + new Animation(BASE_ATTACK_SPEED, Textures.basePlayerAttackSheet[28],Textures.basePlayerAttackSheet[29],Textures.basePlayerAttackSheet[30],Textures.basePlayerAttackSheet[31]) + }; + + public static final Animation[] crudeAxeAttack = new Animation[] { + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[4],Textures.crudeAxeAttackSheet[5],Textures.crudeAxeAttackSheet[6],Textures.crudeAxeAttackSheet[7]), + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[20],Textures.crudeAxeAttackSheet[21],Textures.crudeAxeAttackSheet[22],Textures.crudeAxeAttackSheet[23]), + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[12],Textures.crudeAxeAttackSheet[13],Textures.crudeAxeAttackSheet[14],Textures.crudeAxeAttackSheet[15]), + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[28],Textures.crudeAxeAttackSheet[29],Textures.crudeAxeAttackSheet[30],Textures.crudeAxeAttackSheet[31]), + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[0],Textures.crudeAxeAttackSheet[1],Textures.crudeAxeAttackSheet[2],Textures.crudeAxeAttackSheet[3]), + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[24],Textures.crudeAxeAttackSheet[25],Textures.crudeAxeAttackSheet[26],Textures.crudeAxeAttackSheet[27]), + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[8],Textures.crudeAxeAttackSheet[9],Textures.crudeAxeAttackSheet[10],Textures.crudeAxeAttackSheet[11]), + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[16],Textures.crudeAxeAttackSheet[17],Textures.crudeAxeAttackSheet[18],Textures.crudeAxeAttackSheet[19]), + new Animation(BASE_ATTACK_SPEED, Textures.crudeAxeAttackSheet[20],Textures.crudeAxeAttackSheet[21],Textures.crudeAxeAttackSheet[22],Textures.crudeAxeAttackSheet[23]) + }; + + + public static final Animation[] crudePickAxeAttack = new Animation[] { + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[4],Textures.crudePickAxeAttackSheet[5],Textures.crudePickAxeAttackSheet[6],Textures.crudePickAxeAttackSheet[7]), + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[20],Textures.crudePickAxeAttackSheet[21],Textures.crudePickAxeAttackSheet[22],Textures.crudePickAxeAttackSheet[23]), + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[12],Textures.crudePickAxeAttackSheet[13],Textures.crudePickAxeAttackSheet[14],Textures.crudePickAxeAttackSheet[15]), + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[28],Textures.crudePickAxeAttackSheet[29],Textures.crudePickAxeAttackSheet[30],Textures.crudePickAxeAttackSheet[31]), + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[0],Textures.crudePickAxeAttackSheet[1],Textures.crudePickAxeAttackSheet[2],Textures.crudePickAxeAttackSheet[3]), + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[24],Textures.crudePickAxeAttackSheet[25],Textures.crudePickAxeAttackSheet[26],Textures.crudePickAxeAttackSheet[27]), + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[8],Textures.crudePickAxeAttackSheet[9],Textures.crudePickAxeAttackSheet[10],Textures.crudePickAxeAttackSheet[11]), + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[16],Textures.crudePickAxeAttackSheet[17],Textures.crudePickAxeAttackSheet[18],Textures.crudePickAxeAttackSheet[19]), + new Animation(BASE_ATTACK_SPEED, Textures.crudePickAxeAttackSheet[20],Textures.crudePickAxeAttackSheet[21],Textures.crudePickAxeAttackSheet[22],Textures.crudePickAxeAttackSheet[23]) + }; + + private static int a = 48+32; + public static final Animation[] goblinSpearAttack = new Animation[] { + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]), + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]), + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]), + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]), + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]), + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]), + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]), + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]), + new Animation(BASE_ATTACK_SPEED, Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++],Textures.goblinSpearSheet[a++]) + + }; + +} diff --git a/src/engine/Camera.java b/src/engine/Camera.java new file mode 100755 index 0000000..7d5c919 --- /dev/null +++ b/src/engine/Camera.java @@ -0,0 +1,71 @@ +package engine; + +import player.Player; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class Camera { + + public static double x, y; + + public final static void tick() { + switch(Game.rotation) { + case 1: + x = -Player.center.x + Game.WIDTH / 2 / Game.scaleFactor; + y = -Player.center.y + Game.HEIGHT / 2 / Game.scaleFactor; break; + case 2: + if (((float) Game.WIDTH / Game.HEIGHT) >= (16.0f / 9)) { + x = -Player.center.x + Game.WIDTH / 1.81f / Game.scaleFactor; + y = -Player.center.y - Game.HEIGHT / 3.65f / Game.scaleFactor; + } else if ((Game.WIDTH / Game.HEIGHT) <= (4.0f / 3)) { + x = -Player.center.x + Game.WIDTH / 1.62f / Game.scaleFactor; + y = -Player.center.y - Game.HEIGHT / 8.25f / Game.scaleFactor; + } break; + case 3: + if (((float) Game.WIDTH / Game.HEIGHT) >= (16.0f / 9)) { + x = -Player.center.x + Game.WIDTH / 3.54f / Game.scaleFactor; + y = -Player.center.y - Game.HEIGHT / 1.125f / Game.scaleFactor; + } else if ((Game.WIDTH / Game.HEIGHT) <= (4.0f / 3)) { + x = -Player.center.x + Game.WIDTH / 2.675f / Game.scaleFactor; + y = -Player.center.y - Game.HEIGHT / 1.5f / Game.scaleFactor; + } break; + case 4: + if (((float) Game.WIDTH / Game.HEIGHT) >= (16.0f / 9)) { + x = -Player.center.x - Game.WIDTH / 6.55f / Game.scaleFactor; + y = -Player.center.y - Game.HEIGHT / 1.015f / Game.scaleFactor; + } else if ((Game.WIDTH / Game.HEIGHT) <= (4.0f / 3)) { + x = -Player.center.x - Game.WIDTH / 11.4f / Game.scaleFactor; + y = -Player.center.y - Game.HEIGHT / 1.21f / Game.scaleFactor; + } break; + case 5: + x = -Player.center.x - Game.WIDTH / 2 / Game.scaleFactor; + y = -Player.center.y - Game.HEIGHT / 2 / Game.scaleFactor; break; + case 6: + if (((float) Game.WIDTH / Game.HEIGHT) >= (16.0f / 9)) { + x = -Player.center.x - Game.WIDTH / 1.81f / Game.scaleFactor; + y = -Player.center.y + Game.HEIGHT / 3.65f / Game.scaleFactor; + } else if ((double) (Game.WIDTH / Game.HEIGHT) <= (4.0f / 3)) { + x = -Player.center.x - Game.WIDTH / 1.62f / Game.scaleFactor; + y = -Player.center.y + Game.HEIGHT / 8.25f / Game.scaleFactor; + } break; + case 7: + if (((float) Game.WIDTH / Game.HEIGHT) >= (16.0f / 9)) { + x = -Player.center.x - Game.WIDTH / 3.55f / Game.scaleFactor; + y = -Player.center.y + Game.HEIGHT / 1.125f / Game.scaleFactor; + } else if ((double) (Game.WIDTH / Game.HEIGHT) <= (4.0f / 3)) { + x = -Player.center.x - Game.WIDTH / 2.675f / Game.scaleFactor; + y = -Player.center.y + Game.HEIGHT / 1.5f / Game.scaleFactor; + } break; + case 8: + if (((float) Game.WIDTH / Game.HEIGHT) >= (16.0f / 9)) { + x = -Player.center.x + Game.WIDTH / 6.55f / Game.scaleFactor; + y = -Player.center.y + Game.HEIGHT / 1.015f / Game.scaleFactor; + } else if ((double) (Game.WIDTH / Game.HEIGHT) <= (4.0f / 3)) { + x = -Player.center.x + Game.WIDTH / 11.4f / Game.scaleFactor; + y = -Player.center.y + Game.HEIGHT / 1.21f / Game.scaleFactor; + } break; + } + } +} diff --git a/src/engine/DeveloperConsole.java b/src/engine/DeveloperConsole.java new file mode 100755 index 0000000..008eb61 --- /dev/null +++ b/src/engine/DeveloperConsole.java @@ -0,0 +1,400 @@ +package engine; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.LinkedList; + +import engine.Game.STATE; +import hud.inventory.InvenHelper; +import hud.inventory.Inventory; +import interfaces.Biomes; +import interfaces.Colors; +import interfaces.ItemIDs; +import interfaces.Mob; +import interfaces.Python; +import mobs.Goblin; +import mobs.Rabbit; +import player.Player; +import structures.Fire; +import utils.Circle; +import utils.Point2f; +import utils.Utils; +import world.Boulder; +import world.Flower; +import world.Sapling; +import world.TallGrass; +import world.Tile; +import world.Tree; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class DeveloperConsole extends KeyAdapter implements Colors, ItemIDs, Biomes, Python { + + private static StringBuilder sb; + private static LinkedList history; + private static int index; + private static STATE tempState; + + public static synchronized final void init() { + /* COMMENT THIS IN THE FINAL RELEASE */ + sb = new StringBuilder(); + history = new LinkedList(); + Game.game.addKeyListener(new DeveloperConsole()); + } + + public final void keyPressed(final KeyEvent e) { + + if(e.getKeyCode() == KeyEvent.VK_ESCAPE && Game.state == STATE.DEVELOPER_CONSOLE) { exit(); return; } + else if(e.getKeyChar() == '~') { if(Game.state != STATE.DEVELOPER_CONSOLE) open(); else exit(); return; } + else if(Game.state != STATE.DEVELOPER_CONSOLE) return; + + else if(e.getKeyCode() == KeyEvent.VK_UP) { + if(history.size() <= 0) return; + final String temp = sb.toString(); + sb = new StringBuilder(); + try { sb.append(history.get(index--)); } catch (Exception ex) { + index++; + sb.append(temp); + } + } + + else if(e.getKeyCode() == KeyEvent.VK_DOWN) { + if(history.size() <= 0) return; + final String temp = sb.toString(); + sb = new StringBuilder(); + try { sb.append(history.get(++index)); } catch (Exception ex) { + index--; + sb.append(temp); + } + } + + else if(e.getKeyCode() == KeyEvent.VK_ENTER) { + history.add(sb.toString()); + execute(sb.toString()); + sb = new StringBuilder(); + return; + } + + else if(e.getKeyCode() == KeyEvent.VK_BACK_SPACE) { if(sb.length() > 0) sb.deleteCharAt(sb.length()-1); return; } + + else if(sb.length() < 67) { + switch(e.getKeyCode()) { + case KeyEvent.VK_BACK_SPACE: return; + case KeyEvent.VK_TAB: return; + case KeyEvent.VK_SHIFT: return; + case KeyEvent.VK_UP: return; + case KeyEvent.VK_DOWN: return; + case KeyEvent.VK_LEFT: return; + case KeyEvent.VK_RIGHT: return; + case KeyEvent.VK_CONTROL: return; + case KeyEvent.VK_WINDOWS: return; + case KeyEvent.VK_UNDEFINED: return; + case KeyEvent.VK_NUM_LOCK: return; + default: sb.append(e.getKeyChar()); + } + } + } + + private static synchronized final void execute(final String command) { + if(command.length() <= 0) { exit(); return; } + + String action, item, value; + + // GET THE ACTION, IF THE ACTION IS A ONE-WORD PHRASE, ACTION = THE WHOLE COMMAND + try { action = command.substring(0, command.indexOf(" ")); } catch (StringIndexOutOfBoundsException e) { action = command.toString(); } + + // GET THE ITEM, IF THERE IS NO AMOUNT, ITEM = JUST THE ITEM, IF THERE IS NO ITEM, ITEM = "" + try { final String tempItem = command.substring(command.indexOf(" ") + 1); item = tempItem.substring(0, tempItem.indexOf(" ")); } catch (StringIndexOutOfBoundsException e) { + try { item = command.substring(command.indexOf(" ") + 1); } catch (StringIndexOutOfBoundsException ee) { item = ""; } + } + + // GET THE VALUE ---- + try { final String temp = command.substring(command.indexOf(" ") + 1) ; + value = temp.substring(temp.indexOf(" ") + 1); + } catch (StringIndexOutOfBoundsException ee) { value = ""; } + + item.replace(" ", ""); action.replace(" ", ""); value.replace(" ", ""); + +// -------------------------------------------------------------------------------------------------------------------------------------// + OUTER_SWITCH: + switch(action) { + + case "exec_script": pi.execfile(item); break; + case "exec": pi.exec(item); break; + + case "health": Player.health = Integer.parseInt(value); break; + + case "clear_mobs": Handler.mobs.clear(); break; + + case "garbage_collect": System.gc(); break; + case "clear_history": history.clear(); break; + + case "unlimit_zoom": { Game.MIN_SCALEFACTOR = 0.01d; Game.MAX_SCALEFACTOR = 100; break; } + + case "starter_kit": { + Inventory.addItem(LOGS, 20); + Inventory.addItem(PICKED_GRASS, 40); + Inventory.addItem(STICKS, 20); + Inventory.addItem(ROCKS, 10); + Inventory.addItem(TORCH); + Inventory.addItem(CRUDE_PICKAXE); + Inventory.addItem(CRUDE_AXE); break; + } + + case "speed": { Player.WALKING_SPEED = Float.parseFloat(item); break; } + case "clock_speed": { Game.clockSpeed = Integer.parseInt(item); break; } + case "nuke": { + for(Mob m : Handler.mobs) if(Handler.AREA_RECT.contains(m.center.x, m.center.y)) m.health = 0; + for(Tree m : Handler.trees) if(Handler.AREA_RECT.contains(m.center.x, m.center.y)) m.health = 0; + for(Boulder m : Handler.boulders) if(Handler.AREA_RECT.contains(m.center.x, m.center.y)) m.health = 0; + + for(Flower m : Handler.flowers) if(Handler.AREA_RECT.contains(m.center.x, m.center.y)) m.alive = false; + for(TallGrass m : Handler.grass) if(Handler.AREA_RECT.contains(m.center.x, m.center.y)) m.alive = false; + for(Sapling m : Handler.saplings) if(Handler.AREA_RECT.contains(m.center.x, m.center.y)) m.alive = false; + break; + } + case "clear_all_items": Handler.droppedItems.clear(); break; + case "drop_all_items": InvenHelper.DROP_ALL_INVENTORY(); break; + case "discover_all": Tile.DISCOVER_ALL(); break; + case "undiscover_all": Tile.UN_DISCOVER_ALL(); break; + case "paint_map": Handler.getMapImage(); break; + + ///////////// DEBUG BOOLEAN FLIPPING /////////////////////// + case "draw_mob_attack_bounds": Game.drawMobAttackBounds = !Game.drawMobAttackBounds; break; + case "draw_collision_bounds": Game.drawCollisionBounds = !Game.drawCollisionBounds; break; + case "draw_mob_territories": Game.drawMobTerritoryZones = !Game.drawMobTerritoryZones; break; + case "draw_mob_aggro_radii": Game.drawMobAggroRadii = !Game.drawMobAggroRadii; break; + case "draw_resource_numbers": Game.drawResourceNumbers = !Game.drawResourceNumbers; break; + case "dont_show_debris": Game.dontShowDebris = !Game.dontShowDebris; break; + case "draw_current_time": Game.drawCurrentTime = !Game.drawCurrentTime; break; + case "draw_inventory_bounds": Game.drawInventoryBounds = !Game.drawInventoryBounds; break; + case "draw_center_lines": Game.drawCenterLines = !Game.drawCenterLines; break; + case "dont_draw_player": Game.dontDrawPlayer = !Game.dontDrawPlayer; break; + case "god": Game.godMode = !Game.godMode; break; + case "god_mode": Game.godMode = !Game.godMode; break; + case "no_clip": Game.noClip = !Game.noClip; break; + case "noclip": Game.noClip = !Game.noClip; break; + case "no_hunger": Game.noHunger = !Game.noHunger; break; + case "draw_player_attack_bounds": Game.drawPlayerAttackBounds = !Game.drawPlayerAttackBounds; break; + case "draw_right_click_bounds": Game.drawRightClickBounds = !Game.drawRightClickBounds; break; + case "always_dawn": Game.alwaysDawn = !Game.alwaysDawn; break; + case "always_day": Game.alwaysDay = !Game.alwaysDay; break; + case "always_dusk": Game.alwaysDusk = !Game.alwaysDusk; break; + case "always_night": Game.alwaysNight = !Game.alwaysNight; break; + case "highlight_tiles": { Tile.drawHighLighted = !Tile.drawHighLighted; if(!Tile.drawHighLighted) Tile.resetAllHighlighted(); break; } + + case "reset": { + Game.drawCollisionBounds=Game.noClip=Game.dontShowDebris=Game.drawCurrentTime=Game.drawInventoryBounds=Game.drawCenterLines=Game.dontDrawPlayer=Game.godMode=Game.noHunger= + Game.drawResourceNumbers=Game.drawMobTerritoryZones=Game.drawMobAggroRadii=Game.alwaysDawn=Game.alwaysDay=Game.alwaysDusk=Game.alwaysNight= + Game.drawPlayerAttackBounds=Game.drawRightClickBounds = false; + Tile.drawHighLighted = false; Tile.resetAllHighlighted(); + Player.WALKING_SPEED = 1.75f; Player.RUNNING_SPEED = 3f; Game.clockSpeed = 1; + break; + } + /////////////////////////////////////////////////////////// + + case "give": { + try{ // IF THIS SUCCEEDS, IT MUST BE USING ITEM ID + Integer.parseInt(item); + + // IF THIS SUCCEEDS, THERE MUST BE A QUANTITY + try { Integer.parseInt(value); + Inventory.addItem(Integer.parseInt(item), Integer.parseInt(value)); + } catch (NumberFormatException e) { + // ELSE THE QUANTITY MUST BE ONE + Inventory.addItem(Integer.parseInt(item)); + } + + } catch (NumberFormatException e) { + // IF IT DIDN'T SUCCEED, IT MUST BE USING A STRING NAME FOR ITEM + boolean isQuantity; + + // IF THIS SUCCEEDS, THERE MUST BE A QUANTITY + try { Integer.parseInt(value); isQuantity = true; + } catch (NumberFormatException ee) { isQuantity = false; } + + int ITEM_TO_ADD = -1; + switch(item) { + case "grass": ITEM_TO_ADD = PICKED_GRASS; break; + case "flowers": ITEM_TO_ADD = PICKED_FLOWERS; break; + case "crude_axe": ITEM_TO_ADD = CRUDE_AXE; break; + case "logs": ITEM_TO_ADD = LOGS; break; + case "crude_pickaxe": ITEM_TO_ADD = CRUDE_PICKAXE; break; + case "rocks": ITEM_TO_ADD = ROCKS; break; + case "sticks": ITEM_TO_ADD = STICKS; break; + case "ashes": ITEM_TO_ADD = ASHES; break; + case "torch": ITEM_TO_ADD = TORCH; break; + case "rabbit_carcass": ITEM_TO_ADD = RABBIT_CARCASS; break; + case "rabbit_foot": ITEM_TO_ADD = RABBIT_FOOT; break; + case "rot": ITEM_TO_ADD = ROT; break; + case "goblin_spear": ITEM_TO_ADD = GOBLIN_SPEAR; break; + default: { System.out.println("invalid item identifier"); break OUTER_SWITCH; } + } + + if(isQuantity) Inventory.addItem(ITEM_TO_ADD, Integer.parseInt(value)); + else if(value.equalsIgnoreCase("max")) Inventory.addItem(ITEM_TO_ADD, Utils._2147483647); + else Inventory.addItem(ITEM_TO_ADD); + + } + break; + } + + case "spawn": { + + int quantity; + try { quantity = Integer.parseInt(value); // IF THIS SUCCEEDS, THERE MUST BE A QUANTITY + } catch (NumberFormatException e) { /* ELSE THE QUANTITY MUST BE ONE */ quantity = 1; } + + for(int i = 0; i < quantity; i++) { + int offsetx = Utils.rand.nextInt(20) + 1; + int offsety = Utils.rand.nextInt(20) + 1; + if(Utils.rand.nextBoolean()) offsetx *= -1; + if(Utils.rand.nextBoolean()) offsety *= -1; + +; switch(item) { + case "rabbit": new Rabbit(MouseInput.adjustedMouseXY.x+offsetx, MouseInput.adjustedMouseXY.y+offsety); break; + case "goblin": new Goblin(MouseInput.adjustedMouseXY.x+offsetx, MouseInput.adjustedMouseXY.y+offsety); break; + case "boulder": new Boulder(MouseInput.adjustedMouseXY.x+offsetx, MouseInput.adjustedMouseXY.y+offsety); break; + case "sapling": new Sapling(MouseInput.adjustedMouseXY.x+offsetx, MouseInput.adjustedMouseXY.y+offsety); break; + case "grass": new TallGrass(MouseInput.adjustedMouseXY.x+offsetx, MouseInput.adjustedMouseXY.y+offsety); break; + case "flower": new Flower(MouseInput.adjustedMouseXY.x+offsetx, MouseInput.adjustedMouseXY.y+offsety); break; + case "tree": new Tree(MouseInput.adjustedMouseXY.x+offsetx, MouseInput.adjustedMouseXY.y+offsety); break; + default: System.out.println("invalid mob identifier"); + } + } + break; + } + + case "create": { + switch(item) { + case "fire": Handler.structures.add(new Fire(new Point2f(MouseInput.adjustedMouseXY.x, MouseInput.adjustedMouseXY.y))); break; + + + default: System.out.println("invalid structure identifier"); + } + break; + } + + case "teleport_to_biome": { + outerSwitch: + switch(item) { + case "forest": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == FOREST){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "volcanic": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == VOLCANIC){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "desert": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == DESERT){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "taiga":{ + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == TAIGA){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "tundra": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == SNOW_TUNDA){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "barren_rock":{ + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == BARREN_ROCK){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "back_of_volcano": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == BACK_OF_VOLCANO){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "lake": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == LAKE){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "grass1": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == GRASS1){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + case "grass2": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == GRASS2){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + + case "grass3": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == GRASS3){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + + case "grass4": { + for(int i = 0; i < Handler.numSectionsRowsCols; i++) for(int j = 0; j < Handler.numSectionsRowsCols; j++) for(final Tile tile : Handler.world.get(i).get(j).get(0)) + if(tile.biome == GRASS4){ Player.pos.setLocation(tile.x, tile.y); break outerSwitch; } + } + } break; + } + + case "exit": Game.cleanUp(); break; + case "quit": Game.cleanUp(); break; + + + // ############### SILLY STUFF BELOW ######################################### + case "HOLY_SHIT_BUNNIES": for(int i = 0; i < 1000; i++) { + int offsetx = Utils.rand.nextInt(200) + 1; int offsety = Utils.rand.nextInt(200) + 1; + if(Utils.rand.nextBoolean()) offsetx *= -1; if(Utils.rand.nextBoolean()) offsety *= -1; + new Rabbit(Player.center.x+offsetx, Player.center.y+offsety); + } break; + + case "flower_bomb": { + final Circle bounds = new Circle(Player.center, 300); + for(int i = 0; i < 10000; i++) { + int offsetx = Utils.rand.nextInt(300) + 1; int offsety = Utils.rand.nextInt(300) + 1; + if(Utils.rand.nextBoolean()) offsetx *= -1; if(Utils.rand.nextBoolean()) offsety *= -1; + if(bounds.contains(Player.center.x+offsetx, Player.center.y+offsety)) + new Flower((int)(Player.center.x+offsetx), (int)(Player.center.y+offsety)); + } break; } + // ############### END SILLY STUFF ########################################### + + default: System.out.println("invalid console command"); + } + + + exit(); + } + + public static final void render(final Graphics2D g2d) { + + if(Game.state != STATE.DEVELOPER_CONSOLE) return; + + final int width = Game.game.getWidth(); + final int height = Game.game.getHeight(); + + g2d.setColor(Color.black); + g2d.fillRect(width/2 - width/4, height/2 - height/4, width/2, height/20); + + g2d.setColor(Color.white); + g2d.setFont(fonts.fonts.ponderosa20); + + g2d.drawString(sb.toString(), width/2 - width/4 + 10, height/2 - height/4 + 20); + + g2d.setColor(pastelRed); + g2d.setFont(fonts.fonts.Gregorian48Bold); + g2d.drawString("console:", width/2 - width/4 + 2, height/2 - height/4 - 10); + + g2d.dispose(); + } + + private static synchronized final void open() { + sb = new StringBuilder(); + tempState = Game.state; + Game.state = STATE.DEVELOPER_CONSOLE; + } + + private static synchronized final void exit() { + index = history.size() - 1; + sb = new StringBuilder(); + Game.state = tempState; + tempState = null; + } +} diff --git a/src/engine/Game.java b/src/engine/Game.java new file mode 100755 index 0000000..f9b55ec --- /dev/null +++ b/src/engine/Game.java @@ -0,0 +1,475 @@ +package engine; + +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.image.BufferStrategy; +import javax.swing.JFrame; +import javax.swing.JPanel; +import _texture.loader.TextureLoader; +import _texture.loader.Textures; +import fileIO.Saving; +import fonts.fonts; +import hud.Clock; +import hud.Map; +import hud.RightClickMenu; +import hud.SecondaryHUD; +import hud.SecondaryHUD.TAB; +import hud.constructionmenu.ConstructionMenu; +import hud.inventory.Inventory; +import hud.inventory.InventorySlot; +import interfaces.Colors; +import interfaces.Mob; +import interfaces.Python; +import lighting.PlayerLightPosUpdater; +import lighting.RadialLight; +import player.HealthAndDurability; +import player.Player; +import utils.Runner; +import utils.Stack; +import utils.ThreadPool; +import utils.Utils; +import world.Tile; +import worldGen.WorldGenerator; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +/* MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMM? . MMMMMMMMMMMMMMMM..MMM??MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMM........ MMMMMMMMMMMD .......MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMM ..........,MMMMMMMM.........MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMI.,MMMM8.....,MMMMMM. N?.... MMMMMMMMMM OMMM. .MMMMMMMMMMMMMMMMMMMMMMM . MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMM?.....=MMMM.,MMMM.:MMMMMMMMMMMMM .. ..7MMMMMMMMMMMMMMMMMMMMM. M...MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMM? M....DMMMMMMMMM ~MMMMMMMMMMMMMM .. MMMMMMMMMMMMMMMMMMMMMMMM....MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMM? MZ....NMMMMMMMM ~MMMMMM NMMMMMM....MMMMMMMMMMMMMMMN.MMMMMMM....MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMM? MM...... ..... ~MMMM...... MMM ...MMMMMMMMMMMMMM.... MMM...:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMM..: MMM.....MMMMMMM.~MMMI=,....?MMM ...MMMMMMMMMMMMM = ...,7MMM...:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMM+ .... MMMM....7MMMMMM ~MMMMMMNMMMMMMM ...MMMMMMMMMMMMMMMMNMMMMMMM...:MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMM... .. MMMM8....MMMMMM ~MMMMM..MMMMMMM ...MMMMMM7MMMMMMMM. MMMMMMM...:MMMMMM8MMMMMM,,MMMMMMMMMMMMMM. MMMMMMMMMM + MMMMMMMMM..MMM MMMMM,....MMMMM.~MMMM .. . MMM ...MMMM . DMMMMM8... . .MMM...:MMMM....MMM~ ...:MMMMMMMMMM. ...MMMMMMMMM + MMMMMMMMM,MMMM? MMMMMM.... MMMM ~MMD,......:MMM ...MMM ......=M .......~MMM...:MMN. ...NM ....... MM . ..M7....MMMMMMMM + MMMMMMMMMMMMMM? MMMMMMM ...:MMM.~MMMMM...=MMMMM ...M. M .....MMMMM ..MMMMMM...:MMMMI.... NMMM... MMMMM....MMM....MMMMMMM + MMMMMMMMMMMMMM?.M= ...$N ...MMM.~MMMMM...=MMMMM .. .=MMMO...MMMMMM ..MMMMMM...:MMMMM....MMMMM...~MMMMM ...MMM.. ,MMMMMMM + MMMMMMMMMMMMMM?. MMMMMO......MM.~MMMMM...=MMMMM ..,MMMMMO...MMMMMM ..MMMMMM...:MMMMM...:MMMMM...~MMMMM ...MMM..MMMMMMMMM + MMMMMMMMMMMMMM? MMMMMMMMM.....M.~MMMMM...=MMMMM ...MMMMMO...MMMMMM ..MMMMMM...:MMMMM...:MMMMM...~MMMMM ...M$ $MMMMMMMMMM + MMMMMMMMMMMMMM? MMMMMMMMMM ... ~MMMMM...=MMMMM ...MMMMMO...MMMMMM ..MMMMMM...:MMMMM...:MMMMM...~MMMMM .... MMMMMMMMMMMM + MMMMMMMMMMMMMM? MMMMMM MMM.....~MMMMM...=MMMMM ...MMMMMO...MMMMMM ..MMMMMM...:MMMMM...:MMMMM...~MMMMM ...MMMMMMMMMMMMMM + MMMMMMMMMMM.......... $MMMMM....~MMMMM....MMMMM .. MMMMMO...NMMMMM... MMMMM...~MMMMM ..:MMMMM...~MMMMM....MMMMMM8MMMMMMM + MMMMMMMMM............MMMMMMMM...:MMMMM ....~MD.....=..MMZ... MMMMM ... =MM.....M .M .....M.MM ...778M ..... MM IMMMMMMM + MMMMMMMZ . .MM~ ...MMMMMMMMMMM...MMMMMM....MM..,....MMMM . .NMMMMMI... MN.......MM...... MMMD....+M ........MMMMMMMMMM + MMMMMMM =MMMMMMMMMMMMMMMMMMMMMM MMMMMMM MMMMMMMM.MMMMM MMMMMMMMMM7 MMMMMMM=.MMMMMMMMM MMMMMMM.MMMMMMMMM =MMMMMMMMMMMM + MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM..MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM?.,MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM.. MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM + MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM */ + +public final class Game extends Canvas implements Runnable, Python, Colors { + private static final long serialVersionUID = 1337; + public static final String version = "Pre-Alpha --- Week 10"; + + // Variable Declaration + public static final int TILE_SIZE = 32, threads = ThreadPool.getNumProcessors(); + public static double MAX_SCALEFACTOR = 5, MIN_SCALEFACTOR = 1; + public static int WIDTH = 1280, HEIGHT = 720; /* will change in settings, this is default */ + public static double FPS_CAP = 60.0, frameLimit = (Utils.second / FPS_CAP), scaleFactor = 2.0; + private static boolean running; + public static int rotation = 1; // 1 = N, 2 = NW, 3 = W, 4 = SW, 5 = S, 6 = SE, 7 = E, 8 = NE + private static int frames = 0, ticks = 0, FPS = 0, TPS = 0; + private static long timeTakenForInit; + public static volatile boolean init; + + // Object creation + public static final Game game = new Game(); + public Render renderer; /* can't be static due to Canvas */ + public static Menu menu; + public static volatile Settings settings; /* volatile just */ + public static volatile Saving saving; /* to be safe */ + public static JFrame frame; + public static JPanel panel; + public static ThreadPool pool; + public static STATE state; + public static MouseInput mouse; + + public static boolean settingsChanged = true, fullscreen = true, displayFPS = true, showEnemyHealthBars = true; + + public static enum STATE { GAME, MENU, SETTINGS, ABOUT, LOADING, PAUSED, MAP, GAMEO_OVER, DEVELOPER_CONSOLE; } + + /****************************************************** DEBUG *********************************************************************************/ + public static boolean drawCollisionBounds, noClip, dontShowDebris, drawCurrentTime, drawInventoryBounds, drawCenterLines, dontDrawPlayer, godMode, noHunger, + drawResourceNumbers, drawMobTerritoryZones, drawMobAggroRadii, alwaysDawn, alwaysDay, alwaysDusk, alwaysNight, + drawPlayerAttackBounds, drawRightClickBounds, drawMobAttackBounds; + public static int clockSpeed = 3; + /*************************************************** END DEBUG ********************************************************************************/ + + public static final void main(String[] args) { + game.init(); + } + + public final static void tick() { + ticks++; + + if (state == STATE.GAME) { + + Handler.tick(); + for (int i = 0; i < clockSpeed; i++) Clock.tick(); + + ConstructionMenu.tick(); + PlayerLightPosUpdater.tick(); + HealthAndDurability.tick(); + RightClickMenu.tick(); + + } else if(state == STATE.MAP) Map.tick(); + + KeyInput.tick(); + MouseInput.tick(); + } + + private static BufferStrategy bs; private static Graphics g; + private static Graphics2D g2d, InventoryRenderer, InventorySlotRenderer, ClockRenderer, SecondaryHUDRenderer, constructionMenuRenderer, debugRenderer; + public static boolean justRotated, justCameFromSettings; + public static int tempRotation = 1; + private final class Render implements Runnable { + private boolean rendering; private int menuSplashTimer = 0; + + public final void run() { if(!rendering) render(); } + + public final void render() { + if (menuSplashTimer > 0 && Game.state != STATE.MENU) menuSplashTimer = 0; + rendering = true; + try { + + if (bs == null) game.createBufferStrategy(3); + bs = game.getBufferStrategy(); + if (!(bs.getDrawGraphics() == null)) g = bs.getDrawGraphics(); + if (!(g == null)) { + g2d = (Graphics2D) g; + InventoryRenderer = (Graphics2D) g2d.create(); + ClockRenderer = (Graphics2D) g2d.create(); + InventorySlotRenderer = (Graphics2D) g2d.create(); + SecondaryHUDRenderer = (Graphics2D) g2d.create(); + debugRenderer = (Graphics2D) g2d.create(); + constructionMenuRenderer = (Graphics2D) g2d.create(); + } + + if (state == STATE.GAME) { + + if(!WorldGenerator.WORLD_GENERATED) { + if(WorldGenerator.beginTileCreation) + try{ int total = 0; + for(final Stack i : WorldGenerator.workerStacks) total+= i.size(); + WorldGenerator.percentage = 100 - (100 * (total / WorldGenerator.stackSize)); + }catch(NullPointerException npe) { WorldGenerator.percentage = 100; } + + final int color = Utils.clamp((int)(255*(WorldGenerator.percentage/100)/1.3), 0, 255); + + g2d.setColor(new Color(color, color, color)); + g2d.fillRect(0, 0, getWidth(), getHeight()); + g2d.setColor(new Color(255 - color, 0, 0)); + g2d.setFont(fonts.Gregorian32Bold); + g2d.drawString("LOADING", Game.game.getWidth()/2 - 100, Game.game.getHeight()/2); + g2d.setFont(fonts.Gregorian48Bold); + g2d.drawString(Utils.df.format(WorldGenerator.percentage)+"%", Game.game.getWidth()/2 - 78, Game.game.getHeight()/2 + 60); + } else { + + Camera.tick(); + Inventory.tick(); + + // draw the base layer + g2d.setColor(Color.black); + g2d.fillRect(0, 0, getWidth(), getHeight()); + + g2d.rotate(Utils._45 * (rotation - 1)); + g2d.scale(scaleFactor, scaleFactor); + g2d.translate(Camera.x, Camera.y); + Handler.render(g2d); /* Render game objects */ + g2d.translate(-Camera.x, -Camera.y); + + RadialLight.render(debugRenderer); + } + } else if (state == STATE.PAUSED) { + PauseMenu.tick(); + if (justCameFromSettings) { + g2d.setColor(Color.black); + justCameFromSettings = false; + Inventory.changeSettings(); + } else g2d.setColor(pause_menu_alpha); + g2d.fillRect(0, 0, getWidth() + 50, getHeight() + 50); + PauseMenu.render(g2d); + } else if (state == STATE.MENU) { + menu.tick(); + if (menuSplashTimer <= 0) { + g2d.drawImage(Textures.splashSheet[0].getScaledInstance(getWidth(), getHeight(), 1), 0, 0, null); + g2d.setColor(Color.red); + g2d.setFont(fonts.Gregorian26); + g2d.drawString(version, getWidth() / 17, getHeight() / 1.1f); + menuSplashTimer = 20; + } else menuSplashTimer--; + + menu.render(g2d); + } else if (state == STATE.SETTINGS) { + settings.tick(); + g2d.setColor(Color.black); + g2d.fillRect(0, 0, getWidth() + 50, getHeight() + 50); + settings.render(g2d); + } else if (state == STATE.MAP) { + Map.render(g2d); + } else if(state == STATE.DEVELOPER_CONSOLE) { + DeveloperConsole.render(g2d); + } + + if(WorldGenerator.WORLD_GENERATED){ + // Draw non-scaling / rotating things: + if (displayFPS) { /* can be rendered with any of the other g2d's, just can't be rotated */ + InventoryRenderer.setColor(Color.green); + InventoryRenderer.setFont(fonts.fallbackFont); + InventoryRenderer.drawString(("FPS: " + (int) FPS + " TICKS: " + (int) TPS), (int) (getWidth() * 0.03f), (int) (getHeight() * 0.03f)); + + + + // XXX: HERE IS SOEMTHING TO DELETE! + InventoryRenderer.setColor(Color.red); + InventoryRenderer.drawString(rotation + "", (int) (getWidth() * 0.4f), (int) (getHeight() * 0.04f)); + InventoryRenderer.setFont(fonts.Gregorian32Bold); + InventoryRenderer.drawString("Player Health: " + Player.health, (int)(getWidth() * 0.7f), (int)(getHeight() * 0.04f)); + } + + if (drawCenterLines) { + InventoryRenderer.setColor(Color.white); + InventoryRenderer.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight()); + InventoryRenderer.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2); + } + + if (Game.state == STATE.GAME) { + InventoryRenderer.translate(getWidth() / 2, getHeight() - Inventory.INVENTORY_HEIGHT / 2); + InventoryRenderer.translate(-Inventory.INVENTORY_WIDTH / 2, -Inventory.INVENTORY_HEIGHT / 2); + Inventory.render(InventoryRenderer, InventorySlotRenderer); + + ClockRenderer.translate(getWidth() / 1.08 - Clock.width / 2, getHeight() / 7.75 - Clock.height / 2); + Clock.render(ClockRenderer); + + SecondaryHUD.render(SecondaryHUDRenderer); + ConstructionMenu.render(constructionMenuRenderer); + } + + RightClickMenu.render(debugRenderer); + + if (drawInventoryBounds && Game.state == STATE.GAME) { + + debugRenderer.setColor(Color.pink); + debugRenderer.draw(Inventory.INVENTORY_BOUNDS); + if (SecondaryHUD.tab == TAB.MINIMIZED) debugRenderer.draw(SecondaryHUD.minimizedBounds); + else debugRenderer.draw(SecondaryHUD.maximizedBounds); + + if (SecondaryHUD.tab == TAB.EQUIPMENT) { + for (final InventorySlot i : Player.equipmentSlots) { + debugRenderer.setColor(Color.GREEN); + debugRenderer.drawRect(i.bounds.x, i.bounds.y, i.bounds.width, i.bounds.height); + debugRenderer.setColor(Color.RED); + debugRenderer.drawString(Integer.toString(i.slotNumber), i.bounds.x + i.bounds.width / 2, i.bounds.y + i.bounds.height / 2); + } + } + for (final InventorySlot i : Player.inventorySlots) { + debugRenderer.setColor(Color.orange); + debugRenderer.drawRect(i.bounds.x, i.bounds.y, Inventory.SLOT_WIDTH, Inventory.SLOT_HEIGHT); + debugRenderer.setColor(Color.RED); + debugRenderer.drawString(Integer.toString(i.slotNumber), i.bounds.x + Inventory.SLOT_WIDTH / 2, i.bounds.y + Inventory.SLOT_HEIGHT / 2); + } + for (final InventorySlot i : Player.tabSlots) { + debugRenderer.setColor(Color.MAGENTA); + debugRenderer.drawRect(i.bounds.x, i.bounds.y, i.bounds.width, i.bounds.height); + debugRenderer.setColor(Color.RED); + debugRenderer.drawString(Integer.toString(i.slotNumber), i.bounds.x + i.bounds.width / 2, i.bounds.y + i.bounds.height / 2); + } + }} + + + debugRenderer.dispose(); + SecondaryHUDRenderer.dispose(); + InventorySlotRenderer.dispose(); + InventoryRenderer.dispose(); + ClockRenderer.dispose(); + g.dispose(); + g2d.dispose(); + bs.show(); + + frames++; /**** update fps ****/ + + rotation = tempRotation; + } catch (Exception e){ + e.printStackTrace(); + debugRenderer.dispose(); + SecondaryHUDRenderer.dispose(); + InventorySlotRenderer.dispose(); + InventoryRenderer.dispose(); + ClockRenderer.dispose(); + g.dispose(); + g2d.dispose(); + } + rendering = false; + } + } + + /***************************************************************************************************************************/ + + private final void init(){ + if (!running && !init) { + timeTakenForInit = System.nanoTime(); + init = running = true; + + pool = new ThreadPool(threads); + + SplashScreen.init(); TextureLoader.initSplashSheet(); fonts.init(); + pool.runTask(SplashScreen.splashRender); + + + // put all stuff that doesn't need jython + can be multithreaded here: + pool.runTask( new Runner(() -> { + + System.err.println(Utils.OS); + + renderer = new Render(); + Clock.init(); + RightClickMenu.init(); + SecondaryHUD.init(); + ConstructionMenu.init(); + + setFocusTraversalKeysEnabled(false); /* NOTE YOU NEED THIS FOR TAB KEY TO WORK! */ + frame = new JFrame("\"Nihilne\" ---- " + version); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setResizable(false); + frame.setLocationRelativeTo(null); + mouse = new MouseInput(); + game.addMouseListener(mouse); + game.addMouseWheelListener(mouse); + game.addMouseMotionListener(mouse); + panel = new JPanel(); /* add keybindings to this panel, Canvas does not support them */ + frame.add(panel); frame.add(game); frame.pack(); + + DeveloperConsole.init(); + + KeyInput.init(); + menu = new Menu(); + settings = new Settings(); + saving = new Saving(); + menu.init(); + TextureLoader.init(); + Tile.init(); + + })); + + + initJython(); + + Inventory.init(); Inventory.changeSettings(); + + settings.init(); Settings.applySettings(); settings.cleanUp(); SplashScreen.cleanUp(); + state = STATE.MENU; + System.gc(); + init = false; + System.out.println("Time taken for init: " + Utils.df.format((System.nanoTime() - timeTakenForInit) / Utils.second) + " seconds" + "\n" + "Welcome to Nihilne!"); + pool.runTask(game); + } + } + + private static final void initJython() { + try{ final long then = System.nanoTime(); + + Utils.initializePySystem(); + + // CUSTOM CLASSES + pi.exec("from engine import Game, Camera, DeveloperConsole, Handler, KeyInput, MouseInput"); + pi.exec("from hud import SecondaryHUD, RightClickMenu"); + pi.exec("from hud.inventory import Inventory, InventorySlot, InvenHelper"); + pi.exec("from player import Player, PlayerAttackSequence, HealthAndDurability"); + pi.exec("from world import DroppedItem"); + pi.exec("from mobs import Rabbit, Goblin, DROP_TABLES"); + + // INTERFACES + pi.exec("from interfaces import Mob, Biomes, ItemIDs, Colors, Directions, PlayerAnimationIDs"); + pi.exec("from interfaces.Mob import ANIMATION"); + pi.exec("from interfaces.ItemIDs import *"); + pi.exec("from interfaces.MobData import *"); + + // UTILS JAR + pi.exec("from utils import Utils, Point2f, Stack, Circle, Animation"); + + // LOAD SCRIPTS + pi.exec(Utils.readTextFileAsString("/inventory.py")); + Mob.initAllPyScripts(); + + pi.exec("print " + "'Jython / Python initialized --- Time taken: " + Utils.df.format((System.nanoTime() - then) / Utils.second) + " seconds'"); + } catch (Exception e) { e.printStackTrace(); System.exit(1); } + } + + public final void run() { + long now = System.nanoTime(), frameThen = System.nanoTime(), tickThen = System.nanoTime(), timer = System.currentTimeMillis(); + final double tickLimit = Utils.second / 60.0; + + frame.setVisible(true); + + while (running) { + now = System.nanoTime(); + + if (WorldGenerator.WORLD_GENERATED){ + if(now - tickThen > tickLimit) { + tick(); tickThen = now = System.nanoTime(); + } + + if (now - frameThen > frameLimit) { + frameThen = now; + + pool.runTask(renderer); + + if (displayFPS && System.currentTimeMillis() - timer > 1000) { + FPS = frames; TPS = ticks; frames = ticks = 0; + timer += 1000; + } + } + +// try { Thread.sleep(5); } catch(InterruptedException e) {} + } else try{ renderer.render(); Thread.sleep(20); } catch (InterruptedException e) { } + } + } + + public static synchronized final void makeFullScreen(){ + final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); /* get monitor */ + final GraphicsDevice vc = ge.getDefaultScreenDevice(); /* get video card */ + WIDTH = (int) vc.getDefaultConfiguration().getBounds().getWidth(); /* get width and height of screen */ + HEIGHT = (int) vc.getDefaultConfiguration().getBounds().getHeight(); + frame.setSize(WIDTH, HEIGHT); + /* can't undecorate unless frame is made undisplayable. */ + if (frame.isDisplayable()) frame.dispose(); + frame.setUndecorated(true); + vc.setFullScreenWindow(frame); /* also makes display displayable again */ + } + + public static synchronized final void undoFullScreen(){ frame.dispose(); frame.setUndecorated(false); frame.setVisible(true); } + + public synchronized final static void cleanUp() { + try { frame.dispose(); + pi.cleanup(); + pi.close(); + Handler.cleanUp(); + Map.cleanUp(); + PauseMenu.cleanUp(); + KeyInput.cleanUp(); + settings.cleanUp(); + menu.cleanUp(); + RightClickMenu.cleanUp(); + SecondaryHUD.cleanUp(); + Inventory.cleanUp(); + System.gc(); + System.out.println("~~~ Goodbye! ~~~"); + } catch (Exception e) { e.printStackTrace(); } + running = false; + System.exit(0); + } +} diff --git a/src/engine/GameToComponentCoordCalc.java b/src/engine/GameToComponentCoordCalc.java new file mode 100755 index 0000000..b2f8f34 --- /dev/null +++ b/src/engine/GameToComponentCoordCalc.java @@ -0,0 +1,26 @@ +package engine; + +import utils.Point2f; +import utils.Utils; + +public final class GameToComponentCoordCalc { + + private static float x, y; + public static Point2f convert(Point2f p){ + x = (float)(p.x * Math.cos(-Utils._45 * (Game.rotation - 1)) - (p.y * Math.sin(-Utils._45 * (Game.rotation - 1)))); + y = (float)(p.x * Math.sin(-Utils._45 * (Game.rotation - 1)) + (p.y * Math.cos(-Utils._45 * (Game.rotation - 1)))); + + return new Point2f(x / Game.scaleFactor - Camera.x, y / Game.scaleFactor - Camera.y); + } + + + private static int intX, intY; + public static int convertX(int x, int y){ + intX = (int)(x * Math.cos(-Utils._45 * (Game.rotation - 1)) - (y * Math.sin(-Utils._45 * (Game.rotation - 1)))); + return (int)(intX / Game.scaleFactor - Camera.x); + } public static int convertX(float x, float y){ return convertX((int)x, (int)y); } + public static int convertY(int x, int y){ + intY = (int)(y * Math.sin(-Utils._45 * (Game.rotation - 1)) + (y * Math.cos(-Utils._45 * (Game.rotation - 1)))); + return (int)(intY / Game.scaleFactor - Camera.y); + } public static int convertY(float x, float y){ return convertY((int)x, (int)y); } +} diff --git a/src/engine/Handler.java b/src/engine/Handler.java new file mode 100755 index 0000000..642f9d5 --- /dev/null +++ b/src/engine/Handler.java @@ -0,0 +1,274 @@ +package engine; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import java.util.HashSet; + +import hud.Map; +import hud.constructionmenu.ConstructionItem; +import interfaces.Mob; +import interfaces.Structure; +import player.Player; +import player.PlayerRender; +import player.PlayerTick; +import utils.Runner; +import utils.Stack; +import utils.Utils; +import world.Boulder; +import world.Debris; +import world.DroppedItem; +import world.Flower; +import world.Sapling; +import world.TallGrass; +import world.Tile; +import world.Tree; +import worldGen.WorldGenerator; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class Handler { + + public static final int NUM_TYPES_OF_HASHSETS = 1; /* NOTE: only useful for static things that won't be interacted with (tiles, debris etc) */ + + public static int numSectionsRowsCols; /* number of rectangular sections of map */ + public static Rectangle[][] sections; + public static int SECTION_SIZE_WIDTH_HEIGHT; + public static final int numRowsCols = 2048; /* num of rows and cols of tiles */ + public static boolean creatingMap; + + public static HashSet trees; + public static HashSet boulders; + public static HashSet flowers; + public static HashSet grass; + public static HashSet saplings; + public static HashSet droppedItems; + public static HashSet structures; + public static HashSet mobs; + public static HashSet debris; + + public static ArrayList>>> world; + public static volatile Rectangle AREA_RECT; + + public static void init() { + AREA_RECT = new Rectangle(0,0,0,0); + trees = new HashSet(); + boulders = new HashSet(); + mobs = new HashSet(); + flowers = new HashSet(); + grass = new HashSet(); + saplings = new HashSet(); + droppedItems = new HashSet(); + structures = new HashSet(); + debris = new HashSet(); + + WorldGenerator.generateWorld(); + } + + public static final void tick() { if(!WorldGenerator.WORLD_GENERATED) return; + tickTiles(); + try{ for(final Debris i : debris) i.tick(); } catch (Exception e) {} + try{ for(final Sapling i : saplings) if(AREA_RECT.contains(i.center.x, i.center.y)) i.tick(); } catch (Exception e) {}; + try{ for(final Flower i : flowers) if(AREA_RECT.contains(i.center.x, i.center.y)) i.tick(); } catch (Exception e) {}; + try{ for(final TallGrass i : grass) if(AREA_RECT.contains(i.center.x, i.center.y)) i.tick(); } catch (Exception e) {}; + try{ for(final Tree i : trees) if(AREA_RECT.contains(i.center.x, i.center.y)) i.tick(); } catch (Exception e) {}; + try{ for(final Boulder i : boulders) if(AREA_RECT.contains(i.center.x, i.center.y)) i.tick(); } catch (Exception e) {}; + try{ for(final DroppedItem i : droppedItems) if(AREA_RECT.contains(i.center.x, i.center.y)) i.tick(); } catch (Exception e) {}; + try{ for(final Structure i : structures) if(AREA_RECT.contains(i.center.x, i.center.y)) i.tick(); } catch (Exception e) {}; + + try{ for(final Mob i : mobs) if(AREA_RECT.contains(i.center.x, i.center.y)) i.tick(); } catch (ConcurrentModificationException asdf) {} catch (Exception e) { e.printStackTrace(); }; + + PlayerTick.tick(); + } + + private static boolean dontRenderPlayer; + public static final void render(Graphics2D g2d) { if(!WorldGenerator.WORLD_GENERATED) return; + dontRenderPlayer = false; + renderTiles(g2d); + try{ for(final Debris i : debris) if(i.discovered && AREA_RECT.contains(i.x, i.y)) i.render(g2d); } catch (Exception e) {} + try{ for(final Sapling i : saplings) if(i.discovered && AREA_RECT.contains(i.center.x, i.center.y)) i.render(g2d); } catch (Exception e) {} + try{ for(final Flower i : flowers) if(i.discovered && AREA_RECT.contains(i.center.x, i.center.y)) i.render(g2d); } catch (Exception e) {} + try{ for(final TallGrass i : grass) if(i.discovered && AREA_RECT.contains(i.center.x, i.center.y)) i.render(g2d); } catch (Exception e) {} + try{ for(final Boulder i : boulders) if(i.discovered && AREA_RECT.contains(i.center.x, i.center.y)) i.render(g2d); } catch (Exception e) {} + try{ for(final DroppedItem i : droppedItems) if(i.discovered && AREA_RECT.contains(i.center.x, i.center.y)) i.render(g2d); } catch (Exception e) {} + try{ for(final Mob i : mobs) if(i.discovered && AREA_RECT.contains(i.center.x, i.center.y)) i.render(g2d); } catch (Exception e) {} + try{ for(final Structure i : structures) if(AREA_RECT.contains(i.center.x, i.center.y)) i.render(g2d); } catch (Exception e) {} + + + try{ if(!dontRenderPlayer) PlayerRender.render(g2d); } catch (Exception e) {} + try{ ConstructionItem.render(g2d); } catch (Exception e) {} + try{ for(final Tree i : trees) if(i.discovered && AREA_RECT.contains(i.center.x, i.center.y)){ + if(i.bounds.contains(Player.center.x, Player.center.y)){ + if(i.bounds.y + i.bounds.height/1.25 < Player.center.y){ + i.render(g2d); PlayerRender.render(g2d); dontRenderPlayer = true; + } else if(i.bounds.y + i.bounds.height/1.25 > Player.center.y){ + PlayerRender.render(g2d); dontRenderPlayer = true; i.render(g2d); + } + } else i.render(g2d); }} catch (Exception e) {e.printStackTrace();} + } + + public static final void getMapImage(){ + creatingMap = true; +// final long then = System.currentTimeMillis(); + final double scalefactor = 1d/96d; + final int WH = numRowsCols/3; + final BufferedImage map = new BufferedImage(WH, WH, BufferedImage.TYPE_INT_RGB); + final Graphics2D g2d = (Graphics2D) map.createGraphics(); + g2d.scale(scalefactor, scalefactor); + g2d.setColor(Color.red); + + Game.pool.runTask(new Runner(() -> { + try{ + outerLoop: + for(int i = 0; i < sections.length; i++) + for(int j = 0; j < sections[i].length; j++) + if(sections[i][j].contains(Player.center.x, Player.center.y)){ + try { for(final Tile tile : world.get(i-1).get(j-1).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(final Tile tile : world.get(i).get(j-1).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(final Tile tile : world.get(i+1).get(j-1).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(final Tile tile : world.get(i-1).get(j).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(final Tile tile : world.get(i).get(j).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(final Tile tile : world.get(i+1).get(j).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(final Tile tile : world.get(i-1).get(j+1).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(final Tile tile : world.get(i).get(j+1).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(final Tile tile : world.get(i+1).get(j+1).get(0)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + break outerLoop; + }} catch (Exception e) { e.printStackTrace(); } + + + for(int i = 0; i < sections.length/2; i++) + for(int j = 0; j < sections[i].length; j++) + for(final Tile tile : world.get(i).get(j).get(TILE_LIST)) + try { tile.render(g2d); } catch (Exception e) {} + })); + + Game.pool.runTask(new Runner(() -> { + try{ + for(int i = sections.length/2-1; i < sections.length; i++) + for(int j = 0; j < sections[i].length; j++) + for(final Tile tile : world.get(i).get(j).get(TILE_LIST)) + try { tile.render(g2d); } catch (Exception e) {} + + creatingMap = false; }catch(Exception e) {e.printStackTrace();} + Map.map = map; +// System.err.println("Map Painted --- Total Time Taken: " + Float.toString((System.currentTimeMillis() - then)/1000f)+ " seconds ~~~"); + g2d.dispose(); + })); + + + BufferedImage overlay = new BufferedImage(WH, WH, BufferedImage.TYPE_INT_ARGB); + Graphics2D copy = (Graphics2D) overlay.getGraphics(); + copy.scale(scalefactor, scalefactor); + for(final Boulder i : boulders) i.render(copy); + for(final Tree i : trees) i.render(copy); + for(final Structure i : Handler.structures) i.render(copy); + copy.dispose(); copy = null; + Map.overlay = overlay; + } + + public static int numSectionsRowsColsHalved; + public static final void addTile(Tile t){ + int i = numSectionsRowsColsHalved, j = numSectionsRowsColsHalved; + while(true){ + if(sections[i][j].contains(t.x, t.y)){ + world.get(i).get(j).get(0).push(t); + return; + } + else try{ if(t.x < sections[i][j].x) i--; + else if(t.x > sections[i][j].x && !(t.x < sections[i][j].x + SECTION_SIZE_WIDTH_HEIGHT)) i++; + if(t.y < sections[i][j].y) j--; + else if(t.y > sections[i][j].y && !(t.y < sections[i][j].y + SECTION_SIZE_WIDTH_HEIGHT)) j++; + } catch (IndexOutOfBoundsException e){ i = j = Utils.rand.nextInt(numSectionsRowsCols); } + } + } + + /* Gets the Current section that the coord is in, (only the single section) */ + public static final Stack currentTileSection(float x, float y){ + for(int i = 0; i < sections.length; i++) + for(int j = 0; j < sections[i].length; j++) + if(sections[i][j].contains(x, y)) + return world.get(i).get(j).get(TILE_LIST); + + return world.get(0).get(0).get(TILE_LIST); + } + + private static final int TILE_LIST = 0; /* add more if wanting to add different ones later, but for now just tile is good */ + + private static void tickTiles(){ + Tile.runAnimations(); + try{ + outerLoop: + for(int i = 0; i < sections.length; i++) + for(int j = 0; j < sections[i].length; j++) + if(sections[i][j].contains(Player.center.x, Player.center.y)){ + try{ AREA_RECT.x = sections[i-1][j-1].x; AREA_RECT.y = sections[i-1][j-1].y; /* try left and above */ + } catch (IndexOutOfBoundsException e1){ + try { AREA_RECT.x = sections[i-1][j].x; AREA_RECT.y = sections[i-1][j].y; /* catch, try just to the left */ + } catch (IndexOutOfBoundsException e2){ + try { AREA_RECT.x = sections[i][j-1].x; AREA_RECT.y = sections[i][j-1].y; /* catch, try just above */ + } catch (IndexOutOfBoundsException e3){ /* catch, must be in the top left corner, same coords */ + try{ AREA_RECT.x = sections[i][j].x; AREA_RECT.y = sections[i][j].y; + } catch (IndexOutOfBoundsException e4){ e4.printStackTrace(); System.exit(0); } /* catch, all hope is gone */ + + } + } + } + try { for(Tile tile : world.get(i-1).get(j-1).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i).get(j-1).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i+1).get(j-1).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i-1).get(j).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i).get(j).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i+1).get(j).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i-1).get(j+1).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i).get(j+1).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i+1).get(j+1).get(0)) tile.tick(); } catch (IndexOutOfBoundsException e) {} + break outerLoop; + }} catch (Exception e) { e.printStackTrace(); } + } + + private static void renderTiles(Graphics2D g2d){ + try{ + outerLoop: + for(int i = 0; i < sections.length; i++) + for(int j = 0; j < sections[i].length; j++) + if(sections[i][j].contains(Player.center.x, Player.center.y)){ + try{ AREA_RECT.x = sections[i-1][j-1].x; AREA_RECT.y = sections[i-1][j-1].y; /* try left and above */ + } catch (IndexOutOfBoundsException e1){ + try { AREA_RECT.x = sections[i-1][j].x; AREA_RECT.y = sections[i-1][j].y; /* catch, try just to the left */ + } catch (IndexOutOfBoundsException e2){ + try { AREA_RECT.x = sections[i][j-1].x; AREA_RECT.y = sections[i][j-1].y; /* catch, try just above */ + } catch (IndexOutOfBoundsException e3){ /* catch, must be in the top left corner, same coords */ + try{ AREA_RECT.x = sections[i][j].x; AREA_RECT.y = sections[i][j].y; + } catch (IndexOutOfBoundsException e4){ e4.printStackTrace(); System.exit(0); } /* catch, all hope is gone */ + + } + } + } + + for(int count = 0; count < NUM_TYPES_OF_HASHSETS; count++){ /* render the 3x3 grid of tile hashsets */ + try { for(Tile tile : world.get(i-1).get(j-1).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i).get(j-1).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i+1).get(j-1).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i-1).get(j).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i).get(j).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i+1).get(j).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i-1).get(j+1).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i).get(j+1).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + try { for(Tile tile : world.get(i+1).get(j+1).get(count)) tile.render(g2d); } catch (IndexOutOfBoundsException e) {} + } + + break outerLoop; + }} catch (Exception e) { e.printStackTrace(); } + } + + public static final synchronized void cleanUp() { + try { mobs.clear(); structures.clear(); world.clear(); } catch (NullPointerException npe) { } + world = null; sections = null; mobs = null; structures = null; + } + +} diff --git a/src/engine/KeyInput.java b/src/engine/KeyInput.java new file mode 100755 index 0000000..645b02c --- /dev/null +++ b/src/engine/KeyInput.java @@ -0,0 +1,488 @@ +package engine; + +import java.awt.event.ActionEvent; +import java.awt.event.KeyAdapter; +import java.awt.event.KeyEvent; +import java.util.HashSet; + +import javax.swing.AbstractAction; +import javax.swing.Action; +import javax.swing.JComponent; +import javax.swing.KeyStroke; + +import engine.Game.STATE; +import hud.Map; +import hud.RightClickMenu; +import hud.SecondaryHUD; +import hud.inventory.Inventory; +import player.Player; +import player.PlayerAttackSequence; +import utils.Utils; +import worldGen.WorldGenerator; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2f016 * + ~~~~ All Rights Reserved ~~~~ */ + +@SuppressWarnings("serial") /* all the keybindings require this, really annoying */ +final class KeyInput extends KeyAdapter { + + private static final Integer W=0, A=1, S=2, D=3, SPACE=4, TAB=5, _1=6, _2=7, _3=8, _4=9, _5=10, E=11, Q=12, ESCAPE=13, F=14, + MINUS = 15, EQUALS = 16, CTRL = 17, PLUS=18; + + private static HashSet keysDown; + + public static final void init() { + if(keysDown == null) keysDown = new HashSet(); else keysDown.clear(); + movementButtons(); + escape(); + Game.game.addKeyListener(new KeyInput()); /* for tab and other keys that are a pain with keybinds */ + } + + public final static void tick() { + if(Player.health <= 0) return; + + if(Game.state == STATE.DEVELOPER_CONSOLE && !keysDown.isEmpty()) { keysDown.clear(); return; } + + if(keysDown.contains(TAB)){ + if(Game.state == STATE.GAME){ + Game.state = STATE.MAP; + if(!Handler.creatingMap) Handler.getMapImage(); + } else if(Game.state == STATE.MAP){ + Map.clicked = Map.hasBeenClicked = false; + Game.state = STATE.GAME; + } + keysDown.remove(TAB); + Map.hasBeenClicked = false; + } + + if (Game.state == STATE.GAME) { + if(!WorldGenerator.WORLD_GENERATED) return; + + if (keysDown.contains(_1)) { + SecondaryHUD.tab = SecondaryHUD.TAB.BACKPACK; + Inventory.changeSettings(); + } else if (keysDown.contains(_2)) { + SecondaryHUD.tab = SecondaryHUD.TAB.EQUIPMENT; + Inventory.changeSettings(); + } else if (keysDown.contains(_3)) { + SecondaryHUD.tab = SecondaryHUD.TAB.SKILLS; + Inventory.changeSettings(); + } else if (keysDown.contains(_4)) { + SecondaryHUD.tab = SecondaryHUD.TAB.MAGIC; + Inventory.changeSettings(); + } else if (keysDown.contains(_5)) { + SecondaryHUD.tab = SecondaryHUD.TAB.MINIMIZED; + Inventory.changeSettings(); + } + + if(!RightClickMenu.OVERRIDE_SPACE) { + if (keysDown.contains(SPACE)) { + + RightClickMenu.OVERRIDE_F = false; + + if(!Player.attacking) Player.using = true; + } else Player.using = false; + } + + + if(!RightClickMenu.OVERRIDE_F) { + if (keysDown.contains(F)) { + RightClickMenu.OVERRIDE_SPACE = false; + + if(!Player.using && !Player.attacking) PlayerAttackSequence.start(); + } + } + + // ZOOMING WITH CTRL - + + + if(keysDown.contains(CTRL)) { + + if(keysDown.contains(MINUS)) { + if(Game.state == STATE.GAME) { + Game.scaleFactor -= 0.25d; + Game.scaleFactor = Utils.clamp(Game.scaleFactor, Game.MIN_SCALEFACTOR, Game.MAX_SCALEFACTOR); + } else if (Game.state == STATE.MAP) Map.scaleFactor -= 0.25d; + + keysDown.remove(MINUS); + + // NOTE: ctrl makes player keep moving for some reason, this fixes but its kinda shitty + // will need to find a work around later + if(keysDown.contains(W)) keysDown.remove(W); if(keysDown.contains(A)) keysDown.remove(A); + if(keysDown.contains(S)) keysDown.remove(S); if(keysDown.contains(D)) keysDown.remove(D); + } + + else if(keysDown.contains(EQUALS) || keysDown.contains(PLUS)) { + if(Game.state == STATE.GAME) { + Game.scaleFactor += 0.25d; + Game.scaleFactor = Utils.clamp(Game.scaleFactor, Game.MIN_SCALEFACTOR, Game.MAX_SCALEFACTOR); + } else if (Game.state == STATE.MAP) Map.scaleFactor += 0.25d; + + if(keysDown.contains(EQUALS)) keysDown.remove(EQUALS); + else if(keysDown.contains(PLUS)) keysDown.remove(PLUS); + + if(keysDown.contains(W)) keysDown.remove(W); if(keysDown.contains(A)) keysDown.remove(A); + if(keysDown.contains(S)) keysDown.remove(S); if(keysDown.contains(D)) keysDown.remove(D); + } + } + + // END ZOOMING WITH CTRL - + + + + // NOTE: These two timer values are given that the timer is set to ---> 28 <---- + if(!Player.attacking || PlayerAttackSequence.timer > 25 || PlayerAttackSequence.timer < 7) { + if(keysDown.contains(W) && keysDown.contains(D)){ + Player.velX = Player.WALKING_SPEED; + Player.velY = -Player.WALKING_SPEED; + Player.keepWalkingX = Player.keepWalkingY = false; + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + } else if(keysDown.contains(W) && keysDown.contains(A)){ + Player.velX = -Player.WALKING_SPEED; + Player.velY = -Player.WALKING_SPEED; + Player.keepWalkingX = Player.keepWalkingY = false; + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + } else if(keysDown.contains(S) && keysDown.contains(D)){ + Player.velX = Player.WALKING_SPEED; + Player.velY = Player.WALKING_SPEED; + Player.keepWalkingX = Player.keepWalkingY = false; + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + } else if(keysDown.contains(S) && keysDown.contains(A)){ + Player.velX = -Player.WALKING_SPEED; + Player.velY = Player.WALKING_SPEED; + Player.keepWalkingX = Player.keepWalkingY = false; + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + } else if(keysDown.contains(W)){ + Player.velX = 0; + Player.velY = -Player.WALKING_SPEED; + Player.keepWalkingX = Player.keepWalkingY = false; + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + }else if(keysDown.contains(S)){ + Player.velX = 0; + Player.velY = Player.WALKING_SPEED; + Player.keepWalkingX = Player.keepWalkingY = false; + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + }else if(keysDown.contains(D)){ + Player.velX = Player.WALKING_SPEED; + Player.velY = 0; + Player.keepWalkingX = Player.keepWalkingY = false; + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + }else if(keysDown.contains(A)){ + Player.velX = -Player.WALKING_SPEED; + Player.velY = 0; + Player.keepWalkingX = Player.keepWalkingY = false; + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + } + + // Stop the player + if (!Player.keepWalkingX && !Player.keepWalkingY) + if (!keysDown.contains(W) && !keysDown.contains(A) && !keysDown.contains(S) && !keysDown.contains(D)) + Player.velX = Player.velY = 0; + + if (keysDown.contains(E)) { + if (++Game.tempRotation >= 9) Game.tempRotation = 1; + keysDown.remove(E); + } + if (keysDown.contains(Q)) { + if (--Game.tempRotation < 1) Game.tempRotation = 8; + keysDown.remove(Q); + } + } else Player.velX = Player.velY = 0; + + + + } + + if (keysDown.contains(ESCAPE)) { + if (Game.state == STATE.GAME) { + if (PauseMenu.pauseButtons.size() == 0) { + PauseMenu.cleanUp(); + PauseMenu.init(); + Game.state = STATE.PAUSED; + keysDown.remove(ESCAPE); + } + } else if (Game.state == STATE.PAUSED) { + PauseMenu.cleanUp(); + Game.state = STATE.GAME; + keysDown.remove(ESCAPE); + } + RightClickMenu.OVERRIDE_SPACE = RightClickMenu.OVERRIDE_F = false; + } + } + + private static final void movementButtons() { + // Presses Walking + final Action walkUp = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(W)) keysDown.add(W); + } + }; + + final Action walkDown = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(S)) keysDown.add(S); + } + }; + + final Action walkLeft = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(A)) keysDown.add(A); + } + }; + + final Action walkRight = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(D)) keysDown.add(D); + } + }; + + // Camera Rotation + final Action rotateRight = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(E)) keysDown.add(E); + } + }; + final Action rotateLeft = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(Q)) keysDown.add(Q); + } + }; + + // using (space) + final Action using = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(SPACE)) keysDown.add(SPACE); + } + }; + + // attacking + final Action attacking = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(F)) keysDown.add(F); + } + }; + + // 1 - 5 KEYS + final Action _1 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(KeyInput._1)) keysDown.add(KeyInput._1); + } + }; + final Action _2 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(KeyInput._2)) keysDown.add(KeyInput._2); + } + }; + final Action _3 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(KeyInput._3)) keysDown.add(KeyInput._3); + } + }; + final Action _4 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(KeyInput._4)) keysDown.add(KeyInput._4); + } + }; + final Action _5 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (!keysDown.contains(KeyInput._5)) keysDown.add(KeyInput._5); + } + }; + + // CTRL - + = SCROLLING + final Action MINUS = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if(!keysDown.contains(KeyInput.MINUS)) keysDown.add(KeyInput.MINUS); + } + }; + final Action EQUALS = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if(!keysDown.contains(KeyInput.EQUALS)) keysDown.add(KeyInput.EQUALS); + } + }; + final Action CTRL = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if(!keysDown.contains(KeyInput.CTRL)) keysDown.add(KeyInput.CTRL); + } + }; + final Action PLUS = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if(!keysDown.contains(KeyInput.PLUS)) keysDown.add(KeyInput.PLUS); + } + }; + + final int when = JComponent.WHEN_IN_FOCUSED_WINDOW; + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("W"), "walkUp"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("S"), "walkDown"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("A"), "walkLeft"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("D"), "walkRight"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("UP"), "walkUp"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("DOWN"), "walkDown"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("LEFT"), "walkLeft"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("RIGHT"), "walkRight"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("E"), "rotateRight"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("Q"), "rotateLeft"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("SPACE"), "using"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("F"), "attacking"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("1"), "1"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("2"), "2"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("3"), "3"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("4"), "4"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("5"), "5"); + Game.panel.getActionMap().put("walkUp", walkUp); + Game.panel.getActionMap().put("walkDown", walkDown); + Game.panel.getActionMap().put("walkLeft", walkLeft); + Game.panel.getActionMap().put("walkRight", walkRight); + Game.panel.getActionMap().put("rotateRight", rotateRight); + Game.panel.getActionMap().put("rotateLeft", rotateLeft); + Game.panel.getActionMap().put("using", using); + Game.panel.getActionMap().put("attacking", attacking); + Game.panel.getActionMap().put("1", _1); + Game.panel.getActionMap().put("2", _2); + Game.panel.getActionMap().put("3", _3); + Game.panel.getActionMap().put("4", _4); + Game.panel.getActionMap().put("5", _5); + Game.panel.getActionMap().put("CTRL", CTRL); + Game.panel.getActionMap().put("MINUS", MINUS); + Game.panel.getActionMap().put("EQUALS", EQUALS); + Game.panel.getActionMap().put("PLUS", PLUS); + + + // Releases + final Action stopWalkUp = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(W)) keysDown.remove(W); + } + }; + + final Action stopWalkDown = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(S)) keysDown.remove(S); + } + }; + + final Action stopWalkLeft = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(A)) keysDown.remove(A); + } + }; + + final Action stopWalkRight = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(D)) keysDown.remove(D); + } + }; + + final Action stopUsing = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(SPACE)) keysDown.remove(SPACE); + } + }; + + final Action stopAttacking = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(F)) keysDown.remove(F); + } + }; + + final Action release1 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(KeyInput._1)) keysDown.remove(KeyInput._1); + } + }; + final Action release2 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(KeyInput._2)) keysDown.remove(KeyInput._2); + } + }; + final Action release3 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(KeyInput._3)) keysDown.remove(KeyInput._3); + } + }; + final Action release4 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(KeyInput._4)) keysDown.remove(KeyInput._4); + } + }; + final Action release5 = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(KeyInput._5)) keysDown.remove(KeyInput._5); + } + }; + + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released W"), "stopWalkUp"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released S"), "stopWalkDown"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released A"), "stopWalkLeft"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released D"), "stopWalkRight"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released UP"), "stopWalkUp"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released DOWN"), "stopWalkDown"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released LEFT"), "stopWalkLeft"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released RIGHT"), "stopWalkRight"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released SPACE"), "stopUsing"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released F"), "stopAttacking"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released 1"), "release1"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released 2"), "release2"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released 3"), "release3"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released 4"), "release4"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released 5"), "release5"); + Game.panel.getActionMap().put("stopWalkUp", stopWalkUp); + Game.panel.getActionMap().put("stopWalkDown", stopWalkDown); + Game.panel.getActionMap().put("stopWalkLeft", stopWalkLeft); + Game.panel.getActionMap().put("stopWalkRight", stopWalkRight); + Game.panel.getActionMap().put("stopUsing", stopUsing); + Game.panel.getActionMap().put("stopAttacking", stopAttacking); + Game.panel.getActionMap().put("release1", release1); + Game.panel.getActionMap().put("release2", release2); + Game.panel.getActionMap().put("release3", release3); + Game.panel.getActionMap().put("release4", release4); + Game.panel.getActionMap().put("release5", release5); + } + + private static final void escape() { + final int when = JComponent.WHEN_IN_FOCUSED_WINDOW; + final Action escape = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if(Game.state != STATE.DEVELOPER_CONSOLE) if (!keysDown.contains(ESCAPE)) keysDown.add(ESCAPE); + } + }; + + final Action releasedESCAPE = new AbstractAction() { + public void actionPerformed(ActionEvent e) { + if (keysDown.contains(ESCAPE)) keysDown.remove(ESCAPE); + } + }; + + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("ESCAPE"), "escape"); + Game.panel.getInputMap(when).put(KeyStroke.getKeyStroke("released ESCAPE"), "released ESCAPE"); + Game.panel.getActionMap().put("released ESCAPE", releasedESCAPE); + Game.panel.getActionMap().put("escape", escape); + } + + // BOOLEANS TO STOP CONSTANT FIRING OF KEYS + private static boolean tabDown; + + public final void keyPressed(KeyEvent e){ + if(Game.state == STATE.DEVELOPER_CONSOLE) return; + + else if(e.getKeyCode() == KeyEvent.VK_CONTROL && !keysDown.contains(CTRL)) keysDown.add(CTRL); + else if(e.getKeyCode() == KeyEvent.VK_MINUS && !keysDown.contains(MINUS)) keysDown.add(MINUS); + else if(e.getKeyCode() == KeyEvent.VK_EQUALS && !keysDown.contains(EQUALS)) { keysDown.add(EQUALS); } + else if(e.getKeyCode() == KeyEvent.VK_PLUS && !keysDown.contains(PLUS)) { keysDown.add(PLUS); } + + else if(!tabDown && e.getKeyCode() == KeyEvent.VK_TAB && !keysDown.contains(TAB)){ + keysDown.add(TAB); + tabDown = true; + } + } + + public final void keyReleased(KeyEvent e){ + if(tabDown && e.getKeyCode() == KeyEvent.VK_TAB) tabDown = false; + + else if(e.getKeyCode() == KeyEvent.VK_CONTROL && keysDown.contains(CTRL)) keysDown.remove(CTRL); + else if(e.getKeyCode() == KeyEvent.VK_MINUS && keysDown.contains(MINUS)) keysDown.remove(MINUS); + else if(e.getKeyCode() == KeyEvent.VK_EQUALS && keysDown.contains(EQUALS)) keysDown.remove(EQUALS); + else if(e.getKeyCode() == KeyEvent.VK_PLUS && keysDown.contains(PLUS)) keysDown.remove(PLUS); + } + + public static final synchronized void cleanUp(){ keysDown.clear(); keysDown = null; } +} diff --git a/src/engine/Menu.java b/src/engine/Menu.java new file mode 100755 index 0000000..a2bf96e --- /dev/null +++ b/src/engine/Menu.java @@ -0,0 +1,77 @@ +package engine; + +import java.awt.Desktop; +import java.awt.Graphics2D; + +import engine.Game.STATE; +import utils.Stack; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class Menu { + + public static volatile Stack menuButtons = new Stack(); + + public synchronized void init() { + // PARAMETERS: x, y, width, height, type, isHovering + MenuButton playButton = new MenuButton(0, 0, 155, 29, 0, false, true); + MenuButton settingsButton = new MenuButton(0, 0, 155, 29, 2, false, true); + MenuButton aboutButton = new MenuButton(0, 0, 155, 29, 4, false, true); + MenuButton quitButton = new MenuButton(0, 0, 155, 29, 6, false, true); + + menuButtons.add(playButton); + menuButtons.add(settingsButton); + menuButtons.add(aboutButton); + menuButtons.add(quitButton); + } + + public synchronized void onClick() { + for (int i = 0; i < menuButtons.size(); i++) { + if (menuButtons.get(i).contains(MouseInput.mouseXY) && menuButtons.get(i).type == 0) { // PLAY BUTTON + Game.state = STATE.GAME; + Handler.cleanUp(); + Handler.init(); + Game.settings.cleanUp(); + } else if (menuButtons.get(i).contains(MouseInput.mouseXY) && menuButtons.get(i).type == 2) { // SETTINGS BUTTON + Game.settings.init(); + Game.state = STATE.SETTINGS; + } else if (menuButtons.get(i).contains(MouseInput.mouseXY) && menuButtons.get(i).type == 4) { // ABOUT BUTTON + try { Desktop.getDesktop().browse(java.net.URI.create("https://www.steamcommunity.com/sharedfiles/filedetails/?id=668438834")); } catch (Exception e) { e.printStackTrace(); } + } else if (menuButtons.get(i).contains(MouseInput.mouseXY) && menuButtons.get(i).type == 6) { // QUIT BUTTON + Game.cleanUp(); + } + } + } + + public void render(Graphics2D g2d) { + for (int i = 0; i < menuButtons.size(); i++) + menuButtons.get(i).render(g2d); + + } + + public void tick() { + try { + + // tick buttons x and y to adjust for screen resolutoin changes + menuButtons.get(0).x = (Game.WIDTH - Game.WIDTH / 3.5f); + menuButtons.get(0).y = Game.HEIGHT * 0.65f; + menuButtons.get(1).x = (Game.WIDTH - Game.WIDTH / 3.5f); + menuButtons.get(1).y = Game.HEIGHT * 0.7f; + menuButtons.get(2).x = (Game.WIDTH - Game.WIDTH / 3.5f); + menuButtons.get(2).y = Game.HEIGHT * 0.75f; + menuButtons.get(3).x = (Game.WIDTH - Game.WIDTH / 3.5f); + menuButtons.get(3).y = Game.HEIGHT * 0.8f; + + for (int i = 0; i < menuButtons.size(); i++) + menuButtons.get(i).tick(); + + } catch (Exception e) {} + } + + public void cleanUp() { + menuButtons.clear(); + } + +} diff --git a/src/engine/MenuButton.java b/src/engine/MenuButton.java new file mode 100755 index 0000000..71211dc --- /dev/null +++ b/src/engine/MenuButton.java @@ -0,0 +1,163 @@ +package engine; + +import java.awt.Graphics2D; +import java.awt.Rectangle; + +import _texture.loader.Textures; +import engine.Game.STATE; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class MenuButton extends Rectangle { + private static final long serialVersionUID = 1337; + + public float x, y; + public int width, height; + + public int type; + public volatile boolean isHovering, isVisible, isAtTop, otherContextMenuIsOpen; + + // main buttons + public MenuButton(float x, float y, int width, int height, int type, boolean isHovering, boolean isVisible) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.type = type; + this.isHovering = isHovering; + this.isVisible = isVisible; + setBounds((int) x, (int) y, width, height); + } + + // settings buttons + public MenuButton(float x, float y, int width, int height, int type, boolean isHovering, boolean isVisible, boolean isAtTop, + boolean otherContextMenuIsOpen) { + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.type = type; + this.isHovering = isHovering; + this.isVisible = isVisible; + this.isAtTop = isAtTop; + this.otherContextMenuIsOpen = otherContextMenuIsOpen; + setBounds((int) x, (int) y, width, height); + } + + public void tick() { + setBounds((int) x, (int) y, width, (int) (height * 0.9f)); + calcIsHovering(); + } + + public void calcIsHovering() { + if (Game.state == STATE.MENU) { + // Menu + for (int i = 0; i < (Menu.menuButtons.size()); i++) { + try { + if (Menu.menuButtons.get(i).contains(MouseInput.mouseXY)) { + Menu.menuButtons.get(i).isHovering = true; + } else Menu.menuButtons.get(i).isHovering = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + else if (Game.state == STATE.PAUSED) { + // Paused + for (int i = 0; i < (PauseMenu.pauseButtons.size()); i++) { + try { + if (PauseMenu.pauseButtons.get(i).contains(MouseInput.mouseXY)) { + PauseMenu.pauseButtons.get(i).isHovering = true; + } else PauseMenu.pauseButtons.get(i).isHovering = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + + } + + else if (Game.state == STATE.SETTINGS) { + // settings + for (int i = 0; i < (Game.settings.mainButtons.size()); i++) { + try { + if (Game.settings.mainButtons.get(i).contains(MouseInput.mouseXY)) { + Game.settings.mainButtons.get(i).isHovering = true; + } else Game.settings.mainButtons.get(i).isHovering = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + + for (int i = 0; i < (Game.settings.resolutionContextMenu.size()); i++) { + try { + if (Game.settings.resolutionContextMenu.get(i).contains(MouseInput.mouseXY)) { + Game.settings.resolutionContextMenu.get(i).isHovering = true; + } else Game.settings.resolutionContextMenu.get(i).isHovering = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + + for (int i = 0; i < Game.settings.resizeableContextMenu.size(); i++) { + try { + if (Game.settings.resizeableContextMenu.get(i).contains(MouseInput.mouseXY)) { + Game.settings.resizeableContextMenu.get(i).isHovering = true; + } else Game.settings.resizeableContextMenu.get(i).isHovering = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + + for (int i = 0; i < Game.settings.displayFPSContextMenu.size(); i++) { + try { + if (Game.settings.displayFPSContextMenu.get(i).contains(MouseInput.mouseXY)) { + Game.settings.displayFPSContextMenu.get(i).isHovering = true; + } else Game.settings.displayFPSContextMenu.get(i).isHovering = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + for ( + + int i = 0; i < Game.settings.showEnemyHealthContextMenu.size(); i++) { + try { + if (Game.settings.showEnemyHealthContextMenu.get(i).contains(MouseInput.mouseXY)) { + Game.settings.showEnemyHealthContextMenu.get(i).isHovering = true; + } else Game.settings.showEnemyHealthContextMenu.get(i).isHovering = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + + for (int i = 0; i < (Game.settings.fpsContextMenu.size()); i++) { + try { + if (Game.settings.fpsContextMenu.get(i).contains(MouseInput.mouseXY)) { + Game.settings.fpsContextMenu.get(i).isHovering = true; + } else Game.settings.fpsContextMenu.get(i).isHovering = false; + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + public void render(Graphics2D g2d) { + try{ + if ((this == PauseMenu.pauseButtons.get(2))) { + if (!isHovering && isVisible) g2d.drawImage(Textures.menuButtonSheet[8], (int) x, (int) y, null); + else if (isVisible) g2d.drawImage(Textures.menuButtonSheet[9], (int) x, (int) y, null); + return; + } + } catch (Exception e){ /* because pause menu isn't always init'd */ } + + if (!isHovering && isVisible) g2d.drawImage(Textures.menuButtonSheet[type], (int) x, (int) y, null); + else if (isVisible) g2d.drawImage(Textures.menuButtonSheet[type + 1], (int) x, (int) y, null); + } + + public synchronized void setIsVisible(boolean isVisible) { + this.isVisible = isVisible; + } +} \ No newline at end of file diff --git a/src/engine/MouseInput.java b/src/engine/MouseInput.java new file mode 100755 index 0000000..5560d36 --- /dev/null +++ b/src/engine/MouseInput.java @@ -0,0 +1,200 @@ +package engine; + +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; + +import engine.Game.STATE; +import hud.Clock; +import hud.Map; +import hud.RightClickMenu; +import hud.SecondaryHUD; +import hud.SecondaryHUD.TAB; +import hud.constructionmenu.ConstructionItem; +import hud.constructionmenu.ConstructionMenu; +import hud.constructionmenu.ConstructionMenuCategory; +import hud.inventory.Inventory; +import hud.inventory.InventorySlot; +import player.MouseMovement; +import player.Player; +import utils.Utils; +import world.DroppedItem; +import world.Tile; +import worldGen.WorldGenerator; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class MouseInput implements MouseListener, MouseWheelListener, MouseMotionListener { + + public static final Point mouseXY = new Point(0, 0), rightClickPos = new Point(0, 0); + public static final Point clickPos = new Point(0, 0); + public static final Point adjustedMouseXY = new Point(0,0); + public static final Point adjustedClickPos = new Point(0, 0); + public static final Point adjustedRightClickPos = new Point(0,0); + private static final Point TEMP = new Point(0,0); + + public static boolean mouseClicked, mousePressed, mouseRightClicked, mouseDragged; + + public final void mouseClicked(MouseEvent e) { + + if (e.getButton() == 2) { Game.scaleFactor = Game.MAX_SCALEFACTOR; } // middle click + + if (e.getButton() == 3) { + if(Game.state == STATE.GAME) { + rightClickPos.x = e.getX(); rightClickPos.y = e.getY(); + adjustedRightClickPos.x = adjustedMouseXY.x; adjustedRightClickPos.y = adjustedMouseXY.y; + RightClickMenu.OVERRIDE_F = RightClickMenu.OVERRIDE_SPACE = false; + RightClickMenu.determineText(); + } + } + + if (e.getButton() == 1) { + clickPos.x = e.getX(); clickPos.y = e.getY(); + if (Game.state == STATE.GAME) { + if(!WorldGenerator.WORLD_GENERATED) return; + + Player.using = Player.attacking = false; + + if(ConstructionItem.PLACING){ + MouseMovement.PLACING_STRUCTURE = true; + Tile.pointToCheck.x = MouseInput.adjustedClickPos.x; + Tile.pointToCheck.y = MouseInput.adjustedClickPos.y; + return; + } + + if (RightClickMenu.menuOpen()) { RightClickMenu.onClick(); return; } + else RightClickMenu.OVERRIDE_F = RightClickMenu.OVERRIDE_SPACE = false; + + Inventory.onLeftClick(); + ConstructionMenuCategory.onClick(); + + + mouseXY.x = e.getX(); mouseXY.y = e.getY(); + TEMP.x = (int)(mouseXY.x * Math.cos(-Utils._45 * (Game.rotation - 1)) - (mouseXY.y * Math.sin(-Utils._45 * (Game.rotation - 1)))); + TEMP.y = (int)(mouseXY.x * Math.sin(-Utils._45 * (Game.rotation - 1)) + (mouseXY.y * Math.cos(-Utils._45 * (Game.rotation - 1)))); + adjustedMouseXY.x = (int)(TEMP.x / Game.scaleFactor - Camera.x); + adjustedMouseXY.y = (int)(TEMP.y / Game.scaleFactor - Camera.y); + + if(!validClick()) return; + + Player.keepWalkingX = Player.keepWalkingY = true; + adjustedClickPos.x = adjustedMouseXY.x; adjustedClickPos.y = adjustedMouseXY.y; + } else if (Game.state == STATE.MENU) Game.menu.onClick(); + else if (Game.state == STATE.SETTINGS) Game.settings.onClick(); + else if (Game.state == STATE.PAUSED) PauseMenu.onClick(); + else if (Game.state == STATE.MAP) { Map.hasBeenClicked = true; } + } + } + + public final static void tick() { + if (mousePressed) { + if (Game.state == STATE.GAME) { + if (RightClickMenu.menuOpen()) { return; } + if(!WorldGenerator.WORLD_GENERATED) return; + clickPos.x = mouseXY.x; clickPos.y = mouseXY.y; + + // if the click on the component is inside any inventories / menus etc, do not calc mouse movement + if (!validClick()) return; + + Player.keepWalkingX = Player.keepWalkingY = true; + + adjustedClickPos.x = adjustedMouseXY.x; + adjustedClickPos.y = adjustedMouseXY.y; + } + } + + if(MouseMovement.PLACING_STRUCTURE && (!Player.keepWalkingX || !Player.keepWalkingY)){ + // REFUND ITEM COSTS + for(int i = 0; i < ConstructionItem.TEMP.price.length; i++) + if(Inventory.isFull(ConstructionItem.TEMP.price[i].itemId, ConstructionItem.TEMP.price[i].quantity)) DroppedItem.dropItemsWithOffset(ConstructionItem.TEMP.price[i].itemId, ConstructionItem.TEMP.price[i].quantity, 40, Player.center.x, Player.center.y, 50); + else Inventory.addItem( ConstructionItem.TEMP.price[i].itemId, ConstructionItem.TEMP.price[i].quantity, 50); + + //CANCEL all booleans + ConstructionItem.PLACING = Tile.drawHighLighted = MouseMovement.PLACING_STRUCTURE = false; + + //RESET TILES + Tile.resetAllHighlighted(); + } + } + + public final static boolean validClick() { + // if currently holding an item, don't move + for (InventorySlot i : Player.inventorySlots) if (i.mouseClicked) return false; + + // if in inventory + if (Inventory.INVENTORY_BOUNDS.contains(clickPos)) return false; + + // if in secondary hud + if (SecondaryHUD.tab == TAB.MINIMIZED && SecondaryHUD.minimizedBounds.contains(clickPos)) return false; + else if (!(SecondaryHUD.tab == TAB.MINIMIZED) && SecondaryHUD.maximizedBounds.contains(clickPos)) return false; + + // if inside clock + if (MouseInput.clickPos.x > (Game.game.getWidth() / 1.08 - Clock.width / 2) && MouseInput.clickPos.x < (Game.game.getWidth() / 1.08 + Clock.width / 2)) + if (MouseInput.clickPos.y < (Game.game.getHeight() / 7.75 + Clock.height / 2) && MouseInput.clickPos.y > (Game.game.getHeight() / 7.75 - Clock.height / 2)) + return false; + + // if inside construction tabs + if(ConstructionMenu.bounds.contains(clickPos)) return false; + + // if inside construction menu + for(ConstructionMenuCategory cmg : ConstructionMenuCategory.categories) + if(cmg.selected && cmg.bounds.contains(clickPos) || ConstructionMenuCategory.menuBounds.contains(clickPos)) return false; + + return true; + } + + public final void mousePressed(MouseEvent e) { + if (e.getButton() == 1 && (Game.state == STATE.GAME || Game.state == STATE.MAP)) mousePressed = true; + } + + public final void mouseReleased(MouseEvent e) { + mousePressed = Map.clicked = false; + } + + public final void mouseEntered(MouseEvent e) { + } + + public final void mouseExited(MouseEvent e) { + } + + private final static double MAX_MAP = 12; + public final void mouseWheelMoved(MouseWheelEvent e) { + if(Game.state == STATE.GAME){ + if(!WorldGenerator.WORLD_GENERATED) return; + Game.scaleFactor += -e.getPreciseWheelRotation() / 10; + Game.scaleFactor = Utils.clamp(Game.scaleFactor, Game.MIN_SCALEFACTOR, Game.MAX_SCALEFACTOR); + } else if(Game.state == STATE.MAP){ + Map.scaleFactor += -e.getPreciseWheelRotation() / 5; + Map.scaleFactor = Utils.clamp(Map.scaleFactor, 0.75d, MAX_MAP); + } + } + + public final void mouseDragged(MouseEvent e) { + mouseXY.x = e.getX(); mouseXY.y = e.getY(); /* NOTE: YOU DO NEED THIS DO NOT DELETE! */ + if(Game.state == STATE.GAME){ + TEMP.x = (int)(mouseXY.x * Math.cos(-Utils._45 * (Game.rotation - 1)) - (mouseXY.y * Math.sin(-Utils._45 * (Game.rotation - 1)))); + TEMP.y = (int)(mouseXY.x * Math.sin(-Utils._45 * (Game.rotation - 1)) + (mouseXY.y * Math.cos(-Utils._45 * (Game.rotation - 1)))); + adjustedMouseXY.x = (int)(TEMP.x / Game.scaleFactor - Camera.x); + adjustedMouseXY.y = (int)(TEMP.y / Game.scaleFactor - Camera.y); + } else if(Game.state == STATE.MAP) { + if (Map.mapBounds.contains(mouseXY.x, mouseXY.y)){ + if(!Map.clicked){ clickPos.x = mouseXY.x; clickPos.y = mouseXY.y; } + Map.clicked = Map.hasBeenClicked = true; + } + } + } + + public final void mouseMoved(MouseEvent e) { + mouseXY.x = e.getX(); mouseXY.y = e.getY(); + TEMP.x = (int)(mouseXY.x * Math.cos(-Utils._45 * (Game.rotation - 1)) - (mouseXY.y * Math.sin(-Utils._45 * (Game.rotation - 1)))); + TEMP.y = (int)(mouseXY.x * Math.sin(-Utils._45 * (Game.rotation - 1)) + (mouseXY.y * Math.cos(-Utils._45 * (Game.rotation - 1)))); + adjustedMouseXY.x = (int)(TEMP.x / Game.scaleFactor - Camera.x); + adjustedMouseXY.y = (int)(TEMP.y / Game.scaleFactor - Camera.y); + } + +} \ No newline at end of file diff --git a/src/engine/PauseMenu.java b/src/engine/PauseMenu.java new file mode 100755 index 0000000..36c4ff3 --- /dev/null +++ b/src/engine/PauseMenu.java @@ -0,0 +1,78 @@ +package engine; + +import java.awt.Graphics2D; + +import engine.Game.STATE; +import hud.inventory.Inventory; +import utils.Stack; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +final class PauseMenu { + + public static volatile Stack pauseButtons = new Stack(); + + public static void init() { + MenuButton playButton = new MenuButton(0, 0, 155, 29, 0, false, true); + MenuButton settingsButton = new MenuButton(0, 0, 155, 29, 2, false, true); + MenuButton mainMenuButton = new MenuButton(0, 0, 155, 29, 4, false, true); + MenuButton quitButton = new MenuButton(0, 0, 155, 29, 6, false, true); + pauseButtons.add(playButton); + pauseButtons.add(settingsButton); + pauseButtons.add(mainMenuButton); + pauseButtons.add(quitButton); + } + + public static void tick() { + + try { + // tick buttons x and y to adjust for screen resolutoin changes + pauseButtons.get(0).x = (float) (Game.WIDTH / 2 - (155 / 2)); + pauseButtons.get(0).y = Game.HEIGHT * 0.6f; + pauseButtons.get(1).x = (float) (Game.WIDTH / 2 - (155 / 2)); + pauseButtons.get(1).y = Game.HEIGHT * 0.65f; + pauseButtons.get(2).x = (float) (Game.WIDTH / 2 - (155 / 2)); + pauseButtons.get(2).y = Game.HEIGHT * 0.7f; + pauseButtons.get(3).x = (float) (Game.WIDTH / 2 - (155 / 2)); + pauseButtons.get(3).y = Game.HEIGHT * 0.75f; + + for (int i = 0; i < pauseButtons.size(); i++) { + pauseButtons.get(i).tick(); + } + } catch (ArrayIndexOutOfBoundsException e) { + + } catch (NullPointerException npe) { + + } + } + + public static void render(Graphics2D g2d) { + for (int i = 0; i < pauseButtons.size(); i++) pauseButtons.get(i).render(g2d); + } + + public synchronized static void onClick() { + for (int i = 0; i < pauseButtons.size(); i++) { + if (pauseButtons.get(i).contains(MouseInput.mouseXY) && pauseButtons.get(i).type == 0) { + Game.state = STATE.GAME; + Inventory.changeSettings(); + Game.settings.cleanUp(); + cleanUp(); + } else if (pauseButtons.get(i).contains(MouseInput.mouseXY) && pauseButtons.get(i).type == 2) { + Game.settings.init(); + Game.state = STATE.SETTINGS; + Game.settings.justCameFromPaused = true; + } else if (pauseButtons.get(i).contains(MouseInput.mouseXY) && pauseButtons.get(i).type == 4) { + Game.menu.cleanUp(); + Game.menu.init(); + Game.state = STATE.MENU; + pauseButtons.clear(); + } else if (pauseButtons.get(i).contains(MouseInput.mouseXY) && pauseButtons.get(i).type == 6) Game.cleanUp(); + } + } + + public synchronized static void cleanUp() { + pauseButtons.clear(); + } +} diff --git a/src/engine/Settings.java b/src/engine/Settings.java new file mode 100755 index 0000000..89884c0 --- /dev/null +++ b/src/engine/Settings.java @@ -0,0 +1,1144 @@ +package engine; + +import java.awt.Graphics2D; + +import _texture.loader.Textures; +import engine.Game.STATE; +import fileIO.Saving; +import fileIO.SettingsSaveFile; +import hud.constructionmenu.ConstructionMenu; +import hud.inventory.Inventory; +import utils.Stack; +import utils.Utils; +import worldGen.WorldGenerator; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +final class Settings { + + public boolean justCameFromPaused = false; + + public volatile Stack mainButtons; + public volatile Stack resizeableContextMenu; + public volatile Stack displayFPSContextMenu; + public volatile Stack showEnemyHealthContextMenu; + public volatile Stack resolutionContextMenu; + public volatile Stack fpsContextMenu; + + // main buttons + public static volatile MenuButton resolutionButton, resizeableButton, fpsButton, displayFPSButton, showHealthBarsButton, returnToMenuButton, saveButton; + // True / False + public static volatile MenuButton resizeableTrue, resizeableFalse, displayFPSTrue, displayFPSFalse, showHealthBarsTrue, showHealthBarsFalse; + // Resolutions + public static volatile MenuButton _fullscreen, _480x320, _640x480, _800x600, _1280x720, _1280x960, _1600x900, _1920x1080, _2560x1440, _3840x2160, + _8192x4068; + // FPS CAPS + public static volatile MenuButton FPS30, FPS60, FPS90, FPS120, FPS144, FPS200, FPS_RIP_CPU; + // booleans for button arrangement + public static volatile boolean resizeableTrueFalseReverse, displayFPSTrueFalseReverse, showEnemyHealthBarsTrueFalseReverse; + // count of all the buttons in all the arrays + private static volatile int largestArraySize, max; + + // Save file to be loaded + private static volatile SettingsSaveFile loadedSettings; + + public final synchronized void init() { + try { /* attempt to load save and initialize variables to that save */ + loadedSettings = Saving.readSettingsSaveFile(); + + mainButtons = loadedSettings.mainButtons; + resizeableContextMenu = loadedSettings.resizeable; + displayFPSContextMenu = loadedSettings.displayFPS; + showEnemyHealthContextMenu = loadedSettings.healthBars; + resolutionContextMenu = loadedSettings.resolution; + fpsContextMenu = loadedSettings.fpsCap; + + // Load main buttons + resolutionButton = mainButtons.get(0); + resizeableButton = mainButtons.get(1); + fpsButton = mainButtons.get(2); + displayFPSButton = mainButtons.get(3); + showHealthBarsButton = mainButtons.get(4); + returnToMenuButton = mainButtons.get(5); + saveButton = mainButtons.get(6); + + // Load True / False buttons + resizeableTrue = resizeableContextMenu.get(0); + resizeableFalse = resizeableContextMenu.get(1); + displayFPSTrue = displayFPSContextMenu.get(0); + displayFPSFalse = displayFPSContextMenu.get(1); + showHealthBarsTrue = showEnemyHealthContextMenu.get(0); + showHealthBarsFalse = showEnemyHealthContextMenu.get(1); + + // Load Resolution Buttons + _fullscreen = resolutionContextMenu.get(0); + _480x320 = resolutionContextMenu.get(1); + _640x480 = resolutionContextMenu.get(2); + _800x600 = resolutionContextMenu.get(3); + _1280x720 = resolutionContextMenu.get(4); + _1280x960 = resolutionContextMenu.get(5); + _1600x900 = resolutionContextMenu.get(6); + _1920x1080 = resolutionContextMenu.get(7); + _2560x1440 = resolutionContextMenu.get(8); + _3840x2160 = resolutionContextMenu.get(9); + _8192x4068 = resolutionContextMenu.get(10); + + // Load FPS Cap buttons + FPS30 = fpsContextMenu.get(0); + FPS60 = fpsContextMenu.get(1); + FPS90 = fpsContextMenu.get(2); + FPS120 = fpsContextMenu.get(3); + FPS144 = fpsContextMenu.get(4); + FPS200 = fpsContextMenu.get(5); + FPS_RIP_CPU = fpsContextMenu.get(6); + + // Load booleans + resizeableTrueFalseReverse = loadedSettings.resizeableTF; + displayFPSTrueFalseReverse = loadedSettings.displayFPSTF; + showEnemyHealthBarsTrueFalseReverse = loadedSettings.showHealthTF; + + // Apply the loaded settings: + } catch (Exception e) { + System.err.println("WARNING: Save file either not found or corrupt."); + System.out.println("-------- Creating new save file --------"); + + // initialize array lists: + mainButtons = new Stack(); + resizeableContextMenu = new Stack(); + displayFPSContextMenu = new Stack(); + showEnemyHealthContextMenu = new Stack(); + resolutionContextMenu = new Stack(); + fpsContextMenu = new Stack(); + + // initialize booleans + resizeableTrueFalseReverse = false; + displayFPSTrueFalseReverse = false; + showEnemyHealthBarsTrueFalseReverse = false; + + // PARAMETERS: x, y, width, height, type, isHovering /* TYPE == Which Sprite to draw! */ + + // Main Buttons + resolutionButton = new MenuButton(0, 0, 155, 29, 0, false, true); + resizeableButton = new MenuButton(0, 0, 155, 29, 2, false, true); + fpsButton = new MenuButton(0, 0, 155, 29, 4, false, true); + displayFPSButton = new MenuButton(0, 0, 155, 29, 6, false, true); + showHealthBarsButton = new MenuButton(0, 0, 155, 29, 8, false, true); + returnToMenuButton = new MenuButton(0, 0, 155, 29, 10, false, true); + saveButton = new MenuButton(0, 0, 155, 29, 52, false, true); + + // True / False + resizeableTrue = new MenuButton(0, 0, 155, 29, 12, false, true, false, false); + resizeableFalse = new MenuButton(0, 0, 155, 29, 14, false, false, false, false); + displayFPSTrue = new MenuButton(0, 0, 155, 29, 12, false, true, false, false); + displayFPSFalse = new MenuButton(0, 0, 155, 29, 14, false, false, false, false); + showHealthBarsTrue = new MenuButton(0, 0, 155, 29, 12, false, true, false, false); + showHealthBarsFalse = new MenuButton(0, 0, 155, 29, 14, false, false, false, false); + + // Resolutions + _fullscreen = new MenuButton(0, 0, 155, 29, 16, false, true, true, false); + _480x320 = new MenuButton(0, 0, 155, 29, 18, false, false, false, false); + _640x480 = new MenuButton(0, 0, 155, 29, 20, false, false, false, false); + _800x600 = new MenuButton(0, 0, 155, 29, 22, false, false, false, false); + _1280x720 = new MenuButton(0, 0, 155, 29, 24, false, false, false, false); + _1280x960 = new MenuButton(0, 0, 155, 29, 26, false, false, false, false); + _1600x900 = new MenuButton(0, 0, 155, 29, 28, false, false, false, false); + _1920x1080 = new MenuButton(0, 0, 155, 29, 30, false, false, false, false); + _2560x1440 = new MenuButton(0, 0, 155, 29, 32, false, false, false, false); + _3840x2160 = new MenuButton(0, 0, 155, 29, 34, false, false, false, false); + _8192x4068 = new MenuButton(0, 0, 155, 29, 36, false, false, false, false); + + // FPS caps + FPS30 = new MenuButton(0, 0, 155, 29, 38, false, false, false, false); + FPS60 = new MenuButton(0, 0, 155, 29, 40, false, true, true, false); + FPS90 = new MenuButton(0, 0, 155, 29, 42, false, false, false, false); + FPS120 = new MenuButton(0, 0, 155, 29, 44, false, false, false, false); + FPS144 = new MenuButton(0, 0, 155, 29, 46, false, false, false, false); + FPS200 = new MenuButton(0, 0, 155, 29, 48, false, false, false, false); + FPS_RIP_CPU = new MenuButton(0, 0, 155, 29, 50, false, false, false, false); + + // Main Buttons + mainButtons.add(resolutionButton); + mainButtons.add(resizeableButton); + mainButtons.add(fpsButton); + mainButtons.add(displayFPSButton); + mainButtons.add(showHealthBarsButton); + mainButtons.add(returnToMenuButton); + mainButtons.add(saveButton); + + // True / False + resizeableContextMenu.add(resizeableTrue); + resizeableContextMenu.add(resizeableFalse); + displayFPSContextMenu.add(displayFPSTrue); + displayFPSContextMenu.add(displayFPSFalse); + showEnemyHealthContextMenu.add(showHealthBarsTrue); + showEnemyHealthContextMenu.add(showHealthBarsFalse); + + // Resolutions + resolutionContextMenu.add(_fullscreen); + resolutionContextMenu.add(_480x320); + resolutionContextMenu.add(_640x480); + resolutionContextMenu.add(_800x600); + resolutionContextMenu.add(_1280x720); + resolutionContextMenu.add(_1280x960); + resolutionContextMenu.add(_1600x900); + resolutionContextMenu.add(_1920x1080); + resolutionContextMenu.add(_2560x1440); + resolutionContextMenu.add(_3840x2160); + resolutionContextMenu.add(_8192x4068); + + // FPS CAPS + fpsContextMenu.add(FPS30); + fpsContextMenu.add(FPS60); + fpsContextMenu.add(FPS90); + fpsContextMenu.add(FPS120); + fpsContextMenu.add(FPS144); + fpsContextMenu.add(FPS200); + fpsContextMenu.add(FPS_RIP_CPU); + + // find the largest of the arrays + max = mainButtons.size(); + if (max < resizeableContextMenu.size()) max = resizeableContextMenu.size(); + else if (max < displayFPSContextMenu.size()) max = displayFPSContextMenu.size(); + else if (max < showEnemyHealthContextMenu.size()) max = showEnemyHealthContextMenu.size(); + else if (max < resolutionContextMenu.size()) max = resolutionContextMenu.size(); + else if (max < fpsContextMenu.size()) max = fpsContextMenu.size(); + largestArraySize = max; + + // save default settings + createSettingsSaveFile(); + } + } + + public static synchronized void applySettings() { + + try { + + // True / False Flipping: + if (!resizeableTrueFalseReverse) { + // do something + } // else dont something; + + if (!displayFPSTrueFalseReverse) { + Game.displayFPS = true; + } else Game.displayFPS = false; + + if (!showEnemyHealthBarsTrueFalseReverse) { + Game.showEnemyHealthBars = true; + } else Game.showEnemyHealthBars = false; + + // Resolution Changing + if (_fullscreen.isAtTop) Game.fullscreen = true; + else Game.fullscreen = false; + + if (_fullscreen.isAtTop) Game.makeFullScreen(); + + if (_480x320.isAtTop) { + Game.WIDTH = 480; + Game.HEIGHT = 320; + } else if (_640x480.isAtTop) { + Game.WIDTH = 640; + Game.HEIGHT = 480; + } else if (_800x600.isAtTop) { + Game.WIDTH = 800; + Game.HEIGHT = 600; + } else if (_1280x720.isAtTop) { + Game.WIDTH = 1280; + Game.HEIGHT = 720; + } else if (_1280x960.isAtTop) { + Game.WIDTH = 1280; + Game.HEIGHT = 960; + } else if (_1600x900.isAtTop) { + Game.WIDTH = 1600; + Game.HEIGHT = 900; + } else if (_1920x1080.isAtTop) { + Game.WIDTH = 1920; + Game.HEIGHT = 1080; + } else if (_2560x1440.isAtTop) { + Game.WIDTH = 2560; + Game.HEIGHT = 1440; + } else if (_3840x2160.isAtTop) { + Game.WIDTH = 3840; + Game.HEIGHT = 2160; + } else if (_8192x4068.isAtTop) { + Game.WIDTH = 8192; + Game.HEIGHT = 4068; + } + + // change the frame size + if (!_fullscreen.isAtTop) { + if(!Game.init) Game.undoFullScreen(); + Game.frame.setSize(Game.WIDTH, Game.HEIGHT); + } + + // FPS Cap changing + if (FPS30.isAtTop) Game.FPS_CAP = (30.0); + else if (FPS60.isAtTop) Game.FPS_CAP = (60.0); + else if (FPS90.isAtTop) Game.FPS_CAP = (90.0); + else if (FPS120.isAtTop) Game.FPS_CAP = (120.0); + else if (FPS144.isAtTop) Game.FPS_CAP = (144.0); + else if (FPS200.isAtTop) Game.FPS_CAP = (200.0); + else if (FPS_RIP_CPU.isAtTop) Game.FPS_CAP = 1500; + + Game.frameLimit = Utils.second / Game.FPS_CAP; + + Inventory.changeSettings(); + ConstructionMenu.changeSettings(); + + Game.frame.setLocation(java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width / 2 - Game.frame.getWidth() / 2, + java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height / 2 - Game.frame.getHeight() / 2); + + WorldGenerator.regenWorldSectionsAndTiles(); /* NOTE: will take a while */ + + } catch (NullPointerException npe) { + if (nullCount > 5) { + npe.printStackTrace(); + } else nullCount++; + } catch (Exception e) { + e.printStackTrace(); + } + } + + public synchronized void onClick() { + + try { /* giant null pointer catch for issues when changing menus, ignore */ + + // Main buttons + for (int i = 0; i < mainButtons.size(); i++) { + if (mainButtons.get(i).contains(MouseInput.mouseXY) && mainButtons.get(i).type == 0) { + for (int j = 0; j < resolutionContextMenu.size(); j++) { + if (!resolutionContextMenu.get(j).isAtTop) resolutionContextMenu.get(j).isVisible = !resolutionContextMenu.get(j).isVisible; + } + for (int j = 0; j < largestArraySize; j++) { + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = true; + } + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = true; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = true; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = true; + } + + } + + } else if (mainButtons.get(i).contains(MouseInput.mouseXY) && mainButtons.get(i).type == 2) { + if (!resizeableTrueFalseReverse) resizeableFalse.isVisible = !resizeableFalse.isVisible; + else resizeableTrue.isVisible = !resizeableTrue.isVisible; + + } else if (mainButtons.get(i).contains(MouseInput.mouseXY) && mainButtons.get(i).type == 4) { + for (int j = 0; j < fpsContextMenu.size(); j++) { + if (!fpsContextMenu.get(j).isAtTop) fpsContextMenu.get(j).isVisible = !fpsContextMenu.get(j).isVisible; + } + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = true; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = true; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = true; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = true; + } + } + } else if (mainButtons.get(i).contains(MouseInput.mouseXY) && mainButtons.get(i).type == 6) { + if (!displayFPSTrueFalseReverse) displayFPSFalse.isVisible = !displayFPSFalse.isVisible; + else displayFPSTrue.isVisible = !displayFPSTrue.isVisible; + } else if (mainButtons.get(i).contains(MouseInput.mouseXY) && mainButtons.get(i).type == 8) { + if (!showEnemyHealthBarsTrueFalseReverse) showHealthBarsFalse.isVisible = !showHealthBarsFalse.isVisible; + else showHealthBarsTrue.isVisible = !showHealthBarsTrue.isVisible; + } else if (mainButtons.get(i).contains(MouseInput.mouseXY) && mainButtons.get(i).type == 10) { + + if (!justCameFromPaused) { + Game.state = STATE.MENU; + cleanUp(); + } else if (justCameFromPaused) { + Game.justCameFromSettings = true; + Game.state = STATE.PAUSED; + cleanUp(); + } + + } else if (mainButtons.get(i).contains(MouseInput.mouseXY) && mainButtons.get(i).type == 52) { + if (!justCameFromPaused) { + createSettingsSaveFile(); + Game.state = STATE.MENU; + cleanUp(); + } else if (justCameFromPaused) { + createSettingsSaveFile(); + Game.state = STATE.PAUSED; + cleanUp(); + } + + } + } + + // Resizeable T/F flip + if (resizeableTrue.contains(MouseInput.mouseXY) && resizeableTrueFalseReverse & resizeableFalse.isVisible & resizeableTrue.isVisible) { + resizeableTrueFalseReverse = !resizeableTrueFalseReverse; + if (resizeableTrue.isVisible) resizeableFalse.isVisible = !resizeableFalse.isVisible; + + } else if (resizeableFalse.contains(MouseInput.mouseXY) && !resizeableTrueFalseReverse & resizeableFalse.isVisible) { + resizeableTrueFalseReverse = !resizeableTrueFalseReverse; + if (resizeableFalse.isVisible) resizeableTrue.isVisible = !resizeableTrue.isVisible; + + } + // DisplayFPS T/F flip + else if (displayFPSTrue.contains(MouseInput.mouseXY) && displayFPSTrueFalseReverse & displayFPSFalse.isVisible & displayFPSTrue.isVisible) { + displayFPSTrueFalseReverse = !displayFPSTrueFalseReverse; + if (displayFPSTrue.isVisible) displayFPSFalse.isVisible = !displayFPSFalse.isVisible; + + } else if (displayFPSFalse.contains(MouseInput.mouseXY) && !displayFPSTrueFalseReverse & displayFPSFalse.isVisible) { + displayFPSTrueFalseReverse = !displayFPSTrueFalseReverse; + if (displayFPSFalse.isVisible) displayFPSTrue.isVisible = !displayFPSTrue.isVisible; + + } + // Show Enemy Health Bars Flip + else if (showHealthBarsTrue.contains(MouseInput.mouseXY) + && showEnemyHealthBarsTrueFalseReverse & showHealthBarsFalse.isVisible & showHealthBarsTrue.isVisible) { + showEnemyHealthBarsTrueFalseReverse = !showEnemyHealthBarsTrueFalseReverse; + if (showHealthBarsTrue.isVisible) showHealthBarsFalse.isVisible = !showHealthBarsFalse.isVisible; + + } else if (showHealthBarsFalse.contains(MouseInput.mouseXY) && !showEnemyHealthBarsTrueFalseReverse & showHealthBarsFalse.isVisible) { + showEnemyHealthBarsTrueFalseReverse = !showEnemyHealthBarsTrueFalseReverse; + if (showHealthBarsFalse.contains(MouseInput.mouseXY) && showHealthBarsFalse.isVisible) + showHealthBarsTrue.isVisible = !showHealthBarsTrue.isVisible; + + } + + //// **** FPS CONTEXT MENU BUTTON CLICKS: ******//// + // if clicked and is visible, set it to top then set all others to not at top, and not visible + if (FPS30.contains(MouseInput.mouseXY) && FPS30.isVisible) { + FPS30.isAtTop = true; + for (int i = 0; i < fpsContextMenu.size(); i++) { + if (fpsContextMenu.get(i) != FPS30) { + fpsContextMenu.get(i).isAtTop = false; + fpsContextMenu.get(i).isVisible = false; + } + } + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + } else if (FPS60.contains(MouseInput.mouseXY) && FPS60.isVisible) { + FPS60.isAtTop = true; + for (int i = 0; i < fpsContextMenu.size(); i++) { + if (fpsContextMenu.get(i) != FPS60) { + fpsContextMenu.get(i).isAtTop = false; + fpsContextMenu.get(i).isVisible = false; + } + } + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + } else if (FPS90.contains(MouseInput.mouseXY) && FPS90.isVisible) { + FPS90.isAtTop = true; + for (int i = 0; i < fpsContextMenu.size(); i++) { + if (fpsContextMenu.get(i) != FPS90) { + fpsContextMenu.get(i).isAtTop = false; + fpsContextMenu.get(i).isVisible = false; + } + } + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + } else if (FPS120.contains(MouseInput.mouseXY) && FPS120.isVisible) { + FPS120.isAtTop = true; + for (int i = 0; i < fpsContextMenu.size(); i++) { + if (fpsContextMenu.get(i) != FPS120) { + fpsContextMenu.get(i).isAtTop = false; + fpsContextMenu.get(i).isVisible = false; + } + } + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + } else if (FPS144.contains(MouseInput.mouseXY) && FPS144.isVisible) { + FPS144.isAtTop = true; + for (int i = 0; i < fpsContextMenu.size(); i++) { + if (fpsContextMenu.get(i) != FPS144) { + fpsContextMenu.get(i).isAtTop = false; + fpsContextMenu.get(i).isVisible = false; + } + } + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + } else if (FPS200.contains(MouseInput.mouseXY) && FPS200.isVisible) { + FPS200.isAtTop = true; + for (int i = 0; i < fpsContextMenu.size(); i++) { + if (fpsContextMenu.get(i) != FPS200) { + fpsContextMenu.get(i).isAtTop = false; + fpsContextMenu.get(i).isVisible = false; + } + } + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + } else if (FPS_RIP_CPU.contains(MouseInput.mouseXY) && FPS_RIP_CPU.isVisible) { + FPS_RIP_CPU.isAtTop = true; + for (int i = 0; i < fpsContextMenu.size(); i++) { + if (fpsContextMenu.get(i) != FPS_RIP_CPU) { + fpsContextMenu.get(i).isAtTop = false; + fpsContextMenu.get(i).isVisible = false; + } + } + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } + + //// **** RESOLUTION CONTEXT MENU BUTTON CLICKS: ******//// + // if clicked and is visible, set it to top then set all others to not at top, and not visible + if (_fullscreen.contains(MouseInput.mouseXY) && _fullscreen.isVisible) { + _fullscreen.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _fullscreen) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _fullscreen) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_480x320.contains(MouseInput.mouseXY) && _480x320.isVisible) { + _480x320.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _480x320) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _480x320) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_640x480.contains(MouseInput.mouseXY) && _640x480.isVisible) { + _640x480.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _640x480) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _640x480) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_800x600.contains(MouseInput.mouseXY) && _800x600.isVisible) { + _800x600.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _800x600) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _800x600) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_1280x720.contains(MouseInput.mouseXY) && _1280x720.isVisible) { + _1280x720.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _1280x720) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _1280x720) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_1280x960.contains(MouseInput.mouseXY) && _1280x960.isVisible) { + _1280x960.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _1280x960) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _1280x960) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_1600x900.contains(MouseInput.mouseXY) && _1600x900.isVisible) { + _1600x900.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _1600x900) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _1600x900) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_1920x1080.contains(MouseInput.mouseXY) && _1920x1080.isVisible) { + _1920x1080.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _1920x1080) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _1920x1080) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_2560x1440.contains(MouseInput.mouseXY) && _2560x1440.isVisible) { + _2560x1440.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _2560x1440) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _2560x1440) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_3840x2160.contains(MouseInput.mouseXY) && _3840x2160.isVisible) { + _3840x2160.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _3840x2160) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _3840x2160) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + + } else if (_8192x4068.contains(MouseInput.mouseXY) && _8192x4068.isVisible) { + _8192x4068.isAtTop = true; + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (resolutionContextMenu.get(i) != _8192x4068) resolutionContextMenu.get(i).isAtTop = false; + if (resolutionContextMenu.get(i) != _8192x4068) resolutionContextMenu.get(i).isVisible = false; + } + + for (int j = 0; j < largestArraySize; j++) { + if (j < resizeableContextMenu.size()) { + resizeableContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < displayFPSContextMenu.size()) { + displayFPSContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < showEnemyHealthContextMenu.size()) { + showEnemyHealthContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < resolutionContextMenu.size()) { + resolutionContextMenu.get(j).otherContextMenuIsOpen = false; + } + if (j < fpsContextMenu.size()) { + fpsContextMenu.get(j).otherContextMenuIsOpen = false; + } + } + } + } catch (NullPointerException npe) { + if (nullCount > 5) { + npe.printStackTrace(); + } else nullCount++; + } + } + + public void tick() { + + if(Game.state != STATE.SETTINGS) return; + + try { /**** Giant null pointer check, helps solve odd problems occurring ****/ + + // tick buttons x and y to adjust for screen resolution changes + // Main buttons + resolutionButton.x = Game.game.getWidth() - Game.game.getWidth() / 1.03f; + resolutionButton.y = Game.game.getHeight() * 0.1f; + fpsButton.x = Game.game.getWidth() - Game.game.getWidth() / 1.03f; + fpsButton.y = Game.game.getHeight() * 0.2f; + resizeableButton.x = Game.game.getWidth() - Game.game.getWidth() / 1.03f; + resizeableButton.y = Game.game.getHeight() * 0.3f; + displayFPSButton.x = Game.game.getWidth() - Game.game.getWidth() / 1.03f; + displayFPSButton.y = Game.game.getHeight() * 0.4f; + showHealthBarsButton.x = Game.game.getWidth() - Game.game.getWidth() / 1.03f; + showHealthBarsButton.y = Game.game.getHeight() * 0.5f; + returnToMenuButton.x = Game.game.getWidth() - Game.game.getWidth() / 4.5f; + returnToMenuButton.y = Game.game.getHeight() * 0.85f; + saveButton.x = Game.game.getWidth() - Game.game.getWidth() / 4.5f; + saveButton.y = Game.game.getHeight() * 0.775f; + // True / False buttons + resizeableTrue.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + resizeableTrue.y = Game.game.getHeight() * 0.3f; + resizeableFalse.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + resizeableFalse.y = Game.game.getHeight() * 0.35f; + displayFPSTrue.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + displayFPSTrue.y = Game.game.getHeight() * 0.4f; + displayFPSFalse.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + displayFPSFalse.y = Game.game.getHeight() * 0.45f; + showHealthBarsTrue.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + showHealthBarsTrue.y = Game.game.getHeight() * 0.5f; + showHealthBarsFalse.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + showHealthBarsFalse.y = Game.game.getHeight() * 0.55f; + // Resolution Buttons + _fullscreen.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _fullscreen.y = Game.game.getHeight() * 0.1f; + _480x320.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _480x320.y = Game.game.getHeight() * 0.15f; + _640x480.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _640x480.y = Game.game.getHeight() * 0.2f; + _800x600.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _800x600.y = Game.game.getHeight() * 0.25f; + _1280x720.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _1280x720.y = Game.game.getHeight() * 0.3f; + _1280x960.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _1280x960.y = Game.game.getHeight() * 0.35f; + _1600x900.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _1600x900.y = Game.game.getHeight() * 0.4f; + _1920x1080.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _1920x1080.y = Game.game.getHeight() * 0.45f; + _2560x1440.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _2560x1440.y = Game.game.getHeight() * 0.5f; + _3840x2160.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _3840x2160.y = Game.game.getHeight() * 0.55f; + _8192x4068.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + _8192x4068.y = Game.game.getHeight() * 0.6f; + // FPS CAPS + FPS30.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + FPS30.y = Game.game.getHeight() * 0.2f; + FPS60.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + FPS60.y = Game.game.getHeight() * 0.25f; + FPS90.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + FPS90.y = Game.game.getHeight() * 0.3f; + FPS120.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + FPS120.y = Game.game.getHeight() * 0.35f; + FPS144.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + FPS144.y = Game.game.getHeight() * 0.4f; + FPS200.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + FPS200.y = Game.game.getHeight() * 0.45f; + FPS_RIP_CPU.x = Game.game.getWidth() - Game.game.getWidth() / 1.4f; + FPS_RIP_CPU.y = Game.game.getHeight() * 0.5f; + + // Move buttons around according to if they're supposed to be at the top + /***** FPS ***/ + if (FPS30.isAtTop) FPS30.y = Game.game.getHeight() * 0.2f; + else if (FPS60.isAtTop) FPS60.y = Game.game.getHeight() * 0.2f; + else if (FPS90.isAtTop) FPS90.y = Game.game.getHeight() * 0.2f; + else if (FPS120.isAtTop) FPS120.y = Game.game.getHeight() * 0.2f; + else if (FPS144.isAtTop) FPS144.y = Game.game.getHeight() * 0.2f; + else if (FPS200.isAtTop) FPS200.y = Game.game.getHeight() * 0.2f; + else if (FPS_RIP_CPU.isAtTop) FPS_RIP_CPU.y = Game.game.getHeight() * 0.2f; + /****** RESOLUTIONS *******/ + if (_fullscreen.isAtTop) _fullscreen.y = Game.game.getHeight() * 0.1f; + else if (_480x320.isAtTop) _480x320.y = Game.game.getHeight() * 0.1f; + else if (_640x480.isAtTop) _640x480.y = Game.game.getHeight() * 0.1f; + else if (_800x600.isAtTop) _800x600.y = Game.game.getHeight() * 0.1f; + else if (_1280x720.isAtTop) _1280x720.y = Game.game.getHeight() * 0.1f; + else if (_1280x960.isAtTop) _1280x960.y = Game.game.getHeight() * 0.1f; + else if (_1600x900.isAtTop) _1600x900.y = Game.game.getHeight() * 0.1f; + else if (_1920x1080.isAtTop) _1920x1080.y = Game.game.getHeight() * 0.1f; + else if (_2560x1440.isAtTop) _2560x1440.y = Game.game.getHeight() * 0.1f; + else if (_3840x2160.isAtTop) _3840x2160.y = Game.game.getHeight() * 0.1f; + else if (_8192x4068.isAtTop) _8192x4068.y = Game.game.getHeight() * 0.1f; + + // Move the rest of the context buttons in menu along accordingly + for (int i = 1; i < fpsContextMenu.size() + 1; i++) { + if (!fpsContextMenu.get(i - 1).isAtTop) { + fpsContextMenu.get(i - 1).y = (Game.game.getHeight() * 0.2f) + (Game.game.getHeight() * 0.05f * i); + } + } + for (int i = 1; i < resolutionContextMenu.size() + 1; i++) { + if (!resolutionContextMenu.get(i - 1).isAtTop) { + resolutionContextMenu.get(i - 1).y = (Game.game.getHeight() * 0.1f) + (Game.game.getHeight() * 0.05f * i); + } + } + + // Flip x/y's for True / False selection changes + // Resizeable + if (resizeableTrueFalseReverse) { + resizeableTrue.y = (float) Utils.swap(resizeableFalse.y, resizeableFalse.y = resizeableTrue.y); + resizeableTrue.x = (float) Utils.swap(resizeableFalse.x, resizeableFalse.x = resizeableTrue.x); + } + // DisplayFPS + if (displayFPSTrueFalseReverse) { + displayFPSTrue.y = (float) Utils.swap(displayFPSFalse.y, displayFPSFalse.y = displayFPSTrue.y); + displayFPSFalse.x = (float) Utils.swap(displayFPSFalse.x, displayFPSFalse.x = displayFPSTrue.x); + } + // Show Enemy Health Bars + if (showEnemyHealthBarsTrueFalseReverse) { + showHealthBarsTrue.y = (float) Utils.swap(showHealthBarsFalse.y, showHealthBarsFalse.y = showHealthBarsTrue.y); + showHealthBarsFalse.x = (float) Utils.swap(showHealthBarsFalse.x, showHealthBarsFalse.x = showHealthBarsTrue.x); + } + + for (int i = 0; i < mainButtons.size(); i++) { + mainButtons.get(i).calcIsHovering(); + mainButtons.get(i).setBounds((int) mainButtons.get(i).x, (int) mainButtons.get(i).y, mainButtons.get(i).width, mainButtons.get(i).height); + } + for (int i = 0; i < resizeableContextMenu.size(); i++) { + resizeableContextMenu.get(i).calcIsHovering(); + resizeableContextMenu.get(i).setBounds((int) resizeableContextMenu.get(i).x, (int) resizeableContextMenu.get(i).y, + resizeableContextMenu.get(i).width, resizeableContextMenu.get(i).height); + } + for (int i = 0; i < displayFPSContextMenu.size(); i++) { + displayFPSContextMenu.get(i).calcIsHovering(); + displayFPSContextMenu.get(i).setBounds((int) displayFPSContextMenu.get(i).x, (int) displayFPSContextMenu.get(i).y, + displayFPSContextMenu.get(i).width, displayFPSContextMenu.get(i).height); + } + for (int i = 0; i < showEnemyHealthContextMenu.size(); i++) { + showEnemyHealthContextMenu.get(i).calcIsHovering(); + showEnemyHealthContextMenu.get(i).setBounds((int) showEnemyHealthContextMenu.get(i).x, (int) showEnemyHealthContextMenu.get(i).y, + showEnemyHealthContextMenu.get(i).width, showEnemyHealthContextMenu.get(i).height); + } + for (int i = 0; i < resolutionContextMenu.size(); i++) { + resolutionContextMenu.get(i).calcIsHovering(); + resolutionContextMenu.get(i).setBounds((int) resolutionContextMenu.get(i).x, (int) resolutionContextMenu.get(i).y, + resolutionContextMenu.get(i).width, resolutionContextMenu.get(i).height); + } + for (int i = 0; i < fpsContextMenu.size(); i++) { + fpsContextMenu.get(i).calcIsHovering(); + fpsContextMenu.get(i).setBounds((int) fpsContextMenu.get(i).x, (int) fpsContextMenu.get(i).y, fpsContextMenu.get(i).width, + fpsContextMenu.get(i).height); + } + } catch (NullPointerException e) { + if (nullCount > 5) { + e.printStackTrace(); + } else nullCount++; + } + } + + public void render(Graphics2D g2d) { + if(Game.state != STATE.SETTINGS) return; + + if (g2d == null) return; + + try { /* again, catch null pointers that happen occasionally when switching menus */ + + // Main Buttons + for (int i = 0; i < mainButtons.size(); i++) { + if (!mainButtons.get(i).isHovering && mainButtons.get(i).isVisible) + g2d.drawImage(Textures.settingsButtonSheet[mainButtons.get(i).type], (int) mainButtons.get(i).x, (int) mainButtons.get(i).y, null); + else if (mainButtons.get(i).isVisible) + g2d.drawImage(Textures.settingsButtonSheet[mainButtons.get(i).type + 1], (int) mainButtons.get(i).x, (int) mainButtons.get(i).y, null); + } + + // Resizeable + for (int i = 0; i < resizeableContextMenu.size(); i++) { + if (!resizeableContextMenu.get(i).isHovering && resizeableContextMenu.get(i).isVisible & !resizeableContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[resizeableContextMenu.get(i).type], (int) resizeableContextMenu.get(i).x, + (int) resizeableContextMenu.get(i).y, null); + else if (resizeableContextMenu.get(i).isVisible && !resizeableContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[resizeableContextMenu.get(i).type + 1], (int) resizeableContextMenu.get(i).x, + (int) resizeableContextMenu.get(i).y, null); + } + + // DisplayFPS + for (int i = 0; i < displayFPSContextMenu.size(); i++) { + if (!displayFPSContextMenu.get(i).isHovering && displayFPSContextMenu.get(i).isVisible & !displayFPSContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[displayFPSContextMenu.get(i).type], (int) displayFPSContextMenu.get(i).x, + (int) displayFPSContextMenu.get(i).y, null); + else if (displayFPSContextMenu.get(i).isVisible && !displayFPSContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[displayFPSContextMenu.get(i).type + 1], (int) displayFPSContextMenu.get(i).x, + (int) displayFPSContextMenu.get(i).y, null); + } + + // Show Enemy Health Bars + for (int i = 0; i < showEnemyHealthContextMenu.size(); i++) { + if (!showEnemyHealthContextMenu.get(i).isHovering + && showEnemyHealthContextMenu.get(i).isVisible & !showEnemyHealthContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[showEnemyHealthContextMenu.get(i).type], (int) showEnemyHealthContextMenu.get(i).x, + (int) showEnemyHealthContextMenu.get(i).y, null); + else if (showEnemyHealthContextMenu.get(i).isVisible && !showEnemyHealthContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[showEnemyHealthContextMenu.get(i).type + 1], (int) showEnemyHealthContextMenu.get(i).x, + (int) showEnemyHealthContextMenu.get(i).y, null); + } + + // Resolutions + for (int i = 0; i < resolutionContextMenu.size(); i++) { + if (!resolutionContextMenu.get(i).isHovering && resolutionContextMenu.get(i).isVisible & !resolutionContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[resolutionContextMenu.get(i).type], (int) resolutionContextMenu.get(i).x, + (int) resolutionContextMenu.get(i).y, null); + else if (resolutionContextMenu.get(i).isVisible && !resolutionContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[resolutionContextMenu.get(i).type + 1], (int) resolutionContextMenu.get(i).x, + (int) resolutionContextMenu.get(i).y, null); + } + + // FPS's + for (int i = 0; i < fpsContextMenu.size(); i++) { + if (!fpsContextMenu.get(i).isHovering && fpsContextMenu.get(i).isVisible & !fpsContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[fpsContextMenu.get(i).type], (int) fpsContextMenu.get(i).x, (int) fpsContextMenu.get(i).y, null); + else if (fpsContextMenu.get(i).isVisible && !fpsContextMenu.get(i).otherContextMenuIsOpen) + g2d.drawImage(Textures.settingsButtonSheet[fpsContextMenu.get(i).type + 1], (int) fpsContextMenu.get(i).x, (int) fpsContextMenu.get(i).y, + null); + } + } catch (NullPointerException e) { // null pointer caught} + if (nullCount > 5) { + e.printStackTrace(); + } else nullCount++; + } + } + + public synchronized void createSettingsSaveFile() { + try { + SettingsSaveFile settings = new SettingsSaveFile(mainButtons, resizeableContextMenu, displayFPSContextMenu, showEnemyHealthContextMenu, + resolutionContextMenu, fpsContextMenu, resizeableTrueFalseReverse, displayFPSTrueFalseReverse, showEnemyHealthBarsTrueFalseReverse); + + // Pass in the newly created save file + Saving.saveSettingsSaveFile(settings); + + // Apply new settings to current game + applySettings(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public synchronized void cleanUp() { /* is called when returning to main menu / quitting */ + try { + mainButtons.clear(); + mainButtons = null; + resizeableContextMenu.clear(); + resizeableContextMenu = null; + displayFPSContextMenu.clear(); + displayFPSContextMenu = null; + showEnemyHealthContextMenu.clear(); + showEnemyHealthContextMenu = null; + resolutionContextMenu = null; + fpsContextMenu.clear(); + fpsContextMenu = null; + loadedSettings = null; + } catch (Exception e) {} + } + + private static int nullCount = 0; +} diff --git a/src/engine/SplashScreen.java b/src/engine/SplashScreen.java new file mode 100755 index 0000000..7616e0b --- /dev/null +++ b/src/engine/SplashScreen.java @@ -0,0 +1,64 @@ +package engine; + +import java.awt.Canvas; +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.image.BufferStrategy; + +import javax.swing.JFrame; + +import _texture.loader.Textures; +import utils.Runner; +import utils.Utils; + +final class SplashScreen extends Canvas { + private static final long serialVersionUID = 1337; + + private static Graphics g; + private static Graphics2D g2d; + private static BufferStrategy bs; + public static SplashScreen splash = new SplashScreen(); + public static JFrame splashFrame; + + public static final void init(){ + splashFrame = new JFrame("\"Nihilne\" ---- " + Game.version); + splashFrame.setLocation(java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().width / 2 - splashFrame.getWidth() / 2, + java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds().height / 2 - splashFrame.getHeight() / 2); + splashFrame.setAlwaysOnTop(true); + splashFrame.setUndecorated(true); + splashFrame.setSize(600, 240); + splashFrame.add(splash); + splash.setVisible(true); + splashFrame.setVisible(true); + splashFrame.setLocationRelativeTo(null); + } + + private static volatile boolean rendering; + public static final Runner splashRender = new Runner(() -> { + while(Game.init){ + if(rendering) return; rendering = true; + if(splash == null || splashFrame == null) return; + try{ if (bs == null) splash.createBufferStrategy(3); bs = splash.getBufferStrategy(); g = bs.getDrawGraphics(); + if (!(g == null)) g2d = (Graphics2D) g.create(); + if(g == null || g2d == null || bs == null) return; + g2d.drawImage(Textures.splashSheet[1], 0, 0, null); g2d.setFont(fonts.fonts.Gregorian20); + g2d.setColor(Color.red); g2d.drawString(Game.version, splashFrame.getWidth() / 17, (int)(splashFrame.getHeight() / 1.1f)); + g.setColor(Color.green); g.drawString(Utils.OS, (int)(splashFrame.getWidth() / 17), (int)(splashFrame.getHeight() / 1.3f)); + bs.show(); g2d.dispose(); g.dispose(); + } catch (IllegalStateException ise) { ise.printStackTrace(); + } catch (ClassCastException cce) { + } catch (NullPointerException npe){ + } catch (Exception e){} + + rendering = false; + } + }); + + public static final void cleanUp(){ + try{ splash.setVisible(false); splashFrame.setVisible(false); + splashFrame.dispose(); bs.dispose(); g.dispose(); g2d.dispose(); bs=null; g=g2d=null; splash = null; splashFrame = null; System.gc(); + } catch (NullPointerException npe){ splashFrame.setVisible(false); npe.printStackTrace(); } + } + +} diff --git a/src/fileIO/Saving.java b/src/fileIO/Saving.java new file mode 100755 index 0000000..d01bc55 --- /dev/null +++ b/src/fileIO/Saving.java @@ -0,0 +1,41 @@ +package fileIO; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; + +import engine.Game; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class Saving { + + public static final synchronized SettingsSaveFile readSettingsSaveFile() { + try { + final File in = new File(System.getProperty("user.home"), "settings.nihil"); + final FileInputStream fis = new FileInputStream(in); + final ObjectInputStream ois = new ObjectInputStream(fis); + final SettingsSaveFile readSettingsSaveFile = (SettingsSaveFile) ois.readObject(); + fis.close(); return readSettingsSaveFile; + } catch (Exception e) { + System.out.println("WARNING: Unable to read settings save file."); + return null; + } + } + + public static final synchronized void saveSettingsSaveFile(final SettingsSaveFile saveFile) { + try { + final File out = new File(System.getProperty("user.home"), "settings.nihil"); + final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(out)); + oos.writeObject(saveFile); oos.close(); + } catch (Exception e) { + e.printStackTrace(); + Game.cleanUp(); + } + } + +} diff --git a/src/fileIO/SettingsSaveFile.java b/src/fileIO/SettingsSaveFile.java new file mode 100755 index 0000000..3c778a3 --- /dev/null +++ b/src/fileIO/SettingsSaveFile.java @@ -0,0 +1,47 @@ +package fileIO; + +import java.io.Serializable; + +import engine.MenuButton; +import utils.Stack; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class SettingsSaveFile implements Serializable { + private static final long serialVersionUID = 1337; + + /* In settings class: */ + // resizeableContextMenu + // displayFPSContextMenu + // showEnemyHealthContextMenu + // resolutionContextMenu + // fpsContextMenu + + /* ----------------- TODO: ------------------ */ + // 1: create constructor that copies the current settings. √ + // 2: call the constructor in Settings.createSettingsSaveFile √ + // 3: pass the created object into the Saving class + // 4: use the Saving class method to serialize and store the object + // 5: Later, on new Game load, read from said save file + /* ------------------------------------------ */ + + public volatile Stack mainButtons, resizeable, displayFPS, healthBars, resolution, fpsCap; + public volatile boolean resizeableTF, displayFPSTF, showHealthTF; + + public SettingsSaveFile(Stack mainButtons, Stack resizeable, Stack displayFPS, + Stack healthBars, Stack resolution, Stack fpsCap, boolean resizeableTF, boolean displayFPSTF, boolean displayHealthTF) { + this.mainButtons = mainButtons; + this.resizeable = resizeable; + this.displayFPS = displayFPS; + this.healthBars = healthBars; + this.resolution = resolution; + this.fpsCap = fpsCap; + + this.resizeableTF = resizeableTF; + this.displayFPSTF = displayFPSTF; + this.showHealthTF = showHealthTF; + } + +} diff --git a/src/fileIO/fonts/fonts.java b/src/fileIO/fonts/fonts.java new file mode 100755 index 0000000..7b14941 --- /dev/null +++ b/src/fileIO/fonts/fonts.java @@ -0,0 +1,62 @@ +package fileIO.fonts; + +import java.awt.Font; +import java.awt.GraphicsEnvironment; +import java.io.InputStream; + +import javax.swing.JOptionPane; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class fonts { + + // fall back font if init() fails + public static Font fallbackFont = new Font("serif", Font.PLAIN, 14); + + public static Font GregorianBase = new Font("serif", Font.PLAIN, 24); + public static Font Gregorian10 = new Font("serif", Font.PLAIN, 8); + public static Font Gregorian20 = new Font("serif", Font.PLAIN, 24); + public static Font Gregorian20Bold = new Font("serif", Font.BOLD, 24); + public static Font Gregorian26 = new Font("serif", Font.PLAIN, 24); + public static Font Gregorian32Bold = new Font("serif", Font.BOLD, 32); + public static Font Gregorian48Bold = new Font("serif", Font.BOLD, 32); + + public static Font ponderosaBase = new Font("serif", Font.PLAIN, 12); + public static Font ponderosa20 = new Font("serif", Font.PLAIN, 12); /* is actaully 10 */ + public static Font ponderosa8 = new Font("serif", Font.PLAIN, 12); + + public synchronized static void init() { + try { + InputStream is1 = fonts.class.getResourceAsStream("/gregorian.ttf"); + InputStream is2 = fonts.class.getResourceAsStream("/ponderosa.ttf"); + GregorianBase = Font.createFont(Font.TRUETYPE_FONT, is1); + Gregorian10 = GregorianBase.deriveFont(Font.BOLD, 11.0f); + Gregorian26 = GregorianBase.deriveFont(26.0f); + Gregorian20 = GregorianBase.deriveFont(20.0f); + Gregorian20Bold = GregorianBase.deriveFont(Font.BOLD, 20.0f); + Gregorian32Bold = GregorianBase.deriveFont(Font.BOLD, 32); + Gregorian48Bold = GregorianBase.deriveFont(Font.BOLD, 48); + + ponderosaBase = Font.createFont(Font.TRUETYPE_FONT, is2); + ponderosa20 = ponderosaBase.deriveFont(Font.BOLD, 10.0f); + ponderosa8 = ponderosaBase.deriveFont(Font.ITALIC, 8.0f); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + ge.registerFont(Gregorian10); + ge.registerFont(Gregorian20); + ge.registerFont(Gregorian20Bold); + ge.registerFont(Gregorian26); + ge.registerFont(Gregorian32Bold); + ge.registerFont(Gregorian48Bold); + ge.registerFont(ponderosa20); + ge.registerFont(ponderosa8); + is1.close(); + is2.close(); + } catch (Exception e) { + JOptionPane.showMessageDialog(null, "Some fonts failed to load, using fall back font."); + GregorianBase = Gregorian20 = Gregorian10 = Gregorian20Bold = Gregorian26 = Gregorian32Bold = Gregorian48Bold = ponderosaBase = ponderosa20 = ponderosa8 = fallbackFont; + return; + } + } +} diff --git a/src/fileIO/textures/worldgen/BoulderTextures.java b/src/fileIO/textures/worldgen/BoulderTextures.java new file mode 100755 index 0000000..1b884af --- /dev/null +++ b/src/fileIO/textures/worldgen/BoulderTextures.java @@ -0,0 +1,18 @@ +package fileIO.textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class BoulderTextures { + + public static void getTextures(BufferedImage image) { + // small boulders + for(int i = 0; i < 4; i++) Textures.boulderSheet[i] = Utils.grabSprite(image, i+1, 1, 30, 20); + + // large boulders + for(int i = 4; i < 8; i++) Textures.boulderSheet[i] = Utils.grabSprite(image, i-4+1, 2, 55, 42); + } + +} diff --git a/src/fileIO/textures/worldgen/DebrisTextures.java b/src/fileIO/textures/worldgen/DebrisTextures.java new file mode 100755 index 0000000..7c9eb75 --- /dev/null +++ b/src/fileIO/textures/worldgen/DebrisTextures.java @@ -0,0 +1,15 @@ +package fileIO.textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class DebrisTextures { + + public static void getTextures(BufferedImage image) { + for(int i = 0; i < 4; i++) Textures.debrisSheet[i] = Utils.grabSprite(image, i+1, 1, 15, 10); + + for(int i = 4; i < 7; i++) Textures.debrisSheet[i] = Utils.grabSprite(image, i+1-4, 2, 15, 10); + } +} diff --git a/src/fileIO/textures/worldgen/FlowerTextures.java b/src/fileIO/textures/worldgen/FlowerTextures.java new file mode 100755 index 0000000..d3a0214 --- /dev/null +++ b/src/fileIO/textures/worldgen/FlowerTextures.java @@ -0,0 +1,28 @@ +package fileIO.textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class FlowerTextures { + + public static void getTextures(BufferedImage image) { + Textures.flowerSheet[0] = Utils.grabSprite(image, 1, 1, 23, 8); + Textures.flowerSheet[1] = Utils.grabSprite(image, 2, 1, 23, 8); + Textures.flowerSheet[2] = Utils.grabSprite(image, 3, 1, 23, 8); + Textures.flowerSheet[3] = Utils.grabSprite(image, 4, 1, 23, 8); + Textures.flowerSheet[4] = Utils.grabSprite(image, 5, 1, 23, 8); + Textures.flowerSheet[5] = Utils.grabSprite(image, 6, 1, 23, 8); + Textures.flowerSheet[6] = Utils.grabSprite(image, 7, 1, 23, 8); + Textures.flowerSheet[7] = Utils.grabSprite(image, 8, 1, 23, 8); + Textures.flowerSheet[8] = Utils.grabSprite(image, 1, 2, 23, 8); + Textures.flowerSheet[9] = Utils.grabSprite(image, 2, 2, 23, 8); + Textures.flowerSheet[10] = Utils.grabSprite(image, 3, 2, 23, 8); + Textures.flowerSheet[11] = Utils.grabSprite(image, 4, 2, 23, 8); + Textures.flowerSheet[12] = Utils.grabSprite(image, 5, 2, 23, 8); + Textures.flowerSheet[13] = Utils.grabSprite(image, 6, 2, 23, 8); + Textures.flowerSheet[14] = Utils.grabSprite(image, 7, 2, 23, 8); + Textures.flowerSheet[15] = Utils.grabSprite(image, 8, 2, 23, 8); + } +} diff --git a/src/fileIO/textures/worldgen/SaplingTextures.java b/src/fileIO/textures/worldgen/SaplingTextures.java new file mode 100755 index 0000000..fd3481a --- /dev/null +++ b/src/fileIO/textures/worldgen/SaplingTextures.java @@ -0,0 +1,18 @@ +package fileIO.textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class SaplingTextures { + + public static void getTextures(BufferedImage image) { + Textures.saplingSheet[0] = Utils.grabSprite(image, 1, 1, 16, 25); + Textures.saplingSheet[1] = Utils.grabSprite(image, 2, 1, 16, 25); + Textures.saplingSheet[2] = Utils.grabSprite(image, 3, 1, 16, 25); + Textures.saplingSheet[3] = Utils.grabSprite(image, 4, 1, 16, 25); + Textures.saplingSheet[4] = Utils.grabSprite(image, 5, 1, 16, 25); + } + +} diff --git a/src/fileIO/textures/worldgen/TallGrassTextures.java b/src/fileIO/textures/worldgen/TallGrassTextures.java new file mode 100755 index 0000000..c74f178 --- /dev/null +++ b/src/fileIO/textures/worldgen/TallGrassTextures.java @@ -0,0 +1,20 @@ +package fileIO.textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class TallGrassTextures { + + public static void getTextures(BufferedImage image) { + Textures.grassSheet[0] = Utils.grabSprite(image, 1, 1, 14, 16); + Textures.grassSheet[1] = Utils.grabSprite(image, 2, 1, 14, 16); + Textures.grassSheet[2] = Utils.grabSprite(image, 3, 1, 14, 16); + Textures.grassSheet[3] = Utils.grabSprite(image, 4, 1, 14, 16); + Textures.grassSheet[4] = Utils.grabSprite(image, 5, 1, 14, 16); + Textures.grassSheet[5] = Utils.grabSprite(image, 6, 1, 14, 16); + Textures.grassSheet[6] = Utils.grabSprite(image, 7, 1, 14, 16); + } + +} diff --git a/src/fileIO/textures/worldgen/TileTextures.java b/src/fileIO/textures/worldgen/TileTextures.java new file mode 100755 index 0000000..37a5134 --- /dev/null +++ b/src/fileIO/textures/worldgen/TileTextures.java @@ -0,0 +1,53 @@ +package fileIO.textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class TileTextures { + + public static void getTextures(BufferedImage image) { + Textures.tileSheet[0] = Utils.grabSprite(image, 1, 1, 34, 34); + Textures.tileSheet[1] = Utils.grabSprite(image, 1, 2, 34, 34); + Textures.tileSheet[2] = Utils.grabSprite(image, 1, 3, 34, 34); + Textures.tileSheet[3] = Utils.grabSprite(image, 1, 4, 34, 34); + Textures.tileSheet[4] = Utils.grabSprite(image, 1, 5, 34, 34); + Textures.tileSheet[5] = Utils.grabSprite(image, 1, 6, 34, 34); + Textures.tileSheet[6] = Utils.grabSprite(image, 1, 7, 34, 34); + Textures.tileSheet[7] = Utils.grabSprite(image, 1, 8, 34, 34); + Textures.tileSheet[8] = Utils.grabSprite(image, 1, 9, 34, 34); + Textures.tileSheet[9] = Utils.grabSprite(image, 1, 10, 34, 34); + Textures.tileSheet[10] = Utils.grabSprite(image, 1, 11, 34, 34); + Textures.tileSheet[11] = Utils.grabSprite(image, 1, 12, 34, 34); + Textures.tileSheet[12] = Utils.grabSprite(image, 1, 13, 34, 34); + Textures.tileSheet[13] = Utils.grabSprite(image, 1, 14, 34, 34); + Textures.tileSheet[14] = Utils.grabSprite(image, 1, 15, 34, 34); + Textures.tileSheet[15] = Utils.grabSprite(image, 1, 16, 34, 34); + Textures.tileSheet[16] = Utils.grabSprite(image, 1, 17, 34, 34); + Textures.tileSheet[17] = Utils.grabSprite(image, 1, 18, 34, 34); + } + + public static void getOceanTextures(BufferedImage image) { + Textures.tileSheet[18] = Utils.grabSprite(image, 1, 1, 32, 32); + Textures.tileSheet[19] = Utils.grabSprite(image, 2, 1, 32, 32); + Textures.tileSheet[20] = Utils.grabSprite(image, 3, 1, 32, 32); + Textures.tileSheet[21] = Utils.grabSprite(image, 4, 1, 32, 32); + Textures.tileSheet[22] = Utils.grabSprite(image, 5, 1, 32, 32); + Textures.tileSheet[23] = Utils.grabSprite(image, 6, 1, 32, 32); + Textures.tileSheet[24] = Utils.grabSprite(image, 7, 1, 32, 32); + Textures.tileSheet[25] = Utils.grabSprite(image, 8, 1, 32, 32); + Textures.tileSheet[26] = Utils.grabSprite(image, 1, 2, 32, 32); + Textures.tileSheet[27] = Utils.grabSprite(image, 2, 2, 32, 32); + Textures.tileSheet[28] = Utils.grabSprite(image, 3, 2, 32, 32); + Textures.tileSheet[29] = Utils.grabSprite(image, 4, 2, 32, 32); + Textures.tileSheet[30] = Utils.grabSprite(image, 5, 2, 32, 32); + Textures.tileSheet[31] = Utils.grabSprite(image, 6, 2, 32, 32); + Textures.tileSheet[32] = Utils.grabSprite(image, 7, 2, 32, 32); + Textures.tileSheet[33] = Utils.grabSprite(image, 8, 2, 32, 32); + } +} diff --git a/src/fileIO/textures/worldgen/TreeTextures.java b/src/fileIO/textures/worldgen/TreeTextures.java new file mode 100755 index 0000000..70e2ef1 --- /dev/null +++ b/src/fileIO/textures/worldgen/TreeTextures.java @@ -0,0 +1,17 @@ +package fileIO.textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class TreeTextures { + + public static void getTextures(BufferedImage image) { + Textures.treeSheet[0] = Utils.grabSprite(image, 1, 1, 64, 64); + Textures.treeSheet[1] = Utils.grabSprite(image, 2, 1, 64, 64); + Textures.treeSheet[2] = Utils.grabSprite(image, 3, 1, 64, 64); + Textures.treeSheet[3] = Utils.grabSprite(image, 4, 1, 64, 64); + } + +} diff --git a/src/fonts/fonts.java b/src/fonts/fonts.java new file mode 100755 index 0000000..d27d983 --- /dev/null +++ b/src/fonts/fonts.java @@ -0,0 +1,62 @@ +package fonts; + +import java.awt.Font; +import java.awt.GraphicsEnvironment; +import java.io.InputStream; + +import javax.swing.JOptionPane; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class fonts { + + // fall back font if init() fails + public static Font fallbackFont = new Font("serif", Font.PLAIN, 14); + + public static Font GregorianBase = new Font("serif", Font.PLAIN, 24); + public static Font Gregorian10 = new Font("serif", Font.PLAIN, 8); + public static Font Gregorian20 = new Font("serif", Font.PLAIN, 24); + public static Font Gregorian20Bold = new Font("serif", Font.BOLD, 24); + public static Font Gregorian26 = new Font("serif", Font.PLAIN, 24); + public static Font Gregorian32Bold = new Font("serif", Font.BOLD, 32); + public static Font Gregorian48Bold = new Font("serif", Font.BOLD, 32); + + public static Font ponderosaBase = new Font("serif", Font.PLAIN, 12); + public static Font ponderosa20 = new Font("serif", Font.PLAIN, 12); /* is actaully 10 */ + public static Font ponderosa8 = new Font("serif", Font.PLAIN, 12); + + public synchronized static void init() { + try { + InputStream is1 = fonts.class.getResourceAsStream("/gregorian.ttf"); + InputStream is2 = fonts.class.getResourceAsStream("/ponderosa.ttf"); + GregorianBase = Font.createFont(Font.TRUETYPE_FONT, is1); + Gregorian10 = GregorianBase.deriveFont(Font.BOLD, 11.0f); + Gregorian26 = GregorianBase.deriveFont(26.0f); + Gregorian20 = GregorianBase.deriveFont(20.0f); + Gregorian20Bold = GregorianBase.deriveFont(Font.BOLD, 20.0f); + Gregorian32Bold = GregorianBase.deriveFont(Font.BOLD, 32); + Gregorian48Bold = GregorianBase.deriveFont(Font.BOLD, 48); + + ponderosaBase = Font.createFont(Font.TRUETYPE_FONT, is2); + ponderosa20 = ponderosaBase.deriveFont(Font.BOLD, 10.0f); + ponderosa8 = ponderosaBase.deriveFont(Font.ITALIC, 8.0f); + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + ge.registerFont(Gregorian10); + ge.registerFont(Gregorian20); + ge.registerFont(Gregorian20Bold); + ge.registerFont(Gregorian26); + ge.registerFont(Gregorian32Bold); + ge.registerFont(Gregorian48Bold); + ge.registerFont(ponderosa20); + ge.registerFont(ponderosa8); + is1.close(); + is2.close(); + } catch (Exception e) { + JOptionPane.showMessageDialog(null, "Some fonts failed to load, using fall back font."); + GregorianBase = Gregorian20 = Gregorian10 = Gregorian20Bold = Gregorian26 = Gregorian32Bold = Gregorian48Bold = ponderosaBase = ponderosa20 = ponderosa8 = fallbackFont; + return; + } + } +} diff --git a/src/hud/Clock.java b/src/hud/Clock.java new file mode 100755 index 0000000..fe98e95 --- /dev/null +++ b/src/hud/Clock.java @@ -0,0 +1,75 @@ +package hud; + +import java.awt.Color; +import java.awt.Graphics2D; + +import _texture.loader.Textures; +import engine.Game; +import engine.Game.STATE; +import engine.Handler; +import fonts.fonts; +import interfaces.Colors; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class Clock { + + public static int width = 140, height = 140, day = 1, time; + private static int arrowWidth = 11, arrowHeight = 46; + public static TIME clock; + + public static final int SECOND = 60, MINUTE = SECOND*60, DAWN_DURATION = 1250, DAY_DURATION = 9600, DUSK_DURATION = 3350, NIGHT_DURATION = 7400, FULL_DAY = (DAWN_DURATION + DAY_DURATION + DUSK_DURATION + NIGHT_DURATION); + + public static final int DAWN = 0, DAY = 1250, DUSK = 10850, NIGHT = 14200; + + public static void init(){ time = DAY; clock = TIME.DAY; } + + public enum TIME { DAWN, DAY, DUSK, NIGHT; } + + public static void tick() { + if (Game.state == STATE.GAME) { + time++; + if (time < DAY) clock = TIME.DAWN; + else if (time > DAY && time < DUSK) clock = TIME.DAY; + else if (time > DUSK && time < NIGHT) clock = TIME.DUSK; + else if (time > NIGHT) clock = TIME.NIGHT; + + if(Game.alwaysDawn) clock = TIME.DAWN; + else if(Game.alwaysDay) clock = TIME.DAY; + else if(Game.alwaysDusk) clock = TIME.DUSK; + else if(Game.alwaysNight) clock = TIME.NIGHT; + + if (time > FULL_DAY) { + time = 0; + day++; + Handler.getMapImage(); + System.gc(); + //save + } + } + } + + public static void render(Graphics2D g2d) { + g2d.drawImage(Textures.hudSheet[1], 0, 0, null); + + if (Game.drawCurrentTime) { + g2d.setFont(fonts.fallbackFont); + g2d.setColor(Color.orange); + g2d.drawString(clock.toString(), 52, 160); + } + + Graphics2D arrowg2d = (Graphics2D) g2d.create(); + + arrowg2d.rotate(Math.toRadians(time / 60), width / 2, height / 2); + + arrowg2d.drawImage(Textures.hudSheet[2], width / 2 - arrowWidth / 2 - 1, (int) (height / 2 - arrowHeight / 1.3), null); + + g2d.setColor(Colors.offWhite); + g2d.setFont(fonts.Gregorian32Bold); + if (day < 100) g2d.drawString("Day " + Integer.toString(day), 31, 81); + else g2d.drawString("Day " + Integer.toString(day), 14, 81); + } + +} diff --git a/src/hud/Map.java b/src/hud/Map.java new file mode 100755 index 0000000..c779615 --- /dev/null +++ b/src/hud/Map.java @@ -0,0 +1,90 @@ +package hud; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.image.BufferedImage; + +import engine.Game; +import engine.Game.STATE; +import engine.MouseInput; +import player.Player; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class Map { + + private static final int frameWidth = 10, frameHeight = 10; + private static int width, height, x, y; + public static BufferedImage map, mapCopy; + public static Rectangle mapBounds = new Rectangle(0,0,0,0); + public static double scaleFactor = 1; + public static boolean clicked, hasBeenClicked; + + private static int tempX, tempY, latestX, latestY; + public final static void tick(){ + if(Game.state != STATE.MAP) return; + + if(!hasBeenClicked){ + width = (int)(Game.game.getWidth()/1.5); + height = (int)(Game.game.getHeight()/1.5); + x = (int)(Game.game.getWidth()/2 - width/2); + y = (int)(Game.game.getHeight()/2 - height/2); + tempX = latestX = x; tempY = latestY = y; + } + + if(clicked){ + latestX = tempX + MouseInput.mouseXY.x - MouseInput.clickPos.x; + latestY = tempY + MouseInput.mouseXY.y - MouseInput.clickPos.y; + hasBeenClicked = true; + } + + if(hasBeenClicked && !clicked){ + tempX = latestX; + tempY = latestY; + } + + mapBounds.x = x+frameWidth; + mapBounds.y = y+frameWidth; + mapBounds.width = width - frameWidth*2; + mapBounds.height = height - frameHeight*2; + } + + public static BufferedImage overlay; + public final static void render(Graphics2D g2d) { + if(Game.state != STATE.MAP) return; + + g2d.setColor(Color.black); + g2d.fillRect(x-frameWidth, y-frameHeight, width+frameWidth*2, height+frameHeight*2); + g2d.setColor(Color.gray); + g2d.fillRect(x, y, width, height); + g2d.setColor(Color.black); + g2d.fillRect(x+frameWidth, y+frameWidth, width-frameWidth*2, height-frameWidth*2); + + g2d.setClip(x+frameWidth, y+frameWidth, width-frameWidth*2, height-frameWidth*2); + g2d.scale(scaleFactor, scaleFactor); + + g2d.translate(-Player.center.x/96d + width/2d / scaleFactor, -Player.center.y/96d + height/2d / scaleFactor); + + g2d.drawImage(map, (int)(latestX / scaleFactor), (int)(latestY / scaleFactor), null); + g2d.drawImage(overlay, (int)(latestX / scaleFactor), (int)(latestY / scaleFactor), null); + + BufferedImage playerPosOverlay = new BufferedImage(map.getWidth(), map.getHeight(), BufferedImage.TYPE_INT_ARGB); + Graphics2D playerPos = (Graphics2D) playerPosOverlay.getGraphics(); + playerPos.setColor(Color.orange); int WH = 96; /* 1/96 scale = 1 pixel */ + playerPos.scale(1/96d, 1/96d); + playerPos.fillRect((int)Player.center.x-WH/2, (int)Player.center.y-WH/2, WH, WH); + playerPos.setColor(Color.red); + WH = 960; + playerPos.drawOval((int)Player.center.x-WH/2-96, (int)Player.center.y-WH/2-96, WH, WH); + g2d.drawImage(playerPosOverlay, (int)(latestX / scaleFactor), (int)(latestY / scaleFactor), null); + playerPos.dispose(); playerPos = null; playerPosOverlay = null; + } + + public static synchronized final void cleanUp() { + map = mapCopy = null; mapBounds = null; + } + +} diff --git a/src/hud/RightClickMenu.java b/src/hud/RightClickMenu.java new file mode 100755 index 0000000..1cabfd8 --- /dev/null +++ b/src/hud/RightClickMenu.java @@ -0,0 +1,648 @@ +package hud; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.font.TextAttribute; +import java.util.ArrayList; +import java.util.ConcurrentModificationException; +import java.util.Hashtable; + +import animations.PlayerAnimationUtils; +import engine.Game; +import engine.Handler; +import engine.MouseInput; +import fonts.fonts; +import hud.SecondaryHUD.TAB; +import hud.constructionmenu.ConstructionMenu; +import hud.constructionmenu.ConstructionMenuCategory; +import hud.inventory.InvenHelper; +import hud.inventory.Inventory; +import hud.inventory.InventorySlot; +import interfaces.Colors; +import interfaces.Entity; +import interfaces.ItemIDs; +import interfaces.Mob; +import lighting.RadialLight; +import player.Player; +import player.PlayerAttackSequence; +import utils.Circle; +import utils.Point2f; +import utils.Utils; +import world.Boulder; +import world.DroppedItem; +import world.Flower; +import world.Sapling; +import world.TallGrass; +import world.Tree; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class RightClickMenu implements ItemIDs { + + /***************** XXX! *******************/ + + // This class uses an ArrayList to store the lines + // This list is cleared upon each click + // To add any lines to the right-click menu + // you must first "list.add(new Line());" before + // referencing your new line. + + /******************************************/ + + private static final int DROP = 0, STORE = 1, RETRIEVE = 2, EQUIP = 3, UNEQUIP = 4, EAT = 5, + COOK = 6, ATTACK = 7, PICK_UP = 8, HARVEST = 9, CHOP = 10, MINE = 11, PICK = 12; + + + // ************************************************************************* // + // * * * * * * * * Abandon all hope ye who enter here. * * * * * * * * * // + // ************************************************************************* // + + private static final int l = 9, h = 18; + private static int numLines, width; + private static Circle clickBounds = new Circle(new Point2f(0,0), 20); // the bounds for containing things in right click + private static Rectangle menuBounds = new Rectangle(0, 0, 0, 0); + public static ArrayList lines; + public static String[] actions, items; // items is by item id + public static boolean OVERRIDE_SPACE, OVERRIDE_F; + + private static Integer LOCATION = null; + private static final int WORLD = 1, HUD = 2; + + public synchronized final static void init() { + items = Utils.makeStringArrayFromLinesOfTextFile("/itemTexts.nihil"); + actions = Utils.makeStringArrayFromLinesOfTextFile("/actionTexts.nihil"); + + lines = new ArrayList(); + } + + public final static void determineText() { + if(okayToOpenWorldMenu()) { + LOCATION = WORLD; int count = 0; + /*********************** GOALS ********************/ + // 1: Set click bounds to the current click pos + // 2: Loop first through all mobs in handler, if any found add 'attack' + their class to the top + // 3: Then add the "Walk Here", this will be at the top should there not have been any mobs found. + // 4: Repeat through the rest of the handler sets in desired order. + // 5: When finished, add the 'exit' option to the bottom. + /**************************************************/ + + clickBounds.center.x = MouseInput.adjustedRightClickPos.x; // can't convert from Point to Point2f + clickBounds.center.y = MouseInput.adjustedRightClickPos.y; // this works just fine + + try { for(final Mob i : Handler.mobs) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y) && i.alive()) { + if(clickBounds.contains(i.center)) { + lines.add(new Line()); + lines.get(count++).set(i.toString(), actions[ATTACK]); + } } } catch (ConcurrentModificationException cme) { clearAll(); determineText(); } + + try { for(final DroppedItem i : Handler.droppedItems) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y)) { + if(clickBounds.contains(i.center)) { + lines.add(new Line()); + lines.get(count++).set(items[i.itemId - 1], actions[PICK_UP]); + } } } catch (ConcurrentModificationException cme) { clearAll(); determineText(); } + + try { for(final Sapling i : Handler.saplings) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y)) { + if(!i.alive) continue; + if(clickBounds.contains(i.center)) { + lines.add(new Line()); + lines.get(count++).set("sapling", actions[PICK]); + } } } catch (ConcurrentModificationException cme) { clearAll(); determineText(); } + + try { for(final TallGrass i : Handler.grass) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y)) { + if(!i.alive) continue; + if(clickBounds.contains(i.center)) { + lines.add(new Line()); + lines.get(count++).set("grass", actions[PICK]); + } } } catch (ConcurrentModificationException cme) { clearAll(); determineText(); } + + try { for(final Flower i : Handler.flowers) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y)) { + if(!i.alive) continue; + if(clickBounds.contains(i.center)) { + lines.add(new Line()); + lines.get(count++).set("flower", actions[HARVEST]); + } } } catch (ConcurrentModificationException cme) { clearAll(); determineText(); } + + if(InvenHelper.isPickaxe(Player.equipmentSlots[HAND_SLOT].itemId)) { + try { for(final Boulder i : Handler.boulders) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y)) { + if(!i.alive) continue; + if(clickBounds.contains(i.center)) { + lines.add(new Line()); + lines.get(count++).set("boulder", actions[MINE]); + } } } catch (ConcurrentModificationException cme) { clearAll(); determineText(); } + } + + if(InvenHelper.isAxe(Player.equipmentSlots[HAND_SLOT].itemId)) { + try { for(final Tree i : Handler.trees) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y)) { + if(!i.alive) continue; + if(Utils.intersects(i.bounds, clickBounds)) { + lines.add(new Line()); + lines.get(count++).set("tree", actions[CHOP]); + } } } catch (ConcurrentModificationException cme) { clearAll(); determineText(); } + } + + addWalkHere(); + addExit(); // adds the 'exit' to the bottom of the menu + } + + // HUD RIGHT CLICK MENU + else if (okayToOpenHUDMenu()) { + LOCATION = HUD; int count = 0; + + for (final InventorySlot i : Player.inventorySlots) { if (i.itemId == NULL_ITEM) continue; + + if (i.bounds.contains(MouseInput.rightClickPos)) { + // EQUIP + if (i.equippable) { + lines.add(new Line()); + lines.get(count++).set(items[i.itemId - 1], actions[EQUIP]); + } + + // DROP + lines.add(new Line()); + lines.get(count++).set(items[i.itemId - 1], actions[DROP]); + + break; /* break because we found the slot that contains mouse pos */ + } + } + count = 0; + for (final InventorySlot i : Player.equipmentSlots) { if (i.itemId == NULL_ITEM) continue; + if (i.bounds.contains(MouseInput.rightClickPos)) { + // UNEQUIP + lines.add(new Line()); + lines.get(count++).set(items[i.itemId - 1], actions[UNEQUIP]); + + break; /* break because we found the slot that contains mouse pos */ + } + } + addExit(); // adds the 'exit' to the bottom of the menu + } + // MUST BE INVALID CLICK, CLEAR MENU + else clearAll(); + } + + private static Point2f tempCenter; + private static Tree tempTree; + private static Boulder tempBoulder; + private static DroppedItem tempItem; + private static Entity tempEntity; + private static Mob tempMob; + public final static void tick() { + if(!OVERRIDE_SPACE && !OVERRIDE_F) { + tempTree = null; tempBoulder = null; tempItem = null; tempEntity = null; tempMob = null; tempCenter = null; + return; + } + + if(tempTree != null) { + if(tempTree.alive && InvenHelper.isAxe(Player.equipmentSlots[HAND_SLOT].itemId)) { + tempCenter = tempTree.center; + if(!Utils.intersects(Player.center, Player.radius, tempTree.center, tempTree.chopRadius)) { + Player.keepWalkingX = Player.keepWalkingY = true; + MouseInput.adjustedClickPos.x = (int)tempTree.center.x; + MouseInput.adjustedClickPos.y = (int)tempTree.center.y; + } else { OVERRIDE_SPACE = Player.using = true; Player.keepWalkingX = Player.keepWalkingY = false; } + } else { tempCenter = null; tempTree = null; OVERRIDE_SPACE = Player.using = false; } + } + + else if(tempBoulder != null) { + if(tempBoulder.alive && InvenHelper.isPickaxe(Player.equipmentSlots[HAND_SLOT].itemId)) { + tempCenter = tempBoulder.center; + if(!Utils.intersects(Player.center, Player.radius, tempBoulder.center, tempBoulder.mineRadius)) { + Player.keepWalkingX = Player.keepWalkingY = true; + MouseInput.adjustedClickPos.x = (int)tempBoulder.center.x; + MouseInput.adjustedClickPos.y = (int)tempBoulder.center.y; + } else { OVERRIDE_SPACE = Player.using = true; Player.keepWalkingX = Player.keepWalkingY = false; } + } else { tempCenter = null; tempBoulder = null; OVERRIDE_SPACE = Player.using = false; } + } + + else if(tempItem != null) { + tempCenter = tempItem.center; + if(!Utils.intersects(Player.center, Player.radius, tempItem.center, tempItem.radius)) { + Player.keepWalkingX = Player.keepWalkingY = true; + MouseInput.adjustedClickPos.x = (int)tempItem.center.x; + MouseInput.adjustedClickPos.y = (int)tempItem.center.y; + } else { + if(!Inventory.isFull(tempItem.itemId, tempItem.quantity)) { + tempCenter = null; + Inventory.addItem(tempItem.itemId, tempItem.quantity, tempItem.durability); + Handler.droppedItems.remove(tempItem); tempItem = null; + Player.keepWalkingX = Player.keepWalkingY = false; + } + } + } + + else if(tempEntity != null) { + if(tempEntity.alive) { + tempCenter = tempEntity.center; + if(!Utils.intersects(Player.center, Player.radius, tempEntity.center, tempEntity.radius)) { + Player.keepWalkingX = Player.keepWalkingY = true; + MouseInput.adjustedClickPos.x = (int)tempEntity.center.x; + MouseInput.adjustedClickPos.y = (int)tempEntity.center.y; + } else { OVERRIDE_SPACE = Player.using = true; Player.keepWalkingX = Player.keepWalkingY = false; } + } else { tempCenter = null; tempEntity = null; OVERRIDE_SPACE = Player.using = false; } + } + + else if(tempMob != null) { + if(tempMob.health > 0) { + tempCenter = tempMob.center; + if(!Utils.intersects(Player.center, Player.radius, tempMob.center, tempMob.radius)) { + Player.keepWalkingX = Player.keepWalkingY = true; + MouseInput.adjustedClickPos.x = (int)tempMob.center.x; + MouseInput.adjustedClickPos.y = (int)tempMob.center.y; + } else { if(!Player.attacking) PlayerAttackSequence.start(); } + } else { tempCenter = null; tempMob = null; } + } + + // DIRECTION / FACING TOWARD TARGETED OBJECT + if(tempCenter != null) { + + int temp = (Utils.direction(Player.center, tempCenter) + (Game.rotation - 1)); + if(temp > 8) temp-=8; + Player.facing = temp; + + } + + + } + + public final synchronized static void onClick() { + if (!menuOpen() || LOCATION == null) return; + + if (LOCATION == WORLD) { + for (final Line i : lines) { if (i.isEmpty()) continue; + if (i.bounds.contains(MouseInput.mouseXY)) { + + // EXIT + if (i.action.toString().equals("exit")) { clearAll(); return; } + + // WALK HERE + else if (i.action.toString().equals("walk here")) { + Player.keepWalkingX = Player.keepWalkingY = true; + MouseInput.adjustedClickPos.x = MouseInput.adjustedRightClickPos.x; + MouseInput.adjustedClickPos.y = MouseInput.adjustedRightClickPos.y; + } + + // CHOP + else if (i.action.toString().equals(actions[CHOP])) { + try { for(final Tree T : Handler.trees) if(T.discovered && Handler.AREA_RECT.contains(T.center.x, T.center.y)) { + if(!T.alive) continue; // don't show chop option if its already cut down + if(Utils.intersects(T.bounds, clickBounds)) { + tempTree = T; OVERRIDE_SPACE = true; break; + } } } catch (ConcurrentModificationException cme) { } + } + + // MINE + else if (i.action.toString().equals(actions[MINE])) { + try { for(final Boulder T : Handler.boulders) if(T.discovered && Handler.AREA_RECT.contains(T.center.x, T.center.y)) { + if(!T.alive) continue; // don't show chop option if its already cut down + if(Utils.intersects(T.center, T.mineRadius, clickBounds.center, clickBounds.radius)) { + tempBoulder = T; OVERRIDE_SPACE = true; break; + } } } catch (ConcurrentModificationException cme) { } + } + + // "PICK UP" --- (dropped items) + else if (i.action.toString().equals(actions[PICK_UP])) { + try { for(final DroppedItem T : Handler.droppedItems) if(T.discovered && Handler.AREA_RECT.contains(T.center.x, T.center.y)) { + if(Utils.intersects(T.center, T.radius, clickBounds.center, clickBounds.radius)) { + if(items[T.itemId-1].equals(i.item.toString())) { tempItem = T; OVERRIDE_SPACE = true; break; } + } } } catch (ConcurrentModificationException cme) { } + } + + // "PICK" || "HARVEST" + else if (i.action.toString().equals(actions[PICK]) || i.action.toString().equals(actions[HARVEST])) { + if(i.item.toString().equals("grass")) { + try { for(final TallGrass T : Handler.grass) if(T.discovered && Handler.AREA_RECT.contains(T.center.x, T.center.y)) { + if(Utils.intersects(T.center, T.radius, clickBounds.center, clickBounds.radius)) { + tempEntity = T; OVERRIDE_SPACE = true; break; + } } } catch (ConcurrentModificationException cme) { } + } + else if(i.item.toString().equals("sapling")) { + try { for(final Sapling T : Handler.saplings) if(T.discovered && Handler.AREA_RECT.contains(T.center.x, T.center.y)) { + if(Utils.intersects(T.center, T.radius, clickBounds.center, clickBounds.radius)) { + tempEntity = T; OVERRIDE_SPACE = true; break; + } } } catch (ConcurrentModificationException cme) { } + } + else if(i.item.toString().equals("flower")) { + try { for(final Flower T : Handler.flowers) if(T.discovered && Handler.AREA_RECT.contains(T.center.x, T.center.y)) { + if(Utils.intersects(T.center, T.radius, clickBounds.center, clickBounds.radius)) { + tempEntity = T; OVERRIDE_SPACE = true; break; + } } } catch (ConcurrentModificationException cme) { } + } + } + + // "ATTACK" + else if (i.action.toString().equals(actions[ATTACK])) { + if(!InvenHelper.hasWeapon()) break; + + try { for(final Mob T : Handler.mobs) if(T.discovered && Handler.AREA_RECT.contains(T.center.x, T.center.y)) { + if(Utils.intersects(T.center, T.radius, clickBounds.center, clickBounds.radius)) { + if(T.toString().equals(i.item.toString())) { tempMob = T; OVERRIDE_F = true; break; } + } } } catch (ConcurrentModificationException cme) { } + } + } + } + } + +/*****************************************************************************************************************/ + + else if (LOCATION == HUD) { + + int whichInvenSlot = 0; int whichEquipmentSlot = 0; + + for (final InventorySlot i : Player.inventorySlots) if (i.bounds.contains(MouseInput.rightClickPos)) whichInvenSlot = i.slotNumber; + for (final InventorySlot i : Player.equipmentSlots) if (i.bounds.contains(MouseInput.rightClickPos)) whichEquipmentSlot = i.slotNumber; + + for (final Line i : lines) { if (i.isEmpty()) continue; + if (i.bounds.contains(MouseInput.mouseXY)) { + // Exit + if (i.action.toString().equals("exit")) { clearAll(); return; } + + // Equip + else if (i.action.toString().equals((actions[EQUIP]))) { + for (final InventorySlot slot : Player.inventorySlots) + if (slot.slotNumber == whichInvenSlot) { + int slotToEquipTo = InvenHelper.calcEquipSlot(slot.itemId); + int tempId = slot.itemId; float tempDurability = slot.durability; + + RadialLight.determineLight(slot.itemId); + + slot.itemId = Player.equipmentSlots[slotToEquipTo].itemId; + slot.durability = Player.equipmentSlots[slotToEquipTo].durability; + + + RadialLight.removeLight(slot.itemId); + + Player.equipmentSlots[slotToEquipTo].itemId = tempId; + Player.equipmentSlots[slotToEquipTo].durability = tempDurability; + Player.equipmentSlots[slotToEquipTo].quantity = 1; + slot.mouseClicked = false; + + PlayerAnimationUtils.resetAll(); clearAll(); + Inventory.changeSettings(); + return; + } + } + + + // UNEQUIP + else if (i.action.toString().equals((actions[UNEQUIP]))) { + for (InventorySlot slot : Player.equipmentSlots) { + if (slot.slotNumber == whichEquipmentSlot) + for (final InventorySlot s : Player.inventorySlots) { + if (s.itemId == NULL_ITEM) { // first slot that is empty, switch + s.itemId = slot.itemId; + s.durability = slot.durability; + s.equippable = true; + s.mouseClicked = false; + s.quantity = 1; + s.equippable = true; + + RadialLight.removeLight(slot.itemId); + + slot.itemId = NULL_ITEM; + slot.durability = -1; + slot.quantity = 0; + + PlayerAnimationUtils.resetAll(); clearAll(); + Inventory.changeSettings(); + return; + } + } + }} + + + // Drop + else if (i.action.toString().equals((actions[DROP]))) { + for (final InventorySlot slot : Player.inventorySlots) + if (slot.slotNumber == whichInvenSlot) { + Inventory.dropItem(slot.itemId, slot.quantity, slot.durability, slot.slotNumber); + clearAll(); + return; + } + } + } + } + } + + clearAll(); + } + + public final static void render(Graphics2D g2d) { + if (!menuOpen() || LOCATION == null) return; + + try { + width = numLines = 0; + for (final Line i : lines) { + if (i.isEmpty()) continue; + + if((i.item.length() + i.action.length()) * l > width) + width = (i.item.length() + i.action.length()) * l; + + numLines++; + } + + width += 6; /* the # is for the space at the end */ + + menuBounds.x = (int) (MouseInput.rightClickPos.x - width / 6.5); + menuBounds.y = (int) (MouseInput.rightClickPos.y - h / 3.05); + menuBounds.width = width; + menuBounds.height = h * numLines; + + if (menuBounds.contains(MouseInput.mouseXY)) { + updateLineBounds(); + + for (int i = 0; i < lines.size(); i++) { + if (lines.get(i).isEmpty()) continue; + + // DRAW BOX + if (!(lines.get(i).bounds.contains(MouseInput.mouseXY))) g2d.setColor(Color.BLACK); + else g2d.setColor(Colors.menuGray); + + g2d.fillRect((int) (MouseInput.rightClickPos.x - width / 6.5), (int) (MouseInput.rightClickPos.y + i * h - h / 3.05), width, h); + + g2d.setFont(fonts.ponderosa20); + + if (!lines.get(i).action.toString().equals("exit") && !lines.get(i).action.toString().equals("walk here")) { + // DRAW ACTION + if(!(lines.get(i).action.toString().equals(actions[ATTACK]) && !InvenHelper.hasWeapon())) { + g2d.setColor(Color.white); + g2d.drawString(lines.get(i).action.toString(), (int) (MouseInput.rightClickPos.x + 3 - width / 6.5), + (int) (((MouseInput.rightClickPos.y) + (h * 0.8)) + i * h - h / 3.05)); + } else { + // STRIKE THROUGH ATTACK IF DONT HAVE WEAPON + Hashtable map = new Hashtable(); + map.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON); + g2d.setFont(fonts.ponderosa20.deriveFont(map)); + + g2d.setColor(Colors.pastelRed); + g2d.drawString(lines.get(i).action.toString().substring(0, (lines.get(i).action.toString().indexOf(" "))), + (int) (MouseInput.rightClickPos.x + 3 - width / 6.5), + (int) (((MouseInput.rightClickPos.y) + (h * 0.8)) + i * h - h / 3.05)); + + g2d.setFont(fonts.ponderosa20); // RESET FONT + } + + // DRAW ITEM + g2d.setColor(Color.orange); + g2d.drawString(lines.get(i).item.toString(), (int) (lines.get(i).action.toString().length()*l + MouseInput.rightClickPos.x + 3 - width / 6.5), + (int) (((MouseInput.rightClickPos.y) + (h * 0.8)) + i * h - h / 3.05)); + } else { + // DRAW EXIT / WALK HERE + g2d.setColor(Color.lightGray); + g2d.drawString(lines.get(i).action.toString(), (int) (MouseInput.rightClickPos.x + 3 - width / 6.5), + (int) (((MouseInput.rightClickPos.y) + (h * 0.8)) + i * h - h / 3.05)); + } + } + + g2d.setColor(Color.darkGray); + g2d.draw(menuBounds); + + for (final Line i : lines) try { if (!i.isEmpty()) g2d.draw(i.bounds); } catch(ConcurrentModificationException cme) {} + + if(LOCATION == WORLD && Game.drawCollisionBounds || Game.drawRightClickBounds) { + g2d.setColor(Color.orange); + g2d.drawOval((int)(MouseInput.rightClickPos.x-clickBounds.radius), (int)(MouseInput.rightClickPos.y-clickBounds.radius), (int)clickBounds.radius*2, (int)clickBounds.radius*2); + } + + } else { clearAll(); return; } + } catch (Exception e) { clearAll(); } // from CME's to Nulls to IOOB's, all things can happen from adding / removing lines while rendering + // just catch and miss the frame, no big deal. Not much can do about it. + } + + public final static boolean okayToOpenWorldMenu() { + if (!menuOpen()) return false; // don't open menu if already open + + // if currently holding an item, don't open + for (final InventorySlot i : Player.inventorySlots) if (i.mouseClicked) return false; + + // if in inventory + if (Inventory.INVENTORY_BOUNDS.contains(MouseInput.rightClickPos)) return false; + + // if in secondary hud + if (SecondaryHUD.tab == TAB.MINIMIZED && SecondaryHUD.minimizedBounds.contains(MouseInput.rightClickPos)) return false; + else if (!(SecondaryHUD.tab == TAB.MINIMIZED) && SecondaryHUD.maximizedBounds.contains(MouseInput.rightClickPos)) return false; + + // if inside clock + if (MouseInput.rightClickPos.x > (Game.game.getWidth() / 1.08 - Clock.width / 2) && MouseInput.rightClickPos.x < (Game.game.getWidth() / 1.08 + Clock.width / 2)) + if (MouseInput.rightClickPos.y < (Game.game.getHeight() / 7.75 + Clock.height / 2) && MouseInput.rightClickPos.y > (Game.game.getHeight() / 7.75 - Clock.height / 2)) + return false; + + // if inside construction tabs + if(ConstructionMenu.bounds.contains(MouseInput.rightClickPos)) return false; + + return true; + } + + public final static boolean okayToOpenHUDMenu() { + if (!menuOpen()) return false; // don't open menu if already open + + for (InventorySlot i : Player.inventorySlots) { /* don't show menu if holding item */ + if (i.bounds.contains(MouseInput.rightClickPos)) { + if (i.mouseClicked || (i.itemId == NULL_ITEM)) { + MouseInput.rightClickPos.x = MouseInput.rightClickPos.y = -1; + return false; + } + } + } + + for (InventorySlot i : Player.equipmentSlots) { /* don't show menu if holding item */ + if (i.bounds.contains(MouseInput.rightClickPos)) { + if (i.mouseClicked || (i.itemId == NULL_ITEM)) { + MouseInput.rightClickPos.x = MouseInput.rightClickPos.y = -1; + return false; + } + } + } + + // if not in inventory + if (!Inventory.INVENTORY_BOUNDS.contains(MouseInput.rightClickPos)) { + // and not in secondary hud + if (SecondaryHUD.tab == TAB.MINIMIZED) { return false; + } else if (!(SecondaryHUD.tab == TAB.MINIMIZED)) if (!(SecondaryHUD.maximizedBounds.contains(MouseInput.rightClickPos))) return false; + + } + + // if inside clock + if (MouseInput.rightClickPos.x > (Game.game.getWidth() / 1.08 - Clock.width / 2) && MouseInput.rightClickPos.x < (Game.game.getWidth() / 1.08 + Clock.width / 2)) + if (MouseInput.rightClickPos.y < (Game.game.getHeight() / 7.75 + Clock.height / 2) && MouseInput.rightClickPos.y > (Game.game.getHeight() / 7.75 - Clock.height / 2)) + return false; + + // if inside construction tabs + if(ConstructionMenu.bounds.contains(MouseInput.rightClickPos)) return false; + + // if inside construction menu + for(ConstructionMenuCategory cmg : ConstructionMenuCategory.categories) + if(cmg.selected && cmg.bounds.contains(MouseInput.rightClickPos) || ConstructionMenuCategory.menuBounds.contains(MouseInput.rightClickPos)) return false; + + return true; + } + + public final static boolean menuOpen() { return (MouseInput.rightClickPos.x >= 0 || MouseInput.rightClickPos.y >= 0); } + + public final static void addExit() { + for (final Line i : lines) if (i.action.toString().equals("exit")) i.clear(); + + lines.add(new Line()); + for (int i = 0; i < lines.size(); i++) { + if (!lines.get(i).isEmpty()) continue; + else { lines.get(i).set(" ", "exit"); return; } + } + } + + public final static void addWalkHere() { + for (final Line i : lines) if (i.action.toString().equals("walk here")) i.clear(); + + lines.add(new Line()); + for (int i = 0; i < lines.size(); i++) { + if (!lines.get(i).isEmpty()) continue; + else { lines.get(i).set(" ", "walk here"); return; } + } + } + + private final static void updateLineBounds() { + for (int i = 0; i < lines.size(); i++) { + if (lines.get(i).isEmpty()) continue; + lines.get(i).bounds.x = (int) (MouseInput.rightClickPos.x - width / 6.5); + lines.get(i).bounds.y = (int) (MouseInput.rightClickPos.y + i * h - h / 3.05); + lines.get(i).bounds.width = width; + } + } + + private final static class Line { /* daughter class */ + private final StringBuilder action, item; + private final Rectangle bounds; + + private Line() { + action = new StringBuilder(""); + item = new StringBuilder(""); + bounds = new Rectangle(0, 0, 0, h); + } + + private final void set(String _item, String _action) { + item.setLength(0); + action.setLength(0); + action.append(_action); + item.append(_item); + } + + private final void clear() { + action.setLength(0); + item.setLength(0); + } + + private final boolean isEmpty() { return (item.length() <= 0 || action.length() <= 0); } + } + + private final static void clearAll() { + for(int i = 0; i < lines.size(); i++) lines.get(i).clear(); + lines.clear(); + MouseInput.rightClickPos.x = MouseInput.rightClickPos.y = -1; + LOCATION = null; + } + + public final synchronized static void cleanUp() { + clearAll(); LOCATION = null; lines = null; items = actions = null; clickBounds = null; menuBounds = null; + } +} diff --git a/src/hud/SecondaryHUD.java b/src/hud/SecondaryHUD.java new file mode 100755 index 0000000..392021a --- /dev/null +++ b/src/hud/SecondaryHUD.java @@ -0,0 +1,214 @@ +package hud; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; + +import _texture.loader.Textures; +import engine.Game; +import engine.MouseInput; +import fonts.fonts; +import hud.inventory.InventorySlot; +import player.Player; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class SecondaryHUD { + + public static int x, y; + public static final int SECONDARY_HUD_WIDTH = 245, SECONDARY_HUD_HEIGHT = 320, MINIMIZED_WIDTH = 224, MINIMIZED_HEIGHT = 56, TAB_BOX_WIDTH = 50, TAB_BOX_HEIGHT = 42, MINIMIZED_BUTTON_WIDTH = 33, + MINIMIZED_BUTTON_HEIGHT = 10, ATTACK_STYLE_CHOICE_WIDTH = 63, ATTACK_STYLE_CHOICE_HEIGHT = 37, MINIMIZE_BUTTON = 5; + public static TAB tab = TAB.MINIMIZED; + public static final Rectangle maximizedBounds = new Rectangle(0, 0, SECONDARY_HUD_WIDTH, SECONDARY_HUD_HEIGHT); + public static final Rectangle minimizedBounds = new Rectangle(0, 0, MINIMIZED_WIDTH, MINIMIZED_HEIGHT); + + public static final void init() { + final int NUMBER_OF_TABS_PLUS_MINIMIZE_BUTTON = 5; + int count = 0; + Player.tabSlots = new InventorySlot[NUMBER_OF_TABS_PLUS_MINIMIZE_BUTTON]; + Player.tabSlots[count++] = (new InventorySlot(1, -1, new Point(25, 23), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.tabSlots[count++] = (new InventorySlot(2, -1, new Point(75, 23), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.tabSlots[count++] = (new InventorySlot(3, -1, new Point(125, 23), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.tabSlots[count++] = (new InventorySlot(4, -1, new Point(175, 23), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.tabSlots[count++] = (new InventorySlot(5, -1, new Point(150, 18), new Rectangle(0, 0, MINIMIZED_BUTTON_WIDTH, MINIMIZED_BUTTON_HEIGHT))); + + final int NUMBER_OF_EQUIPMENT_SLOTS_PLUS_ATTACK_STYLE_CHOICES = 15; + count = 0; + Player.equipmentSlots = new InventorySlot[NUMBER_OF_EQUIPMENT_SLOTS_PLUS_ATTACK_STYLE_CHOICES]; + Player.equipmentSlots[count++] = (new InventorySlot(1, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(2, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(3, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(4, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(5, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(6, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(7, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(8, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(9, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(10, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(11, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(12, -3, new Point(0, 0), new Rectangle(0, 0, TAB_BOX_WIDTH, TAB_BOX_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(13, -3, new Point(0, 0), new Rectangle(0, 0, ATTACK_STYLE_CHOICE_WIDTH, ATTACK_STYLE_CHOICE_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(14, -3, new Point(0, 0), new Rectangle(0, 0, ATTACK_STYLE_CHOICE_WIDTH, ATTACK_STYLE_CHOICE_HEIGHT))); + Player.equipmentSlots[count++] = (new InventorySlot(15, -3, new Point(0, 0), new Rectangle(0, 0, ATTACK_STYLE_CHOICE_WIDTH, ATTACK_STYLE_CHOICE_HEIGHT))); + Player.equipmentSlots[12].mouseClicked = true; // set accurate to default attack style + } + + public static enum TAB { + MINIMIZED, BACKPACK, EQUIPMENT, SKILLS, MAGIC + } + + public static final void changeSettings() { + + maximizedBounds.x = (int) (Game.game.getWidth() - SECONDARY_HUD_WIDTH - Game.game.getWidth() * 0.005f); + maximizedBounds.y = (int) (Game.game.getHeight() - SECONDARY_HUD_HEIGHT - Game.game.getHeight() * 0.005f); + minimizedBounds.x = (int) (Game.game.getWidth() - SECONDARY_HUD_WIDTH - Game.game.getWidth() * 0.005f); + minimizedBounds.y = (int) (Game.game.getHeight() - MINIMIZED_HEIGHT - Game.game.getHeight() * 0.005f); + + if (!(tab == TAB.MINIMIZED)) { + for (final InventorySlot i : Player.tabSlots) { + if (i.slotNumber == MINIMIZE_BUTTON) { + i.pos.x = 192; + i.pos.y = -255; + i.bounds.x = (int) (i.pos.x + Game.game.getWidth() - SECONDARY_HUD_WIDTH - Game.game.getWidth() * 0.005f); + i.bounds.y = (int) (i.pos.y + Game.game.getHeight() - MINIMIZED_HEIGHT - Game.game.getHeight() * 0.005f); + i.bounds.width = MINIMIZED_BUTTON_WIDTH; + i.bounds.height = MINIMIZED_BUTTON_HEIGHT; + } else { + i.pos.x = 25 + (i.slotNumber - 1) * TAB_BOX_WIDTH; + i.pos.y = 23; + i.bounds.x = (int) (i.pos.x + Game.game.getWidth() - SECONDARY_HUD_WIDTH - Game.game.getWidth() * 0.005f); + i.bounds.y = (int) (i.pos.y + Game.game.getHeight() - SECONDARY_HUD_HEIGHT - Game.game.getHeight() * 0.005f); + } + + for (final InventorySlot e : Player.equipmentSlots) { + e.bounds.x = (int) (Game.game.getWidth() - Game.game.getWidth() * 0.005f - SECONDARY_HUD_WIDTH + e.pos.x); + e.bounds.y = (int) (Game.game.getHeight() - Game.game.getHeight() * 0.005f - SECONDARY_HUD_HEIGHT + e.pos.y); + if (e.slotNumber < 4) { + e.pos.x = 26 + (e.slotNumber - 1) * TAB_BOX_WIDTH; + e.pos.y = 76; + } else if (e.slotNumber > 3 && e.slotNumber < 7) { + e.pos.x = 26 + (e.slotNumber - 4) * TAB_BOX_WIDTH; + e.pos.y = 118; + } else if (e.slotNumber > 6 && e.slotNumber < 10) { + e.pos.x = 26 + (e.slotNumber - 7) * TAB_BOX_WIDTH; + e.pos.y = 160; + } else if (e.slotNumber > 9 && e.slotNumber < 13) { + e.pos.x = 26 + (e.slotNumber - 10) * TAB_BOX_WIDTH; + e.pos.y = 202; + } else if (e.slotNumber == 13) { + e.pos.x = 28; e.pos.y = 257; + } else if (e.slotNumber == 14) { + e.pos.x = 93; e.pos.y = 257; + } else if (e.slotNumber == 15) { + e.pos.x = 158; e.pos.y = 257; + } + } + } + } else { + for (final InventorySlot i : Player.tabSlots) { + if (i.slotNumber == 5) i.bounds.width = i.bounds.height = 0; + else { + i.pos.x = 25 + (i.slotNumber - 1) * TAB_BOX_WIDTH - 12; + i.pos.y = 23 - 17; + i.bounds.x = (int) (i.pos.x + Game.game.getWidth() - SECONDARY_HUD_WIDTH - Game.game.getWidth() * 0.005f); + i.bounds.y = (int) (i.pos.y + Game.game.getHeight() - MINIMIZED_HEIGHT - Game.game.getHeight() * 0.005f); + } + } + } + } + + private static long equipmentTimer, magicTimer, backPackTimer, skillsTimer; + private static final int TAB_DELAY = 75; + public static final void onLeftClick() { + for (final InventorySlot i : Player.tabSlots) { + if (i.bounds.contains(MouseInput.mouseXY)) { + resetAllMouseClicked(); + + i.mouseClicked = true; + switch (i.slotNumber) { + case 1: tab = TAB.BACKPACK; backPackTimer = System.currentTimeMillis(); break; + case 2: tab = TAB.EQUIPMENT; equipmentTimer = System.currentTimeMillis(); break; + case 3: tab = TAB.SKILLS; skillsTimer = System.currentTimeMillis(); break; + case 4: tab = TAB.MAGIC; magicTimer = System.currentTimeMillis(); break; + case 5: tab = TAB.MINIMIZED; + } + } + } + + if (tab == TAB.EQUIPMENT) { + if (System.currentTimeMillis() - equipmentTimer > TAB_DELAY) { + // Attack style clicks: + for (int i = 12; i < 15; i++) + if (Player.equipmentSlots[i].bounds.contains(MouseInput.mouseXY)) { + for (int e = 12; e < 15; e++) Player.equipmentSlots[e].mouseClicked = false; + Player.equipmentSlots[i].mouseClicked = true; + } + } + } + } + + public static final void render(Graphics2D g2d) { + if (tab == TAB.MINIMIZED) { + g2d.translate((int) (Game.game.getWidth() - SECONDARY_HUD_WIDTH - Game.game.getWidth() * 0.005), + (int) (Game.game.getHeight() - MINIMIZED_HEIGHT - Game.game.getHeight() * 0.005)); + g2d.drawImage(Textures.secondaryHUDSheet[8], 0, 0, null); + + for (final InventorySlot i : Player.tabSlots) i.render(g2d); + + g2d.drawImage(Textures.secondaryHUDSheet[4], 25 - 12, 23 - 17, null); + g2d.drawImage(Textures.secondaryHUDSheet[5], 75 - 12, 23 - 17, null); + g2d.drawImage(Textures.secondaryHUDSheet[6], 125 - 12, 23 - 17, null); + g2d.drawImage(Textures.secondaryHUDSheet[7], 175 - 12, 23 - 17, null); + + } else { + // DRAW MAIN + g2d.translate((int) (Game.game.getWidth() - SECONDARY_HUD_WIDTH - Game.game.getWidth() * 0.005), + (int) (Game.game.getHeight() - SECONDARY_HUD_HEIGHT - Game.game.getHeight() * 0.005)); + + if (tab == TAB.BACKPACK) g2d.drawImage(Textures.secondaryHUDSheet[0], 0, 0, null); + else if (tab == TAB.EQUIPMENT) g2d.drawImage(Textures.secondaryHUDSheet[44], 0, 0, null); + else g2d.drawImage(Textures.secondaryHUDSheet[0], 0, 0, null); //TODO: fix this for skills/magic + + // Render secondaryHUD tab icon boxes + for (InventorySlot i : Player.tabSlots) + i.render(g2d); + + // draw the four tab icons + g2d.drawImage(Textures.secondaryHUDSheet[4], 25, 23, null); + g2d.drawImage(Textures.secondaryHUDSheet[5], 75, 23, null); + g2d.drawImage(Textures.secondaryHUDSheet[6], 125, 23, null); + g2d.drawImage(Textures.secondaryHUDSheet[7], 175, 23, null); + + // EQUIPMENT: + if (tab == TAB.EQUIPMENT) { + for (InventorySlot i : Player.equipmentSlots) { + i.render(g2d); + } + + int adjustedColor = 240, red = 240; + if (Player.weight >= 20) { + if (Player.weight >= 140) red = 255; + adjustedColor = (int) (240 - (Player.weight - 20) * 2.15); + if (adjustedColor <= 0) adjustedColor = 0; + } + g2d.setColor(new Color(red, adjustedColor, adjustedColor)); + g2d.setFont(fonts.Gregorian10); + g2d.drawString(Integer.toString((int) Player.weight) + " kg", 200, 311); + } + + if (tab == TAB.BACKPACK) { + + } + } + } + + private static final void resetAllMouseClicked() { for (InventorySlot x : Player.tabSlots) x.mouseClicked = false; } + + public static final void cleanUp() { + Player.tabSlots = null; + Player.equipmentSlots = null; + } +} diff --git a/src/hud/constructionmenu/CONSTRUCTION_ITEMS.java b/src/hud/constructionmenu/CONSTRUCTION_ITEMS.java new file mode 100755 index 0000000..8331fec --- /dev/null +++ b/src/hud/constructionmenu/CONSTRUCTION_ITEMS.java @@ -0,0 +1,25 @@ +package hud.constructionmenu; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class CONSTRUCTION_ITEMS { + + + // NOTE YOU WILL NEED TO ADD YOUR NEW CONSTRUCTION ITEM HERE! + + //PARAMETERS: ConstructionItem(int menuCategory, int col, int row, int itemId, boolean unlocked, Cost... args) + + public static final void createItems(final ConstructionMenuCategory[] categories) { + + // TOOLS: + categories[0].items[0] = new ConstructionItem(0, 1, 1, 3, true, new Cost(7, 1), new Cost(6, 1), new Cost(1, 1)); // CRUDE + categories[0].items[1] = new ConstructionItem(0, 2, 1, 5, true, new Cost(7, 1), new Cost(6, 2), new Cost(1, 1)); // CRUDE PICKAXE + + // FIRE / LIGHTING: + categories[1].items[0] = new ConstructionItem(1, 1, 1, 10, true, new Cost(7, 2), new Cost(1, 2)); // FIRST TORCH + categories[1].items[1] = new ConstructionItem(1, 2, 1, 8, true, new Cost(4, 3), new Cost(1, 2)); // REG FIRE + + } +} diff --git a/src/hud/constructionmenu/ConstructionItem.java b/src/hud/constructionmenu/ConstructionItem.java new file mode 100755 index 0000000..cf366a2 --- /dev/null +++ b/src/hud/constructionmenu/ConstructionItem.java @@ -0,0 +1,98 @@ +package hud.constructionmenu; + +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; + +import javax.swing.JOptionPane; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import engine.MouseInput; +import hud.inventory.Inventory; +import player.MouseMovement; +import structures.Fire; +import utils.Point2f; +import world.Tile; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class ConstructionItem { + + public static boolean PLACING; + public static ConstructionItem TEMP; + + public int menuCategory, row, col, itemId; /* menuCat is numbered from 0-7 */ + public Cost[] price; + public boolean unlocked, hovered, selected; + public Rectangle bounds; + + public ConstructionItem(int menuCategory, int col, int row, int itemId, boolean unlocked, Cost... args){ + this.row = row; this.col = col; + this.itemId = itemId; this.unlocked = unlocked; + this.menuCategory = menuCategory; + this.bounds = new Rectangle(0, 0, ConstructionMenuCategory.MENUBOXWIDTH, ConstructionMenuCategory.MENUBOXHEIGHT); + this.price = new Cost[args.length]; + for (int i = 0; i < args.length; i++) this.price[i] = args[i]; + } public ConstructionItem(int menuCategory, int col, int row, int itemId, Cost... args){ new ConstructionItem(menuCategory, col, row, itemId, true, args); } + + public synchronized final void createItem(){ + if(!unlocked) return; + + for(int i = 0; i < price.length; i++) if(!Inventory.contains(price[i].itemId, price[i].quantity)) return; + + if(!calcIsStructure()){ + for(int i = 0; i < price.length; i++) Inventory.removeItem(price[i].itemId, price[i].quantity); + Inventory.addItem(itemId, 1, 100); + } else { TEMP = this; startStructureSequence(); } + + ConstructionMenu.changeSettings(); + } + + private synchronized final void startStructureSequence(){ + PLACING = Tile.drawHighLighted = true; + + //REMOVE ITEMS FOR COST + for(int i = 0; i < price.length; i++) Inventory.removeItem(price[i].itemId, price[i].quantity); + } + + private static Point POINT; + public synchronized final static void placeStructure(){ + POINT = Tile.pointToCheck; + + switch(TEMP.itemId){ + case 8: Handler.structures.add(new Fire(new Point2f(POINT.x, POINT.y))); break; + default: JOptionPane.showMessageDialog(null, "Problem with this structure... Yell at the developer"); + } + + PLACING = Tile.drawHighLighted = false; + Tile.resetAllHighlighted(); + } + + private static Point p; + public static final void render(Graphics2D g2d){ + if(!PLACING) return; + + if(MouseMovement.PLACING_STRUCTURE) p = Tile.pointToCheck; else p = MouseInput.adjustedMouseXY; + + AffineTransform transform = new AffineTransform(); Graphics2D copy = (Graphics2D) g2d.create(); + transform.rotate(-0.78539816 * (Game.rotation - 1), p.x, p.y); copy.transform(transform); + + switch(TEMP.itemId){ + case 8: copy.drawImage(Textures.structureSheet[0], p.x - Fire.WIDTH/2, p.y - Fire.HEIGHT /2 , null); + } + } + + + private final boolean calcIsStructure(){ + switch(itemId){ + case 8: return true; + + default: return false; + } + } +} diff --git a/src/hud/constructionmenu/ConstructionMenu.java b/src/hud/constructionmenu/ConstructionMenu.java new file mode 100755 index 0000000..296074b --- /dev/null +++ b/src/hud/constructionmenu/ConstructionMenu.java @@ -0,0 +1,62 @@ +package hud.constructionmenu; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Rectangle; + +import _texture.loader.Textures; +import engine.Game; +import engine.MouseInput; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class ConstructionMenu { + + public static final int WIDTH = 80, HEIGHT = 450, BOXWIDTH = 46, BOXHEIGHT = 45, MENUWIDTH = 140, MENUHEIGHT = 400; + public static int x, y; + public static boolean hidden; + public static Rectangle bounds = new Rectangle(0, 0, WIDTH, HEIGHT); + public static Rectangle hideBounds = new Rectangle(0, 0, MENUWIDTH + WIDTH, Game.game.getHeight()); + + public static final synchronized void init() {ConstructionMenuCategory.init();} + + public static final void tick() { + for (final ConstructionMenuCategory i : ConstructionMenuCategory.categories) i.tick(); + + if (hideBounds.contains(MouseInput.mouseXY)) { reveal(); if (x == 0) hidden = false; + } else { hide(); if (x == -WIDTH + 15) hidden = true; } + } + + public static final void render(Graphics2D g2d) { + g2d.drawImage(Textures.baseConstructionSheet[0], x, Game.game.getHeight() / 2 - HEIGHT / 2, null); + + for (final ConstructionMenuCategory cmg : ConstructionMenuCategory.categories) cmg.render(g2d); + + if (Game.drawInventoryBounds) { + g2d.setColor(Color.green); g2d.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); + g2d.setColor(Color.orange); g2d.drawRect(hideBounds.x, hideBounds.y, hideBounds.width, hideBounds.height); + } + } + + private static final void hide() { + if (x > -WIDTH + 15) x -= 3; if(x < -WIDTH + 15) x = -WIDTH + 15; + changeSettings(); + } + + private static final void reveal() { + if (x < 0) x += 5; if(x > 0) x = 0; + changeSettings(); + } + + public static final void changeSettings() { + y = Game.game.getHeight() / 2 - HEIGHT / 2; + ConstructionMenuCategory.changeSettings(); + bounds.x = x; bounds.y = y; + + hideBounds.height = Game.game.getHeight(); + hideBounds.width = MENUWIDTH + WIDTH; + hideBounds.x = hideBounds.y = 0; + } +} diff --git a/src/hud/constructionmenu/ConstructionMenuCategory.java b/src/hud/constructionmenu/ConstructionMenuCategory.java new file mode 100755 index 0000000..24a16bb --- /dev/null +++ b/src/hud/constructionmenu/ConstructionMenuCategory.java @@ -0,0 +1,187 @@ +package hud.constructionmenu; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Rectangle; + +import _texture.loader.Textures; +import engine.Game; +import engine.MouseInput; +import interfaces.Colors; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class ConstructionMenuCategory implements Colors{ + + public static final int MENUWIDTH = 140, MENUHEIGHT = 386, MENUBOXWIDTH = 40, MENUBOXHEIGHT = 40; + + public static ConstructionMenuCategory[] categories; + public ConstructionItem[] items; + public int x, y; + public static int width = 46, height = 45; + public boolean hovered, selected, unlocked; + public Rectangle bounds = new Rectangle(0, 0, 46, 45); + public static final Rectangle menuBounds = new Rectangle(0, 0, MENUWIDTH, MENUHEIGHT); + + public ConstructionMenuCategory(){ items = new ConstructionItem[27]; } + + public static synchronized final void init(){ + categories = new ConstructionMenuCategory[8]; + categories[0] = new ConstructionMenuCategory(); + categories[1] = new ConstructionMenuCategory(); + categories[2] = new ConstructionMenuCategory(); + categories[3] = new ConstructionMenuCategory(); + categories[4] = new ConstructionMenuCategory(); + categories[5] = new ConstructionMenuCategory(); + categories[6] = new ConstructionMenuCategory(); + categories[7] = new ConstructionMenuCategory(); + categories[0].unlocked = true; + categories[1].unlocked = true; + changeSettings(); + + CONSTRUCTION_ITEMS.createItems(categories); + } + + public static final void changeSettings(){ + for(int i = 0; i < categories.length; i++){ + categories[i].x = ConstructionMenu.x + 15; + categories[i].y = ConstructionMenu.y + (height * i) + 5*i + 22; + categories[i].bounds.x = categories[i].x; + categories[i].bounds.y = categories[i].y; + } + categories[7].y = ConstructionMenu.y + 354 + 22; /* last one is off a bit */ + categories[7].bounds.x = categories[7].x; categories[7].bounds.y = categories[7].y; + + + try{ + for(final ConstructionMenuCategory cmg : categories){ + for(int i = 0, count = 0; i < 9; i++) + for(int j = 0; j < 3; j++, count++){ + try{ + if(cmg.selected){ + cmg.items[count].bounds.x = ConstructionMenu.x + ConstructionMenu.WIDTH + MENUBOXWIDTH * j; + cmg.items[count].bounds.y = ConstructionMenu.y + 34 + MENUBOXHEIGHT * i; + } else { + cmg.items[count].bounds.x = -100; /* if not selected make their bounds not clickable */ + cmg.items[count].bounds.y = -100; // " " + } + } catch (NullPointerException npe){} + }} + } catch(ArrayIndexOutOfBoundsException asdf){asdf.printStackTrace();} + + + menuBounds.x = ConstructionMenu.x + ConstructionMenu.WIDTH - 10; + menuBounds.y = ConstructionMenu.y + 20; + } + + public final void tick(){ + if(ConstructionMenu.hidden) return; + + if(!selected) return; else if(!ConstructionMenu.hideBounds.contains(MouseInput.mouseXY)) selected = false; + } + + public final static void onClick(){ + if(!ConstructionMenu.hideBounds.contains(MouseInput.clickPos) || ConstructionMenu.hidden) return; + for(final ConstructionMenuCategory i : categories) if(i.bounds.contains(MouseInput.clickPos) && i.unlocked) i.selected = true; else i.selected = false; + + if(menuBounds.contains(MouseInput.clickPos)) + for(ConstructionMenuCategory cmg : categories) + for(ConstructionItem ci : cmg.items) + try{ if(ci.bounds.contains(MouseInput.clickPos)){ ci.createItem(); return; } + } catch (NullPointerException npe){} + + + } + + public final void render(final Graphics2D g2d){ + if(!unlocked){ + g2d.drawImage(Textures.baseConstructionSheet[3], x, y, null); + g2d.drawImage(Textures.baseConstructionSheet[4], x, y, null); + if(calcIcon() != 0) g2d.drawImage(Textures.baseConstructionSheet[calcIcon()], x, y, null); + g2d.setColor(construction_menu_darken); + g2d.fillRect(x, y, ConstructionMenu.BOXWIDTH, ConstructionMenu.BOXHEIGHT); + } else { + if(selected) g2d.drawImage(Textures.baseConstructionSheet[3], x, y, null); + else if(bounds.contains(MouseInput.mouseXY)) g2d.drawImage(Textures.baseConstructionSheet[2], x, y, null); + else g2d.drawImage(Textures.baseConstructionSheet[1], x, y, null); + if(calcIcon() != 0) g2d.drawImage(Textures.baseConstructionSheet[calcIcon()], x, y, null); + } + if(Game.drawInventoryBounds){ g2d.setColor(Color.pink); g2d.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); } + + + if(!selected) return; + + g2d.drawImage(Textures.baseConstructionSheet[13], ConstructionMenu.x + ConstructionMenu.WIDTH - 10, ConstructionMenu.y + 20, null); + + int count = 0; + for(int i = 0; i < 9; i++) + for(int j = 0; j < 3; j++, count++){ + try{ + if(items[count].bounds.contains(MouseInput.mouseXY)) g2d.drawImage(Textures.baseConstructionSheet[15], ConstructionMenu.x + ConstructionMenu.WIDTH + MENUBOXWIDTH * j, ConstructionMenu.y + 34 + MENUBOXHEIGHT * i, null); + else g2d.drawImage(Textures.baseConstructionSheet[14], ConstructionMenu.x + ConstructionMenu.WIDTH + MENUBOXWIDTH * j, ConstructionMenu.y + 34 + MENUBOXHEIGHT * i, null); + } catch (Exception e){ + g2d.drawImage(Textures.baseConstructionSheet[14], ConstructionMenu.x + ConstructionMenu.WIDTH + MENUBOXWIDTH * j, ConstructionMenu.y + 34 + MENUBOXHEIGHT * i, null); + g2d.drawImage(Textures.baseConstructionSheet[4], ConstructionMenu.x + ConstructionMenu.WIDTH + MENUBOXWIDTH * j, ConstructionMenu.y + 34 + MENUBOXHEIGHT * i, null); + g2d.setColor(construction_menu_darken125); + g2d.fillRect(ConstructionMenu.x + ConstructionMenu.WIDTH + MENUBOXWIDTH * j, ConstructionMenu.y + 34 + MENUBOXHEIGHT * i, MENUBOXWIDTH, MENUBOXHEIGHT); + } + } + + if(this == categories[0]) renderTools(g2d); + else if(this == categories[1]) renderFire(g2d); + + + if(Game.drawInventoryBounds) drawInvenBounds(g2d); + + ConstructionMenuHover.render(g2d); + } + + private final void renderTools(final Graphics2D g2d){ + g2d.drawImage(Utils.reverseImage(Textures.itemIconSheet[2]).getScaledInstance(MENUBOXWIDTH, MENUBOXHEIGHT, 2), 80, y + 12, null); // CRUDE AXE + g2d.drawImage(Utils.reverseImage(Textures.itemIconSheet[4]).getScaledInstance(MENUBOXWIDTH, MENUBOXHEIGHT, 2), 80 + MENUBOXWIDTH, y + 11, null); // CRUDE PICKAXE + + int count = 0; ConstructionMenuHover.render = false; + for(int i = 0; i < 9; i++) + for(int j = 0; j < 3; j++, count++) + try{if(categories[0].items[count].bounds.contains(MouseInput.mouseXY)){ ConstructionMenuHover.item = categories[0].items[count]; ConstructionMenuHover.render = true; } + } catch (Exception e){} + } + + + private final void renderFire(final Graphics2D g2d){ + g2d.drawImage(Utils.reverseImage(Textures.itemIconSheet[9]).getScaledInstance((int)(MENUBOXWIDTH * 1.3), (int)(MENUBOXHEIGHT * 1.3), 2), 73, y - 43, null); // regular fire + g2d.drawImage(Utils.reverseImage(Textures.baseConstructionSheet[6]).getScaledInstance(MENUBOXWIDTH, MENUBOXHEIGHT, 2), 81 + MENUBOXWIDTH, y - 38, null); // regular fire + + int count = 0; ConstructionMenuHover.render = false; + for(int i = 0; i < 9; i++) + for(int j = 0; j < 3; j++, count++) + try{if(categories[1].items[count].bounds.contains(MouseInput.mouseXY)){ ConstructionMenuHover.item = categories[1].items[count]; ConstructionMenuHover.render = true; } + } catch (Exception e){} + } + + private final void drawInvenBounds(final Graphics2D g2d){ + g2d.setColor(Color.red); g2d.drawRect(menuBounds.x, menuBounds.y, menuBounds.width, menuBounds.height); + + int temp = 0; g2d.setColor(Color.cyan); + for(int i = 0; i < 9; i++) + for(int j = 0; j < 3; j++, temp++) + try{ g2d.drawRect(items[temp].bounds.x, items[temp].bounds.y, items[temp].bounds.width, items[temp].bounds.height); } + catch (Exception e) {} + } + + private final int calcIcon(){ + if(this == categories[0]) return 5; + else if(this == categories[1]) return 6; +// else if(this == categories[2]) return 7; +// else if(this == categories[3]) return 8; +// else if(this == categories[4]) return 9; +// else if(this == categories[5]) return 10; +// else if(this == categories[6]) return 11; +// else if(this == categories[7]) return 12; + + return 0; + } +} diff --git a/src/hud/constructionmenu/ConstructionMenuHover.java b/src/hud/constructionmenu/ConstructionMenuHover.java new file mode 100755 index 0000000..e94709c --- /dev/null +++ b/src/hud/constructionmenu/ConstructionMenuHover.java @@ -0,0 +1,163 @@ +package hud.constructionmenu; + +import java.awt.Color; +import java.awt.Graphics2D; + +import javax.swing.JOptionPane; + +import _texture.loader.Textures; +import engine.MouseInput; +import fonts.fonts; +import hud.inventory.Inventory; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class ConstructionMenuHover { + + public static final String[] lines = Utils.makeStringArrayFromLinesOfTextFile("/itemTextsCapitalized.nihil"); + + public static ConstructionItem item; + public static boolean render; + + public static final void render(final Graphics2D g2d){ + if(!render) return; + + g2d.setColor(Color.gray); + g2d.fillRect(MouseInput.mouseXY.x, MouseInput.mouseXY.y, 150, 150); + + g2d.setColor(Color.darkGray); + g2d.fillRect(MouseInput.mouseXY.x + 5, MouseInput.mouseXY.y + 5, 140, 140); + + g2d.setColor(Color.black); + g2d.fillRect(MouseInput.mouseXY.x + 11, MouseInput.mouseXY.y + 32, 70, 70); + + g2d.setColor(Color.lightGray); + g2d.fillRect(MouseInput.mouseXY.x + 13, MouseInput.mouseXY.y + 34, 65, 65); + + try{ g2d.drawImage(Utils.reverseImage(Textures.itemIconSheet[item.itemId - 1]).getScaledInstance(80, 65, 1), MouseInput.mouseXY.x + 5, MouseInput.mouseXY.y + 33, null); + } catch (Exception e){ secondaryRender(g2d); } + + g2d.setFont(fonts.Gregorian20); + g2d.setColor(Color.white); + + g2d.drawString(lines[item.itemId - 1], MouseInput.mouseXY.x + 8, MouseInput.mouseXY.y + 23); + + flavorText(g2d); + reqMaterials(g2d); + } + + private static final void reqMaterials(final Graphics2D g2d){ + switch(item.price.length){ /* get the number of different items req */ + case 1: { + g2d.setColor(Color.lightGray); + g2d.fillRect(MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 108, 32, 32); + g2d.setColor(Color.black); + g2d.fillRect(MouseInput.mouseXY.x + 59, MouseInput.mouseXY.y + 110, 28, 28); + + g2d.drawImage(Textures.itemIconSheet[item.price[0].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 107, null); + + g2d.setFont(fonts.Gregorian20); + + if(Inventory.contains(item.price[0].itemId, item.price[0].quantity)) + g2d.setColor(Color.white); else g2d.setColor(Color.red); + g2d.drawString("x" + item.price[0].quantity+"", MouseInput.mouseXY.x + 30, MouseInput.mouseXY.y + 136); + break; + } + + case 2: { + g2d.setColor(Color.lightGray); + g2d.fillRect(MouseInput.mouseXY.x + 15, MouseInput.mouseXY.y + 108, 32, 32); + g2d.fillRect(MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 108, 32, 32); + g2d.setColor(Color.black); + g2d.fillRect(MouseInput.mouseXY.x + 17, MouseInput.mouseXY.y + 110, 28, 28); + g2d.fillRect(MouseInput.mouseXY.x + 59, MouseInput.mouseXY.y + 110, 28, 28); + + g2d.drawImage(Textures.itemIconSheet[item.price[0].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 15, MouseInput.mouseXY.y + 107, null); + g2d.drawImage(Textures.itemIconSheet[item.price[1].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 107, null); + + g2d.setFont(fonts.Gregorian20); + + if(Inventory.contains(item.price[0].itemId, item.price[0].quantity)) + g2d.setColor(Color.white); else g2d.setColor(Color.red); + g2d.drawString("x" + item.price[0].quantity+"", MouseInput.mouseXY.x + 30, MouseInput.mouseXY.y + 136); + if(Inventory.contains(item.price[1].itemId, item.price[1].quantity)) + g2d.setColor(Color.white); else g2d.setColor(Color.red); + g2d.drawString("x" + item.price[1].quantity+"", MouseInput.mouseXY.x + 72, MouseInput.mouseXY.y + 136); + break; + } + + case 3: { + g2d.setColor(Color.lightGray); + g2d.fillRect(MouseInput.mouseXY.x + 15, MouseInput.mouseXY.y + 108, 32, 32); + g2d.fillRect(MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 108, 32, 32); + g2d.fillRect(MouseInput.mouseXY.x + 100, MouseInput.mouseXY.y + 108, 32, 32); + g2d.setColor(Color.black); + g2d.fillRect(MouseInput.mouseXY.x + 17, MouseInput.mouseXY.y + 110, 28, 28); + g2d.fillRect(MouseInput.mouseXY.x + 59, MouseInput.mouseXY.y + 110, 28, 28); + g2d.fillRect(MouseInput.mouseXY.x + 102, MouseInput.mouseXY.y + 110, 28, 28); + + g2d.drawImage(Textures.itemIconSheet[item.price[0].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 15, MouseInput.mouseXY.y + 107, null); + g2d.drawImage(Textures.itemIconSheet[item.price[1].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 57, MouseInput.mouseXY.y + 107, null); + g2d.drawImage(Textures.itemIconSheet[item.price[2].itemId - 1].getScaledInstance(32, 32, 3), MouseInput.mouseXY.x + 100, MouseInput.mouseXY.y + 107, null); + + g2d.setFont(fonts.Gregorian20); + + if(Inventory.contains(item.price[0].itemId, item.price[0].quantity)) + g2d.setColor(Color.white); else g2d.setColor(Color.red); + g2d.drawString("x" + item.price[0].quantity+"", MouseInput.mouseXY.x + 30, MouseInput.mouseXY.y + 136); + if(Inventory.contains(item.price[1].itemId, item.price[1].quantity)) + g2d.setColor(Color.white); else g2d.setColor(Color.red); + g2d.drawString("x" + item.price[1].quantity+"", MouseInput.mouseXY.x + 72, MouseInput.mouseXY.y + 136); + if(Inventory.contains(item.price[2].itemId, item.price[2].quantity)) + g2d.setColor(Color.white); else g2d.setColor(Color.red); + g2d.drawString("x" + item.price[2].quantity+"", MouseInput.mouseXY.x + 115, MouseInput.mouseXY.y + 136); + break; + } + + case 4: { + g2d.setColor(Color.blue); + g2d.fillRect(MouseInput.mouseXY.x, MouseInput.mouseXY.y, 100, 100); + break; + } + default: { JOptionPane.showMessageDialog(null, "There is a problem with this item."); } + } + } + + private static final int X = 83, row1 = 75, row2 = 85, row3 = 95; + private static final void flavorText(final Graphics2D g2d){ + g2d.setColor(Color.white); + g2d.setFont(fonts.ponderosa8); + + switch(item.itemId){ + case 3: { + g2d.drawString("It chops", MouseInput.mouseXY.x + X, MouseInput.mouseXY.y + row1); + g2d.drawString("things.", MouseInput.mouseXY.x + X, MouseInput.mouseXY.y + row2); + g2d.drawString("... kinda", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row3); break; + } + case 5: { + g2d.drawString("Break", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row1); + g2d.drawString("rock with", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row2); + g2d.drawString("rock.", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row3); break; + } + case 8: { + g2d.drawString("Nice,", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row1); + g2d.drawString("safe, ", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row2); + g2d.drawString("and warm.", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row3); break; + } + case 10: { + g2d.drawString("For", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row1); + g2d.drawString("burning", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row2); + g2d.drawString("things.", MouseInput.mouseXY.x + 82, MouseInput.mouseXY.y + row3); + } + } + } + + private static final void secondaryRender(final Graphics2D g2d){ + switch(item.itemId){ + case 8: g2d.drawImage(Utils.reverseImage(Textures.baseConstructionSheet[6]).getScaledInstance(80, 65, 1), MouseInput.mouseXY.x + 7, MouseInput.mouseXY.y + 35, null); + } + } +} diff --git a/src/hud/constructionmenu/Cost.java b/src/hud/constructionmenu/Cost.java new file mode 100755 index 0000000..122117a --- /dev/null +++ b/src/hud/constructionmenu/Cost.java @@ -0,0 +1,13 @@ +package hud.constructionmenu; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class Cost { + + public final int itemId, quantity; + + public Cost(int itemId, int quantity){ this.itemId = itemId; this.quantity = quantity; } + +} diff --git a/src/hud/inventory/Backpack.java b/src/hud/inventory/Backpack.java new file mode 100755 index 0000000..7b716cd --- /dev/null +++ b/src/hud/inventory/Backpack.java @@ -0,0 +1,33 @@ +package hud.inventory; + +import java.awt.Graphics2D; + +import utils.Stack; + +public class Backpack { + + private static final int boxWidth = 40, boxHeight = 40; + public static volatile Stack backpacks = new Stack(); + public volatile InventorySlot[] slots; + public boolean equipped; + public int id; + private static int count; + + public Backpack(int numSlots) { + slots = new InventorySlot[numSlots]; + for (Backpack i : backpacks) + i.equipped = false; + this.equipped = true; + this.id = count++; + backpacks.add(this); + } + + public void tick() { + + } + + public void render(Graphics2D g2d) { + + } + +} diff --git a/src/hud/inventory/InvenHelper.java b/src/hud/inventory/InvenHelper.java new file mode 100755 index 0000000..7d3929c --- /dev/null +++ b/src/hud/inventory/InvenHelper.java @@ -0,0 +1,133 @@ +package hud.inventory; + +import interfaces.ItemIDs; +import player.Player; +import utils.Utils; +import world.DroppedItem; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class InvenHelper implements ItemIDs{ + + private static float tempWeight; + public static final void calcWeight() { + tempWeight = 0; + for (final InventorySlot i : Player.inventorySlots) if (i.itemId != NULL_ITEM) computeWeightOfItemSlot(i); + for (final InventorySlot i : Player.equipmentSlots) if (i.itemId != NULL_ITEM) computeWeightOfItemSlot(i); + Player.weight = tempWeight; + } + + private static final void computeWeightOfItemSlot(final InventorySlot i) { + switch (i.itemId) { + case PICKED_GRASS: tempWeight += 0.1f * i.quantity; break; + case PICKED_FLOWERS: tempWeight += 0.075f * i.quantity; break; + case CRUDE_AXE: tempWeight += 1.35f * i.quantity; break; + case LOGS: tempWeight += 1.15f * i.quantity; break; + case CRUDE_PICKAXE: tempWeight += 1.5f * i.quantity; break; + case ROCKS: tempWeight += 0.95f * i.quantity; break; + case STICKS: tempWeight += 0.3f * i.quantity; break; + case ASHES: tempWeight += 0.1f * i.quantity; break; + case TORCH: tempWeight += 1f * i.quantity; break; + case RABBIT_CARCASS: tempWeight += 1.8f * i.quantity; break; + case RABBIT_FOOT: tempWeight += 0f * i.quantity; break; + case ROT: tempWeight += 0.05f * i.quantity; break; + case BONES: tempWeight += 0.5f * i.quantity; break; + case GOBLIN_SPEAR: tempWeight += 2.1f * i.quantity; break; + + default: System.out.println("YO YOU NEED TO COMPUTE WEIGHT OF YOUR NEW ITEM!"); System.exit(0); + } + } + + public final static boolean isStackable(final int itemId) { + switch(itemId) { + case PICKED_GRASS: return true; + case PICKED_FLOWERS: return true; + case LOGS: return true; + case ROCKS: return true; + case STICKS: return true; + case ASHES: return true; + case RABBIT_FOOT: return true; + case ROT: return true; + case BONES: return true; + + default: return false; + } + } + + public final static boolean isEquippable(final int itemId) { + switch(itemId){ + case CRUDE_AXE: return true; + case CRUDE_PICKAXE: return true; + case TORCH: return true; + case GOBLIN_SPEAR: return true; + + default: return false; + } + } + + public final static boolean hasWeapon() { + switch(Player.equipmentSlots[HAND_SLOT].itemId) { + case CRUDE_AXE: return true; + case CRUDE_PICKAXE: return true; + case GOBLIN_SPEAR: return true; + default: return false; + } + } + + public final static int calcEquipSlot(final int itemId) { + switch(itemId){ + case CRUDE_AXE: return HAND_SLOT; + case CRUDE_PICKAXE: return HAND_SLOT; + case TORCH: return HAND_SLOT; + case GOBLIN_SPEAR: return HAND_SLOT; + default: { System.out.println("YO CALC EQUIP SLOT IS BROKEN"); return -1; } + } + } + + public static final int getStackableAmount(final int itemId) { + switch(itemId) { + case PICKED_GRASS: return 40; + case PICKED_FLOWERS: return 40; + case LOGS: return 20; + case ROCKS: return 30; + case STICKS: return 40; + case ASHES: return 40; + case ROT: return 40; + case BONES: return 40; + + default: return Utils._2147483647; + } + } + + public final static boolean isAxe(final int itemId){ + switch(itemId){ + case CRUDE_AXE: return true; + + default: return false; + } + } + + public final static boolean isPickaxe(final int itemId){ + switch(itemId){ + case CRUDE_PICKAXE: return true; + + default: return false; + } + } + + + public static synchronized final void DROP_ALL_INVENTORY() { + for(final InventorySlot i : Player.inventorySlots) { + if(i.itemId == NULL_ITEM) continue; + DroppedItem.dropItemsWithOffsetAsStack(i.itemId, i.quantity, 100, Player.center.x, Player.center.y, i.durability); + i.itemId = NULL_ITEM; + i.quantity = 0; + i.durability = 100; + i.mouseClicked = false; + i.equippable = false; + } + } + +} diff --git a/src/hud/inventory/Inventory.java b/src/hud/inventory/Inventory.java new file mode 100755 index 0000000..f5e9aee --- /dev/null +++ b/src/hud/inventory/Inventory.java @@ -0,0 +1,209 @@ +package hud.inventory; + +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; + +import org.python.core.PyFloat; +import org.python.core.PyFunction; +import org.python.core.PyInteger; + +import _texture.loader.Textures; +import engine.Game; +import engine.MouseInput; +import hud.SecondaryHUD; +import interfaces.ItemIDs; +import interfaces.Python; +import player.Player; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class Inventory implements ItemIDs, Python { + + public static final int INVENTORY_WIDTH = 750, INVENTORY_HEIGHT = 110, SLOT_WIDTH = 84, SLOT_HEIGHT = 78; + public static final Rectangle INVENTORY_BOUNDS = new Rectangle(0, 0, INVENTORY_WIDTH, INVENTORY_HEIGHT); + + public static final void init() { + Player.inventorySlots = new InventorySlot[8]; + Player.inventorySlots[0] = (new InventorySlot(1, 0, 0, new Point(37, 22), new Rectangle(0, 0, SLOT_WIDTH, SLOT_HEIGHT))); + Player.inventorySlots[1] = (new InventorySlot(2, 0, 0, new Point(120, 22), new Rectangle(0, 0, SLOT_WIDTH, SLOT_HEIGHT))); + Player.inventorySlots[2] = (new InventorySlot(3, 0, 0, new Point(205, 22), new Rectangle(0, 0, SLOT_WIDTH, SLOT_HEIGHT))); + Player.inventorySlots[3] = (new InventorySlot(4, 0, 0, new Point(288, 22), new Rectangle(0, 0, SLOT_WIDTH, SLOT_HEIGHT))); + Player.inventorySlots[4] = (new InventorySlot(5, 0, 0, new Point(370, 22), new Rectangle(0, 0, SLOT_WIDTH, SLOT_HEIGHT))); + Player.inventorySlots[5] = (new InventorySlot(6, 0, 0, new Point(454, 22), new Rectangle(0, 0, SLOT_WIDTH, SLOT_HEIGHT))); + Player.inventorySlots[6] = (new InventorySlot(7, 0, 0, new Point(538, 22), new Rectangle(0, 0, SLOT_WIDTH, SLOT_HEIGHT))); + Player.inventorySlots[7] = (new InventorySlot(8, 0, 0, new Point(626, 22), new Rectangle(0, 0, SLOT_WIDTH, SLOT_HEIGHT))); + initJythonScripts(); + } + + +/**************** ON CLICK *****************************************************************************************/ + public synchronized static final void onLeftClick() { + SecondaryHUD.onLeftClick(); + + // SLOT SWAPPING! + /** @param i: The slot you are currently holding + * @param e: The slot you are trying to click on */ + for (final InventorySlot i : Player.inventorySlots) { + // IF THE SLOT ISN'T CLICKED OR IS EMPTY DON'T BOTHER + if (i.itemId == NULL_ITEM || !i.mouseClicked) continue; + for (final InventorySlot e : Player.inventorySlots) { + // IF THE SECOND SLOT CONTAINS THE MOUSE POINTER, AND THE TWO SLOTS AREN'T THE SAME, SWAP! + if (e.bounds.contains(MouseInput.mouseXY)) { + final int tempId = i.itemId; + final int tempQ = i.quantity; + final boolean tempEquippable = i.equippable; + final float tempDurability = i.durability; + i.itemId = e.itemId; + i.quantity = e.quantity; + i.equippable = e.equippable; + i.durability = e.durability; + e.itemId = tempId; + e.quantity = tempQ; + e.equippable = tempEquippable; + e.durability = tempDurability; + e.mouseClicked = false; + if(e.itemId == NULL_ITEM) resetMouseClicked(); + changeSettings(); + return; // NOTE: YOU MUST RETURN HERE OR IT WONT WORK! + } + } + } + + // GRAPHICAL SLOT MOVING! + for (final InventorySlot i : Player.inventorySlots) { if(i.itemId == NULL_ITEM) continue; + // SET MOUSELCICKED TO TRUE + if (i.bounds.contains(MouseInput.mouseXY)) { + resetMouseClicked(); // ONLY WANT 1 ITEM TO BE MOUSE CLICKED AT A TIME + i.mouseClicked = true; + break; + } + // IF HOLDING AN ITEM, AND CLICK OUTSIDE OF THE INVENTORY BOUNDS --- DROP + else if (i.mouseClicked && !INVENTORY_BOUNDS.contains(MouseInput.mouseXY)) { + dropItem(i.itemId, i.quantity, i.durability, i.slotNumber); + i.mouseClicked = false; + break; + } + // ELSE IF YOU JUST CLICKED SOMEWHERE IN THE INVEN WITHOUT ON A SLOT LIKE AN IDIOT + else { + i.mouseClicked = false; + i.pos.x = 37 + (SLOT_WIDTH * (i.slotNumber - 1)); i.pos.y = 22; + } + } + + // FIXES BUGS -- ALWAYS RUN THIS + changeSettings(); + } +/*************** END ON CLICK *****************************************************************************************/ + +/************************************** TICK AND RENDER ***************************************************************************************************/ + private static int weightTimer; private static final int WEIGHT_TIMER_AMOUNT = 12; + public final static void tick() { + for (final InventorySlot i : Player.inventorySlots) + if (i.mouseClicked) { i.pos.x = MouseInput.mouseXY.x - SLOT_WIDTH/2; i.pos.y = MouseInput.mouseXY.y - SLOT_HEIGHT/2; } + + if (--weightTimer <= 0) { + InvenHelper.calcWeight(); weightTimer = WEIGHT_TIMER_AMOUNT; + /* REMOVE ITEMS WHEN DURABILITY GOES BELOW OR EQUALS ZERO */ + for (final InventorySlot i : Player.inventorySlots) if (i.itemId != NULL_ITEM && i.durability <= 0) removeItem(i.itemId, i.quantity, i.slotNumber); + for (final InventorySlot i : Player.equipmentSlots) if (i.itemId != NULL_ITEM && i.durability <= 0) removeEquipment(i.itemId, i.quantity, i.slotNumber); + } + } + + private static InventorySlot tempSlot; private static int render_count = 3; /** @param render_count: no fucking idea why its 3, wrote this ages ago */ + public final static void render(final Graphics2D g2dCopy, final Graphics2D slotRenderer) { + try { // draw base inventory / highlights if mouse hovered + for (final InventorySlot i : Player.inventorySlots) { + g2dCopy.drawImage(Textures.hudSheet[0], 0, 0, null); // BASE; + if (i.bounds.contains(MouseInput.mouseXY)) { + g2dCopy.drawImage(Textures.hudSheet[render_count], 0, 0, null); // highlighted + break; + } render_count++; + } + + //NOTE:: quantities / etc are drawn in invenslot.render() + + // Render Player.inventorySlots + for (final InventorySlot i : Player.inventorySlots) + if (!i.mouseClicked) i.render(g2dCopy); else tempSlot = i; + + + if (tempSlot != null) tempSlot.render(slotRenderer); + + render_count = 3; /* reset counter */ + tempSlot = null; + } catch (Exception e) { e.printStackTrace(); } + } + +/************************************** END TICK AND RENDER *****************************************************************************************************/ + +/********************************* ADDING AND REMOVING ITEMS ****************************************************************************************************/ + public final synchronized static void dropItem(final int itemId, final int quantity, final float durability, final int slotNumber) { + drop_item.__call__(new PyInteger(itemId), new PyInteger(quantity), new PyFloat(durability), new PyInteger(slotNumber)); + } + + public final synchronized static void addItem(final int itemId, final int quantity, final float durability) { + add_item.__call__(new PyInteger(itemId), new PyInteger(quantity), new PyFloat(durability)); + } public final synchronized static void addItem(final int itemId, final int quantity) { addItem(itemId, quantity, 100); } + public final synchronized static void addItem(final int itemId) { addItem(itemId, 1, 100); } + + public final synchronized static void removeItem(final int itemId, final int quantity, final int slotNumber) { + remove_item_with_slot_number.__call__(new PyInteger(itemId), new PyInteger(quantity), new PyInteger(slotNumber)); + } + public final synchronized static void removeItem(int itemId, int quantity) { + remove_item.__call__(new PyInteger(itemId), new PyInteger(quantity)); + } + + public final synchronized static void removeEquipment(final int itemId, final int quantity, final int slotNumber) { + remove_equipment.__call__(new PyInteger(itemId), new PyInteger(quantity), new PyInteger(slotNumber)); + } +/********************************** END ADDING AND REMOVING ITEMS *********************************************************************************************************/ + +/**************************************** MISC ******************************************************************************************************************/ + public final static void changeSettings() { + INVENTORY_BOUNDS.x = (int)(Game.game.getWidth() * 0.5f - INVENTORY_WIDTH * 0.5f); + INVENTORY_BOUNDS.y = Game.game.getHeight() - INVENTORY_HEIGHT; + + for (final InventorySlot i : Player.inventorySlots) { + if(!i.mouseClicked) { + i.pos.x = 37 + (SLOT_WIDTH * (i.slotNumber - 1)); i.pos.y = 22; + i.bounds.x = i.pos.x + Game.game.getWidth() / 2 - INVENTORY_WIDTH / 2; + i.bounds.y = Game.game.getHeight() - i.pos.y - SLOT_HEIGHT; + } + if(i.itemId == NULL_ITEM) i.mouseClicked = false; + } + + SecondaryHUD.changeSettings(); + } + + public final static boolean isFull(final int itemId, final int quantity) { + return isFull.__call__(new PyInteger(itemId), new PyInteger(quantity)).asInt() == 1; + } + public final static boolean contains(final int itemId, final int quantity) { + return contains.__call__(new PyInteger(itemId), new PyInteger(quantity)).asInt() == 1; + } + + public final static void resetMouseClicked() { for (final InventorySlot i : Player.inventorySlots) i.mouseClicked = false; } + + /*************** JYTHON STUFF ***********************************************************************************/ + private static PyFunction add_item, remove_item, remove_item_with_slot_number, remove_equipment, drop_item, contains, isFull; + private static final void initJythonScripts() { + add_item = pi.get("add_item", PyFunction.class); + remove_item = pi.get("remove_item", PyFunction.class); + remove_item_with_slot_number = pi.get("remove_item_with_slot_number", PyFunction.class); + remove_equipment = pi.get("remove_equipment", PyFunction.class); + drop_item = pi.get("drop_item", PyFunction.class); + contains = pi.get("inventory_contains", PyFunction.class); + isFull = pi.get("inventory_is_full", PyFunction.class); + } + /************* END JYTHON STUFF ***********************************************************************************/ + + public final synchronized static void cleanUp() { + Player.inventorySlots = null; tempSlot = null; + add_item = remove_item = remove_item_with_slot_number = remove_equipment = drop_item = contains = isFull = null; + } +/******************************************* END MISC *********************************************************************************************************/ + +} diff --git a/src/hud/inventory/InventorySlot.java b/src/hud/inventory/InventorySlot.java new file mode 100755 index 0000000..f8d7238 --- /dev/null +++ b/src/hud/inventory/InventorySlot.java @@ -0,0 +1,184 @@ +package hud.inventory; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Point; +import java.awt.Rectangle; + +import _texture.loader.Textures; +import engine.MouseInput; +import fonts.fonts; +import hud.SecondaryHUD; +import hud.SecondaryHUD.TAB; +import interfaces.Colors; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class InventorySlot implements Colors { + + public Point pos; + public Rectangle bounds; + public boolean mouseClicked, equippable; + public int itemId, quantity, slotNumber, equipSlot, TYPE; + public float durability; + + public InventorySlot(int slotNumber, int itemId, int quantity, Point pos, Rectangle bounds) { + this.pos = pos; + this.bounds = bounds; + this.itemId = itemId; + this.quantity = quantity; + this.mouseClicked = false; + this.slotNumber = slotNumber; + } + + // tab icon slots for secondaryHUD + public InventorySlot(int slotNumber, int TYPE, Point pos, Rectangle bounds) { + this.pos = pos; + this.bounds = bounds; + this.slotNumber = slotNumber; + this.TYPE = TYPE; + } + + public void render(Graphics2D g2d) { + try { + if (TYPE == -1) { + if (slotNumber == 5) return; + + // TAB SLOTS + if (slotNumber == 1 && SecondaryHUD.tab == TAB.BACKPACK) { + g2d.drawImage(Textures.secondaryHUDSheet[3], pos.x, pos.y, null); + return; + } else if (slotNumber == 2 && SecondaryHUD.tab == TAB.EQUIPMENT) { + g2d.drawImage(Textures.secondaryHUDSheet[3], pos.x, pos.y, null); + return; + } else if (slotNumber == 3 && SecondaryHUD.tab == TAB.SKILLS) { + g2d.drawImage(Textures.secondaryHUDSheet[3], pos.x, pos.y, null); + return; + } else if (slotNumber == 4 && SecondaryHUD.tab == TAB.MAGIC) { + g2d.drawImage(Textures.secondaryHUDSheet[3], pos.x, pos.y, null); + return; + } + + // EQUIPMENT SLOTS --- BASE BOXES + if (bounds.contains(MouseInput.mouseXY)) g2d.drawImage(Textures.secondaryHUDSheet[2], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[1], pos.x, pos.y, null); + } else if (TYPE == -3) { // EQUIPMENT + + if (slotNumber == 1) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[11], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[12], pos.x, pos.y, null); + } else if (slotNumber == 2) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[13], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[14], pos.x, pos.y, null); + } else if (slotNumber == 3) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[15], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[16], pos.x, pos.y, null); + } else if (slotNumber == 4) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[17], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[18], pos.x, pos.y, null); + } else if (slotNumber == 5) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[19], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[20], pos.x, pos.y, null); + } else if (slotNumber == 6) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[21], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[22], pos.x, pos.y, null); + } else if (slotNumber == 7) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[23], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[24], pos.x, pos.y, null); + } else if (slotNumber == 8) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[25], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[26], pos.x, pos.y, null); + } else if (slotNumber == 9) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[27], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[28], pos.x, pos.y, null); + } else if (slotNumber == 10) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[29], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[30], pos.x, pos.y, null); + } else if (slotNumber == 11) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[31], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[32], pos.x, pos.y, null); + } else if (slotNumber == 12) { + if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[33], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[34], pos.x, pos.y, null); + } + + if (!(itemId == 0)) { + g2d.drawImage(Textures.itemIconSheet[itemId - 1].getScaledInstance((int) (Inventory.SLOT_WIDTH * 0.6), (int) (Inventory.SLOT_HEIGHT * 0.6), + Image.SCALE_SMOOTH), pos.x, pos.y, null); + + if (durability < 100) { + g2d.setColor(Color.white); + g2d.setFont(fonts.Gregorian10); + g2d.drawString(Float.toString(durability) + "%", pos.x + 20, pos.y + 38); + } + } + + // EQUIPMENT ATTACK STYLE SLOTS + if (slotNumber == 13) { + if (mouseClicked) g2d.drawImage(Textures.secondaryHUDSheet[37], pos.x, pos.y, null); + else if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[35], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[36], pos.x, pos.y, null); + } else if (slotNumber == 14) { + if (mouseClicked) g2d.drawImage(Textures.secondaryHUDSheet[40], pos.x, pos.y, null); + else if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[38], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[39], pos.x, pos.y, null); + } else if (slotNumber == 15) { + if (mouseClicked) g2d.drawImage(Textures.secondaryHUDSheet[43], pos.x, pos.y, null); + else if (!(bounds.contains(MouseInput.mouseXY))) g2d.drawImage(Textures.secondaryHUDSheet[41], pos.x, pos.y, null); + else g2d.drawImage(Textures.secondaryHUDSheet[42], pos.x, pos.y, null); + } + } + + + /*** INVENTORY SLOTS ***/ + else if (!(itemId == 0) && TYPE >= 0) { + g2d.drawImage(Textures.itemIconSheet[itemId - 1], pos.x, pos.y, null); + + // DONT DRAW QUANTITY OR DURABILITY IF CLICKED + if (!mouseClicked) { + + if (InvenHelper.isStackable(itemId)) { + g2d.setFont(fonts.Gregorian26); + + if(quantity < 10_000) { // UNDER 10k + g2d.setColor(Color.white); + g2d.drawString(Integer.toString(quantity), pos.x + 57, pos.y + 25); + } else if(quantity < 100_000) { // 10k TO 99,999 + g2d.setColor(Color.white); + g2d.drawString(Integer.toString(quantity / 1000) + "k", pos.x + 57, pos.y + 25); + } else if(quantity < 1_000_000) { // 100k to 999,999 + g2d.setColor(Color.white); + g2d.drawString(Integer.toString(quantity / 1000) + "k", pos.x + 57, pos.y + 25); + } else if(quantity < 10_000_000) { // 1000k to 99_999_999 + g2d.setColor(Color.white); + g2d.drawString(Integer.toString(quantity / 1000) + "k", pos.x + 57, pos.y + 25); + } else if(quantity < 100_000_000) { // 10M to 999_999_999 + g2d.setColor(Color.green); + g2d.drawString(Integer.toString(quantity / 1000000) + "m", pos.x + 57, pos.y + 25); + } else if(quantity < 1_000_000_000) { // 100M to 1B + g2d.setColor(Color.green); + g2d.drawString(Integer.toString(quantity / 1000000) + "m", pos.x + 57, pos.y + 25); + } else if(quantity < Utils._2147483647) { // 1000M to MAX STACK - 1 + g2d.setColor(Color.cyan); + g2d.drawString(Integer.toString(quantity / 1000000) + "m", pos.x + 57, pos.y + 25); + } else if(quantity == Utils._2147483647) { // MAX STACK + g2d.setColor(pastelRed); + g2d.drawString(Integer.toString(quantity / 1000000) + "m", pos.x + 57, pos.y + 25); + } else if(quantity > Utils._2147483647) { + System.out.println(" WHOA WE HAVE A PROBLEM HERE. INVEN RENDER MAX INT "); System.exit(0); + } + + + } else if (InvenHelper.isEquippable(itemId) && durability < 100) { + g2d.setFont(fonts.Gregorian20); g2d.setColor(Color.white); + g2d.drawString(Float.toString(durability) + "%", (int) (pos.x + Inventory.SLOT_WIDTH - Float.toString(durability).length() * 13.75), pos.y + 61); + } + } + } + } catch ( Exception e) { e.printStackTrace(); } + } +} diff --git a/src/interfaces/Biomes.java b/src/interfaces/Biomes.java new file mode 100755 index 0000000..f86935d --- /dev/null +++ b/src/interfaces/Biomes.java @@ -0,0 +1,28 @@ +package interfaces; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public interface Biomes { + + public static final int OCEAN=0, + COASTLINE=1, + BEACH=2, + GRASS1=3, + GRASS2=4, + GRASS3=5, + GRASS4=6, + FOREST=7, + DESERT=8, + TAIGA=9, + BARREN_ROCK=10, + SNOW_TUNDA=11, + ASH=12, + VOLCANIC=13, + RIVER=14, + LAKE=15, + BACK_OF_VOLCANO=16, + HIGHLIGHTED = 17; + +} diff --git a/src/interfaces/Colors.java b/src/interfaces/Colors.java new file mode 100755 index 0000000..0c84059 --- /dev/null +++ b/src/interfaces/Colors.java @@ -0,0 +1,21 @@ +package interfaces; + +import java.awt.Color; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public interface Colors { + + static final Color offWhite = new Color(249,249,249), + offBlack = new Color(10, 10, 10), + menuGray = new Color(120, 120, 120), + pastelRed = new Color(255, 80, 50), + pause_menu_alpha = new Color(0, 0, 0, 2), + + + construction_menu_darken = new Color(0,0,0,100), + construction_menu_darken125 = new Color(0,0,0,125); + +} diff --git a/src/interfaces/Directions.java b/src/interfaces/Directions.java new file mode 100755 index 0000000..cb1253d --- /dev/null +++ b/src/interfaces/Directions.java @@ -0,0 +1,19 @@ +package interfaces; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public interface Directions { + + static final int NORTH = 1, + NORTHEAST = 2, + EAST = 3, + SOUTHEAST = 4, + SOUTH = 5, + SOUTHWEST = 6, + WEST = 7, + NORTHWEST = 8; + + +} diff --git a/src/interfaces/Entity.java b/src/interfaces/Entity.java new file mode 100755 index 0000000..419b0a5 --- /dev/null +++ b/src/interfaces/Entity.java @@ -0,0 +1,38 @@ +package interfaces; + +import java.awt.Graphics2D; + +import player.Player; +import utils.Point2f; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public abstract class Entity implements GameObject { + + protected int width, height; + protected Point2f pos; + public Point2f center; + public float radius; + public boolean alive = true, playerCollided, discovered; + public int health; + + public abstract void tick(); + + public abstract void render(Graphics2D g2d); + + protected double dist = 0; + protected float sum = 0; + protected Point2f center2 = new Point2f(0, 0); // to stop mass method calls + + public boolean getDiscoveryStatus() { + if(!discovered) return discovered = Player.DISCOVERY.contains(center.x, center.y); + else return discovered; + } + + public boolean checkIfAlive() { + return alive = health > 0; + } + +} diff --git a/src/interfaces/GameObject.java b/src/interfaces/GameObject.java new file mode 100755 index 0000000..9beaf82 --- /dev/null +++ b/src/interfaces/GameObject.java @@ -0,0 +1,14 @@ +package interfaces; + +import java.awt.Graphics2D; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public interface GameObject { + + public abstract void tick(); + public abstract void render(Graphics2D g2d); + +} diff --git a/src/interfaces/ItemIDs.java b/src/interfaces/ItemIDs.java new file mode 100755 index 0000000..397464a --- /dev/null +++ b/src/interfaces/ItemIDs.java @@ -0,0 +1,31 @@ +package interfaces; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public interface ItemIDs { + + // SECONDARY HUD EQUIPMENT SLOT REFERENCES: + public static final int CAPE_SLOT=0, HEAD_SLOT=1, QUIVER_SLOT=2, HAND_SLOT=3, NECK_SLOT=4, SHIELD_SLOT=5; + + // ***************** FINAL INT ITEM_ID REFERENCES ****************** // + public static final int NULL_ITEM = 0, + PICKED_GRASS = 1, + PICKED_FLOWERS = 2, + CRUDE_AXE = 3, + LOGS = 4, + CRUDE_PICKAXE = 5, + ROCKS = 6, + STICKS = 7, + FIRE = 8, + ASHES = 9, + TORCH = 10, + RABBIT_CARCASS=11, + RABBIT_FOOT=12, + ROT=13, + BONES=14, + GOBLIN_SPEAR=15; + // ***************************************************************** // + +} diff --git a/src/interfaces/Mob.java b/src/interfaces/Mob.java new file mode 100755 index 0000000..1cad7c6 --- /dev/null +++ b/src/interfaces/Mob.java @@ -0,0 +1,388 @@ +package interfaces; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.util.HashSet; + +import engine.Game; +import engine.Handler; +import mobs.Goblin; +import player.HealthAndDurability; +import player.Player; +import player.PlayerAttackSequence; +import utils.Circle; +import utils.Point2f; +import utils.Utils; +import world.Boulder; +import world.DroppedItem; +import world.Tile; +import world.Tree; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public abstract class Mob implements GameObject, Directions, ItemIDs, MobData, Python, Biomes, Colors { + + /** @param PLAYER: A default object to be a placeholder for keeping track of the player. This is necessary as the player is not an object, it is used staticaly. + * @param GET_HIT_ANIMATION_TIMER: The length of time in ticks to show the get hit animation frame */ + public static enum MOB_ID { RABBIT, GOBLIN } + public static enum ANIMATION { idleWalk, idle1, idle2, idle3, runAway, sleep; } + public static final Object PLAYER = new Object(); + public static final int GET_HIT_ANIMATION_TIMER_AMOUNT = 40; + + /** @param destroyingTimer: needs to be AT LEAST your [death animation speed * death animation frames] + * @param territory = is the total circle of territory each mob + * @param hostile: isn't used yet! ... keeping it because it might be nice to have later + * @flag 'public' needs to be used to be accessible from Jython, methods that do not need to be accessed from Jython, but do need to be accessed from its java class, use 'protected' */ + public final int MAX_HEALTH, width, height, combatLevel; + public final float radius, aggroRadius; + public int damage, facing = 3, destroyingTimer = 0, howFarToRunAwayTimer = 20; + public float health, velX, velY, distanceToMove, walkingSpeed, runningSpeed; + public boolean attacking, hostile, runningAway, discovered, sleeping, inCombat; + public Point2f pos, center; + public Circle home, territory, attackBounds; + public MOB_ID id; + public ANIMATION currentAnimation = ANIMATION.idleWalk; + + public Mob(MOB_ID id, Point2f pos, int width, int height, int homeRadius, int aggroRadius, boolean hostile, int damage, int combatLevel, int TERRITORY_ZONE_DISTANCE, int health){ + this.pos = pos; this.width = width; this.height = height; this.hostile = hostile; this.damage = damage; this.id = id; this.aggroRadius = aggroRadius; this.combatLevel = combatLevel; + this.health = MAX_HEALTH = health; + center = new Point2f(pos.x + width/2, pos.y + height/2); + radius = width/2; + + home = new Circle(new Point2f(pos.x + width/2, pos.y + height/2), homeRadius); + territory = new Circle(home.center, TERRITORY_ZONE_DISTANCE); + distanceToMove = Utils.rand.nextInt((int)(home.radius * 1.25)); + Handler.mobs.add(this); + } + +// ------------------------------------- ABSTRACT METHODS ------------------------------------------------------------------------------------------------------------------------------------ // + public abstract void tick(); + public abstract void render(Graphics2D g2d); + public abstract void destroy(); + public abstract void runAnimations(); +// ------------------------------------ END ABSTRACT METHODS ---------------------------------------------------------------------------------------------------------------------------------- // + +// ----------------------------------- JYTHON STUFF ------------------------------------------------------------------------------------------------------------------------------------------// + public static final void initAllPyScripts() { + Goblin.initPyScripts(); + } +// -------------------------------- END JYTHON STUFF -----------------------------------------------------------------------------------------------------------------------------------------// + +// ------------------------------------------------------- COLLISION ---------------------------------------------------------------------------------------------------------------------- // + public boolean collided, justCollided, playerCollided, playerAggroCollided, treeCollided, boulderCollided, itemCollided, structureCollided, waterCollided; + private int alternateCollision; private static final boolean STOP = true, DONT_STOP = false; + public void collision() { + playerAggroCollided = calcCollision(aggroRadius, Player.center, Player.radius, DONT_STOP); + if(!playerAggroCollided) playerCollided = calcCollision(radius, Player.center, Player.radius, STOP); + + collideWithOtherMobs(); + + if(--alternateCollision <= 0) alternateCollision = 3; else return; // helps cut down on the lag + + treeCollided = boulderCollided = structureCollided = itemCollided = false; + + for(final Structure i : Handler.structures) if(calcCollision(radius, i.center, i.radius, STOP)) { structureCollided = true; break; } + if(!(velX == 0 && velY == 0)) { /* no need to calc hard collision if they're just chillin */ + for(final Tree i : Handler.trees) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y) && calcCollision(radius, i.center, i.radius, STOP)) { treeCollided = true; break; } + for(final Boulder i : Handler.boulders) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y) && calcCollision(radius, i.center, i.radius, STOP)) { boulderCollided = true; break; } + for(final DroppedItem i : Handler.droppedItems) if(i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y) && calcCollision(radius, i.center, i.radius, DONT_STOP)) { itemCollided = true; break; } + } + + if(playerCollided || treeCollided || boulderCollided || collided) justCollided = collided = true; else collided = false; + } + + private float diffX, diffY, COMBINED_RADII; private int DISTANCEX, DISTANCEY; + private boolean calcCollision(float RADIUS, Point2f p, float r, final boolean STOP) { + if(Utils.intersects(center, RADIUS, p, r)) { + if (STOP) { + + COMBINED_RADII = RADIUS + r; + DISTANCEX = (int)Utils.abs(center.x - p.x); + DISTANCEY = (int)Utils.abs(center.y - p.y); + diffX = Utils.sqrt(COMBINED_RADII - DISTANCEX) / 2; + diffY = Utils.sqrt(COMBINED_RADII - DISTANCEY) / 2; + + if (center.x > p.x) pos.x += diffX; else pos.x -= diffX; + if (center.y > p.y) pos.y += diffY; else pos.y -= diffY; + + center.x = pos.x + width/2; + center.y = pos.y + height/2; + } + return true; + } return false; + } + + private final void collideWithOtherMobs() { + /** @loop != this ~~~ don't check for collision against themselves */ + for(final Mob i : Handler.mobs) if(i != this && i.discovered && Handler.AREA_RECT.contains(i.center.x, i.center.y)) + switch(id){ + /** @default: DEFAULT == STOP AGAINST ALL OTHER MOBS EXCEPT FOR SMALL CREATURES! */ + // NOTE: small animals should collide with themselves! + case RABBIT: calcCollision(radius, i.center, i.radius, STOP); + default: if(i.id != MOB_ID.RABBIT) { calcCollision(radius, i.center, i.radius, STOP); } + } + } + + public void fixBuggyCollision() { + if(!justCollided) return; + justCollided = collided = false; + idleMove(walkingSpeed); + } +// ------------------------------------------------------ END COLLISION -------------------------------------------------------------------------------------------------------------------- // + +// ------------------------------------------------------ POSITION UPDATING ----------------------------------------------------------------------------------------------------------------- // + /** @param alternateUpdatePosition: the alternate helps them slow down and stop bugging out all random directions + * @param tempFacing: Saves the last facing from the last successful tick. Keeps mobs from spinning around */ + private int tempFacing = 1, alternateUpdatePosition; + public void updatePosition() { + if(collided) velX = velY = 0; + + // NO NEED TO UPDATE POSITION IF NOT MOVING + if(!(velX == 0 && velY == 0)) { + + // LOOP THROUGH ALL TILES TO CHECK IF GOING INTO WATER + outerLoop: + for(final Tile i : Handler.currentTileSection(center.x, center.y)) { + if(!territory.contains(i.x, i.y)) continue; + switch(i.biome) { + case Tile.OCEAN: { if(i.getBounds().contains(center.x + velX, center.y + velY)) { velX = velY = 0; collided = waterCollided = true; break outerLoop; }} + case Tile.LAKE: { if(i.getBounds().contains(center.x + velX, center.y + velY)) { velX = velY = 0; collided = waterCollided = true; break outerLoop; }} + case Tile.RIVER: { if(i.getBounds().contains(center.x + velX, center.y + velY)) { velX = velY = 0; collided = waterCollided = true; break outerLoop; }} + } + } + + // IF MOVING IN BOTH X AND Y, NORMALIZE SPEED + if (velX != 0 && velY != 0) { pos.x += velX / Utils.sqrtOf2; pos.y += velY / Utils.sqrtOf2; } + // ELSE JUST ADD THE SINGULAR VELOCITY + else { pos.x += velX; pos.y += velY; } + + // UPDATE CENTER + center.x = pos.x + (width * 0.5f); center.y = pos.y + (height * 0.5f); + } + + if(!inCombat) { // else facing is calc'd in attack sequence + if(alternateUpdatePosition <= 0) { + if(!(velX == 0 && velY == 0)){ /* if not moving, keep the tempFacing value */ + if (velX == 0 && velY < 0) facing = NORTH; else if (velX == 0 && velY > 0) facing = SOUTH; + else if ( velX > 0 && velY == 0) facing = EAST; else if (velX < 0 && velY == 0) facing = WEST; + else if (velX > 0 && velY > 0) facing = SOUTHEAST; else if (velX < 0 && velY < 0) facing = NORTHWEST; + else if (velX > 0 && velY < 0) facing = NORTHEAST; else if (velX < 0 && velY > 0) facing = SOUTHWEST; + tempFacing = facing; + } alternateUpdatePosition = 5; + } else alternateUpdatePosition--; + facing = tempFacing; + + facing += Game.rotation - 1; + if(facing >= 9) facing -= 8; + } + } + + public void idleMove(final float SPEED) { + if(inCombat) return; + /* Get which direction + speed to move */ + final float angle = Utils.toRadians(Utils.rand.nextInt(360)); + velX = (float)Utils.rotateX(SPEED, SPEED, angle); + velY = (float)Utils.rotateY(SPEED, SPEED, angle); + + /* Get the distance to move */ + distanceToMove = Utils.rand.nextInt((int)home.radius); + + /* switch the animation */ + currentAnimation = ANIMATION.idleWalk; + } + + public void goHome(final float SPEED){ + if(inCombat) return; runningAway = false; + distanceToMove = center.distance(home.center) - randomizeNum(home.radius / 2); + switch(Utils.direction(center, home.center)) { + case NORTH: velX = 0; velY = -SPEED; break; + case NORTHEAST: velX = SPEED; velY = -SPEED; break; + case EAST: velX = SPEED; velY = 0; break; + case SOUTHEAST: velX = SPEED; velY = SPEED; break; + case SOUTH: velX = 0; velY = SPEED; break; + case SOUTHWEST: velX = -SPEED; velY = SPEED; break; + case WEST: velX = -SPEED; velY = 0; break; + case NORTHWEST: velX = -SPEED; velY = -SPEED; break; + } + } + /** @param TICKS_TO_RUN_AWAY: the number of ticks to keep running away from player, + * without yet stopping after having cleared its collision */ + private static final int TICKS_TO_RUN_AWAY = 30; + public void runAway(final float SPEED, final Point2f centerOfWhereToRunFrom){ + if(inCombat) return; runningAway = true; + switch(Utils.direction(center, centerOfWhereToRunFrom)){ + case NORTH: velX = 0; velY = SPEED; break; + case NORTHEAST: velX = -SPEED; velY = SPEED; break; + case EAST: velX = -SPEED; velY = 0; break; + case SOUTHEAST: velX = -SPEED; velY = -SPEED; break; + case SOUTH: velX = 0; velY = -SPEED; break; + case SOUTHWEST: velX = SPEED; velY = -SPEED; break; + case WEST: velX = SPEED; velY = 0; break; + case NORTHWEST: velX = SPEED; velY = SPEED; break; + } + howFarToRunAwayTimer = randomizeNum(TICKS_TO_RUN_AWAY); + } + + public void fixBuggyMovement(final float SPEED) { if(currentAnimation == ANIMATION.idleWalk && velX == 0 && velY == 0 && !inCombat) idleMove(SPEED); } + +// public void runTowards(final float speed, final Point2f centerOfWhereToRunTo) { +// velX = velY = 0; +// switch (Utils.direction(center, centerOfWhereToRunTo)) { +// case NORTH: velX = 0; velY = -speed; break; +// case NORTHEAST: velX = speed; velY = -speed; break; +// case EAST: velX = speed; velY = 0; break; +// case SOUTHEAST: velX = speed; velY = speed; break; +// case SOUTH: velX = 0; velY = speed; break; +// case SOUTHWEST: velX = -speed; velY = speed; break; +// case WEST: velX = -speed; velY = 0; break; +// case NORTHWEST: velX = -speed; velY = -speed; break; +// } +// // put a way to stop here +// } + +// -------------------------------------------------- END POSITION UPDATING ------------------------------------------------------------------------------------------------------------ // + +// -------------------------------------------------- COMBAT --------------------------------------------------------------------------------------------------------------------------- // + /*********************************** VARIABLES ************************************************/ + /** @param TARGET: The point the mob should run to + * @param hitObjects: The objects that have been hit since start of attack sequence + * @param HITBOX_DELAY_AMOUNT: The delay from the start of attack to when hitbox becomes effective + * @param attackTimer: The length of time in ticks the full attack will last + * @param ATTACK_RANGE_FUDGE_DISTANCE: The length away from intersecting ones needs to be to still be considered intersecting + * @param GET_HIT_TIMER: The time to show the 'get hit' animation frame + * @param GET_HIT_TIMER_AMOUNT: A const to set the above timer to */ + private Point2f TARGET; public HashSet hitObjects = new HashSet(); + private static final int HITBOX_DELAY_AMOUNT = 26, ATTACK_RANGE_FUDGE_DISTANCE = 20, GET_HIT_TIMER_AMOUNT = 25; + protected int GET_HIT_TIMER; private int hitboxDelay, attackTimer; + /********************************* END VARIABLES *******************************************/ + + public void combat() { // NOTE: THIS IS THE GENERIC COMBAT, OVERRIDE THIS FOR SPECIFIC MOB NEEDS + if(!attacking || hitboxDelay > 0) return; // (don't keep spamming hits if already hit an entity + + // IF HIT PLAYER + if(!hitObjects.contains(PLAYER) && Utils.intersects(attackBounds, Player.center, Player.radius)) { + hitObjects.add(PLAYER); + HealthAndDurability.hurtPlayer(damage); + } + } + + public void startAttackSequence( /* some kind of object? */ ) { + if(attacking || inCombat) return; // don't restart sequence if already in combat + inCombat = true; + TARGET = Player.center; + hitObjects.clear(); + hitboxDelay = HITBOX_DELAY_AMOUNT; + GET_HIT_TIMER = 0; + currentAnimation = ANIMATION.idleWalk; // XXX: YOU MAY NEED TO OVERRIDE THIS FOR SOME MOBS! + } + + public void attackSequence(final float SPEED) { + // NULL CHECK IN CASE TARGET HAS DIED / ETC OR IF TARGET HAS GONE OUTSIDE ITS TERRITORY AGGRO, STOP ATTACK SEQUENCE + if (TARGET == null || Player.health <= 0 || !territory.contains(TARGET)) { STOP_ATTACK_SEQUENCE(); return; } + + // MOVE TOWARDS TARGET + if (!attacking) { + final double angle = Math.atan2(TARGET.y - center.y, TARGET.x - center.x); + velX = (float)((Math.cos(angle) * SPEED) * Utils.sqrtOf2); + velY = (float)((Math.sin(angle) * SPEED) * Utils.sqrtOf2); + + // DIRECTION / FACING TOWARD TARGET + int tempFacing = Utils.direction(center, TARGET) + (Game.rotation - 1); + if (tempFacing > 8) tempFacing -= 8; + facing = tempFacing; + } else velX = velY = 0f; + + // STOP MOB WHEN REACHES THE TARGET, THEN ATTACK! + if (attacking) { + if(hitboxDelay > 0) hitboxDelay--; else combat(); + if(attackTimer > 0) attackTimer--; else STOP_ATTACK_SEQUENCE(); + } else if (Utils.distance(attackBounds.center, TARGET) < ATTACK_RANGE_FUDGE_DISTANCE) { + attacking = true; + attackTimer = calcAttackTimerAmount(); + } + + } + + private int calcAttackTimerAmount() { + switch (id) { + case GOBLIN: return 55; + + default: return 25; + } + } + + private void STOP_ATTACK_SEQUENCE() { TARGET = null; hitObjects.clear(); attacking = inCombat = false; currentAnimation = ANIMATION.idleWalk; } + + public void HIT_BY_PLAYER() { // XXX: WILL NEED TO RETROFIT THIS TO WORK WITH MOBS NOT JUST PLAYER + hitboxDelay += HITBOX_DELAY_AMOUNT/4; + attackTimer += HITBOX_DELAY_AMOUNT/4; + + // DEDUCT DURABILITY FROM PLAYER'S WEAPON + if(!PlayerAttackSequence.hitMobs.contains(this)) { + HealthAndDurability.HIT_MOB(); + + // SUBTRACT FROM CURRENT HEALTH + health -= Player.currentDamage; // NOTE: For mobs strong against certain attacks, etc, override this method. + + // SET THE GET HIT TIMER TO RENDER THE GET-HIT ANIMATION IN RENDER + GET_HIT_TIMER = GET_HIT_TIMER_AMOUNT; + } + } + + public void getHitClock() { if(GET_HIT_TIMER > 0) GET_HIT_TIMER--; } +// ------------------------------------------------- END COMBAT ------------------------------------------------------------------------------------------------------------------------- // + +// -------------------------------------------------------------- DISCOVERING ---------------------------------------------------------------------------------------------------------- // + private static final int DISCOVERY_STATUS_DELAY = 30; + private int getDiscoveredStatusDelay = DISCOVERY_STATUS_DELAY; + public boolean getDiscoveredStatus() { + if(!discovered) { return discovered = Player.DISCOVERY.contains(center.x, center.y); } + + // IF MOB WALKS OUTSIDE OF DISCOVERED TILES, SET THE MOB TO BE NOT DISCOVERED + // DELAY THIS BECAUSE ITS EXPENSIVE! + if(getDiscoveredStatusDelay < 0) { + + for(final Tile t : Handler.currentTileSection(center.x, center.y)) if(!t.discovered && t.getBounds().contains(center.x, center.y)) discovered = false; + + getDiscoveredStatusDelay = DISCOVERY_STATUS_DELAY; + } else getDiscoveredStatusDelay--; + + return discovered; + } +// ---------------------------------------------------------- END DISCOVERING ------------------------------------------------------------------------------------------------------------- // + +// ---------------------------------------------------------- MISC METHODS ----------------------------------------------------------------------------------------------------------------- // + public void drawCollisionBounds(Graphics2D copy){ + if(Game.drawCollisionBounds){ copy.setColor(Color.green); copy.drawOval((int)(center.x - radius), (int)(center.y - radius), (int)(radius*2), (int)(radius*2)); } + if(Game.drawMobAggroRadii || Game.drawCollisionBounds){ copy.setColor(Color.red); copy.drawOval((int)(center.x - aggroRadius), (int)(center.y - aggroRadius), (int)(aggroRadius*2), (int)(aggroRadius*2)); } + if(Game.drawMobTerritoryZones || Game.drawCollisionBounds) { copy.setColor(Color.orange); copy.drawOval((int)(home.center.x - aggroRadius), (int)(home.center.y - aggroRadius), (int)(home.diameter()), (int)(home.diameter())); } + if(Game.drawMobAttackBounds || Game.drawCollisionBounds) { copy.setColor(Color.magenta); copy.drawOval((int)(attackBounds.center.x - attackBounds.radius), (int)(attackBounds.center.y - attackBounds.radius), (int)(attackBounds.diameter()), (int)(attackBounds.diameter())); } + if(Game.drawCollisionBounds) { copy.setColor(Color.BLACK); territory.draw(copy); } + } + + public void allBugFixes() { + fixBuggyCollision(); + fixBuggyMovement(walkingSpeed); + } + + public String toString() { return getClass().toString().substring(getClass().toString().indexOf(".")+1); } + + public boolean alive(){ return health > 0; } + + public void normalizeHealth() { if(health > MAX_HEALTH) health = MAX_HEALTH; } + + protected static final int randomizeNum(float num) { return (int)(Utils.rand.nextInt((int)num/2) + num*0.75f); } + + protected final void NULL_ALL_FROM_SUPER_CLASS() { + home.center = territory.center = attackBounds.center = null; + home = territory = attackBounds = null; + center = pos = null; + id = null; currentAnimation = null; + hitObjects.clear(); hitObjects = null; TARGET = null; + } +// --------------------------------------------------------- END MISC METHODS ---------------------------------------------------------------------------------------------------------------- // + + +} diff --git a/src/interfaces/MobData.java b/src/interfaces/MobData.java new file mode 100755 index 0000000..d1dfe56 --- /dev/null +++ b/src/interfaces/MobData.java @@ -0,0 +1,36 @@ +package interfaces; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public interface MobData { + +/********************************************************************** RABBIT **********************************************************************************************/ + static final int RABBIT_WIDTH = 10, + RABBIT_HEIGHT = 10, + RABBIT_HOME_RADIUS = 60, + RABBIT_AGGRO_RADIUS = 30, + RABBIT_COMBAT_LEVEL = 2, + RABBIT_TOTAL_HEALTH = 6; + + static final float RABBIT_WALKING_SPEED = 0.125f, + RABBIT_RUNNING_SPEED = 1.55f; +/******************************************************************* END RABBIT *********************************************************************************************/ + +/************************************************************************* GOBLIN *******************************************************************************************/ + static final int GOBLIN_WIDTH = 22, + GOBLIN_HEIGHT = 28, + GOBLIN_AGGRO_RADIUS = 140, + GOBLIN_HOME_RADIUS = GOBLIN_AGGRO_RADIUS, + GOBLIN_DAMAGE = 5, + GOBLIN_COMBAT_LEVEL = 6, + GOBLIN_TERRITORY_AGGRO_DISTANCE = 500, + GOBLIN_ATTACK_BOUNDS_RADIUS = 15, + GOBLIN_TOTAL_HEALTH = 30; + + static final float GOBLIN_WALKING_SPEED = 0.45f, + GOBLIN_RUNNING_SPEED = 1f; +/************************************************************************ END GOBLIN ****************************************************************************************/ + +} diff --git a/src/interfaces/PlayerAnimationIDs.java b/src/interfaces/PlayerAnimationIDs.java new file mode 100755 index 0000000..b65989a --- /dev/null +++ b/src/interfaces/PlayerAnimationIDs.java @@ -0,0 +1,20 @@ +package interfaces; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public interface PlayerAnimationIDs { + + + static final int IDLE = 0, + WALK = 1, + RUN = 2, + PICK_UP_ITEM = 3, + AXE_CHOP = 4, + MINE_ROCK = 5, + GET_HIT = 6; + + + +} diff --git a/src/interfaces/Python.java b/src/interfaces/Python.java new file mode 100755 index 0000000..351c8d5 --- /dev/null +++ b/src/interfaces/Python.java @@ -0,0 +1,16 @@ +package interfaces; + +import utils.PythonBase; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public interface Python extends PythonBase { + // NOTE: PythonBase has 'pi' for PythonInterpreter! + + + // PUT YOUR SCRIPTS-TO-STRING HERE: + + +} diff --git a/src/interfaces/Structure.java b/src/interfaces/Structure.java new file mode 100755 index 0000000..6373a69 --- /dev/null +++ b/src/interfaces/Structure.java @@ -0,0 +1,30 @@ +package interfaces; + +import java.awt.Graphics2D; + +import utils.Point2f; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public abstract class Structure implements GameObject { + + public int itemId; + public Point2f center, pos; + public float radius; + public float health = 100; + + public Structure(int itemId, Point2f center, int WIDTH, int HEIGHT){ + this.itemId = itemId; + this.center = center; + this.radius = WIDTH/2; + this.pos = new Point2f(center.x - WIDTH/2, center.y - HEIGHT/2); + } + + public abstract void destroy(); + + public abstract void tick(); + + public abstract void render(Graphics2D g2d); +} \ No newline at end of file diff --git a/src/items/DroppedItemIconTextures.java b/src/items/DroppedItemIconTextures.java new file mode 100755 index 0000000..b7cec7d --- /dev/null +++ b/src/items/DroppedItemIconTextures.java @@ -0,0 +1,38 @@ +package items; + +import java.awt.Image; + +import _texture.loader.Textures; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class DroppedItemIconTextures { + + public static final void getTextures() { + + + + // FROM INVENTORY CLASS: + final int boxWidth = 84, boxHeight = 78; + + // NOTE: ITEM ID IS THE # + 1 + + for(int i = 0; i < Textures.itemIconSheet.length; i++) { + + try { + switch(i) { + case 11: Textures.droppedItemIconSheet[i] = Utils.imageToBufferedImage(Textures.itemIconSheet[i].getScaledInstance(boxWidth / 5, boxHeight / 5, Image.SCALE_FAST)); break; + + default: Textures.droppedItemIconSheet[i] = Utils.imageToBufferedImage(Textures.itemIconSheet[i].getScaledInstance(boxWidth / 4, boxHeight / 4, Image.SCALE_FAST)); + } + } catch (NullPointerException npe) { /* must be a structure or not init'd, ignore */ } + + } + + + } + +} diff --git a/src/items/ItemIconTextures.java b/src/items/ItemIconTextures.java new file mode 100755 index 0000000..294e537 --- /dev/null +++ b/src/items/ItemIconTextures.java @@ -0,0 +1,31 @@ +package items; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class ItemIconTextures { + + public static void getTextures(final BufferedImage image){ + final int width = 70, height = 60; + Textures.itemIconSheet[0] = Utils.grabSprite(image, 3, 1, width, height); /*** picked_grass ***/ + Textures.itemIconSheet[1] = Utils.grabSprite(image, 4, 1, width, height); /*** picked_flowers ***/ + Textures.itemIconSheet[2] = Utils.grabSprite(image, 2, 1, width, height); /*** crude axe ***/ + Textures.itemIconSheet[3] = Utils.grabSprite(image, 1, 1, width, height); /*** log ***/ + Textures.itemIconSheet[4] = Utils.grabSprite(image, 5, 1, width, height); /*** crude pick axe ***/ + Textures.itemIconSheet[5] = Utils.grabSprite(image, 6, 1, width, height); /*** rock ***/ + Textures.itemIconSheet[6] = Utils.grabSprite(image, 7, 1, width, height); /**** sticks ****/ + Textures.itemIconSheet[8] = Utils.grabSprite(image, 8, 1, width, height); /**** ASHES ****/ + Textures.itemIconSheet[9] = Utils.grabSprite(image, 1, 2, width, height); /**** torch ****/ + Textures.itemIconSheet[10] = Utils.grabSprite(image, 2, 2, width, height); /**** RABBIT CARCASS ****/ + Textures.itemIconSheet[11] = Utils.grabSprite(image, 3, 2, width, height); /**** RABBIT FOOT *****/ + Textures.itemIconSheet[12] = Utils.grabSprite(image, 4, 2, width, height); /**** ROT *****/ + Textures.itemIconSheet[13] = Utils.grabSprite(image, 5, 2, width, height); /**** BONES ****/ + Textures.itemIconSheet[14] = Utils.grabSprite(image, 6, 2, width, height); /**** goblin spear ***/ + } +} diff --git a/src/lighting/PlayerLightPosUpdater.java b/src/lighting/PlayerLightPosUpdater.java new file mode 100755 index 0000000..5b4cfdf --- /dev/null +++ b/src/lighting/PlayerLightPosUpdater.java @@ -0,0 +1,25 @@ +package lighting; + +import player.Player; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerLightPosUpdater { + + public static final void tick(){ + + // NOTE: WILL NEED TO MOVE LIGHT WITH SWITCH STATEMENT + // FOR DIFFERENT ITEMS / GAME ROTATIONS! + + for(final RadialLight i : Player.playerLights){ + + if(i == Player.torchLight) i.center = Player.center; + + } + + + } + +} diff --git a/src/lighting/RadialLight.java b/src/lighting/RadialLight.java new file mode 100755 index 0000000..9cc8a15 --- /dev/null +++ b/src/lighting/RadialLight.java @@ -0,0 +1,122 @@ +package lighting; + +import java.awt.AlphaComposite; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Image; +import java.awt.Point; +import java.awt.RadialGradientPaint; +import java.awt.image.BufferedImage; +import java.util.ConcurrentModificationException; + +import engine.Camera; +import engine.Game; +import engine.Handler; +import hud.Clock; +import hud.Clock.TIME; +import interfaces.ItemIDs; +import player.Player; +import utils.Point2f; +import utils.Stack; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class RadialLight implements ItemIDs { + + public final static Stack lights = new Stack(); + public final int radius; + public Point2f center; + public final BufferedImage lightImage; + + private static BufferedImage lightmap = new BufferedImage(Game.WIDTH, Game.HEIGHT, BufferedImage.TYPE_INT_ARGB); + + public RadialLight(final Point2f center, final int radius, final float intensity){ + this.center = center; this.radius = radius; + Color[] color = { new Color(0, 0, 0, intensity), new Color(0, 0, 0, 0) }; + lightImage = new BufferedImage(radius * 2, radius * 2, BufferedImage.TYPE_INT_ARGB); + Graphics2D g2d = (Graphics2D) lightImage.getGraphics(); + + float[] distance = { 0f, 1f }; + g2d.setPaint(new RadialGradientPaint(new Point(radius, radius), radius, distance, color)); + g2d.fillOval(0, 0, radius * 2, radius * 2); + g2d.dispose(); + } + + private final void update(Graphics2D lightsRenderer){ + lightsRenderer.drawImage(lightImage.getScaledInstance((int)(lightImage.getWidth() * Game.scaleFactor), + (int)(lightImage.getHeight() * Game.scaleFactor), Image.SCALE_FAST), + (int)((center.x + Camera.x) * Game.scaleFactor) - (int)(radius * Game.scaleFactor), + (int)((center.y + Camera.y) * Game.scaleFactor) - (int)(radius * Game.scaleFactor), null); + } + + private static int alternate, darkness, hue; + private static float temp; + private static final int RED_AMOUNT = 65, GREEN_AMOUNT = 10; + public static final void render(final Graphics2D g2d){ + // DONT RENDER LIGHTS IF IT IS DAY + if(Clock.clock == TIME.DAY) return; + + // ONLY UPDATE THE EVERY OTHER FRAME, HELPS REDUCE LAG + if(alternate <= 0){ alternate++; /* draw the update all the lights every other frame to reduce lag, not very noticeable */ + + lightmap = new BufferedImage((int) (Game.game.getWidth() * 1.1), (int) (Game.game.getHeight() * 1.1), BufferedImage.TYPE_INT_ARGB); + + Graphics2D lightsRenderer = (Graphics2D) lightmap.getGraphics(); + + if (Clock.clock == TIME.DAWN){ + temp = ((((float)(Clock.DAY - Clock.time)) / (Clock.DAY))); + + darkness = (int)(temp*254); + if(darkness < 0) darkness = 0; + else if(darkness > 254) darkness = 242; + + if(temp < 0.5f) hue = (int)(temp * GREEN_AMOUNT); + else hue = GREEN_AMOUNT - (int)(temp * GREEN_AMOUNT); + + lightsRenderer.setColor(new Color(hue/3, hue, 0, darkness)); + + } else if (Clock.clock == TIME.DUSK){ + temp = ((((float)(Clock.time - Clock.DUSK)) / (Clock.NIGHT - Clock.DUSK))); + + darkness = (int)(temp*255); + if(darkness < 0) darkness = 0; + else if(darkness > 255) darkness = 255; + + if(temp < 0.5f) hue = (int)(temp * RED_AMOUNT); + else hue = RED_AMOUNT - (int)(temp * RED_AMOUNT); + + lightsRenderer.setColor(new Color(hue, 0, 0, darkness)); + } else if (Clock.clock == TIME.NIGHT)lightsRenderer.setColor(Color.black); + + lightsRenderer.fillRect(0, 0, lightmap.getWidth(), lightmap.getHeight()); + lightsRenderer.setComposite(AlphaComposite.DstOut); + lightsRenderer.rotate((Game.rotation - 1) * Utils._45); + + try{ for(final RadialLight light : lights) if(Handler.AREA_RECT.contains(light.center.x, light.center.y)) light.update(lightsRenderer); } + catch (ConcurrentModificationException cme){ /* happens when adding / removing lights, ignore */ } + + try{ for(final RadialLight playerLight : Player.playerLights) if(Handler.AREA_RECT.contains(playerLight.center.x, playerLight.center.y)) playerLight.update(lightsRenderer); } + catch (ConcurrentModificationException cme){ /* happens when adding / removing lights, ignore */ } + + lightsRenderer.dispose(); + } else { alternate--; } + + g2d.drawImage(lightmap, 0, 0, null); + } + + public static final void determineLight(final int itemId){ + switch(itemId){ + case TORCH: if(!Player.playerLights.contains(Player.torchLight)) Player.playerLights.add(Player.torchLight); break; + } + } + + public static final void removeLight(final int itemId){ + switch(itemId){ + case TORCH: if(Player.playerLights.contains(Player.torchLight)) Player.playerLights.remove(Player.torchLight); break; + } + } + +} diff --git a/src/mobs/DROP_TABLES.java b/src/mobs/DROP_TABLES.java new file mode 100755 index 0000000..cc71dea --- /dev/null +++ b/src/mobs/DROP_TABLES.java @@ -0,0 +1,50 @@ +package mobs; + +import java.util.Random; + +import interfaces.ItemIDs; +import interfaces.Mob.MOB_ID; +import utils.Point2f; +import utils.Utils; +import world.DroppedItem; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class DROP_TABLES implements ItemIDs { + + public static synchronized final void dropItem (final MOB_ID id, final Point2f center) { + CENTER = center; + + switch(id) { + case RABBIT: { + roll(1000, RABBIT_FOOT); + roll(300, PICKED_GRASS); + drop(RABBIT_CARCASS); break; + } + case GOBLIN: { + roll(1000, ASHES); + roll(300, PICKED_GRASS); + roll(200, STICKS); + roll(100, ROCKS); + roll(50, ROT, 3); + roll(15, ROT); + if(chance(10)) new DroppedItem(CENTER, GOBLIN_SPEAR, 1, (Utils.rand.nextInt(200) + 1)*0.5f); // drop spear with random durability + drop(BONES); break; + } + + default: System.out.println("YO YOU NEED TO CONFIG THIS MOBS DROPS!!!!!"); System.exit(1); + } + + } + +/********************************************************************************************************************************/ + private static Point2f CENTER = new Point2f(0,0); + private static final synchronized void roll(int CHANCE, int itemId) { if(chance(CHANCE)) drop(itemId); } + private static final synchronized void roll(int CHANCE, int itemId, int quantity) { if(chance(CHANCE)) drop(itemId, quantity); } + private static final synchronized void drop(int itemId) { new DroppedItem(CENTER, itemId); } + private static final synchronized void drop(int itemId, int quantity) { new DroppedItem(CENTER, itemId, quantity); } + private static final synchronized boolean chance(final int bound) { return new Random().nextInt(bound) == 0; } + +} diff --git a/src/mobs/Goblin.java b/src/mobs/Goblin.java new file mode 100755 index 0000000..be32b17 --- /dev/null +++ b/src/mobs/Goblin.java @@ -0,0 +1,180 @@ +package mobs; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; + +import org.python.core.Py; +import org.python.core.PyFunction; +import org.python.core.PyObject; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import interfaces.Mob; +import utils.Animation; +import utils.Circle; +import utils.Point2f; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class Goblin extends Mob { + + public Goblin(float x, float y) { + super(MOB_ID.GOBLIN, new Point2f(x , y), GOBLIN_WIDTH, GOBLIN_HEIGHT, GOBLIN_HOME_RADIUS, randomizeNum(GOBLIN_AGGRO_RADIUS), true, GOBLIN_DAMAGE, GOBLIN_COMBAT_LEVEL, randomizeNum(GOBLIN_TERRITORY_AGGRO_DISTANCE), GOBLIN_TOTAL_HEALTH); + + walkingSpeed = GOBLIN_WALKING_SPEED; runningSpeed = GOBLIN_RUNNING_SPEED; + attackBounds = new Circle(center, GOBLIN_ATTACK_BOUNDS_RADIUS); + currentAnimation = ANIMATION.idleWalk; + destroyingTimer = deaths.length * DEATH_ANIMATION_SPEED; + idleMove(walkingSpeed); + } + + public void tick() { + pyTick.__call__(thisGoblin); + + /** uncomment for interactive scripting (SLOW) ******/ +// pi.exec(Utils.readTextFileAsString("/goblin_ai.py")); +// pi.get("__goblin_tick__", PyFunction.class).__call__(thisGoblin); + } + + public void destroy() { + DROP_TABLES.dropItem(id, center); + for(int i = 0; i < runs.length; i++) runs[i] = null; + for(int i = 0; i < idle1s.length; i++) idle1s[i] = null; + for(int i = 0; i < idle2s.length; i++) idle2s[i] = null; + for(int i = 0; i < attacks.length; i++) attacks[i] = null; + for(int i = 0; i < deaths.length; i++) deaths[i] = null; + runs = idle1s = idle2s = attacks = deaths = null; + copy = null; transform = null; + NULL_ALL_FROM_SUPER_CLASS(); + Handler.mobs.remove(this); + } + + + // ----------------------------- RENDERING ---------------------------------------------------------------------------------------------------------------------------------------------- // + private Graphics2D copy; private AffineTransform transform = new AffineTransform(); + public void render(Graphics2D g2d) { + if(!discovered) return; + copy = (Graphics2D) g2d.create(); drawCollisionBounds(copy); transform.setToRotation(-Utils._45 * (Game.rotation - 1), center.x, center.y); copy.transform(transform); + + if(alive()){ + if(GET_HIT_TIMER > 0) { + copy.drawImage(getHits[facing - 1], (int)(pos.x - width / 3 + 1), (int)(pos.y - height / 3), null); + } else { + if(!attacking) { + switch(currentAnimation) { + case idleWalk: runs[facing - 1].drawAnimation(copy, pos.x - width/3 + 1, pos.y - height/3); break; + case idle1: idle1s[facing - 1].drawAnimation(copy, pos.x - width/3 + 1, pos.y - height/3); break; + case idle2: idle2s[facing - 1].drawAnimation(copy, pos.x - width/3 + 1, pos.y - height/3); break; + default: break; + } + } else attacks[facing - 1].drawAnimation(copy, pos.x - width/3 + 1, pos.y - height/3); + } + } else deaths[facing - 1].drawAnimation(copy, pos.x - width/3 + 1, pos.y - height/3); + + drawCollisionBounds(copy); + + copy.dispose(); copy = null; + } + // -------------------------- END RENDERING ----------------------------------------------------------------------------------------------------------------------------------------// + +// ----------------------------- JYTHON STUFF ----------------------------------------------------------------------------------------------------------------------------------------- // + private final PyObject thisGoblin = Py.java2py(this); + private static PyFunction pyTick; + public static final void initPyScripts(){ + pi.exec(Utils.readTextFileAsString("/goblin_ai.py")); + pyTick = pi.get("__goblin_tick__", PyFunction.class); + } +// ---------------------------- END JYTHON STUFF -------------------------------------------------------------------------------------------------------------------------------------- // + +// ----------------------------------------------------------------- ANIMATION STUFF --- IGNORE ---------------------------------------------------------------------------------------------- // + private static final int RUN_ANIMATION_SPEED = 12, IDLE_1_ANIMATION_SPEED = 28, ATTACK_ANIMATION_SPEED = 12, DEATH_ANIMATION_SPEED = 11; + public int idleAnimationTimer; + + public void runAnimations() { + if(alive()) { + if(!attacking) for(Animation a : runs) a.runAnimation(); + + if(!inCombat && currentAnimation != ANIMATION.idleWalk) { + idle1s[facing - 1].runAnimation(); + idle2s[facing - 1].runAnimation(); + } + + if(attacking) for (Animation a : attacks) a.runAnimation(); + else for(Animation a : attacks) a.restartAnimation(); + } else try { for(Animation a : deaths) if(a.currentFrame != deaths.length) a.playAnimationOnce(); } catch (NullPointerException npe) {} + } + + private static final BufferedImage[] getHits = { + Textures.goblinSheet[96], + Textures.goblinSheet[97], + Textures.goblinSheet[98], + Textures.goblinSheet[99], + Textures.goblinSheet[100], + Textures.goblinSheet[101], + Textures.goblinSheet[102], + Textures.goblinSheet[103], + }; + + private int __count = 0; + private Animation[] runs = { // N NE E SE S SW W NW + new Animation(RUN_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(RUN_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(RUN_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(RUN_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(RUN_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(RUN_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(RUN_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(RUN_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + }; + + private Animation[] idle1s = { + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]) + }; + private Animation[] idle2s = { + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(IDLE_1_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]) + }; + + private Animation[] attacks = { // N NE E SE S SW W NW + new Animation(ATTACK_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(ATTACK_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(ATTACK_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(ATTACK_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(ATTACK_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(ATTACK_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(ATTACK_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + new Animation(ATTACK_ANIMATION_SPEED, Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++], Textures.goblinSheet[__count++]), + }; + + private int __new_count = __count + 8; + public Animation[] deaths = { + new Animation(DEATH_ANIMATION_SPEED, Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++]), + new Animation(DEATH_ANIMATION_SPEED, Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++]), + new Animation(DEATH_ANIMATION_SPEED, Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++]), + new Animation(DEATH_ANIMATION_SPEED, Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++]), + new Animation(DEATH_ANIMATION_SPEED, Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++]), + new Animation(DEATH_ANIMATION_SPEED, Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++]), + new Animation(DEATH_ANIMATION_SPEED, Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++]), + new Animation(DEATH_ANIMATION_SPEED, Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++], Textures.goblinSheet[__new_count++]), + }; +// --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------// + +} diff --git a/src/mobs/Rabbit.java b/src/mobs/Rabbit.java new file mode 100755 index 0000000..96b7eab --- /dev/null +++ b/src/mobs/Rabbit.java @@ -0,0 +1,258 @@ +package mobs; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import hud.Clock; +import hud.Clock.TIME; +import interfaces.Mob; +import player.Player; +import utils.Animation; +import utils.Point2f; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public class Rabbit extends Mob { +/**********************************************************************************************************************************************************/ + /**** NOTE: THIS WAS THE FIRST MOB I CREATED FOR THIS GAME + * IT IS THE ONLY MOB WRITTEN PURELY IN JAVA, WHERE AS + * THE OTHERS ARE SCRIPTED WITH PYTHON / JYTHON. + * THIS IS TO BE USED AS A REFERENCE FOR THOSE + * OTHER MOBS TO BE SCRIPTED */ +/***********************************************************************************************************************************************************/ + + public Rabbit(final float x, final float y) { + super(Mob.MOB_ID.RABBIT, new Point2f(x, y), RABBIT_WIDTH, RABBIT_HEIGHT, RABBIT_HOME_RADIUS, randomizeNum(RABBIT_AGGRO_RADIUS), false, -1, RABBIT_COMBAT_LEVEL, 0, RABBIT_TOTAL_HEALTH); + currentAnimation = ANIMATION.idleWalk; + destroyingTimer = DEATH_ANIMATION_SPEED * death.length; + walkingSpeed = RABBIT_WALKING_SPEED; runningSpeed = RABBIT_RUNNING_SPEED; + idleMove(walkingSpeed); + } + + private int idleAnimationTimer = Utils.rand.nextInt(250); + public void tick() { + + // DISCOVER + getDiscoveredStatus(); + + // AFTER DEATH + if(!alive()) { whileDead(); return; } + + // NORMALIZE HEALTH + normalizeHealth(); + + // COLLISION / COMBAT / POSITION + collision(); combat(); if(!collided) updatePosition(); + + // SLEEPING + if(!collided && !playerAggroCollided && Clock.clock == TIME.DAWN || Clock.clock == TIME.NIGHT) sleeping = true; else sleeping = false; + + // RUN ANIMATIONS + runAnimations(); + + // SLEEPING + if(sleeping && !playerAggroCollided){ velX = velY = 0; currentAnimation = ANIMATION.sleep; } + + // RUN AWAY + if(playerAggroCollided){ currentAnimation = ANIMATION.runAway; runAway(runningSpeed, Player.center); } + + // STOP RUNNING AWAY + if(runningAway && !collided) { + if(--howFarToRunAwayTimer <= 0) { + velX = velY = 0; runningAway = false; + if(Utils.rand.nextBoolean()) currentAnimation = ANIMATION.idle1; + else if(runningAway){ currentAnimation = ANIMATION.idleWalk; idleMove(walkingSpeed);} + } + } + + // IDLE ANIMATION ALGORITHMS ~~~ ONLY START IF NOT SLEEPING AND NOT RUNNING AWAY + if(!collided && !runningAway && !sleeping){ + + // IF NOT WALKING AROUND, MUST BE EATING GROUND + if(currentAnimation != ANIMATION.idleWalk) idleAnimationTimer--; + + // IF FINISHED IDLE WALKING, CHANGE ANIMATION + if(distanceToMove <= 0 && currentAnimation == ANIMATION.idleWalk) { + if(Utils.rand.nextInt(4) == 0) idleMove(walkingSpeed); /* 1 in 4 chance of keeping on walking */ + else { idleAnimationTimer = Utils.rand.nextInt(200) + 100; velX = velY = 0; + currentAnimation = ANIMATION.idle1; + } + } + + // IF WAS IDLING, AND TIMER IS UP, START WALKING + if(currentAnimation != ANIMATION.idleWalk && idleAnimationTimer <= 0){ + currentAnimation = ANIMATION.idleWalk; + idleMove(walkingSpeed); + } + + // IF WALKING, SUBSTRACT FROM WALK DISTANCE + if(currentAnimation == ANIMATION.idleWalk) distanceToMove -= Utils.pythagoras(velX, velY); + + // IF HAS STEPPED OUTSIDE ITS TERRITORY, GO HOME + if(!home.contains(center) && !collided) { + if(home.center.distance(center) < 1500){ + goHome(walkingSpeed); + currentAnimation = ANIMATION.idleWalk; + } else { + goHome(runningSpeed); + currentAnimation = ANIMATION.runAway; + } + } + + // FIX BUGGY WALKING AROUND + fixBuggyMovement(walkingSpeed); + } + // FIX BUGGY COLLISION --- (they get stuck occasionally) -- just start + // the idiots moving again until they find a good direction. + if(justCollided){ idleMove(walkingSpeed); justCollided = collided = false; } + + + getHitClock(); // sub hit timer + } + + public void whileDead() { + if(alive() || destroyingTimer <= 0) return; + + try { if(--destroyingTimer <= 0) destroy(); + + for(final Animation i : death) if(i.currentFrame != 2) i.runAnimation(); /* != 2 means it won't restart the animation */ + + } catch (NullPointerException npe) {} // npe is to catch if the handler is slow and ticks again after mob gets removed + } + + private Graphics2D copy; private AffineTransform transform = new AffineTransform(); + public void render(Graphics2D g2d) { + if(!discovered) return; + copy = (Graphics2D) g2d.create(); transform.setToRotation(-Utils._45 * (Game.rotation - 1), center.x, center.y); copy.transform(transform); + if(alive() && GET_HIT_TIMER <= 0) { + switch(currentAnimation){ + case idleWalk: idleWalks[facing - 1].drawAnimation(copy, center.x, center.y); break; + case idle1: idle1[facing - 1].drawAnimation(copy, center.x, center.y); break; + case runAway: runAway[facing - 1].drawAnimation(copy, center.x, center.y); break; + case sleep: sleep[facing - 1].drawAnimation(copy, center.x, center.y); break; + default: break; + } + drawCollisionBounds(copy); + } else if (alive()) copy.drawImage(GET_HITS[facing - 1], (int)center.x, (int)center.y, null); // THIS IS IF THE GET_HIT TIMER IS ABOVE ZERO, MEANING WE NEED TO RENDER THE GET_HIT ANIMATION + else try { death[facing - 1].drawAnimation(copy, pos.x - width/2, pos.y - height/2); } catch (NullPointerException npe) { /* means he finished dying and got removed */ } + + // NOTE: will stop rendering when it gets removed from the mobs list after destroy() + + copy.dispose(); copy = null; + } + + public void combat() { + if(Player.attacking && Utils.intersects(Player.attackBounds, center, radius)){ + health-= Player.currentDamage; + HIT_BY_PLAYER(); + } + } + + public void destroy() { + DROP_TABLES.dropItem(id, center); + +// /* implicitly null everything because I'm paranoid */ + for(int i = 0; i < idleWalks.length; i++) idleWalks[i] = null; + for(int i = 0; i < idle1.length; i++) idle1[i] = null; + for(int i = 0; i < runAway.length; i++) runAway[i] = null; + for(int i = 0; i < sleep.length; i++) sleep[i] = null; + for(int i = 0; i < death.length; i++) death[i] = null; + idleWalks = idle1 = runAway = sleep = death = null; + copy = null; transform = null; + + Handler.mobs.remove(this); + } + + + + + +/********************************************************* ANIMATION DECLARATIONS --- IGNORE ******************************************************************/ + private static final int IDLE_WALK_ANIMATION_SPEED = 18, IDLE_EAT_GROUND_ANIMATION_SPEED = 18, RUN_AWAY_ANIMATION_SPEED = 5, SLEEP_ANIMATION_SPEED = 25, DEATH_ANIMATION_SPEED = 10; + + public void runAnimations() { + switch(currentAnimation){ + case idleWalk: idleWalks[facing - 1].runAnimation(); break; + case idle1: idle1[facing - 1].runAnimation(); break; + case runAway: runAway[facing - 1].runAnimation(); break; + case sleep: sleep[facing -1].runAnimation(); break; + default: break; + } + } + + private static BufferedImage[] GET_HITS = { + Textures.rabbitSheet[136], + Textures.rabbitSheet[137], + Textures.rabbitSheet[138], + Textures.rabbitSheet[139], + Textures.rabbitSheet[140], + Textures.rabbitSheet[141], + Textures.rabbitSheet[142], + Textures.rabbitSheet[143] + }; + + private Animation[] idleWalks = { + new Animation(IDLE_WALK_ANIMATION_SPEED, Textures.rabbitSheet[0], Textures.rabbitSheet[1], Textures.rabbitSheet[2], Textures.rabbitSheet[3]), // SOUTH -- FACING = 5 + new Animation(IDLE_WALK_ANIMATION_SPEED, Textures.rabbitSheet[20], Textures.rabbitSheet[21], Textures.rabbitSheet[22], Textures.rabbitSheet[23]), // NE -- FACING = 2 + new Animation(IDLE_WALK_ANIMATION_SPEED, Textures.rabbitSheet[12], Textures.rabbitSheet[13], Textures.rabbitSheet[14], Textures.rabbitSheet[15]), // EAST -- FACING = 3 + new Animation(IDLE_WALK_ANIMATION_SPEED, Textures.rabbitSheet[28], Textures.rabbitSheet[29], Textures.rabbitSheet[30], Textures.rabbitSheet[31]), // SE -- FACING = 4 + new Animation(IDLE_WALK_ANIMATION_SPEED, Textures.rabbitSheet[4], Textures.rabbitSheet[5], Textures.rabbitSheet[6], Textures.rabbitSheet[7]), // NORTH -- FACING = 1 + new Animation(IDLE_WALK_ANIMATION_SPEED, Textures.rabbitSheet[24], Textures.rabbitSheet[25], Textures.rabbitSheet[26], Textures.rabbitSheet[27]), // SW -- FACING = 6 + new Animation(IDLE_WALK_ANIMATION_SPEED, Textures.rabbitSheet[8], Textures.rabbitSheet[9], Textures.rabbitSheet[10], Textures.rabbitSheet[11]), // WEST -- FACING = 7 + new Animation(IDLE_WALK_ANIMATION_SPEED, Textures.rabbitSheet[16], Textures.rabbitSheet[17], Textures.rabbitSheet[18], Textures.rabbitSheet[19]) // NW -- FACING = 8 + }; + + private Animation[] idle1 = { + new Animation(IDLE_EAT_GROUND_ANIMATION_SPEED, Textures.rabbitSheet[32], Textures.rabbitSheet[33], Textures.rabbitSheet[34], Textures.rabbitSheet[35]), // SOUTH -- FACING = 5 + new Animation(IDLE_EAT_GROUND_ANIMATION_SPEED, Textures.rabbitSheet[52], Textures.rabbitSheet[53], Textures.rabbitSheet[54], Textures.rabbitSheet[55]), // NE -- FACING = 2 + new Animation(IDLE_EAT_GROUND_ANIMATION_SPEED, Textures.rabbitSheet[44], Textures.rabbitSheet[45], Textures.rabbitSheet[46], Textures.rabbitSheet[47]), // EAST -- FACING = 3 + new Animation(IDLE_EAT_GROUND_ANIMATION_SPEED, Textures.rabbitSheet[60], Textures.rabbitSheet[61], Textures.rabbitSheet[62], Textures.rabbitSheet[63]), // SE -- FACING = 4 + new Animation(IDLE_EAT_GROUND_ANIMATION_SPEED, Textures.rabbitSheet[36], Textures.rabbitSheet[37], Textures.rabbitSheet[38], Textures.rabbitSheet[39]), // NORTH -- FACING = 1 + new Animation(IDLE_EAT_GROUND_ANIMATION_SPEED, Textures.rabbitSheet[56], Textures.rabbitSheet[57], Textures.rabbitSheet[58], Textures.rabbitSheet[59]), // SW -- FACING = 6 + new Animation(IDLE_EAT_GROUND_ANIMATION_SPEED, Textures.rabbitSheet[40], Textures.rabbitSheet[41], Textures.rabbitSheet[42], Textures.rabbitSheet[43]), // WEST -- FACING = 7 + new Animation(IDLE_EAT_GROUND_ANIMATION_SPEED, Textures.rabbitSheet[48], Textures.rabbitSheet[49], Textures.rabbitSheet[50], Textures.rabbitSheet[51]) // NW -- FACING = 8 + }; + + private Animation[] runAway = { + new Animation(RUN_AWAY_ANIMATION_SPEED, Textures.rabbitSheet[64], Textures.rabbitSheet[65], Textures.rabbitSheet[66], Textures.rabbitSheet[67]), //SOUTH -- FACING = 5 + new Animation(RUN_AWAY_ANIMATION_SPEED, Textures.rabbitSheet[84], Textures.rabbitSheet[85], Textures.rabbitSheet[86], Textures.rabbitSheet[87]), //NE -- FACING = 2 + new Animation(RUN_AWAY_ANIMATION_SPEED, Textures.rabbitSheet[76], Textures.rabbitSheet[77], Textures.rabbitSheet[78], Textures.rabbitSheet[79]), //EAST -- FACING = 3 + new Animation(RUN_AWAY_ANIMATION_SPEED, Textures.rabbitSheet[92], Textures.rabbitSheet[93], Textures.rabbitSheet[94], Textures.rabbitSheet[95]), //SE -- FACING = 4 + new Animation(RUN_AWAY_ANIMATION_SPEED, Textures.rabbitSheet[68], Textures.rabbitSheet[69], Textures.rabbitSheet[70], Textures.rabbitSheet[71]), //NORTH -- FACING = 1 + new Animation(RUN_AWAY_ANIMATION_SPEED, Textures.rabbitSheet[88], Textures.rabbitSheet[89], Textures.rabbitSheet[90], Textures.rabbitSheet[91]), //SW -- FACING = 6 + new Animation(RUN_AWAY_ANIMATION_SPEED, Textures.rabbitSheet[72], Textures.rabbitSheet[73], Textures.rabbitSheet[74], Textures.rabbitSheet[75]), //WEST -- FACING = 7 + new Animation(RUN_AWAY_ANIMATION_SPEED, Textures.rabbitSheet[80], Textures.rabbitSheet[81], Textures.rabbitSheet[82], Textures.rabbitSheet[83]) //NW -- FACING = 8 + }; + + private Animation[] sleep = { + new Animation(SLEEP_ANIMATION_SPEED, Textures.rabbitSheet[96], Textures.rabbitSheet[97]), // SOUTH -- FACING = 5 + new Animation(SLEEP_ANIMATION_SPEED, Textures.rabbitSheet[106], Textures.rabbitSheet[107]), //NE -- FACING = 2 + new Animation(SLEEP_ANIMATION_SPEED, Textures.rabbitSheet[102], Textures.rabbitSheet[103]), // EAST -- FACING = 3 + new Animation(SLEEP_ANIMATION_SPEED, Textures.rabbitSheet[110], Textures.rabbitSheet[111]), // SE -- FACING = 4 + new Animation(SLEEP_ANIMATION_SPEED, Textures.rabbitSheet[98], Textures.rabbitSheet[99]), // NORTH -- FACING = 1 + new Animation(SLEEP_ANIMATION_SPEED, Textures.rabbitSheet[108], Textures.rabbitSheet[109]), //SW -- FACING = 6 + new Animation(SLEEP_ANIMATION_SPEED, Textures.rabbitSheet[100], Textures.rabbitSheet[101]), // WEST -- FACING = 7 + new Animation(SLEEP_ANIMATION_SPEED, Textures.rabbitSheet[104], Textures.rabbitSheet[105]) //NW -- FACING = 8 + }; + + + private Animation[] death = { + new Animation(DEATH_ANIMATION_SPEED, Textures.rabbitSheet[112], Textures.rabbitSheet[113], Textures.rabbitSheet[114]), + new Animation(DEATH_ANIMATION_SPEED, Textures.rabbitSheet[124], Textures.rabbitSheet[125], Textures.rabbitSheet[126]), + new Animation(DEATH_ANIMATION_SPEED, Textures.rabbitSheet[121], Textures.rabbitSheet[122], Textures.rabbitSheet[123]), + new Animation(DEATH_ANIMATION_SPEED, Textures.rabbitSheet[133], Textures.rabbitSheet[134], Textures.rabbitSheet[135]), + new Animation(DEATH_ANIMATION_SPEED, Textures.rabbitSheet[115], Textures.rabbitSheet[116], Textures.rabbitSheet[117]), + new Animation(DEATH_ANIMATION_SPEED, Textures.rabbitSheet[130], Textures.rabbitSheet[131], Textures.rabbitSheet[132]), + new Animation(DEATH_ANIMATION_SPEED, Textures.rabbitSheet[118], Textures.rabbitSheet[119], Textures.rabbitSheet[120]), + new Animation(DEATH_ANIMATION_SPEED, Textures.rabbitSheet[127], Textures.rabbitSheet[128], Textures.rabbitSheet[129]) + }; +/******************************************************************************************************************************************************************************/ + +} diff --git a/src/player/HealthAndDurability.java b/src/player/HealthAndDurability.java new file mode 100755 index 0000000..5f530ca --- /dev/null +++ b/src/player/HealthAndDurability.java @@ -0,0 +1,51 @@ +package player; + +import hud.Clock; +import interfaces.ItemIDs; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class HealthAndDurability implements ItemIDs { + + private static int torchTimer; + + public static final void tick(){ + + // UPDATE FIRE-BASED DURABILTIES + switch(Player.equipmentSlots[HAND_SLOT].itemId) { + + case TORCH: if(++torchTimer > (Clock.NIGHT_DURATION * 0.75f) / 200){ + Player.equipmentSlots[HAND_SLOT].durability -= 0.5f; + torchTimer = 0; } break; + } + + } + + // SUBTRACT FROM PLAYER HEALTH AND START THE GET-HIT ANIMATION + private static final int GET_HIT_TIMER_AMOUNT = 20; + public static final float hurtPlayer(float damage) { + + // manipulate damage based on currently worn armour + + Player.health -= damage; + + // subtract durabilities from aromurs here + + // START GET-HIT ANIMATION + if(Player.getHitTimer <= 0) Player.getHitTimer = GET_HIT_TIMER_AMOUNT; + + // return the player health just for convenience sake + return Player.health; + } + + public static final void HIT_MOB() { + switch(Player.equipmentSlots[HAND_SLOT].itemId) { + case CRUDE_AXE: Player.equipmentSlots[HAND_SLOT].durability -= 2.5f; break; + case CRUDE_PICKAXE: Player.equipmentSlots[HAND_SLOT].durability -= 2.5f; break; + case GOBLIN_SPEAR: Player.equipmentSlots[HAND_SLOT].durability -= 7.5f; break; + } + } + +} diff --git a/src/player/MouseMovement.java b/src/player/MouseMovement.java new file mode 100755 index 0000000..49fd3d1 --- /dev/null +++ b/src/player/MouseMovement.java @@ -0,0 +1,44 @@ +package player; + +import engine.Game; +import engine.MouseInput; +import hud.RightClickMenu; +import hud.constructionmenu.ConstructionItem; +import interfaces.Directions; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class MouseMovement implements Directions { + + public static double tempX, tempY, angle; + + public static boolean PLACING_STRUCTURE; + + public final static void runMouseMovement() { + if (!Player.collided && (Player.keepWalkingX || Player.keepWalkingY)) { + + // MOVE TOWARDS CLICK POINT + angle = Math.atan2(MouseInput.adjustedClickPos.y - Player.center.y, MouseInput.adjustedClickPos.x - Player.center.x); + Player.velX = (float)((Math.cos(angle) * Player.WALKING_SPEED) * Utils.sqrtOf2); + Player.velY = (float)((Math.sin(angle) * Player.WALKING_SPEED) * Utils.sqrtOf2); + + // FACING /* if not auto-following do to a right-click attack, else it is calc'd in RightClickMenu.tick(); */ + if(!RightClickMenu.OVERRIDE_F){ + int temp = Utils.direction(MouseInput.adjustedClickPos.x, MouseInput.adjustedClickPos.y, Player.center.x, Player.center.y) + (Game.rotation - 1); + if (temp > 8) temp -= 8; + Player.facing = temp; + } + + // STOP THE PLAYER WHEN INTERSECTS THE CLICK POINT + if(Player.bounds.contains(MouseInput.adjustedClickPos)){ + if(PLACING_STRUCTURE){ ConstructionItem.placeStructure(); } + /* note the refunding of items on key movement has been moved to MouseInput.tick() */ + PLACING_STRUCTURE = Player.keepWalkingX = Player.keepWalkingY = false; + } + } + } + +} \ No newline at end of file diff --git a/src/player/Player.java b/src/player/Player.java new file mode 100755 index 0000000..e3b58c3 --- /dev/null +++ b/src/player/Player.java @@ -0,0 +1,39 @@ +package player; + +import java.awt.Rectangle; + +import hud.inventory.InventorySlot; +import lighting.RadialLight; +import utils.Circle; +import utils.Point2f; +import utils.Stack; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class Player { + + public static final int width = 20, height = 36, discoveryRadius = 475; + public static final float radius = width / 2.75f; + public static float velX, velY, weight, WALKING_SPEED = 1.75f, RUNNING_SPEED = 2.75f, currentDamage; + public static int health = 100, maximumHealth = 100, currentAnimation, facing = 5, getHitTimer; + public static boolean keepWalkingX, keepWalkingY, attacking, using, hasBackpack, collided, animate = true; + + public static volatile InventorySlot[] inventorySlots, tabSlots, equipmentSlots; + + public static final Rectangle bounds = new Rectangle(0, 0, 20, 36); + public static Point2f center = new Point2f(0, 0); + public static Point2f pos = new Point2f(0,0); + + // COLLIDEDS + public static boolean treeCollided, boulderCollided, flowerCollided, grassCollided, droppedItemCollided, + saplingCollided; + + public static final Stack playerLights = new Stack(); + public static final RadialLight torchLight = new RadialLight(new Point2f(0,0), 50, 0.475f); + + public static final Circle attackBounds = new Circle(new Point2f(0,0), 0f); + public static final Circle DISCOVERY = new Circle(center, discoveryRadius); + +} diff --git a/src/player/PlayerAttackSequence.java b/src/player/PlayerAttackSequence.java new file mode 100755 index 0000000..042cbef --- /dev/null +++ b/src/player/PlayerAttackSequence.java @@ -0,0 +1,244 @@ +package player; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import animations.PlayerAttackAnimations; +import engine.Game; +import engine.Handler; +import interfaces.Directions; +import interfaces.ItemIDs; +import interfaces.Mob; +import utils.Animation; +import utils.Stack; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerAttackSequence implements ItemIDs, Directions { + // NOTE: hitbox is actually a hit-circle + + /* GOALS: + * + * 0) --- axioms --- + * 0a) player is holding a weapon that can be used to attack --- check + * 0b) player is not already undergoing an attack ---- (timer is not == 0) + * 1) Begin the animation sequence -- (start) + * 1a) calculate the damage that should be used + * 1b) calculate which base animation to play + set the timer to its length + * 1c) set the player's attacking boolean to true + * 1d) calculate the timer delay before the hitbox appears + * 1e) calculate the size the hitbox should be + * 2) Tick and Render the current animation until the timer is up. + * 2a) move the hitbox infront of the player in the correct direction of facing + * 2b) according to the 'currentWeapon' tick the correct animation + * 2c) " " ---- render said animation + * 2d) when timer is up, reset all variables, reset animation, set Player.attacking to false; + */ + + // ANIMATIONS: + private static int currentWeapon; + + public static volatile long timer; + + private static final int ATTACK_COOLDOWN_TIMER_AMOUNT = 10; + public static int ATTACK_COOLDOWN_TIMER; + + public final static void start(){ + if(Player.attacking || ATTACK_COOLDOWN_TIMER > 0) return; + Player.currentDamage = calcWeaponDamage(); + if(Player.currentDamage <= 0) return; /* 0 because is not holding a valid weapon */ + currentWeapon = calcAnimationType(); /* also sets the correct timer amount */ + Player.attacking = true; + hitMobs.clear(); + } + + + public final static void tick() { + if(!Player.attacking) return; + Player.using = false; + + moveHitbox(); + + tickAnimations(); + + if(--timer <= 0) { + Player.attacking = false; + Player.currentDamage = 0; + ATTACK_COOLDOWN_TIMER = ATTACK_COOLDOWN_TIMER_AMOUNT; + // substract durability + for(final Animation a : PlayerAttackAnimations.basePlayerAttack) a.restartAnimation(); + for(final Animation a : PlayerAttackAnimations.crudeAxeAttack) a.restartAnimation(); + for(final Animation a : PlayerAttackAnimations.crudePickAxeAttack) a.restartAnimation(); + for(final Animation a : PlayerAttackAnimations.goblinSpearAttack) a.restartAnimation(); + return; + } + + if(currentWeapon != Player.equipmentSlots[HAND_SLOT].itemId) timer = 0; /* this happens if player unequips item mid-swing, stop animation */ + + combat(); + } + + public static final Stack hitMobs = new Stack(); + private static final void combat() { + // LOOP THROUGH ALL MOBS, THEN CALL THEIR HIT-BY-PLAYER-METHOD + // IF THE MOB HAS ALREADY BEEN HIT, DONT HIT AGAIN + for(Mob m : Handler.mobs) { + if(!hitMobs.contains(m) && Utils.intersects(Player.attackBounds, m.center, m.radius)){ + m.HIT_BY_PLAYER(); + hitMobs.add(m); + } + } + } + + private static final void moveHitbox(){ + // MAKE THE ATTACK BOUNDS UNUSABLE UNTIL A CERTAIN DELAY + // NOTE THE NUMBER IS YOUR TIMER AMOUNT + if(timer < 28 * 0.75f) Player.attackBounds.center.x = Player.attackBounds.center.y = -99999999; + + + + // FIRST SWITCH = ANIMATION TYPE ----- SECOND SWITCH = ROTATION, THIRD = FACING + + int x = (int)Player.center.x; + int y = (int)Player.center.y; + + switch(Game.rotation){ + case 1: { switch(Player.facing){ + case NORTH:{ x+=0; y-=6; break; } + case NORTHEAST:{ x+=8; y+=2; break; } + case EAST:{ x+=5; y+=3; break; } + case SOUTHEAST:{ x+=1; y+=20; break; } + case SOUTH:{ x-=6; y+=15; break; } + case SOUTHWEST:{ x-=5; y+=12; break; } + case WEST:{ x-=10; y+=4; break; } + case NORTHWEST:{ x-=5; y-=3; break; } + } break; } + case 2:{ switch(Player.facing){ + case 1:{ x-=2; y-=5; break; } + case 2:{ x+=7; y-=4; break; } + case 3:{ x+=6; y-=1; break; } + case 4:{ x+=15; y+=13; break; } + case 5:{ x+=6; y+=16; break; } + case 6:{ x+=5; y+=13; break; } + case 7:{ x-=5; y+=11; break; } + case 8:{ x-=7; y+=2; break; } + } break; } + case 3:{ switch(Player.facing){ + case 1:{ x-=5; y-=0; break; } + case 2:{ x+=3; y-=7; break; } + case 3:{ x+=3; y-=4; break; } + case 4:{ x+=19; y-=1; break; } + case 5:{ x+=15; y+=8; break; } + case 6:{ x+=11; y+=8; break; } + case 7:{ x+=4; y+=12; break; } + case 8:{ x-=4; y+=6; break; } + } break; } + case 4:{ switch(Player.facing){ + case 1:{ x-=5; y+=5; break; } + case 2:{ x-=3; y-=6; break; } + case 3:{ x-=1; y-=4; break; } + case 4:{ x+=14; y-=14; break; } + case 5:{ x+=16; y-=4; break; } + case 6:{ x+=13; y-=2; break; } + case 7:{ x+=10; y+=7; break; } + case 8:{ x+=3; y+=7; break; } + } break; } + case 5:{ switch(Player.facing){ + case 1:{ x-=0; y+=8; break; } + case 2:{ x-=7; y-=2; break; } + case 3:{ x-=4; y-=2; break; } + case 4:{ x-=1; y-=20; break; } + case 5:{ x+=8; y-=14; break; } + case 6:{ x+=8; y-=11; break; } + case 7:{ x+=12; y-=1; break; } + case 8:{ x+=7; y+=4; break; } + } break; } + case 6:{ switch(Player.facing){ + case 1:{ x+=6; y+=6; break; } + case 2:{ x-=6; y+=4; break; } + case 3:{ x-=5; y+=1; break; } + case 4:{ x-=14; y-=13; break; } + case 5:{ x-=5; y-=15; break; } + case 6:{ x-=2; y-=12; break; } + case 7:{ x+=7; y-=9; break; } + case 8:{ x+=7; y-=2; break; } + } break; } + case 7:{ switch(Player.facing){ + case 1:{ x+=8; y+=0; break; } + case 2:{ x-=1; y+=8; break; } + case 3:{ x-=3; y+=5; break; } + case 4:{ x-=20; y+=1; break; } + case 5:{ x-=14; y-=6; break; } + case 6:{ x-=11; y-=6; break; } + case 7:{ x-=1; y-=11; break; } + case 8:{ x+=4; y-=5; break; } + } break; } + case 8:{ switch(Player.facing){ + case 1:{ x+=5; y-=4; break; } + case 2:{ x+=4; y+=6; break; } + case 3:{ x+=1; y+=6; break; } + case 4:{ x-=14; y+=15; break; } + case 5:{ x-=15; y+=7; break; } + case 6:{ x-=13; y+=5; break; } + case 7:{ x-=10; y-=4; break; } + case 8:{ x-=1; y-=7; break; } + } break; } + } + + Player.attackBounds.center.x = x; + Player.attackBounds.center.y = y; + } + + private static Graphics2D copy; private static AffineTransform transform = new AffineTransform(); + public final static void render(Graphics2D g2d){ + transform.setToRotation(-Utils._45 * (Game.rotation - 1), Player.center.x, Player.center.y); copy = (Graphics2D) g2d.create(); copy.transform(transform); + + // draw the base animation --- TODO: you will need to switch these around for other animations + + PlayerAttackAnimations.basePlayerAttack[Player.facing - 1].drawAnimation(copy, Player.pos.x - Player.width/2, Player.pos.y - Player.height/2); + + switch(currentWeapon) { /* will be the itemId of the current weapon */ + case CRUDE_AXE: { PlayerAttackAnimations.crudeAxeAttack[Player.facing - 1].drawAnimation(copy, Player.pos.x - Player.width/2, Player.pos.y - Player.height/2); break; } + case CRUDE_PICKAXE: { PlayerAttackAnimations.crudePickAxeAttack[Player.facing -1].drawAnimation(copy, Player.pos.x - Player.width/2, Player.pos.y - Player.height/2); break; } + case GOBLIN_SPEAR: { PlayerAttackAnimations.goblinSpearAttack[Player.facing - 1].drawAnimation(copy, Player.pos.x - Player.width/2, Player.pos.y - Player.height/2); break; } + } + + if(Game.drawPlayerAttackBounds){ + g2d.setColor(Color.red); + g2d.drawOval((int)(Player.attackBounds.center.x-Player.attackBounds.radius), (int)(Player.attackBounds.center.y-Player.attackBounds.radius), (int)Player.attackBounds.radius*2, (int)Player.attackBounds.radius*2); + } + copy.dispose(); copy = null; + } + + private static final void tickAnimations() { + for(final Animation a : PlayerAttackAnimations.basePlayerAttack) a.runAnimation(); + + switch(currentWeapon) { + case CRUDE_AXE: { for(final Animation a : PlayerAttackAnimations.crudeAxeAttack) a.playAnimationOnce(); break; } + case CRUDE_PICKAXE: { for(final Animation a : PlayerAttackAnimations.crudePickAxeAttack) a.playAnimationOnce(); break; } + case GOBLIN_SPEAR: { for(final Animation a : PlayerAttackAnimations.goblinSpearAttack) a.playAnimationOnce(); break; } + } + } + + private static final int ATTACK_BOUNDS_RADIUS = 7; + private final static float calcWeaponDamage() { + // change based on weapon + Player.attackBounds.radius = ATTACK_BOUNDS_RADIUS; + + switch(Player.equipmentSlots[HAND_SLOT].itemId) { + case CRUDE_AXE: return 5; // crude axe + case CRUDE_PICKAXE: return 6; // crude pickaxe + case GOBLIN_SPEAR: return 6.75f; // goblin spear + default: return 0; + } + } + + private final static int calcAnimationType(){ + timer = 28; /* needs to be the speed * number of frames in animation */ + return Player.equipmentSlots[HAND_SLOT].itemId; + } +} diff --git a/src/player/PlayerCollision.java b/src/player/PlayerCollision.java new file mode 100755 index 0000000..d8bf719 --- /dev/null +++ b/src/player/PlayerCollision.java @@ -0,0 +1,77 @@ +package player; + +import java.util.ConcurrentModificationException; + +import engine.Camera; +import engine.Handler; +import utils.Point2f; +import utils.Utils; +import world.Boulder; +import world.DroppedItem; +import world.Flower; +import world.Sapling; +import world.TallGrass; +import world.Tree; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +final class PlayerCollision { + + private static float diffX, diffY; + + private static final boolean calcCollision(boolean stopPlayer, Point2f p, float r) { + if (Utils.intersects(Player.center, Player.radius, p, r)) { + diffX = Utils.abs(Player.center.x - p.x); + diffY = Utils.abs(Player.center.y - p.y); + + if (Player.center.x > p.x) { + if (stopPlayer) { + Player.pos.x += diffX/20; + Player.velX = 0; + } + } else if (Player.center.x < p.x) { + if (stopPlayer) { + Player.pos.x -= diffX/20; + Player.velX = 0; + } + } + if (Player.center.y > p.y) { + if (stopPlayer) { + Player.pos.y += diffY/20; + Player.velY = 0; + } + } else if (Player.center.y < p.y) { + if (stopPlayer) { + Player.pos.y -= diffY/20; + Player.velY = 0; + } + } + if(stopPlayer) Camera.tick(); + return true; + } + return false; + } + + public static final boolean collision() { + try { + + // PLAYER COLLIDED's + for (final Flower i : Handler.flowers) if (i.alive && calcCollision(false, i.center, i.radius)){ i.playerCollided = Player.flowerCollided = true; break; } else i.playerCollided = Player.flowerCollided = false; + for (final TallGrass i : Handler.grass) if (i.alive && calcCollision(false, i.center, i.radius)) { i.playerCollided = Player.grassCollided = true; break; } else i.playerCollided = Player.grassCollided = false; + for (final Sapling i : Handler.saplings) if(calcCollision(false, i.center, i.radius)){ i.playerCollided = Player.saplingCollided = true; break;} else i.playerCollided = Player.saplingCollided = false; + for (final DroppedItem i : Handler.droppedItems) if (calcCollision(false, i.center, i.radius)){ i.playerCollided = Player.droppedItemCollided = true; break;} else i.playerCollided = Player.droppedItemCollided = false; + for (final Tree i : Handler.trees) if (i.alive && calcCollision(false, i.center, i.chopRadius)) { i.playerCollided = Player.treeCollided = true; break; } else i.playerCollided = Player.treeCollided = false; + for (final Boulder i : Handler.boulders) if (i.alive && calcCollision(false, i.center, i.mineRadius)) { i.playerCollided = Player.boulderCollided = true; break; } else i.playerCollided = Player.boulderCollided = false; + + // SOLID OBJECTS + for (final Tree i : Handler.trees) if (i.alive && calcCollision(true, i.center, i.radius)) return true; + for (final Boulder i : Handler.boulders) if (i.alive && calcCollision(true, i.center, i.radius)) return true; + + } catch (ConcurrentModificationException cme ) {} + + return false; /* if no solid objects have been hit and returned true, return false */ + } + +} diff --git a/src/player/PlayerDeath.java b/src/player/PlayerDeath.java new file mode 100755 index 0000000..d2864d7 --- /dev/null +++ b/src/player/PlayerDeath.java @@ -0,0 +1,43 @@ +package player; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import animations.PlayerAnimations; +import engine.Game; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerDeath { + + private static int DEATH_ANIMATION_DELAY; + public static boolean RUNNING; + + public static final void START() { + RUNNING = true; + final int seconds = 60; + DEATH_ANIMATION_DELAY = seconds * 5; + } + + public static void tick() { + PlayerAnimations.deaths[Player.facing - 1].playAnimationOnce(); + if(--DEATH_ANIMATION_DELAY < 0) END_DEATH(); + } + + private static Graphics2D copy; private static final AffineTransform transform = new AffineTransform(); + public static void render(final Graphics2D g2d) { + transform.setToRotation(-Utils._45 * (Game.rotation - 1), Player.center.x, Player.center.y); copy = (Graphics2D) g2d.create(); copy.transform(transform); + PlayerAnimations.deaths[Player.facing - 1].drawAnimation(copy, Player.pos.x - Player.width/2, Player.pos.y - Player.height/2); + copy.dispose(); copy = null; + } + + private static final void END_DEATH() { + RUNNING = false; + //display message, delete save, etc etc. + System.out.println("YOU DIED!"); + } + +} diff --git a/src/player/PlayerPosition.java b/src/player/PlayerPosition.java new file mode 100755 index 0000000..b07e078 --- /dev/null +++ b/src/player/PlayerPosition.java @@ -0,0 +1,74 @@ +package player; + +import engine.Game; +import engine.Handler; +import hud.RightClickMenu; +import interfaces.Directions; +import utils.Utils; +import world.Tile; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + + +final class PlayerPosition implements Directions { + + private static final float SNOW_SPEED_REDUCTION = 0.75f; + private static float tempX, tempY; + + public final static void update() { + if (!Player.collided) { + if (Player.velX != 0 && Player.velY != 0){ Player.velX /= Utils.sqrtOf2; Player.velY /= Utils.sqrtOf2; } + + if(!Player.keepWalkingX && !Player.keepWalkingY && !RightClickMenu.OVERRIDE_F && !RightClickMenu.OVERRIDE_SPACE){ /* ie if not doing mouse-movement */ + + if (Player.velX == 0 && Player.velY < 0) Player.facing = NORTH; + else if (Player.velX == 0 && Player.velY > 0) Player.facing = SOUTH; + else if (Player.velX > 0 && Player.velY == 0) Player.facing = EAST; + else if (Player.velX < 0 && Player.velY == 0) Player.facing = WEST; + else if (Player.velX > 0 && Player.velY > 0) Player.facing = SOUTHEAST; + else if (Player.velX < 0 && Player.velY < 0) Player.facing = NORTHWEST; + else if (Player.velX > 0 && Player.velY < 0) Player.facing = NORTHEAST; + else if (Player.velX < 0 && Player.velY > 0) Player.facing = SOUTHWEST; + + + tempX = (float) Utils.rotateX(Player.velX, Player.velY, (Game.rotation - 1) * -Utils._45); + tempY = (float) Utils.rotateY(Player.velX, Player.velY, (Game.rotation - 1) * -Utils._45); + + if(!Game.noClip) + outerLoop1: + for(Tile i : Handler.currentTileSection(Player.center.x, Player.center.y)) { + switch(i.biome){ + case Tile.OCEAN: { if(i.getBounds().contains(Player.center.x + tempX, Player.center.y + tempY)){ Player.collided = true; break outerLoop1; }} + case Tile.LAKE: { if(i.getBounds().contains(Player.center.x + tempX, Player.center.y + tempY)){ Player.collided = true; break outerLoop1; }} + case Tile.RIVER: { if(i.getBounds().contains(Player.center.x + tempX, Player.center.y + tempY)){ Player.collided = true; break outerLoop1; }} + case Tile.SNOW_TUNDA: { if(i.getBounds().contains(Player.center.x, Player.center.y)){tempX *= SNOW_SPEED_REDUCTION; tempY *= SNOW_SPEED_REDUCTION; break outerLoop1; }} + } + } + + if(!Player.collided) { Player.velX = tempX; Player.velY = tempY; } + } else { + + if(!Game.noClip) + outerLoop2: + for(Tile i : Handler.currentTileSection(Player.center.x, Player.center.y)) { + switch(i.biome){ + case Tile.OCEAN: { if(i.getBounds().contains(Player.center.x + Player.velX, Player.center.y + Player.velY)){ Player.collided = true; break outerLoop2; }} + case Tile.LAKE: { if(i.getBounds().contains(Player.center.x + Player.velX, Player.center.y + Player.velY)) { Player.collided = true; break outerLoop2; }} + case Tile.RIVER: { if(i.getBounds().contains(Player.center.x + Player.velX, Player.center.y + Player.velY)){ Player.collided = true; break outerLoop2; }} + case Tile.SNOW_TUNDA: { if(i.getBounds().contains(Player.center.x, Player.center.y)){Player.velX *= SNOW_SPEED_REDUCTION; Player.velY *= SNOW_SPEED_REDUCTION; break outerLoop2; }} + } + } + } + + if(!Player.collided) { Player.pos.x += Player.velX; Player.pos.y += Player.velY; } + } + + Player.center.x = Player.pos.x + Player.width * 0.5f; + Player.center.y = Player.pos.y + Player.height * 0.5f; + + Player.bounds.x = (int) Player.pos.x; + Player.bounds.y = (int) Player.pos.y; + } +} diff --git a/src/player/PlayerRender.java b/src/player/PlayerRender.java new file mode 100755 index 0000000..6d30854 --- /dev/null +++ b/src/player/PlayerRender.java @@ -0,0 +1,60 @@ +package player; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import animations.PlayerAnimations; +import engine.Game; +import hud.inventory.InvenHelper; +import interfaces.PlayerAnimationIDs; +import rendercalculator.player.HandSlotRenderer; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerRender implements PlayerAnimationIDs { + + public static final int AMOUNT = 5; /* fast = 2, smooth = 4 */ + + private static Graphics2D copy; private static final AffineTransform transform = new AffineTransform(); + public static final void render(final Graphics2D g2d) { +// if (Game.dontDrawPlayer || !Player.animate) return; + + if(Player.health <= 0) { PlayerDeath.render(g2d); return; } + + if(Player.attacking) { PlayerAttackSequence.render(g2d); return; } + + transform.setToRotation(-Utils._45 * (Game.rotation - 1), Player.center.x, Player.center.y); copy = (Graphics2D) g2d.create(); copy.transform(transform); + + if (Game.drawCollisionBounds) { + g2d.setColor(Color.BLUE); + g2d.drawOval((int) (Player.center.x - Player.radius), (int) (Player.center.y - Player.radius), (int) Player.radius * 2, (int) Player.radius * 2); + g2d.setColor(Color.BLUE); + g2d.draw(Player.bounds); + } + + drawAnimation(copy); /* BASE PLAYER ANIMATION */ + drawEquippedItems(copy); + + copy.dispose(); copy = null; + } + + private static final void drawAnimation(final Graphics2D copy) { + switch (Player.currentAnimation) { + case IDLE: PlayerAnimations.base.renderIdle(copy); break; + case WALK: PlayerAnimations.base.renderWalk(copy); break; + case AXE_CHOP: PlayerAnimations.base.renderChop(copy); break; + case MINE_ROCK: PlayerAnimations.base.renderMine(copy); break; + case GET_HIT: PlayerAnimations.base.renderGetHit(copy); break; + } + } + + private static final void drawEquippedItems(final Graphics2D copy){ + try{ if(Player.equipmentSlots[InvenHelper.HAND_SLOT].itemId != InvenHelper.NULL_ITEM) HandSlotRenderer.render(copy); + } catch(ArrayIndexOutOfBoundsException e){ // must catch these + } + } +} diff --git a/src/player/PlayerTick.java b/src/player/PlayerTick.java new file mode 100755 index 0000000..4c7703e --- /dev/null +++ b/src/player/PlayerTick.java @@ -0,0 +1,90 @@ +package player; + +import animations.PlayerAnimationUtils; +import animations.PlayerAnimations; +import engine.Game; +import hud.inventory.InvenHelper; +import interfaces.ItemIDs; +import interfaces.PlayerAnimationIDs; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class PlayerTick implements PlayerAnimationIDs, ItemIDs { + + public static final void tick() { + //*********** DEBUG STUFF **************// + if(Game.godMode) Player.health = 100; + //*************************************// + + // CALC COLLISION + if (!Game.noClip) Player.collided = PlayerCollision.collision(); + + // ------ CLAMP PLAYER HEALTH -----------------------------------------------// + Player.health = Utils.clamp(Player.health, 0, Player.maximumHealth); + // ----- RUN DEATH IF DEAD -------------------------------------------------// + if(Player.health <= 0) { if(!PlayerDeath.RUNNING) PlayerDeath.START(); PlayerDeath.tick(); return; } + + // ---- POSITION UPDATING ---------------------------// + if (!Player.collided) MouseMovement.runMouseMovement(); + else Player.keepWalkingX = Player.keepWalkingY = false; + PlayerPosition.update(); + // ----- END POSITION UPDATING ---------------------// + + // ----------- ATTACKING --------------------- // + if(Player.attacking) { PlayerAttackSequence.tick(); return; } + if(PlayerAttackSequence.ATTACK_COOLDOWN_TIMER > 0) PlayerAttackSequence.ATTACK_COOLDOWN_TIMER--; + // ---------- END ATTACKING -------------------// + + // --- CALC WHICH ANIMATION TO USE, THEN RUN THEM --- // + if(Player.animate) { + PlayerAnimationUtils.calc(); + runAnimation(); + runEquipmentAnimations(); + } + // ------- END ANIMATION CALC / RUN ---------------- // + + // ----------- reset animations --------------// + if(Player.velX == 0 && Player.velY == 0) PlayerAnimationUtils.resetWalking(); //TODO fix this, it will grow way too resource heavy + if (!(Player.treeCollided && Player.using && InvenHelper.isAxe(Player.equipmentSlots[HAND_SLOT].itemId))) PlayerAnimationUtils.resetAxeChops(); + if (!(Player.boulderCollided && Player.using && InvenHelper.isPickaxe(Player.equipmentSlots[HAND_SLOT].itemId))) PlayerAnimationUtils.resetPickaxeMines(); + // ---------- end animation resetting ---------// + } + + private static final void runAnimation() { + switch (Player.currentAnimation) { + case IDLE: PlayerAnimations.base.runIdle(); break; + case WALK: PlayerAnimations.base.runWalk(); break; + case AXE_CHOP: PlayerAnimations.base.runChop(); break; + case MINE_ROCK: PlayerAnimations.base.runMine(); break; + } + } + + private static final void runEquipmentAnimations() { + switch (Player.currentAnimation) { + case IDLE: { switch(Player.equipmentSlots[HAND_SLOT].itemId){ + case CRUDE_AXE: PlayerAnimations.crudeAxe.runIdle(); break; + case CRUDE_PICKAXE: PlayerAnimations.crudePickaxe.runIdle(); break; + case TORCH: PlayerAnimations.torch.runIdle(); break; + case GOBLIN_SPEAR: PlayerAnimations.goblinSpear.runIdle(); break; + }} break; + + case WALK: { switch(Player.equipmentSlots[HAND_SLOT].itemId){ + case CRUDE_AXE: PlayerAnimations.crudeAxe.runWalk(); break; + case CRUDE_PICKAXE: PlayerAnimations.crudePickaxe.runWalk(); break; + case TORCH: PlayerAnimations.torch.runWalk(); break; + case GOBLIN_SPEAR: PlayerAnimations.goblinSpear.runWalk(); break; + }} break; + + case AXE_CHOP: { switch(Player.equipmentSlots[HAND_SLOT].itemId){ + case CRUDE_AXE: PlayerAnimations.crudeAxe.runChop(); break; + }} break; + + case MINE_ROCK: { switch(Player.equipmentSlots[HAND_SLOT].itemId){ + case CRUDE_PICKAXE: PlayerAnimations.crudePickaxe.runMine(); break; + }} break; + } + } +} diff --git a/src/rendercalculator/player/HandSlotRenderer.java b/src/rendercalculator/player/HandSlotRenderer.java new file mode 100755 index 0000000..643f7f6 --- /dev/null +++ b/src/rendercalculator/player/HandSlotRenderer.java @@ -0,0 +1,64 @@ +package rendercalculator.player; + +import java.awt.Graphics2D; + +import animations.PlayerAnimations; +import interfaces.ItemIDs; +import interfaces.PlayerAnimationIDs; +import player.Player; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class HandSlotRenderer implements ItemIDs, PlayerAnimationIDs { + + public final static void render(final Graphics2D g2d){ + switch(Player.currentAnimation){ + case IDLE: idle(g2d); break; + case WALK: walk(g2d); break; + case AXE_CHOP: axeChop(g2d); break; + case MINE_ROCK: mine(g2d); + case GET_HIT: getHit(g2d); + } + } + + private final static void idle(final Graphics2D g2d){ + switch(Player.equipmentSlots[HAND_SLOT].itemId){ + case CRUDE_AXE: PlayerAnimations.crudeAxe.renderIdle(g2d); break; + case CRUDE_PICKAXE: PlayerAnimations.crudePickaxe.renderIdle(g2d); break; + case TORCH: PlayerAnimations.torch.renderIdle(g2d); break; + case GOBLIN_SPEAR: PlayerAnimations.goblinSpear.renderIdle(g2d); break; + } + } + + private final static void walk(final Graphics2D g2d){ + switch(Player.equipmentSlots[HAND_SLOT].itemId){ + case CRUDE_AXE: PlayerAnimations.crudeAxe.renderWalk(g2d); break; + case CRUDE_PICKAXE: PlayerAnimations.crudePickaxe.renderWalk(g2d); break; + case TORCH: PlayerAnimations.torch.renderWalk(g2d); break; + case GOBLIN_SPEAR: PlayerAnimations.goblinSpear.renderWalk(g2d); + } + } + + private static final void getHit(final Graphics2D g2d) { + switch(Player.equipmentSlots[HAND_SLOT].itemId) { + case CRUDE_AXE: PlayerAnimations.crudeAxe.renderGetHit(g2d); break; + case CRUDE_PICKAXE: PlayerAnimations.crudePickaxe.renderGetHit(g2d); break; + case TORCH: PlayerAnimations.torch.renderGetHit(g2d); break; + case GOBLIN_SPEAR: PlayerAnimations.goblinSpear.renderGetHit(g2d); break; + } + } + + private final static void axeChop(final Graphics2D g2d){ + switch(Player.equipmentSlots[HAND_SLOT].itemId){ + case CRUDE_AXE: PlayerAnimations.crudeAxe.renderChop(g2d); break; + } + } + + private final static void mine(final Graphics2D g2d){ + switch(Player.equipmentSlots[HAND_SLOT].itemId){ + case CRUDE_PICKAXE: PlayerAnimations.crudePickaxe.renderMine(g2d); break; + } + } +} \ No newline at end of file diff --git a/src/structures/Fire.java b/src/structures/Fire.java new file mode 100755 index 0000000..b7e14f3 --- /dev/null +++ b/src/structures/Fire.java @@ -0,0 +1,65 @@ +package structures; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import hud.Clock; +import interfaces.GameObject; +import interfaces.Structure; +import lighting.RadialLight; +import utils.Animation; +import utils.Point2f; +import utils.Utils; +import world.DroppedItem; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class Fire extends Structure implements GameObject { + + public static final int WIDTH = 22, HEIGHT = 22; + + private final Animation animation = new Animation(17, Textures.structureSheet[0], Textures.structureSheet[1],Textures.structureSheet[2],Textures.structureSheet[3],Textures.structureSheet[4],Textures.structureSheet[5]); + private RadialLight light; + + public Fire(Point2f center) { + super(8, center, WIDTH, HEIGHT); + light = new RadialLight(center, 100, 0.775f); + RadialLight.lights.add(light); + health = Clock.NIGHT_DURATION * 1.3f; + } + + public final synchronized void destroy() { + new DroppedItem(center, 9); + + // REMOVE THE FIRES LIGHT + RadialLight.lights.remove(light); + + Handler.structures.remove(this); + } + + public final void tick() { + animation.runAnimation(); + + if(--health <= 0) destroy(); + } + + private Graphics2D copy; + private AffineTransform transform = new AffineTransform(); + public final void render(Graphics2D g2d) { + copy = (Graphics2D) g2d.create(); transform.setToRotation(-Utils._45 * (Game.rotation - 1), center.x, center.y); copy.transform(transform); + + animation.drawAnimation(copy, pos.x, pos.y); + + + if(Game.drawCollisionBounds){ + g2d.setColor(Color.red); + g2d.drawOval((int)(center.x - radius), (int)(center.y - radius), (int)radius*2, (int)radius*2); + } + } +} diff --git a/src/textures/hud/HUDTextures.java b/src/textures/hud/HUDTextures.java new file mode 100755 index 0000000..d8e5f6c --- /dev/null +++ b/src/textures/hud/HUDTextures.java @@ -0,0 +1,24 @@ +package textures.hud; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class HUDTextures { + + public static void getTextures(BufferedImage image) { + Textures.hudSheet[0] = Utils.grabSprite(image, 1, 1, 750, 110); // BASE INVENTORY + Textures.hudSheet[1] = Utils.grabSprite(image, 7, 1, 140, 140); // CLOCK + Textures.hudSheet[2] = Utils.grabSprite(image, 73, 1, 11, 46); // CLOCK NEEDLE + Textures.hudSheet[3] = Utils.grabSprite(image, 1, 2, 750, 110); // HIGHLIGHT 1 INVENTORY + Textures.hudSheet[4] = Utils.grabSprite(image, 1, 3, 750, 110); // HIGHLIGHT 2 INVENTORY + Textures.hudSheet[5] = Utils.grabSprite(image, 1, 4, 750, 110); // HIGHLIGHT 3 INVENTORY + Textures.hudSheet[6] = Utils.grabSprite(image, 1, 5, 750, 110); // HIGHLIGHT 4 INVENTORY + Textures.hudSheet[7] = Utils.grabSprite(image, 1, 6, 750, 110); // HIGHLIGHT 5 INVENTORY + Textures.hudSheet[8] = Utils.grabSprite(image, 1, 7, 750, 110); // HIGHLIGHT 6 INVENTORY + Textures.hudSheet[9] = Utils.grabSprite(image, 1, 8, 750, 110); // HIGHLIGHT 7 INVENTORY + Textures.hudSheet[10] = Utils.grabSprite(image, 1, 9, 750, 110); // HIGHLIGHT 8 INVENTORY + } + +} diff --git a/src/textures/hud/SecondaryHUDTextures.java b/src/textures/hud/SecondaryHUDTextures.java new file mode 100755 index 0000000..1ef5d24 --- /dev/null +++ b/src/textures/hud/SecondaryHUDTextures.java @@ -0,0 +1,57 @@ +package textures.hud; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class SecondaryHUDTextures { + + public static void getTextures(BufferedImage image){ + Textures.secondaryHUDSheet[0] = Utils.grabSprite(image, 1, 1, 245, 320); + Textures.secondaryHUDSheet[1] = Utils.grabSprite(image, 6, 1, 50, 42); // grey + Textures.secondaryHUDSheet[2] = Utils.grabSprite(image, 6, 2, 50, 42); // sepia + Textures.secondaryHUDSheet[3] = Utils.grabSprite(image, 6, 3, 50, 42); // dark + Textures.secondaryHUDSheet[4] = Utils.grabSprite(image, 6, 4, 50, 42); // backpack icon + Textures.secondaryHUDSheet[5] = Utils.grabSprite(image, 6, 5, 50, 42); // equipment icon + Textures.secondaryHUDSheet[6] = Utils.grabSprite(image, 6, 6, 50, 42); // skills icon + Textures.secondaryHUDSheet[7] = Utils.grabSprite(image, 6, 7, 50, 42); // magic icon + Textures.secondaryHUDSheet[8] = Utils.grabSprite(image, 1, 7, 224, 56); // minimized + Textures.secondaryHUDSheet[9] = Utils.grabSprite(image, 1, 11, 50, 42); // Equipment Tab Blank Block + Textures.secondaryHUDSheet[10] = Utils.grabSprite(image, 2, 11, 50, 42); // Equipment Tab Highlighted Block + Textures.secondaryHUDSheet[11] = Utils.grabSprite(image, 1, 12, 50, 42); // Equipment Tab reg bag/cape + Textures.secondaryHUDSheet[12] = Utils.grabSprite(image, 4, 12, 50, 42); // Equipment Tab Highlighted bag/cape + Textures.secondaryHUDSheet[13] = Utils.grabSprite(image, 2, 12, 50, 42); // Equipment Tab reg helm + Textures.secondaryHUDSheet[14] = Utils.grabSprite(image, 5, 12, 50, 42); // Equipment Tab Highlighted helm + Textures.secondaryHUDSheet[15] = Utils.grabSprite(image, 3, 12, 50, 42); // Equipment Tab reg quiver + Textures.secondaryHUDSheet[16] = Utils.grabSprite(image, 6, 12, 50, 42); // Equipment Tab Highlighted quiver + Textures.secondaryHUDSheet[17] = Utils.grabSprite(image, 1, 13, 50, 42); // Equipment Tab reg handslot + Textures.secondaryHUDSheet[18] = Utils.grabSprite(image, 4, 13, 50, 42); // Equipment Tab Highlighted handlslot + Textures.secondaryHUDSheet[19] = Utils.grabSprite(image, 2, 13, 50, 42); // Equipment Tab reg chest + Textures.secondaryHUDSheet[20] = Utils.grabSprite(image, 5, 13, 50, 42); // Equipment Tab Highlighted chest + Textures.secondaryHUDSheet[21] = Utils.grabSprite(image, 3, 13, 50, 42); // Equipment Tab reg shield + Textures.secondaryHUDSheet[22] = Utils.grabSprite(image, 6, 13, 50, 42); // Equipment Tab Highlighted shield + Textures.secondaryHUDSheet[23] = Utils.grabSprite(image, 1, 14, 50, 42); // Equipment Tab reg gloves + Textures.secondaryHUDSheet[24] = Utils.grabSprite(image, 4, 14, 50, 42); // Equipment Tab Highlighted gloves + Textures.secondaryHUDSheet[25] = Utils.grabSprite(image, 2, 14, 50, 42); // Equipment Tab reg legs + Textures.secondaryHUDSheet[26] = Utils.grabSprite(image, 5, 14, 50, 42); // Equipment Tab Highlighted legs + Textures.secondaryHUDSheet[27] = Utils.grabSprite(image, 3, 14, 50, 42); // Equipment Tab reg amulet + Textures.secondaryHUDSheet[28] = Utils.grabSprite(image, 6, 14, 50, 42); // Equipment Tab Highlighted amulet + Textures.secondaryHUDSheet[29] = Utils.grabSprite(image, 1, 15, 50, 42); // Equipment Tab reg UNKNOWN + Textures.secondaryHUDSheet[30] = Utils.grabSprite(image, 4, 15, 50, 42); // Equipment Tab Highlighted UNKNOWN + Textures.secondaryHUDSheet[31] = Utils.grabSprite(image, 2, 15, 50, 42); // Equipment Tab reg boots + Textures.secondaryHUDSheet[32] = Utils.grabSprite(image, 5, 15, 50, 42); // Equipment Tab Highlighted boots + Textures.secondaryHUDSheet[33] = Utils.grabSprite(image, 3, 15, 50, 42); // Equipment Tab reg ring + Textures.secondaryHUDSheet[34] = Utils.grabSprite(image, 6, 15, 50, 42); // Equipment Tab Highlighted ring + Textures.secondaryHUDSheet[35] = Utils.grabSprite(image, 1, 19, 63, 37); // Equipment tab --- accurate reg + Textures.secondaryHUDSheet[36] = Utils.grabSprite(image, 1, 20, 63, 37); // Equipment tab --- accurate hovered + Textures.secondaryHUDSheet[37] = Utils.grabSprite(image, 1, 21, 63, 37); // Equipment tab --- accurate selected + Textures.secondaryHUDSheet[38] = Utils.grabSprite(image, 2, 19, 63, 37); // Equipment tab --- Strong reg + Textures.secondaryHUDSheet[39] = Utils.grabSprite(image, 2, 20, 63, 37); // Equipment tab --- Strong hovered + Textures.secondaryHUDSheet[40] = Utils.grabSprite(image, 2, 21, 63, 37); // Equipment tab --- Strong selected + Textures.secondaryHUDSheet[41] = Utils.grabSprite(image, 3, 19, 63, 37); // Equipment tab --- Defensive reg + Textures.secondaryHUDSheet[42] = Utils.grabSprite(image, 3, 20, 63, 37); // Equipment tab --- Defensive hovered + Textures.secondaryHUDSheet[43] = Utils.grabSprite(image, 3, 21, 63, 37); // Equipment tab --- Defensive selected + Textures.secondaryHUDSheet[44] = Utils.grabSprite(image, 1, 4, 245, 320); // Equipment base + } +} diff --git a/src/textures/hud/constructionmenu/BaseConstructionMenu.java b/src/textures/hud/constructionmenu/BaseConstructionMenu.java new file mode 100755 index 0000000..6fad897 --- /dev/null +++ b/src/textures/hud/constructionmenu/BaseConstructionMenu.java @@ -0,0 +1,26 @@ +package textures.hud.constructionmenu; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class BaseConstructionMenu { + public static void getTextures(BufferedImage image) { + Textures.baseConstructionSheet[0] = Utils.grabSprite(image, 1, 1, 80, 450); + Textures.baseConstructionSheet[1] = Utils.grabSprite(image, 3, 1, 46, 45); // base + Textures.baseConstructionSheet[2] = Utils.grabSprite(image, 3, 2, 46, 45); // sepia + Textures.baseConstructionSheet[3] = Utils.grabSprite(image, 3, 3, 46, 45); // selected + Textures.baseConstructionSheet[4] = Utils.grabSprite(image, 3, 4, 46, 45); // padlock + + Textures.baseConstructionSheet[5] = Utils.grabSprite(image, 3, 5, 46, 45); // tools icon + Textures.baseConstructionSheet[6] = Utils.grabSprite(image, 3, 6, 46, 45); // fire/light icon + + + Textures.baseConstructionSheet[13] = Utils.grabSprite(image, 2, 1, 140, 386); // base menu + Textures.baseConstructionSheet[14] = Utils.grabSprite(image, 8, 1, 40, 40); // reg menu square + Textures.baseConstructionSheet[15] = Utils.grabSprite(image, 8, 2, 40, 40); // sepia menu square + Textures.baseConstructionSheet[16] = Utils.grabSprite(image, 8, 3, 40, 40); // locked menu square + + } +} diff --git a/src/textures/menu/MenuButtonTextures.java b/src/textures/menu/MenuButtonTextures.java new file mode 100755 index 0000000..38dda96 --- /dev/null +++ b/src/textures/menu/MenuButtonTextures.java @@ -0,0 +1,22 @@ +package textures.menu; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class MenuButtonTextures { + + public static void getTextures(BufferedImage image){ + Textures.menuButtonSheet[0] = Utils.grabSprite(image, 1, 1, 155, 29); // Play + Textures.menuButtonSheet[1] = Utils.grabSprite(image, 2, 1, 155, 29); // Play + Textures.menuButtonSheet[2] = Utils.grabSprite(image, 1, 2, 155, 29); // Settings + Textures.menuButtonSheet[3] = Utils.grabSprite(image, 2, 2, 155, 29); // Settings + Textures.menuButtonSheet[4] = Utils.grabSprite(image, 1, 3, 155, 29); // About + Textures.menuButtonSheet[5] = Utils.grabSprite(image, 2, 3, 155, 29); // About + Textures.menuButtonSheet[6] = Utils.grabSprite(image, 1, 4, 155, 29); // Quit + Textures.menuButtonSheet[7] = Utils.grabSprite(image, 2, 4, 155, 29); // Quit + Textures.menuButtonSheet[8] = Utils.grabSprite(image, 1, 5, 155, 29); // Back to Main + Textures.menuButtonSheet[9] = Utils.grabSprite(image, 2, 5, 155, 29); // Back to Main + } +} diff --git a/src/textures/menu/MenuSplashSheetTextures.java b/src/textures/menu/MenuSplashSheetTextures.java new file mode 100755 index 0000000..a839702 --- /dev/null +++ b/src/textures/menu/MenuSplashSheetTextures.java @@ -0,0 +1,15 @@ +package textures.menu; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class MenuSplashSheetTextures { + + public static void getTextures(BufferedImage image){ + Textures.splashSheet[0] = Utils.grabSprite(image, 1, 1, 1920, 1080); + Textures.splashSheet[1] = Utils.grabSprite(image, 1, 6, 600, 240); + } + +} diff --git a/src/textures/mobs/goblin/GoblinTextures.java b/src/textures/mobs/goblin/GoblinTextures.java new file mode 100755 index 0000000..d2787d8 --- /dev/null +++ b/src/textures/mobs/goblin/GoblinTextures.java @@ -0,0 +1,46 @@ +package textures.mobs.goblin; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class GoblinTextures { + + public static final void getTextures(final BufferedImage image){ + final int WIDTH = 33, HEIGHT = 42; + + // RUN? WALK? --- 8 directions, 4 frames per direction + int count = 0; + for(int i = 1; i < 8+1; i++) + for(int j = 1; j < 4+1; j++, count++) + Textures.goblinSheet[count] = Utils.grabSprite(image, j, i, WIDTH, HEIGHT); + + // idle1 --- 8 directions, 2 frames per directions + for(int i = 1; i < 8+1; i++) + for(int j = 5; j < 6+1; j++, count++) + Textures.goblinSheet[count] = Utils.grabSprite(image, j, i, WIDTH, HEIGHT); + + // idle2 --- 8 directions, 2 frames per directions + for(int i = 1; i < 8+1; i++) + for(int j = 7; j < 8+1; j++, count++) + Textures.goblinSheet[count] = Utils.grabSprite(image, j, i, WIDTH, HEIGHT); + + // attack --- 8 directions, 4 frames + for(int i = 1; i < 8+1; i++) + for(int j = 9; j < 12+1; j++, count++) + Textures.goblinSheet[count] = Utils.grabSprite(image, j, i, WIDTH, HEIGHT); + + // GET HIT ANIMATINO--- 1 frame, 8 directions + for(int i = 1; i < 8+1; i++) Textures.goblinSheet[count++] = Utils.grabSprite(image, 13, i, WIDTH, HEIGHT); + + // DEATH ANIMATIONS --- 4 frames - 8 directions + for(int ROW = 1; ROW < 8+1; ROW++) + for(int COL = 14; COL < 17+1; COL++) + Textures.goblinSheet[count++] = Utils.grabSprite(image, COL, ROW, WIDTH, HEIGHT); + } +} diff --git a/src/textures/mobs/rabbit/RabbitDeathTextures.java b/src/textures/mobs/rabbit/RabbitDeathTextures.java new file mode 100755 index 0000000..cfdfa97 --- /dev/null +++ b/src/textures/mobs/rabbit/RabbitDeathTextures.java @@ -0,0 +1,68 @@ +package textures.mobs.rabbit; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class RabbitDeathTextures { + + public static void getTextures(BufferedImage image){ + + final int WIDTH_HEIGHT = 20; + + /*** SOUTH IDLE ***/ + Textures.rabbitSheet[112] = Utils.grabSprite(image, 15, 1, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[113] = Utils.grabSprite(image, 16, 1, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[114] = Utils.grabSprite(image, 17, 1, WIDTH_HEIGHT, WIDTH_HEIGHT); + + /*** NORTH IDLE ***/ + Textures.rabbitSheet[115] = Utils.grabSprite(image, 15, 2, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[116] = Utils.grabSprite(image, 16, 2, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[117] = Utils.grabSprite(image, 17, 2, WIDTH_HEIGHT, WIDTH_HEIGHT); + + /*** WEST IDLE ***/ + Textures.rabbitSheet[118] = Utils.grabSprite(image, 15, 3, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[119] = Utils.grabSprite(image, 16, 3, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[120] = Utils.grabSprite(image, 17, 3, WIDTH_HEIGHT, WIDTH_HEIGHT); + + /*** EAST IDLE ***/ + Textures.rabbitSheet[121] = Utils.reverseImage(Utils.grabSprite(image, 15, 3, WIDTH_HEIGHT, WIDTH_HEIGHT)); + Textures.rabbitSheet[122] = Utils.reverseImage(Utils.grabSprite(image, 16, 3, WIDTH_HEIGHT, WIDTH_HEIGHT)); + Textures.rabbitSheet[123] = Utils.reverseImage(Utils.grabSprite(image, 17, 3, WIDTH_HEIGHT, WIDTH_HEIGHT)); + + /*** NORTHWEST IDLE ***/ + Textures.rabbitSheet[124] = Utils.grabSprite(image, 15, 4, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[125] = Utils.grabSprite(image, 16, 4, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[126] = Utils.grabSprite(image, 17, 4, WIDTH_HEIGHT, WIDTH_HEIGHT); + + /*** NORTHEAST IDLE ***/ + Textures.rabbitSheet[127] = Utils.reverseImage(Utils.grabSprite(image, 15, 4, WIDTH_HEIGHT, WIDTH_HEIGHT)); + Textures.rabbitSheet[128] = Utils.reverseImage(Utils.grabSprite(image, 16, 4, WIDTH_HEIGHT, WIDTH_HEIGHT)); + Textures.rabbitSheet[129] = Utils.reverseImage(Utils.grabSprite(image, 17, 4, WIDTH_HEIGHT, WIDTH_HEIGHT)); + + /*** SOUTHWEST IDLE ***/ + Textures.rabbitSheet[130] = Utils.grabSprite(image, 15, 5, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[131] = Utils.grabSprite(image, 16, 5, WIDTH_HEIGHT, WIDTH_HEIGHT); + Textures.rabbitSheet[132] = Utils.grabSprite(image, 17, 5, WIDTH_HEIGHT, WIDTH_HEIGHT); + + /*** SOUTHEAST IDLE ***/ + Textures.rabbitSheet[133] = Utils.reverseImage(Utils.grabSprite(image, 15, 5, WIDTH_HEIGHT, WIDTH_HEIGHT)); + Textures.rabbitSheet[134] = Utils.reverseImage(Utils.grabSprite(image, 16, 5, WIDTH_HEIGHT, WIDTH_HEIGHT)); + Textures.rabbitSheet[135] = Utils.reverseImage(Utils.grabSprite(image, 17, 5, WIDTH_HEIGHT, WIDTH_HEIGHT)); + + + // @@@@@@@@@@ RABBIT GET-HET GOES HERE @@@@@@@@@@@@@@@@@ // + // 1 frame, 8 directions + Textures.rabbitSheet[136] = Utils.grabSprite(image, 18, 1, WIDTH_HEIGHT, WIDTH_HEIGHT); // NORTH + Textures.rabbitSheet[137] = Utils.reverseImage(Utils.grabSprite(image, 18, 4, WIDTH_HEIGHT, WIDTH_HEIGHT)); // NORTHEAST + Textures.rabbitSheet[138] = Utils.reverseImage(Utils.grabSprite(image, 18, 3, WIDTH_HEIGHT, WIDTH_HEIGHT)); // EAST + Textures.rabbitSheet[139] = Utils.reverseImage(Utils.grabSprite(image, 18, 5, WIDTH_HEIGHT, WIDTH_HEIGHT)); // SOUTHEAST + Textures.rabbitSheet[140] = Utils.grabSprite(image, 18, 2, WIDTH_HEIGHT, WIDTH_HEIGHT); // SOUTH + Textures.rabbitSheet[141] = Utils.grabSprite(image, 18, 5, WIDTH_HEIGHT, WIDTH_HEIGHT); // SOUTHWEST + Textures.rabbitSheet[142] = Utils.grabSprite(image, 18, 3, WIDTH_HEIGHT, WIDTH_HEIGHT); // WEST + Textures.rabbitSheet[143] = Utils.grabSprite(image, 18, 4, WIDTH_HEIGHT, WIDTH_HEIGHT); // NORTHWEST + + } + +} diff --git a/src/textures/mobs/rabbit/RabbitIdleEatGroundTextures.java b/src/textures/mobs/rabbit/RabbitIdleEatGroundTextures.java new file mode 100755 index 0000000..df1fb27 --- /dev/null +++ b/src/textures/mobs/rabbit/RabbitIdleEatGroundTextures.java @@ -0,0 +1,60 @@ +package textures.mobs.rabbit; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class RabbitIdleEatGroundTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH IDLE ***/ + Textures.rabbitSheet[32] = Utils.grabSprite(image, 5, 1, 20, 20); + Textures.rabbitSheet[33] = Utils.grabSprite(image, 6, 1, 20, 20); + Textures.rabbitSheet[34] = Utils.grabSprite(image, 7, 1, 20, 20); + Textures.rabbitSheet[35] = Utils.grabSprite(image, 8, 1, 20, 20); + + /*** NORTH IDLE ***/ + Textures.rabbitSheet[36] = Utils.grabSprite(image, 5, 2, 20, 20); + Textures.rabbitSheet[37] = Utils.grabSprite(image, 6, 2, 20, 20); + Textures.rabbitSheet[38] = Utils.grabSprite(image, 7, 2, 20, 20); + Textures.rabbitSheet[39] = Utils.grabSprite(image, 8, 2, 20, 20); + + /*** WEST IDLE ***/ + Textures.rabbitSheet[40] = Utils.grabSprite(image,5, 3, 20, 20); + Textures.rabbitSheet[41] = Utils.grabSprite(image,6, 3, 20, 20); + Textures.rabbitSheet[42] = Utils.grabSprite(image,7, 3, 20, 20); + Textures.rabbitSheet[43] = Utils.grabSprite(image,8, 3, 20, 20); + + /*** EAST IDLE ***/ + Textures.rabbitSheet[44] = Utils.reverseImage(Utils.grabSprite(image,5, 3, 20, 20)); + Textures.rabbitSheet[45] = Utils.reverseImage(Utils.grabSprite(image,6, 3, 20, 20)); + Textures.rabbitSheet[46] = Utils.reverseImage(Utils.grabSprite(image,7, 3, 20, 20)); + Textures.rabbitSheet[47] = Utils.reverseImage(Utils.grabSprite(image,8, 3, 20, 20)); + + /*** NORTHWEST IDLE ***/ + Textures.rabbitSheet[48] = Utils.grabSprite(image,5, 4, 20, 20); + Textures.rabbitSheet[49] = Utils.grabSprite(image, 6, 4, 20, 20); + Textures.rabbitSheet[50] = Utils.grabSprite(image, 7, 4, 20, 20); + Textures.rabbitSheet[51] = Utils.grabSprite(image, 8, 4, 20, 20); + + /*** NORTHEAST IDLE ***/ + Textures.rabbitSheet[52] = Utils.reverseImage(Utils.grabSprite(image, 5, 4, 20, 20)); + Textures.rabbitSheet[53] = Utils.reverseImage(Utils.grabSprite(image, 6, 4, 20, 20)); + Textures.rabbitSheet[54] = Utils.reverseImage(Utils.grabSprite(image, 7, 4, 20, 20)); + Textures.rabbitSheet[55] = Utils.reverseImage(Utils.grabSprite(image, 8, 4, 20, 20)); + + /*** SOUTHWEST IDLE ***/ + Textures.rabbitSheet[56] = Utils.grabSprite(image, 5, 5, 20, 20); + Textures.rabbitSheet[57] = Utils.grabSprite(image, 6, 5, 20, 20); + Textures.rabbitSheet[58] = Utils.grabSprite(image, 7, 5, 20, 20); + Textures.rabbitSheet[59] = Utils.grabSprite(image, 8, 5, 20, 20); + + /*** SOUTHEAST IDLE ***/ + Textures.rabbitSheet[60] = Utils.reverseImage(Utils.grabSprite(image, 5, 5, 20, 20)); + Textures.rabbitSheet[61] = Utils.reverseImage(Utils.grabSprite(image, 6, 5, 20, 20)); + Textures.rabbitSheet[62] = Utils.reverseImage(Utils.grabSprite(image, 7, 5, 20, 20)); + Textures.rabbitSheet[63] = Utils.reverseImage(Utils.grabSprite(image, 8, 5, 20, 20)); + + } +} diff --git a/src/textures/mobs/rabbit/RabbitIdleWalkTextures.java b/src/textures/mobs/rabbit/RabbitIdleWalkTextures.java new file mode 100755 index 0000000..547db69 --- /dev/null +++ b/src/textures/mobs/rabbit/RabbitIdleWalkTextures.java @@ -0,0 +1,60 @@ +package textures.mobs.rabbit; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class RabbitIdleWalkTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH IDLE ***/ + Textures.rabbitSheet[0] = Utils.grabSprite(image, 1, 1, 20, 20); + Textures.rabbitSheet[1] = Utils.grabSprite(image, 2, 1, 20, 20); + Textures.rabbitSheet[2] = Utils.grabSprite(image, 3, 1, 20, 20); + Textures.rabbitSheet[3] = Utils.grabSprite(image, 4, 1, 20, 20); + + /*** NORTH IDLE ***/ + Textures.rabbitSheet[4] = Utils.grabSprite(image,1, 2, 20, 20); + Textures.rabbitSheet[5] = Utils.grabSprite(image,2, 2, 20, 20); + Textures.rabbitSheet[6] = Utils.grabSprite(image,3, 2, 20, 20); + Textures.rabbitSheet[7] = Utils.grabSprite(image,4, 2, 20, 20); + + /*** WEST IDLE ***/ + Textures.rabbitSheet[8] = Utils.grabSprite(image,1, 3, 20, 20); + Textures.rabbitSheet[9] = Utils.grabSprite(image,2, 3, 20, 20); + Textures.rabbitSheet[10] = Utils.grabSprite(image,3, 3, 20, 20); + Textures.rabbitSheet[11] = Utils.grabSprite(image,4, 3, 20, 20); + + /*** EAST IDLE ***/ + Textures.rabbitSheet[12] = Utils.reverseImage(Utils.grabSprite(image,1, 3, 20, 20)); + Textures.rabbitSheet[13] = Utils.reverseImage(Utils.grabSprite(image,2, 3, 20, 20)); + Textures.rabbitSheet[14] = Utils.reverseImage(Utils.grabSprite(image,3, 3, 20, 20)); + Textures.rabbitSheet[15] = Utils.reverseImage(Utils.grabSprite(image,4, 3, 20, 20)); + + /*** NORTHWEST IDLE ***/ + Textures.rabbitSheet[16] = Utils.grabSprite(image,1, 4, 20, 20); + Textures.rabbitSheet[17] = Utils.grabSprite(image, 2, 4, 20, 20); + Textures.rabbitSheet[18] = Utils.grabSprite(image, 3, 4, 20, 20); + Textures.rabbitSheet[19] = Utils.grabSprite(image, 4, 4, 20, 20); + + /*** NORTHEAST IDLE ***/ + Textures.rabbitSheet[20] = Utils.reverseImage(Utils.grabSprite(image, 1, 4, 20, 20)); + Textures.rabbitSheet[21] = Utils.reverseImage(Utils.grabSprite(image, 2, 4, 20, 20)); + Textures.rabbitSheet[22] = Utils.reverseImage(Utils.grabSprite(image, 3, 4, 20, 20)); + Textures.rabbitSheet[23] = Utils.reverseImage(Utils.grabSprite(image, 4, 4, 20, 20)); + + /*** SOUTHWEST IDLE ***/ + Textures.rabbitSheet[24] = Utils.grabSprite(image, 1, 5, 20, 20); + Textures.rabbitSheet[25] = Utils.grabSprite(image, 2, 5, 20, 20); + Textures.rabbitSheet[26] = Utils.grabSprite(image, 3, 5, 20, 20); + Textures.rabbitSheet[27] = Utils.grabSprite(image, 4, 5, 20, 20); + + /*** SOUTHEAST IDLE ***/ + Textures.rabbitSheet[28] = Utils.reverseImage(Utils.grabSprite(image, 1, 5, 20, 20)); + Textures.rabbitSheet[29] = Utils.reverseImage(Utils.grabSprite(image, 2, 5, 20, 20)); + Textures.rabbitSheet[30] = Utils.reverseImage(Utils.grabSprite(image, 3, 5, 20, 20)); + Textures.rabbitSheet[31] = Utils.reverseImage(Utils.grabSprite(image, 4, 5, 20, 20)); + } + +} diff --git a/src/textures/mobs/rabbit/RabbitRunAwayTextures.java b/src/textures/mobs/rabbit/RabbitRunAwayTextures.java new file mode 100755 index 0000000..c584eac --- /dev/null +++ b/src/textures/mobs/rabbit/RabbitRunAwayTextures.java @@ -0,0 +1,60 @@ +package textures.mobs.rabbit; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class RabbitRunAwayTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH IDLE ***/ + Textures.rabbitSheet[64] = Utils.grabSprite(image, 9, 1, 20, 20); + Textures.rabbitSheet[65] = Utils.grabSprite(image, 10, 1, 20, 20); + Textures.rabbitSheet[66] = Utils.grabSprite(image, 11, 1, 20, 20); + Textures.rabbitSheet[67] = Utils.grabSprite(image, 12, 1, 20, 20); + + /*** NORTH IDLE ***/ + Textures.rabbitSheet[68] = Utils.grabSprite(image,9, 2, 20, 20); + Textures.rabbitSheet[69] = Utils.grabSprite(image,10, 2, 20, 20); + Textures.rabbitSheet[70] = Utils.grabSprite(image,11, 2, 20, 20); + Textures.rabbitSheet[71] = Utils.grabSprite(image,12, 2, 20, 20); + + /*** WEST IDLE ***/ + Textures.rabbitSheet[72] = Utils.grabSprite(image,9, 3, 20, 20); + Textures.rabbitSheet[73] = Utils.grabSprite(image,10, 3, 20, 20); + Textures.rabbitSheet[74] = Utils.grabSprite(image,11, 3, 20, 20); + Textures.rabbitSheet[75] = Utils.grabSprite(image,12, 3, 20, 20); + + /*** EAST IDLE ***/ + Textures.rabbitSheet[76] = Utils.reverseImage(Utils.grabSprite(image,9, 3, 20, 20)); + Textures.rabbitSheet[77] = Utils.reverseImage(Utils.grabSprite(image,10, 3, 20, 20)); + Textures.rabbitSheet[78] = Utils.reverseImage(Utils.grabSprite(image,11, 3, 20, 20)); + Textures.rabbitSheet[79] = Utils.reverseImage(Utils.grabSprite(image,12, 3, 20, 20)); + + /*** NORTHWEST IDLE ***/ + Textures.rabbitSheet[80] = Utils.grabSprite(image,9, 4, 20, 20); + Textures.rabbitSheet[81] = Utils.grabSprite(image, 10, 4, 20, 20); + Textures.rabbitSheet[82] = Utils.grabSprite(image, 11, 4, 20, 20); + Textures.rabbitSheet[83] = Utils.grabSprite(image, 12, 4, 20, 20); + + /*** NORTHEAST IDLE ***/ + Textures.rabbitSheet[84] = Utils.reverseImage(Utils.grabSprite(image, 9, 4, 20, 20)); + Textures.rabbitSheet[85] = Utils.reverseImage(Utils.grabSprite(image, 10, 4, 20, 20)); + Textures.rabbitSheet[86] = Utils.reverseImage(Utils.grabSprite(image, 11, 4, 20, 20)); + Textures.rabbitSheet[87] = Utils.reverseImage(Utils.grabSprite(image, 12, 4, 20, 20)); + + /*** SOUTHWEST IDLE ***/ + Textures.rabbitSheet[88] = Utils.grabSprite(image, 9, 5, 20, 20); + Textures.rabbitSheet[89] = Utils.grabSprite(image, 10, 5, 20, 20); + Textures.rabbitSheet[90] = Utils.grabSprite(image, 11, 5, 20, 20); + Textures.rabbitSheet[91] = Utils.grabSprite(image, 12, 5, 20, 20); + + /*** SOUTHEAST IDLE ***/ + Textures.rabbitSheet[92] = Utils.reverseImage(Utils.grabSprite(image, 9, 5, 20, 20)); + Textures.rabbitSheet[93] = Utils.reverseImage(Utils.grabSprite(image, 10, 5, 20, 20)); + Textures.rabbitSheet[94] = Utils.reverseImage(Utils.grabSprite(image, 11, 5, 20, 20)); + Textures.rabbitSheet[95] = Utils.reverseImage(Utils.grabSprite(image, 12, 5, 20, 20)); + } + +} diff --git a/src/textures/mobs/rabbit/RabbitSleepTextures.java b/src/textures/mobs/rabbit/RabbitSleepTextures.java new file mode 100755 index 0000000..fd8697a --- /dev/null +++ b/src/textures/mobs/rabbit/RabbitSleepTextures.java @@ -0,0 +1,44 @@ +package textures.mobs.rabbit; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class RabbitSleepTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH SLEEP ***/ + Textures.rabbitSheet[96] = Utils.grabSprite(image, 13, 1, 20, 20); + Textures.rabbitSheet[97] = Utils.grabSprite(image, 14, 1, 20, 20); + + /*** NORTH SLEEP ***/ + Textures.rabbitSheet[98] = Utils.grabSprite(image,13, 2, 20, 20); + Textures.rabbitSheet[99] = Utils.grabSprite(image,14, 2, 20, 20); + + /*** WEST SLEEP ***/ + Textures.rabbitSheet[100] = Utils.grabSprite(image,13, 3, 20, 20); + Textures.rabbitSheet[101] = Utils.grabSprite(image,14, 3, 20, 20); + + /*** EAST SLEEP ***/ + Textures.rabbitSheet[102] = Utils.reverseImage(Utils.grabSprite(image,13, 3, 20, 20)); + Textures.rabbitSheet[103] = Utils.reverseImage(Utils.grabSprite(image,14, 3, 20, 20)); + + /*** NORTHWEST SLEEP ***/ + Textures.rabbitSheet[104] = Utils.grabSprite(image,13, 4, 20, 20); + Textures.rabbitSheet[105] = Utils.grabSprite(image, 14, 4, 20, 20); + + /*** NORTHEAST SLEEP ***/ + Textures.rabbitSheet[106] = Utils.reverseImage(Utils.grabSprite(image, 13, 4, 20, 20)); + Textures.rabbitSheet[107] = Utils.reverseImage(Utils.grabSprite(image, 14, 4, 20, 20)); + + /*** SOUTHWEST SLEEP ***/ + Textures.rabbitSheet[108] = Utils.grabSprite(image, 13, 5, 20, 20); + Textures.rabbitSheet[109] = Utils.grabSprite(image, 14, 5, 20, 20); + + /*** SOUTHEAST SLEEP ***/ + Textures.rabbitSheet[110] = Utils.reverseImage(Utils.grabSprite(image, 13, 5, 20, 20)); + Textures.rabbitSheet[111] = Utils.reverseImage(Utils.grabSprite(image, 14, 5, 20, 20)); + } + +} diff --git a/src/textures/player/BasePlayerGetHitAndDeath.java b/src/textures/player/BasePlayerGetHitAndDeath.java new file mode 100755 index 0000000..1f612b2 --- /dev/null +++ b/src/textures/player/BasePlayerGetHitAndDeath.java @@ -0,0 +1,69 @@ +package textures.player; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class BasePlayerGetHitAndDeath { + + public static final void getTextures(final BufferedImage image) { + final int width = 40, height = 72; + int count = 0; int ROW = 1; + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 1, ROW++, width, height); // GET HIT NORTH + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 1, ROW++, width, height); // GET HIT NE + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 1, ROW++, width, height); // GET HIT E + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 1, ROW++, width, height); // GET HIT SE + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 1, ROW++, width, height); // GET HIT S + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 1, ROW++, width, height); // GET HIT SW + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 1, ROW++, width, height); // GET HIT W + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 1, ROW++, width, height); // GET HIT NW +/**********************************************************************************************************************************************/ + ROW = 1; + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 2, ROW, width, height); // NORTH DEATH 1 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 3, ROW, width, height); // NORTH DEATH 2 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 4, ROW, width, height); // NORTH DEATH 3 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 5, ROW, width, height); // NORTH DEATH 4 + + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 2, ++ROW, width, height); // NORTHEAST DEATH 1 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 3, ROW, width, height); // NORTHEAST DEATH 2 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 4, ROW, width, height); // NORTHEAST DEATH 3 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 5, ROW, width, height); // NORTHEAST DEATH 4 + + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 2, ++ROW, width, height); // EAST DEATH 1 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 3, ROW, width, height); // EAST DEATH 2 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 4, ROW, width, height); // EAST DEATH 3 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 5, ROW, width, height); // EAST DEATH 4 + + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 2, ++ROW, width, height); // SOUTHEAST DEATH 1 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 3, ROW, width, height); // SOUTHEAST DEATH 2 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 4, ROW, width, height); // SOUTHEAST DEATH 3 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 5, ROW, width, height); // SOUTHEAST DEATH 4 + + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 2, ++ROW, width, height); // SOUTH DEATH 1 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 3, ROW, width, height); // SOUTH DEATH 2 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 4, ROW, width, height); // SOUTH DEATH 3 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 5, ROW, width, height); // SOUTH DEATH 4 + + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 2, ++ROW, width, height); // SOUTHWEST DEATH 1 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 3, ROW, width, height); // SOUTHWEST DEATH 2 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 4, ROW, width, height); // SOUTHWEST DEATH 3 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 5, ROW, width, height); // SOUTHWEST DEATH 4 + + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 2, ++ROW, width, height); // WEST DEATH 1 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 3, ROW, width, height); // WEST DEATH 2 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 4, ROW, width, height); // WEST DEATH 3 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 5, ROW, width, height); // WEST DEATH 4 + + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 2, ++ROW, width, height); // NORTHWEST DEATH 1 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 3, ROW, width, height); // NORTHWEST DEATH 2 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 4, ROW, width, height); // NORTHWEST DEATH 3 + Textures.basePlayerGetHitAndDeath[count++] = Utils.grabSprite(image, 5, ROW, width, height); // NORTHWEST DEATH 4 + + } + +} diff --git a/src/textures/player/PlayerAxeChopTextures.java b/src/textures/player/PlayerAxeChopTextures.java new file mode 100755 index 0000000..c897080 --- /dev/null +++ b/src/textures/player/PlayerAxeChopTextures.java @@ -0,0 +1,56 @@ +package textures.player; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class PlayerAxeChopTextures { + + public static void getTextures(BufferedImage image){ + /*** FACING SOUTH ***/ + Textures.basePlayerAxeSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.basePlayerAxeSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.basePlayerAxeSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.basePlayerAxeSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + /*** FACING NORTH ***/ + Textures.basePlayerAxeSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.basePlayerAxeSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.basePlayerAxeSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.basePlayerAxeSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + /*** FACING WEST ***/ + Textures.basePlayerAxeSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.basePlayerAxeSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.basePlayerAxeSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.basePlayerAxeSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + /*** FACING EAST ***/ + Textures.basePlayerAxeSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.basePlayerAxeSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.basePlayerAxeSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.basePlayerAxeSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + /*** FACING NW ***/ + Textures.basePlayerAxeSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.basePlayerAxeSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.basePlayerAxeSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.basePlayerAxeSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + /*** FACING NE ***/ + Textures.basePlayerAxeSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.basePlayerAxeSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.basePlayerAxeSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.basePlayerAxeSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + /*** FACING SW ***/ + Textures.basePlayerAxeSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.basePlayerAxeSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.basePlayerAxeSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.basePlayerAxeSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + /*** FACING SE ***/ + Textures.basePlayerAxeSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.basePlayerAxeSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.basePlayerAxeSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.basePlayerAxeSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } +} diff --git a/src/textures/player/PlayerIdleTextures.java b/src/textures/player/PlayerIdleTextures.java new file mode 100755 index 0000000..4279ab0 --- /dev/null +++ b/src/textures/player/PlayerIdleTextures.java @@ -0,0 +1,64 @@ +package textures.player; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public class PlayerIdleTextures { + + + public static void getTextures(BufferedImage image){ + /*** SOUTH IDLE ***/ + Textures.playerSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.playerSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.playerSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.playerSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + + /*** NORTH IDLE ***/ + Textures.playerSheet[4] = Utils.grabSprite(image,1, 2, 40, 72); + Textures.playerSheet[5] = Utils.grabSprite(image,2, 2, 40, 72); + Textures.playerSheet[6] = Utils.grabSprite(image,3, 2, 40, 72); + Textures.playerSheet[7] = Utils.grabSprite(image,4, 2, 40, 72); + + /*** WEST IDLE ***/ + Textures.playerSheet[8] = Utils.grabSprite(image,1, 3, 40, 72); + Textures.playerSheet[9] = Utils.grabSprite(image,2, 3, 40, 72); + Textures.playerSheet[10] = Utils.grabSprite(image,3, 3, 40, 72); + Textures.playerSheet[11] = Utils.grabSprite(image,4, 3, 40, 72); + + /*** EAST IDLE ***/ + Textures.playerSheet[12] = Utils.reverseImage(Utils.grabSprite(image,1, 3, 40, 72)); + Textures.playerSheet[13] = Utils.reverseImage(Utils.grabSprite(image,2, 3, 40, 72)); + Textures.playerSheet[14] = Utils.reverseImage(Utils.grabSprite(image,3, 3, 40, 72)); + Textures.playerSheet[15] = Utils.reverseImage(Utils.grabSprite(image,4, 3, 40, 72)); + + /*** NORTHWEST IDLE ***/ + Textures.playerSheet[16] = Utils.grabSprite(image,1, 4, 40, 72); + Textures.playerSheet[17] = Utils.grabSprite(image,2, 4, 40, 72); + Textures.playerSheet[18] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.playerSheet[19] = Utils.grabSprite(image, 4, 4, 40, 72); + + /*** NORTHEAST IDLE ***/ + Textures.playerSheet[20] = Utils.reverseImage(Utils.grabSprite(image, 1, 4, 40, 72)); + Textures.playerSheet[21] = Utils.reverseImage(Utils.grabSprite(image, 2, 4, 40, 72)); + Textures.playerSheet[22] = Utils.reverseImage(Utils.grabSprite(image, 3, 4, 40, 72)); + Textures.playerSheet[23] = Utils.reverseImage(Utils.grabSprite(image, 4, 4, 40, 72)); + + /*** SOUTHWEST IDLE ***/ + Textures.playerSheet[24] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.playerSheet[25] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.playerSheet[26] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.playerSheet[27] = Utils.grabSprite(image, 4, 5, 40, 72); + + /*** SOUTHEAST IDLE ***/ + Textures.playerSheet[28] = Utils.reverseImage(Utils.grabSprite(image, 1, 5, 40, 72)); + Textures.playerSheet[29] = Utils.reverseImage(Utils.grabSprite(image, 2, 5, 40, 72)); + Textures.playerSheet[30] = Utils.reverseImage(Utils.grabSprite(image, 3, 5, 40, 72)); + Textures.playerSheet[31] = Utils.reverseImage(Utils.grabSprite(image, 4, 5, 40, 72)); + } +} diff --git a/src/textures/player/PlayerMineTextures.java b/src/textures/player/PlayerMineTextures.java new file mode 100755 index 0000000..b2f524d --- /dev/null +++ b/src/textures/player/PlayerMineTextures.java @@ -0,0 +1,51 @@ +package textures.player; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class PlayerMineTextures { + public static void getTextures(BufferedImage image){ + /*** FACING SOUTH ***/ + Textures.basePlayerPickaxeSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.basePlayerPickaxeSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.basePlayerPickaxeSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.basePlayerPickaxeSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + /*** FACING NORTH ***/ + Textures.basePlayerPickaxeSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.basePlayerPickaxeSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.basePlayerPickaxeSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.basePlayerPickaxeSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + /*** FACING WEST ***/ + Textures.basePlayerPickaxeSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.basePlayerPickaxeSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.basePlayerPickaxeSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.basePlayerPickaxeSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + /*** FACING EAST ***/ + Textures.basePlayerPickaxeSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.basePlayerPickaxeSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.basePlayerPickaxeSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.basePlayerPickaxeSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + /*** FACING NW ***/ + Textures.basePlayerPickaxeSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.basePlayerPickaxeSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.basePlayerPickaxeSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.basePlayerPickaxeSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + /*** FACING NE ***/ + Textures.basePlayerPickaxeSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.basePlayerPickaxeSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.basePlayerPickaxeSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.basePlayerPickaxeSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + /*** FACING SW ***/ + Textures.basePlayerPickaxeSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.basePlayerPickaxeSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.basePlayerPickaxeSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.basePlayerPickaxeSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + /*** FACING SE ***/ + Textures.basePlayerPickaxeSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.basePlayerPickaxeSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.basePlayerPickaxeSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.basePlayerPickaxeSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } +} diff --git a/src/textures/player/PlayerWalkTextures.java b/src/textures/player/PlayerWalkTextures.java new file mode 100755 index 0000000..ceeb189 --- /dev/null +++ b/src/textures/player/PlayerWalkTextures.java @@ -0,0 +1,79 @@ +package textures.player; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 4016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class PlayerWalkTextures { + + public static void getTextures(BufferedImage image) { + /*** SOUTH WALK ***/ + Textures.playerSheet[32] = Utils.grabSprite(image, 5, 1, 40, 72); + Textures.playerSheet[33] = Utils.grabSprite(image, 6, 1, 40, 72); + Textures.playerSheet[34] = Utils.grabSprite(image, 7, 1, 40, 72); + Textures.playerSheet[35] = Utils.grabSprite(image, 8, 1, 40, 72); + Textures.playerSheet[36] = Utils.grabSprite(image, 9, 1, 40, 72); + Textures.playerSheet[37] = Utils.grabSprite(image, 10, 1, 40, 72); + + /*** NORTH WALK ***/ + Textures.playerSheet[38] = Utils.grabSprite(image, 5, 2, 40, 72); + Textures.playerSheet[39] = Utils.grabSprite(image, 6, 2, 40, 72); + Textures.playerSheet[40] = Utils.grabSprite(image, 7, 2, 40, 72); + Textures.playerSheet[41] = Utils.grabSprite(image, 8, 2, 40, 72); + Textures.playerSheet[42] = Utils.grabSprite(image, 9, 2, 40, 72); + Textures.playerSheet[43] = Utils.grabSprite(image, 10, 2, 40, 72); + + /*** WEST WALK ***/ + Textures.playerSheet[44] = Utils.grabSprite(image, 5, 3, 40, 72); + Textures.playerSheet[45] = Utils.grabSprite(image, 6, 3, 40, 72); + Textures.playerSheet[46] = Utils.grabSprite(image, 7, 3, 40, 72); + Textures.playerSheet[47] = Utils.grabSprite(image, 8, 3, 40, 72); + Textures.playerSheet[48] = Utils.grabSprite(image, 9, 3, 40, 72); + Textures.playerSheet[49] = Utils.grabSprite(image, 10, 3, 40, 72); + + /*** EAST WALK ***/ + Textures.playerSheet[50] = Utils.reverseImage(Utils.grabSprite(image, 5, 3, 40, 72)); + Textures.playerSheet[51] = Utils.reverseImage(Utils.grabSprite(image, 6, 3, 40, 72)); + Textures.playerSheet[52] = Utils.reverseImage(Utils.grabSprite(image, 7, 3, 40, 72)); + Textures.playerSheet[53] = Utils.reverseImage(Utils.grabSprite(image, 8, 3, 40, 72)); + Textures.playerSheet[54] = Utils.reverseImage(Utils.grabSprite(image, 9, 3, 40, 72)); + Textures.playerSheet[55] = Utils.reverseImage(Utils.grabSprite(image, 10, 3, 40, 72)); + + /*** NORTHWEST WALK ***/ + Textures.playerSheet[56] = Utils.grabSprite(image, 5, 4, 40, 72); + Textures.playerSheet[57] = Utils.grabSprite(image, 6, 4, 40, 72); + Textures.playerSheet[58] = Utils.grabSprite(image, 7, 4, 40, 72); + Textures.playerSheet[59] = Utils.grabSprite(image, 8, 4, 40, 72); + Textures.playerSheet[60] = Utils.grabSprite(image, 9, 4, 40, 72); + Textures.playerSheet[61] = Utils.grabSprite(image, 10, 4, 40, 72); + + /*** NORTHEAST WALK ***/ + Textures.playerSheet[62] = Utils.reverseImage(Utils.grabSprite(image, 5, 4, 40, 72)); + Textures.playerSheet[63] = Utils.reverseImage(Utils.grabSprite(image, 6, 4, 40, 72)); + Textures.playerSheet[64] = Utils.reverseImage(Utils.grabSprite(image, 7, 4, 40, 72)); + Textures.playerSheet[65] = Utils.reverseImage(Utils.grabSprite(image, 8, 4, 40, 72)); + Textures.playerSheet[66] = Utils.reverseImage(Utils.grabSprite(image, 9, 4, 40, 72)); + Textures.playerSheet[67] = Utils.reverseImage(Utils.grabSprite(image, 10, 4, 40, 72)); + + /*** SOUTHWEST WALK ***/ + Textures.playerSheet[68] = Utils.grabSprite(image, 5, 5, 40, 72); + Textures.playerSheet[69] = Utils.grabSprite(image, 6, 5, 40, 72); + Textures.playerSheet[70] = Utils.grabSprite(image, 7, 5, 40, 72); + Textures.playerSheet[71] = Utils.grabSprite(image, 8, 5, 40, 72); + Textures.playerSheet[72] = Utils.grabSprite(image, 9, 5, 40, 72); + Textures.playerSheet[73] = Utils.grabSprite(image, 10, 5, 40, 72); + + /*** SOUTHEAST WALK ***/ + Textures.playerSheet[74] = Utils.reverseImage(Utils.grabSprite(image, 5, 5, 40, 72)); + Textures.playerSheet[75] = Utils.reverseImage(Utils.grabSprite(image, 6, 5, 40, 72)); + Textures.playerSheet[76] = Utils.reverseImage(Utils.grabSprite(image, 7, 5, 40, 72)); + Textures.playerSheet[77] = Utils.reverseImage(Utils.grabSprite(image, 8, 5, 40, 72)); + Textures.playerSheet[78] = Utils.reverseImage(Utils.grabSprite(image, 9, 5, 40, 72)); + Textures.playerSheet[79] = Utils.reverseImage(Utils.grabSprite(image, 10, 5, 40, 72)); + } +} diff --git a/src/textures/player/attacks/BasePlayerAttackTextures.java b/src/textures/player/attacks/BasePlayerAttackTextures.java new file mode 100755 index 0000000..435cb70 --- /dev/null +++ b/src/textures/player/attacks/BasePlayerAttackTextures.java @@ -0,0 +1,53 @@ +package textures.player.attacks; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class BasePlayerAttackTextures { + + public static void getTextures(BufferedImage image) { + /*** FACING SOUTH ***/ + Textures.basePlayerAttackSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.basePlayerAttackSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.basePlayerAttackSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.basePlayerAttackSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + /*** FACING NORTH ***/ + Textures.basePlayerAttackSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.basePlayerAttackSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.basePlayerAttackSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.basePlayerAttackSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + /*** FACING WEST ***/ + Textures.basePlayerAttackSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.basePlayerAttackSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.basePlayerAttackSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.basePlayerAttackSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + /*** FACING EAST ***/ + Textures.basePlayerAttackSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.basePlayerAttackSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.basePlayerAttackSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.basePlayerAttackSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + /*** FACING NW ***/ + Textures.basePlayerAttackSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.basePlayerAttackSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.basePlayerAttackSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.basePlayerAttackSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + /*** FACING NE ***/ + Textures.basePlayerAttackSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.basePlayerAttackSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.basePlayerAttackSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.basePlayerAttackSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + /*** FACING SW ***/ + Textures.basePlayerAttackSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.basePlayerAttackSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.basePlayerAttackSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.basePlayerAttackSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + /*** FACING SE ***/ + Textures.basePlayerAttackSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.basePlayerAttackSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.basePlayerAttackSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.basePlayerAttackSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } + +} diff --git a/src/textures/player/attacks/CrudeAxeAttackTextures.java b/src/textures/player/attacks/CrudeAxeAttackTextures.java new file mode 100755 index 0000000..6211949 --- /dev/null +++ b/src/textures/player/attacks/CrudeAxeAttackTextures.java @@ -0,0 +1,53 @@ +package textures.player.attacks; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class CrudeAxeAttackTextures { + + public static void getTextures(BufferedImage image){ + /*** FACING SOUTH ***/ + Textures.crudeAxeAttackSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.crudeAxeAttackSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.crudeAxeAttackSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.crudeAxeAttackSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + /*** FACING NORTH ***/ + Textures.crudeAxeAttackSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.crudeAxeAttackSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.crudeAxeAttackSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.crudeAxeAttackSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + /*** FACING WEST ***/ + Textures.crudeAxeAttackSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.crudeAxeAttackSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.crudeAxeAttackSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.crudeAxeAttackSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + /*** FACING EAST ***/ + Textures.crudeAxeAttackSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.crudeAxeAttackSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.crudeAxeAttackSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.crudeAxeAttackSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + /*** FACING NW ***/ + Textures.crudeAxeAttackSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.crudeAxeAttackSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.crudeAxeAttackSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.crudeAxeAttackSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + /*** FACING NE ***/ + Textures.crudeAxeAttackSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.crudeAxeAttackSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.crudeAxeAttackSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.crudeAxeAttackSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + /*** FACING SW ***/ + Textures.crudeAxeAttackSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.crudeAxeAttackSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.crudeAxeAttackSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.crudeAxeAttackSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + /*** FACING SE ***/ + Textures.crudeAxeAttackSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.crudeAxeAttackSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.crudeAxeAttackSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.crudeAxeAttackSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } + +} diff --git a/src/textures/player/attacks/CrudePickAxeAttackTextures.java b/src/textures/player/attacks/CrudePickAxeAttackTextures.java new file mode 100755 index 0000000..8d05b40 --- /dev/null +++ b/src/textures/player/attacks/CrudePickAxeAttackTextures.java @@ -0,0 +1,53 @@ +package textures.player.attacks; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public final class CrudePickAxeAttackTextures { + + public static void getTextures(BufferedImage image){ + /*** FACING SOUTH ***/ + Textures.crudePickAxeAttackSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.crudePickAxeAttackSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.crudePickAxeAttackSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.crudePickAxeAttackSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + /*** FACING NORTH ***/ + Textures.crudePickAxeAttackSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.crudePickAxeAttackSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.crudePickAxeAttackSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.crudePickAxeAttackSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + /*** FACING WEST ***/ + Textures.crudePickAxeAttackSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.crudePickAxeAttackSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.crudePickAxeAttackSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.crudePickAxeAttackSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + /*** FACING EAST ***/ + Textures.crudePickAxeAttackSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.crudePickAxeAttackSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.crudePickAxeAttackSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.crudePickAxeAttackSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + /*** FACING NW ***/ + Textures.crudePickAxeAttackSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.crudePickAxeAttackSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.crudePickAxeAttackSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.crudePickAxeAttackSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + /*** FACING NE ***/ + Textures.crudePickAxeAttackSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.crudePickAxeAttackSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.crudePickAxeAttackSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.crudePickAxeAttackSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + /*** FACING SW ***/ + Textures.crudePickAxeAttackSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.crudePickAxeAttackSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.crudePickAxeAttackSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.crudePickAxeAttackSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + /*** FACING SE ***/ + Textures.crudePickAxeAttackSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.crudePickAxeAttackSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.crudePickAxeAttackSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.crudePickAxeAttackSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } + +} diff --git a/src/textures/player/items/crudeaxe/CrudeAxeChopTextures.java b/src/textures/player/items/crudeaxe/CrudeAxeChopTextures.java new file mode 100755 index 0000000..a0ec179 --- /dev/null +++ b/src/textures/player/items/crudeaxe/CrudeAxeChopTextures.java @@ -0,0 +1,53 @@ +package textures.player.items.crudeaxe; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class CrudeAxeChopTextures { + + + public static void getTextures(BufferedImage image){ + /*** FACING SOUTH ***/ + Textures.crudeAxeChopSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.crudeAxeChopSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.crudeAxeChopSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.crudeAxeChopSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + /*** FACING NORTH ***/ + Textures.crudeAxeChopSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.crudeAxeChopSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.crudeAxeChopSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.crudeAxeChopSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + /*** FACING WEST ***/ + Textures.crudeAxeChopSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.crudeAxeChopSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.crudeAxeChopSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.crudeAxeChopSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + /*** FACING EAST ***/ + Textures.crudeAxeChopSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.crudeAxeChopSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.crudeAxeChopSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.crudeAxeChopSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + /*** FACING NW ***/ + Textures.crudeAxeChopSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.crudeAxeChopSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.crudeAxeChopSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.crudeAxeChopSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + /*** FACING NE ***/ + Textures.crudeAxeChopSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.crudeAxeChopSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.crudeAxeChopSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.crudeAxeChopSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + /*** FACING SW ***/ + Textures.crudeAxeChopSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.crudeAxeChopSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.crudeAxeChopSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.crudeAxeChopSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + /*** FACING SE ***/ + Textures.crudeAxeChopSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.crudeAxeChopSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.crudeAxeChopSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.crudeAxeChopSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } +} diff --git a/src/textures/player/items/crudeaxe/CrudeAxeGetHitTextures.java b/src/textures/player/items/crudeaxe/CrudeAxeGetHitTextures.java new file mode 100755 index 0000000..4ff7e31 --- /dev/null +++ b/src/textures/player/items/crudeaxe/CrudeAxeGetHitTextures.java @@ -0,0 +1,27 @@ +package textures.player.items.crudeaxe; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class CrudeAxeGetHitTextures { + + public static final void getTextures(BufferedImage image) { + final int width = 40, height = 72; final int col = 1; + int row = 1; int START = 80; + Textures.crudeAxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudeAxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudeAxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudeAxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudeAxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudeAxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudeAxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudeAxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + } + +} diff --git a/src/textures/player/items/crudeaxe/CrudeAxeIdleTextures.java b/src/textures/player/items/crudeaxe/CrudeAxeIdleTextures.java new file mode 100755 index 0000000..312a815 --- /dev/null +++ b/src/textures/player/items/crudeaxe/CrudeAxeIdleTextures.java @@ -0,0 +1,59 @@ +package textures.player.items.crudeaxe; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class CrudeAxeIdleTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH IDLE ***/ + Textures.crudeAxeSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.crudeAxeSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.crudeAxeSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.crudeAxeSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + + /*** NORTH IDLE ***/ + Textures.crudeAxeSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.crudeAxeSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.crudeAxeSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.crudeAxeSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + + /*** WEST IDLE ***/ + Textures.crudeAxeSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.crudeAxeSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.crudeAxeSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.crudeAxeSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + + /*** EAST IDLE ***/ + Textures.crudeAxeSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.crudeAxeSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.crudeAxeSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.crudeAxeSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + + /*** NORTHWEST IDLE ***/ + Textures.crudeAxeSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.crudeAxeSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.crudeAxeSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.crudeAxeSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + + /*** NORTHEAST IDLE ***/ + Textures.crudeAxeSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.crudeAxeSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.crudeAxeSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.crudeAxeSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + + /*** SOUTHWEST IDLE ***/ + Textures.crudeAxeSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.crudeAxeSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.crudeAxeSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.crudeAxeSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + + /*** SOUTHEAST IDLE ***/ + Textures.crudeAxeSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.crudeAxeSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.crudeAxeSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.crudeAxeSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } +} diff --git a/src/textures/player/items/crudeaxe/CrudeAxeWalkTextures.java b/src/textures/player/items/crudeaxe/CrudeAxeWalkTextures.java new file mode 100755 index 0000000..6b6a9f9 --- /dev/null +++ b/src/textures/player/items/crudeaxe/CrudeAxeWalkTextures.java @@ -0,0 +1,75 @@ +package textures.player.items.crudeaxe; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class CrudeAxeWalkTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH WALK ***/ + Textures.crudeAxeSheet[32] = Utils.grabSprite(image, 5, 1, 40, 72); + Textures.crudeAxeSheet[33] = Utils.grabSprite(image, 6, 1, 40, 72); + Textures.crudeAxeSheet[34] = Utils.grabSprite(image, 7, 1, 40, 72); + Textures.crudeAxeSheet[35] = Utils.grabSprite(image, 8, 1, 40, 72); + Textures.crudeAxeSheet[36] = Utils.grabSprite(image, 9, 1, 40, 72); + Textures.crudeAxeSheet[37] = Utils.grabSprite(image, 10, 1, 40, 72); + + /*** NORTH WALK ***/ + Textures.crudeAxeSheet[38] = Utils.grabSprite(image, 5, 2, 40, 72); + Textures.crudeAxeSheet[39] = Utils.grabSprite(image, 6, 2, 40, 72); + Textures.crudeAxeSheet[40] = Utils.grabSprite(image, 7, 2, 40, 72); + Textures.crudeAxeSheet[41] = Utils.grabSprite(image, 8, 2, 40, 72); + Textures.crudeAxeSheet[42] = Utils.grabSprite(image, 9, 2, 40, 72); + Textures.crudeAxeSheet[43] = Utils.grabSprite(image, 10, 2, 40, 72); + + /*** WEST WALK ***/ + Textures.crudeAxeSheet[44] = Utils.grabSprite(image, 5, 3, 40, 72); + Textures.crudeAxeSheet[45] = Utils.grabSprite(image, 6, 3, 40, 72); + Textures.crudeAxeSheet[46] = Utils.grabSprite(image, 7, 3, 40, 72); + Textures.crudeAxeSheet[47] = Utils.grabSprite(image, 8, 3, 40, 72); + Textures.crudeAxeSheet[48] = Utils.grabSprite(image, 9, 3, 40, 72); + Textures.crudeAxeSheet[49] = Utils.grabSprite(image, 10, 3, 40, 72); + + /*** EAST WALK ***/ + Textures.crudeAxeSheet[50] = Utils.grabSprite(image, 5, 4, 40, 72); + Textures.crudeAxeSheet[51] = Utils.grabSprite(image, 6, 4, 40, 72); + Textures.crudeAxeSheet[52] = Utils.grabSprite(image, 7, 4, 40, 72); + Textures.crudeAxeSheet[53] = Utils.grabSprite(image, 8, 4, 40, 72); + Textures.crudeAxeSheet[54] = Utils.grabSprite(image, 9, 4, 40, 72); + Textures.crudeAxeSheet[55] = Utils.grabSprite(image, 10, 4, 40, 72); + + /*** NORTHWEST WALK ***/ + Textures.crudeAxeSheet[56] = Utils.grabSprite(image, 5, 5, 40, 72); + Textures.crudeAxeSheet[57] = Utils.grabSprite(image, 6, 5, 40, 72); + Textures.crudeAxeSheet[58] = Utils.grabSprite(image, 7, 5, 40, 72); + Textures.crudeAxeSheet[59] = Utils.grabSprite(image, 8, 5, 40, 72); + Textures.crudeAxeSheet[60] = Utils.grabSprite(image, 9, 5, 40, 72); + Textures.crudeAxeSheet[61] = Utils.grabSprite(image, 10, 5, 40, 72); + + /*** NORTHEAST WALK ***/ + Textures.crudeAxeSheet[62] = Utils.grabSprite(image, 5, 6, 40, 72); + Textures.crudeAxeSheet[63] = Utils.grabSprite(image, 6, 6, 40, 72); + Textures.crudeAxeSheet[64] = Utils.grabSprite(image, 7, 6, 40, 72); + Textures.crudeAxeSheet[65] = Utils.grabSprite(image, 8, 6, 40, 72); + Textures.crudeAxeSheet[66] = Utils.grabSprite(image, 9, 6, 40, 72); + Textures.crudeAxeSheet[67] = Utils.grabSprite(image, 10, 6, 40, 72); + + /*** SOUTHWEST WALK ***/ + Textures.crudeAxeSheet[68] = Utils.grabSprite(image, 5, 7, 40, 72); + Textures.crudeAxeSheet[69] = Utils.grabSprite(image, 6, 7, 40, 72); + Textures.crudeAxeSheet[70] = Utils.grabSprite(image, 7, 7, 40, 72); + Textures.crudeAxeSheet[71] = Utils.grabSprite(image, 8, 7, 40, 72); + Textures.crudeAxeSheet[72] = Utils.grabSprite(image, 9, 7, 40, 72); + Textures.crudeAxeSheet[73] = Utils.grabSprite(image, 10, 7, 40, 72); + + /*** SOUTHEAST WALK ***/ + Textures.crudeAxeSheet[74] = Utils.grabSprite(image, 5, 8, 40, 72); + Textures.crudeAxeSheet[75] = Utils.grabSprite(image, 6, 8, 40, 72); + Textures.crudeAxeSheet[76] = Utils.grabSprite(image, 7, 8, 40, 72); + Textures.crudeAxeSheet[77] = Utils.grabSprite(image, 8, 8, 40, 72); + Textures.crudeAxeSheet[78] = Utils.grabSprite(image, 9, 8, 40, 72); + Textures.crudeAxeSheet[79] = Utils.grabSprite(image, 10, 8, 40, 72); + } +} diff --git a/src/textures/player/items/crudepickaxe/CrudePickAxeGetHitTextures.java b/src/textures/player/items/crudepickaxe/CrudePickAxeGetHitTextures.java new file mode 100755 index 0000000..8c528af --- /dev/null +++ b/src/textures/player/items/crudepickaxe/CrudePickAxeGetHitTextures.java @@ -0,0 +1,28 @@ +package textures.player.items.crudepickaxe; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class CrudePickAxeGetHitTextures { + + public static final void getTextures(BufferedImage image) { + final int width = 40, height = 72; final int col = 1; + int row = 1; + int START = 80; + Textures.crudePickaxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudePickaxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudePickaxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudePickaxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudePickaxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudePickaxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudePickaxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.crudePickaxeSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + } + +} diff --git a/src/textures/player/items/crudepickaxe/CrudePickaxeIdleTextures.java b/src/textures/player/items/crudepickaxe/CrudePickaxeIdleTextures.java new file mode 100755 index 0000000..a6116dc --- /dev/null +++ b/src/textures/player/items/crudepickaxe/CrudePickaxeIdleTextures.java @@ -0,0 +1,59 @@ +package textures.player.items.crudepickaxe; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class CrudePickaxeIdleTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH IDLE ***/ + Textures.crudePickaxeSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.crudePickaxeSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.crudePickaxeSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.crudePickaxeSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + + /*** NORTH IDLE ***/ + Textures.crudePickaxeSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.crudePickaxeSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.crudePickaxeSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.crudePickaxeSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + + /*** WEST IDLE ***/ + Textures.crudePickaxeSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.crudePickaxeSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.crudePickaxeSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.crudePickaxeSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + + /*** EAST IDLE ***/ + Textures.crudePickaxeSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.crudePickaxeSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.crudePickaxeSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.crudePickaxeSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + + /*** NORTHWEST IDLE ***/ + Textures.crudePickaxeSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.crudePickaxeSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.crudePickaxeSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.crudePickaxeSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + + /*** NORTHEAST IDLE ***/ + Textures.crudePickaxeSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.crudePickaxeSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.crudePickaxeSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.crudePickaxeSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + + /*** SOUTHWEST IDLE ***/ + Textures.crudePickaxeSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.crudePickaxeSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.crudePickaxeSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.crudePickaxeSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + + /*** SOUTHEAST IDLE ***/ + Textures.crudePickaxeSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.crudePickaxeSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.crudePickaxeSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.crudePickaxeSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } +} diff --git a/src/textures/player/items/crudepickaxe/CrudePickaxeMineTextures.java b/src/textures/player/items/crudepickaxe/CrudePickaxeMineTextures.java new file mode 100755 index 0000000..41a3a22 --- /dev/null +++ b/src/textures/player/items/crudepickaxe/CrudePickaxeMineTextures.java @@ -0,0 +1,51 @@ +package textures.player.items.crudepickaxe; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class CrudePickaxeMineTextures { + public static void getTextures(BufferedImage image){ + /*** FACING SOUTH ***/ + Textures.crudePickaxeMineSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.crudePickaxeMineSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.crudePickaxeMineSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.crudePickaxeMineSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + /*** FACING NORTH ***/ + Textures.crudePickaxeMineSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.crudePickaxeMineSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.crudePickaxeMineSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.crudePickaxeMineSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + /*** FACING WEST ***/ + Textures.crudePickaxeMineSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.crudePickaxeMineSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.crudePickaxeMineSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.crudePickaxeMineSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + /*** FACING EAST ***/ + Textures.crudePickaxeMineSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.crudePickaxeMineSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.crudePickaxeMineSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.crudePickaxeMineSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + /*** FACING NW ***/ + Textures.crudePickaxeMineSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.crudePickaxeMineSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.crudePickaxeMineSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.crudePickaxeMineSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + /*** FACING NE ***/ + Textures.crudePickaxeMineSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.crudePickaxeMineSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.crudePickaxeMineSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.crudePickaxeMineSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + /*** FACING SW ***/ + Textures.crudePickaxeMineSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.crudePickaxeMineSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.crudePickaxeMineSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.crudePickaxeMineSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + /*** FACING SE ***/ + Textures.crudePickaxeMineSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.crudePickaxeMineSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.crudePickaxeMineSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.crudePickaxeMineSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } +} diff --git a/src/textures/player/items/crudepickaxe/CrudePickaxeWalkTextures.java b/src/textures/player/items/crudepickaxe/CrudePickaxeWalkTextures.java new file mode 100755 index 0000000..246602f --- /dev/null +++ b/src/textures/player/items/crudepickaxe/CrudePickaxeWalkTextures.java @@ -0,0 +1,74 @@ +package textures.player.items.crudepickaxe; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class CrudePickaxeWalkTextures { + public static void getTextures(BufferedImage image){ + /*** SOUTH WALK ***/ + Textures.crudePickaxeSheet[32] = Utils.grabSprite(image, 5, 1, 40, 72); + Textures.crudePickaxeSheet[33] = Utils.grabSprite(image, 6, 1, 40, 72); + Textures.crudePickaxeSheet[34] = Utils.grabSprite(image, 7, 1, 40, 72); + Textures.crudePickaxeSheet[35] = Utils.grabSprite(image, 8, 1, 40, 72); + Textures.crudePickaxeSheet[36] = Utils.grabSprite(image, 9, 1, 40, 72); + Textures.crudePickaxeSheet[37] = Utils.grabSprite(image, 10, 1, 40, 72); + + /*** NORTH WALK ***/ + Textures.crudePickaxeSheet[38] = Utils.grabSprite(image, 5, 2, 40, 72); + Textures.crudePickaxeSheet[39] = Utils.grabSprite(image, 6, 2, 40, 72); + Textures.crudePickaxeSheet[40] = Utils.grabSprite(image, 7, 2, 40, 72); + Textures.crudePickaxeSheet[41] = Utils.grabSprite(image, 8, 2, 40, 72); + Textures.crudePickaxeSheet[42] = Utils.grabSprite(image, 9, 2, 40, 72); + Textures.crudePickaxeSheet[43] = Utils.grabSprite(image, 10, 2, 40, 72); + + /*** WEST WALK ***/ + Textures.crudePickaxeSheet[44] = Utils.grabSprite(image, 5, 3, 40, 72); + Textures.crudePickaxeSheet[45] = Utils.grabSprite(image, 6, 3, 40, 72); + Textures.crudePickaxeSheet[46] = Utils.grabSprite(image, 7, 3, 40, 72); + Textures.crudePickaxeSheet[47] = Utils.grabSprite(image, 8, 3, 40, 72); + Textures.crudePickaxeSheet[48] = Utils.grabSprite(image, 9, 3, 40, 72); + Textures.crudePickaxeSheet[49] = Utils.grabSprite(image, 10, 3, 40, 72); + + /*** EAST WALK ***/ + Textures.crudePickaxeSheet[50] = Utils.grabSprite(image, 5, 4, 40, 72); + Textures.crudePickaxeSheet[51] = Utils.grabSprite(image, 6, 4, 40, 72); + Textures.crudePickaxeSheet[52] = Utils.grabSprite(image, 7, 4, 40, 72); + Textures.crudePickaxeSheet[53] = Utils.grabSprite(image, 8, 4, 40, 72); + Textures.crudePickaxeSheet[54] = Utils.grabSprite(image, 9, 4, 40, 72); + Textures.crudePickaxeSheet[55] = Utils.grabSprite(image, 10, 4, 40, 72); + + /*** NORTHWEST WALK ***/ + Textures.crudePickaxeSheet[56] = Utils.grabSprite(image, 5, 5, 40, 72); + Textures.crudePickaxeSheet[57] = Utils.grabSprite(image, 6, 5, 40, 72); + Textures.crudePickaxeSheet[58] = Utils.grabSprite(image, 7, 5, 40, 72); + Textures.crudePickaxeSheet[59] = Utils.grabSprite(image, 8, 5, 40, 72); + Textures.crudePickaxeSheet[60] = Utils.grabSprite(image, 9, 5, 40, 72); + Textures.crudePickaxeSheet[61] = Utils.grabSprite(image, 10, 5, 40, 72); + + /*** NORTHEAST WALK ***/ + Textures.crudePickaxeSheet[62] = Utils.grabSprite(image, 5, 6, 40, 72); + Textures.crudePickaxeSheet[63] = Utils.grabSprite(image, 6, 6, 40, 72); + Textures.crudePickaxeSheet[64] = Utils.grabSprite(image, 7, 6, 40, 72); + Textures.crudePickaxeSheet[65] = Utils.grabSprite(image, 8, 6, 40, 72); + Textures.crudePickaxeSheet[66] = Utils.grabSprite(image, 9, 6, 40, 72); + Textures.crudePickaxeSheet[67] = Utils.grabSprite(image, 10, 6, 40, 72); + + /*** SOUTHWEST WALK ***/ + Textures.crudePickaxeSheet[68] = Utils.grabSprite(image, 5, 7, 40, 72); + Textures.crudePickaxeSheet[69] = Utils.grabSprite(image, 6, 7, 40, 72); + Textures.crudePickaxeSheet[70] = Utils.grabSprite(image, 7, 7, 40, 72); + Textures.crudePickaxeSheet[71] = Utils.grabSprite(image, 8, 7, 40, 72); + Textures.crudePickaxeSheet[72] = Utils.grabSprite(image, 9, 7, 40, 72); + Textures.crudePickaxeSheet[73] = Utils.grabSprite(image, 10, 7, 40, 72); + + /*** SOUTHEAST WALK ***/ + Textures.crudePickaxeSheet[74] = Utils.grabSprite(image, 5, 8, 40, 72); + Textures.crudePickaxeSheet[75] = Utils.grabSprite(image, 6, 8, 40, 72); + Textures.crudePickaxeSheet[76] = Utils.grabSprite(image, 7, 8, 40, 72); + Textures.crudePickaxeSheet[77] = Utils.grabSprite(image, 8, 8, 40, 72); + Textures.crudePickaxeSheet[78] = Utils.grabSprite(image, 9, 8, 40, 72); + Textures.crudePickaxeSheet[79] = Utils.grabSprite(image, 10, 8, 40, 72); + } +} diff --git a/src/textures/player/items/goblinspear/GoblinSpearTextures.java b/src/textures/player/items/goblinspear/GoblinSpearTextures.java new file mode 100755 index 0000000..7c272c9 --- /dev/null +++ b/src/textures/player/items/goblinspear/GoblinSpearTextures.java @@ -0,0 +1,186 @@ +package textures.player.items.goblinspear; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class GoblinSpearTextures { + + private static int count = 0; + + /** ORDER: idles, (8x4) - 32 + * walks, (8x6) - 48 + 32 + * attacks,(8x4) + * getHits(8x1) */ + + public static final void getIdlesWalksTextures(final BufferedImage image) { + + final int width = 40, height = 72; + // IDLES + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 2, width, height); // NORTH + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 2, 2, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 3, 2, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 4, 2, width, height); + + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 6, width, height); // NORTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 2, 6, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 3, 6, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 4, 6, width, height); + + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 4, width, height); // EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 2, 4, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 3, 4, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 4, 4, width, height); + + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 8, width, height); // SOUTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 2, 8, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 3, 8, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 4, 8, width, height); + + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 1, width, height); // SOUTH + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 2, 1, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 3, 1, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 4, 1, width, height); + + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 7, width, height); // SOUTH WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 2, 7, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 3, 7, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 4, 7, width, height); + + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 3, width, height); // WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 2, 3, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 3, 3, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 4, 3, width, height); + + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 5, width, height); // NORTH WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 2, 5, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 3, 5, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 4, 5, width, height); + + // WALKS + int col = 5; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); // NORTH + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); + col = 5; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); // NORTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); + col = 5; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); // EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); + col = 5; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); // SOUTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); + col = 5; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); // SOUTH + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); + col = 5; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); // SOUTH WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); + col = 5; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); // WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); + col = 5; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); // NORTH WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); + } + + public static final void getHitsTextures(BufferedImage image) { + final int width = 40, height = 72; + // GET HITS + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 2, width, height); // NORTH + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 6, width, height); // NORTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 4, width, height); // EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 8, width, height); // SOUTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 1, width, height); // SOUTH + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 7, width, height); // SOUTHWEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 3, width, height); // WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, 1, 5, width, height); // NORTHWEST + } + + public static final void getAttackTextures(BufferedImage image) { + final int width = 40, height = 72; + // ATTACKS + int col = 1; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); // NORTH + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 2, width, height); + col = 1; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); // NORTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 6, width, height); + col = 1; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); // NORTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 4, width, height); + col = 1; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); // SOUTH EAST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 8, width, height); + col = 1; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); // SOUTH + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 1, width, height); + col = 1; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); // SOUTH WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 7, width, height); + col = 1; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); // WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 3, width, height); + col = 1; + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); // NORTH WEST + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); + Textures.goblinSpearSheet[count++] = Utils.grabSprite(image, col++, 5, width, height); + } + + + + + +} diff --git a/src/textures/player/items/torch/TorchGetHitTextures.java b/src/textures/player/items/torch/TorchGetHitTextures.java new file mode 100755 index 0000000..48d63dc --- /dev/null +++ b/src/textures/player/items/torch/TorchGetHitTextures.java @@ -0,0 +1,28 @@ +package textures.player.items.torch; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/** ------------- Nihilne ------------ + *** @author Mitch Weaver - 2016 *** + ~~~~ All Rights Reserved ~~~~ */ + +public final class TorchGetHitTextures { + + public static final void getTextures(BufferedImage image) { + final int width = 40, height = 72; final int col = 1; + int row = 1; + int START = 80; + Textures.torchSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.torchSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.torchSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.torchSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.torchSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.torchSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.torchSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + Textures.torchSheet[START++] = Utils.grabSprite(image, col, row++, width, height); + } + +} diff --git a/src/textures/player/items/torch/TorchIdleTextures.java b/src/textures/player/items/torch/TorchIdleTextures.java new file mode 100755 index 0000000..8d23efe --- /dev/null +++ b/src/textures/player/items/torch/TorchIdleTextures.java @@ -0,0 +1,59 @@ +package textures.player.items.torch; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class TorchIdleTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH IDLE ***/ + Textures.torchSheet[0] = Utils.grabSprite(image, 1, 1, 40, 72); + Textures.torchSheet[1] = Utils.grabSprite(image, 2, 1, 40, 72); + Textures.torchSheet[2] = Utils.grabSprite(image, 3, 1, 40, 72); + Textures.torchSheet[3] = Utils.grabSprite(image, 4, 1, 40, 72); + + /*** NORTH IDLE ***/ + Textures.torchSheet[4] = Utils.grabSprite(image, 1, 2, 40, 72); + Textures.torchSheet[5] = Utils.grabSprite(image, 2, 2, 40, 72); + Textures.torchSheet[6] = Utils.grabSprite(image, 3, 2, 40, 72); + Textures.torchSheet[7] = Utils.grabSprite(image, 4, 2, 40, 72); + + /*** WEST IDLE ***/ + Textures.torchSheet[8] = Utils.grabSprite(image, 1, 3, 40, 72); + Textures.torchSheet[9] = Utils.grabSprite(image, 2, 3, 40, 72); + Textures.torchSheet[10] = Utils.grabSprite(image, 3, 3, 40, 72); + Textures.torchSheet[11] = Utils.grabSprite(image, 4, 3, 40, 72); + + /*** EAST IDLE ***/ + Textures.torchSheet[12] = Utils.grabSprite(image, 1, 4, 40, 72); + Textures.torchSheet[13] = Utils.grabSprite(image, 2, 4, 40, 72); + Textures.torchSheet[14] = Utils.grabSprite(image, 3, 4, 40, 72); + Textures.torchSheet[15] = Utils.grabSprite(image, 4, 4, 40, 72); + + /*** NORTHWEST IDLE ***/ + Textures.torchSheet[16] = Utils.grabSprite(image, 1, 5, 40, 72); + Textures.torchSheet[17] = Utils.grabSprite(image, 2, 5, 40, 72); + Textures.torchSheet[18] = Utils.grabSprite(image, 3, 5, 40, 72); + Textures.torchSheet[19] = Utils.grabSprite(image, 4, 5, 40, 72); + + /*** NORTHEAST IDLE ***/ + Textures.torchSheet[20] = Utils.grabSprite(image, 1, 6, 40, 72); + Textures.torchSheet[21] = Utils.grabSprite(image, 2, 6, 40, 72); + Textures.torchSheet[22] = Utils.grabSprite(image, 3, 6, 40, 72); + Textures.torchSheet[23] = Utils.grabSprite(image, 4, 6, 40, 72); + + /*** SOUTHWEST IDLE ***/ + Textures.torchSheet[24] = Utils.grabSprite(image, 1, 7, 40, 72); + Textures.torchSheet[25] = Utils.grabSprite(image, 2, 7, 40, 72); + Textures.torchSheet[26] = Utils.grabSprite(image, 3, 7, 40, 72); + Textures.torchSheet[27] = Utils.grabSprite(image, 4, 7, 40, 72); + + /*** SOUTHEAST IDLE ***/ + Textures.torchSheet[28] = Utils.grabSprite(image, 1, 8, 40, 72); + Textures.torchSheet[29] = Utils.grabSprite(image, 2, 8, 40, 72); + Textures.torchSheet[30] = Utils.grabSprite(image, 3, 8, 40, 72); + Textures.torchSheet[31] = Utils.grabSprite(image, 4, 8, 40, 72); + } +} diff --git a/src/textures/player/items/torch/TorchWalkTextures.java b/src/textures/player/items/torch/TorchWalkTextures.java new file mode 100755 index 0000000..ba88a5e --- /dev/null +++ b/src/textures/player/items/torch/TorchWalkTextures.java @@ -0,0 +1,76 @@ +package textures.player.items.torch; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class TorchWalkTextures { + + public static void getTextures(BufferedImage image){ + /*** SOUTH WALK ***/ + Textures.torchSheet[32] = Utils.grabSprite(image, 5, 1, 40, 72); + Textures.torchSheet[33] = Utils.grabSprite(image, 6, 1, 40, 72); + Textures.torchSheet[34] = Utils.grabSprite(image, 7, 1, 40, 72); + Textures.torchSheet[35] = Utils.grabSprite(image, 8, 1, 40, 72); + Textures.torchSheet[36] = Utils.grabSprite(image, 9, 1, 40, 72); + Textures.torchSheet[37] = Utils.grabSprite(image, 10, 1, 40, 72); + + /*** NORTH WALK ***/ + Textures.torchSheet[38] = Utils.grabSprite(image, 5, 2, 40, 72); + Textures.torchSheet[39] = Utils.grabSprite(image, 6, 2, 40, 72); + Textures.torchSheet[40] = Utils.grabSprite(image, 7, 2, 40, 72); + Textures.torchSheet[41] = Utils.grabSprite(image, 8, 2, 40, 72); + Textures.torchSheet[42] = Utils.grabSprite(image, 9, 2, 40, 72); + Textures.torchSheet[43] = Utils.grabSprite(image, 10, 2, 40, 72); + + /*** WEST WALK ***/ + Textures.torchSheet[44] = Utils.grabSprite(image, 5, 3, 40, 72); + Textures.torchSheet[45] = Utils.grabSprite(image, 6, 3, 40, 72); + Textures.torchSheet[46] = Utils.grabSprite(image, 7, 3, 40, 72); + Textures.torchSheet[47] = Utils.grabSprite(image, 8, 3, 40, 72); + Textures.torchSheet[48] = Utils.grabSprite(image, 9, 3, 40, 72); + Textures.torchSheet[49] = Utils.grabSprite(image, 10, 3, 40, 72); + + /*** EAST WALK ***/ + Textures.torchSheet[50] = Utils.grabSprite(image, 5, 4, 40, 72); + Textures.torchSheet[51] = Utils.grabSprite(image, 6, 4, 40, 72); + Textures.torchSheet[52] = Utils.grabSprite(image, 7, 4, 40, 72); + Textures.torchSheet[53] = Utils.grabSprite(image, 8, 4, 40, 72); + Textures.torchSheet[54] = Utils.grabSprite(image, 9, 4, 40, 72); + Textures.torchSheet[55] = Utils.grabSprite(image, 10, 4, 40, 72); + + /*** NORTHWEST WALK ***/ + Textures.torchSheet[56] = Utils.grabSprite(image, 5, 5, 40, 72); + Textures.torchSheet[57] = Utils.grabSprite(image, 6, 5, 40, 72); + Textures.torchSheet[58] = Utils.grabSprite(image, 7, 5, 40, 72); + Textures.torchSheet[59] = Utils.grabSprite(image, 8, 5, 40, 72); + Textures.torchSheet[60] = Utils.grabSprite(image, 9, 5, 40, 72); + Textures.torchSheet[61] = Utils.grabSprite(image, 10, 5, 40, 72); + + /*** NORTHEAST WALK ***/ + Textures.torchSheet[62] = Utils.grabSprite(image, 5, 6, 40, 72); + Textures.torchSheet[63] = Utils.grabSprite(image, 6, 6, 40, 72); + Textures.torchSheet[64] = Utils.grabSprite(image, 7, 6, 40, 72); + Textures.torchSheet[65] = Utils.grabSprite(image, 8, 6, 40, 72); + Textures.torchSheet[66] = Utils.grabSprite(image, 9, 6, 40, 72); + Textures.torchSheet[67] = Utils.grabSprite(image, 10, 6, 40, 72); + + /*** SOUTHWEST WALK ***/ + Textures.torchSheet[68] = Utils.grabSprite(image, 5, 7, 40, 72); + Textures.torchSheet[69] = Utils.grabSprite(image, 6, 7, 40, 72); + Textures.torchSheet[70] = Utils.grabSprite(image, 7, 7, 40, 72); + Textures.torchSheet[71] = Utils.grabSprite(image, 8, 7, 40, 72); + Textures.torchSheet[72] = Utils.grabSprite(image, 9, 7, 40, 72); + Textures.torchSheet[73] = Utils.grabSprite(image, 10, 7, 40, 72); + + /*** SOUTHEAST WALK ***/ + Textures.torchSheet[74] = Utils.grabSprite(image, 5, 8, 40, 72); + Textures.torchSheet[75] = Utils.grabSprite(image, 6, 8, 40, 72); + Textures.torchSheet[76] = Utils.grabSprite(image, 7, 8, 40, 72); + Textures.torchSheet[77] = Utils.grabSprite(image, 8, 8, 40, 72); + Textures.torchSheet[78] = Utils.grabSprite(image, 9, 8, 40, 72); + Textures.torchSheet[79] = Utils.grabSprite(image, 10, 8, 40, 72); + } + +} diff --git a/src/textures/settings/SettingsTextures.java b/src/textures/settings/SettingsTextures.java new file mode 100755 index 0000000..22cda33 --- /dev/null +++ b/src/textures/settings/SettingsTextures.java @@ -0,0 +1,79 @@ +package textures.settings; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class SettingsTextures { + + public static void getTextures(BufferedImage image) { + + // Settings Buttons + /****** Brown Buttons Default ******/ + Textures.settingsButtonSheet[0] = Utils.grabSprite(image, 1, 1, 155, 29); + Textures.settingsButtonSheet[2] = Utils.grabSprite(image, 1, 3, 155, 29); + Textures.settingsButtonSheet[4] = Utils.grabSprite(image, 1, 5, 155, 29); + Textures.settingsButtonSheet[6] = Utils.grabSprite(image, 1, 7, 155, 29); + Textures.settingsButtonSheet[8] = Utils.grabSprite(image, 1, 9, 155, 29); + Textures.settingsButtonSheet[10] = Utils.grabSprite(image, 2, 5, 155, 29); + Textures.settingsButtonSheet[52] = Utils.grabSprite(image, 2, 7, 155, 29); + /******* Brown Buttons Hovered ******/ + Textures.settingsButtonSheet[1] = Utils.grabSprite(image, 1, 2, 155, 29); + Textures.settingsButtonSheet[3] = Utils.grabSprite(image, 1, 4, 155, 29); + Textures.settingsButtonSheet[5] = Utils.grabSprite(image, 1, 6, 155, 29); + Textures.settingsButtonSheet[7] = Utils.grabSprite(image, 1, 8, 155, 29); + Textures.settingsButtonSheet[9] = Utils.grabSprite(image, 1, 10, 155, 29); + Textures.settingsButtonSheet[11] = Utils.grabSprite(image, 2, 6, 155, 29); + Textures.settingsButtonSheet[53] = Utils.grabSprite(image, 2, 8, 155, 29); + + /****** TRUE / FALSE Default ******/ + Textures.settingsButtonSheet[12] = Utils.grabSprite(image, 2, 1, 155, 29); + Textures.settingsButtonSheet[14] = Utils.grabSprite(image, 2, 3, 155, 29); + /****** TRUE / FALSE Hovered ******/ + Textures.settingsButtonSheet[13] = Utils.grabSprite(image, 2, 2, 155, 29); + Textures.settingsButtonSheet[15] = Utils.grabSprite(image, 2, 4, 155, 29); + + /******* Resolutions Default ********/ + Textures.settingsButtonSheet[16] = Utils.grabSprite(image, 3, 1, 155, 29); + Textures.settingsButtonSheet[18] = Utils.grabSprite(image, 3, 3, 155, 29); + Textures.settingsButtonSheet[20] = Utils.grabSprite(image, 3, 5, 155, 29); + Textures.settingsButtonSheet[22] = Utils.grabSprite(image, 3, 7, 155, 29); + Textures.settingsButtonSheet[24] = Utils.grabSprite(image, 3, 9, 155, 29); + Textures.settingsButtonSheet[26] = Utils.grabSprite(image, 3, 11, 155, 29); + Textures.settingsButtonSheet[28] = Utils.grabSprite(image, 4, 2, 155, 29); + Textures.settingsButtonSheet[30] = Utils.grabSprite(image, 4, 4, 155, 29); + Textures.settingsButtonSheet[32] = Utils.grabSprite(image, 4, 6, 155, 29); + Textures.settingsButtonSheet[34] = Utils.grabSprite(image, 4, 8, 155, 29); + Textures.settingsButtonSheet[36] = Utils.grabSprite(image, 4, 10, 155, 29); + /******** Resolutions Hovered *******/ + Textures.settingsButtonSheet[17] = Utils.grabSprite(image, 3, 2, 155, 29); + Textures.settingsButtonSheet[19] = Utils.grabSprite(image, 3, 4, 155, 29); + Textures.settingsButtonSheet[21] = Utils.grabSprite(image, 3, 6, 155, 29); + Textures.settingsButtonSheet[23] = Utils.grabSprite(image, 3, 8, 155, 29); + Textures.settingsButtonSheet[25] = Utils.grabSprite(image, 3, 10, 155, 29); + Textures.settingsButtonSheet[27] = Utils.grabSprite(image, 4, 1, 155, 29); + Textures.settingsButtonSheet[29] = Utils.grabSprite(image, 4, 3, 155, 29); + Textures.settingsButtonSheet[31] = Utils.grabSprite(image, 4, 5, 155, 29); + Textures.settingsButtonSheet[33] = Utils.grabSprite(image, 4, 7, 155, 29); + Textures.settingsButtonSheet[35] = Utils.grabSprite(image, 4, 9, 155, 29); + Textures.settingsButtonSheet[37] = Utils.grabSprite(image, 4, 11, 155, 29); + + /****** FPS CAPS DEFAULT *******/ + Textures.settingsButtonSheet[38] = Utils.grabSprite(image, 5, 1, 155, 29); + Textures.settingsButtonSheet[39] = Utils.grabSprite(image, 5, 2, 155, 29); + Textures.settingsButtonSheet[40] = Utils.grabSprite(image, 5, 3, 155, 29); + Textures.settingsButtonSheet[41] = Utils.grabSprite(image, 5, 4, 155, 29); + Textures.settingsButtonSheet[42] = Utils.grabSprite(image, 5, 5, 155, 29); + Textures.settingsButtonSheet[43] = Utils.grabSprite(image, 5, 6, 155, 29); + Textures.settingsButtonSheet[44] = Utils.grabSprite(image, 5, 7, 155, 29); + /******* FPS CAPS Hovered ******/ + Textures.settingsButtonSheet[45] = Utils.grabSprite(image, 6, 1, 155, 29); + Textures.settingsButtonSheet[46] = Utils.grabSprite(image, 6, 2, 155, 29); + Textures.settingsButtonSheet[47] = Utils.grabSprite(image, 6, 3, 155, 29); + Textures.settingsButtonSheet[48] = Utils.grabSprite(image, 6, 4, 155, 29); + Textures.settingsButtonSheet[49] = Utils.grabSprite(image, 6, 5, 155, 29); + Textures.settingsButtonSheet[50] = Utils.grabSprite(image, 6, 6, 155, 29); + Textures.settingsButtonSheet[51] = Utils.grabSprite(image, 6, 7, 155, 29); + } +} diff --git a/src/textures/structures/StructuresTextures.java b/src/textures/structures/StructuresTextures.java new file mode 100755 index 0000000..2bd80ef --- /dev/null +++ b/src/textures/structures/StructuresTextures.java @@ -0,0 +1,19 @@ +package textures.structures; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class StructuresTextures { + + public static void getTextures(BufferedImage image){ + Textures.structureSheet[0] = Utils.grabSprite(image, 1, 1, 22, 22); + Textures.structureSheet[1] = Utils.grabSprite(image, 2, 1, 22, 22); + Textures.structureSheet[2] = Utils.grabSprite(image, 3, 1, 22, 22); + Textures.structureSheet[3] = Utils.grabSprite(image, 4, 1, 22, 22); + Textures.structureSheet[4] = Utils.grabSprite(image, 5, 1, 22, 22); + Textures.structureSheet[5] = Utils.grabSprite(image, 6, 1, 22, 22); + } + +} diff --git a/src/textures/worldgen/BoulderTextures.java b/src/textures/worldgen/BoulderTextures.java new file mode 100755 index 0000000..9e9a542 --- /dev/null +++ b/src/textures/worldgen/BoulderTextures.java @@ -0,0 +1,18 @@ +package textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class BoulderTextures { + + public static void getTextures(BufferedImage image) { + // small boulders + for(int i = 0; i < 4; i++) Textures.boulderSheet[i] = Utils.grabSprite(image, i+1, 1, 30, 20); + + // large boulders + for(int i = 4; i < 8; i++) Textures.boulderSheet[i] = Utils.grabSprite(image, i-4+1, 2, 55, 42); + } + +} diff --git a/src/textures/worldgen/DebrisTextures.java b/src/textures/worldgen/DebrisTextures.java new file mode 100755 index 0000000..ea704e2 --- /dev/null +++ b/src/textures/worldgen/DebrisTextures.java @@ -0,0 +1,15 @@ +package textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class DebrisTextures { + + public static void getTextures(BufferedImage image) { + for(int i = 0; i < 4; i++) Textures.debrisSheet[i] = Utils.grabSprite(image, i+1, 1, 15, 10); + + for(int i = 4; i < 7; i++) Textures.debrisSheet[i] = Utils.grabSprite(image, i+1-4, 2, 15, 10); + } +} diff --git a/src/textures/worldgen/FlowerTextures.java b/src/textures/worldgen/FlowerTextures.java new file mode 100755 index 0000000..e34c9a3 --- /dev/null +++ b/src/textures/worldgen/FlowerTextures.java @@ -0,0 +1,28 @@ +package textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class FlowerTextures { + + public static void getTextures(BufferedImage image) { + Textures.flowerSheet[0] = Utils.grabSprite(image, 1, 1, 23, 8); + Textures.flowerSheet[1] = Utils.grabSprite(image, 2, 1, 23, 8); + Textures.flowerSheet[2] = Utils.grabSprite(image, 3, 1, 23, 8); + Textures.flowerSheet[3] = Utils.grabSprite(image, 4, 1, 23, 8); + Textures.flowerSheet[4] = Utils.grabSprite(image, 5, 1, 23, 8); + Textures.flowerSheet[5] = Utils.grabSprite(image, 6, 1, 23, 8); + Textures.flowerSheet[6] = Utils.grabSprite(image, 7, 1, 23, 8); + Textures.flowerSheet[7] = Utils.grabSprite(image, 8, 1, 23, 8); + Textures.flowerSheet[8] = Utils.grabSprite(image, 1, 2, 23, 8); + Textures.flowerSheet[9] = Utils.grabSprite(image, 2, 2, 23, 8); + Textures.flowerSheet[10] = Utils.grabSprite(image, 3, 2, 23, 8); + Textures.flowerSheet[11] = Utils.grabSprite(image, 4, 2, 23, 8); + Textures.flowerSheet[12] = Utils.grabSprite(image, 5, 2, 23, 8); + Textures.flowerSheet[13] = Utils.grabSprite(image, 6, 2, 23, 8); + Textures.flowerSheet[14] = Utils.grabSprite(image, 7, 2, 23, 8); + Textures.flowerSheet[15] = Utils.grabSprite(image, 8, 2, 23, 8); + } +} diff --git a/src/textures/worldgen/SaplingTextures.java b/src/textures/worldgen/SaplingTextures.java new file mode 100755 index 0000000..66bd4a3 --- /dev/null +++ b/src/textures/worldgen/SaplingTextures.java @@ -0,0 +1,18 @@ +package textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class SaplingTextures { + + public static void getTextures(BufferedImage image) { + Textures.saplingSheet[0] = Utils.grabSprite(image, 1, 1, 16, 25); + Textures.saplingSheet[1] = Utils.grabSprite(image, 2, 1, 16, 25); + Textures.saplingSheet[2] = Utils.grabSprite(image, 3, 1, 16, 25); + Textures.saplingSheet[3] = Utils.grabSprite(image, 4, 1, 16, 25); + Textures.saplingSheet[4] = Utils.grabSprite(image, 5, 1, 16, 25); + } + +} diff --git a/src/textures/worldgen/TallGrassTextures.java b/src/textures/worldgen/TallGrassTextures.java new file mode 100755 index 0000000..70860f4 --- /dev/null +++ b/src/textures/worldgen/TallGrassTextures.java @@ -0,0 +1,20 @@ +package textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class TallGrassTextures { + + public static void getTextures(BufferedImage image) { + Textures.grassSheet[0] = Utils.grabSprite(image, 1, 1, 14, 16); + Textures.grassSheet[1] = Utils.grabSprite(image, 2, 1, 14, 16); + Textures.grassSheet[2] = Utils.grabSprite(image, 3, 1, 14, 16); + Textures.grassSheet[3] = Utils.grabSprite(image, 4, 1, 14, 16); + Textures.grassSheet[4] = Utils.grabSprite(image, 5, 1, 14, 16); + Textures.grassSheet[5] = Utils.grabSprite(image, 6, 1, 14, 16); + Textures.grassSheet[6] = Utils.grabSprite(image, 7, 1, 14, 16); + } + +} diff --git a/src/textures/worldgen/TileTextures.java b/src/textures/worldgen/TileTextures.java new file mode 100755 index 0000000..1403fd5 --- /dev/null +++ b/src/textures/worldgen/TileTextures.java @@ -0,0 +1,53 @@ +package textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class TileTextures { + + public static void getTextures(BufferedImage image) { + Textures.tileSheet[0] = Utils.grabSprite(image, 1, 1, 34, 34); + Textures.tileSheet[1] = Utils.grabSprite(image, 1, 2, 34, 34); + Textures.tileSheet[2] = Utils.grabSprite(image, 1, 3, 34, 34); + Textures.tileSheet[3] = Utils.grabSprite(image, 1, 4, 34, 34); + Textures.tileSheet[4] = Utils.grabSprite(image, 1, 5, 34, 34); + Textures.tileSheet[5] = Utils.grabSprite(image, 1, 6, 34, 34); + Textures.tileSheet[6] = Utils.grabSprite(image, 1, 7, 34, 34); + Textures.tileSheet[7] = Utils.grabSprite(image, 1, 8, 34, 34); + Textures.tileSheet[8] = Utils.grabSprite(image, 1, 9, 34, 34); + Textures.tileSheet[9] = Utils.grabSprite(image, 1, 10, 34, 34); + Textures.tileSheet[10] = Utils.grabSprite(image, 1, 11, 34, 34); + Textures.tileSheet[11] = Utils.grabSprite(image, 1, 12, 34, 34); + Textures.tileSheet[12] = Utils.grabSprite(image, 1, 13, 34, 34); + Textures.tileSheet[13] = Utils.grabSprite(image, 1, 14, 34, 34); + Textures.tileSheet[14] = Utils.grabSprite(image, 1, 15, 34, 34); + Textures.tileSheet[15] = Utils.grabSprite(image, 1, 16, 34, 34); + Textures.tileSheet[16] = Utils.grabSprite(image, 1, 17, 34, 34); + Textures.tileSheet[17] = Utils.grabSprite(image, 1, 18, 34, 34); + } + + public static void getOceanTextures(BufferedImage image) { + Textures.tileSheet[18] = Utils.grabSprite(image, 1, 1, 32, 32); + Textures.tileSheet[19] = Utils.grabSprite(image, 2, 1, 32, 32); + Textures.tileSheet[20] = Utils.grabSprite(image, 3, 1, 32, 32); + Textures.tileSheet[21] = Utils.grabSprite(image, 4, 1, 32, 32); + Textures.tileSheet[22] = Utils.grabSprite(image, 5, 1, 32, 32); + Textures.tileSheet[23] = Utils.grabSprite(image, 6, 1, 32, 32); + Textures.tileSheet[24] = Utils.grabSprite(image, 7, 1, 32, 32); + Textures.tileSheet[25] = Utils.grabSprite(image, 8, 1, 32, 32); + Textures.tileSheet[26] = Utils.grabSprite(image, 1, 2, 32, 32); + Textures.tileSheet[27] = Utils.grabSprite(image, 2, 2, 32, 32); + Textures.tileSheet[28] = Utils.grabSprite(image, 3, 2, 32, 32); + Textures.tileSheet[29] = Utils.grabSprite(image, 4, 2, 32, 32); + Textures.tileSheet[30] = Utils.grabSprite(image, 5, 2, 32, 32); + Textures.tileSheet[31] = Utils.grabSprite(image, 6, 2, 32, 32); + Textures.tileSheet[32] = Utils.grabSprite(image, 7, 2, 32, 32); + Textures.tileSheet[33] = Utils.grabSprite(image, 8, 2, 32, 32); + } +} diff --git a/src/textures/worldgen/TreeTextures.java b/src/textures/worldgen/TreeTextures.java new file mode 100755 index 0000000..1d1ef35 --- /dev/null +++ b/src/textures/worldgen/TreeTextures.java @@ -0,0 +1,17 @@ +package textures.worldgen; + +import java.awt.image.BufferedImage; + +import _texture.loader.Textures; +import utils.Utils; + +public class TreeTextures { + + public static void getTextures(BufferedImage image) { + Textures.treeSheet[0] = Utils.grabSprite(image, 1, 1, 64, 64); + Textures.treeSheet[1] = Utils.grabSprite(image, 2, 1, 64, 64); + Textures.treeSheet[2] = Utils.grabSprite(image, 3, 1, 64, 64); + Textures.treeSheet[3] = Utils.grabSprite(image, 4, 1, 64, 64); + } + +} diff --git a/src/world/Boulder.java b/src/world/Boulder.java new file mode 100755 index 0000000..a2883e6 --- /dev/null +++ b/src/world/Boulder.java @@ -0,0 +1,122 @@ +package world; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import fonts.fonts; +import hud.inventory.InvenHelper; +import interfaces.Entity; +import interfaces.GameObject; +import player.Player; +import utils.Point2f; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class Boulder extends Entity implements GameObject { + + private static final int MAX_HEALTH = 13; + + private int type, rocksAwarded; + public float mineRadius; + private long pickTimer; + + public Boulder(int x, int y) { + this.pos = new Point2f(x, y); + if (Utils.rand.nextBoolean()) { + this.type = (Utils.rand.nextInt(4)) + 4; + if (this.type == 4) { + this.width = 49; + this.height = 36; + } else if (this.type == 5) { + this.width = 52; + this.height = 34; + } else if (this.type == 6) { + this.width = 40; + this.height = 42; + } else if (this.type == 7) { + this.width = 53; + this.height = 31; + } + + rocksAwarded = Utils.rand.nextInt(5) + 3; health = MAX_HEALTH; + } else { this.type = 0; rocksAwarded = Utils.rand.nextInt(3) + 1; health = 8;} + + this.center = new Point2f(this.pos.x + this.width / 2, this.pos.y + this.height / 2); + this.radius = this.width / 2; + this.mineRadius = this.radius*1.7f; + this.alive = true; + this.pickTimer = System.currentTimeMillis(); + Handler.boulders.add(this); + } + + public void tick() { + if(!checkIfAlive() || !getDiscoveryStatus()) return; + + if (playerCollided && Player.using) { + if (InvenHelper.isPickaxe(Player.equipmentSlots[3].itemId)) getPicked(Player.equipmentSlots[3].itemId); + } + + switch(health){ + case MAX_HEALTH: return; + case 8: { type = 0; width = 28; height = 18; break; } + case 6: { type = 1; width = 27; height = 17; break; } + case 4: { type = 2; width = 18; height = 17; break; } + case 2: { type = 3; width = 15; height = 18; break; } + case 0: { + DroppedItem.dropItemsWithOffset(6, rocksAwarded, 25, center.x, center.y, 100); + Handler.boulders.remove(this); + } + } + + center.setLocation(pos.x + width / 2, pos.y + height / 2); + radius = width / 2; mineRadius = radius*1.7f; + } + + private void getPicked(int axeType) { + int chopDamage = 0; + switch (axeType) { + case 5: chopDamage = 1000; break; + case 1337: chopDamage = 500; break; + } + + if (System.currentTimeMillis() - pickTimer > chopDamage) { + health = Utils.clamp(--health, 0, 13); + Player.equipmentSlots[3].durability -= 2.5f; + pickTimer = System.currentTimeMillis(); + } + } + + private Graphics2D copy; + private AffineTransform transform = new AffineTransform(); + public void render(Graphics2D g2d) { + if(!discovered) return; + if(!alive) return; + copy = (Graphics2D) g2d.create(); transform.setToRotation(-Utils._45 * (Game.rotation - 1), pos.x + width / 2, pos.y + height / 2); copy.transform(transform); + + copy.drawImage(Textures.boulderSheet[type], (int)pos.x, (int)pos.y, null); + + + if (Game.drawCollisionBounds) { + g2d.setColor(Color.MAGENTA); + g2d.drawOval((int) (center.x - radius), (int) (center.y - radius), (int) radius * 2, (int) radius * 2); + g2d.setColor(Color.yellow); + g2d.drawOval((int) (center.x - mineRadius), (int) (center.y - mineRadius), (int) mineRadius * 2, (int) mineRadius * 2); + } + + if (Game.drawResourceNumbers) { + g2d.setColor(Color.white); + g2d.setFont(fonts.ponderosa20); + g2d.drawString(Integer.toString(health), center.x, center.y); + } + + copy.dispose(); + } + +} diff --git a/src/world/Debris.java b/src/world/Debris.java new file mode 100755 index 0000000..03a0934 --- /dev/null +++ b/src/world/Debris.java @@ -0,0 +1,40 @@ +package world; + +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import interfaces.GameObject; +import player.Player; +import utils.Utils; + +public class Debris implements GameObject { + + public int x, y, width, height, type; + public boolean discovered; + + public Debris(int x, int y) { + this.x = x; this.y = y; + this.type = Utils.rand.nextInt(7); /* assign it a random sprite */ + Handler.debris.add(this); + } + + private Graphics2D copy; + private AffineTransform transform = new AffineTransform(); + public void render(Graphics2D g2d) { + if(!discovered) return; + if (Game.dontShowDebris) return; + copy = (Graphics2D) g2d.create(); transform.setToRotation(-Utils._45 * (Game.rotation - 1), x + width / 2, y + height / 2); copy.transform(transform); + + copy.drawImage(Textures.debrisSheet[type], (int) x, (int) y, null); + + copy.dispose(); + } + + public void tick() { + if(!Game.dontShowDebris && !discovered && Player.DISCOVERY.contains(x, y)) discovered = true; + } + +} diff --git a/src/world/DroppedItem.java b/src/world/DroppedItem.java new file mode 100755 index 0000000..24f3602 --- /dev/null +++ b/src/world/DroppedItem.java @@ -0,0 +1,138 @@ +package world; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import hud.Clock; +import hud.inventory.Inventory; +import interfaces.GameObject; +import interfaces.ItemIDs; +import player.Player; +import utils.Circle; +import utils.Point2f; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class DroppedItem implements GameObject, ItemIDs { + + public int x, y, itemId, radius, quantity, health, totalHealth; + public float durability; + public Point2f center; + public boolean playerCollided, perishable, discovered; + + public DroppedItem(int x, int y, int itemId, int quantity, float durability) { + this.x = x; this.y = y; this.itemId = itemId; this.quantity = quantity; this.durability = durability; + + switch(itemId){ + case PICKED_FLOWERS: perishable = true; health = Clock.FULL_DAY*14; break; + case ASHES: perishable = true; health = Clock.FULL_DAY*5; break; + case RABBIT_CARCASS: perishable = true; health = Clock.FULL_DAY*3; break; + } + + this.radius = 10; + this.center = new Point2f(x + radius, y + radius); + Handler.droppedItems.add(this); + } + + public DroppedItem(int x, int y, int itemId, int quantity) { new DroppedItem(x, y, itemId, quantity, 100);} + public DroppedItem(Point2f p, int itemId, int quantity) { new DroppedItem((int)p.x, (int)p.y, itemId, quantity, 100);} + public DroppedItem(Point2f p, int itemId, int quantity, float durability){ new DroppedItem((int)p.x, (int)p.y, itemId, quantity, durability);} + public DroppedItem(Point2f p, int itemId){ new DroppedItem((int)p.x, (int)p.y, itemId, 1, 100); } + public DroppedItem(int x, int y, int itemId){ new DroppedItem(x, y, itemId, 1, 100); } + + + public final static void dropItemsWithOffset(int itemId, int quantity, int offset, int centerX, int centerY, float durability) { + final Circle bounds = new Circle(new Point2f(centerX, centerY), offset); + int offsetX, offsetY; + for (int i = 0; i < quantity; i++) { + while(true) { + offsetX = Utils.rand.nextInt(offset); + offsetY = Utils.rand.nextInt(offset); + if (Utils.rand.nextBoolean()) offsetX *= -1; + if (Utils.rand.nextBoolean()) offsetY *= -1; + if(bounds.contains(centerX + offsetX, centerY + offsetY)) { + new DroppedItem(centerX + offsetX, centerY + offsetY, itemId, 1, durability); + break; + } + } + } + } public final static void dropItemsWithOffset(int itemId, int quantity, int offset, float centerX, float centerY, float durability) { dropItemsWithOffset(itemId, quantity, offset, (int)centerX, (int)centerY, durability);} + + public final static void dropItemsWithOffsetAsStack(int itemId, int quantity, int offset, int centerX, int centerY, float durability) { + final Circle bounds = new Circle(new Point2f(centerX, centerY), offset); + while(true) { + int offsetX = Utils.rand.nextInt(offset); + int offsetY = Utils.rand.nextInt(offset); + if (Utils.rand.nextBoolean()) offsetX *= -1; + if (Utils.rand.nextBoolean()) offsetY *= -1; + if(bounds.contains(centerX + offsetX, centerY + offsetY)) { + new DroppedItem(centerX + offsetX, centerY + offsetY, itemId, quantity, durability); + return; + } + } + } public static void dropItemsWithOffsetAsStack(int itemId, int quantity, int offset, float centerX, float centerY, float durability) {dropItemsWithOffsetAsStack(itemId, quantity, offset, (int)centerX, (int)centerY, durability);} + + public final static void dropRandomAmountOfItemsWithOffset(int itemId, int baseQuantity, int ceiling, int offset, int centerX, int centerY, float durability) { + final Circle bounds = new Circle(new Point2f(centerX, centerY), offset); + int offsetX, offsetY, amount = (Utils.rand.nextInt(ceiling) + baseQuantity); + for (int i = 0; i < amount; i++) { + while(true) { + offsetX = Utils.rand.nextInt(offset); + offsetY = Utils.rand.nextInt(offset); + if (Utils.rand.nextBoolean()) offsetX *= -1; + if (Utils.rand.nextBoolean()) offsetY *= -1; + if(bounds.contains(centerX + offsetX, centerY + offsetY)) { + new DroppedItem(centerX + offsetX, centerY + offsetY, itemId, 1, durability); + break; + } + } + } + } public static void dropRandomAmountOfItemsWithOffset(int itemId, int baseQuantity, int ceiling, int offset, float centerX, float centerY, float durability) {dropRandomAmountOfItemsWithOffset(itemId, baseQuantity, ceiling, offset, (int)centerX, (int)centerY, durability); } + public static void dropRandomAmountOfItemsWithOffset(int itemId, int baseQuantity, int ceiling, int offset, float centerX, float centerY) {dropRandomAmountOfItemsWithOffset(itemId, baseQuantity, ceiling, offset, (int)centerX, (int)centerY, 100); } + + public final void tick() { + if(!discovered) discovered = Player.DISCOVERY.contains(x, y); + if(!discovered) return; + + if(perishable && --health <= 0) destroy(); + + if (Player.using && playerCollided && !Inventory.isFull(itemId, quantity)) { + Inventory.addItem(itemId, quantity, durability); + Handler.droppedItems.remove(this); + } + } + + private final void destroy() { + if(perishable) { + switch(itemId) { // SOME ITEMS, LIKE ASHES, SHOULDN"T DROP ROT + case ASHES: break; + default: new DroppedItem(x, y, ROT); + } + } + + Handler.droppedItems.remove(this); + } + + private Graphics2D copy; + private final AffineTransform transform = new AffineTransform(); + public final void render(final Graphics2D g2d) { + copy = (Graphics2D) g2d.create(); transform.setToRotation(-Utils._45 * (Game.rotation - 1), center.x, center.y); copy.transform(transform); + + copy.drawImage(Textures.droppedItemIconSheet[itemId - 1], x, y, null); + + if (Game.drawCollisionBounds) { + copy.setColor(Color.RED); + copy.drawOval((int) (center.x - radius), (int) (center.y - radius), (int) radius * 2, (int) radius * 2); + } + + copy.dispose(); copy = null; + } + +} diff --git a/src/world/Flower.java b/src/world/Flower.java new file mode 100755 index 0000000..88d8699 --- /dev/null +++ b/src/world/Flower.java @@ -0,0 +1,77 @@ +package world; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import hud.inventory.InvenHelper; +import hud.inventory.Inventory; +import interfaces.Colors; +import interfaces.Entity; +import interfaces.GameObject; +import player.Player; +import utils.Point2f; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class Flower extends Entity implements GameObject { + + private final int PICK_UP_DELAY = 45; + + private int type; + private int pickUpTimer; + + public Flower(int x, int y) { + this.pos = new Point2f(x, y); + this.width = 23; // These are according to the sprite size; + this.height = 8; // " " + this.center = new Point2f((int) (pos.x + width / 2), (int) (pos.y + height / 2)); + this.radius = width / 1.2f; + this.type = Utils.rand.nextInt(15); + Handler.flowers.add(this); + } + + + private Graphics2D copy; + private AffineTransform transform = new AffineTransform(); + public void render(Graphics2D g2d) { + if(!discovered) return; + copy = (Graphics2D) g2d.create(); transform.setToRotation(-Utils._45 * (Game.rotation - 1), pos.x + width / 2, pos.y + height / 2); copy.transform(transform); + + if (alive) copy.drawImage(Textures.flowerSheet[type], (int) pos.x, (int) pos.y, null); + else copy.drawImage(Textures.flowerSheet[15], (int) pos.x, (int) pos.y, null); + + if (Game.drawCollisionBounds && alive) { + copy.setColor(Color.YELLOW); + copy.drawOval((int) (center.x - radius), (int) (center.y - radius), (int) radius * 2, (int) radius * 2); + } + + if(pickUpTimer > 0){ + copy.setColor(Colors.offBlack); + copy.fillRect((int)pos.x, (int)pos.y - 14, 20, 4); + copy.setColor(Color.green); + copy.fillRect((int)pos.x + 1, (int)pos.y - 13, (int)(pickUpTimer / 2.3275), 2); + } + + + copy.dispose(); + } + + public void tick() { + if(!checkIfAlive() || !getDiscoveryStatus()) return; + + if (Player.using && alive && playerCollided && !Inventory.isFull(InvenHelper.PICKED_FLOWERS, 1)) { + if (++pickUpTimer >= PICK_UP_DELAY) { + alive = false; + Inventory.addItem(2, 1, 100); + pickUpTimer = 0; } + } else pickUpTimer = 0; + } + +} diff --git a/src/world/Sapling.java b/src/world/Sapling.java new file mode 100755 index 0000000..c7c824f --- /dev/null +++ b/src/world/Sapling.java @@ -0,0 +1,71 @@ +package world; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import hud.inventory.InvenHelper; +import hud.inventory.Inventory; +import interfaces.Colors; +import interfaces.Entity; +import interfaces.GameObject; +import player.Player; +import utils.Point2f; +import utils.Utils; + +public class Sapling extends Entity implements GameObject { + + private final int PICK_UP_DELAY = 45; + + private int type; + private int pickUpTimer; + + public Sapling(int x, int y) { + this.pos = new Point2f(x, y); + this.width = 16; // These are according to the sprite size; + this.height = 25; // " " + this.center = new Point2f((int) (x + width / 2), (int) (y + height / 2)); + this.radius = width / 1.4f; + this.type = Utils.rand.nextInt(4); + Handler.saplings.add(this); + } + + private Graphics2D copy; + private AffineTransform transform = new AffineTransform(); + public void render(Graphics2D g2d) { + if(!discovered) return; + + copy = (Graphics2D) g2d.create(); transform.setToRotation(-Utils._45 * (Game.rotation - 1), pos.x + width / 2, pos.y + height / 2); copy.transform(transform); + + if (alive) copy.drawImage(Textures.saplingSheet[type], (int) pos.x, (int) pos.y, null); + else copy.drawImage(Textures.saplingSheet[4], (int) pos.x, (int) pos.y, null); + + if (Game.drawCollisionBounds && alive) { + copy.setColor(Color.CYAN); + copy.drawOval((int) (center.x - radius), (int) (center.y - radius), (int) radius * 2, (int) radius * 2); + } + + if(pickUpTimer > 0){ + copy.setColor(Colors.offBlack); copy.fillRect((int)pos.x, (int)pos.y - 10, 20, 4); + copy.setColor(Color.green); copy.fillRect((int)pos.x + 1, (int)pos.y - 9, (int)(pickUpTimer / 2.3275), 2); + } + + copy.dispose(); + } + + public void tick() { + if(!checkIfAlive() || !getDiscoveryStatus()) return; + + if (Player.using && alive && playerCollided && !Inventory.isFull(InvenHelper.STICKS, 1)) { + if (++pickUpTimer >= PICK_UP_DELAY) { + alive = false; + Inventory.addItem(7, 1, 100); + pickUpTimer = 0; + } + } else pickUpTimer = 0; + } + +} diff --git a/src/world/TallGrass.java b/src/world/TallGrass.java new file mode 100755 index 0000000..ff440ee --- /dev/null +++ b/src/world/TallGrass.java @@ -0,0 +1,75 @@ +package world; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import hud.inventory.InvenHelper; +import hud.inventory.Inventory; +import interfaces.Colors; +import interfaces.Entity; +import interfaces.GameObject; +import player.Player; +import utils.Point2f; +import utils.Utils; + +public class TallGrass extends Entity implements GameObject { + + private final int PICK_UP_DELAY = 45; + + private int type; + public boolean playerCollided; + private int pickUpTimer; + + public TallGrass(int x, int y) { + this.pos = new Point2f(x, y); + this.width = 14; // These are according to the sprite size; + this.height = 16; // " " + this.center = new Point2f((int) (pos.x + width / 2), (int) (pos.y + height / 2)); + this.radius = width / 1.4f; + this.type = Utils.rand.nextInt(6); + Handler.grass.add(this); + } + + private Graphics2D copy; + private AffineTransform transform = new AffineTransform(); + public void render(Graphics2D g2d) { + if(!discovered) return; + + copy = (Graphics2D) g2d.create(); transform.setToRotation(-0.78539816 * (Game.rotation - 1), pos.x + width / 2, pos.y + height / 2); copy.transform(transform); + + if (alive) copy.drawImage(Textures.grassSheet[type], (int) pos.x, (int) pos.y, null); + else copy.drawImage(Textures.grassSheet[6], (int) pos.x, (int) pos.y, null); + + if (Game.drawCollisionBounds && alive) { + copy.setColor(Color.CYAN); + copy.drawOval((int) (center.x - radius), (int) (center.y - radius), (int) radius * 2, (int) radius * 2); + } + + if(pickUpTimer > 0){ + copy.setColor(Colors.offBlack); + copy.fillRect((int)pos.x, (int)pos.y - 10, 20, 4); + copy.setColor(Color.green); + copy.fillRect((int)pos.x + 1, (int)pos.y - 9, (int)(pickUpTimer / 2.3275), 2); + } + + copy.dispose(); + } + + public void tick() { + if(!checkIfAlive() || !getDiscoveryStatus()) return; + + + if (Player.using && alive && playerCollided && !Inventory.isFull(InvenHelper.PICKED_GRASS, 1)) { + if (++pickUpTimer >= PICK_UP_DELAY) { + alive = false; + Inventory.addItem(1, 1, 100); + pickUpTimer = 0; + } + } else pickUpTimer = 0; + } + +} diff --git a/src/world/Tile.java b/src/world/Tile.java new file mode 100755 index 0000000..22aaa59 --- /dev/null +++ b/src/world/Tile.java @@ -0,0 +1,122 @@ +package world; + +import java.awt.Graphics2D; +import java.awt.Point; +import java.awt.Rectangle; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import engine.MouseInput; +import interfaces.Biomes; +import interfaces.GameObject; +import interfaces.Mob; +import player.MouseMovement; +import player.Player; +import utils.Animation; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public final class Tile implements GameObject, Biomes { + + private static final int TILE_SIZE = Game.TILE_SIZE; /* will need to be referenced a lot, cut down on external references */ + private static Animation[] animations; + public static boolean drawHighLighted; + public static final Point pointToCheck = new Point(0,0); + public static final int radius = TILE_SIZE/2; + +/*************************************************************************************************************************************************************************/ + public int x, y, biome; + public boolean highlighted, discovered; // <--- discovered = fog of war + public Rectangle bounds; + public Tile(final int x, final int y, final int biome) { + this.x = x; this.y = y; this.biome = biome; + bounds = new Rectangle(x, y, TILE_SIZE, TILE_SIZE); + } + + public final void tick() { + if(!discovered && Player.DISCOVERY.contains(x, y)) discovered = true; + else if(drawHighLighted) { + if(MouseMovement.PLACING_STRUCTURE) { if(getBounds().contains(pointToCheck)) highlighted = true; else highlighted = false;} + else if(getBounds().contains(MouseInput.adjustedMouseXY)) highlighted = true; else highlighted = false; + } + } + + public final void render(Graphics2D g2d) { + if(highlighted){ + g2d.drawImage(Textures.tileSheet[HIGHLIGHTED], x, y, null); + return; + } else if(discovered) animations[biome].drawAnimation(g2d, x, y); + } + + public final Rectangle getBounds(){ return bounds; } +/***************************************************************************************************************************************************************************/ + + public static final void init(){ + animations = new Animation[18]; + for(int i = 0; i < animations.length; i++) animations[i] = new Animation(0, Textures.tileSheet[i]); /* Fill array with default images */ + + final int OCEAN_ANIMATION_SPEED = 25; + final int RIVER_ANIMATION_SPEED = 12; + final int LAKE_ANIMAITON_SPEED = 20; + final int VOLCANIC_ANIMATION_SPEED = 30; + + animations[OCEAN] = new Animation(OCEAN_ANIMATION_SPEED, + Textures.tileSheet[18], Textures.tileSheet[19], Textures.tileSheet[20], Textures.tileSheet[21], + Textures.tileSheet[22], Textures.tileSheet[23], Textures.tileSheet[24], Textures.tileSheet[25], + Textures.tileSheet[26], Textures.tileSheet[27], Textures.tileSheet[28], Textures.tileSheet[29], + Textures.tileSheet[30], Textures.tileSheet[31], Textures.tileSheet[32], Textures.tileSheet[33]); + + + animations[RIVER] = new Animation(RIVER_ANIMATION_SPEED, Textures.tileSheet[RIVER], Utils.reverseImage(Textures.tileSheet[RIVER])); + animations[LAKE] = new Animation(LAKE_ANIMAITON_SPEED, Textures.tileSheet[LAKE], Utils.reverseImage(Textures.tileSheet[LAKE])); + // VOLCANIC: + animations[VOLCANIC] = new Animation(VOLCANIC_ANIMATION_SPEED, Textures.tileSheet[VOLCANIC], Utils.reverseImage(Textures.tileSheet[VOLCANIC])); + } + + public static final void runAnimations(){ + animations[OCEAN].runAnimation(); + animations[LAKE].runAnimation(); + animations[RIVER].runAnimation(); + animations[VOLCANIC].runAnimation(); + } + + public static final void resetAllHighlighted(){ + for(int i = 0; i < Handler.sections.length; i++) + for(int j = 0; j < Handler.sections[i].length; j++) + for(Tile t : Handler.world.get(i).get(j).get(0)) + t.highlighted = false; + } + + public static final void DISCOVER_ALL(){ + for(int i = 0; i < Handler.sections.length; i++) + for(int j = 0; j < Handler.sections[i].length; j++) + for(Tile t : Handler.world.get(i).get(j).get(0)) { + t.discovered = true; t.highlighted = false; } + + for(final Sapling i : Handler.saplings) i.discovered = true; + for(final Tree i : Handler.trees) i.discovered = true; + for(final Flower i : Handler.flowers) i.discovered = true; + for(final TallGrass i : Handler.grass) i.discovered = true; + for(final Boulder i : Handler.boulders) i.discovered = true; + for(final Mob i : Handler.mobs) i.discovered = true; + } + + public static final void UN_DISCOVER_ALL(){ + for(int i = 0; i < Handler.sections.length; i++) + for(int j = 0; j < Handler.sections[i].length; j++) + for(final Tile t : Handler.world.get(i).get(j).get(0)) { + t.discovered = false; t.highlighted = false; } + + for(final Sapling i : Handler.saplings) i.discovered = false; + for(final Tree i : Handler.trees) i.discovered = false; + for(final Flower i : Handler.flowers) i.discovered = false; + for(final TallGrass i : Handler.grass) i.discovered = false; + for(final Boulder i : Handler.boulders) i.discovered = false; + for(final Mob i : Handler.mobs) i.discovered = false; + } + +} \ No newline at end of file diff --git a/src/world/Tree.java b/src/world/Tree.java new file mode 100755 index 0000000..11b100f --- /dev/null +++ b/src/world/Tree.java @@ -0,0 +1,113 @@ +package world; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.Rectangle; +import java.awt.geom.AffineTransform; + +import _texture.loader.Textures; +import engine.Game; +import engine.Handler; +import fonts.fonts; +import hud.inventory.InvenHelper; +import interfaces.Entity; +import interfaces.GameObject; +import player.Player; +import utils.Point2f; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +public class Tree extends Entity implements GameObject { + + private int type; + public float chopRadius; + private long chopTimer; + public Rectangle bounds; + + public Tree(int x, int y) { + this.pos = new Point2f(x, y); + this.width = 64; // These are according to the sprite size; + this.height = 64; + this.center = new Point2f((int) (x + width / 2), (int) (y + height / 1.1)); + this.radius = width / 15f; + this.chopRadius = radius*3f; + this.type = Utils.rand.nextInt(3) + 1; // randomly assign the tree one of the 3 sprites, (change with seasons) + this.health = Utils.rand.nextInt(7) + 5; // randomly give tree a certain health + this.chopTimer = System.currentTimeMillis(); + bounds = new Rectangle(x, y, width, height); + Handler.trees.add(this); + } public Tree(float x, float y){ new Tree((int)x, (int)y);}; + + public void tick() { + if(!getDiscoveryStatus()) return; + + if (playerCollided && Player.using && alive) { + if (InvenHelper.isAxe(Player.equipmentSlots[3].itemId)) getChopped(Player.equipmentSlots[3].itemId); + } + + switch (Game.rotation) { /* re-adjust center points */ + case 1: { center.x = (int) (pos.x + width / 2); center.y = (int) (pos.y + height / 1.025); break; } + case 2: { center.x = (int) (pos.x + width / 1.225); center.y = (int) (pos.y + height / 1.175); break; } + case 3: { center.x = (int) (pos.x + width / 1.0375); center.y = (int) (pos.y + height / 1.825); break; } + case 4: { center.x = (int) (pos.x + width / 1.16); center.y = (int) (pos.y + height / 4.9); break; } + case 5: { center.x = (int) (pos.x + width / 1.85); center.y = (int) (pos.y + height / 18); break; } + case 6: { center.x = (int) (pos.x + width / 5); center.y = (int) (pos.y + height / 6); break; } + case 7: { center.x = (int) (pos.x + width / 20); center.y = (int) (pos.y + height / 1.95); break; } + case 8: { center.x = (int) (pos.x + width / 5.35); center.y = (int) (pos.y + height / 1.2); break; } + } + + if (alive && health <= 0) { /* place logs in a random direction around tree */ + alive = false; + DroppedItem.dropRandomAmountOfItemsWithOffset(InvenHelper.LOGS, 1, 3, 25, center.x, center.y, 100); + } + } + + private void getChopped(int axeType) { + int chopDamage = 0; + switch (axeType) { + case InvenHelper.CRUDE_AXE: chopDamage = 1000; break; + case 1337: chopDamage = 500; break; + } + + if (System.currentTimeMillis() - chopTimer > chopDamage) { + health--; + Player.equipmentSlots[3].durability -= 2.5f; + // TODO: play get hit animation + chopTimer = System.currentTimeMillis(); + } + } + + private Graphics2D copy; + private AffineTransform transform = new AffineTransform(); + public void render(Graphics2D g2d) { + if(!discovered) return; + + if (Game.drawCollisionBounds) { + g2d.setColor(Color.GREEN); + g2d.drawOval((int) (center.x - radius), (int) (center.y - radius), (int) radius * 2, (int) radius * 2); + g2d.setColor(Color.MAGENTA); + g2d.drawOval((int) (center.x - chopRadius), (int) (center.y - chopRadius), (int) chopRadius * 2, (int) chopRadius * 2); + g2d.setColor(Color.yellow); + g2d.draw(bounds); + } + if (Game.drawResourceNumbers) { + g2d.setColor(Color.white); + g2d.setFont(fonts.ponderosa20); + g2d.drawString(Integer.toString(health), center.x, center.y); + } + + + transform.setToRotation(-Utils._45 * (Game.rotation - 1), pos.x + width/2, pos.y + height/2); + copy = (Graphics2D) g2d.create(); + + copy.transform(transform); + + if (alive) copy.drawImage(Textures.treeSheet[type], (int) pos.x, (int) pos.y, null); + else copy.drawImage(Textures.treeSheet[0], (int) pos.x, (int) pos.y, null); + + copy.dispose(); + } +} diff --git a/src/worldGen/EntityGenerator.java b/src/worldGen/EntityGenerator.java new file mode 100755 index 0000000..f73a52f --- /dev/null +++ b/src/worldGen/EntityGenerator.java @@ -0,0 +1,148 @@ +package worldGen; + +import engine.Game; +import interfaces.Biomes; +import mobs.Goblin; +import mobs.Rabbit; +import utils.Stack; +import utils.Utils; +import world.Boulder; +import world.Debris; +import world.DroppedItem; +import world.Flower; +import world.Sapling; +import world.TallGrass; +import world.Tile; +import world.Tree; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +final class EntityGenerator implements Biomes { + + public static final void generate(final Stack tiles) { + if(tiles == null || tiles.isEmpty()) return; + + final int NUM_OF_BIOMES = 17; + + final int TYPES_OF_ENTITIES = 10; + final int DEBRIS=0,TREE=1,BOULDER=2,FLOWER=3,TALLGRASS=4,SAPLING=5,RABBIT=6, ROCKS=7, STICKS=8, + GOBLIN=9; + + final float[][] biomes = new float[NUM_OF_BIOMES][TYPES_OF_ENTITIES]; + + // OCEAN = no chances + // RIVER = no chances + // LAKE = no chances + + biomes[COASTLINE][DEBRIS] = 1/2000f; + + biomes[BEACH][DEBRIS] = 1/1650f; + biomes[BEACH][ROCKS] = 1/5000f; + biomes[BEACH][STICKS] = 1/4500f; + + biomes[GRASS1][DEBRIS] = 1/800f; + biomes[GRASS1][TREE] = 1/2550f; + biomes[GRASS1][BOULDER] = 1/3500f; + biomes[GRASS1][FLOWER] = 1/400f; + biomes[GRASS1][TALLGRASS] = 1/500f; + biomes[GRASS1][SAPLING] = 1/600f; + biomes[GRASS1][RABBIT] = 1/400f; + biomes[GRASS1][ROCKS] = 1/800f; + biomes[GRASS1][GOBLIN] = 1/1000f; + + biomes[GRASS2][DEBRIS] = 1/800f; + biomes[GRASS2][TREE] = 1/2550f; + biomes[GRASS2][BOULDER] = 1/3500f; + biomes[GRASS2][FLOWER] = 1/250f; + biomes[GRASS2][TALLGRASS] = 1/500f; + biomes[GRASS2][SAPLING] = 1/600f; + biomes[GRASS2][RABBIT] = 1/400f; + biomes[GRASS2][ROCKS] = 1/800f; + biomes[GRASS2][GOBLIN] = 1/1000f; + + biomes[GRASS3][DEBRIS] = 1/800f; + biomes[GRASS3][TREE] = 1/2550f; + biomes[GRASS3][BOULDER] = 1/3500f; + biomes[GRASS3][FLOWER] = 1/250f; + biomes[GRASS3][TALLGRASS] = 1/500f; + biomes[GRASS3][SAPLING] = 1/600f; + biomes[GRASS3][RABBIT] = 1/400f; + biomes[GRASS3][ROCKS] = 1/800f; + biomes[GRASS3][GOBLIN] = 1/1000f; + + biomes[GRASS4][DEBRIS] = 1/800f; + biomes[GRASS4][TREE] = 1/2550f; + biomes[GRASS4][BOULDER] = 1/3500f; + biomes[GRASS4][FLOWER] = 1/250f; + biomes[GRASS4][TALLGRASS] = 1/500f; + biomes[GRASS4][SAPLING] = 1/600f; + biomes[GRASS4][RABBIT] = 1/400f; + biomes[GRASS4][ROCKS] = 1/800f; + biomes[GRASS4][GOBLIN] = 1/1000f; + + biomes[FOREST][DEBRIS] = 1/175f; + biomes[FOREST][TREE] = 1/25f; + biomes[FOREST][BOULDER] = 1/500f; + biomes[FOREST][FLOWER] = 1/900f; + biomes[FOREST][TALLGRASS] = 1/1500f; + biomes[FOREST][SAPLING] = 1/700f; + biomes[FOREST][RABBIT] = 1/3000f; + biomes[FOREST][ROCKS] = 1/475f; + biomes[FOREST][STICKS] = 1/2000f; + biomes[FOREST][GOBLIN] = 1/200f; + + biomes[DESERT][DEBRIS] = 1/3000f; + biomes[DESERT][BOULDER] = 1/500f; + biomes[DESERT][TALLGRASS] = 1/200f; + biomes[DESERT][SAPLING] = 1/1500f; + biomes[DESERT][RABBIT] = 1/400f; + biomes[DESERT][ROCKS] = 1/200f; + biomes[DESERT][GOBLIN] = 0f; + + biomes[TAIGA][DEBRIS] = 1/2000f; + biomes[TAIGA][BOULDER] = 1/1250f; + biomes[TAIGA][TALLGRASS] = 1/300f; + biomes[TAIGA][SAPLING] = 1/1200f; + biomes[TAIGA][RABBIT] = 1/400f; + biomes[TAIGA][GOBLIN] = 0f; + + biomes[BARREN_ROCK][DEBRIS] = 1/1000f; + biomes[BARREN_ROCK][BOULDER] = 1/50f; + biomes[BARREN_ROCK][SAPLING] = 1/2500f; + biomes[BARREN_ROCK][ROCKS] = 1/100f; + biomes[BARREN_ROCK][GOBLIN] = 0f; + + + int xOffset = 0, yOffset= 0; final int FOURTH_TILE = Game.TILE_SIZE/4; + for(final Tile t : tiles){ + + switch(t.biome){ + case OCEAN: continue; + case LAKE: continue; + case RIVER: continue; + } + + xOffset = Utils.rand.nextInt(FOURTH_TILE); + yOffset = Utils.rand.nextInt(FOURTH_TILE); + + if(Utils.COIN_FLIP()) xOffset *= -1; + if(Utils.COIN_FLIP()) yOffset *= -1; + + + if(biomes[t.biome][DEBRIS] > Utils.rand.nextFloat()) new Debris(t.x + xOffset, t.y + yOffset); + if(biomes[t.biome][TREE] > Utils.rand.nextFloat()) new Tree(t.x + xOffset, t.y + yOffset); + if(biomes[t.biome][BOULDER] > Utils.rand.nextFloat()) new Boulder(t.x + xOffset, t.y + yOffset); + if(biomes[t.biome][FLOWER] > Utils.rand.nextFloat()) new Flower(t.x + xOffset, t.y + yOffset); + if(biomes[t.biome][TALLGRASS] > Utils.rand.nextFloat()) new TallGrass(t.x + xOffset, t.y + yOffset); + if(biomes[t.biome][SAPLING] > Utils.rand.nextFloat()) new Sapling(t.x + xOffset, t.y + yOffset); + if(biomes[t.biome][RABBIT] > Utils.rand.nextFloat()) new Rabbit(t.x + xOffset, t.y + yOffset); + if(biomes[t.biome][ROCKS] > Utils.rand.nextFloat()) new DroppedItem(t.x + xOffset, t.y + yOffset, 6); + if(biomes[t.biome][STICKS] > Utils.rand.nextFloat()) new DroppedItem(t.x + xOffset, t.y + yOffset, 7); + if(biomes[t.biome][GOBLIN] > Utils.rand.nextFloat()) new Goblin(t.x + xOffset, t.y + yOffset); + + } + } + +} diff --git a/src/worldGen/MapCreator.java b/src/worldGen/MapCreator.java new file mode 100755 index 0000000..ffccb8a --- /dev/null +++ b/src/worldGen/MapCreator.java @@ -0,0 +1,264 @@ +package worldGen; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.HashSet; +import java.util.LinkedList; + +import interfaces.Biomes; +import utils.Stack; +import utils.ThreadPool; +import utils.Utils; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +// MAP GENERATOR: +// http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/demo.html + +final class MapCreator implements Serializable, Runnable, Biomes { + private static final long serialVersionUID = 1337; + + private static volatile LinkedList bytes_list; + private static volatile Stack filenames; + private static volatile int count, currentThreadsRunning; + private static float stackSize; + + public static final void main(String[] args) { + bytes_list = new LinkedList(); filenames = new Stack(); + final int numProcessors = ThreadPool.getNumProcessors(); + final ThreadPool pool = new ThreadPool(numProcessors); + final MapCreator task = new MapCreator(); + final Integer NUMBER_OF_MAPS_PLUS_ONE = 21; + + // STEP 1: FILL STACK WITH MAP FILE PATHS + for(int i = 1; i < NUMBER_OF_MAPS_PLUS_ONE; i++) + filenames.add("/map" + i + ".png"); + + stackSize = filenames.size(); + + // STEP 2: RUN THREADS TO COMPUTE MAPS + while(count < stackSize){ + + while (currentThreadsRunning < numProcessors && count < stackSize){ + pool.runTask(task); + currentThreadsRunning++; + } + + try { Thread.sleep(1000); } catch (InterruptedException e) { } + } + + // STEP 3: WHEN DONE, SAVE THE LIST OF BYTE[]'s + save(bytes_list); + System.err.println("ALL MAPS GENERATED!"); + bytes_list.clear(); bytes_list = null; filenames = null; System.exit(0); + } + + public void run() { + if(filenames.isEmpty()) return; + bytes_list.add(readMap(Utils.loadImage(filenames.pop()))); + } + + private static final byte[] readMap(BufferedImage image) { + try { byte[] bytes = new byte[image.getWidth() * image.getHeight()]; + final HashSet needsReview = new HashSet(); + final int nextRow = image.getWidth(); + + READ_IN_BYTES(needsReview, image, bytes); + + bytes = REVIEW_FUZZY_PIXELS(needsReview, bytes, nextRow); + bytes = FIX_RANDOM_ISLANDS_OF_LAND(nextRow, bytes); + bytes = REMOVE_RIVERS_FROM_COASTLINE(bytes, nextRow); + bytes = REMOVE_RIVERS_FROM_LAKE(bytes, nextRow); + bytes = REMOVE_OCEAN_FROM_RIVERS(bytes, nextRow); + + needsReview.clear(); + printProgress(); + return bytes; + } catch (Exception e) { e.printStackTrace(); return null; } + } + + private synchronized static final void printProgress(){ + System.err.println("--- PROGRESS: " + (int)((++count / stackSize)*100) + "%"); + currentThreadsRunning--; + } + + private static final byte[] REMOVE_OCEAN_FROM_RIVERS(final byte[] bytes, final int nextRow) { + for(int ITERATIONS = 0; ITERATIONS < 10; ITERATIONS++) { + boolean all_clear = true; + for(int i = 0; i < bytes.length; i++) { + if(bytes[i] == RIVER){ + try{ if(bytes[i + 1] == OCEAN) { bytes[i + 1] = RIVER; all_clear = false; } + if(bytes[i - 1] == OCEAN) { bytes[i - 1] = RIVER; all_clear = false; } + if(bytes[i + nextRow] == OCEAN) { bytes[i + nextRow] = RIVER; all_clear = false; } + if(bytes[i - nextRow] == OCEAN) { bytes[i - nextRow] = RIVER; all_clear = false; } + if(bytes[i + nextRow + 1] == OCEAN) { bytes[i + nextRow + 1] = RIVER; all_clear = false; } + if(bytes[i + nextRow - 1] == OCEAN) { bytes[i + nextRow - 1] = RIVER; all_clear = false; } + if(bytes[i - nextRow + 1] == OCEAN) { bytes[i - nextRow + 1] = RIVER; all_clear = false; } + if(bytes[i - nextRow - 1] == OCEAN) { bytes[i - nextRow - 1] = RIVER; all_clear = false; } + } catch (ArrayIndexOutOfBoundsException e) { continue; } + } + } + if(all_clear) break; + } + return bytes; + } + + private static final byte[] REMOVE_RIVERS_FROM_LAKE(final byte[] bytes, final int nextRow){ + final byte TEMP_BIOME = -120; + for(int ITERATIONS = 0; ITERATIONS < 10; ITERATIONS++) { + for(int i = 0; i < bytes.length; i++){ /* maps creates river around coastline, change them to ocean if by coastline */ + if(bytes[i] == RIVER){ + try{ + if(bytes[i + 1] == LAKE || bytes[i + 1] == TEMP_BIOME) { bytes[i] = TEMP_BIOME; } + if(bytes[i - 1] == LAKE || bytes[i - 1] == TEMP_BIOME) { bytes[i] = TEMP_BIOME; } + if(bytes[i + nextRow] == LAKE || bytes[i + nextRow] == TEMP_BIOME) { bytes[i] = TEMP_BIOME; } + if(bytes[i - nextRow] == LAKE || bytes[i - nextRow] == TEMP_BIOME) { bytes[i] = TEMP_BIOME; } + if(bytes[i + nextRow + 1] == LAKE || bytes[i + nextRow + 1] == TEMP_BIOME) { bytes[i] = TEMP_BIOME; } + if(bytes[i + nextRow - 1] == LAKE || bytes[i + nextRow - 1] == TEMP_BIOME) { bytes[i] = TEMP_BIOME; } + if(bytes[i - nextRow + 1] == LAKE || bytes[i - nextRow + 1] == TEMP_BIOME) { bytes[i] = TEMP_BIOME; } + if(bytes[i - nextRow - 1] == LAKE || bytes[i - nextRow - 1] == TEMP_BIOME) { bytes[i] = TEMP_BIOME; } + + } catch (ArrayIndexOutOfBoundsException e) {} + } + } + } + + // replace the temp biome with lake + for(int i = 0; i < bytes.length; i++) if(bytes[i] == TEMP_BIOME) bytes[i] = LAKE; + + return bytes; + } + + private static final byte[] REMOVE_RIVERS_FROM_COASTLINE(final byte[] bytes, final int nextRow){ + for(int i = 0; i < bytes.length; i++){ /* maps creates river around coastline, change them to ocean if by coastline */ + if(bytes[i] == LAKE || bytes[i] == RIVER){ + try{ + if(bytes[i + 1] == COASTLINE) bytes[i] = OCEAN; + else if(bytes[i - 1] == COASTLINE) bytes[i] = OCEAN; + else if(bytes[i + nextRow] == COASTLINE) bytes[i] = OCEAN; + else if(bytes[i - nextRow] == COASTLINE) bytes[i] = OCEAN; + else if(bytes[i + nextRow + 1] == COASTLINE) bytes[i] = OCEAN; + else if(bytes[i + nextRow - 1] == COASTLINE) bytes[i] = OCEAN; + else if(bytes[i - nextRow + 1] == COASTLINE) bytes[i] = OCEAN; + else if(bytes[i - nextRow - 1] == COASTLINE) bytes[i] = OCEAN; + + } catch (ArrayIndexOutOfBoundsException e) {} + } + } + return bytes; + } + + private static final byte[] REVIEW_FUZZY_PIXELS(final HashSet needsReview, final byte[] bytes, final int nextRow){ + // IF ANY TILES AROUND THE REVIEWING TILE ARE NOT WATER, MAKE IT THAT TILES BIOME + // NOTE THESE ARE INDEXES, NOT BIOMES + for(int i : needsReview) { + + int offset = 1; + while(bytes[i] == OCEAN){ + try{ if(bytes[i + offset] != OCEAN && bytes[i + offset] != RIVER && bytes[i + offset] != LAKE) bytes[i] = bytes[i + offset]; + else if(bytes[i - offset] != OCEAN && bytes[i - offset] != RIVER && bytes[i - offset] != LAKE) bytes[i] = bytes[i - offset]; + else if(bytes[i + nextRow] != OCEAN && bytes[i + nextRow] != RIVER && bytes[i + nextRow] != LAKE) bytes[i] = bytes[i + nextRow]; + else if(bytes[i - nextRow] != OCEAN && bytes[i - nextRow] != RIVER && bytes[i - nextRow] != LAKE) bytes[i] = bytes[i - nextRow]; + else if(bytes[i + nextRow + offset] != OCEAN && bytes[i + nextRow + offset] != RIVER && bytes[i + nextRow + offset] != LAKE) bytes[i] = bytes[i + nextRow + offset]; + else if(bytes[i + nextRow - offset] != OCEAN && bytes[i - nextRow - offset] != RIVER && bytes[i + nextRow - offset] != LAKE) bytes[i] = bytes[i + nextRow - offset]; + else if(bytes[i - nextRow + offset] != OCEAN && bytes[i + nextRow + offset] != RIVER && bytes[i - nextRow + offset] != LAKE) bytes[i] = bytes[i - nextRow + offset]; + else if(bytes[i - nextRow - offset] != OCEAN && bytes[i - nextRow - offset] != RIVER && bytes[i - nextRow - offset] != LAKE) bytes[i] = bytes[i - nextRow - offset]; + offset++; + } catch(ArrayIndexOutOfBoundsException e){ bytes[i] = OCEAN; System.err.println("PROBLEM!"); System.exit(0); } + } + } + return bytes; + } + + private final static byte[] FIX_RANDOM_ISLANDS_OF_LAND(final int nextRow, final byte[] bytes){ + // TO FIX RANDOM STRAY ISLAND TILES OUT IN WATER, DO THIS LOOP + // CONTINUE DOING THIS LOOP UNTIL THE CONDITION IS FALSE + boolean ALL_CLEAR = false; + while(!ALL_CLEAR) { + + boolean NO_TILES_RESET = true; + int TILES_LEFT = 0; + + for(int i = 0; i < bytes.length; i++){ + try { + // DONT NEED TO RUN THE TILE IF IT IS WATER OR COASTLINE, OBV + if(bytes[i] == LAKE || bytes[i] == RIVER || bytes[i] == OCEAN || bytes[i] == COASTLINE) continue; + + // GO THROUGH ALL THE SURROUNDING TILES + // IF ANY OF THE SURROUNDING TILES ARE WATER, INCREMENT COUNT + int count = 0; + + final Stack temp = new Stack(); + + if(bytes[i + 1] == OCEAN || bytes[i + 1] == RIVER || bytes[i + 1] == LAKE) { count++; temp.add(bytes[i + 1]); } + if(bytes[i - 1] == OCEAN || bytes[i - 1] == RIVER || bytes[i - 1] == LAKE) { count++; temp.add(bytes[i - 1]); } + if(bytes[i + nextRow] == OCEAN || bytes[i + nextRow] == RIVER || bytes[i + nextRow] == LAKE) { count++; temp.add(bytes[i + nextRow]); } + if(bytes[i - nextRow] == OCEAN || bytes[i - nextRow] == RIVER || bytes[i - nextRow] == LAKE) { count++; temp.add(bytes[i - nextRow]); } + if(bytes[i + nextRow + 1] == OCEAN || bytes[i + nextRow + 1] == RIVER || bytes[i + nextRow + 1] == LAKE) { count++; temp.add(bytes[i + nextRow + 1]); } + if(bytes[i + nextRow - 1] == OCEAN || bytes[i + nextRow - 1] == RIVER || bytes[i + nextRow - 1] == LAKE) { count++; temp.add(bytes[i + nextRow - 1]); } + if(bytes[i - nextRow + 1] == OCEAN || bytes[i - nextRow + 1] == RIVER || bytes[i - nextRow + 1] == LAKE) { count++; temp.add(bytes[i - nextRow + 1]); } + if(bytes[i - nextRow - 1] == OCEAN || bytes[i - nextRow - 1] == RIVER || bytes[i - nextRow - 1] == LAKE) { count++; temp.add(bytes[i - nextRow - 1]); } + + // IF COUNT == 8, THEN ALL SURROUNDING TILES MUST BE WATER! + // IF COUNT >= ~5, IT MUST BE A SHITTY PENINSULA, SCRAP IT --- (note change 5 to desire) + // SET THIS ISLAND TILE TO ONE OF ITS WATER NEIGHBOURS + + if(count >= 6){ + NO_TILES_RESET = false; + bytes[i] = temp.get(Utils.rand.nextInt(temp.size())); + TILES_LEFT++; +// bytes[i] = SNOW_TUNDA; + } + + temp.clear(); + } catch (Exception e) { System.out.println("PROBLEM!"); System.exit(0); } + } + System.out.println("tiles left " + TILES_LEFT); + if(NO_TILES_RESET) ALL_CLEAR = true; + } + + return bytes; + } + + private static final byte[] READ_IN_BYTES(HashSet needsReview, BufferedImage image, byte[] bytes){ + int pixel = 0, red = 0, green = 0, blue = 0, index = 0; + for (int i = 0; i < image.getWidth(); i++) + for (int j = 0; j < image.getHeight(); j++, index++) { + pixel = image.getRGB(i, j); red = Utils.convertRed(pixel); green = Utils.convertGreen(pixel); blue = Utils.convertBlue(pixel); + + if(red == 68 && green == 68 && blue == 122) bytes[index] = OCEAN; + else if(red == 160 && green == 144 && blue == 119) bytes[index] = COASTLINE; + else if(red == 210 && green == 185 && blue == 139) bytes[index] = BEACH; + else if(red == 136 && green == 170 && blue == 85) bytes[index] = GRASS1; + else if(red == 85 && green == 153 && blue == 68) bytes[index] = GRASS2; + else if(red == 103 && green == 148 && blue == 89) bytes[index] = GRASS3; + else if(red == 63 && green == 136 && blue == 85) bytes[index] = GRASS4; + else if(red == 51 && green == 119 && blue == 85) bytes[index] = FOREST; + else if(red == 201 && green == 210 && blue == 155) bytes[index] = DESERT; + else if(red == 153 && green == 170 && blue == 119) bytes[index] = TAIGA; + else if(red == 136 && green == 153 && blue == 119) bytes[index] = BARREN_ROCK; + else if(red == 255 && green == 255 && blue == 255) bytes[index] = SNOW_TUNDA; + else if(red == 136 && green == 136 && blue == 136) bytes[index] = ASH; + else if(red == 85 && green == 85 && blue == 85) bytes[index] = VOLCANIC; + else if(red == 34 && green == 85 && blue == 136) bytes[index] = RIVER; + else if(red == 51 && green == 102 && blue == 153) bytes[index] = LAKE; + else if(red == 187 && green == 187 && blue == 170) bytes[index] = BACK_OF_VOLCANO; + else needsReview.add(index); // for the fuzzy pixels + + /* if not one of the above RGB's, set it to one of its neighbors (avoids the big holes caused by the image's compression */ + } + return bytes; + } + + private static final synchronized void save(final Object obj){ + try { final File file = new File("res/data/mapsdata.nihil"); + final ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); + oos.writeObject(obj); oos.close(); + } catch (Exception e) { e.printStackTrace(); System.exit(1); } + } + } diff --git a/src/worldGen/WorldGenerator.java b/src/worldGen/WorldGenerator.java new file mode 100755 index 0000000..7077b2f --- /dev/null +++ b/src/worldGen/WorldGenerator.java @@ -0,0 +1,209 @@ +package worldGen; + +import java.awt.Rectangle; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.util.ArrayList; +import java.util.LinkedList; + +import engine.Game; +import engine.Handler; +import interfaces.Biomes; +import player.Player; +import utils.Runner; +import utils.Stack; +import utils.Utils; +import world.Tile; + +/* ------------- Nihilne ------------ + * Created by Mitch Weaver - 2016 * + ~~~~ All Rights Reserved ~~~~ */ + +@SuppressWarnings("unchecked") +public final class WorldGenerator implements Biomes { + + public static boolean WORLD_GENERATED, beginTileCreation; + public static Stack> workerStacks; + private static long tilesThen, then; + public static float stackSize; + public static volatile int workerNumber; + + public static final void generateWorld() { + final int threads; if(Game.threads > 2) threads = Game.threads - 2; else threads = 1; + final long generateWorldInitThen = then = System.currentTimeMillis(); workerNumber = 0; + generateWorldSections(); beginTileCreation = false; percentage = 0; + if(workerStacks != null) workerStacks.clear(); workerStacks = new Stack>(); + for(int i = 0; i < threads; i++) workerStacks.push(new Stack()); + Handler.numSectionsRowsColsHalved = Handler.numSectionsRowsCols/2; + System.out.println("World Gen Preparation Complete --- Time Taken: " + Float.toString((float)(System.currentTimeMillis() - generateWorldInitThen)/1000f)+ " seconds"); + + final Stack tiles = new Stack(); + + try { long getMapDataThen = System.currentTimeMillis(); + InputStream fis = WorldGenerator.class.getResourceAsStream("/mapsdata.nihil"); + ObjectInputStream ois = new ObjectInputStream(fis); + LinkedList bytes = (LinkedList) ois.readObject(); + byte[] mapToGenerate = (byte[])bytes.get(Utils.rand.nextInt(bytes.size())); + for (int i = 0, count = 0; i < Handler.numRowsCols; i++) + for (int j = 0; j < Handler.numRowsCols; j++) + tiles.push(new Tile(i * Game.TILE_SIZE, j * Game.TILE_SIZE, mapToGenerate[count++])); + fis.close(); ois.close(); stackSize = tiles.size(); bytes.clear(); bytes = null; fis = null; ois = null; mapToGenerate = null; + System.out.println("Map Data Retrieved --- Time Taken: " + Float.toString((float)(System.currentTimeMillis() - getMapDataThen)/1000f)+ " seconds"); + } catch (Exception e) { e.printStackTrace(); System.exit(0); } + + generateWorldEntities(tiles); + + beginTileCreation = true; tilesThen = System.currentTimeMillis(); + + System.gc(); + + for(int i = 0; i < workerStacks.size() - 1; i++) + for(int j = 0; j < stackSize / threads; j++) + workerStacks.get(i).push(tiles.pop()); + while(!tiles.isEmpty()) workerStacks.peek().push(tiles.pop()); + + System.gc(); + + for(int i = 0; i < workerStacks.size(); i++) { + final int temp = i; + Game.pool.runTask(new Runner(() -> fillSectionsWithTiles(workerStacks.get(temp)))); + } + } + + private static final synchronized void generateWorldEntities(Stack tiles){ + final long then = System.currentTimeMillis(); + EntityGenerator.generate(tiles); int temp, biome; + while(true){ /* set player somewhere random on the map, except in water / rare / dangeous place */ + temp = Utils.rand.nextInt(tiles.size()); biome = tiles.get(temp).biome; + switch(biome){ + case OCEAN: break; + case LAKE: break; + case RIVER: break; + case VOLCANIC: break; + case COASTLINE: break; + case BACK_OF_VOLCANO: break; + case HIGHLIGHTED: break; + case SNOW_TUNDA: break; + case TAIGA: break; + case BARREN_ROCK: break; + default: { Player.pos.setLocation(tiles.get(temp).x + Game.TILE_SIZE/2, tiles.get(temp).y + Game.TILE_SIZE/2); + System.out.println("World Entities Generated --- Time Taken: " + Float.toString((float)(System.currentTimeMillis() - then)/1000f)+ " seconds"); + return; } + } + } + } + + private static final void generateWorldSections(){ + Handler.sections = null; + Handler.SECTION_SIZE_WIDTH_HEIGHT = determineSectionSize(); + Handler.numSectionsRowsCols = (Handler.numRowsCols * Game.TILE_SIZE) / Handler.SECTION_SIZE_WIDTH_HEIGHT; + Handler.AREA_RECT.width = Handler.AREA_RECT.height = Handler.SECTION_SIZE_WIDTH_HEIGHT*3; + + /* Create and fill the array of rectangles for sections of map */ + Handler.sections = new Rectangle[Handler.numSectionsRowsCols][Handler.numSectionsRowsCols]; + for(int i = 0; i < Handler.numSectionsRowsCols; i++) + for(int j = 0; j < Handler.numSectionsRowsCols; j++) + Handler.sections[i][j] = new Rectangle(i*Handler.SECTION_SIZE_WIDTH_HEIGHT, j*Handler.SECTION_SIZE_WIDTH_HEIGHT, Handler.SECTION_SIZE_WIDTH_HEIGHT, Handler.SECTION_SIZE_WIDTH_HEIGHT); + + /* Create and fill the arraylist of arraylists of arraylist of hashsets for tiles objects in map */ + Handler.world = new ArrayList>>>(Handler.numSectionsRowsCols); + + for(int i = 0; i < Handler.numSectionsRowsCols; i++){ + Handler.world.add(new ArrayList>>(Handler.numSectionsRowsCols)); /* ROW */ + for(int j = 0; j < Handler.numSectionsRowsCols; j++){ + Handler.world.get(i).add(new ArrayList>()); /* COL */ + for(int k = 0; k < Handler.NUM_TYPES_OF_HASHSETS; k++) + Handler.world.get(i).get(j).add(new Stack()); /* TYPE */ + } + } + } + + /* calculates a section size that is able to be spread evenly through the map */ + private static final int determineSectionSize(){ + int length = Handler.numRowsCols * Game.TILE_SIZE; if(Utils.isOdd(length)) length++; + int w = (int)(Game.WIDTH * 0.5f); if(Utils.isOdd(w)) w++; /* width will always be longer than height... or atleast should be may need to fix later if complaints */ + //NOTE: change this --------^ amount for smaller/larger squares --- (0.5f minimum) + while(length % w != 0){ + if(length % w == w) {System.err.println("width is bigger than map length"); System.exit(1); } /* if the screen width is bigger than the map */ + else { + int max = w, min = w; + + while(length % max != 0 && length % max != max) max++; + + while(length % min != min && length % min != 0 && min > ((Game.WIDTH * 0.5)-1)) min--; + + final int diffMax = Utils.abs(max - w); + final int diffMin = Utils.abs(min - w); + + if(diffMin <= diffMax && diffMin > Game.WIDTH * 0.5f) w = min; else w = max; + } + } + if(w == 0) { System.err.println("PROBLEM WITH WORLD GENERATOR -- (w == 0) ---- determineSectionSize()"); System.exit(0); } + return w; + } + + /* adds all objects from handler.tiles to stack, then erases handler.tiles, and re-adds */ + public static void regenWorldSectionsAndTiles(){ + if(Handler.world == null) return; // happens because @ start up + final Stack tiles = new Stack(); + + WORLD_GENERATED = beginTileCreation = Player.keepWalkingX = Player.keepWalkingY = Player.using = Player.attacking = false; + Player.velX = Player.velY = 0; workerNumber = 0; percentage = 0; stackSize = 0; + + for(int i = 0; i < Handler.numSectionsRowsCols; i++) + for(int j = 0; j < Handler.numSectionsRowsCols; j++) + for(int k = 0; k < Handler.NUM_TYPES_OF_HASHSETS; k++) + for(Tile o : Handler.world.get(i).get(j).get(k)) + tiles.push(o); + + stackSize = tiles.size(); + Game.pool.runTask(new Runner(() -> { generateWorldSections(); })); + + if(workerStacks != null) workerStacks.clear(); + workerStacks = new Stack>(); + for(int i = 0; i < Game.threads; i++) workerStacks.push(new Stack()); + + for(int i = 0; i < workerStacks.size() - 1; i++) + for(int j = 0; j < stackSize / Game.threads; j++) + workerStacks.get(i).push(tiles.pop()); + + while(!tiles.isEmpty()) workerStacks.get(workerStacks.size() - 1).push(tiles.pop()); + + for(int i = 0; i < workerStacks.size(); i++) { + final int temp = i; Game.pool.runTask(new Runner(() -> fillSectionsWithTiles(workerStacks.get(temp)))); + } + } + + public static float percentage; + public static final void fillSectionsWithTiles(Stack stack) { + if(stack == null || stack.isEmpty()){ System.err.println("PROBLEM fillSectionsWithTiles!"); System.exit(0); } + + while(!stack.isEmpty()) Handler.addTile(stack.pop()); + + System.out.println("Worker " + ++workerNumber + " finished."); + checkIfDone(); + } + + private static synchronized final void checkIfDone(){ + System.gc(); + for(final Stack i : workerStacks) if(!i.isEmpty()) return; + + + System.out.println("Tiles Generated --- Time Taken: " + Float.toString((float)(System.currentTimeMillis() - tilesThen)/1000f)+ " seconds"); + + workerStacks.clear(); workerStacks = null; + + System.out.println("Tiles: " + Utils.square(Handler.numRowsCols)); + System.out.println("TREES: " + Handler.trees.size()); + System.out.println("BOULDERS: " + Handler.boulders.size()); + System.out.println("MOBS: " + Handler.mobs.size()); + System.out.println("FLOWERS: " + Handler.flowers.size()); + System.out.println("TALLGRASS: " + Handler.grass.size()); + System.out.println("SAPLINGS: " + Handler.saplings.size()); + System.err.println("~~~ World Generated --- Total Time Taken: " + Float.toString((System.currentTimeMillis() - then)/1000f)+ " seconds ~~~"); + WORLD_GENERATED = true; + Handler.tick(); + Handler.getMapImage(); + System.gc(); + } +}