Having enemy NPC deaths increase player's coinCoint. (Extreme noob question)

26 views
Skip to first unread message

Joe Ford

unread,
Mar 9, 2014, 10:48:11 AM3/9/14
to replica-island-...@googlegroups.com
All,
I'm trying to have enemy deaths increment the player's number of coins (e.g. I have 3 coins, I kill an NPC, now i have 4 coins).
I thought this would be relatively easy (and it may be), but I've been struggling with it for countless hours now.
(Please note: I'm extremely new to computer programing, let alone Java. I have zero education on it outside of what I read/watch on the internet this year. Needless to say I'm in way over my head).

With that said, I learn best by doing, so in case anyone still reads this group and wants to help an amateur enthusiast out, here's what I was thinking that's failed.

The "HitReactionComponent" class states:

          if (mDieOnAttack) {
                parent.life = 0;    
         }


Later on it states
           case CollisionParameters.HitType.DEATH:
                // respect teams?
                parent.life = 0;
                break;


My thoughts were to add code within these if statements that simply say to add a coin the player's inventory.
Something along the lines of:

InventoryComponent.UpdateRecord addCoin = new InventoryComponent.UpdateRecord();
                addCoin.coinCount = 1;
               

I also attempted other similar things regarding the variable in the HudSystem class, among others.

Any thoughts?
Thanks!

Joe Ford

unread,
Mar 9, 2014, 12:43:49 PM3/9/14
to replica-island-...@googlegroups.com
*coinCount


Also considering somehow replace Update Record from InventoryComponent content with COUNTER_ROBOTS_DESTROYED from EventRecorder class within the HudSystem class.

vecima

unread,
Mar 9, 2014, 4:02:02 PM3/9/14
to replica-island-...@googlegroups.com
You may want to look at how enemies are created in the GameObjectFactory class.  One thing you could try is to look at enemies that spawn something on death, and add in code to spawn a coin on death.  That way, you might even get to see a coin being "dropped" by the enemy, though this may not fit with your design.

Joe Ford

unread,
Mar 9, 2014, 7:13:04 PM3/9/14
to replica-island-...@googlegroups.com
YESSSSSSSSS. It worked!!! Thanks so much vecima!!

I still don't want the player seeing the coin, so in true half-assed fashion, I plan to erase all the content out of the coin's PNG and leave the code as is, lol.

Also, it looks like the player can kill an enemy and still miss the coin. Since i want it to be automatic, I also plan to increase the detection area of the coin so if the player's close enough to kill the enemy, they're close enough to get the coin.

Thanks again! Wish me luck!

vecima

unread,
Mar 10, 2014, 10:43:01 PM3/10/14
to replica-island-...@googlegroups.com
That may work as a work-around, but if you really do want the coin increment to be automatic, you probably should try to get it done without spawning a GameObject to do it.  I'm not sure what that implementation would look like though.


--
You received this message because you are subscribed to the Google Groups "ReplicaIsland Coding Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages