|
Post by thelonemagpie on Aug 28, 2015 21:37:39 GMT
Been trying to create a gate that is opened by collecting 4 gems.
Q is the variable for gems collected, set up in Game Initialisation.
In Main Loop 1, I have the following;
DETECTOBJ IF OBJ=255 ELSE IF OBJ=4 [the gate] SUBTRACT 10 FROM X [bounces player upwards away from gate] ELSE GET OBJ [The only other OBJs are "gems"] ADD 1 TO Q [This line seems to be the problem] ENDIF ENDIF
IF Q = 4 REMOVE OBJ 4 ENDIF
When I remove the line ADD 1 to Q, the player gets the obj no problem. When I put the line back in, it gets the object, but the player is removed, and OBJ 4 ISN'T removed.
Any ideas what I'm doing wrong?
|
|
|
Post by lamptonworm on Aug 29, 2015 14:02:54 GMT
Hi,
I'm new here, so this may be wrong! I think "REMOVE" applies to sprites only, not objects. You can use "GET OBJ" on the gate to have it 'vanish' perhaps, or use a sprite for the gate instead and use collision/remove in it's event code?
Cheers, LW.
|
|
|
Post by thelonemagpie on Aug 31, 2015 0:32:35 GMT
Cheers, it didn't occur to me that REMOVE only worked with sprites. Doh! I've now got collectable sprites that allow me GET OBJ once I have all the sprites. I was afraid that using sprites would result in them returning once I went offscreen, but they don't return.
|
|
|
Post by alessandro on Sept 8, 2015 11:23:28 GMT
If you need an object to "disappear" soon after you get another one, or after you have used it, you could set an unreachable 16x16 pixel area with the same INK and PAPER so that you translate your character there, let it drop the object (it becomes "invisible") and immediately go back to the previous position. I did this for some of the puzzles in Cronopios y Famas and in the third chapter of Cousin Horace.
|
|
|
Post by andrewvanbeck on Sept 9, 2015 8:03:19 GMT
I don't think 'REMOVE OBJ 4' will work, AGD events aren't that advanced.
If it's only the 4 gems to open 1 door, then I'd just check each gem object with GOT...
IF GOT 1 IF GOT 2 IF GOT 3 IF GOT 4 REMOVE ENDIF ENDIF ENDIF ENDIF
Inside the doors event of course, the REMOVE command will only work with a sprite in it's own event or maybe by detecting it with another sprite.
However, if you just want the player to collect all the objects in the screen before a door opens, then that can be done quite dynamically. You could GET all the objects at the start of the game, and PUT some of the objects on the screen, so any objects on screen aren't in the players inventory. So, if you loop through the objects and find one that the player doesn't have, then you know there's still an object to collect.
If you have 5 objects maximum, in the game initialisation event...
LET A = 1 REPEAT 5 GET A ADD 1 TO A ENDREPEAT
So, all those objects are assigned to the player.
Then in the player event:
DETECTOBJ IF OBJ > 0 GET OBJ ENDIF
And if you have a door event:
LET A = 1 REPEAT 5 IF GOT A ADD 1 TO A ELSE EXIT ENDIF ENDREPEAT REMOVE
That would make the door sprite disappear when all objects have been collected - you could have it animate as well of course - like rather than removing the sprite, you could set it to a different event that just animates a sprite. I like to have an event just for playing sprites then removing them, real handy for death animations etc... usually in event 8 I'd have:
ANIMATE IF FRAME 0 REMOVE ENDIF
Then it's easy to set a type to 8 and make any necessary adjustments to the image and frame. It also lets you ignore any collisions or other behaviour that the sprites own event might do.
|
|