Thread: Help with C++ on a simple game

  1. #16
    Registered User
    Join Date
    May 2011
    Posts
    19
    No text display no, thats why i thought it could use a cout function but talking to my friends and they haven't done it that way. And i have been limited to the header and CPP files i can use. We got told what the headerrs we have and the outcome they hope for and then i have free reign. Is there no way to do it within the mainprog?

  2. #17
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Do you also have a console window along side the graphics window of SDL ?

    If you do have a console, then perhaps cout/cin may work for you. But you might also need to run the whole SDL thing in a separate thread (a whole new set of problems might arise here).

    I thought the only thing you had was the SDL message loop you have at present. Perhaps test to see if it also receives key presses.
    If it does, perhaps you could type in say 3-digit angles without having to overly worry about a UI feedback.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #18
    Registered User
    Join Date
    May 2011
    Posts
    19
    No, ive talked to people doing similar things and they haven't used cout or cin so it can't be that. I don't see a way to do it, would it help if i posted the whole mainprog?

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    Posting a small program to demonstrate one aspect of the problem would be better.

    A 600 line program might take 30 minutes just to read with some degree of comprehension, and that's a LOT of time for most people to spend on just one post. Understanding code is very non-linear (more like geometric). A hundred lines might take only a few minutes, and most helpers would probably go for that.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #20
    Registered User
    Join Date
    May 2011
    Posts
    19
    Thats why i didn't post it all, i don't see what i could put anyway because its not a problem in my program its just something i don't know what to do.

  6. #21
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I assume you are only worried about angles when they first shoot the ball? In that case why not draw a little arrow showing what angle the ball is going to go in?

  7. #22
    Registered User
    Join Date
    May 2011
    Posts
    19
    I think it has to be at the top of the page with the information. But how would i tell the projectile to move at the angel chosen from the user?

  8. #23
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Code:
    x += cosf(angle) * speed * frameDeltaSeconds;
    y += sinf(angle) * speed * frameDeltaSeconds;
    Angle is expressed in radians since cosf() and sinf() both expect their arguments in radians.
    Last edited by VirtualAce; 05-24-2011 at 09:37 PM.

  9. #24
    Registered User
    Join Date
    May 2011
    Posts
    19
    How would i make a loop that just gets a counter counting up (starting at a variable of 1 and add, say, 0.2 to it each loop) and then save whatever the value it has into a variable when the return keys pressed, then use that variable as the angle to pass to the function that shoots the projectile?

  10. #25
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,662
    How about
    Code:
    	while (!gameover) //loop untill game over
    	{
    		SDL_Delay(10); //delay 10MS so CPU not used excessaivily
    		angle += 0.1;
    Inside your event handler, detect the enter key, and do something with the current value.

    Use some other key to set angle back to 0 when you're ready to go again.

    Just one way of doing this...
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Simple Game
    By lukec2 in forum C++ Programming
    Replies: 9
    Last Post: 03-11-2011, 11:34 PM
  2. C++ Simple Game.
    By united07 in forum C++ Programming
    Replies: 14
    Last Post: 05-05-2010, 06:09 AM
  3. help with a simple game..
    By ninne in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2006, 05:48 AM
  4. A simple game using RNG
    By amirahasanen1 in forum C++ Programming
    Replies: 6
    Last Post: 03-12-2005, 11:05 AM
  5. my new (simple) game
    By dune911 in forum C Programming
    Replies: 14
    Last Post: 03-16-2002, 03:20 PM