Discuss Scratch
- windows11_fan300
- 
                             Scratcher Scratcher
37 posts
Help With Coding!
That made no senseBut I don’t want to rewrite so much code!Rewriting code is easier than writing code, so when you say the word “but” it sounds like you want somebody to do it for you. A good place to start if you want to write your own engine though is rendering tiles from a list and playing with it using logic to possibly build a map, but I already have some maths for you. I cant help with rewriting for reasons I cant disclose. Anyways, some basic logic; Loop through the different tiles that could be displayed on screen (repeat ciel(360 / tile-size) + 1) and (repeat ciel(480 / tile-size) + 1) with an x and y counter for the tile on the screen. Convert these x and y to map space with newx to floor(scrollx / tile-size) + x and newy to floor(scrolly / tile-size) + y. You can find the index of these in the 1d list with index = newx + newy * mapwidth. If each item in your list is a number representing the costume you can set costume to list and x-position to (newx * tile-size) - scrollx and y-position to (newy * tile-size) - scrolly. Collisions are similar in method if your using pen stamps to render; just swap the repeats with 3 each, swap the scrollx and scrolly with playerx and playery and instead of the rendering logic use a simple box bounding check with numbers for the players hitbox width and height. x1 + width1 > x2 - width2 && x1 - width1 < x2 + width2 && y1 + height1 > y2 - height2 && y1 - height1 < y2 + height2 you can swap the x1 and y1 for player positions and the width1 and height1 to the hitbox width / 2 and height / 2, and swap the x2 and y2 with the positions of the tile and the width2 and height2 both to tile-size / 2. though that's just for checking the collision you can move out by using velocity edge snapping (you use the direction of movement to snap to one edge of the tile) or step calculating (go frame by frame and move out if collision is detected). Of course this is just an overview and may not be clear.snipI said “rewrite” not “write” but you can help me if you want!
- s714655
- 
                             Scratcher Scratcher
100+ posts
Help With Coding!
Basically loop through the amount of tiles that can be on the screen at one time and calculate their position and costume. And do the same thing with collisions but with a 3x3 area assuming the player is in the middle of it but instead of rendering you use a bounding box check.That made no senseBut I don’t want to rewrite so much code!snipsnipI said “rewrite” not “write” but you can help me if you want!
- windows11_fan300
- 
                             Scratcher Scratcher
37 posts
Help With Coding!
Ok but do you have any recommendations for music, textures, characters, etc?Basically loop through the amount of tiles that can be on the screen at one time and calculate their position and costume. And do the same thing with collisions but with a 3x3 area assuming the player is in the middle of it but instead of rendering you use a bounding box check.That made no senseBut I don’t want to rewrite so much code!snipsnipI said “rewrite” not “write” but you can help me if you want!
 
            ![[RSS Feed] [RSS Feed]](http://cdn.scratch.mit.edu/scratchr2/static/__5b3e40ec58a840b41702360e9891321b__//djangobb_forum/img/feed-icon-small.png)

