Thursday, 24 January 2013

Lua & Lanarts

So lately I have been making some significant progress on the Lua side of Lanarts. Here's some summary!

LuaWrap, my pet Lua binder

After much frustration with existing Lua binding solutions (manual bindings, LuaBind, SimpleLuaBinder) I decided like any arrogant programmer to simply write my own. Of course, since I wrote it from the ground up, it suits my use-case quite well.

It is fairly small (24 short source files), flexible, and does not try to control your Lua environment in any way like SLB does. As well, although some performance was traded for ease-of-use, it provides an easy to use interface to eg Lua tables that suffers no performance penalties (assuming sufficient inlining). Here's an example of binding a global variable that should compile to the same code as if written by hand:

void bind_globals(lua_State* L) {
     LuaSpecialValue globals = luawrap::globals(L);

     globals["foo"] = "bar";
     globals["baz"] = 1;
}

LuaWrap is located in the lanarts source-tree under src/luawrap/. It does not depend on any libraries other than Lua.

Rewriting the main loop

So I wanted to move more towards having Lanarts as a game engine controlled by Lua. Now I definitely treat this as the compromise that it is -- it is perfectly possible to write a game in Lua, and that is not the goal. The plan is to allow people to modify the game very flexible in Lua without worrying about the networking aspect (except possibly for very heavy modification). The hope is that will inspire experimentation with the game mechanics.

So, as a start to this direction, I rewrote the main loop in Lua. Here's a look at the inside of the loop!

function main()
    net.sync_message_consume()

    local timer = timer_create()

    if not steponly then
        game.draw()
    end

    if not game.step() then 
        return false 
    end

    if not game.input_handle() then 
        return false 
    end

    local surplus = settings.time_per_step - timer:get_milliseconds()

    if surplus > 0 then 
        game.wait(surplus) 
    end

    return true
end

Object-Oriented Lua!

Figuring I'd continue this top-down approach, I have begun working on porting some of the menu code in Lua. For the first time, this actually meant I wanted to write something object-oriented on the Lua side! Now, OOP isn't a silver bullet, and I always like to weigh the pros & cons of other solutions -- but for graphical interfaces I think object orientation makes a lot of sense.

The first task I had was to decide on an object model. Now I think this is a really cool part of Lua -- it does not impose an object model on you. I settled on a very simple syntax, a single function 'newtype' returns a table suitable for use a 'type'. After which you simply add methods to the type. A special method, the 'init' method, is used to form a 'create' function. Here's what this looks like in action!

import "utils.lua" -- imports 'do_nothing'

TextLabel = newtype()

function TextLabel:init(font, options, text)
    self.font = font
    self.options = options
    self.text = text
end

TextLabel.step = do_nothing

function TextLabel:draw(xy)
    self.font:draw( self.options, xy, self.text )
end

-- Example usage
mylabel = TextLabel.create(font, options, text)

Some things notable here that highlight features of Lua:
  1. For people coming from a Python background, 'import' seems like a Lua keyword. Actually, it's a function that is being called with a string literal. Lua allows this syntax for one-argument table & string literal functions.
  2. 'function TextLabel:draw(xy)' is equivalent to 'function TextLabel.draw(self, xy)'. The colon operator is nothing more than syntax sugar for 'pass self as first parameter'.
  3. Lua silently (for better, or for worse!) ignores extra parameters, allowing a generic 'do_nothing' function like the one used.
 Anyway, that's all for today! Just wanted to give an update as I take a break from gameplay-oriented updates, and the dreaded mess of implementing client-side prediction. Stay tuned.

Sunday, 30 December 2012

My Year of Game Development

TL;DR? It's new years, and the first release of lanarts in 3 months! 
Download: here!
Github link

I believe I've grown a lot as a programmer in the past year. My knowledge of version control has expanded greatly -- from initially using SVN as little more than a file drop. I've moved from using windows exclusively to using linux exclusively. I started working at Red Hat this summer and learned much about real-world code (for the curious, I'm on the OpenJDK team, working on icedtea-web).

I decided to write a retrospective on my past year of game development on lanarts, I hope you enjoy it.

... Though to be honest, I didn't feel I could do it justice without some additional background pre-2012.

Pre(r)amble    Game Maker days

http://www.64digits.com/users/ludamad/CirboticsGIF4.gif

A game from my Game Maker days


I started programming by making games in Game Maker, although I have sworn off the program years ago. Since then I found that programming was fascinating in itself, and perhaps more so without annoying user interaction to worry about. In that time I did a great deal of hobby C++ programming, and some Java.

I started to enjoy working on large projects, namely a python-like scripting language. While very interesting, this proved to be unremarkable to my friends. So I thought, developing games again would be nice.

Summer 2011    From zerglings to witches and wizardry

My roommate was interested in collaborating on a project, and so we set off to make an RTS that was centered around LAN play. Lanarts. Somehow this idea got dropped, and instead we opted to make an RPG. The name stuck.

The first thing I did was toy around with level-generation code. It was quite simple, just plop down some rooms and tunnel between them randomly (backtracking on failure), but it worked well -- the code in place still stems from this.

After that I sought out find tiles to graphically display this dungeon, and found the rltiles tile-set, and subsequently the rogue-like Dungeon Crawl which uses them in a heavily modified form. Much distraction ensued! Soon me and Pat were playing Dungeon Crawl more than coding. However at the end of all the dungeon-diving my vision was clear, to make a game that could closely resemble a co-op roguelike as possible. 

Fall Semester 2011
    The foundations of a game

I used SVN & CMake in a research project during a research position I had during summer 2011, so they were natural choices for me to use in my game. Pat was using linux exclusively, while I was on windows, and this was a very good thing to tackle from day 1. In retrospect I wish I had also handled networking issues from this point as well.

Work on the engine progressed. I had the foundation of a game engine going in C++. OpenGL drawing, game actors acting in an event loop, and a rather complicated actor-storing data-structure that, while tricky to write, I still use and has worked very well.

January 2012    Movin' to git

Why git ?

I was fed up with using TortoiseSVN, and Pat convinced me to get a google-code account and try out a better version control system.

Features at this point
Basic .BMP loading, OpenGL drawing, font loading with FreeType, a minimap, collision system, field-of-view, keyboard controls.

No gameplay ... yet!

February 2012    It's alive!

Initial Development

The game progressed with some additional sprites hard-coded into the game, which now could be any image format and not just .BMP. A single enemy was added, able to path-find to the player. It could be killed with a simple ranged attack. A fog-of-war outside of the field-of-view was implemented; the map no longer starts revealed.

March 2012    It's a game!

Adding Gameplay
The game progressed by leaps and bounds this month. Enemies could attack, and 4 different kinds of enemies were introduced (all still in the game!). The level generation was tuned further and levels were given distinct layouts. An inventory was added, basic items such as HP & MP potions, as well as basic stats such as experience points and levels, and damage. No death animations were present yet, and melee attacking was preformed by simply walking into enemies, much like typical rogue-likes.

April 2012    It's an online game!


Taking it 2-Player
The game became even more game-like, with weapons, scrolls, and an additional spell (in addition to blinking and fireball which were already in). Monsters were no longer melee-attacked by walking into them, instead requiring a key press. Enemies get stronger by a fixed formula the deeper you go. Online was implemented! It was fraught with problems - crashes and synchronization issues - but the game could be played with 2 people!

May 2012

Online was further stabilized, projectile items added, additional tilesets, a game-chat bar that features notifications. Many new enemies.

June 2012
    First blog post!

Overhaul of stat system to one used currently, many new enemies including a set of animals, and two bosses. Many UI improvements, addition of weapons such as bows, early prototype of fighter class. Added visual representation of resting-system. Enemies travel in groups nicely thanks to the RVO2 library.

July 2012



Fighter class fully added, with separate sprite, and berserk spell. New tabs added to the interface. Stats displayed more nicely. Arbitrary numbers of players were added. Moved to github, where the code currently resides. Mostly fail at attempts to get additional developer interest.



August 2012    ... More than 2 players!

Shops were added. New archer class hastily added, was quite underpowered. Continue to look for help on the game, without much luck.

September 2012   ... ARRP, last official release (until today!)



The game was released for the ARRP. See this playthrough! The equipment system was redone with many new equipment slots. The main-screen was redone to allow for setting IP and connection port cleanly without fiddling with resource files. Work started on a new game, Carny Death Peddlers, with and old partner-in-crime, REZ, from my Game Maker days. The ability to work with a brilliant pixel artist was too enticing -- even if the project was forced to use Game Maker...
 
October 2012
    ... And Carny Death Peddlers is finished!

Frantic game development, in time for Halloween!
The game was successfully finished within a month-and-a-half for a Halloween-themed game development contest. I think it's obvious that this is a very small timeframe to complete a game. The dedication that my artist partner REZ showed for completing the project kept me on-task. There was definitely many stressful periods but I've never worked on a game with someone with such unified vision, it was awesome! The game has since been featured on several gaming websites such as GameJolt, and has ~1000 downloads on 64Digits.com. The game features great original music by Glock&Mr8bit

 November & December 2012    ... A needed break, and then back at it

Engine improvements
After the release of the last game I was a bit burned out. However, creating a full game in such short amount of time was inspiring to reapply my efforts towards polishing Lanarts. Glock&Mr8bit and REZ both agreed to help with the game. Unfortunately, REZ soon became busy with his own projects. Glock&Mr8bit worked away at producing music, and I worked on improving the engine in various ways, such as being able to play sound effects and music, and a better Lua framework. Still looking for additional developers.

Download: here!

This release features:
  • Lots of balancing work
  • Lots of new items, with new items added for practically every equipment slot.
  • Two new enemies, a centaur who keeps his distance, and a hydra whose head count represents its remaining HP (a future change will make these more like the 'cut off one head two grow back' hydras of legend).
  • A new fighter ability - 'Power Strike', an attack that hits multiple enemies in an area with your weapon, and also knocks them back with a temporary stun. Gained at level 3.
  • Interface improvements, better auto-equip logic when switching equipping projectiles & projectile-using weapons. Spells that are typically used once and then switched to melee no longer default to melee when their key is held. You are now able to use spells without first switching to them (previously two keystrokes were needed to use a not-selected spell).

Tuesday, 30 October 2012

Carny Death Peddlers is Released!


A classic beat-em up.

Download Page: here
Download Now


I mentioned I was on a break from lanarts. I was not slacking! I don't think I could keep myself from coding if I tried.


Features:
  • Amazing animated pixel art by Clay Bullard
  • Catchy tunes by Glock & Mr8bit
  • Fun, classic beat'em'up gameplay with a fair bit of polish
The game is 2 stages long, with 2 bosses. Lots of hard work was put into getting this game done in a small timeframe (~1 month and 2 weeks), I hope you enjoy!

Note: This is a Windows-only game, unforunately. However this game seems to work smoothly, albeit without sound effects, under WINE.

From the README:
Welcome to Carny Death Peddlers, a classic-style beatemup with a simple plot.

Made by:
    ludamad aka Adam Domurad - programming, sound effects
    REZ aka Clay Bullard - art, content design
    Glock and mr8bit - music, testing

Saving:
    Saving is automatic at the start of every battle.
    You know when a battle starts because "FIGHT!" text will appear.
    Progress before the next battle starts will not be saved.

Controls:
    s - charge punch when held, normal punch
    d - push
    z - backslide
    x - block
    space - use reserve item

    m - mute
    p - pause
       The following controls were not documented in-game (Unfortunately it cannot be modified, they will probably be added in an update):
    enter - skip text
    F4 - toggle fullscreen

Screenshots:

Saturday, 15 September 2012

Lanarts ARRP Release!



Screen shot showing off redone configuration screen
Download: here

Another release in a short time - this one focused on the setup menu mainly.
This release aligns with the ARRP: 
http://roguebasin.roguelikedevelopment.org/index.php/2012_ARRP
Here are the changes since a few days ago, see also the last post for recent changes:
  • Made the last boss harder
  • Made less difficult enemies spawn in later levels
  • Simplified startup screen into a single 'start' button, press enter to continue. Escape no longer continues.
  • Speed setting added to start menu, I recommend default setting. 

Tuesday, 11 September 2012

Lanarts Update September 11th, 2012





Screen shot showing off redone equipment system
Download: here
Recent changes:
  • Lots of new types of equipment! In addition to the previous single armour slot there are now two ring slots, a glove slot, a boots slot and a helmets slot. Items spawn and can be found in shops for each equipment type.
  • Redone equipment system where equipment shows in inventory.
  • Greatly improved the code for top-bar descriptions of items and things, now guaranteed to be formatted nicely as small as 640x480 (This is the smallest I expect the game to be run, use settings.yaml to change resolution if need be, it defaults to quite large).
  • Equipment tab now shows all new equipment slots and can be used to see which slots must still be filled.
  • Some new weapons, thanks to gigimoi.
  • A few slime enemies and a spider added, thanks to gigimoi.
  • Enemies no longer stack in tight (1-tile) corridors! This has been long overdue (it was hard to think of a good way to do it for technical reasons) and makes tight corridors a lot safer. (For the curious, previously enemy's more or less ignored collisions with each other when they were in corridors).
  • Last boss made beatable again... :)

Friday, 31 August 2012

Lanarts Update August 31st, 2012




New archer class and tiles (credit to white_noise from DCSS forums)
Download: here
Recent changes:
  •     Option to force sync in out of sync games - press F5 and you will essentially send a save file to everyone
  •     F5 to save game/F6 to load game for single-player games
  •     Improved robustness when playing >2 players
  •     Bunch of bug fixes
  •     New archer class - heavily work in progress. Has bow-oriented abilities, such as being able to hit multiple enemies with a single arrow, faster shooting with level-ups, and a spell that only works with a bow.
  •     More tiles, variations for player class tiles
  •     Balance changes as always

Monday, 20 August 2012

Lanarts Update August 20th, 2012


New tiles and statue features
Windows binary snapshot: here [Updated 21/08: Fixed a bug that caused crashes when doors were seen]
Recent changes:
  • Rewritten net code, uses SDL_net instead of asio. Dependency on boost removed. 
  • Support for >2 players
  • Much faster online play, increase frame_action_repeat in res/settings.yaml as desired and you should get arbitrarily faster play for a trade-off of responsiveness of controls.
  • Experience always shared in online
  • One synching issue found and fixed, more still exist sadly. Next release will include a button to force a synch as a practical measure.
  • Some tile updates, stairs & wall tiles picked from Dungeon Crawl
  • Balance changes as always