Forum de Custom Protocol Retourner sur le site

Le lieu de discussion francophone par excellence sur le hack et la scène underground

La section "Underground" est faite pour parler de tout ce qui touche plus ou moins à la scène underground de la console : homebrews, plugins, custom firmwares...

Modérateur : Administration

#3244
Hi, After a long time of elbowing a mini test on this subject, I meet do not understand well how to collisions ...

Image

I mean, using Onelua V4, I'm testing this code ..
Code : Tout sélectionner
--Tables (Maps)
dofile("Tile_Maps.lua")
 
BKG=image.load("BKG.png")
 
Map0=image.load("BKG_Back_Tileset.png")
if Map0 then maps0=map.new(Map0,tabla0,16,16) end
 
Map1=image.load("BKG_Front_Tileset.png")
if Map1 then maps1=map.new(Map1,tabla1,16,16) end
 
function newPlayer()
	local obj = {
		x = 0,
		y = 0,
		h = 0,
		s = 0,
		dir = false,
		-- size of tile player
		ws = 20,
		hs = 36,
		data = image.load("sprites.png",20,36),
		crono = timer.new(),
		jump_enable = true,
		map_sizeW = 0,
		map_sizeH = 0,
	}
	obj.crono:start()
	function obj:MapSize(w,h)
		obj.map_sizeW = w
		obj.map_sizeH = h
	end
	function obj:xy(x,y)
		obj.x = (x or obj.x)
		obj.y = (y or obj.y)
	end
	function obj:walking(xm,ym)
		if buttons.released.right then
			obj.s = 0
		end
		if buttons.cross and obj.jump_enable then
			obj.jump_enable = false
		end
		if buttons.held.right then
			if obj.dir then
				image.flipv(obj.data)
				obj.dir = not obj.dir
			end
			local mtw = 16 -- tile size map
			local mth = 16 -- tile size map
			tx = math.floor(((obj.x+obj.ws) + xm) / (obj.map_sizeW/16))
			ty = math.floor(((obj.y+obj.hs) + ym) / (obj.map_sizeH/16))
			if tabla1[tx][ty] == 20 then -- todo el problema radica en estos index :P :-/
				return nil
			end
			if obj.crono:time()> 16 then
				obj.crono:reset(); 
				obj.crono:start();
				obj.s = obj.s + 1 
				if obj.s > 2 then
					obj.s = 0
				end
				obj.x = obj.x + 4
				if obj.x > 240 then
					obj.x = 240
					return 2
				end
				return 1
			end
		end
		if buttons.held.left then
			if not obj.dir then
				image.flipv(obj.data)
				obj.dir = not obj.dir
			end
			if obj.crono:time()> 32 then
				obj.crono:reset(); 
				obj.crono:start();
				obj.s = obj.s + 1 
				if obj.s > 2 then
					obj.s = 0
				end
				obj.x = obj.x - 4
				if obj.x < 10 then
					obj.x = 10
					return -2
				end
				return -1
			end
		end
	end
	--obj.data:resize(17*1.5,31*1.5)
	function obj:draw()
		obj.data:blitsprite(obj.x,obj.y+obj.h,obj.s)
		if not obj.jump_enable then 
			obj.h = obj.h - 4
			if obj.h < -75 then obj.jump_enable = true end
		else
			if obj.h < 0 then 
				obj.h = obj.h + 4
			end
		end
	end
	return obj
end
Luigui = newPlayer()
Luigui:xy(10,187)
Luigui:MapSize(map.sizex(maps1),map.sizey(maps1))
x,y=0,0
xx,yy=0,0
while true do
buttons.read()
 
--blitear el fondo
image.blit(BKG,0,0)
 
--Blitear el mapa de detras
map.blit(maps0,x,160)
 
--Blitear el mapa de delante
map.blit(maps1,xx,160)
 
 
local move_back = Luigui:walking(xx,160)
if move_back then
	x=x+(1*move_back)
	xx=xx+(2*move_back)
end
Luigui:draw()
screen.flip()
end
Really I do not understand how to do the calculations for the index in the array of map, and whether the tile is solid or nothing .. in this case the solid with which would crash walking to the right I would be the tile 20: P

Complete Code if like to try :)
Download!

I really hope the community helps, of course, these coders in the shadows give me a hand xD
This post is for educational purposes simply! xDDD
Wirus, Tuxbot123 a aimé cela
#3255
Hey, sorry I'm late xD To use collision in Anésidor, I have create a new map with GBA Graphics with red color.
Image
When this new table is create and load (dofile and not with map function), i add new condition when the player meet a collision.
Code : Tout sélectionner
if buttons.held.right or buttons.analogx > 64 then--RIGHT
		for i=8,16 do
			if map_e[math.floor((y+i)/8)][math.floor((x+15)/8)] == 0x0001 then
				stop_move = true--DONT GO TO RIGHT
			elseif map_e[math.floor((y+i)/8)][math.floor((x+15)/8)] == 0x0002 then
				trans = "droite"
			end
		end
		if stop_move == false then--ELSE YOU CAN
			x = x + 2
		end
		statut = "droite"
		
	elseif buttons.held.left or buttons.analogx < -64 then--LEFT
		for i=8,16 do
			if map_e[math.floor((y+i)/8)][math.floor((x+4)/8)] == 0x0001 then
				stop_move = true--DONT GO TO RIGHT
			elseif map_e[math.floor((y+i)/8)][math.floor(x+4/8)] == 0x0002 then
				trans = "gauche"
			end
		end
		if stop_move == false then--ELSE YOU CAN
			x = x - 2
		end
		statut = "gauche"
		
	elseif buttons.held.up or buttons.analogy < -64  then--UP
		for i=5,11 do
			if map_e[math.floor((y+5)/8)][math.floor((x+i)/8)] == 0x0001 then
				stop_move = true--DONT GO TO RIGHT
			elseif map_e[math.floor((y+5)/8)][math.floor((x+i)/8)] == 0x0002 then
				trans = "haut"
			end
		end
		if stop_move == false then--ELSE YOU CAN
			y = y - 2
		end
		statut = "haut"
		
	elseif buttons.held.down or buttons.analogy > 64 then--DOWN
		for i=5,11 do
			if map_e[math.floor((y+18)/8)][math.floor((x+i)/8)] == 0x0001 then
				stop_move = true--DONT GO TO RIGHT
			elseif map_e[math.floor((y+18)/8)][math.floor((x+i)/8)] == 0x0002 then
				trans = "bas"
			end
		end
		if stop_move == false then--ELSE YOU CAN
			y = y + 2
		end
		statut = "bas"
	end

Image
The result when I show the red texture :p
#3463
Applelo a écrit :Hey, sorry I'm late xD To use collision in Anésidor, I have create a new map with GBA Graphics with red color.
Image
When this new table is create and load (dofile and not with map function), i add new condition when the player meet a collision.
Code : Tout sélectionner
if buttons.held.right or buttons.analogx > 64 then--RIGHT
		for i=8,16 do
			if map_e[math.floor((y+i)/8)][math.floor((x+15)/8)] == 0x0001 then
				stop_move = true--DONT GO TO RIGHT
			elseif map_e[math.floor((y+i)/8)][math.floor((x+15)/8)] == 0x0002 then
				trans = "droite"
			end
		end
		if stop_move == false then--ELSE YOU CAN
			x = x + 2
		end
		statut = "droite"
		
	elseif buttons.held.left or buttons.analogx < -64 then--LEFT
		for i=8,16 do
			if map_e[math.floor((y+i)/8)][math.floor((x+4)/8)] == 0x0001 then
				stop_move = true--DONT GO TO RIGHT
			elseif map_e[math.floor((y+i)/8)][math.floor(x+4/8)] == 0x0002 then
				trans = "gauche"
			end
		end
		if stop_move == false then--ELSE YOU CAN
			x = x - 2
		end
		statut = "gauche"
		
	elseif buttons.held.up or buttons.analogy < -64  then--UP
		for i=5,11 do
			if map_e[math.floor((y+5)/8)][math.floor((x+i)/8)] == 0x0001 then
				stop_move = true--DONT GO TO RIGHT
			elseif map_e[math.floor((y+5)/8)][math.floor((x+i)/8)] == 0x0002 then
				trans = "haut"
			end
		end
		if stop_move == false then--ELSE YOU CAN
			y = y - 2
		end
		statut = "haut"
		
	elseif buttons.held.down or buttons.analogy > 64 then--DOWN
		for i=5,11 do
			if map_e[math.floor((y+18)/8)][math.floor((x+i)/8)] == 0x0001 then
				stop_move = true--DONT GO TO RIGHT
			elseif map_e[math.floor((y+18)/8)][math.floor((x+i)/8)] == 0x0002 then
				trans = "bas"
			end
		end
		if stop_move == false then--ELSE YOU CAN
			y = y + 2
		end
		statut = "bas"
	end

Image
The result when I show the red texture :p
Hello Applelo, first apology not respond before,

I was very distracted these days,

So could you explain more in detail how you do the math ?, I see you do a sweep with "for", but do not entirely understand it does.
#3470
I use math function for round the result because I can't find a number 0.1 but 1 in the collision table :p
The "for" loop is here to check many pixel.

Bonjour @ Enzo , @ broly et @ thanks guys , effec[…]

Idées Homebrews HENkaku

Je te comprend aussi, j'ai fais pareil avec le hac[…]

N’oubliez pas de visiter le site !