Log In  


Cart #mapcompress-2 | 2022-02-27 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
4


new version of mapcompress
use 4x the sprites (kind of)!
this cart serves as a map editor for a new way to draw the map
ESDF to move
left click to place tiles on the map
right click to get a tile from the map
left arrow to toggle x flip
right arrow to toggle y flip
up arrow to toggle sprite selector
z to save map to cart
x to load map/sprites to editor

notice:

  1. currently you cant use sprite flags to draw certain sprites
  2. camera won't work with this, use sx and sy
  3. you cant choose the width/height of the map area you want to draw

map code (put this in your game instead of map()):


function _map(x,y,sx,sy)
local x,y=x or 0,y or 0
local sx=sx or 0
local sy=sy or 0
--local celw=celw or 17
--local celh=celh or 17
--local layer=layer or 0
local mx,my=0,0
for i=0,305 do
local tile=mget(mx+x+(sx\8),my+y+(sy\8))
local tsec=tile\64
local flipx=false
local flipy=false
if(tsec==1 or tsec==3)flipx=true
if(tsec==2 or tsec==3)flipy=true
tile+=(tsec-1)-64
spr(tile,mx
8-(sx%8),my*8-(sy%8),1,1,flipx,flipy)
mx+=1
if mx>17 then
mx=0
my+=1
end
end
end

first version:


Cart #mapcompress-0 | 2020-11-20 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
4


so you know how half of the sprite sheet is shared with the map? because of that, usually I use the half for the map, one spritesheet tab for sprites, and one tab for map tiles. well, I just figured out that in doing so I dont use 1/4th of the tile data. this program I made uses the 1/4th tile data to flip the map tile. i will be making a tool to use this easily soon.

Code to import:

function _map(x,y,sx,sy,celw,celh,layer)
	local x=x
	local y=y
	local celw=celw
	local celh=celh
	local layer=layer --not used yet
	if x==nil then 
	 x=0
	end
	if y==nil then 
	 y=0
	end
	local sx=x
	local sy=y
	if celw==nil then
		celw=16
	end
	if celh==nil then
		celh=16
	end
	for i=0,celw*celh do
		tile=mget(x,y)
		if tile<64 then
		 --first tab
			flipx=false
			flipy=false
			tile+=64
		elseif tile>63 and tile<128 then
		 --second tab
		 flipx=true
		 flipy=false
		elseif tile>127 and tile<192 then
		 --third tab
		 flipx=false
		 flipy=true
		 tile-=64
		else
		 --fourth tab
		 flipx=true
		 flipy=true
		 tile-=128
		end
		spr(tile,x*8,y*8,1,1,flipx,flipy)
	 x+=1
	 if x==sx+16 then
	 	x=0
	 	y+=1
  end
	end
end

The code uses the 2nd spritesheet tab for the tiles.
Call _map() whenever you want to use the function in your game.


*only when you are using the 2nd tab of the sprite sheet

4


You have overwritten the sx and sy parameters in your code, so this is ignored.
Why do you call "local x=x"? Parameters are normally already local. Variables in for normally too.

I have shorted your _map-routine a little bit:

function _map(x,y,sx,sy,celw,celh,layer)
 sx=sx or 0
 sy=sy or 0
 for y=0,celh or 16 do
   for x=0,celw or 16 do     
	   	local tile=mget(x,y)
	   	spr((tile & 63) + 64,
	   	    sx+x*8,sy+y*8,1,1,
	   	    (63 < tile and tile <128) or tile>=192,
	   	    tile>127)
	  end
	end	
end

when you have questions about my code ask :)


amogus
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣤⣤⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⠟⠉⠉⠉⠉⠉⠉⠉⠙⠻⢶⣄⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⣷⡀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣸⡟⠀⣠⣶⠛⠛⠛⠛⠛⠛⠳⣦⡀⠀⠘⣿⡄⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⣿⠁⠀⢹⣿⣦⣀⣀⣀⣀⣀⣠⣼⡇⠀⠀⠸⣷⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠉⠛⠿⠿⠿⠿⠛⠋⠁⠀⠀⠀⠀⣿⡄⣠
⠀⠀⢀⣀⣀⣀⠀⠀⢠⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢻⡇⠀
⠿⠿⠟⠛⠛⠉⠀⠀⣸⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣧⠀
⠀⠀⠀⠀⠀⠀⠀⢸⡿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⠀
⠀⠀⠀⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀
⠀⠀⠀⠀⠀⠀⠀⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀
⠀⠀⠀⠀⠀⠀⢰⣿⠀⠀⠀⠀⣠⡶⠶⠿⠿⠿⠿⢷⣦⠀⠀⠀⠀⠀⠀⠀⣿⠀
⠀⠀⣀⣀⣀⠀⣸⡇⠀⠀⠀⠀⣿⡀⠀⠀⠀⠀⠀⠀⣿⡇⠀⠀⠀⠀⠀⠀⣿⠀
⣠⡿⠛⠛⠛⠛⠻⠀⠀⠀⠀⠀⢸⣇⠀⠀⠀⠀⠀⠀⣿⠇⠀⠀⠀⠀⠀⠀⣿⠀
⢻⣇⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⡟⠀⠀⢀⣤⣤⣴⣿⠀⠀⠀⠀⠀⠀⠀⣿⠀
⠈⠙⢷⣶⣦⣤⣤⣤⣴⣶⣾⠿⠛⠁⢀⣶⡟⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡟⠀
⢷⣶⣤⣀⠉⠉⠉⠉⠉⠄⠀⠀⠀⠀⠈⣿⣆⡀⠀⠀⠀⠀⠀⠀⢀⣠⣴⡾⠃⠀
⠀⠈⠉⠛⠿⣶⣦⣄⣀⠀⠀⠀⠀⠀⠀⠈⠛⠻⢿⣿⣾⣿⡿⠿⠟⠋⠁⠀⠀⠀



[Please log in to post a comment]