migcak's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Active Members
Active Posts:
56 (0.06 per day)
Joined:
15-August 12
Profile Views:
710
Last Active:
User is offline Jan 28 2015 11:36 PM
Currently:
Offline

Previous Fields

Country:
US
OS Preference:
Windows
Favorite Browser:
Chrome
Favorite Processor:
Who Cares
Favorite Gaming Platform:
Playstation
Your Car:
Dodge
Dream Kudos:
0
Icon   migcak Feeling optimistic

Posts I've Made

  1. In Topic: Problem with mouse input and displaying

    Posted 19 Jan 2015

    View Poststayscrisp, on 19 January 2015 - 02:56 PM, said:

    I thought we'd been over this already :dontgetit:

    Basically you want to create a piece when the mouse is clicked. Let the piece handle it's own movement and rendering.

    I know :stupid:

    I believe you were saying to have two functions, one for rendering and one for movement. The problem is I don't know how to display the piece in different positions depending on where the user clicked.
    This code will move the piece downward:
    void GamePiece::handle_input()
    {
    	int x = 0, y = 0;
    
    	if(event.type == SDL_MOUSEBUTTONDOWN)
    	{
    		if(event.button.button = SDL_BUTTON_LEFT)
    		{
    			x = event.button.x;
    			y = event.button.y;
    
    			for(int i = 0; i < 7; i++)
    			{
    				if((x > box[i].x) && (x < box[i].x + box[i].w) && (y > box[i].y) && (y < box[i].y + box[i].h))
    				{
    					yVel += PIECE_HEIGHT / 7;
    				}
    			}
    		}
    	}
    }
    

    And this will display the piece:
    void GamePiece::show()
    {
    	apply_surface(x - 17, y, redPiece, screen);
    
    }
    

    I don't know how to change my show() function to where the piece will display above one of the seven columns (as the pictures above gives an example).
  2. In Topic: Problem with mouse input and displaying

    Posted 18 Jan 2015

    Attached File  ex1.jpg (304.6K)
    Number of downloads: 3Attached File  ex4.jpg (304.94K)
    Number of downloads: 3

    View Postyothsoggoth, on 18 January 2015 - 10:10 AM, said:

    Your problem is that you're calling apply_surface(box[index].x, 0, redPiece, screen); within the input function only when the mouse button is pressed.

    You should move it to be called just after you've rendered your background.

    I want to display the connect four piece after the mouse button is pressed. It should display above the top row of the board. I attached two pictures to help you see what I mean. You can't see my mouse as I print screened but I think this will help.
  3. In Topic: Problem with motion in Connect Four game

    Posted 14 Jan 2015

    I'll create another topic for the question.
  4. In Topic: Problem with motion in Connect Four game

    Posted 13 Jan 2015

    View Postyothsoggoth, on 11 January 2015 - 09:00 AM, said:

    View Postmigcak, on 09 January 2015 - 10:59 PM, said:

    So if you want to display anything put it in a loop and use SDL_FillRect to refresh the screen?


    Pretty much.

    In the long-term, and in larger games, it's sometimes the case that you may need to do something a little more sophisticated, like render certain parts to a texture to apply effects or render different components at different times.
    But, for the most part, a "render pass" will consist of clearing the render target (i.e. the buffer that will be presented to the screen) and rendering all of your content.

    Using SDL_FillRect with black just draws full black over the previous content, effectively clearing it. Then over that you render everything.

    Thanks, I appreciate your explanation. Can I ask another question pertaining to graphics? My connect four piece displays but only if I hold the left mouse button and if I release it the piece goes away for some reason. Is this a graphics problem or a logic problem?
  5. In Topic: Problem with motion in Connect Four game

    Posted 9 Jan 2015

    View Poststayscrisp, on 09 January 2015 - 02:59 AM, said:

    Just wondering but why haven't you moved onto SDL2?

    No real reason, I'll make the change soon. Is there anything you would advise a beginner like me to learn?

    View Postyothsoggoth, on 09 January 2015 - 05:52 PM, said:

    Your problem is the way you're rendering to the backbuffer.
    The easiest way to explain this problem is to imagine rendering like painting in real life. Whatever you paint first is on the back, then each thing you paint after that will be over the top of that.
    If you don't clear the paper and you carry on painting an object in a slightly different place - you simply now have two of those on your painting.


    You're rendering the background, then the board, then repeatedly rendering the piece each frame.

    What you should be doing is clearing the back buffer every time you render, then render the images in back-to-front order, then present the buffer (flip in SDL terminology).


    Try moving apply_surface(0, 0, background, screen); and apply_surface(20, SCREEN_HEIGHT - 480, board, screen); within the loop so they're called each frame (e.g. just before you call piece.show();).

    Something like:
    // Clear buffer by filling with black no-alpha
    SDL_FillRect(screen, NULL, 0x00000000);
    
    // Render
    apply_surface(0, 0, background, screen);
    apply_surface(20, SCREEN_HEIGHT - 480, board, screen);
    piece.show();
    
    // Present
    if (SDL_Flip(screen) == -1)
        return 1;
    
    

    Thanks, it worked just like you said. So if you want to display anything put it in a loop and use SDL_FillRect to refresh the screen? Thanks again I appreciate it.

My Information

Member Title:
D.I.C Head
Age:
22 years old
Birthday:
February 23, 1993
Gender:
Location:
Tennessee
Interests:
Artificial Intelligence
C++ programing
game programming
Years Programming:
2
Programming Languages:
C++
C#
Python
LUA

Contact Information

E-mail:
Click here to e-mail me
Yahoo:
Yahoo  george_hunter86@yahoo.com

Friends

Comments

migcak has no profile comments yet. Why not say hello?