Post Reply 
Classic game "Lighs Out"
01-02-2014, 04:59 PM
Post: #7
RE: Classic game "Lighs Out"
You can make your program much smaller by using the drawing commands such as FILLPOLY to color the boxes instead of the two different graphics for each type of box.

Code:

DRAW();

EXPORT TILE()
BEGIN
  LOCAL s=16;
  LOCAL onoff,key,x=2*s,y=2*s,run=1;
  DIMGROB_P(G2,320,240);
  DIMGROB_P(G1,s,s);

  // create a temporary example; if you want a tile block, then
  // you only really need one and then color the rest using
  // FILLPOLY
  BLIT_P(G1,G0,320-s,0,320,s);

  WHILE run DO
  DRAW(x,y,onoff);
  key:=WAIT(-1);
   
  CASE
    if TYPE(key)==6 then run:=0; end;
    if key==27 then onoff:=(onoff+1) MOD 2; end;

    REPEAT
      CASE
        if key==2 then y:=y-s; end;
        if key==7 then x:=x-s; end;
        if key==8 then x:=x+s; end;
        if key==12 then y:=y+s; end;
      END;

      if x<0 then x:=320-s; end;
      if x>320-s then x:=0; end;
      if y<0 then y:=240-s; end;
      if y>240-s then y:=0; end;
      DRAW(x,y,onoff);
      WAIT(.2);
 
    UNTIL NOT ISKEYDOWN(key); // repeat loop 
  END; // outer case

  END; // while loop 
END;

DRAW(x,y,onoff)
BEGIN
  LOCAL s=16;
  LOCAL red:=#FF0000h, blue:=#FFh;
      RECT_P(G2);
      BLIT_P(G2,x,y,G1);
      FILLPOLY_P(G2,
        { {x,y},{x+s,y},{x+s,y+s},{x,y+s} },
        (NOT onoff)*red+onoff*blue,
      128);
      BLIT_P(G0,G2);
END;

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Classic game "Lighs Out" - ArielPalazzesi - 01-01-2014, 10:47 PM
RE: Classic game "Lighs Out" - tgallo - 01-02-2014, 05:25 AM
RE: Classic game "Lighs Out" - tgallo - 01-02-2014, 12:16 PM
RE: Classic game "Lighs Out" - Han - 01-02-2014, 06:13 AM
RE: Classic game "Lighs Out" - Han - 01-02-2014 04:59 PM
RE: Classic game "Lighs Out" - tgallo - 01-03-2014, 06:23 PM
RE: Classic game "Lighs Out" - Han - 01-03-2014, 06:03 PM
RE: Classic game "Lighs Out" - eried - 01-03-2014, 07:31 PM
RE: Classic game "Lighs Out" - eried - 01-03-2014, 08:03 PM
RE: Classic game "Lighs Out" - Mic - 01-04-2014, 02:54 PM



User(s) browsing this thread: 2 Guest(s)