CPU controlled movement for enemy

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
SammL1
Posts: 5
Joined: Thu Jun 05, 2014 11:12 am

CPU controlled movement for enemy

Post by SammL1 » Mon Dec 01, 2014 9:53 am

My code for creating an enemy at a random location on the top of the screen now works but I can't get the enemy to move down the screen, this is what I've got so far;

Code: Select all

on moveAlien
   if moveEnemy = true then
      send this to me in 10 millisecs
      set the top of image "alienEnemy" to (the bottom of image"alienEnemy" + 2)
      if the top of image "alienEnemy" >= 400 then
         delete image"alienEnemy"
         
         put false into moveEnemy
         //put (lives - 1) into lives
         put false into alienEnemy
      end if
   end if
end moveAlien
Many thanks. Samm.

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: CPU controlled movement for enemy

Post by Klaus » Mon Dec 01, 2014 2:07 pm

Hi Samm,

almost! :D

Code: Select all

on moveAlien
   if moveEnemy = true then
      send "movealien" to me in 10 millisecs
...
But I would put this at the end of the handler and use better readable and UNnested IF THEN clauses 8)

Code: Select all

on moveAlien
     ## No need to continue in this case:
     if moveEnemy = FALSE then
        exit movealien
     end if

      set the top of image "alienEnemy" to (the bottom of image"alienEnemy" + 2)
      if the top of image "alienEnemy" >= 400 then
         delete image"alienEnemy"       
         put false into moveEnemy
         //put (lives - 1) into lives
         put false into alienEnemy
      end if
      send "movealien" to me in 10 millisecs
end moveAlien
Best

Klaus

Post Reply

Return to “Games”