Menu
CoddyTech

גיבור: הגעה למדף

חלק מהיחידה קלט ותנועה במסלול ה-Godot של Coddy. שיעור 28 מתוך 28.

המטרה היא המדף הגבוה עם הדגל. הגיבור נושא Banner, Label מוסתר שמציג הצלחת!

על הקרקע, הערך של position.y של הגיבור הוא 278. על המדרגה הוא 218, ועל המדף 158. לכן הגיבור נמצא על המדף כשהוא על הרצפה וערך position.y קטן מ־170:

if is_on_floor() and position.y < 170:
	$Banner.visible = true

החלק is_on_floor() חשוב. גם בקפיצה מהקרקע עוברים לרגע דרך 170, אבל באוויר.

כדי לנצח, קפוץ מעל הבור, אחר כך אל המדרגה, ואז אל המדף.

challenge icon

אתגר

בינוני

הצג כרזה כשהגיבור מגיע למדף.

  1. בסוף _physics_process(), הוסף תנאי if: is_on_floor() וגם position.y < 170.
  2. בתוכו, הצג את $Banner.

לחץ על "שחק" וטפס אל המדף: You made it! מופיע בכרזה. לאחר מכן לחץ על "בדיקה".

נסו בעצמכם

extends CharacterBody2D

var speed = 220
var acceleration = 1200
var friction = 2400
var gravity = 1000
var jump_velocity = -500
var start_position = Vector2()

func _ready():
	start_position = position

func _physics_process(delta):
	velocity.y += gravity * delta
	if Input.is_action_just_pressed("jump") and is_on_floor():
		velocity.y = jump_velocity
	var direction = Input.get_axis("move_left", "move_right")
	if direction == 0:
		velocity.x = move_toward(velocity.x, 0, friction * delta)
	else:
		velocity.x = move_toward(velocity.x, direction * speed, acceleration * delta)
	if direction > 0:
		$Look.scale.x = 1
	if direction < 0:
		$Look.scale.x = -1
	move_and_slide()
	if position.y > 400:
		position = start_position
		velocity = Vector2(0, 0)
quiz iconבחנו את עצמכם

השיעור הזה כולל חידון קצר. התחילו את השיעור כדי לענות עליו ולעקוב אחרי ההתקדמות.

כל השיעורים ביחידה קלט ותנועה

תרגלו בעצמכם: Godot אונליין