Pascal

Moderators: None (Apply to moderate this forum)
Number of threads: 4106
Number of posts: 14016

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
making a char move across screen Posted by fredlegman on 4 Apr 2003 at 12:46 PM
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?

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.








Report
Re: making a char move across screen Posted by Phat Nat on 4 Apr 2003 at 1:57 PM
This message was edited by Phat Nat at 2003-4-4 14:1:6

: 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?
:
:
: 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.
: 
: 


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:

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

begin
     thing := 'c';
     blank := ' ';
 
     for position := 1 to 80 do
     begin        
          gotoxy(x,1);
          write(thing:position);
          for timer := 1 to 600
          begin
          end;
          gotoxy(x,1);
          write(blank:position)
     end;
end.


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 delay(10); or put a couple of loops in:
VAR
   X, Y : Word;
Begin
     For Y := 0 to 200 Do
         For X := 0 to 64000 Do;
End;

This should give you a decent speed, but it will change from computer to computer. Anyways, this should solve your problem.

Phat Nat



Report
Re: making a char move across screen Posted by fredlegman on 5 Apr 2003 at 3:15 AM
: This message was edited by Phat Nat at 2003-4-4 14:1:6

: : 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?
: :
: :
: : 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.
: : 
: : 

:
: 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:
:
:
: USES Crt;
: var
:    position : integer;
:    thing : string;
:    timer : integer;
:    blank : string;
: 
: begin
:      thing := 'c';
:      blank := ' ';
:  
:      for position := 1 to 80 do
:      begin        
:           gotoxy(x,1);
:           write(thing:position);
:           for timer := 1 to 600
:           begin
:           end;
:           gotoxy(x,1);
:           write(blank:position)
:      end;
: end.
: 

:
: 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 delay(10); or put a couple of loops in:
:
: VAR
:    X, Y : Word;
: Begin
:      For Y := 0 to 200 Do
:          For X := 0 to 64000 Do;
: End;
: 

: 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


Report
Re: making a char move across screen Posted by Perran on 5 Apr 2003 at 5:40 AM
: : This message was edited by Phat Nat at 2003-4-4 14:1:6

: : : 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?
: : :
: : :
: : : 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.
: : : 
: : : 

: :
: : 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:
: :
: :
: : USES Crt;
: : var
: :    position : integer;
: :    thing : string;
: :    timer : integer;
: :    blank : string;
: : 
: : begin
: :      thing := 'c';
: :      blank := ' ';
: :  
: :      for position := 1 to 80 do
: :      begin        
: :           gotoxy(x,1);
: :           write(thing:position);
: :           for timer := 1 to 600
: :           begin
: :           end;
: :           gotoxy(x,1);
: :           write(blank:position)
: :      end;
: : end.
: : 

: :
: : 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 delay(10); or put a couple of loops in:
: :
: : VAR
: :    X, Y : Word;
: : Begin
: :      For Y := 0 to 200 Do
: :          For X := 0 to 64000 Do;
: : End;
: : 

: : 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:
gotoxy(position,1);

???
Report
Re: making a char move across screen Posted by Phat Nat on 6 Apr 2003 at 3:08 AM
This message was edited by Phat Nat at 2003-4-6 3:9:41

: : : This message was edited by Phat Nat at 2003-4-4 14:1:6

: : : : 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?
: : : :
: : : :
: : : : 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.
: : : : 
: : : : 

: : :
: : : 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:
: : :
: : :
: : : USES Crt;
: : : var
: : :    position : integer;
: : :    thing : string;
: : :    timer : integer;
: : :    blank : string;
: : : 
: : : begin
: : :      thing := 'c';
: : :      blank := ' ';
: : :  
: : :      for position := 1 to 80 do
: : :      begin        
: : :           gotoxy(x,1);
: : :           write(thing:position);
: : :           for timer := 1 to 600
: : :           begin
: : :           end;
: : :           gotoxy(x,1);
: : :           write(blank:position)
: : :      end;
: : : end.
: : : 

: : :
: : : 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 delay(10); or put a couple of loops in:
: : :
: : : VAR
: : :    X, Y : Word;
: : : Begin
: : :      For Y := 0 to 200 Do
: : :          For X := 0 to 64000 Do;
: : : End;
: : : 

: : : 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:
:
: gotoxy(position,1);
: 

: ???

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

Phat Nat






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.