Grid based game

Non-platform specific questions.

Re: Grid based game

Postby skydereign » Sat Oct 22, 2011 12:12 am

No worries there. It just wasn't clear (to me) why you were suggesting using linked lists for this. I understand you wanting reusability, but does that mean that even small tasks will use that structure? Kind of seems you end up bypassing a lot of the simplicity that gE provides (although you end up creating your own). But, to each their own.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Grid based game

Postby EvanBlack » Sat Oct 22, 2011 12:42 am

Define small task?

I personally don't like making small things, I'm American. XD

I wouldn't use a linked list for everything XD Sure, gE provides a lot of things for you to make it simpler, and I don't write a script for everything. I kind-of use gE like I would use visual studio, I create the functions and variables I need, but anything that only needs to be created once and in the beginning and doesn't involve a large number of tedious objects then I just use the tools provided. But sometimes using the tools provided in gE can be far more tedious to set and change especially if you need to calibrate it where as in script you could just type in a few things to change it all at once.

Also, smaller projects often make it easier to learn advanced topics. That way if there is a problem you can look over what happened and try to understand what went wrong. Then once you know about both topics you can decide for yourself which you would need.

It didn't seem that a 3x3 area was his main goal. It just seemed like he wanted a small project to begin learning more about how it all works.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Grid based game

Postby skydereign » Sat Oct 22, 2011 1:34 am

I'm American as well, though I've never let nationality influence the way I make games. But, as I said before, I get where you are coming from, and due to your inclination to larger things, I understand even more so. Usually I keep to using functions, so that I only need to make the changes in global space. Anyway, we kind of hijacked this thread. foleyjo, did you end up getting what you needed? By now there is a lot of information on this that you didn't really ask for...
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Grid based game

Postby foleyjo » Sun Oct 23, 2011 5:03 pm

Haven't managed to work on it for a couple of days due to other commitments.

Probably going to try to do 2 different versions. 1 with linked lists and one without.
That way I get to learn both methods
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Grid based game

Postby foleyjo » Tue Oct 25, 2011 1:52 pm

OK have a bit of time to work on this again. Going to start again from scratch forgetting everything I've done before.
Just wanted to quote this

EvanBlack wrote:It didn't seem that a 3x3 area was his main goal. It just seemed like he wanted a small project to begin learning more about how it all works.


It's correct. My main goal will be to have a large grid. However I want to get things working on a 3x3 grid first so i know what I'm doing and I want to use a method where I only have to worry about changing the grid itself and not worry about the effect it will have on everything else.

Now one thing that I am still unsure about after all of this is how to actually draw the grid :lol: .
Do I use 1 big grid image or should I be using 1 square and then the clones.
If using the square do I add one at a time or do I use the code to put them in the correct locations?
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Grid based game

Postby skydereign » Tue Oct 25, 2011 11:14 pm

I believe both systems use clones to form the grid. Essentially you'd use two for loops, drawing the two dimensions. Using the function I posted, all you need to do is change the num_columns and num_rows, to change the size of the grid. Then, when you create it, you use a for loop. If you have separate values preloaded, you'll have to make a two dimensional array. Otherwise, you can use getclone2 functions to change the color (assuming initial conditions are the same).
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Grid based game

Postby foleyjo » Wed Oct 26, 2011 2:02 pm

ME AGAAAIIINN :lol:

Thanks Sky. I got the grid built and can change the grid size. I used the clones and for loops. (Though on first try I made a mistake with the loop and ended up with a freeze while thousands of squares were put accross the screen :? )

I have used a simple cloneindex to see what number square is clicked on on the grid.

This means part 1 of the to do list is complete. So now I need to locate the squares on either side of the one I clicked.
Looking through every thing I have a question about Evans method.

Code: Select all
 Square TopLeftSquare, TopMiddleSquare, TopRightSquare,
 CenterLeftSquare, CenterMiddleSquare, CenterRightSquare,
 BottomLeftSquare, BottomMiddleSquare, BottomRightSquare;
// Put all the squares into an array for later use.
 Square *grid[9] = { &TopLeftSquare, &TopMiddleSquare, &TopRightSquare,
                  &CenterLeftSquare, &CenterMiddleSquare, &CenterRightSquare,
                  &BottomLeftSquare, &BottomMiddleSquare, &BottomRightSquare };


I (kinda) understand how this works but surely this method is only useful if I stick to the same 3x3 size grid.
What happens if I then decide to have a 30x30 grid. Surely I'm not expected to input every single square with a name?

**Actually ignore that I see you have already mentioned that in your comparison to arrays later in the thread.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Grid based game

Postby foleyjo » Wed Oct 26, 2011 5:32 pm

Sky the code that you suggested doesn't appear to work for me. Probably because I'm not using it right.

The X and Y value that I pass to get_cindex, is that the X and Y value of the grid square that is being selected?



int num_columns = 3;
int num_rows = 3;

int
get_cindex (int gx, int gy, int dir)
{
int x_offset = 0;
int y_offset = 0;

switch(dir)
{
case 0: // right
x_offset=(gx+1 < num_columns);
break;

case 1: // up
y_offset=-(gy-1 >= 0);
break;

case 2: // left
x_offset=-(gx-1 >= 0);
break;

case 3: // down
y_offset=(gy+1 < num_rows);
break;
}

if(x_offset+y_offset != 0) // square is valid (would return 0 if square isn't valid)
{
// gets the cloneindex of position (gx,gy)
return ((gy+y_offset)*num_columns + (gx+x_offset));
}
return -1; // does not exist
}
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Grid based game

Postby skydereign » Thu Oct 27, 2011 12:06 am

You use the grid xy, not the real xy, though as I said you can do a pretty simple conversion. Here is a ged of it, the function currently doesn't get the diagonals but those are pretty simple as well. Anyway, attached is a ged of it working. Click the text actor, and edit the text so it is some number, some number (so for example 5,7) then press enter. It'll create the grid, and clicking them will select the tiles next to it.
http://game-editor.net/media/kunena/attachments/66/grid_cindex.zip
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Grid based game

Postby foleyjo » Thu Oct 27, 2011 10:42 am

GOT IT :D Thanks Sky. I was forgetting to divide by the width and height to get the start location of the grid.

Now I have a re-sizable grid that tells you the square you click on and all the squares around it.

I think I should be ok from here.
I have had a couple of ideas how to proceed.

I am going to use 2 grids. One visible and then one over the top invisible. The visible one won't do anything but look pretty. The invisible will detect the clicks and then I can use this to add things into the grid. Not sure if this is the best method but I was finding if I added an actor to a grid square it would register the mouse clicks on the actor rather than the square.

I want to get the hang of this linked list/ structure method so I was thinking of using a loop at the start which builds the structure telling each square its top,bot,left and right values. Then change the mouse clicks to find the adjacent cells from the structure.(if that makes sense)
I need the cells to register another value based on the actor attached to it which is why I am going to try this method. If I can't work it out I will use an array to register the value.

There may be some areas that I struggle with at a later stage. 1 is the AI. it's a 2 player game. I may just make it 2 players with no computer player.
The 2nd is the timing of an event. This will make sense when I get further through.

Right now though I am ready to progress so thank you all who helped especially Sky and Evan . I'll upload a demo as soon as there is enough going on to show what I am aiming for.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Grid based game

Postby foleyjo » Thu Oct 27, 2011 3:44 pm

DON'T GOT IT :oops:

Tried to use a structure thing but keep getting a memory related error.

I can't get my head around the linked list stuff but I would really like to. So could someone have a look and see where I went wrong.

If not I will just need to use an array system which isn't too bad. I would just prefer to do it differently so I can learn more.

Knowledge is power and all that
Attachments
gridz.ged
(7.53 KiB) Downloaded 72 times
data.rar
(70.07 KiB) Downloaded 71 times
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Grid based game

Postby EvanBlack » Fri Oct 28, 2011 1:13 am

Code: Select all
for (i=0;i<j;i++)
  {
    ThisClone = getclone2("GridSquare",i);
    xx=(ThisClone->x-getclone("GridSquare.0")->x)/width;  //Grid location
    yy=(ThisClone->y-getclone("GridSquare.0")->y)/height;


    grid[0]->SquareNumber = ThisClone->cloneindex;
    grid[0]->TopSquare= grid[get_cindex (xx,yy,1)];
    grid[0]->LeftSquare=grid[get_cindex (xx,yy,2)];
    grid[0]->RightSquare= grid[get_cindex (xx,yy,0)];
    grid[0]->BottomSquare= grid[get_cindex (xx,yy,3)];
  }


I don't even know that that does....

But also its possible you are reading out of the bounds of the grid array.

You need need to do some checking to see if that part of the array even exists. Or just make sure that your not accessing out of bounds of the array.

Your code is a mess BTW :D Its hard to read and you are initializing variables and functions and structures randomly it seems.

Also Where is CELL defined? I am just can't follow this and I dont have enough time to do anything with it right now.

UPDATE:
Your problem is you have two grid arrays. 1 is a 1D array of Square pointers, but you don't allocate memory for the Squares, and you have Grid, which you allocate memory for it but don't use it. I am really confused with this code you wrote.
(\__/) ( Soon... The world)
(O.o )< will be mine!____)
(> < )
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Bunny Overlord 2012!
EvanBlack
 
Posts: 202
Joined: Fri Sep 30, 2011 10:17 am
Score: 19 Give a positive score

Re: Grid based game

Postby foleyjo » Sat Oct 29, 2011 9:25 am

Sorry 'bout the mess. It's the way I learn. Then when I know what I'm doing I start again from scratch using what I learned.

The for loop is using the code from Sky. It is being used on each square to find out the clone index of each square that is adjacent.

I think the confusion comes from me not understanding how to use the linked lists and trying to use part of everything suggested in the same code. I think for now I will stick with the Array method because I understand how arrays work and I'm getting much further with it.
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Re: Grid based game

Postby foleyjo » Sat Oct 29, 2011 1:17 pm

OK getting there now.

Though I have a new problem.

I've uploaded what I have done so far and this time the code is more organized. :wink:

If you click on the grid it will add a blob.
Clicking again will add another blob.
When there are more than 3 blobs the blob will be destroyed and all the surrounding grid squares will add a blob.

The problem I am having now is that when there are 2 or more adjacent grid squares with 3 blobs instead of getting a chain reaction it causes a freeze.
Attachments
Gridz.ged
(5.13 KiB) Downloaded 75 times
data.zip
(12.85 KiB) Downloaded 71 times
KISS -Keep It Simple Stoopid
foleyjo
 
Posts: 275
Joined: Mon Jul 09, 2007 1:15 pm
Score: 15 Give a positive score

Previous

Return to General

Who is online

Users browsing this forum: No registered users and 1 guest