initial commit
3
.gitignore
vendored
@@ -1,3 +1,6 @@
|
||||
bin
|
||||
/bin/
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
|
||||
34
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:
|
||||
---------------------------------------
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
BIN
dev/LOGO.ico
Executable file
|
After Width: | Height: | Size: 262 KiB |
BIN
dev/LOGO.png
Executable file
|
After Width: | Height: | Size: 18 KiB |
BIN
dev/numbers-on-map.png
Executable file
|
After Width: | Height: | Size: 477 KiB |
BIN
dev/pyxeledit/Misc/item_icons.pyxel
Executable file
BIN
dev/pyxeledit/Mobs/goblins.pyxel
Executable file
BIN
dev/pyxeledit/Mobs/rabbits.pyxel
Executable file
BIN
dev/pyxeledit/Player/attacks.pyxel
Executable file
BIN
dev/pyxeledit/Player/axe_chops.pyxel
Executable file
BIN
dev/pyxeledit/Player/get-hits and death.pyxel
Executable file
BIN
dev/pyxeledit/Player/idles and walks.pyxel
Executable file
BIN
dev/pyxeledit/Player/mines.pyxel
Executable file
BIN
dev/screenshots/lighting - 4-30.png
Executable file
|
After Width: | Height: | Size: 564 KiB |
13
res/data/actionTexts.nihil
Executable file
@@ -0,0 +1,13 @@
|
||||
drop
|
||||
store
|
||||
retrieve
|
||||
equip
|
||||
unequip
|
||||
eat
|
||||
cook
|
||||
attack
|
||||
pick up
|
||||
harvest
|
||||
chop
|
||||
mine
|
||||
pick
|
||||
15
res/data/itemTexts.nihil
Executable file
@@ -0,0 +1,15 @@
|
||||
grass
|
||||
flowers
|
||||
crude axe
|
||||
logs
|
||||
crude pickaxe
|
||||
rocks
|
||||
sticks
|
||||
fire
|
||||
ashes
|
||||
torch
|
||||
rabbit carcass
|
||||
rabbit foot
|
||||
rot
|
||||
bones
|
||||
goblin spear
|
||||
15
res/data/itemTextsCapitalized.nihil
Executable file
@@ -0,0 +1,15 @@
|
||||
Grass
|
||||
Flowers
|
||||
Crude Axe
|
||||
Logs
|
||||
Crude Pickaxe
|
||||
Rocks
|
||||
Sticks
|
||||
Fire
|
||||
Ashes
|
||||
Torch
|
||||
Rabbit Carcass
|
||||
Rabbit Foot
|
||||
Rot
|
||||
Bones
|
||||
Goblin Spear
|
||||
BIN
res/data/mapsdata.nihil
Executable file
BIN
res/fonts/gregorian.ttf
Executable file
BIN
res/fonts/ponderosa.ttf
Executable file
BIN
res/saving/settings.nihil
Executable file
BIN
res/screenshots/mainscreen.png
Normal file
|
After Width: | Height: | Size: 32 KiB |
BIN
res/screenshots/screenshot1.jpg
Executable file
|
After Width: | Height: | Size: 95 KiB |
BIN
res/screenshots/screenshot2.jpg
Normal file
|
After Width: | Height: | Size: 528 KiB |
BIN
res/spritesheets/hud sheets/HUDsheet.nihil
Executable file
|
After Width: | Height: | Size: 784 KiB |
BIN
res/spritesheets/hud sheets/constructionsheet.nihil
Executable file
|
After Width: | Height: | Size: 100 KiB |
BIN
res/spritesheets/hud sheets/secondaryhudsheet.nihil
Executable file
|
After Width: | Height: | Size: 180 KiB |
BIN
res/spritesheets/menu sheets/menubuttonsheet.nihil
Executable file
|
After Width: | Height: | Size: 17 KiB |
BIN
res/spritesheets/menu sheets/settingsbuttonsheet.nihil
Executable file
|
After Width: | Height: | Size: 211 KiB |
BIN
res/spritesheets/menu sheets/splashsheet.nihil
Executable file
|
After Width: | Height: | Size: 81 KiB |
BIN
res/spritesheets/misc sheets/itemiconsheet.nihil
Executable file
|
After Width: | Height: | Size: 11 KiB |
BIN
res/spritesheets/mob sheets/goblinsheet.nihil
Executable file
|
After Width: | Height: | Size: 16 KiB |
BIN
res/spritesheets/mob sheets/rabbitsheet.nihil
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
res/spritesheets/player items sheets/CRUDE AXE/crudeaxeattacksheet.nihil
Executable file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
res/spritesheets/player items sheets/CRUDE AXE/crudeaxechopsheet.nihil
Executable file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
res/spritesheets/player items sheets/CRUDE AXE/crudeaxegethitsheet.nihil
Executable file
|
After Width: | Height: | Size: 969 B |
BIN
res/spritesheets/player items sheets/CRUDE AXE/crudeaxesheet.nihil
Executable file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxeattacksheet.nihil
Executable file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxegethitsheet.nihil
Executable file
|
After Width: | Height: | Size: 980 B |
BIN
res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxeminesheet.nihil
Executable file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
res/spritesheets/player items sheets/CRUDE PICKAXE/crudepickaxesheet.nihil
Executable file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspearattacksheet.nihil
Executable file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspeargethitsheet.nihil
Executable file
|
After Width: | Height: | Size: 688 B |
BIN
res/spritesheets/player items sheets/GOBLIN SPEAR/goblinspearsheet.nihil
Executable file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
res/spritesheets/player items sheets/TORCH/torchgethitsheet.nihil
Executable file
|
After Width: | Height: | Size: 816 B |
BIN
res/spritesheets/player items sheets/TORCH/torchwalkidlesheet.nihil
Executable file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
res/spritesheets/player sheets/baseplayerattacksheet.nihil
Executable file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
res/spritesheets/player sheets/playeraxesheet.nihil
Executable file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
res/spritesheets/player sheets/playerdeathsheet.nihil
Executable file
|
After Width: | Height: | Size: 6.1 KiB |
BIN
res/spritesheets/player sheets/playerminesheet.nihil
Executable file
|
After Width: | Height: | Size: 3.8 KiB |
BIN
res/spritesheets/player sheets/playersheet.nihil
Executable file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
res/spritesheets/world sheets/bouldersheet.nihil
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
res/spritesheets/world sheets/debrissheet.nihil
Executable file
|
After Width: | Height: | Size: 514 B |
BIN
res/spritesheets/world sheets/flowersheet.nihil
Executable file
|
After Width: | Height: | Size: 825 B |
BIN
res/spritesheets/world sheets/grasssheet.nihil
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
res/spritesheets/world sheets/oceantilesheet.nihil
Executable file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
res/spritesheets/world sheets/saplingsheet.nihil
Executable file
|
After Width: | Height: | Size: 592 B |
BIN
res/spritesheets/world sheets/structuresheet.nihil
Executable file
|
After Width: | Height: | Size: 581 B |
BIN
res/spritesheets/world sheets/tilesheet.nihil
Executable file
|
After Width: | Height: | Size: 18 KiB |
BIN
res/spritesheets/world sheets/treesheet.nihil
Executable file
|
After Width: | Height: | Size: 19 KiB |
90
scripts/mob_scripts/goblin_ai.py
Executable file
@@ -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()
|
||||
|
||||
124
scripts/other/inventory.py
Executable file
@@ -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 #######################################################################################
|
||||
|
||||
|
||||
145
src/_texture/loader/TextureLoader.java
Executable file
@@ -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");
|
||||
}
|
||||
}
|
||||
64
src/_texture/loader/Textures.java
Executable file
@@ -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];
|
||||
}
|
||||
141
src/animations/PlayerAnimationSequence.java
Executable file
@@ -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);
|
||||
}
|
||||
|
||||
/********************************************************************/
|
||||
}
|
||||
115
src/animations/PlayerAnimationUtils.java
Executable file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
272
src/animations/PlayerAnimations.java
Executable file
@@ -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]
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
66
src/animations/PlayerAttackAnimations.java
Executable file
@@ -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++])
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
71
src/engine/Camera.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
400
src/engine/DeveloperConsole.java
Executable file
@@ -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<String> 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<String>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
475
src/engine/Game.java
Executable file
@@ -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<Tile> 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);
|
||||
}
|
||||
}
|
||||
26
src/engine/GameToComponentCoordCalc.java
Executable file
@@ -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); }
|
||||
}
|
||||
274
src/engine/Handler.java
Executable file
@@ -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<Tree> trees;
|
||||
public static HashSet<Boulder> boulders;
|
||||
public static HashSet<Flower> flowers;
|
||||
public static HashSet<TallGrass> grass;
|
||||
public static HashSet<Sapling> saplings;
|
||||
public static HashSet<DroppedItem> droppedItems;
|
||||
public static HashSet<Structure> structures;
|
||||
public static HashSet<Mob> mobs;
|
||||
public static HashSet<Debris> debris;
|
||||
|
||||
public static ArrayList<ArrayList<ArrayList<Stack<Tile>>>> world;
|
||||
public static volatile Rectangle AREA_RECT;
|
||||
|
||||
public static void init() {
|
||||
AREA_RECT = new Rectangle(0,0,0,0);
|
||||
trees = new HashSet<Tree>();
|
||||
boulders = new HashSet<Boulder>();
|
||||
mobs = new HashSet<Mob>();
|
||||
flowers = new HashSet<Flower>();
|
||||
grass = new HashSet<TallGrass>();
|
||||
saplings = new HashSet<Sapling>();
|
||||
droppedItems = new HashSet<DroppedItem>();
|
||||
structures = new HashSet<Structure>();
|
||||
debris = new HashSet<Debris>();
|
||||
|
||||
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<Tile> 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;
|
||||
}
|
||||
|
||||
}
|
||||
488
src/engine/KeyInput.java
Executable file
@@ -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<Integer> keysDown;
|
||||
|
||||
public static final void init() {
|
||||
if(keysDown == null) keysDown = new HashSet<Integer>(); 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; }
|
||||
}
|
||||
77
src/engine/Menu.java
Executable file
@@ -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<MenuButton> menuButtons = new Stack<MenuButton>();
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
163
src/engine/MenuButton.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
200
src/engine/MouseInput.java
Executable file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
78
src/engine/PauseMenu.java
Executable file
@@ -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<MenuButton> pauseButtons = new Stack<MenuButton>();
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
1144
src/engine/Settings.java
Executable file
64
src/engine/SplashScreen.java
Executable file
@@ -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(); }
|
||||
}
|
||||
|
||||
}
|
||||
41
src/fileIO/Saving.java
Executable file
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
47
src/fileIO/SettingsSaveFile.java
Executable file
@@ -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<MenuButton> mainButtons, resizeable, displayFPS, healthBars, resolution, fpsCap;
|
||||
public volatile boolean resizeableTF, displayFPSTF, showHealthTF;
|
||||
|
||||
public SettingsSaveFile(Stack<MenuButton> mainButtons, Stack<MenuButton> resizeable, Stack<MenuButton> displayFPS,
|
||||
Stack<MenuButton> healthBars, Stack<MenuButton> resolution, Stack<MenuButton> 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;
|
||||
}
|
||||
|
||||
}
|
||||
62
src/fileIO/fonts/fonts.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/fileIO/textures/worldgen/BoulderTextures.java
Executable file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
15
src/fileIO/textures/worldgen/DebrisTextures.java
Executable file
@@ -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);
|
||||
}
|
||||
}
|
||||
28
src/fileIO/textures/worldgen/FlowerTextures.java
Executable file
@@ -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);
|
||||
}
|
||||
}
|
||||
18
src/fileIO/textures/worldgen/SaplingTextures.java
Executable file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
20
src/fileIO/textures/worldgen/TallGrassTextures.java
Executable file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
53
src/fileIO/textures/worldgen/TileTextures.java
Executable file
@@ -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);
|
||||
}
|
||||
}
|
||||
17
src/fileIO/textures/worldgen/TreeTextures.java
Executable file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
62
src/fonts/fonts.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
75
src/hud/Clock.java
Executable file
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
90
src/hud/Map.java
Executable file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
648
src/hud/RightClickMenu.java
Executable file
@@ -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<Line> 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<Line>();
|
||||
}
|
||||
|
||||
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<TextAttribute, Object> map = new Hashtable<TextAttribute, Object>();
|
||||
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;
|
||||
}
|
||||
}
|
||||
214
src/hud/SecondaryHUD.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
25
src/hud/constructionmenu/CONSTRUCTION_ITEMS.java
Executable file
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
98
src/hud/constructionmenu/ConstructionItem.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
62
src/hud/constructionmenu/ConstructionMenu.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
187
src/hud/constructionmenu/ConstructionMenuCategory.java
Executable file
@@ -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;
|
||||
}
|
||||
}
|
||||
163
src/hud/constructionmenu/ConstructionMenuHover.java
Executable file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||