Posted: Sun Dec 13, 2009 2:14 pm Post subject: Re: RE:Need Help Making Graphics Move By Themselves In Turing
Tony @ Sat Dec 12, 2009 3:29 pm wrote:
You are drawing the asteroid outside of the loop, always at the same location. You want to draw it together with the player
code:
Pic.Draw (pic, x, y, picCopy)
Pic.Draw (asteroid, x1, y1, picCopy)
And you would obviously have to change the x1/y1 in the same loop as you change x/y.
P.S. there is no need to do "Unable to load JPEG:" checks inside the loop. The check is for loading the image, not drawing it.
Sorry for the double post, but I just put the asteroid inside the loop , and I did change the x1/y1 in the same loop as the x/y, but my asteroids still don't fall down. The picture of the asteroid just keeps poping up every where on the screen. I dont know if it was something I did, but could you please tell me if this was my fault, or something that you told me to do. I would really appreciate that,
Here's what I changed the program to,
View.Set ("graphics:640,427")
var name : string
var chars : array char of boolean
var pic : int := Pic.FileNew ("F:\\images2.jpg")
var backGround : int := Pic.FileNew ("F:\\back.jpg")
var asteroid : int := Pic.FileNew ("F:\\Asteroid.jpg")
var x, y : int
var x1, y1 : int
x := 10
y := 10
put "Please enter your name player one: " ..
put skip
get name
loop
Pic.Draw (backGround, 0, 0, picCopy)
if backGround = 0 then
put "Unable to load JPEG: ", Error.LastMsg
end if
if asteroid = 0 then
put "Unable to load BMP: ", Error.LastMsg
end if
loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
x := x + 5
elsif chars (KEY_LEFT_ARROW) then
x := x - 5
elsif chars (KEY_UP_ARROW) then
y := y + 5
elsif chars (KEY_DOWN_ARROW) then
y := y - 5
end if
randint (x1, 0, maxx)
randint (y1, 0, maxy)
if pic = 0 then
put "Unable to load JPEG: ", Error.LastMsg
end if
Pic.Draw (pic, x, y, picCopy)
Pic.Draw (asteroid, x1, y1, picCopy)
delay (10)
end loop
end loop
Sponsor Sponsor
Tony
Posted: Sun Dec 13, 2009 2:39 pm Post subject: RE:Need Help Making Graphics Move By Themselves In Turing
could you explain those two lines that you've added?
Posted: Sun Dec 13, 2009 2:42 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
The zeroes make it so that asteroids pop up anywhere, I will change it so that they are alawys at the top later on, once I figure out how to make the asteroids fall.
TheGuardian001
Posted: Sun Dec 13, 2009 3:17 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
I think what tony meant is, Is there a reason you put those in the loop? Is randomly generating coordinates something you want to repeat?
The Lone Ranger
Posted: Sun Dec 13, 2009 3:20 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
I thought that randomly generating coordinates would make the asteroids appear anywhere, which they do, but the picture of the asteroid still doesn't fall down from the top of the screen.
TheGuardian001
Posted: Sun Dec 13, 2009 3:45 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
That's because you aren't moving them. There is no gravity in programming. If you want something to move, you have to do it yourself.
In your loop, you randomly generate a new coordinate each time, then draw the picture at that new coordinate. This will produce asteroids popping up randomly around the screen.
If you want the asteroid to move down, what should you be doing to the coordinates in the loop, instead of randomizing them?
The Lone Ranger
Posted: Sun Dec 13, 2009 3:49 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
I don't know. Maye take the coordinates out of the loop?
Tony
Posted: Sun Dec 13, 2009 4:06 pm Post subject: RE:Need Help Making Graphics Move By Themselves In Turing
You want to have something like
code:
set-up/initialize your variables
loop
move player
move asteroid
end loop
The random initial position does the "initialization" type of work, something you want to happen just once, so it's a good idea to put that outside of the loop.
You would still need to add more code to describe how the asteroid moves while inside the loop; and I've hinted that you should take a look at how the player moves.
Posted: Sun Dec 13, 2009 4:09 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
Take the randomization out? Yes. But that won't move the thing down.
Draw a dot on a piece of graph paper, then draw another dot down 3 units. What have you done to the coordinates to get it to move down? Do this in your program, and the asteroid will fall.
The Lone Ranger
Posted: Sun Dec 13, 2009 4:12 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
I just made some changes to the program, I'vegot the asteroid to fall down, but a new problem has come up. The asteroid only falls in the same place and I can't move my character anymore. Can anyone help me out?
Here's the new program,
View.Set ("graphics:640,427")
var name : string
var chars : array char of boolean
var pic : int := Pic.FileNew ("F:\\images2.jpg")
var backGround : int := Pic.FileNew ("F:\\back.jpg")
var asteroid : int := Pic.FileNew ("F:\\Asteroid.jpg")
var x, y : int
var x1, y1 : int
x := 10
y := 10
y1 := 427
put "Please enter your name player one: " ..
put skip
get name
procedure game
randint (x1, 100, 599)
Pic.Draw (pic, x, y, picCopy)
Pic.Draw (asteroid, x1, y1, picCopy)
loop
Pic.Draw (asteroid, x1, y1, picCopy)
y1 := y1 - 10
delay (10)
if y1 < 0 then
y1 := 427
Pic.Draw (asteroid, x1, y1, picCopy)
y1 := y1-10
end if
end loop
end game
loop
Pic.Draw (backGround, 0, 0, picCopy)
if backGround = 0 then
put "Unable to load JPEG: ", Error.LastMsg
end if
if asteroid = 0 then
put "Unable to load BMP: ", Error.LastMsg
end if
loop
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
x := x + 5
elsif chars (KEY_LEFT_ARROW) then
x := x - 5
elsif chars (KEY_UP_ARROW) then
y := y + 5
elsif chars (KEY_DOWN_ARROW) then
y := y - 5
end if
if pic = 0 then
put "Unable to load JPEG: ", Error.LastMsg
end if
randint (x1, 100, maxx)
randint (y1, 280, maxy)
game
delay (10)
end loop
end loop
TheGuardian001
Posted: Sun Dec 13, 2009 4:59 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
The reason you can no longer move your character is that you suddenly added a new procedure called game, and are now running in a loop inside that procedure. When you have a loop inside of a procedure, that procedure becomes blocking. Since there is a loop inside the procedure, that procedure will never end, and the rest of the code will be ignored.
Instead of having loops inside of a procedure, you should loop the call to the procedure. For example this:
code:
proc game
loop
x -= 1
Pic.Draw(img,x,20,0)
%Never exits, nothing else will run.
end loop
end game
loop
%stuff
%more stuff
game
end loop
Is wrong. Game will never exit and the rest of your main program will never run.
This:
code:
proc game
x -= 1
Pic.Draw(img,x,20,0)
end game
loop
%stuff
%more stuff
game
end loop
Is right. Since there is no loop inside of game, the program will continue once the end of game is reached.
The Lone Ranger
Posted: Sun Dec 13, 2009 5:44 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
OK, but what about the fact that the asteroid only falls in one place during the program.
Also I took the loop out of the procedure, and I was back to where I started, the asteroids don't fall anymore, they just keep apperaring again, and again.
TheGuardian001
Posted: Sun Dec 13, 2009 7:01 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
That's because inside of your loop, you still have these two lines:
code:
randint (x1, 100, maxx)
randint (y1, 280, maxy)
As you know, these lines will randomize the asteroids position. If you have these in your loop, the position will randomize every single time. This is not what you want.
You also have this line:
code:
randint (x1, 100, 599)
Inside of your game procedure. This means that every time you run game to move the asteroid down, you will instead send it to a random location. If you don't want it to randomly jump around, don't randomize the position.
As for it only falling in one spot, you know when the asteroid hits the bottom, so once it does, just randomize where it will fall from. You already have code to move it back up to the top, you just need to combine that with code that will move it left or right.
The Lone Ranger
Posted: Sun Dec 13, 2009 7:25 pm Post subject: Re: Need Help Making Graphics Move By Themselves In Turing
Ok, thank you, you guys have been so, much help. All I have to do is make the asteroid not fall in the same place and I'll be done.
Thanks again.