From eaa1617b9a823b5c4449ea71b0948a24df04ff9b Mon Sep 17 00:00:00 2001 From: John Breaux Date: Thu, 11 Nov 2021 14:38:10 -0600 Subject: [PATCH] Pushing what I've done of the game logic. --- godot_ship/script/game/Gameplay/Board.gd | 31 ++++++++++++++++++----- godot_ship/script/game/Gameplay/Game.gd | 4 ++- godot_ship/script/game/Gameplay/Player.gd | 3 +++ godot_ship/script/game/Gameplay/Ship.gd | 7 +++-- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/godot_ship/script/game/Gameplay/Board.gd b/godot_ship/script/game/Gameplay/Board.gd index 90dc099..adb134a 100644 --- a/godot_ship/script/game/Gameplay/Board.gd +++ b/godot_ship/script/game/Gameplay/Board.gd @@ -1,5 +1,8 @@ extends Node +# Path to Ship class, for instantiating new Ships in code +onready var Ship = load("res://script/game/Gameplay/Ship.gd") + var bottomBoard # Player board var topBoard # Opponent board var ships # list of Ships @@ -7,17 +10,16 @@ var shipCount # number of 'active' (un-sunk) ships # Called when the node enters the scene tree for the first time. func _ready(): - pass # Replace with function body. - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -#func _process(delta): -# pass + ships = [] + shipCount = 0 +# TODO: What state? func getState(): pass -func placeShip(): +# 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)) pass func getBottomBoard(): @@ -25,3 +27,18 @@ func getBottomBoard(): func getShipCount(): pass + +func _init(): + for i in range(10): + bottomBoard.append([]) + for _i in range(0, 10): + bottomBoard[i].resize(10) + for i in range(10): + topBoard.append([]) + for _i in range(0, 10): + bottomBoard[i].resize(10) + +func worldspace_to_boardspace(coordinate:Vector2): + coordinate -= Vector2(36, 36) + coordinate /= Vector2(32,32) + return coordinate diff --git a/godot_ship/script/game/Gameplay/Game.gd b/godot_ship/script/game/Gameplay/Game.gd index 5289713..1af66d2 100644 --- a/godot_ship/script/game/Gameplay/Game.gd +++ b/godot_ship/script/game/Gameplay/Game.gd @@ -1,5 +1,8 @@ extends Node +# Path to Player class, for instantiating new Players in code +var Player = "res://script/game/Gameplay/Player.gd" + var players # = player1, player2, ... var turnCount = 0 var wasHit = false @@ -8,7 +11,6 @@ var isMultiplayer = false # Called when the node enters the scene tree for the first time. func _ready(): gameStart() - pass # Replace with function body. # Called every frame. 'delta' is the elapsed time since the previous frame. diff --git a/godot_ship/script/game/Gameplay/Player.gd b/godot_ship/script/game/Gameplay/Player.gd index ddaa32c..72ca7f6 100644 --- a/godot_ship/script/game/Gameplay/Player.gd +++ b/godot_ship/script/game/Gameplay/Player.gd @@ -1,5 +1,8 @@ extends Node +# Path to Board class, for instantiating new Boards in code +var Board = "res://script/game/Gameplay/Board.gd" + var pid var board diff --git a/godot_ship/script/game/Gameplay/Ship.gd b/godot_ship/script/game/Gameplay/Ship.gd index d8799b8..a7502f1 100644 --- a/godot_ship/script/game/Gameplay/Ship.gd +++ b/godot_ship/script/game/Gameplay/Ship.gd @@ -1,6 +1,9 @@ extends Node -# This is the rendered element of a "ship", auto-generated when +# This is the rendered element of a "ship", generated when the game transitions from the placing state to the gameplay state + +# +enum Orientation {X = 1, Y = 0} var size = 0 # Size of ship in units var position # Coordinates of ship's center. Ship extends [-(size-1 >> 1), (size/2 >> 1)] @@ -34,7 +37,7 @@ func getSunk(): func setSunk(): sunk = true -func makeShip(in_position, in_size, in_orientation): +func _init(in_position = Vector2(0,0), in_size = 2, in_orientation = Orientation.X): position = in_position size = in_size orientation = in_orientation