mooc上学习acllib后写的包含背景音乐的小涂鸦板(初入江湖,大佬勿喷)

#include "acllib.h"
ACL_Sound sound1;
ACL_Image img;//开始图
ACL_Image img1;//涂鸦图
ACL_Color c=RED;//默认画笔颜色
int cx=0;
int cy=0;
int j=0;//开始界面和绘图界面分离
int m=0;//重置当前绘图点and监控鼠标左或右键是否一直按着
void BEGIN(void)
{
 loadImage("begin_one.jpg",&img);
 loadSound("pop.mp3",&sound1);
 playSound(sound1,1);
 beginPaint();
 putImage(&img,0,0);
 setTextColor(RED);
 setTextBkColor(GREEN);
 setTextSize(50);
 setTextFont("Goudy Stout");
 paintText(125,200,"BEGIN");
 paintText(175,275,"MUSIC");
 paintText(225,350,"EXIT");
 endPaint();
}

void face_paint()
{
   loadImage("tu.jpg",&img1);
  
   //事先插图为了能够在上面涂鸦
   beginPaint();
   putImage(&img1,200,200);
    endPaint();
}

void rel_paint()
{
    static int ox = 0;
    static int oy = 0;
 
       if(m==1)//避免线画图成为点画图和把绘图起点确定
      {
            ox=cx;
           oy=cy;
           m++;
      }
     if(!(cx>=10&&cx<=72&&cy>=10&&cy<=30))
    { 
       
        beginPaint();
        setPenWidth(3);
        setPenColor(c);
        line(ox,oy,cx,cy);
        endPaint();
        ox=cx;
        oy=cy;
    
    }
}

void mouseEvent(int x,int y,int key,int event)
{
         static int k = 0; //完成歌曲开关键的重复使用(用全局或静态变量保证生存周期)
         //记录绘图坐标
         cx=x;
         cy=y;
 
      //开始界面的begin功能实现
    if(j==0&&x>=125&&x<=260&&y>=200&&y<=250&&key==LEFT_BUTTON&&event==BUTTON_DOWN)
      {
                beginPaint();
                clearDevice();
                endPaint();
                face_paint();
                j=1;
      }
 
          //MUSIC开关控制
     if(j==0&&x>=175&&x<=309&&y>=275&&y<=322&&key==LEFT_BUTTON&&event==BUTTON_DOWN)
    {
       switch(k)
      {
          case 0: 
         //菜单颜色
          beginPaint();
          putImage(&img,0,0);
           setTextColor(RED);
           setTextBkColor(GREEN);
           setTextSize(50);
           setTextFont("Goudy Stout");
           paintText(125,200,"BEGIN");
           paintText(225,350,"EXIT");
           endPaint();
          //改变选项颜色
           beginPaint();
          setTextColor(GREEN);
          setTextBkColor(RED);
          setTextSize(50);
         setTextFont("Goudy Stout");
         paintText(175,275,"MUSIC");
         endPaint(); 
         stopSound(sound1);//关闭音乐
         k=1;
         break;
  
          case 1:
          playSound(sound1,1);
            beginPaint();
            putImage(&img,0,0);
             setTextColor(RED);
             setTextBkColor(GREEN);
             setTextSize(50);
             setTextFont("Goudy Stout");
              paintText(125,200,"BEGIN");
              paintText(175,275,"MUSIC");
              paintText(225,350,"EXIT");
              endPaint();
             k=0;
             break;
         }
    }
 
 
    if(j==0&&x>=222&&x<=319&&y>=349&&y<=398&&key==LEFT_BUTTON&&event==BUTTON_DOWN)
 {
  exit(0);//退出功能
 }
 
 //画板面
 
       if(j==1)
     {   
       //选色板
         beginPaint();
        setBrushColor(BLUE);
        rectangle(10,10,30,30);
        endPaint();
 
        beginPaint();
       setBrushColor(GREEN);
       rectangle(31,10,51,30);
       endPaint();
 
       beginPaint();
       setBrushColor(BLACK);
       rectangle(52,10,72,30);
       endPaint();
   
       //调用划线函数
      //按住左键即可画图
             if(m!=0)
             {   
                rel_paint();
            }

//笔色
            if(key==LEFT_BUTTON&&event==BUTTON_DOWN)
           {
                 m=1;
                          if(x>=10&&x<=30&&y>=10&&y<=30)
                        {
                              c=BLUE;
                         }
                        if(x>=31&&x<=51&&y>=10&&y<=30)
                         {
                                c=GREEN;
                          }
                       if(x>=52&&x<=72&&y>=10&&y<=30)
                        {
                                c=BLACK;
                       }
           }

if(event==BUTTON_UP)
         {
              m=0;//既停止了一次画线,又重置了绘图点
          }
   
    }
 
}

int Setup()
{
 
 initWindow("",DEFAULT,DEFAULT,800,600);
 initConsole();
 switch(j)
 {
 case 0: BEGIN();break;
 }
 registerMouseEvent(mouseEvent);
    return 0;
 
}

//选用开始图片(img)

mooc上学习acllib后写的包含背景音乐的小涂鸦板(初入江湖,大佬勿喷)

//选用音乐和涂鸦图随意

上一篇:如何在IIS6,7中部署ASP.NET网站


下一篇:hadoop分布式集群完全安装(非HA)