<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>When he said world, he meant a piece of data that describes the state of the program, for example a data structure that stores the positions of “myself” and “shark1”, etc in a structure:</div><div><font face="Courier New">(define-struct world (myself-posn food1-posn food2-posn shark1-posn))</font></div><div><br></div><div>And when you use big-bang and on-tick-event, etc, you should use instances of this <font face="Courier New">world</font> structure:</div><div><div><font face="Courier New">(define initial-world</font></div><div><font face="Courier New">  (make-world myself-initialposition</font></div><div><font face="Courier New">              food1-initialposition</font></div><div><font face="Courier New">              food2-initialposition</font></div><div><font face="Courier New">              shark1-initialposition))</font></div></div><div><font face="Courier New"><br></font></div><div><div><font face="Courier New">(define (world-move-on-tick w) ; w should be an instance of the world structure</font></div><div><font face="Courier New">  (make-world (myself-move-xy-on-tick (world-myself-posn w))</font></div><div><font face="Courier New">              (world-food1-posn w)</font></div><div><font face="Courier New">              (world-food2-posn w)</font></div><div><font face="Courier New">              (shark1-move-xy-on-tick (world-shark1-posn w))))</font></div></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(big-bang width height 1/30 initial-world)</font></div><div><font face="Courier New"><br></font></div><div><font face="Courier New">(on-tick-event world-move-on-tick)</font></div><div><br></div><div>Does that help?  </div><br><div><div>On Apr 17, 2014, at 4:09 PM, Zee Ken <<a href="mailto:udaybhasker552009@gmail.com">udaybhasker552009@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr"><div><div><div><div><div><div><div><div>How can I make 2 different images move in different ways inside only 1 world.<br><br></div><div>I placed "myself" at (posn 550 550) = right end of the screen<br>
<br></div><div>Placed "food" at respective fixed position.<br><br></div><div>I want "shark1" to move only in x-direction automatically on clock-tick.<br><br></div><div>I want to control "myself" via key-press.<br>
</div><div><br>;--------------------------------------------------------------------------------------------------------------------------------------------------<br></div><div>;;; Initializations<br></div><div>(define newinitialposition (make-posn 550 550))<br>
<br>(define (mynewposition-xy p)<br>  (place-image myself (posn-x p) (posn-y p) <br>               (place-image food 200 250 <br>               (place-image food 100 550 <br>               (place-image shark1 (posn-x p) 400 background)))))<br>
</div><div>;--------------------------------------------------------------------------------------------------------------------------------------------------<br><br>;--------------------------------------------------------------------------------------------------------------------------------------------------<br>
</div><div>;;; Movement handlers<br><br>(define shark1-move-x 20)<br>(define (shark1-move-x-on-tick x1) (- x1 oppshark-move-x))<br>(define (shark1-move-xy-on-tick p)<br>  (make-posn (shark1-move-x-on-tick (posn-x p)) (posn-y p)))<br>
<br></div><div>(define myself-move-x 10)<br>(define (myself-move-on-tick x) (- x myself-move-x))<br>(define (myself-move-xy-on-tick p)<br>  (make-posn (myself-move-on-tick (posn-x p)) (myself-move-on-tick (posn-y p))))<br>
</div><div>;--------------------------------------------------------------------------------------------------------------------------------------------------<br><br>;--------------------------------------------------------------------------------------------------------------------------------------------------<br>
</div><div>;;; Running the game<br></div>;1<br>(big-bang width height 1/30 newinitialposition)<br><br>;2<br></div>(on-tick-event shark1-move-x-on-tick)<br><br>;3<br></div>(on-key-event move-myself-xy-on-keypress)<br><br>;4<br>
</div>(on-redraw mynewposition-xy)   ;; ---> I guess something should be done here<br>;--------------------------------------------------------------------------------------------------------------------------------------------------<br>
<br></div>1) Both shark1 and myself keep moving in the x-direction because of the on-tick-event.<br></div>2) If I don't include the ;2, and I press a key, both of them move. (I did the key pressing part separately). <left right> controls both the images but <up down> controls only myself which is obvious because of the way I wrote "mynewposition-xy".<br>
<br></div>I can't seem to combine these two ideas of automatic and control into 1 world.<br><br></div>How do I proceed?????<br></div>
____________________<br>  Racket Users list:<br>  <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></blockquote></div><br></body></html>