2021-11-08 13:40:11 +00:00
|
|
|
extends Node
|
|
|
|
|
2021-11-11 20:38:10 +00:00
|
|
|
# Path to Ship class, for instantiating new Ships in code
|
|
|
|
onready var Ship = load("res://script/game/Gameplay/Ship.gd")
|
|
|
|
|
2021-11-11 21:38:50 +00:00
|
|
|
var bottom_board # Player board
|
|
|
|
var top_board # Opponent board
|
2021-11-08 13:40:11 +00:00
|
|
|
var ships # list of Ships
|
2021-11-11 21:38:50 +00:00
|
|
|
var ship_count # number of 'active' (un-sunk) ships
|
2021-11-08 13:40:11 +00:00
|
|
|
|
2021-11-12 02:45:38 +00:00
|
|
|
# a board is square. This is its side lengths
|
|
|
|
var board_len = 10
|
|
|
|
|
2021-11-08 13:40:11 +00:00
|
|
|
# Called when the node enters the scene tree for the first time.
|
|
|
|
func _ready():
|
2021-11-11 20:38:10 +00:00
|
|
|
ships = []
|
2021-11-12 02:45:38 +00:00
|
|
|
ship_count = 0
|
2021-11-08 13:40:11 +00:00
|
|
|
|
2021-11-11 20:38:10 +00:00
|
|
|
# TODO: What state?
|
2021-11-08 13:40:11 +00:00
|
|
|
func getState():
|
|
|
|
pass
|
|
|
|
|
2021-11-11 20:38:10 +00:00
|
|
|
# Place a ship on the board at board-space coordinates
|
|
|
|
func placeShip(in_position, in_size, in_orientation):
|
|
|
|
ships.append(Ship.new(in_position, in_size, in_orientation))
|
2021-11-08 13:40:11 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
func getBottomBoard():
|
|
|
|
pass
|
|
|
|
|
|
|
|
func getShipCount():
|
2021-11-12 02:45:38 +00:00
|
|
|
return ship_count
|
2021-11-11 20:38:10 +00:00
|
|
|
|
|
|
|
func _init():
|
2021-11-11 21:38:50 +00:00
|
|
|
# Initialize the bottom_board to a 10x10 array
|
2021-11-12 02:45:38 +00:00
|
|
|
for _row in range(board_len):
|
2021-11-11 21:38:50 +00:00
|
|
|
bottom_board.append([])
|
2021-11-12 02:45:38 +00:00
|
|
|
for column in bottom_board:
|
|
|
|
column.resize(10)
|
2021-11-11 21:38:50 +00:00
|
|
|
# Initialize the top_board to a 10x10 array
|
2021-11-12 02:45:38 +00:00
|
|
|
for _row in range(board_len):
|
2021-11-11 21:38:50 +00:00
|
|
|
top_board.append([])
|
2021-11-12 02:45:38 +00:00
|
|
|
for column in top_board:
|
|
|
|
column.resize(board_len)
|
2021-11-11 20:38:10 +00:00
|
|
|
|
2021-11-11 21:38:50 +00:00
|
|
|
# worldspace_to_boardspace: convert a Vector2 in world-space to board-space
|
2021-11-11 20:38:10 +00:00
|
|
|
func worldspace_to_boardspace(coordinate:Vector2):
|
2021-11-11 21:38:50 +00:00
|
|
|
# subtract 36 to get the position relative to (0,0) on the board, and integer divide by 32
|
|
|
|
return Vector2(int(coordinate.x - 36) >> 5, int(coordinate.y-36) >> 5)
|
2021-11-12 02:45:38 +00:00
|
|
|
|
|
|
|
# Coordinates of ship's center. Ship extends [-(size-1 >> 1), (size/2 >> 1)]
|
|
|
|
func shiptoboard(ship:Ship):
|
|
|
|
for i in range (ship.)
|
|
|
|
pass
|