Log In  

Cart #map_col142-0 | 2022-01-10 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
8


This is an open-source cartridge/engine with map collision, player movement, and map scrolling. (206 tokens in total)

P#104766 2022-01-10 20:40 ( Edited 2022-01-10 21:20)

1

That is really optimized, @Lolscope. I ran into this situation doing collision checks with blocks on a previous platformer I was working on.

I'm wondering if there is a way to do just one FGET() per direction instead of 2.

Gold star for distinctly compact coding !

P#104785 2022-01-10 23:35
2

This is pretty compact, but there's a lot of reused code with different values plugged in, so I made a version using some lookup tables. Just 125 tokens.=)

--position table
p=split"60,60"
--movement table
m=split"-1,0,-1,7,-1,8,0,8,7,1,0,-1,7,-1,-1,0,8,7,8,1"

function _update()
 cls(1)
 x,y=p[1],p[2]
 for i=0,3 do
  local n=i*5
  if btn(i)
  and fget(mget((x+m[n+1])/8,(y+m[n+2])/8))!=1
  and fget(mget((x+m[n+3])/8,(y+m[n+4])/8))!=1 then
   p[i\2+1]+=m[n+5]
  end
 end
 map()
 spr(1,x,y)
 camera(x\128*128,y\128*128)
end
P#104800 2022-01-11 06:44 ( Edited 2022-01-11 06:46)

The original by @Lolscope is 495-chars.

@JadeLombax. Yours is 369 chars, impressive to scan the box for that small size !

Cart #kuwupikine-0 | 2022-01-11 | Code ▽ | Embed ▽ | No License

Here is mine at 330 chars, though it only scans the edges - still functional for a topview adventure game like Zelda.

I remember doing this years ago myself. The code is likely not all compact though:

https://www.lexaloffle.com/bbs/?tid=36388

In the case though for this particular code, Do I hear a lower number than 330 ? :)

P#104851 2022-01-11 23:44 ( Edited 2022-01-11 23:48)
1

Well, I was trying to minimize tokens instead of character count, but here's a smaller version that fits in a tweet (277 chars, 127 tokens).

c=128p=split"60,60"m=split"-1,0,-1,7,-1,8,0,8,7,1,0,-1,7,-1,-1,0,8,7,8,1"
::_::x,y=p[1],p[2]?'⁶1⁶c1'
for i=0,3do n=i*5
if(btn(i)and fget(mget((x+m[n+1])/8,(y+m[n+2])/8))!=1and fget(mget((x+m[n+3])/8,(y+m[n+4])/8))!=1)p[i\2+1]+=m[n+5]end
map()spr(1,x,y)camera(x\c*c,y\c*c)goto _

--Edit: Fixed camera bug.

P#104854 2022-01-12 00:14 ( Edited 2022-01-12 04:27)

@JadeLombax, where's the other map ? You can go off the edge to the right and there's another map.

P#104856 2022-01-12 00:22

Oh, I was in a hurry and didn't test the code before posting. It's fixed now.

P#104868 2022-01-12 04:28

Ah ! And there you go, @JadeLombax. So the score I need to beat is 278 characters. I think I can do it.

P#104871 2022-01-12 04:31
3

Cart #sidokopiso-0 | 2022-01-12 | Code ▽ | Embed ▽ | No License
3

252-char, @JadeLombax. Yet I'm still only checking one map flag which kinna gives me the leading edge, literally. :)

I also set it so you can peek out the exit and arrive on the other side also peeking in.

. . .

There is another method to this madness mapping. How about the way they do it in Final Fantasy ? In minimal code.

P#104898 2022-01-12 16:07 ( Edited 2022-01-12 16:13)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-04-19 11:32:04 | 0.045s | Q:35