Help with spawning enemies
Author |
Message |
Tamaranian
|
Posted: Tue Jun 11, 2013 7:22 pm Post subject: Help with spawning enemies |
|
|
What is it you are trying to achieve?
I'm attempting to spawn enemies from the right of the screen. They should come in from a random y coordinate then move out of the screen from the left side (x decreases)
What is the problem you are having?
I'm fairly new with working with turing sprites and games and I have no idea how to do this. I know my code is completely wrong, but I hope it gives you guys an idea of what I'm trying to do. I'm not sure where to put the loops and other lines and the sprite won't show up at all :/
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Please specify what version of Turing you are using
Turing 4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
evildaddy911
|
Posted: Tue Jun 11, 2013 7:52 pm Post subject: RE:Help with spawning enemies |
|
|
what you are doing every loop is setting the enemyY to something random, then putting that sprite at the random location. hundreds of times per second. what you want to do is set the y-coord, move it until its offscreen, THEN randomize the y-coord and reset the X.
What you have is pretty close, you just need an inner loop to move the sprite, exiting when its offscreen |
|
|
|
|
|
Tamaranian
|
Posted: Tue Jun 11, 2013 8:03 pm Post subject: Re: RE:Help with spawning enemies |
|
|
evildaddy911 @ Tue Jun 11, 2013 7:52 pm wrote: what you are doing every loop is setting the enemyY to something random, then putting that sprite at the random location. hundreds of times per second. what you want to do is set the y-coord, move it until its offscreen, THEN randomize the y-coord and reset the X.
What you have is pretty close, you just need an inner loop to move the sprite, exiting when its offscreen
Sorry, could you show me an example or something? I don't really follow.. |
|
|
|
|
|
evildaddy911
|
Posted: Tue Jun 11, 2013 8:11 pm Post subject: RE:Help with spawning enemies |
|
|
what you have:
code: |
loop
randomize Y
reset X
move left 50
end loop
|
What you need:
code: |
loop
randomize Y
reset X
loop % <- add this loop
move left 50 until offscreen % <- add "until offscreen" condition
end loop
end loop
|
|
|
|
|
|
|
Tamaranian
|
Posted: Tue Jun 11, 2013 8:32 pm Post subject: Re: RE:Help with spawning enemies |
|
|
evildaddy911 @ Tue Jun 11, 2013 8:11 pm wrote: what you have:
code: |
loop
randomize Y
reset X
move left 50
end loop
|
What you need:
code: |
loop
randomize Y
reset X
loop % <- add this loop
move left 50 until offscreen % <- add "until offscreen" condition
end loop
end loop
|
code: |
setscreen ("graphics:max;max")
var enemy,enemyX,enemyY, picEnemy : int := 0
enemyX := maxx
picEnemy := Pic.FileNew ("sprite.JPG")
enemy := Sprite.New (picEnemy)
loop
randint (enemyY,200,700)
Sprite.SetPosition (enemy,enemyX,enemyY,true)
Sprite.Show (enemy)
loop
enemyX := enemyX - 50
if enemyX < 5 then
exit %Testing (Could I use Sprite.Hide/Sprite.Free here?)
end if
end loop
end loop
|
Nothing shows up on the screen, but if I put a delay before the first loop it does weird jumps before disappearing. It's randomizing the same enemies Y coordinate instead of different enemy's Y coordinates right? |
|
|
|
|
|
Raknarg
|
Posted: Tue Jun 11, 2013 9:31 pm Post subject: RE:Help with spawning enemies |
|
|
Here's the same code with slight adjustments:
Turing: |
setscreen ("graphics:max;max")
var enemy, enemyX, enemyY, picEnemy : int := 0
enemyX := maxx
picEnemy := Pic.FileNew ("sprite.jpg")
enemy := Sprite.New (picEnemy )
loop
enemyX := maxx
randint (enemyY, 200, 700)
loop
Sprite.SetPosition (enemy, enemyX, enemyY, true)
Sprite.Show (enemy )
enemyX := enemyX - 1
if enemyX < 5 then
exit %Testing (Could I use Sprite.Hide/Sprite.Free here?)
end if
delay (1)
end loop
end loop
|
First, you need to understand that the first loop is where the initial parameters are set. The second loop is where all the updating happens. In the second loop you tell it to update the position and draw it on screen
Next, you forgot to set the enemy's x position.
Then, you're subracting way too much from x for smooth movement, anbd because there's no delay (even slight) the program just whizzes by rediculously fast, so you can't see anything. Try running this instead. |
|
|
|
|
|
Tamaranian
|
Posted: Tue Jun 11, 2013 9:49 pm Post subject: Re: RE:Help with spawning enemies |
|
|
Raknarg @ Tue Jun 11, 2013 9:31 pm wrote: Here's the same code with slight adjustments:
Turing: |
setscreen ("graphics:max;max")
var enemy, enemyX, enemyY, picEnemy : int := 0
enemyX := maxx
picEnemy := Pic.FileNew ("sprite.jpg")
enemy := Sprite.New (picEnemy )
loop
enemyX := maxx
randint (enemyY, 200, 700)
loop
Sprite.SetPosition (enemy, enemyX, enemyY, true)
Sprite.Show (enemy )
enemyX := enemyX - 1
if enemyX < 5 then
exit %Testing (Could I use Sprite.Hide/Sprite.Free here?)
end if
delay (1)
end loop
end loop
|
First, you need to understand that the first loop is where the initial parameters are set. The second loop is where all the updating happens. In the second loop you tell it to update the position and draw it on screen
Next, you forgot to set the enemy's x position.
Then, you're subracting way too much from x for smooth movement, anbd because there's no delay (even slight) the program just whizzes by rediculously fast, so you can't see anything. Try running this instead.
Thank you, that worked perfectly |
|
|
|
|
|
Raknarg
|
Posted: Wed Jun 12, 2013 5:36 pm Post subject: RE:Help with spawning enemies |
|
|
The important thing is that you understand what you did wrong. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|