Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Creating an explosion, where is "shrapnel3.png"?

Author
Message
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 21st Feb 2014 12:21
I am having trouble including explosions and consulted AppGameKit examples, Creating an explosion. This example states, "This example program relies on an external image named "shrapnel3.png":".

Unfortunately, I can't find shrapnel3.png. Its probably obvious where to find it and I'm just being silly but thats me. I can get a not bad explosion using any old png but it might be better with the correct one.

Does anybody know where to find shrapnell3.png or know of a really simple way to create a short explosion?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Feb 2014 17:50
C:\Program Files (x86)\The Game Creators\AGK\Projects\Basic\Examples\Particles\Explosion\

Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 21st Feb 2014 18:15
Thanks Phaelax,

I really do feel particularly thick, but also so pleased. I realise that the program files were installed when I downloaded AppGameKit but to me, whose brain was switched off, it looks as if you magically scanned my PC. Brain restarted now, thank you.
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 21st Feb 2014 19:49
Rob....

"Shrapnel3.png" is in "myleg2.png" LOL (well it is Friday)

www.bitmanip.com
All the juicy you could ever dream of!
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 22nd Feb 2014 19:09
Well I now have my explosions destroying the correct target and it looks good. However, and this is not too important, all the other targets stop flying around the screen while the explosion takes place.

Is there any way to have the explosion destroy the correct target but allow the incorrect targets to continue to bounce around the screen?

Perfection is not necessary but it is nice
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 22nd Feb 2014 19:35
The example for creating an explosion doesn't have anything else on screen, so I am assuming you have added stuff.

Can you post the code you have so far.
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 22nd Feb 2014 22:44
Thanks Marl. I've already used the text that you have in your Code Snippet and it is working quite well. I would gladly post my program code but the program is 792 lines long. Is this too long to post?

If I do ever want to post code do I just click the code button, paste in the code and do I then press the code button again?
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 23rd Feb 2014 02:08 Edited at: 23rd Feb 2014 02:08
Pretty much.

I posted the code straight from the example, kind of to see if that is the example you were using or if you'd found a different one.

So back to your previous question
Quote: "Is there any way to have the explosion destroy the correct target but allow the incorrect targets to continue to bounce around the screen?"

Yes, there are lot of ways, but it depends on how you've coded the rest ( hence why I asked for code ).

Simply presenting an example might not help as you may do things very differently.

To use the example, that runs a loop continually and enables or disables the ability to create a new explosion using an IF statement which checks GetParticlesMaxReached().

In other words The loop is gong around and around doing nothing but waiting for the previous animation to finish.

There is no "Wait" point so there is nothing to stop the rest of the loop moving objects around. Since the loop is running all the time, they wouldn't stop while the explosion is occurring.

So the question has to be, why does yours?

It is possibly because you've come from a traditional BASIC background, in a lot of versions, the program does something and then waits for the user to respond.

AGK is designed primarily for games (I know some would say not, but c'mon just look at the command set - it's not a database language ) it is important to keep things moving, this is why the screen display is reset every frame - unlike "traditional" BASIC where you print something and it stays.

If the program just stopped on the spot and waited for the user, the sync() command would not be called and the screen would not be updated. This in turn would be seen by the system as a hang state and reported as a fault.

So while the people on here will have many ideas on how to answer the question, which one will suits your program will depend on what you do already.

Does that make sense?
29 games
19
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 23rd Feb 2014 04:08
Quote: "is 792 lines long"

Shouldn't be a problem, I've posted 1600 before now.

Quote: "If I do ever want to post code do I just click the code button, paste in the code and do I then press the code button again?"


I paste my code in, highlight it then click the code button but apparently your way also works (I never knew that) or you can just type the code tags in.

Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 23rd Feb 2014 11:45
OK, here goes. I don't think I've ever posted any code before! The zipped media folder is included as an attachment.

The explode function starts at line 38 and it is called from line 637. Feel free to criticise the code. It was written just as additions to additions to additions to AppGameKit beginner's code with no proper planning. I did write in DarkBASIC (Classic) in 2003/4/5/6ish so that is indeed where I am coming from.

Attachments

Login to view attachments
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 23rd Feb 2014 12:51
The first thing I notice is that you have a lot of repetition of code. this could be reduced by making small functions to do what the repeating blocks do.

For example, the block;

Is doing the same thing but with slightly different values. This could be replace with something like;

by having an additional function to do the repetition;

The functionality of the program is unchanged, we have simply offloaded the repeating code to a function, passing the differences as parameters. There are a couple of "tweaks" for colour, for the exceptions to the rule.

I appreciate this doesn't answer the original question, but I thought it might be an idea to get the code a little more manageable first. Following through the logic of the code will be much easier without the distraction of all those repeating blocks.

If you like this idea, have a look yourself at blocks such as


Before you know it, the code will be a quarter of the original size.
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 23rd Feb 2014 13:13
Thanks Marl. This is just the kind of criticism I had hoped for. I'll make a copy of my program, just in case, and get to work on carrying out your suggestions. You are a lot quicker at reading and understanding the program than I am, and I wrote it

I'll take a while but, I'll get there.
Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 23rd Feb 2014 18:32
You have sync() all over the code, with many loops. Try only having 1 sync() command, and have it in your main loop, then use flag variables, to tell the functions what steps to take, so that everything runs one step further every loop. If you suddenly starts an explosion loop, everything else has to wait for that one to end, before they can move on... This is called "blocking code" style.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 23rd Feb 2014 19:49
I've always had trouble with sync()and when a program didn't run I'd pop in a sync(). If that solved the immediate problem it would stay there. When I added more code it sometimes wouldn't run properly and I'd drop in another sync(). I never removed sync()s that helped, so they just grew and grew.

When I learned to program many years ago I would write short, simple programs to do a set task, find a prime number, perfect number, etc. With AppGameKit I started off with a simple program and, when I got it to work, I'd add another bit so my programs just grew without any planning or proper repair work. With help, I will be able to repair my past attempts and do a bit more planning on my future projects. Thanks.
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 24th Feb 2014 15:03
I counted and actually had 9 sync()s in the program. I removed 5 of them and it still runs. The remaining 4 caused the program to stall but at least I've made a start.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 24th Feb 2014 19:05 Edited at: 24th Feb 2014 19:13
I had a quiet day, so took the liberty of hacking about with your code to get rid of some of the larger chunks of repetitions. This does not change any of the functionality.

As well as the changes above, I have added a user defined type array to replace your individual sprite and text definitions (sprite0 to sprite9 and text0 to text9).

All the relevant code has been modified to use the array rather than the globals, also the use of an array has allowed some of the routines to be put in loops.

Have a look and you should get an idea of how this works, if not, I'm happy to help out with any questions.

I've commented out the blocks which were replaced, but left them, in for reference.


I've also attached the main.agc to save the massive copy/paste.

Edit: With commented out code removed, it is down to 600 lines.

Attachments

Login to view attachments
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 24th Feb 2014 20:33
To me that looks like a lot of work that you have put in, Marl, and I appreciate it. This morning after getting rid of 5 of my sync() calls I had replaced my huge "`print top two lines of choosetables page" paragraph with your much shorter snippet and your function, and I was very impressed. It was much shorter and worked exactly like my original verbose version.

I read through my program with a view to carrying out the homework that you had assigned and decided that I'd tackle that tomorrow! (typical student). Then your rewritten, much improved version of my program arrived.

I feel that I should explain some thing about me. I am a retired teacher who was diagnosed with multiple sclerosis (MS) 23 years ago. I am not trying to improve my programming to boost my career prospects or to start an app business. My main reason is simply to keep my mind going.

I had written some DarkBASIC programs years ago and published them as freeware. My daughter who teaches primary children asked me to write an app version of some of my arithmetic programs.

I am happy to be given advice and will follow your suggestions but the MS will sometimes slow me down and force me to rest.

It is evening here and too late to put much effort but I'll install your version start learning. Thanks and keep on teaching.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 25th Feb 2014 13:45
Quote: "To me that looks like a lot of work that you have put in, Marl"

It was about an hour's work and I was happy to do it. The most time consuming part was adding all the comment bars (//) to the lines

After my last post, I realized that some of the changes I suggested might need a bit more work than simply popping in a function.

The fact that you use sprites and text in pairs (for example) could end up messy with multiple functions, so I decided to give you an example of how to combine the two using a UDT array.

Importantly, I didn't change the mechanics of the code - it still operates in exactly the same way although structured differently. Perhaps the best way to describe it is that I advised on your programming style rather than your technique.

While I could have redone more of it, that would be of no benefit to you, I just took a swing at one of the big bits to get you started.
Quote: "I am happy to be given advice and will follow your suggestions but the MS will sometimes slow me down and force me to rest."
Take all the time you need, it's not a race after all and these things can't be rushed.

I also use programming to keep my mind active. If I hit a dull spot in my own projects, I will often break off and look at little problems like this for a bit of a change - it keeps things fresh and keeps me interested.

So we're both getting something out of it.

Login to post a reply

Server time is: 2024-11-25 03:04:13
Your offset time is: 2024-11-25 03:04:13