码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-07-20 13:37:55      阅读:470      评论:0      收藏:0      [点我收藏+]

标签:菜单   画图   color   江湖   cas   绘图   turn   break   idt   

#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();
  BEGIN();
 registerMouseEvent(mouseEvent);
    return 0;
 
}

//选用开始图片(img)

 技术分享

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

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

标签:菜单   画图   color   江湖   cas   绘图   turn   break   idt   

原文地址:http://www.cnblogs.com/hisir/p/7210644.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!