1
0
Fork 0

Beautify | Cleanup

This commit is contained in:
Unknown 2018-04-22 16:20:25 +02:00
parent 308dcc8281
commit 95c9f7aa1d
5 changed files with 28 additions and 28 deletions

View file

@ -64,7 +64,7 @@
/// Gets the current HP. /// Gets the current HP.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public int getHealth() { public int GetHealth() {
return currentHP; return currentHP;
} }
@ -72,7 +72,7 @@
/// Gets the maximum HP. /// Gets the maximum HP.
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public int getMaxHealth() { public int GetMaxHealth() {
return maxHP; return maxHP;
} }
} }

View file

@ -12,7 +12,7 @@ public class DungeonGenerator {
public HashSet<GenRoom> rooms; public HashSet<GenRoom> rooms;
public GenRoom path; public GenRoom path;
public void generate() { public void Generate() {
int minRoomSize = 50; int minRoomSize = 50;
rooms = new HashSet<GenRoom>(); rooms = new HashSet<GenRoom>();
for ( int i = 0; i < 7 + ( int ) ( UnityEngine.Random.value * 4 ); i++ ) { for ( int i = 0; i < 7 + ( int ) ( UnityEngine.Random.value * 4 ); i++ ) {
@ -104,11 +104,11 @@ public class DungeonGenerator {
float diff4 = ed.r2.r.bounds.x - ed.r1.r.bounds.x - ed.r1.r.bounds.width + TUNNEL_THICKNESS; float diff4 = ed.r2.r.bounds.x - ed.r1.r.bounds.x - ed.r1.r.bounds.width + TUNNEL_THICKNESS;
if ( diff1 < 0 && diff2 < 0 ) { if ( diff1 < 0 && diff2 < 0 ) {
addStraightHorizontal(rooms2, ed); AddStraightHorizontal(rooms2, ed);
} else if ( diff3 < 0 && diff4 < 0 ) { } else if ( diff3 < 0 && diff4 < 0 ) {
addStraightVertical(rooms2, ed); AddStraightVertical(rooms2, ed);
} else } else
addCurve(rooms2, ed); AddCurve(rooms2, ed);
} }
path = new GenRoom(); path = new GenRoom();
@ -122,7 +122,7 @@ public class DungeonGenerator {
path.tiles.Add(new Vector2Int(x2, y2), Room.TileType.WALL); path.tiles.Add(new Vector2Int(x2, y2), Room.TileType.WALL);
} }
} }
foreach ( Vector2Int v in r.allDoors() ) foreach ( Vector2Int v in r.AllDoors() )
r.tiles.Add(v, Room.TileType.DOOR); r.tiles.Add(v, Room.TileType.DOOR);
} }
foreach ( GenRoom r in rooms ) { foreach ( GenRoom r in rooms ) {
@ -134,7 +134,7 @@ public class DungeonGenerator {
for ( int y1 = r.bounds.y + 1; y1 < r.bounds.y + r.bounds.height - 1; y1++ ) { for ( int y1 = r.bounds.y + 1; y1 < r.bounds.y + r.bounds.height - 1; y1++ ) {
r.tiles.Add(new Vector2Int(x1, y1), Room.TileType.GROUND); r.tiles.Add(new Vector2Int(x1, y1), Room.TileType.GROUND);
} }
foreach ( Vector2Int v in r.allDoors() ) foreach ( Vector2Int v in r.AllDoors() )
r.tiles.Add(v, Room.TileType.DOOR); r.tiles.Add(v, Room.TileType.DOOR);
} }
rooms.Add(path); rooms.Add(path);
@ -146,9 +146,9 @@ public class DungeonGenerator {
} }
} }
public static void addStraightHorizontal(HashSet<GenRoom> rooms, GenEdge ed) { public static void AddStraightHorizontal(HashSet<GenRoom> rooms, GenEdge ed) {
GenRoom righter = ed.r1.r.getCenter().x > ed.r2.r.getCenter().x ? ed.r1.r : ed.r2.r; GenRoom righter = ed.r1.r.GetCenter().x > ed.r2.r.GetCenter().x ? ed.r1.r : ed.r2.r;
GenRoom lefter = ed.r1.r.getCenter().x > ed.r2.r.getCenter().x ? ed.r2.r : ed.r1.r; GenRoom lefter = ed.r1.r.GetCenter().x > ed.r2.r.GetCenter().x ? ed.r2.r : ed.r1.r;
GenRoom tunnel = new GenRoom(); GenRoom tunnel = new GenRoom();
int minX = Math.Min(ed.r1.r.bounds.x + ed.r1.r.bounds.width, ed.r2.r.bounds.x + ed.r2.r.bounds.width); int minX = Math.Min(ed.r1.r.bounds.x + ed.r1.r.bounds.width, ed.r2.r.bounds.x + ed.r2.r.bounds.width);
int minY = Math.Max(ed.r1.r.bounds.y, ed.r2.r.bounds.y); int minY = Math.Max(ed.r1.r.bounds.y, ed.r2.r.bounds.y);
@ -167,9 +167,9 @@ public class DungeonGenerator {
} }
} }
public static void addStraightVertical(HashSet<GenRoom> rooms, GenEdge ed) { public static void AddStraightVertical(HashSet<GenRoom> rooms, GenEdge ed) {
GenRoom higher = ed.r1.r.getCenter().y > ed.r2.r.getCenter().y ? ed.r1.r : ed.r2.r; GenRoom higher = ed.r1.r.GetCenter().y > ed.r2.r.GetCenter().y ? ed.r1.r : ed.r2.r;
GenRoom lower = ed.r1.r.getCenter().y > ed.r2.r.getCenter().y ? ed.r2.r : ed.r1.r; GenRoom lower = ed.r1.r.GetCenter().y > ed.r2.r.GetCenter().y ? ed.r2.r : ed.r1.r;
GenRoom tunnel = new GenRoom(); GenRoom tunnel = new GenRoom();
int minX = Math.Max(ed.r1.r.bounds.x, ed.r2.r.bounds.x); int minX = Math.Max(ed.r1.r.bounds.x, ed.r2.r.bounds.x);
int minY = Math.Min(ed.r1.r.bounds.y + ed.r1.r.bounds.height, ed.r2.r.bounds.y + ed.r2.r.bounds.height); int minY = Math.Min(ed.r1.r.bounds.y + ed.r1.r.bounds.height, ed.r2.r.bounds.y + ed.r2.r.bounds.height);
@ -188,13 +188,13 @@ public class DungeonGenerator {
} }
} }
public static void addCurve(HashSet<GenRoom> rooms, GenEdge ed) { public static void AddCurve(HashSet<GenRoom> rooms, GenEdge ed) {
GenRoom higher = ed.r1.r.getCenter().y > ed.r2.r.getCenter().y ? ed.r1.r : ed.r2.r; GenRoom higher = ed.r1.r.GetCenter().y > ed.r2.r.GetCenter().y ? ed.r1.r : ed.r2.r;
GenRoom lower = ed.r1.r.getCenter().y > ed.r2.r.getCenter().y ? ed.r2.r : ed.r1.r; GenRoom lower = ed.r1.r.GetCenter().y > ed.r2.r.GetCenter().y ? ed.r2.r : ed.r1.r;
GenRoom righter = ed.r1.r.getCenter().x > ed.r2.r.getCenter().x ? ed.r1.r : ed.r2.r; GenRoom righter = ed.r1.r.GetCenter().x > ed.r2.r.GetCenter().x ? ed.r1.r : ed.r2.r;
GenRoom lefter = ed.r1.r.getCenter().x > ed.r2.r.getCenter().x ? ed.r2.r : ed.r1.r; GenRoom lefter = ed.r1.r.GetCenter().x > ed.r2.r.GetCenter().x ? ed.r2.r : ed.r1.r;
RectInt r = new RectInt(lefter.getCenter().x, lower.getCenter().y, righter.getCenter().x - lefter.getCenter().x, higher.getCenter().y - lower.getCenter().y); RectInt r = new RectInt(lefter.GetCenter().x, lower.GetCenter().y, righter.GetCenter().x - lefter.GetCenter().x, higher.GetCenter().y - lower.GetCenter().y);
GenRoom verticalLefter = new GenRoom(); GenRoom verticalLefter = new GenRoom();
verticalLefter.bounds.x = r.x - TUNNEL_THICKNESS / 2; verticalLefter.bounds.x = r.x - TUNNEL_THICKNESS / 2;
@ -240,8 +240,8 @@ public class DungeonGenerator {
} }
bool flip = UnityEngine.Random.value > 0.5; bool flip = UnityEngine.Random.value > 0.5;
bool diffX = ed.r2.r.getCenter().x - ed.r1.r.getCenter().x > 0; bool diffX = ed.r2.r.GetCenter().x - ed.r1.r.GetCenter().x > 0;
bool diffY = ed.r2.r.getCenter().y - ed.r1.r.getCenter().y > 0; bool diffY = ed.r2.r.GetCenter().y - ed.r1.r.GetCenter().y > 0;
bool addHorizontal1 = false, addHorizontal2 = false, addVertical1 = false, addVertical2 = false; bool addHorizontal1 = false, addHorizontal2 = false, addVertical1 = false, addVertical2 = false;
if ( diffX && diffY ) { if ( diffX && diffY ) {
if ( flip ) { if ( flip ) {

View file

@ -8,7 +8,7 @@ public class GenEdge {
public GenEdge(GenVertex r1, GenVertex r2) { public GenEdge(GenVertex r1, GenVertex r2) {
this.r1 = r1; this.r1 = r1;
this.r2 = r2; this.r2 = r2;
dist = r1.r.distance(r2.r); dist = r1.r.Distance(r2.r);
} }
} }

View file

@ -10,15 +10,15 @@ public class GenRoom {
public HashSet<Vector2Int> doorsLeft = new HashSet<Vector2Int>(); public HashSet<Vector2Int> doorsLeft = new HashSet<Vector2Int>();
public HashSet<Vector2Int> doorsRight = new HashSet<Vector2Int>(); public HashSet<Vector2Int> doorsRight = new HashSet<Vector2Int>();
public float distance(GenRoom r) { public float Distance(GenRoom r) {
return Math.Abs(getCenter().x - r.getCenter().x) + Math.Abs(getCenter().y - r.getCenter().y); return Math.Abs(GetCenter().x - r.GetCenter().x) + Math.Abs(GetCenter().y - r.GetCenter().y);
} }
public Vector2Int getCenter() { public Vector2Int GetCenter() {
return new Vector2Int(( int ) bounds.center.x, ( int ) bounds.center.y); return new Vector2Int(( int ) bounds.center.x, ( int ) bounds.center.y);
} }
public HashSet<Vector2Int> allDoors() { public HashSet<Vector2Int> AllDoors() {
HashSet<Vector2Int> ret = new HashSet<Vector2Int>(); HashSet<Vector2Int> ret = new HashSet<Vector2Int>();
ret.UnionWith(doorsUp); ret.UnionWith(doorsUp);
ret.UnionWith(doorsDown); ret.UnionWith(doorsDown);

View file

@ -12,7 +12,7 @@ public class HealthbarController : MonoBehaviour {
void Update() { void Update() {
// if player alive and spawned // if player alive and spawned
if ( player != null ) { if ( player != null ) {
UpdatePointer(player.getHealth()); UpdatePointer(player.GetHealth());
} else if (currentRotation != 0) { } else if (currentRotation != 0) {
//if player dead or not spawned //if player dead or not spawned
UpdatePointer(0); UpdatePointer(0);