-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCResource.cpp
68 lines (63 loc) · 2.35 KB
/
CResource.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "stdafx.h"
#include "Resource.h"
#include <mmsystem.h>
#include <ddraw.h>
#include "gamelib.h"
#include "CConvert.h"
#include "CSprite.h"
#include "CResourceTable.h"
#include "CResource.h"
#include "CSelectionPanel.h"
#include "mygame.h"
namespace game_framework {
/////////////////////////////////////////////////////////////////////////////
// 這個class為所有地圖中單位與建築物的基底類別
/////////////////////////////////////////////////////////////////////////////
CResource::CResource(){
isResource = true;
}
void CResource::OnSelected(){ //要處理再選擇框內只出現一次的狀況
CSelectionPanel* panel = CSelectionPanel::GetSelectionPanel();
isSelected=true;
if(panel->SelectedSprites().size()!=1){//框選狀況只能選取一個資源物件
panel->AddSpriteToEraseQueue(this);
//以上兩個都會錯,在使用iterator尋訪的時候 刪除過後不能使用++
isSelected=false;
}
}
void CResource::OnShowSelectedLine(){
//畫圓圈
CDC *pDC = CDDraw::GetBackCDC(); // 取得 Back Plain 的 CDC
CPen penBlack;
CPen penWhite;
CPen* pOldPen;
penBlack.CreatePen(PS_SOLID,2,RGB(0,0,0));
penWhite.CreatePen(PS_SOLID,2,RGB(255,255,255));
pOldPen = pDC->SelectObject(&penBlack);
CPoint screenPoint(CConvert::GetScreenPointByMapPoint(mapPoint));
pDC->MoveTo(screenPoint.x,screenPoint.y);//畫黑底線
pDC->LineTo(screenPoint.x+32,screenPoint.y-16);
pDC->LineTo(screenPoint.x,screenPoint.y-32);
pDC->LineTo(screenPoint.x-32,screenPoint.y-16);
pDC->LineTo(screenPoint.x,screenPoint.y);
pDC->SelectObject(&penWhite);//
pDC->MoveTo(screenPoint.x,screenPoint.y+1);//畫白底線
pDC->LineTo(screenPoint.x+32,screenPoint.y-15);
pDC->LineTo(screenPoint.x,screenPoint.y-31);
pDC->LineTo(screenPoint.x-32,screenPoint.y-15);
pDC->LineTo(screenPoint.x,screenPoint.y+1);
pDC->SelectObject(pOldPen); //
CDDraw::ReleaseBackCDC(); // 放掉 Back Plain 的 CDC
}
//void CResource::SetMapPoint(CPoint mapPoint){
// CPoint gridPoint(CConvert::GetGridPointByMapPoint(mapPoint));
// this->mapPoint = CConvert::GetMapPointByGridPoint(gridPoint)+CPoint(63,63);
// CGameMap* map = CGameMap::GetMap();
// //mapTile[0][0] = map->GetMapTile(gridPoint);
// mapTile = map->GetMapTile(gridPoint);
//}
void CResource::FitMapPoint(CPoint mapPoint){
CPoint gridPoint(CConvert::GetGridPointByMapPoint(mapPoint));
SetMapPoint(CConvert::GetMapPointByGridPoint(gridPoint)+CPoint(63,63));
}
}