ai 2009 homework#2
DESCRIPTION
พื้นหญ้า. พื้นทราย. +10. +7. +14. +14. +4. +4. +10. +10. +7. +7. +14. +4. +14. +4. +10. +7. AI 2009 Homework#2. งานกลุ่ม แก้ไข map ใหม่ ให้สวยงาม เพิ่มพื้นทราย(มีรูปให้แล้ว) แก้ไขโปรแกรม เส้นทางการเดิน ที่ใช้ A* ดังนี้ กำหนดส่ง วันที่ 20 มกราคม 2553 - PowerPoint PPT PresentationTRANSCRIPT
AI 2009 Homework#2
• งานกลุ่��ม• แกไข map ใหม� ใหสวยงาม เพิ่��มพิ่��นทราย(ม�ร�ปใหแลุ่ว)• แกไขโปรแกรม เสนทางการเดิ�น ท��ใช้ A* ดิ!งน��
• ก"าหนดิส�ง ว!นท�� 20 มกราคม 2553• ร�ปเลุ่�มรายงาน อธิ�บาย
– หลุ่!กการท"างานของ A*– ส�วนของโปรแกรมท��ไดิปร!บปร�งแกไข
+10
+10
+10 +10
+14+14
+14+14
พิ่��นหญ้า พิ่��นทราย+7
+7
+7 +7
+4+4
+4+4
การเร�ยกโปรแกรม1.ลุ่ง C#2.ลุ่ง XNA3. unrar TileMap74. double click Tilemap.sln
เก��ยวก!บไฟลุ่)• Game1 โปรแกรมหลุ่!ก• Mymap ส�วนจั!ดิการ map แลุ่ะ A*• Myview ส�วนจั!ดิการ view (แสดิงผลุ่ส�วนย�อยๆ ของ
map)• Mypath ส�วนเก.บขอม�ลุ่เสนทาง path ท��ตั!วลุ่ะครเดิ�น• Myobject ส�วนจั!ดิการตั!วลุ่ะคร ตั"าแหน�งของตั!วลุ่ะคร• Mysprite ส�วนจั!ดิการวาดิร�ปตั!วลุ่ะคร การเคลุ่��อนไหว• Myutils ฟ0งก)ช้! �นย�อยๆ ตั�างๆ
MyMap.csตั!วลุ่ะครเดิ�นไดิหร�อไม� ข1�นอย��ก!บค�า mapenum // ค�าสถานะของ map public enum mapenum { map_none = 0, map_walk = 1, map_obstracle = 2 };
ภาพิ่ในฉากแผนท�� ข1�นก!บค�า mapenumimage public enum mapenumimage { empty=0, block, pira, chest, doorclose, dooropen, //5 grass, grassshadow, rocks, sandgrass1, sandgrass2, //10 sandgrass3, sandgrass4, sandgrass, sandgrass6, sandgrass7, //15 sandgrass8, sandgrass9, sand, wall1, waterwall, //20 watergrass, water, waterref2, waterref3, waterref //25 };
MyMap.cs.2แตั�ลุ่�ะตั"าแหน�งของ map จัะเก.บค�าดิ!งน�� public struct mapelement { public mapenum maptype; // ประเภทของ map public mapenumimage mapimage; // ร�ปของ map public float g; // ตั!วแปร A* public float h; // ตั!วแปร A* public float f; // ตั!วแปร A* public int parentX; // ตั!วแปร A* public int parentY; // ตั!วแปร A* public bool isopenlist; // ตั!วแปร A* public bool iscloselist; // ตั!วแปร A* public int count; // ตั!วแปร A* }public mapelement[,] mapdata; array 2D ของ mappublic Texture2D[] mappic; array ของ ร�ปpublic mypath pathdata; path ท��สรางโดิย A*
Clearmap() ลุ่างขอม�ลุ่Createmap() สรางขอม�ลุ่แผนท��drawmap(Vector2 startpos) วาดิแผนท��clearAstarParams() ลุ่างขอม�ลุ่ A* // A* fn g : g fn ม�ค�าเพิ่��มข1�นจัากการเคลุ่��อนท�� public float fn_g(int px, int py, int fromX, int fromY) // A* fn h : heuristic fn ม�ค�าลุ่ดิลุ่งเม��อเขาใกลุ่ target public float fn_h(int px, int py, int targetX, int targetAstarAB(Vector2 a) ค"านวณ A จัาก ตั"าแหน�ง a ไปย!ง targetX,
targetY ค�อค�าเป6น path
C# XNA : 2D Map Scrollingand others related useful functions
Dr.Yodthong Rodkaew
RTS + RPG
2D Map in XNA
•Map as 2D array•1 block of map is struct
If map area is larger than screen area ?
64,64
800,600
2D Map in XNAIf map area is larger than screen area ?
64,64
800,600
MAP AREA
SCREEN AREA
2D Map Scrolling
MAP AREA
SCREEN AREAViewport
Map[0,0]
Screen(0,0)
Screen(800,600)Map[w,h]
2D Map Scrolling
Screen(0,0)
Screen(800,600)
Map[20,20]
2D Map Scrolling
Screen(0,0)
Screen(800,600)
Map[10,20]
2D Map Scrolling
Screen(0,0)
Screen(800,600)
Map[10,20]
2D Map to Block
Screen(0,0)
Screen(800,600)
Map[10,20]
Mouse Pointer = Map[x,y] ??
Mouse pointer at(400,250)
การใช้ view
• View ส"าหร!บควบค�ม การเลุ่��อนหนาจัอ
map
view
View.position
View.widthView.height
Map.widthMap.height
Mouse.position
[Need]-View center at mapblock(x,y)-View moving: up/down/left/right-map mouse to view position, to real mapblock-is_position_in_view(x,y)
Map RTS, select & move
view
View.position
View.widthView.height
View.center_at_mapblock(int mapx, int mapy)
viewx = ________________? viewy = ________________?
map(mapx,mapy)
View (viewx,viewy)
Center of view
ตัองการหา viewxy ทราบ mapxy view width height
view
View.position
View.widthView.height
View.mouse_to_viewblock(int mousex, int mousey)
mapx = ________________? mapy = ________________?
map(mapx,mapy)
View (viewx,viewy)
Mouse
Screen(0,0)
Screen(800,600)
ตัองการหา mapxy ทราบ
mousexy view width
height
view
View.position
View.widthView.height
View.is_position_in_view(int mapx, int mapy)
In_view = ________________________?
map(mapx,mapy)View (viewx,viewy)
ตัองการหา mapxyอย��ใน view หร�อไม�
ทราบ mapxy,viewxy, view width
height
map(mapx,mapy)
map
view
View.position
View.widthView.height
Map.widthMap.height
Move down
Task.I: arrow key move viewIf ( ______ ) { _______________ }Task.II: mouse near border move viewIf ( ______ ) { _______________ }
Move right
view
View.position
View.widthView.height
step1
Click & MoveStep1: find what hero is clicked [source+hero]Step2: find what area is clicked [target]Step3: get path from A*Step4: make hero move follow a path
step2
Step3&4