It's "hardco
de", not "hardcore"
. And it's a verb, not an adjective - the adjective is "hardcoded".
Strictly speaking, something "hardcoded" is something which "that you can only change by editing the source code". The opposite example would be "data driven" or "parametrized".
A typical example: a game that you have to recompile to change the player speed (for example), then that it "hard-coded". If you can change that behaviour by modifying a config file, then it's "less hardcoded". And if you can modify it using the game's interface, it's not harcoded at all. (I'm aware that in LÖVE and Lua the line that separates a "config file" or a "data file" from a "source file" is very tenuous).
Nevertheless, I'm seeing "hardcoded" being used as "programming in an inflexible way" these days. The typical example is when you use numbers instead of variables in your code. For example, on the following code, "2.5" and "0.5" are "hardcoded".
Code: Select all
function moveLeft(player, dt)
player.x = player.x + 2.5*dt
end
function moveUp(player, dt)
player.y = player.y + 0.5*dt
end
They represent horizontal and vertical player speed. They are very likely to be used in other places. Better give those numbers a name:
Code: Select all
horizontalSpeed = 2.5
verticalSpeed = 0.5
...
function moveLeft(player, dt)
player.x = player.x + horizontalSpeed * dt
end
function moveUp(player, dt)
player.y = player.y + verticalSpeed * dt
end
There are several reasons for this. First, these numbers are likely to be used in other parts (trajectory calculations, etc) so it makes sense to have them in one place, so you can change one line and that changes everything. But also it makes the code more readable for humans.
With the old meaning, the player speed is still "hardcoded" - you still have to modify the source to change the player speed. But the code itself can be very easily, and flexibly - it's "less hard to code", or less "hardcoded" in the second meaning of the word.
On your code the "hardcoding" happened because to two parts of your code - key pressing and player logic - that where unnecessarily
coupled. Using a boolean decouples them; now more things can move your player, for example, gravity, or a cutscene. With a little change, you can use that same code to move enemies around, too.