hungry mouse

Upload: pierre-schippert

Post on 06-Apr-2018

230 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/2/2019 Hungry Mouse

    1/25

    ;Spielbilder(definemaus-down.)

    (definemaus-right.)

    (definemaus-left.)

    (definemaus-up.)(definecat-img-up.)(definecat-img-down.)(definecat-img-left.)(definecat-img-right.)(definekse.)

    (defineblue-black-hole-1.)

    (defineblue-black-hole-2.)

    (defineblue-black-hole-3.)

    (defineblue-black-hole-4.)

    (definehindernis-holz-hori.)(definehindernis-holz-verti.)(definehinderniss-holz-verti-ganze-seite.)(definehinderniss-holz-hori-ganze-seite.)(definehinderniss-level-6.)(definelevel-7-screen.)(definehintergrund.)(definefirst-screen-pic.)

    ;Prozedurmouse-pos,welchedasBilddermausbestimmt(definemaus-pos(lambda(g)

    (cond((string=?(game-directiong)"down")maus-down)((string=?(game-directiong)"right")maus-right)((string=?(game-directiong)"left")maus-left)((string=?(game-directiong)"up")maus-up)(elsemaus-up))))

    ;Prozedurcat-pos(definecat-pos(lambda(g)(letrec((catdirection(cat-direction(game-catg))))(cond((string=?catdirection"down")cat-img-down)((string=?catdirection"right")cat-img-right)((string=?catdirection"left")cat-img-left)

    ((string=?catdirection"up")cat-img-up)(elsecat-img-down)))))

    ;RecordderKatzebestehendaus:;-x-Koordinate(x);-y-Koordinate(y);-direction(direction);-cattick(define-record-procedurescatmake-cat

  • 8/2/2019 Hungry Mouse

    2/25

    cat?(cat-xcat-ycat-directioncat-tick))

    ;RecordfrPositionenvonMausbzw.Blckenbestehendaus:;-derx-Koordinate(x);-dery-Koordinate(y)(:make-position(realreal->position))(define-record-procedurespositionmake-positionposition?(position-xposition-y))

    ;3er-Tupelbestehendaus:;-x-Koordinatedesblocks;-y-Koordinatedesblocks;-demSpielstand(define-record-procedurestupelmake-tupeltupel?(block-x

    block-yscorecollision-score))

    ;2er-Tupelbestehendaus:;-ksex-Koordinate;-ksey-Koordinate(define-record-procedurestupel2make-tupel2tupel2?(kse-xkse-y))

    ;RecordfrHindernisse(define-record-procedureshintmake-hinthint?(hint-xhint-yhint-ma-xhint-ma-y));Signaturfrdirections(definedirection(signature(one-of"right""left""down""up""")))

    ;CatimAnfangszustand

    (definestart-cat(make-cat0-150""0))

    ;GameRecord(:make-game(imagetupel2realrealdirectionrealrealcatrealnaturalnaturalbooleanhintnatural(list-ofnatural)(list-of(mixednatural%a))->game))(define-record-proceduresgamemake-gamegame?(game-scenegame-cheese-tupel

  • 8/2/2019 Hungry Mouse

    3/25

    game-tick-xgame-tick-ygame-directiongame-block-xgame-block-ygame-catgame-scoregame-lifegame-collisiongame-first-screen?game-hindernissegame-levelgame-hole-phasegame-hole-time))

    (definedraw-field(lambda(g)(make-game(game-sceneg)(game-cheese-tupelg)(game-tick-xg)(game-tick-yg)(game-directiong)(game-block-xg)(game-block-yg)(game-catg)(game-scoreg)(game-lifeg)(game-collisiong)(game-first-screen?g)(game-hindernisseg)(game-levelg)(game-hole-phaseg)(game-hole-timeg))))

    (definestart-game(make-game(place-imagemaus-right400200(empty-scene800600))(make-tupel2(list0800)(list0390))400200"right"5050start-cat050#f(make-hint0000)1(list00)(list0#f)))

    (definefirst-screen(make-gamefirst-screen-pic(make-tupel2(list0800)(list0390))04""5050start-cat050#t(MAKE-HINT0000)1(list00)(list0#f)))(definegame-over-screen(lambda(g)(make-game(place-image(text"Press[Y]tostartagain"40"blue")400450

    (place-image(text(string-append"YourScore:"(number->string(game-scoreg)))60"black")400300(place-image(text"GameOver"100"black")400150(place-imagehintergrund400200(empty-scene800600)))))(game-cheese-tupelg)(game-tick-xg)(game-tick-yg)(game-directiong)(game-block-xg)(game-block-yg)(game-catg)(game-scoreg)(game-lifeg)(game-collisiong)(game-first-screen?g)(game-hindernisseg)(game-levelg)(game-hole-phaseg)(game-hole-timeg))))

    (definescene(lambda(g)(game-scene(draw-fieldg))))

    (definegametick(lambda(z)(+z1)))

    ;Prozedurrandom-between,die2zahlenakzeptiertundzwichenden2eneinezufallszahlauswhlt(:random-between(naturalnatural->natural))(definerandom-between(lambda(xy)

  • 8/2/2019 Hungry Mouse

    4/25

    (let((randomy(randomy)))(cond((randomyx)randomy)))));ListederMglichenx/y-KoordinatenanwelchenderKseplatziertwerdenkann(definekse-level-1(list(make-tupel2(list0800)(list0600))))

    (definekse-level-2(list(make-tupel2(list0800)(list0390))(make-tupel2(list0800)(list450600))))

    (definekse-level-3(list(make-tupel2(list50750)(list0600))))

    (definekse-level-4(list(make-tupel2(list0800)(list50550))))

    (definekse-level-5(list(make-tupel2(list50750)(list50550))))

    (definekse-level-6(list(make-tupel2(list0800)(list060))(make-tupel2(list0800)(list530600))(make-tupel2(list020)(list0600))

    (make-tupel2(list590800)(list0600))(make-tupel2(list200330)(list200400))(make-tupel2(list370580)(list220360))))

    (definekse-level-7(list(make-tupel2(list0800)(list5090))(make-tupel2(list200600)(list0110))(make-tupel2(list0800)(list150160))(make-tupel2(list0800)(list500600))(make-tupel2(list0800)(list310340))(make-tupel2(list660800)(list310600))(make-tupel2(list0140)(list310600))(make-tupel2(list340470)(list0190))))

    ;ProzedurEat-blocks,diedieMauskSEblckeessenlsst(:eat-blocks(game(list-of%a)->tupel))(defineeat-blocks(lambda(gxs)(letrec((snake-pos(make-position(game-tick-xg)(game-tick-yg)))(snake-pos-x(position-xsnake-pos))(snake-pos-y(position-ysnake-pos))(block-pos-x(game-block-xg))(block-pos-y(game-block-yg)))(cond((and(>(+block-pos-x50)snake-pos-x(-block-pos-x50))(>(+block-pos-y30)snake-pos-y(-block-pos-y30)))(make-tupel(random-between(first(kse-x(game-cheese-tupelg)))(fi

    rst(rest(kse-x(game-cheese-tupelg)))))(random-between(first(kse-y(game-cheese-tupelg)))(first(rest(kse-y(game-cheese-tupelg)))))(+(game-scoreg)1)(+(game-collisiong)1)))(else(make-tupel(game-block-xg)(game-block-yg)(game-scoreg)(game-collisiong)))))));game-cheese-tupel;Prozedurrandom-tupel,dieeintupelausderlevel-kaselistewhlt

  • 8/2/2019 Hungry Mouse

    5/25

    (definerandom-tupel(lambda(gxs)(letrec((snake-pos(make-position(game-tick-xg)(game-tick-yg)))(snake-pos-x(position-xsnake-pos))(snake-pos-y(position-ysnake-pos))(block-pos-x(game-block-xg))(block-pos-y(game-block-yg)))(list-refxs(random(lengthxs))))));Prozedurcat-time?-new;(definecat-time?-new;(lambda(g);(random-between(game-scoreg)(+(game-scoreg)10))))

    ;Prozedurhole-time?,dieberwachtobdieMausinslochluft;x1-linkex-koordinatedeslochs;x2-rechtex-koordinatedeslochs;y1-oberey-koordinatedeslochs;y2-unterey-koordinatedeslochs(definehole-time?(lambda(gx1x2y1y2)(letrec((mouse-pos(make-position(game-tick-xg)(game-tick-yg)))(mouse-pos-x(position-xmouse-pos))(mouse-pos-y(position-ymouse-pos)))(cond((first(rest(game-hole-timeg)))(list(+1(first(game-hole-timeg)))

    #t))((and(>x2mouse-pos-xx1)(>y2mouse-pos-yy1))(list(first(game-hole-timeg))#t))(else(game-hole-timeg))))))

    ;Prozedurcat-time?,prftobcatangreift(definecat-time?(lambda(g)(cond((=(game-collisiong)5)(make-cat-5(random300)"down"1))((=(game-collisiong)11)(make-cat-5(random300)"down"1))((=(game-collisiong)16)(make-cat-5(random300)"down"1))((=(game-collisiong)22)(make-cat-5(random300)"down"1))((=(game-collisiong)31)(make-cat-5(random300)"down"1))

    ((=(game-collisiong)38)(make-cat-5(random300)"down"1))((=(game-collisiong)48)(make-cat-5(random300)"down"1))((=(game-collisiong)59)(make-cat-5(random300)"down"1))((=(game-collisiong)67)(make-cat-5(random300)"down"1))((=(game-collisiong)77)(make-cat-5(random300)"down"1))((=(game-collisiong)80)(make-cat-5(random300)"down"1))((=(game-collisiong)90)(make-cat-5(random300)"down"1))((=(game-collisiong)105)(make-cat-5(random300)"down"1))((=(game-collisiong)120)(make-cat-5(random300)"down"1))((=(game-collisiong)126)(make-cat-5(random300)"down"1))((=(game-collisiong)131)(make-cat-5(random300)"down"1))((=(game-collisiong)139)(make-cat-5(random300)"down"1))((=(game-collisiong)146)(make-cat-5(random300)"down"1))

    ((>(game-collisiong)155)(make-cat-5(random300)"down"1))(else(if(=(cat-tick(game-catg))1500)start-cat(game-catg))))))

    ;Prozedurcollision,diedieKollisionmitderkatzeberwacht(definecollision(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))

  • 8/2/2019 Hungry Mouse

    6/25

    (catdirection(cat-direction(game-catg)))(cattick(cat-tick(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(cond((and(

  • 8/2/2019 Hungry Mouse

    7/25

    (caty(cat-y(game-catg)))(catspeed(if(>(game-scoreg)100)42.5))(catdirection(cat-direction(game-catg))))(if(string(game-levelg)))30"BLACK")40020(place-image(text(string-append"Score:"(number->string(

  • 8/2/2019 Hungry Mouse

    8/25

    game-scoreg)))30"BLACK")71520(place-image(text(string-append"Lives:"(number->string(game-lifeg)))30"black")58520(place-image(cat-posg)catxcaty(place-image(maus-posg)mouse-xmouse-y(place-imagekse(game-block-xg)(game-block-yg)(place-imagehintergrund400200(empty-scene800600)))))))))));Prozedur,dieSpielfeldfrlevel-1berechnet(:level-1-tick(game->game))(definelevel-1-tick(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(if(game-first-screen?g)first-screen

    (if(=(game-lifeg)0)(game-over-screeng)(if(and(

  • 8/2/2019 Hungry Mouse

    9/25

    (game-hole-phaseg)(game-hole-timeg))))))))

    ;Prozedur,dieSpielfeldfrLEvel2zeichnet(definelevel-2-scene(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg)))(place-imagehindernis-holz-hori400400(place-imagehindernis-holz-hori300400(place-image(text(string-append"Level:"(number->string(game-levelg)))30"BLACK")40020(place-image(text(string-append"Score:"(number->string(game-scoreg)))30"BLACK")71520(place-image(text(string-append"Lives:"(number->string(game-lifeg)))30"black")58520(place-image(cat-posg)catxcaty(place-image(maus-posg)

    mouse-xmouse-y(place-imagekse(game-block-xg)(game-block-yg)(place-imagehintergrund400200(empty-scene800600)))))))))))));Prozedur,dieSpielfeldfrLevel2berechnet(:level-2-tick(game->game))(definelevel-2-tick(lambda(g)

    (letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(if(game-first-screen?g)first-screen(if(=(game-lifeg)0)(game-over-screeng)(if(and(

  • 8/2/2019 Hungry Mouse

    10/25

    100)))(-(game-tick-xg)2.5)(if(string=?(game-directiong)"right")(+(game-tick-xg)2.5)(if(and(

  • 8/2/2019 Hungry Mouse

    11/25

    "up"(game-directiong)))))(block-x(eat-blocksgkse-level-2))(block-y(eat-blocksgkse-level-2))(gamecatg)(score(eat-blocksgkse-level-2))(game-lifeg)(collision-score(eat-blocksgkse-level-2))(game-first-screen?g)(make-hint40040010015)2(game-hole-phaseg)(game-hole-timeg))))))))

    ;Prozedur,dieSpielfeldfrLEvel3zeichnet(definelevel-3-scene(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg)))(place-imagehinderniss-holz-verti-ganze-seite795300(place-imagehinderniss-holz-verti-ganze-seite5300

    (place-image(text(string-append"Level:"(number->string(game-levelg)))30"BLACK")40020(place-image(text(string-append"Score:"(number->string(game-scoreg)))30"BLACK")71520(place-image(text(string-append"Lives:"(number->string(game-lifeg)))30"black")58520(place-image(cat-posg)catxcaty(place-image(maus-posg)mouse-x

    mouse-y(place-imagekse(game-block-xg)(game-block-yg)(place-imagehintergrund400200(empty-scene800600)))))))))))))

    ;Prozedur,dieSpielfeldfrlevel-3berechnet(:level-3-tick(game->game))(definelevel-3-tick(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))

    (catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(if(game-first-screen?g)first-screen(if(=(game-lifeg)0)(game-over-screeng)(if(and(

  • 8/2/2019 Hungry Mouse

    12/25

    (collision-gameg)(make-game(level-3-sceneg)(random-tupelgkse-level-3)(if(>(game-tick-xg)800)0(if((game-tick-yg)600)0(if((game-tick-xg)750))

    "left"(if(and(string=?mouse-direction"left")(string(game-levelg)

    ))30"BLACK")40020(place-image(text(string-append"Score:"(number->string(game-scoreg)))30"BLACK")71520(place-image(text(string-append"Lives:"(number->string(game-lifeg)))30"black")58520(place-imagehinderniss-holz-hori-ganze-seite50010(place-imagehinderniss-holz-hori-ganze-seite300590(place-im

  • 8/2/2019 Hungry Mouse

    13/25

    age(cat-posg)catxcaty(place-image(maus-posg)mouse-xmouse-y(place-imagekse(game-block-xg)(game-block-yg)(place-imagehintergrund400200(empty-scene800600)))))))))))))

    ;Prozedur,dieSpielfeldfrlevel-4berechnet(:level-4-tick(game->game))(definelevel-4-tick(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(if(game-first-screen?g)

    first-screen(if(=(game-lifeg)0)(game-over-screeng)(if(and(

  • 8/2/2019 Hungry Mouse

    14/25

    ((game-tick-yg)530))"right"(if(and(and(string=?mouse-direction"right")(>(game-tick-xg)780))(>(game-tick-yg)530))"left"(if(and(and(string=?mouse-direction"up")(>(game-tick-xg)195))((game-tick-xg)180))(string(game-lifeg)))30"black")58520(place-imagehinderniss-holz-verti-ganze-seite10100(place-imagehinderniss-holz-verti-ganze-seite790500(place-imagehinderniss-holz-hori-ganze-seite50010(place-imagehinderniss-holz-hori-ganze-seite300590

    (place-image(cat-posg)catxcaty(place-image(maus-posg)mouse-xmouse-y(place-imagekse(game-block-xg)(game-block-yg)

  • 8/2/2019 Hungry Mouse

    15/25

    (place-imagehintergrund400200(empty-scene800600)))))))))))))))

    ;Prozedur,dieSpielfeldfrlevel-5berechnet(:level-5-tick(game->game))(definelevel-5-tick(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(if(game-first-screen?g)first-screen(if(=(game-lifeg)0)(game-over-screeng)(if(and(

  • 8/2/2019 Hungry Mouse

    16/25

    "left"(if(and(and(string=?mouse-direction"up")((game-tick-xg)750))"up"(if(and(and(string=?mouse-direction"down")((game-tick-yg)530))"up"(if(and(and(string=?mouse-direction"left")((game-tick-yg)550))"right"(if(and(and(string=?mouse-direction"right")(>(game-tick-xg)780))(>(game-tick-yg)550))"left"(if(and(and(string=?mouse-direction"up")(>(game-tick-xg)195))((game-tick-xg)180))(string(game-lifeg)))30"black")58520(place-image(cat-posg)catxcaty(place-image(maus-posg)mouse-xmouse-y(place-imagekse(game-block-xg)(game-block-yg)

  • 8/2/2019 Hungry Mouse

    17/25

    (place-imagehinderniss-level-6289280(place-imagehintergrund400200(empty-scene800600))))))))))))

    ;Prozedur,dieSpielfeldfrLevel6berechnet(:level-6-tick(game->game))(definelevel-6-tick(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(if(game-first-screen?g)first-screen(if(=(game-lifeg)0)(game-over-screeng)(if(and(

  • 8/2/2019 Hungry Mouse

    18/25

    (if(

  • 8/2/2019 Hungry Mouse

    19/25

    ")(

  • 8/2/2019 Hungry Mouse

    20/25

    game-scoreg)))30"BLACK")71520(place-image(text(string-append"Lives:"(number->string(game-lifeg)))30"black")58520(place-image(cat-posg)catxcaty(place-image(maus-posg)mouse-xmouse-y(place-imagekse(game-block-xg)(game-block-yg)(place-imagelevel-7-screen400300(empty-scene800600)))))))))));Prozedur,dieSpielfeldfrLevel7berechnet(:level-7-tick(game->game))(definelevel-7-tick(lambda(g)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(if(game-first-screen?g)first-screen

    (if(=(game-lifeg)0)(game-over-screeng)(if(and(

  • 8/2/2019 Hungry Mouse

    21/25

    (string=?mouse-direction"right")(

  • 8/2/2019 Hungry Mouse

    22/25

    (string=?mouse-direction"down")(string(game-lifeg)))30"black")58520(place-image(cat-posg)catxcaty(place-image(maus-posg)

    mouse-xmouse-y(place-imagekse(game-block-xg)(game-block-yg)(place-image(spinning-holespin-hole-n)395380(place-imagehintergrund400200(empty-scene800600))))))))))));Prozedur,dieSpielfeldfrlevel-8berechnet(:level-8-tick(game->game))(definelevel-8-tick(lambda(g)

    (letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(cat-direction(game-catg)))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong))(mouse-speed(if(first(rest(game-hole-timeg)))12.5)))(if(game-first-screen?g)

  • 8/2/2019 Hungry Mouse

    23/25

    first-screen(if(=(game-lifeg)0)(game-over-screeng)(if(and(15(game-scoreg)9)(level-3-tickg))((>20(game-scoreg)14)(level-4-tickg))((>30(game-scoreg)19)(level-5-tickg))((>45(game-scoreg)29)(level-6-tickg))

  • 8/2/2019 Hungry Mouse

    24/25

    ((>61(game-scoreg)44)(level-7-tickg))((>(game-scoreg)60)(level-8-tickg)))))

    ;Prozeduron-key-pressed,diedietastatureingabeberwacht(defineon-key-pressed(lambda(gs)(letrec((catx(cat-x(game-catg)))(caty(cat-y(game-catg)))(catdirection(game-catg))(mouse-x(game-tick-xg))(mouse-y(game-tick-yg))(mouse-direction(game-directiong)))(cond((key=?s"")(if(game-first-screen?g)start-gameg))((key=?s"y")(if(=0(game-lifeg))start-gameg))((key=?s"right")(make-game(game-sceneg)(game-cheese-tupelg)(game-tick-xg)(game-tick-yg)"right"(game-block-xg)(game-block-yg)(make-catcatxcaty(cat-attackg)(cat-tick(game-catg)))(game-scoreg)(game-lifeg)(game-collisiong)

    (game-first-screen?g)(game-hindernisseg)(game-levelg)(game-hole-phaseg)(game-hole-timeg)))((key=?s"left")(make-game(game-sceneg)(game-cheese-tupelg)(game-tick-xg)(game-tick-yg)"left"(game-block-xg)(game-block-yg)(make-catcatxcaty(cat-attackg)(cat-tick(game-catg)))(game-scoreg)(game-lifeg)(game-collisiong)(game-first-screen?g)(game-hindernisseg)(game-levelg)(game-hole-phaseg)(game-hole-timeg)))

    ((key=?s"down")(make-game(game-sceneg)(game-cheese-tupelg)(game-tick-xg)(game-tick-yg)"down"(game-block-xg)(game-block-yg)(make-catcatxcaty(cat-attackg)(cat-tick(game-catg)))(game-scoreg)(game-lifeg)(game-collisiong)(game-first-screen?g)(game-hindernisseg)(game-levelg)(game-hole-phaseg)(game-hole-timeg)))((key=?s"up")(make-game(game-sceneg)(game-cheese-tupelg)(game-tick-xg)(game-tick-yg)"up"(game-block-xg)(game-block-yg)(make-catcatxcaty(cat

    -attackg)(cat-tick(game-catg)))(game-scoreg)(game-lifeg)(game-collisiong)(game-first-screen?g)(game-hindernisseg)(game-levelg)(game-hole-phaseg)(game-hole-timeg)))(elseg)))))

    ;Big-Bang(big-bangfirst-screen(on-keyon-key-pressed)

  • 8/2/2019 Hungry Mouse

    25/25

    (on-ticktick(/1100))(to-drawscene))