Monday 23 April 2012

Final Post

All I had left to do today was to give the user lives and make them decrement every time they miss the target. I did this by declaring an integer as the user lives and then take one life away every time the direction = 0 and the target has not been hit. I first had to convert the integer to a constant character in order to display it on the screen.

I ran different tests on the game today and the only problem I encountered was the click and drag function, as if a mirror was being dragged and collided with another mirror, both mirrors would be emrged together and unusable in the game.

 The game is now finished and ready to submit. I will probably go on to develop the game further after the project and translate it to an android or iphone app when it is fully ready and more lvels have been added. 

Finishing the gameplay

Now that all of the collision detection is in and the game now works, I started to design the first level of the game. I added in red walls that are drawn from the text file which if hit by the user, the level is failed. I have given the user 7 mirrors to navigate the beam to the target. The level is not very hard, but it shows that the program works.

I have also put a starting menu on the screen, and a loop so that if the player fails the level, it resets. If the level is complete is leaves back to the main menu.



 Main Menu
Red Wall is hit


I've also added that all the mirrors in the level must be used to hit the target. I did this by having the number of mirrors in the text file and then declaring a separate integer in main which increments every time a mirror is hit. If, when the target is hit, the integer in main is not greater than or equal to the number of mirrors, the level has been failed.









Saturday 21 April 2012

Final collisions

I have now put in the final collision detection functions. The beam will now know if it has hit the back of a mirror, and if it has, it will stop and the user has failed the level. The code uses the same idea as the detection for hitting the angled side of the mirror:

//Back of BR & TR mirror
if((getpixel(backBuffer,X-1,Y) == makecol(0,255,0)) && (getpixel(backBuffer,X-1,Y+10) == makecol(0,255,0)))
{
if(   (getpixel(backBuffer,X-21,Y+20) == makecol(0,255,0) || getpixel(backBuffer,X-21, Y+10) == makecol(0,255,0))
|| (getpixel(backBuffer,X-21,Y) == makecol(0,255,0) || getpixel(backBuffer,X-21, Y-10) == makecol(0,255,0))
)




{
directionx = 0;
directiony = 0;
}



I also pass the target to hit into the bounding box collision function, to see if the player has hit it. If the beam has hit the yellow target box, the level has been won. However, if the direction of the beam is = 0,0, and the target hasn't been hit, the user has failed the level.
















Level has been completed











Level has been failed



Friday 20 April 2012

Game Engine

I now have the functions for detecting if a mirror is hit by the beam, and if so, what kind of mirror it is and how the direction of the beam should change.

Each mirror position (bottom left, top left, bottom right, top right) has its own function that detects if the beam has hit it. It knows what kind of mirror it has hit by checking he coordinates around it and matching them to the function. he function is passed in the bitmap, x coordinate, y coordinate and the colour so it knows exactly what kind of mirror it has collided with.

bool bottomleft(BITMAP * backBuffer,int x, int y, int colour)
{

    if(getpixel(backBuffer, x - 10, y) == colour && (getpixel(backBuffer, x + 10, y + 20) == colour))
                    {
                        if(((getpixel(backBuffer, x - 10, y + 20) == colour)  && (getpixel(backBuffer, x, y  + 11) == colour )))
                            {   
                               
                                    return true;                       
                       
                            }
                        else return false;
                    }

    else return false;

}


In main():




if(bottomleft(backBuffer,X,Y,makecol(255,0,0)))
                {
                    directionx = 0;
                    directiony = -1;
                }










 





















 


 





Wednesday 18 April 2012

Mirror Placement

I now have the program reading the coordinates for the mirrors to be placed from a text file.
In Main(), the program opens the file, reads the coordinates for the mirror to be drawn, the colour of the mirror, and where it is to be placed on the screen. This means that for different levels, I can specify how many mirrors there will be, what kind of mirrors they will be, and where they are to be placed. There is a bar at the side of the screen where the mirrors for each level are placed, and the user drags them on to the grid and places them where they want.

I already had the mirror draw coordinates and colour in place, so to add the screen position coordinates, I added the variables posx and posy to the mirror function, which are then passed to main(). The Vector positions are assigned to posx and posy in the mirror function.


The mirror function:

Mirror45::Mirror45(float x1, float y1, float x2, float y2, float x3, float y3,float posx, float posy, int color)
{
       
        myBitmap=create_bitmap(25,25);
        clear_to_color(myBitmap,makecol(255,0,255));
        triangle(myBitmap,x1,y1,x2,y2,x3,y3, color);
        //rectfill(myBitmap,0,0,20,20,color);
        position.x = posx;
        position.y = posy;
   
}



The text file:











The values being passed to main, and main reading from a text file:



            string astring, anotherstring, color;

            float x1,y1,x2,y2,x3,y3,posx,posy;
                 
        while(!mirrors.eof())
        {
            getline(mirrors,astring);
            stringstream ss(astring);
            ss >> anotherstring;
           
                       
       
                if(anotherstring == "box")
                    {
                        ss >> x1;
                        ss >> y1;
                        ss >> x2;
                        ss >> y2;
                        ss >> x3;
                        ss >> y3;
                        ss >> color;
                        ss >> posx;
                        ss >> posy;
                        listOfShapes.push_back(new Mirror45(x1,y1,x2,y2,x3,y3,posx,posy,colorFunction(color)));
                       
                    }

               
       
        }
        mirrors.close();