Thread: Expression preceding parethenses?

  1. #46
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by nothing909 View Post
    this is honestly so confusing as to why this is doing this.

    whats happening now is, when i change it to long int, the values no longer get truncated, but when i run the program, nothing will show up on the screen. it literally works perfectly without the delay, but when i put in like 100000, nothing will show on the screen.

    do you have any kind of idea why this is happening?
    no not without looking at the code to try and figure it out, Me, I'd start putting printf where they need to be to give me feed back to see what is going on. if this is a terminal game and you can see them without it messing up the game. otherwise it time to learn how to use a debugger to step through your code to see what it is doing.
    Last edited by userxbw; 12-10-2017 at 06:18 PM.

  2. #47
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by nothing909 View Post
    if i set the delay to 50000, it will delay everything on the screen instead of just the racket (yR2) as intended.
    how are you controlling the racket in the first place? if it is just moving, their should be a way in side of that code you could maybe figure out how to control its movement.

  3. #48
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    i think i've kinda worked out why this is happening and i'm hoping you can help me fix it.

    when i'm putting in a delay of say 50000, it is actually delaying like i want it to, but here's the problem.

    when the racket is still, the movement of it doesn't need to be delayed so everything on the screen runs smoothly. but, when the racket does start moving, not only is the racket delayed, it delays the ball as well. how is this code delaying the ball as well as the racket and not just the racket like i intended?

  4. #49
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by nothing909 View Post
    i think i've kinda worked out why this is happening and i'm hoping you can help me fix it.

    when i'm putting in a delay of say 50000, it is actually delaying like i want it to, but here's the problem.

    when the racket is still, the movement of it doesn't need to be delayed so everything on the screen runs smoothly. but, when the racket does start moving, not only is the racket delayed, it delays the ball as well. how is this code delaying the ball as well as the racket and not just the racket like i intended?
    I or anyone else can only guess. it all depends on how you're controlling the ball and paddle action, separately or as a whole, which by what you're saying it is reacting to each other as a whole and not separately. where the user controls the angle and speed of the paddle. so that chance of the user swinging the paddle or moving the paddle is entirely up to the user.

    in other words the paddle speed is controlled by the user and not the program. Where it sounds like you're trying to make the paddle speed controlled by the program so it will hit the ball. ( all of the time)

  5. #50
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    its 1 player against the computer. the part of code i'm putting the delay in is the computer controlled racket. right now, the way the code is without the delay, the y of the racket will follow the y of the ball exactly, it will never miss. i'm adding the delay so sometimes it will miss because its not fast enough to get to the ball.

    its got nothing to do with any of the other code, it's only inside this function.

    is it because i'm writing if (yR2 > yBall) then yR2--, is this somehow inadvertently delaying the ball as well?

  6. #51
    Banned
    Join Date
    Aug 2017
    Posts
    861
    try to figure this out then, track it. the computers paddle is always in track with the ball. so regardless of the angle the ball is going the computers paddle is in front of the ball so it hits the computers paddle then the ball reacts to that velocity, angle, speed to determine its direction after hitting the computers paddle.

  7. #52
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    can you reword that, i dont know what u mean, what should i do?

  8. #53
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by nothing909 View Post
    can you reword that, i dont know what u mean, what should i do?
    you have coordence what the ball is at and the size of a paddle. code it so that the paddles top and bottom are always within the the balls center
    paddle:
    height / 2 gets middle of paddle. how ever you're moving the paddle. the ball has a center
    Code:
    The center-radius form of the circle equation is in the format (x – h)2 + (y – k)2 = r2, with the center being at the point (h, k) and the radius being "r".
     This form of the equation is helpful, since you can easily find the center and the radius.
    so code it so that the paddles center is always lined up with the balls center.

  9. #54
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    it is already coded like that. the ball will always hit the paddle in the centre.

    i thought that adding the delay for the paddle increments that it would make the ball hit it off centre sometimes and also miss it sometimes.

  10. #55
    Banned
    Join Date
    Aug 2017
    Posts
    861
    Quote Originally Posted by nothing909 View Post
    it is already coded like that. the ball will always hit the paddle in the centre
    sorry I missed that part you want to make it miss sometimes. I misunderstood, you'd have to write an algorithm to make paddle miss the ball.
    just ball parking this mind you because it can be done different ways, and at different times. code it to keep count of how many times it hits the ball, when an amount of times is reached, then make the paddle move so it misses the ball. Whence you figure that out you can move to figuring out how to make that occur at random amounts of time so it is not so predicable.

  11. #56
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    why can't i just line the y paddle up with the y ball, but when it moves the y paddle is slower than the ball, so sometimes when the player hits the ball back it cant follow it fast enough and it will miss.

    this seems like a much simpler way of doing it.

    the only problem i'm having with that code is that it's delaying the ball as well as the racket. why is it delaying the ball, when it looks like its coded just to delay the racket?

  12. #57
    Banned
    Join Date
    Aug 2017
    Posts
    861
    your best bet right now is using the internet resources that are out there and googling how to do this, and find all of the different methods on how to do this. I've already read a few .so they are out there to help you in your endeavor in this event.

  13. #58
    Registered User
    Join Date
    Oct 2017
    Posts
    33
    Quote Originally Posted by userxbw View Post
    your best bet right now is using the internet resources that are out there and googling how to do this, and find all of the different methods on how to do this. I've already read a few .so they are out there to help you in your endeavor in this event.
    I've already googled things and I've seen people talking about a delay which im trying to implement, but the only problem I'm having is that it's not only delaying the paddle it's delaying the ball as well.

    I know I've asked this before but can you look at the most recent code I posted and maybe indicate why the ball is being delayed when I'm only intending the paddle to be delayed

  14. #59
    Banned
    Join Date
    Aug 2017
    Posts
    861
    that original code ? does it shows how the paddles and ball interact with each other.

  15. #60
    Registered User
    Join Date
    Dec 2017
    Posts
    1,644
    Presumably your overall algorithm is something like:
    Code:
    Loop:
      Draw paddles and ball
      Check for user input and update user paddle position
      Calc computer action and update computer paddle position
      Update ball position
    So if you put a delay in the computer's move, it will delay everything, unless your app is multi-threaded.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rotation independent of preceding rotations (DirectX)
    By blakeo_x in forum Game Programming
    Replies: 12
    Last Post: 10-03-2012, 05:23 PM
  2. initializer expression list treated as compound expression
    By karthikeyanvisu in forum C Programming
    Replies: 7
    Last Post: 02-26-2011, 05:19 PM
  3. Replies: 2
    Last Post: 11-25-2009, 07:38 AM
  4. preceding zeros in int variables
    By AshFooYoung in forum C Programming
    Replies: 2
    Last Post: 09-23-2001, 02:28 PM
  5. Preceding 0
    By morbuz in forum C++ Programming
    Replies: 2
    Last Post: 09-19-2001, 12:15 PM

Tags for this Thread