Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help with spawning enemies
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tamaranian




PostPosted: 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)


Turing:


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
Sponsor
Sponsor
Sponsor
sponsor
evildaddy911




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: 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 Smile
Raknarg




PostPosted: 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
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: