Author Topic: Rotate and fire  (Read 5450 times)

johnno56

  • Guest
Rotate and fire
« on: July 12, 2018, 12:30:35 AM »
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+

  • Guest
Re: Rotate and fire
« Reply #1 on: July 13, 2018, 12:18:54 AM »
Is the ship drawn or an image?

johnno56

  • Guest
Re: Rotate and fire
« Reply #2 on: July 13, 2018, 01:34:08 AM »
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+

  • Guest
Re: Rotate and fire
« Reply #3 on: July 13, 2018, 01:17:50 PM »
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: July 13, 2018, 01:20:15 PM by B+ »

B+

  • Guest
Re: Rotate and fire
« Reply #4 on: July 13, 2018, 01:55:10 PM »
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

  • Guest
Re: Rotate and fire
« Reply #5 on: July 13, 2018, 03:20:10 PM »
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

ZXDunny

  • Guest
Re: Rotate and fire
« Reply #6 on: July 13, 2018, 04:02:31 PM »
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

  • Guest
Re: Rotate and fire
« Reply #7 on: July 13, 2018, 11:33:48 PM »
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

ScriptBasic

  • Guest
Re: Rotate and fire
« Reply #8 on: July 14, 2018, 01:48:40 AM »
Have you tried NaaLaa? It is the perfect language for what your after. The author is a commercial game developer in real life.

johnno56

  • Guest
Re: Rotate and fire
« Reply #9 on: July 14, 2018, 06:28:55 AM »
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

B+

  • Guest
Re: Rotate and fire
« Reply #10 on: July 14, 2018, 01:29:32 PM »
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: July 14, 2018, 01:33:37 PM by B+ »

johnno56

  • Guest
Re: Rotate and fire
« Reply #11 on: July 14, 2018, 01:58:21 PM »
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

ScriptBasic

  • Guest
Re: Rotate and fire
« Reply #12 on: July 14, 2018, 05:52:26 PM »
NaaLaa just released its Linux version that runs great on my Ubuntu 64 bit environment.

johnno56

  • Guest
Re: Rotate and fire
« Reply #13 on: July 14, 2018, 08:35:40 PM »
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

ScriptBasic

  • Guest
Re: Rotate and fire
« Reply #14 on: July 14, 2018, 09:20:36 PM »
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.