Sprite Code Examples: Difference between revisions

From MZXWiki
Jump to navigation Jump to search
m (→‎Example 2.3: Minor addition)
(Added example 2.4)
Line 611: Line 611:
  end
  end
[[Sprite#E2.3|Back]]
[[Sprite#E2.3|Back]]
==Example 2.4==
. "Global robot"
'''put "@sprites.mzm" Image_file p02 at 0 0'''
set "bminx" to '''1'''
set "bminy" to '''1'''
set "bmaxx" to '''81'''
set "bmaxy" to '''26'''
'''set "vw" to 80'''
'''set "vh" to 25'''
set "spr_yorder" to 1
set "spr_p_x" to '''0'''
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 '''3'''
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 '''6'''
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
set "local2" to "playerx"
set "local3" to "playery"
'''set "local4" to "scrolledx"'''
'''set "local5" to "scrolledy"'''
'''. "Uberleet expression hack method:"'''
'''. "set \"local4\" to \"(('scrolledx'<'bminx'*('bminx'-'scrolledx'))+('scrolledx'+'vw'>'bmaxx'*('bmaxx'-'vw'-'scrolledx'))+'scrolledx')\""'''
'''. "set \"local5\" to \"(('scrolledy'<'bminy'*('bminy'-'scrolledy'))+('scrolledy'+'vh'>'bmaxy'*('bmaxy'-'vh'-'scrolledy'))+'scrolledy')\""'''
restore "justentered" 1
| "justentered"
set "spr&playersprite&_off" to 1
loop start
set "spr('keysprite&loopcount&')_off" to 1
loop for "('num_keys'-1)"
loop start
set "spr('doorsprite&loopcount&')_off" to 1
loop for "('num_doors'-1)"
set "num_keys" to 0
set "num_doors" to 0
lockscroll
'''scrollview position "local4" "local5"'''
set "player_x" to "local2"
set "player_y" to "local3"
put player at 0 0
''': "playerloop"'''
'''if "player_x" < "('bminx'+'bmaxx'/2)" then "#playerleft"'''
'''if "player_x" > "('bminx'+'bmaxx'/2)" then "#playerright"'''
'''if "player_y" < "('bminy'+'bmaxy'/2)" then "#playerup"'''
'''if "player_y" > "('bminy'+'bmaxy'/2)" then "#playerdown"'''
'''. "Uberleet expression hack method:"'''
'''. "put player at \"('bminx'+'bmaxx'/2<'player_x'*('board_w'-1))\" \"('bminy'+'bmaxy'/2<'player_y'*('board_h'-1))\""'''
'''wait for 1'''
'''goto "playerloop"'''
end
: "edge0"
set "local2" to "player_x"
set "local3" to "('bmaxy'-'spr_p_h')"
'''set "local4" to "scrolledx"'''
'''set "local5" to "('bmaxy'-'vh')"'''
<s>put player at 0 0</s>
move player NORTH
end
: "edge1"
set "local2" to "player_x"
set "local3" to "bminy"
'''set "local4" to "scrolledx"'''
'''set "local5" to "bminy"'''
<s>put player at "('board_w'-1)" "('board_h'-1)"</s>
move player SOUTH
end
: "edge2"
set "local2" to "('bmaxx'-'spr_p_w')"
set "local3" to "player_y"
'''set "local4" to "('bmaxx'-'vw')"'''
'''set "local5" to "scrolledy"'''
<s>put player at 0 0</s>
move player WEST
end
: "edge3"
set "local2" to "bminx"
set "local3" to "player_y"
'''set "local4" to "bminx"'''
'''set "local5" to "scrolledy"'''
<s>put player at "('board_w'-1)" "('board_h'-1)"</s>
move player EAST
end
''': "#playerleft"'''
'''put player at 0 "playery"'''
'''goto "#return"'''
''': "#playerright"'''
'''put player at "('board_w'-1)" "playery"'''
'''goto "#return"'''
''': "#playerup"'''
'''put player at "playerx" 0'''
'''goto "#return"'''
''': "#playerdown"'''
'''put player at "playerx" "('board_h'-1)"'''
'''goto "#return"'''
---------------------------------------------------------------
. "Player robot"
lockplayer
set "local" to "robot_id"
gotoxy "local" 0
set "playersprite" to "local"
. "&spr&local&"
restore "justentered" 1
| "justentered"
'''set "spr&local&_vlayer" to 1'''
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"
set "spr&local&_lastmove" to 0
if "player_y" <= "bminy" then "edgecollide"
if c?? Sprite_colliding "local" at 0 -1 then "collision"
dec "player_y" by 1
goto "#draw"
goto "#return"
: "#down"
set "spr&local&_lastmove" to 1
if "player_y" >= "('bmaxy'-'spr&local&_height')" then "edgecollide"
if c?? Sprite_colliding "local" at 0 1 then "collision"
inc "player_y" by 1
goto "#draw"
goto "#return"
: "#left"
set "spr&local&_lastmove" to 2
if "player_x" <= "bminx" then "edgecollide"
if c?? Sprite_colliding "local" at -1 0 then "collision"
dec "player_x" by 1
goto "#draw"
goto "#return"
: "#right"
set "spr&local&_lastmove" to 3
if "player_x" >= "('bmaxx'-'spr&local&_width')" then "edgecollide"
if c?? Sprite_colliding "local" at 1 0 then "collision"
inc "player_x" by 1
goto "#draw"
goto "#return"
: "#draw"
put c?? Sprite "local" at "player_x" "player_y"
set "spr&local&_setview" to 1
'''if "scrolledx" < "bminx" then "#fixleft"'''
'''if "scrolledx" > "('bmaxx'-'vw')" then "#fixright"'''
'''if "scrolledx" < "bminy" then "#fixup"'''
'''if "scrolledx" > "('bmaxy'-'vy')" then "#fixdown"'''
'''. "Uberleet expression hack method:"'''
'''. "set \"local2\" to \"(('scrolledx'<'bminx'*('bminx'-'scrolledx'))+('scrolledx'+'vw'>'bmaxx'*('bmaxx'-'vw'-'scrolledx'))+'scrolledx')\""'''
'''. "set \"local3\" to \"(('scrolledy'<'bminy'*('bminy'-'scrolledy'))+('scrolledy'+'vh'>'bmaxy'*('bmaxy'-'vh'-'scrolledy'))+'scrolledy')\""'''
'''. "scrollview position \"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"
: "edgecollide"
send "global" to "edge&spr('local')_lastmove&"
goto "#return"
''': "#fixleft"'''
'''scrollview position "bminx" "scrolledy"'''
'''goto "#return"'''
''': "#fixright"'''
'''scrollview position "('bmaxx'-'vw')" "scrolledy"'''
'''goto "#return"'''
''': "#fixup"'''
'''scrollview position "scrolledx" "bminy"'''
'''goto "#return"'''
''': "#fixdown"'''
'''scrollview position "scrolledx" "('bmaxy'-'vh')"'''
'''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&"
restore "justentered" 1
| "justentered"
set "spr&local&_lpos" to "num_keys"
set "keysprite('spr&local&_lpos')" to "local"
inc "num_keys" by 1
'''set "spr&local&_vlayer" to 1'''
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
dec "num_keys" by 1
set "spr('keysprite&num_keys&')_lpos" to "spr&local&_lpos"
set "keysprite('spr&local&_lpos')" to "keysprite&num_keys&"
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&"
restore "justentered" 1
| "justentered"
set "spr&local&_lpos" to "num_doors"
set "doorsprite('spr&local&_lpos')" to "local"
inc "num_doors" by 1
'''set "spr&local&_vlayer" to 1'''
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
dec "num_doors" by 1
set "spr('doorsprite&num_doors&')_lpos" to "spr&local&_lpos"
set "doorsprite('spr&local&_lpos')" to "doorsprite&num_doors&"
set "spr&local&_off" to 1
die
: "end"
end
[[Sprite#E2.4|Back]]


[[Category:MegaZeux]]
[[Category:MegaZeux]]

Revision as of 19:11, 28 August 2008

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"

Back

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"
set "spr&local&_setview" to 1
goto "#return"

Back

Example 1.3

. "Global robot"
set "spr_yorder" to 1
---------------------------------------------------------------
. "Player robot"
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"
set "spr&local&_setview" to 1
goto "#return"

Back

Example 2.1

. "Global robot"
set "spr_yorder" to 1
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"
set "spr&local&_setview" to 1
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

Back

Example 2.2

. "Global robot"
set "spr_yorder" to 1
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
set "num_keys" to 0
set "num_doors" to 0
---------------------------------------------------------------
. "Player robot"
lockplayer
set "local" to "robot_id"
set "local2" to "thisx"
set "local3" to "thisy"
gotoxy "local" 0
set "playersprite" to "local"
. "&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"
set "spr&local&_setview" to 1
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&_lpos" to "num_keys"
set "keysprite('spr&local&_lpos')" to "local"
inc "num_keys" by 1
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
dec "num_keys" by 1
set "spr('keysprite&num_keys&')_lpos" to "spr&local&_lpos"
set "keysprite('spr&local&_lpos')" to "keysprite&num_keys&"
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&_lpos" to "num_doors"
set "doorsprite('spr&local&_lpos')" to "local"
inc "num_doors" by 1
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
dec "num_doors" by 1
set "spr('doorsprite&num_doors&')_lpos" to "spr&local&_lpos"
set "doorsprite('spr&local&_lpos')" to "doorsprite&num_doors&"
set "spr&local&_off" to 1
die
: "end"
end

Back

Example 2.3

. "Global robot"
set "bminx" to 0
set "bminy" to 0
set "bmaxx" to 80
set "bmaxy" to 25
set "spr_yorder" to 1
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
set "local2" to "playerx"
set "local3" to "playery"
restore "justentered" 1
| "justentered"
set "spr&playersprite&_off" to 1
loop start
set "spr('keysprite&loopcount&')_off" to 1
loop for "('num_keys'-1)"
loop start
set "spr('doorsprite&loopcount&')_off" to 1
loop for "('num_doors'-1)"
set "num_keys" to 0
set "num_doors" to 0
lockscroll
set "player_x" to "local2"
set "player_y" to "local3"
put player at 0 0
end
: "edge0"
set "local2" to "player_x"
set "local3" to "('bmaxy'-'spr_p_h')"
put player at 0 0
move player NORTH
end
: "edge1"
set "local2" to "player_x"
set "local3" to "bminy"
put player at "('board_w'-1)" "('board_h'-1)"
move player SOUTH
end
: "edge2"
set "local2" to "('bmaxx'-'spr_p_w')"
set "local3" to "player_y"
put player at 0 0
move player WEST
end
: "edge3"
set "local2" to "bminx"
set "local3" to "player_y"
put player at "('board_w'-1)" "('board_h'-1)"
move player EAST
end
---------------------------------------------------------------
. "Player robot"
lockplayer
set "local" to "robot_id"
set "local2" to "thisx"
set "local3" to "thisy"
gotoxy "local" 0
set "playersprite" to "local"
. "&spr&local&"
restore "justentered" 1
| "justentered"
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"
set "spr&local&_lastmove" to 0
if "player_y" <= "bminy" then "edgecollide"
if c?? Sprite_colliding "local" at 0 -1 then "collision"
dec "player_y" by 1
goto "#draw"
goto "#return"
: "#down"
set "spr&local&_lastmove" to 1
if "player_y" >= "('bmaxy'-'spr&local&_height')" then "edgecollide"
if c?? Sprite_colliding "local" at 0 1 then "collision"
inc "player_y" by 1
goto "#draw"
goto "#return"
: "#left"
set "spr&local&_lastmove" to 2
if "player_x" <= "bminx" then "edgecollide"
if c?? Sprite_colliding "local" at -1 0 then "collision"
dec "player_x" by 1
goto "#draw"
goto "#return"
: "#right"
set "spr&local&_lastmove" to 3
if "player_x" >= "('bmaxx'-'spr&local&_width')" then "edgecollide"
if c?? Sprite_colliding "local" at 1 0 then "collision"
inc "player_x" by 1
goto "#draw"
goto "#return"
: "#draw"
put c?? Sprite "local" at "player_x" "player_y"
set "spr&local&_setview" to 1
goto "#return"
: "collision"
loop start
goto "#collide('spr_clist&loopcount&')"
send "spr('spr_clist&loopcount&')" to "touch"
loop for "('spr_collisions'-1)"
goto "#return"
: "edgecollide"
send "global" to "edge&spr('local')_lastmove&"
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&"
restore "justentered" 1
| "justentered"
set "spr&local&_lpos" to "num_keys"
set "keysprite('spr&local&_lpos')" to "local"
inc "num_keys" by 1
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
dec "num_keys" by 1
set "spr('keysprite&num_keys&')_lpos" to "spr&local&_lpos"
set "keysprite('spr&local&_lpos')" to "keysprite&num_keys&"
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&"
restore "justentered" 1
| "justentered"
set "spr&local&_lpos" to "num_doors"
set "doorsprite('spr&local&_lpos')" to "local"
inc "num_doors" by 1
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
dec "num_doors" by 1
set "spr('doorsprite&num_doors&')_lpos" to "spr&local&_lpos"
set "doorsprite('spr&local&_lpos')" to "doorsprite&num_doors&"
set "spr&local&_off" to 1
die
: "end"
end

Back

Example 2.4

. "Global robot"
put "@sprites.mzm" Image_file p02 at 0 0
set "bminx" to 1
set "bminy" to 1
set "bmaxx" to 81
set "bmaxy" to 26
set "vw" to 80
set "vh" to 25
set "spr_yorder" to 1
set "spr_p_x" to 0
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 3
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 6
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
set "local2" to "playerx"
set "local3" to "playery"
set "local4" to "scrolledx"
set "local5" to "scrolledy"
. "Uberleet expression hack method:"
. "set \"local4\" to \"(('scrolledx'<'bminx'*('bminx'-'scrolledx'))+('scrolledx'+'vw'>'bmaxx'*('bmaxx'-'vw'-'scrolledx'))+'scrolledx')\""
. "set \"local5\" to \"(('scrolledy'<'bminy'*('bminy'-'scrolledy'))+('scrolledy'+'vh'>'bmaxy'*('bmaxy'-'vh'-'scrolledy'))+'scrolledy')\""
restore "justentered" 1
| "justentered"
set "spr&playersprite&_off" to 1
loop start
set "spr('keysprite&loopcount&')_off" to 1
loop for "('num_keys'-1)"
loop start
set "spr('doorsprite&loopcount&')_off" to 1
loop for "('num_doors'-1)"
set "num_keys" to 0
set "num_doors" to 0
lockscroll
scrollview position "local4" "local5"
set "player_x" to "local2"
set "player_y" to "local3"
put player at 0 0
: "playerloop"
if "player_x" < "('bminx'+'bmaxx'/2)" then "#playerleft"
if "player_x" > "('bminx'+'bmaxx'/2)" then "#playerright"
if "player_y" < "('bminy'+'bmaxy'/2)" then "#playerup"
if "player_y" > "('bminy'+'bmaxy'/2)" then "#playerdown"
. "Uberleet expression hack method:"
. "put player at \"('bminx'+'bmaxx'/2<'player_x'*('board_w'-1))\" \"('bminy'+'bmaxy'/2<'player_y'*('board_h'-1))\""
wait for 1
goto "playerloop"
end
: "edge0"
set "local2" to "player_x"
set "local3" to "('bmaxy'-'spr_p_h')"
set "local4" to "scrolledx"
set "local5" to "('bmaxy'-'vh')"
put player at 0 0
move player NORTH
end
: "edge1"
set "local2" to "player_x"
set "local3" to "bminy"
set "local4" to "scrolledx"
set "local5" to "bminy"
put player at "('board_w'-1)" "('board_h'-1)"
move player SOUTH
end
: "edge2"
set "local2" to "('bmaxx'-'spr_p_w')"
set "local3" to "player_y"
set "local4" to "('bmaxx'-'vw')"
set "local5" to "scrolledy"
put player at 0 0
move player WEST
end
: "edge3"
set "local2" to "bminx"
set "local3" to "player_y"
set "local4" to "bminx"
set "local5" to "scrolledy"
put player at "('board_w'-1)" "('board_h'-1)"
move player EAST
end
: "#playerleft"
put player at 0 "playery"
goto "#return"
: "#playerright"
put player at "('board_w'-1)" "playery"
goto "#return"
: "#playerup"
put player at "playerx" 0
goto "#return"
: "#playerdown"
put player at "playerx" "('board_h'-1)"
goto "#return"
---------------------------------------------------------------
. "Player robot"
lockplayer
set "local" to "robot_id"
gotoxy "local" 0
set "playersprite" to "local"
. "&spr&local&"
restore "justentered" 1
| "justentered"
set "spr&local&_vlayer" to 1
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"
set "spr&local&_lastmove" to 0
if "player_y" <= "bminy" then "edgecollide"
if c?? Sprite_colliding "local" at 0 -1 then "collision"
dec "player_y" by 1
goto "#draw"
goto "#return"
: "#down"
set "spr&local&_lastmove" to 1
if "player_y" >= "('bmaxy'-'spr&local&_height')" then "edgecollide"
if c?? Sprite_colliding "local" at 0 1 then "collision"
inc "player_y" by 1
goto "#draw"
goto "#return"
: "#left"
set "spr&local&_lastmove" to 2
if "player_x" <= "bminx" then "edgecollide"
if c?? Sprite_colliding "local" at -1 0 then "collision"
dec "player_x" by 1
goto "#draw"
goto "#return"
: "#right"
set "spr&local&_lastmove" to 3
if "player_x" >= "('bmaxx'-'spr&local&_width')" then "edgecollide"
if c?? Sprite_colliding "local" at 1 0 then "collision"
inc "player_x" by 1
goto "#draw"
goto "#return"
: "#draw"
put c?? Sprite "local" at "player_x" "player_y"
set "spr&local&_setview" to 1
if "scrolledx" < "bminx" then "#fixleft"
if "scrolledx" > "('bmaxx'-'vw')" then "#fixright"
if "scrolledx" < "bminy" then "#fixup"
if "scrolledx" > "('bmaxy'-'vy')" then "#fixdown"
. "Uberleet expression hack method:"
. "set \"local2\" to \"(('scrolledx'<'bminx'*('bminx'-'scrolledx'))+('scrolledx'+'vw'>'bmaxx'*('bmaxx'-'vw'-'scrolledx'))+'scrolledx')\""
. "set \"local3\" to \"(('scrolledy'<'bminy'*('bminy'-'scrolledy'))+('scrolledy'+'vh'>'bmaxy'*('bmaxy'-'vh'-'scrolledy'))+'scrolledy')\""
. "scrollview position \"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"
: "edgecollide"
send "global" to "edge&spr('local')_lastmove&"
goto "#return"
: "#fixleft"
scrollview position "bminx" "scrolledy"
goto "#return"
: "#fixright"
scrollview position "('bmaxx'-'vw')" "scrolledy"
goto "#return"
: "#fixup"
scrollview position "scrolledx" "bminy"
goto "#return"
: "#fixdown"
scrollview position "scrolledx" "('bmaxy'-'vh')"
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&"
restore "justentered" 1
| "justentered"
set "spr&local&_lpos" to "num_keys"
set "keysprite('spr&local&_lpos')" to "local"
inc "num_keys" by 1
set "spr&local&_vlayer" to 1
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
dec "num_keys" by 1
set "spr('keysprite&num_keys&')_lpos" to "spr&local&_lpos"
set "keysprite('spr&local&_lpos')" to "keysprite&num_keys&"
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&"
restore "justentered" 1
| "justentered"
set "spr&local&_lpos" to "num_doors"
set "doorsprite('spr&local&_lpos')" to "local"
inc "num_doors" by 1
set "spr&local&_vlayer" to 1
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
dec "num_doors" by 1
set "spr('doorsprite&num_doors&')_lpos" to "spr&local&_lpos"
set "doorsprite('spr&local&_lpos')" to "doorsprite&num_doors&"
set "spr&local&_off" to 1
die
: "end"
end

Back