Level Editor with Grid

For questions about using Classic.

Post » Mon Apr 19, 2010 2:40 pm

Hello! Another Help Thread by me for you! :lol:


I planned to make a level editor. It has a grid with 32x32 big blocks. I wanted to make this with an array.

When the player pastes a Wall at "x 1 y 1", it should get a value of "1". Then, when the player puts the player start point at "x 2 y 2", it should get a value of "2".

Now, is it possible, that there is an event, that just says, every coordinate with value 1, creates a wall object and every coordinate with value 2, creates a player object?
Or is it only possible by doing 200 events for every point that looks if the value is this, then do that?
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Mon Apr 19, 2010 3:04 pm

Start of layout
for each in array
>-value at current x,y is equal to 1
-->system create object wall at current x,y * 32
>-value at current x,y is equal to 2
-->system create object player at current x,y * 32
Image Image
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

Post » Mon Apr 19, 2010 7:47 pm

Thank you, this works like a charm!

[Edit]Grr, somehow, I can't make the array save the value to the place of the wall. I tried to do with x to 640 and y to 480. But this can make the file to 4MB big.
I want to use for example:
Wall is at x=32 and y=416
Array should save this as x=1 y=1

I could do this with events for every place in the grid, but than I would have 234 Events. :?
Any ways to make this smaller.
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Thu Apr 22, 2010 5:41 pm

Maybe I didn't clearly explain my problem.

I tried the solution by newt and it works perfectly fine. However, the array technique I wanted to use was for Levels to download. I planned to allow people to upload their own levels.

Now, the thing is, I first made the array size like this:
x - 640
y - 480
z - 1

The problem is, the file get's extremly big. It's 4MB big!
So I thought to make this like the picture in the first post. Using only this:
x - 18
y - 12
z - 1

This makes the file tiny and more acceptable to download the file. The thing is, the only way I know is, to make event to test what place the object is:
> Wall is in position x=32, y=419
-> Add value 1 at Array (x=1, y=1)

To do this, I would have to make a lot of events. That's why I want to ask, is there any other way to make as less events as possible, not to cluter the event sheet?
B
7
S
1
G
2
Posts: 87
Reputation: 1,099

Post » Thu Apr 22, 2010 8:38 pm

First you have to decide wether your levels should be pixel-based or grid-based. Either way you don't have to set up an array of huge sizes.

1) Pixel-based
Easiest way is to use S. ([url:m11q4z8h]http://www.scirra.com/forum/viewtopic.php?f=2&t=4791&hilit=lucid+s&start=47[/url:m11q4z8h]) If you don't want to use S, you can do the following:

Let the user place the objects. When it comes to saving, you count the objects on a global scope and so creating an id (object A 20x = 0-19, object B 12x = 20-31, etc) and then "misuse" a hash table. For every object you create 3 keys named
-"whateveryoulike" & str(globalcounter) (content would be the id for the object type, like wall or player start point)
-"whateveryoulike" & str(globalcounter) & "x" (content would be the horizontal position)
-"whateveryoulike" & str(globalcounter) & "y" (content would be the vertical position)
When loading, you use HashTable.KeyCount / 3 to get the number of objects. Then in a for loop you access the values via "whateveryoulike" & str(LoopIndex) and create the objects according to their type and position.

2) Grid-based
This version has fixed positions on the layout, depending on the cell size the grid represents. So you have to make sure, the objects are correctly placed at the fixed positions. The rest is easy. When the user wants to save, loop through your grid size to see what object is at that position and add the value to the array. Assuming the grid is 16x16, representing cell sizes of 32x32, and the objects hotspot is upper left, this would be:
+For loopx from 1 to 16
For loopy from 1 to 16
++objectwall.x equal to (LoopIndex("loopx") - 1) * 32
objectwall.y equal to (LoopIndex("loopy") - 1) * 32
-Array: Set index (LoopIndex("loopx"), LoopIndex("loopy")) to 'yourobjectidforwall'
++objectplayer.x equal to (LoopIndex("loopx") - 1) * 32
objectplayer.y equal to (LoopIndex("loopy") - 1) * 32
-Array: Set index (LoopIndex("loopx"), LoopIndex("loopy")) to 'yourobjectidforplayer'
++etc for all your object types
When loading you do as newt wrote.

If your objects hotspots are not upper left just add the distance from upper left to the hotspots position like this:
objectwall.x equal to (LoopIndex("loopx") - 1) * 32 + 'distanceX' (for example 16, if hotspot is centered)
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Tue Apr 27, 2010 7:19 pm

Thank you for the solution. I will use S. Just have to read the tutorials, so I can understand this. :lol:
B
7
S
1
G
2
Posts: 87
Reputation: 1,099


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: Yahoo [Bot] and 0 guests