Posts for 2011


Strong 1.0.1

Just posting a blog to let everyone know about the latest release for strong, which is 1.0.1. There's no API changes, just a few things that are better under-the-hood. For more details see the change log.

Enjoy!

Ludum Dare 20: My Experience

From April 29 to May 2 Ludum Dare 20 has been going on. For those who don't know, the main competition involves making a game based on a certain theme in a 48 period; tough call. Hundreds of developers have a shot at this every four months, and I thought I'd give it a try. In this post, I'm going to write about my experience in it, and the lessons I learnt. I'll let you know now, however, the end result was me pulling out not long after half-way.

So anyway, I started when the competition was about 6 or 7 hours in. My plan was to use the Love2D engine, along with a personal framework I'd written for it. The theme was "It s Dangerous to go Alone! Take this!" So my first idea was to have sort of dangerous test facility which was pitch black with darkness (making it dangerous to go all alone), and you're given a light or something (the "this") to see your way through. Well that didn't work too well, so I switch the character to a rolling ball, and made "this" the ability to propel yourself in any which way.

Read more

Strong: Make Your Strings Stronger in Lua

For the last few days I've been working on a library called "strong". It's a string enhancement library for Lua. Strong adds a few operators to strings, and many methods to Lua's string library. I've already written more information in the README and the wiki, which you can go to for more information. Here's the direct link to the GitHub repo by the way.

Read more

Cameras in Love2D Part 2: Parallax Scrolling

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.

Now, for those who don't know, what is parallax scrolling? It's a way to get a pseudo-3D effect while still have all graphics and gameplay based in 2D. It's currently used very widely among 2D games, as it adds a sense of depth that normally isn't there.

Read more

Cameras in Love2D Part 1: The Basics

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.

Read more

Specifying Names in Lua Without Strings

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 class like this:

class('MyClass')

What we're going to change that into, is this:

Read more

Launcher

I've been working on a little game (in the LÖVE game engine), which for now I'm calling "Launcher". The core gameplay mechanic is this: you are a circle, which can stick to certain surfaces, and then launch yourself at great speed off them in the direction of the mouse. It's completely controlled by the mouse, you aim with it, and the distance between the player and the mouse determines the speed of launch.

On my YouTube channel I've already posted three gameplay videos of the work done so far. Here's the first:

Read more

Implementing Proper Getter/Setters in Lua

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, even attributes that don't need getter and setters, to keep your API consistent. This would end up slowing everything down.
  • It doesn't look as proper as using real getting and setting syntax, like obj.foo and obj.foo = v.
  • It's more to type.

What I really wanted was syntax like this:

Read more

Simulate Bitwise Shift Operators in Lua

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.

Read more

ClosureClass

I've recently created an experimental Lua object-orientation library using the closure approach to OOP. It's based largely on MiddleClass, sharing a lot of design features with it.

I've already written a README, so go and visit the GitHub repo for more information.

Mixin Inheritance in MiddleClass

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 mixin, because MiddleClass does not do this itself.

Read more

Singleton Class in MiddleClass (Lua)

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 on. So let's have a look at the method.

Read more

Generating a Joomla Password (for reseting)

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 JUserHelper();
$salt = $instance->genRandomPassword(32);
$final_pwd = $instance->getCryptedPassword($pwd, $salt) . ':' . $salt;
?>

(Note that I have to use the <?php tags to get syntax highlighting to work properly.)

Read more

Making a Dynamic Copyright With PHP

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 might want to wrap around the code in a helper function:

Read more