Example Script: clamp slice

Upload your games here. Download other people's games here.

Moderators: Bob the Hamster, marionline, SDHawk

Post Reply
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Example Script: clamp slice

Post by Bob the Hamster »

This is a tiny tech demo, showing how to use the clamp slice plotscripting command.

Code: Select all


global variable(1, sprite)
global variable(2, box)
global variable(3, button)

plotscript, clampslice example, begin
  suspend player
  init mouse
  unhide mouse cursor

  load slice collection(0)
  sprite := lookup slice(sli:dinosaur)
  box := lookup slice(sli:box)
  button := lookup slice(sli:button)

  while(true) do(
    if(keyval(key:esc) > 1) then(game over)
    update button()
    set slice edge x(sprite, edge:center, mouse pixel x -- slice x(box))
    set slice edge y(sprite, edge:center, mouse pixel y -- slice y(box))
    clamp slice(sprite, box)
    wait(1)
  )
end

script, update button, begin
  if(slice collide point(button, mouse pixel x, mouse pixel y)) then(
    set rect bg col(button, random(0, 255))
    if(mouse click(left button)) then(
      randomize the box()
    )
  )else(
    set rect bg col(button, 96)
  )
end

script, randomize the box, begin
  variable(width)
  width := slice width(sprite layer)
  variable(height)
  height := slice height(sprite layer)
  set slice x(box, random(0, width / 4))
  set slice y(box, random(0, height / 4))
  set slice width(box, random(width / 2, width * 3/4))
  set slice height(box, random(height / 2, height * 3/4))
end
Attachments
clampslice.zip
clamp slice example rpg (with script)
(50.37 KiB) Downloaded 368 times
clampslice0001.gif
clampslice0001.gif (377.95 KiB) Viewed 1932 times
Post Reply