Starting positions

This commit is contained in:
Kienan Stewart 2022-04-02 11:46:19 -04:00
parent 9f0afc8a1e
commit bcd538a306
34 changed files with 654 additions and 0 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
build/
.import/

BIN
assets/export/bishop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/bishop.png-9e052c6f362b2248acf5ced5c1d39bbb.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/export/bishop.png"
dest_files=[ "res://.import/bishop.png-9e052c6f362b2248acf5ced5c1d39bbb.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

BIN
assets/export/king.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/king.png-07ffe82c467263d078bdd00ecc260910.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/export/king.png"
dest_files=[ "res://.import/king.png-07ffe82c467263d078bdd00ecc260910.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

BIN
assets/export/knight.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/knight.png-cd94a1c957955d24a4b172ef025165bd.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/export/knight.png"
dest_files=[ "res://.import/knight.png-cd94a1c957955d24a4b172ef025165bd.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

BIN
assets/export/pawn.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/pawn.png-ea3858ceb85926cfe768cbdc4cefb202.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/export/pawn.png"
dest_files=[ "res://.import/pawn.png-ea3858ceb85926cfe768cbdc4cefb202.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

BIN
assets/export/queen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/queen.png-b40ec150b980fde42f9ae368b5da74a9.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/export/queen.png"
dest_files=[ "res://.import/queen.png-b40ec150b980fde42f9ae368b5da74a9.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

BIN
assets/export/rook.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/rook.png-024d03a0931bc1008f05a9e2d8bb93aa.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/export/rook.png"
dest_files=[ "res://.import/rook.png-024d03a0931bc1008f05a9e2d8bb93aa.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 793 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/square_center_0.png-58cbbdc1eb62a39927b47443c3feb6ac.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/export/square_center_0.png"
dest_files=[ "res://.import/square_center_0.png-58cbbdc1eb62a39927b47443c3feb6ac.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

Binary file not shown.

After

Width:  |  Height:  |  Size: 891 B

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/square_edge.png-03ab64193a0e2810802d31d0367576c5.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://assets/export/square_edge.png"
dest_files=[ "res://.import/square_edge.png-03ab64193a0e2810802d31d0367576c5.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

BIN
assets/source/Squares.xcf Normal file

Binary file not shown.

View File

@ -16,8 +16,16 @@ _global_script_class_icons={
[application]
config/name="Ld 50"
run/main_scene="res://src/Game.tscn"
config/icon="res://icon.png"
[display]
window/size/width=1280
window/size/height=1024
window/stretch/mode="2d"
window/stretch/aspect="keep"
[rendering]
environment/default_environment="res://default_env.tres"

124
src/Game.gd Normal file
View File

@ -0,0 +1,124 @@
extends Container
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var pf_scale
var turn = 1
var is_player_turn = true
# Index: weakref to piece
var pieces = {}
var height
var width
const piece_types = {
"pawn": "res://src/pieces/Pawn.tscn",
"rook": "res://src/pieces/Rook.tscn",
"bishop": "res://src/pieces/Bishop.tscn",
"knight": "res://src/pieces/Knight.tscn",
"king": "res://src/pieces/King.tscn",
"queen": "res://src/pieces/Queen.tscn",
}
func new_piece(piece_type, group, position = null):
if not piece_types.has(piece_type):
return null
var piece = ResourceLoader.load(piece_types[piece_type]).instance()
if position:
if !set_piece_position(piece, position, true):
piece.queue_free()
return null
piece.set_position(Vector2(
position.x * 128,
position.y * 128
))
var pf = get_node("/root/Game/MarginContainer/Playfield")
piece.add_to_group("pieces")
piece.add_to_group(group)
if group == "opponent":
piece.get_node("Body").set_modulate(
Color(0.75, 0.1, 0.1, 1.0)
)
pf.add_child(piece)
print("Created piece", piece_type, " at ", position, " for group ", group)
return piece
func pos_to_index(position):
return (position.y * self.height) + position.x
func set_piece_position(piece, position, destroy = false):
var idx = pos_to_index(position)
if self.pieces.has(idx):
if destroy:
if self.pieces[idx].get_ref():
self.pieces[idx].get_ref().queue_free()
else:
print("Warning, piece collision dur set_piece_position at ", position)
return false
self.pieces[idx] = weakref(piece)
return true
# Called when the node enters the scene tree for the first time.
func _ready():
var pf = get_node("/root/Game/MarginContainer/Playfield")
var start_height = 8
var start_width = 8
pf.initialize(start_width, start_height)
self.height = start_height
self.width = start_width
# Translate the pf to it sits on top left
# We want to scale it to fit within the margin container
var pf_size = Vector2(width * 128.0, height * 128.0)
var larger = pf_size.x
if pf_size.y > larger:
larger = pf_size.y
# Container is 768x768
var scale = 768 / larger
print("Scaling playfield by ", scale)
pf.apply_scale(Vector2(scale, scale))
pf.translate(Vector2(
64 * scale,
64 * scale
))
self.pf_scale = scale
reset_game_state()
func reset_game_state():
self.is_player_turn = true
self.turn = 0
for p in get_tree().get_nodes_in_group("pieces"):
p.queue_free()
# Create starting pieces
# 8 pawns per side, starting at col 0 + (width-8)/2
# on rows 2, height - 2
var start_x = (self.width - 8) / 2
var y_opponent = 1
var y_player = self.height - 2
var i = 0
while i < 8:
var x = start_x + i
new_piece("pawn", "player", Vector2(x, y_player))
new_piece("pawn", "opponent", Vector2(x, y_opponent))
i += 1
new_piece("rook", "player", Vector2(start_x, self.height -1))
new_piece("rook", "player", Vector2(start_x + 7, self.height -1))
new_piece("rook", "opponent", Vector2(start_x, 0))
new_piece("rook", "opponent", Vector2(start_x + 7, 0))
new_piece("bishop", "player", Vector2(start_x + 2, self.height -1))
new_piece("bishop", "player", Vector2(start_x + 5, self.height -1))
new_piece("bishop", "opponent", Vector2(start_x + 2, 0))
new_piece("bishop", "opponent", Vector2(start_x + 5, 0))
new_piece("knight", "player", Vector2(start_x + 1, self.height -1))
new_piece("knight", "player", Vector2(start_x + 6, self.height -1))
new_piece("knight", "opponent", Vector2(start_x + 1, 0))
new_piece("knight", "opponent", Vector2(start_x + 6, 0))
new_piece("king", "player", Vector2(start_x + 4, self.height - 1))
new_piece("king", "opponent", Vector2(start_x + 4, 0))
new_piece("queen", "player", Vector2(start_x + 3, self.height - 1))
new_piece("queen", "opponent", Vector2(start_x + 3, 0))
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

26
src/Game.tscn Normal file
View File

@ -0,0 +1,26 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/Game.gd" type="Script" id=1]
[ext_resource path="res://src/Playfield.tscn" type="PackedScene" id=2]
[node name="Game" type="Container"]
anchor_right = 1.0
anchor_bottom = 1.0
size_flags_horizontal = 2
size_flags_vertical = 2
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="MarginContainer" type="MarginContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 256.0
margin_top = 128.0
margin_right = -256.0
margin_bottom = -128.0
size_flags_horizontal = 2
size_flags_vertical = 2
[node name="Playfield" parent="MarginContainer" instance=ExtResource( 2 )]

23
src/Piece.gd Normal file
View File

@ -0,0 +1,23 @@
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Each piece should belong to a group - player or opponent
#
var health = 1
var damage = 1
var abilities = []
var kills = 0
var at_spawn = true
# 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

52
src/Playfield.gd Normal file
View File

@ -0,0 +1,52 @@
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var height
var width
# holds weakrefs to the square nodes
var squares = []
func initialize(width: int = 8, height: int = 8):
# Remove any Squares beneath us
for i in self.squares:
if i.get_ref():
i.get_ref().queue_free()
self.squares = []
self.height = height
self.width = width
# Create new squares
var i = 0
while i < self.width:
var j = 0
while j < self.height:
var instance = ResourceLoader.load("res://src/Square.tscn").instance()
# @TODO any tweaks to the node by calling custom function initialize()
instance.translate(Vector2(128*i, 128*j))
self.squares.append(weakref(instance))
add_child(instance)
j += 1
i += 1
func to_index(row: int, col: int):
# 0-based basing width, height
if row < 0 or col < 0:
return null
if row >= self.width or col >= self.height:
return null
return (row*self.width)+col
# Called when the node enters the scene tree for the first time.
func _ready():
initialize(8, 8)
# pass
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

6
src/Playfield.tscn Normal file
View File

@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/Playfield.gd" type="Script" id=1]
[node name="Playfield" type="Node2D"]
script = ExtResource( 1 )

13
src/Square.tscn Normal file
View File

@ -0,0 +1,13 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://assets/export/square_edge.png" type="Texture" id=1]
[ext_resource path="res://assets/export/square_center_0.png" type="Texture" id=2]
[node name="Square" type="Node2D"]
z_index = -1
[node name="Body" type="Sprite" parent="."]
texture = ExtResource( 2 )
[node name="Edge" type="Sprite" parent="."]
texture = ExtResource( 1 )

21
src/hilight.shader Normal file
View File

@ -0,0 +1,21 @@
shader_type canvas_item;
uniform float width: hint_range(0.0, 50.0);
uniform vec4 color: hint_color;
void fragment() {
vec2 size = TEXTURE_PIXEL_SIZE * width;
float outline = texture(TEXTURE, UV + vec2(-size.x, 0)).a;
outline += texture(TEXTURE, UV + vec2(0, size.y)).a;
outline += texture(TEXTURE, UV + vec2(size.x, 0)).a;
outline += texture(TEXTURE, UV + vec2(0, -size.y)).a;
outline += texture(TEXTURE, UV + vec2(-size.x, size.y)).a;
outline += texture(TEXTURE, UV + vec2(size.x, size.y)).a;
outline += texture(TEXTURE, UV + vec2(-size.x, -size.y)).a;
outline += texture(TEXTURE, UV + vec2(size.x, -size.y)).a;
outline = min(outline, 1.0);
vec4 ncolor = texture(TEXTURE, UV);
COLOR = mix(ncolor, color, outline - ncolor.a);
}

9
src/pieces/Bishop.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/pieces/Piece.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/export/bishop.png" type="Texture" id=2]
[node name="Piece" instance=ExtResource( 1 )]
[node name="Body" parent="." index="0"]
texture = ExtResource( 2 )

9
src/pieces/King.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/pieces/Piece.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/export/king.png" type="Texture" id=2]
[node name="Piece" instance=ExtResource( 1 )]
[node name="Body" parent="." index="0"]
texture = ExtResource( 2 )

9
src/pieces/Knight.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/pieces/Piece.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/export/knight.png" type="Texture" id=2]
[node name="Piece" instance=ExtResource( 1 )]
[node name="Body" parent="." index="0"]
texture = ExtResource( 2 )

9
src/pieces/Pawn.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/pieces/Piece.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/export/pawn.png" type="Texture" id=3]
[node name="Piece" instance=ExtResource( 1 )]
[node name="Body" parent="." index="0"]
texture = ExtResource( 3 )

39
src/pieces/Piece.gd Normal file
View File

@ -0,0 +1,39 @@
extends Sprite
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
const types = {
"pawn": "res://src/pieces/Pawn.tscn",
"rook": "res://src/pieces/Rook.tscn",
"bishop": "res://src/pieces/Bishop.tscn",
"knight": "res://src/pieces/Knight.tscn",
"king": "res://src/pieces/King.tscn",
"queen": "res://src/pieces/Queen.tscn",
}
# Each piece should belong to a group - player or opponent
#
var health = 1
var damage = 1
var abilities = []
var kills = 0
static func new_piece(piece_type):
if not types.has(piece_type):
return null
return ResourceLoader.load(types[piece_type]).instance()
#piece.apply_scale(Vector2(pf.scale, pf.scale))
#piece.add_to_group(group)
#return piece
# 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

15
src/pieces/Piece.tscn Normal file
View File

@ -0,0 +1,15 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://src/Piece.gd" type="Script" id=1]
[ext_resource path="res://src/hilight.shader" type="Shader" id=2]
[sub_resource type="ShaderMaterial" id=1]
shader = ExtResource( 2 )
shader_param/width = 2.0
shader_param/color = null
[node name="Piece" type="Node2D"]
script = ExtResource( 1 )
[node name="Body" type="Sprite" parent="."]
material = SubResource( 1 )

9
src/pieces/Queen.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/pieces/Piece.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/export/queen.png" type="Texture" id=2]
[node name="Piece" instance=ExtResource( 1 )]
[node name="Body" parent="." index="0"]
texture = ExtResource( 2 )

9
src/pieces/Rook.tscn Normal file
View File

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/pieces/Piece.tscn" type="PackedScene" id=1]
[ext_resource path="res://assets/export/rook.png" type="Texture" id=2]
[node name="Rook" instance=ExtResource( 1 )]
[node name="Body" parent="." index="0"]
texture = ExtResource( 2 )