Computer Science Canada

how to move an image

Author:  Notthebbq [ Mon Apr 04, 2011 1:14 pm ]
Post subject:  how to move an image

my group member wants to know how to move an image around the screen with out use of arrow keys (ie: an NPC/AI) and if you could explain it simply would be nice

Author:  apython1992 [ Mon Apr 04, 2011 1:23 pm ]
Post subject:  RE:how to move an image

Well, if you are using the arrow keys to move an image, you would be watching the event queue for a KEYDOWN event, which is a conditional, correct?

Pseudocode
code:

if KEYDOWN(left_arrow):
    image_x -= 1


and so on. With an AI, moving the image is the same, in that you change its position. It's just the condition that's different (not a button pressed, but perhaps its position relative to the tower and which direction the path follows).

Author:  Notthebbq [ Mon Apr 04, 2011 1:27 pm ]
Post subject:  Re: how to move an image

Thanks for the advice, I was just wondering if you could elaborate on the whole AI moving part, like an example code would be really helpful. I kind of knew of the moving with keyboard solution.
Thanks again.

Author:  Insectoid [ Mon Apr 04, 2011 1:32 pm ]
Post subject:  RE:how to move an image

Say we have a loop. Inside that loop we have image_x += 1. If we execute that loop, the image will move in the +x direction.

Similarly, we can do something like
code:

if my_dog_is_male :
    image_x += 1


alternatively;
code:

if i_want_to_go_left:
    image_x += 1


Whether or not you want to go left is an entirely different question.

Author:  Tony [ Mon Apr 04, 2011 2:41 pm ]
Post subject:  RE:how to move an image

Most NPCs are scripted -- they don't make decisions, just follow the actions described in some text-file.

Basic AIs come down to a very simple model: what is the current world state? What move should I make this turn for this state? Repeat.


: