how to move an image
Author |
Message |
Notthebbq
![](http://compsci.ca/v3/uploads/user_avatars/11181326514ee8f2aca9c82.jpg)
|
Posted: 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 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
apython1992
![](http://compsci.ca/v3/uploads/user_avatars/17001640684d87a16bb8fbb.jpg)
|
Posted: 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). |
|
|
|
|
![](images/spacer.gif) |
Notthebbq
![](http://compsci.ca/v3/uploads/user_avatars/11181326514ee8f2aca9c82.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Insectoid
![](http://compsci.ca/v3/uploads/user_avatars/13760332514cbd0ce972eaa.jpg)
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: 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. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
|
|