Skip to content

Commit

Permalink
gameplay tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Sep 25, 2024
1 parent 631c3c9 commit e00c6ba
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 96 deletions.
2 changes: 1 addition & 1 deletion code/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function debugUpdate()
debugCapture = 1;
if (keyWasPressed('KeyQ') && !freeCamMode)
testDrive = !testDrive
if (keyWasPressed('KeyP'))
if (keyWasPressed('KeyU'))
sound_win.play();
if (debug && keyWasPressed('KeyV'))
spawnVehicle(playerVehicle.pos.z-1300)
Expand Down
33 changes: 9 additions & 24 deletions code/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ Features
*/

//devMode = 1
//devMode = debugInfo = 1
//soundVolume = 0
//debugInfo = 1
//debugGenerativeCanvas = 1
//autoPause = 0

Expand Down Expand Up @@ -63,7 +62,7 @@ const drawDistance = 1e3; // how many track segments to draw for scener
const cameraPlayerOffset = vec3(0,680,1050);
const checkpointTrackSegments = testQuick?1e3:4500;
const checkpointDistance = checkpointTrackSegments*trackSegmentLength;
const startCheckpointTime = 50;
const startCheckpointTime = 45;
const extraCheckpointTime = 40;
const levelLerpRange = .1;
const levelGoal = 10;
Expand Down Expand Up @@ -102,10 +101,14 @@ function gameInit()
mainContext = mainCanvas.getContext('2d');

const styleCanvas = 'position:absolute;' + // position
'top:50%;left:50%;transform:translate(-50%,-50%);' + // center
(clampAspectRatios?'top:50%;left:50%;transform:translate(-50%,-50%);':'') + // center
(pixelate?' image-rendering: pixelated':''); // pixelated

glCanvas.style.cssText = mainCanvas.style.cssText = styleCanvas;

if (!clampAspectRatios)
document.body.style.margin = '0px';

drawInit();
inputInit()
initGenerative();
Expand All @@ -120,7 +123,7 @@ function gameStart()
time = frame = frameTimeLastMS = averageFPS = frameTimeBufferMS =
cameraOffset = checkpointTimeLeft = raceTime = playerLevel = playerWin = playerNewDistanceRecord = playerNewRecord = freeRide = checkpointSoundCount = 0;
startCountdown = quickStart || testLevel ? 0 : 4;
worldHeading = titleScreenMode ? rand(7) : .9;
worldHeading = titleScreenMode ? rand(7) : .8;
checkpointTimeLeft = startCheckpointTime;
nextCheckpointDistance = checkpointDistance;
startCountdownTimer = new Timer;
Expand Down Expand Up @@ -250,25 +253,7 @@ function gameUpdateInternal()
}
}
}

// spawn in more vehicles
const playerIsSlow = titleScreenMode || playerVehicle.velocity.z < 20;
const trafficPosOffset = playerIsSlow? 0 : 18e4; // check in front/behind
const trafficLevel = (playerVehicle.pos.z+trafficPosOffset)/checkpointDistance;
const trafficLevelInfo = getLevelInfo(trafficLevel);
const trafficDensity = trafficLevelInfo.trafficDensity;
const maxVehicleCount = 10*trafficDensity;
if (trafficDensity)
if (vehicles.length<maxVehicleCount && !gameOverTimer.isSet() && !vehicleSpawnTimer.active())
{
const spawnOffset = playerIsSlow ? -1300 : rand(5e4,6e4);
spawnVehicle(playerVehicle.pos.z + spawnOffset);
vehicleSpawnTimer.set(rand(1,2)/trafficDensity);
}

for(const v of vehicles)
v.update();
vehicles = vehicles.filter(o=>!o.destroyed);
updateCars();
}

function gameUpdate(frameTimeMS=0)
Expand Down
2 changes: 1 addition & 1 deletion code/generative.js
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ function generateTetures()
}
else
{
// city building
// y flippable city building
color(BLACK);
for(let i=19; i--;)
{
Expand Down
2 changes: 1 addition & 1 deletion code/hud.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function drawHUD()

if (debugInfo&&!titleScreenMode) // mph
{
const mph = playerVehicle.velocity.z>>1;
const mph = playerVehicle.velocity.z|0;
const mphPos = vec3(.01,.95);
drawHUDText(mph+' MPH', mphPos, .08, undefined,undefined,'left',900,'italic');
}
Expand Down
23 changes: 13 additions & 10 deletions code/input.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const gamepadsEnable = enhancedMode;
const gamepadDirectionEmulateStick = 1;
const inputWASDEmulateDirection = enhancedMode;
const allowTouch = enhancedMode;
const isTouchDevice = allowTouch && window.ontouchstart !== undefined;
Expand All @@ -11,23 +10,23 @@ const touchGamepadAlpha = .3;
///////////////////////////////////////////////////////////////////////////////
// Input user functions

const keyIsDown = (key) => inputData[key] & 1;
const keyWasPressed = (key) => inputData[key] & 2 ? 1 : 0;
const keyIsDown = (key) => inputData[key] & 1;
const keyWasPressed = (key) => inputData[key] & 2 ? 1 : 0;
const keyWasReleased = (key) => inputData[key] & 4 ? 1 : 0;
const clearInput = () => inputData = [];

let mousePos = vec3();
const mouseIsDown = keyIsDown;
const mouseWasPressed = keyWasPressed;
let mousePos;
const mouseIsDown = keyIsDown;
const mouseWasPressed = keyWasPressed;
const mouseWasReleased = keyWasReleased;

let isUsingGamepad;
const gamepadIsDown = (key, gamepad=0) => !!(gamepadData[gamepad][key] & 1);
const gamepadWasPressed = (key, gamepad=0) => !!(gamepadData[gamepad][key] & 2);
const gamepadIsDown = (key, gamepad=0) => !!(gamepadData[gamepad][key] & 1);
const gamepadWasPressed = (key, gamepad=0) => !!(gamepadData[gamepad][key] & 2);
const gamepadWasReleased = (key, gamepad=0) => !!(gamepadData[gamepad][key] & 4);
const gamepadStick = (stick, gamepad=0) =>
const gamepadStick = (stick, gamepad=0) =>
gamepadStickData[gamepad] ? gamepadStickData[gamepad][stick] || vec3() : vec3();
const gamepadGetValue = (key, gamepad=0) => gamepadDataValues[gamepad][key];
const gamepadGetValue = (key, gamepad=0) => gamepadDataValues[gamepad][key];

///////////////////////////////////////////////////////////////////////////////
// Input event handlers
Expand All @@ -36,6 +35,9 @@ let inputData = []; // track what keys are down

function inputInit()
{
if (!js13kBuildLevel2)
mousePos = vec3();

if (gamepadsEnable)
{
gamepadData = [];
Expand Down Expand Up @@ -177,6 +179,7 @@ function gamepadsUpdate()
isUsingGamepad ||= !i && button.pressed;
}

const gamepadDirectionEmulateStick = 1;
if (gamepadDirectionEmulateStick)
{
// copy dpad to left analog stick when pressed
Expand Down
48 changes: 29 additions & 19 deletions code/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function initLevelInfos()
LI.horizonSpriteSize = .5;
//LI.tunnel = trackSprites.tunnel2; // test tunnel
LI.billboardChance = .3 // more billboards at start
LI.trafficDensity = .7; // less traffic start

// mostly straight with few well defined turns or bumps
LI.turnChance = .6;
Expand Down Expand Up @@ -58,7 +59,7 @@ function initLevelInfos()
LI.bumpFreqMin = .4;
//LI.bumpFreqMax = .7;
//LI.bumpScaleMin = 50;
LI.bumpScaleMax = 120;
LI.bumpScaleMax = 140;

// Level 3 - desert -
// has long straight thin roads and tunnel
Expand Down Expand Up @@ -199,7 +200,7 @@ function initLevelInfos()
LI.bumpFreqMin = .3;
LI.bumpFreqMax = .6;
LI.bumpScaleMin = 80;
LI.bumpScaleMax = 160;
LI.bumpScaleMax = 200;

// Level 7 - graveyard -
LI = new LevelInfo(level++, [
Expand All @@ -226,12 +227,10 @@ function initLevelInfos()

// thin road over hills in graveyard
//LI.turnChance = .5;
LI.turnMin = .1;
LI.turnMax = .7;
LI.bumpChance = .7;
LI.bumpFreqMin = .3;
LI.bumpFreqMax = .7;
LI.bumpScaleMin = 100;
LI.turnMax = .6;
LI.bumpChance = .6;
LI.bumpFreqMin = LI.bumpFreqMax = .7;
LI.bumpScaleMin = 80;
//LI.bumpScaleMax = 150;

// Level 8 - jungle - dirt road, many trees
Expand Down Expand Up @@ -267,9 +266,9 @@ function initLevelInfos()
LI.turnMax = .3; // lots of slight turns
LI.bumpChance = 1;
LI.bumpFreqMin = .4;
LI.bumpFreqMax = .8;
LI.bumpFreqMax = .6;
LI.bumpScaleMin = 10;
LI.bumpScaleMax = 60;
LI.bumpScaleMax = 80;

// Level 9 - strange area
LI = new LevelInfo(level++, [
Expand Down Expand Up @@ -297,7 +296,7 @@ function initLevelInfos()
LI.bumpFreqMin = .5;
LI.bumpFreqMax = .9;
LI.bumpScaleMin = 100;
//LI.bumpScaleMax = 150;
LI.bumpScaleMax = 200;

// Level 10 - mountains - hilly, rocks on sides
LI = new LevelInfo(level++, [
Expand All @@ -306,22 +305,27 @@ function initLevelInfos()
trackSprites.grass_flower1,
trackSprites.rock_huge2,
trackSprites.rock_huge,
], trackSprites.tree_pink, trackSprites.horizon_mountains);
], trackSprites.tree_pink);
LI.trackSideRate = 21;
LI.skyColorTop = hsl(.2,1,.9);
LI.skyColorBottom = hsl(.55,1,.5);
LI.roadColor = hsl(0,0,.1);
LI.groundColor = hsl(.1,.5,.7);
LI.cloudColor = hsl(0,0,1,.5);
LI.tunnel = trackSprites.tunnel1;
LI.sunHeight = .6;
LI.horizonSpriteSize = .5;
if (js13kBuildLevel2)
LI.horizonSpriteSize = 0;
else
{
LI.sunHeight = .6;
LI.horizonSprite = trackSprites.horizon_mountains
LI.horizonSpriteSize = .5;
}

// mountains, most difficult level
LI.turnChance = .8;
//LI.turnMin = 0;
LI.turnMax = 1;
LI.bumpChance = 1;
LI.turnMax = LI.bumpChance = 1;
LI.bumpFreqMin = .3;
LI.bumpFreqMax = .9;
//LI.bumpScaleMin = 50;
Expand All @@ -335,15 +339,21 @@ function initLevelInfos()
trackSprites.grass_plain,
trackSprites.tree_oak,
trackSprites.tree_bush,
], trackSprites.tree_oak, trackSprites.horizon_mountains);
], trackSprites.tree_oak);
LI.sceneryListBias = 1;
LI.groundColor = hsl(.2,.3,.5);
LI.trackSideRate = LI.billboardChance = 0;
LI.bumpScaleMin = 1e3; // hill in the distance

// match settings to previous level
LI.sunHeight = .6;
LI.horizonSpriteSize = .5;
if (js13kBuildLevel2)
LI.horizonSpriteSize = 0;
else
{
LI.sunHeight = .6;
LI.horizonSprite = trackSprites.horizon_mountains
LI.horizonSpriteSize = .5;
}
}

const getLevelInfo = (level) => testLevelInfo || levelInfoList[level|0] || levelInfoList[0];
Expand Down
13 changes: 8 additions & 5 deletions code/trackGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function initTrackSprites()
trackSprites.telephonePole = new TrackSprite(vec3(0,4),1800,0,0,.03,0);
//trackSprites.parts_girder = new TrackSprite(vec3(0,6),500,0,.05,30,0);
trackSprites.telephonePole.shadowScale = .3;
trackSprites.grave_stone = new TrackSprite(vec3(2,6),500,.4,.05,.5,0);
trackSprites.grave_stone = new TrackSprite(vec3(2,6),500,.3,.05,.5,0);
trackSprites.grave_stone.lightnessRandomness = .5;
trackSprites.light_tunnel = new TrackSprite(vec3(0,0),200,0,0,0,0);
trackSprites.light_tunnel.shadowScale = 0;
Expand All @@ -149,9 +149,6 @@ function initTrackSprites()
trackSprites.horizon_city.lightnessRandomness = .15;
trackSprites.horizon_city.colorHSL = vec3(1); // vary color

trackSprites.horizon_mountains = new TrackSprite(vec3(7,6));
trackSprites.horizon_mountains.colorHSL = vec3(0, 0, .7);
trackSprites.horizon_mountains.canMirror = 0;
trackSprites.horizon_islands = new TrackSprite(vec3(7,6));
trackSprites.horizon_islands.colorHSL = vec3(.25, .5, .6);
trackSprites.horizon_islands.canMirror = 0;
Expand All @@ -176,6 +173,12 @@ function initTrackSprites()
trackSprites.horizon_weird = new TrackSprite(vec3(7,6));
trackSprites.horizon_weird.colorHSL = vec3(.7, .5, .6);
trackSprites.horizon_weird.canMirror = 0;
if (!js13kBuildLevel2)
{
trackSprites.horizon_mountains = new TrackSprite(vec3(7,6));
trackSprites.horizon_mountains.colorHSL = vec3(0, 0, .7);
trackSprites.horizon_mountains.canMirror = 0;
}
}

// a sprite that can be placed on the track
Expand Down Expand Up @@ -483,7 +486,7 @@ function buildTrack()

//turn = .5; height = 0;
//turn = Math.sin(i/100)*.7;
//height = noise1D(i/29)*-1700;turn =0; // jumps test
//height = noise1D((i-50)/99)*2700;turn =0; // jumps test

// create track segment
const o = vec3(turn, height, i*trackSegmentLength);
Expand Down
Loading

0 comments on commit e00c6ba

Please sign in to comment.