making a char move across screen - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

making a char move across screen

fredlegmanfredlegman Posts: 3Member
I was trying to make a character, a c in this case, move across the screen. I thought that I could use a for loop with a variable and then use that variable as the field width of my c. Unfortunately for some reason i got c's all over the place and not in a straight line. Does anyone no why?

[code]
program move;

var
position : integer;
thing : string;
timer : integer;
blank : string;

begin

thing := 'c';
blank := ' ';

for position := 1 to 80 do
begin
write(thing:position);
for timer := 1 to 600
begin
end;
write(blank:position)
end;
end.

[/code]






Comments

  • Phat NatPhat Nat Posts: 757Member
    [b][red]This message was edited by Phat Nat at 2003-4-4 14:1:6[/red][/b][hr]
    : I was trying to make a character, a c in this case, move across the screen. I thought that I could use a for loop with a variable and then use that variable as the field width of my c. Unfortunately for some reason i got c's all over the place and not in a straight line. Does anyone no why?
    :
    : [code]
    : program move;
    :
    : var
    : position : integer;
    : thing : string;
    : timer : integer;
    : blank : string;
    :
    : begin
    :
    : thing := 'c';
    : blank := ' ';
    :
    : for position := 1 to 80 do
    : begin
    : write(thing:position);
    : for timer := 1 to 600
    : begin
    : end;
    : write(blank:position)
    : end;
    : end.
    :
    : [/code]

    Your problem is that you are writing a "c" and then writing a " " right after it and then repeating this. Try doing it like this:

    [code]
    [b]USES Crt;[/b]
    var
    position : integer;
    thing : string;
    timer : integer;
    blank : string;

    begin
    thing := 'c';
    blank := ' ';

    for position := 1 to 80 do
    begin
    [b]gotoxy(x,1);[/b]
    write(thing:position);
    for timer := 1 to 600
    begin
    end;
    [b]gotoxy(x,1);[/b]
    write(blank:position)
    end;
    end.
    [/code]

    This will set the cursor back to the place were it was so it will actually erase the old "c" before doing the next one. Also, your timer wait command probably won't work too well unless your running an extremely old computer. Try [b]delay(10);[/b] or put a couple of loops in:
    [code]
    VAR
    X, Y : Word;
    Begin
    For Y := 0 to 200 Do
    For X := 0 to 64000 Do;
    End;
    [/code]
    This should give you a decent speed, but it will change from computer to computer. Anyways, this should solve your problem.

    Phat Nat



  • fredlegmanfredlegman Posts: 3Member
    : [b][red]This message was edited by Phat Nat at 2003-4-4 14:1:6[/red][/b][hr]
    : : I was trying to make a character, a c in this case, move across the screen. I thought that I could use a for loop with a variable and then use that variable as the field width of my c. Unfortunately for some reason i got c's all over the place and not in a straight line. Does anyone no why?
    : :
    : : [code]
    : : program move;
    : :
    : : var
    : : position : integer;
    : : thing : string;
    : : timer : integer;
    : : blank : string;
    : :
    : : begin
    : :
    : : thing := 'c';
    : : blank := ' ';
    : :
    : : for position := 1 to 80 do
    : : begin
    : : write(thing:position);
    : : for timer := 1 to 600
    : : begin
    : : end;
    : : write(blank:position)
    : : end;
    : : end.
    : :
    : : [/code]
    :
    : Your problem is that you are writing a "c" and then writing a " " right after it and then repeating this. Try doing it like this:
    :
    : [code]
    : [b]USES Crt;[/b]
    : var
    : position : integer;
    : thing : string;
    : timer : integer;
    : blank : string;
    :
    : begin
    : thing := 'c';
    : blank := ' ';
    :
    : for position := 1 to 80 do
    : begin
    : [b]gotoxy(x,1);[/b]
    : write(thing:position);
    : for timer := 1 to 600
    : begin
    : end;
    : [b]gotoxy(x,1);[/b]
    : write(blank:position)
    : end;
    : end.
    : [/code]
    :
    : This will set the cursor back to the place were it was so it will actually erase the old "c" before doing the next one. Also, your timer wait command probably won't work too well unless your running an extremely old computer. Try [b]delay(10);[/b] or put a couple of loops in:
    : [code]
    : VAR
    : X, Y : Word;
    : Begin
    : For Y := 0 to 200 Do
    : For X := 0 to 64000 Do;
    : End;
    : [/code]
    : This should give you a decent speed, but it will change from computer to computer. Anyways, this should solve your problem.
    :
    : Phat Nat
    :
    :
    :
    :
    thanks I was getting really confused.
    fred


  • PerranPerran Posts: 241Member
    : : [b][red]This message was edited by Phat Nat at 2003-4-4 14:1:6[/red][/b][hr]
    : : : I was trying to make a character, a c in this case, move across the screen. I thought that I could use a for loop with a variable and then use that variable as the field width of my c. Unfortunately for some reason i got c's all over the place and not in a straight line. Does anyone no why?
    : : :
    : : : [code]
    : : : program move;
    : : :
    : : : var
    : : : position : integer;
    : : : thing : string;
    : : : timer : integer;
    : : : blank : string;
    : : :
    : : : begin
    : : :
    : : : thing := 'c';
    : : : blank := ' ';
    : : :
    : : : for position := 1 to 80 do
    : : : begin
    : : : write(thing:position);
    : : : for timer := 1 to 600
    : : : begin
    : : : end;
    : : : write(blank:position)
    : : : end;
    : : : end.
    : : :
    : : : [/code]
    : :
    : : Your problem is that you are writing a "c" and then writing a " " right after it and then repeating this. Try doing it like this:
    : :
    : : [code]
    : : [b]USES Crt;[/b]
    : : var
    : : position : integer;
    : : thing : string;
    : : timer : integer;
    : : blank : string;
    : :
    : : begin
    : : thing := 'c';
    : : blank := ' ';
    : :
    : : for position := 1 to 80 do
    : : begin
    : : [b]gotoxy(x,1);[/b]
    : : write(thing:position);
    : : for timer := 1 to 600
    : : begin
    : : end;
    : : [b]gotoxy(x,1);[/b]
    : : write(blank:position)
    : : end;
    : : end.
    : : [/code]
    : :
    : : This will set the cursor back to the place were it was so it will actually erase the old "c" before doing the next one. Also, your timer wait command probably won't work too well unless your running an extremely old computer. Try [b]delay(10);[/b] or put a couple of loops in:
    : : [code]
    : : VAR
    : : X, Y : Word;
    : : Begin
    : : For Y := 0 to 200 Do
    : : For X := 0 to 64000 Do;
    : : End;
    : : [/code]
    : : This should give you a decent speed, but it will change from computer to computer. Anyways, this should solve your problem.
    : :
    : : Phat Nat
    : :
    : :
    : :
    : :
    : thanks I was getting really confused.
    : fred
    :
    :
    :
    Shouldn't that say:
    [code]
    gotoxy(position,1);
    [/code]
    ???
  • Phat NatPhat Nat Posts: 757Member
    [b][red]This message was edited by Phat Nat at 2003-4-6 3:9:41[/red][/b][hr]
    : : : [b][red]This message was edited by Phat Nat at 2003-4-4 14:1:6[/red][/b][hr]
    : : : : I was trying to make a character, a c in this case, move across the screen. I thought that I could use a for loop with a variable and then use that variable as the field width of my c. Unfortunately for some reason i got c's all over the place and not in a straight line. Does anyone no why?
    : : : :
    : : : : [code]
    : : : : program move;
    : : : :
    : : : : var
    : : : : position : integer;
    : : : : thing : string;
    : : : : timer : integer;
    : : : : blank : string;
    : : : :
    : : : : begin
    : : : :
    : : : : thing := 'c';
    : : : : blank := ' ';
    : : : :
    : : : : for position := 1 to 80 do
    : : : : begin
    : : : : write(thing:position);
    : : : : for timer := 1 to 600
    : : : : begin
    : : : : end;
    : : : : write(blank:position)
    : : : : end;
    : : : : end.
    : : : :
    : : : : [/code]
    : : :
    : : : Your problem is that you are writing a "c" and then writing a " " right after it and then repeating this. Try doing it like this:
    : : :
    : : : [code]
    : : : [b]USES Crt;[/b]
    : : : var
    : : : position : integer;
    : : : thing : string;
    : : : timer : integer;
    : : : blank : string;
    : : :
    : : : begin
    : : : thing := 'c';
    : : : blank := ' ';
    : : :
    : : : for position := 1 to 80 do
    : : : begin
    : : : [b]gotoxy(x,1);[/b]
    : : : write(thing:position);
    : : : for timer := 1 to 600
    : : : begin
    : : : end;
    : : : [b]gotoxy(x,1);[/b]
    : : : write(blank:position)
    : : : end;
    : : : end.
    : : : [/code]
    : : :
    : : : This will set the cursor back to the place were it was so it will actually erase the old "c" before doing the next one. Also, your timer wait command probably won't work too well unless your running an extremely old computer. Try [b]delay(10);[/b] or put a couple of loops in:
    : : : [code]
    : : : VAR
    : : : X, Y : Word;
    : : : Begin
    : : : For Y := 0 to 200 Do
    : : : For X := 0 to 64000 Do;
    : : : End;
    : : : [/code]
    : : : This should give you a decent speed, but it will change from computer to computer. Anyways, this should solve your problem.
    : : :
    : : : Phat Nat
    : : :
    : : :
    : : :
    : : :
    : : thanks I was getting really confused.
    : : fred
    : :
    : :
    : :
    : Shouldn't that say:
    : [code]
    : gotoxy(position,1);
    : [/code]
    : ???

    Right. Usually use [b]X[/b] for my loops. hehe. Apparently I helped him, but I would have been even ore confused if I had read my last post!!! :-D Thanks for catching that.

    Phat Nat



Sign In or Register to comment.