-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cs
More file actions
74 lines (66 loc) · 2.14 KB
/
Map.cs
File metadata and controls
74 lines (66 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using Godot;
using System;
using System.Collections.Generic;
public partial class Map : Control
{
public List<Room> rooms;
private int nx, ny, mx, my;
[Export]
public StyleBox unknown;
[Export]
public StyleBox known;
[Export]
public StyleBox current;
[Export]
public Texture2D doorH;
[Export]
public Texture2D doorV;
[Export]
public Texture2D boss;
public bool map = false;
public bool poi = false;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
}
public void GenMap(List<Room> rooms) {
this.rooms = rooms;
nx = rooms[0].RoomPosition.X;
ny = rooms[0].RoomPosition.Y;
mx = rooms[0].RoomPosition.X + rooms[0].RoomSize.X;
my = rooms[0].RoomPosition.Y + rooms[0].RoomSize.Y;
foreach (var room in rooms) {
nx = Math.Min(nx, room.RoomPosition.X);
ny = Math.Min(ny, room.RoomPosition.Y);
mx = Math.Max(mx, room.RoomPosition.X + room.RoomSize.X);
my = Math.Max(my, room.RoomPosition.Y + room.RoomSize.Y);
}
CustomMinimumSize = new Vector2((mx - nx) * 7, (my - ny) * 7);
}
public override void _Process(double delta) {
QueueRedraw();
}
public override void _Draw() {
if (rooms == null) return;
foreach (var room in rooms) {
//DrawRect(new Rect2((room.RoomPosition - new Vector2(nx, ny)) * 2, room.RoomSize * 2), room.active ? Colors.Green : room.visited ? Colors.Cyan : Colors.White, room.visited);
var pos = (room.RoomPosition - new Vector2(nx, ny)) * 7;
if (map || room.visited) {
DrawStyleBox(room.active ? current : room.visited ? known : unknown, new Rect2(pos, room.RoomSize * 7 + Vector2.One));
}
if (map) {
for (int i = 0; i < room.doors.Count; i++) {
if (!room.doors[i]) continue;
(var side, var index) = room.GetDoorSideIndex(i);
var vert = side == Side.Top || side == Side.Bottom;
DrawTexture(vert ? doorV : doorH, (room.GetDoorRoomPos(side, index) - new Vector2(nx, ny)) * 7 + (vert ? new Vector2(2, -1) : new Vector2(-1, 2)));
}
}
if (poi) {
if (room.boss != null) {
DrawTexture(boss, (room.RoomPosition + room.RoomSize.Float()/2f - new Vector2(nx, ny)) * 7 - new Vector2(3.5f, 3.5f));
}
}
}
}
}