Archive

Archive for February, 2012

No Work Done in a While

February 29, 2012 1 comment

So…. not much work has been done on my game lately. I’ve been really busy with house repairs being done last week into this weekend and my car needing to be fixed late this weekend up until today. On a positive note, I’ve been so exhausted when I get home that I’ve been getting 9-10 hours of sleep every day this week. So this weekend I should be good to go.

Also, it seems that computer issues are catching in my house. A week after I recovered my game code with the decompiler, my desktop died. I’m planning on using the desktop to create my game art, so this is yet another set back. I’m going to need to reinstall Windows XP on it, so I’ll do that once I get my installation disk back from my friend. Fortunately, I installed Windows XP on a separate partition from all my data in case of such an issue. So I’ll also start working on my game art this weekend.

I’m not going to wait this long for my next update. I promise something will be done for my game this weekend and if I can figure out my video capture software, I’ll post a video on Sunday.

Decompilers Good, Hibernating Bad

February 11, 2012 Leave a comment

So I haven’t done any work at all on my game since last weekend. Mostly because losing a week’s worth of work on it was depressing me. I believe I’ve found a way to fix it, but it’s still a pain in the butt.

Hibernation Fail
Here’s what happened. I loaded up my computer on Tuesday night to start doing some coding. FlashDevelop was open when the computer put itself into hibernation due to a low battery. I pulled it up to see this:

FlashDevelop post hibernation

There might not appear to be anything wrong with that at first. The only problem is that when I shut down my computer on Saturday night, I had about 14 classes and there’s only 6 in that picture. I figured, “Well, that just must be because that’s what I had open.” So I browse to the folder where I had been saving all my files. Which I had been saving regularly. And what did I see? 7 files with the last modified date listed as 1/29/2012. Even though I had been working on my code as recently as 2/4/2012.

Looking For The cause
Now I can’t say for sure that it was the hibernation file that caused the issue. I don’t see how loading the contents of RAM should affect a folder full of files saved on the hard drive. I suppose it’s possible that “Saving” was only occurring in FlashDevelop’s memory, but that seems unlikely.

The odd part about it all, was that the compiled swf file – the one that’s created every time I try to debug the game – was still showing a last modified date of 2/4/2012. I loaded it up and, lo and behold, it was the same file I had pulled screenshots from last Saturday.

I still don’t know for sure what happened. But I’ve turned off all hibernation on the laptop just in case. I really don’t mind shutting it down every night when I’m done working. It forces me to save more often anyways.

Finding a Fix
I did try downloading a trial for a deleted files recovery tool. But it acted as if the files had never existed as well. I knew about the importance of securing your code before releasing it into the public. This is because it’s supposed to be really easy to decompile unencrypted flash files. I figured I would look for a decompiler and see what my finished swf file could give me.

I can tell you to NOT try sothink’s swf decompiler. It will let you see your code, but the local variable names will be changed and you can only copy out the code if you buy the full version.

I knew there had to be a free decompiler out there, so I googled “free actionscript 3 decompiler” and was led to F.L.A.S.W.F.. He had links to several decompilers and the one I decided to try was ASDec. Looking at the output I was surprised to find that every variable name is identical to the original version.

My Code Is Reborn!

The decompiler isn’t perfect though. It still has to leave out all the comments because those aren’t compiled at all. It also has many extra lines added in declaring variables and then initializing them on separate lines. Fortunately, it should recompile fine for now and I can update it as I go. I was really concerned for a couple days, but I’m ready to return to coding my game once again.

I’ve learned to appreciate decompilers, so long as they aren’t used to steal my game and pass it off as someone else’s. Anyone else every have computer nightmares resulting in lost code?

Move Engine Recompleted

February 4, 2012 1 comment

Once again I can move my units as I desire. Next is the reprogramming of the AI. For now, enjoy this screenshot of the movement area, recreated.

3 Steps Forward, 2 Steps Back

Well, time to tuck into bed for the night. While it’s disappointing that I haven’t gotten back to where I was 2 weeks ago, I think I’ll be much happier with the code once it’s done. Just about every variable is private now and the classes are properly encapsulated.

Doctor Who and Programming Time

February 3, 2012 Leave a comment

I just found that my local library has the first two seasons of Doctor Who available on DVD. I watched the third season a few months ago and loved it and thought it was the only season they had. I’m wide awake and ready for some programming. I think I’ve got one more class to program and the game will be functioning again.

So it’s 9:30 and I’m settling down in front of my desk with season 1 of the new Doctor Who and FlashDevelop to finish my game prototype. Screenshots to follow later tonight, maybe even a video.

Programming A Click and Drag Function

February 3, 2012 Leave a comment

Last night I decided to program in a function to allow easier map scrolling when using mouse controls. Previously I had made it similar to the Wii’s turning functionality in first-person shooters. When you got near the edge of the screen, the game would start to scroll in that direction.

The problems arose when you were just trying to access buttons that were off screen because the game would try to scroll in the direction of the buttons. It was just too easy to accidentally scroll. And if you wanted to scroll to the other side of the screen from where you were, you needed to move your mouse all the way to the other side.

Enter Click and Drag
So last night, I decided I was going to make my game scroll when I clicked and dragged. This was a more intuitive interface, similar to the iPhone’s scrolling functionality.

My first attempt at setting this up had mixed results. The scrolling was jittery and it wasn’t 1:1 for some reason. Check out my code below to see if you can spot the error. For reference, the mouseDown function is called when the user presses the left mouse button while on the map, the mouseUp function is called when the user releases the left mouse button while on the map and the mouseMove function is called when the user moves the mouse around the playField, but only after the mouse button is pressed.

private function mouseDown(e:MouseEvent):void {
	this.startMouseX = this.mouseX;
	this.startMouseY = this.mouseY;
	this.startX = this.x;
	this.startY = this.y;
		
	this.addEventListener(MouseEvent.MOUSE_UP, mouseUp);
	this.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
	Main.stageSprite.addEventListener(Event.DEACTIVATE, mouseUp);		
}

private function mouseUp(e:Event):void {
	this.removeEventListener(MouseEvent.MOUSE_UP, mouseUp);
	this.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
	Main.stageSprite.removeEventListener(Event.DEACTIVATE, mouseUp);	
}

private function mouseMove(e:Event):void {
	this.x = (this.startX - this.startMouseX + this.mouseX);
	this.y = (this.startY - this.startMouseY + this.mouseY);
}

Ignore the fact that the game will keep scrolling if you happen to release the mouse button while your mouse is outside the flash screen. I haven’t yet figured out how to fix that, so anyone that has a solution should let me know. If you can spot the other error in my code, then you’re a better programmer than I was last night.

The Solution
The problem, it turned out, was caused by my use of this.mouseX and this.mouseY. You see, as you move a sprite around, it’s mouseX and mouseY coordinates change to reflect the relative position of the mouse from the sprite’s (0,0) point, usually the upper-left hand corner.

What was happening was the game would update the mouse coordinates at the same time it tried to update the map’s coordinates. Resulting in what some would call hilarity, but what I called annoyance. To fix the problem, all I had to do was update the references to this.mouseX and this.mouseY to Main.stageSprite.mouseX and Main.stageSprite.mouseY.

Main is my initializing class and stageSprite is a static reference to a sprite that never moves. So as the map scrolled around, the stageSprite stays where it is and provides an accurate reference point to calculate how far the mouse has moved. Here are the results:

Starting Position

The ending point after one click and drag

So overall, I’m pretty happy with the results. I’m trying to reintegrate my old classes for moving units around and attacking other units now. The only problem is that I changed many of the variable names for my units and actually implemented private variables instead of public variables, so I have a lot of updates left to make before I can even run the game without compiler errors. Maybe I just need to program those classes from scratch too. As I write this I’m buzzing from my 2nd coffee this week (I only drink coffee 2-3 times per week to avoid developing a tolerance) and I’m probably feeling way too ambitious. Maybe that’s for the best.

Medieval Tactics: Zombie Wars Concept

February 2, 2012 2 comments

I realized recently that I haven’t actually explained the concept for my game yet, so here goes.

Game Mechanics
Medieval Tactics is going to be a turn-based strategy (TBS) game, similar to Advance Wars. Each turn you can move and attack with each of your units.

Every unit will have statistics based on its unit type and every unit of that type will be identical. This is in contrast to most fantasy TBS games in which each unit is unique. I thought this would allow for better tactical decisions, because once you learn how to use a unit type you know how to use all units of that type. This also simplifies the balancing because I know exactly what each unit will be able to do.

Each map will probably have a specific set of units available to it. I’ve considered adding the ability to purchase units at the beginning of each map to add more strategy to it, but if I don’t have time then it won’t be added. At the end of each level, player’s will receive a grade or score based on the number and health of units remaining. This will be used to generate a cumulative score that will either unlock future levels or provide a bonus in the final level.

Units
So far I’ve decided on 14-15 units to include in the game. This should be large enough to provide a learning curve and diversity of map types, but small enough to allow easy balancing.

Good Units
Spearman
-High defense
-Average attack and armor
-Average movement

Swordsman
-High attack
-Average defense and armor
-Average movement

Archer
-Average, medium-ranged attack
-Low defense and armor
-Average movement with ability to move and fire

Hammerer
-Very high attack
-Low defense and armor
-Average or high movement depending on balancing

Lancer
-High attack
-Low defense
-Average armor
-Very high movement

Knight
-Very high attack
-High defense and armor
-High movement

Catapult
-Very high attack with large range
-Average armor
-No defense
-Low movement and can’t move and fire same turn

Cleric
-Low attack, defense and armor
-Ability to heal allied units
-Average movement

Enemy Units
Note: Most zombie units will have an ability that fully heals them whenever they destroy a unit. Zombies would be able to turn units into zombies to replenish their numbers.

Zombie
-Average attack
-Average defense and armor
-Average movement

Zombie Archer
-Average, medium-ranged attack
-Low defense and armor
-Average movement with ability to move and fire

Explosive Zombie
-Very high attack no matter what unit’s health is
-Low defense and armor
-Average movement

Hulking Zombie
-Very high attack
-Average defense
-High armor
-Low movement

Vultures
-Average attack
-Average defense and armor
-Very high movement with ability to cross all terrain

Necromancer
-Very high attack (Or maybe ability to ignore armor)
-High defense
-Average armor
-High movement
-Ability to turn any unit it defeats into a new zombie unit

Level plans
I’m aiming to create around 20 levels for the game, depending on how long it takes to complete each level. Overall I hope the game takes a couple hours to complete and hopefully the ability to get a bonus on the last mission will encourage people to replay levels to get a high score.

Control scheme
I was originally planning on making the game completely playable with either keyboard or mouse, but I’m thinking that optimizing it for mouse will make for a better playing experience. While I prefer using keyboard controls for games, I don’t think I can easily optimize a strategy game for keyboard controls.

I also think that mouse controls are just more intuitive, i.e. click this unit, click there to move it, click the enemy to attack. Keyboard controls would be more like, let’s see, press ‘n’ to go to the next unit, press ‘m’ to move, scroll over to the target square with arrow keys, press ‘m’ to move to that square, press ‘a’ to attack, scroll over to target unit with arrow keys, press ‘a’ again to attack that unit.

Final Thoughts
There are a couple additional mechanics I’d like to include, such as wizards with spells, water-based units and an alternate campaign. I don’t think any of these are going to make it into the first version of the game. I’ll reserve them for sequels.

Any thing you’d like to see in the game that I’m not including? Let me know in the comments.