Skip to content

Commit

Permalink
Merge branch 'master' into navigation_astar_hexagonal
Browse files Browse the repository at this point in the history
  • Loading branch information
m21-cerutti authored Jul 13, 2024
2 parents 4fbff04 + 16d8ba0 commit 2399874
Show file tree
Hide file tree
Showing 809 changed files with 9,720 additions and 8,100 deletions.
4 changes: 2 additions & 2 deletions 2d/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
These demos are all 2D, but otherwise do not have a common theme.

Languages: Most have GDScript, some have
[GDSL](https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/shading_language.html)
[Godot shader language](https://docs.godotengine.org/en/latest/tutorials/shaders/shader_reference/shading_language.html)

Renderers: 4 of them are GLES 3, but most are GLES 2
Renderers: Glow for 2D and Physics Platformer use Forward+, 2D Particles uses Mobile, and the rest use Compatibility
4 changes: 2 additions & 2 deletions 2d/bullet_shower/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ in the documentation for more information.

Language: GDScript

Renderer: Vulkan Mobile
Renderer: Compatibility

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/887
Check out this demo on the asset library: https://godotengine.org/asset-library/asset/2711

## Screenshots

Expand Down
36 changes: 18 additions & 18 deletions 2d/bullet_shower/bullets.gd
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,28 @@ const BULLET_COUNT = 500
const SPEED_MIN = 20
const SPEED_MAX = 80

const bullet_image = preload("res://bullet.png")
const bullet_image := preload("res://bullet.png")

var bullets := []
var shape
var shape := RID()


class Bullet:
var position = Vector2()
var speed = 1.0
var position := Vector2()
var speed := 1.0
# The body is stored as a RID, which is an "opaque" way to access resources.
# With large amounts of objects (thousands or more), it can be significantly
# faster to use RIDs compared to a high-level approach.
var body = RID()
var body := RID()


func _ready():
func _ready() -> void:
shape = PhysicsServer2D.circle_shape_create()
# Set the collision shape's radius for each bullet in pixels.
PhysicsServer2D.shape_set_data(shape, 8)

for _i in BULLET_COUNT:
var bullet = Bullet.new()
var bullet := Bullet.new()
# Give each bullet its own random speed.
bullet.speed = randf_range(SPEED_MIN, SPEED_MAX)
bullet.body = PhysicsServer2D.body_create()
Expand All @@ -45,22 +45,22 @@ func _ready():
randf_range(0, get_viewport_rect().size.x) + get_viewport_rect().size.x,
randf_range(0, get_viewport_rect().size.y)
)
var transform2d = Transform2D()
var transform2d := Transform2D()
transform2d.origin = bullet.position
PhysicsServer2D.body_set_state(bullet.body, PhysicsServer2D.BODY_STATE_TRANSFORM, transform2d)

bullets.push_back(bullet)


func _process(_delta):
func _process(_delta: float) -> void:
# Order the CanvasItem to update every frame.
queue_redraw()


func _physics_process(delta):
var transform2d = Transform2D()
var offset = get_viewport_rect().size.x + 16
for bullet in bullets:
func _physics_process(delta: float) -> void:
var transform2d := Transform2D()
var offset := get_viewport_rect().size.x + 16
for bullet: Bullet in bullets:
bullet.position.x -= bullet.speed * delta

if bullet.position.x < -16:
Expand All @@ -73,15 +73,15 @@ func _physics_process(delta):

# Instead of drawing each bullet individually in a script attached to each bullet,
# we are drawing *all* the bullets at once here.
func _draw():
var offset = -bullet_image.get_size() * 0.5
for bullet in bullets:
func _draw() -> void:
var offset := -bullet_image.get_size() * 0.5
for bullet: Bullet in bullets:
draw_texture(bullet_image, bullet.position + offset)


# Perform cleanup operations (required to exit without error messages in the console).
func _exit_tree():
for bullet in bullets:
func _exit_tree() -> void:
for bullet: Bullet in bullets:
PhysicsServer2D.free_rid(bullet.body)

PhysicsServer2D.free_rid(shape)
Expand Down
14 changes: 7 additions & 7 deletions 2d/bullet_shower/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ extends Node2D
# efficient than using instancing and nodes, but requires more programming and
# is less visual. Bullets are managed together in the `bullets.gd` script.

# The number of bullets currently touched by the player.
var touching = 0
## The number of bullets currently touched by the player.
var touching := 0

@onready var sprite = $AnimatedSprite2D
@onready var sprite: AnimatedSprite2D = $AnimatedSprite2D


func _ready():
func _ready() -> void:
# The player follows the mouse cursor automatically, so there's no point
# in displaying the mouse cursor.
Input.set_mouse_mode(Input.MOUSE_MODE_HIDDEN)


func _input(event):
func _input(event: InputEvent) -> void:
# Getting the movement of the mouse so the sprite can follow its position.
if event is InputEventMouseMotion:
position = event.position - Vector2(0, 16)


func _on_body_shape_entered(_body_id, _body, _body_shape, _local_shape):
func _on_body_shape_entered(_body_id: RID, _body: Node2D, _body_shape_index: int, _local_shape_index: int) -> void:
# Player got touched by a bullet so sprite changes to sad face.
touching += 1
if touching >= 1:
sprite.frame = 1


func _on_body_shape_exited(_body_id, _body, _body_shape, _local_shape):
func _on_body_shape_exited(_body_id: RID, _body: Node2D, _body_shape_index: int, _local_shape_index: int) -> void:
touching -= 1
# When non of the bullets are touching the player,
# sprite changes to happy face.
Expand Down
11 changes: 6 additions & 5 deletions 2d/bullet_shower/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ run/main_scene="res://shower.tscn"
config/features=PackedStringArray("4.2")
config/icon="res://icon.webp"

[debug]

gdscript/warnings/untyped_declaration=1

[display]

window/stretch/mode="canvas_items"
Expand All @@ -26,10 +30,7 @@ window/stretch/aspect="expand"

2d_physics/layer_1="Player"

[physics]

2d/cell_size=64

[rendering]

renderer/rendering_method="mobile"
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
6 changes: 5 additions & 1 deletion 2d/dodge_the_creeps/HUD.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[gd_scene load_steps=4 format=3 uid="uid://ccqoreueuxdb7"]
[gd_scene load_steps=5 format=3 uid="uid://ccqoreueuxdb7"]

[ext_resource type="Script" path="res://HUD.gd" id="1"]
[ext_resource type="FontFile" uid="uid://cit6gwe5px1q8" path="res://fonts/Xolonium-Regular.ttf" id="2_2jm3i"]

[sub_resource type="InputEventAction" id="InputEventAction_fopy7"]
action = &"start_game"
Expand All @@ -16,6 +17,7 @@ anchors_preset = 10
anchor_right = 1.0
offset_bottom = 78.0
grow_horizontal = 2
theme_override_fonts/font = ExtResource("2_2jm3i")
theme_override_font_sizes/font_size = 60
text = "0"
horizontal_alignment = 1
Expand All @@ -29,6 +31,7 @@ offset_top = -79.5
offset_bottom = 79.5
grow_horizontal = 2
grow_vertical = 2
theme_override_fonts/font = ExtResource("2_2jm3i")
theme_override_font_sizes/font_size = 60
text = "Dodge the
Creeps"
Expand All @@ -46,6 +49,7 @@ offset_right = 90.0
offset_bottom = -100.0
grow_horizontal = 2
grow_vertical = 0
theme_override_fonts/font = ExtResource("2_2jm3i")
theme_override_font_sizes/font_size = 60
shortcut = SubResource("4")
text = "Start"
Expand Down
2 changes: 1 addition & 1 deletion 2d/dodge_the_creeps/Player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func start(pos):
$CollisionShape2D.disabled = false


func _on_Player_body_entered(_body):
func _on_body_entered(_body):
hide() # Player disappears after being hit.
hit.emit()
# Must be deferred as we can't change physics properties on a physics callback.
Expand Down
2 changes: 1 addition & 1 deletion 2d/dodge_the_creeps/Player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@ process_material = SubResource("7")
texture = ExtResource("2")
speed_scale = 2.0

[connection signal="body_entered" from="." to="." method="_on_Player_body_entered"]
[connection signal="body_entered" from="." to="." method="_on_body_entered"]
6 changes: 2 additions & 4 deletions 2d/dodge_the_creeps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ consider following the tutorial in the documentation.

Language: GDScript

Renderer: Vulkan Mobile
Renderer: Compatibility

Note: There is a C# version available [here](https://github.com/godotengine/godot-demo-projects/tree/master/mono/dodge_the_creeps).

Note: There is a GDNative C++ version available [here](https://github.com/godotengine/gdnative-demos/tree/master/cpp/dodge_the_creeps).

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/515
Check out this demo on the asset library: https://godotengine.org/asset-library/asset/2712

## Screenshots

Expand Down
6 changes: 0 additions & 6 deletions 2d/dodge_the_creeps/fonts/Xolonium-Regular.tres

This file was deleted.

17 changes: 7 additions & 10 deletions 2d/dodge_the_creeps/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ run/main_scene="res://Main.tscn"
config/features=PackedStringArray("4.2")
config/icon="res://icon.webp"

[debug]

gdscript/warnings/redundant_await=false

[display]

window/size/viewport_width=480
Expand All @@ -37,44 +33,45 @@ window/stretch/mode="canvas_items"
[input]

move_left={
"deadzone": 0.5,
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null)
]
}
move_right={
"deadzone": 0.5,
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"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":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null)
]
}
move_up={
"deadzone": 0.5,
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null)
]
}
move_down={
"deadzone": 0.5,
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null)
]
}
start_game={
"deadzone": 0.5,
"deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194309,"key_label":0,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":0,"echo":false,"script":null)
]
}

[rendering]

renderer/rendering_method="mobile"
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"
4 changes: 3 additions & 1 deletion 2d/dynamic_tilemap_layers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ to disable collisions per layer.

Language: GDScript

Renderer: OpenGL
Renderer: Compatibility

Check out this demo on the asset library: https://godotengine.org/asset-library/asset/2713

## Screenshots

Expand Down
23 changes: 12 additions & 11 deletions 2d/dynamic_tilemap_layers/level/tile_map.gd
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
extends TileMap


var secret_layer: int # You can have multiple layers if you make this an array.
var player_in_secret: bool
# You can have multiple layers if you make this an array.
var secret_layer := 0
var player_in_secret := false
var layer_alpha := 1.0


func _init() -> void:
for i in get_layers_count(): # Find the secret layer by name.
for i in get_layers_count():
# Find the secret layer by name.
if get_layer_name(i) == "Secret":
secret_layer = i

Expand All @@ -19,7 +19,8 @@ func _ready() -> void:
func _process(delta: float) -> void:
if player_in_secret:
if layer_alpha > 0.3:
layer_alpha = move_toward(layer_alpha, 0.3, delta) # Animate the layer transparency.
# Animate the layer transparency.
layer_alpha = move_toward(layer_alpha, 0.3, delta)
set_layer_modulate(secret_layer, Color(1, 1, 1, layer_alpha))
else:
set_process(false)
Expand All @@ -32,17 +33,17 @@ func _process(delta: float) -> void:


func _use_tile_data_runtime_update(layer: int, _coords: Vector2i) -> bool:
if layer == secret_layer:
return true
return false
return layer == secret_layer


func _tile_data_runtime_update(_layer: int, _coords: Vector2i, tile_data: TileData) -> void:
tile_data.set_collision_polygons_count(0, 0) # Remove collision for secret layer.
# Remove collision for secret layer.
tile_data.set_collision_polygons_count(0, 0)


func _on_secret_detector_body_entered(body: Node2D) -> void:
if not body is CharacterBody2D: # Detect player only.
if not body is CharacterBody2D:
# Detect the player only.
return

player_in_secret = true
Expand Down
6 changes: 3 additions & 3 deletions 2d/dynamic_tilemap_layers/player/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const WALK_MAX_SPEED = 200
const STOP_FORCE = 1300
const JUMP_SPEED = 200

@onready var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@onready var gravity: float = ProjectSettings.get_setting("physics/2d/default_gravity")

func _physics_process(delta):
func _physics_process(delta: float) -> void:
# Horizontal movement code. First, get the player's input.
var walk = WALK_FORCE * (Input.get_axis(&"move_left", &"move_right"))
var walk := WALK_FORCE * (Input.get_axis(&"move_left", &"move_right"))
# Slow down the player if they're not trying to move.
if abs(walk) < WALK_FORCE * 0.2:
# The velocity, slowed down a bit, and then reassigned.
Expand Down
Loading

0 comments on commit 2399874

Please sign in to comment.