diff --git a/Assets/Scripts/Entity.cs b/Assets/Scripts/Entity.cs index cae8daa..87d558f 100644 --- a/Assets/Scripts/Entity.cs +++ b/Assets/Scripts/Entity.cs @@ -39,6 +39,10 @@ public class Entity : MonoBehaviour hp = hpMax; } + public virtual void OnNewLevel() { + Destroy(gameObject); + } + public virtual void Die() { Debug.LogWarning("Die not overridden"); Destroy(gameObject); diff --git a/Assets/Scripts/EntityItemShop.cs b/Assets/Scripts/EntityItemShop.cs index 424d42e..7b2ab25 100644 --- a/Assets/Scripts/EntityItemShop.cs +++ b/Assets/Scripts/EntityItemShop.cs @@ -6,21 +6,14 @@ public class EntityItemShop : EntityItem { public float hpChange = -1f; public float maxHpChange = -1f; - protected EntityPlayer player; - - protected override void Start() { - base.Start(); - player = GameObject.FindGameObjectWithTag("Player").GetComponent(); - } - - protected virtual void OnPurchase() { + protected virtual void OnPurchase(EntityPlayer player) { Debug.LogWarning("OnPurchase not overridden"); } public override void OnPickup(EntityPlayer player) { player.hp += hpChange; player.hpMax += maxHpChange; - OnPurchase(); + OnPurchase(player); messageBar.Write("Bought: " + Name, Color.yellow); Destroy(gameObject); } diff --git a/Assets/Scripts/EntityItemShopSword.cs b/Assets/Scripts/EntityItemShopSword.cs index 384528d..1219486 100644 --- a/Assets/Scripts/EntityItemShopSword.cs +++ b/Assets/Scripts/EntityItemShopSword.cs @@ -12,7 +12,7 @@ public class EntityItemShopSword : EntityItemShop { } } - protected override void OnPurchase() { + protected override void OnPurchase(EntityPlayer player) { Destroy(player.GetComponent()); player.gameObject.AddComponent(); PlayerAttackMelee pam = player.GetComponent(); diff --git a/Assets/Scripts/EntityItemStairs.cs b/Assets/Scripts/EntityItemStairs.cs new file mode 100644 index 0000000..09dea9e --- /dev/null +++ b/Assets/Scripts/EntityItemStairs.cs @@ -0,0 +1,17 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class EntityItemStairs : EntityItem +{ + public override string Name { + get { + return "Stairs"; + } + } + + public override void OnPickup(EntityPlayer player) { + messageBar.Write("Generating next floor...", Color.magenta); + map.NewLevel(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/EntityMonsterMage.cs b/Assets/Scripts/EntityMonsterMage.cs deleted file mode 100644 index 72a8209..0000000 --- a/Assets/Scripts/EntityMonsterMage.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EntityMonsterMage : EntityMonster -{ - public override string Name { - get { - return "Mage"; - } - } - - public float moveChance = 0.5f; - public float visionRange = 7f; - public GameObject attackAnimation; - protected EntityPlayer player; - - protected new void Start() { - base.Start(); - player = GameObject.FindGameObjectWithTag("Player").GetComponent(); - } - - public override void OnTurn(){ - if(Random.Range(0f, 1f) < moveChance) return; - if (CanSeePlayer()){ - Vector2Int distance = player.MapPosition - MapPosition; - if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (distance.y > 0 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (distance.y < 0 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } - } - else { - int direction = Random.Range(0, 4); - if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } - } - } - - public bool CanSeePlayer(){ - return Vector3.Distance(player.transform.position, transform.position) < visionRange; - } - - private void OnDrawGizmosSelected() { - Gizmos.color = Color.cyan; - Gizmos.DrawWireSphere(transform.position, visionRange); - } -} \ No newline at end of file diff --git a/Assets/Scripts/EntityMonsterSkeletonArcher.cs b/Assets/Scripts/EntityMonsterSkeletonArcher.cs deleted file mode 100644 index a165085..0000000 --- a/Assets/Scripts/EntityMonsterSkeletonArcher.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EntityMonsterSkeletonArcher : EntityMonster -{ - public override string Name { - get { - return "Skeleton Archer"; - } - } - - public float moveChance = 0f; - public float visionRange = 5f; - public GameObject attackAnimation; - protected EntityPlayer player; - - protected new void Start() { - base.Start(); - player = GameObject.FindGameObjectWithTag("Player").GetComponent(); - } - - public override void OnTurn(){ - if(Random.Range(0f, 1f) < moveChance) return; - if (CanSeePlayer()){ - Vector2Int distance = player.MapPosition - MapPosition; - if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (distance.y > 0 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (distance.y < 0 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } - } - else { - int direction = Random.Range(0, 4); - if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } - } - } - - public bool CanSeePlayer(){ - return Vector3.Distance(player.transform.position, transform.position) < visionRange; - } - - private void OnDrawGizmosSelected() { - Gizmos.color = Color.cyan; - Gizmos.DrawWireSphere(transform.position, visionRange); - } -} \ No newline at end of file diff --git a/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs b/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs deleted file mode 100644 index 078da7e..0000000 --- a/Assets/Scripts/EntityMonsterSkeletonSwordsman.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EntityMonsterSkeletonSwordsman : EntityMonster -{ - public override string Name { - get { - return "Skeleton Swordsman"; - } - } - - public float moveChance = 0f; - public float visionRange = 4f; - public GameObject attackAnimation; - protected EntityPlayer player; - - protected new void Start() { - base.Start(); - player = GameObject.FindGameObjectWithTag("Player").GetComponent(); - } - - public override void OnTurn(){ - if(Random.Range(0f, 1f) < moveChance) return; - if (CanSeePlayer()){ - Vector2Int distance = player.MapPosition - MapPosition; - if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (distance.y > 0 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (distance.y < 0 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } - } - else { - int direction = Random.Range(0, 4); - if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } - } - } - - public bool CanSeePlayer(){ - return Vector3.Distance(player.transform.position, transform.position) < visionRange; - } - - private void OnDrawGizmosSelected() { - Gizmos.color = Color.cyan; - Gizmos.DrawWireSphere(transform.position, visionRange); - } -} \ No newline at end of file diff --git a/Assets/Scripts/EntityMonsterSlime.cs b/Assets/Scripts/EntityMonsterSlime.cs index 84a93dc..c831a0c 100644 --- a/Assets/Scripts/EntityMonsterSlime.cs +++ b/Assets/Scripts/EntityMonsterSlime.cs @@ -12,6 +12,7 @@ public class EntityMonsterSlime : EntityMonster public float moveChance = 0.5f; public float visionRange = 4f; + public float attackRange = 1f; public float damage = 1f; public GameObject attackAnimation; protected EntityPlayer player; @@ -25,7 +26,13 @@ public class EntityMonsterSlime : EntityMonster if(Random.Range(0f, 1f) < moveChance) return; if (CanSeePlayer()){ Vector2Int distance = player.MapPosition - MapPosition; - if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ + if(distance.magnitude <= attackRange) { + float actualDamage = Random.value * damage; + player.hp -= actualDamage; + Instantiate(attackAnimation, player.transform); + messageBar.Write("Took damage from a slime.", Color.red); + } + else if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ transform.Translate(Vector3.left); } else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){ @@ -39,24 +46,18 @@ public class EntityMonsterSlime : EntityMonster } } else { - if(Vector3.Distance(player.transform.position, transform.position) > 2){ - int direction = Random.Range(0, 4); - if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } + int direction = Random.Range(0, 4); + if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ + transform.Translate(Vector3.left); } - else{ - float damage_done = Random.value * damage; - player.hp -= damage; + else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ + transform.Translate(Vector3.right); + } + else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ + transform.Translate(Vector3.up); + } + else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ + transform.Translate(Vector3.down); } } } diff --git a/Assets/Scripts/EntityMonsterWatcher.cs b/Assets/Scripts/EntityMonsterWatcher.cs deleted file mode 100644 index 6e2d4ca..0000000 --- a/Assets/Scripts/EntityMonsterWatcher.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class EntityMonsterWatcher : EntityMonster -{ - public override string Name { - get { - return "Watcher"; - } - } - - public float moveChance = 0f; - public float visionRange = 12f; - public GameObject attackAnimation; - protected EntityPlayer player; - - protected new void Start() { - base.Start(); - player = GameObject.FindGameObjectWithTag("Player").GetComponent(); - } - - public override void OnTurn(){ - if(Random.Range(0f, 1f) < moveChance) return; - if (CanSeePlayer()){ - Vector2Int distance = player.MapPosition - MapPosition; - if (distance.x < 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (distance.y > 0 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (distance.y < 0 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } - } - else { - int direction = Random.Range(0, 4); - if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ - transform.Translate(Vector3.left); - } - else if (direction == 1 && map.CanMoveTo(MapPosition + Vector2Int.right)){ - transform.Translate(Vector3.right); - } - else if (direction == 2 && map.CanMoveTo(MapPosition + Vector2Int.up)){ - transform.Translate(Vector3.up); - } - else if (direction == 3 && map.CanMoveTo(MapPosition + Vector2Int.down)){ - transform.Translate(Vector3.down); - } - } - } - - public bool CanSeePlayer(){ - return Vector3.Distance(player.transform.position, transform.position) < visionRange; - } - - private void OnDrawGizmosSelected() { - Gizmos.color = Color.cyan; - Gizmos.DrawWireSphere(transform.position, visionRange); - } -} \ No newline at end of file diff --git a/Assets/Scripts/EntityPlayer.cs b/Assets/Scripts/EntityPlayer.cs index 89b9f76..27ef73d 100644 --- a/Assets/Scripts/EntityPlayer.cs +++ b/Assets/Scripts/EntityPlayer.cs @@ -110,4 +110,6 @@ public class EntityPlayer : Entity turnHandler.OnTurn(); } } + + public override void OnNewLevel() {}; } diff --git a/Assets/Scripts/Map.cs b/Assets/Scripts/Map.cs index 9775f3a..328ff94 100644 --- a/Assets/Scripts/Map.cs +++ b/Assets/Scripts/Map.cs @@ -287,8 +287,9 @@ public class Map : MonoBehaviour } } - private void Start() - { + public void NewLevel() { + //Cleanup everything. + transform.parent.BroadcastMessage("OnNewLevel"); //Initialize everything tiles = new GameObject[mapSize, mapSize]; rooms = new List(); @@ -299,4 +300,9 @@ public class Map : MonoBehaviour PlacePlayer(); PlaceEnemies(); } + + private void Start() + { + NewLevel(); + } } diff --git a/Assets/Scripts/MapTile.cs b/Assets/Scripts/MapTile.cs index 847627a..a0a1465 100644 --- a/Assets/Scripts/MapTile.cs +++ b/Assets/Scripts/MapTile.cs @@ -15,4 +15,8 @@ public class MapTile : MonoBehaviour spriteRenderer = GetComponent(); spriteRenderer.sprite = sprite; } + + public void OnNewLevel() { + Destroy(gameObject); + } } diff --git a/Assets/Scripts/NextLevel.cs b/Assets/Scripts/NextLevel.cs deleted file mode 100644 index c72849a..0000000 --- a/Assets/Scripts/NextLevel.cs +++ /dev/null @@ -1,7 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class NextLevel : MonoBehaviour { - //TODO -} \ No newline at end of file diff --git a/Flask-Server/dummy.py b/Flask-Server/dummy.py deleted file mode 100644 index da31816..0000000 --- a/Flask-Server/dummy.py +++ /dev/null @@ -1,3 +0,0 @@ -import requests -r = requests.post("http://127.0.0.1:5000/message/2", data={'content':'Piano 2'}) -print(r.text) \ No newline at end of file diff --git a/Flask-Server/server.py b/Flask-Server/server.py deleted file mode 100644 index 287fec6..0000000 --- a/Flask-Server/server.py +++ /dev/null @@ -1,58 +0,0 @@ -from flask import Flask, session, url_for, redirect, request, render_template, abort, flash, Markup, json -from datetime import datetime -from flask_sqlalchemy import SQLAlchemy -import random -import os -from sqlalchemy.sql.expression import func - -app = Flask(__name__) -app.secret_key = "debug-attivo" -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite' -app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False -db = SQLAlchemy(app) -app.config.from_object(__name__) - - -# Database Classes go beyond this line - -class Message(db.Model): - mid = db.Column(db.Integer, primary_key=True) - floor = db.Column(db.Integer, nullable=False) - content = db.Column(db.String, nullable=False) - - def toJSON(self): - return {"Message": {'floor': self.floor, - 'content': self.content}} - - def __init__(self, content, floor): - self.content = content - self.floor = floor - - def __repr__(self): - return self.content - - -def give_json_response(floor): - messages = Message.query.filter_by(floor=floor).order_by(func.random()).limit(5).all() - return json.dumps([message.toJSON() for message in messages]) - - -# Website pages and API functions go beyond this line -@app.route("/message/", methods=["GET", "POST"]) -def page_message(floor): - if request.method == "GET": - return give_json_response(floor) - newmessage = Message(request.form['content'], floor) - db.session.add(newmessage) - db.session.commit() - return "Success." - - -if __name__ == "__main__": - # Se non esiste il database viene creato - if not os.path.isfile("db.sqlite"): - newmessage = Message("Welcome to the dungeon, mortal.", 1) - db.create_all() - db.session.add(newmessage) - db.session.commit() - app.run(debug=True)