Get help using Construct 2

### » Thu Sep 20, 2012 1:40 pm

I am trying to create a game like this

But I am really struggling.

What would be the best way to have multiple sprites, draggable in set directions, along a grid? (Can't use families)

Also, how can I do collisions? Solids don't seem to work, when using drag/drop.

B
11
S
2
Posts: 127
Reputation: 1,532

### » Thu Sep 20, 2012 8:16 pm

Use one object type with a animation frame for each car.
The drag and drop is perfect for this and you can customize it with it's conditions.

If you save the position of the piece you're dragging to some variables at "on drag start" you can keep motion in one direction. For example for horizontal only motion make an event like this:
is dragging
or
on drop
---set y to start_y

When you drop the piece is when you want it to snap to the grid. It greatly simplifies things if the sprite's origin is to the top left since the cars are different sizes. Here is the formula for snapping to a grid: round(self.x/gridsize)*gridsize.

For collisions you could find the low and high limits of the motion so you could do the positioning like this:
is dragging
or
on drop
---set x to clamp(self.x, low, high)
---set y to start_y

A way to find the low and high would be to do a looping event under "on drag start" to first move the car left by grid steps until there is a wall to it's left. Save that as the low_x and then do a loop to do the same but moving right to find high_x.
ex.
on drag start:
--- repeat 10 times:
------[inverted] car overlaps wall at offset -gridsize
------ ++ car: set x to self.x-gridsize
------ ++ set low_x to car.x
--- repeat 10 times:
------[inverted] car overlaps wall at offset +gridsize
------ ++ car: set x to self.x+gridsize
------ ++ set high_x to car.x
B
75
S
21
G
47
Posts: 4,659
Reputation: 36,683

### » Fri Sep 21, 2012 9:17 am

Thanks R0J0

I am not entirely sure what I am doing wrong, I have implemented as suggested, but I may be misunderstanding your markings before the events.

And also, would the Variables be Instance or Global Variable?

Would you mind taking a look for me?

http://dl.dropbox.com/u/67025590/C2/game/Attempt%204.capxPixiefingers2012-09-21 09:25:34
B
11
S
2
Posts: 127
Reputation: 1,532

### » Fri Sep 21, 2012 7:06 pm

B
75
S
21
G
47
Posts: 4,659
Reputation: 36,683