MakeCode Kart

Pls explain how this whole thing works I really wanna know but my tiny brain cannot understand the code

One more advice, the fill rectangle block is veeeery sloooow.
Try using the set ( ) color at x ( ) y ( ) with a higher resolution, it may run better.

As far as I know, the fastest way to draw is to use scene.createRenderable combined with Image.setRows. That’s what I use in Space Rocks 3D.

Here’s an older discussion about the topic: Is it possible to write directly to screen (pixels) on the Arcade?

scene.createRenderable takes a function as its second argument, that function gets called each time the screen content is refreshed on updates. The called function gets an Image as its first argument which is a reference to the screen buffer, you can modify that image to draw directly onto the screen.

The image.getRows and image.setRows methods copy pixels from the screen into a byte buffer and back.

Something like this (untested):

const buf = Buffer.create(120)
const zLayer = 0
scene.createRenderable(zLayer, (target: Image, camera: scene.Camera) => {
  for (let x = 0; x < 160; +=x) {
    // Read the current screen content for modification
    image.getRows(x, buf)
    // Now "buf" contains a color value for the current pixel row 
    // (it's actually a vertical column onscreen) where it can be modified.
    buf[12] = 15
    // Write the modified pixels back to the screen.
    image.setRows(x, buf)

Yeah, but you can’t do that in blocks

1 Like

I made it render 1600 pixels (20x80) and it looks good(30 fps on pc)(thanks @Nome_muito_criativo ). if I would try for 20x160 the framerate is horrible. (sorry @kwx I don’t know Javascript so I don’t know how to implement your method)

Curious to know why a sprite cannot be inserted into this scene?

@frank_schmidt the camera coords are way lower, try using relative to camera

also, anyone have any idea how to make the actual casting of the rays be faster, because that’s my main problem. I’m using a 1x1 sprite and detecting what tile is in that sprite’s position for each pixel and I think there might be a more efficient method. If anyone knows or has any ideas please let me know because I want to get to full pixel density (1x1 pixels instead of 2x1 pixels).

That’s the goal.

I’m working on collidable pipes

Instead of using sprites you could use X and Y variables, just increment them instead of setting the sprite’s position, then you can get the tile under them with the
(tilemap cols ( ) rows ( ))

The problem is, I’m working with angles and there’s no “detect tile (angle) (distance) from (mysprite)”

This is called “polar coordinates”, to convert to x and y (cartesian coordinates) you just set

x = distance * cos (angle)
y = distance * sin (angle)

Considering an angle of 0 to be on the right

NOTE: trigonometry in MakeCode uses radians not degrees

Thanks! I haven’t taken trigonometry yet, so I never learned how cos and sin worked. I’ll get working on the code!

The rendering is warped and movement doesn’t work correctly, but thanks @Nome_muito_criativo , but do you have any ideas on how to fix movement and warping?

am back!!!


Welcome back, nice to see you again ^-^

I’ve been working on this for a hours and I found some wiki articles, but I just can’t seem to get the rendering right. Am I missing something in the calculation of the angles?

I don’t know, I haven’t actually looked very far into the code, but it seems correct.

@Nome_muito_criativo are you finished with the mode 7 project or is it abandoned?