Tuesday, 17 April 2012

Pixel Collision

Today I implemented pixel collision to the program. It will be usedfor checking if the beam has hit a mirror and if so,what kind of mirror. I'd been working on it for a while but today I fixed all the bugs in it. I created a bool function called pixelcollision which is passed in values which are then checked to seeif they are colliding with a certain colour. If the pixel is colliding, it will return the value true The code for the function is:

bool pixelcollision(BITMAP * backBuffer, int x, int y, int width, int height, int color)
{
if (getpixel(backBuffer, x - 1, y) == color || getpixel(backBuffer, x, y -1 ) == color ||
getpixel(backBuffer, x + width + 1, y) == color || getpixel(backBuffer, x, y + height + 1) == color)
return true;
return false;
}



So if the function returns true, the direction of the beam will change. I'm still trying to work out the trigonometry for the angle of changing the direction, so for the moment I'm just reversing the x and y coordinates of it.




if(pixelcollision(backBuffer, X, Y,width,height,makecol(0,255,0)))
{


directionx = directionx*(-1);
  directiony = directiony*( -1);

}



This just makes the beam hit a green object and then reverse the direction it's heading in.


Starting points


Blue Box moving at x = -1 y = 0



Blue box has hit the green box, so now the direction is x = 1, y = -1




Thursday, 12 April 2012

Collision Detection

Today I finally began putting in collision detection to the program.

It took me a long-time to get it right but I now use collisions to enable the user to click and drag the mirrors around the screen to be placed in the path of the laser.

The algorithm works by detecting if the mouse pointer is inside the same area as the mirror's bitmap, and then when the left mouse button is pressed down, the mirror will follow the mouse's coordinates.


if (mouse_x > (position.x - 20) && mouse_x < (position.x + 20) && mouse_y > (position.y - 20) && mouse_y < (position.y + 20) && mouse_b & 1)
{

if (position.x < mouse_x)
position.x += 10;


if (position.x > mouse_x)
position.x -= 10;


if (position.y < mouse_y)
position.y+= 10;


if (position.y > mouse_y)
position.y -= 10;







Dragged by mouse:




New placement:





The next step is to work out the collision detection for the laser beam to reflect off the mirrors














Monday, 27 February 2012

1st Update - 27/02/2012

After a lot more thought about the project, I decided to scrap the catapult idea. I have decided that the game will involve a laser beam that is shot from the user's cannon, which the user must direct, through an obstacle course of mirrors and other objects that affect the path of the laser, to a specific target. The game will get progressively harder, with new obstacles and more challenging courses being introduced.
The game will be done using allegro and C++.

I began the foundations for the programming design, by drawing a class diagram and planning the basic functions of the program.

I drew a grid to the screen using for loops to give it a more technological and and anasthetically pleasing effect.



Next I had to design the cannon. Art is definitely not one of my strong points, so I just wanted a very basic sketch.






I drew a modified cannon on the screen and began testing putting in objects. I first put in a box that reads its values from a file using the STL Vector, as I plan on using file reading to get the positions of objects in the game.






Over the next few days, I plan on drawing the objects properly and getting some movement into the game.


Tuesday, 14 February 2012

OOP Project

Idea Proposal

After long brainstorming sessions in a small subway with my classmates, I had a few ideas floating around for what I would do for my project. We were given a lot of freedom with it so there are many possibilities of what it can be.

First I thought about what flash games/apps I liked and why I liked them. I wanted to come up with an addictive but original game that could be programmed well enough so that it is fun to play. My first idea was a game where laser are shot in the screen, and the user must align different kinds of mirrors which have different affects on the laser, so that the laser hits a certain point. However, after thinking of all the games that I liked playing, I realised that most of them involved some sort of catapult or slingshot. Because of this I scrapped the laser idea and began thinking of a catapult style game that is somewhat original.

I have a fairly good idea of what the game will be like, but I have not designed it in detail yet. So far I plan on having:

  •  A ball that is thrown by the user where the speed and direction is controlled either by dragging the mouse back or by using a 'power bar' and an 'angle bar'.   
  •  A target on screen to be hit by the user.
  • Obstacles that affect the ball in different ways upon contact with it.
  • Progession through levels with increasing difficulty.

 I plan on improvising a bit during the programming of the game, but I will do a detailed design before even going near a computer to program it. Hopefully after a short while I will have worked out exactly what it is I need to do and be able to do.

I will be keeping blog updates on my progress.