
-----------------------------------
Tamaranian
Tue Jun 11, 2013 7:22 pm

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)




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)
      enemyX := enemyX - 50

end loop



Please specify what version of Turing you are using
Turing 4.1.1

-----------------------------------
evildaddy911
Tue Jun 11, 2013 7:52 pm

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
Tue Jun 11, 2013 8:03 pm

Re: 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

Sorry, could you show me an example or something? I don't really follow..

-----------------------------------
evildaddy911
Tue Jun 11, 2013 8:11 pm

RE:Help with spawning enemies
-----------------------------------
what you have:
[code]
loop
    randomize Y
    reset X
    move left 50
end loop
[/code]
What you need:
[code]
loop
    randomize Y
    reset X
    loop % 