Skip to content

Commit

Permalink
updated example for tilemap changes, added LoS, rebuilt
Browse files Browse the repository at this point in the history
Added Line of Sight to the example, second character hiding in the
'cave' can only been see when there are no walls betwen it and the
player.
  • Loading branch information
MalphasWats committed Jan 8, 2013
1 parent 5a98713 commit 79f954a
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 34 deletions.
22 changes: 17 additions & 5 deletions examples/example14.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
<body style="background:black; color:white;">

<canvas width="320" height="320" style="background:white;"></canvas>
<p>FPS: <span id="fps"></span>. Click a dirt tile to move.</p>
<p>FPS: <span id="fps"></span>. Click a dirt tile to move. Find the hiding villain.</p>

<div id="info">
<h1>Example 14: Pathfinding in a TileMap</h1>
<h1>Example 14: Pathfinding and Line of Sight in a TileMap</h1>
</div>

<script>
function Rouge() {
var player
var player, evil_player
var walls
var fps

Expand Down Expand Up @@ -110,11 +110,19 @@ <h1>Example 14: Pathfinding in a TileMap</h1>
{
if (this.path.length > 0)
{
var next_node = this.path.shift()
this.destination = floor_map.cell(next_node[0], next_node[1])[0]
this.destination = this.path.shift()
}
else { this.destination = false }
}

evil_player = new jaws.Sprite({image: "example14/player.png", x:160, y:192, anchor: "bottom_right", angle:180})
evil_player.visible = function()
{
/**
* check if line of sight between evil player and the player
*/
return wall_map.lineOfSight([this.x, this.y], [player.x, player.y])
}

jaws.context.mozImageSmoothingEnabled = false; // non-blurry, blocky retro scaling
jaws.preventDefaultKeys(["up", "down", "left", "right", "space"])
Expand Down Expand Up @@ -161,6 +169,10 @@ <h1>Example 14: Pathfinding in a TileMap</h1>
floor.draw()
walls.draw()
player.draw()
if (evil_player.visible())
{
evil_player.draw()
}
}
}

Expand Down
Loading

0 comments on commit 79f954a

Please sign in to comment.