Category: Tutorials

Linked Lists in Lua

Posted on November 16, 2012

As an example of creating custom data structures in Lua, I thought I'd give a little demonstration of a linked lists implementation. Note that this isn't going to be an in-depth tutorial or anything; for the most part I'll just be showing pieces of the code. Linked lists are wonderful data structures, perfect if you need to efficiently add, remove, and iterate through elements. The one trade off is that you can't find an element...

Read more...

Custom Cursors in Love2D

Posted on September 20, 2012

When making a game in LÖVE, you'll probably end up needing to customise the mouse cursor. As I recently had to do just that, I thought I'd make a quick tutorial on it. If you want an example cursor, here's the crosshair I'm using in a game right now. Now, all of what we need is contained within the love.mouse module. The first step is to hide the mouse with love.mouse.setVisible. You'll probably want to...

Read more...

Lua for Programmers Part 4: Tips and Tricks

Posted on September 09, 2012

If you haven't read the previous parts (one, two and three), then I'd highly recommend doing so. For reference, here's a list of the parts in this series: Part 1: Language Essentials, covers fundamental syntax and concepts such as operators, loops, and functions. Part 2: Data and Standard Libraries, covers Lua's built-in data types and some of the standard libraries. Part 3: More Advanced Concepts, deals with things like variable scope, advanced functions, and file...

Read more...

Lua for Programmers Part 3: More Advanced Concepts

Posted on September 07, 2012

If you haven't read part one and two already, I'd highly recommend doing so. For reference, here's a list of the parts in this series: Part 1: Language Essentials, covers fundamental syntax and concepts such as operators, loops, and functions. Part 2: Data and Standard Libraries, covers Lua's built-in data types and some of the standard libraries. Part 3: More Advanced Concepts, the current part; deals with things like variable scope, advanced functions, and file...

Read more...

Lua for Programmers Part 2: Data and Standard Libraries

Posted on August 27, 2012

If you haven't read part one already, I'd highly recommend doing so. For reference, here's a list of the parts in this series: Part 1: Language Essentials, covers fundamental syntax and concepts such as operators, loops, and functions. Part 2: Data and Standard Libraries, the current part; covers Lua's built-in data types and some of the standard libraries. Part 3: More Advanced Concepts, deals with things like variable scope, advanced functions, and file loading. Part...

Read more...

Lua for Programmers Part 1: Language Essentials

Posted on August 27, 2012

In this series we'll be taking a look at most everything you should know to program in Lua. The series is targeted at people who already know how to program, and as such I'll aim to be brief in my explanations. Here's an overview of the four parts the compose the series: Part 1: Language Essentials, the current part; covers fundamental syntax and concepts such as operators, loops, and functions. Part 2: Data and Standard...

Read more...

Getting More Ratings in Ludum Dare

Posted on May 02, 2012

I thought I'd share a few quick tips on getting more ratings, which I've picked up in my experience with Ludum Dare. Please note, I'm not putting this down as fact or anything, but merely expressing my own opinion. Rating Games Yeah, this one's kind of obvious by now I'd say. Your "coolness level" increases by one per game you rate, and the cooler you are, the higher chance you have of getting rated. Games...

Read more...

How It Works: The Thruster in Facilitated Escape

Posted on October 23, 2011

In this post I'll be taking a look at how I programmed aspects of the ship's thruster in my game, Facilitated Escape. I'll most likely be making more posts like this in the future (as in, I intend to make a series of "How It Works" posts). Initially I had a lot of trouble getting the thruster to look right; you might be able to see some of my troubles in the Ludum Dare time-lapse....

Read more...

Mouse Dragging in Love2D

Posted on September 06, 2011

In this tutorial, I'll be taking you through my method of enabling objects to dragged by the mouse (in LÖVE of course). You can view the completed code for this tutorial at gist #1196228. So, say you have an object with x/y coordinates, width, and height, and you want this object to be draggable by the mouse. For this tutorial, I'm just going to construct a table and put in the global, rect: function love.load()...

Read more...

Changing Filename Case in Git

Posted on August 31, 2011

UPDATE: A much easier way is to use git mv -f readme.txt README.txt. Thanks to "Gurpartap Singh" for pointing that out in the comments section. I thought I'd share a quick little trick I've learned for changing the case of a filename in Git. Git is (unfortunately) case-insensitive with filenames. Therefore, if you make a change to a filename's case without using git mv, it won't be picked up. If you do try to use...

Read more...

Glow Effect for Lined Shapes in Love2D

Posted on July 16, 2011

Recently I experimented with an easy way to make lined shapes glow (using LÖVE of course). There are of course other ways of doing it, and there are many styles of glow that can be used, but this is the one I came up with. love.graphics.setColor(r, g, b, 15) for i = 7, 2, -1 do if i == 2 then i = 1 love.graphics.setColor(r, g, b, 255) end love.graphics.setLineWidth(i) -- draw lined shape here...

Read more...

Lua Metatables Tutorial

Posted on June 30, 2011

In this tutorial I'll be covering a very important concept in Lua: metatables. Knowledge of how to use metatables will allow you to be much more powerful in your use of Lua. Every table can have a metatable attached to it. A metatable is a table which, with some certain keys set, can change the behaviour of the table it's attached to. Let's see an example. t = {} -- our normal table mt =...

Read more...

A Guide to Getting Started with Love2D

Posted on June 14, 2011

In this post, I'll attempt to give you my personal guide on some good steps to getting started with the Love2D game engine (the proper name is LÖVE, which I'll be using from now on). It's not perfect, of course, but I hope you find it useful. If you have any feedback, I'd love to hear from you in the comments. What is LÖVE? I'm guessing you probably already know, but for those who don't,...

Read more...

Making a 3D Button in CSS

Posted on June 05, 2011

In this tutorial I'll be showing you how to create a 3D-looking button, made out of pure CSS. The button we'll be building is similar to the button I've used on my project pages. Take note that this uses a number of CSS3 properties, like border-radius and box-shadow. Anyway, let's get into it. The HTML The only HTML code we'll need is a div tag with the proper class: <div class="big-button">Your Text Here</div> If you...

Read more...

ASCII Code Manipulation

Posted on May 12, 2011

While inspecting the ASCII table a little while ago, I noticed some interesting patterns in it, which can be used for string manipulation. It's important to understand the ASCII table, because it's the base of most encodings. Note I'll be using C-like syntax in my examples, but I won't be taking advantage of C's characters, which convert stuff like 'a' into 97 (a's ASCII code). An Introduction For those who don't know what much about...

Read more...

Cameras in Love2D Part 3: Movement Bounds

Posted on May 09, 2011

Because there was some interest in a part 3, of this series, I've written it, and in this part we'll cover creating bounds that the camera can't move beyond. Make sure you've read part 1 and part 2 before continuing. In case you're wondering what I mean by this, I mean restricting the movement of the camera to a "box", as in, having minimum and maximum x/y coordinates for the camera. This comes in handy...

Read more...

Draw Origins in Love2D

Posted on May 06, 2011

In this post I'm going to be showing you origins when drawing stuff in Love2D. First of all, what are origins? They specify the offset for the origin of the object's x/y coordinates. In other words, if you specify the x origin to be 20, the object will be drawn 20 pixels to the left, as in x - 20. It's the same for the y origin: if we have a y origin of 20,...

Read more...

Cameras in Love2D Part 2: Parallax Scrolling

Posted on April 22, 2011

In part 1 we constructed a basic camera. Now we're going to extend it by adding some parallax scrolling. Note that the method I'll use is probably not the prettiest, as I came up with it in half an hour. Nevertheless, this will be a starting point for you to develop your own system. What Is It? Now, for those who don't know, what is parallax scrolling? It's a way to get a pseudo-3D effect...

Read more...

Cameras in Love2D Part 1: The Basics

Posted on April 19, 2011

This is the first of a couple of blogs on creating cameras in the LÖVE engine. This part will deal with the fundamentals of creating a camera. Part two will deal with parallax scrolling and creating layers. So, let's get to it! Update: I've actually ended up writing a part 3, which covers restricting camera movement. The Functions The functions we'll need are these: love.graphics.pop love.graphics.push love.graphics.translate love.graphics.rotate love.graphics.scale Love2D (I'll use this name from...

Read more...

Specifying Names in Lua Without Strings

Posted on April 18, 2011

Lua is the most flexible language I've ever used, aside from its speed, this is probably the best thing about it. In this post, I'm going to show you how to specify names of things in function arguments, without strings. The method I'll use it a bit hackish, and isn't fit for normal operation; but hey, Lua allows us do it! For an example, say you had an OOP implementation that used a function called...

Read more...

Implementing Proper Getter/Setters in Lua

Posted on April 04, 2011

When I create a class in Lua, there are always times when I need to use a getter or setter on attributes, instead of raw access. The way I've always done this is to use methods with names like getFoo and setFoo. And then to keep my API consistent, I have to switch every single property to use these getter/setter methods. The pain about these type of methods is that: You have to switch everything,...

Read more...

Some Uses for the Modulos Operator (%)

Posted on March 21, 2011

I've been learning about a few of the awesome things you can do with the modulos operator lately. For those who don't know, the modulos operator (the percent symbol in code) gives the remainder of dividing two numbers. Therefore, 10 % 4 equals 2, because 4 goes into 10 two times, and what we have left is the number 2. Now let's get into what we can do (note, I'll be using Ruby code here,...

Read more...

Simulate Bitwise Shift Operators in Lua

Posted on March 21, 2011

EDIT: Here's a couple functions which will do the shift operations that I've put in gist #938502. The fact that Lua doesn't have bitwise operators is a pain. There are pure Lua implementations out there, such as LuaBit, but I find these to be a little slow (I think LuaBit using tables or something like that). I've found a way to simulate both the left-shift and right-shift operator by using some simple mathematics. Left-Shift By...

Read more...

Mixin Inheritance in MiddleClass

Posted on March 09, 2011

The technique I'm about to present, may seem obvious, but I'll share it anyway. The way I would create mixins that inherit stuff from other mixins is this: Mixin = {} function Mixin:included(class) if not includes(ParentMixin, class) then class:include(ParentMixin) end end When the mixin is included, it will check whether the class includes the mixin, and if not, it will include it, therefore simulating inheritance. It's good to check if the class includes the parent...

Read more...

Singleton Class in MiddleClass (Lua)

Posted on March 07, 2011

I thought I'd demonstrate a method for making a singleton class in MiddleClass. If you don't know, MiddleClass is an object-orientation library for Lua. So why would you want to make a class that only has one instance with MiddleClass? Couldn't you just use a table? Well, making it a class in MiddleClass allows you to take advantage of a number of other cool things that MiddleClass has on offer, like mixins, inheritance and so...

Read more...

Generating a Joomla Password (for reseting)

Posted on February 23, 2011

I recently found myself in the awkward situation of having only a Super Admin user in the Joomla installation, and neither I nor my client knew the password. I had to the fix the problem, and I decided to do so by generating a Joomla user password (which required a lot of searching through code, mind you). Here's the PHP code I used: <?php // JUserHelper class from libraries/joomla/user/helper.php $pwd = 'my_new_password'; $instance = new...

Read more...

Making a Dynamic Copyright With PHP

Posted on February 23, 2011

I though I'd just write a quick tutorial on how I make a dynamic copyright for my websites. If you don't know what a function does in the code, look it up on the PHP manual. <?php echo strftime('%Y', time()); ?> That's the year generating code. It's just grabbing the year from the current timestamp. So we could do something like this in the copyright: &copy; <?php echo strftime('%Y', time()); ?> Legion of Weirdos. You...

Read more...

Using AMFPHP Toolbox 2.1

Posted on November 15, 2010

Yesterday I recorded and released a 10 video tutorial series how to use my ActionScript 3 library, AMFPHP Toolbox. I've been meaning to do this for ages, but, you how it is. You can view all the videos at its YouTube playlist. Due to AMFPHP kindly tweeting about it, and a number of others retweeting (1, 2, 3, 4, 5 - thanks guys!), there's been a big upward spike in my visitors graph. In fact,...

Read more...