# Retrogamecoding and Basicprogramming Forum

## Retrogamecoding(.org) => General game development => Topic started by: johnno56 on 12. July 2018, 02:30:35

Title: Rotate and fire
Post by: johnno56 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
Title: Re: Rotate and fire
Post by: B+ on 13. July 2018, 02:18:54
Is the ship drawn or an image?
Title: Re: Rotate and fire
Post by: johnno56 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
Title: Re: Rotate and fire
Post by: B+ 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.
Title: Re: Rotate and fire
Post by: B+ 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.
Title: Re: Rotate and fire
Post by: johnno56 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
Title: Re: Rotate and fire
Post by: ZXDunny 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.
Title: Re: Rotate and fire
Post by: johnno56 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
Title: Re: Rotate and fire
Post by: ScriptBasic 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.
Title: Re: Rotate and fire
Post by: johnno56 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
Title: Re: Rotate and fire
Post by: B+ 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:
A platform game tutorial!
Title: Re: Rotate and fire
Post by: johnno56 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
Title: Re: Rotate and fire
Post by: ScriptBasic on 14. July 2018, 19:52:26
NaaLaa just released its Linux version that runs great on my Ubuntu 64 bit environment.
Title: Re: Rotate and fire
Post by: johnno56 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
Title: Re: Rotate and fire
Post by: ScriptBasic 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.
Title: Re: Rotate and fire
Post by: johnno56 on 14. July 2018, 23:50:12
Ha. Lurking. I'm a pro at that. Not much else mind you... lol

J
Title: Re: Rotate and fire
Post by: ZXDunny on 15. July 2018, 11:28:20
I think  that these days pre-calculation reduces workload on the CPU (though as you rightly point out, a simple retro-style game might not need it) and that is important in these days of reduced energy usage. Many mobile platforms means that battery life is king - even in Windows, where I have a couple of handheld devices that directly benefit from optimisation to keep battery life as long as possible.