Update test project for Godot 4.3 (#159)

Co-authored-by: Andi Susanto <and1zero@users.noreply.github.com>
Co-authored-by: Hugo Locurcio <hugo.locurcio@hugo.pro>
This commit is contained in:
Andi Susanto
2024-10-24 05:06:47 +08:00
committed by GitHub
parent dd1db58f33
commit 9a460209d7
25 changed files with 876 additions and 522 deletions

14
test-project/scripts/Cannon.gd Executable file → Normal file
View File

@@ -1,6 +1,6 @@
extends "res://scripts/ColoredEntity.gd"
onready var Bullet: PackedScene = preload("res://scenes/Projectile.tscn")
@onready var Bullet: PackedScene = preload("res://scenes/Projectile.tscn")
const RATE_OF_CHANGE: float = 0.9
const UPPER_LIMIT: int = -89
const LOWER_LIMIT: int = -5
@@ -11,8 +11,8 @@ func _ready():
self.highlight()
func _process(delta):
$Sprite.set_rotation(deg2rad(self.angle))
$Sprite.rect_size.y = 24
$Sprite2D.set_rotation(deg_to_rad(self.angle))
$Sprite2D.size.y = 24
func _input(event):
if Input.is_action_pressed("ui_up"):
@@ -30,10 +30,10 @@ func move_down() -> void:
func shoot() -> void:
if $FireCooldown.time_left == 0:
var NewBullet = Bullet.instance()
NewBullet.global_position = $Sprite/CannonTip.global_position
var NewBullet = Bullet.instantiate()
NewBullet.global_position = $Sprite2D/CannonTip.global_position
NewBullet.rotation_degrees = self.angle
var at: Vector2 = $Sprite/CannonTip.global_position - $Sprite/CannonBase.global_position
var at: Vector2 = $Sprite2D/CannonTip.global_position - $Sprite2D/CannonBase.global_position
NewBullet.shoot(at)
var BulletSprite = NewBullet.get_node("Mask")
@@ -42,7 +42,7 @@ func shoot() -> void:
else:
BulletSprite.lowlight()
NewBullet.setup(GLOBAL.BULLET, GLOBAL.BULLET_SPEED)
NewBullet.setup(GLOBAL.SpriteType.BULLET, GLOBAL.BULLET_SPEED)
NewBullet.update_collision_layer()
$Projectiles.add_child(NewBullet)
$FireCooldown.start()

10
test-project/scripts/EnemyGenerator.gd Executable file → Normal file
View File

@@ -1,6 +1,6 @@
extends Node2D
onready var EnemyScene: PackedScene = preload("res://scenes/Projectile.tscn")
@onready var EnemyScene: PackedScene = preload("res://scenes/Projectile.tscn")
signal start
signal stop
@@ -11,16 +11,16 @@ func _ready():
self.emit_signal("stop")
func setup_enemy() -> void:
self.Enemy = EnemyScene.instance()
Enemy.setup(GLOBAL.MISSILE, GLOBAL.MISSILE_SPEED["max"])
self.Enemy = EnemyScene.instantiate()
Enemy.setup(GLOBAL.SpriteType.MISSILE, GLOBAL.MISSILE_SPEED["max"])
func spawn_and_shoot_enemy() -> void:
var Duplicate = Enemy.duplicate(Node.DUPLICATE_USE_INSTANCING)
var Duplicate = Enemy.duplicate(Node.DUPLICATE_USE_INSTANTIATION)
Duplicate.set_random_color()
Duplicate.update_collision_layer()
$Enemies.add_child(Duplicate)
$SpawnArea/SpawnLocation.set_offset(randi())
$SpawnArea/SpawnLocation.set_h_offset(randi())
Duplicate.global_position = $SpawnArea/SpawnLocation.position
var direction: Vector2 = (Vector2(0, 1080) - Duplicate.global_position).normalized()

View File

@@ -5,7 +5,7 @@ signal start_zoom_out
const ZOOM_DELTA: float = 0.2
const MOVE_DELTA: float = 0.353
onready var camera: Camera2D = $Path2D/PathFollow2D/MenuCamera
@onready var camera: Camera2D = $Path2D/PathFollow2D/MenuCamera
var camera_zooming: bool = false
func _process(delta: float):
@@ -19,7 +19,7 @@ func zoom_out_proccess(delta: float) -> void:
else:
self.camera_zooming = false
$Path2D/PathFollow2D.unit_offset += delta * MOVE_DELTA
$Path2D/PathFollow2D.progress_ratio += delta * MOVE_DELTA
func _on_Main_start_zoom_out():
self.camera_zooming = true

32
test-project/scripts/Projectile.gd Executable file → Normal file
View File

@@ -1,7 +1,7 @@
extends RigidBody2D
var MissileSprite: Texture = load("res://resources/img/missile-placeholder.png")
var BulletSprite: Texture = load("res://resources/img/bullet-placeholder.png")
var MissileSprite: Texture2D = load("res://resources/img/missile-placeholder.png")
var BulletSprite: Texture2D = load("res://resources/img/bullet-placeholder.png")
var bodies_in_area: Array = []
var sprite_type: int
@@ -10,20 +10,20 @@ var armed: bool = false
func _ready():
self.gravity_scale = 0.0
self.friction = 0
self.physics_material_override.friction = 0.0
self.contact_monitor = true
self.contacts_reported = 1
self.max_contacts_reported = 1
func setup(sprite_type: int, speed: float) -> void:
self.sprite_type = sprite_type
self.speed = speed
if sprite_type == GLOBAL.BULLET:
$Mask/Sprite.set_texture(self.BulletSprite)
if sprite_type == GLOBAL.SpriteType.BULLET:
$Mask/Sprite2D.set_texture(self.BulletSprite)
self.armed = true
$ExplosionArea/ExplosionShape.disabled = false
else:
$Mask/Sprite.set_texture(self.MissileSprite)
$Mask/Sprite2D.set_texture(self.MissileSprite)
func shoot(at: Vector2) -> void:
var direction = (at - self.global_position)
@@ -31,22 +31,22 @@ func shoot(at: Vector2) -> void:
func shoot_missile(at: Vector2) -> void:
var direction = (at - self.global_position)
self.add_central_force(at * GLOBAL.MISSILE_SPEED["max"])
self.apply_central_force(at * GLOBAL.MISSILE_SPEED["max"])
func set_random_color() -> void:
$Mask.set_random_color()
func update_collision_layer() -> void:
if $Mask.highlighted:
self.set_collision_layer_bit(GLOBAL.HIGH_COLLISION, 1)
self.set_collision_mask_bit(GLOBAL.HIGH_COLLISION, 1)
$ExplosionArea.set_collision_layer_bit(GLOBAL.HIGH_COLLISION, 1)
$ExplosionArea.set_collision_mask_bit(GLOBAL.HIGH_COLLISION, 1)
self.set_collision_layer_value(GLOBAL.HIGH_COLLISION, 1)
self.set_collision_mask_value(GLOBAL.HIGH_COLLISION, 1)
$ExplosionArea.set_collision_layer_value(GLOBAL.HIGH_COLLISION, 1)
$ExplosionArea.set_collision_mask_value(GLOBAL.HIGH_COLLISION, 1)
else:
self.set_collision_layer_bit(GLOBAL.LOW_COLLISION, 1)
self.set_collision_mask_bit(GLOBAL.LOW_COLLISION, 1)
$ExplosionArea.set_collision_layer_bit(GLOBAL.LOW_COLLISION, 1)
$ExplosionArea.set_collision_mask_bit(GLOBAL.LOW_COLLISION, 1)
self.set_collision_layer_value(GLOBAL.LOW_COLLISION, 1)
self.set_collision_mask_value(GLOBAL.LOW_COLLISION, 1)
$ExplosionArea.set_collision_layer_value(GLOBAL.LOW_COLLISION, 1)
$ExplosionArea.set_collision_mask_value(GLOBAL.LOW_COLLISION, 1)
# --- Signals ---