Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Level editor #4

Merged
merged 13 commits into from
Aug 1, 2019
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,5 @@ __pycache__/
# vscode files
.vscode/

# mac
.DS_Store
Binary file modified Documentation/R5 Coords.xlsx
Binary file not shown.
1 change: 1 addition & 0 deletions Documentation/level_1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
;;;;;;;;1;1;1;1;2;;;;;;;;;;;;;;6;1;0;0;0;0;2;2;2;;;;;;;;;;4;6;6;1;0;0;0;0;2;2;2;2;4;;;;;;;6;6;6;6;1;0;0;0;0;0;2;2;2;2;2;;;;;4;6;6;6;6;1;0;0;0;0;0;0;2;2;2;2;4;;;;6;6;6;6;6;1;0;0;0;0;1;0;0;0;2;2;2;;;6;6;6;6;6;6;1;1;1;1;0;1;1;1;0;0;2;2;2;;6;6;6;6;6;1;1;1;1;1;1;1;1;1;1;1;0;2;2;6;6;6;6;6;1;1;1;1;1;1;1;1;1;1;1;1;0;2;2;26;6;6;6;1;1;1;0;1;1;1;1;1;0;0;1;1;1;1;1;26;6;6;1;1;0;0;0;1;1;1;1;1;0;0;1;1;10;9;9;91;1;1;1;0;0;0;0;0;1;1;1;1;0;0;1;1;9;3;3;31;7;7;8;0;0;0;0;0;1;1;1;1;0;0;0;4;3;3;3;3;5;5;8;1;1;1;0;0;0;1;1;1;0;0;9;3;3;3;3;;5;5;5;8;1;1;0;0;0;1;1;1;0;0;9;3;3;3;3;;;5;5;8;1;1;0;0;0;1;1;1;0;9;3;3;3;3;;;;4;5;5;8;0;0;0;0;0;1;1;0;9;3;3;3;4;;;;;5;5;5;8;8;8;0;0;1;1;1;9;3;3;3;;;;;;;4;5;5;5;5;8;0;1;1;1;9;3;4;;;;;;;;;;5;5;5;5;8;5;5;5;9;;;;;;;;;;;;;;5;5;5;8;5;;;;;;;;
Expand Down
11 changes: 7 additions & 4 deletions Game_RPG_Adventure/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
<button>Look</button>
</div>
<div id="move" style="display:none">
<button onclick="move()">North</button>
<button onclick="move()">East</button>
<button onclick="move()">South</button>
<button onclick="move()">West</button>
<button id="move_north">North</button>
<button id="move_east">East</button>
<button id="move_south">South</button>
<button id="move_west">West</button>
</div>
</body>
<!-- script for moving logic this needs to be after
the buttons otherwise they dont exist -->
<script src="js/player/input.js"></script>
</html>
62 changes: 62 additions & 0 deletions Game_RPG_Adventure/js/player/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// class for the player position
class xy {
constructor(x, y) {
this.x = x;
this.y = y;
}
}

// variable for storing the location of the player
var player_location = new xy(0, 0);

// handler for all the key presses
function keypress_handler(event) {
console.log("Keyboard button pressed", event.keyCode);
}

// handler for the buttons
function move_direction(evt) {
switch (evt.target.direction) {
case 0:
player_location.y += 1;
break;
case 1:
player_location.x += 1;
break;
case 2:
player_location.y -= 1;
break;
case 3:
player_location.x -= 1;
break;
}

console.log(player_location);
}

// for keypresses we can use one of the following listeners
// keydown, keypress, keyup
document.addEventListener("keypress", keypress_handler);

// movement button's
var north_button = document.getElementById("move_north");
var east_button = document.getElementById("move_east");
var south_button = document.getElementById("move_south");
var west_button = document.getElementById("move_west");

// array with all the buttons
var buttons = [north_button, east_button, south_button, west_button];

// set the event listener for all buttons with a button id
for (var i = 0; i < buttons.length; i++) {
if (!buttons[i]) {
// button doesnt exist on the page so dont add a listener
continue;
}

// set the button id of the button
buttons[i].direction = i;

// add the click listener to the button
buttons[i].addEventListener("click", move_direction);
}
Loading