Tuesday, March 06, 2007
Zelda Optimization
:::: EDIT ::::
Okay, I have a new version! I think it should be much faster now (than the regular version; I haven't edited the speed remix), smoother, etc... there may be a few bugs, but nothing too bad. Here it is:
http://www.baomon.com/blog/zelda-2007-01.exe (3.2mb)
You should go back to the zelda help file to remember some of the important information, about ledges, skill points, saving/loading, and more. Anyway, of course, there are a few edits:
- Like I said in the section below, enemies now die when you leave their home screen, so it'll still be laggy when enemies are on screen, but when you leave the screen everything should be fine as pie
- I checked my code - everytime you move, you would relearn the placement of all the walls, which made it really slow. So now, instead of checking it every frame you move, it only checks every 2 or 3 seconds, and everytime you come onto a new screen. So, sometimes if you hit a switch that moves a wall, it won't check the move until 2 or 3 seconds later, so you'll have to wait; similarly, some NPCs move around and sometimes it will seem like you're stuck, because an NPC's "shadow" will be there.
- I made the first tiny dungeon easier - that "6" puzzle is no longer there, you can just go through as if there was no wall; and some enemies were removed, because for some reason, their hit detection is really, really poor.
Also... well, I really want my game to be played. It's like I know the start and ending of a movie and everything in between, and it's killing me not being able to share it with anyone. So, I want to put out some incentive for people to play my game.
First, if it's too slow still, let me know, but I hope it's at least a bit faster than before. But if the game's okay... well, I put FIVE secret passwords scattered in my game. At five certain points in the game, when talking to a character, he would tell you a passcode... he'll say something like "(bao says PASSWORD)".
So the deal is, you play my game, and then when you get far enough, you'll get a password, and let me know so I know you've played it thus far, and I give you a reward. I'm not sure what it is yet.. maybe money? heh. I dunno. But let's say... if you get the last or the second last password... for now... I'll give you... EIGHT dollars. Yes... that sounds fun. Also, if you could also provide feedback when I give you the EIGHT dollars, that'd be awesome.
Lastly, if you know the cheatcode, please don't use it :P
:::: /END EDIT ::::
So a while ago, I made a Zelda game in Flash – it was my own piece of work, which I spent about 3 months making. It had my vision, my script, my ideas (and ideas that I’ve taken from other places, and turned them into my ideas) – overall, I thought it was really awesome. But then nobody played it – at least, not more than a couple minutes. Nobody got to see the funny surprises I put in; the giant enemy crab, the new enemies, the secret temple (which wasn’t so secret, since you had to go there to beat the game), the new weapons, the other boss, the cutscenes, the music, the ending – nothing! And that kind of reaction pretty much slowed down my game making. Why make games if nobody is going to play them?
So what went wrong?
It was slow. It was too slow. There were too many operations happening in each frame, that the game seemed really laggy. There were a few other problems, such as weird hit detection, but those were excusable – but the slowdown was unbearable. So unless you played it on a really high-end machine (like the machine I made it on), it was really, really chunky.
I stopped working on the game since there was almost no feedback on it. Duy played it a bit, and Oleg beat it, but mostly, there was no feedback. But I’m willing to edit the game a bit, if I can, to make it less chunky. So how do I do that?
First, since then, I learned a few things, which might make it faster, but I somehow doubt it… well… maybe? I’ll totally have to think about it though. But anyway, let me tell you how the game engine works and what happens each frame, and then maybe you can help me reduce the number of things that happen each frame, so that the game moves faster.
Almost for sure, the primary thing that causes slowdown is enemies, because they have to check so many things each frame. Mainly, they have to check if they come in contact with anything, such as 1) the player, 2) the sword, 3) arrow 1, 4) arrow 2, 5) arrow 3, 6) bomb, 7) boomerang, 8) nova bolt 1, 9) nova bolt 2, 10) nova bolt 3, and more. So if there’s 3 enemies on the screen, and 10 operations per frame per enemy, that’s 900 operations per second. I’m not sure if that’s a big number or not (can’t a computer can do a billion operations per second?), but it sounds pretty big, and if we can reduce that, that’d be great.
I did release a speed-remix version, which made your character run faster, and make some weapons not work on some enemies, to reduce the number of operations per frame (nova stopped working on most enemies, which reduces the 10 operations per frame to 7). That didn’t improve the game that much though. It was still laggy, but it took you less frames to move across the screen, so it felt faster.
HMM… I just had an idea. I was going to write about my old code and the new code that I’ve learnt lately, but for the past 20 minutes I’ve been thinking of a way that *might* make the game work more smoothly. OR… I could first change a major philosophy of the game to see how it’ll affect it, and if it’s good enough… well, then that’s good enough.
So right now, in my game, if you see enemies, the game will slow down drastically, and if you leave the room… the game is still slow. That’s because the enemies will continue to check for you and your weapons until you’re about 1000 pixels away from them, or about 1.5-2 rooms. If I change the philosophy so that enemies die when you leave the screen (so you can “zone” away from them), the game should be much faster, right?
Hm… I’ll try that later. My other idea was that I can create enemies dynamically, and remove them dynamically, and then move the weapon detection into the weapons themselves, so that it will only slow down a bit when you’re using your weapon. HMMM…. Lots to think about. But for now, I’ll try to change the other philosophy, where enemies will die when either you or they leave the screen. Hopefully the game goes faster then. I’ll code it later and try it later. And then, hopefully, you all will enjoy the battles of fighting a giant enemy crab, fighting the hate drafter, and casting your summon spell on the last boss.
Comments:
Post a Comment
:::: EDIT :::: Okay, I have a new version! I think it should be much faster now (than the regular version; I haven't edited the speed remix), smoother, etc... there may be a few bugs, but nothing too bad. Here it is: http://www.baomon.com/blog/zelda-2007-01.exe (3.2mb) You should go back to the zelda help file to remember some of the important information, about ledges, skill points, saving/loading, and more. Anyway, of course, there are a few edits: - Like I said in the section below, enemies now die when you leave their home screen, so it'll still be laggy when enemies are on screen, but when you leave the screen everything should be fine as pie - I checked my code - everytime you move, you would relearn the placement of all the walls, which made it really slow. So now, instead of checking it every frame you move, it only checks every 2 or 3 seconds, and everytime you come onto a new screen. So, sometimes if you hit a switch that moves a wall, it won't check the move until 2 or 3 seconds later, so you'll have to wait; similarly, some NPCs move around and sometimes it will seem like you're stuck, because an NPC's "shadow" will be there. - I made the first tiny dungeon easier - that "6" puzzle is no longer there, you can just go through as if there was no wall; and some enemies were removed, because for some reason, their hit detection is really, really poor. Also... well, I really want my game to be played. It's like I know the start and ending of a movie and everything in between, and it's killing me not being able to share it with anyone. So, I want to put out some incentive for people to play my game. First, if it's too slow still, let me know, but I hope it's at least a bit faster than before. But if the game's okay... well, I put FIVE secret passwords scattered in my game. At five certain points in the game, when talking to a character, he would tell you a passcode... he'll say something like "(bao says PASSWORD)". So the deal is, you play my game, and then when you get far enough, you'll get a password, and let me know so I know you've played it thus far, and I give you a reward. I'm not sure what it is yet.. maybe money? heh. I dunno. But let's say... if you get the last or the second last password... for now... I'll give you... EIGHT dollars. Yes... that sounds fun. Also, if you could also provide feedback when I give you the EIGHT dollars, that'd be awesome. Lastly, if you know the cheatcode, please don't use it :P :::: /END EDIT :::: So a while ago, I made a Zelda game in Flash – it was my own piece of work, which I spent about 3 months making. It had my vision, my script, my ideas (and ideas that I’ve taken from other places, and turned them into my ideas) – overall, I thought it was really awesome. But then nobody played it – at least, not more than a couple minutes. Nobody got to see the funny surprises I put in; the giant enemy crab, the new enemies, the secret temple (which wasn’t so secret, since you had to go there to beat the game), the new weapons, the other boss, the cutscenes, the music, the ending – nothing! And that kind of reaction pretty much slowed down my game making. Why make games if nobody is going to play them? So what went wrong? It was slow. It was too slow. There were too many operations happening in each frame, that the game seemed really laggy. There were a few other problems, such as weird hit detection, but those were excusable – but the slowdown was unbearable. So unless you played it on a really high-end machine (like the machine I made it on), it was really, really chunky. I stopped working on the game since there was almost no feedback on it. Duy played it a bit, and Oleg beat it, but mostly, there was no feedback. But I’m willing to edit the game a bit, if I can, to make it less chunky. So how do I do that? First, since then, I learned a few things, which might make it faster, but I somehow doubt it… well… maybe? I’ll totally have to think about it though. But anyway, let me tell you how the game engine works and what happens each frame, and then maybe you can help me reduce the number of things that happen each frame, so that the game moves faster. Almost for sure, the primary thing that causes slowdown is enemies, because they have to check so many things each frame. Mainly, they have to check if they come in contact with anything, such as 1) the player, 2) the sword, 3) arrow 1, 4) arrow 2, 5) arrow 3, 6) bomb, 7) boomerang, 8) nova bolt 1, 9) nova bolt 2, 10) nova bolt 3, and more. So if there’s 3 enemies on the screen, and 10 operations per frame per enemy, that’s 900 operations per second. I’m not sure if that’s a big number or not (can’t a computer can do a billion operations per second?), but it sounds pretty big, and if we can reduce that, that’d be great. I did release a speed-remix version, which made your character run faster, and make some weapons not work on some enemies, to reduce the number of operations per frame (nova stopped working on most enemies, which reduces the 10 operations per frame to 7). That didn’t improve the game that much though. It was still laggy, but it took you less frames to move across the screen, so it felt faster. HMM… I just had an idea. I was going to write about my old code and the new code that I’ve learnt lately, but for the past 20 minutes I’ve been thinking of a way that *might* make the game work more smoothly. OR… I could first change a major philosophy of the game to see how it’ll affect it, and if it’s good enough… well, then that’s good enough. So right now, in my game, if you see enemies, the game will slow down drastically, and if you leave the room… the game is still slow. That’s because the enemies will continue to check for you and your weapons until you’re about 1000 pixels away from them, or about 1.5-2 rooms. If I change the philosophy so that enemies die when you leave the screen (so you can “zone” away from them), the game should be much faster, right? Hm… I’ll try that later. My other idea was that I can create enemies dynamically, and remove them dynamically, and then move the weapon detection into the weapons themselves, so that it will only slow down a bit when you’re using your weapon. HMMM…. Lots to think about. But for now, I’ll try to change the other philosophy, where enemies will die when either you or they leave the screen. Hopefully the game goes faster then. I’ll code it later and try it later. And then, hopefully, you all will enjoy the battles of fighting a giant enemy crab, fighting the hate drafter, and casting your summon spell on the last boss. |