Log In  

Cart #simple_mouse-0 | 2019-08-01 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
2

For those learning PICO-8, you may have heard that you can write carts that access the hardware mouse. While the information to do this is not readily apparent, I put together this simple demonstration program with remarks to show how you can do it by reading the position and both buttons of the device.

-- simple introduction to
-- using stat(32,33,34)
-- for reading the mouse
-- by dw817 -- (08-01-19)
--
-- poke(24365,1)
-- enables keyboard + mouse
--
-- stat(32) mouse-x position
-- stat(33) mouse-y position
-- stat(34) =1 if left button
-- stat(34) =2 if right button
-- stat(34) =3 both buttons
--
-- flip() updates the screen

cls()
poke(24365,1) -- enable mouse

c=7
repeat
  color(7)

-- if right-button pressed,
-- change plotting color

  if stat(34)==2 then
    c=c+1
    if (c==16) c=1

-- if both buttons pressed,
-- clear the screen

  elseif stat(34)==3 then
    cls()
  end

-- read x+y position of mouse

  x=stat(32) y=stat(33)

-- if left button pressed,
-- draw on screen

  if stat(34)==1 then
    if ox!=nil then
      line(ox,oy,x,y,c)
    end
    ox=x oy=y
  else
    ox=nil
  end

  p=pget(x,y)
  pset(x,y,c)
  flip()
  pset(x,y,p)

-- loop until press [esc]

until forever

Those who want to reword this OOPS are welcome to.

Hope This Helps !

P#66295 2019-08-01 20:09 ( Edited 2019-08-01 20:12)

This mouse has a drawings on it! Awesome!! <3

P#66450 2019-08-08 00:02

[Please log in to post a comment]

Follow Lexaloffle:        
Generated 2020-08-08 09:28 | 0.017s | 4194k | Q:29