tutorial:umaipixel-2dplatformer

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen Revision Vorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
tutorial:umaipixel-2dplatformer [2023/07/04 08:14] – [First Script] 185.38.49.0tutorial:umaipixel-2dplatformer [2023/07/04 21:06] (aktuell) – [Character animation] 185.38.49.0
Zeile 14: Zeile 14:
       * KinematicBody2D       * KinematicBody2D
       * Sprite\\ Sprite Reimport mit Preset 2D Pixel\\ Sprite Einstellungen für CharacterMap       * Sprite\\ Sprite Reimport mit Preset 2D Pixel\\ Sprite Einstellungen für CharacterMap
 +      * [[https://opengameart.org/content/a-platformer-in-the-forest|Assets mit Beschreibung]]
       * CollisionsShape2D       * CollisionsShape2D
       * Group Selected Nodes\\ {{ :tutorial:schnappschuss_070423_075207_am.jpg?400 |}}       * Group Selected Nodes\\ {{ :tutorial:schnappschuss_070423_075207_am.jpg?400 |}}
Zeile 85: Zeile 86:
 </codedoc>  </codedoc> 
 ===== Jumping and gravity ===== ===== Jumping and gravity =====
 +{{youtube>xAXyHxxYPrQ?}}\\
 +Version 2.0 - Gravitation und Springen
 +<codedoc code:c++>
 +extends KinematicBody2D
 +
 +const SPEED = 60
 +const GRAVITY = 10
 +const JUMP_POWER = -250
 +const UP_DIR = Vector2(0, -1)
 +
 +var velocity = Vector2()
 + 
 +func _physics_process(delta):
 + if Input.is_action_pressed("ui_right"):
 + velocity.x = SPEED
 + elif Input.is_action_pressed("ui_left"):
 + velocity.x = -SPEED
 + else:
 + velocity.x = 0
 +
 + if Input.is_action_pressed("ui_up"):
 + velocity.y = JUMP_POWER
 +
 + # velocity.y = velocity.y + GRAVITY
 + velocity.y += GRAVITY
 +
 + velocity = move_and_slide(velocity, UP_DIR)
 +</codedoc>
 +Version 2.1 - jump on ground
 +<codedoc code:c++>
 +extends KinematicBody2D
 +
 +const SPEED = 60
 +const GRAVITY = 10
 +const JUMP_POWER = -250
 +const UP_DIR = Vector2(0, -1)
 +
 +var velocity = Vector2()
 +var on_ground = false
 + 
 +func _physics_process(delta):
 + if Input.is_action_pressed("ui_right"):
 + velocity.x = SPEED
 + elif Input.is_action_pressed("ui_left"):
 + velocity.x = -SPEED
 + else:
 + velocity.x = 0
 +
 + if Input.is_action_pressed("ui_up"):
 + if on_ground == true:
 + velocity.y = JUMP_POWER
 + on_ground = false
 +
 + # velocity.y = velocity.y + GRAVITY
 + velocity.y += GRAVITY
 +
 + if is_on_floor():
 + on_ground = true
 + else:
 + on_ground = false
 +
 + velocity = move_and_slide(velocity, UP_DIR)
 +</codedoc>
 ===== Tilsets and Tilemaps ===== ===== Tilsets and Tilemaps =====
 ===== Character animation ===== ===== Character animation =====
 +  * Sprite durch AnimatedSprite ersetzen
 +  * Animationen anlegen
 +        * fall, idle, jump jweils ein Bild, Speed = 0 FPS, Loop = false
 +        * run 5 Bilder
 +        * [[https://opengameart.org/content/a-platformer-in-the-forest|Assets mit Beschreibung]]
 +<codedoc code:c++>
 +extends KinematicBody2D
 +
 +const SPEED = 60
 +const GRAVITY = 10
 +const JUMP_POWER = -250
 +const UP_DIR = Vector2(0, -1)
 +
 +var velocity = Vector2()
 +var on_ground = false
 + 
 +func _physics_process(delta):
 + if Input.is_action_pressed("ui_right"):
 + velocity.x = SPEED
 + $AnimatedSprite.play("run ")
 + $AnimatedSprite.flip_h = false
 + elif Input.is_action_pressed("ui_left"):
 + velocity.x = -SPEED
 + $AnimatedSprite.play("run ")
 + $AnimatedSprite.flip_h = true
 + else:
 + velocity.x = 0
 + if on_ground:
 + $AnimatedSprite.play("idle")
 +
 + if Input.is_action_pressed("ui_up"):
 + if on_ground == true:
 + velocity.y = JUMP_POWER
 + on_ground = false
 + $AnimatedSprite.play("jump")
 +
 + # velocity.y = velocity.y + GRAVITY
 + velocity.y += GRAVITY
 +
 + if is_on_floor():
 + on_ground = true
 + else:
 + on_ground = false
 + if velocity.y < 0:
 + $AnimatedSprite.play("jump")
 + else:
 + $AnimatedSprite.play("fall")
 +
 + velocity = move_and_slide(velocity, UP_DIR)
 +</codedoc>
 ===== Fireball alright! ===== ===== Fireball alright! =====
 ===== Fireball alright and left ===== ===== Fireball alright and left =====
  
  • tutorial/umaipixel-2dplatformer.1688451252.txt.gz
  • Zuletzt geändert: 2023/07/04 08:14
  • von 185.38.49.0