Early Access, v1.0.1

This commit is contained in:
Nicola Sovic
2022-02-24 10:45:40 +01:00
parent 9610402e53
commit 639b127238
936 changed files with 75851 additions and 0 deletions

View File

@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class AudioHandler : MonoBehaviour
{
public AudioClip buttonClick;
public AudioClip damage;
public AudioClip explosion;
public AudioClip hit;
public AudioClip hitDagger;
public AudioClip IceHit;
public AudioClip LevelUp;
public AudioClip jump;
AudioSource cameraAudio;
AudioSource playerAudio;
// Start is called before the first frame update
void Start()
{
cameraAudio = GameObject.Find("Main Camera").GetComponent<AudioSource>();
playerAudio = GameObject.Find("Player").GetComponent<AudioSource>();
loadAudioSettings();
}
public void playButtonClick()
{
cameraAudio.mute = true;
playerAudio.clip = buttonClick;
playerAudio.Play();
cameraAudio.mute = false;
}
public void playDamage()
{
cameraAudio.mute = true;
playerAudio.clip = damage;
playerAudio.Play();
cameraAudio.mute = false;
}
public void playExplosion()
{
cameraAudio.mute = true;
playerAudio.clip = explosion;
playerAudio.Play();
cameraAudio.mute = false;
}
public void playHit()
{
cameraAudio.mute = true;
playerAudio.clip = hit;
playerAudio.Play();
cameraAudio.mute = false;
}
public void playDaggerHit()
{
cameraAudio.mute = true;
playerAudio.clip = hitDagger;
playerAudio.Play();
cameraAudio.mute = false;
}
public void playIceHit()
{
cameraAudio.mute = true;
playerAudio.clip = IceHit;
playerAudio.Play();
cameraAudio.mute = false;
}
public void playJump()
{
cameraAudio.mute = true;
playerAudio.clip = jump;
playerAudio.Play();
cameraAudio.mute = false;
}
public void playLevelUp()
{
cameraAudio.mute = true;
playerAudio.clip = LevelUp;
playerAudio.Play();
cameraAudio.mute = false;
}
public void changeVolumeMusic()
{
cameraAudio.volume = GameObject.Find("slideMusic").GetComponent<Slider>().value;
}
public void changeVolumeEffects()
{
playerAudio.volume = GameObject.Find("slideMusic").GetComponent<Slider>().value;
}
private void loadAudioSettings()
{
//Need to work on
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f49961101d617314a83ae0efcd6e4e53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts
{
public class BasicSkill
{
int level;
int baseDamage;
int secondaryConsumption;
int cooldown;
int maxCooldown;
string skillname;
Texture skillIcon;
GameObject skillAnimation;
public BasicSkill(int baseDamage, int secondaryConsumption, int maxCooldown, string name, string skillIconPath, GameObject skillAnimation)
{
this.baseDamage = baseDamage;
this.secondaryConsumption = secondaryConsumption;
this.maxCooldown = maxCooldown;
cooldown = 0;
level = 1;
skillname = name;
skillIcon = Resources.Load<Texture>(skillIconPath);
this.skillAnimation = skillAnimation;
}
public int calculateDamage(int attribute, bool isCrit)
{
cooldown = maxCooldown;
if (isCrit)
{
return (baseDamage + attribute)* level * 2;
}
return (baseDamage + attribute) * level ;
}
public bool canPlayerCast(int playerSecondary)
{
bool result = false;
if (playerSecondary >= secondaryConsumption && cooldown == 0)
{
result = true;
}
return result;
}
public void display(GameObject image, GameObject desc, int playerSecondary)
{
image.GetComponent<RawImage>().texture = skillIcon;
if (canPlayerCast(playerSecondary))
{
desc.GetComponent<Text>().text = skillname + "(Lvl." + level + ") (" + secondaryConsumption + ")";
}
else
{
desc.GetComponent<Text>().text = "Not castable (" + secondaryConsumption + ")";
}
}
public void reduceCooldown()
{
if (cooldown > 0)
{
cooldown--;
}
}
public int getSecondaryConsumption()
{
return secondaryConsumption;
}
public void playSound(AudioHandler audioHandler)
{
switch (skillname)
{
case "Slash":
audioHandler.playHit();
break;
case "Block":
break;
case "Execution":
audioHandler.playHit();
break;
case "Stab":
audioHandler.playDaggerHit();
break;
case "SmokeScreen":
break;
case "Heartstop":
audioHandler.playDaggerHit();
break;
case "Icicle":
audioHandler.playIceHit();
break;
case "Teleport":
break;
case "Fireball":
audioHandler.playExplosion();
break;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 56733a5ac2a22c3429b97a069f0916c8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,122 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Assets.Scripts
{
public class ButtonHandler : MonoBehaviour
{
UIHandler uihandler;
Player player;
AudioHandler audioHandler;
private void Start()
{
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
player = GameObject.Find("Player").GetComponent<Player>();
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
}
public void startGame()
{
audioHandler.playButtonClick();
uihandler.openTutorial();
}
public void closeGame()
{
audioHandler.playButtonClick();
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#endif
Application.Quit();
}
public void openOptions()
{
audioHandler.playButtonClick();
uihandler.openOptions();
}
public void closeOptions()
{
audioHandler.playButtonClick();
uihandler.closeOptions();
}
public void openCreation()
{
audioHandler.playButtonClick();
uihandler.openCharacterCreation();
}
public void closeCreation()
{
audioHandler.playButtonClick();
uihandler.closeCharacterCreation();
}
public void exitToMenu()
{
audioHandler.playButtonClick();
uihandler.openMainMenu();
}
public void closePauseMenu()
{
audioHandler.playButtonClick();
uihandler.closePauseMenu();
}
public void upgradeStrength()
{
audioHandler.playButtonClick();
player.upgradeStrength();
EventSystem.current.SetSelectedGameObject(null);
}
public void upgradeDexterity()
{
audioHandler.playButtonClick();
player.upgradeDexterity();
EventSystem.current.SetSelectedGameObject(null);
}
public void upgradeIntelligence()
{
audioHandler.playButtonClick();
player.upgradeIntelligence();
EventSystem.current.SetSelectedGameObject(null);
}
public void upgradeHealth()
{
audioHandler.playButtonClick();
player.upgradeHealth();
EventSystem.current.SetSelectedGameObject(null);
}
public void upgradeSecondary()
{
audioHandler.playButtonClick();
player.upgradeSecondary();
EventSystem.current.SetSelectedGameObject(null);
}
public void saveOptions()
{
audioHandler.playButtonClick();
uihandler.adaptScreen();
}
public void closeTutorial()
{
audioHandler.playButtonClick();
uihandler.startGame();
EventSystem.current.SetSelectedGameObject(null);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d229e5b0d08dea24787131fcabebdf42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 79c536bb7cfa17d43a369a6257663ee8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Classes
{
public class BasicClass
{
public string classname;
protected int dexterityBonus;
protected int intelligenceBonus;
protected int strengthBonus;
protected int healthBonus;
protected int secondaryBonus;
public BasicClass()
{
classname = "";
dexterityBonus = 0;
intelligenceBonus = 0;
strengthBonus = 0;
healthBonus = 0;
secondaryBonus = 0;
}
public void applyBonus(Player player)
{
player.changeStats(strengthBonus, healthBonus, dexterityBonus, intelligenceBonus, secondaryBonus);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 858b63eec39e4594986e017a41eb3311
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Classes
{
class MageClass : BasicClass
{
public MageClass() : base()
{
classname = "Mage";
dexterityBonus = 0;
intelligenceBonus = 2;
strengthBonus = -2;
healthBonus = -10;
secondaryBonus = 10;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ea236f5073a4eb941adbcc851756a366
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Classes
{
class ThiefClass : BasicClass
{
public ThiefClass() : base()
{
classname = "Thief";
dexterityBonus = 2;
intelligenceBonus = -1;
strengthBonus = -1;
healthBonus = 0;
secondaryBonus = 0;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a6fd6a8ede6d5cf45a605dbc61c467df
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Classes
{
class WarriorClass : BasicClass
{
public WarriorClass() : base()
{
classname = "Warrior";
dexterityBonus = 0;
intelligenceBonus = -2;
strengthBonus = 2;
healthBonus = 10;
secondaryBonus = -10;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0dfab60c3eae69f40ab8b69d2336c7d6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,104 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ContentGenerator : MonoBehaviour
{
public GameObject[] enemies;
public GameObject[] trees;
public GameObject[] stones;
public GameObject grass;
public GameObject boss;
//public GameObject npc;
static System.Random rand = new System.Random();
public GameObject generateEnemy()
{
int index = rand.Next(0, enemies.Length);
return enemies[index];
}
public GameObject generateContent(string tiletype)
{
switch (tiletype)
{
case "Tile":
return generateTileContent();
case "StoneTile":
return generateStoneTileContent();
case "TreeTile":
return generateTreeTileContent();
}
return null;
}
public GameObject generateTileContent()
{
int chance = rand.Next(1, 101);
if (chance < 50)
{
return null;
}
else if (chance >= 50 && chance < 90)
{
if (rand.Next(0,trees.Length) == 0)
{
return trees[rand.Next(0, trees.Length)];
}
else
{
return stones[rand.Next(0, stones.Length)];
}
}
else if (chance >= 90 && chance < 99)
{
return generateEnemy();
}
else
{
return boss;
}
}
public GameObject generateStoneTileContent()
{
int chance = rand.Next(1, 101);
if (chance < 60)
{
return stones[rand.Next(0, stones.Length)];
}
else if (chance >= 60 && chance < 90)
{
return trees[rand.Next(0, trees.Length)];
}
else if (chance >= 90 && chance < 99)
{
return generateEnemy();
}
else
{
return boss;
}
}
public GameObject generateTreeTileContent()
{
int chance = rand.Next(1, 101);
if (chance < 60)
{
return trees[rand.Next(0, trees.Length)];
}
else if (chance >= 60 && chance < 90)
{
return stones[rand.Next(0, stones.Length)];
}
else if (chance >= 90 && chance < 99)
{
return generateEnemy();
}
else
{
return boss;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d16cb1af3326c2c4d9e5d4ff8e4ed7cc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

105
Assets/Scripts/Controls.cs Normal file
View File

@@ -0,0 +1,105 @@
using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Controls : MonoBehaviour
{
GameObject player;
GameObject fight;
GameObject worldGen;
GameObject playerCam;
UIHandler uihandler;
void Start()
{
player = GameObject.Find("Player");
fight = GameObject.Find("Fight");
worldGen = GameObject.Find("WorldGenerator");
playerCam = GameObject.Find("InformationCamera");
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
}
// Update is called once per frame
void Update()
{
if (!player.GetComponent<Player>().takeDamage(0))
{
if (!uihandler.isPlayerInFight())
{
checkNormalControls();
}
else
{
checkFightControls();
}
}
}
private void checkNormalControls()
{
if (uihandler.canPlayerMove())
{
player.GetComponent<Player>().move();
if (Input.GetKeyDown(KeyCode.M))
{
worldGen.GetComponent<WorldGenerator>().prepareMap();
uihandler.switchMap();
}
else if (Input.GetKeyDown(KeyCode.E))
{
GameObject target = playerCam.GetComponent<PlayerCamera>().interactWithObject();
if (target != null)
{
switch (target.tag.Split(':')[1])
{
case "Enemy":
fight.GetComponent<Fight>().startFight(worldGen.GetComponent<WorldGenerator>().getCurrentTile(), target, player);
break;
}
}
}
else if (Input.GetKeyDown(KeyCode.C))
{
uihandler.switchCharactersheet();
}
else if (Input.GetKeyDown(KeyCode.Q))
{
uihandler.switchQuestLog();
}
}
if (Input.GetKeyDown(KeyCode.Escape))
{
uihandler.switchPauseMenu();
}
}
private void checkFightControls()
{
if (Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1))
{
fight.GetComponent<Fight>().playerAction(1);
}
else if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2))
{
fight.GetComponent<Fight>().playerAction(2);
}
else if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3))
{
fight.GetComponent<Fight>().playerAction(3);
}
else if (Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4))
{
fight.GetComponent<Fight>().playerAction(4);
}
else if (Input.GetKeyDown(KeyCode.Alpha5) || Input.GetKeyDown(KeyCode.Keypad5))
{
fight.GetComponent<Fight>().playerAction(5);
}
else if (Input.GetKeyDown(KeyCode.Alpha6) || Input.GetKeyDown(KeyCode.Keypad6))
{
fight.GetComponent<Fight>().playerAction(6);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5becc189f2c76a14490d22e7435bbf40
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

123
Assets/Scripts/Enemy.cs Normal file
View File

@@ -0,0 +1,123 @@
using Assets.Scripts;
using Assets.Scripts.Slimes;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Assets.Scripts
{
public class Enemy : MonoBehaviour
{
string enemyname;
System.Random rand = new System.Random();
BasicSlime slime;
SlimeFactory factory = new SlimeFactory();
// Start is called before the first frame update
void Start()
{
enemyname = gameObject.name;
if (enemyname.Contains("("))
{
enemyname = enemyname.Split('(')[0];
}
renameEnemy();
}
// Update is called once per frame
void Update()
{
}
private void renameEnemy()
{
switch (enemyname)
{
case "SlimeMageIdle":
enemyname = "Slime (Mage)";
break;
case "SlimeBaseIdle":
enemyname = "Slime";
break;
case "SlimeMetalIdle":
enemyname = "Slime (Metal)";
break;
case "SlimeMiniBossIdle":
enemyname = "Slime (MiniBoss)";
break;
case "SlimeWarriorIdle":
enemyname = "Slime (Warrior)";
break;
case "SlimeWaterIdle":
enemyname = "Slime (Water)";
break;
case "SlimeBossIdle":
enemyname = "Slime (Boss)";
break;
}
}
public void scaleEnemy(Player player)
{
if (slime == null)
{
switch (enemyname)
{
case "Slime (Mage)":
slime = factory.generateMageSlime(player);
break;
case "Slime":
slime = factory.generateNormalSlime(player);
break;
case "Slime (Metal)":
slime = factory.generateMetalSlime(player);
break;
case "Slime (MiniBoss)":
slime = factory.generateMiniBossSlime(player);
break;
case "Slime (Warrior)":
slime = factory.generateWarriorSlime(player);
break;
case "Slime (Water)":
slime = factory.generateWaterSlime(player);
break;
case "Slime (Boss)":
slime = factory.generateBossSlime(player);
break;
}
}
}
public int[] getStats()
{
return slime.getStats();
}
public string getEnemyName()
{
return enemyname;
}
public int calculateDamage()
{
return slime.calculateDamage(rand);
}
public int calculateHeavy()
{
return slime.calculateHeavy(rand);
}
public bool takeDamage(int amount)
{
return slime.takeDamage(amount,rand);
}
public int getExperience()
{
return slime.getExperience();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc3c1c0815bce34498b5dc8b199d0118
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

136
Assets/Scripts/Fight.cs Normal file
View File

@@ -0,0 +1,136 @@
using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Fight : MonoBehaviour
{
GameObject tile;
GameObject enemy;
GameObject player;
System.Random rand = new System.Random();
UIHandler uihandler;
public void startFight(GameObject tile, GameObject enemy, GameObject player)
{
this.tile = tile;
this.enemy = enemy;
this.player = player;
enemy.GetComponent<Enemy>().scaleEnemy(player.GetComponent<Player>());
enemy.transform.rotation = player.transform.rotation;
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
uihandler.openFight();
uihandler.updateFightInterface(enemy, player);
}
private void endFight()
{
uihandler.closeFight();
}
public void playerAction(int index)
{
int playerDamage = 0;
int skillnumber = -1;
switch (index)
{
case 1:
endFight();
uihandler.showMessage("INFORMATION;You escaped");
break;
case 2:
//User waits
break;
case 3:
playerDamage = player.GetComponent<Player>().calculateDamage();
break;
case 4:
skillnumber = 0;
break;
case 5:
skillnumber = 1;
break;
case 6:
skillnumber = 2;
break;
}
if (skillnumber != -1)
{
playerDamage = player.GetComponent<Player>().castSkill(skillnumber);
}
player.GetComponent<Player>().reduceCooldown(skillnumber);
player.GetComponent<Player>().regainSecondary(2);
bool isDead = enemy.GetComponent<Enemy>().takeDamage(playerDamage);
if (isDead)
{
endFight();
tile.GetComponent<Tile>().enemyKilled(enemy);
player.GetComponent<Player>().enemyKilled();
player.GetComponent<Player>().gainExperience(enemy.GetComponent<Enemy>().getExperience());
}
else
{
if (index != 1)
{
enemyAction();
uihandler.updateFightInterface(enemy, player);
}
}
}
public void enemyAction()
{
int enemyDamage = -1;
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
int[] enemyStats = enemy.GetComponent<Enemy>().getStats();
int index = rand.Next(0,3);
if (enemyStats[0] <= enemyStats[1] / 4 && index != 0)
{
enemyDamage = secondChance();
if (enemyDamage != 0)
{
enemyDamage = secondChance();
}
}
else if (enemyStats[0] <= enemyStats[1] / 2 && index != 0)
{
enemyDamage = secondChance();
}
if (index == 2 && enemyStats[2] <= 0)
{
index = 1;
}
if (enemyDamage == 0 || index == 0)
{
endFight();
uihandler.showMessage("INFORMATION;The enemy escaped!");
}
else
{
switch (index)
{
case 1:
enemyDamage = enemy.GetComponent<Enemy>().calculateDamage();
break;
case 2:
enemyDamage = enemy.GetComponent<Enemy>().calculateHeavy();
break;
}
}
if (player.GetComponent<Player>().takeDamage(enemyDamage))
{
uihandler.showDeathScreen();
}
}
private int secondChance()
{
int result = rand.Next(0, 3);
return result;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ce357854cffde645bddea205b4381e8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,80 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts
{
class LogWriter : MonoBehaviour
{
GameObject img;
GameObject txt;
List<string> messages;
bool isDisplaying = false;
DateTime call;
void Start()
{
img = GameObject.Find("MessageImage").gameObject;
txt = GameObject.Find("MessageText").gameObject;
messages = new List<string>();
}
void Update()
{
if (messages.Count > 0 && GameObject.Find("Fight").transform.localScale.Equals(new Vector3(0, 0, 0)))
{
if (!isDisplaying)
{
writeMessage();
}
else
{
hideMessage();
}
}
}
public void addMessage(string message)
{
messages.Add(message);
}
public void writeMessage()
{
switch (messages[0].Split(';')[0])
{
case "ERROR":
img.GetComponent<RawImage>().color = Color.red;
break;
case "INFORMATION":
img.GetComponent<RawImage>().color = Color.black;
break;
case "SUCCESS":
img.GetComponent<RawImage>().color = Color.green;
break;
case "WARNING":
img.GetComponent<RawImage>().color = Color.yellow;
break;
}
txt.GetComponent<Text>().text = messages[0].Split(';')[1];
gameObject.transform.localScale = new Vector3(1, 1, 1);
isDisplaying = true;
call = DateTime.Now;
}
private void hideMessage()
{
if (call.AddSeconds(2).CompareTo(DateTime.Now) <= 0)
{
gameObject.transform.localScale = new Vector3(0, 0, 0);
isDisplaying = false;
messages.Remove(messages[0]);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c12bf8662ea7f9141960b628beeb3546
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

74
Assets/Scripts/Map.cs Normal file
View File

@@ -0,0 +1,74 @@
using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Map : MonoBehaviour
{
public Image city;
public Image plains;
public Image forest;
public Image stone;
public Image spawn;
public Image[] mapTiles;
public void prepare(Dictionary<Vector3, GameObject> tiles, GameObject currentTile)
{
destroyMap();
generateMap(tiles, currentTile);
}
private void destroyMap()
{
for (int i = 0; i < mapTiles.Length; i++)
{
mapTiles[i].color = Color.white;
}
}
private void generateMap(Dictionary<Vector3, GameObject> tiles, GameObject currentTile)
{
Vector3 current = currentTile.GetComponent<Tile>().getPosition();
Vector3 position;
Color color;
int posX = (int)current.x - 2;
int posZ = (int)current.z + 2;
for (int i = 0; i < mapTiles.Length; i++)
{
if (i == 5 || i == 10 || i == 15 || i == 20)
{
posX = (int)current.x - 2;
posZ--;
}
position = new Vector3(posX, 0, posZ);
if (tiles.ContainsKey(position))
{
switch (tiles[position].name.Split('_')[0])
{
case "StoneTile":
color = stone.color;
break;
case "CityTile":
color = city.color;
break;
case "Tile":
color = plains.color;
break;
case "TreeTile":
color = forest.color;
break;
default:
color = spawn.color;
break;
}
mapTiles[i].color = color;
}
posX++;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3a168312b9f89044eac3b72d87cde0ac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

23
Assets/Scripts/NPC.cs Normal file
View File

@@ -0,0 +1,23 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NPC : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void interact()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 87ac36bb4d63c7b4f901ce681578ca4b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,73 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NoiseGenerator
{
public void applyTileNoise(GameObject tile)
{
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
float[] samples = calculateSamples(tile);
for (int i = 0; i < samples.Length; i++)
{
vertices[i].y = samples[i] * 5;
}
applyMesh(tile, vertices, mesh);
}
public void applyStoneTileNoise(GameObject tile)
{
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
float[] samples = calculateSamples(tile);
for (int i = 0; i < samples.Length; i++)
{
vertices[i].y = samples[i] * 10;
}
applyMesh(tile, vertices, mesh);
}
public void applyTreeTileNoise(GameObject tile)
{
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
float[] samples = calculateSamples(tile);
for (int i = 0; i < samples.Length; i++)
{
vertices[i].y = samples[i] * 7.5f;
}
applyMesh(tile, vertices, mesh);
}
public void applyCityTileNoise(GameObject tile)
{
//Currently no noise. (Objects floating)
}
private float[] calculateSamples(GameObject tile)
{
Mesh mesh = tile.GetComponent<MeshFilter>().mesh;
Vector3[] vertices = mesh.vertices;
float[] samples = new float[vertices.Length - 1];
for (int i = 0; i < vertices.Length; i++)
{
if (vertices[i].x != 5 && vertices[i].z != 5 && vertices[i].x != -5 && vertices[i].z != -5)
{
float xCord = tile.GetComponent<Tile>().getPosition().x + vertices[i].x / (vertices.Length - 1) * 10;
float yCord = tile.GetComponent<Tile>().getPosition().z + vertices[i].z / (vertices.Length - 1) * 10;
float sample = Mathf.PerlinNoise(xCord, yCord) - 0.5f;
samples[i] = sample;
}
}
return samples;
}
private void applyMesh(GameObject tile, Vector3[] vertices, Mesh mesh)
{
mesh.vertices = vertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
tile.GetComponent<MeshCollider>().sharedMesh = mesh;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ae238f7dd6dcd124db5d74a1c506c439
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

441
Assets/Scripts/Player.cs Normal file
View File

@@ -0,0 +1,441 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;
using Assets.Scripts.Classes;
using Assets.Scripts.Races;
namespace Assets.Scripts
{
public class Player : MonoBehaviour
{
public float speed = 5f;
System.Random rand = new System.Random();
DateTime now;
UIHandler uihandler;
AudioHandler audioHandler;
int bobbingDirection = -1;
string playername;
int health;
int maxHealth;
int maxSecondary;
int secondary;
int strength;
int dexterity;
int intelligence;
int level;
int experience;
int maxExperience;
BasicRace race;
BasicClass role;
BasicSkill[] skills = new BasicSkill[3];
int points = 0;
bool isDodging = false;
int killcount = -1;
int difficulty = 0;
// Start is called before the first frame update
void Start()
{
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
audioHandler = GameObject.Find("AudioHandler").GetComponent<AudioHandler>();
}
public void generatePlayer(BasicRace race, BasicClass role, string name, int difficulty)
{
playername = name;
health = 100;
maxHealth = 100;
maxSecondary = 20;
secondary = 20;
strength = 5;
dexterity = 5;
intelligence = 5;
experience = 0;
maxExperience = 10;
level = 0;
killcount = 0;
this.race = race;
this.race.applyBonus(this);
this.role = role;
this.role.applyBonus(this);
this.difficulty = difficulty;
generateSkills();
}
private void generateSkills()
{
switch (role.classname)
{
case "Warrior":
skills[0] = new BasicSkill(15,10,2,"Slash","Skills/Warrior/Slash",null);
skills[1] = new BasicSkill(0, 5, 1, "Block", "Skills/Warrior/Block", null);
skills[2] = new BasicSkill(30, 30, 4, "Execution", "Skills/Warrior/Execution", null);
break;
case "Thief":
skills[0] = new BasicSkill(15, 10, 2, "Stab", "Skills/Thief/Stab", null);
skills[1] = new BasicSkill(0, 5, 1, "SmokeScreen", "Skills/Thief/SmokeScreen", null);
skills[2] = new BasicSkill(30, 30, 4, "Heartstop", "Skills/Thief/Heartstop", null);
break;
case "Mage":
skills[0] = new BasicSkill(15, 10, 2, "Icicle", "Skills/Mage/Icicle", null);
skills[1] = new BasicSkill(0, 5, 1, "Teleport", "Skills/Mage/Teleport", null);
skills[2] = new BasicSkill(30, 30, 4, "Fireball", "Skills/Mage/Fireball", null);
break;
}
}
public void changeStats(int strength, int health, int dexterity, int intelligence, int secondary)
{
this.maxHealth = this.maxHealth + health;
this.health = maxHealth;
this.maxSecondary = this.maxSecondary + secondary;
this.secondary = maxSecondary;
this.strength = this.strength + strength;
this.dexterity = this.dexterity + dexterity;
this.intelligence = this.intelligence + intelligence;
}
// Update is called once per frame
void Update()
{
if (killcount != -1)
{
getRotation();
regeneratePlayer();
uihandler.adjustInformation(this);
}
}
private void regeneratePlayer()
{
if (uihandler.state != UIState.FIGHT)
{
if (now == null)
{
now = DateTime.Now;
}
else
{
if (now.AddSeconds(10).CompareTo(DateTime.Now) <= 0)
{
now = DateTime.Now;
regainSecondary(5);
healPlayer();
}
}
}
else
{
now = DateTime.Now;
}
}
public void regainSecondary(int amount)
{
secondary = secondary + amount;
if (secondary >= maxSecondary)
{
secondary = maxSecondary;
}
}
private void healPlayer()
{
health = health + 5;
if (health >= maxHealth)
{
health = maxHealth;
}
}
public void move()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
if (Input.GetKeyDown(KeyCode.Space))
{
if ((int)(gameObject.GetComponent<Rigidbody>().velocity.y * 10) == 0)
{
gameObject.GetComponent<Rigidbody>().velocity = new Vector3(0, 5, 0);
audioHandler.playJump();
}
}
Vector3 movement = new Vector3(0, 0, z);
Vector3 rotation = new Vector3(0, x * 20, 0);
gameObject.transform.Rotate(rotation * speed * Time.deltaTime);
gameObject.transform.Translate(movement * speed * Time.deltaTime);
if (z != 0)
{
GameObject camera = GameObject.Find("Main Camera");
if (camera.transform.localPosition.y >= 0.5)
{
bobbingDirection = -1;
}
else if (camera.transform.localPosition.y <= 0.3)
{
bobbingDirection = 1;
}
camera.transform.Translate(new Vector3(0, bobbingDirection, 0) * Time.deltaTime / 2);
}
}
public void getRotation()
{
GameObject.Find("North").GetComponent<Text>().color = Color.white;
GameObject.Find("East").GetComponent<Text>().color = Color.white;
GameObject.Find("South").GetComponent<Text>().color = Color.white;
GameObject.Find("West").GetComponent<Text>().color = Color.white;
float rotation = gameObject.transform.rotation.eulerAngles.y;
if (rotation < 0)
{
rotation += 360;
}
if (rotation <= 44 || rotation >= 315)
{
GameObject.Find("North").GetComponent<Text>().color = Color.red;
}
else if (rotation >= 45 && rotation <= 134)
{
GameObject.Find("East").GetComponent<Text>().color = Color.red;
}
else if (rotation >= 135 && rotation <= 224)
{
GameObject.Find("South").GetComponent<Text>().color = Color.red;
}
else if (rotation >= 225 && rotation <= 314)
{
GameObject.Find("West").GetComponent<Text>().color = Color.red;
}
}
public int[] getStats()
{
int[] result = { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points};
return result;
}
public void displaySkill(int index, GameObject image, GameObject desc)
{
skills[index].display(image, desc, secondary);
}
public int calculateDamage()
{
int result;
int bonus = 0;
if (isCrit())
{
bonus = strength * 2;
}
result = strength + bonus + 5;
switch (difficulty)
{
case 0:
result = result * 2;
break;
case 1:
//Default difficulty
break;
case 2:
result = result / 2;
break;
}
return result;
}
public void updateKillcount(GameObject gameObject)
{
gameObject.GetComponent<Text>().text = "Slimes: " + killcount + "/" + (20 * (difficulty + 1));
}
public int castSkill(int index)
{
int damage = 0;
if (skills[index].canPlayerCast(secondary))
{
if (index == 1)
{
isDodging = true;
}
secondary = secondary - skills[index].getSecondaryConsumption();
if (role.classname == "Wizard")
{
damage = skills[index].calculateDamage(intelligence, isCrit());
}
else
{
damage = skills[index].calculateDamage(strength, isCrit());
}
switch (difficulty)
{
case 0:
damage = damage * 2;
break;
case 1:
//Default difficulty
break;
case 2:
damage = damage / 2;
break;
}
skills[index].playSound(audioHandler);
}
return damage;
}
public void reduceCooldown(int index)
{
for (int i = 0; i < skills.Length; i++)
{
if (i != index)
{
skills[i].reduceCooldown();
}
}
}
public bool isCrit()
{
return rand.Next(1, 101) <= dexterity;
}
public int getKillCount()
{
return killcount;
}
public bool takeDamage(int amount)
{
if (amount > 0)
{
if (isDodging)
{
isDodging = false;
}
else
{
if (rand.Next(1, 101) > dexterity + (intelligence / 2))
{
health = health - amount;
audioHandler.playDamage();
}
}
}
return health <= 0;
}
public void enemyKilled()
{
uihandler.showMessage("SUCCESS;You killed your enemy!");
killcount++;
if (killcount == 30 * (difficulty + 1) && GameObject.Find("Worldgenerator").GetComponent<WorldGenerator>().gameWon())
{
uihandler.showMessage("SUCCESS;You won the game!");
}
}
public void gainExperience(int amount)
{
experience = experience + amount;
if (experience >= maxExperience)
{
experience = experience - maxExperience;
maxExperience = maxExperience * 2;
level++;
uihandler.showMessage("SUCCESS;You gained a level!");
points = points + 3;
audioHandler.playLevelUp();
}
}
public void updateName(Text nameUI)
{
nameUI.text = playername + " (" + race.racename + "/" + role.classname + ", Lvl. " + level + ")";
}
public void updateNameHUD(Text nameUI)
{
nameUI.text = playername + "\n\r" + race.racename + "/" + role.classname + "\r\n Lvl. " + level;
}
public void upgradeStrength()
{
if (points > 0)
{
strength++;
points--;
}
else
{
uihandler.showMessage("ERROR;You don't have enough points!");
}
}
public void upgradeDexterity()
{
if (points > 0)
{
dexterity++;
points--;
}
else
{
uihandler.showMessage("ERROR;You don't have enough points!");
}
}
public void upgradeIntelligence()
{
if (points > 0)
{
intelligence++;
points--;
}
else
{
uihandler.showMessage("ERROR;You don't have enough points!");
}
}
public void upgradeHealth()
{
if (points > 0)
{
maxHealth = maxHealth + 5;
health = maxHealth;
points--;
}
else
{
uihandler.showMessage("ERROR;You don't have enough points!");
}
}
public void upgradeSecondary()
{
if (points > 0)
{
maxSecondary = maxSecondary + 5;
secondary = maxSecondary;
points--;
}
else
{
uihandler.showMessage("ERROR;You don't have enough points!");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6eac15f641a82224c87a6ada5746d64b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,87 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Assets.Scripts
{
public class PlayerCamera : MonoBehaviour
{
UIHandler uihandler;
// Start is called before the first frame update
void Start()
{
uihandler = GameObject.Find("UIHandler").GetComponent<UIHandler>();
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
showInformation();
}
public GameObject interactWithObject()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, 3))
{
if (hit.collider.gameObject.tag.ToLower().Contains("object"))
{
return hit.collider.gameObject;
}
}
return null;
}
void showInformation()
{
RaycastHit hit;
if (Physics.Raycast(transform.position, transform.forward, out hit, Mathf.Infinity))
{
if (hit.collider.gameObject.tag.ToLower().Contains("object"))
{
string obj = hit.collider.gameObject.tag.Split(':')[1];
switch (obj.ToLower())
{
case "tree":
displayInformation("Tree");
break;
case "stone":
displayInformation("Stone");
break;
case "npc":
displayInformation("NPC");
break;
case "enemy":
displayInformation(hit.collider.gameObject.GetComponent<Enemy>().getEnemyName());
break;
case "city":
displayInformation("City");
break;
}
}
}
else
{
uihandler.hideInformation();
}
}
private void displayInformation(string information)
{
if (!uihandler.isPlayerInFight())
{
uihandler.displayInformation(information);
}
else
{
uihandler.hideInformation();
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0dafbb406c854e141ba4c7f354514063
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5ee96bf6174d0474c805836425ba155d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Races
{
public class BasicRace
{
public string racename;
protected int dexterityBonus;
protected int intelligenceBonus;
protected int strengthBonus;
protected int healthBonus;
protected int secondaryBonus;
public BasicRace()
{
racename = "";
dexterityBonus = 0;
intelligenceBonus = 0;
strengthBonus = 0;
healthBonus = 0;
secondaryBonus = 0;
}
public void applyBonus(Player player)
{
player.changeStats(strengthBonus, healthBonus, dexterityBonus, intelligenceBonus, secondaryBonus);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9d7205b9e587ea844a590901f6ab3118
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Races
{
class DwarvenRace : BasicRace
{
public DwarvenRace() : base()
{
racename = "Dwarf";
dexterityBonus = 1;
intelligenceBonus = 0;
strengthBonus = 2;
healthBonus = 10;
secondaryBonus = -10;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 33997d803fe792b498271ab199504f27
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Races
{
class ElvenRace : BasicRace
{
public ElvenRace() : base()
{
racename = "Elf";
dexterityBonus = 2;
intelligenceBonus = 3;
strengthBonus = -2;
healthBonus = 0;
secondaryBonus = 20;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 887319a01dbcc7146813838a0f824cdf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Races
{
class GiantRace : BasicRace
{
public GiantRace() : base()
{
racename = "Giant";
dexterityBonus = 0;
intelligenceBonus = -3;
strengthBonus = 2;
healthBonus = 20;
secondaryBonus = -10;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4211e7c55cb15f44c855072c2d94d1d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Races
{
class GoblinRace : BasicRace
{
public GoblinRace() : base()
{
racename = "Goblin";
dexterityBonus = 3;
intelligenceBonus = -1;
strengthBonus = -2;
healthBonus = -10;
secondaryBonus = -10;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 882772f2b274cbf4082a5df89b98c49d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Races
{
class HumanRace : BasicRace
{
public HumanRace() : base()
{
racename = "Human";
dexterityBonus = 0;
intelligenceBonus = 0;
strengthBonus = 0;
healthBonus = 0;
secondaryBonus = 0;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2dbb989f6aa8fc84085a77f592987411
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bc482ea949740254194d33b97307a7cc
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
public class BasicSlime
{
protected int health;
protected int maxHealth;
protected int maxSecondary;
protected int secondary;
protected int strength;
protected int dexterity;
protected int intelligence;
protected int level;
protected int experience;
public BasicSlime(Player player)
{
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, playerlevel};
int[] playerStats = player.getStats();
maxHealth = playerStats[1];
health = maxHealth;
maxSecondary = playerStats[3];
secondary = maxSecondary;
strength = playerStats[4];
dexterity = playerStats[5];
intelligence = playerStats[6];
experience = (int)(10 + playerStats[7] * 1.5f);
level = playerStats[7];
}
public int[] getStats()
{
int[] result = { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
return result;
}
public bool takeDamage(int amount, System.Random rand)
{
if (rand.Next(1, 101) > dexterity + (intelligence / 2))
{
health = health - amount;
}
return health <= 0;
}
public int calculateHeavy(System.Random rand)
{
int result = 0;
if (secondary >= maxSecondary / 2)
{
int bonus = 0;
if (rand.Next(1, 101) <= dexterity)
{
bonus = strength * 2;
}
result = strength + bonus + 10;
secondary = secondary - (maxSecondary / 2);
}
return result;
}
public int calculateDamage(System.Random rand)
{
int result;
int bonus = 0;
if (rand.Next(1, 101) <= dexterity)
{
bonus = strength * 2;
}
result = strength + bonus + 5;
return result;
}
public int getExperience()
{
return experience;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 10a03b21cc65dd64db3f88e6000e7d42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
class BossSlime : BasicSlime
{
public BossSlime(Player player) : base(player)
{
intelligence = intelligence + 5;
strength = strength + 10;
maxHealth = maxHealth + 40;
health = maxHealth;
maxSecondary = maxSecondary + 20;
dexterity = dexterity + 5;
secondary = maxSecondary;
experience = experience * 2;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0f4bf4ca6466f624da5700a719049d53
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
public class MageSlime : BasicSlime
{
public MageSlime(Player player) : base(player)
{
intelligence = intelligence + 2;
strength = strength - 2;
maxHealth = maxHealth - 10;
health = maxHealth;
maxSecondary = maxSecondary + 10;
dexterity = dexterity - 2;
secondary = maxSecondary;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 879d7335690dea74f8be9d3b27a56b44
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
class MetalSlime : BasicSlime
{
public MetalSlime(Player player) : base(player)
{
//intelligence = intelligence;
strength = strength + 2;
maxHealth = maxHealth + 10;
health = maxHealth;
//maxSecondary = maxSecondary;
//dexterity = dexterity;
//secondary = maxSecondary;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a3d743ccb908a84a8ea47b1d8786405
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
class MiniBossSlime : BasicSlime
{
public MiniBossSlime(Player player) : base(player)
{
intelligence = intelligence + 3;
strength = strength + 3;
maxHealth = maxHealth + 20;
health = maxHealth;
maxSecondary = maxSecondary + 20;
dexterity = dexterity + 3;
secondary = maxSecondary;
experience = (int)(experience + experience * 0.5f);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 05539a1b68bd2d84ba3b2d01298101c5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
class NormalSlime : BasicSlime
{
public NormalSlime(Player player) : base(player)
{
maxHealth = maxHealth + 10;
health = maxHealth;
maxSecondary = maxSecondary + 10;
secondary = maxSecondary;
strength = strength - 2;
dexterity = dexterity - 2;
intelligence = intelligence - 2;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 291ac333aaf45f64f9b06b041736a0a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
class SlimeFactory
{
public NormalSlime generateNormalSlime(Player player)
{
return new NormalSlime(player);
}
public MageSlime generateMageSlime(Player player)
{
return new MageSlime(player);
}
public MetalSlime generateMetalSlime(Player player)
{
return new MetalSlime(player);
}
public MiniBossSlime generateMiniBossSlime(Player player)
{
return new MiniBossSlime(player);
}
public WarriorSlime generateWarriorSlime(Player player)
{
return new WarriorSlime(player);
}
public WaterSlime generateWaterSlime(Player player)
{
return new WaterSlime(player);
}
public BossSlime generateBossSlime(Player player)
{
return new BossSlime(player);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: bec7e4d4999a7d242bd4cc4cf996c183
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
class WarriorSlime : BasicSlime
{
public WarriorSlime(Player player) : base(player)
{
intelligence = intelligence - 2;
strength = strength + 2;
maxHealth = maxHealth + 10;
health = maxHealth;
//maxSecondary = maxSecondary;
//dexterity = dexterity;
//secondary = maxSecondary;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e93c75883af91bd46b384952c35db9b9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts.Slimes
{
class WaterSlime : BasicSlime
{
public WaterSlime(Player player) : base(player)
{
//intelligence = intelligence;
//strength = strength;
maxHealth = maxHealth + 10;
health = maxHealth;
maxSecondary = maxSecondary + 10;
dexterity = dexterity + 2;
secondary = maxSecondary;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2ea5cb52f1beba147a695af67d5d622f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

204
Assets/Scripts/Tile.cs Normal file
View File

@@ -0,0 +1,204 @@
using Assets.Scripts;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tile : MonoBehaviour
{
Vector3 position;
float borderNorth;
float borderEast;
float borderSouth;
float borderWest;
System.Random rand = new System.Random();
string tilename;
GameObject contentGenerator;
List<GameObject> aliveEnemies = new List<GameObject>();
List<GameObject> deadEnemies = new List<GameObject>();
public void generateTile(Vector3 pos, string name)
{
tilename = name;
contentGenerator = GameObject.Find("ContentGenerator");
setPosition(pos);
setBorders();
generateContent();
}
public void setBorders()
{
borderNorth = position.z * 100 + 50;
borderEast = position.x * 100 + 50;
borderSouth = position.z * 100 - 50;
borderWest = position.x * 100 - 50;
}
public void generateContent()
{
if (!tilename.ToLower().Equals("City"))
{
foreach (Vector3 position in getSpawnLocations())
{
spawnObject(position);
}
}
}
public List<Vector3> getSpawnLocations()
{
List<Vector3> list = new List<Vector3>();
int xChange = 0;
int zChange = 0;
for (float i = borderNorth - 10; i >= borderSouth + 10; i = i - 10)
{
for (float j = borderWest + 10; j <= borderEast - 10; j = j + 10)
{
xChange = rand.Next(-4, +4);
zChange = rand.Next(-4, +4);
list.Add(new Vector3(j + xChange, 5, i + zChange));
}
}
return list;
}
public void spawnObject(Vector3 position)
{
int chance = rand.Next(1, 101);
if (chance >= 50)
{
GameObject content = contentGenerator.GetComponent<ContentGenerator>().generateContent(tilename);
if (content != null)
{
GameObject obj = Instantiate(content, position, Quaternion.identity);
obj.transform.parent = gameObject.transform;
if (obj.tag.Contains("Enemy"))
{
aliveEnemies.Add(obj);
}
}
}
}
public void setPosition(Vector3 position)
{
this.position = position;
}
public Vector3 getPosition()
{
return position;
}
public bool leftTile(float playerX, float playerZ)
{
bool result = false;
if (playerX >= borderEast + 10 || playerX <= borderWest - 10 || playerZ >= borderNorth + 10 || playerZ <= borderSouth - 10)
{
changeRenderer();
result = true;
}
return result;
}
public void changeRenderer()
{
foreach (Rigidbody rigid in gameObject.GetComponentsInChildren<Rigidbody>())
{
if (!deadEnemies.Contains(rigid.gameObject))
{
rigid.useGravity = !rigid.useGravity;
}
}
foreach (Renderer rend in gameObject.GetComponentsInChildren<Renderer>())
{
if (!deadEnemies.Contains(rend.gameObject))
{
rend.enabled = !rend.enabled;
}
}
foreach (Collider col in gameObject.GetComponentsInChildren<Collider>())
{
if (!deadEnemies.Contains(col.gameObject))
{
col.enabled = !col.enabled;
}
}
}
public void resetSpawn()
{
foreach (Rigidbody rigid in gameObject.GetComponentsInChildren<Rigidbody>())
{
rigid.useGravity = true;
}
foreach (Renderer rend in gameObject.GetComponentsInChildren<Renderer>())
{
rend.enabled = true;
}
foreach (Collider col in gameObject.GetComponentsInChildren<Collider>())
{
col.enabled = true;
}
}
public bool enteredTile(float playerX, float playerZ)
{
bool result = false;
if (playerX <= borderEast && playerX >= borderWest && playerZ <= borderNorth && playerZ >= borderSouth)
{
result = true;
}
return result;
}
public Vector3 needConnectedTile(float playerX, float playerZ)
{
Vector3 result = new Vector3(position.x, 1, position.z);
if (playerX >= borderEast - 10)
{
result.x = result.x + 1;
result.y = 0;
}
else if(playerX <= borderWest + 10)
{
result.x = result.x - 1;
result.y = 0;
}
if (playerZ >= borderNorth - 10)
{
result.z = result.z + 1;
result.y = 0;
}
else if(playerZ <= borderSouth + 10)
{
result.z = result.z - 1;
result.y = 0;
}
return result;
}
public bool removeConnectedTiles(float playerX, float playerZ)
{
bool result = false;
if (playerX <= borderEast - 10 && playerX >= borderWest + 10 && playerZ <= borderNorth - 10 && playerZ >= borderSouth + 10)
{
result = true;
}
return result;
}
public void enemyKilled(GameObject enemy)
{
deadEnemies.Add(enemy);
enemy.GetComponent<Rigidbody>().useGravity = false;
enemy.GetComponent<Renderer>().enabled = false;
enemy.GetComponent<Collider>().enabled = false;
aliveEnemies.Remove(enemy);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c137a267f9c5b424ba76ed1d54cde205
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

555
Assets/Scripts/UIHandler.cs Normal file
View File

@@ -0,0 +1,555 @@
using Assets.Scripts.Classes;
using Assets.Scripts.Races;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace Assets.Scripts
{
public class UIHandler : MonoBehaviour
{
public GameObject map;
public GameObject compass;
public GameObject information;
public GameObject fight;
public GameObject message;
public GameObject charactersheet;
public GameObject deathscreen;
public GameObject mainMenu;
public GameObject options;
public GameObject characterCreation;
public GameObject pauseMenu;
public GameObject playerHUD;
public GameObject questlog;
public GameObject tutorial;
public UIState state;
// Start is called before the first frame update
void Start()
{
options.SetActive(false);
hideOtherElements(mainMenu);
state = UIState.MAINMENU;
}
// Update is called once per frame
void Update()
{
if (state == UIState.GAME)
{
updatePlayerHUD();
Cursor.visible = false;
}
else
{
if (state != UIState.FIGHT && state != UIState.MAP && state != UIState.QUEST)
{
Cursor.visible = true;
}
}
}
private void updatePlayerHUD()
{
updateHUD(GameObject.Find("Player").GetComponent<Player>());
}
public bool canPlayerMove()
{
if (state == UIState.GAME || state == UIState.MAP || state == UIState.CHARACTER || state == UIState.QUEST)
{
return true;
}
return false;
}
public bool isPlayerInFight()
{
return state == UIState.FIGHT;
}
public void startGame()
{
int index = GameObject.Find("dropSize").GetComponent<Dropdown>().value;
int cityAmount = 0;
switch (index)
{
case 0:
cityAmount = 5;
break;
case 1:
cityAmount = 10;
break;
case 2:
cityAmount = 20;
break;
case 3:
cityAmount = 40;
break;
}
GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().resetGame(cityAmount);
setPlayerInformation();
tutorial.transform.localScale = new Vector3(0,0,0);
compass.transform.localScale = new Vector3(1, 1, 1);
showHUD();
state = UIState.GAME;
EventSystem.current.SetSelectedGameObject(null);
}
private void setPlayerInformation()
{
string name = GameObject.Find("inName").GetComponent<InputField>().text;
int role = GameObject.Find("dropClass").GetComponent<Dropdown>().value;
int race = GameObject.Find("dropRace").GetComponent<Dropdown>().value;
BasicRace playerRace = new BasicRace();
BasicClass playerClass = new BasicClass();
switch (role)
{
case 0:
playerClass = new WarriorClass();
break;
case 1:
playerClass = new MageClass();
break;
case 2:
playerClass = new ThiefClass();
break;
}
switch (race)
{
case 0:
playerRace = new HumanRace();
break;
case 1:
playerRace = new ElvenRace();
break;
case 2:
playerRace = new DwarvenRace();
break;
case 3:
playerRace = new GoblinRace();
break;
case 4:
playerRace = new GiantRace();
break;
}
GameObject.Find("Player").GetComponent<Player>().generatePlayer(playerRace, playerClass, name, GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
}
public void switchMap()
{
if (state == UIState.MAP)
{
closeMap();
}
else
{
openMap();
}
}
public void switchCharactersheet()
{
if (state == UIState.CHARACTER)
{
closeCharactersheet();
}
else
{
openCharactersheet();
}
}
public void openCharacterCreation()
{
mainMenu.transform.localScale = new Vector3(0, 0, 0);
characterCreation.transform.localScale = new Vector3(1, 1, 1);
state = UIState.CHARACTERCREATION;
}
public void closeCharacterCreation()
{
characterCreation.transform.localScale = new Vector3(0, 0, 0);
state = UIState.MAINMENU;
openMainMenu();
}
public void openOptions()
{
options.SetActive(true);
hideOtherElements(options);
if (state == UIState.MAINMENU)
{
state = UIState.OPTIONS;
}
else
{
state = UIState.PAUSEOPTIONS;
}
GameObject.Find("ScrollbarOptions").GetComponent<Scrollbar>().value = 1f;
}
public void closeOptions()
{
options.SetActive(false);
if (state == UIState.PAUSEOPTIONS)
{
state = UIState.PAUSE;
openPauseMenu();
}
else
{
state = UIState.MAINMENU;
openMainMenu();
}
}
public void openCharactersheet()
{
hideOtherElements(charactersheet);
state = UIState.CHARACTER;
}
public void closeCharactersheet()
{
charactersheet.transform.localScale = new Vector3(0, 0, 0);
state = UIState.GAME;
}
public void openMap()
{
hideOtherElements(map);
map.transform.localScale = new Vector3(1, 1, 1);
state = UIState.MAP;
}
public void closeMap()
{
map.transform.localScale = new Vector3(0, 0, 0);
state = UIState.GAME;
}
public void openFight()
{
GameObject.Find("txtRounds").GetComponent<Text>().text = "-1";
hideOtherElements(fight);
state = UIState.FIGHT;
}
public void closeFight()
{
fight.transform.localScale = new Vector3(0, 0, 0);
showHUD();
state = UIState.GAME;
}
public void showHUD()
{
playerHUD.transform.localScale = new Vector3(1,1,1);
}
public void openMainMenu()
{
hideOtherElements(mainMenu);
state = UIState.MAINMENU;
}
public void switchPauseMenu()
{
if (state == UIState.GAME || state == UIState.CHARACTER || state == UIState.MAP || state == UIState.PAUSE || state == UIState.QUEST)
{
if (state == UIState.PAUSE)
{
closePauseMenu();
}
else
{
openPauseMenu();
}
}
}
public void switchQuestLog()
{
if (state == UIState.QUEST)
{
closeQuestLog();
}
else
{
openQuestLog();
}
}
public void openQuestLog()
{
state = UIState.QUEST;
hideOtherElements(questlog);
GameObject.Find("Player").GetComponent<Player>().updateKillcount(GameObject.Find("txtSlimesKilled"));
GameObject.Find("WorldGenerator").GetComponent<WorldGenerator>().updateCityCount(GameObject.Find("txtCitiesFound"));
}
public void closeQuestLog()
{
questlog.transform.localScale = new Vector3(0,0,0);
compass.transform.localScale = new Vector3(1, 1, 1);
state = UIState.GAME;
showHUD();
}
public void adaptScreen()
{
GameObject resolution = GameObject.Find("dropResolution");
GameObject mode = GameObject.Find("dropMode");
switch (resolution.GetComponent<Dropdown>().value)
{
case 0:
Screen.SetResolution(800,600, Screen.fullScreenMode);
break;
case 1:
Screen.SetResolution(1280, 800, Screen.fullScreenMode);
break;
case 2:
Screen.SetResolution(1920,1080, Screen.fullScreenMode);
break;
}
switch (mode.GetComponent<Dropdown>().value)
{
case 0:
if (Screen.fullScreenMode != FullScreenMode.Windowed)
{
Screen.fullScreenMode = FullScreenMode.Windowed;
}
break;
case 1:
if (Screen.fullScreenMode != FullScreenMode.ExclusiveFullScreen)
{
Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
}
break;
case 2:
if (Screen.fullScreenMode != FullScreenMode.FullScreenWindow)
{
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
}
break;
}
}
public void openPauseMenu()
{
hideOtherElements(pauseMenu);
state = UIState.PAUSE;
}
public void closePauseMenu()
{
pauseMenu.transform.localScale = new Vector3(0, 0, 0);
compass.transform.localScale = new Vector3(1,1,1);
playerHUD.transform.localScale = new Vector3(1, 1, 1);
state = UIState.GAME;
}
public void showDeathScreen()
{
state = UIState.DEATH;
hideOtherElements(deathscreen);
}
public void hideOtherElements(GameObject obj)
{
for (int i = 0; i < GameObject.Find("Canvas").transform.childCount; i++)
{
if (!GameObject.Find("Canvas").transform.GetChild(i).gameObject.Equals(obj))
{
GameObject.Find("Canvas").transform.GetChild(i).localScale = new Vector3(0, 0, 0);
}
}
obj.transform.localScale = new Vector3(1, 1, 1);
}
public void displayInformation(string information)
{
GameObject.Find("txtObjectName").GetComponent<Text>().text = information;
this.information.transform.localScale = new Vector3(1, 1, 1);
}
public void hideInformation()
{
information.transform.localScale = new Vector3(0, 0, 0);
}
public void showMessage(string message)
{
this.message.GetComponent<LogWriter>().addMessage(message);
}
public void updateFightInterface(GameObject enemy, GameObject player)
{
updateFightInterfacePlayer(player);
updateFightInterfaceEnemy(enemy);
updateFightInterfaceActions(player);
GameObject.Find("txtRounds").GetComponent<Text>().text = (int.Parse(GameObject.Find("txtRounds").GetComponent<Text>().text) + 1).ToString();
}
private void updateFightInterfaceActions(GameObject player)
{
GameObject actionFour = GameObject.Find("action4");
GameObject actionFive = GameObject.Find("action5");
GameObject actionSix = GameObject.Find("action6");
player.GetComponent<Player>().displaySkill(0, actionFour.transform.Find("imgAction").gameObject, actionFour.transform.Find("descAction").gameObject);
player.GetComponent<Player>().displaySkill(1, actionFive.transform.Find("imgAction").gameObject, actionFive.transform.Find("descAction").gameObject);
player.GetComponent<Player>().displaySkill(2, actionSix.transform.Find("imgAction").gameObject, actionSix.transform.Find("descAction").gameObject);
}
private void updateFightInterfacePlayer(GameObject player)
{
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
int[] playerStats = player.GetComponent<Player>().getStats();
GameObject foreground = GameObject.Find("healthForegroundPlayer");
GameObject background = GameObject.Find("healthBackgroundPlayer");
GameObject text = GameObject.Find("healthTextPlayer");
updateBar(foreground, background, text, playerStats[1], playerStats[0]);
foreground = GameObject.Find("secondaryForegroundPlayer");
background = GameObject.Find("secondaryBackgroundPlayer");
text = GameObject.Find("secondaryTextPlayer");
updateBar(foreground, background, text, playerStats[3], playerStats[2]);
}
private void updateFightInterfaceEnemy(GameObject enemy)
{
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence };
int[] enemyStats = enemy.GetComponent<Enemy>().getStats();
GameObject foreground = GameObject.Find("healthForegroundEnemy");
GameObject background = GameObject.Find("healthBackgroundEnemy");
GameObject text = GameObject.Find("healthTextEnemy");
updateBar(foreground, background, text, enemyStats[1], enemyStats[0]);
foreground = GameObject.Find("secondaryForegroundEnemy");
background = GameObject.Find("secondaryBackgroundEnemy");
text = GameObject.Find("secondaryTextEnemy");
updateBar(foreground, background, text, enemyStats[3], enemyStats[2]);
}
public void adjustInformation(Player player)
{
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points};
int[] playerStats = player.GetComponent<Player>().getStats();
GameObject.Find("txtStrength").GetComponent<Text>().text = "STR: " + playerStats[4];
GameObject.Find("txtDexterity").GetComponent<Text>().text = "DEX: " + playerStats[5];
GameObject.Find("txtIntelligence").GetComponent<Text>().text = "INT: " + playerStats[6];
GameObject.Find("txtHealth").GetComponent<Text>().text = "Health: " + playerStats[1];
GameObject.Find("txtSecondary").GetComponent<Text>().text = "Secondary: " + playerStats[3];
updateHealthUI(playerStats[0], playerStats[1]);
updateSecondaryUI(playerStats[2], playerStats[3]);
updateExperienceUI(playerStats[8], playerStats[9]);
player.updateName(GameObject.Find("txtName").GetComponent<Text>());
updatePoints(playerStats[10]);
}
private void updatePoints(int points)
{
GameObject strength = GameObject.Find("btnStrengthIncrease");
GameObject dexterity = GameObject.Find("btnDexterityIncrease");
GameObject intelligence = GameObject.Find("btnIntelligenceIncrease");
GameObject health = GameObject.Find("btnHealthIncrease");
GameObject secondary = GameObject.Find("btnSecondaryIncrease");
GameObject txtPoints = GameObject.Find("txtPoints");
txtPoints.GetComponent<Text>().text = "Your available points: " + points;
if (points > 0)
{
strength.transform.localScale = new Vector3(1, 1, 1);
dexterity.transform.localScale = new Vector3(1, 1, 1);
intelligence.transform.localScale = new Vector3(1, 1, 1);
health.transform.localScale = new Vector3(1, 1, 1);
secondary.transform.localScale = new Vector3(1, 1, 1);
}
else
{
strength.transform.localScale = new Vector3(0, 0, 0);
dexterity.transform.localScale = new Vector3(0, 0, 0);
intelligence.transform.localScale = new Vector3(0, 0, 0);
health.transform.localScale = new Vector3(0, 0, 0);
secondary.transform.localScale = new Vector3(0, 0, 0);
}
}
private void updateHealthUI(int health, int maxHealth)
{
GameObject foreground = GameObject.Find("healthForegroundInformation");
GameObject background = GameObject.Find("healthBackgroundInformation");
GameObject text = GameObject.Find("healthTextInformation");
updateBar(foreground, background, text, maxHealth, health);
}
private void updateSecondaryUI(int secondary, int maxSecondary)
{
GameObject foreground = GameObject.Find("secondaryForegroundInformation");
GameObject background = GameObject.Find("secondaryBackgroundInformation");
GameObject text = GameObject.Find("secondaryTextInformation");
updateBar(foreground, background, text, maxSecondary, secondary);
}
private void updateExperienceUI(int experience, int maxExperience)
{
GameObject foreground = GameObject.Find("experienceForeground");
GameObject background = GameObject.Find("experienceBackground");
GameObject text = GameObject.Find("experienceText");
updateBar(foreground, background, text, maxExperience, experience);
}
public void updateHUD(Player player)
{
// { health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience};
int[] playerStats = player.GetComponent<Player>().getStats();
GameObject information = GameObject.Find("txtInformationHUD");
player.updateNameHUD(information.GetComponent<Text>());
GameObject foreground = GameObject.Find("healthForegroundHUD");
GameObject background = GameObject.Find("healthBackgroundHUD");
updateBar(foreground, background, null, playerStats[1], playerStats[0]);
foreground = GameObject.Find("secondaryForegroundHUD");
background = GameObject.Find("secondaryBackgroundHUD");
updateBar(foreground, background, null, playerStats[3], playerStats[2]);
}
public void updateBar(GameObject bar, GameObject barBackground, GameObject textField, int maxValue, int minValue)
{
string text = minValue + "/" + maxValue;
double percentage = (1 / (double)maxValue) * minValue;
float change = (float)(barBackground.GetComponent<RectTransform>().rect.width - (barBackground.GetComponent<RectTransform>().rect.width * percentage));
if (textField != null)
{
textField.GetComponent<Text>().text = text;
}
bar.GetComponent<RectTransform>().offsetMax = new Vector2(-change, bar.GetComponent<RectTransform>().offsetMax.y);
}
public void openTutorial()
{
hideOtherElements(tutorial);
state = UIState.TUTORIAL;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d858d7fd66f78a44e9e67ec2a2d4f1e1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

24
Assets/Scripts/UIState.cs Normal file
View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Assets.Scripts
{
public enum UIState
{
MAINMENU,
FIGHT,
CHARACTERCREATION,
CHARACTER,
MAP,
DEATH,
OPTIONS,
GAME,
PAUSE,
PAUSEOPTIONS,
TUTORIAL,
QUEST
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fb49b5f108ff1be47a72625b1cee7ca6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,217 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class WorldGenerator : MonoBehaviour
{
public GameObject player;
public GameObject[] prefabs;
Dictionary<Vector3, GameObject> tiles;
GameObject currentTile;
List<GameObject> renderedTiles;
List<GameObject> toRemove;
NoiseGenerator noise;
int cityAmount = 0;
int maxCityAmount = 0;
System.Random rand = new System.Random();
// Start is called before the first frame update
void Start()
{
tiles = new Dictionary<Vector3, GameObject>();
tiles.Add(new Vector3(0,0,0), GameObject.Find("Spawn"));
renderedTiles = new List<GameObject>();
currentTile = GameObject.Find("Spawn");
currentTile.GetComponent<Tile>().setPosition(new Vector3(0, 0, 0));
currentTile.GetComponent<Tile>().setBorders();
renderedTiles.Add(currentTile);
noise = new NoiseGenerator();
cityAmount = 10;
maxCityAmount = 10;
}
public bool gameWon()
{
return cityAmount <= 0;
}
public void resetGame(int cityAmount)
{
foreach (GameObject tile in tiles.Values)
{
if (tile.name != "Spawn")
{
Destroy(tile);
}
}
player.transform.position = new Vector3(0,1.5f,0);
player.transform.rotation = Quaternion.identity;
Start();
currentTile.GetComponent<Tile>().resetSpawn();
this.cityAmount = cityAmount;
maxCityAmount = cityAmount;
}
// Update is called once per frame
void Update()
{
createTile(player.transform.position.x, player.transform.position.z);
hideTile(player.transform.position.x, player.transform.position.z);
resetPlayer();
}
public void prepareMap()
{
GameObject.Find("Map").GetComponent<Map>().prepare(tiles, currentTile);
}
void resetPlayer()
{
if (player.transform.position.y <= -5)
{
Vector3 position = new Vector3(currentTile.transform.position.x, 5, currentTile.transform.position.z);
player.transform.SetPositionAndRotation(position, player.transform.rotation);
}
}
public void createTile(float playerX, float playerZ)
{
Vector3 pos = currentTile.GetComponent<Tile>().needConnectedTile(playerX, playerZ);
if (!tiles.ContainsKey(pos) && pos.y == 0)
{
int index;
int chance = rand.Next(1,101);
while (true)
{
if (chance < 50)
{
index = 0;
}
else if (chance >= 50 && chance < 70)
{
index = 1;
}
else if (chance >= 70 && chance < 90)
{
index = 2;
}
else
{
index = 3;
}
if (index == 3)
{
if (cityAmount > 0)
{
cityAmount--;
break;
}
else
{
chance = rand.Next(1, 101);
}
}
else
{
break;
}
}
Vector3 mapPos = new Vector3(pos.x * 100, 0, pos.z * 100);
GameObject newTile = Instantiate(prefabs[index], mapPos, Quaternion.identity);
string name = prefabs[index].name;
if (name.Contains("_"))
{
name = name.Split('_')[0];
}
newTile.name = name + "_" + tiles.Count;
newTile.GetComponent<Tile>().generateTile(pos, name);
applyNoise(newTile, name.Split('_')[0]);
tiles.Add(pos, newTile);
renderedTiles.Add(newTile);
}
else
{
if (tiles.ContainsKey(pos) && pos.y == 0)
{
if (!tiles[pos].GetComponent<Renderer>().enabled)
{
tiles[pos].GetComponent<Tile>().changeRenderer();
renderedTiles.Add(tiles[pos]);
}
}
}
}
private void applyNoise(GameObject tile, string type)
{
switch (type.ToLower())
{
case "tile":
noise.applyTileNoise(tile);
break;
case "stonetile":
noise.applyStoneTileNoise(tile);
break;
case "treetile":
noise.applyTreeTileNoise(tile);
break;
case "citytile":
noise.applyCityTileNoise(tile);
break;
}
}
public void hideTile(float playerX, float playerZ)
{
if (currentTile.GetComponent<Tile>().leftTile(playerX, playerZ))
{
renderedTiles.Remove(currentTile);
foreach (GameObject tile in renderedTiles)
{
if (tile.GetComponent<Tile>().enteredTile(playerX, playerZ))
{
currentTile = tile;
break;
}
}
updateRenderedTiles();
}
if (currentTile.GetComponent<Tile>().removeConnectedTiles(playerX, playerZ))
{
updateRenderedTiles();
}
}
private void updateRenderedTiles()
{
toRemove = new List<GameObject>();
foreach (GameObject tile in renderedTiles)
{
if (!tile.Equals(currentTile))
{
tile.GetComponent<Tile>().changeRenderer();
toRemove.Add(tile);
}
}
foreach (GameObject tile in toRemove)
{
renderedTiles.Remove(tile);
}
}
public GameObject getCurrentTile()
{
return currentTile;
}
public void updateCityCount(GameObject gameObject)
{
gameObject.GetComponent<Text>().text = "Cities: " + (maxCityAmount - cityAmount) + "/" + maxCityAmount;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 170fdf07749d6ae4dbb6173de2af77e2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: