This is a racing game for Windows, written in pure JS, converted into an application with Electron js
This repository is a full-fledged little game in the form of a desktop application.
Electron is a framework for building desktop applications using JavaScript, HTML, and CSS. By embedding Chromium and Node.js into its binary, Electron allows you to maintain one JavaScript codebase and create cross-platform apps that work on Windows, macOS, and Linux — no native development experience required..
The main goal of the project was to make a game out of html, css and native js that would easily run on desktops.
- The game is realized in
2D
. - All the necessary photographs of the cars are already in the folder with
images
inpng
format. - There is also music that runs along with the game, which is located in the
audio
folder - Special JSX flags can be used during compile time to optimize runtime performance at application level
- Many micro optimizations
To operate Electron, you need to create a JS file with a name different from the main program code
And write down the next set of commands:
const url = require('url').format({
protocol: 'file',
slashes: true,
pathname: require('path').join(__dirname, 'index.html')
});
Initialize Electron JS, And create a win object:
const {app, BrowserWindow} = require('electron');
let win;
After that, we create a wrapper for our program with a width and a length createWindow () function that loads index.html into a new BrowserWindow instance
function createWindow() {
win = new BrowserWindow({
width: 500,
height: 850
});
win.loadURL(url);
win.on('closed', function() {
win = null;
});
}
On Windows and Linux, exiting all windows will usually close the application completely.
To do this, listen for the app module's 'window-all-closed'
event and call [app.quit ()] [app-quit]
if the user is not using macOS (darwin).
app.on('ready', createWindow);
app.on('window-all-closed', function(){
app.quit();
})
Core package:
npm install
To run the program:
# to run from terminal
npm start
To create a folder with a Windows application with an .exe
extension, enter the following command :
# Creates a folder with a name `racing-game-win32-x64`
electron-packager .