mirror of
https://github.com/JohnBreaux/Boat-Battle.git
synced 2024-11-15 05:25:57 +00:00
Merge branch 'game-logic' of https://github.com/StatewideInk/Group12 into game-logic
This commit is contained in:
commit
ddf63b569c
@ -8,17 +8,19 @@ enum Orientation {X = 0, Y = 1}
|
|||||||
# Size of ship in board units
|
# Size of ship in board units
|
||||||
var size
|
var size
|
||||||
# Coordinates of ship's center. Ship extends [-(size-1 >> 1), (size/2 >> 1)]
|
# Coordinates of ship's center. Ship extends [-(size-1 >> 1), (size/2 >> 1)]
|
||||||
var position
|
var boardposition
|
||||||
# Variable storing whether the ship is sunk, for rendering purposes
|
# Variable storing whether the ship is sunk, for rendering purposes
|
||||||
var sunk = false
|
var sunk = false
|
||||||
# Orientation of the ship (see enum Orientation)
|
# Orientation of the ship (see enum Orientation)
|
||||||
var orientation = Orientation.Y
|
var orientation = Orientation.Y
|
||||||
|
# array of spots thats been hit
|
||||||
|
var hit = []
|
||||||
|
|
||||||
# Ship sprite metadata
|
# Ship sprite metadata
|
||||||
# sprite: the texture atlas containing all ship parts
|
# sprite: the texture atlas containing all ship parts
|
||||||
var atlas # = TODO: figure out how to use one sprite for multiple textures
|
var atlas # = TODO: figure out how to use one sprite for multiple textures
|
||||||
# texture: the offset into the texture atlas of the first part of the ship.
|
# variant: for ship 3. A is 0, B is 1
|
||||||
var texture = 0
|
var variant = 0
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready():
|
func _ready():
|
||||||
@ -31,7 +33,7 @@ func getSize():
|
|||||||
|
|
||||||
# getPosition: get the position of the ship's center, in board units
|
# getPosition: get the position of the ship's center, in board units
|
||||||
func getPosition():
|
func getPosition():
|
||||||
return position
|
return boardposition
|
||||||
|
|
||||||
# getOrientation: get the orientation of the ship (see enum Orientation)
|
# getOrientation: get the orientation of the ship (see enum Orientation)
|
||||||
func getOrientation():
|
func getOrientation():
|
||||||
@ -41,24 +43,43 @@ func getOrientation():
|
|||||||
func getSunk():
|
func getSunk():
|
||||||
return sunk
|
return sunk
|
||||||
|
|
||||||
|
# returns an array of the positions that the ship occupies
|
||||||
func getExtent():
|
func getExtent():
|
||||||
var extent = []
|
var extent = []
|
||||||
#vertical orientation
|
#vertical orientation
|
||||||
if orientation == 1:
|
if orientation == 1:
|
||||||
for i in size:
|
for i in size:
|
||||||
var pos
|
var pos
|
||||||
pos.x = position.x
|
pos.x = boardposition.x
|
||||||
pos.y = position.y - ((size - 1) / 2) + i
|
pos.y = boardposition.y - ((size - 1) / 2) + i
|
||||||
extent.append(pos)
|
extent.append(pos)
|
||||||
#horizontal orientation
|
#horizontal orientation
|
||||||
if orientation == 0:
|
if orientation == 0:
|
||||||
for i in size:
|
for i in size:
|
||||||
var pos
|
var pos
|
||||||
pos.x = position.x - ((size - 1) / 2) + i
|
pos.x = boardposition.x - ((size - 1) / 2) + i
|
||||||
pos.y = position.y
|
pos.y = boardposition.y
|
||||||
extent.append(pos)
|
extent.append(pos)
|
||||||
print(extent)
|
print(extent)
|
||||||
return extent
|
return extent
|
||||||
|
|
||||||
|
# generates a texture at the spot (index should start at 0)
|
||||||
|
func texture(index):
|
||||||
|
var state = 0 # floating
|
||||||
|
if(hit[index]):
|
||||||
|
state = 1 # sunk
|
||||||
|
var textureSize = 32
|
||||||
|
var t = AtlasTexture.new()
|
||||||
|
t.atlas = load("res://assets/game/TextureAtlas.png")
|
||||||
|
t.region (
|
||||||
|
(size * textureSize) * variant + (32 * index),
|
||||||
|
(size - 2) * textureSize * 2 + (32 * state),
|
||||||
|
textureSize,
|
||||||
|
textureSize
|
||||||
|
)
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
# setSunk: sink the ship
|
# setSunk: sink the ship
|
||||||
func setSunk():
|
func setSunk():
|
||||||
sunk = true
|
sunk = true
|
||||||
@ -68,6 +89,6 @@ func setSunk():
|
|||||||
# in_size: size of the ship, in board-units; 2 by default
|
# in_size: size of the ship, in board-units; 2 by default
|
||||||
# in_orientation: orientation of the ship (see enum Orientation); vertical by default
|
# in_orientation: orientation of the ship (see enum Orientation); vertical by default
|
||||||
func _init(in_position = Vector2(0,0), in_size = 2, in_orientation = Orientation.Y):
|
func _init(in_position = Vector2(0,0), in_size = 2, in_orientation = Orientation.Y):
|
||||||
position = in_position
|
boardposition = in_position
|
||||||
size = in_size
|
size = in_size
|
||||||
orientation = in_orientation
|
orientation = in_orientation
|
||||||
|
Loading…
Reference in New Issue
Block a user