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.

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 31st Mar 2015 21:20
Hi.

I wrote a code for my enemy that can shoot to player. but I want enemy shoot randomly, for this work I used Random Command but shooting is not Random.

Please Guide Me.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 31st Mar 2015 21:45
If you are calling this every loop then the "Random" element is pretty much lost. You need to set the time each enemy will next fire their weapon and then only fire once that time has passed. I normally store enemy data in a UDT array like this:


Then loop through like this:


Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 31st Mar 2015 22:13 Edited at: 31st Mar 2015 22:14
what is Fire(enemy(i).spr)?
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 1st Apr 2015 09:14
It is a call to a function that fires the bullet.
The function doesn't exist because it is just an example of how to do it. You will need to write the bullet firing function yourself because that is specific to your game.

AGK V2 user - Tier 1 & 2
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Apr 2015 10:36
Quote: "It is a call to a function that fires the bullet.
The function doesn't exist because it is just an example of how to do it. You will need to write the bullet firing function yourself because that is specific to your game."

Exactly.

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 1st Apr 2015 10:51
I Trying to guess should use EnemyBullet() function but it don't work.
is there better way without create several enemy[x] for each enemy?
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 1st Apr 2015 13:05 Edited at: 1st Apr 2015 13:55
@baxslash

I compound my code with your code and create this code and seem enemy shoot randomly. please see and tell this way is correct or no? is there better way?



and this is my full code:




UPDATE: this is above code with little different that there is 10 enemies and I want randomly fire them, but after compile give me an error, please tell me where is the problem?

Problem is relate to below code and when I changed Enemy to Enemy(x).



this is full code:



Thanks
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Apr 2015 14:37
Quote: "UPDATE: this is above code with little different that there is 10 enemies and I want randomly fire them, but after compile give me an error, please tell me where is the problem?"

What is the compiler error? Sorry I don't have much time today. Compiler errors are usually pretty self-explanatory but if you tell me what it says I'll explain it to you.

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 1st Apr 2015 14:50
Quote: "Sorry I don't have much time today."


Ok, I find Problem. but another problem is only one enemy shoot bullet and others don't shoot.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Apr 2015 16:55
Ok, I took a look and tried to tidy things up a bit so they made sense to me. The main problem was that you were putting the position code in a loop which caused it to always be put on the last enemy:

Really what you want is an individual timer for each enemy so that when there are more enemies you get shot at more (like in real life). I made some basic changes that you can take a look at here:

You aren't far off, you just need to understand why this is working and your version wasn't. Keep it up, this is starting to look like a game

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 1st Apr 2015 18:32
Thanks baxslash now work good. I think understood all thing but if there is any problem I ask you.

Quote: "Keep it up, this is starting to look like a game "


yes, I created two game with AppGameKit and I decided create hardest games for more familiar with AGK.

you can see my games from below links:

http://cafebazaar.ir/developer/behdadgames/?l=en

really I learned Many things from you and other users and I hope learn more.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 1st Apr 2015 19:20
I don't know what the app is like but you need to get someone who speaks English to read through your description for "Learn English for Kids"... the English is terrible.

Here's a better translation
Quote: "'Learn English for Kids' is an application designed for all ages. This application has 8 categories:

1- Alphabet
2- Numbers
3- Colors
4- Shapes
5- Animals
6- Fruits
7- Vegetables
8- Vehicles

Thank you.""

I would personally change it more than that but I just put a better translation of what you already have.

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 1st Apr 2015 19:45
Quote: "
I don't know what the app is like but you need to get someone who speaks English to read through your description for "Learn English for Kids"... the English is terrible.

Here's a better translation
Quote: "'Learn English for Kids' is an application designed for all ages. This application has 8 categories:

1- Alphabet
2- Numbers
3- Colors
4- Shapes
5- Animals
6- Fruits
7- Vegetables
8- Vehicles

Thank you.""
I would personally change it more than that but I just put a better translation of what you already have."


I fixed it.

Thanks baxslash for translate.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 7th May 2015 20:55
Hi baxslash.

I wrote another code enemies and used random fire for them. but there is an problem when enemies fire to player.
I want when WorldToScreenX(GetSpriteX(enemy)) <= 60 then fire to player but my code don't work good. mean sometimes when there is no any enemy at screen, random fire code still work.for better understand run my code.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th May 2015 21:27
new explanation:

I created a new sample game that enemies can randomly shoot to player.for shoot I define a location for enemies with below code:



mean when enemy.x is less or equal 60, then enemies shoot to player.
now there is a problem:

above rule not work good.mean enemies can shoot to player even are out of screen (In other words, even when enemy.x is great that 60, can shoot to player.)



Thanks.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th May 2015 13:39
Try adding another rule that stops sprites that are off screen from firing? Ie: less than zero...

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 9th May 2015 18:37
Quote: "Try adding another rule that stops sprites that are off screen from firing? Ie: less than zero..."


yes, I tried change rule to less than zero but this problem is still there.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 9th May 2015 20:50
How did you do it? It should work...

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 10th May 2015 19:13 Edited at: 10th May 2015 20:41
I add use this code but don't work:

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 10th May 2015 23:40
Well you aren't checking for an X value of less than zero here...

You need to think about what condition you don't want the enemy to fire under and check for that. What is the precise condition where you want them to not fire?

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 11th May 2015 06:54
Quote: "What is the precise condition where you want them to not fire?"


I want when if WorldtoScreenX(GetSPriteX(enemy[x])) > 60, them to not fire.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 11th May 2015 09:44
Oh I think I get it now. Your CreateEnemyBullet function is not firing for the correct enemy. You need to make sure this function is using the correct enemy not just any enemy as it currently does.

Using AppGameKit V2 Tier 1
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 11th May 2015 14:18
ok, I try it.

Login to post a reply

Server time is: 2024-04-24 03:35:39
Your offset time is: 2024-04-24 03:35:39