-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsys_debug.go
132 lines (119 loc) · 3.72 KB
/
sys_debug.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package kar
import (
"fmt"
"image"
"kar/items"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/setanarut/v"
)
type Debug struct {
drawItemHitboxEnabled bool
drawPlayerTileHitboxEnabled bool
drawDebugTextEnabled bool
tile uint8
}
func (d *Debug) Init() {}
func (d *Debug) Update() {
if inpututil.IsKeyJustPressed(ebiten.Key1) {
pos := tileMapRes.FloorToBlockCenter(cameraRes.ScreenToWorld(ebiten.CursorPosition()))
mapPlatform.NewEntity(
&AABB{
Pos: v.Vec{pos.X, pos.Y},
Half: v.Vec{10, 10},
},
&Velocity{1, 0},
&PlatformType{"solid"},
)
}
if inpututil.IsKeyJustPressed(ebiten.Key2) {
pos := tileMapRes.FloorToBlockCenter(cameraRes.ScreenToWorld(ebiten.CursorPosition()))
mapPlatform.NewEntity(
&AABB{
Pos: v.Vec{pos.X, pos.Y},
Half: v.Vec{10, 10},
},
&Velocity{1, 0},
&PlatformType{"oneway"},
)
}
if inpututil.IsKeyJustPressed(ebiten.Key3) {
x, y := cameraRes.ScreenToWorld(ebiten.CursorPosition())
mapEnemy.NewEntity(
&AABB{
Pos: v.Vec{x, y},
Half: v.Vec{10, 10},
},
&Velocity{0.5, 0.5},
&AI{},
)
}
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
x, y := cameraRes.ScreenToWorld(ebiten.CursorPosition())
p := tileMapRes.WorldToTile(x, y)
tileMapRes.Set(p.X, p.Y, d.tile)
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
x, y := cameraRes.ScreenToWorld(ebiten.CursorPosition())
p := tileMapRes.WorldToTile(x, y)
d.tile = tileMapRes.GetID(p.X, p.Y)
}
if inpututil.IsKeyJustPressed(ebiten.KeyBackspace) {
inventoryRes.ClearCurrentSlot()
}
if inpututil.IsKeyJustPressed(ebiten.KeyK) {
inventoryRes.RandomFillAllSlots()
}
if inpututil.IsKeyJustPressed(ebiten.KeyM) {
inventoryRes.SetSlot(0, items.Coal, 64, 0)
inventoryRes.SetSlot(1, items.RawGold, 64, 0)
inventoryRes.SetSlot(2, items.RawIron, 64, 0)
inventoryRes.SetSlot(3, items.Stick, 64, 0)
inventoryRes.SetSlot(4, items.DiamondPickaxe, 1, items.GetDefaultDurability(items.DiamondPickaxe))
inventoryRes.SetSlot(5, items.DiamondShovel, 1, items.GetDefaultDurability(items.DiamondShovel))
inventoryRes.SetSlot(6, items.DiamondAxe, 1, items.GetDefaultDurability(items.DiamondAxe))
inventoryRes.SetSlot(7, items.Diamond, 64, 0)
inventoryRes.SetSlot(8, items.Snowball, 64, 0)
}
if inpututil.IsKeyJustPressed(ebiten.KeyV) {
d.drawDebugTextEnabled = !d.drawDebugTextEnabled
}
if inpututil.IsKeyJustPressed(ebiten.KeyO) {
}
if inpututil.IsKeyJustPressed(ebiten.KeyC) {
d.drawItemHitboxEnabled = !d.drawItemHitboxEnabled
}
if inpututil.IsKeyJustPressed(ebiten.KeyB) {
d.drawPlayerTileHitboxEnabled = !d.drawPlayerTileHitboxEnabled
}
if inpututil.IsKeyJustPressed(ebiten.KeyF12) {
dataManager.SaveItem("map.png", tileMapRes.GetImageByte())
}
if inpututil.IsKeyJustPressed(ebiten.KeyF11) {
box := mapAABB.GetUnchecked(currentPlayer)
tileMapRes.Set(tileMapRes.W/2, tileMapRes.H-3, items.Air)
box.Pos = tileMapRes.TileToWorld(image.Point{tileMapRes.W / 2, tileMapRes.H - 3})
cameraRes.SetCenter(box.Pos.X, box.Pos.Y)
}
}
func (d *Debug) Draw() {
if world.Alive(currentPlayer) {
box, vel, _, playerController, _ := mapPlayer.GetUnchecked(currentPlayer)
if d.drawPlayerTileHitboxEnabled {
DrawAABB(box)
}
if d.drawDebugTextEnabled {
ebitenutil.DebugPrintAt(Screen, fmt.Sprintf(
"state %v\nVel.X: %.2f\nVel.Y: %.2f\nCamera: %v",
playerController.CurrentState,
vel.X,
vel.Y,
cameraRes,
), 0, 10)
}
} else {
ebitenutil.DebugPrintAt(Screen, fmt.Sprintf("Camera: %v", cameraRes), 0, 10)
}
ebitenutil.DebugPrintAt(Screen, fmt.Sprintf("DEBUG MODE: %v", debugEnabled), int(ScreenSize.X)-60, 10)
}