Worms bamers, zdrojáčik utešene pribúda a my testujeme prvé fičúry, aka Červíci bombíci

Worms bamers, zdrojáčik utešene pribúda a my testujeme prvé fičúry, aka Červíci bombíci

Tak dnes sa bavíme na zdrojáku Worms Bamers, postupne nám už pribúda na stránke https://hrubos.tech/repository/ á môžeme vidieť prvé animácie na obrázkoch https://hrubos.tech/repository/worms-bamers-test1.webm Samozrejme ďalšie nápady sú rozpohybovať postavičku cez AnimationPlayer na stlačenie šípok klávesnice á kúpil som si Bluetooth herný ovládač z temu_com á mohli by sme mať hru ovládanú nielen klávesnicou :)

extends CharacterBody2D
@onready var line: Line2D = $Line2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0
func _ready():
    line.clear_points()

func _input(event):
    if event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
        var click_pos: Vector2 = get_global_mouse_position()
        draw_line_to(click_pos)
        if is_click_on_static_body(click_pos):
            print(which_click_on_static_body(click_pos))
            $"../GPUParticles2D".position=click_pos

func is_click_on_static_body(world_pos: Vector2) -> bool:
    var space := get_world_2d().direct_space_state

    var query := PhysicsPointQueryParameters2D.new()
    query.position = world_pos
    query.collide_with_bodies = true
    query.collide_with_areas = false

    var result := space.intersect_point(query)

    for hit in result:
        if hit.collider is StaticBody2D:
            return true

    return false

func which_click_on_static_body(world_pos: Vector2) -> StringName:
    var space := get_world_2d().direct_space_state

    var query := PhysicsPointQueryParameters2D.new()
    query.position = world_pos
    query.collide_with_bodies = true
    query.collide_with_areas = false

    var result := space.intersect_point(query)

    for hit in result:
        if hit.collider is StaticBody2D:
            return hit.collider.name

    return ""


func draw_line_to(target_pos: Vector2):
    line.clear_points()
    line.add_point(Vector2.ZERO) # pozícia CharacterBody2D
    line.add_point(to_local(target_pos))

func _physics_process(delta: float) -> void:
    # Add the gravity.
    if not is_on_floor():
        velocity += get_gravity() * delta

    # Handle jump.
    if Input.is_action_just_pressed("ui_accept") and is_on_floor():
        velocity.y = JUMP_VELOCITY

    # Get the input direction and handle the movement/deceleration.
    # As good practice, you should replace UI actions with custom gameplay actions.
    var direction := Input.get_axis("ui_left", "ui_right")
    if direction==1.0:
        velocity.x = direction * SPEED
        $CollisionPolygon2D/Sprite2D.flip_h=true
    elif direction==-1.0:
        velocity.x = direction * SPEED
        $CollisionPolygon2D/Sprite2D.flip_h=false
    else:
        velocity.x = move_toward(velocity.x, 0, SPEED)

    move_and_slide()

Samozrejme z programátorského hľadiska sa treba zamyslieť nad TileMap a tiež nad manuálnym uložením StaticBody2D, otázka je: Dokáže TileMap definovať Statické teleso daného indexu na prienik kliknutím? Ďalej sa treba zamyslieť nad tým, ktoré SB2D sú bližšie k pištoli, to by sme mohli vyriešiť cez tzv Touching Matrix alebo obdobne, nie je to nič zložité, len sa zráta matica polôh SB2Ds á následne sa určí, ktoré je bližšie x1-x2 ku červíčkovi, aby si nemohol páliť na tie v pozadí.


Author: AarNoma

The first Slovak cyborg 1 system

Comments “Worms bamers, zdrojáčik utešene pribúda a my testujeme prvé fičúry, aka Červíci bombíci”