Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CSE493F-FinalProject
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Leanna Mi Nguyen
CSE493F-FinalProject
Commits
5992cab7
Commit
5992cab7
authored
9 months ago
by
Greatroot
Browse files
Options
Downloads
Patches
Plain Diff
Integrate Wu and my movement logic with Leannas character sprite rendering fix.
parent
d86b122d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gamejs/game.js
+72
-23
72 additions, 23 deletions
gamejs/game.js
with
72 additions
and
23 deletions
gamejs/game.js
+
72
−
23
View file @
5992cab7
...
...
@@ -193,8 +193,8 @@ function Game() {
}
// Variables to store the current position of the character
let
characterX
=
0
;
let
characterY
=
0
;
let
characterX
=
startingTileIndex
.
x
;
let
characterY
=
startingTileIndex
.
y
;
let
lastKeyPressTime
=
0
;
let
keyPressInterval
=
200
;
// Adjust this value to change the movement speed
...
...
@@ -218,21 +218,24 @@ function Game() {
y
:
mouseY
});
let
newCharacterX
=
characterX
;
let
newCharacterY
=
characterY
;
// Move the character based on WASD keys
if
(
keyIsDown
(
65
)
&&
millis
()
-
lastKeyPressTime
>
keyPressInterval
)
{
// 'A' key
c
haracterX
=
constrain
(
characterX
-
1
,
0
,
tile_arr_size
-
1
);
newC
haracterX
=
constrain
(
characterX
-
1
,
0
,
tile_arr_size
-
1
);
direction
=
2
;
// left
lastKeyPressTime
=
millis
();
}
else
if
(
keyIsDown
(
68
)
&&
millis
()
-
lastKeyPressTime
>
keyPressInterval
)
{
// 'D' key
c
haracterX
=
constrain
(
characterX
+
1
,
0
,
tile_arr_size
-
1
);
newC
haracterX
=
constrain
(
characterX
+
1
,
0
,
tile_arr_size
-
1
);
direction
=
3
;
// right
lastKeyPressTime
=
millis
();
}
else
if
(
keyIsDown
(
87
)
&&
millis
()
-
lastKeyPressTime
>
keyPressInterval
)
{
// 'W' key
c
haracterY
=
constrain
(
characterY
-
1
,
0
,
tile_arr_size
-
1
);
newC
haracterY
=
constrain
(
characterY
-
1
,
0
,
tile_arr_size
-
1
);
direction
=
1
;
// backward
lastKeyPressTime
=
millis
();
}
else
if
(
keyIsDown
(
83
)
&&
millis
()
-
lastKeyPressTime
>
keyPressInterval
)
{
// 'S' key
c
haracterY
=
constrain
(
characterY
+
1
,
0
,
tile_arr_size
-
1
);
newC
haracterY
=
constrain
(
characterY
+
1
,
0
,
tile_arr_size
-
1
);
direction
=
0
;
// forward
lastKeyPressTime
=
millis
();
}
...
...
@@ -251,6 +254,13 @@ function Game() {
}
}
// Check to make sure that the new position of the character does not
// violate game rules (e.g. character cannot go onto broken sidewalk tiles)
if
(
movementIsValid
(
characterX
,
characterY
,
newCharacterX
,
newCharacterY
))
{
characterX
=
newCharacterX
;
characterY
=
newCharacterY
;
}
// Second loop: display the character
let
tsc
=
tileArr
[
characterX
][
characterY
];
...
...
@@ -301,6 +311,44 @@ function Game() {
// pop();
}
function
movementIsValid
(
prevX
,
prevY
,
nextX
,
nextY
)
{
/*
Checks to see if the character moving from (prevX, prevY) to (nextX, nextY)
is valid for the wheelchair character to move to
*/
// Check to make sure that the new coords are valid, if not, then don't
// allow the player to move to that tile
let
tileType_playerIsOn
=
tileArr
[
prevX
][
prevY
].
type
;
let
tileType_nextTile
=
tileArr
[
nextX
][
nextY
].
type
;
// check redundancy later here
if
(
tileType_nextTile
==
"
road
"
&&
tileType_playerIsOn
==
"
sidewalk_corner_curbRamp
"
)
{
return
true
;
}
if
(
tileType_nextTile
==
"
sidewalk_corner_curbRamp
"
&&
tileType_playerIsOn
==
"
road
"
)
{
return
true
;
}
if
(
tileType_nextTile
==
"
road
"
&&
tileType_playerIsOn
==
"
road
"
)
{
return
true
;
}
if
(
tileType_nextTile
==
"
sidewalk_corner_curbRamp
"
)
{
return
true
;
}
// I think we only want to walk on sidwalk no?
if
(
tileType_playerIsOn
!=
"
road
"
&&
(
tileType_nextTile
==
"
sidewalk
"
||
tileType_nextTile
==
"
sidewalk_corner
"
))
{
return
true
;
}
// If we got here, then the movement is not allowed
return
false
;
}
this
.
mouseClicked
=
function
()
{
let
{
x
:
tgc_x
,
...
...
@@ -366,21 +414,22 @@ function Game() {
// this.keyPressed = function() {
// if (key === 'r') {
// tileArr = rotateMatrixClockwise(tileArr);
// }
this
.
keyPressed
=
function
()
{
// FUTURE FEATURE: rotation
// if (key === 'r') {
// tileArr = rotateMatrixClockwise(tileArr);
// }
//
if (key === 't') {
//
// Cycle to the next tool in our tools array (and wrap back around if
//
// we have reached the end of our tools array)
//
currentToolIndex = (currentToolIndex + 1) % tools.length;
if
(
key
===
'
t
'
)
{
// Cycle to the next tool in our tools array (and wrap back around if
// we have reached the end of our tools array)
currentToolIndex
=
(
currentToolIndex
+
1
)
%
tools
.
length
;
//
// TODO: Change the cursor to an image that matches the current tool
//
// type can either be predefined image or path to image
//
// cursor(type, x, y)
//
}
//
}
// TODO: Change the cursor to an image that matches the current tool
// type can either be predefined image or path to image
// cursor(type, x, y)
}
}
// this.keyReleased = function() {
...
...
@@ -399,10 +448,10 @@ function Game() {
// playerSprite_newTcgCords_x += 1;
// }
//
// Check to make sure that the new coords are valid, if not, then don't
//
// allow the player to move to that tile
//
let tileType_playerIsOn = tileArr[playerSprite_curTgc.x][playerSprite_curTgc.y].type;
//
let tileType_nextTile = tileArr[playerSprite_newTcgCords_x][playerSprite_newTcgCords_y].type;
//
// Check to make sure that the new coords are valid, if not, then don't
//
// allow the player to move to that tile
//
let tileType_playerIsOn = tileArr[playerSprite_curTgc.x][playerSprite_curTgc.y].type;
//
let tileType_nextTile = tileArr[playerSprite_newTcgCords_x][playerSprite_newTcgCords_y].type;
// // console.log(`\nCurrent tile: ${tileType_playerIsOn}`);
// // console.log(`Next tile: ${tileType_nextTile}`);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment