Double jump, WASD keys, small level tweaks
This commit is contained in:
		
							parent
							
								
									55ed2fadbe
								
							
						
					
					
						commit
						9f84017a62
					
				| @ -1,13 +1,49 @@ | |||||||
| extends CharacterBody2D | extends CharacterBody2D | ||||||
| 
 | 
 | ||||||
| var gravity = 800 | var gravity = 800 | ||||||
| const SPEED = 60.0 | const SPEED = 200.0 | ||||||
| const JUMP_VELOCITY = -400.0 | const JUMP_VELOCITY = -400.0 | ||||||
| @onready var sprite = $Sprites | @onready var sprite = $Sprites | ||||||
| 
 | 
 | ||||||
| var land_time = 0 | var land_time = 0 | ||||||
| var jumping = false | var jumping = false | ||||||
| var side = 1 | var side = 1 | ||||||
|  | var double_jump = false | ||||||
|  | 
 | ||||||
|  | enum State { | ||||||
|  | 	Idle, | ||||||
|  | 	Run, | ||||||
|  | 	Walk, | ||||||
|  | 	Jump, | ||||||
|  | 	AirSpin, | ||||||
|  | 	Landing | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | enum JumpState { | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func _play_anim(state: State, velocity: Vector2): | ||||||
|  | 	match state: | ||||||
|  | 		State.Idle: | ||||||
|  | 			sprite.play("Idle") | ||||||
|  | 		State.Run: | ||||||
|  | 			sprite.play("Run") | ||||||
|  | 		State.Walk: | ||||||
|  | 			sprite.play("Walk") | ||||||
|  | 		State.Jump: | ||||||
|  | 			sprite.pause() | ||||||
|  | 			sprite.set_frame_and_progress(0, 0) | ||||||
|  | 			if velocity.y > 50: | ||||||
|  | 				sprite.set_frame_and_progress(2,0) | ||||||
|  | 			elif velocity.y > -150: | ||||||
|  | 				sprite.set_frame_and_progress(1, 0) | ||||||
|  | 		State.AirSpin: | ||||||
|  | 			pass | ||||||
|  | 		State.Landing: | ||||||
|  | 			sprite.play("Land") | ||||||
|  | 
 | ||||||
|  | func _process_velocity(state: State, delta): | ||||||
|  | 	pass | ||||||
| 
 | 
 | ||||||
| func _physics_process(delta): | func _physics_process(delta): | ||||||
| 	if not is_on_floor(): | 	if not is_on_floor(): | ||||||
| @ -15,16 +51,23 @@ func _physics_process(delta): | |||||||
| 	elif jumping: | 	elif jumping: | ||||||
| 		jumping = false | 		jumping = false | ||||||
| 		sprite.play("Land") | 		sprite.play("Land") | ||||||
| 		land_time = 0.33 | 		double_jump = false | ||||||
|  | 		land_time = 0.16 | ||||||
| 
 | 
 | ||||||
| 	if Input.is_action_just_pressed("ui_accept") and is_on_floor(): | 	if Input.is_action_just_pressed("ui_accept"): | ||||||
| 		velocity.y = JUMP_VELOCITY | 		if is_on_floor(): | ||||||
| 		sprite.play("Jump") | 			velocity.y = JUMP_VELOCITY | ||||||
| 		jumping = true | 			sprite.play("Jump") | ||||||
| 		sprite.pause() | 			jumping = true | ||||||
| 		sprite.set_frame_and_progress(0, 0) | 			sprite.pause() | ||||||
|  | 			sprite.set_frame_and_progress(0, 0) | ||||||
|  | 		elif not double_jump: | ||||||
|  | 			sprite.play("AirSpin") | ||||||
|  | 			double_jump = true | ||||||
|  | 			var boost = 0 if velocity.y > 0 else velocity.y / 3 | ||||||
|  | 			velocity.y = JUMP_VELOCITY / 1.4 + boost | ||||||
| 
 | 
 | ||||||
| 	if jumping: | 	if jumping and not double_jump: | ||||||
| 		if velocity.y > 50: | 		if velocity.y > 50: | ||||||
| 			sprite.set_frame_and_progress(2,0) | 			sprite.set_frame_and_progress(2,0) | ||||||
| 		elif velocity.y > -150: | 		elif velocity.y > -150: | ||||||
| @ -32,8 +75,8 @@ func _physics_process(delta): | |||||||
| 
 | 
 | ||||||
| 	var speed = SPEED | 	var speed = SPEED | ||||||
| 	if Input.is_key_pressed(KEY_SHIFT): | 	if Input.is_key_pressed(KEY_SHIFT): | ||||||
| 		speed *= 3 | 		speed /= 3 | ||||||
| 	var direction = Input.get_axis("ui_left", "ui_right") | 	var direction = Input.get_axis("left", "right") | ||||||
| 	if direction: | 	if direction: | ||||||
| 		velocity.x = direction * speed | 		velocity.x = direction * speed | ||||||
| 	else: | 	else: | ||||||
| @ -41,8 +84,6 @@ func _physics_process(delta): | |||||||
| 	if direction != 0: | 	if direction != 0: | ||||||
| 		sprite.flip_h = direction == -1 | 		sprite.flip_h = direction == -1 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	if land_time >= 0: | 	if land_time >= 0: | ||||||
| 		land_time -= delta | 		land_time -= delta | ||||||
| 
 | 
 | ||||||
| @ -50,12 +91,10 @@ func _physics_process(delta): | |||||||
| 	if land_time <= 0 and not jumping: | 	if land_time <= 0 and not jumping: | ||||||
| 		if velocity.x != 0: | 		if velocity.x != 0: | ||||||
| 			if Input.is_key_pressed(KEY_SHIFT): | 			if Input.is_key_pressed(KEY_SHIFT): | ||||||
| 				sprite.play("Run") |  | ||||||
| 			else: |  | ||||||
| 				sprite.play("Walk") | 				sprite.play("Walk") | ||||||
|  | 			else: | ||||||
|  | 				sprite.play("Run") | ||||||
| 		else: | 		else: | ||||||
| 			sprite.play("Idle") | 			sprite.play("Idle") | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| 	move_and_slide() | 	move_and_slide() | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ | |||||||
| [sub_resource type="QuadMesh" id="QuadMesh_n5vip"] | [sub_resource type="QuadMesh" id="QuadMesh_n5vip"] | ||||||
| 
 | 
 | ||||||
| [sub_resource type="RectangleShape2D" id="RectangleShape2D_s46ls"] | [sub_resource type="RectangleShape2D" id="RectangleShape2D_s46ls"] | ||||||
| size = Vector2(300, 20) | size = Vector2(500, 20) | ||||||
| 
 | 
 | ||||||
| [node name="Node2D" type="Node2D"] | [node name="Node2D" type="Node2D"] | ||||||
| 
 | 
 | ||||||
| @ -13,11 +13,11 @@ size = Vector2(300, 20) | |||||||
| position = Vector2(163, 99) | position = Vector2(163, 99) | ||||||
| 
 | 
 | ||||||
| [node name="StaticBody2D" type="StaticBody2D" parent="."] | [node name="StaticBody2D" type="StaticBody2D" parent="."] | ||||||
| position = Vector2(198, 184) | position = Vector2(265, 254) | ||||||
| 
 | 
 | ||||||
| [node name="MeshInstance2D" type="MeshInstance2D" parent="StaticBody2D"] | [node name="MeshInstance2D" type="MeshInstance2D" parent="StaticBody2D"] | ||||||
| modulate = Color(0.168627, 0.678431, 0.701961, 1) | modulate = Color(0.168627, 0.678431, 0.701961, 1) | ||||||
| scale = Vector2(300, 20) | scale = Vector2(500, 20) | ||||||
| mesh = SubResource("QuadMesh_n5vip") | mesh = SubResource("QuadMesh_n5vip") | ||||||
| 
 | 
 | ||||||
| [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] | [node name="CollisionShape2D" type="CollisionShape2D" parent="StaticBody2D"] | ||||||
|  | |||||||
| @ -1,12 +1,37 @@ | |||||||
| [gd_scene load_steps=44 format=3 uid="uid://bjc6dwxaakqdg"] | [gd_scene load_steps=48 format=3 uid="uid://bjc6dwxaakqdg"] | ||||||
| 
 | 
 | ||||||
| [ext_resource type="Script" path="res://Code/Character.gd" id="1_23c20"] | [ext_resource type="Script" path="res://Code/Character.gd" id="1_23c20"] | ||||||
| [ext_resource type="Texture2D" uid="uid://wfwjlevruveu" path="res://Import/Sprites/Character Idle 48x48.png" id="2_8h572"] | [ext_resource type="Texture2D" uid="uid://wfwjlevruveu" path="res://Import/Sprites/Character Idle 48x48.png" id="2_8h572"] | ||||||
|  | [ext_resource type="Texture2D" uid="uid://c87b08n23v0kx" path="res://Import/Sprites/player air spin 48x48.png" id="2_gpxo5"] | ||||||
| [ext_resource type="Texture2D" uid="uid://bge22c82umdui" path="res://Import/Sprites/PlayerWalk 48x48.png" id="3_xxdqr"] | [ext_resource type="Texture2D" uid="uid://bge22c82umdui" path="res://Import/Sprites/PlayerWalk 48x48.png" id="3_xxdqr"] | ||||||
| [ext_resource type="Texture2D" uid="uid://y8syonuki304" path="res://Import/Sprites/run cycle 48x48.png" id="4_rqcgh"] | [ext_resource type="Texture2D" uid="uid://y8syonuki304" path="res://Import/Sprites/run cycle 48x48.png" id="4_rqcgh"] | ||||||
| [ext_resource type="Texture2D" uid="uid://8ikuchoh7pyd" path="res://Import/Sprites/player jump 48x48.png" id="5_f2sni"] | [ext_resource type="Texture2D" uid="uid://8ikuchoh7pyd" path="res://Import/Sprites/player jump 48x48.png" id="5_f2sni"] | ||||||
| [ext_resource type="Texture2D" uid="uid://diiqvgeqnmn1c" path="res://Import/Sprites/player land 48x48.png" id="6_ba2s3"] | [ext_resource type="Texture2D" uid="uid://diiqvgeqnmn1c" path="res://Import/Sprites/player land 48x48.png" id="6_ba2s3"] | ||||||
| 
 | 
 | ||||||
|  | [sub_resource type="AtlasTexture" id="AtlasTexture_c40es"] | ||||||
|  | atlas = ExtResource("2_gpxo5") | ||||||
|  | region = Rect2(0, 0, 48, 48) | ||||||
|  | 
 | ||||||
|  | [sub_resource type="AtlasTexture" id="AtlasTexture_12cxk"] | ||||||
|  | atlas = ExtResource("2_gpxo5") | ||||||
|  | region = Rect2(48, 0, 48, 48) | ||||||
|  | 
 | ||||||
|  | [sub_resource type="AtlasTexture" id="AtlasTexture_yyln8"] | ||||||
|  | atlas = ExtResource("2_gpxo5") | ||||||
|  | region = Rect2(96, 0, 48, 48) | ||||||
|  | 
 | ||||||
|  | [sub_resource type="AtlasTexture" id="AtlasTexture_kfcja"] | ||||||
|  | atlas = ExtResource("2_gpxo5") | ||||||
|  | region = Rect2(144, 0, 48, 48) | ||||||
|  | 
 | ||||||
|  | [sub_resource type="AtlasTexture" id="AtlasTexture_3mg0x"] | ||||||
|  | atlas = ExtResource("2_gpxo5") | ||||||
|  | region = Rect2(192, 0, 48, 48) | ||||||
|  | 
 | ||||||
|  | [sub_resource type="AtlasTexture" id="AtlasTexture_2sfvi"] | ||||||
|  | atlas = ExtResource("2_gpxo5") | ||||||
|  | region = Rect2(240, 0, 48, 48) | ||||||
|  | 
 | ||||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_t3ih3"] | [sub_resource type="AtlasTexture" id="AtlasTexture_t3ih3"] | ||||||
| atlas = ExtResource("2_8h572") | atlas = ExtResource("2_8h572") | ||||||
| region = Rect2(0, 0, 48, 48) | region = Rect2(0, 0, 48, 48) | ||||||
| @ -67,22 +92,10 @@ region = Rect2(0, 0, 48, 48) | |||||||
| atlas = ExtResource("6_ba2s3") | atlas = ExtResource("6_ba2s3") | ||||||
| region = Rect2(48, 0, 48, 48) | region = Rect2(48, 0, 48, 48) | ||||||
| 
 | 
 | ||||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_iiovw"] |  | ||||||
| atlas = ExtResource("6_ba2s3") |  | ||||||
| region = Rect2(96, 0, 48, 48) |  | ||||||
| 
 |  | ||||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_sx58l"] | [sub_resource type="AtlasTexture" id="AtlasTexture_sx58l"] | ||||||
| atlas = ExtResource("6_ba2s3") | atlas = ExtResource("6_ba2s3") | ||||||
| region = Rect2(144, 0, 48, 48) | region = Rect2(144, 0, 48, 48) | ||||||
| 
 | 
 | ||||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_6l2e7"] |  | ||||||
| atlas = ExtResource("6_ba2s3") |  | ||||||
| region = Rect2(240, 0, 48, 48) |  | ||||||
| 
 |  | ||||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_acowd"] |  | ||||||
| atlas = ExtResource("6_ba2s3") |  | ||||||
| region = Rect2(336, 0, 48, 48) |  | ||||||
| 
 |  | ||||||
| [sub_resource type="AtlasTexture" id="AtlasTexture_3u4f5"] | [sub_resource type="AtlasTexture" id="AtlasTexture_3u4f5"] | ||||||
| atlas = ExtResource("4_rqcgh") | atlas = ExtResource("4_rqcgh") | ||||||
| region = Rect2(0, 0, 48, 48) | region = Rect2(0, 0, 48, 48) | ||||||
| @ -151,6 +164,29 @@ region = Rect2(336, 0, 48, 48) | |||||||
| animations = [{ | animations = [{ | ||||||
| "frames": [{ | "frames": [{ | ||||||
| "duration": 1.0, | "duration": 1.0, | ||||||
|  | "texture": SubResource("AtlasTexture_c40es") | ||||||
|  | }, { | ||||||
|  | "duration": 1.0, | ||||||
|  | "texture": SubResource("AtlasTexture_12cxk") | ||||||
|  | }, { | ||||||
|  | "duration": 1.0, | ||||||
|  | "texture": SubResource("AtlasTexture_yyln8") | ||||||
|  | }, { | ||||||
|  | "duration": 1.0, | ||||||
|  | "texture": SubResource("AtlasTexture_kfcja") | ||||||
|  | }, { | ||||||
|  | "duration": 1.0, | ||||||
|  | "texture": SubResource("AtlasTexture_3mg0x") | ||||||
|  | }, { | ||||||
|  | "duration": 1.0, | ||||||
|  | "texture": SubResource("AtlasTexture_2sfvi") | ||||||
|  | }], | ||||||
|  | "loop": false, | ||||||
|  | "name": &"AirSpin", | ||||||
|  | "speed": 10.0 | ||||||
|  | }, { | ||||||
|  | "frames": [{ | ||||||
|  | "duration": 1.0, | ||||||
| "texture": SubResource("AtlasTexture_t3ih3") | "texture": SubResource("AtlasTexture_t3ih3") | ||||||
| }, { | }, { | ||||||
| "duration": 1.0, | "duration": 1.0, | ||||||
| @ -206,16 +242,7 @@ animations = [{ | |||||||
| "texture": SubResource("AtlasTexture_3uk3c") | "texture": SubResource("AtlasTexture_3uk3c") | ||||||
| }, { | }, { | ||||||
| "duration": 1.0, | "duration": 1.0, | ||||||
| "texture": SubResource("AtlasTexture_iiovw") |  | ||||||
| }, { |  | ||||||
| "duration": 1.0, |  | ||||||
| "texture": SubResource("AtlasTexture_sx58l") | "texture": SubResource("AtlasTexture_sx58l") | ||||||
| }, { |  | ||||||
| "duration": 1.0, |  | ||||||
| "texture": SubResource("AtlasTexture_6l2e7") |  | ||||||
| }, { |  | ||||||
| "duration": 1.0, |  | ||||||
| "texture": SubResource("AtlasTexture_acowd") |  | ||||||
| }], | }], | ||||||
| "loop": true, | "loop": true, | ||||||
| "name": &"Land", | "name": &"Land", | ||||||
| @ -290,7 +317,9 @@ script = ExtResource("1_23c20") | |||||||
| texture_filter = 1 | texture_filter = 1 | ||||||
| position = Vector2(0, -16) | position = Vector2(0, -16) | ||||||
| sprite_frames = SubResource("SpriteFrames_gvqqb") | sprite_frames = SubResource("SpriteFrames_gvqqb") | ||||||
| animation = &"Run" | animation = &"AirSpin" | ||||||
|  | frame = 5 | ||||||
|  | frame_progress = 1.0 | ||||||
| 
 | 
 | ||||||
| [node name="CollisionShape2D" type="CollisionShape2D" parent="."] | [node name="CollisionShape2D" type="CollisionShape2D" parent="."] | ||||||
| position = Vector2(0, -14.5) | position = Vector2(0, -14.5) | ||||||
|  | |||||||
| @ -22,3 +22,30 @@ window/size/viewport_height=300 | |||||||
| window/size/window_width_override=1600 | window/size/window_width_override=1600 | ||||||
| window/size/window_height_override=1050 | window/size/window_height_override=1050 | ||||||
| window/stretch/scale=3.0 | window/stretch/scale=3.0 | ||||||
|  | 
 | ||||||
|  | [input] | ||||||
|  | 
 | ||||||
|  | left={ | ||||||
|  | "deadzone": 0.5, | ||||||
|  | "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"echo":false,"script":null) | ||||||
|  | , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":0,"echo":false,"script":null) | ||||||
|  | ] | ||||||
|  | } | ||||||
|  | right={ | ||||||
|  | "deadzone": 0.5, | ||||||
|  | "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) | ||||||
|  | , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) | ||||||
|  | ] | ||||||
|  | } | ||||||
|  | up={ | ||||||
|  | "deadzone": 0.5, | ||||||
|  | "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194320,"key_label":0,"unicode":0,"echo":false,"script":null) | ||||||
|  | , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) | ||||||
|  | ] | ||||||
|  | } | ||||||
|  | down={ | ||||||
|  | "deadzone": 0.5, | ||||||
|  | "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194322,"key_label":0,"unicode":0,"echo":false,"script":null) | ||||||
|  | , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) | ||||||
|  | ] | ||||||
|  | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user