Ok so basically I just want to be able to have my player moving up and down automatically
how do you make this work?
MY CODE:
-- Use this function to perform your initial setup
function setup()
xpos=0
grass={1,1,0,0,0,1,1,0,0,0}
end
-- This function gets called once every frame
function draw()
sprite("Documents:Background",WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
sprite("Documents:spaceship",120,120)
-- for i = 1,20 do
-- sprite("Cargo Bot:Title Large Crate 1", xpos/2+ 50*i-100, 60,60,70)
-- end
for i = 1,10 do
if grass[i]==1 then
sprite("Tyrian Remastered:Space Ice 6", xpos+101*i-100, 0)
else
sprite("Documents:Floor", xpos+101*i-100, 0)
end
end
xpos=xpos-1
--need to reset xpos at an appropriate point to get wraparound
end
```
--# Main
function setup()
xpos = 0
grass={1,1,0,0,0,1,1,0,0,0}
currPos = WIDTH/2
leftMax = 200
rightMax = 500
goRight = true
goLeft = false
end
-- This function gets called once every frame
function draw()
sprite("Documents:Background",WIDTH/2,HEIGHT/2,WIDTH,HEIGHT)
sprite("Documents:spaceship",120,120)
for i = 1,10 do
if i==1 then
if currPos < leftMax then
goRight = true
goLeft = false
elseif currPos > rightMax then
goLeft = true
goRight = false
end
if goRight == true then
currPos = currPos + 3
elseif goLeft == true then
currPos = currPos - 3
end
sprite("Tyrian Remastered:Space Ice 6", xpos+WIDTH*i-100, currPos)
else
sprite("Documents:Floor", xpos+101*i-100, 0)
end
end
xpos=xpos-1
--need to reset xpos at an appropriate point to get wraparound
end
Not sure if thats what you wanted.
I also changed grass[i] == 1 to i==1 if you dont understand why i did that you can comment asking
I can see two beginners playing ping-pong. I have to step right in.
Yes, Marcos, I have to ask why you changed grass[i] == 1 to i == 1 because I have no idea. And please make use of proper code indentation.
Kingamer, I assume your spaceship is the player. If you want it to go up and down you need to adjust the y-position of the sprite. And you need to know if you have to go up or down.
-- ship globals
shipY = 120
shipDir = "up"
Make your ship adjustable in the y-axis. Homework (sorry that I consider this a homework, but it absolutely think it is):
Which of the following options is correct?
function draw()
-- <code snipped>
-- Is this correct?
sprite("Documents:spaceship",shipY,120)
-- Or is this correct?
sprite("Documents:spaceship",120,shipY)
-- <code snipped>
end
Now you have a ship than can possibly move up and down, yet is doesn’t. You have to tell it to do so.
function draw()
-- <code snipped>
if shipDir == "up" then
shipY = shipY + 1
elseif shipDir == "down" then
shipY = shipY - 1
end
-- <code snipped>
end
Homework: In which direction will your ship go initially? (Yes, up is correct.) At some point it has to go down. Determine a point, your choice. If the ship passes that point, let it go down.
Constraints: Don’t ask my questions on a new thread as you like to it now.
Oops sorry, i answered in a rush and messed it all up :p.
Now i see that player is actually some other thing other than a player.
I looked over his code and somehow tought that he was mistakenly creating lots of players and went on to fix that.
Now i dont know why i tought he needed a loop to paint one player and well, nine floors…
So i changed it to if i==1… I may want to fix that, sorry that was really stupid, thanks for pointing that out.
atleast i got the moving working i guess… Lol.