Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 how to move an image
Index -> Programming, Python -> Python Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Notthebbq




PostPosted: 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
Sponsor
Sponsor
Sponsor
sponsor
apython1992




PostPosted: 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).
Notthebbq




PostPosted: 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.
Insectoid




PostPosted: 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.
Tony




PostPosted: 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.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Display posts from previous:   
   Index -> Programming, Python -> Python Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: