|
Post by grahamb on Apr 20, 2017 16:24:53 GMT
Hi All. I have recently become aware of Arcade Games Designer and have been really enjoying experimenting with it. Thanks to the great AGD tutorials on YouTube I have been able to get me head around most of the ins and outs of the program to create some interesting bits and pieces. However one thing I have been having a problem with is creating a successful mechanism to allow for keys and doors in a game. I have been looking around on the board as well as some other places (mainly the Facebook group) but haven't got much further forward with these. What I have so far is having a key as an object and a door as a sprite, once the key is collected this noted by a variable. When the player collides with the door it checks the variable to see if the key has been collected and if it has the door is removed. The only problem with this is once you leave the screen and return to it, the sprite door re-appears, Also, I am unsure how to make the sprite impassable. I have thought about creating the door as a block but I am not sure how I would code this in an event to manipulate a block. If anyone has had any experience with this or any help or tips using doors and keys it would be greatly appreciated...
|
|
|
Post by grahamb on Apr 21, 2017 9:00:08 GMT
I just thought I would do a quick update to this in case anyone else has this problem or is looking for ways to achieve this...
I have had best results creating a door as an object, this then means that once the door has been unlocked (collected) it does not re-appear on the screen. The only down side on this is that the door can only be an 8x8 object, however, for the purpose I am using it for currently that is not a problem.
In case you are interested this is the code I have in the Main Loop
Detectobj -- detects the object if obj = 1 -- If the object is the door (obj 1) if got 0 -- If the player has collected the key (obj 0) get obj -- Collects/removes the door else subtract 5 from y -- If you do not have the key you simply bounce away from the door. endif endif
However, I m still playing about with different methods of doing this so if anyone has any ideas, suggestions etc. then please feel free to share.
|
|
|
Post by Doug Bagnall on Apr 21, 2017 22:59:51 GMT
Your door does not need to be sprite, it would be easier if it was a "wall" block, this way you would automatically bounce off. If you have the key, then replace the "wall" door block with an "empty" door block.
If you define your blocks as: 0 = default empty background block 1 = closed door block (top of door) - WALL TYPE 2 = closed door block (bottom of door) - WALL TYPE 3 = open door block (top of door) - EMPTY TYPE 4 = open door block (bottom of door) - EMPTY TYPE
You would place the closed door blocks on your screen (we'll assume screen 1 for this example) and record their locations (let's say for this example at line 10, column 31 (top) and line 11, column 31 (bottom).
In the player event, you would have something like this: DETECTOBJ IF OBJ <> 255 GET OBJ ENDIF IF SCREEN = 1 IF GOT 0 // If the player has collected the key (object 0) LET LINE = 10 LET COLUMN = 31 PUTBLOCK 3 // open the door (top) LET LINE = 11 LET COLUMN = 31 PUTBLOCK 4 // open the door (bottom) ENDIF ENDIF
Hope this helps.
|
|
|
Post by highrise on Apr 22, 2017 0:44:28 GMT
I have played about with doors using blocks but the problem is that when you replace a wall with an empty block, the code gets confused and it creates graphical glitches - when your player sprite goes past it leaves a trace.
However, I can tell you how to stop a player from going through a sprite door - you just stop the player character moving if the sprite is ahead of it. So for example, if the door was sprite 1 then you would do something like this:
if key 0 add 2 to y if collision 1 else spriteright endif subtract 2 from y endif
The add / subtract for y looks 2 pixels ahead for a collision, so that the player doesn't get stuck on the sprite itself. You do the same thing for key 1 but subtracting from y and moving left.
In addition, you can use this routine to make the door open, and check if they have a key.
if key 0 add 2 to y 'move 2 pixels ahead if collision 1 'check door collision if k=1 'check for key other ' has key, switch to door sprite let frame=2 ' change to open original 'switch back to player spriteright 'let them move else sound 1 'make a sound to show door is locked endif else
spriteright 'no door collision, let player move
endif
subtract 2 from y 'restore player position endif
If you want the door to close behind the player, you should do a collision check on the door itself in the same way, closing it if the player is not in collision.
I hope that helps.
|
|
|
Post by highrise on Apr 22, 2017 0:48:48 GMT
p.s if you don't want the sprite to spawn, you can put something in the 'initialise sprite' section to stop it from being created if certain conditions are met, i.e if screen 1, if key 2 etc etc.
|
|
|
Post by Doug Bagnall on Apr 22, 2017 7:07:12 GMT
Yes, that block corruption problem is a know issue and has been fixed in version 4.7, which you will find in the files section of the Facebook group.
|
|
|
Post by grahamb on Apr 22, 2017 21:44:28 GMT
Thank you Doug and highrise for the info and advice, I really appreciate it! I have been playing around with both of the suggestions and both seem to do the job and work well.
I am currently using 4.7, however I am getting the trace glitch you mentioned when walking through the empty block from left to right, but walking back in the other direction removes the trace glitch.
It is awesome to get some input from other users of this great program, especially from people who have been using this a lot longer than myself.
I suppose there are a number different ways to create doors, just a little thinking 'out of the box' can help to get around lots of issues.
I have been incorporating custom blocks for the doors as blocks and using that to check if the user has the correct key in order to open the door and activate the block changes.
If screen = 1 if custom --Wrapping this in the custom block checks if the key has been collected so the door will not open until the player is at the door if got 1 let line = 15 let column = 14 putblock 4 let line = 16 let column = 14 putblock 5 else spriteleft --stops the play passing the door if they do not have the key endif endif endif
This would also work in exactly the same way using the door as a sprite.
I have also been experimenting with floor switches (walking over them) that activate doors etc which seem to work pretty well.
|
|
|
Post by highrise on Apr 22, 2017 23:02:07 GMT
Yes, I still got the corruption problem with the blocks, it seems to relate to how the player sprite is masked.
I actually tried to make a hybrid of sprites and blocks - sprites for animation, blocks because you can't shoot a laser through it. Anyway, if you are playing about with putting blocks, here is some simple code which allows you to put a block at the current sprite's location.
divide x by 8 divide y by 8 let line=x let column=y putblock xx (where xx is your block number) multiply x by 8 multiply y by 8
|
|
|
Post by Doug Bagnall on Apr 23, 2017 19:59:18 GMT
Make sure you are not putting the blocks on the screen over the top of your sprite as this will cause problems with artefacts being left behind due to the way AGD handles sprite drawing.
|
|
|
Post by highrise on Apr 24, 2017 11:16:46 GMT
I see - so if the sprite is removed, then the block placed, and then the sprite put back, all within the same script loop, it should work?
|
|
|
Post by Doug Bagnall on Apr 24, 2017 18:23:47 GMT
No, that doesn't work I'm afraid. You will need to put any blocks to the side or above/below the sprite.
|
|