Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Creating a maze without using tiled or tilemap images. — Gideros Forum

Creating a maze without using tiled or tilemap images.

xGuiltxGuilt Member
edited August 2013 in General questions
Just wondering is this possible?

Right now i'm trying to create a maze like level for my game. I've read around that tiled is a nice tilemap and physics editor software but it seems rather too much since this is just a mini game which involves only one or two images for the design of the maze so i figured that tile maps wouldn't be that much used.

Is it possible to create a simple grid map using array in Gideros? Where 1 will be an image that a physics body can attach to while 0 will be a transparent image of the same size where there is no physics body (walkable path) So basically it's just 2 pics.

Comments

  • ar2rsawseenar2rsawseen Maintainer
    edited August 2013
    @xGuilt well most probably yes, I have not seen an implementation yet, but I see no reason for it not to work :)
    Not so related, but there were even pathfinding implementations in lua:
    http://www.giderosmobile.com/forum/discussion/1081/jumper-very-fast-pathfinder-for-2d-grid-based-games
  • Hm as of now what i have on my mind is something like having an array like
    local maze = {
        {1,1,1,1,1,1,1,1,1,1},
        {0,0,0,1,0,0,0,1,0,1},
        {1,1,0,0,0,1,0,0,2,1},
        {1,1,1,1,1,1,1,1,0,1},
    }
    Where 0 = imageless path, 1 = image with static body(walls), 2 = image with dynamic body(blocks movable by swipe) would it work if i try to create a for loop which goes through the whole array and having conditions like if the value is 1 create this. etc etc.
    What i don't get right now is how to make the for loop go through all the values of the array. Would this work?
  • Something like this:
    for i = 1, #maze do
        for j = 1, #maze[i] do
            if maze[i][j] == 0 then
                --do nothing
            elseif maze[i][j] == 1 then
                --add static body
            elseif maze[i][j] == 2 then
                --add dynamic body
            end
        end
    end
  • thanks @ar2rsawseen I'll try this out when i get home. :D

    @unlying i've checked the screenshots looks real nice. How'd you do it? Using arrays like what i plan?
  • Ok i've managed to create the maze and all others in it. Managed to make a movable debris and a character that will walk through the maze but one problem i found was how do i make bodies snap to another body?

    i have the code
    		self.hX, self.hY = self.test.body:getPosition()
    		self.test.body:applyLinearImpulse(-2,0, self.hX, self.hY)
     
    		local timer = Timer.delayedCall(300, breaks) --break sets the linear velocity to (0,0) to stop the body.
    This works nicely when moving the character 1 block or so but the problem is that the player object (marked with red X in the attached pic) doesn't always exactly stops at the paths which are static bodies with invisible sprite and are sensors. And if somehow the player object doesn't align in the same spots as the path bodies, it can't move since it somehow hits the body of the walls.

    I tried to create a collision event which will set the X and Y of the player object to the X and Y of the path in collision but it doesn't even trigger the collision.
     
    if(BodyA.name == "hero" and BodyB.name == "path") or 
    (BodyA.name == "path" and BodyB.name == "hero") then
     
    if BodyA.name == "hero" then BodyA:setX(BodyB.getX()) BodyA:setY(BodyB.getY()) end
     
    if BodyB.name == "hero" then BodyB:setX(BodyA.getX()) BodyB:setY(BodyA.getY()) end
     
    print("test")
    end
    any insight to how this can be done?
    maze.jpg
    957 x 602 - 109K
  • Sorry don't really understand the problem, but firstly, you most probably would want to set friction to 0, so your body would slide through walls, second you would want to set fixedRotation as true so your body does not rotate on collisions.

    And as for why collisions do not occur, then would need to see more code.
    There are cases, that collisions do not occur between two static bodies, or between to sensors, but as I understood you have a dynamic body and static sensor, all should be working here.
  • xGuiltxGuilt Member
    edited August 2013
    Sorry i wasn't clear with the problem, it's just that the player object suddenly can't move maybe blocked or caught by the body of the wall. I'm trying find a way for the object to avoid making contact with the walls by moving it to the x and y of the path it steps in so it would always be in the center of the path but collisions are not registering.
    --The code creating the paths
    	for i = 1, #maze do
    		for j = 1, #maze[i] do
    			if maze[i][j] == 0 then
    local path = Bitmap.new(Texture.new("images/x2/c3path.png", conf.textureFilter))
    			path:setPosition(65 + (50*j), 50 + (50*i))
    			path:setAnchorPoint(0.5,0.5)
    			path:setScale(0.9)
    			path.body = world:createBody{type = b2.STATIC_BODY}
    			path.body:setPosition(path:getX(), path:getY())
    			SetShapes:setAsBox(path:getWidth()/2, path:getHeight()/2)
    path.body:createFixture{shape = SetShapes, density = 100, friction = 0, restitution = .2, isSensor = false}
    			path.body.name = "path"
     
    			self:addChild(path)
    end
    end
    end
     
     
    --The function used to create the player object
     
    	function gameIII:testing(x,y)
    	local test = Bitmap.new(Texture.new("images/x2/c3block.JPG", conf.textureFilter))
    			test:setAnchorPoint(0.5,0.5)
    			test:setScale(.85)
    			test:setPosition(x,y)
     
    			local SetShapes2 = b2.PolygonShape.new()
    			test.body = world:createBody{type = b2.DYNAMIC_BODY}
    			test.body:setPosition(test:getX(), test:getY())
    			SetShapes2:setAsBox(test:getWidth()/2, test:getHeight()/2)
    test.body:createFixture{shape = SetShapes2, density = 0, friction = 0, restitution = 0, fixedRotation = true}
    			test.body:setGravityScale(0)
    			test.body.name = "hero"
    			self:addChild(test)	
    			return test
    	end
    And the collision codes are at my previous post. I don't understand why the collisions aren't triggering. I've tried the collision in the minigame i've created before this and turned one of the walls into static sensor and the collision is still working.
  • currently have no idea why you don't get any events. Are you sure that event handler is seen from the that scope?
    And you set path body as isSensor = false, wasn't it supposed to be true?
    And I think you should set fixedRotation to body and not the fixture.
  • how can i test if the event handler can be seen?

    i've set it to false just to test if the objects are hitting or something.
  • @xGuilt simply put print statement in the function, without any if statements, it should be called.
  • tried that and apparently it's not printing. what do you think went wrong?
  • ok found the problem, there was no event listener added it. Collision are working fine now but only for other objects like "hero" and "walls" but not "hero" and "path"
    oh and collisions seems to be only working for "walls" in the most lowest part of the maze probably the last created by the for loop. Could it be possible the upper levels of the array are losing their body names? Because i've tried making a sensor body outside the for loop and it registers the collision even with the name "path"
  • @xGuilt again very interesting and currently have no idea why this happens.
    Only thing comes to a mind, that I see you are reusing same shape for every object. Maybe internally each body needs it's own shape and not referencing to the same on?
    Just and idea
  • I'm not sure if it's about the shape though, in the other mini game i've made which is an angry bird clone, the blocks there are made using the same shapes but they aren't made created using for loop just individually and each sprite's body is given the same name which kinda reinforces the suspicion that the looping takes away the body name and i don't think i would consider making the paths individually since the maze is like 20x18 blocks.

    Would it be possible to create a unique sprite in every loop? I tried to make sprite_name[i][j] but as expected it wouldn't work. I'm thinking that maybe if the path were given their own sprite and their sprites are given the same name then it could work
  • @xGuilt your code seems to be completely valid from that point, you create local variable path in each loop and add it to the scene, and keep reference of each body.
    Nothing seems to be wrong there.

    If you want you can post your project here or email it to me (my user name) at gmail.com and I can take a look. But I could only probably do it tomorrow.
  • I've sent it to your email.

    What i find weird is how only the lowest layer of the array gets the names for their bodies while others even though they are supposed to have their own, lost theirs.
Sign In or Register to comment.