encompass-cs-docs/content/getting_started/case_study_love.md

87 lines
2.5 KiB
Markdown
Raw Normal View History

2019-05-22 20:56:04 +00:00
---
title: "Case Study: LÖVE"
date: 2019-05-22T10:38:01-07:00
weight: 12
2019-05-22 20:56:04 +00:00
---
2019-06-10 23:41:30 +00:00
LÖVE is a 2D game engine that uses Lua as its scripting language. Because of this, we can use [Encompass-TS](https://github.com/encompass-ecs/encompass-ts) with the [TypescriptToLua transpiler](https://github.com/TypeScriptToLua/TypeScriptToLua) to make games for it.
If you are new to TypeScript, or even new to programming in general, I _strongly_ recommend reviewing the [TypeScript handbook](https://www.typescriptlang.org/docs/handbook/basic-types.html).
Install [LÖVE](https://love2d.org).
2019-05-22 20:56:04 +00:00
Make sure you can run it from the terminal by running:
```sh
2019-06-12 01:20:41 +00:00
love
2019-05-22 20:56:04 +00:00
```
You should see the LÖVE window pop up with the NO GAME screen. If you don't see this, check your terminal environment. On Windows you probably need to manually add the path where you installed LÖVE to your Path Environment Variable and then restart the machine. Thanks Windows!
Encompass-TS uses [Node.js](https://nodejs.org/) for its build process and [npm](https://www.npmjs.com/) to manage dependencies.
Install Node, which automatically installs npm.
Make sure it is properly installed by running:
```sh
2019-06-12 01:20:41 +00:00
npm
2019-05-22 20:56:04 +00:00
```
You should see npm print out a bunch of help information. Now we're almost ready to begin.
Download the [Encompass/LÖVE starter project](https://github.com/encompass-ecs/encompass-love2d-starter). Place its contents in a folder and rename the folder to the name of your project. Change information in the `package.json` file where appropriate.
Now we are ready. Enter the project folder in your terminal and do:
```sh
2019-06-12 01:20:41 +00:00
npm install
2019-05-22 20:56:04 +00:00
```
2019-06-10 23:41:30 +00:00
This will install everything you need to compile your project to Lua.
2019-05-22 20:56:04 +00:00
The starter project contains some scripts to automate the build process.
2019-06-12 01:20:41 +00:00
To create a clean build from scratch, do:
```sh
npm run build
```
To incrementally build your game as you make changes, do:
```sh
npm run watch
```
This will run continuously and build only files that change. It will reduce your build times significantly, so I recommend using it!
To copy your assets into the game build, do:
```sh
npm run copyassets
```
Make sure to do this if you are in incremental mode and make changes to assets.
2019-05-22 20:56:04 +00:00
To run your game, do:
```sh
2019-06-12 01:20:41 +00:00
npm run love
2019-05-22 20:56:04 +00:00
```
Or, on Windows:
```sh
2019-06-12 01:20:41 +00:00
npm run lovec
2019-05-22 20:56:04 +00:00
```
so that you get proper debug console output.
2019-06-12 01:20:41 +00:00
If you want to completely clean your build folder without making a new build, do:
2019-05-22 20:56:04 +00:00
```sh
2019-06-12 01:20:41 +00:00
npm run clean
2019-05-22 20:56:04 +00:00
```
2019-05-22 21:06:02 +00:00
That's everything you need to start making a game with Encompass and LÖVE!