add svg sprite source
[blok] / blokgameview.cpp
1 #include "blokgameview.h"
2
3 BlokGameView::BlokGameView(QWidget *parent) :
4         QGraphicsView(parent)
5 {
6
7     mScene = new PhysicsScene;
8     mWallpaperItem = new QGraphicsPixmapItem;
9     mGroundItem = new BoxItem(QRectF(0,430,800,50),true);
10
11     setScene(mScene);
12
13
14     mScene->addPhysicsItem(new BoxItem(QRectF(0,0,10,480),true));
15     mScene->addPhysicsItem(new BoxItem(QRectF(790,0,10,480),true));
16     mScene->addPhysicsItem(new BoxItem(QRectF(0,0,800,10),true));
17     mScene->addPhysicsItem(new BoxItem(QRectF(0,470,800,10),true));
18
19
20     //Level
21
22
23
24
25
26
27
28
29     mScene->addItem(mWallpaperItem);
30     mScene->addPhysicsItem(mGroundItem);
31
32     setWallpaper(":sprites/sky_wallpaper.png");
33     setGround(":sprites/green_ground.png");
34
35
36
37
38
39
40
41
42     for ( int i=0; i<5; ++i)
43     {
44
45         NormalBlokItem * item =new NormalBlokItem(1,1);
46         item->setPos(32,i*32);
47         mScene->addPhysicsItem(item);
48
49         NormalBlokItem * item2 =new NormalBlokItem(1,1);
50         item2->setPos(40, i*32);
51         mScene->addPhysicsItem(item2);
52
53
54
55     }
56
57
58
59 mScene->addPhysicsItem(new SolidBlokItem(2,2));
60 mScene->addPhysicsItem(new SolidBlokItem(1,4));
61
62
63
64     mScene->start();
65
66 }
67
68 void BlokGameView::setGround(const QString& path)
69 {
70     mGroundItem->setBrush(QBrush(QPixmap(path)));
71 }
72
73 void BlokGameView::setWallpaper(const QString& path)
74 {
75
76     mWallpaperItem->setPixmap(QPixmap(path));
77
78
79 }
80
81 void BlokGameView::mousePressEvent(QMouseEvent *event)
82 {
83
84     if (event->button() == Qt::RightButton)
85         mScene->stop();
86
87     else
88         mScene->start();
89
90
91
92 }
93
94 void BlokGameView::loadMap(const QString& path)
95 {
96
97
98 }