Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
Enemy Counter in CopperCube

dynamogames
Registered User
Quote
2023-08-29 22:58:07

I'm trying to implement a system in CopperCube where in a particular scene or level, there is the player and there are enemies (for instance, 5 enemies). I want to create an enemy counter for the player such that the player has an enemy counter to know how many enemies are currently in the level, the counter also reduces by one when an enemy dies.


okeoke
Registered User
Quote
2023-08-30 08:10:46

Hi. You can put all your enemy nodes to a separate folder.
That way you can calculate nodes inside this folder:
// get folder containing enemy nodes
const enemiesFolder = ccbGetSceneNodeFromName('YOUR_FOLDER_NAME_HERE');
// get enemies count
const enemiesCount = ccbGetSceneNodeChildCount(enemiesFolder ;
// set coppercube variable
ccbSetCopperCubeVariable('enemiesCount', enemiesCount);

Actor behavior contains "actionOnDeath" or something like that. You put an action which reduces variable 'enemiesCount' by 1.
I believe, this should do.


Dieter
Guest
Quote
2023-08-30 09:21:19

okeoke's suggestion looks pretty good, maintenance-free.

In this context I may mention:

There are many ways to implement scripts in CC, and the multitude of options may be confusing at first. Personally, I try to follow a certain methodology:

Define all CC variables that I will use in the "do something before first drawing" behavior of the top scene node.

Use a high frequency task for the same node, "do something every few seconds", maybe about every 50 ms, or try to synch it with the framerate somewhat, like with 60 fps you'd say every 66 ms, that's every 4th frame. (1000/60=16.667)

In this node I control things that need to be done immediately, like fading out audio. This task must be kept fast, so it just checks a couple of variables to see whether any action must be done.

I also use a task every second to manage things that are less critical in exact timing, like hiding again a 2D overlay that was shown to display a message for 4 to 5 seconds.

Additionally I use the "inline" scripts (special - execute javascript), mostly and only to set for example a variable to a certain value on a click event. So I would set secret_door_countdown to 100, and in the beforementioned 50ms task I would check this variable, and if bigger than 0, I would progressively move the secret door mesh up, and decrement the variable by 1.
I can play a sound on the click event, and stop the sound when the variable has reached 0.

So that is a very simple way to structure your game. A further method I use and combine with the above, is an action script that can be used by many items, for instance after clicking them, and then in the script I check the name of the node that was clicked, and I use a certain name convention, where certain terms trigger certain actions, or reactions. For example I have nodes "door1" to door5. Clicking them triggers the door handler inside this main action script. But the same script also deals with other clickable items, like pickups, buttons etc, all differentiated by the name of the node, so these names become a scripting language by their own. And I can simply copy-paste the same behavior to all clickable items, and handle them all in one action script.

These structures work, but there may be other methodologies, and disputes about what's best of course. Just thought I mention it, because I just had my 2nd coffee ^^


dynamogames
Registered User
Quote
2023-09-01 12:18:06

Thanks @okeoke, I've been able to implement it and it works.
Thanks dieter for the contribution too.


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Intern?tional" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact