Category Archives: Angst

“If you’re not burning with rage, you’re not learning computer skills”

Code Duplication

I’m running into duplication problems that seem to be inherent to Flash itself. Here’s the deal:

We have 5 player characters which have been designed in Flash Professional. As of now they are just colored blocks (“why do they gotta be colored? That’s racist”). These characters obviously share certain properties, like for example HP, MP, that sort of thing; that’s not a problem for the most part: I can simply have each PC class extend a base class that has those properties and they’ll inherit them just fine.

That’s great for properties that you can define in code, but what about shared properties you want to design within Flash Professional itself? For example, as a temporary element each PC has a text box which they can manipulate to say certain things: e.g. “Ouch,” when nailed by a ninja star. This is the kind of thing that we don’t want to duplicate so we would keep that text box in the parent class; but there’s no way that I know of right now to extend a parent class and work with it inside FP. You want to be able to extend Library objects, basically.

Thinking off the top of my head, maybe you could achieve something like this by combining different Library objects which each have their own code. If you properly nested things each “child” (really a compound of sorts) the code duplication would be small. However the whole concept is still rooted in duplication – you have five classes that must contain all the same elements; in fact the duplication just moves into FP, which is worse in a way.

Another way might be to have a single PlayerCharacter class which contains all the necessary design stuff, then skin each instance with a certain set of animations. This might make the most sense of all, if such a thing is possible or I knew what I was talking about here.

The solution that I’ve adopted now is to abstract out as much as possible and duplicate as little as possible. So in the case of the message boxes, the parent class has a method say(String) which gets called in all the appropriate cases; that method in turn calls another method say_internal(String) which is a stub in the parent class but which each child class can override. (Note that method names have been changed to protect the innocent – I’m not really sure what the proper naming here would be.) Thus to make the text appear in the box we’re only duplicating a few lines of code:

override function say_internal(str:String):void {
statusText.text = str;
}

That’s not great, but it does save us some implementation work. The real question I don’t really know yet is how big a problem this is: my example is contrived and temporary. What are the real, lasting situations in which this issue might arise?

Wat

It’s now become clear that I have reached the point in Flash Pro where I don’t know what the fuck is going on and I won’t be able to continue until I figure that out. I mean, to the basics, and no progress should be made until I get there.

I just spent an hour trying to figure out some bug I thought was of my own creation, only to realize that my entire fundamental understanding of what was going on is totally incorrect. Each Ninja gets placed in one of five lanes, one per player. In order that Ninjas in the same lane don’t overlap one another completely I introduced some randomization to their y position. Unfortunately some Ninjas were appearing outside of their given lanes; I spent some time debugging it, going over the randomization code and working through the math over and over.

It didn’t make any sense, until I checked things out in FP. Then it made even less sense. The sizes of all the characters are supposed to be 76px, but they’re all actually 80px tall scaled down by some percentage. Worse, each lane is supposed to be 86px high, but they’re being reported at runtime as anywhere from 170-190px. I can’t even find those numbers in FP to even start to make sense of them.

Trying to remove the transforms – scaling in this case – on the ninjas is totally ineffective. So… do you have to draw it the exact right size the first time, otherwise you’re screwed? I just want to change the size of a fucking square, you know? I don’t even know how to approach the lane height problem, since I can’t even see where the error is coming in.

Maybe I should be using scaleHeight or some other such thing at runtime? But really, this just points to my fundamental non-understanding of what’s happening in FP. So any further hacking around in FP or code is only going to fuck things up more. It’s time to sit down and do some hard core reading.

Stuffs

Various Notes

MovieClips don’t get any ENTER_FRAME events until they are added to the stage (via an addChild() or something to that effect). Makes sense.

Layer Carnage

Something that really drives me nuts about Flash is the inability to interact with layers in ActionScript. And before anybody gets pedantic and says that’s mistaken thinking, unask the question, l2flash, git gud or anything like that, yes, I understand (I think) the design choices that make this the ‘wrong’ way of thinking, but I still think it’s stupid.

My understanding is that layers are purely design-side elements, and that once your flash gets exported they’re gone and it doesn’t make sense to try to interact with them at runtime. Okay, I can see that design decision, and fine, you want to be consistent, okay great you win the consistency prize. But as a programmer/builder of interactive things, I want the ability to put objects on different layers at design time and runtime, and that’s just not possible. It doesn’t make intuitive sense that layers go away at runtime. You can place, say, a square on the stage, give it a name and then move it around at design or runtime. Yet layers go away? Why can’t you just name them and they become Sprites or something?

One solution is to create a Sprite for each layer you want when your Engine initializes, then add all your objects to the appropriate Sprite. Which is a fine solution except that it completely sucks, since you have to duplicate your layer structure in code, so hooray we get to build everything twice, what could possibly go wrong, oh and also that will all be on top of the stuff you built in Flash Pro itself, so have fun manually reordering things, or you build it once in code and can no longer design anything in Flash any more. Either way it sucks.

The better way is to add an invisible/size 0,0 display object of some kind at the origin of the appropriate layer, then add stuff in code to those display objects. Of course event the most cursory examination of this method reveals it’s a total hack, but all the same it’s a much better solution: it gives the illusion that layers still exist – each created display object exists at the proper z position already and so it’s like the Sprite solution except sensible.

This is how I solved the problem in the first flash test game that I made; unfortunately that code is miles away and I don’t have access to it, so I’m fumbling trying to recreate it. Do you just place like a square at 0,0? But if you make the size 0,0 or make it transparent Flash just destroys it (…why? Can we not have invisible or infinitely small things?). Kind of dreading the internet search that is to follow.

Okay, 30 or so minutes later the solution: create a new MovieClip in the library and put an instance at the origin of each layer. So I did:

  • Insert –> Symbol…
  • Call it Layer
  • Drag it onto the stage on the proper layer; manually set x and y to 0
  • Name the instance – in this case I went with layer_projectiles

There’s a lot of debate on variable name prefixes. Many hatefully oppose it, but I’m going to justify it like this: AS isn’t exactly strongly typed, so it’s not like I’m saying

int __int_myInt; // an integer

or some shit like that. Prefixing with layer_ will let me organize mentally better than just projectiles, enemies, etc.

WordPress Categories vs. Tags

As I’m going to categorize/tag this post I’m looking at my options and thinking two things:

  1. I don’t really know what the difference between tags and categories is
  2. So far my choices for categories are ActionScript, Angst, BS, Development, and FMB. Well, all of those categories apply to this post, and every post I’ve yet made. In fact it’s pretty safe to say every post about FMB Development will indeed involve much Angst about ActionScript BS.

So: TODO figure out difference between cats and tags and use them appropriately. Also write about happier things.

Keyboards

For typists, and programmers especially, the right hand pinky finger is ridiculously overused. Unless you rolled a natural 18 DEX it’s absurd to have to type things like:

p0["'>:-0'"] += ‘{p}’;

Especially considering the number of backspaces one will probably need to employ along the way. So I always move my hand when sequences like this are required – which is just about every line of code. But that’s horrible, because then your hand shifts out of home position and chances are you’re going to come back wrong, slowing you even more and making more mistakes.

Furthermore, look at your keyboard: chances are the keys are staggered so that each row is shifted to the left of the row directly below it. This makes sense for the right hand, because it naturally comes in at an angle from the side of your body to the keyboard; to hit the proper key with the proper key you extend the finger forward relative to your hand. But for the left hand it’s disastrous. Your choice is either a really unnatural finger movement, or a horrible wrist position to accommodate a natural finger motion.

I’ve seen keyboards that don’t stagger their rows, but this alone is not sufficient to solve the problem – you need to then tilt the keys to face the hands properly. On a laptop this becomes absurd. Why not stagger the two sides of the keyboard oppositely, then move some of the pinky punctuation keys to the space in the center that opens up? Why has nobody done this yet?

Trigonometry

I’ve done this so many times and each time I have to mega-think my way through it all over again. And I always do it wrong the first time, then the lights dim in the room as I power ponder the solution out. Given that I’m going to forget it the next time I need it, I’ll leave some notes here.

So a ninja throws a star at a dude. That star follows a trajectory that describes the hypotenuse of a triangle with a and b sides equal to the difference in x and y positions start to finish. The star has a velocity which we’ll express as the number of pixels it can move in one second, which will be some percentage of the length of the aforementioned hypotenuse. We’re interested in knowing how far the star will travel in the x direction and the y direction each second.

We need what I’m calling a unit vector, and it can be expressed in a couple ways. We could do it with just an angle and a velocity, which is really easy and vector intuitive. But we need to apply the change in x and y 60 times a second, so we don’t want to make the calculations to translate that vector into its components over and over again. So the better way is reduce it to it’s components once then work with that. (Note that if the momentum changes over time, due to say friction or whatever it would be useful to keep the angle and magnitude around because we will need to make those calculations every time.)

The easiest way to express the unit vector then is as a single point [x,y] which represents the distance from the origin the star can travel in a second. So if our momentum is [3,4] the star will travel (using graphics orientation) 3 pixels to the right and 4 down each second. (Incidentally the total velocity in this case, as we all know, is 5 pixels/second and the angle is… something, whatever, who cares.) Here’s the bit of code that works this out:

var adjacent = target.x – tosser.x;
var opposite = target.y – tosser.y;

// TOA: tan(theta) = opp / adj ==> angle = tan-1(opp/adj), so:
var angle = Math.atan2(opposite, adjacent); //angle will be in radians, as required

momentum = new Point();
// CAH: cos(theta) = adj / hyp ==> adj = hyp * cos(theta)
momentum.x = Math.cos(angle) * velocity;

// SOH: sin(theta) = opp / hyp ==> opp = hyp * sin(theta)
momentum.y = Math.sin(angle) * velocity;

Goddamn it’s late.

Fucking WP

Jesus god is WP ever monumentally failing me right now as I’m trying to put code tags around my code.

The Endginning of the Begend

So I figured it would be nice to document the process a bit. For one, because as a developer I’m always solving obscure problems, then forgetting the solution, then encountering the very same problem later and racking my brain trying to remember what the solution was. For two, to act as a work log on the project. For three, for maximum transparency. For four, for fun and profit.

It should probably be pretty private; I intend to post some intimate things about the problem solving process, which experienced programmers may look upon and scoff at my abilities, which will hurt my feelings. Also because I dislike having eyes on the embryonic stages of a creative process; or any stage of that process, come to think of it.

I debated for a bit whether to use the existing CMS on my site, or install WordPress, and went with the existing solution because, really, laziness. Then I reversed that decision and just manned up and installed WP. Not sure anybody in history has had to actually get manlier to install WP, but there you go.

Some shit I had to deal with yesterday:

Actionscript inheritence

I have different classes for each player character, all subclassing the “abstract” PlayerCharacter class. Quotes because AS doesn’t really have abstract classes. So just like promise not to instantiate one, ok? Problem: no var inheritence. So you can’t define

public function get playerName():String {
    return this.__name;
}

in PlayerCharacter then just override the __name var in the file, because you can’t override vars. So that raises the question: do you just set __name in the constructor, or override playerName() to return the right name?

The problem with the constructor method is that it’s like invisible. There are some things you can override but you have to dig around the superclass to find them, or the (eventual) documentation. But because there’s no real abstract classes, you can’t just leave playerName() unimplemented and get a compile-time error letting you know to implement it. You could throw a runtime error or something but that’s… unseemly.

I went with the constructor, because: 1. it kind of reminds me of django, where you do something similar if you subclass a Model; 2. code reuse – you don’t have to write getters like 100 times or whatever; 3. you can do this with functions also; and

4. thinking ahead, I’d like to be able to read character settings and instantiate from file. This is so a collaborator could say, e.g., I don’t think FMB is firing fast enough, and then change the setting in a text file (or use a tool for same) without having to touch code or recompile. That’d ease the balancing process.

WordPress

Is it better to install an old version of WP (3.1) automatically from Fantastico, or manually install a later version (3.6)? I’m thinking manual, since then you’re not depending on yet another tool for your tools. Downsides: you gotta keep on top of updating. Maybe a big security flaw comes out, maybe you get hacked, maybe you end up responsible for zombie nuclear site attacks, or worse, spam.

This started yet another colossal rabbit hole tech one-thing-after-another hate fuck. Can’t download wordpress because my local website repository died in my HDD crash a few months ago. Need to git clone it from my server. What was that URL again? Can’t remember. Or do I restore it from backup? Should I restore it then git it? Did I do anything since the last backup? I should check my laptop, since I think I last developed from there. Do I even want to maintain the WP install with git? Does that even make sense?

Can one/should one deploy a simple website with git, instead of the typical FTP and pray method?

http://sebduggan.com/blog/deploy-your-website-changes-using-git/

http://toroid.org/ams/git-website-howto

http://www.bitbonsai.com/git-deploy-website-5steps/

Yes, one can. But that’s effort, and anyway it seems like a weak deploy solution, so should I look into capistrano? For a simple fucking website? Ugh. I just wanted a pepsi. Still so tired, I guess from the injury and healing or something, maybe residual percocets, even though I didn’t take any today in hopes of not being so tired. Foot hurts a little as a result, too. Sheeit.

So today:

F It

In the end I said fuck it, I’m not gonna try to git my site, I don’t even care about that right now. Just downloaded the latest wordpress, detarred it on the server – didn’t even unpack it down here, that’s how much IDGAF – ran the setup and here we are. I spent some time having a little fantasy about customizing the theme but that’s going in the trash for now. Who really cares what the random development journal looks like?

Just need to change up my subdomain configuration and add a user for Sean, assuming he wants in on this garbage.

Next

Since I’m already in a morass of non-development, I may as well get up a git repository or two. In the process I suppose I’ll see if I can recover my website and get that figured out. Same with all the other projects that died with the HDD – I can’t remember now where I backed them up, or when, or if I changed anything since the last backup that’ll be lost forever, lol.

For development, next is to get all characters on screen, then queue some enemies and get them moving.