<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>