Game Programming With Godot
Game Programming With Godot
Game Programming With Godot
Godot
foss-gbg 2019-10 // Johan Thelin
What we will look at today
I’ve done lots and lots of embedded devices with Qt, Linux, etc
Visual editor
Open source
www.godotengine.org
Getting Godot
● A ~25MB download from https://godotengine.org/download
● Available for Linux, Windows, MacOS and Server
● Create nodes
○ Node2D
■ Sprite x2
■ Area2D
● CollisionShape2D
The flipper script
extends Node2D
signal flipped_changed
var flipped : bool = false setget set_flipped
func _ready():
$Label.text = str(no_of_flipped_cards())
$Card.connect("flipped_changed", self, "_on_flipped_changed")
$Card2.connect("flipped_changed", self, "_on_flipped_changed")
func _on_flipped_changed():
$Label.text = str(no_of_flipped_cards())
From https://github.com/e8johan/supermemory/blob/master/table.gd#L210
Platformer time!
● The game plan:
○ Create tile set
○ Create tile map
○ Create character
○ Jump around
● CaptainCode!
Importing
Enter into the World
Jump around!
extends KinematicBody2D func _physics_process(delta):
get_input()
export (int) var speed = 240 velocity.y += gravity * delta
export (int) var jump_speed = -320 velocity = move_and_slide(velocity, Vector2.UP)
export (int) var gravity = 600 if Input.is_action_just_pressed("jump"):
if is_on_floor():
var velocity = Vector2.ZERO velocity.y = jump_speed
func get_input():
velocity.x = 0
if Input.is_action_pressed("ui_right"):
velocity.x += speed
if Input.is_action_pressed("ui_left"):
velocity.x -= speed http://kidscancode.org/godot_recipes/2d/platform_character/
What is an input?
Animations!
● Change Captain Code from Sprite to AnimatedSprite
● New SpriteFrames in Frames
● Add the following:
○ Idle
○ Run
○ Jump
Play the right animation
func get_input() -> int: func _physics_process(delta):
var res : int = 0 var dir := get_input()
velocity.x = 0 if dir > 0:
if Input.is_action_pressed("ui_right"): $Sprite.flip_h = false
velocity.x += speed $Sprite.play("walk")
res = 1 elif dir < 0:
if Input.is_action_pressed("ui_left"): $Sprite.play("walk")
velocity.x -= speed $Sprite.flip_h = true
res = -1 else:
return res $Sprite.play("idle")
…
if is_on_floor():
...
else:
$Sprite.play("jump")
What about 3D?
● You will learn about:
○ GridMaps and Mesh libraries
○ Basic lights and shadows
○ 3D collisions
Meshes and Maps
● MeshInstance
○ Mesh: CubeMesh
○ Create Convex Static Body
● Material
● SpatialMaterial
● Albedo
A World
● New 3D Scene - World
○ GridMap
○ Mesh Library = meshes.tres
● Setup inputs
● Add to world
Movement script
extends KinematicBody if Input.is_action_pressed("left"):
velocity.x = -SPEED
var velocity : Vector3 = Vector3.ZERO elif Input.is_action_pressed("right"):
velocity.x = SPEED
const SPEED = 10 else:
const GRAVITY = 10 velocity.x = 0
if is_on_floor():
if Input.is_action_just_pressed("jump"):
velocity.y = JUMP
Going VR
● Godot comes with AR and VR support
● I’ve played around with SteamVR (Oculus DK2) and Google Cardboard
● Initialize sub-system:
func _ready():
var interface = ARVRServer.find_interface("Native mobile")
if interface and interface.initialize():
get_viewport().arvr = true