News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_AMSDOS

Moving Graphical Images Down the Screen.

Started by AMSDOS, 11:52, 29 August 12

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

AMSDOS

Hi folks,


I've been trying to work on a specific method of moving graphical images down a screen and I came up with this program:


10 MODE 1: RANDOMIZE TIME
20 DIM r%(200),a%(10)
30 r$=CHR$(225)
40 y%=398:p%=(398*RND)+1
50 x%=x%+1:IF x%>200 THEN x%=1
60 r%(x%)=p%
70 MOVE r%(x%),y%
80 TAG:PRINT a$;:TAGOFF
90 y%=y%-1:IF y%>0 THEN GOTO 70
100 GOTO 40



I've managed to get this routine going with a single image moving down the screen, though I'm a bit stumped how I could set this up so I could get multiple images moving down the screen.
I've setup the a% in that program which doesn't do anything at the moment, I thought a second array needs to be used to gather where the multiple images need to be stored. The r% stores the xpos information though perhaps the size of it (200) is questionable.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

MacDeath


AMSDOS

Quote from: MacDeath on 14:34, 29 August 12
you mean a vertical scrolling ?


The effect might make it seem like vertical scrolling is happening, though what I was looking to recreate is a BASIC demonstration of something which focuses on a series of objects and move them down the screen.


I've already made a routine using LDIR to produce a vertical scrolling effect:


Silly Programming Ideas - Turning Text into Graphics


though it's nature is to physically shift the screen which makes everything shift, which also has it's setbacks.


The small BASIC example I've put here in this case is targeting a specific thing and moving it.


I hope that makes sense.


I think for this example I have to think more about setting up more loops and fetching and storing data from an array. Ultimately BASIC will be a bit slow at this :( though it will help me understanding process better (I hope).
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

This is what I came up with which is a bit closer to the truth, but it's still buggy, the problem is my pixels make it to the bottom line and then the others which I've displaced are left sitting on the screen stranded.



10 MODE 1:RANDOMIZE TIME
20 DIM x%(50),y%(200)
30 loop%=1:FOR n%=398 TO 0 STEP -2:y%(loop%)=n%:loop%=loop%+1:NEXT n%
31 FOR n%=1 TO 5: GOSUB 2000:NEXT n%
40 n%=1: oldn%=n%:a%=1: olda%=a%
60 GOSUB 1000
80 GOTO 60
1000 FOR z%=1 TO 200
1010 FOR s%=1 TO 200
1020 PLOT x%(n%),y%(a%),1
1021 IF a%>50 THEN PLOT x%(n%+1),y%(a%-50)
1022 IF a%>100 THEN PLOT x%(n%+2),y%(a%-100)
1023 IF a%>150 THEN PLOT x%(n%+3),y%(a%-150)
1030 olda%=a%
1040 IF a%<>200 THEN a%=a%+1
1041 IF a%=200 THEN a%=1
1050 PLOT x%(n%),y%(olda%),0
1051 IF a%>50 THEN PLOT x%(n%+1),y%(olda%-50)
1052 IF a%>100 THEN PLOT x%(n%+2),y%(olda%-100)
1053 IF a%>150 THEN PLOT x%(n%+3),y%(olda%-150)
1060 NEXT s%
1090 NEXT z%
1100 RETURN
2000 p%=(RND*398)+1
2010 x%(n%)=p%
2020 RETURN



I'm a bit over this now given I've spent hours on this program today and it shows.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Border_7

I only just copied and pasted this into Winape and ran this now.... looks like rain! Only the first three are left on the screen - the fourth one isn't. Why? something different going on there?
01000001 01101101 01110011 01110100 01110010
01100001 01100100
01000011 01101111 01101101 01110000 01110101
01110100 01101001 01101110 01100111

AMSDOS

Quote from: Border_7 on 06:56, 14 December 12
I only just copied and pasted this into Winape and ran this now.... looks like rain! Only the first three are left on the screen - the fourth one isn't. Why? something different going on there?


This was my attempt in moving some graphical imagery down the screen in a process I could understand a little better, though as you point out some of the objects are left on the screen. It's got something to do with the fetching cycle, my idea of a fetching cycle and the computers fetching cycle are different. The best example I can think of where this can be applied is a Starfield and I think I've got one somewhere which I'll need to check out because it's not using INK switching to make it look like it's a moving Starfield.


What I was trying to do here was simulate a moving starfield like found in Space Storm 2 which simply moves a single cluster of something without actually moving the screen. :( Handy because you don't need to worry about other objects being moved out of place.  The Game which was in The PC Mag I just sent you I thought was a perfect example of where it could be applied. Though I would of been happier to understand the process, rather than do a rip-off job of Space Storm 2. :(
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

With some help from a friend at work with a clear understanding of conditions, I've been able to interpret their Pseudocode into BASIC using the process outlined and then enhanced the program further by making 3 Dimensional Arrays with the 3 parameter relating to each pixel (star) which needs to be moved and simply using a FOR loop to count between those stars and move them to the next position, which is simply down the screen. Using this approach I can plot multiple pixels on the screen and move them accordingly without actually physically moving the screen. So while this example is written in BASIC, I hope that it can be written in other languages to that it will improve results, my only concern with this approach is the 3 Dimensional Array.

10 DIM a%(1,2,10),olda%(1,2,10)
20 FOR n%=1 TO 10:a%(1,1,n%)=(RND*160):a%(1,2,n%)=(RND*398):NEXT n%
30 MODE 0:INK 0,0:INK 1,26
40 WHILE 1
50  FOR n%=1 TO 10
60   olda%(1,1,n%)=a%(1,1,n%):olda%(1,2,n%)=a%(1,2,n%)
70   IF a%(1,2,n%)>2 THEN a%(1,2,n%)=a%(1,2,n%)-2 ELSE tst%=1
80   IF tst%=1 THEN a%(1,1,n%)=(RND*160):a%(1,2,n%)=398:tst%=0
90   PLOT a%(1,1,n%),a%(1,2,n%),1
100  PLOT olda%(1,1,n%),olda%(1,2,n%),0
110 NEXT n%
120 WEND


* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

This time around what I have done is created an array with an object in it and I'm moving it down the screen, I've made two examples in BASIC (to show the process), the first is text orientated using LOCATE & PRINT (solid block) to position the image, move it's position and redraw it. I'm using 0 from the 3rd Array I've setup (for the Ball Data), to delete the image.

10 DIM ball%(128),oldball%(128),grid%(64)
20 GOSUB 500
30 xn%=1:yn%=1
40 FOR no%=1 TO 128 STEP 2
50  x%=no%:y%=no%+1
60  ball%(x%)=xn%:xn%=xn%+1
70  IF xn%=9 THEN tst%=1:xn%=1
80  ball%(y%)=yn%
90  IF tst%=1 THEN yn%=yn%+1:tst%=0
100  IF yn%=9 THEN yn%=1
110 NEXT no%
120 MODE 0:INK 0,0:INK 1,26
130 WHILE 1:num%=1
140 FOR no%=1 TO 128 STEP 2
150  x%=no%:y%=no%+1
160  IF ball%(y%)<20 THEN ball%(y%)=ball%(y%)+1 ELSE tst%=1
170  IF tst%=1 THEN ball%(y%)=1:tst%=0
180  oldball%(x%)=ball%(x%):oldball%(y%)=ball%(y%)
190  LOCATE ball%(x%),ball%(y%):IF grid%(num%)=1 THEN PRINT CHR$(143);
200  LOCATE oldball%(x%),oldball%(y%):IF grid%(num%)=0 THEN PRINT CHR$(32);
210  num%=num%+1
220 NEXT no%
230 num%=1
240 WEND
500 FOR num%=1 TO 64
510 READ c%
520 grid%(num%)=c%
530 NEXT num%
540 RETURN
550 DATA 0,0,0,0,0,0,0,0
560 DATA 0,0,0,1,1,0,0,0
570 DATA 0,0,1,0,0,1,0,0
580 DATA 0,0,1,0,0,1,0,0
590 DATA 0,0,1,0,0,1,0,0
600 DATA 0,0,1,0,0,1,0,0
610 DATA 0,0,0,1,1,0,0,0
620 DATA 0,0,0,0,0,0,0,0


The second program is a little bit different and to get a similar effect, a few changes had to be taken place with the variables for the effects to take place.

10 DIM ball%(128),oldball%(128),grid%(64)
20 GOSUB 500
30 xn%=0:yn%=398
40 FOR no%=1 TO 128 STEP 2
50  x%=no%:y%=no%+1
60  ball%(x%)=xn%:xn%=xn%+4
70  IF xn%=32 THEN tst%=1:xn%=0
80  ball%(y%)=yn%
90  IF tst%=1 THEN yn%=yn%-2:tst%=0
100  IF yn%=18 THEN yn%=398
110 NEXT no%
120 MODE 0:INK 0,0:INK 1,26
130 WHILE 1:num%=1
140 FOR no%=1 TO 128 STEP 2
150  x%=no%:y%=no%+1
160  IF ball%(y%)>18 THEN ball%(y%)=ball%(y%)-2 ELSE tst%=1
170  IF tst%=1 THEN ball%(y%)=398:tst%=0
180  oldball%(x%)=ball%(x%):oldball%(y%)=ball%(y%)
190  IF grid%(num%)=1 THEN PLOT ball%(x%),ball%(y%),1
200  IF grid%(num%)=0 THEN PLOT oldball%(x%),oldball%(y%),0
210  num%=num%+1
220 NEXT no%
230 num%=1
240 WEND
500 FOR num%=1 TO 64
510 READ c%
520 grid%(num%)=c%
530 NEXT num%
540 RETURN
550 DATA 0,0,0,0,0,0,0,0
560 DATA 0,0,0,1,1,0,0,0
570 DATA 0,0,1,0,0,1,0,0
580 DATA 0,0,1,1,1,1,0,0
590 DATA 0,0,1,0,0,1,0,0
600 DATA 0,0,1,0,0,1,0,0
610 DATA 0,0,0,1,1,0,0,0
620 DATA 0,0,0,0,0,0,0,0


The process may not be much to look at, though with these sort of programs done in other languages, it may be possible to have user designed levels specifically in games or something of that nature which make it look as if the screen is moving around.

I made some attempt at making an Assembly equivalent a couple of weeks ago with the random star version, though I didn't have much luck, but certainly feel to make one if it's no hassle, cause I'd certainly like to see the process.  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Devilmarkus

You use very slow routines here.
Is that wanted?
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

AMSDOS

Quote from: Devilmarkus on 17:31, 31 August 13
You use very slow routines here.
Is that wanted?

Er no. I'm using BASIC to show the process.  :)
The idea here was to make a pattern and move it accordingly, which I've done here successfully.

I can rework it like I reworked the random stars program above so it exists in Pascal and Small-C which will improve the speed of it, though I'm keen to see an Assembly equivalent of it. I'll see if I can use CPC BASIC 3 to knock up something.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

#10
Quote from: Devilmarkus on 17:31, 31 August 13
You use very slow routines here.
Is that wanted?

Yes I see what you mean. I took the second example and used CPC BASIC 3 to make an Assembly file of it, but it was very slow, however the program is wrong in the context I'm writing it for. I don't know why I decided to make a graphical plot version of it now, I was mucking about with the Text Version and perhaps thought the graphical version would present some challenge.  Using it to make an Assembly equivalent of the program was just stupid of me.

The first example with the 8x8 Squares is perhaps a closer representation and wrote that just to see how to move a pattern from an array, though eventually I thought it would be good to use it for generating some sort of Level Data and have that Data (represented as Large 16x16 Sprites) move around the screen without physically moving the screen. I can probably play around with that idea soon and post something in here.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

This is more like what I'm trying to produce:

10 DIM ball%(128),oldball%(128),grid%(64)
20 GOSUB 250
30 xn%=1:yn%=20
40 FOR no%=1 TO 128 STEP 2
50  x%=no%:y%=no%+1
60  ball%(x%)=xn%:xn%=xn%+1
70  IF xn%=9 THEN tst%=1:xn%=1
80  ball%(y%)=yn%
90  IF tst%=1 THEN yn%=yn%-1:tst%=0
100  IF yn%=1 THEN yn%=20
110 NEXT no%
120 MODE 0:INK 0,0:INK 1,26
130 WHILE 1:num%=1
140 FOR no%=1 TO 128 STEP 2
150  x%=no%:y%=no%+1
151  oldball%(x%)=ball%(x%):oldball%(y%)=ball%(y%)
160  IF ball%(y%)>2 THEN ball%(y%)=ball%(y%)-1 ELSE tst%=1
170  IF tst%=1 THEN ball%(y%)=20:tst%=0
190  LOCATE ball%(x%),ball%(y%):IF grid%(num%)=1 THEN PRINT CHR$(143);
200  LOCATE oldball%(x%),oldball%(y%):IF grid%(num%)=1 THEN PRINT" ";
210  num%=num%+1
220 NEXT no%
230 num%=1
240 WEND
250 FOR num%=1 TO 64
260 READ c%
270 grid%(num%)=c%
280 NEXT num%
290 RETURN
300 DATA 0,0,0,0,0,0,0,1
310 DATA 1,0,0,0,0,0,0,0
320 DATA 0,0,1,0,0,1,0,0
330 DATA 0,0,0,0,0,0,0,0
340 DATA 0,1,0,0,0,0,0,0
350 DATA 1,0,1,0,0,0,0,0
360 DATA 0,0,0,1,1,0,0,0
370 DATA 0,0,0,0,0,0,0,1


So in this example I've define a pattern using the array and then that pattern gets moved, this example seems to be faster in BASIC.

Only problem with this example is I've told it to setup the Y-coordinate in Line 30 to be 20, so what happens is when the Data from the Array gets displayed the Y position is reversed - so the top line starts at the bottom and the bottom line at the top for example. So to fix that the setup needs to be altered:

30 xn%=1:yn%=1
90  IF tst%=1 THEN yn%=yn%+1:tst%=0
100  IF yn%=20 THEN yn%=1


But I haven't fixed this in the attached file.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

This is the latest version I've done which is more of an example of making a maze like effect and moving it along.

10 DIM ball%(320),oldball%(320),grid%(160)
20 GOSUB 250
30 xn%=1:yn%=3
40 FOR no%=1 TO 320 STEP 2
50  x%=no%:y%=no%+1
60  ball%(x%)=xn%:xn%=xn%+1
70  IF xn%=9 THEN tst%=1:xn%=1
80  ball%(y%)=yn%
90  IF tst%=1 THEN yn%=yn%+1:tst%=0
110 NEXT no%
120 MODE 0:INK 0,0:INK 1,26
130 num%=1:WHILE 1
140 FOR no%=1 TO 320 STEP 2
150  x%=no%:y%=no%+1
151  oldball%(x%)=ball%(x%):oldball%(y%)=ball%(y%)
160  IF ball%(y%)>2 THEN ball%(y%)=ball%(y%)-1 ELSE tst%=1
170  IF tst%=1 THEN ball%(y%)=24:tst%=0
190  LOCATE ball%(x%),ball%(y%):IF grid%(num%)=1 THEN PRINT CHR$(143)
200  LOCATE oldball%(x%),oldball%(y%):IF grid%(num%)=1 THEN PRINT" "
210  IF num%<160 THEN num%=num%+1
220 NEXT no%
230 IF num%=160 THEN num%=1
240 WEND
250 FOR num%=1 TO 160
260 READ c%
270 grid%(num%)=c%
280 NEXT num%
290 RETURN
300 DATA 0,0,0,0,0,0,0,1
310 DATA 1,0,0,0,0,0,0,0
320 DATA 0,0,1,0,0,1,0,0
330 DATA 0,0,0,0,0,0,0,0
340 DATA 0,1,0,0,0,0,0,0
350 DATA 1,0,1,0,0,0,0,0
360 DATA 0,0,0,1,1,0,0,0
370 DATA 0,0,0,0,0,0,0,1
440 DATA 0,0,0,0,0,0,0,0
450 DATA 0,0,0,0,0,0,0,0
460 DATA 1,0,0,0,0,1,1,1
470 DATA 1,1,1,0,0,0,0,1
480 DATA 1,1,1,0,0,0,0,1
490 DATA 1,0,0,1,1,0,0,1
500 DATA 0,0,0,0,0,0,0,0
520 DATA 0,0,0,0,0,0,0,0
530 DATA 1,0,0,1,0,0,1,1
540 DATA 1,0,0,1,1,0,0,1
550 DATA 1,0,0,0,0,0,0,1
560 DATA 1,1,0,0,1,1,1,1


But I'm having problems with it in regards to what I'm trying to do (but this example works though). The issue I'm having is when I'm trying to limit the size of the moving area to an area of 8x8, the rest of my Maze Data is coming in and overwriting the first bit of the Data for it, which I don't want. What I would like instead is to draw the first bit of the array, move that to a spot and as that moves, move in the next bit of the array to the bottom and the top bit disappears, never to return sort of thing. I know it has something to do with how I've setup the num% variable, which points to the position of the Maze Array (I called it Grid%) and I feel I'm missing some condition and I'm not calculating the next position of that array properly, which I'm having difficulty working out.  Can anyone help please? :'(
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

AMSDOS

I've had a bit more of a play around with this program above, but it looks like I'll have to go back to the idea of having a 3D Array for this to work, I'm not sure, it's coming up with Subscript out of Range error, even though I'm telling my loop to exit when it's supposed to be going past a certain number.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ervin

#14
Hi there.

I'm not sure what isn't working as I'm not sure what exactly you're trying to do, but I have noticed that line 170 sets ball(y) to 24.
Is that what you want to do?
In the setup in lines 40 to 110, ball(y) maxes out at 22.

You could probably speed things up a little bit by rearranging lines 190 and 200 to look like this:

190  IF grid%(num%)=1 THEN LOCATE ball%(x%),ball%(y%):PRINT CHR$(143)
200  IF grid%(num%)=1 THEN LOCATE oldball%(x%),oldball%(y%):PRINT" "


Also, if you take out the "WHILE 1" in line 130, and change the WEND in 240 to GOTO 130, you can remove 230, and "num" will always reset back to 1 before each run through the FOR loop starting on 140.
You'll also be able to take out the IF check in 210, and simply increment num.

You can also simplify (and make slightly faster) the initialisation code by removing tst%.

40 FOR no%=1 TO 320 STEP 2
50  x%=no%:y%=no%+1
60  ball%(x%)=xn%:ball%(y%)=yn%
70  xn%=xn%+1:IF xn%=9 THEN xn%=1:yn%=yn%+1
110 NEXT no%


On that note, you can remove tst% from lines 160 and 170 (in fact remove 170 altogether), and change 160 to this:

160  IF ball%(y%)>2 THEN ball%(y%)=ball%(y%)-1 ELSE ball%(y%)=24


You can also combine lines 190 and 200, and remove a repeated IF check.

190  IF grid%(num%)=1 THEN LOCATE ball%(x%),ball%(y%):PRINT CHR$(143):LOCATE oldball%(x%),oldball%(y%):PRINT " "


You can do more to speed up your initialisation code:

250 FOR num%=1 TO 160
260 READ grid%(num%)
280 NEXT num%
290 RETURN


Also, I've just noticed that you don't need oldball%(x%) in this code.
Just use ball%(x%).

(I love optimising stuff, and I couldn't resist!)

Here's how the code looks now in my editor:

10 DIM ball%(320),oldball%(320),grid%(160)
20 GOSUB 250
30 xn%=1:yn%=3

40 FOR no%=1 TO 320 STEP 2
50  x%=no%:y%=no%+1
60  ball%(x%)=xn%:ball%(y%)=yn%
70  xn%=xn%+1:IF xn%=9 THEN xn%=1:yn%=yn%+1
110 NEXT no%

120 MODE 0:INK 0,0:INK 1,26

130 num%=1
140 FOR no%=1 TO 320 STEP 2
150  x%=no%:y%=no%+1
151  oldball%(y%)=ball%(y%)
160  IF ball%(y%)>2 THEN ball%(y%)=ball%(y%)-1 ELSE ball%(y%)=22
190  IF grid%(num%)=1 THEN LOCATE ball%(x%),ball%(y%):PRINT CHR$(143):LOCATE ball%(x%),oldball%(y%):PRINT " "
210  num%=num%+1
220 NEXT no%

240 GOTO 130

250 FOR num%=1 TO 160
260 READ grid%(num%)
280 NEXT num%
290 RETURN

300 DATA 0,0,0,0,0,0,0,1
310 DATA 1,0,0,0,0,0,0,0
320 DATA 0,0,1,0,0,1,0,0
330 DATA 0,0,0,0,0,0,0,0
340 DATA 0,1,0,0,0,0,0,0
350 DATA 1,0,1,0,0,0,0,0
360 DATA 0,0,0,1,1,0,0,0
370 DATA 0,0,0,0,0,0,0,1
440 DATA 0,0,0,0,0,0,0,0
450 DATA 0,0,0,0,0,0,0,0
460 DATA 1,0,0,0,0,1,1,1
470 DATA 1,1,1,0,0,0,0,1
480 DATA 1,1,1,0,0,0,0,1
490 DATA 1,0,0,1,1,0,0,1
500 DATA 0,0,0,0,0,0,0,0
520 DATA 0,0,0,0,0,0,0,0
530 DATA 1,0,0,1,0,0,1,1
540 DATA 1,0,0,1,1,0,0,1
550 DATA 1,0,0,0,0,0,0,1
560 DATA 1,1,0,0,1,1,1,1

ervin

#15
Here's a rewritten version that does away with the need for 2 PRINTs for each cell.
I've also discarded the ball% and oldball% arrays.
It's quite a bit faster.


10 dim map%(160),scr%(160)
100 FOR n%=1 TO 160
110 scr%(n%)=0
120 READ map%(n%)
130 NEXT n%
200 MODE 0:INK 0,0:INK 1,26
210 base%=1
300 s%=1:m%=base%
310 for y%=3 to 22
320 for x%=1 to 8
330 if scr%(s%)=map%(m%) then goto 360
340 scr%(s%)=map%(m%)
350 locate x%,y%:if map%(m%)=1 then print chr$(143) else print " "
360 s%=s%+1:m%=m%+1
370 NEXT x%
380 if m%>160 then m%=1
390 next y%
500 base%=base%+8
510 if base%>160 then base%=1
520 goto 300
600 DATA 0,0,0,0,0,0,0,1
610 DATA 1,0,0,0,0,0,0,0
620 DATA 0,0,1,0,0,1,0,0
630 DATA 0,0,0,0,0,0,0,0
640 DATA 0,1,0,0,0,0,0,0
650 DATA 1,0,1,0,0,0,0,0
660 DATA 0,0,0,1,1,0,0,0
670 DATA 0,0,0,0,0,0,0,1
680 DATA 0,0,0,0,0,0,0,0
690 DATA 0,0,0,0,0,0,0,0
700 DATA 1,0,0,0,0,1,1,1
710 DATA 1,1,1,0,0,0,0,1
720 DATA 1,1,1,0,0,0,0,1
730 DATA 1,0,0,1,1,0,0,1
740 DATA 0,0,0,0,0,0,0,0
750 DATA 0,0,0,0,0,0,0,0
760 DATA 1,0,0,1,0,0,1,1
770 DATA 1,0,0,1,1,0,0,1
780 DATA 1,0,0,0,0,0,0,1
790 DATA 1,1,0,0,1,1,1,1

ervin

And here's the 8x8 version.


10 dim map%(160),scr%(64)
100 FOR n%=1 TO 160:READ map%(n%):next n%
110 FOR n%=1 TO 64:scr%(n%)=0:next n%
200 MODE 0:INK 0,0:INK 1,26
210 base%=1
300 s%=1:m%=base%
310 for y%=1 to 8
320 for x%=1 to 8
330 if scr%(s%)=map%(m%) then goto 360
340 scr%(s%)=map%(m%)
350 locate x%,y%:if map%(m%)=1 then print chr$(143) else print " "
360 s%=s%+1:m%=m%+1
370 NEXT x%
380 if m%>160 then m%=1
390 next y%
500 base%=base%+8
510 if base%>160 then base%=1
520 goto 300
600 DATA 0,0,0,0,0,0,0,1
610 DATA 1,0,0,0,0,0,0,0
620 DATA 0,0,1,0,0,1,0,0
630 DATA 0,0,0,0,0,0,0,0
640 DATA 0,1,0,0,0,0,0,0
650 DATA 1,0,1,0,0,0,0,0
660 DATA 0,0,0,1,1,0,0,0
670 DATA 0,0,0,0,0,0,0,1
680 DATA 0,0,0,0,0,0,0,0
690 DATA 0,0,0,0,0,0,0,0
700 DATA 1,0,0,0,0,1,1,1
710 DATA 1,1,1,0,0,0,0,1
720 DATA 1,1,1,0,0,0,0,1
730 DATA 1,0,0,1,1,0,0,1
740 DATA 0,0,0,0,0,0,0,0
750 DATA 0,0,0,0,0,0,0,0
760 DATA 1,0,0,1,0,0,1,1
770 DATA 1,0,0,1,1,0,0,1
780 DATA 1,0,0,0,0,0,0,1
790 DATA 1,1,0,0,1,1,1,1

ervin

Wow... I just compiled the program using CPC Basic 3 (no changes needed in this case), and the speed difference is astonishing!

Despite using the same print routine (I believe locomotive basic and cpc basic 3 both call the firmware for PRINT), the cpc basic 3 version is much, much faster.

AMSDOS

That's Fantastic, thanks very much for doing that.  :)

The 8x8 is the sort of code I'm looking for. I can see the trouble was I was using one variable called num% to try and move through the array that way, but it wasn't working. Originally I had the ball% & oldball% array from when I was using arrays for the graphical Starfield, though Text Based Objects don't need an array to store those sorts of values and as you say it slows things down.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ervin

Cool, glad I could help.
:)

(I was paranoid that I was stepping on your toes a bit).
:-[

ervin

#20
Just out of interest, I replaced the PRINT commands with POKES directly into screen memory.

In Locomotive Basic, it's horrendously slow (MUCH slower than using PRINT). Just shows how slow direct memory access is from Basic!

But in CPC Basic 3... WOW!!!
You'll be amazed at the difference.


10 dim map%(160),scr%(160)
100 FOR n%=1 TO 160
110 scr%(n%)=0
120 READ map%(n%)
130 NEXT n%
200 MODE 0:INK 0,0:INK 1,26
210 base%=1
300 s%=1:m%=base%
301 charAddr=&c0a0
310 for y%=3 to 22
320 for x%=1 to 8
330 if scr%(s%)=map%(m%) then goto 360
340 scr%(s%)=map%(m%)
350 if map%(m%)=1 then colour%=&c0 else colour%=0
351 for addr=0 to &3800 step &800
352 poke charAddr+addr,colour%
353 poke charAddr+addr+1,colour%
354 poke charAddr+addr+2,colour%
355 poke charAddr+addr+3,colour%
356 next addr
360 s%=s%+1:m%=m%+1
365 charAddr=charAddr+4
370 NEXT x%
380 if m%>160 then m%=1
381 charAddr=charAddr-32+&50
390 next y%
500 base%=base%+8
510 if base%>160 then base%=1
520 goto 300
600 DATA 0,0,0,0,0,0,0,1
610 DATA 1,0,0,0,0,0,0,0
620 DATA 0,0,1,0,0,1,0,0
630 DATA 0,0,0,0,0,0,0,0
640 DATA 0,1,0,0,0,0,0,0
650 DATA 1,0,1,0,0,0,0,0
660 DATA 0,0,0,1,1,0,0,0
670 DATA 0,0,0,0,0,0,0,1
680 DATA 0,0,0,0,0,0,0,0
690 DATA 0,0,0,0,0,0,0,0
700 DATA 1,0,0,0,0,1,1,1
710 DATA 1,1,1,0,0,0,0,1
720 DATA 1,1,1,0,0,0,0,1
730 DATA 1,0,0,1,1,0,0,1
740 DATA 0,0,0,0,0,0,0,0
750 DATA 0,0,0,0,0,0,0,0
760 DATA 1,0,0,1,0,0,1,1
770 DATA 1,0,0,1,1,0,0,1
780 DATA 1,0,0,0,0,0,0,1
790 DATA 1,1,0,0,1,1,1,1

ervin

#21
Of course it can be made considerably faster by unrolling the FOR loop that the pokes live in.
(Try this in CPC Basic 3).
8)


10 dim map%(160),scr%(160)
100 FOR n%=1 TO 160
110 scr%(n%)=0
120 READ map%(n%)
130 NEXT n%
200 MODE 0:INK 0,0:INK 1,26
210 base%=1
300 s%=1:m%=base%
301 charAddr=&c0a0
310 for y%=3 to 22
320 for x%=1 to 8
330 if scr%(s%)=map%(m%) then goto 360
340 scr%(s%)=map%(m%)
350 if map%(m%)=1 then colour%=&c0 else colour%=0
351 poke charAddr+0,colour%:poke charAddr+1,colour%:poke charAddr+2,colour%:poke charAddr+3,colour%
352 poke charAddr+&800,colour%:poke charAddr+&801,colour%:poke charAddr+&802,colour%:poke charAddr+&803,colour%
353 poke charAddr+&1000,colour%:poke charAddr+&1001,colour%:poke charAddr+&1002,colour%:poke charAddr+&1003,colour%
354 poke charAddr+&1800,colour%:poke charAddr+&1801,colour%:poke charAddr+&1802,colour%:poke charAddr+&1803,colour%
355 poke charAddr+&2000,colour%:poke charAddr+&2001,colour%:poke charAddr+&2002,colour%:poke charAddr+&2003,colour%
356 poke charAddr+&2800,colour%:poke charAddr+&2801,colour%:poke charAddr+&2802,colour%:poke charAddr+&2803,colour%
357 poke charAddr+&3000,colour%:poke charAddr+&3001,colour%:poke charAddr+&3002,colour%:poke charAddr+&3003,colour%
358 poke charAddr+&3800,colour%:poke charAddr+&3801,colour%:poke charAddr+&3802,colour%:poke charAddr+&3803,colour%
360 s%=s%+1:m%=m%+1
365 charAddr=charAddr+4
370 NEXT x%
380 if m%>160 then m%=1
381 charAddr=charAddr-32+&50
390 next y%
500 base%=base%+8
510 if base%>160 then base%=1
520 goto 300
600 DATA 0,0,0,0,0,0,0,1
610 DATA 1,0,0,0,0,0,0,0
620 DATA 0,0,1,0,0,1,0,0
630 DATA 0,0,0,0,0,0,0,0
640 DATA 0,1,0,0,0,0,0,0
650 DATA 1,0,1,0,0,0,0,0
660 DATA 0,0,0,1,1,0,0,0
670 DATA 0,0,0,0,0,0,0,1
680 DATA 0,0,0,0,0,0,0,0
690 DATA 0,0,0,0,0,0,0,0
700 DATA 1,0,0,0,0,1,1,1
710 DATA 1,1,1,0,0,0,0,1
720 DATA 1,1,1,0,0,0,0,1
730 DATA 1,0,0,1,1,0,0,1
740 DATA 0,0,0,0,0,0,0,0
750 DATA 0,0,0,0,0,0,0,0
760 DATA 1,0,0,1,0,0,1,1
770 DATA 1,0,0,1,1,0,0,1
780 DATA 1,0,0,0,0,0,0,1
790 DATA 1,1,0,0,1,1,1,1

AMSDOS

Quote from: ervin on 03:01, 09 September 13
Cool, glad I could help.
:)

(I was paranoid that I was stepping on your toes a bit).
:-[

Not at all, I'm only trying to get an idea of the approach used in making a redefined maze so that anyone could implement it possibly to their language.

I think this code is extremely useful and you were even able to optimise the code, something I'm not terribly good at because I turn to Compiled Languages or Assembly if I want to enhance code.
I think it's good to be able to show the process and doing it in BASIC will allow people to see a working version of the program, earlier on I was able to take the Starfield routine and write it into Pascal & Small-C, which also took advantage of those routines when they were converted into Machine Code.
The CPC BASIC 3 situation has done the same thing and indeed using a printing workaround with POKE instead of PRINT I think means you're using LD instructions instead of the firmware &BB5A for TXT OUTPUT, I'm unsure if CPC BASIC 3 uses TXT OUTPUT in conjunction with PRINT, though the alternative is to use TXT WR CHAR (&BB5D), which does the same thing, though doesn't preserve the registers, which I think makes it a little bit faster.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ervin

#23
Interesting... CPC Basic 3 compiles to CCZ80 before compiling to machine code.
CCZ80 is my CPC language of choice, so I had a look at the generated code... and I felt right at home.

I converted the code that writes direct to VRAM (the equivalent of the POKEs in the Basic code) into hastily optimised inline assembly, and now it is running at around 27 fps!

AMSDOS

Quote from: ervin on 06:44, 09 September 13
Interesting... CPC Basic 3 compiles to CCZ80 before compiling to machine code.
CCZ80 is my CPC language of choice, so I had a look at the generated code... and I felt right at home.

I converted the code that writes direct to VRAM (the equivalent of the POKEs in the Basic code) into hastily optimised inline assembly, and now it is running at around 27 fps!

Yeah, I had a little look at that and generated some CCZ80 Source Code Files which look pretty good, I haven't had much to do with CCZ80, though I should be able to take that BASIC code and make working versions of it from Pascal & Small-C. Don't know if they will be running at 27 fps, how do you measure the fps?
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Powered by SMFPacks Menu Editor Mod