-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
readded map on loading screen, further optimized rendering
- Loading branch information
1 parent
1ea5660
commit f3b62bc
Showing
3 changed files
with
165 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Igis | ||
import Scenes | ||
|
||
class Map { | ||
var map : [[Color]] | ||
let pixelSize : Int | ||
|
||
init(xSize:Int, ySize:Int, pixelSize:Int) { | ||
map = [] | ||
for y in 0 ..< ySize { | ||
map.append([]) | ||
for _ in 0 ..< xSize { | ||
map[y].append(Color(red:0, green:0, blue:0)) | ||
} | ||
} | ||
self.pixelSize = pixelSize | ||
} | ||
|
||
func changePixel(x:Int, y:Int, to:Color) { | ||
precondition(y < map.count, "Map.swift, function changePixel(x:\(x), y:\(y)): Unexpected y value \(y), value must be less than \(map.count)") | ||
precondition(x < map[0].count, "Map.swift, function changePixel(x:\(x), y:\(y)): Unexpected x value \(x), value must be less than \(map[0].count)") | ||
|
||
map[y][x] = to | ||
} | ||
|
||
func getPixel(x:Int, y:Int) -> Color { | ||
precondition(y < map.count, "Map.swift, function getPixel(x:\(x), y:\(y)): Unexpected y value \(y), value must be less than \(map.count)") | ||
precondition(x < map[0].count, "Map.swift, function getPixel(x:\(x), y:\(y)): Unexpected x value \(x), value must be less than \(map[0].count)") | ||
|
||
return map[y][x] | ||
} | ||
|
||
func render(canvas:Canvas) { | ||
let center = Point(x:canvas.canvasSize!.width/2, y:canvas.canvasSize!.height/2) | ||
let startingPoint = Point(x:center.x-((map[0].count*pixelSize)/2), y:center.y-((map.count*pixelSize)/2)) | ||
|
||
for y in 0 ..< map.count { | ||
for x in 0 ..< map[y].count { | ||
canvas.render(FillStyle(color:map[y][x])) | ||
canvas.render(Rectangle(rect:Rect(topLeft:Point(x:startingPoint.x+(x*pixelSize), y:startingPoint.y+(y*pixelSize)), size:Size(width:pixelSize, height:pixelSize)), fillMode:.fill)) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.