|
Post by zxspirits on Feb 10, 2018 21:25:36 GMT
How made enemy patrolling AGD 4.6?
I I I________ I x <<<<ENEMY I l I l _______l ____________l I l I l I l I____________________l
|
|
|
Post by alessandro on Feb 11, 2018 14:30:50 GMT
Just out of my head: you should break the path into waypoints (i.e. the places where the enemy sprites changes its direction) and set a series of IF...ENDIF conditions accordingly. You should also take into account which direction the sprite is facing. This for two reasons: a) let the sprite do a round trip, and b) change the sprite image so that it does not look always the same - this uses way more memory but is much better to look at For simplicity's sake, let's suppose your sprite images for facing right, left, down and up are 0, 1, 2 and 3 respectively (following AGD's own convention for directions). Locate the starting point at 48,128, then place the sprite in the screen, facing down. The code should be as follows: IF X = 48 ; when reaching this point, the sprite will always go down IF Y = 128 LET PARAMA 0 LET DIRECTION 2 LET IMAGE 2 ENDIF ENDIF IF X = 96 ; 16 x 3, i.e. three positions down IF Y = 128 ; 96,128 is the second waypoint IF PARAMA = 0 ; if the sprite is going down LET DIRECTION 1 LET IMAGE 1 ; the sprite goes left ELSE LET DIRECTION 3 ; the sprite is returning LET IMAGE 3 ENDIF ENDIF ENDIF IF X = 96 ; the sprite has moved five positions to the left (128 - 16 x 5 = 48) IF Y = 48 ; 96,48 is the third waypoint IF PARAMA = 0 ; if the sprite is going left LET DIRECTION 2 LET IMAGE 2 ; then it goes down now ELSE LET DIRECTION 0 ; going right LET IMAGE 0 ENDIF ENDIF ENDIF IF X = 128 IF Y = 48 ; 128,48 is the fourth waypoint IF PARAMA = 0 LET DIRECTION 0 LET IMAGE 0 ELSE LET DIRECTION 3 LET IMAGE 3 ENDIF ENDIF ENDIF IF X = 128 IF Y = 96 ; 128,96 is the fifth and final waypoint LET DIRECTION 1 LET IMAGE 1 LET PARAMA 1 ; if PARAMA = 1 then the sprite is returning ENDIF ENDIF IF DIRECTION = 0 SPRITERIGHT ENDIF IF DIRECTION = 1 SPRITELEFT ENDIF IF DIRECTION = 2 SPRITEDOWN ENDIF IF DIRECTION = 3 SPRITEUP ENDIF
I'd suggest you to set the co-ordinates for each waypoint first and then compose the code accordingly. Attached to this post there is a snapshot (v4.7) for you to examine and play with. Attachments:Example.zip (32.23 KB)
|
|
|
Post by zxspirits on Feb 11, 2018 15:59:23 GMT
Thank Alessandro, i try it!
|
|