When I was 9 years old, I got really bored one day and decided to draw up a video game that I wanted to make someday called Undersea Adventure. It involves catching fish with bubbles, battling various sea creatures (crabs, etc) and upgrading your ship to contain more bubble cannons and such. I have gotten the engine running and I can move and rotate a ship, shoot a bubble, and catch a fish. However, the aiming for the bubble is inaccurate (it's gives it a trajectory if it's in a certain range), and I want to make the bubble travel on a path determined by the location of the ship and the mouse. Here is my code for aiming currently:
Code:
b1x is the ΔX and b1y is the ΔYfor the bubble. Here is the bubble movement code:
Code:
I am trying to make an algorithm that makes the bubble travel directly toward where the mouse was when it was fired and travel at roughly the same speed in any direction. Any ideas?
Code:
if sum(mousePressed) > 0 and ticks-bubbleDelay>bubbleDelayAmount/shooters:
bubble1 = True
bubbleX1 = shipX-12
bubbleY1 = shipY-12
slope = 0
b1x = 0
b1y = 0
if not(mousePos[0] == shipX):
slope = (mousePos[1]-shipY)/(mousePos[0]-shipX)
if abs(slope) < 0.3:
b1x = 6
b1y = 0
elif abs(slope) < 1:
b1x = 5
b1y = 2.5
elif abs(slope) < 2:
b1x = 3.2
b1y = 3.2
elif abs(slope) < 4:
b1x = 2.5
b1y = 5
else:
b1x = 0
b1y = 6
if mousePos[1] < shipY:
b1y *= -1
if mousePos[0] < shipX:
b1x *= -1
bubbleDelay = ticks
b1x is the ΔX and b1y is the ΔYfor the bubble. Here is the bubble movement code:
Code:
if bubble1:
bubbleX1 += b1x
bubbleY1 += b1y
I am trying to make an algorithm that makes the bubble travel directly toward where the mouse was when it was fired and travel at roughly the same speed in any direction. Any ideas?