1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-15 13:25:58 +00:00
Boat-Battle/godot_ship/script/game/Gameplay/Board.gd

47 lines
1.2 KiB
GDScript3
Raw Normal View History

2021-11-08 13:40:11 +00:00
extends Node
# Path to Ship class, for instantiating new Ships in code
onready var Ship = load("res://script/game/Gameplay/Ship.gd")
var bottom_board # Player board
var top_board # Opponent board
2021-11-08 13:40:11 +00:00
var ships # list of Ships
var ship_count # number of 'active' (un-sunk) ships
2021-11-08 13:40:11 +00:00
# Called when the node enters the scene tree for the first time.
func _ready():
ships = []
shipCount = 0
2021-11-08 13:40:11 +00:00
# TODO: What state?
2021-11-08 13:40:11 +00:00
func getState():
pass
# 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():
pass
func _init():
# Initialize the bottom_board to a 10x10 array
for i in range(10):
bottom_board.append([])
for _i in range(0, 10):
bottom_board[i].resize(10)
# Initialize the top_board to a 10x10 array
for i in range(10):
top_board.append([])
for _i in range(0, 10):
top_board[i].resize(10)
# worldspace_to_boardspace: convert a Vector2 in world-space to board-space
func worldspace_to_boardspace(coordinate:Vector2):
# 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)