-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDSABattleMapView.m
More file actions
71 lines (55 loc) · 2.46 KB
/
DSABattleMapView.m
File metadata and controls
71 lines (55 loc) · 2.46 KB
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
69
70
71
/*
Project: DSA-SpielHelfer
Copyright (C) 2025 Free Software Foundation
Author: Sebastian Reitenbach
Created: 2025-05-16 21:33:14 +0200 by sebastia
This application is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This application is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import "DSABattleMapView.h"
#import "DSAAreaMap.h"
#import "DSACharacter.h"
@implementation DSABattleMapView
- (void)drawRect:(NSRect)dirtyRect {
[super drawRect:dirtyRect];
if (!self.battleMap) return;
CGFloat tileSize = 32.0;
NSUInteger rows = self.battleMap.areaMap.height;
NSUInteger cols = self.battleMap.areaMap.width;
for (NSUInteger y = 0; y < rows; y++) {
for (NSUInteger x = 0; x < cols; x++) {
NSRect tileRect = NSMakeRect(x * tileSize, y * tileSize, tileSize, tileSize);
DSABattleMapTile *tile = self.battleMap.battleTiles[y][x];
NSColor *fillColor = [self colorForTerrain:tile.baseTile.terrainType];
[fillColor setFill];
NSBezierPath *path = [NSBezierPath bezierPathWithRect:tileRect];
[path fill];
if (tile.occupant) {
if (tile.occupant.isNPC) {
[[NSColor redColor] set];
} else {
[[NSColor blackColor] set];
}
NSBezierPath *circle = [NSBezierPath bezierPathWithOvalInRect:NSInsetRect(tileRect, 4, 4)];
[circle fill];
}
}
}
}
- (NSColor *)colorForTerrain:(NSString *)terrainType {
if ([terrainType isEqualToString:@"grass"]) return [NSColor greenColor];
if ([terrainType isEqualToString:@"stone"]) return [NSColor grayColor];
if ([terrainType isEqualToString:@"water"]) return [NSColor blueColor];
if ([terrainType isEqualToString:@"bush"]) return [NSColor darkGrayColor];
return [NSColor whiteColor];
}
@end