Hey there fellow scripters that know a f*ckton more than i do about programming.
I'm looking for some help optimizing some code in my current project regarding hit detection. I don't need exact codes at the moment so theoretical pseudocode is all I need. So first off, things you need to know:
So at the moment, the mechanic I have in place does this:
The player can hit(trigger) an event that has one tile between it and the player, if the player is facing the event. The player can be off by 1 tile horizontally to the direction he is facing, so there is a leeway of space where the event will trigger.
The pseudocode for it is as follows:
If A button is being pressed
- If player is within tile distance (by ints) of an event. Parameters are distance and if facing the event
- - When player is facing down, check if player y is less than event y, and if player x is within 1 of event x
- - When player is facing left, check if player x is more than event x, and if player y is within 1 of event y
- - When player is facing right, -- - - - - - - etc
- - When player is facing up, -- - - - - - - etc
- else false
I'm wondering if this is the most efficient way to check for hit detection. at specific distances, changing the parameters in green when needed.
I'm looking for some help optimizing some code in my current project regarding hit detection. I don't need exact codes at the moment so theoretical pseudocode is all I need. So first off, things you need to know:
- I'm using pixel movement, checking the X and Y of a player will effectively give you decimal point numbers in multiples of 0.125.
So at the moment, the mechanic I have in place does this:
The player can hit(trigger) an event that has one tile between it and the player, if the player is facing the event. The player can be off by 1 tile horizontally to the direction he is facing, so there is a leeway of space where the event will trigger.
The pseudocode for it is as follows:
If A button is being pressed
- If player is within tile distance (by ints) of an event. Parameters are distance and if facing the event
- - When player is facing down, check if player y is less than event y, and if player x is within 1 of event x
- - When player is facing left, check if player x is more than event x, and if player y is within 1 of event y
- - When player is facing right, -- - - - - - - etc
- - When player is facing up, -- - - - - - - etc
- else false
I'm wondering if this is the most efficient way to check for hit detection. at specific distances, changing the parameters in green when needed.