Building XNA 2.0 Games- P4

Building XNA Games- P4: I would like to acknowledge John Sedlak, who saved this book from certain doom, as well as all of the great guys in the XNA community and Microsoft XNA team, who helped me with all of my stupid programming questions. (That is actually the term used—“stupid programming question”—and it is a question that one should not have to ask if one has been approached to write a book about the subject.) | CHAPTER 4 THE MAP EDITOR 77 The Grid We ll define the grid in the Map class and then add functionality for viewing and editing it in Camel. MapSegment mapSeg int col In the constructor initialize col to be a 20-by-20 array mapSeg new MapSegment 3 64 col new int 20 20 ReadSegmentDefinitions As usual we add a property to gain access from the outside public int Grid get return col Back in Camel we make a function to draw the grid and collisions private void DrawCrid for int y 0 y 20 y for int x 0 x 20 x Rectangle dRect new Rectangle x 32 - int 2 y 32 - int 2 32 32 if x 19 nullTex new Rectangle 32 1 new Color 255 0 0 100 if y 19 nullTex new Rectangle 1 32 new Color 255 0 0 100 78 CHAPTER 4 THE MAP EDITOR if x 19 y 19 if x y 1 nullTex dRect new Color 255 0 0 100 We re using our 1 x 1 white texture again to draw a grid here filling in grid spaces where the value of col is 1. To allow the user to edit the collision map we ll need to let the user change the drawing mode. Currently the drawing mode allows us to place map segments we want to be able to switch to a collision map drawing mode. Add a new class to the MapEditor project called DrawingMode. When the editor opens change it from a class to an enumerator adding the following values enum DrawingMode Segmentselection CollisionMap Then in the Game1 class add the following field DrawingMode drawType We ll make a drawing button sort of like our layer-selection button ugly yet functional. In right next to the layer button add the following switch drawType case layerName select break case layerName col break if 5 25 draw layerName mosX mosY mouseClick drawType DrawingMode int drawType 1 2 CHAPTER 4 THE MAP EDITOR 79 Because we don t want to

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.