Castle

Quick Start

Here's all you need to do to get a simple Castle project running:

  1. Download and run Castle.
  2. Click the button to Create a Castle Project.
  3. We'll prompt you for a directory, and then we'll create a file called main.lua.
  4. Open main.lua in your favorite text editor. You're ready to go!

Want some ideas for what to do next? Read the next section of this page, where we'll learn how to draw a circle, print some logs, and move the circle around with the arrow keys.

Make Your First Castle Game

Follow this small tutorial to get oriented with Castle's basic workflow. You'll need a text editor and a few minutes.

Learning to LÖVE

Castle uses a programming language called lua, and a framework called LÖVE. If you're already familiar with LÖVE, you're in luck! Anything you can normally do with LÖVE will work in Castle.

If you aren't familiar with LÖVE, we'll go over some of the basics here. You might find the LÖVE API reference page useful to keep open while you work.

Getting Oriented

If you haven't already, follow the previous Quick Start section of this page. At this point, you should have a file called main.lua running inside Castle, and you should be editing main.lua in a text editor of your choice.

The URL Bar at the bottom of the screen shows you the path to the project you're running.

The Logs View on the right side of the screen is where you'll see development logs while you work.

Drawing a Circle and Reloading

Let's draw a circle on screen. Inside main.lua, find the line that says love.graphics.print(...). Delete that line and replace it with this:

love.graphics.setColor(0.4, 0.4, 1.0, 1.0)
love.graphics.circle("fill", 100, 100, 20, 32)

If you'd like to change the circle to be red, try replacing the first line with this:

love.graphics.setColor(1.0, 0.4, 0.4, 1.0)

Save your file, and then, with the Castle’s window focused, press Cmd+R on Mac, or Ctrl+R on Windows to reload and see the changes.

Printing Logs

If you’d like to debug using logs, Castle has a built-in logger. You can show and hide the Logs View in Castle by pressing Cmd+J (Mac) or Ctrl+J (Windows). If you can't already see the Logs View, try pressing these keys now.

To print a log when the up arrow key is pressed, add this code at the bottom of main.lua:

function love.update(dt)
  if love.keyboard.isDown("up") then
    print("up arrow pressed!")
  end
end

Save main.lua, Reload in Castle (Cmd or Ctrl + R), then try pressing the up arrow on your keyboard. You should see some logs appear. If you're on Windows, you might need to click in the game area first.

Moving the Circle

Let's move the circle around with the arrow keys.

  1. At the very top of main.lua, add this:
    local playerPos = {
      x = 100,
      y = 100
    }
  2. Find the line with love.graphics.circle(...) and change it to this:
    love.graphics.circle("fill", playerPos.x, playerPos.y, 20, 32)
  3. Change the contents of love.update(dt) to this:
      if love.keyboard.isDown("right") then 
        playerPos.x = playerPos.x + 256 * dt
      end
      if love.keyboard.isDown("left") then
        playerPos.x = playerPos.x - 256 * dt
      end
      if love.keyboard.isDown("up") then
        playerPos.y = playerPos.y - 256 * dt
      end
      if love.keyboard.isDown("down") then
        playerPos.y = playerPos.y + 256 * dt
      end

Save your revised main.lua, Reload in Castle (Cmd or Ctrl + R), then try moving the circle around with the arrow keys. If you're on Windows, you might need to click in the game area first.

That's it for now!

You should now have a simple program where you can move a circle with the arrow keys. What happens next is up to you!

Next Steps

View the source code for the completed tutorial.

Check out our list of Example projects to see more ideas about where you can go from here.

Need help? Or just want to chat with fellow Castlers? Join us on the Castle Discord!

Say hello and learn more about what we're doing: Twitter · Medium · Discord