Retrogamecoding(.org) > General game development

Rotate and fire

(1/4) > >>

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.


Is the ship drawn or an image?

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...


For QB64 image rotation:;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.

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.


[0] Message Index

[#] Next page

Go to full version