Sprite Code Examples: Difference between revisions
Jump to navigation
Jump to search
(Created as a storage page for all that sample code, since I can't get the boxes to hide.) |
(Added intermediate code for example 1.1) |
||
Line 1: | Line 1: | ||
__NOTOC__ | __NOTOC__ | ||
This article contains all of the code described in the [[Sprite#Sprite Tutorial|Sprite Tutorial]]. | This article contains all of the code described in the [[Sprite#Sprite Tutorial|Sprite Tutorial]]. | ||
==Example 1.1== | |||
lockplayer | |||
set "spr0_refx" to 80 | |||
set "spr0_refy" to 0 | |||
set "spr0_width" to 3 | |||
set "spr0_height" to 3 | |||
: "drawloop" | |||
wait for 1 | |||
put c?? Sprite p00 at "x" "y" | |||
if uppressed then "up" | |||
if leftpressed then "left" | |||
if rightpressed then "right" | |||
if downpressed then "down" | |||
goto "drawloop" | |||
: "up" | |||
dec "y" by 1 | |||
goto "drawloop" | |||
: "down" | |||
inc "y" by 1 | |||
goto "drawloop" | |||
: "left" | |||
dec "x" by 1 | |||
goto "drawloop" | |||
: "right" | |||
inc "x" by 1 | |||
goto "drawloop" | |||
[[Sprite#E1.1|Back]] | |||
==Example 1.2== | ==Example 1.2== | ||
lockplayer | lockplayer | ||
set "local" to 0 | '''set "local" to 0''' | ||
set "local2" to 5 | '''set "local2" to 5''' | ||
set "local3" to 5 | '''set "local3" to 5''' | ||
set "spr&local&_refx" to 80 | set "spr'''&local&'''_refx" to 80 | ||
set "spr&local&_refy" to 0 | set "spr'''&local&'''_refy" to 0 | ||
set "spr&local&_width" to 3 | set "spr'''&local&'''_width" to 3 | ||
set "spr&local&_height" to 3 | set "spr'''&local&'''_height" to 3 | ||
goto "#draw" | '''goto "#draw"''' | ||
: "drawloop" | : "drawloop" | ||
if uppressed then "#up" | if uppressed then "'''#'''up" | ||
if leftpressed then "#left" | if leftpressed then "'''#'''left" | ||
if rightpressed then "#right" | if rightpressed then "'''#'''right" | ||
if downpressed then "#down" | if downpressed then "'''#'''down" | ||
wait for 1 | wait for 1 | ||
goto "drawloop" | goto "drawloop" | ||
: "#up" | : "'''#'''up" | ||
if "local3" <= 0 then "#return" | '''if "local3" <= 0 then "#return"''' | ||
dec "local3" by 1 | dec '''"local3"''' by 1 | ||
goto "#draw" | '''goto "#draw"''' | ||
goto "#return" | goto '''"#return"''' | ||
: "#down" | : "'''#'''down" | ||
if "local3" >= "(25-'spr&local&_height')" then "#return" | '''if "local3" >= "(25-'spr&local&_height')" then "#return"''' | ||
inc "local3" by 1 | inc '''"local3"''' by 1 | ||
goto "#draw" | '''goto "#draw"''' | ||
goto "#return" | goto '''"#return"''' | ||
: "#left" | : "'''#'''left" | ||
if "local2" <= 0 then "#return" | '''if "local2" <= 0 then "#return"''' | ||
dec "local2" by 1 | dec '''"local2"''' by 1 | ||
goto "#draw" | '''goto "#draw"''' | ||
goto "#return" | goto '''"#return"''' | ||
: "#right" | : "'''#'''right" | ||
if "local2" >= "(80-'spr&local&_width')" then "#return" | '''if "local2" >= "(80-'spr&local&_width')" then "#return"''' | ||
inc "local2" by 1 | inc '''"local2"''' by 1 | ||
goto "#draw" | '''goto "#draw"''' | ||
goto "#return" | goto '''"#return"''' | ||
: "#draw" | ''': "#draw"''' | ||
put c?? Sprite "local" at "local2" "local3" | '''put c?? Sprite "local" at "local2" "local3"''' | ||
goto "#return" | '''goto "#return"''' | ||
[[Sprite#E1.2|Back]] | [[Sprite#E1.2|Back]] | ||
==Example 2== | ==Example 2== |
Revision as of 20:34, 29 October 2007
This article contains all of the code described in the Sprite Tutorial.
Example 1.1
lockplayer set "spr0_refx" to 80 set "spr0_refy" to 0 set "spr0_width" to 3 set "spr0_height" to 3 : "drawloop" wait for 1 put c?? Sprite p00 at "x" "y" if uppressed then "up" if leftpressed then "left" if rightpressed then "right" if downpressed then "down" goto "drawloop" : "up" dec "y" by 1 goto "drawloop" : "down" inc "y" by 1 goto "drawloop" : "left" dec "x" by 1 goto "drawloop" : "right" inc "x" by 1 goto "drawloop"
Example 1.2
lockplayer set "local" to 0 set "local2" to 5 set "local3" to 5 set "spr&local&_refx" to 80 set "spr&local&_refy" to 0 set "spr&local&_width" to 3 set "spr&local&_height" to 3 goto "#draw" : "drawloop" if uppressed then "#up" if leftpressed then "#left" if rightpressed then "#right" if downpressed then "#down" wait for 1 goto "drawloop" : "#up" if "local3" <= 0 then "#return" dec "local3" by 1 goto "#draw" goto "#return" : "#down" if "local3" >= "(25-'spr&local&_height')" then "#return" inc "local3" by 1 goto "#draw" goto "#return" : "#left" if "local2" <= 0 then "#return" dec "local2" by 1 goto "#draw" goto "#return" : "#right" if "local2" >= "(80-'spr&local&_width')" then "#return" inc "local2" by 1 goto "#draw" goto "#return" : "#draw" put c?? Sprite "local" at "local2" "local3" goto "#return"
Example 2
lockplayer set "local" to 0 set "local2" to 5 set "local3" to 5 set "spr&local&_refx" to 80 set "spr&local&_refy" to 0 set "spr&local&_width" to 3 set "spr&local&_height" to 3 set "spr&local&_cx" to 0 set "spr&local&_cy" to 2 set "spr&local&_cwidth" to 3 set "spr&local&_cheight" to 1 goto "#draw" : "drawloop" if uppressed then "#up" if leftpressed then "#left" if rightpressed then "#right" if downpressed then "#down" wait for 1 goto "drawloop" : "#up" if "local3" <= 0 then "#return" if c?? Sprite_colliding "local" at 0 -1 then "#return" dec "local3" by 1 goto "#draw" goto "#return" : "#down" if "local3" >= "(25-'spr&local&_height')" then "#return" if c?? Sprite_colliding "local" at 0 1 then "#return" inc "local3" by 1 goto "#draw" goto "#return" : "#left" if "local2" <= 0 then "#return" if c?? Sprite_colliding "local" at -1 0 then "#return" dec "local2" by 1 goto "#draw" goto "#return" : "#right" if "local2" >= "(80-'spr&local&_width')" then "#return" if c?? Sprite_colliding "local" at 1 0 then "#return" inc "local2" by 1 goto "#draw" goto "#return" : "#draw" put c?? Sprite "local" at "local2" "local3" goto "#return"
Example 3.1
. "Global robot" set "spr_p_x" to 80 set "spr_p_y" to 0 set "spr_p_w" to 3 set "spr_p_h" to 3 set "spr_p_cx" to 0 set "spr_p_cy" to 2 set "spr_p_cw" to 3 set "spr_p_ch" to 1 set "spr_d_x" to 83 set "spr_d_y" to 0 set "spr_d_w" to 3 set "spr_d_h" to 3 set "spr_d_cx" to 0 set "spr_d_cy" to 0 set "spr_d_cw" to 3 set "spr_d_ch" to 3 set "spr_k_x" to 86 set "spr_k_y" to 0 set "spr_k_w" to 2 set "spr_k_h" to 3 set "spr_k_cx" to 0 set "spr_k_cy" to 0 set "spr_k_cw" to 2 set "spr_k_ch" to 3 . "Your values may differ, so please change them to suit." --------------------------------------------------------------- . "Player robot" lockplayer set "local" to "robot_id" set "local2" to "thisx" set "local3" to "thisy" gotoxy "local" 0 . "&spr&local&" set "spr&local&_refx" to "spr_p_x" set "spr&local&_refy" to "spr_p_y" set "spr&local&_width" to "spr_p_w" set "spr&local&_height" to "spr_p_h" set "spr&local&_cx" to "spr_p_cx" set "spr&local&_cy" to "spr_p_cy" set "spr&local&_cwidth" to "spr_p_cw" set "spr&local&_cheight" to "spr_p_ch" goto "#draw" : "drawloop" if uppressed then "#up" if leftpressed then "#left" if rightpressed then "#right" if downpressed then "#down" wait for 1 goto "drawloop" : "#up" if "local3" <= 0 then "#return" if c?? Sprite_colliding "local" at 0 -1 then "collision" dec "local3" by 1 goto "#draw" goto "#return" : "#down" if "local3" >= "(25-'spr&local&_height')" then "#return" if c?? Sprite_colliding "local" at 0 1 then "collision" inc "local3" by 1 goto "#draw" goto "#return" : "#left" if "local2" <= 0 then "#return" if c?? Sprite_colliding "local" at -1 0 then "collision" dec "local2" by 1 goto "#draw" goto "#return" : "#right" if "local2" >= "(80-'spr&local&_width')" then "#return" if c?? Sprite_colliding "local" at 1 0 then "collision" inc "local2" by 1 goto "#draw" goto "#return" : "#draw" put c?? Sprite "local" at "local2" "local3" goto "#return" : "collision" loop start goto "#collide('spr_clist&loopcount&')" send "spr('spr_clist&loopcount&')" to "touch" loop for "('spr_collisions'-1)" goto "#return" --------------------------------------------------------------- . "Key robot" set "local" to "robot_id" set "local2" to "thisx" set "local3" to "thisy" set "local4" to "this_color" gotoxy "local" 0 . "@spr&local&" set "spr&local&_refx" to "spr_k_x" set "spr&local&_refy" to "spr_k_y" set "spr&local&_width" to "spr_k_w" set "spr&local&_height" to "spr_k_h" set "spr&local&_cx" to "spr_k_cx" set "spr&local&_cy" to "spr_k_cy" set "spr&local&_cwidth" to "spr_k_cw" set "spr&local&_cheight" to "spr_k_ch" put "local4" Sprite "local" at "local2" "local3" end : "touch" inc "key_&local4&" by 1 set "spr&local&_off" to 1 die --------------------------------------------------------------- . "Door robot" set "local" to "robot_id" set "local2" to "thisx" set "local3" to "thisy" set "local4" to "this_color" gotoxy "local" 0 . "@spr&local&" set "spr&local&_refx" to "spr_d_x" set "spr&local&_refy" to "spr_d_y" set "spr&local&_width" to "spr_d_w" set "spr&local&_height" to "spr_d_h" set "spr&local&_cx" to "spr_d_cx" set "spr&local&_cy" to "spr_d_cy" set "spr&local&_cwidth" to "spr_d_cw" set "spr&local&_cheight" to "spr_d_ch" put "local4" Sprite "local" at "local2" "local3" end : "touch" if "key_&local4&" <= 0 then "end" dec "key_&local4&" by 1 set "spr&local&_off" to 1 die : "end" end