~bigbes/game-prototype-ftl

ref: 7d266a3ed0ff36694b042467963d582a7b694405 game-prototype-ftl/ship.go -rw-r--r-- 2.0 KiB
7d266a3e — Eugene Blikh fix(wasm): set go.env to empty object 6 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
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
package main

// RoomRole identifies the functional purpose of a room aboard a ship.
// Rendering code maps roles to colors; ship data itself stays
// free of any renderer-specific information.
type RoomRole int

const (
	RolePilot RoomRole = iota
	RoleWeapons
	RoleShields
	RoleMedBay
	RoleEngines
)

// Room describes a rectangular cell on the ship grid.
// All coordinates and sizes are in tile units; conversion to pixels
// happens only in the renderer.
type Room struct {
	ID    int
	Name  string
	GridX int
	GridY int
	GridW int
	GridH int
	Role  RoomRole
	Cells [][2]int
}

// Ship is a pure-data description of a ship layout.
type Ship struct {
	Rooms []Room
}

// NewEnemyShip returns a 5-room layout that mirrors NewPlayerShip but with
// every room shifted +24 tiles along the X axis so the enemy ship sits on
// the right half of the virtual screen.
func NewEnemyShip() Ship {
	player := NewPlayerShip()
	rooms := make([]Room, len(player.Rooms))
	for i, r := range player.Rooms {
		r.GridX += 24
		shifted := make([][2]int, len(r.Cells))
		for j, c := range r.Cells {
			shifted[j] = [2]int{c[0] + 24, c[1]}
		}
		r.Cells = shifted
		rooms[i] = r
	}
	return Ship{Rooms: rooms}
}

// NewPlayerShip returns a hard-coded 5-room placeholder layout:
// Pilot front-left, Weapons mid-upper, Shields mid-center,
// MedBay mid-lower, Engines rear-right.
func NewPlayerShip() Ship {
	return Ship{
		Rooms: []Room{
			{ID: 1, Name: "Pilot", GridX: 3, GridY: 9, GridW: 3, GridH: 3, Role: RolePilot,
				Cells: [][2]int{{4, 10}, {5, 10}}},
			{ID: 2, Name: "Weapons", GridX: 6, GridY: 6, GridW: 4, GridH: 3, Role: RoleWeapons,
				Cells: [][2]int{{7, 7}, {8, 7}}},
			{ID: 3, Name: "Shields", GridX: 6, GridY: 9, GridW: 4, GridH: 3, Role: RoleShields,
				Cells: [][2]int{{7, 10}, {8, 10}}},
			{ID: 4, Name: "MedBay", GridX: 6, GridY: 12, GridW: 4, GridH: 3, Role: RoleMedBay,
				Cells: [][2]int{{7, 13}, {8, 13}}},
			{ID: 5, Name: "Engines", GridX: 10, GridY: 9, GridW: 3, GridH: 3, Role: RoleEngines,
				Cells: [][2]int{{11, 10}, {12, 10}}},
		},
	}
}