A little new to JS so I apologize if my code looks… rudimentary… but I’m trying to code a platformer completely from scratch. I started this project with very little JS knowledge and have made quite some progress since. I just finished coding hitbox detection, however buggy it may currently be, and it works pretty well. I still have to work out some kinks and only the bottom two anchors have been actually coded but I ran into an issue that haven’t been able to find a definitive answer to.
Code
https://pastebin.com/C8xPtCv1
Line 724:
if (tile3 == "D27" || tile3 == "D28" || tile3 == "D29" || tile3 == "D30" || tile4 == "D27" || tile4 == "D28" || tile4 == "D29" || tile4 == "D30" || tile3 == "H36" || tile3 == "H37" || tile3 == "H38" || tile3 == "H39" || tile4 == "H36" || tile4 == "H37" || tile4 == "H38" || tile4 == "H39" || tile3 == "L30" || tile3 == "L31" || tile3 == "L32" || tile3 == "L33" || tile4 == "L30" || tile4 == "L31" || tile4 == "L32" || tile4 == "L33" || tile3 == "L20" || tile3 == "L21" || tile3 == "L22" || tile3 == "L23" || tile4 == "L20" || tile4 == "L21" || tile4 == "L22" || tile4 == "L23") {
On line 724 I have coded a basic detection system that allows the sprite to interact with 4 platforms. The issue; its extremely tedious, and if I plan on coding multiple scenes all on a 48×27 tile canvas this is not a great way to go about it. My initial thinking for tile detection was arrays but in my fruitless attempts at trying to figure them out I failed. I’m looking for a way to assign each anchor to each tiles state. Currently the way to do that is the test if the anchor is inside the tile. eg. (tile3 == “D27 || tile4 ==”D27”) writing this code for EVERY tile however, is not the way I want to write this code, not to mention the sprite has 2 more anchors i need to code for head collision. I want to write these conditionals in a more efficient way but i have no idea how.