-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #490 from paulscottrobson/tilex
New tilemap demo
- Loading branch information
Showing
9 changed files
with
180 additions
and
65 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,68 @@ | ||
' | ||
' New Blitter | ||
' *** Tile map demonstration program *** | ||
' | ||
f = alloc(16) | ||
t = alloc(16) | ||
cls:sprite clear:gload "graphics.gfx" | ||
rect 0,0 solid ink 4 to 319,239 | ||
|
||
cls:sprite clear:cursor 0,20 | ||
dat = alloc(256) | ||
for i = 0 to 255:poke dat+i,(i >> 4)+5:next | ||
|
||
call setup(f,0,dat,64,64,1) | ||
call setup(t,$80,0,8,320,8) | ||
t1 = time() | ||
for x = 0 to 39 | ||
for y = 0 to 23 | ||
while peek($FF00):wend | ||
doke t,x*8+y*320*8 | ||
poke $FF04,0 | ||
doke $FF05,f | ||
doke $FF07,t | ||
poke $FF01,3 | ||
poke $FF00,12 | ||
next | ||
next | ||
print time()-t1 | ||
call CreateTileMap() | ||
xPos = 0:yPos = 0 | ||
call DrawTileMap(xPos,yPos) | ||
repeat | ||
if event(t1,2) | ||
fire = joypad(dx,dy) | ||
xPos = max(xPos+dx,0):yPos = max(yPos+dy,0) | ||
call DrawTileMap(xPos,yPos) | ||
endif | ||
until false | ||
end | ||
' | ||
' This draws the tilemap offset by x,y | ||
' | ||
proc DrawTileMap(xo,yo) | ||
ink 7:print chr$(20);"At offset ";xo;" ";yo;" " | ||
' Sets the tilemap data to draw with and the offset in pixels. | ||
tilemap map,xo,yo | ||
' Draw the tilemap in a window | ||
tiledraw 10,20 to 240,210 | ||
' Draw a small second one using the same data | ||
tiledraw 250,20 to 310,80 | ||
endproc | ||
' | ||
' This creates a single tile map in memory. See api.pdf | ||
' | ||
proc CreateTileMap() | ||
width = 30:height = 20 | ||
' an array of memory with a small header : type, width and height. | ||
map = alloc(width*height+3) | ||
poke map,1: poke map+1, width: poke map+2, height | ||
' Fill the map with $F2 which is a solid green block. | ||
for i = 0 to width*height-1:poke map+3+i,$F2:next | ||
' Draw a frame around the whole screen | ||
call DrawRect(0,0,width,height,$F3,-1) | ||
' Draw some things on the tilemap | ||
call DrawRect(3,2,8,5,6,0) | ||
call DrawRect(17,6,10,7,6,3) | ||
call DrawRect(5,10,10,7,6,5) | ||
endproc | ||
|
||
proc setup(a,p,addr,size,offset,count) | ||
doke a+0,addr | ||
poke a+2,p | ||
doke a+4,size:doke a+6,0 | ||
doke a+8,offset:doke a+10,0 | ||
doke a+12,count:doke a+14,0 | ||
endproc | ||
' | ||
' Draw a rectangle on the tile map at (x,y) size (w,h) with frame edgeColour | ||
' and fill with fillColour (if >= 0) | ||
' | ||
proc DrawRect(x,y,w,h,edgeColour,fillColour) | ||
if fillColour >= 0 | ||
for i = x to x+w-1 | ||
for j = y to y+h-1 | ||
call set(i,j,fillColour) | ||
next | ||
next | ||
endif | ||
for i = x to x+w-1:call set(i,y,edgeColour):call set(i,y+h-1,edgeColour):next | ||
for i = y to y+h-1:call set(x,i,edgeColour):call set(x+w-1,i,edgeColour):next | ||
endproc | ||
' | ||
' Set tilemap tile to x,y | ||
' | ||
proc set(x,y,t) | ||
poke map+x+3+y*width,t | ||
endproc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
' | ||
' Tile map testing program. | ||
' | ||
cls:sprite clear:gload "graphics.gfx":cls | ||
for i = 0 to 64:line i*5,0 ink 1 to i*5,239:next | ||
call BuildTileMap() | ||
' call PrintTileMap() | ||
rect ink 3 frame 9,9 to 307,233 | ||
rCount = 0:t1 = time() | ||
for j = 1 to 20 | ||
for i = 0 to 15 | ||
tilemap map,i,i | ||
tiledraw 10,10 to 306,232 | ||
't2 = time()+10:repeat:until time() > t2 | ||
rCount = rCount + 1 | ||
next | ||
next | ||
t = (time()-t1)/100/rCount | ||
print 1/t | ||
end | ||
|
||
proc BuildTileMap() | ||
width = 22:height = 14 | ||
map = alloc(width*height+3) | ||
poke map,1 | ||
poke map+1, width | ||
poke map+2, height | ||
for i = 0 to width*height-1:poke map+3+i,$F2:next | ||
for i = 0 to width-1:call set(i,0,0):call set(i,height-1,0):next | ||
for i = 0 to height-1:call set(0,i,1):call set(width-1,i,1):next | ||
for i = 2 to 6:call set(i,i,i):call set(i+4,i+1,i):next | ||
for i = 1 to 9:call set(2+i,height-3,i+$F0):next | ||
call set(0,1,$F3):call set(0,2,$F1) | ||
endproc | ||
|
||
proc PrintTileMap() | ||
for y = 0 to height-1 | ||
for x = 0 to width-1 | ||
c = peek(map+3+y*width+x):if c <> 7:print c;:else:print " ";:endif | ||
next | ||
next | ||
endproc | ||
|
||
proc set(x,y,t) | ||
poke map+x+3+y*width,t | ||
endproc |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,68 @@ | ||
' | ||
' Tile map testing program. | ||
' | ||
cls:sprite clear:gload "graphics.gfx":cls | ||
for i = 0 to 64:line i*5,0 ink 1 to i*5,239:next | ||
call BuildTileMap() | ||
' call PrintTileMap() | ||
rect ink 3 frame 9,9 to 307,233 | ||
rCount = 0:t1 = time() | ||
for j = 1 to 20 | ||
for i = 0 to 15 | ||
tilemap map,i,i | ||
tiledraw 10,10 to 306,232 | ||
't2 = time()+10:repeat:until time() > t2 | ||
rCount = rCount + 1 | ||
next | ||
next | ||
t = (time()-t1)/100/rCount | ||
print 1/t | ||
end | ||
' *** Tile map demonstration program *** | ||
' | ||
cls:sprite clear:gload "graphics.gfx" | ||
rect 0,0 solid ink 4 to 319,239 | ||
|
||
proc BuildTileMap() | ||
width = 22:height = 14 | ||
call CreateTileMap() | ||
xPos = 0:yPos = 0 | ||
call DrawTileMap(xPos,yPos) | ||
repeat | ||
if event(t1,2) | ||
fire = joypad(dx,dy) | ||
xPos = max(xPos+dx,0):yPos = max(yPos+dy,0) | ||
call DrawTileMap(xPos,yPos) | ||
endif | ||
until false | ||
end | ||
' | ||
' This draws the tilemap offset by x,y | ||
' | ||
proc DrawTileMap(xo,yo) | ||
ink 7:print chr$(20);"At offset ";xo;" ";yo;" " | ||
' Sets the tilemap data to draw with and the offset in pixels. | ||
tilemap map,xo,yo | ||
' Draw the tilemap in a window | ||
tiledraw 10,20 to 240,210 | ||
' Draw a small second one using the same data | ||
tiledraw 250,20 to 310,80 | ||
endproc | ||
' | ||
' This creates a single tile map in memory. See api.pdf | ||
' | ||
proc CreateTileMap() | ||
width = 30:height = 20 | ||
' an array of memory with a small header : type, width and height. | ||
map = alloc(width*height+3) | ||
poke map,1 | ||
poke map+1, width | ||
poke map+2, height | ||
poke map,1: poke map+1, width: poke map+2, height | ||
' Fill the map with $F2 which is a solid green block. | ||
for i = 0 to width*height-1:poke map+3+i,$F2:next | ||
for i = 0 to width-1:call set(i,0,0):call set(i,height-1,0):next | ||
for i = 0 to height-1:call set(0,i,1):call set(width-1,i,1):next | ||
for i = 2 to 6:call set(i,i,i):call set(i+4,i+1,i):next | ||
for i = 1 to 9:call set(2+i,height-3,i+$F0):next | ||
call set(0,1,$F3):call set(0,2,$F1) | ||
' Draw a frame around the whole screen | ||
call DrawRect(0,0,width,height,$F3,-1) | ||
' Draw some things on the tilemap | ||
call DrawRect(3,2,8,5,6,0) | ||
call DrawRect(17,6,10,7,6,3) | ||
call DrawRect(5,10,10,7,6,5) | ||
endproc | ||
|
||
proc PrintTileMap() | ||
for y = 0 to height-1 | ||
for x = 0 to width-1 | ||
c = peek(map+3+y*width+x):if c <> 7:print c;:else:print " ";:endif | ||
' | ||
' Draw a rectangle on the tile map at (x,y) size (w,h) with frame edgeColour | ||
' and fill with fillColour (if >= 0) | ||
' | ||
proc DrawRect(x,y,w,h,edgeColour,fillColour) | ||
if fillColour >= 0 | ||
for i = x to x+w-1 | ||
for j = y to y+h-1 | ||
call set(i,j,fillColour) | ||
next | ||
next | ||
next | ||
endif | ||
for i = x to x+w-1:call set(i,y,edgeColour):call set(i,y+h-1,edgeColour):next | ||
for i = y to y+h-1:call set(x,i,edgeColour):call set(x+w-1,i,edgeColour):next | ||
endproc | ||
|
||
' | ||
' Set tilemap tile to x,y | ||
' | ||
proc set(x,y,t) | ||
poke map+x+3+y*width,t | ||
endproc |