Thursday, October 21, 2010

Refactoring

Where have I been!?

The main.lua file for my game has gotten a bit... bloated. 1500 lines isn't that big really, but its big enough and dense enough that I'm feeling the wear of searching through it for a particular line. It's time to re-write, and split some of it up into seperate files.

Time to work off some of that baby fat.


That's where I've been. Progress has been good, but I still have a ways to go before I'll have more "actual" updates on the game.  I did add a (very) simple enemy AI system before I started on this project, so when the refactoring is finished, we should have some baddies pretty quickly.

This winter: attacking a skeleton near you.

Friday, October 15, 2010

Solutions to Boring Problems

Done! Managed to work through some boring, boring debugging, and the character movement is working better than ever. Besides special moves, like wall jumping or edge climbing, my little guy has everything he needs for now to move efficiently though a level. Think I'm ready to proceed to adding some enemies.

Today I worked for a few hours on composing some music using Pixel's Org Maker 2. Made good progress, but I'm having a serious problem with an excess of happiness in my tunes. Think it comes from only using major chords. I need to figure out how to get some spooky in there.

This. I need more of this.
Spooky, son.

Thursday, October 14, 2010

Boring Problems + Sounds

I've hit a lull, and am trying to power through. I have some boring as dirt problems to solve, engine wise, before I can do much else. Making the art, sound and levels is fun and glamorous. This is not. Gonna beat it though.

Problems:
  • 1) Hesitation when running from a flat surface to a slope
    • FIXED - the program thought that the slope was a tiny, tiny wall until horizontal momentum was 0 - fixed this by checking that the wall size was > a pixel before killing horizontal momentum.
  • 2) Jumping while running up a slope: jumping straight up instead of up and forward, and only jumping half height
    • IN PROGRESS - think the character is hitting the slope, and getting slowed.
  • 3) Jumping while running down a slope / touching ground inconsistancy
    • Think the problem is that I only have one variable for touching the ground. Need seperate checks: one for wheter character should be allowed to jump, which is more forgiving, and one for whether the character is actually, physically, touching the ground, which should be tougher. Probably need to make the character somehow "stick" to the ground while running down slopes. Right now he runs faster than the slope, so he's constantly falling, and unable to jump. HMMMM... ):|
In less boring-as-hell news, I've started making sounds for the game. Well. "Making" might be a stretch. "Randomly generating using CXFR" would probably be more accurate. At any rate:

Jump by drinkdecaf

Slide by drinkdecaf

Next up: Music! If I can, I'll use Pixel's Org Maker. Not sure if I can turn that into a .wav though. We'll see, Margaret. We'll see.

Monday, October 11, 2010

Sprites

Sprite system is a go!

Careful there, sparky.
It's funny how much time I'm spending on the little parts of this game. A tile-system took almost no time to implement. Character movement was done in 30 minutes. But making sure the character wouldn't continuously jump by holding down the jump key took about 3 hours (there are a surprising number of ways this scenario can happen), and adding dirt clods that fly when you jump or slide that are visible for all of 5 frames (less than half a second) has taken me two days.

I'd be worried about this except 1) I'm having a blast, and 2) I really think the little details are what separate a mediocre game from a truly excellent one. Thats not saying much, I know, except that maybe people can tell when you loved what you were working on.

To do:
  • smoother climb hills 
    • - Still having a problem with character hesitating at transition between flat and sloped tiles.
  • background tile layer
    • - Think I may implement this as a whole new tile layer. Maybe?
  • char animation
    •  - So many more frames than I ever realized!
  • death
  • enemies
  • shooting
  • swimming
  • scripting movies / camera

Sunday, October 10, 2010

Weekend Update

Just a short update, I've been working on a sprite system over the weekend, and am getting close to having it working. One of the hardest things about writing an engine, I'm discovering, is anticipating what needs I might have in the future for making a game. For now I just need small animations, like water, or e plosions, but later I'm sure I'll need particles, bullets and more. Learning to think ahead is definitely one of the biggest challenges of a project like this.

The character movement function is getting pretty refined. I still have a few bugs to work out, but my little skelly guy is moving pretty well. I think I need to do some "research" tommorow on some of my favorite sidescrollers, to make sure I'm not forgetting anything. Did someone say walljump?

Friday, October 8, 2010

Tiled .tmx loader for Love Engine (Lua)

After several hours of work, my .tmx loader for my game is working! This will speed things up considerably!

I'm posting the source in case anyone wants it, but be warned that it makes some assumptions:

  • that tilewidth and tileheight are the same across the map, and all the tilesheets
  • that we've saved file under the csv method
  • this snippet only loads the variables from the file, and doesn't do anything with them - loading the info into tiles is another several hundred lines of code I'm not including here

Here it is: it's ugly, but its working.

function getTileArg(stringVal, argVal)
 --gets argument value from the string in the form argument="value"
 mySearchBegin, mySearchEnd = string.find(stringVal, ' ' .. argVal .. '="')
 if mySearchBegin then
    --find closing quote (")
    openQuote = mySearchEnd
    closeQuote, closeQuoteEnd = string.find(stringVal, '"', openQuote + 1)
    return string.sub(stringVal, openQuote + 1, closeQuote - 1)
 else
  return -1
 end
end

function explodeNumeric(div,str)
  if (div=='') then return false end
  local pos,arr = 0,{}
  -- for each divider found
  for st,sp in function() return string.find(str,div,pos,true) end do
    table.insert(arr,tonumber(string.sub(str,pos,st-1))) -- Attach chars left of current divider
    pos = sp + 1 -- Jump past current divider
  end
  table.insert(arr,string.sub(str,pos)) -- Attach chars right of last divider
  return arr
end

function setupLevel(levelfile)

 lines = {}
 for line in love.filesystem.lines(levelfile .. ".tmx") do
  table.insert(lines, line)
 end

  --find <map> line, get arguments
  mapWidth = -1
  mapHeight = -1
  tileSize = -1
  collideMapFirstLine = -1
  collideMapWidth = -1
  collideMapHeight = -1
  spritesMapFirstLine = -1
  spritesMapWidth = -1
  spritesMapHeight = -1
  collideFirstTile = -1
  collideFile = -1
  spritesFirstTile = -1 
  spriteFile = -1
  for i,v in ipairs(lines) do
    --main map line
   if string.find(v, "<map ") then
    --get mapWidth, mapHeight, tileSize
  mapWidth = tonumber(getTileArg(v, "width"))
  mapHeight = tonumber(getTileArg(v, "height"))
  tileWidth = tonumber(getTileArg(v, "tilewidth"))
  tileHeight = tonumber(getTileArg(v, "tileheight"))
  if tileWidth == tileHeight then tileSize = tileWidth end
   end
   
   --tilesets
   if string.find(v, "<tileset ") then
    --get which map this is
    whichMap = getTileArg(v, "name")
    if whichMap == "collide" then
     collideFirstTile = tonumber(getTileArg(v, "firstgid"))
     collideTileWidth = tonumber(getTileArg(v, "tilewidth"))
     collideTileHeight = tonumber(getTileArg(v, "tileheight"))
     collideFile = getTileArg(lines[i + 1], "source")
    elseif whichMap == "sprites" then
     spritesFirstTile = tonumber(getTileArg(v, "firstgid"))
     spritesTileWidth = tonumber(getTileArg(v, "tilewidth"))
     spritesTileHeight = tonumber(getTileArg(v, "tileheight"))
     spriteFile = getTileArg(lines[i + 1], "source")
    end
   end
   
   --layers
   if string.find(v, "<layer ") then
    --get which layer this is
    whichLayer = getTileArg(v, "name")
    if whichLayer == "Collision" then
     collideMapWidth = tonumber(getTileArg(v, "width"))
     collideMapHeight = tonumber(getTileArg(v, "height"))
     collideMapFirstLine = i + 2
    elseif whichLayer == "Sprites" then
     spritesMapWidth = tonumber(getTileArg(v, "width"))
     spritesMapHeight = tonumber(getTileArg(v, "height"))
     spritesMapFirstLine = i + 2
    end
   end
   
  end
  
  if mapWidth == -1 or mapHeight == -1 or tileSize == -1 then
   error("Error Loading .tmx File (1)")
  end
  
  if collideFirstTile == -1 or collideFile == -1 or collideTileHeight ~= collideTileWidth or collideTileHeight ~= tileSize then
   error("Error Loading .tmx File (1)")
  end  

  if spritesFirstTile == -1 or spriteFile == -1 or spritesTileHeight ~= spritesTileWidth or spritesTileHeight ~= tileSize then
   error("Error Loading .tmx File (1)")
  end  
  
  if collideMapWidth == -1 or spritesMapWidth == -1 or collideMapWidth ~= spritesMapWidth or collideMapHeight == -1 or spritesMapHeight == -1 or collideMapHeight ~= spritesMapHeight or collideMapFirstLine == -1 or spritesMapFirstLine == -1 or collideMapWidth ~= mapWidth or collideMapHeight ~= mapHeight
   then
   error("Error Loading .tmx File (1)")
  end 
end

Next up is some glitch fixes - my character won't jump while running downhill - I need to tweak the touchingGround check somehow. Yay for bug fixes!

Thanks to the tilemap loader, I can now create nice looking levels
... er... nicer looking levels than before, at any rate.

Thursday, October 7, 2010

Hello World

Here we go.

My name is Rick, and I go by drinkdecaf. I'm 29, and realizing that if I want to do the things I've always wanted to do, I'd better start actually doing them.

I've always wanted to make games. So I'm doing that.

My first project is a 2-D tile-based platformer engine / game. I'm writing it using the love engine, which is cheating, I'm pretty sure. Programming in Lua wont grow hair on your chest, but it will get you started, which is what I'm after right now -- gotta crawl before I can run.

I've made some good progress so far on the engine - it loads a collision sheet and a sprite sheet, has collision detection I wrote that actually works pretty well, and has pretty good physics for the player character. It's nowhere near being a "game" yet, but its been fun working on it a little each day and getting closer to something that might be fun to play.


Right now, I'm using Tiled to create the level / colision maps, so my next step, boring though it may be, is to write a parser that reads the .tmx Tiled files into my game automatically - I've checked, but no one seems to have written one of these for Lua, so its up to me, it seems.

Other to-do items:
  • character start point loads from collision map
  • camera start point loads from collision map
  • character run animation
  • death
  • enemies
  • shooting
  • swimming