CheddarCheese

Members
  • Content count

    36
  • Joined

  • Last visited

Community Reputation

116 Neutral

About CheddarCheese

  • Rank
    Member
  1. SDL Camera Interaction Problem

    @ nfries88: Thanks for your advice! And you were correct, I wasn't drawing the bullet relative to the camera, and that was one of the problems. The other problem that I had was that the camera still refused to follow the bullet (I'm not sure why), but I worked around that by making the camera move at the same velocity as the bullet. (Instead of making the camera move WITH the bullet) Thanks for your help, it turns out I was just being dumb.
  2. Hi everyone, I have a bit of a problem. I'm working on a C++ SDL game. I just recently inputed the ability to scroll through the level with a camera. However, there is a problem. My game is turn based, and the character can fire his bullet past the limits of the camera screen. I want the player to know where the bullet lands, so I decided I would make the camera follow the bullet, keeping the bullet in the middle of the screen until it hits something. However, for some reason, when I input the code for following the bullet with the camera, the bullet starts off to the side of the character, instead of from his gun. Without the camera following, the bullet starts from his gun as planned. I'm not completely sure why this is happening, but it seems that the bullet doesn't want to travel separately from the camera, and all the changes made with the position of the camera applies to the bullet as well. Here is some code I have: When the "Fire" button is clicked: //Make the bullet position the same as the player position Bulletx = ((Player1x) - camera.x); Bullety = ((Player1y) - camera.y); In function Bullet::move() : //Move the Bullet Bulletx += Velx; Bullety += Vely; //Make the camera follow the bullet camera.x = ( Bulletx + bullet->w/2 );camera.y = ( Bullety + bullet->h/2 ); In function Bullet::show() : //Show the bullet apply_surface( Bulletx - bullet->w/2, Bullety - bullet->h/2, bullet, screen ); Any ideas as to what I'm doing wrong, or what I can do to fix this problem? Thanks. (P.S. I've posted this in the beginners area, but I don't think it was the correct area.)
  3. SDL Camera Interaction Problem

    Looking back on this, I think I may have put this question in the wrong section. I should probably have put it in "Alternative Game Libraries" or something. Should I repost it there? Or just leave it here?
  4. SDL Camera Interaction Problem

    Hi everyone, I have a bit of a problem. I'm working on a C++ SDL game. I just recently inputed the ability to scroll through the level with a camera. However, there is a problem. My game is turn based, and the character can fire his bullet past the limits of the camera screen. I want the player to know where the bullet lands, so I decided I would make the camera follow the bullet, keeping the bullet in the middle of the screen until it hits something. However, for some reason, when I input the code for following the bullet with the camera, the bullet starts off to the side of the character, instead of from his gun. Without the camera following, the bullet starts from his gun as planned. I'm not completely sure why this is happening, but it seems that the bullet doesn't want to travel separately from the camera, and all the changes made with the position of the camera applies to the bullet as well. Here is some code I have: When the "Fire" button is clicked: //Make the bullet position the same as the player position Bulletx = ((Player1x) - camera.x); Bullety = ((Player1y) - camera.y); In function Bullet::move() : //Move the Bullet Bulletx += Velx; Bullety += Vely; //Make the camera follow the bullet camera.x = ( Bulletx + bullet->w/2 );camera.y = ( Bullety + bullet->h/2 ); In function Bullet::show() : //Show the bullet apply_surface( Bulletx - bullet->w/2, Bullety - bullet->h/2, bullet, screen ); Any ideas as to what I'm doing wrong, or what I can do to fix this problem? Thanks.
  5. SDL_rotozoom. How do I use it?

    Nevermind, I found the solution myself. Thank you everyone for all your help!
  6. SDL_rotozoom. How do I use it?

    Thanks! Your solution was successful, the character rotates from the center. Unfortunatly (again), there's yet another problem. The angle that the character points seems to be off. The front of the player doesn't face the mouse directly, but is off a few degrees. My angle calculation: angle = -(atan2(Mousey-Playery, Mousex-Playerx)) * (180/PI); Rotate the player: player= rotozoomSurface(original, angle, 1., 0); Any idea what the problem might be? Or am I missing anything? Any help would be appreciated. Thanks!
  7. SDL_rotozoom. How do I use it?

    void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL ) { //Holds offsets SDL_Rect offset; //Get offsets offset.x = x; offset.y = y; //Blit SDL_BlitSurface( source, clip, destination, &offset ); } ... apply_surface(Playerx, Playery, player, screen); Is this what you mean?
  8. SDL_rotozoom. How do I use it?

    Sorry for bumping, but this problem is still unresolved.
  9. SDL_rotozoom. How do I use it?

    Hi, thanks for your explanation, and it makes perfect sense. However, I'm still doing something wrong, because it still refuses to work for me. void FindMousePosition() { //Initialize Player location & size Playerx = 250; Playery = 200; if( event.type == SDL_MOUSEMOTION ) { //Assign Variables to the mouse position Mousex = event.motion.x; Mousey = event.motion.y; PlayerCenterx = Playerx + (player ->w / 2); PlayerCentery = Playery + (player ->h / 2); //Calculate Angle angle = -(atan2(Mousey-PlayerCentery , Mousex-PlayerCenterx)) * (180/PI) - 90; //Rotate Player SDL_FreeSurface( player ); player = rotozoomSurface(original, angle, 1., 0); } } I've tried to use your method, but it still gives off a wobble. I'm not quite sure what's wrong.
  10. SDL_rotozoom. How do I use it?

    Thanks for the information, but my main problem at the moment is the fact that I can't get the character to pivot on one spot. It seems to wobble a bit, and I'm not sure how to fix it. I tried getting the middle point of the character by doing Playerx = (x1+x2)/2 and Playery = (y1+y2)/2. Then I use: angle = -(atan2(Mousey-Playery , Mousex-Playerx)) * (180/PI) - 90; However, the character still wobbles when it rotates. Any help would be appreciated.
  11. SDL_rotozoom. How do I use it?

    Thank you for that information. I have changed my code accordingly, and tweaked it a little to get my desired results. For some reason, my picture required a calculation of: angle = -(atan2(Mousey-Playery , Mousex-Playerx)) * (180/PI) - 90; To actually get the player facing the mouse. There is one more problem however. When the player turns, it doesn't pivot in place, but rather jumps around a little bit. I'm assuming it's because I'm not using the center of the image, although I'm not 100% sure how to get this. The image is also off by a few degrees, but I'm not sure if it's because it's pivot point is wrong, or something else.
  12. SDL_rotozoom. How do I use it?

    Hi, thanks for all the information! I have been looking into the rotations based on your info. I still can't seem to figure something out however, This is my following code for rotating what I have at the moment: ... //Variables for player location Playerx = 15; Playery = 15; //If mouse is moved if( event.type == SDL_MOUSEMOTION ) { //Find Mouse Position Mousex = event.motion.x; Mousey = event.motion.y; //Calculate Angle angle = atan2(Mousey-Playery,Mousex-Playerx); //Rotate Player player = rotozoomSurface(player, angle, 1., 0); } ... I looked through a bunch of threads regarding getting the angle, and my search came up with that. It doesn't work, and whenever the mouse is moved, the player character distorts and spins into strange shapes and goes flying off screen. I know I'm doing something really wrong here, but I don't know how to fix it. Any help would be appreciated.
  13. SDL_rotozoom. How do I use it?

    Unfortunately, I still don't really know how to apply rotozoom for what I need. Like I stated at the beginning, I want an image of the player to spin according to the mouse. How would I do this? (And how do I cache files to prevent reduced speed?) Sorry for not knowing stuff. I'm still quite new to this.
  14. SDL_rotozoom. How do I use it?

    The debugger showed no errors in the code. Compiling worked fine without error. However, I have gone through a whole bunch of topics regarding SDL_gfx, thinking that would be the problem, and I seemed to have figured it out. My problem was that I was trying to link SDL_gfx like the other libraries (SDL_ttf, SDL_mixer), and I linked it with -lSDL_gfx. This apparently didn't work by itself, and required me to link to the actual library - twice. The rotations now work to some extent. Thanks everyone for giving advice.
  15. SDL_rotozoom. How do I use it?

    @ Servant of the Lord Thank you for your explanation. All of the files seem to load correctly, as the program only does not work when that single "rotozoomSurface" is not present. It only refuses to work with that line. I'm not sure what the error is because it Complies completely fine. It just doesn't run. There is no error message or anything. I have tried changing the number values within the rotozoomSurface function to no avail.