Una Selva Oscura

Tuesday, February 1, 2011
Running hasn't been the most wonderful thing in the world for me the past month - after recovering from being sick for a week starting around Dec 24th (then going to Quebec City with Sarah and enjoying the living fuck out of it...) I got nailed again two weeks ago with the flu. I was finishing up a pretty decent workout on January 14th and the last two reps or so I noticed that my muscles were aching pretty hardcore. Then I realized that they were ones that have nothing to do with running at all - lower back, neck, shoulders - the places that typically indicate that my immune system is losing both the battle and the war. I crawled into bed and emerged 7 days later and 10 pounds lighter.

Just this past week I felt like I was actually myself again when running, but despite that I did not have stunning success at the Terrier Invite this past Saturday. Running 9:12 or so for 3k wasn't really what I'd hoped for, and I'd be less annoyed by it if it wasn't an indication that I probably will not be able to give the Elder Statesman Jeffpa a good race. The wheel will turn, though, and my legs will stop complaining and do what I want again - just maybe not by the time he'll be retired. If I cannot give him a good race, I will at the very least buy him a good beer.

I'll have some real running numbers again beginning this week - I'm kind of pretending January didn't happen, or at least trying to hit the reset button. It wasn't godawful (150ish miles - which was standard for me in college) but it's certainly not what I want to be doing.

As running hopefully begins to fall into place again, other things fall out. That just seems to be the way the world works. On Thursday when I went to go blast my car out of the snow and head to work I noticed as I walked up that...oh hey...the bumper is kinda hanging off. Hmm. That wasn't like that before. Wonder if they left a note? Nope.

I'm a little conflicted about how angry that makes me. I have no interest in being a person whose entire self-worth and happiness is caught up in their possessions - but damnit I really love that car. There's not a day when I don't feel like driving it, and the experience of being on point, focused, and ...tuned in, let's say, to the feeling of the car, it's just not comparable to anything I know. It's similar to a track race...less noise in your head, and the howling of all your nerves, of course. More cerebral skill than brute willpower. Squealing tires and screaming engines versus on-fire muscles and pounding blood.

I've been dinking around with No Way But Down a little bit since I last updated it and I'm running into a few stylistic / programming problems. One of the primary quandaries I'm running into is how to deal with the control flow.

In the old days (for me, at least) of BASIC control flow is a really simple concept. Reading what would happen next in a program was a matter of going down the page according to line numbers:


10 INPUT "What is your name: ", U$
20 PRINT "Hello "; U$
30 INPUT "How many stars do you want: ", N
40 S$ = ""
50 FOR I = 1 TO N
60 S$ = S$ + "*"
70 NEXT I
80 PRINT S$
90 INPUT "Do you want more stars? ", A$
100 IF LEN(A$) = 0 THEN GOTO 90
110 A$ = LEFT$(A$, 1)
120 IF A$ = "Y" OR A$ = "y" THEN GOTO 30
130 PRINT "Goodbye "; U$
140 END

This is straight from Wikipedia's page on BASIC. Some of the keywords may not make a ton of sense, but the basic gist is: read from top to bottom, and wherever there's a GOTO ## the program is jumping to that line number. 


In object-oriented languages, you can still program this way. The only problem is that things get...messy when your programs get complicated. Writing a roguelike game is a pretty straightforward enterprise (at least in terms of algorithms and whatnot - I don't have to reticulate any splines) but it's not brief by any measure. 

In the pseudo-est of pseudocode, here's the control flow for No Way But Down:



* Wait for keyboard / virtual keyboard input
* Determine what state the game is in
* Process input according to game state (d key does different things if you're viewing your inventory as opposed to looking at the dungeon map...)
* Update the world
* Re-draw the world



The problem that has arisen is that there are probably 20 or 30 different 'game states' that all should process keyboard input and draw to the screen differently. I had figured something like this might happen, but hadn't designed for it, so I ended up with code like this...






else if(GameState.Inventory == GameState.InventoryMode.CARRIED) 
{
 if(unicodeChar == 10) 
 { 
    GameState.Inventory = GameState.InventoryMode.OFF; 
    GameState.InventoryOffset = 0; 
    updateWorld = false; 
 }
}




Consider briefly that the enum GameState has about 10 values right now, and that there are an awful lot of Unicode characters, and you can see my problem. Keeping a long list of else if's just ain't gonna work, especially when the string you're constructing to display is modified based on what GameState you're in.






What I'd like to do (and am currently attempting to implement in fits and starts) is mimicking the stack-based approach of Activities in the Android OS. I'm creating a static singleton class, DisplayStack, which I can push and pop objects called GameScreens onto and off of. Each GameScreen will have input handling logic - and return the display string for its particular screen. The DisplayStack will merely pass the character codes for input to the topmost GameScreen. Some characters may cause the topmost GameScreen to change (closing the inventory, for example, or opening it) by either pushing a new GameScreen or popping the current one. 



It might take a few days, and the code changes will be completely unnoticeable to anyone playing the game, but it does mean I'll be able to add new ideas quicker. Right now the notion of adding a dialogue screen is just really painful to contemplate given all the potential switches for each character I'd have to do. 





I just realized I could probably forego my own implementation and just make each GameScreen into an Activity...but honestly that feels a little heavyweight to me. It does mean I could use a different XML layout for each GameScreen...hmmm! I probably won't go this route but its nice that just writing about it gives me some ideas. Plus this is the first time I'll actually be writing a stack...ever. Might as well, ya know?






I've been listening to WGBH on the way home from work (and sometimes to it) recently and paying some attention to the Tunisian revolts giving way slowly to the Egyptian protests. I'm sure that Iraq and Afghanistan are not exactly the models of democracy that Tunisia and Egypt are looking towards and longing for, but I am curious if their presence in the region has had any effect. It would be weird to have the idea of infectious democracy espoused by the Bush administration to actually have some merit. The utilitarian in me actually questions whether the Iraq and Afghanistan wars were actually more worthwhile if that's so. It's very clear that the Egyptian and Tunisian people have been suffering - you don't get thousands and thousands of angry people in the streets by treating them well. 

I doubt it's anything quite that direct, if at all, and there's no guarantee that Egypt and Tunisia will emerge from the tumult any better for the chaos, but...something very good could happen in time. If working with people from China, India, Georgia (country! not state, though they're pretty far out too...), Haiti, etc - has taught me anything, its that the world's population is one big mongrel of fairly similar ideas and rockin' fellows. Or maybe just the engineers from those countries. Except the engineers who like Objective C and Perl...and whoever the dude was who hit my car. He's excluded from my world-party.


Just so we're clear, so are the Blogger formatting tools. Argh! Annoying to no end. That's why the second half of this post looks gimpy, but I am too lazy to fruit with it any longer. I bet the guy who designed it is named Duane.

0 comments:

Post a Comment