Follow the course at https://www.facebook.com/groups/867151224158600 METTIAMO INSIEME BINARI E VAGONI Segui il corso su at https://www.facebook.com/groups/867151224158600 NOUS ASSEMBLONS LES CHENILLES ET LES WAGONS Suivez le cours sur https://www.facebook.com/groups/867151224158600
DEFINE STRING SPACE 256 DEFINE STRING COUNT 16 BITMAP ENABLE(16) CLS wagonLRImage := LOAD IMAGE( "/usr/src/mine-rails/resources/wagonLR.png") wagonUDImage := LOAD IMAGE( "/usr/src/mine-rails/resources/wagonUD.png") level1 := LOAD TILEMAP("/usr/src/mine-rails/resources/level1.tmx") tileset := TILESET(level1) '''''''' POSITIVE CONST startX = 1 POSITIVE CONST startY = 1 POSITIVE CONST tileWidth = TILE WIDTH( tileset ) POSITIVE CONST tileWidth2 = (SCREEN SPRITE RATIO X / 100 ) * tileWidth POSITIVE CONST tileHeight = TILE HEIGHT( tileset ) POSITIVE CONST screenWidthInTiles = SCREEN WIDTH / tileWidth POSITIVE CONST screenHeightInTiles = SCREEN HEIGHT / tileHeight POSITIVE CONST maxPageX = ( ( TILEMAP WIDTH( level1 ) - 1 ) / screenWidthInTiles ) + 1 POSITIVE CONST maxPageY = ( ( TILEMAP HEIGHT( level1 ) - 1 ) / screenHeightInTiles ) + 1 CONST offsetX = tileWidth2/2 - 8 CONST offsetY = 4 POSITIVE CONST wagonSpeed = 1 POSITIVE CONST wagonSpeedX = 1 POSITIVE CONST wagonSpeedY = 1 '''''' POSITIVE CONST railLU = TILE ID( tileset, railLU ) POSITIVE CONST railLD = TILE ID( tileset, railLD ) POSITIVE CONST railRU = TILE ID( tileset, railRU ) POSITIVE CONST railRD = TILE ID( tileset, railRD ) POSITIVE CONST railLR = TILE ID( tileset, railLR ) POSITIVE CONST railUD = TILE ID( tileset, railUD ) POSITIVE CONST terrain = TILE ID( tileset, terrain ) POSITIVE CONST terrain2 = TILE ID( tileset, terrain2 ) POSITIVE CONST score = TILE ID( tileset, score ) POSITIVE CONST digit0 = TILE ID( tileset, digit0 ) POSITIVE CONST wagonST = TILE ID( tileset, wagonST ) POSITIVE CONST railLRbroken = TILE ID( tileset, railLRbroken ) POSITIVE CONST railUDbroken = TILE ID( tileset, railUDbroken ) POSITIVE CONST sign = TILE ID( tileset, sign ) POSITIVE CONST wagonLR = 0 POSITIVE CONST wagonUD = 1 wagon = CSPRITE( wagonLRImage ) POSITIVE CONST wagonImageWidth = IMAGE WIDTH( wagonLRImage ) POSITIVE CONST wagonImageHeight = IMAGE HEIGHT( wagonLRImage ) POSITIVE CONST minWagonX = SCREEN BORDER X POSITIVE CONST minWagonY = SCREEN BORDER Y POSITIVE CONST screenWidthInWagonCoords = ( SCREEN WIDTH * SCREEN SPRITE RATIO X ) / 100 POSITIVE CONST screenHeightInWagonCoords = ( SCREEN HEIGHT * SCREEN SPRITE RATIO Y ) / 100 POSITIVE CONST maxWagonX = SCREEN BORDER X + offsetX + screenWidthInWagonCoords - wagonImageWidth POSITIVE CONST maxWagonY = SCREEN BORDER Y + offsetY + screenHeightInWagonCoords - ( wagonImageHeight * SCREEN SPRITE RATIO X ) / 100 DIM actualPageX AS SIGNED BYTE DIM actualPageY AS SIGNED BYTE DIM previousPageX AS SIGNED BYTE = -1 DIM previousPageY AS SIGNED BYTE = -1 DIM x AS POSITION = SCREEN BORDER X + offsetX + startX*tileWidth2 DIM y AS POSITION = SCREEN BORDER Y + offsetY + startY*tileHeight DIM px AS POSITION = -1 DIM py AS POSITION = -1 DIM dx AS POSITION = 0 DIM dy AS POSITION = 0 DIM c AS POSITION = 0 ''''''''' DIM previousRail AS BYTE DIM actualRail AS BYTE ''''''''' DIM tx AS BYTE = startX DIM ty AS BYTE = startY DIM wagonId AS BYTE = 0 PROCEDURE changeWagonSpriteAndDirection[ rail AS BYTE, previous AS BYTE ] SHARED wagon, level1, tileset, tx, ty SHARED wagonUDImage, wagonLRImage, x, y, dx, dy SHARED actualPageX, actualPageY, previousPageX, previousPageY DIM tocheck AS BYTE tocheck = rail IF rail = terrain OR rail = terrain2 THEN tocheck = previous ENDIF IF ( dx > 0 ) AND ( tocheck <> railLR ) THEN dx = 0 dy = 0 IF tocheck = previous THEN DEC tx ENDIF SELECT CASE tocheck CASE railLU dx = 0 dy = -wagonSpeedY wagon = CSPRITE( wagonUDImage, wagon ) wagonId = wagonUD CASE railLD dx = 0 dy = wagonSpeedY wagon = CSPRITE( wagonUDImage, wagon ) wagonId = wagonUD ENDSELECT ELSE IF ( dx < 0 ) AND ( tocheck <> railLR ) THEN dx = 0 dy = 0 IF tocheck = previous THEN INC tx ENDIF SELECT CASE tocheck CASE railRU dx = 0 dy = -wagonSpeedY wagon = CSPRITE( wagonUDImage, wagon ) wagonId = wagonUD CASE railRD dx = 0 dy = wagonSpeedY wagon = CSPRITE( wagonUDImage, wagon ) wagonId = wagonUD ENDSELECT ELSE IF ( dy > 0 ) AND ( tocheck <> railUD ) THEN dx = 0 dy = 0 IF tocheck = previous THEN DEC ty ENDIF SELECT CASE tocheck CASE railLU dx = -wagonSpeedX dy = 0 wagon = CSPRITE( wagonLRImage, wagon ) wagonId = wagonLR CASE railRU dx = wagonSpeedX dy = 0 wagon = CSPRITE( wagonLRImage, wagon ) wagonId = wagonLR ENDSELECT ELSE IF ( dy < 0 ) AND ( tocheck <> railUD ) THEN dx = 0 dy = 0 IF tocheck = previous THEN INC ty ENDIF SELECT CASE tocheck CASE railLD dx = -wagonSpeedX dy = 0 wagon = CSPRITE( wagonLRImage, wagon ) wagonId = wagonLR CASE railRD dx = wagonSpeedX dy = 0 wagon = CSPRITE( wagonLRImage, wagon ) wagonId = wagonLR ENDSELECT ENDIF END PROC PROCEDURE moveWagonToStart SHARED tx, ty, x, y, dx, dy SHARED actualPageX, actualPageY SHARED previousPageX, previousPageY tx = startX ty = startY x = SCREEN BORDER X + offsetX + startX*tileWidth2 y = SCREEN BORDER Y + offsetY + startY*tileHeight actualPageX = 0 actualPageY = 0 previousPageX = -1 previousPageY = -1 dx = wagonSpeedX dy = 0 changeWagonSpriteAndDirection[ railLR, terrain ] END PROC PROCEDURE prepareBitmaps ON CPC, ATARI, ATARIXL, COCO, DRAGON, MO5, PC128OP, ZX SHARED wagonImage SHARED wagonBackground wagonBackground := NEW IMAGE( wagonImageWidth, wagonImageHeight ) END PROC PROCEDURE drawWagonSprite ON C64, C128, COLECO, MSX, SC3000, SG1000 SHARED x, y SHARED wagon SPRITE wagon ENABLE AT x+offsetX, y+offsetY END PROC PROCEDURE hideWagonSprite ON C64, C128, COLECO, MSX, SC3000, SG1000 SHARED wagon SPRITE wagon DISABLE END PROC PROCEDURE saveWagonBackground ON CPC, ATARI, ATARIXL, COCO, DRAGON, MO5, PC128OP, ZX SHARED x, y SHARED wagonBackground GET IMAGE wagonBackground FROM x, y END PROC PROCEDURE drawWagonBitmap ON CPC, ATARI, ATARIXL, COCO, DRAGON, MO5, PC128OP, ZX SHARED x, y SHARED px, py SHARED wagonLRImage, wagonUDImage, wagonBackground, tileset IF ( px <> x ) OR ( py <> y ) THEN WHILE RASTER LINE < y WAIT 1 CYCLES WEND IF (px<>-1) AND (py<>-1) THEN PUT IMAGE wagonBackground AT px, py ENDIF saveWagonBackground[] ON CPC, ATARI, ATARIXL, COCO, DRAGON, MO5, PC128OP, ZX IF wagonId = wagonLR THEN PUT IMAGE wagonLRImage AT x,y WITH TRANSPARENCY ELSE IF wagonId = wagonUD THEN PUT IMAGE wagonUDImage AT x,y WITH TRANSPARENCY ENDIF WHILE RASTER LINE > 0 WAIT 1 CYCLES WEND px = x py = y ENDIF END PROC PARALLEL PROCEDURE drawWagon SHARED x, y, dx, dy, tx, ty SHARED wagon DIM ti AS WORD ti = TIMER DO IF ( TIMER - ti ) > 0 THEN ADD x, dx IF ( ( ( (x - SCREEN BORDER X) AND (tileWidth2-1) ) = 0 ) ) THEN IF ( dx <> 0 ) THEN IF dx > 0 THEN INC tx ELSE IF dx < 0 THEN DEC tx ENDIF ENDIF ENDIF YIELD ADD y, dy IF ( ( ( ( y - SCREEN BORDER Y ) AND (tileHeight-1) ) = 0 ) ) THEN IF ( dy <> 0 ) THEN IF dy > 0 THEN INC ty ELSE IF dy < 0 THEN DEC ty ENDIF ENDIF ENDIF YIELD drawWagonSprite[] ON C64, C128, COLECO, MSX, SC3000, SG1000 drawWagonBitmap[] ON CPC, ATARI, ATARIXL, COCO, DRAGON, MO5, PC128OP, ZX YIELD ti = TIMER ENDIF LOOP END PROC PROCEDURE drawMap SHARED level1 SHARED actualPageX, actualPageY SHARED previousPageX, previousPageY SHARED px, py SHARED wagonBackground IF ( previousPageX <> actualPageX ) OR ( previousPageY <> actualPageY ) THEN hideWagonSprite[] ON C64, C128, COLECO, MSX, SC3000, SG1000 PUT TILEMAP level1 FROM actualPageX * screenWidthInTiles, actualPageY * screenHeightInTiles GET IMAGE wagonBackground FROM px, py previousPageX = actualPageX previousPageY = actualPageY ENDIF END PROC PROCEDURE checkMapLocation SHARED actualRail, previousRail SHARED tx, ty, actualPageX, actualPageY actualRail = TILEMAP level1 AT( tx, ty ) IF actualRail = railLRbroken THEN actualRail = railLR ENDIF IF actualRail = railUDbroken THEN actualRail = railUD ENDIF IF actualRail = railLRbroken OR actualRail = railUDbroken THEN EVERY OFF HALT moveWagonToStart[] ELSE IF previousRail <> actualRail THEN changeWagonSpriteAndDirection[ actualRail, previousRail ] previousRail = actualRail ENDIF ENDIF IF ( actualPageX < maxPageX ) AND tx >= ( (actualPageX+1) * screenWidthInTiles ) THEN x = minWagonX INC actualPageX ELSE IF ( actualPageX > 0 ) AND tx < ( (actualPageX) * screenWidthInTiles ) THEN x = maxWagonX - tileWidth2 - 1 DEC actualPageX ELSE IF ( actualPageY < maxPageY ) AND ty >= ( (actualPageY+1) * screenHeightInTiles ) THEN y = minWagonY INC actualPageY ELSE IF ( actualPageY > 0 ) AND ty < ( (actualPageY) * screenHeightInTiles ) THEN y = maxWagonY - 1 DEC actualPageY ENDIF END PROC prepareBitmaps[] ON CPC, ATARI, ATARIXL, COCO, DRAGON, MO5, PC128OP, ZX moveWagonToStart[] SPAWN drawWagon DO drawMap[] checkMapLocation[] RUN PARALLEL LOOP
The instructions here refer to compiling the example from the command line. For Microsoft Windows users we suggest using UGBASIC-IDE, which allows you to compile the example with just one click.
In order to compile and run the example, you need to have the Altirra emulator, and in particular that the altirra
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.atari test2.bas -o example.xex altirra example.xex # Windows ugbc.atari.exe test2.bas -o example.xex altirra example.xex
In order to compile and run the example, you need to have the Altirra emulator, and in particular that the altirra
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.atarixl test2.bas -o example.xex altirra example.xex # Windows ugbc.atarixl.exe test2.bas -o example.xex altirra example.xex
In order to compile and run the example, you need to have the VICE emulator, and in particular that the x64sc
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.c64 test2.bas -o example.prg x64sc example.prg # Windows ugbc.c64.exe test2.bas -o example.prg x64sc example.prg
In order to run the example, you need to have the YAPE emulator. In particular that the yape
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.plus4 test2.bas -o example.prg yape example.prg # Windows ugbc.plus4.exe test2.bas -o example.prg yape example.prg
In order to run the example, you need to have the VICE emulator. In particular that the xplus4
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.plus4 test2.bas -o example.prg xplus4 example.prg # Windows ugbc.plus4.exe test2.bas -o example.prg xplus4 example.prg
In order to compile and run the example, you need to have the XROAR emulator, and in particular that the xroar
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.d32 test2.bas -o example.bin xroar -rompath (your rom path) example.bin # Windows ugbc.d32.exe test2.bas -o example.bin xroar.exe -rompath (your rom path) example.bin
In order to compile and run the example, you need to have the XROAR emulator, and in particular that the xroar
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.d64 test2.bas -o example.bin xroar -rompath (your rom path) example.bin # Windows ugbc.d64.exe test2.bas -o example.bin xroar.exe -rompath (your rom path) example.bin
In order to compile and run the example, you need to have the DCMOTO emulator, and in particular that the dcmoto
executable is accessible.
Then, type this command on the command line and on the emulator:
# Linux ugbc.pc128op test2.bas -o example.k7 dcmoto (choose BASIC 128) CLEAR,&H2FFF: LOADM"CASS:",R: EXEC # Windows ugbc.pc128op.exe test2.bas -o example.k7 dcmoto (choose example.k7) (choose BASIC 128) CLEAR,&H2FFF: LOADM"CASS:",R: EXEC
In order to compile and run the example, you need to have the DCMOTO emulator, and in particular that the dcmoto
executable is accessible.
Then, type this command on the command line and on the emulator:
# Linux ugbc.pc128op test2.bas -o example.k7 dcmoto (choose BASIC 128) CLEAR,&H2FFF: LOADM"CASS:",R: EXEC # Windows ugbc.pc128op.exe test2.bas -o example.k7 dcmoto (choose example.k7) (choose BASIC 128) CLEAR,&H2FFF: LOADM"CASS:",R: EXEC
In order to compile and run the example, you need to have the VICE emulator, and in particular that the xvic
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.vic20 test2.bas -o example.prg xvic --memory 24k example.prg # Windows ugbc.vic20.exe test2.bas -o example.prg xvic --memory 24k example.prg
In order to compile and run the example, you need to have the Speccy emulator, and in particular that the speccy
executable is accessible.
Then, type this command on the command line:
# Linux ugbc.zx test2.bas -o example.tap Speccy example.tap # Windows ugbc.zx.exe test2.bas -o example.tap Speccy example.tap
In order to compile and run the example, you need to have the openMsx or the BlueMSX emulator, and in particular that its executable is accessible.
Then, type this command on the command line:
# Linux ugbc.msx1 test2.bas -o example.rom openmsx -cart example.rom # Windows ugbc.msx1.exe test2.bas -o example.rom openmsx -cart example.rom
# Linux ugbc.msx1 test2.bas -o example.rom bluemsx example.rom # Windows ugbc.msx1.exe test2.bas -o example.rom bluemsx example.rom
In order to compile and run the example, you need to have the openMsx or the BlueMSX emulator, and in particular that its executable is accessible.
Then, type this command on the command line:
# Linux ugbc.coleco test2.bas -o example.rom openmsx -machine \"COL - ColecoVision\" -cart example.rom # Windows ugbc.coleco.exe test2.bas -o example.rom bluemsx -machine \"COL - ColecoVision\" example.rom
# Linux ugbc.coleco test2.bas -o example.rom bluemsx /machine \"COL - ColecoVision\" /rom1 example.rom # Windows ugbc.coleco.exe test2.bas -o example.rom bluemsx /machine \"COL - ColecoVision\" /rom1 example.rom
In order to compile and run the example, you need to have the BlueMSX emulator, and in particular that its executable is accessible.
Then, type this command on the command line:
# Linux ugbc.sc3000 test2.bas -o example.rom bluemsx /machine \"SEGA - SC-3000\" /rom1 example.rom # Windows ugbc.sc3000.exe test2.bas -o example.rom bluemsx /machine \"SEGA - SC-3000\" /rom1 example.rom
In order to compile and run the example, you need to have the BlueMSX emulator, and in particular that its executable is accessible.
Then, type this command on the command line:
# Linux ugbc.sg1000 test2.bas -o example.rom bluemsx /machine \"SEGA - SG-1000\" /rom1 example.rom # Windows ugbc.sg1000.exe test2.bas -o example.rom bluemsx /machine \"SEGA - SG-1000\" /rom1 example.rom
If you have found a problem trying to run this example, if you think there is a bug or, more simply, you would like it to be improved, open an issue for this example on GitHub. Thank you!