Skip to content

Commit

Permalink
feat(game) : added ui base for steering
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Jan 22, 2024
1 parent 4f3e52b commit 602536b
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
<title>Mario Kart 3.js</title>
</head>
<body>
<div id="root"></div>
Expand Down
Binary file added public/favicon.ico
Binary file not shown.
Binary file added public/steering_wheel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions src/HUD.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useEffect, useRef } from "react";

export const HUD = () => {
const wheel = useRef();

useEffect(() => {
const handleMouseMove = (e) => {
if (wheel.current) {
const { clientX, clientY } = e;
const screenWidth = window.innerWidth;
const rotation = ((clientX - screenWidth / 2) / screenWidth) * 180;

wheel.current.style.left = `${clientX - 100}px`;
wheel.current.style.top = `${clientY - 100}px`;
wheel.current.style.transform = `rotate(${rotation}deg)`;
}
};

window.addEventListener("mousemove", handleMouseMove);

return () => {
window.removeEventListener("mousemove", handleMouseMove);
};
}, []);

return (
<img
ref={wheel}
src="./steering_wheel.png"
alt="steering wheel"
className="steering-wheel"
style={{ position: 'absolute', pointerEvents: 'none', transformOrigin: 'center' }}
/>
);
};
17 changes: 17 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@
height: 100vh;
}

*
body {
margin: 0;
cursor:none;
overflow-y: none;
overflow-x: none;

}

body::-webkit-scrollbar {
display: none;
}

img {
position:absolute;
z-index: 100;
top:0;
width: 200px;
opacity: 0.2;
}
2 changes: 2 additions & 0 deletions src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
import { HUD } from './HUD'

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
<HUD />
</React.StrictMode>,
)

0 comments on commit 602536b

Please sign in to comment.