Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - piji

Pages: [1]
1
General / Re: Battleship (Need help and idea with some codes)
« on: September 06, 2013, 09:20:32 am »
This in another problem that I just encountered, variable changing value in event space key pressed wont execute and I dont know why.

//VARIABLES
bool ship1Position;
bool ship2Position;
bool dragShip1 = false;
bool dragShip2 = false;
 

                case sf::Event::KeyPressed:
                {
                    switch(event.key.code)
                    {
                        case sf::Keyboard::Space:
                            if(dragShip1)
                                ship2Position = true;
                                dragShip1 = false;
                            break;
                    }
                    break;
                }

                case sf::Event::KeyReleased:
                {
                    switch(event.key.code)
                    {
                        case sf::Keyboard::Space:
                            break;
                    }
                }
            }
       }  

        window.clear();
        ship1Position = true;

        while(ship1Position)
        {
            window.draw(ship1);
            dragShip1 = true;
            ship1Position = false;

        }

        while(ship2Position)
        {
            window.draw(ship2);
            dragShip2 = true;
            ship2Position = false;
        }

 

2
General / Re: Battleship (Need help and idea with some codes)
« on: September 05, 2013, 11:08:41 am »
Thanks, so back to my current problem again.

How to make the ships to associate with the grids? Please give some examples if possible.

3
General / Re: AW: Battleship (Need help and idea with some codes)
« on: September 05, 2013, 05:47:38 am »
Since you know the position of the ship you could take an array or better a vector and calculate the correct indices based on the position.
With these indices you can set the bool variable on the vector to true or maybe use an integer (or char) to indicate states such as (ship, hit, water, etc).

Thank you for the idea. Now I see where I'm heading to.

In a meanwhile, I try to change the orientation of the ship from horizontal to vertical using RMB while LMB is pressed. It went good, but I've encountered some problems:
1. When changing the orientation from horizontal to vertical, the ship went far off the mouse pointer (Attached pic #1)
2. When I try to drag the ship after changing the ship's orientation, the ship went a slight off the mouse pointer, but still dragable (Attached pic #2)

these are what I've wrote
if (event.type == sf::Event::MouseButtonPressed && event.mouseButton.button == sf::Mouse::Right)
            {
                mouseClickedRight = true;
                if (draggingShip1 == true) //when LMB is pressed at the same time
                    ship1.setRotation(90);
                    ship1.setPosition(sf::Vector2f(mouseX,mouseY));

            }
 

How do I get the ship exactly under the mouse pointer even after I've changed its orientation?

4
General / Re: Battleship (Need help and idea with some codes)
« on: September 04, 2013, 09:10:03 pm »
First of all, I'd suggest you trying to make this game in OOP(object oriented programming), then the code will be a whole lot easier to modify, arrange and understand to other people. Also, then you could make classes, such as ship, or tiles of your map. With this logic it will be easier to make this game.

Actually, I'm taking the OOP subject next semester. But I'll take a look on it. Thank you  :D

5
General / Battleship (Need help and idea with some codes)
« on: September 04, 2013, 08:30:30 pm »
Hi, I just started using SFML a week ago and there is this assignment I need to complete which involve writing a Battleship game using SFML library. So far, I was able to complete the graphics and just done dealing with drag and drop all the ships. These are what I've wrote since 3 days ago:

http://codepad.org/W7cG5vsx

^Posted the code there cause it's more than 300 lines

These are what I've achieved (still to far away from completing the assignment  :-\ ) :
-Draw grids and ships
-Figured how to drag and drop the ships

This is the current problem which I focus on and don't know how to solve:
-Drop the ships onto the grids and assign their properties to the grids (This is for attacking and getting attacked)

If you don't get the idea, I'm bad in explaining things  :(
If you do get the idea, please help me out if you have any solutions or ideas  :D

Attached file is the screenshot of the program (I've moved the ships onto the grids)

Thank you

Pages: [1]