mirror of
https://github.com/Steffo99/particle-clash.git
synced 2024-11-21 15:14:19 +00:00
Gameplay works
This commit is contained in:
parent
b7d6a0305f
commit
f4ac2a2723
11 changed files with 175 additions and 75 deletions
|
@ -8,9 +8,4 @@ extends Node2D
|
|||
|
||||
# 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
|
||||
$Timer.start()
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
[gd_scene load_steps=6 format=2]
|
||||
[gd_scene load_steps=5 format=2]
|
||||
|
||||
[ext_resource path="res://src/MainMenu.gd" type="Script" id=1]
|
||||
[ext_resource path="res://src/scenes/Background.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://src/scenes/Play Area.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://src/scenes/Minimap.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://src/scenes/Timer.tscn" type="PackedScene" id=5]
|
||||
|
||||
[node name="MainMenu" type="Node2D"]
|
||||
|
@ -13,32 +12,14 @@ script = ExtResource( 1 )
|
|||
modulate = Color( 0, 0.31, 0, 1 )
|
||||
|
||||
[node name="Left Play Area" parent="." instance=ExtResource( 3 )]
|
||||
modulate = Color( 1, 0.7, 0.7, 1 )
|
||||
position = Vector2( 400, 450 )
|
||||
player = "p1"
|
||||
|
||||
[node name="Spinner" parent="Left Play Area/Tiles" index="0"]
|
||||
modulate = Color( 1, 0.5, 0.5, 1 )
|
||||
|
||||
[node name="Right Play Area" parent="." instance=ExtResource( 3 )]
|
||||
modulate = Color( 0.7, 0.7, 1, 1 )
|
||||
position = Vector2( 1200, 450 )
|
||||
player = "p2"
|
||||
|
||||
[node name="Spinner" parent="Right Play Area/Tiles" index="0"]
|
||||
modulate = Color( 0.5, 0.5, 1, 1 )
|
||||
|
||||
[node name="Minimap" parent="." instance=ExtResource( 4 )]
|
||||
position = Vector2( 0, 16 )
|
||||
|
||||
[node name="Atom" parent="Minimap" index="0"]
|
||||
modulate = Color( 1, 0.7, 0.7, 1 )
|
||||
|
||||
[node name="Atom2" parent="Minimap" index="1"]
|
||||
modulate = Color( 0.7, 0.7, 1, 1 )
|
||||
|
||||
[node name="Timer" parent="." instance=ExtResource( 5 )]
|
||||
|
||||
[editable path="Left Play Area"]
|
||||
[editable path="Right Play Area"]
|
||||
[editable path="Minimap"]
|
||||
|
|
12
src/scenes/Atom.gd
Normal file
12
src/scenes/Atom.gd
Normal file
|
@ -0,0 +1,12 @@
|
|||
extends Sprite
|
||||
|
||||
|
||||
var linked = false setget set_linked
|
||||
|
||||
|
||||
func set_linked(val):
|
||||
if val:
|
||||
modulate = Color.white
|
||||
else:
|
||||
modulate = Color(0.501961, 0.501961, 0.501961)
|
||||
linked = val
|
9
src/scenes/Atom.tscn
Normal file
9
src/scenes/Atom.tscn
Normal file
|
@ -0,0 +1,9 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://src/sprites/atom.png" type="Texture" id=1]
|
||||
[ext_resource path="res://src/scenes/Atom.gd" type="Script" id=2]
|
||||
|
||||
[node name="Atom" type="Sprite"]
|
||||
modulate = Color( 0.501961, 0.501961, 0.501961, 1 )
|
||||
texture = ExtResource( 1 )
|
||||
script = ExtResource( 2 )
|
|
@ -1,15 +0,0 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://src/sprites/atom.png" type="Texture" id=1]
|
||||
|
||||
[node name="Minimap" type="Node2D"]
|
||||
position = Vector2( 0, 880 )
|
||||
|
||||
[node name="Atom" type="Sprite" parent="."]
|
||||
scale = Vector2( 0.5, 0.5 )
|
||||
texture = ExtResource( 1 )
|
||||
|
||||
[node name="Atom2" type="Sprite" parent="."]
|
||||
position = Vector2( 1600, 0 )
|
||||
scale = Vector2( 0.5, 0.5 )
|
||||
texture = ExtResource( 1 )
|
|
@ -1,19 +1,27 @@
|
|||
extends Sprite
|
||||
|
||||
|
||||
const TILE_SIZE = 86
|
||||
func tiles_init():
|
||||
$Tiles.set_shape([
|
||||
" RRBB ",
|
||||
"RRBRBB",
|
||||
"RBRBRB",
|
||||
"BRBRBR",
|
||||
"BBRBRR",
|
||||
" BBRR "
|
||||
])
|
||||
check_matches()
|
||||
|
||||
|
||||
var cursor_pos setget set_cursor_pos
|
||||
func set_cursor_pos(val):
|
||||
var shape = $Tiles.shape
|
||||
#warning-ignore:integer_division
|
||||
var offset_x = len(shape) / 2 - 1
|
||||
#warning-ignore:integer_division
|
||||
var offset_y = len(shape[0]) / 2 - 1
|
||||
$Tiles/Spinner.position = Vector2((val.x - offset_x) * TILE_SIZE, (val.y - offset_y) * TILE_SIZE)
|
||||
var offset = $Tiles.size / 2
|
||||
$Tiles/Cursor.position = Vector2( \
|
||||
(val.x - offset) * $Tiles.TILE_SIZE + 43, \
|
||||
(val.y - offset) * $Tiles.TILE_SIZE + 43 \
|
||||
)
|
||||
cursor_pos = val
|
||||
|
||||
|
||||
func cursor_would_collide(top_left: Vector2):
|
||||
var shape = $Tiles.shape
|
||||
var size_x = len(shape) - 1
|
||||
|
@ -63,7 +71,81 @@ func cursor_move(dest):
|
|||
print("Cursor collided @ %d, %d" % [dest.x, dest.y])
|
||||
|
||||
func cursor_rotate():
|
||||
pass
|
||||
var top_left = $Tiles.atoms[cursor_pos.y][cursor_pos.x]
|
||||
var top_right = $Tiles.atoms[cursor_pos.y][cursor_pos.x+1]
|
||||
var bottom_left = $Tiles.atoms[cursor_pos.y+1][cursor_pos.x]
|
||||
var bottom_right = $Tiles.atoms[cursor_pos.y+1][cursor_pos.x+1]
|
||||
|
||||
var tmp = top_left.position
|
||||
top_left.position = top_right.position
|
||||
top_right.position = bottom_right.position
|
||||
bottom_right.position = bottom_left.position
|
||||
bottom_left.position = tmp
|
||||
|
||||
$Tiles.atoms[cursor_pos.y][cursor_pos.x] = bottom_left
|
||||
$Tiles.atoms[cursor_pos.y][cursor_pos.x+1] = top_left
|
||||
$Tiles.atoms[cursor_pos.y+1][cursor_pos.x+1] = top_right
|
||||
$Tiles.atoms[cursor_pos.y+1][cursor_pos.x] = bottom_right
|
||||
|
||||
# Optimizable
|
||||
check_matches()
|
||||
|
||||
|
||||
func check_matches():
|
||||
# Horizontally
|
||||
var size = $Tiles.size
|
||||
|
||||
for row in $Tiles.atoms:
|
||||
for col in row:
|
||||
if col == null:
|
||||
continue
|
||||
col.linked = false
|
||||
|
||||
for row in $Tiles.atoms:
|
||||
var x = 0
|
||||
while x < size - 3:
|
||||
var a1 = row[x]
|
||||
var a2 = row[x+1]
|
||||
var a3 = row[x+2]
|
||||
var a4 = row[x+3]
|
||||
x += 1
|
||||
if a1 == null || a2 == null || a3 == null || a4 == null:
|
||||
continue
|
||||
if a1.self_modulate == a2.self_modulate && a2.self_modulate == a3.self_modulate && a3.self_modulate == a4.self_modulate:
|
||||
a1.linked = true
|
||||
a2.linked = true
|
||||
a3.linked = true
|
||||
a4.linked = true
|
||||
|
||||
var y = 0
|
||||
while y < size - 3:
|
||||
var x = 0
|
||||
while x < size:
|
||||
var a1 = $Tiles.atoms[y][x]
|
||||
var a2 = $Tiles.atoms[y+1][x]
|
||||
var a3 = $Tiles.atoms[y+2][x]
|
||||
var a4 = $Tiles.atoms[y+3][x]
|
||||
x += 1
|
||||
if a1 == null || a2 == null || a3 == null || a4 == null:
|
||||
continue
|
||||
if a1.self_modulate == a2.self_modulate && a2.self_modulate == a3.self_modulate && a3.self_modulate == a4.self_modulate:
|
||||
a1.linked = true
|
||||
a2.linked = true
|
||||
a3.linked = true
|
||||
a4.linked = true
|
||||
y += 1
|
||||
|
||||
var score = 0
|
||||
|
||||
for row in $Tiles.atoms:
|
||||
for col in row:
|
||||
if col == null:
|
||||
continue
|
||||
if col.linked:
|
||||
score += 1
|
||||
|
||||
$Label.text = "%d" % score
|
||||
|
||||
|
||||
|
||||
export(String) var player
|
||||
|
@ -82,4 +164,5 @@ func _process(_delta):
|
|||
|
||||
|
||||
func _ready():
|
||||
tiles_init()
|
||||
cursor_init()
|
||||
|
|
|
@ -33,5 +33,6 @@ valign = 2
|
|||
|
||||
[node name="Tiles" parent="." instance=ExtResource( 6 )]
|
||||
|
||||
[node name="Spinner" type="Sprite" parent="Tiles"]
|
||||
[node name="Cursor" type="Sprite" parent="Tiles"]
|
||||
position = Vector2( -43, -43 )
|
||||
texture = ExtResource( 4 )
|
||||
|
|
6
src/scenes/Timer.gd
Normal file
6
src/scenes/Timer.gd
Normal file
|
@ -0,0 +1,6 @@
|
|||
extends Timer
|
||||
|
||||
|
||||
func _process(_delta):
|
||||
$Minimap/Left.position.x = (1 - time_left / wait_time) * (get_viewport().size.x / 2)
|
||||
$Minimap/Right.position.x = get_viewport().size.x - (1 - time_left / wait_time) * (get_viewport().size.x / 2)
|
|
@ -1,12 +1,15 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
[gd_scene load_steps=7 format=2]
|
||||
|
||||
[ext_resource path="res://src/music/2-atoms-sine.ogg" type="AudioStream" id=1]
|
||||
[ext_resource path="res://src/music/2-atoms-square.ogg" type="AudioStream" id=2]
|
||||
[ext_resource path="res://src/music/2-atoms-saw.ogg" type="AudioStream" id=3]
|
||||
[ext_resource path="res://src/music/2-atoms-base.ogg" type="AudioStream" id=4]
|
||||
[ext_resource path="res://src/sprites/atom.png" type="Texture" id=5]
|
||||
[ext_resource path="res://src/scenes/Timer.gd" type="Script" id=6]
|
||||
|
||||
[node name="Timer" type="Timer"]
|
||||
wait_time = 10.0
|
||||
script = ExtResource( 6 )
|
||||
|
||||
[node name="AudioBase" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 4 )
|
||||
|
@ -19,3 +22,15 @@ stream = ExtResource( 2 )
|
|||
|
||||
[node name="AudioSaw" type="AudioStreamPlayer" parent="."]
|
||||
stream = ExtResource( 3 )
|
||||
|
||||
[node name="Minimap" type="Node2D" parent="."]
|
||||
position = Vector2( 0, 16 )
|
||||
|
||||
[node name="Left" type="Sprite" parent="Minimap"]
|
||||
scale = Vector2( 0.5, 0.5 )
|
||||
texture = ExtResource( 5 )
|
||||
|
||||
[node name="Right" type="Sprite" parent="Minimap"]
|
||||
position = Vector2( 1600, 0 )
|
||||
scale = Vector2( 0.5, 0.5 )
|
||||
texture = ExtResource( 5 )
|
||||
|
|
|
@ -1,38 +1,49 @@
|
|||
extends TileMap
|
||||
|
||||
|
||||
const COLORS = {
|
||||
"R": Color.red,
|
||||
"G": Color.green,
|
||||
"B": Color.blue,
|
||||
"C": Color.cyan,
|
||||
"M": Color.magenta,
|
||||
"Y": Color.yellow,
|
||||
"W": Color.white,
|
||||
"K": Color.black,
|
||||
}
|
||||
const ATOM = preload("res://src/scenes/Atom.tscn")
|
||||
const TILE_SIZE = 86
|
||||
|
||||
|
||||
var shape setget set_shape
|
||||
var size
|
||||
var atoms = []
|
||||
|
||||
|
||||
func set_shape(val):
|
||||
|
||||
var size = len(val)
|
||||
var new_size = len(val)
|
||||
var rescale_to = clamp(6 / float(new_size), 0, 1)
|
||||
|
||||
clear()
|
||||
var offset = int(size / 2)
|
||||
var y = - offset
|
||||
atoms = []
|
||||
var y = - (new_size / 2)
|
||||
for row in val:
|
||||
var x = - offset
|
||||
var atoms_row = []
|
||||
var x = - (new_size / 2)
|
||||
for col in row:
|
||||
if col != " ":
|
||||
set_cell(x, y, 0)
|
||||
var atom = ATOM.instance()
|
||||
atom.self_modulate = COLORS[col]
|
||||
atom.position = Vector2(x * TILE_SIZE, y * TILE_SIZE)
|
||||
add_child(atom)
|
||||
atoms_row.append(atom)
|
||||
else:
|
||||
atoms_row.append(null)
|
||||
x += 1
|
||||
atoms.append(atoms_row)
|
||||
y += 1
|
||||
|
||||
var rescale_to = clamp(5 / float(size), 0, 1)
|
||||
scale = Vector2(rescale_to, rescale_to)
|
||||
|
||||
size = new_size
|
||||
shape = val
|
||||
|
||||
|
||||
const TEST = [
|
||||
"OOOOOO",
|
||||
"OOOOOO",
|
||||
"OO OO",
|
||||
"OO OO",
|
||||
"OOOOOO",
|
||||
"OOOOOO",
|
||||
]
|
||||
|
||||
|
||||
func _ready():
|
||||
set_shape(TEST)
|
||||
scale = Vector2(rescale_to, rescale_to)
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
[sub_resource type="TileSet" id=1]
|
||||
0/name = "grid-tile.png 0"
|
||||
0/texture = ExtResource( 1 )
|
||||
0/tex_offset = Vector2( 0, 0 )
|
||||
0/tex_offset = Vector2( -43, -43 )
|
||||
0/modulate = Color( 1, 1, 1, 1 )
|
||||
0/region = Rect2( 0, 0, 85, 85 )
|
||||
0/tile_mode = 0
|
||||
|
@ -20,7 +20,9 @@
|
|||
0/z_index = 0
|
||||
|
||||
[node name="Tiles" type="TileMap"]
|
||||
position = Vector2( 43, 43 )
|
||||
tile_set = SubResource( 1 )
|
||||
cell_size = Vector2( 86, 86 )
|
||||
cell_tile_origin = 1
|
||||
format = 1
|
||||
script = ExtResource( 2 )
|
||||
|
|
Loading…
Reference in a new issue