ADD: field destruction.

main
bog 2023-09-30 15:56:43 +02:00
parent 751fe607bd
commit b913e87654
14 changed files with 105 additions and 29 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 438 B

View File

@ -4,9 +4,9 @@
[ext_resource type="Texture2D" uid="uid://blr8qcmuqs5vl" path="res://icon.svg" id="2_itibm"] [ext_resource type="Texture2D" uid="uid://blr8qcmuqs5vl" path="res://icon.svg" id="2_itibm"]
[sub_resource type="CircleShape2D" id="CircleShape2D_e2sef"] [sub_resource type="CircleShape2D" id="CircleShape2D_e2sef"]
radius = 16.0312 radius = 6.0
[node name="Actor" type="CharacterBody2D"] [node name="Actor" type="CharacterBody2D" groups=["actors"]]
script = ExtResource("1_0612w") script = ExtResource("1_0612w")
[node name="Sprite2D" type="Sprite2D" parent="."] [node name="Sprite2D" type="Sprite2D" parent="."]

View File

@ -4,9 +4,11 @@ var m_world = null
var m_target = null var m_target = null
var m_shoot_time = 2.0 var m_shoot_time = 2.0
var m_shoot_timer = 0.0 var m_shoot_timer = 0.0
var m_range = 300.0
func _ready(): func _ready():
$Actor/Sprite2D.modulate = Color.RED $Actor/Sprite2D.modulate = Color.RED
m_shoot_timer = randf_range(0.0, m_shoot_time)
func _process(delta): func _process(delta):
if m_target and $Actor.is_normal() and not m_target.get_node('Actor').is_dead(): if m_target and $Actor.is_normal() and not m_target.get_node('Actor').is_dead():
@ -14,7 +16,8 @@ func _process(delta):
var to_target = m_target.get_node('Actor').global_position - $Actor.global_position var to_target = m_target.get_node('Actor').global_position - $Actor.global_position
var dir = to_target.normalized() var dir = to_target.normalized()
var dist = to_target.length() var dist = to_target.length()
m_world.throw_bomb($Actor.global_position, dir, dist) if dist < m_range:
m_world.throw_bomb($Actor.global_position, dir, dist)
m_shoot_timer = 0.0 m_shoot_timer = 0.0
m_shoot_timer += delta m_shoot_timer += delta

View File

@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://Bear/bear.gd" id="1_yppa7"] [ext_resource type="Script" path="res://Bear/bear.gd" id="1_yppa7"]
[ext_resource type="PackedScene" uid="uid://c0kqx6dsury58" path="res://Actor/actor.tscn" id="2_6n7sl"] [ext_resource type="PackedScene" uid="uid://c0kqx6dsury58" path="res://Actor/actor.tscn" id="2_6n7sl"]
[node name="Bear" type="Node2D"] [node name="Bear" type="Node2D" groups=["bears"]]
script = ExtResource("1_yppa7") script = ExtResource("1_yppa7")
[node name="Actor" parent="." instance=ExtResource("2_6n7sl")] [node name="Actor" parent="." instance=ExtResource("2_6n7sl")]

View File

@ -30,9 +30,13 @@ func _physics_process(delta):
m_state.call(delta) m_state.call(delta)
func _explode(_delta): func _explode(_delta):
emit_signal('on_explode', self) emit_signal('on_explode', self, 1)
queue_free() queue_free()
func _moving(delta): func _moving(delta):
self.velocity = m_dir * m_speed self.velocity = m_dir * m_speed
move_and_collide(self.velocity * delta) move_and_collide(self.velocity * delta)
func _on_area_2d_area_entered(area):
pass

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=4 format=3 uid="uid://b212rruvxhwqe"] [gd_scene load_steps=5 format=3 uid="uid://b212rruvxhwqe"]
[ext_resource type="Texture2D" uid="uid://blr8qcmuqs5vl" path="res://icon.svg" id="1_ga5l4"] [ext_resource type="Texture2D" uid="uid://blr8qcmuqs5vl" path="res://icon.svg" id="1_ga5l4"]
[ext_resource type="Script" path="res://Molotov/molotov.gd" id="1_uepii"] [ext_resource type="Script" path="res://Molotov/molotov.gd" id="1_uepii"]
@ -6,6 +6,9 @@
[sub_resource type="CircleShape2D" id="CircleShape2D_oq4si"] [sub_resource type="CircleShape2D" id="CircleShape2D_oq4si"]
radius = 14.0 radius = 14.0
[sub_resource type="CircleShape2D" id="CircleShape2D_v1u5d"]
radius = 34.0147
[node name="Molotov" type="CharacterBody2D"] [node name="Molotov" type="CharacterBody2D"]
collision_layer = 0 collision_layer = 0
collision_mask = 0 collision_mask = 0
@ -18,3 +21,10 @@ texture = ExtResource("1_ga5l4")
[node name="CollisionShape2D" type="CollisionShape2D" parent="."] [node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource("CircleShape2D_oq4si") shape = SubResource("CircleShape2D_oq4si")
[node name="Area2D" type="Area2D" parent="." groups=["bombs"]]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource("CircleShape2D_v1u5d")
[connection signal="area_entered" from="Area2D" to="." method="_on_area_2d_area_entered"]

View File

@ -1,8 +1,24 @@
extends Node2D extends Node2D
func _physics_process(_dt): var m_world = null
var m_shoot_time = 0.2
var m_shoot_timer = 0.0
func _physics_process(dt):
var delta = Vector2(0, 0) var delta = Vector2(0, 0)
if Input.is_action_just_pressed("player_shoot") \
and m_shoot_timer >= m_shoot_time \
and not $Actor.is_dead():
var coord = get_global_mouse_position()
var to_mouse = coord - $Actor.global_position
var dir = to_mouse.normalized()
var dist = to_mouse.length()
m_world.throw_bomb($Actor.global_position, dir, dist)
m_shoot_timer = 0.0
m_shoot_timer += dt
if Input.is_action_pressed("player_up"): if Input.is_action_pressed("player_up"):
delta.y -= 1.0 delta.y -= 1.0
if Input.is_action_pressed("player_down"): if Input.is_action_pressed("player_down"):

View File

@ -1,21 +1,41 @@
extends Node2D extends Node2D
var m_broken_timer = 0.0
var m_broken_time = 0.2
func _ready(): func _ready():
$Bear.m_target = $Player for bear in get_tree().get_nodes_in_group('bears'):
$Bear.m_world = self bear.m_target = $Player
bear.m_world = self
$Player.m_world = self
func _process(_delta): func _process(delta):
if is_outside($Player/Actor) and $Player/Actor.is_normal(): for actor in get_tree().get_nodes_in_group('actors'):
$Player/Actor.to_falling() if is_outside(actor) and actor.is_normal():
actor.to_falling()
if is_outside($Bear/Actor) and $Bear/Actor.is_normal(): if m_broken_timer >= m_broken_time:
$Bear/Actor.to_falling() var k = 0
var N = 2
var all_cell = $TileMap.get_used_cells(0)
all_cell.shuffle()
for t in all_cell:
var data = $TileMap.get_cell_tile_data(0, t)
var type = data.get_custom_data('type')
if type == 'broken' and k < N:
$TileMap.set_cell(0, t, 0, Vector2i(1, 0))
add_broken_ground(t, 1, 0.4)
k += 1
m_broken_timer = 0.0
m_broken_timer += delta
func is_outside(actor): func is_outside(actor):
var coord = $TileMap.local_to_map(actor.global_position) var coord = $TileMap.local_to_map(actor.global_position)
var tile : TileData = $TileMap.get_cell_tile_data(0, coord) var tile : TileData = $TileMap.get_cell_tile_data(0, coord)
return tile.get_custom_data('is_void') if tile:
return tile.get_custom_data('type') == 'void'
func throw_bomb(from: Vector2, dir: Vector2, dist: float): func throw_bomb(from: Vector2, dir: Vector2, dist: float):
@ -24,12 +44,24 @@ func throw_bomb(from: Vector2, dir: Vector2, dist: float):
bomb.throw_at(from, dir, dist) bomb.throw_at(from, dir, dist)
add_child(bomb) add_child(bomb)
func _on_bomb_explode(bomb): func _on_bomb_explode(bomb, _level):
var tilemap: TileMap = $TileMap var tilemap: TileMap = $TileMap
var pos = tilemap.local_to_map(bomb.position) var pos = tilemap.local_to_map(bomb.position)
var rad = bomb.m_explosion_radius var rad = bomb.m_explosion_radius
var extra = 2
var proba = 0.6
add_broken_ground(pos, extra, proba)
for i in range(pos.y - rad, pos.y + rad ): for i in range(pos.y - rad, pos.y + rad ):
for j in range(pos.x - rad, pos.x + rad ): for j in range(pos.x - rad, pos.x + rad ):
tilemap.set_cell(0, Vector2i(j, i), 0, Vector2i(1, 0)) tilemap.set_cell(0, Vector2i(j, i), 0, Vector2i(1, 0))
func add_broken_ground(pos: Vector2i, rad, proba):
for i in range(pos.y - rad , pos.y + rad):
for j in range(pos.x - rad, pos.x + rad):
if randf() <= proba:
var data = $TileMap.get_cell_tile_data(0, Vector2i(j, i))
if data and data.get_custom_data('type') == 'ground':
$TileMap.set_cell(0, Vector2i(j, i), 0, Vector2i(2, 0))

File diff suppressed because one or more lines are too long

View File

@ -8,16 +8,21 @@ texture_region_size = Vector2i(32, 32)
0:0/0 = 0 0:0/0 = 0
0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) 0:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
0:0/0/physics_layer_0/angular_velocity = 0.0 0:0/0/physics_layer_0/angular_velocity = 0.0
0:0/0/custom_data_0 = "ground"
1:0/0 = 0 1:0/0 = 0
1:0/0/physics_layer_0/linear_velocity = Vector2(0, 0) 1:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
1:0/0/physics_layer_0/angular_velocity = 0.0 1:0/0/physics_layer_0/angular_velocity = 0.0
1:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16) 1:0/0/physics_layer_0/polygon_0/points = PackedVector2Array(-16, -16, 16, -16, 16, 16, -16, 16)
1:0/0/custom_data_0 = true 1:0/0/custom_data_0 = "void"
2:0/0 = 0
2:0/0/physics_layer_0/linear_velocity = Vector2(0, 0)
2:0/0/physics_layer_0/angular_velocity = 0.0
2:0/0/custom_data_0 = "broken"
[resource] [resource]
tile_size = Vector2i(32, 32) tile_size = Vector2i(32, 32)
physics_layer_0/collision_layer = 0 physics_layer_0/collision_layer = 0
physics_layer_0/collision_mask = 0 physics_layer_0/collision_mask = 0
custom_data_layer_0/name = "is_void" custom_data_layer_0/name = "type"
custom_data_layer_0/type = 1 custom_data_layer_0/type = 4
sources/0 = SubResource("TileSetAtlasSource_0k0yx") sources/0 = SubResource("TileSetAtlasSource_0k0yx")

Binary file not shown.

Before

Width:  |  Height:  |  Size: 172 B

After

Width:  |  Height:  |  Size: 438 B

0
src/export_presets.cfg Normal file
View File

View File

@ -37,6 +37,11 @@ player_right={
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null)
] ]
} }
player_shoot={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":0,"position":Vector2(0, 0),"global_position":Vector2(0, 0),"factor":1.0,"button_index":1,"canceled":false,"pressed":false,"double_click":false,"script":null)
]
}
[rendering] [rendering]