first commit, initial starting game
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								Characters/test_player/WARRIOR SKELETON SS 2.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Characters/test_player/WARRIOR SKELETON SS 2.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 3.6 KiB  | 
							
								
								
									
										34
									
								
								Characters/test_player/WARRIOR SKELETON SS 2.png.import
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								Characters/test_player/WARRIOR SKELETON SS 2.png.import
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
[remap]
 | 
			
		||||
 | 
			
		||||
importer="texture"
 | 
			
		||||
type="CompressedTexture2D"
 | 
			
		||||
uid="uid://cs5o8bykug82q"
 | 
			
		||||
path="res://.godot/imported/WARRIOR SKELETON SS 2.png-5f9e9652b0cc681753eb4189c226a7f7.ctex"
 | 
			
		||||
metadata={
 | 
			
		||||
"vram_texture": false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[deps]
 | 
			
		||||
 | 
			
		||||
source_file="res://Characters/test_player/WARRIOR SKELETON SS 2.png"
 | 
			
		||||
dest_files=["res://.godot/imported/WARRIOR SKELETON SS 2.png-5f9e9652b0cc681753eb4189c226a7f7.ctex"]
 | 
			
		||||
 | 
			
		||||
[params]
 | 
			
		||||
 | 
			
		||||
compress/mode=0
 | 
			
		||||
compress/lossy_quality=0.7
 | 
			
		||||
compress/hdr_compression=1
 | 
			
		||||
compress/bptc_ldr=0
 | 
			
		||||
compress/normal_map=0
 | 
			
		||||
compress/channel_pack=0
 | 
			
		||||
mipmaps/generate=false
 | 
			
		||||
mipmaps/limit=-1
 | 
			
		||||
roughness/mode=0
 | 
			
		||||
roughness/src_normal=""
 | 
			
		||||
process/fix_alpha_border=true
 | 
			
		||||
process/premult_alpha=false
 | 
			
		||||
process/normal_map_invert_y=false
 | 
			
		||||
process/hdr_as_srgb=false
 | 
			
		||||
process/hdr_clamp_exposure=false
 | 
			
		||||
process/size_limit=0
 | 
			
		||||
detect_3d/compress_to=1
 | 
			
		||||
							
								
								
									
										204
									
								
								Characters/test_player/test_player.gd
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										204
									
								
								Characters/test_player/test_player.gd
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,204 @@
 | 
			
		||||
extends CharacterBody2D
 | 
			
		||||
 | 
			
		||||
@export var speed:int = 50
 | 
			
		||||
@export var max_speed:int = 350
 | 
			
		||||
@export var push_power:int = 50 + speed
 | 
			
		||||
@onready var health := max_health
 | 
			
		||||
 | 
			
		||||
@export var max_health := 3
 | 
			
		||||
@export var attack_speed := 2000
 | 
			
		||||
@export var throwback_strength := 2
 | 
			
		||||
@onready var player_sprite = $Sprite2D
 | 
			
		||||
@onready var player := get_node(".")
 | 
			
		||||
#Animation
 | 
			
		||||
@onready var anim_tree = $AnimationTree
 | 
			
		||||
@onready var atk_str := "parameters/attacking/current"
 | 
			
		||||
@onready var mov_str := "parameters/moving/current"
 | 
			
		||||
@onready var damage_str := "parameters/damaged/current"
 | 
			
		||||
@onready var disabled_str := "parameters/disabled/current"
 | 
			
		||||
#Other
 | 
			
		||||
@export var value:int = 0
 | 
			
		||||
 | 
			
		||||
@onready var player_facing:String = "right"
 | 
			
		||||
@onready var next_attack_time := 0
 | 
			
		||||
@onready var is_attacking := false
 | 
			
		||||
 | 
			
		||||
@onready var equipped:Node2D
 | 
			
		||||
@onready var spawned_item:Node2D
 | 
			
		||||
@onready var invulnerability_timer:Timer = get_node("InvulnerableTimer")
 | 
			
		||||
@onready var player_disabled := false
 | 
			
		||||
@onready var player_in_inventory := false
 | 
			
		||||
@onready var is_searching := false
 | 
			
		||||
 | 
			
		||||
@onready var item_hovering := false
 | 
			
		||||
 | 
			
		||||
@onready var rng = RandomNumberGenerator.new()
 | 
			
		||||
 | 
			
		||||
# Get the gravity from the project settings to be synced with RigidBody nodes.
 | 
			
		||||
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
 | 
			
		||||
 | 
			
		||||
@onready var player_hit := {
 | 
			
		||||
	"is_player_hit": false,
 | 
			
		||||
	"hit_velocity": Vector2(0,0),
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
signal speed_changed
 | 
			
		||||
signal value_changed
 | 
			
		||||
signal health_changed
 | 
			
		||||
signal player_killed
 | 
			
		||||
 | 
			
		||||
func _ready():
 | 
			
		||||
	if not is_multiplayer_authority(): return
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
func value_changed_func(amount: int) -> void:
 | 
			
		||||
	value = value + amount
 | 
			
		||||
	emit_signal("value_changed", value)
 | 
			
		||||
 | 
			
		||||
func set_disabled(is_disabled:bool):
 | 
			
		||||
	player_disabled = is_disabled
 | 
			
		||||
	if is_disabled:
 | 
			
		||||
		anim_tree.set(disabled_str, 1)
 | 
			
		||||
	else:
 | 
			
		||||
		anim_tree.set(disabled_str, 0)
 | 
			
		||||
 | 
			
		||||
func speed_changed_func(amount: int) -> void:
 | 
			
		||||
	speed = speed + amount
 | 
			
		||||
	if speed <= 0:
 | 
			
		||||
		health_changed_func(-1)
 | 
			
		||||
		speed = 100
 | 
			
		||||
	elif speed > max_speed:
 | 
			
		||||
		speed = max_speed
 | 
			
		||||
		health_changed_func(1)
 | 
			
		||||
	emit_signal("speed_changed", speed)
 | 
			
		||||
	
 | 
			
		||||
# reset our invulnerability animations
 | 
			
		||||
func _on_invulnerable_timer_timeout():
 | 
			
		||||
	anim_tree.set(damage_str, 0)
 | 
			
		||||
	
 | 
			
		||||
func health_changed_func(amount: int):
 | 
			
		||||
	if amount < 0:
 | 
			
		||||
		if invulnerability_timer.is_stopped():
 | 
			
		||||
			invulnerability_timer.start()
 | 
			
		||||
			health = health + amount
 | 
			
		||||
			if health < 0:
 | 
			
		||||
				print("kill!")
 | 
			
		||||
				health = max_health
 | 
			
		||||
				#TODO: Respawn char
 | 
			
		||||
			else:
 | 
			
		||||
				print("Setting health frame: ", health)
 | 
			
		||||
				anim_tree.set(damage_str, 1)
 | 
			
		||||
	else:
 | 
			
		||||
		health = health + amount
 | 
			
		||||
	emit_signal("health_changed", health)
 | 
			
		||||
	
 | 
			
		||||
func attack_finished():
 | 
			
		||||
	anim_tree.set(atk_str, 0)
 | 
			
		||||
	is_attacking = false
 | 
			
		||||
	
 | 
			
		||||
func get_input():
 | 
			
		||||
	if Input.is_action_just_pressed("print_pos"):
 | 
			
		||||
		print("PLAYER POSITION!: ", player.get_position())
 | 
			
		||||
	if Input.is_action_just_pressed("show_inventory"):
 | 
			
		||||
		pass
 | 
			
		||||
		#show_inventory()
 | 
			
		||||
	
 | 
			
		||||
	if player_disabled or player_in_inventory:
 | 
			
		||||
		return
 | 
			
		||||
		
 | 
			
		||||
	if Input.is_action_just_pressed("speed_up"):
 | 
			
		||||
		speed_changed_func(10)
 | 
			
		||||
	if Input.is_action_just_pressed("attack"):
 | 
			
		||||
		if item_hovering:
 | 
			
		||||
			spawned_item = null
 | 
			
		||||
			return
 | 
			
		||||
		var now = Time.get_ticks_msec()
 | 
			
		||||
		if now >= next_attack_time:
 | 
			
		||||
			is_attacking = true
 | 
			
		||||
			if player_facing == "left":
 | 
			
		||||
				player_sprite.flip_h = true
 | 
			
		||||
				anim_tree.set(atk_str, 1)
 | 
			
		||||
			else:
 | 
			
		||||
				player_sprite.flip_h = false
 | 
			
		||||
				anim_tree.set(atk_str, 1)
 | 
			
		||||
			if equipped:
 | 
			
		||||
				pass
 | 
			
		||||
				#spawned_item = load(ItemDatabase.Castable_objects[equipped.item_name]).instantiate()
 | 
			
		||||
				#var map = get_tree().current_scene
 | 
			
		||||
				#map.add_child(spawned_item)
 | 
			
		||||
				#inventory_ui.item_cooldown()
 | 
			
		||||
				#if equipped.item_clip_size > 0:
 | 
			
		||||
			#		inventory_ui.set_ammo(-1)
 | 
			
		||||
				#spawned_item.use_item(player, spawned_item, map)
 | 
			
		||||
				#next_attack_time = now + attack_speed
 | 
			
		||||
	velocity = Vector2()
 | 
			
		||||
	var direction : String
 | 
			
		||||
	#	if not input_active:
 | 
			
		||||
#		return
 | 
			
		||||
	if Input.is_action_pressed("right") and not is_attacking:
 | 
			
		||||
		player_facing = "right"
 | 
			
		||||
		player_sprite.flip_h = false
 | 
			
		||||
		velocity.x += 1
 | 
			
		||||
		anim_tree.set(mov_str, 1)
 | 
			
		||||
	if Input.is_action_pressed("left") and not is_attacking:
 | 
			
		||||
		player_sprite.flip_h = true
 | 
			
		||||
		player_facing = "left"
 | 
			
		||||
		velocity.x -= 1
 | 
			
		||||
		anim_tree.set(mov_str, 1)
 | 
			
		||||
	if Input.is_action_pressed("down") and not is_attacking:
 | 
			
		||||
		direction = "down"
 | 
			
		||||
		velocity.y += 1
 | 
			
		||||
		anim_tree.set(mov_str, 1)
 | 
			
		||||
	if Input.is_action_pressed("up") and not is_attacking:
 | 
			
		||||
		direction = "up"
 | 
			
		||||
		velocity.y -= 1
 | 
			
		||||
		anim_tree.set(mov_str, 1)
 | 
			
		||||
			
 | 
			
		||||
	
 | 
			
		||||
	velocity = velocity.normalized() * speed
 | 
			
		||||
	if velocity == Vector2.ZERO:
 | 
			
		||||
		anim_tree.set(mov_str, 0)
 | 
			
		||||
 | 
			
		||||
func _physics_process(delta):
 | 
			
		||||
#	if not is_multiplayer_authority():
 | 
			
		||||
#		get_input()
 | 
			
		||||
#		move_and_slide()
 | 
			
		||||
#		return
 | 
			
		||||
 | 
			
		||||
	get_input()
 | 
			
		||||
	move_and_slide()
 | 
			
		||||
 | 
			
		||||
	for i in get_slide_collision_count():
 | 
			
		||||
		var collision = get_slide_collision(i)
 | 
			
		||||
		var collider = collision.get_collider()
 | 
			
		||||
		if collider.is_in_group("moveable"):
 | 
			
		||||
			var normal = collision.get_normal()
 | 
			
		||||
			collider.apply_central_impulse(-collision.get_normal() * push_power)
 | 
			
		||||
 | 
			
		||||
	if player_hit.is_player_hit:
 | 
			
		||||
		velocity = Vector2.ZERO
 | 
			
		||||
		set_disabled(true)
 | 
			
		||||
		player_hit.is_player_hit = false
 | 
			
		||||
		var tween = get_tree().create_tween()
 | 
			
		||||
		var new_location = (player_hit.hit_velocity * throwback_strength) * delta
 | 
			
		||||
		tween.tween_method(move_player, Vector2(0,0) * delta, new_location, 1)
 | 
			
		||||
		await get_tree().create_timer(0.5).timeout
 | 
			
		||||
		set_disabled(false)
 | 
			
		||||
	# Update sync variables, which will be replicated to everyone else
 | 
			
		||||
	#rpc(&'update_movement', velocity)
 | 
			
		||||
#	$Networking.sync_position = position
 | 
			
		||||
#	$Networking.sync_velocity = velocity
 | 
			
		||||
#	$Networking.flipped_v = player_sprite.flip_v
 | 
			
		||||
#	$Networking.flipped_h = player_sprite.flip_h
 | 
			
		||||
#	$Networking.sync_frame_coords = player_sprite.get_frame_coords()
 | 
			
		||||
 | 
			
		||||
func move_player(c_velocity: Vector2):
 | 
			
		||||
#	rpc(&'update_movement', velocity)
 | 
			
		||||
	var collided = move_and_collide(c_velocity)
 | 
			
		||||
#	if collided:
 | 
			
		||||
#		print("Collided again?", collided)
 | 
			
		||||
#			var collider = collision.get_collider()
 | 
			
		||||
#			if collider.is_in_group("moveable"):
 | 
			
		||||
#				var normal = collision.get_normal()
 | 
			
		||||
#				collider.apply_central_impulse(-collision.get_normal() * push_power)
 | 
			
		||||
	player_hit.is_player_hit = false
 | 
			
		||||
							
								
								
									
										95
									
								
								Characters/test_player/test_player.tscn
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								Characters/test_player/test_player.tscn
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,95 @@
 | 
			
		||||
[gd_scene load_steps=9 format=3 uid="uid://c1gncjamuavvs"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" path="res://Characters/test_player/test_player.gd" id="1_6aci1"]
 | 
			
		||||
[ext_resource type="Texture2D" uid="uid://cs5o8bykug82q" path="res://Characters/test_player/WARRIOR SKELETON SS 2.png" id="1_8pmbp"]
 | 
			
		||||
 | 
			
		||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_8xegc"]
 | 
			
		||||
size = Vector2(22, 20)
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Animation" id="Animation_ue5sa"]
 | 
			
		||||
resource_name = "idle"
 | 
			
		||||
length = 2.0
 | 
			
		||||
loop_mode = 1
 | 
			
		||||
tracks/0/type = "value"
 | 
			
		||||
tracks/0/imported = false
 | 
			
		||||
tracks/0/enabled = true
 | 
			
		||||
tracks/0/path = NodePath("Sprite2D:frame_coords")
 | 
			
		||||
tracks/0/interp = 1
 | 
			
		||||
tracks/0/loop_wrap = true
 | 
			
		||||
tracks/0/keys = {
 | 
			
		||||
"times": PackedFloat32Array(0, 0.4, 0.8, 1.2, 1.6),
 | 
			
		||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1),
 | 
			
		||||
"update": 1,
 | 
			
		||||
"values": [Vector2i(0, 0), Vector2i(1, 0), Vector2i(2, 0), Vector2i(3, 0), Vector2i(4, 0)]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Animation" id="Animation_o87wd"]
 | 
			
		||||
resource_name = "walk"
 | 
			
		||||
length = 2.5
 | 
			
		||||
loop_mode = 1
 | 
			
		||||
tracks/0/type = "value"
 | 
			
		||||
tracks/0/imported = false
 | 
			
		||||
tracks/0/enabled = true
 | 
			
		||||
tracks/0/path = NodePath("Sprite2D:frame_coords")
 | 
			
		||||
tracks/0/interp = 1
 | 
			
		||||
tracks/0/loop_wrap = true
 | 
			
		||||
tracks/0/keys = {
 | 
			
		||||
"times": PackedFloat32Array(0, 0.4, 0.8, 1.2, 1.6, 2.1),
 | 
			
		||||
"transitions": PackedFloat32Array(1, 1, 1, 1, 1, 1),
 | 
			
		||||
"update": 1,
 | 
			
		||||
"values": [Vector2i(0, 1), Vector2i(1, 1), Vector2i(2, 1), Vector2i(3, 1), Vector2i(4, 1), Vector2i(5, 1)]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="Animation" id="Animation_6p4h5"]
 | 
			
		||||
resource_name = "attack"
 | 
			
		||||
length = 0.65
 | 
			
		||||
tracks/0/type = "value"
 | 
			
		||||
tracks/0/imported = false
 | 
			
		||||
tracks/0/enabled = true
 | 
			
		||||
tracks/0/path = NodePath("Sprite2D:frame_coords")
 | 
			
		||||
tracks/0/interp = 1
 | 
			
		||||
tracks/0/loop_wrap = true
 | 
			
		||||
tracks/0/keys = {
 | 
			
		||||
"times": PackedFloat32Array(0, 0.2, 0.4, 0.6),
 | 
			
		||||
"transitions": PackedFloat32Array(1, 1, 1, 1),
 | 
			
		||||
"update": 1,
 | 
			
		||||
"values": [Vector2i(0, 5), Vector2i(1, 5), Vector2i(2, 5), Vector2i(3, 5)]
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_0a2an"]
 | 
			
		||||
_data = {
 | 
			
		||||
"attack": SubResource("Animation_6p4h5"),
 | 
			
		||||
"idle": SubResource("Animation_ue5sa"),
 | 
			
		||||
"walk": SubResource("Animation_o87wd")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[sub_resource type="AnimationNodeBlendTree" id="AnimationNodeBlendTree_h4jmi"]
 | 
			
		||||
nodes/output/position = Vector2(900, 140)
 | 
			
		||||
 | 
			
		||||
[node name="test_player" type="CharacterBody2D"]
 | 
			
		||||
script = ExtResource("1_6aci1")
 | 
			
		||||
 | 
			
		||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
 | 
			
		||||
position = Vector2(1, 2)
 | 
			
		||||
shape = SubResource("RectangleShape2D_8xegc")
 | 
			
		||||
 | 
			
		||||
[node name="Sprite2D" type="Sprite2D" parent="."]
 | 
			
		||||
z_index = 1
 | 
			
		||||
texture = ExtResource("1_8pmbp")
 | 
			
		||||
hframes = 6
 | 
			
		||||
vframes = 6
 | 
			
		||||
frame = 33
 | 
			
		||||
 | 
			
		||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
 | 
			
		||||
libraries = {
 | 
			
		||||
"": SubResource("AnimationLibrary_0a2an")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
[node name="AnimationTree" type="AnimationTree" parent="."]
 | 
			
		||||
tree_root = SubResource("AnimationNodeBlendTree_h4jmi")
 | 
			
		||||
anim_player = NodePath("../AnimationPlayer")
 | 
			
		||||
 | 
			
		||||
[node name="player_cam" type="Camera2D" parent="."]
 | 
			
		||||
current = true
 | 
			
		||||
 | 
			
		||||
[node name="InvulnerableTimer" type="Timer" parent="."]
 | 
			
		||||
		Reference in New Issue
	
	Block a user