Retrogamecoding(.org) > General game development

Rotate and fire

(1/4) > >>

johnno56:
I use qb64 and sdlbasic and need help with an Asteroids-type game. I do not need the game to be written for me... I need help with rotating the ship and firing in the direction it is facing. Much appreciated.

J

B+:
Is the ship drawn or an image?

johnno56:
No ship yet. Concept level only. If the rotating is too difficult or can't be done then there is little point in getting it "off the drawing board"... lol

But I'm not too fussed. Drawn or loaded. I don't know the math behind rotating a sprite or rotating a polygon. Math was NOT my best subject... lol  I am open to suggestion...

J

B+:
For QB64 image rotation:
https://www.qb64.org/forum/index.php?topic=278.msg1617;topicseen#msg1617

also stretching or compressing or zooming, all in one with Rotozoom. (Come to think of it, the separate scale for x and y doesn't always work but if just rotating image then all set.

B+:
Say the ship is pointed at some angle A and assuming projectiles will go the way the ship is pointed at moment of fire then

newProjectileX = lastProjectileX + speed * cos(shipAngle)
newProjectileY = lastProjectileY + speed * sin(shipAngle)

shipAngle usually needs to be in Radian units. If in degrees, then multiply by pi/180 to convert degrees units to radian units.

keep updating the projectile until it hits its target (and explodes) or it goes off screen.