How far can you make it? Battle through randomly generated lands and 1000 randomly generated dungeons. Slay monsters, gather resources, and craft new an powerful weapons. All to see just how far you can go. Die in dungeon 999? Start over from one. This is a war of perseverance.

Report article RSS Feed Shadow and Light Part 1

In the first installment of a two part update we talk about adding dynamic shadows and lighting to 1000 Dungeons.

Posted by trihex on May 8th, 2013

So for the past week or so, most of my development time was spent on getting some lighting and shadowing into the game. I had implemented the same basic functionality in Java using Slick2D, and in a previous version of Torque2D, so I didn't think it was going to be all that tough. Yea, you know what happened.

Since I was in Torque2D, I decided to start with my previous shadowing code that I used in the older version. It took maybe an hour or so to get the code to the point where it would compile. If only that meant it would work too. After running the initial compiling version, I was treated with absolutely nothing. No shadows, no nothing. Just the dungeon as usual. Time to take a look at what's going on.

The old code grabbed objects based on the group they were in. Torque2D allows you to assign objects to specific groups and layers, and then you can control various things (like collision or rendering order) on the group and/or layer. It's a very handy feature. The latest version still has this information, but getting it out of the scene is bit more tricky. And that is were the first issue was, the scene is not where my information was.

When I was initially doing the pick area to grab the objects, I was doing so on the scene and only ever getting 3 things back. No matter what I tried, all I ever got back was 3 items. Why you may ask? Well, because the scene only contained 3 items. It contained a composite sprite, a sprite, and the shadow object. The items I want are on the composite sprite, not in the scene individually. So first update was to change the code to take a composite sprite object and update the selection code to select sprites in group 6 (the group I designated for blocking line of sight). Stepping through the code once more, I now see that I'm getting back 4000+ objects. On the right track! Let's see what what we got, lovely shadows? No.


What we got was a jumbled mess of black things, that somewhat resembled shadows, but were not aligned to the walls of the dungeon. As an added issue, when the player moved, the shape of the shadows did not. Older versions of Torque2D had a mounting feature where you could "attach" one sprite to another with specific offsets, and the two would move as one. The new version no longer has this feature, replacing it instead with Box2D joints. The joints provide a much more powerful way of linking objects together, but it also more complex; especially if you are not familiar with Box2d and its joints, which I'm not. So after playing around for a bit trying to use a joint to get the shadow objects position to move with the players, I just implemented a very basic event system in script that allows objects to subscribe to specific events (like player movement) and have an update method called automatically. So now the shadows are moving with the player, but they have this odd habit of just disappearing as you reach the edges of the map.


In part two, we will finally track down the final piece to the shadow puzzle and tie it into some actual game play. As always, you can track the development of the game at our website, and follow us on Twitter.

Post a Comment
click to sign in

You are not logged in, your comment will be anonymous unless you join the community today (totally free - or sign in with your social account on the right) which we encourage all contributors to do.

2000 characters limit; HTML formatting and smileys are not supported - text only

Icon
1000 Dungeons
Platforms
Windows, Mac, Linux
Engine
Torque 2D
Contact
Send Message
Official Page
Bloodytongue.com
Release Date
TBD
Game Watch
Track this game
News
Browse
News
Report Abuse
Report article
Related Games
1000 Dungeons
1000 Dungeons Single Player Roguelike
Related Engines
Torque 2D
Torque 2D Commercial Released Dec 31, 2004
Related Groups
Bloody Tongue Games
Bloody Tongue Games Developer with 2 members