creating game - moving enemy

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

creating game - moving enemy

Post by star0629 » Fri Dec 13, 2013 9:44 pm

I am wanting the enemy to appear at random times. At the moment it is a bird continuously moving across the card. I am wanting it to wait for atleast 20 seconds before appearing again and moving across the card. I am some ideas how to code this but am not entirely sure how exactly

thanks

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: creating game - moving enemy

Post by dunbarx » Fri Dec 13, 2013 9:49 pm

Hi.

Do you already have a handler running, perhaps using the "move" command? Look up the "send" command, and look carefully at its "in time" variant.

Craig Newman

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: creating game - moving enemy

Post by star0629 » Fri Dec 13, 2013 11:26 pm

this is what i have so far when the game is running

on moveEnemy
set the left of button "box" to the left of button "box" + 5
if the left of button "box" > the right of card id"1003" then
set the left of button "box" to the left of card id"1003"
end if
end moveEnemy


the box being the enemy

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: creating game - moving enemy

Post by Simon » Sat Dec 14, 2013 1:37 am

I am wanting it to wait for atleast 20 second...
liveCode uses many English words. hint hint

Simon
Edit: But if you can use "send" that is way cooler.
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9648
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: creating game - moving enemy

Post by dunbarx » Sat Dec 14, 2013 4:48 pm

Hi.

Do you use invoke "sendEnemy" in a loop"? Anyway, when do you want "box" to disappear? When it hits the right of the card?

Try this experiment. In a button somewhere:

Code: Select all

on mouseUp
resetbox
end mouseUp

on resetbox
   if the optionKey is down then
      show btn "box"
      exit to top
   end if
   set the visible of btn "box" to not the visible of btn "box"
   set the loc of btn "box" to random(250),random(250)
   send "resetbox" to me in 1 second
end resetbox
Hold down the optionKey to escape. Simon has hinted at a method using the "wait" command. Do look this up and consider it. But note that "wait" is blocking, and this may or may not be to your liking, depending on how you want this procedure to run.

Craig

capellan
Posts: 654
Joined: Wed Aug 15, 2007 11:09 pm

Re: creating game - moving enemy

Post by capellan » Sun Dec 15, 2013 11:25 pm

Hi Star0629,

Check if this stack and it´s script could be useful
as inspiration or a starting point in your project:

http://andregarzia.on-rev.com/alejandro ... gman_2.zip

Have a nice week!

Al

Newbie4
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 327
Joined: Sun Apr 15, 2012 1:17 am
Location: USA
Contact:

Re: creating game - moving enemy

Post by Newbie4 » Mon Dec 16, 2013 3:12 am

You could simply add a timer. When the box goes off the end of the screen, store the time (the seconds) into a global. Then do not move the box again until 20 seconds have passed.

Code: Select all

 on moveEnemy
  global gTime
  if the seconds-gTime > 20 then
     show button “box”
     set the left of button "box" to the left of button "box" + 5
  if the left of button "box" > the right of card id"1003" then
     set the left of button "box" to the left of card id"1003"
     hide button “box”
     put the seconds into gTime
  end if 
end moveEnemy
When the program starts up, you may have to initialize the global so that it works right away.

This is a simple approach, you may think of another way.
Cyril Pruszko
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: creating game - moving enemy

Post by chris25 » Mon Dec 16, 2013 12:45 pm

I have a question for you capellan, or if someone else might be good enough to answer I would appreciate it. It concerns just one line of script in your card in the Keydown message namely:
if tKey is in "1,2,3,4,5,6,7,8,9,q,w,e,a,s,d,z,x,c" and the tEnabled of this card <> false

In the above your temporary variable is declared only once within the keydown, what puzzles me is this: if it is false assumes the possibility of it being 'true'. How can it possibly ever be true when it has no declaration or value assigned to it. It appears in this one line and that is it, where is its property/value/meaning acquired from? It's what confuses me sometimes when I see these.

and in your image mlr2:
move me to the points of grc 1 in the MovingTime of this stack seconds

The same applies here with 'movingTime' except that I do not even know what this is, it is not a command or a function because it is no where else declared throughout the whole program. So again it seems a tVariable?

I am still very knew to all this and still trying to grapple with a the basics.
Thankyou
chris

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

Re: creating game - moving enemy

Post by Klaus » Mon Dec 16, 2013 12:53 pm

chris25 wrote:...
if tKey is in "1,2,3,4,5,6,7,8,9,q,w,e,a,s,d,z,x,c" and the tEnabled of this card <> false
...
tEnabled is NOT a variable -> THE tEnabled of cd ...
It is a custom property of a card, which obviously might have been set earlier.

chris25
Posts: 354
Joined: Tue Oct 08, 2013 9:32 pm

Re: creating game - moving enemy

Post by chris25 » Mon Dec 16, 2013 1:34 pm

Oh, thankyou. And the movingtime? looked also like a custom property because of your emboldened definite article, but not so, nothing in the stack property and nothing in the image property inspector either.

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

Re: creating game - moving enemy

Post by Klaus » Mon Dec 16, 2013 1:43 pm

"movingtime"?

Sorry, did not load/examine the stack Alejandro posted,
just commented the the line you have posted.

star0629
Posts: 22
Joined: Thu Nov 28, 2013 9:04 pm

Re: creating game - moving enemy

Post by star0629 » Mon Dec 16, 2013 8:15 pm

Newbie4 wrote:You could simply add a timer. When the box goes off the end of the screen, store the time (the seconds) into a global. Then do not move the box again until 20 seconds have passed.

Code: Select all

 on moveEnemy
  global gTime
  if the seconds-gTime > 20 then
     show button “box”
     set the left of button "box" to the left of button "box" + 5
  if the left of button "box" > the right of card id"1003" then
     set the left of button "box" to the left of card id"1003"
     hide button “box”
     put the seconds into gTime
  end if 
end moveEnemy
When the program starts up, you may have to initialize the global so that it works right away.

This is a simple approach, you may think of another way.

thank you soo mcuh this is exactly what i needed, it works perfectly! and doesnt stop running the entire program also not complicated to understand either :D thanks!!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”