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.

Newcomers AppGameKit Corner / [QUESTION] Creating waves of enemies with arrays or external file

Author
Message
Stupinator
8
Years of Service
User Offline
Joined: 14th Sep 2015
Location: Vancouver, WA, USA
Posted: 14th Sep 2015 23:29
So here's the dealio: I'm working on a top-down 2d shooter, arcade-ish style. I need to implement a simple way of creating waves.

I thought about doing arrays, but there would need to be two per wave, or a good way of parsing different array parts to different things (first number does this, second number does this, third does same as first, fourth does same as second, etc. etc.) Same issue with an external file.

Simply put: I need a way to make 0 1 0 1 to mean 0 is the enemy type, 1 is the amount of time before spawning the next enemy.

any thoughts?

-Stupinator
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 15th Sep 2015 10:59
2 Arrays and 2 Types

Something like this...



Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Stupinator
8
Years of Service
User Offline
Joined: 14th Sep 2015
Location: Vancouver, WA, USA
Posted: 15th Sep 2015 16:16 Edited at: 17th Sep 2015 02:26
Brilliant! Now to go find that tutorial you mentioned in the other thread.

Why the heck didn't I think of using an array inside an array... I've done that so many times...

Brain wasn't braining I suppose.

Also, I'm assuming you meant twave instead I A integer.

-Stupinator
Stupinator
8
Years of Service
User Offline
Joined: 14th Sep 2015
Location: Vancouver, WA, USA
Posted: 17th Sep 2015 03:39
Well here's what I got so far:




not quite working, was going to use for loops, but that wouldn't allow me to spawn them by a time variable. any thoughts?

-Stupinator
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Sep 2015 10:58
I'm not sure what isn't working? I see it creating a sprite every second.

It would be a good idea to incorporate some of the variables into your wave type. This will make them more autonomous and later on you can start to add variation such as different spawn times and different appearance times for each wave:

startTime - to allow differing start times rather than just one after the other. It also allows you to check the interval between enemy spawns more accurately against a base starting time.

lastSpawn - the element number of the last spawned enemy in this wave. Allows you to track the last enemy in each specific wave, giving you the freedom to have multiple waves spawning enemies at the same time.

nextSpawnTime - this is a performance thing. At the end of each spawn, calculate the time of the next one. Then you are not calculating this time every cycle, you can just compare timer() to this value.


Now, you can:

. Loop through Waves and check startTime. If < timer():
. . Check nextSpawnTime and if < timer():
. . . Spawn enemy
. . . Set nextSpawnTime
. . . If all enemies spawned, set startTime to 99999999 so that it is ignored in spawn function.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Stupinator
8
Years of Service
User Offline
Joined: 14th Sep 2015
Location: Vancouver, WA, USA
Posted: 17th Sep 2015 17:59
well initially I intended to have spawninterval be a variable of the enemy table, which would allow for different spawn times for each. I think that might allow for more flexibility than checking against nextspawntime?

-Stupinator
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th Sep 2015 20:39
That's another possibility that is even more granular. You could also vary the nextSpawnTime with a random time (e.g 0.5 - 1.5 seconds)

nextSpawnTime# = (timer() - 0.5) + (random(0,10) / 10.0)

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Stupinator
8
Years of Service
User Offline
Joined: 14th Sep 2015
Location: Vancouver, WA, USA
Posted: 18th Sep 2015 06:43
gah, not sure why everyone uses # for floats, I understand it makes it a float automagically, but it's so much more of a hassle. I prefer just defining it as a float first

nextSpawnTime as float etc. etc.

Anyways, I'll make a wip thread with what I'm making now, that way I can log changes properly etc. etc. and you can see how I'm implementing this specific bit of code.

-Stupinator
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 18th Sep 2015 12:05
Quote: "gah, not sure why everyone uses # for floats"


I don't, but you'd be amazed how many people copy and paste a snippet of code like this and wonder why it fails. Hence the #s and $s on the forums.

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 18th Sep 2015 12:32
Quote: "not sure why everyone uses # for floats"


I never used to do this... For some reason, it irritated me too lol, but now, I do it all the time, and the reason is because when you have a huge project and you are coding against loads of variables, it really helps to know what the variable type is without the need to go back and check your declarations all the time...

I actually do both; global Time# as float

Using AppGameKit V2 Tier 1
Stupinator
8
Years of Service
User Offline
Joined: 14th Sep 2015
Location: Vancouver, WA, USA
Posted: 19th Sep 2015 17:14
Well to each their own I suppose!

-Stupinator

Login to post a reply

Server time is: 2024-04-19 00:56:39
Your offset time is: 2024-04-19 00:56:39