creating game - moving enemy
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
creating game - moving enemy
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
thanks
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: creating game - moving enemy
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
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
Re: creating game - moving enemy
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
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
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: creating game - moving enemy
liveCode uses many English words. hint hintI am wanting it to wait for atleast 20 second...
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!
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: creating game - moving enemy
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:
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
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
Craig
Re: creating game - moving enemy
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
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
-
- VIP Livecode Opensource Backer
- Posts: 327
- Joined: Sun Apr 15, 2012 1:17 am
- Location: USA
- Contact:
Re: creating game - moving enemy
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.
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.
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
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/
https://sites.google.com/a/pgcps.org/livecode/
https://sites.google.com/a/setonhs.org/app-and-game-workshop/home
https://learntolivecode.com/
Re: creating game - moving enemy
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
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
Re: creating game - moving enemy
tEnabled is NOT a variable -> THE tEnabled of cd ...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
...
It is a custom property of a card, which obviously might have been set earlier.
Re: creating game - moving enemy
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.
Re: creating game - moving enemy
"movingtime"?
Sorry, did not load/examine the stack Alejandro posted,
just commented the the line you have posted.
Sorry, did not load/examine the stack Alejandro posted,
just commented the the line you have posted.
Re: creating game - moving enemy
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.
When the program starts up, you may have to initialize the global so that it works right away.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
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 thanks!!