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 / [Tier 1] How to dynamically create enemies?

Author
Message
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 4th Sep 2017 17:28
I want to make a 3D arcade shooter, so I need to dynamically spawn a lot of enemies during gameplay! I also needs loop through the enemies in the main loop, to test collision and suchlike.

I think I have to use "type", and give each enemy life points, and .fbx and such. But this way beyond my comfort zone - please help!!!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Sep 2017 17:44 Edited at: 4th Sep 2017 17:49
yes you need a struct with some enemy data/state and object id. and your game logic need also some kind of a state maschine.
some fucntion to load/create/clone/move/shoot/destroy enemy
an array with all enemys you can give this by reference to a function that handle all enemys.
you need to think about what should happen when.
if me have a complex task to do, i create all the functions without content and then i fill them one by one until everything is done.
AGK (Steam) V2017.08.16 : Windows 10 Pro 64 Bit : AMD (17.7.2) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Sep 2017 18:20
I wrote this some time ago for DarkBasic, but the principles are the same...

http://tutcity.devink.co.uk/asset-management/

And this one expands on the ideas...

https://www.thegamecreators.com/pages/newsletters/newsletter_issue_29.html#9
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 4th Sep 2017 19:12
Quote: "if me have a complex task to do, i create all the functions without content and then i fill them one by one until everything is done."


+1, create the framework, then the functionality, done right with a state machine you give yourself an event driven framework to build your app from.
BuccaneerBob
AGK Developer
14
Years of Service
User Offline
Joined: 18th Aug 2010
Location: Canada
Posted: 4th Sep 2017 21:20
Basically, and this is purely off of the of my head, no promises it would work out of the box.

But you'd have something along the lines of



Next you'll need a function to create these enemies (I recommend creating them at run-time and hiding them until they're needed, or you can choose to create them on the fly whenever you want them to spawn). There are pros and cons to both methods.

But it would look something like

Robert Janes (Samu Games)
http://www.samugames.com/artifact
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 4th Sep 2017 21:53
Arrays in Version 2
https://www.appgamekit.com/documentation/guides/12_array_changes.htm

AGK (Steam) V2017.08.16 : Windows 10 Pro 64 Bit : AMD (17.7.2) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 5th Sep 2017 12:09 Edited at: 5th Sep 2017 12:11
Thanks for the advice! Working at getting this stuff implemented. I guess each enemy would also need exist_in_game as Integer to tjeck if they are currently in use



This is weird - from the url, I understood that Dim Enemy[1000] as EnemyType should be replaced with Enemy as EnemyType[1000]. But that gives me the error "enemy" has not been defined:

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 5th Sep 2017 12:27 Edited at: 5th Sep 2017 12:29


the new arrays are dynamic, you can add,insert,sort,remove items. you do not need to start with 1000 items.

AGK (Steam) V2017.08.16 : Windows 10 Pro 64 Bit : AMD (17.7.2) Radeon R7 265 : Mac mini OS Sierra (10.12.2)
Rich Dersheimer
AGK Developer
15
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 5th Sep 2017 16:28
@basicFanatic - I tried your code, and I don't get the error.

local Enemy as EnemyType[1000] works fine

and

Enemy as EnemyType[1000] works fine too.

Are you on the latest version of AGK2?
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 5th Sep 2017 17:02

Hi Rich - you're right, local Enemy as EnemyType[1000] works perfectly. I had just forgotten to write local (Markus fixed that!)

But I'm unsure about this one:
Enemy[ID].Mesh = LoadObject( "toxiccrate.x", 1.0)
Do I really need to load the file from the hard drive for each single enemy?

IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 5th Sep 2017 20:16 Edited at: 5th Sep 2017 20:17
This is usually how I deal with dynamic objects.
Golelorn
7
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 6th Sep 2017 02:42
From a newbie perspective:

I would create the enemies, hide them, test for distance, and then activate them - and then hide them again. I have read on these forum deleting unused sprites/objects does not free up RAM. I have also come across deleting sprites does not remove them from your screen, so you have to hide them, as well(no idea why this happens, perhaps something I am missing).

You'll need to learn types and arrays to keep control of your code, or you will quickly become overwhelmed and lost in your own code. I do not know your background, but mine is SQL and Excel. I just think of these like fields, rows, and tables. Arrays are servers, types are tables, type definitions are fields, and what is in the types are rows.

I have recently learned the power of types. It is easy once you get past that initial stage of learning(I created a test program and did a bunch of random crap to understand it - yes it took me hours to get it and I still am learning . Much more manageable, and truly powerful. Basically, its like having a database, and seems to be much simpler than SQL to pull back what you need. Unless, its truly simple - for pathfinding I find it simple enough to just use multidimensional arrays. I need to know the vector and if its passable. I just feel in that instance its easier. But defining an enemy you need a lot more data stored.

Here is an example of my creature type:





Wilf
Valued Member
18
Years of Service
User Offline
Joined: 1st Jun 2006
Location: Gone to Unity.
Posted: 6th Sep 2017 06:32
+1 Golelorn. I used to create and destroy entities dynamically but it lead to tracking issues when something was referenced but no longer existing. Now I create a cache of cloned enemies and items at loadtime, hide/deactivate them, and spawn them only when necessary.
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 6th Sep 2017 14:56
IronManhood had some really solid code! Still, I think I'll go for just hiding the unused enemies. It's just a bit simpler. So far I used the code below to make the game ignore the unused enemies. Is that enough?


Also (as seen below) I load the file book.x from the hard drive 500 times. Is there a way to only load it once?

IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 7th Sep 2017 02:16 Edited at: 7th Sep 2017 02:16
You could try using CloneObject(). I don't have a whole lot of experience with 3d commands in tier 1.
ShaunRW
DBPro Developer
16
Years of Service
User Offline
Joined: 7th Jan 2008
Location: Brisbane, Australia
Posted: 7th Sep 2017 02:41 Edited at: 7th Sep 2017 02:42
Quote: "I have read on these forum deleting unused sprites/objects does not free up RAM."

Wait really? Can someone confirm this? In my current project it's possible to have 100s of sprites on screen which are then deleted when the turn is over, only to be recreated in the next turn.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 7th Sep 2017 04:44 Edited at: 7th Sep 2017 05:04
I have noticed that the DeleteSprite function doesn't remove it completely from the internal list. Calling DeletALLSprites seems to reset it. I noticed it by printing sprite IDs and observing the difference when using both functions. I don't know if that is intentional or a bug. Also, I don't know if that has anything to do with the memory issue. This was like a year ago, I haven't tested this recently.

Edit: This illustrates what I'm talking about.

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 7th Sep 2017 12:35
Even though the sprite ID is constantly increasing, the old sprites are deleted. It's quicker to keep increasing the ID than search the previously used IDs to see which ones have been deleted.
IronManhood
9
Years of Service
User Offline
Joined: 6th Feb 2015
Location: US
Posted: 8th Sep 2017 20:39
Quote: "Even though the sprite ID is constantly increasing, the old sprites are deleted. It's quicker to keep increasing the ID than search the previously used IDs to see which ones have been deleted."


That makes sense.

Quote: "I have read on these forum deleting unused sprites/objects does not free up RAM."


Well is the ram thing a feature or a bug?
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 11th Sep 2017 13:08 Edited at: 11th Sep 2017 13:08
Quote: "Well is the ram thing a feature or a bug?"

I'm not aware of any memory leaks in AGK. If you find one please let me know with a (preferably small) example demonstrating the problem.

Login to post a reply

Server time is: 2024-09-30 07:29:18
Your offset time is: 2024-09-30 07:29:18