Hello, so I am currently at a stump. I am creating a simple space shooter for my Advanced Higher project (Scottish qualification), and right now I cannot seem to have enemy aliens spawn in. Could anyone give me pointers on how I would go about this?
Many thanks, Conall
			
			
									
									
						Spawning in other objects?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
- 
				catalinanesia
 - Posts: 83
 - Joined: Sun Feb 16, 2014 10:08 pm
 
Re: Spawning in other objects?
Hi there,
Check this http://forums.livecode.com/viewtopic.php?f=22&t=19380
a very nice space shooter done by a forum member.
Do you want to spawn based on "time" or by an action "intersect" ?
If you have some code will be nice if you can post ...
This is a must for you to check, will answer many of your questions ...
https://sites.google.com/a/pgcps.org/livecode/home
Regards!
Catalin
			
			
									
									
						Check this http://forums.livecode.com/viewtopic.php?f=22&t=19380
a very nice space shooter done by a forum member.
Do you want to spawn based on "time" or by an action "intersect" ?
If you have some code will be nice if you can post ...
This is a must for you to check, will answer many of your questions ...
https://sites.google.com/a/pgcps.org/livecode/home
Regards!
Catalin
- 
				ConallChloride
 - Posts: 6
 - Joined: Wed Nov 12, 2014 1:42 pm
 
Re: Spawning in other objects?
Hi Catalin, many thanks for taking the time to reply. Also, apologies for taking so long to get back to you, I've had other school work  
.
Fortunately, I do have some code! Here it is:
This is what I have so far, there is also this too however it does not work.
Any help is appreciated!
			
			
									
									
						Fortunately, I do have some code! Here it is:
Code: Select all
on startalien
   
   create img
   put it into myImg
   set the text of myImg to the text of img "canvas.png"
   
   set the loc of image "canvas.png" to (random(500),0)
   
   //Undecied on size yet, Decide on size
   
   set the width of "canvas.png" to 128
   set the height of "canvas.png" to 32
   
   movealien
   
end startalien
function checkalien
   if there is an image "shooter" then
      if the top of image "canvas.png" >= the bottom of image "shooter" and the top of image "canvas.png" <= the top of image "shooter" then
         if the left of image "canvas.png" >= the left of image "shooter" and the right of image "canvas.png" <= the right of image "shooter" then
            return true
         end if
      end if
   end if
end checkalien
on movealien
   
   if the visible of "canvas.png" is false then set the visible of image "canvas.png" to true
   set the top of image "canvas.png" to (the bottom of image"canvas.png" + 2)
   if the top of image "canvas.png" >= 582 then
      delete image"canvas.png"
      put (lives - 1) into lives
   else
      if checkalien() is true then
         delete image "canvas.png"
         --         hide group "enemy" with visual effect dissolve very fast 
         set the loc image "shooter" to (327,289)
         send startalien to me in random(1000) milliseconds
         exit movealien
      end if
   end if
   
   if there is an image "canvas.png" then send movealien to me in 4 milliseconds
   
end movealienCode: Select all
on createalien
   
   set the loc of image "canvas.png" to (random(500),0)
   
   set the width of "canvas.png" to 128
   set the height of "canvas.png" to 32
   
   movealien
end createalienRe: Spawning in other objects?
Hi ConallChloride,
when addressing objects in Livecode you ALWAYS need to add the TYPE of object!
##Correct:
...
set the loc of image "canvas.png" to (random(500),0)
...
## NOT correct:
set the width of "canvas.png" to 128
set the height of "canvas.png" to 32
...
## Correct: (img = abbreviation for image)
set the width of IMG "canvas.png" to 128
set the height of IMG "canvas.png" to 32
...
Some general hints!
Whe using lots of nested IF THEN clauses, see, if you can start the other way round!
I mean do not check for TRUE conditions, but for the opposite first, so we can LEAVE the function/handler immediately in that case!
That will shorten your IFs and make them MUCH more readable.
Example, your finction "checkalien", does what it should, but is hardly readable:
Here my variation, which does exactly the same but is readable and understandable at ONE glance:
Best
Klaus
			
			
									
									
						when addressing objects in Livecode you ALWAYS need to add the TYPE of object!
##Correct:
...
set the loc of image "canvas.png" to (random(500),0)
...
## NOT correct:
set the width of "canvas.png" to 128
set the height of "canvas.png" to 32
...
## Correct: (img = abbreviation for image)
set the width of IMG "canvas.png" to 128
set the height of IMG "canvas.png" to 32
...
Some general hints!
Whe using lots of nested IF THEN clauses, see, if you can start the other way round!
I mean do not check for TRUE conditions, but for the opposite first, so we can LEAVE the function/handler immediately in that case!
That will shorten your IFs and make them MUCH more readable.
Example, your finction "checkalien", does what it should, but is hardly readable:
Code: Select all
function checkalien
   if there is an image "shooter" then
      if the top of image "canvas.png" >= the bottom of image "shooter" and the top of image "canvas.png" <= the top of image "shooter" then
         if the left of image "canvas.png" >= the left of image "shooter" and the right of image "canvas.png" <= the right of image "shooter" then
            return true
         end if
      end if
   end if
end checkalienCode: Select all
function checkalien
   if there is NOT an image "shooter" then
     ## I think this should ALSO be returned!
      return false
   end if
   if the top of image "canvas.png" < the bottom of image "shooter" and the top of image "canvas.png" > the top of image "shooter" then
      return false
   end if
   if the left of image "canvas.png" < the left of image "shooter" and the right of image "canvas.png" > the right of image "shooter" then
      return true
   end if
    return false
end checkalienKlaus
- 
				ConallChloride
 - Posts: 6
 - Joined: Wed Nov 12, 2014 1:42 pm
 
Re: Spawning in other objects?
Many thanks for replying Klaus, I will have a look at what you've said and see what I can do!  
 
Conall
			
			
									
									
						Conall