1
Fork 0

boh forse scale

This commit is contained in:
Steffo 2019-04-29 15:27:26 +02:00
parent 897df5f308
commit 6832e20527
15 changed files with 57 additions and 358 deletions

View file

@ -39,6 +39,10 @@ public class Entity : MonoBehaviour
hp = hpMax; hp = hpMax;
} }
public virtual void OnNewLevel() {
Destroy(gameObject);
}
public virtual void Die() { public virtual void Die() {
Debug.LogWarning("Die not overridden"); Debug.LogWarning("Die not overridden");
Destroy(gameObject); Destroy(gameObject);

View file

@ -6,21 +6,14 @@ public class EntityItemShop : EntityItem {
public float hpChange = -1f; public float hpChange = -1f;
public float maxHpChange = -1f; public float maxHpChange = -1f;
protected EntityPlayer player; protected virtual void OnPurchase(EntityPlayer player) {
protected override void Start() {
base.Start();
player = GameObject.FindGameObjectWithTag("Player").GetComponent<EntityPlayer>();
}
protected virtual void OnPurchase() {
Debug.LogWarning("OnPurchase not overridden"); Debug.LogWarning("OnPurchase not overridden");
} }
public override void OnPickup(EntityPlayer player) { public override void OnPickup(EntityPlayer player) {
player.hp += hpChange; player.hp += hpChange;
player.hpMax += maxHpChange; player.hpMax += maxHpChange;
OnPurchase(); OnPurchase(player);
messageBar.Write("Bought: " + Name, Color.yellow); messageBar.Write("Bought: " + Name, Color.yellow);
Destroy(gameObject); Destroy(gameObject);
} }

View file

@ -12,7 +12,7 @@ public class EntityItemShopSword : EntityItemShop {
} }
} }
protected override void OnPurchase() { protected override void OnPurchase(EntityPlayer player) {
Destroy(player.GetComponent<PlayerAttack>()); Destroy(player.GetComponent<PlayerAttack>());
player.gameObject.AddComponent<PlayerAttackMelee>(); player.gameObject.AddComponent<PlayerAttackMelee>();
PlayerAttackMelee pam = player.GetComponent<PlayerAttackMelee>(); PlayerAttackMelee pam = player.GetComponent<PlayerAttackMelee>();

View file

@ -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();
}
}

View file

@ -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<EntityPlayer>();
}
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);
}
}

View file

@ -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<EntityPlayer>();
}
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);
}
}

View file

@ -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<EntityPlayer>();
}
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);
}
}

View file

@ -12,6 +12,7 @@ public class EntityMonsterSlime : EntityMonster
public float moveChance = 0.5f; public float moveChance = 0.5f;
public float visionRange = 4f; public float visionRange = 4f;
public float attackRange = 1f;
public float damage = 1f; public float damage = 1f;
public GameObject attackAnimation; public GameObject attackAnimation;
protected EntityPlayer player; protected EntityPlayer player;
@ -25,7 +26,13 @@ public class EntityMonsterSlime : EntityMonster
if(Random.Range(0f, 1f) < moveChance) return; if(Random.Range(0f, 1f) < moveChance) return;
if (CanSeePlayer()){ if (CanSeePlayer()){
Vector2Int distance = player.MapPosition - MapPosition; 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); transform.Translate(Vector3.left);
} }
else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){ else if (distance.x > 0 && map.CanMoveTo(MapPosition + Vector2Int.right)){
@ -39,7 +46,6 @@ public class EntityMonsterSlime : EntityMonster
} }
} }
else { else {
if(Vector3.Distance(player.transform.position, transform.position) > 2){
int direction = Random.Range(0, 4); int direction = Random.Range(0, 4);
if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){ if (direction == 0 && map.CanMoveTo(MapPosition + Vector2Int.left)){
transform.Translate(Vector3.left); transform.Translate(Vector3.left);
@ -54,11 +60,6 @@ public class EntityMonsterSlime : EntityMonster
transform.Translate(Vector3.down); transform.Translate(Vector3.down);
} }
} }
else{
float damage_done = Random.value * damage;
player.hp -= damage;
}
}
} }
public bool CanSeePlayer(){ public bool CanSeePlayer(){

View file

@ -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<EntityPlayer>();
}
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);
}
}

View file

@ -110,4 +110,6 @@ public class EntityPlayer : Entity
turnHandler.OnTurn(); turnHandler.OnTurn();
} }
} }
public override void OnNewLevel() {};
} }

View file

@ -287,8 +287,9 @@ public class Map : MonoBehaviour
} }
} }
private void Start() public void NewLevel() {
{ //Cleanup everything.
transform.parent.BroadcastMessage("OnNewLevel");
//Initialize everything //Initialize everything
tiles = new GameObject[mapSize, mapSize]; tiles = new GameObject[mapSize, mapSize];
rooms = new List<MapRoom>(); rooms = new List<MapRoom>();
@ -299,4 +300,9 @@ public class Map : MonoBehaviour
PlacePlayer(); PlacePlayer();
PlaceEnemies(); PlaceEnemies();
} }
private void Start()
{
NewLevel();
}
} }

View file

@ -15,4 +15,8 @@ public class MapTile : MonoBehaviour
spriteRenderer = GetComponent<SpriteRenderer>(); spriteRenderer = GetComponent<SpriteRenderer>();
spriteRenderer.sprite = sprite; spriteRenderer.sprite = sprite;
} }
public void OnNewLevel() {
Destroy(gameObject);
}
} }

View file

@ -1,7 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NextLevel : MonoBehaviour {
//TODO
}

View file

@ -1,3 +0,0 @@
import requests
r = requests.post("http://127.0.0.1:5000/message/2", data={'content':'Piano 2'})
print(r.text)

View file

@ -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/<int:floor>", 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)