Home

Tutorial

Introduction

Welcome to the tutorial! Today we're going to be learning the basics of AstralCode.

Let's start by making a Flappy Bird game!

Click Next to continue.

1/14

Sprites

For working with sprites.

  • sprite.size: The size of the sprite.

    Example: sprite.size = 50

  • sprite.visible: Whether or not the sprite is visible.

    Example: sprite.visible = false

  • sprite.x: The horizontal position of the sprite.

    Example: sprite.x = 100

  • sprite.y: The vertical position of the sprite.

    Example: sprite.y = 200

  • sprite.rotation: The rotation of the sprite.

    Example: sprite.rotation = 45

  • touching(object, other): Returns true if the object is touching the other object.

    Example: if (touching(player, coin)) { score += 1 }

Control and Time

For controlling when functions run, how often, and conditional execution.

  • forever(func): Runs the function every frame.

    Example: forever(myFunction)

  • after(seconds, func): Runs the function after the specified number of seconds.

    Example: after(2, myFunction)

  • every(seconds, func): Runs the function every specified number of seconds.

    Example: every(1, myFunction)

  • if (condition) { ... }: Executes code block if condition is true.

    Example: if (score > 100) { levelComplete() }

  • if (condition) { ... } else { ... }: Executes first block if condition is true, second block if false.

    Example: if (health > 0) { continue() } else { gameOver() }

  • if (condition) { ... } else if (condition) { ... } else { ... }: Multiple conditional branches.

    Example: if (score > 100) { giveGold() } else if (score > 50) { giveSilver() } else { giveBronze() }

Keyboard and Mouse

For reading input from the keyboard and mouse.

  • Mouse.x: The horizontal position of the mouse cursor.

    Example: sprite.x = Mouse.x

  • Mouse.y: The vertical position of the mouse cursor.

    Example: sprite.y = Mouse.y

  • Mouse.isDown(button): Returns true if the specified button is down.

    Example: if (Mouse.isDown(MouseButton.Left)) { shoot() }

  • Keyboard.keyTapped(key): Returns true if the specified key was tapped.

    Example: if (Keyboard.keyTapped(Key.Space)) { jump() }

  • Keyboard.keyHeld(key): Returns true if the specified key is held down.

    Example: if (Keyboard.keyHeld(Key.ArrowRight)) { moveRight() }

Math

Additional math functions.

  • Math.random(min, max): Returns a random number between min and max.

    Example: let x = Math.random(0, 100)

  • Math.sin(angle): Returns the sine of the angle.

    Example: let height = Math.sin(angle) * 100

  • Math.cos(angle): Returns the cosine of the angle.

    Example: let width = Math.cos(angle) * 100

  • Math.tan(angle): Returns the tangent of the angle.

    Example: let slope = Math.tan(45)