26 January 2020, 16:41 | #1 |
Registered User
Join Date: Oct 2015
Location: Landsberg / Germany
Posts: 526
|
Bullet controller in Shmup-game
After some constructive feedback to the last video of my forthcoming shmup RESHOOT PROXIMA 3, I decided to totally ditch the existing bullet control code and try something new; aim for code which allows much more control of bullet objects at launchtime.
As I am a mathematical dyslexic, I wonder if anyone wants to share some kind of algo. I will then use this algo to develop code which is able to - launch an object towards a set position - adjust precision - adjust angle - adjust speed Object controller uses a 2d world with conventional x and y coords, x and y stored within longwords (upper 16 bits define worldcoord, lower 16 bits define subpixel coord). Efficiency rules, so no divs and muls at all; or only at launch. Any suggestions much appreciated! |
26 January 2020, 18:42 | #2 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
The obvious answer would be "Bresenham", which works without any multiplications and divisions. But how were you doing it before?
In Black Strawberry Cake I'm using such aimed missiles in the world 2 boss fight (monster.asm/newAimedMissile). I'm using a lookup table with 64 entries in x- and y-direction with values between 0.0 and 1.0. The stored format is 1.7 bits, which is sufficient. So you only have to normalize your dx and dy, by shifting both values right at the same time, until both are less than 64. Then read the gradient from the table, which you can add in each step to the missile movement. See also here: http://eab.abime.net/showpost.php?p=...5&postcount=14 ...which includes the C source to generate the table. |
26 January 2020, 23:39 | #3 |
Registered User
Join Date: Oct 2015
Location: Landsberg / Germany
Posts: 526
|
Bresenham does not work for me, for the same reasons that you mention in your thread. So far I am using a forced vector approach, by calculating dx and dy first and do some simple bitshifts to get x- and y-acceleration at launch. These two values are just added to x- and y-coords the following frames, so hardly any extra calculation is needed. Works fine, but is not versatile at all; for example acceleration of bullets cannot be controlled. Maybe I have to re-visit my code.
I will also try the table approach, as it seems to work pretty well in your game. Thanks a lot! |
27 January 2020, 01:10 | #4 | |
Registered User
Join Date: Jan 2019
Location: Brisbane
Posts: 99
|
Quote:
For the acceleration, you are able to fudge it along with the dx/dy approach. Since you are storing your coords in 32bit with upper 16 bits as world, and lower as remainder its even easier. Caveat is that you would need to store your dx/dy along with each bullet object (so that each bullet can have its own current speed state) also in your same fixed point format. When firing a bullet, copy the initial deltas to your bullet object, then each frame or whenever add your acceleration in the same fixed point format equally values to each of the dx/dy. Adding equally keeps the bullet firing straight in the existing direction. You can add with unequal values to increase/decrease the acceleration on either axis. Psuedo would look something like: Code:
onShoot: bullet_deltax = tablex[index] bullet_deltay = tabley[index] for each frame: add.l bullet_deltax,bullet_posx add.l bullet_deltay,bullet_posy add.l acceleration,bullet_deltax add.l acceleration,bullet_deltay Acceleration as 32768 would increase objects dx by 1/2 pixel each frame... and so forth. You are using pretty high precision so you have good control. Of course in this you need to add.l not add.w because your format is 32bit. I also use 32bit fixed point, its simple to swap, and deref each word separately. Wish there was a swap.w on 68k. |
|
28 January 2020, 10:02 | #5 |
Registered User
Join Date: Oct 2015
Location: Landsberg / Germany
Posts: 526
|
@Auscoder: Thank you for your input. It does work, in fact that´s what my code did already. Unfortunately, with this method, speed of bullets depends on spawn-target-distance, which is not desired.
@PHX: You inspired me to finally adress compiling c- and assembler-code using VASM. The makefile for compiling your C-code on Mac looks something like this: Code:
gcc $AMIDEV/source/createBulletVectorTable.c -o $AMIDEV/source/bulletVectorTable.exe #compile chmod +x $AMIDEV/bulletVectorTable.exe #is executable $AMIDEV/bulletVectorTable.exe 64 $AMIDEV/bulletVectorTable #create table with [64] entries on x- and y-axis |
28 January 2020, 10:03 | #6 |
Inviyya Dude!
Join Date: Sep 2016
Location: Amiga Island
Posts: 2,770
|
Also you can do this a lot less complicated with simple bit shifts..
|
28 January 2020, 13:24 | #7 |
Registered User
Join Date: Jan 2019
Location: Brisbane
Posts: 99
|
Yes great, normalized delta's are key here. I guess the table you are now generating is providing those to you. I will have to do this, as I am calculating normalized vector each time a tracking bullet spawns
Last edited by Auscoder; 28 January 2020 at 13:24. Reason: Formatting |
28 January 2020, 13:25 | #8 |
Registered User
Join Date: Jan 2019
Location: Brisbane
Posts: 99
|
|
29 January 2020, 11:35 | #9 |
Registered User
Join Date: Jun 2016
Location: UK
Posts: 428
|
If you want to trade memory for speed then the fastest option is to use lookup tables. They have the additional advantage of being able to control accuracy.
You can just have a very simple bounded x/y relative lookup using low resolution coordinates, say 16x16 blocks because then you can avoid shifts. |
29 January 2020, 12:40 | #10 | |
Registered User
Join Date: Jun 2015
Location: Germany
Posts: 1,918
|
Quote:
EDIT: I just realised that this is exactly what you were referring to. Sorry! |
|
29 January 2020, 12:52 | #11 |
Registered User
Join Date: Oct 2015
Location: Landsberg / Germany
Posts: 526
|
Quick update: I implemented the lookup table approach that phx suggested - thanks a lot for this, phx! The modified approach only eats up additional 8k, ends up with fast and versatile code, and works nicely. Sharing some thoughts and a short video on my Patreon-page. Feel free to read and have a look!
Will share code here as soon as I´ve cleaned it up a bit. Last edited by buzzybee; 29 January 2020 at 14:10. Reason: Link did not work as intended |
29 January 2020, 13:38 | #12 |
Registered User
Join Date: Jul 2014
Location: Warsaw/Poland
Posts: 171
|
looks promising
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
32 color shmup demo | Master484 | Coders. Blitz Basic | 68 | 01 March 2019 17:03 |
[Found: X-Out] Looking for insect shmup | Kitty | Looking for a game name ? | 12 | 17 March 2010 21:44 |
New ShMUp, help required | Marcuz | project.Amiga Game Factory | 3 | 28 June 2007 09:49 |
Nanostray: Cool GB DS Shmup | ST Dragon | Retrogaming General Discussion | 19 | 23 March 2005 03:10 |
Cloudphobia (shmup) | Dastardly | Retrogaming General Discussion | 0 | 07 November 2003 16:53 |
|
|