2009年7月28日 星期二

目前的程式畫面


打中障礙物後,已經能清掉障礙了,子彈改成可複數.
read more...

2009年7月24日 星期五

準備用Qt來寫個小遊戲

目前寫好了機台Body和子彈,子彈移動是用執行續來做,機台是用抓滑鼠移動x座標

抓滑鼠移動(移動body)
void Frame::mouseMoveEvent(QMouseEvent *e)//滑鼠事件move
抓滑鼠按下(發射子彈)
void Frame::mousePressEvent(QMouseEvent *event)//滑鼠事件press

執行結果:

read more...

2009年7月18日 星期六

寫個Qt動畫

無聊,把之前寫的xmms2播放介面來弄個動畫

read more...

Slax - 你專屬的小系統


undefined

slax是一個微型Linux系統滿方便的,可安裝在大姆哥隨身碟,大姆哥就是一套好用的OS,便利性100%,好玩的是,可整套OS放在ram來執行,更可怕的是軟件都不用安裝,這對不太懂電腦的,真是太方便了,剛試一下wine gba模擬器竟然成功,不錯,這樣以後要出門只要帶大姆哥OS,XD..............
read more...

2009年7月10日 星期五

Qt讓畫圖達到旋轉


這是在QMatrix的說明中的一段,我們拿來套用,QMatrix可讓QPainter,上下左右或者旋轉

double pi = 3.14;

// double a = pi/180 * 185.0; //改變角度
double a = pi/180 * shapex;
double sina = sin(a);
double cosa = cos(a);

QMatrix translationMatrix(1, 0, 0, 1, 50.0, 50.0);
QMatrix rotationMatrix(cosa, sina, -sina, cosa, 0, 0);
QMatrix scalingMatrix(0.5, 0, 0, 1.0, 0, 0);

QMatrix matrix;
matrix = scalingMatrix * rotationMatrix * translationMatrix;


painter.setPen(QPen(Qt::blue, 1, Qt::DashLine));
painter.drawRect(0, 0, 100, 100);

painter.setMatrix(matrix); //這會改變painter的matrix

painter.setFont(QFont("Helvetica", 24));
painter.setPen(QPen(Qt::black, 1));
painter.drawText(20, 10, "QMatrix");

來看結果:


read more...

2009年7月5日 星期日

Qt製作動畫




太高興了,搞了快2天才知道動畫原理,我新增了一個QThread的Class,然後要在此Class作一個信號槽(SIGNAL),連到
QWidget的SlOT,一直沒注意到應該跟QTimer類似,才想很久才想通,當然用QTimer也可達到動畫效果,只是我要用QThread來達成,彈性較大

Wthread.h
--------------------------------------------------------------------------

#ifndef WTHREAD_H
#define WTHREAD_H

#include
class Wthread:public QThread
{
Q_OBJECT
public:
Wthread(QObject *parent = 0);
~Wthread();
//信號
signals:
void setxy(int i1, int i2,int i3,int i4);
protected:
void run();
};

#endif // WTHREAD_H
----------------------------------------------------------------------------
Wthread.cpp
----------------------------------------------------------------

#include "wthread.h"
#include
Wthread::Wthread(QObject *parent)
: QThread(parent)
{




}
void Wthread::run() {

for(int i = 10; i 300; i += 10) {

emit setxy(i,i,i,i);
msleep(1000);
}

}
Wthread::~Wthread()
{

}
--------------------------------------------------------------------
Widget.cpp
----------------------------------------------------------------------------
#include "widget.h"
#include "ui_widget.h"
#include
#include
#include
#include
#include
#include "wthread.h"
Widget::Widget(QWidget *parent)
: QWidget(parent), ui(new Ui::Widget)
{

ui->setupUi(this);
setShape(20,20,120,120);
step_value=0;
//qRegisterMetaType("i1");
connect(&thread, SIGNAL(setxy(int , int ,int ,int )),this, SLOT(setShape(int ,int ,int ,int )));


}

Widget::~Widget()
{
delete ui;

}
//重畫
void Widget::setShape(int x,int y,int w,int h)
{
shapex=x;
shapey=y;
shape_width=w;
shape_height=h;
update();
}

void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPainterPath path;
painter.setBrush(QColor(122, 163, 39));
path.addRect(shapex, shapey, shape_width, shape_height);
painter.drawPath(path);

}

void Widget::on_pushButton_pressed()
{
step_value= step_value+10;
setShape(20,20,120+step_value,120+step_value);
}

void Widget::on_pushButton_2_pressed()
{
step_value= step_value-10;
setShape(20,20,120+step_value,120+step_value);
}

void Widget::on_pushButton_3_pressed()
{
thread.start();
}







又作一個,做在QFrame裡面



重前面幾段,就可完成一個動畫,又能一邊控制物件移動,就可用Qt來作簡單的遊戲了,來看下面的例子


read more...

2009年7月4日 星期六

Qt畫圖



畫圖很簡單,問題是我要按一下按鈕就會重劃,找很久,才知道他的原理,首先要重新宣告paintEvent,要把處裡畫圖寫到這裡面,然後用update(),重劃
下面就是一個例子,setShape(int x,int y,int w,int h)是一個重劃函式,給了一個座標,和寬高,update來達成重劃矩形
paintEvent則重新宣告來畫圖(這裡是畫矩形)

void Widget::setShape(int x,int y,int w,int h)
{
shapex=x;
shapey=y;
shape_width=w;
shape_height=h;
update();
}
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPainterPath path;
painter.setBrush(QColor(122, 163, 39));
path.addRect(shapex, shapey, shape_width, shape_height);
painter.drawPath(path);
painter.restore();
}
------------------------slot函數-----------------------------------
void Widget::on_pushButton_pressed()
{
step_value= step_value+10;
setShape(20,20,120+step_value,120+step_value);
}

void Widget::on_pushButton_2_pressed()
{
step_value= step_value-10;
setShape(20,20,120+step_value,120+step_value);
}
------------------------------------------------------------------------
下面就是一個簡單例子,每當我按一次放大,長寬會加10,縮小則減10



read more...