1
Fork 0
mirror of https://github.com/Steffo99/particle-clash.git synced 2024-11-21 23:24:18 +00:00

Create cursor and grid

This commit is contained in:
Steffo 2022-10-01 22:39:27 +02:00
parent db279643a5
commit b7d6a0305f
Signed by: steffo
GPG key ID: 6965406171929D01
6 changed files with 235 additions and 52 deletions

View file

@ -21,6 +21,59 @@ window/size/width=1600
window/size/height=900
window/size/resizable=false
[input]
p1_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":87,"unicode":0,"echo":false,"script":null)
]
}
p1_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":68,"unicode":0,"echo":false,"script":null)
]
}
p1_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":83,"unicode":0,"echo":false,"script":null)
]
}
p1_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":65,"unicode":0,"echo":false,"script":null)
]
}
p1_rotate={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":32,"unicode":0,"echo":false,"script":null)
]
}
p2_up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777232,"unicode":0,"echo":false,"script":null)
]
}
p2_right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777233,"unicode":0,"echo":false,"script":null)
]
}
p2_down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777234,"unicode":0,"echo":false,"script":null)
]
}
p2_left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777231,"unicode":0,"echo":false,"script":null)
]
}
p2_rotate={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":0,"physical_scancode":16777221,"unicode":0,"echo":false,"script":null)
]
}
[physics]
common/enable_pause_aware_picking=true

View file

@ -10,29 +10,35 @@
script = ExtResource( 1 )
[node name="Background" parent="." instance=ExtResource( 2 )]
modulate = Color( 0, 0.294118, 0.196078, 1 )
modulate = Color( 0, 0.31, 0, 1 )
[node name="Play Area" parent="." instance=ExtResource( 3 )]
self_modulate = Color( 0, 0.34902, 0.329412, 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="Tiles" parent="Play Area" index="0"]
self_modulate = Color( 0, 0.34902, 0.329412, 1 )
[node name="Spinner" parent="Left Play Area/Tiles" index="0"]
modulate = Color( 1, 0.5, 0.5, 1 )
[node name="Atom" parent="Play Area/Atoms" index="0"]
modulate = Color( 0, 1, 1, 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="Play Area" index="2"]
modulate = Color( 0, 1, 0.658824, 1 )
[node name="Label" parent="Play Area" index="3"]
modulate = Color( 0, 1, 0.658824, 1 )
[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( 0, 1, 0.658824, 1 )
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="Play Area"]
[editable path="Left Play Area"]
[editable path="Right Play Area"]
[editable path="Minimap"]

85
src/scenes/Play Area.gd Normal file
View file

@ -0,0 +1,85 @@
extends Sprite
const TILE_SIZE = 86
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)
cursor_pos = val
func cursor_would_collide(top_left: Vector2):
var shape = $Tiles.shape
var size_x = len(shape) - 1
var size_y = len(shape[0]) - 1
return \
top_left.x < 0 || \
top_left.y < 0 || \
top_left.x >= size_x || \
top_left.y >= size_y || \
shape[top_left.x][top_left.y] == " " || \
shape[top_left.x+1][top_left.y] == " " || \
shape[top_left.x][top_left.y+1] == " " || \
shape[top_left.x+1][top_left.y+1] == " "
func cursor_init():
var shape = $Tiles.shape
var y = 0
while y < len(shape):
var x = 0
while x < len(shape[y]):
var new_pos = Vector2(x, y)
if not cursor_would_collide(new_pos):
print("Found location for cursor @ %d, %d" % [new_pos.x, new_pos.y])
set_cursor_pos(new_pos)
return
x += 1
y += 1
push_error("Could not find a valid position for the cursor")
get_tree().quit()
func cursor_up():
cursor_move(Vector2(cursor_pos.x, cursor_pos.y - 1))
func cursor_right():
cursor_move(Vector2(cursor_pos.x + 1, cursor_pos.y))
func cursor_down():
cursor_move(Vector2(cursor_pos.x, cursor_pos.y + 1))
func cursor_left():
cursor_move(Vector2(cursor_pos.x - 1, cursor_pos.y))
func cursor_move(dest):
if not cursor_would_collide(dest):
set_cursor_pos(dest)
else:
print("Cursor collided @ %d, %d" % [dest.x, dest.y])
func cursor_rotate():
pass
export(String) var player
func _process(_delta):
if Input.is_action_just_pressed(player + "_up"):
cursor_up()
if Input.is_action_just_pressed(player + "_right"):
cursor_right()
if Input.is_action_just_pressed(player + "_down"):
cursor_down()
if Input.is_action_just_pressed(player + "_left"):
cursor_left()
if Input.is_action_just_pressed(player + "_rotate"):
cursor_rotate()
func _ready():
cursor_init()

View file

@ -1,26 +1,10 @@
[gd_scene load_steps=9 format=2]
[gd_scene load_steps=8 format=2]
[ext_resource path="res://src/sprites/huge-atom.png" type="Texture" id=1]
[ext_resource path="res://src/sprites/grid-tile.png" type="Texture" id=2]
[ext_resource path="res://src/sprites/atom.png" type="Texture" id=3]
[ext_resource path="res://src/scenes/Play Area.gd" type="Script" id=2]
[ext_resource path="res://src/sprites/spinner.png" type="Texture" id=4]
[ext_resource path="res://src/fonts/Xolonium-Bold.ttf" type="DynamicFontData" id=5]
[sub_resource type="TileSet" id=1]
0/name = "grid-tile.png 0"
0/texture = ExtResource( 2 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 85, 85 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape_one_way = false
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
[ext_resource path="res://src/scenes/tiles/Tiles.tscn" type="PackedScene" id=6]
[sub_resource type="DynamicFont" id=2]
size = 48
@ -30,24 +14,8 @@ font_data = ExtResource( 5 )
default_font = SubResource( 2 )
[node name="Play Area" type="Sprite"]
position = Vector2( 400, 450 )
texture = ExtResource( 1 )
[node name="Tiles" type="TileMap" parent="."]
tile_set = SubResource( 1 )
cell_size = Vector2( 86, 86 )
format = 1
tile_data = PoolIntArray( -131074, 0, 0, -131073, 0, 0, -196608, 0, 0, -196607, 0, 0, -65539, 0, 0, -65538, 0, 0, -65537, 0, 0, -131072, 0, 0, -131071, 0, 0, -131070, 0, 0, -3, 0, 0, -2, 0, 0, -1, 0, 0, -65536, 0, 0, -65535, 0, 0, -65534, 0, 0, 65533, 0, 0, 65534, 0, 0, 65535, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 131069, 0, 0, 131070, 0, 0, 131071, 0, 0, 65536, 0, 0, 65537, 0, 0, 65538, 0, 0, 196606, 0, 0, 196607, 0, 0, 131072, 0, 0, 131073, 0, 0 )
[node name="Atoms" type="Node2D" parent="."]
[node name="Atom" type="Sprite" parent="Atoms"]
position = Vector2( 43, -215 )
texture = ExtResource( 3 )
[node name="Spinner" type="Sprite" parent="."]
position = Vector2( -87, -173 )
texture = ExtResource( 4 )
script = ExtResource( 2 )
[node name="Label" type="Label" parent="."]
anchor_left = 0.5
@ -55,8 +23,15 @@ anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -407.0
margin_top = -32.0
margin_top = -8.0
margin_right = -335.0
margin_bottom = -342.0
margin_bottom = 50.0
theme = SubResource( 3 )
text = "32"
align = 1
valign = 2
[node name="Tiles" parent="." instance=ExtResource( 6 )]
[node name="Spinner" type="Sprite" parent="Tiles"]
texture = ExtResource( 4 )

38
src/scenes/tiles/Tiles.gd Normal file
View file

@ -0,0 +1,38 @@
extends TileMap
var shape setget set_shape
func set_shape(val):
var size = len(val)
clear()
var offset = int(size / 2)
var y = - offset
for row in val:
var x = - offset
for col in row:
if col != " ":
set_cell(x, y, 0)
x += 1
y += 1
var rescale_to = clamp(5 / float(size), 0, 1)
scale = Vector2(rescale_to, rescale_to)
shape = val
const TEST = [
"OOOOOO",
"OOOOOO",
"OO OO",
"OO OO",
"OOOOOO",
"OOOOOO",
]
func _ready():
set_shape(TEST)

View file

@ -0,0 +1,26 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://src/sprites/grid-tile.png" type="Texture" id=1]
[ext_resource path="res://src/scenes/tiles/Tiles.gd" type="Script" id=2]
[sub_resource type="TileSet" id=1]
0/name = "grid-tile.png 0"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 0, 85, 85 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape_one_way = false
0/shape_one_way_margin = 0.0
0/shapes = [ ]
0/z_index = 0
[node name="Tiles" type="TileMap"]
tile_set = SubResource( 1 )
cell_size = Vector2( 86, 86 )
format = 1
script = ExtResource( 2 )