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 88a0ca8..0000000 Binary files a/Smiley.png and /dev/null differ diff --git a/Smiley.png.import b/Smiley.png.import deleted file mode 100644 index 297364a..0000000 --- a/Smiley.png.import +++ /dev/null @@ -1,35 +0,0 @@ -[remap] - -importer="texture" -type="StreamTexture" -path="res://.import/Smiley.png-21025cc2924b94a90cc7095293287091.stex" -metadata={ -"vram_texture": false -} - -[deps] - -source_file="res://Smiley.png" -dest_files=[ "res://.import/Smiley.png-21025cc2924b94a90cc7095293287091.stex" ] - -[params] - -compress/mode=0 -compress/lossy_quality=0.7 -compress/hdr_mode=0 -compress/bptc_ldr=0 -compress/normal_map=0 -flags/repeat=0 -flags/filter=false -flags/mipmaps=false -flags/anisotropic=false -flags/srgb=2 -process/fix_alpha_border=true -process/premult_alpha=false -process/HDR_as_SRGB=false -process/invert_color=false -process/normal_map_invert_y=false -stream=false -size_limit=0 -detect_3d=true -svg/scale=1.0 diff --git a/project.godot b/project.godot index a0bd2e1..b273654 100644 --- a/project.godot +++ b/project.godot @@ -12,24 +12,24 @@ _global_script_classes=[ { "base": "KinematicBody2D", "class": "Enemy", "language": "GDScript", -"path": "res://Enemy-KinematicBody2D.gd" +"path": "res://src/enemy/Enemy-KinematicBody2D.gd" }, { -"base": "KinematicBody2D", +"base": "Reference", "class": "Enemy2", "language": "GDScript", "path": "res://src/enemyB/Enemy2-KinematicBody2D.gd" }, { -"base": "Reference", +"base": "Position2D", "class": "Gun", "language": "GDScript", "path": "res://src/playerB/Gun.gd" }, { -"base": "Node", +"base": "Reference", "class": "Movement", "language": "GDScript", "path": "res://src/playerB/player_move_component.gd" }, { -"base": "KinematicBody2D", +"base": "Reference", "class": "Player", "language": "GDScript", "path": "res://src/playerB/Player-KinematicBody2D.gd" diff --git a/Position2D.gd b/src/CameraControl-Position2D.gd similarity index 100% rename from Position2D.gd rename to src/CameraControl-Position2D.gd diff --git a/Projectile.gd b/src/Projectile.gd similarity index 100% rename from Projectile.gd rename to src/Projectile.gd diff --git a/Projectile.tscn b/src/Projectile.tscn similarity index 79% rename from Projectile.tscn rename to src/Projectile.tscn index debb251..85c2783 100644 --- a/Projectile.tscn +++ b/src/Projectile.tscn @@ -1,11 +1,11 @@ [gd_scene load_steps=5 format=2] -[ext_resource path="res://assets/bullet.png" type="Texture" id=1] -[ext_resource path="res://Projectile.gd" type="Script" id=2] +[ext_resource path="res://src/Projectile.gd" type="Script" id=1] +[ext_resource path="res://assets/bullet.png" type="Texture" id=2] [sub_resource type="SpriteFrames" id=1] animations = [ { -"frames": [ ExtResource( 1 ) ], +"frames": [ ExtResource( 2 ) ], "loop": true, "name": "default", "speed": 5.0 @@ -20,7 +20,7 @@ collision_mask = 33 gravity_scale = 0.0 contacts_reported = 2 contact_monitor = true -script = ExtResource( 2 ) +script = ExtResource( 1 ) [node name="AnimatedSprite" type="AnimatedSprite" parent="."] frames = SubResource( 1 ) diff --git a/Enemy-KinematicBody2D.gd b/src/enemy/Enemy-KinematicBody2D.gd similarity index 100% rename from Enemy-KinematicBody2D.gd rename to src/enemy/Enemy-KinematicBody2D.gd diff --git a/Enemy.tscn b/src/enemy/Enemy.tscn similarity index 97% rename from Enemy.tscn rename to src/enemy/Enemy.tscn index b00075a..c1b9d26 100644 --- a/Enemy.tscn +++ b/src/enemy/Enemy.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=24 format=2] -[ext_resource path="res://Enemy-KinematicBody2D.gd" type="Script" id=1] +[ext_resource path="res://src/enemy/Enemy-KinematicBody2D.gd" type="Script" id=1] [sub_resource type="StreamTexture" id=75] load_path = "res://.import/botEnemy.png-46efd539a38730ff15fb4ddb087329c6.stex" diff --git a/src/enemyB/Enemy2.tscn b/src/enemyB/Enemy2.tscn index ec009c8..7ffb66f 100644 --- a/src/enemyB/Enemy2.tscn +++ b/src/enemyB/Enemy2.tscn @@ -1,15 +1,15 @@ [gd_scene load_steps=35 format=2] [ext_resource path="res://src/enemyB/Enemy2-KinematicBody2D.gd" type="Script" id=1] -[ext_resource path="res://src/states/enemy/fall.gd" type="Script" id=2] +[ext_resource path="res://src/enemyB/states/fall.gd" type="Script" id=2] [ext_resource path="res://src/state_machine.gd" type="Script" id=3] -[ext_resource path="res://src/states/enemy/jump.gd" type="Script" id=4] -[ext_resource path="res://src/states/enemy/move.gd" type="Script" id=5] -[ext_resource path="res://src/states/enemy/wander.gd" type="Script" id=6] -[ext_resource path="res://src/states/enemy/idle.gd" type="Script" id=7] -[ext_resource path="res://src/states/enemy/attack.gd" type="Script" id=8] +[ext_resource path="res://src/enemyB/states/jump.gd" type="Script" id=4] +[ext_resource path="res://src/enemyB/states/move.gd" type="Script" id=5] +[ext_resource path="res://src/enemyB/states/wander.gd" type="Script" id=6] +[ext_resource path="res://src/enemyB/states/idle.gd" type="Script" id=7] +[ext_resource path="res://src/enemyB/states/attack.gd" type="Script" id=8] [ext_resource path="res://src/playerB/Gun.gd" type="Script" id=9] -[ext_resource path="res://src/states/enemy/hurt.gd" type="Script" id=10] +[ext_resource path="res://src/enemyB/states/hurt.gd" type="Script" id=10] [ext_resource path="res://src/enemyB/enemy_move_component.gd" type="Script" id=11] [sub_resource type="StreamTexture" id=149] diff --git a/src/states/enemy/attack.gd b/src/enemyB/states/attack.gd similarity index 100% rename from src/states/enemy/attack.gd rename to src/enemyB/states/attack.gd diff --git a/src/states/enemy/fall.gd b/src/enemyB/states/fall.gd similarity index 100% rename from src/states/enemy/fall.gd rename to src/enemyB/states/fall.gd diff --git a/src/states/enemy/hurt.gd b/src/enemyB/states/hurt.gd similarity index 100% rename from src/states/enemy/hurt.gd rename to src/enemyB/states/hurt.gd diff --git a/src/states/enemy/idle.gd b/src/enemyB/states/idle.gd similarity index 100% rename from src/states/enemy/idle.gd rename to src/enemyB/states/idle.gd diff --git a/src/states/enemy/jump.gd b/src/enemyB/states/jump.gd similarity index 100% rename from src/states/enemy/jump.gd rename to src/enemyB/states/jump.gd diff --git a/src/states/enemy/move.gd b/src/enemyB/states/move.gd similarity index 100% rename from src/states/enemy/move.gd rename to src/enemyB/states/move.gd diff --git a/src/states/enemy/wander.gd b/src/enemyB/states/wander.gd similarity index 100% rename from src/states/enemy/wander.gd rename to src/enemyB/states/wander.gd diff --git a/src/playerB/Gun.gd b/src/playerB/Gun.gd index 8b7e5c2..cc1abac 100644 --- a/src/playerB/Gun.gd +++ b/src/playerB/Gun.gd @@ -5,7 +5,7 @@ extends Position2D const BULLET_VELOCITY = 350 -const Bullet = preload("res://Projectile.tscn") +const Bullet = preload("res://src/Projectile.tscn") #onready var sound_shoot = $Shoot onready var timer = $Cooldown diff --git a/wander.gd b/wander.gd deleted file mode 100644 index 4d313d1..0000000 --- a/wander.gd +++ /dev/null @@ -1,61 +0,0 @@ -extends State - -export (NodePath) var jump_node -export (NodePath) var fall_node -export (NodePath) var idle_node -export (NodePath) var dash_node - -onready var jump_state: State = get_node(jump_node) -onready var fall_state: State = get_node(fall_node) -onready var idle_state: State = get_node(idle_node) -onready var dash_state: State = get_node(dash_node) - -func process_input(_event: InputEvent) -> 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