Explorar o código

:memo: Adapt code to illustrate OOP concepts

DricomDragon hai 2 semanas
pai
achega
967e6fddf2
Modificáronse 1 ficheiros con 11 adicións e 12 borrados
  1. 11 12
      godot/slides/274/ScriptOOP.tscn

+ 11 - 12
godot/slides/274/ScriptOOP.tscn

@@ -47,7 +47,7 @@ offset_bottom = 196.0
 text = "Orienté objet"
 
 [node name="GdScriptEdit" type="CodeEdit" parent="."]
-offset_left = 1011.0
+offset_left = 986.0
 offset_top = 18.0
 offset_right = 1895.0
 offset_bottom = 1064.0
@@ -56,19 +56,18 @@ theme_override_colors/font_color = Color(0, 0, 0, 1)
 theme_override_font_sizes/font_size = 46
 text = "class_name Penguin
 extends RigidBody2D
-# My amazing main character
 
-var speed: float = 0.0 # km/h
+func _process(_delta: float) -> void:
+	if position.y < 0.0 :
+		print(\"Plouf !\")
+		hide()
+	else:
+		show()
 
-func _ready():
-	speed = 10.0
-	for increment in range(4):
-		accelerate()
-	if penguin_speed > 100:
-		print(\"Tux flies!\")
-
-func accelerate() -> void:
-	speed = speed + 2.0"
+func _physics_process(_delta: float):
+	if position.y < -1.0f:
+		var nage = Vector2.UP * 42.0
+		apply_central_force(nage)"
 deselect_on_focus_loss_enabled = false
 virtual_keyboard_enabled = false
 syntax_highlighter = SubResource("CodeHighlighter_2654d")