~bigbes/game-prototype-ftl

ref: fcffe5a136eb4af0863f4e02a627ff6dd4443538 game-prototype-ftl/hud.go -rw-r--r-- 977 bytes
fcffe5a1 — Eugene Blikh docs(systems-power): record review conclusion 30 days ago
                                                                                
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
package main

// HUD geometry constants. All values are in virtual pixels (640×360 grid).
// HudY is the top edge of the HUD strip; the five power columns begin at HudX
// and are each HudColW pixels wide. The reactor-readout band occupies the
// horizontal range [0, HudX).
const (
	HudY        = 272
	HudX        = 200
	HudColW     = 40
	HudColCount = 5
)

// hudHitTest maps a virtual-pixel coordinate to the RoomRole whose power column
// was clicked. Returns ok=false for any coordinate outside the column strip:
//   - py < HudY  (above the HUD)
//   - px < HudX  (reactor-readout band to the left)
//   - px >= HudX + HudColCount*HudColW  (right of last column)
//
// Columns are flush (no gutters). Column i covers [HudX+i*HudColW, HudX+(i+1)*HudColW).
func hudHitTest(px, py int) (RoomRole, bool) {
	if py < HudY {
		return 0, false
	}
	if px < HudX || px >= HudX+HudColCount*HudColW {
		return 0, false
	}
	idx := (px - HudX) / HudColW
	return RoomRole(idx), true
}