Wednesday, August 6, 2008

Rolling Your Own

When programming you either have the choice of using someone else’s code or writing your own. In this example, I will be talking about a graphic library that would help me write the user interface. I can either use someone else’s or try to write my own.

The downside of using someone else’s code is that you have to practically memorize the documentation in order to get anything done. You also have to understand the logic of how to use the code. Just reading the documentation alone rarely answers all of your questions, just like the encyclopedia doesn’t explain grammar or how to write a book.

Writing your own code library is often called “rolling your own.” The user interface for MTG Forge is going to be very simple. User’s can move cards. Life points and the mana pool will be shown for both players. These requirements are very, very simple compared with most videogames. The benefits of “rolling your own” is that you don’t have to read any confusing documentation and that you often get things working up and running more quickly.

After trying a simple graphics library, I gave up and decided to roll my own. All I have to do is read a card image, reduce its size, draw a white rectangle, and draw the card name. The attack and defense as well as the damage and assigned combat damage will also be shown on each card. (Sometimes you want to know how much damage is assigned to your creature during combat.) No animation has to be done and everything else is pretty straightforward.

This card picture is taken from MTG Forge’s version 2 user interface. The red number represents the damage and the blue number represents the assigned combat damage.


Rob Cashwalker said...

Slightly off-topic:

The picture reminds me of one of the things I hate about Magic Online. The way all the images are drawn and then text is drawn on top of them, usually with disastrous looking results. Since when do magic cards use Arial-Narrow? (Since they need to be able to squeeze lots of text onto small digital objects that have no presence in reality and could be vaporized at will by greedy executives....)

When I played around with some VB code to handle drawing card pictures, I couldn't find anything good in pure code. I ended up finding a DLL that I could pass the picture handle to, and it would process the image for size and rotation, which was neat because the "tapped" property would be easy enough to implement graphically without significant extra logic.

As I experimented with the resized cards, I found that using the card images from gave good enough results when resized to 66%, where you could still read most of the cards critical info. Whatever you couldn't read, should pop up in full size on the side. You don't need to overlay the entire text box with the name and printed P/T. Just a small box along the bottom for the assigned damage, P/T boosts/reductions, counters, etc.

One thing's for sure the interface needs to allow us to arrange the cards nearly any way we want, not just single-file rows based on time stamp order, with scroll bars all over the place.

Gando the Wandering Fool said...

I will withhold judgement on whether that is sufficient until I see a screenie of how it looks in game...but the concept seems fairly simple and workable so I am think while it might not be attractive compared to other programs it might just serve quite well...Though I'd rather see damage and assigned damage be listed in a constant status window as well as on the cards. As Rob says the cards will need to be dragable and arrangable to be part of a good interface. I like the idea of rezisable cards particularly if it is done at the user's descretion.

Anonymous said...

i cant run program u say to type stuff for java. i have ezjava but i dont know what to do with it help i cant run it. readme says double clik jar but my file just want to unpack. sorry english, i dont program i just want 2 play

nantuko said...

try to write using command line:
"java -jar run-forge.jar"
(from the dir where run-forge.jar is)

nantuko said...

I've modified MTG Forge a little so now it uses images (only if downloaded) for permanents

U can see the screenshot here

If you want, I can send you the changes to merge them into current code

The other idea was to make packages for all code (I'm using eclipse that has refactor features so it is rather simple task ), but I postponed this activity for a while

p.s. you haven't answered my e-mails

p.s.s. your program is great!!!;)))just to mention)

nantuko said...

as previous image url wasn't displayed correctly

click for screen shot

Mr.Chaos, unofficial beta tester. said...

Nantuko, I really like the way that looks.
Well done!
I would really like to playtest that version you made.

DCelso said...

I think the same, it is great.

Rob Cashwalker said...

nantuko - THAT'S. FRIGGIN. AWESOME!!!!!!!

Forge said...

Hi nantuko,

Sorry RL (real life) has gotten in the way. I try to check my e-mail about once a week. Your screenshot looks great. Designing a good user interface takes time and feedback from the users. I don't really know what a great Magic program looks like. (Well I do, it is Incantus, but I'm not sure how to get my stuff to look that good.)