jeu: le début de la collision!

Le jeu contient une princesse qui utilise la physique basique de Godot.
A remplacer ultérieurement car non réellement satisfaisant. Le but va
être de porter dans les prochaines contributions le code de microstudio.
This commit is contained in:
Thomas Lavocat
2023-04-13 16:40:18 +02:00
parent 983501bdaf
commit 17269c4256
5 changed files with 562 additions and 4 deletions

14
game.tscn Normal file
View File

@@ -0,0 +1,14 @@
[gd_scene load_steps=3 format=3 uid="uid://8mc82qjj5gma"]
[ext_resource type="PackedScene" uid="uid://cfou80f4ng1q0" path="res://level.tscn" id="1_qv57y"]
[ext_resource type="PackedScene" uid="uid://dv0mokf4eogm7" path="res://princesse.tscn" id="2_0ku48"]
[node name="game" type="Node"]
[node name="Node2D" parent="." instance=ExtResource("1_qv57y")]
position = Vector2(1, 10)
[node name="Princesse" parent="Node2D" instance=ExtResource("2_0ku48")]
position = Vector2(87, -430)
scale = Vector2(0.6, 0.6)
collision_mask = 28

227
level.tscn Normal file

File diff suppressed because one or more lines are too long

76
princesse.gd Normal file
View File

@@ -0,0 +1,76 @@
extends CharacterBody2D
const WALK_SPEED = 200.0
const ACCELERATION_SPEED = WALK_SPEED * 6.0
const JUMP_VELOCITY = -400.0
## Maximum speed at which the player can fall.
const TERMINAL_VELOCITY = 400
## The player listens for input actions appended with this suffix.[br]
## Used to separate controls for multiple players in splitscreen.
@export var action_suffix := ""
var gravity: int = ProjectSettings.get("physics/2d/default_gravity")
@onready var platform_detector := $PlatformDetector as RayCast2D
@onready var animation := $AnimatedSprite2D as AnimatedSprite2D
@onready var animation_player := $AnimationPlayer as AnimationPlayer
@onready var camera := $Camera2D as Camera2D
var _double_jump_charged := false
func _physics_process(delta: float) -> void:
if is_on_floor():
_double_jump_charged = true
if Input.is_action_just_pressed("jump" + action_suffix):
try_jump()
elif Input.is_action_just_released("jump" + action_suffix) and velocity.y < 0.0:
# The player let go of jump early, reduce vertical momentum.
velocity.y *= 0.6
# Fall.
velocity.y = minf(TERMINAL_VELOCITY, velocity.y + gravity * delta)
var direction := Input.get_axis("move_left" + action_suffix, "move_right" + action_suffix) * WALK_SPEED
velocity.x = move_toward(velocity.x, direction, ACCELERATION_SPEED * delta)
if not is_zero_approx(velocity.x):
if velocity.x > 0.0:
animation.scale.x = 1.0
else:
animation.scale.x = -1.0
floor_stop_on_slope = not platform_detector.is_colliding()
move_and_slide() # Character is colliding
var anim := get_new_animation(false)
if anim != animation.animation:
animation.animation = anim
animation.play()
func get_new_animation(is_shooting := false) -> String:
var animation_new: String
if is_on_floor():
if absf(velocity.x) > 0.1:
animation_new = "walk"
else:
animation_new = "idle"
else:
if velocity.y > 0.0:
animation_new = "falling_straight"
else:
animation_new = "jumping"
return animation_new
func try_jump() -> void:
if is_on_floor():
pass
elif _double_jump_charged:
_double_jump_charged = false
velocity.x *= 2.5
else:
return
velocity.y = JUMP_VELOCITY

View File

@@ -1,3 +1,217 @@
[gd_scene format=3 uid="uid://dv0mokf4eogm7"]
[gd_scene load_steps=31 format=3 uid="uid://dv0mokf4eogm7"]
[node name="Princesse" type="Area2D"]
[ext_resource type="Script" path="res://princesse.gd" id="1_dkp7s"]
[ext_resource type="Texture2D" uid="uid://dr7fyh2rufsyj" path="res://sprite/princess_falling_direction.png" id="2_hholp"]
[ext_resource type="Texture2D" uid="uid://cc2vjgg2dw27g" path="res://sprite/princess_falling.png" id="3_kbaya"]
[ext_resource type="Texture2D" uid="uid://bwod37xemy88x" path="res://sprite/princess.png" id="4_iiu2b"]
[ext_resource type="Texture2D" uid="uid://b1624w7katr05" path="res://sprite/princess_jumping_impulsion.png" id="5_njcte"]
[ext_resource type="Texture2D" uid="uid://c2xtcu5ysgi7o" path="res://sprite/princess_jumping.png" id="6_srvje"]
[ext_resource type="Texture2D" uid="uid://d23lmsjrjw1mk" path="res://sprite/princess_wall_stick.png" id="7_8dix4"]
[sub_resource type="AtlasTexture" id="AtlasTexture_i248f"]
atlas = ExtResource("2_hholp")
region = Rect2(0, 0, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_e23c2"]
atlas = ExtResource("2_hholp")
region = Rect2(0, 50, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_fyqwp"]
atlas = ExtResource("3_kbaya")
region = Rect2(0, 0, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_mxdjd"]
atlas = ExtResource("3_kbaya")
region = Rect2(0, 50, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_yxjwj"]
atlas = ExtResource("4_iiu2b")
region = Rect2(0, 0, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_yqpcg"]
atlas = ExtResource("5_njcte")
region = Rect2(0, 0, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_8yyph"]
atlas = ExtResource("5_njcte")
region = Rect2(0, 50, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_ftqux"]
atlas = ExtResource("5_njcte")
region = Rect2(0, 100, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_du0hw"]
atlas = ExtResource("6_srvje")
region = Rect2(0, 0, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_gu3eg"]
atlas = ExtResource("6_srvje")
region = Rect2(0, 50, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_0nfn2"]
atlas = ExtResource("4_iiu2b")
region = Rect2(0, 50, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_wo2be"]
atlas = ExtResource("4_iiu2b")
region = Rect2(0, 100, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_4j10n"]
atlas = ExtResource("4_iiu2b")
region = Rect2(0, 150, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_kwlld"]
atlas = ExtResource("4_iiu2b")
region = Rect2(0, 200, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_57mjl"]
atlas = ExtResource("4_iiu2b")
region = Rect2(0, 250, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_34pfo"]
atlas = ExtResource("7_8dix4")
region = Rect2(0, 0, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_xck10"]
atlas = ExtResource("7_8dix4")
region = Rect2(0, 50, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_1qhca"]
atlas = ExtResource("7_8dix4")
region = Rect2(0, 100, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_bljfu"]
atlas = ExtResource("7_8dix4")
region = Rect2(0, 150, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_fvex7"]
atlas = ExtResource("7_8dix4")
region = Rect2(0, 200, 24, 50)
[sub_resource type="AtlasTexture" id="AtlasTexture_qw8g6"]
atlas = ExtResource("7_8dix4")
region = Rect2(0, 250, 24, 50)
[sub_resource type="SpriteFrames" id="SpriteFrames_q52wx"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_i248f")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_e23c2")
}],
"loop": true,
"name": &"falling_diagonals",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_fyqwp")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_mxdjd")
}],
"loop": true,
"name": &"falling_straight",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_yxjwj")
}],
"loop": true,
"name": &"idle",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_yqpcg")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_8yyph")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_ftqux")
}],
"loop": true,
"name": &"jump_impulsion",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_du0hw")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_gu3eg")
}],
"loop": true,
"name": &"jumping",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_yxjwj")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_0nfn2")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_wo2be")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_4j10n")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_kwlld")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_57mjl")
}],
"loop": true,
"name": &"walk",
"speed": 10.0
}, {
"frames": [{
"duration": 1.0,
"texture": SubResource("AtlasTexture_34pfo")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_xck10")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_1qhca")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_bljfu")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_fvex7")
}, {
"duration": 1.0,
"texture": SubResource("AtlasTexture_qw8g6")
}],
"loop": true,
"name": &"wall_stick",
"speed": 5.0
}]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_6r7th"]
height = 52.0
[node name="Princesse" type="CharacterBody2D"]
script = ExtResource("1_dkp7s")
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_q52wx")
animation = &"idle"
[node name="PlatformDetector" type="RayCast2D" parent="."]
collision_mask = 8
[node name="Camera2D" type="Camera2D" parent="."]
zoom = Vector2(2, 2)
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
position = Vector2(2, 0)
shape = SubResource("CapsuleShape2D_6r7th")

View File

@@ -10,11 +10,38 @@ config_version=5
[application]
config/name="Nouveau Projet De Jeu"
config/name="Princesse Lactose"
run/main_scene="res://level.tscn"
config/features=PackedStringArray("4.0", "GL Compatibility")
config/icon="res://icon.svg"
[input]
move_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":0,"key_label":4194321,"unicode":0,"echo":false,"script":null)
]
}
move_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":0,"key_label":4194319,"unicode":0,"echo":false,"script":null)
]
}
crouch={
"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":0,"key_label":4194322,"unicode":0,"echo":false,"script":null)
]
}
jump={
"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":0,"key_label":32,"unicode":32,"echo":false,"script":null)
]
}
[layer_names]
2d_render/layer_1="plateformes"
[rendering]
renderer/rendering_method="gl_compatibility"
renderer/rendering_method.mobile="gl_compatibility"