From 4bb970187d0e127b9813ba9c5780668696fc17ee Mon Sep 17 00:00:00 2001 From: Nitsud Yarg Date: Thu, 25 Apr 2024 20:49:45 -0700 Subject: [PATCH] More Cleanup --- KinematicBody2D-bak.gd | 98 ------------------ Main.tscn | 2 +- Smiley.png | Bin 508 -> 0 bytes Smiley.png.import | 35 ------- project.godot | 10 +- .../CameraControl-Position2D.gd | 0 Projectile.gd => src/Projectile.gd | 0 Projectile.tscn => src/Projectile.tscn | 8 +- .../enemy/Enemy-KinematicBody2D.gd | 0 Enemy.tscn => src/enemy/Enemy.tscn | 2 +- src/enemyB/Enemy2.tscn | 14 +-- src/{states/enemy => enemyB/states}/attack.gd | 0 src/{states/enemy => enemyB/states}/fall.gd | 0 src/{states/enemy => enemyB/states}/hurt.gd | 0 src/{states/enemy => enemyB/states}/idle.gd | 0 src/{states/enemy => enemyB/states}/jump.gd | 0 src/{states/enemy => enemyB/states}/move.gd | 0 src/{states/enemy => enemyB/states}/wander.gd | 0 src/playerB/Gun.gd | 2 +- wander.gd | 61 ----------- 20 files changed, 19 insertions(+), 213 deletions(-) delete mode 100644 KinematicBody2D-bak.gd delete mode 100644 Smiley.png delete mode 100644 Smiley.png.import rename Position2D.gd => src/CameraControl-Position2D.gd (100%) rename Projectile.gd => src/Projectile.gd (100%) rename Projectile.tscn => src/Projectile.tscn (79%) rename Enemy-KinematicBody2D.gd => src/enemy/Enemy-KinematicBody2D.gd (100%) rename Enemy.tscn => src/enemy/Enemy.tscn (97%) rename src/{states/enemy => enemyB/states}/attack.gd (100%) rename src/{states/enemy => enemyB/states}/fall.gd (100%) rename src/{states/enemy => enemyB/states}/hurt.gd (100%) rename src/{states/enemy => enemyB/states}/idle.gd (100%) rename src/{states/enemy => enemyB/states}/jump.gd (100%) rename src/{states/enemy => enemyB/states}/move.gd (100%) rename src/{states/enemy => enemyB/states}/wander.gd (100%) delete mode 100644 wander.gd diff --git a/KinematicBody2D-bak.gd b/KinematicBody2D-bak.gd deleted file mode 100644 index ae69061..0000000 --- a/KinematicBody2D-bak.gd +++ /dev/null @@ -1,98 +0,0 @@ -extends KinematicBody2D - -enum STATE {IDLE, RUN, JUMP, FALL, HURT} -enum STATE_SECONDARY {NONE, SHOOT} - -class StateMachine: - var primary = STATE.IDLE - var secondary = STATE_SECONDARY.NONE - -onready var player_state = StateMachine.new() -onready var player_last_state = StateMachine.new() - -# Declare member variables here. Examples: -# var a = 2 -# var b = "text" -onready var gravity = 60*9.8 - -onready var speed = Vector2((30*5), (gravity * 1/2)) -#onready var gravity = ProjectSettings.get("physics/2d/default_gravity") - -onready var _animated_sprite = $AnimatedSprite - -var velocity = Vector2.ZERO - - -# Called when the node enters the scene tree for the first time. -func _ready(): - pass # Replace with function body. - - -func get_direction(): - return Vector2( - Input.get_axis("ui_left", "ui_right"), - -1 if is_on_floor() and Input.is_action_just_pressed("ui_accept") else 0 - ) - -func calculate_move_velocity( - linear_velocity, - direction, - speed - ): - var velocity = linear_velocity - velocity.x = speed.x * direction.x - if direction.y != 0.0: - velocity.y = speed.y * direction.y - return velocity - - -# Called every frame. 'delta' is the elapsed time since the previous frame. -func _physics_process(delta): - var direction = get_direction() -# if not is_on_floor(): -# velocity.y += gravity * delta -# -# # Handle jump. -# if Input.is_action_just_pressed("ui_accept") and is_on_floor(): -# velocity.y += (gravity * -1) * delta -# -# # 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: -# velocity.x = direction * SPEED -# else: -# velocity.x = move_toward(velocity.x, 0, SPEED) - velocity = calculate_move_velocity(velocity, direction, speed) - move_and_slide(velocity, Vector2(0, -1)) - # Apply Gravity - velocity.y += gravity * delta - - #Animation - - if direction.x > 0 and _animated_sprite.flip_h != true: - _animated_sprite.flip_h = true - if direction.x < 0 and _animated_sprite.flip_h != false: - _animated_sprite.flip_h = false - - - player_state.primary = STATE.IDLE - - match player_state.primary: - STATE.IDLE: - if direction.y == 0: - player_state.primary = STATE.FALL - STATE.FALL: - print("Fall") - STATE.RUN: - print("Idle") - - if not is_on_floor(): - if _animated_sprite.animation != "jump": - _animated_sprite.play("jump") - else: - if direction and _animated_sprite.animation != "run": - print(_animated_sprite.animation, direction) - _animated_sprite.play("run") - elif not direction: - _animated_sprite.play("idle") diff --git a/Main.tscn b/Main.tscn index 30ecb3a..5362bf4 100644 --- a/Main.tscn +++ b/Main.tscn @@ -2,7 +2,7 @@ [ext_resource path="res://src/playerB/Player.tscn" type="PackedScene" id=1] [ext_resource path="res://assets/Tiles/Assets/Assets.png" type="Texture" id=3] -[ext_resource path="res://Position2D.gd" type="Script" id=5] +[ext_resource path="res://src/CameraControl-Position2D.gd" type="Script" id=5] [ext_resource path="res://src/enemyB/Enemy2.tscn" type="PackedScene" id=6] [sub_resource type="ConvexPolygonShape2D" id=2] diff --git a/Smiley.png b/Smiley.png deleted file mode 100644 index 88a0ca8bdfb9e5473ebfbaade72a6116f219f191..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 508 zcmVPx$wn;=mRCt{2o6T{BDuT3)hq`Qb+no1HSqoUnGyl!|ww61b*)- zi3jX}1{O{y00000fZdr2zMUJC`Evf;%08q&|KH9RE?>VTn0<}*v2@0v{i&79?);TXLC9|WN~It)^QTnI-1#eoK`=Ldr7#Fh{ckb3 ztMi}c`RMbd4Bt;H=yx^#X`YQfU&=V7KNbLJOeg@wQ_mK|C@3EKTMVOM7e6CF3;_^h z3P5aXsyTJJh)oSOr;gTsMt~RsAcg>l2?bz^Ex2+ptcIu9f+q*VYS`rWedF`LXB#$n zR=m65YiR2qaBV+(L1I6;;Ma=H1Xyb|cmP ztbD+T`|)ajaz<>_jFj4+loK8~C#&{H?+1*2K40zUV3wHR{eV|EpRe{a0>lsiF{S{F zbUt70X9S2L0AiX1pysjiqxn?bGOuO9#aI_C}r*le~xXlL&L0000 State: - if move_component.wants_jump() and parent.is_on_floor(): - return jump_state - - move_component.get_movement_direction() - - return null - - -func process_physics(delta: float) -> State: -# if move_component.wants_jump() and parent.is_on_floor(): -# return jump_state - - parent.velocity.y += gravity * delta - -# var movement = move_component.get_movement_direction() * move_speed -# -# # only detecting input not actual movement -# if movement == 0: -# return idle_state - -# parent.velocity.x = movement -# parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) - - parent.velocity.x = move_component.desired_movement_vector.x * move_speed - parent.velocity = parent.move_and_slide(parent.velocity, Vector2(0, -1)) - - if parent.velocity.x == 0.0: - return idle_state - else: - if parent.velocity.x > 0: - parent.direction.x = 1 - elif parent.velocity.x < 0: - parent.direction.x = -1 - - - if move_component.flipped_sprite == true: - animations.flip_h = parent.direction.x > 0 - else: - animations.flip_h = parent.direction.x < 0 - - - # Another approach of changing state based on actual achieved velocity -# if parent.velocity.x == 0: -# return idle_state - - if !parent.is_on_floor(): - return fall_state - return null