Drag and drop game

Get help using Construct 2

Post » Mon May 14, 2012 3:55 pm

Hi,
This is my very first attempt at making a game in Construct 2, also I'm a newbie in programming. I'm trying to make a very simple Drag and drop game. There are 10 objects on the screen, which the players have to match to their 10 descriptions. (So object 1 matches description 1 etc).

What I can do so far easily is to calculate score, so if the player matches 1 object correctly, he gets 1 point, and if he does so incorrectly, he loses 1 point. When an object is dragged, correctly or incorrectly, it is destroyed because I don't want them to be dragged again.

All this works fine, only thing I can't work out is, how to code that once all the 10 items are dragged (correct or not), we reach the end of the game, and I can display a Good job screen.(I'm not using time here). Is there a way to do this?

Thanks for your help.
B
5
S
1
Posts: 16
Reputation: 736

Post » Mon May 14, 2012 4:21 pm

Can someone please help? My problem with teh game is that since there are 10 different items, I can't apply instance variables...I need to put in an action which says something like once ALL the 10 objects are dragged, display the Good job screen.
Thanks for looking.
B
5
S
1
Posts: 16
Reputation: 736

Post » Mon May 14, 2012 4:44 pm

You could use a family if you want to use instance variables.
I guess you could also do it with a normal global variable. Everytime you match/mismatch a pair add 1 to that variable, and when it reaches 10 make the final screen appear. Just be sure to reset the variable at start of layout if you have more than one level.Xavier2012-05-14 16:46:21
B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Mon May 14, 2012 5:13 pm

Hi Xavier,
Thanks for your reply. I've tried Global variable, but because my events go like this, I can't have a single global variable:
A is on collison with Description A, add 1 to global variable
A is dropped (not in collison with Description A), subtract 1 from global variable

But when I do this, since there is no set number in the end, as I don't know if the players will get 5/10 or 9/10 or 1/10, I don't know what to set the final Global varioable value to be.

What I wanted to do ideally was to create something like this:
Object A in collion with Description A, add 1 to Global variable
ELSE
subtract 1 from global variable

But I can't do this since there is no else activated in the Actions tab....
sorry does this make sense? I would like to add my file but I can't seem to do that here?

Thanks
B
5
S
1
Posts: 16
Reputation: 736

Post » Mon May 14, 2012 5:39 pm

Well, then I guess you could use 2 variables, one that takes care of the score, and the other one that takes care of the number of objects. So everytime a match/mistmatch happens, you always add 1 to one variable, and also you add or substract 1 to the score variable. At the end you will have one variable that will always be 10 which will trigger the "final screen" and another one that will be 1-10 that can be used to display the score.

"Else" is not on the actions, you have to right-click on the condition, select the Add option and finally "Add Else".

You can post a .capx of your project, just upload it to dropbox public folder like everyone else.

B
63
S
23
G
17
Posts: 254
Reputation: 14,342

Post » Mon May 14, 2012 5:54 pm

object.Count will tell you how many of the objects there are. When they're all destroyed it will be 0.
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Mon May 14, 2012 7:54 pm

I just posted an example drag-n-drop matching game in the arcade, with source. Although by default it checks to see if all of the objects are matched, I updated it to also include the option to end the game based on the number of tries. Look at the comments to see what to toggle disabled to switch the end of game test.

Drag-n-drop-matching-game

If you have any questions, just ask.kittiewan2012-05-14 19:56:25
B
29
S
11
G
12
Posts: 281
Reputation: 11,878

Post » Mon May 14, 2012 10:29 pm

Thanks Xavier, ramones and Kittiwan, this was very helpful. I'll try these suggestions tomorrow and hopefully my game should work fine.
Thanks very much Kittiewan, for the game and source :)
B
5
S
1
Posts: 16
Reputation: 736

Post » Thu May 17, 2012 3:26 pm

Hi Kittiewan,
I've looked at your game's code, and it works very well! This might seem like a stupid question, but how/where in the events list does the title know to match up to it's picture? I mean since there are 10 pictures and 10 titles, and you have set Matched to true, but I can't see where you say that the cat's picture matches the title Cat...
Thanks for your help again
B
5
S
1
Posts: 16
Reputation: 736

Post » Thu May 17, 2012 3:43 pm

Glad to help.

Inside the draggableText drop event, after the check to see if ObjectImage is overlapping draggableText, there are two more subevents to see if draggableText.Text does or does not = an instance variable created on ObjectImage called Description. For this to work, when you create each instance of the ObjectImage, you have to set its description to the same as the matching text.
B
29
S
11
G
12
Posts: 281
Reputation: 11,878

Next

Return to How do I....?

Who is online

Users browsing this forum: Khamsou, Yahoo [Bot] and 21 guests