Author Topic: BoulderDash butterfly movement (AI).. QB64 pmackay  (Read 5790 times)

0 Members and 1 Guest are viewing this topic.

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
BoulderDash butterfly movement (AI).. QB64 pmackay
« on: October 30, 2019, 07:36:52 am »
WIDTH 40
DIM a$(10), BX(10), BY(10), BD(10)
DIM SCREENMEM%(20, 9)
CONST BUTTERFLY = 1, SPACE = 32, WALL = 79
a$(1) = "wwwwwwwwwwwwwwwwwwww"
a$(2) = "w   .       .     .w"
a$(3) = "w .   .  .  . ... .w"
a$(4) = "w ......... . . .  w"
a$(5) = "w        .  .   .  w"
a$(6) = "w.......... ..... .w"
a$(7) = "wz                .w"
a$(8) = "w... ...   ........w"
a$(9) = "wwwwwwwwwwwwwwwwwwww"

TID% = 0
FOR I = 1 TO 10
    TID% = 0
    FOR J = 1 TO 9
        IF MID$(a$(J), I, 1) = "z" THEN TID% = TID% + 1: BX(TID%) = J: BY(TID%) = I: BD(TID%) = 1
    NEXT J
NEXT I
FOR J = 1 TO 9
    FOR I = 1 TO 20
        B$ = MID$(a$(J), I, 1)
        SCREENMEM%(I, J) = VAL(B$)
        LOCATE J, I: PRINT B$
    NEXT I
NEXT J
DO
    _LIMIT 20
    I$ = INKEY$: IF I$ = "Q" THEN EXIT DO
    GOSUB FPS
    GOSUB MOVE
LOOP
END
MOVE:
SELECT CASE BD(1)

    CASE 0
        GOTO PASSMOVE

    CASE 1 ' UP
        B$ = MID$(a$(BX(1) - 1), BY(1), 1)
        C$ = MID$(a$(BX(1)), BY(1) - 1, 1)
        D$ = MID$(a$(BX(1)), BY(1) + 1, 1)
        IF C$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BY(1) = BY(1) - 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 2: GOTO PASSMOVE
        IF B$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BX(1) = BX(1) - 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 1: GOTO PASSMOVE
        IF D$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BY(1) = BY(1) + 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 4: GOTO PASSMOVE
        BD(1) = 3

    CASE 2 ' LEFT
        B$ = MID$(a$(BX(1)), BY(1) - 1, 1)
        C$ = MID$(a$(BX(1) + 1), BY(1), 1)
        D$ = MID$(a$(BX(1) - 1), BY(1), 1)
        IF C$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BX(1) = BX(1) + 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 3: GOTO PASSMOVE
        IF B$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BY(1) = BY(1) - 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 2: GOTO PASSMOVE
        IF D$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BX(1) = BX(1) - 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 1: GOTO PASSMOVE
        BD(1) = 4

    CASE 3 'DOWN
        B$ = MID$(a$(BX(1) + 1), BY(1), 1)
        C$ = MID$(a$(BX(1)), BY(1) + 1, 1)
        D$ = MID$(a$(BX(1)), BY(1) - 1, 1)
        IF C$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BY(1) = BY(1) + 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 4: GOTO PASSMOVE
        IF B$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BX(1) = BX(1) + 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 3: GOTO PASSMOVE
        IF D$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BY(1) = BY(1) - 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 2: GOTO PASSMOVE
        BD(1) = 1

    CASE 4 'RIGHT
        B$ = MID$(a$(BX(1)), BY(1) + 1, 1)
        C$ = MID$(a$(BX(1) - 1), BY(1), 1)
        D$ = MID$(a$(BX(1) + 1), BY(1), 1)
        IF C$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BX(1) = BX(1) - 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 1: GOTO PASSMOVE
        IF B$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BY(1) = BY(1) + 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 4: GOTO PASSMOVE
        IF D$ = " " THEN MID$(a$(BX(1)), BY(1), 1) = " ": BX(1) = BX(1) + 1: MID$(a$(BX(1)), BY(1), 1) = "z": BD(1) = 3: GOTO PASSMOVE
        BD(1) = 2

        PASSMOVE:
END SELECT
RETURN
FPS:
COLOR 4, 0
FOR J = 1 TO 9
    FOR I = 1 TO 20
        B$ = MID$(a$(J), I, 1)
        SCREENMEM%(I, J) = VAL(B$)
        LOCATE J, I: PRINT B$
    NEXT I
NEXT J

COLOR 6
FOR I = 1 TO 9
    FOR J = 1 TO 20
        LOCATE I + 8, J + 10
        B$ = MID$(a$(I), J, 1)
        IF B$ = "w" THEN COLOR 6, 1: PRINT CHR$(WALL)
        IF B$ = "." THEN COLOR 14, 4: PRINT "°"
        IF B$ = "z" THEN COLOR 15, 0: PRINT CHR$(BUTTERFLY)
        IF B$ = " " THEN COLOR 0, 0: PRINT CHR$(SPACE)
    NEXT J
NEXT I
_DISPLAY
RETURN

this is my AI routine.. Not the smartest but works great.
MackyWhite

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: BoulderDash butterfly movement (AI).. QB64 pmackay
« Reply #1 on: October 30, 2019, 07:56:02 am »
thhis draws one complete FRAME with 8x Frame Animated Blocks (8 x frames per cycle) very pretty when running. have demo version but not willing to share CODE as Still Writting game. but Superfast and fully animated. Including music and sound. will upload Linux64 bit bin it requested. (demo only)

All rocks-diamonds fall as per frame cycle so its cool to see them slide down off each other. the trick is to read the screen from bottom right to top left. move pieces down (not up) so the screen draws on cycle (frame) before re looping so full animation is achieved. which i have all graphics animated, rock and diamonds falling, monsters moving all in under one frame. up to 40 of each monster and entire screen is moved and calcuated in one frame.

I have six on timers running. looking at running another to achieve the door flash when you can exit... the butterflys and fireflys where harddest to program. but they run very fast. 40 of each so 80 in total. yet on my pc there is speed loss. keyboard also runs on a on timer so i fixed the problem of the key repeat being to fast. i call fps on a timer also so i can have more time available for maths. works sweet (run beautiful program the whole thing on timers)




FPS: CLS: FOR I% = 1 TO 40: FOR J% = 1 TO 22: B% = SCREENMEM%(J%, I%): SELECT CASE B%
        CASE WALL: PUT (I% * 8 - 1, J% * 16 - 16), WALL(): CASE SPACE: PUT (I% * 8 - 1, J% * 16 - 16), SPACE()
        CASE DIRT: PUT (I% * 8 - 1, J% * 16 - 16), DIRT(): CASE MAN: PUT (I% * 8 - 1, J% * 16 - 16), PLAYER()
        CASE BOULDER: PUT (I% * 8 - 1, J% * 16 - 16), BOULDER(): CASE BOULDERF: PUT (I% * 8 - 1, J% * 16 - 16), BOULDER()
        CASE BRICK: PUT (I% * 8 - 1, J% * 16 - 16), BRICK(): CASE EXITLEVEL: IF COLLECTED% >= TOCOLLECT% THEN PUT (I% * 8 - 1, J% * 16 - 16), REXIT(): REXIT% = 1 ELSE PUT (I% * 8 - 1, J% * 16 - 16), WALL()
            CASE PICKUPKEY: PUT (I% * 8 - 1, J% * 16 - 16), PICKUPKEY()
            CASE DOORCLOSE: PUT (I% * 8 - 1, J% * 16 - 16), DOORCLOSE()
            CASE DOOROPEN: PUT (I% * 8 - 1, J% * 16 - 16), DOOROPEN()
            END SELECT: SELECT CASE ANIMATION%
            CASE 1
                IF B% = DIAMOND THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND1()
                IF B% = FUNGUS THEN PUT (I% * 8 - 1, J% * 16 - 16), FUNGUS1()
                IF B% = FLUTTERFLY THEN PUT (I% * 8 - 1, J% * 16 - 16), FLUTTER1()
                IF B% = BOXER THEN PUT (I% * 8 - 1, J% * 16 - 16), BOXER1()
                IF B% = EXPLODEA THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM1()
                IF B% = EXPLODEB THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM1(): _SNDPLAY BOOMSOUND
                IF B% = MAJIC THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC1()
                IF B% = MAJICROCKROCK THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC1()
            CASE 2
                IF B% = DIAMOND THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND2()
                IF B% = FUNGUS THEN PUT (I% * 8 - 1, J% * 16 - 16), FUNGUS2()
                IF B% = FLUTTERFLY THEN PUT (I% * 8 - 1, J% * 16 - 16), FLUTTER2()
                IF B% = BOXER THEN PUT (I% * 8 - 1, J% * 16 - 16), BOXER2()
                IF B% = EXPLODEA THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM1()
                IF B% = EXPLODEB THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM1()
                IF B% = MAJIC THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC2()
                IF B% = MAJICROCK THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC2()
            CASE 3
                IF B% = DIAMOND THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND3()
                IF B% = FUNGUS THEN PUT (I% * 8 - 1, J% * 16 - 16), FUNGUS3()
                IF B% = FLUTTERFLY THEN PUT (I% * 8 - 1, J% * 16 - 16), FLUTTER3()
                IF B% = BOXER THEN PUT (I% * 8 - 1, J% * 16 - 16), BOXER3()
                IF B% = EXPLODEA THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM2()
                IF B% = EXPLODEB THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM2()
                IF B% = MAJIC THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC3()
                IF B% = MAJICROCK THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC3()
            CASE 4
                IF B% = DIAMOND THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND4()
                IF B% = FUNGUS THEN PUT (I% * 8 - 1, J% * 16 - 16), FUNGUS4()
                IF B% = FLUTTERFLY THEN PUT (I% * 8 - 1, J% * 16 - 16), FLUTTER4()
                IF B% = BOXER THEN PUT (I% * 8 - 1, J% * 16 - 16), BOXER4()
                IF B% = EXPLODEA THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM3()
                IF B% = EXPLODEB THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM3()
                IF B% = MAJIC THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC4()
                IF B% = MAJICROCK THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC4()
            CASE 5
                IF B% = DIAMOND THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND5()
                IF B% = FUNGUS THEN PUT (I% * 8 - 1, J% * 16 - 16), FUNGUS4()
                IF B% = FLUTTERFLY THEN PUT (I% * 8 - 1, J% * 16 - 16), FLUTTER5()
                IF B% = BOXER THEN PUT (I% * 8 - 1, J% * 16 - 16), BOXER5()
                IF B% = EXPLODEA THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM3()
                IF B% = EXPLODEB THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM3()
                IF B% = MAJIC THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC5()
                IF B% = MAJICROCK THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC5()
            CASE 6
                IF B% = DIAMOND THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND6()
                IF B% = FUNGUS THEN PUT (I% * 8 - 1, J% * 16 - 16), FUNGUS6()
                IF B% = FLUTTERFLY THEN PUT (I% * 8 - 1, J% * 16 - 16), FLUTTER6()
                IF B% = BOXER THEN PUT (I% * 8 - 1, J% * 16 - 16), BOXER6()
                IF B% = EXPLODEA THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM2()
                IF B% = EXPLODEB THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM2()
                IF B% = MAJIC THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC6()
                IF B% = MAJICROCK THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC6()
            CASE 7
                IF B% = DIAMOND THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND7()
                IF B% = FUNGUS THEN PUT (I% * 8 - 1, J% * 16 - 16), FUNGUS7()
                IF B% = FLUTTERFLY THEN PUT (I% * 8 - 1, J% * 16 - 16), FLUTTER7()
                IF B% = BOXER THEN PUT (I% * 8 - 1, J% * 16 - 16), BOXER7()
                IF B% = EXPLODEA THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM1()
                IF B% = EXPLODEB THEN PUT (I% * 8 - 1, J% * 16 - 16), BOOM1()
                IF B% = MAJIC THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC7()
                IF B% = MAJICROCK THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC7()
            CASE 8
                IF B% = DIAMOND THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND8()
                IF B% = FUNGUS THEN PUT (I% * 8 - 1, J% * 16 - 16), FUNGUS8()
                IF B% = FLUTTERFLY THEN PUT (I% * 8 - 1, J% * 16 - 16), FLUTTER8()
                IF B% = BOXER THEN PUT (I% * 8 - 1, J% * 16 - 16), BOXER8()
                IF B% = EXPLODEA THEN PUT (I% * 8 - 1, J% * 16 - 16), DIAMOND1(): SCREENMEM%(J%, I%) = DIAMOND
                IF B% = EXPLODEB THEN PUT (I% * 8 - 1, J% * 16 - 16), SPACE(): SCREENMEM%(J%, I%) = SPACE
                IF B% = MAJIC THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC8()
                IF B% = MAJICROCK THEN PUT (I% * 8 - 1, J% * 16 - 16), MAJIC8()
                IF MANDIED% = 1 THEN MANDIED% = -1
END SELECT: NEXT J%: NEXT I%: COLOR 34: LOCATE 23, 1: PRINT "CAVE - "; LEVEL; "     SCORE - "; SCORE%: PRINT "      LIVES - "; LIVES; " TIMER:"; MAJICCOUNT%;: LOCATE 1, 1: _DISPLAY: RETURN




TIMER1 = ANIMATION SPEED (ANIMATION = ANIMATION + 1) IF > 8 ANIMATION = 0 : TIMER SPEED IS .06  so i call this .06 times every 8 FPS call
TIMER2 = FPS (MAIN CALLER FOR FRAMES PER SECOND) SET TO .03 (=SMOOTH AND ANIMATED X 8 DIFERENT FRAMES PER SPRITE)
TIMER3 = KEYBOARD ROUTINE
TIMER4 = ROCKS AND DIAMONDS FALL ROUTINE
TIMER5 = BUTTERFLY MOVEMENT AI
TIMER6 = FIREFLY MOVEMENT AI
TIMER7 = AMOEBAE TIMER (RUNS FOR SEC COUNT)
TIMER8 = MAJIC TILES (DROP ROCK THROUGH AND RECEIVE A DIAMOND). ALSO DISABLE WHEN OUT OF TIME.
TIMER9 = LEVEL LENGTH COMPLETE
TIMER10 = FLASH EXIT WHEN GOT ENOUGH DIAMONDS
« Last Edit: October 30, 2019, 08:33:58 am by PMACKAY »
MackyWhite

Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: BoulderDash butterfly movement (AI).. QB64 pmackay
« Reply #2 on: October 30, 2019, 08:02:41 am »
the below download is just my butterfly AI. Works great. Not included is the Firefly. Firefly is reverse pattern upside down. took me a day to work it out a pattern to replicate. I am not good with maths. but i got it. :)
« Last Edit: October 30, 2019, 08:35:19 am by PMACKAY »
MackyWhite

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: BoulderDash butterfly movement (AI).. QB64 pmackay
« Reply #3 on: October 30, 2019, 10:44:17 am »
Hi PMACKAY! It will be good if you put the code in codebox. ;))
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: BoulderDash butterfly movement (AI).. QB64 pmackay
« Reply #4 on: October 30, 2019, 12:10:59 pm »
PMACKAY, you're back! Bolder than ever!

Say is there something here you want to discuss, maybe this should be in Programs you want to show off (as well as the code easier to copy and test if in code blocks, follow the arrow...

  [ You are not allowed to view this attachment ]  


Offline PMACKAY

  • Forum Regular
  • Posts: 188
  • LIFE is Temporary
    • View Profile
Re: BoulderDash butterfly movement (AI).. QB64 pmackay
« Reply #5 on: November 23, 2019, 07:33:48 pm »
here is the test run in zip format. i am looking for someone who would like to help me debug my code, speed it up more and make this better than it is. I have included source code. its a mess. but fast and works.

* Needed to add are rock fall on man detection
* More monsters (bugs) - currently has two which are Fireflys and Butterflys
* Put all maps on harddisk rather than in same bin file
* Maybe different Music and Sound effects
* A tittle screen and score holding routines
* Recode the door for better detection, routine to open door when key got to open other area of screen
* Glow routine for glow around firefly (unsure how to go about this) without using too many frames

This is just a project I am doing for fun. anyway atleast i wont have to purchase a copy :) 
This is all my code. just messy and needs a good clean up.
MackyWhite