Spiny Dobopty - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Spiny Dobopty (/thread-5033.html)
Spiny Dobopty - Coin - Sep 14, 2005 01:44 PM
I think the title says it all.
This is for the same game as my last post and i am being lame again i think
I want it to so when you click on a gem owned by you it spins the 8 ajacent jems counter clockwise and when you ctrl+click it spints them clockwise.
so far i have this:
x and y being the coordinates of the mouseDown event the tiles are 32x32 and there is a 10 pixel boarder around the screen thus all the tens. Can someone enlighten me as to how to get them to spin clockwise in that if, the "Gems" have are methods -x -y -owner
and -index, index refers to which index they are in the main game board array.
All I know is I will need an array to hold all ajacent tiles after that my mind goes in circles and i fall asleep .
Spiny Dobopty - akb825 - Sep 14, 2005 01:54 PM
I would do it by having an array of arrays for the gems. Basically, you have one array that holds all the rows, then for each row you have an array for the gems in that row. So when you get the 2 indices that correspond to where you click, you can get the 8 adjacent gems and move them to the next position.
BTW, with Objective C you don't have to cast the object coming out of the array. It already knows which method it needs to call.
Spiny Dobopty - Coin - Sep 14, 2005 10:50 PM
It gets mad if i remove it (the cast) because it (the compiler) thinks im trying to use NSObject's -owner.
also i read that too late and here i am:
yea its ugly and hard to read.That seems to me like it should work but it doesnt remotly, all it does right now is make all the gems move to the left side.... very depressing. Why do code tags add 700 tabs? anyone i cant read my code in a code tag!!!
Spiny Dobopty - akb825 - Sep 14, 2005 11:27 PM
Are you sure your set methods are correct? Why are you doing this: (x-(x%32)+10)? If you have your grid set up from 0 to whatever in increments of 32 (when processing it), you should just subtract 10 from x and y, then see if it's >= location and <= location + 32 (for both x and y). Also, that will be extremely slow. You're looping through all the gems 17 times: once to see which one, once for each of the 8 gems around, and for each of those times, you are looping through to set the new coordinate.
Spiny Dobopty - Coin - Sep 15, 2005 10:25 AM
I only see 2 loops. and there is a 10 px boarder around the board thus the 10s.
What are you saying im doing about the looping to set the new coordinate? and yea the set method works, i used it in all my previous movment stuff and those work fine.
Edit: i think i see what is happening. There arnt any elses so they are all happening so its pushing the gems around and around. OR something of that sort
Edited Edit: I added elses for all exept the first one, it works now exept on the first mouse down, and there is no bounds protection
Spiny Dobopty - akb825 - Sep 15, 2005 10:51 AM
I don't know why, but I thought you'd be going into a loop when setting the X and Y to find the gem. Hey, it was late! (also, I would have put the set methods in the gem object itself, but that's just me) But the fact remains that it must loop through all of the gems for each of the 8 gems you are searching for. If you used the double-array method, you'd get the x and y coordinates, you could get the 2 indices from those coordinates, then directly figure out the other indices from that. No loops required. You can do the same thing with 1 large array, but it would be a little more difficult.
Edit: the only thing I can think of for your other problem is possibly your event-handling code and the way you change the x and y coordinates to something you can check for indices.
Spiny Dobopty - Coin - Sep 15, 2005 12:12 PM
There is a seX in the gem object, but i have an array of gems that are drawn so i have to change that ones X, so it has to be in Game.
Also i got it to work bascially but the only thing is that the out of bounds protection is going to be tricky how should i handle that.
Spiny Dobopty - akb825 - Sep 15, 2005 01:22 PM
As in you go all the way to the right and it starts shifting ones you don't want? You can check to see if it's all the way in one direction, don't process the ones beyond.