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:
parent
de9684d22f
commit
6fa1319ec4
@ -0,0 +1,3 @@
|
|||||||
|
source_md5="3b774873968ed3ad322fe34d56720cd8"
|
||||||
|
dest_md5="17d758d595e2d6d8e58671b48f45f54a"
|
||||||
|
|
Binary file not shown.
34
godot_ship/assets/game/TextureAtlas.png.import
Normal file
34
godot_ship/assets/game/TextureAtlas.png.import
Normal 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
|
@ -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