Mouse-click game

Game development specific discussions.
Post Reply
hhr
Posts: 250
Joined: Nov 29, 2019 10:41

Mouse-click game

Post by hhr »

A very old and simple mouse-click game, level 1 only.
Change the color with 4 clicks.

Code: Select all

#cmdline "-s gui"
screen 0 'Useful in Linux with a slow terminal
windowtitle "MouseFlip"

dim as long x,y,buttons,result,windowsize,imagesize

windowsize = 400
windowsize -= (windowsize mod 2)
imagesize = (windowsize\2)-1

screenres windowsize,windowsize,32

dim as byte ptr image(1 to 2)
image(1) = imagecreate(imagesize,imagesize,rgb(127,255,0))
image(2) = imagecreate(imagesize,imagesize,rgb(255,127,0))
line image(1),(0,0)-(imagesize,imagesize),0,B
line image(2),(0,0)-(imagesize,imagesize),0,B

dim as byte c(0 to 3)

do
   put (0,0),image(c(0)+2),pset
   put (0,imagesize+1),image(c(1)+2),pset
   put (imagesize+1,0),image(c(2)+2),pset
   put (imagesize+1,imagesize+1),image(c(3)+2),pset
   
   result = getmouse (x,y,,buttons)
   if (result = 0) and (buttons <> 0) then
      if (x < imagesize+1) and (y < imagesize+1) then c(0) = not(c(0)) : c(1) = not(c(1)) : c(2) = not(c(2))
      if (x > imagesize+1) and (y < imagesize+1) then c(0) = not(c(0)) : c(2) = not(c(2)) : c(3) = not(c(3))
      if (x < imagesize+1) and (y > imagesize+1) then c(0) = not(c(0)) : c(1) = not(c(1)) : c(3) = not(c(3))
      if (x > imagesize+1) and (y > imagesize+1) then c(1) = not(c(1)) : c(2) = not(c(2)) : c(3) = not(c(3))
   end if
   
   do
      result = getmouse (x,y,,buttons)
      sleep 10,1
   loop until (result <> 0) or (buttons = 0)
   
loop until len(inkey)

imagedestroy image(1)
imagedestroy image(2)
end
hhr
Posts: 250
Joined: Nov 29, 2019 10:41

Re: Mouse-click game

Post by hhr »

You can specify the level in line 7. Levels 1 to 3 are easy. I cannot solve any other levels, maybe that's not possible.

Code: Select all

#cmdline "-s gui -exx"
screen 0 'Useful in Linux with a slow terminal
windowtitle "MouseFlip"

dim as long level,x,y,buttons,result,windowsize,imagesize

level = 2

windowsize = 400
windowsize -= (windowsize mod (level+1))
imagesize = (windowsize\(level+1))-1

screenres windowsize,windowsize+50,32
draw string (windowsize/2-21,windowsize+25),"Reset"

dim as byte ptr image(1 to 2)
image(1) = imagecreate(imagesize,imagesize,rgb(127,255,0))
image(2) = imagecreate(imagesize,imagesize,rgb(255,127,0))
line image(1),(0,0)-(imagesize,imagesize),0,B
line image(2),(0,0)-(imagesize,imagesize),0,B

dim as byte c(1 to level+1,1 to level+1)
dim as long i,j

do
   for i = 0 to level
      for j = 0 to level
         put (i*(imagesize+1),j*(imagesize+1)),image(c(i+1,j+1)+2),pset
      next j
   next i
   
   result = getmouse (x,y,,buttons)
   if (result = 0) and (buttons <> 0) then
      if y >= windowsize then 'Reset
         for i = 0 to level
            for j = 0 to level
               c(i+1,j+1) = 0
            next j
         next i
      else 'Change colors
         i=((level+1)*x\windowsize)+1
         j=((level+1)*y\windowsize)+1
         c(i,j) = not(c(i,j))
         if i <= level then c(i+1,j) = not(c(i+1,j))
         if i > 1 then c(i-1,j) = not(c(i-1,j))
         if j <= level then c(i,j+1) = not(c(i,j+1))
         if j > 1 then c(i,j-1) = not(c(i,j-1))
      end if
   end if
   
   do
      result = getmouse (x,y,,buttons)
      sleep 10,1
   loop until (result <> 0) or (buttons = 0)
   
loop until len(inkey)

imagedestroy image(1)
imagedestroy image(2)
end
Post Reply