Skip to main content

Hello World With LOVE2D

 


I came to know about the LOVE2D thing when I taking the "CS50's Introduction to Game Development" course on Edx.

" LÖVE is a framework for making 2D games in the Lua programming language. LÖVE is totally free, and can be used in anything from friendly open-source hobby projects, to evil, closed-source commercial ones." - according to the official  LOVE2D  website.

As the instructor of the course was demonstrating the usage of LOVE and the LUA framework to make some games, my initial reaction was, "Wow. This really looks simpler than other frameworks for game development. This could be done as a simple Game Development Course for kids with Code Chautari. So I wanted to give it a try to see how easy and convenient it will to make the first game, from a kids's perspective who isn't a code per se.

PS: My intention was to make a simple game without understanding the underlying functionalities of the framework itself.

HELLO WORLD

The first one is always, "Hello World!", isn't it? :D 

STEPS

1. I went to the official page. https://love2d.org/wiki/Main_Page

2. I clicked on "Getting Started" to reach to this page. https://love2d.org/wiki/Getting_Started

3. It says -

Get LÖVE

Download the latest version of LÖVE from the website, and install it. If you're on Windows and don't want to install LÖVE, you can also just download the zipped executables and extract them anywhere.


4. I definitely wanted the easy path to install. So I downloaded the 'windows 64 bit' installer from here. https://love2d.org/#download 

5. The next step was to run some code and see the output. The website says- 

Making a Game

To make a minimal game, create a folder anywhere, and open up your favorite text editor. Sublime Text is a pretty good one for all operating systems, and it has Lua support built in. Create a new file in the folder you just created, and name it main.lua. Put the following code in the file, and save it.

function love.draw()
    love.graphics.print("Hello World", 400, 300)
end

6. The instructions were pretty straightforward : 
  • Download and install Sublime Text editor
  • Create a folder 'anywhere' on your PC 
  • Open the folder with Sublime 
  • Create a new file named "main.lua" inside the folder. (YES, the name has to be exactly main.lua)
  • Paste the code and save the file.
7. It was easy to do this. Nothing really complicated. But HOW DO I RUN THE CODE???

8. Here's what the website says-

Running Games

LÖVE can load a game in two ways:

  • From a folder that contains a main.lua file.
  • From a .love file that has a main.lua file in the top-most directory level (aka root)

For creating .love files see Game Distribution.


Windows

ZeroBrane StudioSublime TextNotepad++, and SciTE allow you to launch the game from within their code editors.

Otherwise, the easiest way to run the game is to drag the folder onto either love.exe or a shortcut to love.exe. Remember to drag the folder containing main.lua, and not main.lua itself.

You can also launch the game from the command line:

"C:\Program Files\LOVE\love.exe" "C:\games\mygame"
"C:\Program Files\LOVE\love.exe" "C:\games\packagedgame.love"

You can create a shortcut to do this; simply make a shortcut to love.exe, right-click on it and select "Properties", and then put the command line you want in the "Target" box for the shortcut.

On Windows, there is a special command-line option which will attach a console to the window, allowing you to see the result of print calls (equivalent to setting t.console=true in conf.lua or running lovec.exe (since 0.10.2)):

"C:\Program Files\LOVE\love.exe" --console

9. There are a lot of ways to run/load the game, it seems. I had to go for the easiest way. (Course for Kids! Remember?)

10. It says -
ZeroBrane StudioSublime TextNotepad++, and SciTE allow you to launch the game from within their code editors.


So, it means Sublime can load the game within itself. Well, that's cool and convenient. Yay, no command lines! :D 
But how? 
Now you can use Ctrl+B or Cmd+B to run your love project.

I tried CTRL+B and it worked fine. No any hassles. 

If it didn't work, you can check your BUILD SYSTEM.

Make sure there is a build  system named 'love-run' and that it is selected. 

If there is no such build system. Do this.

Simple Build System

Create a new Build System: Tools -> Build System -> New Build System and use the following code.

{
    "selector": "source.lua",
    "file_regex": "^Error: (?:[^:]+: )?([^: ]+?):(\\d+):() ([^:]*)$",
    "windows": {
        "cmd": ["C:/Program Files/LOVE/love.exe", "${folder:${file_path}}"],
        "shell": true
    },
    "osx": {
        "cmd": ["/Applications/love.app/Contents/MacOS/love", "${folder:${file_path}}"]
    },
    "linux": {
        "cmd": ["love", "${folder:${file_path}}"]
    }
}

Save it in the suggested location as love-run.sublime-build.

Now you can use Ctrl+B or Cmd+B to run your love project.


BONUS

This page (https://love2d.org/wiki/Sublime_Text) has additional instructions on how to make Sublime ready for LOVE2D. 

I installed the Lua (Love) syntax inside the Sublime itself. Basically it's just for syntax highlighting, snippets, autocompletion and build rules for LUA , which is the programming language used in LOVE2D. 
  • Install Package Control 


    Press Ctrl+Shift+P to open the command palette.
    When you type just "package" you can see a list of suggestions, click on "Package Control: Install Package". This will install package control in your Sublime.

  • Enable Lua (Love) syntax highlighting


    Press Ctrl+Shift+P to open the command palette.
    When you type just "lua" you can see a list of suggestions, click on "Set Syntax: Lua (Love)". This will Lua Love package in your Sublime.

Comments

Popular posts from this blog

Bikharney Ka Mujhko Shauq Hai Bada | Qala | Guitar Chords and Lyrics

Full song here:  https://youtu.be/-lcd1ixHqjE?t=670  or here  https://youtu.be/1Hd7Gl_mLzw G                                             C Bikharney Ka Mujhko, Shauq Hai Bada G                D                        C  G  D Sameitega Mujhko, Tu Bata Zara... G                                                C Haaye, Bikharney Ka Mujhko, Shauq Hai Bada G                D                        C  G  D Sameitega Mujhko, Tu Bata Zara... G D G G                 C                                G Doob-ti Hai Tujh Mein, Aaj Meri Kashti G                    C                  G Guftagu Mein Utri Baat Ki Tarah G                   C                               G Ho, Dekh Ke Tujhey Hi, Raat Ki Hawa Ne G                         C            D               G Saans Thaam Li Hai Haath Ki Tarah, Haaye... G                                             C                Ki Aankhon Mein Teri Raat Ki Nadi G                         D Yeh Baazi To Haari Hai G      C        G D Sau Feesadi... G           

Timi Uta Ma Yeta (Sunsaan Raat Ma) Guitar Chords - Pratik Gurung Cover - Original by Milan Newar, Rajan Raj Shiwakoti

 I came across this song when Kanden Limbu sang this in Nepal Idol.  He was one of the contestants. I thought it was his original. Surprisingly, it is not. His was based on Pratik Gurung's cover. This is actually a full fledge song with a music video. Here's the original one. However, I like the cover version. Here are the chords for a portion of the song. The chords are based on this tutorial . In the tutorial, plucking is used. You can strum as well if that's what you prefer.  CAPO: 2nd fret STRUMMING: D-DU Plucking used: 5-2-3 (C and Am), 4-2-3 (FT and GT), 6-2-3 (G) Chords: C, Am, G Major, F Major Triad (FT), G Major Triad (GT) NOTE: It's easier if you play G Major in C's original position; just move 2 and 3 fingers one step up.   C                             Am (Sunsan raat ma yo mero aatma FT               GT    C Chasakka bijheko mayalu C                             Am Timlai nai samjhi ma ruda ruda FT       GT   C Sirani bhijheko ) x 2 C                  

Pokhiyera Ghaam Ko Jhulka Guitar Chords|| Narayan Gopal || Ambar Gurung || Hari Bhakta Katuwal

  Pokhiyera Ghaam Ko Jhulka Guitar Chords || Narayan Gopal  Composer: Ambar Gurung Lyrics: Haribhakta Katwal Vocals: Narayan Gopal Guitar Chords based on tutorial by Nepali E-Chords . I take no responsibility if the chords are not absolutely right. But it sounded good enough for me.  Chords used: G, C, D, Am, Em, Bm Strumming: D-DUDU Intro: D       G      D             G              D      G Pokhiyera Ghamko Jhulka, Bhari Sangharama G                     D                     Em                G Timro Jindagiko Dhoka, Kholu Kholu Lagchha Hai Am                     C           D Kholu Kholu Lagchha Hai D      G      D    G       D      G Sayapatri Fula Sitai, Fakri Aaganama G                  D          Em              G Batasko Bhaka Tipi, Bolu Bolu Lagchha Hai Am                C           D Bolu Bolu Lagchha Hai Verse:1 G                Bm                     G                         D (Kati