I will be away from computer until tomorrow, but I will write you a up a quick Check function that can check matches and if it can swipe down/left etc. which should give you an idea of how to move forward
Thanks m8 for helping. I think the first game you make is the most important game to understand it all.
There are 2 scenarios I can come up with but I donāt know if corona supports that.
First one:
In the grid make a variable with the name for the sprite. Make a draw function that checks the whole grid and draws all the sprites.(loop).
Second one:
Moving the display elements in the arrays but I donāt know if this is possible I donāt understand how you can move a display that is already in a element in a array. Every time i get into the gridObj directly and move the x nothing happens. And to check if there is a match I need to move the elements in the array.
I tried allot but i dont think this can workā¦you cant know which icon is where to match i really think i have to use the grid and shift the objects with every swipe and draw the animation.
function scene:AddMiddleIcons() local tmpIcons = {"icon\_1", "icon\_2", "icon\_3", "icon\_4", "icon\_5"} local speed = 500 for columnX=1,7 do local gridObj = self.topGrid[columnX][6].gridObj print(gridObj.x) local iconObj = display.newImage(self.sceneGroup, self.gameArtSheet , self.gameArtInfo:getFrameIndex(tmpIcons[math.random(1, 5)])) self.topGrid[columnX][6].gridObj = iconObj iconObj.anchorX, iconObj.anchorY = 0.5, 0.5 iconObj.x = gridObj.x + (gridObj.width \* .5) iconObj.y = (gridObj.y + (gridObj.height \* .5)) self.topGrid[columnX][6].gridObj = iconObj iconObj.xScale,iconObj.yScale = 4 iconObj.alpha = 0 transition.to(iconObj, {transition = easing.outBounce, time=speed,alpha = 1,xScale = 1,yScale = 1, onComplete=function(iObj) self.topGrid[columnX][6].iconObj = iObj self.topGrid[columnX][6].active = true end }) speed = speed + 100 end local mContainer = display.newRect((display.contentWidth \* .5),(self.topBG.y + self.topBG.height), 749, 100) mContainer.anchorX, mContainer.anchorY = 0.5, 0 mContainer:setFillColor(0,0,0,0.01) mContainer.touch = function(gObj, gEvent) local swipeLengthX = math.abs(gEvent.x - gEvent.xStart) local swipeLengthY = math.abs(gEvent.y - gEvent.yStart) local t = gEvent.target local phase = gEvent.phase if "began" == phase then return true elseif "ended" == phase or "cancelled" == phase then if gEvent.xStart \> gEvent.x and swipeLengthX \> 10 then print("swipe left") shift(self.topGrid,"left") for columnX=1,#self.topGrid do local tmpObj = self.topGrid[columnX][6].gridObj if tmpObj.x \< 85 then tmpObj.x = 742 transition.to(tmpObj, {transition = easing.outBack, time = 200, x = 722, onComplete = function(iObj) end}) else -- table.insert(self.topGrid[columnX - 1],6,tmpObj) -- table.remove(self.topGrid[columnX - 1],6) transition.to(tmpObj, {transition = easing.outBack, time = 200, x = tmpObj.x - 107, onComplete = function(iObj)end}) end end elseif gEvent.xStart \< gEvent.x and swipeLengthX \> 10 then print("swipe right") for columnX=1,#self.topGrid do local tmpObj = self.topGrid[columnX][6].gridObj if tmpObj.x \> 710 then tmpObj.x = 60 transition.to(tmpObj, {transition = easing.outBack, time = 200, x = 80, onComplete = function(iObj) end}) else transition.to(tmpObj, {transition = easing.outBack, time = 200, x = tmpObj.x + 107, onComplete = function(iObj)end}) end end elseif gEvent.yStart \< gEvent.y and swipeLengthY \> 10 then print("swipe down") for columnY=1,11 do local tmpObj = self.topGrid[1][columnY].gridObj transition.to(tmpObj, {transition = easing.outBack, time = 200, y = tmpObj.y + 100, onComplete = function(iObj) end}) end end end return true end mContainer:addEventListener("touch") mContainer:toFront() end
Pretty sure it will work as below is one of the very first games I made using corona and it was made in under a week using the same type of logic and it isnāt very polished and was more of a proof of concept for something else I was working on.
Google Play
https://play.google.com/store/apps/details?id=com.purplebean.uguessit
iTunes
https://itunes.apple.com/us/app/u-guess-it/id635813137?mt=8
It plays much better on iPad as I had no idea what was what on Google Play at the time
Anyhoot, I am going to piece together some stuff for you just got really swamped next few days then I will be getting back to it
I tried everything to get it into a table and move the grid but lua doesnt have allot of choice like other languages. you cant even store a 2d array simple, its very weird lol.
But what i wanted to say is what was your idea to do a check if the same iconsā¦can you explain itā¦?
Hey Christopher I got a long way with your help. I am moving the grids and so on but I have a question.
When the icons enter the field with a transition to. Sometimes I am moving that column up or down but the transition to is already set to go to the y that was empty at the moment it moved but after I moved the column up a icon is shifted to it. Now the icons are on top of each other and one does not exist in the table (itās overwritten)
How can such a problem be solved if you know what I mean ?
Without knowing more it sounds like you need an array that contains both x/y for example.
local grid = {} for x = 1, 5 do --Lets say 5 rows across grid[x] = {} --Create empty table for columns. for y = 1, 5 do --Lets say 5 columns down. grid[x][y] = {iconKey = "fred", pushed = false, center = false, iconObject = someImageObj} --fill slot with info end end
So if you add your icon āimageā to the iconObject = of the table you will now have access to it by simply saying
grid[2][1].iconObject -> this would be the second row and the first column icon.
as you move stuff around you can simply either destroy the iconObject or swap it using that object in the correct position.
Matching would be simple too, just say something along the lines ofā¦
if (grid[1][1].iconKey == grid[1][2].iconKey and grid[1][2].iconKey == grid[1][3].iconKey) then --its a match, continue checking more or return true/false end
Granted above is pretty simplistic but gives you the general idea.
[quote=āChristopher_Bishop,post:27,topic:323818ā]
Without knowing more it sounds like you need an array that contains both x/y for example.
local grid = {} for x = 1, 5 do --Lets say 5 rows across grid[x] = {} --Create empty table for columns. for y = 1, 5 do --Lets say 5 columns down. grid[x][y] = {iconKey = "fred", pushed = false, center = false, iconObject = someImageObj} --fill slot with info end end
So if you add your icon āimageā to the iconObject = of the table you will now have access to it by simply saying
grid[2][1].iconObject -> this would be the second row and the first column icon.
as you move stuff around you can simply either destroy the iconObject or swap it using that object in the correct position.
Matching would be simple too, just say something along the lines ofā¦
if (grid[1][1].iconKey == grid[1][2].iconKey and grid[1][2].iconKey == grid[1][3].iconKey) then --its a match, continue checking more or return true/false end
Granted above is pretty simplistic but gives you the general idea. [/quote]
So in essence you say do all in one 2d array instead of one array for where the matching happens and one for the icons top or down ?
Btw this is the game I want to make⦠I am not going to clone it but I thought its a good first gameā¦
Just downloaded the game to check it out however it makes no sense to me a slid the middle row left and right but nothing happen lolā¦
But given that yes, that is how I would do it it looks like there is 7 rows and 9 columns and the ones sliding in from the top and bottom are simple transitions.to so for example build your grid layout and inside the table do something like if (y == 5) then isCenter = true end
then it is a simple if y <= 4 then it is the top row if y >5 then it is the bottom row.
if you expand this out a little bit and do a newRect at each grid location with a 0 or alpha fill 0 then when you are dropping from the top or shooting up from the bottom you simply say transition.to(newBallIMage, {y = grid[1][4].y}) etc. and so forth.
But i am still half a sleep
Haha I wonder if game design logic is always so hard. I canāt wrap my head around something that looks so easy.
So this is the idea:
Make a function that generates a grid for all columns and rows. Making sure that each object has a place for a object name, x and y.
Make a function that pushes some random objects into the generated grid (updating the object Name and x and y)
Make a function that goes through the grid and draws all ? Is this a good idea or should I fill the table with display objects instead of names ?
Am I going the right direction so far?
I wonāt be back at computer until tomorrow but I think I have most of the functions you are looking for on my old dev box that I could shoot up here for ya to get you a head start
Wow I am curious just want to finish a game from beginning to end so I can understand the logic and process much better. In tutorials you say easy and oke I can do that. But the minute you have something you canāt figure it out lol
No worries, it just takes a bit to kind of figure out how the flow works and if you are coming from C#, PHP you should be able to grasp it pretty quick you just need a basic this is how the flow works etc. and so forth⦠I found some code on one of my backups that will help you out just need to put it all together into one file and comment it so you can see itā¦Ā
Once you see it I am pretty sure the light will go off and you will just get it
I have to finish putting up my fence (weekend project) so more than likely wont be able to put it all together until tonight or tomorrow am
Hey khawtf, sorry it took me so long ended up just writing it from scratch as the old code i had was all G1.0 stuff and thought it would be easier just to write it up and had some other things going on so was doing it in between
Ok couple things.
1: If you are like me, it might be better to understand the code by just removing the comments lol.
2: I did this in under 3 hours so it is kind of ugly but you will get the idea.
3: Didnāt put a whole lot of game logic in because to be honest i have no idea how that game works.
4: The swipe for the middle row is āreal basicā and not doing any loading from left right.
5: And of course do whatever you want with it
I tried to put a few different things in just so you could get a head start on how things all come together so I ended up just making main.lua just that a main entry point and then used composer so you could see how scene stuff is put together.
Screenshot is here:Ā
Link to zip file is here:Ā https://s3.amazonaws.com/mclss/Grid.zip
Enjoy and let me know if you need help with anything else
Wow this is awsome!!! Let me dive in the code.
I really appreciate this !
No problem, just keep in mind some of it isĀ spaghetti code as i was distracted and sleep deprived lol
I can follow what you did very good. Really like it. I have a question about the grids. So you divided it up into 3 different grids. Isnāt that a bit harder to move a column down into the middle field ?
Then I would have to check where I swiped up or down and shift the icon that is moved up into the column and the one that comes from beneath into the middle column⦠Is that the best way to do this ?
Yeah, I split it up because I really didnāt understand the game and given that I didnāt understand the game I made 3 different functions so if need be you could knock it down to one function and just increase the row/column in the for x and for y
So what you could do is remove the Middle and Bottom functions (move the bottom rect up to the build top function) then just increase the x/y values in the for loop and modify the drop function to check for < 6 = Top and > 6 = Bottom and 6 = Middle
Make sense?
If I had a better idea of how the game should actually work i could modify it fairly quickly, it sounds kind of like candy crush with a twist of a sliding middle piece?
Hehe its rather simpleā¦the icons drop from the top and bottom and you can move the columns up and down you have to match them in the middleā¦its rather simple game
So basicly i have to change the first function and add to the y and remove the functions for middle and down. Change the function for swiping to move only the middle.
Right ?
having a hard time changing the function to 1. I will try it from the bottom up
Flip the showDebug at the top to true so you can see the grid lines being draw, I will have a look at it in morning as you should be able to comment out Middle, Bottom and just increase the y in the top function to for y = 1, 11 (as 11 would be the new value)Ā