Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 04 Aug 2011
Offline Last Active Aug 31 2016 08:52 AM

#5059813 Problem with understanding data access and responding to events in component...

Posted by on 06 May 2013 - 02:09 PM

Hi GameDev,


I have a problem figuring out how something like this would work:


In a component based system I have solid objects (which can collide) and gameplay type objects (which have various stats like damage...) which are combined (inherited).


Now if I detect a collision between 2 solid objects, in C++ how should I go about checking if the objects are gameplay type and consequently do damage to each other?



I will elaborate when I get more time, thanks in advance

#5049617 AS3 creating new objects.

Posted by on 03 April 2013 - 11:03 AM

I would make an array (or vector) of Bullet objects and have a var index:int that will tell me what the last used bullet in the array was.


So the implementation would go somewhat like this:




function spawnBullet():void
    //Pseudo code
    //Take the Bullet at position index and "activate it"(by activating I mean setting it's position and adding listeners)
    index = (index+1) % MaxNumberOfBullets;

// This next function I would call every few frames (it depends)
function cleanUp():void
    //Again pseudo code
    //Go through the array of bullets and check if they are ready for "deletion" (by deletion I mean removing the listeners and         
    //maybe making them invisible)


Now what this should do is it will allow you to always have a free bullet object that is hopefully destroyed (unless somehow you needed more bullets than the array could hold, in that case you increase the maximum size and add more bullets to the array) and it will make removing them not really taxing on the PC.


Ofcourse, the special case is when a bullet hits an enemy and it disapears but yout can solve that by implementing a function that will deactivate the bullet which you can, again, call in the cleanUp function instead of handling it manually.


Hope it helps you ;)

#5049308 Shooting in SFML

Posted by on 02 April 2013 - 02:55 PM

Actually, if you look at the code, the only place where the bullets position is updated is this:



bulletX += ((shot_XOffset*0.1)) ;
bulletY += ((shot_YOffset*0.1)) ;


but shot_XOffset and shot_YOffset are calculated like this:



shot_XOffset = mouseX -( bulletX );
shot_YOffset = mouseY -( bulletY );

This makes the bullet move 10% of the distance between the mouse pointer and the origin position, which means it is not constant if you change the mouse position (hence the faster and slower movement).