Mario's Corona Coding

December 6th, 2011 Battlemaps for Corona with SVG LevelBuilder – Let’s get started

This entry is part 1 of 1 in the series RPG Maps
  • Battlemaps for Corona with SVG LevelBuilder – Let’s get started

Don’t reinvent the wheel! Use Karnak Games’ SVG Level Builder to make your levels!!

You’ll need to download/buy:

  • KarnakGames’ Corona SVG Level Builder: here
  • Borrow this map for testing purposes here from Wizards of the Coast here (Save it as ‘map1.jpg’ in a directory named ‘backgrounds’ your main directory where ‘main.lua’ lives. You can use ANY map you like, just follow the basic principles described below)
  • Inkscape,  here (OS X or Windows, perfect!)
  • The SVG Level Builder iOS templates here (Follow the directions on that page for installation)
We’re just going to assume you have Corona SDK since you’re here already.
Open Inkscape and go to File->New Document->Corona_SVG_Level_Builder_iPad
Press the “-” key a few times until everything zooms out so you can see the black outline of the iPad area:

Borders

 

Now press Ctrl+Shift+L to bring up the layers window:

We want to add another layer and name it ‘background’, so click on the blue “+” and name the new layer accordingly:

Make sure that the background layer is highlighted, then go to File->Import and we’ll choose the map we downloaded named “map1.jpg”. When it come into Inkscape, it may be off-center. Adjust the X and Y coordinates highlighted below to 0 and 0:

 

Whew! OK, we’re done with setup. Click the little lock icon next to the layer named ‘background’. This will prevent us from clicking on it accidentally. Then click on the layer named ‘Game’:

NOW we get to do the fun stuff like placing objects that will be physics object in our game. Think of it like a giant piece tracing paper where you draw lines and shapes around the objects you DONT want players to be able to walk ‘through’ and it will bounce other objects off of it.

 

Well, I made a small quick screencast of me tracing some outlines and drawing some rectangles here:

 

We just save it out as test1.svg.

Now we can paste the following into our ‘main.lua’ file. Create it if you haven’t already:

local svg = require("svgparser")
local levelBodies = svg:new("test1", {drawMode = "hybrid"})
physics.setGravity( 0, 0 )
function AddBouncies()
	for i=1,10 do
		local tempX = 130 --math.random(0,display.contentWidth)
		local tempY = 110 --math.random(0,display.contentHeight)
		local tempRadius = 2
		local circleMaterial = { density = 15.0, bounce = 0.5, radius = tempRadius, friction = 5.0 }
		local tempCircle = display.newCircle(tempX,tempY,tempRadius)
		tempCircle:setFillColor(255,150,0)
		tempCircle.alpha = .5
		tempCircle.rotation = 0
		physics.addBody( tempCircle, circleMaterial )
		tempCircle.isFixedRotation = true
		local tempValue =3.5
		tempCircle:applyLinearImpulse(math.random(-tempValue,tempValue),math.random(-tempValue,tempValue))
	end
end
 
AddBouncies()

..and make sure that all the following files/directories are in your directory (Note: ‘backgrounds’ is a directory where our map1.jpg file resides, and of course the svgparser.lua and xmlparse.lua you got from KarnakGames)

 

So compile and run it and you should see:

Sorry if it’s a little small, you can always watch it fullscreen but what we’re really interested in is 2 things;

  1. That the level physics objects are being loaded from the Inkscape file we saved out
  2. My ‘AddBouncies’ function throws a bunch of balls around in the dungeon chamber and YES! They bounce around and off the walls we just created!
Heck, the ONLY piece of code you need to get the level loaded and working is:
local svg = require("svgparser")
local levelBodies = svg:new("test1", {drawMode = "hybrid"})
All the rest of the code is for my bouncing balls test!
Yep, it’s THAT easy! :)
So let’s recap:
  • I didn’t make the map, I swiped it from the WOTC site
  • KarnakGames made a great level editor (That I haven’t even scratched the surface on, you can see his site’s demo here)
  • You only need 2 lines of code to get the physics and graphics into your Corona SDK app
The next post should be something interesting.
Stay tuned!
Best,
Mario
  • http://karnakgames.com Alfred Reinold Baudisch

    Again, thanks for posting about the Corona SVG Level Builder! Will you sure you love the new version, since it will allow multiple layers to be filtered, making it easier to work with the parser and to filter your game elements.

    Plus, 30+ additional features. Finally coming out this week, as I tweeted: https://twitter.com/#!/karnakgames/status/143902432311783425

  • http://karnakgames.com Alfred R. Baudisch

    Hello Mario, how is the game going?

    • admin

      Hey Alfred!!

      It goes well, I’m merely waiting for my friend who’s actually handling the story and rules to deliver some finalized versions of the play. I’m bummed, my YouTube video of the game play is just showing up as a green block now….but back when I posted it it was pretty neat. I’ll try to get a new video up and going. I’m also trying my hand at PubNub in Corona. It was sort of tough these first few days getting a hang of it. But now I’m finally grasping the basics. :) How are things on LevelBuilder going? Still a great tool!!