From f1d7c8968a1ef8161915f16633efa1e29b0aa385 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 4 Nov 2025 21:24:54 -0500 Subject: [PATCH] Refactored a bit. Punching improved, for example --- graphics/animations/Player Jab 48x48.png | Bin 0 -> 1770 bytes .../animations/Player Jab 48x48.png.import | 40 +++++++ project.godot | 2 +- scenes/game.tscn | 9 +- scenes/level_2.tscn | 8 +- scenes/level_3.tscn | 8 +- scenes/player.tscn | 36 +++++-- scripts/player.gd | 100 +++++++++++------- 8 files changed, 138 insertions(+), 65 deletions(-) create mode 100644 graphics/animations/Player Jab 48x48.png create mode 100644 graphics/animations/Player Jab 48x48.png.import diff --git a/graphics/animations/Player Jab 48x48.png b/graphics/animations/Player Jab 48x48.png new file mode 100644 index 0000000000000000000000000000000000000000..0ace3f07353365d380faf6f75381970c00cf8e5c GIT binary patch literal 1770 zcma)7dpO%!8vcp4_F*D=qs63+GHP14Y4zrkP!+0f868u)jmD}*Cc?A`BB{}$EmP4h zolYxM#JCi#T#!bl-73?@ATH4u4T6jYk;*0rv00tY{I}13f1Gok=X~#X&U@bTyx;ZE zU?kYs(ii{$aDcxr3IGg7^=p^EZPJgwJg7F+PX?DzNFSj7SLo`F@A(ph`2C(X&!pRnLzcs91PA*BWGu z-(85p!g$-JAML((aIdi6C&sd(An!BR-WR{C%p_wYOPr>rrUkE%l}toyt9&kXO|bCm zDU7k%=Kn8x4?N#D9=z<-b?+wmw^f=avnnqaW^<#*i!!7reywAG6#J|Ry1K#>rT#bD z0-LrEKYw#PBOGsdQp@VzrRGl3DS_UatroP&V-LeKOD<$;OXQ{TL4ciIGJuTK2KFhuS)GYb^5?qU^2s&!UR z`1KSc()fxuFi&k96Hh@Ub;K=2cKXs1o(ZrRGa>JkRI}$T;ntqA!|9vr2O-~(np;bq z>dxFzzC9iFiPz$URX!N9!F>aY?szUKSYfHM1KU1Y70V#nk)j^-0?30{Vc)!>5jgIL z6YmnE4!9JwbR5QI9*Gm?6s18M+IY1B`n_Rk-zeWuhH-TkIGq$NEjar2TeGBYqeAW#>@0^XdD_&6^VAT= z&oP)OG4ID+cOfR+^stvYDva87=ueGl8PX@xu8rD&ua(cF{-mwX1uh^J*cOpW5&8g~ z2@w8Nd3W1T!tt0t6jRBT&-5fIfkw@QJ7A-v4hO_SY$`H&?u&L0rpVk8()U0fL61t| zx(*CGs}~v`qqQsN`B6p7mmGg~<`b>_^G>=49T^y=$;M7nnM7=P3mo5(wfEFtS>1Sa zdzQL3DI%?WP3$|n@pNC(V!pkyKkBQ#H8wVu!IPMCq`T8#jj`C0%iDG`DnD=%F5{pH zAv8oI%&FmEhA2*RO{yn->slrEZi^e9z=Q(UpWf1;ubxd~4sBQAaV=)r^!${RO`N00 zyqw~_d&GoP^r{^3E{vBcopB7`v`7|WK9gFTuk$cT zoGA1#49oBq8x^W`=|fe=-7u7qbyu{j;m_?E#XDM{8cNs};RQ;l3oFVRq46 j)Z9uQE$@HD4GkP#5ehtRIx?tlUO>Q!VBdP5= void: facing = FaceDirection.RIGHT # Handle shoving. - if Input.is_action_just_pressed("shove"): - print_debug("Shoving!") - if push_enabled == true: - var shove_direction : int + if Input.is_action_just_pressed("punch"): + print_debug("Trying to punch") + if punch_enabled == true: + print_debug("Punching enabled") + var punch_direction : int match facing: FaceDirection.RIGHT: - shove_direction = 1 + punch_direction = 1 FaceDirection.LEFT: - shove_direction = -1 - print_debug("Shoving %s" % push_target.name) - current_state = State.SHOVE - push_target.apply_central_impulse(Vector2(shove_direction, 0) * SHOVE_POWER) + punch_direction = -1 + print_debug("Punching %s" % punch_target.name) + current_state = State.PUNCH + punch_target.apply_central_impulse(Vector2(punch_direction, 0) * PUNCH_POWER) # Handle shooting if Input.is_action_just_pressed("shoot"): @@ -118,10 +131,10 @@ func handle_movement(delta) -> void: # Character is jumping; apply normal gravity velocity += get_gravity() * delta if velocity.y > 0: - current_state = State.FALLING + current_state = State.FALL else: # Character falling; apply hard gravity - current_state = State.FALLING + current_state = State.FALL velocity += get_gravity() * HARD_GRAVITY * delta func handle_collisions() -> void: @@ -132,46 +145,51 @@ func handle_collisions() -> void: c.get_collider().apply_central_impulse(-c.get_normal() * BUMP_POWER) if right_cast.is_colliding() and facing == FaceDirection.RIGHT: + #print_debug("Colliding with something to the right") var collider = right_cast.get_collider() - # check if this is OK - if collider is Node and collider is RigidBody2D and collider.is_in_group("pushable"): - push_target = collider - push_enabled = true + #print_debug("Colliding with %s " % collider.name) + if collider is Node and collider is RigidBody2D and collider.is_in_group("punchable"): + print_debug("We have a punch target") + punch_target = collider + punch_enabled = true if left_cast.is_colliding() and facing == FaceDirection.LEFT: + #print_debug("Colliding with something to the left") var collider = left_cast.get_collider() - if collider is Node and collider is RigidBody2D and collider.is_in_group("pushable"): - push_target = collider - push_enabled = true + #print_debug("Colliding with %s " % collider.name) + if collider is Node and collider is RigidBody2D and collider.is_in_group("punchable"): + print_debug("We have a punch target") + punch_target = collider + punch_enabled = true if not right_cast.is_colliding() and not left_cast.is_colliding(): - push_enabled = false + punch_enabled = false func update_state() -> void: match current_state: # If player is moving left or right State.IDLE when velocity.x !=0: - current_state = State.WALK + current_state = State.RUN # If player stops walking, or starts falling - State.WALK: + State.RUN: # If not moving left or right if velocity.x == 0: current_state = State.IDLE # If falling if not is_on_floor() and velocity.y > 0: - current_state = State.FALLING + current_state = State.FALL # When jump peaks, we start to fall State.JUMP when velocity.y > 0: - current_state = State.FALLING + current_state = State.FALL # Player lands, either still or moving - State.FALLING when is_on_floor(): + State.FALL when is_on_floor(): if velocity.x == 0: current_state = State.IDLE else: - current_state = State.WALK + current_state = State.RUN # Player shooting State.SHOOT_STILL: @@ -181,10 +199,10 @@ func update_state() -> void: # Player shooting while moving State.SHOOT_RUN: await player_sprite.animation_finished - current_state = State.WALK + current_state = State.RUN # Player shoving - State.SHOVE: + State.PUNCH: await player_sprite.animation_finished current_state = State.IDLE @@ -197,18 +215,18 @@ func update_animation() -> void: match current_state: State.IDLE: player_sprite.play("idle") - State.WALK: + State.RUN: player_sprite.play("run") State.JUMP: player_sprite.play("jump") - State.FALLING: + State.FALL: player_sprite.play("fall") State.SHOOT_STILL: player_sprite.play("shoot_still") State.SHOOT_RUN: player_sprite.play("shoot_run") - State.SHOVE: + State.PUNCH: player_sprite.play("punch") func update_debug(): - %StateLabel.text = "Current state: %s" % current_state + %StateLabel.text = "Current state: %s" % State.keys()[current_state]