<div dir="ltr"><div><div><div><div><div><div><div><div>Your on-key-event handler is:<br><br>;Movement of Myself in XY-direction on key-press<br>(define (alter-myself-xy-on-key w key)<br>  (cond<br>    [(key=? key 'up)<br>
     (make-world (make-posn (posn-x (world-myself w))<br>                            (- (posn-y (world-myself w)) key-distance))<br>                 (world-shark1 w)<br>                 (world-shark2 w)<br>                 (world-food1 w))]<br>
    [(key=? key 'down)<br>     (make-world (make-posn (posn-x (world-myself w))<br>                            (+ (posn-y (world-myself w)) key-distance))<br>                 (world-shark1 w)<br>                 (world-shark2 w)<br>
                 (world-food1 w))]<br>    [(key=? key 'left)<br>     (make-world (make-posn (- (posn-x (world-myself w)) key-distance)<br>                            (posn-y (world-myself w)))<br>                 (world-shark1 w)<br>
                 (world-shark2 w)<br>                 (world-food1 w))]<br>    [(key=? key 'right)<br>     (make-world (make-posn (+ (posn-x (world-myself w)) key-distance)<br>                            (posn-y (world-myself w)))<br>
                 (world-shark1 w)<br>                 (world-shark2 w)<br>                 (world-food1 w))]<br>    [else w]))<br><br></div>This suggests that your reasoning is that only myself is affected by key events and only 'left and 'right key events change the state of the game. However, you want the 'space to also affect the state of the game. Therefore, write a key-processing function that according to they key pressed calls the appropriate auxiliary function. I am suggesting something along the lines of:<br>
<br></div><div>; world key --> world<br></div>(define (process-key w k)<br></div>  (cond [(key=? k 'space) (try-to-eat-food w)]<br></div>           [(or (key=? k 'right) (key=? k 'left) (key=? k 'up) (key=? k 'down)) (alter-myself-xy-on-key w key)]<br>
</div>           [else w]))<br><br></div>I would also ask you:<br><br>(define (game-over? w)<br>  (cond<br>    [(overlapping? (world-myself w)<br>                   (shark-info-position (world-shark1 w))) <br>     true]<br>
    [(overlapping? (world-myself w)<br>                   (shark-info-position (world-shark2 w)))<br>     true]<br>    [else false]))<br><br></div>Why do you use a cond? Consider simply using or.<br><br></div>Hope this helps!<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 1, 2014 at 1:26 PM, Zee Ken <span dir="ltr"><<a href="mailto:udaybhasker552009@gmail.com" target="_blank">udaybhasker552009@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hi,<br><br>I am creating a game which runs in the below world.<br><br><span style="font-family:courier new,monospace">(define-struct world (myself monster1 monster2 food1 food2))</span><br>
</div><div><br>
</div><div>The objective of the game is to move yourself in the world, not get hit by monsters and eat the food.<br><br></div><div>I am done with <br>1) Keyboard manipulation of <span style="font-family:courier new,monospace"><b>myself</b></span>, <br>

2) Stopping the game when I hit any of the monsters (monsters move randomly in the world).<br><br></div><div><u>Question1:</u> Placing the food is also an easy task. But, how do I modify the world when I eat the food?<br>

<br></div><div>I am thinking of writing a procedure that checks if the user hit a SPACE button and is also near the food. If both of these are true, then that particular food image at the location should disappear and the game should continue.<br>

<u><br></u></div><div><u>Question2:</u> Also, are there any timer events in racket where I can include a stop clock counting down from a number to zero?<br></div><div><br></div><div>I am a bit confused as to how I should tackle the idea.<br>

<br></div><div><br></div><div>Best,<br></div><div>Zeek<br></div></div>
<br>____________________<br>
  Racket Users list:<br>
  <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br><br>Cheers,<br><br>Marco<br><br>Have a´¨)<br>¸.·´¸.·*´¨) ¸.·*¨)<br>(¸.·´ (¸.·´ * wonderful day! :)
</div>