Page 1 of 1

Moving an alien to bottom of the screen?

Posted: Wed Dec 17, 2014 1:09 pm
by ConallChloride
Hi all, I have code to move the enemy ship in my game, however I cannot get it to move from the top of the card to the bottom. Spawning of the enemy works, but movement down does not.

Code: Select all

on moveAlien
   if moveEnemy = FALSE then
      movealien
   end if
   
   set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)
   if the top of image "alienEnemy" >= 400 then
      delete image"alienEnemy"       
      put false into moveEnemy
      //put (lives - 1) into lives
      put false into alienEnemy
      put false into moveEnemy
   end if
end moveAlien
This is what I have so far. Any help is appreciated! :D

Many thanks, Conall

Re: Moving an alien to bottom of the screen?

Posted: Wed Dec 17, 2014 1:27 pm
by ConallChloride
Update: Movement now works due to adding in the line "send "moveAlien" to me in 5 milliseconds", however when the enemy is shot I get an error with the first line in this sub-rutine "set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)". Can anyone help?

Thanks, Conall

Re: Moving an alien to bottom of the screen?

Posted: Wed Dec 17, 2014 2:04 pm
by Klaus
Hi Canall,

sorry, don't get this?

WHAT condition in your handler refers to the fact that an ALIEN might be "dead"?
And WHAT error do you get?

We surely need a tad more info! 8)


Best

Klaus

Re: Moving an alien to bottom of the screen?

Posted: Thu Dec 18, 2014 9:59 am
by ConallChloride
Hi Klaus

So basically, when my bullet intersects with the alien the image is deleted. This can happen up to four times before I'm taken into my code due to a problem with the line "set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)"

I'm not too sure on how I can fix this.

The whole block is

Code: Select all

on moveAlien
   if moveEnemy = FALSE then
      return false
   end if
   
   if game = false then
      return false
   end if
   
   set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)
   if the top of image "alienEnemy" >= 590 then
      delete image"alienEnemy"
      put false into moveEnemy
      put (lives - 1) into lives
      put false into alienEnemy
      send gameloop to me
   end if
   send moveAlien to me in 5 millisecs
end moveAlien

Re: Moving an alien to bottom of the screen?

Posted: Thu Dec 18, 2014 1:23 pm
by Klaus
Hi Conall,

hm, still not sure I get it :D
Maybe addind another if then clause will do the trick?

Code: Select all

on moveAlien
   if there is NOT an img "alienEnemy" then
     exit moveAlien
   end if
   ...
?


Best

Klaus

Re: Moving an alien to bottom of the screen?

Posted: Fri Dec 19, 2014 4:44 am
by Newbie4
Even after you delete the alienEnemy, you still send the message "moveAlien". Could it be that message that gets you the next time you go in that code and try to move an alienenemy that has been deleted?

Try this

Code: Select all

  set the top of image "alienEnemy" to (the top of image"alienEnemy" + 5)
   if the top of image "alienEnemy" >= 590 then
      delete image"alienEnemy"
      put false into moveEnemy
      put (lives - 1) into lives
      put false into alienEnemy
      send gameloop to me
   else
       send moveAlien to me in 5 millisecs
   end if