aboutsummaryrefslogtreecommitdiff
path: root/entities/player
diff options
context:
space:
mode:
authorIndrajith K L2022-04-15 02:08:49 +0530
committerIndrajith K L2022-04-15 02:08:49 +0530
commit31089507aae1d35d0deeb2c412cfa311e7a57563 (patch)
tree65f773c23eaa44df8dbb8423e020fb79d3ded47a /entities/player
parentaef396151234aa21af4a658ea11f03ea9434961c (diff)
downloadgamedevjs-jam-31089507aae1d35d0deeb2c412cfa311e7a57563.tar.gz
gamedevjs-jam-31089507aae1d35d0deeb2c412cfa311e7a57563.tar.bz2
gamedevjs-jam-31089507aae1d35d0deeb2c412cfa311e7a57563.zip
Adds Chicken Enemy
Animation Tree - In-Progress
Diffstat (limited to 'entities/player')
-rw-r--r--entities/player/Player.gd61
-rw-r--r--entities/player/Player.tscn248
2 files changed, 309 insertions, 0 deletions
diff --git a/entities/player/Player.gd b/entities/player/Player.gd
new file mode 100644
index 0000000..6087221
--- /dev/null
+++ b/entities/player/Player.gd
@@ -0,0 +1,61 @@
+extends KinematicBody2D
+
+export (int) var run_speed = 200
+export (int) var jump_speed = -400
+export (int) var gravity = 1200
+export var entity_type = "PLAYER"
+export (int) var health = 90
+var hurt = false
+
+var velocity = Vector2()
+var jumping = false
+onready var sprite = $AnimatedSprite
+var facing_right = true
+func get_input():
+ velocity.x = 0
+ var right = Input.is_action_pressed('right')
+ var left = Input.is_action_pressed('left')
+ var jump = Input.is_action_just_pressed('jump')
+
+ if facing_right == true:
+ sprite.flip_h = false
+ else:
+ sprite.flip_h = true
+
+
+ if jump and is_on_floor():
+ jumping = true
+ velocity.y = jump_speed
+ if right:
+ velocity.x += run_speed
+ facing_right = true
+ play_animation("run")
+ elif left:
+ velocity.x -= run_speed
+ facing_right = false
+ play_animation("run")
+ else:
+ play_animation("idle")
+
+ if !jumping && !is_on_floor():
+ play_animation("jump")
+
+func _physics_process(delta):
+ get_input()
+ velocity.y += gravity * delta
+ if jumping and is_on_floor():
+ jumping = false
+ velocity = move_and_slide(velocity, Vector2(0, -1))
+
+func _on_enemyHit(health):
+ hurt = true
+ play_animation("hit")
+
+func _ready() -> void:
+ SignalBus.connect("on_hit", self, "_on_enemyHit")
+
+func play_animation(animation_name):
+ if $AnimatedSprite.get_animation()!=animation_name :
+ #$AnimatedSprite.play(animation_name)
+ #$AnimatedSprite/AnimationPlayer.stop()
+ $AnimatedSprite/AnimationPlayer.play(animation_name)
diff --git a/entities/player/Player.tscn b/entities/player/Player.tscn
new file mode 100644
index 0000000..26ade6f
--- /dev/null
+++ b/entities/player/Player.tscn
@@ -0,0 +1,248 @@
+[gd_scene load_steps=52 format=2]
+
+[ext_resource path="res://pinkman/run/run7.png" type="Texture" id=1]
+[ext_resource path="res://pinkman/double-jump/double_jump6.png" type="Texture" id=2]
+[ext_resource path="res://pinkman/hit/hit6.png" type="Texture" id=3]
+[ext_resource path="res://pinkman/idle/idle4.png" type="Texture" id=4]
+[ext_resource path="res://pinkman/wall-jump/wall-jump2.png" type="Texture" id=5]
+[ext_resource path="res://pinkman/fall/fall.png" type="Texture" id=6]
+[ext_resource path="res://pinkman/hit/hit1.png" type="Texture" id=7]
+[ext_resource path="res://pinkman/double-jump/double_jump1.png" type="Texture" id=8]
+[ext_resource path="res://pinkman/idle/idle11.png" type="Texture" id=9]
+[ext_resource path="res://pinkman/double-jump/double_jump3.png" type="Texture" id=10]
+[ext_resource path="res://pinkman/run/run6.png" type="Texture" id=11]
+[ext_resource path="res://pinkman/idle/idle1.png" type="Texture" id=12]
+[ext_resource path="res://pinkman/idle/idle7.png" type="Texture" id=13]
+[ext_resource path="res://pinkman/wall-jump/wall-jump5.png" type="Texture" id=14]
+[ext_resource path="res://pinkman/wall-jump/wall-jump4.png" type="Texture" id=15]
+[ext_resource path="res://pinkman/run/run11.png" type="Texture" id=16]
+[ext_resource path="res://pinkman/wall-jump/wall-jump1.png" type="Texture" id=17]
+[ext_resource path="res://pinkman/jump/jump.png" type="Texture" id=18]
+[ext_resource path="res://pinkman/double-jump/double_jump2.png" type="Texture" id=19]
+[ext_resource path="res://pinkman/idle/idle3.png" type="Texture" id=20]
+[ext_resource path="res://pinkman/idle/idle9.png" type="Texture" id=21]
+[ext_resource path="res://pinkman/idle/idle5.png" type="Texture" id=22]
+[ext_resource path="res://pinkman/idle/idle6.png" type="Texture" id=23]
+[ext_resource path="res://pinkman/double-jump/double_jump5.png" type="Texture" id=24]
+[ext_resource path="res://pinkman/double-jump/double_jump4.png" type="Texture" id=25]
+[ext_resource path="res://pinkman/run/run9.png" type="Texture" id=26]
+[ext_resource path="res://pinkman/idle/idle8.png" type="Texture" id=27]
+[ext_resource path="res://pinkman/idle/idle10.png" type="Texture" id=28]
+[ext_resource path="res://pinkman/idle/idle2.png" type="Texture" id=29]
+[ext_resource path="res://pinkman/wall-jump/wall-jump3.png" type="Texture" id=30]
+[ext_resource path="res://pinkman/hit/hit2.png" type="Texture" id=31]
+[ext_resource path="res://pinkman/run/run5.png" type="Texture" id=32]
+[ext_resource path="res://pinkman/hit/hit3.png" type="Texture" id=33]
+[ext_resource path="res://pinkman/run/run1.png" type="Texture" id=34]
+[ext_resource path="res://pinkman/run/run8.png" type="Texture" id=35]
+[ext_resource path="res://pinkman/hit/hit5.png" type="Texture" id=36]
+[ext_resource path="res://pinkman/run/run10.png" type="Texture" id=37]
+[ext_resource path="res://pinkman/hit/hit4.png" type="Texture" id=38]
+[ext_resource path="res://pinkman/run/run2.png" type="Texture" id=39]
+[ext_resource path="res://pinkman/run/run12.png" type="Texture" id=40]
+[ext_resource path="res://pinkman/run/run3.png" type="Texture" id=41]
+[ext_resource path="res://pinkman/hit/hit7.png" type="Texture" id=42]
+[ext_resource path="res://pinkman/run/run4.png" type="Texture" id=43]
+[ext_resource path="res://entities/player/Player.gd" type="Script" id=44]
+
+[sub_resource type="CapsuleShape2D" id=2]
+height = 8.0
+
+[sub_resource type="SpriteFrames" id=1]
+animations = [ {
+"frames": [ ExtResource( 12 ), ExtResource( 29 ), ExtResource( 20 ), ExtResource( 4 ), ExtResource( 22 ), ExtResource( 23 ), ExtResource( 13 ), ExtResource( 27 ), ExtResource( 21 ), ExtResource( 28 ), ExtResource( 9 ) ],
+"loop": true,
+"name": "idle",
+"speed": 25.0
+}, {
+"frames": [ ExtResource( 17 ), ExtResource( 5 ), ExtResource( 30 ), ExtResource( 15 ), ExtResource( 14 ) ],
+"loop": true,
+"name": "wall_jump",
+"speed": 25.0
+}, {
+"frames": [ ExtResource( 6 ) ],
+"loop": true,
+"name": "fall",
+"speed": 5.0
+}, {
+"frames": [ ExtResource( 8 ), ExtResource( 19 ), ExtResource( 10 ), ExtResource( 25 ), ExtResource( 24 ), ExtResource( 2 ) ],
+"loop": true,
+"name": "double_jump",
+"speed": 25.0
+}, {
+"frames": [ ExtResource( 7 ), ExtResource( 31 ), ExtResource( 33 ), ExtResource( 38 ), ExtResource( 36 ), ExtResource( 3 ), ExtResource( 42 ) ],
+"loop": true,
+"name": "hit",
+"speed": 30.0
+}, {
+"frames": [ ExtResource( 18 ) ],
+"loop": true,
+"name": "jump",
+"speed": 5.0
+}, {
+"frames": [ ExtResource( 34 ), ExtResource( 39 ), ExtResource( 41 ), ExtResource( 43 ), ExtResource( 32 ), ExtResource( 11 ), ExtResource( 1 ), ExtResource( 35 ), ExtResource( 26 ), ExtResource( 37 ), ExtResource( 16 ), ExtResource( 40 ) ],
+"loop": true,
+"name": "run",
+"speed": 25.0
+} ]
+
+[sub_resource type="Animation" id=3]
+length = 0.001
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:animation")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 0,
+"values": [ "idle" ]
+}
+tracks/1/type = "value"
+tracks/1/path = NodePath(".:frame")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 0,
+"values": [ 0 ]
+}
+
+[sub_resource type="Animation" id=7]
+resource_name = "hit"
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:animation")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 1,
+"values": [ "hit" ]
+}
+tracks/1/type = "value"
+tracks/1/path = NodePath(".:frame")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/keys = {
+"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4, 0.5 ),
+"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1 ),
+"update": 1,
+"values": [ 1, 2, 3, 4, 5, 6 ]
+}
+
+[sub_resource type="Animation" id=4]
+resource_name = "idle"
+loop = true
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:animation")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 1,
+"values": [ "idle" ]
+}
+tracks/1/type = "value"
+tracks/1/path = NodePath(".:frame")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/keys = {
+"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 ),
+"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ),
+"update": 1,
+"values": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
+}
+
+[sub_resource type="Animation" id=5]
+resource_name = "jump"
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:animation")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 1,
+"values": [ "jump" ]
+}
+tracks/1/type = "value"
+tracks/1/path = NodePath(".:frame")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 1,
+"values": [ 0 ]
+}
+
+[sub_resource type="Animation" id=6]
+resource_name = "run"
+tracks/0/type = "value"
+tracks/0/path = NodePath(".:animation")
+tracks/0/interp = 1
+tracks/0/loop_wrap = true
+tracks/0/imported = false
+tracks/0/enabled = true
+tracks/0/keys = {
+"times": PoolRealArray( 0 ),
+"transitions": PoolRealArray( 1 ),
+"update": 1,
+"values": [ "run" ]
+}
+tracks/1/type = "value"
+tracks/1/path = NodePath(".:frame")
+tracks/1/interp = 1
+tracks/1/loop_wrap = true
+tracks/1/imported = false
+tracks/1/enabled = true
+tracks/1/keys = {
+"times": PoolRealArray( 0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 ),
+"transitions": PoolRealArray( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ),
+"update": 1,
+"values": [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ]
+}
+
+[node name="Player" type="KinematicBody2D" groups=["player"]]
+z_index = 1
+script = ExtResource( 44 )
+
+[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
+position = Vector2( 0, 2 )
+shape = SubResource( 2 )
+
+[node name="Area2D" type="Area2D" parent="."]
+
+[node name="CollisionShape2D2" type="CollisionShape2D" parent="Area2D"]
+position = Vector2( 0, 2 )
+shape = SubResource( 2 )
+
+[node name="AnimatedSprite" type="AnimatedSprite" parent="."]
+frames = SubResource( 1 )
+animation = "idle"
+
+[node name="AnimationPlayer" type="AnimationPlayer" parent="AnimatedSprite"]
+anims/RESET = SubResource( 3 )
+anims/hit = SubResource( 7 )
+anims/idle = SubResource( 4 )
+anims/jump = SubResource( 5 )
+anims/run = SubResource( 6 )