Sunday, September 21, 2014

Flying Enemies and Heavy Blocks!

Today was a great saturday! I had a good chunk of time to work on adding some new aspects to the game, and despite some really tricky curve balls, I was able to get the basics figured out.

I had avoided making enemies for a while just because the random nature of enemies is somewhat intimidating to try and code. I decided to go with a simple approach of just a flying, back and forth enemy, which I quickly added a ghost-esque flyer sprite to.

I'm not sure if this so called "Shadow" will make it to the end stages of the game, but I like his vague nature, and putting him to be about 30% transparent makes him at least somewhat interesting. Good old math came in handy and I made him follow a "sin(x)" path, so his ghosty movement is fairly pleasing to the eye.

Along with working on the enemies I made some simple gravity-obeying blocks to test out along with my destructible blocks, and just seeing their behavior is already getting the wheels in my head turning for some puzzles in the game.

As I worked on these blocks I uncovered some coding issues which turned out to be a really pain, but luckily I found this out early on rather than way down the road. To give a simplified version of the problem, basically it dealt with how projectiles interacted with destructible objects. Before today, the fireballs would explode whenever they impacted anything solid, which works just fine until you need the impacted object to react to that fireball... that exploded a few frames earlier. I dug around on the internet and finally found an approach that allows the block to find out what is hitting it before said thing explodes, and through this it now allows me to have much more control on interactivity between things.

Coding Lesson of the Day :
Original code :  (place_meeting(x,y,obj_fireball)  { hits -= 1;  }

New code: var inst;
inst = instance_place(x, y, obj_bullet);
if (inst != noone)
{
   hits -= inst.damage;
}                                        
At first glance it looks a LOT more complex, and it is a little at first, but it gives me a lot more to work with in a function. The original would say if any fireball hits me, take away one of my "hits". Once the hits were gone, the block breaks. There were some inherent problems along with this like trying to destroy the last fireball that broke the block, or trying to ONLY destroy that one fireball instead of every fireball, etc.  The new code however takes a fundamentally different approach that makes a huge difference. The variable holds a specific instance, and so if that instance comes in contact with the block, the code actually accesses the object and can use data from that object. What does that mean? It means I can now make unique spells that do different amounts of damage! And that's just the basics.

"Unlocking" this new aspect of inter-object interaction, I was now able to quickly make the Shadows do a set amount of damage to the player, make the Shadows have a set amount of hp that is affected by the damage of the specific spell... The list just keeps going on. I'm glad I figured this out because it's going to be a very crucial and absolutely necessary part of adding in unique enemies and spells. Now comes the fun part of making unique and different spells and behaviors!!! Sneak peak :




No comments:

Post a Comment