I've commented it just to see if i have grasped the concept, thats it.
thanks all
thanks all
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuTYPE _rect
x; y; width; height
ENDTYPE
GLOBAL screen AS _rect, boundary AS _rect, tile AS _rect, player AS _rect, tile_map$[] //we use the variable "screen" as pointer to the type
// _rect, same goes for boundary, tile, player..and declare them globals
main()
FUNCTION main:
init()
animate_scene()
ENDFUNCTION
FUNCTION init:
screen.width = 640
screen.height = 480
SETSCREEN screen.width, screen.height, FALSE //set the screen size and windowed mode
tile.width = 64
tile.height = 64
boundary.x = -tile.width //this is the starting X point of the field
boundary.width = screen.width + tile.width //this is the ending X point of the field
boundary.y = -tile.height //starting Y point of the field
boundary.height = screen.height + tile.height //ending Y point of the field
tile.y = INTEGER(screen.height * 4 / tile.height) // it should be the total number of tiles on the y axis, in this case 30
// Generate an ASCII maze quickly: http://www.vidarholen.net/cgi-bin/labyrinth?w=9&h=31
DIM tile_map$[tile.y + 1] //we set the dimensions of the map array, the size is the total number of tiles on the y axis plus 1
tile_map$[0] = "???????????????"
tile_map$[1] = "???????????????"
tile_map$[2] = "? ? ? ??? ??? ?"
tile_map$[3] = "? ??? ? ????? ?"
tile_map$[4] = "??? ????? ??? ?"
tile_map$[5] = "? ? ? ??? ?????"
tile_map$[6] = "? ? ? ? ??? ? ?"
tile_map$[7] = "? ? ????????? ?"
tile_map$[8] = "? ??? ? ????? ?"
tile_map$[9] = "??? ? ??? ?????"
tile_map$[10] = "? ????? ? ? ? ?"
tile_map$[11] = "? ? ? ? ????? ?"
tile_map$[12] = "? ? ? ? ? ??? ?"
tile_map$[13] = "? ? ? ? ? ? ? ?"
tile_map$[14] = "? ? ????? ? ? ?"
tile_map$[15] = "? ????? ???????"
tile_map$[16] = "??? ? ??? ??? ?"
tile_map$[17] = "? ? ? ? ? ? ???"
tile_map$[18] = "? ? ? ??????? ?"
tile_map$[19] = "? ????? ????? ?"
tile_map$[20] = "? ? ? ??? ?????"
tile_map$[21] = "? ? ??? ????? ?"
tile_map$[22] = "? ? ? ????? ? ?"
tile_map$[23] = "? ????? ? ? ? ?"
tile_map$[24] = "????? ? ? ? ???"
tile_map$[25] = "? ??????????? ?"
tile_map$[26] = "? ? ? ? ????? ?"
tile_map$[27] = "? ? ??????? ? ?"
tile_map$[28] = "? ??????? ??? ?"
tile_map$[29] = "???????????????"
tile.x = LEN(tile_map$[0]) //we set the total amount of tiles on the x axis, based on the map array dimension (len is used to return
//a number of char in a string, in this case 15)
ENDFUNCTION
FUNCTION animate_scene:
WHILE TRUE
update_player()
draw_field()
SHOWSCREEN
WEND
ENDFUNCTION
FUNCTION update_player:
LOCAL step_move = 4
IF KEY(200) THEN INC player.y, step_move // when we press up,we increase the player.y variable by step_move (in this case 4)
IF KEY(203) THEN INC player.x, step_move // when we press left we do as above
IF KEY(205) THEN DEC player.x, step_move // when we press right we decrease the player.y variable by step_move
IF KEY(208) THEN DEC player.y, step_move // when we press down as above
ENDFUNCTION
FUNCTION draw_field:
LOCAL map AS _rect //we use map as a local pointer to the type _rect
FOR map.y = 0 TO tile.y - 1 //we tell the pc to tile vertically until it reach the total amount of tiles minus 1
FOR map.x = 0 TO tile.x - 1 //same for the x axis
draw_tile(map.x, map.y) //draws the tiles based on the amount contained in map.x and map.y
NEXT
NEXT
ENDFUNCTION
FUNCTION draw_tile: map_x, map_y //a function which accept 2 parameters
LOCAL box AS _rect, color, ascii, line$ //box is locally used as a pointer to rect, color, ascii and line
box.x = (map_x * tile.width) + player.x //this is used to set the x starting point at which we draw the tiles, and since we want
//to scroll them too we add the player.x amount, which is a sort of speed
box.y = (map_y * tile.height) + player.y //same for the y starting point
IF BOXCOLL(box.x, box.y, box.width, box.height, boundary.x, boundary.y, boundary.width, boundary.height)//check if theres a collision
//between boundaries and the actual tile we are on, so we can make the border flash!
line$ = tile_map$[map_y]
ascii = ASC(MID$(line$, map_x, 1))
SELECT ascii
CASE 32
color = RGB(0, 128, 0)
DEFAULT
IF map_x = 0 OR map_y = 0 OR map_x = tile.x - 1 OR map_y = tile.y - 1
color = RGB(0, 0, 64 * SIN(GETTIMERALL() / 10) + 64) // outer wall
ELSE
color = RGB(0, 0, 32) // inner wall
ENDIF
ENDSELECT
DRAWRECT box.x, box.y, tile.width - 1, tile.height - 1, color // DRAWSPRITE tiles here
ENDIF
ENDFUNCTION
Quote// Generate an ASCII maze quickly: http://www.vidarholen.net/cgi-bin/labyrinth?w=9&h=31it says width=9 .... height=31
Quotetile.x = LEN(tile_map$[0])should give a result of 15, not 9.
QuoteGLOBAL screen AS _rect, boundary AS _rect, tile AS _rect, player AS _rect, tile_map$[]everything is easy, you basically create a type and make few instances of it, and declare them globals.
QuoteFUNCTION init:are used to set the tile size, the starting points of the playfield and the end points (if i am right..).
screen.width = 640
screen.height = 480
SETSCREEN screen.width, screen.height, FALSE
tile.width = 64
tile.height = 64
boundary.x = -tile.width
boundary.width = screen.width + tile.width
boundary.y = -tile.height
boundary.height = screen.height + tile.height
Quotetile.y = INTEGER(screen.height * 4 / tile.height)is a mystery..i actually can't understand what "tile.y" is used for!