Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mouse off
#1
Hi everyone

Making some mouse studies in NaaLaa. Glade to share this code. Feel free to improve it. [Image: smile.png]


Code:
import "keycodes.lib"

constant:
  MOUSE_LEFT 0
  MOUSE_RIGHT 1
  SCREENWIDTH 640
  SCREENHEIGHT 480

hidden:

set window 0, 0, SCREENWIDTH, SCREENHEIGHT, false, 2
set redraw off
set color 0,0,0
cls

eventmouseleftbuttonpressed=0
eventmouserightbuttonpressed=0

set mouse off
set mouse SCREENWIDTH/2, SCREENHEIGHT/2

do  
  mx=mousex()
  my=mousey()

  if mousebutton(MOUSE_LEFT)
    eventmouseleftbuttonpressed=1
  else
    eventmouseleftbuttonpressed=0
  endif

  if mousebutton(MOUSE_RIGHT)
    eventmouserightbuttonpressed=1
  else
    eventmouserightbuttonpressed=0
  endif
 
  if eventmouseleftbuttonpressed=1 and eventmouserightbuttonpressed=0
    set color 0,0,0
    cls
    set color 0,255,0
    set caret 10,10
    wln "mouse left button: ON"
    draw ellipse mx, my, 20, 20, 1
    set color 255,0,0
    set caret 10,20
    wln "mouse right button: OFF"
  endif

  if eventmouseleftbuttonpressed=0 and eventmouserightbuttonpressed=1
    set color 0,0,0
    cls
    set color 255,0,0
    set caret 10,10
    wln "mouse left button: OFF"
    set color 255,0,255
    set caret 10,20
    wln "mouse right button: ON"
    set color 255,0,255
    draw ellipse mx, my, 10, 10, 1
  endif

  if eventmouseleftbuttonpressed=1 and eventmouserightbuttonpressed=1
    set color 0,0,0
    cls
    set color 0,255,0
    set caret 10,10
    wln "mouse left button: ON"
    set color 0,255,0
    draw ellipse mx, my, 20, 20, 1

    set color 255,0,255
    set caret 10,20
    wln "mouse right button: ON"
    set color 255,0,255
    draw ellipse mx, my, 10, 10, 1
  endif

  if eventmouseleftbuttonpressed=0 and eventmouserightbuttonpressed=0
    set color 0,0,0
    cls
    set color 255,0,0
    set caret 10,10
    wln "mouse left button: OFF"
    set color 255,0,0
    set caret 10,20
    wln "mouse right button: OFF"
  endif

  set color 255,255,255
  draw ellipse mx, my, 20, 20, 0

  redraw
until keydown(VK_ESC) or not running()
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)