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

Author Topic: Bouncing Projectile  (Read 1617 times)

0 Members and 1 Guest are viewing this topic.

xzazer

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Bouncing Projectile
« on: March 02, 2016, 03:18:25 pm »
Hey everyone!

I'm relatively new to programming and now I'm working on this project where I create a projectile that fires from the avatar and goes towards the direction of the mouse.
The problem I have encountered is that my projectile is bouncing of enemies. This is happening because you can hold down the fire button after you have fired and I have tried to solve this on my own for a while and it is just not working. So I would love all the help I can get!

The projectile is not bouncing when it hits the edges of the screen but it fires automatically if that happens. So I need help making it so that clicking the mouse while its active doesn't work.

http://pastebin.com/0kR0NrTQ

*I am using pollEvent in the engine that is suppose to set mouserepeat to false
« Last Edit: March 02, 2016, 03:22:32 pm by xzazer »

ast

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Bouncing Projectile
« Reply #1 on: March 05, 2016, 09:41:12 pm »
This seems pretty much a problem in the internal logic of your program and not so much related to SFML or any external parts. Solving these and get the code work is petty much the fun factor in programming  ;). I would suggest you to work little bit on the problematic area to gain more information on what is going on and where it goes differently than you'd think it should. Debugger might help or some debug code that print things on the console or draw additional things on the screen.

It is pretty difficult for anyone else to solve the problem without deeply diving into what internal logic you are trying to implement. Others most probably would like to implement the whole thing slightly differently.

Best regards,
ast

Tigre Pablito

  • Full Member
  • ***
  • Posts: 226
    • View Profile
    • Email
Re: Bouncing Projectile
« Reply #2 on: March 19, 2016, 04:08:43 pm »
Hi
I think you should program the enemies to be destroyed (or whatever you want, explosion, etc.) when the projectile reaches them, and also the projectile to disappear ...

[ The projectile is not bouncing when it hits the edges of the screen but it fires automatically if that happens. So I need help making it so that clicking the mouse while its active doesn't work. ]

I don't know if i understand Ok ... you want the projectile to bound on the edges? And it fires (from start) when it hits the edges? And you can fire while the projectile is active and you shouldn't?

What it seems is that, inside the main loop, the projectile is launched whenever it's not active (i.e., when it hits the edges), and if you click when it's active it is reseted ...
I would suggest 1) to create a matrix or a List if you want many projectiles to be at the same time, 2) to check, for firing a new one, that mouse button is released when you press it and the current number (index) is lower that the maximum projectiles there can be (or if you want just one, that it is not active when you press the button to be able to fire), 3) if you want them to bounce on the edges, then you have to detect when they hit, and change the angle as (180 - angle) if they hit the side edges

Perhaps i would be able to help better if you can explain with a bit more detail what it is about and what you want  :)

 

anything