Author Topic: Rotate and fire  (Read 131 times)

johnno56

  • Newcomer
  • *
  • Posts: 33
  • Logic is the beginning of Wisdom.
    • View Profile
Rotate and fire
« on: 12. July 2018, 02:30:35 »
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
May your journey be free of incident.

Live long and prosper.

B+

  • Hero Member
  • *****
  • Posts: 534
    • View Profile
Re: Rotate and fire
« Reply #1 on: 13. July 2018, 02:18:54 »
Is the ship drawn or an image?

johnno56

  • Newcomer
  • *
  • Posts: 33
  • Logic is the beginning of Wisdom.
    • View Profile
Re: Rotate and fire
« Reply #2 on: 13. July 2018, 03:34:08 »
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
May your journey be free of incident.

Live long and prosper.

B+

  • Hero Member
  • *****
  • Posts: 534
    • View Profile
Re: Rotate and fire
« Reply #3 on: 13. July 2018, 15:17:50 »
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.
« Last Edit: 13. July 2018, 15:20:15 by B+ »

B+

  • Hero Member
  • *****
  • Posts: 534
    • View Profile
Re: Rotate and fire
« Reply #4 on: 13. July 2018, 15:55:10 »
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.

johnno56

  • Newcomer
  • *
  • Posts: 33
  • Logic is the beginning of Wisdom.
    • View Profile
Re: Rotate and fire
« Reply #5 on: 13. July 2018, 17:20:10 »
This looks interesting! But I have to get some sleep first... Will attempt a test some time later this morning... Many thanks for the code snippet.

J
May your journey be free of incident.

Live long and prosper.

ZXDunny

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: Rotate and fire
« Reply #6 on: 13. July 2018, 18:02:31 »
In general you want to avoid performing trig during loops, so pre-calculate your dx/dy for the projectile when the user presses fire and use those to update its position for its lifespan.

johnno56

  • Newcomer
  • *
  • Posts: 33
  • Logic is the beginning of Wisdom.
    • View Profile
Re: Rotate and fire
« Reply #7 on: 14. July 2018, 01:33:48 »
I agree with 'pre calculate', instead of 'on the fly', as a good practice to adopt. But, my question would be, why? "Back in the day" (and they never say which day... lol) I can understand the reasons. Slower processors to laboriously use trig calculations would tend to 'slow things down'. But what about today? Processor speeds have increased by leaps and bounds and memory storage has gone through the roof. I can see where pre-calc would be beneficial when it comes to a game that is heavy in number crunching (3D'ish type games) but for a game that is, by all intent and measure, a 'retro-style' game? I would be curious as to whether or not there would be a "savings" on machine load... Just a thought... I think of stuff like that from time to time... lol

J
May your journey be free of incident.

Live long and prosper.

John

  • Sr. Member
  • ****
  • Posts: 402
    • View Profile
Re: Rotate and fire
« Reply #8 on: 14. July 2018, 03:48:40 »
Have you tried NaaLaa? It is the perfect language for what your after. The author is a commercial game developer in real life.

johnno56

  • Newcomer
  • *
  • Posts: 33
  • Logic is the beginning of Wisdom.
    • View Profile
Re: Rotate and fire
« Reply #9 on: 14. July 2018, 08:28:55 »
I most certainly have... Great bunch of guys there... Very helpful... I even have the Linux version installed. Now that you mention it, I must pay them a visit... But, living on the other side of the planet, makes discussions stretch out... lol  Thanks for the suggestion. Much appreciated.

J
May your journey be free of incident.

Live long and prosper.

B+

  • Hero Member
  • *****
  • Posts: 534
    • View Profile
Re: Rotate and fire
« Reply #10 on: 14. July 2018, 15:29:32 »
http://www.naalaa.com/community/index.php

Hey looks like new forum site!  :)

Is Marcus back this time? ;)

Johnno have you seen this:
https://www.youtube.com/watch?v=T4R8n9URiWU
A platform game tutorial!
« Last Edit: 14. July 2018, 15:33:37 by B+ »

johnno56

  • Newcomer
  • *
  • Posts: 33
  • Logic is the beginning of Wisdom.
    • View Profile
Re: Rotate and fire
« Reply #11 on: 14. July 2018, 15:58:21 »
That site's been up for a while now. Visit several times per day just to see what's going on. In regards to Marcus, to tell you the truth, I haven't been looking out for him. It's not that I don't want to, it's just that I haven't had the need to contact him...

In regards to the tutorial... That was using Gimp 2.6 for the graphics and yes, that one I completed a long time ago. It was very well made and even easy enough for ME to follow... lol

I have been researching platform tutorials and have little to no luck when it comes to basic. Pete's qbasic website has a lot of tutorials, some on platformers, but they are far from complete in the sense of producing a game... Some are too short. Some are as old as dirt. I haven't gone through all of them yet, so there may be a glimmer of light at the end of the tunnel.

I have been too tired to work on the sdlbasic platformer... We had our early morning fruit and veg marketing this morning (6am) and my only coffee has stopped working... Running on fumes...

I have even tried Game Maker and the Linux version LateralGM. Game Maker runs through Wine and does not behave itself all the time and LateralGM, although it says it's GM compatible, isn't quite 100% correct...

I am quickly running out of options in the area of game making on Linux.Most stuff is catering for Windblows and usually costs some outright payment of regular fee to eventually produce a game. I'm not even going down the 'learning curve' path, it makes my head ache, just thinking about it. I'll keep chipping away with Basic for now... but the time will come when the limitations of Basic will determine what games we make and our imaginations will end up falling in line... *sigh*

It's almost midnight and I've been up since 5:30am and struggling to type. I'm off to bed. Have a great day.

J
May your journey be free of incident.

Live long and prosper.

John

  • Sr. Member
  • ****
  • Posts: 402
    • View Profile
Re: Rotate and fire
« Reply #12 on: 14. July 2018, 19:52:26 »
NaaLaa just released its Linux version that runs great on my Ubuntu 64 bit environment.

johnno56

  • Newcomer
  • *
  • Posts: 33
  • Logic is the beginning of Wisdom.
    • View Profile
Re: Rotate and fire
« Reply #13 on: 14. July 2018, 22:35:40 »
I use the 64 bit version of Linux Mint, and likewise, Naalaa runs flawlessly. I can't say the same about my ability (or inability) to program... lol

J
May your journey be free of incident.

Live long and prosper.

John

  • Sr. Member
  • ****
  • Posts: 402
    • View Profile
Re: Rotate and fire
« Reply #14 on: 14. July 2018, 23:20:36 »
If game programming was my thing, I'm sure I would be having a blast with NaaLaa. I tend to be just a lurker and supporter on the AllBASIC forum.