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

Added touchscreen and mouse support #47

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,4 @@ node_modules/
Godino.png
offline-sprite-2x.png
.htaccess
package.json
package-lock.json
bot/
debug.html
js/config-debug.js
bot/
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🦖 T-Rex Run 3D
Play the game here: http://priler.github.io/dino3d/low.html
Alt. version with best quality settings for high-end PCs: http://priler.github.io/dino3d/
Play the game here: https://misheus.github.io/dino3d/low.html
Alt. version with best quality settings for high-end PCs: https://misheus.github.io/dino3d/

# Description
T-Rex Run 3D is a ThreeJS WebGL game made as an experiment.
Expand Down Expand Up @@ -42,6 +42,12 @@ https://trello.com/b/Pt4FSqOi/t-rex-run-3d
- Scores display fixed
- Moving objects stuttering fixed (never use .splice() again :3)

## Development
- Use some webserver to serve this. It wouldn't work if you just open index.html from your filesystem.
- First time run `npm install` to install dependencies.
- Now you can run `npx gulp reload-js` to build js once, `npx gulp reload-css` to build scss once, or `npx gulp` to do those things automatically when you save a file.


## Credits
https://threejs.org/ - WebGL 3D Library
https://ephtracy.github.io/ - Free lightweight 8-bit voxel art editor
Expand Down
794 changes: 473 additions & 321 deletions css/style.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion css/style.min.css

Large diffs are not rendered by default.

4,078 changes: 2,039 additions & 2,039 deletions css/style.scss

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
var
gulp = require("gulp"),
livereload = require("gulp-livereload"),
sass = require("gulp-sass"),
sass = require("gulp-sass")(require("sass")),
autoprefixer = require("gulp-autoprefixer"),
cleancss = require("gulp-clean-css"),
rename = require("gulp-rename"),
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>T-Rex Run 3D</title>

<!-- Custom CSS -->
Expand Down
38 changes: 36 additions & 2 deletions js/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@
// addKey(39, 'right');
// addKey(38, 'up');
addKey(40, 'down'); // down
// addKey(83, 'down'); // s
addKey(83, 'down'); // s
addKey(17, 'down'); // Ctrl

// addKey(87, 'space'); // w
addKey(87, 'space'); // w
addKey(38, 'space'); // up
addKey(32, 'space'); // space

addKey(81, 'debug_speedup'); // q


//keyboard

window.addEventListener('keydown', (e) => {
// console.log(e.keyCode);
setKeyFromKeyCode(e.keyCode, true);
Expand All @@ -97,6 +100,37 @@
window.addEventListener('keyup', (e) => {
setKeyFromKeyCode(e.keyCode, false);
});


//mouse

window.addEventListener('mousedown', (e) => {
// console.log(e.keyCode);
if (e.pageY < document.documentElement.clientHeight/2) setKey('space', true);
else setKey('down', true);
});

window.addEventListener('mouseup', (e) => {
setKey('space', false);
setKey('down', false);
});

//touchscreen

window.addEventListener('touchstart', (e) => {
// console.log(e.keyCode);
if (e.touches[0].pageY < document.documentElement.clientHeight/2) setKey('space', true);
else setKey('down', true);
});

window.addEventListener('touchend', (e) => {
setKey('space', false);
setKey('down', false);
});




}

update() {
Expand Down
2 changes: 1 addition & 1 deletion js/build.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/config-high.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @type {Object}
*/
const config = {
"base_path": "/dino3d/",
"base_path": location.pathname.replace(/[^\/]*\.html$/, ''),
"logs": true,
"debug": false,
"camera": {
Expand Down
2 changes: 1 addition & 1 deletion js/config-low.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @type {Object}
*/
const config = {
"base_path": "/dino3d/",
"base_path": location.pathname.replace(/[^\/]*\.html$/, ''),
"logs": true,
"debug": false,
"camera": {
Expand Down
38 changes: 36 additions & 2 deletions js/src/input_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,18 @@
// addKey(39, 'right');
// addKey(38, 'up');
addKey(40, 'down'); // down
// addKey(83, 'down'); // s
addKey(83, 'down'); // s
addKey(17, 'down'); // Ctrl

// addKey(87, 'space'); // w
addKey(87, 'space'); // w
addKey(38, 'space'); // up
addKey(32, 'space'); // space

addKey(81, 'debug_speedup'); // q


//keyboard

window.addEventListener('keydown', (e) => {
// console.log(e.keyCode);
setKeyFromKeyCode(e.keyCode, true);
Expand All @@ -95,6 +98,37 @@
window.addEventListener('keyup', (e) => {
setKeyFromKeyCode(e.keyCode, false);
});


//mouse

window.addEventListener('mousedown', (e) => {
// console.log(e.keyCode);
if (e.pageY < document.documentElement.clientHeight/2) setKey('space', true);
else setKey('down', true);
});

window.addEventListener('mouseup', (e) => {
setKey('space', false);
setKey('down', false);
});

//touchscreen

window.addEventListener('touchstart', (e) => {
// console.log(e.keyCode);
if (e.touches[0].pageY < document.documentElement.clientHeight/2) setKey('space', true);
else setKey('down', true);
});

window.addEventListener('touchend', (e) => {
setKey('space', false);
setKey('down', false);
});




}

update() {
Expand Down
1 change: 1 addition & 0 deletions low.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<title>T-Rex Run 3D</title>
<meta name="viewport" content="width=device-width, user-scalable=no">

<!-- Custom CSS -->
<link rel="stylesheet" href="css/style.min.css?patch=3x1">
Expand Down
Loading