Showing posts with label hit. Show all posts
Showing posts with label hit. Show all posts

Tuesday, 4 September 2012

Select Your Side

Today I've spend about 3-4 hours working on my game, I've gotten the double jump working, bad garbage can now hit and kill rats, and the level selection page is working.

For the double jump, I was having a hard time getting it to do what I wanted, but after taking a look at the code I've been trying to use I realized something, it would be far easier so just delete the guts of the function and start over. After looking back I saw just how complicated I had been making it, when in reality I was able to cut down between 5-10 lines of code and get it to work perfectly.

When I wanted to get the garbage to his the rats as well as the rubbish I first didn't think it would have to be done any differently then the hit detection I have for the garbage hitting the rubbish or the rubbish hitting the rats, however after did some thinking I had to consider that all the garbage and rats only has two targets they were looking for, one is the single rubbish and the other is the non-moving ground. This was easy enough to do if I just kept track of the rubbish's current x and y, along with it's height and width, but since there could be multiple rats and bad garbage I had to think of a different way. I ended up making a 2D array, with each position containing a smaller array containing information about that particular bad garbage. It has it's current x and y positions, it's width and height, if it's been removed from the screen(I used a Boolean) and it's name. This allowed my rat, every time it tried to move, to scan through this array using a while loop, checking to see if it was currently colliding with any bad garbage that was still on screen. The rat kills itself then modifies the array referring to the garbage that hit it, so when the garbage updates it see's that it's collided and shouldn't be on screen anymore so it kills itself.

The level selection page wasn't that much extra work because I've been coding this game so far so it works off what the current level it, so all I have to do when a different level is selected, is to then assign stats.currentLevel to the number of the button clicked. I did have a few problems trying to catch the event that was dispatched when a level was clicked but I was able to fix this by having my map page listen for the buttons on it, then dispatch it's own event to the main page controller when something was clicked. In order to place all the different level buttons using code but without taking too much time I ended up using 2D arrays again with a while loop. Each array inside the main array just contains the x and y position of each level button, this way all I have to do is change those two numbers, which are all in one location, in order to get the buttons to move around. I'm starting to use arrays more and I have to say they really cut down on not only the lines of code that I have to write, but it also makes it easier to go back and make changes later, if you arn't a big fan of arrays I'd really suggest finding a few tutorials and trying to slowly incorporate them into your projects, before long you'll hopefully find them as helpful as I do.


Wednesday, 29 August 2012

Mini me

I've been working on getting the mousetraps to work, killing a rat if it's ready when the rat walks past it. I also have it so once the trap has been released, a counter starts that doesn't allow the trap to be rearmed until a given amount of time has passed, which can be reduced by upgrading the mouse trap speed stat. Another thing that I worked on is getting it so the hit detection area for the garbage isn't based upon hard-coded numbers, but instead based upon where I place the top and right hit points, the bottom and left are based off the origin. This allowed me to remove the generic background I had been using as the basic hit box, and instead have the invisible hit box suited for each different shaped garbage. I also scaled down the size of just about everything, from the garbage and mousetrap, to the rubbish and rats. Lastly I've added in a background to the level that changes depending on which level the user is currently playing.


This is a video taken before most of the work was done described in this post.


This is a rough animation I did for the instructions book.

Friday, 10 August 2012

Life's really just garbage

Today I worked on the lives page in the shop. I ended up adding several more stat boxes, one for current lives, cost of new lives your going to buy and the percentage saved with your bargaining chip. I also added a button for purchasing your new lives, along with several constraints. One constraint is the fact that you can't select more new lives then you currently have the garbage points to buy, and you each new life price is based upon the current number of lives you have plus the current number of new lives your trying to buy, this way someone won't just stock up on 100 lives at the start, it'll cost far too much, and the less lives they have 'floating' while they play the more points they'll have for buying stat upgrades and equipment.