1
0
mirror of https://github.com/JohnBreaux/Boat-Battle.git synced 2024-11-15 05:25:57 +00:00

Added partial texture function for ship

This commit is contained in:
hpham474 2021-11-14 03:15:27 -06:00
parent de9684d22f
commit 6fa1319ec4
4 changed files with 67 additions and 9 deletions

View File

@ -0,0 +1,3 @@
source_md5="3b774873968ed3ad322fe34d56720cd8"
dest_md5="17d758d595e2d6d8e58671b48f45f54a"

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/TextureAtlas.png-f8378824db0f2b64b8339984d33f1a41.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/game/TextureAtlas.png"
dest_files=[ "res://.import/TextureAtlas.png-f8378824db0f2b64b8339984d33f1a41.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=true
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View File

@ -8,17 +8,19 @@ enum Orientation {X = 0, Y = 1}
# Size of ship in board units
var size
# 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
var sunk = false
# Orientation of the ship (see enum Orientation)
var orientation = Orientation.Y
# array of spots thats been hit
var hit = []
# Ship sprite metadata
# sprite: the texture atlas containing all ship parts
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.
var texture = 0
# variant: for ship 3. A is 0, B is 1
var variant = 0
# Called when the node enters the scene tree for the first time.
func _ready():
@ -31,7 +33,7 @@ func getSize():
# getPosition: get the position of the ship's center, in board units
func getPosition():
return position
return boardposition
# getOrientation: get the orientation of the ship (see enum Orientation)
func getOrientation():
@ -41,24 +43,43 @@ func getOrientation():
func getSunk():
return sunk
# returns an array of the positions that the ship occupies
func getExtent():
var extent = []
#vertical orientation
if orientation == 1:
for i in size:
var pos
pos.x = position.x
pos.y = position.y - ((size - 1) / 2) + i
pos.x = boardposition.x
pos.y = boardposition.y - ((size - 1) / 2) + i
extent.append(pos)
#horizontal orientation
if orientation == 0:
for i in size:
var pos
pos.x = position.x - ((size - 1) / 2) + i
pos.y = position.y
pos.x = boardposition.x - ((size - 1) / 2) + i
pos.y = boardposition.y
extent.append(pos)
print(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
func setSunk():
sunk = true
@ -68,6 +89,6 @@ func setSunk():
# in_size: size of the ship, in board-units; 2 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):
position = in_position
boardposition = in_position
size = in_size
orientation = in_orientation