include, plotscr.hsd plotscript, test, begin variable(sl, sl2, sl3, i, cont) $0="sort tests", show string(0) wait(5) cont := create container fill parent(cont) for(i, 0, 22), do, begin sl := create rect(50, 50, random(0,2)) set parent(sl, cont) set slice x(sl, i * 14) set slice y(sl, i * 4) wait(1) end $0="sort tests: move blue back", show string(0) sl := first child(cont) while(sl) do, begin set slice y(sl, slice y(sl) + 1) sl2 := 0 if (get rect style(sl) == 0) then(sl2 := sl) sl := next sibling(sl) if(sl2) then(slice to back(sl2)) wait(2) end $0="sort tests: move green forward", show string(0) sl := first child(cont) sl2 := last child(cont) while(sl) do, begin sl3 := 0 set slice y(sl, slice y(sl) + 1) if (get rect style(sl) == 1) then(sl3:=sl) if(sl == sl2) then(break) sl := next sibling(sl) if(sl3) then(slice to front(sl3)) wait(2) end wait(5) $0="sort tests: y sort", show string(0) y sort children (cont) wait(5) $0="sort tests: shuffle red up", show string(0) sl := last child(cont) sl2 := first child(cont) while(sl) do, begin sl3 := previous sibling(sl) set slice y(sl, slice y(sl) + 1) if (get rect style(sl) == 2) then( sl2 := next sibling(sl) if (sl2) then( move slice above(sl, sl2) if(previous sibling(sl) <> sl2) then($1="move slice above failed", trace(1)) ) ) sl := sl3 wait(2) end wait(10) $0="sort tests: reverse y sort (sort children)", show string(0) for(i, 0, child count(cont) -- 1) do, begin sl := slice child(cont, i) set sort order(sl, slice y(sl) * -1) end sort children(cont) wait(10) $0="sort tests: move green forward (sort children)", show string(0) sl := first child(cont) sl2 := last child(cont) while(sl) do, begin if (get rect style(sl) == 1) then(set sort order(sl, 1)) sl := next sibling(sl) end sort children(cont, false) wait(30) $0="sort tests: move green back (sort children)", show string(0) sl := first child(cont) while(sl) do, begin set sort order(sl, get sort order(sl) * -1) sl := next sibling(sl) end sort children(cont) wait(30) free slice(cont) wait(5) $0="edge tests", show string(0) wait(5) cont := create rect(300, 180) center slice(cont) wait(2) sl := load small enemy sprite(0) set parent(sl, cont) wait(2) sl := load small enemy sprite(0) set parent(sl, cont) realign slice(sl, edge:right, edge:bottom, edge:right, edge:bottom) wait(3) set left padding(cont, 5) if(get left padding(cont) <> 5) then($1="set/get padding failed", trace(1)) wait(2) set padding(cont, 10) glide size(cont, -2, -2, 3, 2) glide size(cont, 2, 2, 3, 2) set padding(cont, 0) wait(3) set padding(cont, -10) glide size(cont, -2, -2, 3, 2) glide size(cont, 2, 2, 3, 2) wait(5) $0="filling tests", show string(0) set padding(cont, 16) sl := create rect(10, 10, 3) set rect trans(sl, true) wait(3) set parent(sl, cont) wait(3) if(is filling parent(sl)) then($1="should not be filling yet", trace(1)) fill parent(sl) if(not(is filling parent(sl))) then($1="should be filling now", trace(1)) wait(3) glide size(cont, -3, -3, 25, 1) wait(3) glide pos(cont, 3, 0, 7, 2) wait(5) free slice(cont) $0="Load tests", show string(1) wait(2) sl := load large enemy sprite(1) wait(2) sl2 := load large enemy sprite(0) wait(2) free sprite(sl2) wait(2) replace large enemy sprite(sl, 0) wait(2) $0="position tests", show string(0) wait(2) set slice x(sl, 10) wait(2) set slice y(sl, 10) wait(2) place sprite(sl, 0, 0) wait(2) $0="Align and Anchor tests", show string(0) set horiz align(sl, edge:center) wait(2) set vert align(sl, edge:center) wait(2) set horiz anchor(sl, edge:center) wait(2) set vert anchor(sl, edge:center) wait(2) sl2 := load large enemy sprite(1) wait(2) $0="Deletion tests", show string(0) wait(2) replace medium enemy sprite(sl,0) wait(2) replace large enemy sprite(sl,0) wait(2) free sprite(sl) wait(2) free sprite(sl2) $0="looping tests", show string(0) for (i, 0, 15), do, begin sl := load large enemy sprite(random(0,1)) place sprite(sl, i*10, 0) wait(1) end sl := first child(sprite layer) while(sl) do, begin set slice y(sl, slice y(sl) + 8) wait(1) sl := next sibling(sl) end sl := first child(sprite layer) while(sl) do, begin free sprite(sl) wait(1) sl := first child(sprite layer) end wait(2) $0="container tests", show string(0) cont := create container(120, 120) sl := load medium enemy sprite(0) set parent(sl, cont) wait(10) sl := load medium enemy sprite(0) set parent(sl, cont) realign slice(sl, edge:right, edge:top, edge:right, edge:top) wait(3) sl := load medium enemy sprite(0) set parent(sl, cont) realign slice(sl, edge:right, edge:bottom, edge:right, edge:bottom) wait(3) sl := load medium enemy sprite(0) set parent(sl, cont) realign slice(sl, edge:left, edge:bottom, edge:left, edge:bottom) wait(3) sl := create rect(40, 40, 1) set parent(sl, cont) set horiz align(sl, edge:center) set horiz anchor(sl, edge:center) set vert align(sl, edge:center) set vert anchor(sl, edge:center) wait(3) glide pos(cont, 3, 3, 15) sl := first child(cont) $0+" " append number(0, slice screen x(sl)) $0+"x" append number(0, slice screen y(sl)) show string(0) glide size(cont, 4, 2, 10) glide size(cont, -3, -2, 10) glide pos(cont, 0, -3, 15) glide pos(cont, -3, 0, 15) wait(5) sl := first sprite child(cont) while(sl) do, begin glide pos(sl, -2, 1, 3) glide pos(sl, 2, -1, 3) sl := next sprite sibling(sl) end sl := first rect child(cont) while(sl) do, begin glide pos(sl, 5, -5, 3) glide pos(sl, -5, 5, 3) sl := next rect sibling(sl) end if(slice is container(cont)) then(free slice(cont)) wait(5) $0="rect style tests", show string(0) wait(2) sl := create rect(200, 180) center slice(sl) wait(2) for(i, 1, 14) do, begin set rect style(sl, i) wait(2) end set rect border(sl, -1) #NOTE: this is a decent way to do tests! if(get rect style(sl) <> -1) then($1="change of border failed to clear style", trace(1)) for(i, 0, 7) do, begin set rect bgcol(sl, random(0,255)) wait(2) end for(i, 0, 7) do, begin set rect fgcol(sl, random(0,255)) wait(2) end set rect style(sl,0) for(i, 0, 7) do, begin set rect trans(sl, not(get rect trans(sl))) wait(2) end wait(5) free slice(sl) $0="flip tests", show string(0) wait(5) for(i, 0, 10) do, begin sl := load large enemy sprite(0) set slice y(sl, i * 12) horiz flip sprite (sl, (i, mod, 2)) vert flip sprite (sl, random(0,1)) wait(2) end variable(diff) for (i, 0, 10) do, begin sl := first child(sprite layer) while(sl) do, begin if(sprite is horiz flipped(sl)) then(diff := -2) else(diff := 2) set slice x(sl, slice x(sl) + diff) sl := next sibling(sl) end wait(2) end sl := first child(sprite layer) while(sl) do, begin free slice(sl) sl := first child(sprite layer) end wait(2) $0="invalid operations tests", show string(0) wait(3) sl := load medium enemy sprite(0) set rect style(sl, 0) wait(2) free slice(sl) wait(2) sl := create rect(10, 10) set sprite frame(sl, 0) wait(2) free slice(sl) wait(2) $0="tests finished", show string(0) wait(10) $0="press a key to exit", show string(0) wait for key game over end script, glide pos, sl, xgo, ygo, cycles, ticks=1, begin variable(i) for(i, 1, cycles), do, begin set slice x(sl, slice x(sl) + xgo) set slice y(sl, slice y(sl) + ygo) wait(ticks) end end script, glide size, sl, xgo, ygo, cycles, ticks=1, begin variable(i) for(i, 1, cycles), do, begin set slice width(sl, slice width(sl) + xgo) set slice height(sl, slice height(sl) + ygo) wait(ticks) end end