VaW progress: Week 4

Published September 07, 2011
Advertisement
Welcome back!

Once again, I haven't had a great deal of time to work on VaW, as I came back from a trip to France on Sunday and started school the following day. But I've got a few bits and pieces done.

Customary screenshot:
week4.png

As you can see, I'm playing as a tomato. What's great about the Asset-Player relationship is that humans and AI can step into the shoes of any Character asset they want with the set_player method for Assets and the set_ai method for Players (though the instance of Player with an ID of 0 is the human player regardless). But this isn't anything new.

I've created a new fan asset (complete with spinning fins! tongue.gif) that basically manages a Force that pushes upwards (just 'cause I can). I've renamed the Beam force to Push and also created a Pull force. They just push/pull in one direction. When a fan is created, it creates a Push force that is directed upwards (and destroys the force on fan destruction). Jump above the fan and you'll be propelled into the air!

I've created a new Asset type: Projectile. At the beginning of the project I felt I didn't need this kind of Asset as you could just create one by using a Generic type. But I created this type because bullets needed to selectively collide with objects, i.e. they should not collide with Assets of the same team as the Asset that shot the bullet. I don't fancy friendly fire, to be honest. To create an instance of Asset with type Projectile, you just do this in the Item Asset code:

def on_fire
myBullet.new rotation, x, y, team
end


An instance of myBullet is created, firing in direction rotation at the specified coordinates and with the team of the Item it is fired from (which the corresponding Character Asset it is attached to gives to it). The Projectile's speed, gravity, etc. is defined in the class definition in the new_asset method which loads up the Asset data into the dictionary. Projectiles are also rotated to their direction by the C++ engine, so if they are affected by gravity or a Force, they won't look weird.

Lastly, I've optimised the collision algorithms. Before, I was using the quick to implement but nasty 'loop through every instance and then loop through every other instance and check if they collide' algorithm. This wasn't really a problem in terms of speed, because there weren't a great deal of objects to collide with. But I felt I should optimise it now in this early stage, just to get it out the way, and so that I don't need to do it later when there is more code to potentially break. I used a simple spatial partitioning system that splits the scene into a 2D grid (no need for full 3D collision detection in this game!), and then all of the assets decide which grid spaces they occupy, and stick themselves in the relevant grid spaces' lists of assets it contains. Moving Assets such as Generics, Characters and Projectiles are relocated when they move, but static assets like Scenery only do grid calculations on construction. Any Scenery at a depth other than 0 or are not collidable are not included.

There is actually a separate list in a grid space for each type of Asset, so that they can selectively collide with other types. For instance, Projectiles need to collide with Generics, Characters and Scenery, but not Items or other Projectiles. Actually, Projectiles never get their own collision detection stage in the collision handling part of the game loop. Scenery collision is handled earlier in the loop, at the stage where Assets are moved according to their velocity. I decided (for no reason) to check for collisions with Generics first, which involved other Generics, Characters, and Projectiles. Then Characters are checked for collision against Scenery and Projectiles (we've already done Generics!). Scenery, Generic and Character collision has already been handled, so no there's need to do any more checks.

And that's all the main bits this week! There were some other bits and pieces and tweaks, but they aren't particularly notable. On my to-do list I've got some pretty chunky things to be getting on with, so next week should hopefully be a little bit more exciting!

Thanks for reading, and I appreciate any comments smile.gif

See you next week!

Max
@supermaximo93
Previous Entry VaW progress: Week 3
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement
Advertisement