-
Notifications
You must be signed in to change notification settings - Fork 0
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
Projectiles #103
Draft
bananu7
wants to merge
20
commits into
main
Choose a base branch
from
projectiles
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Projectiles #103
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5555b5b
Moved ConeIndicator to a separate file
bananu7 7e45ea3
First experimental display of a projectile
bananu7 83e0ed9
Refactored Projectile into a separate component
bananu7 612ae14
Added parabola equation for projectile paths
bananu7 7301ca1
Read the attack rate from unit's attacker component
bananu7 b14603c
Make Catapult a proper unit and add Trooper with the peasant model fo…
bananu7 e6281f8
Added lerp to target but that doesn't work since the unit doesn't kno…
bananu7 a05e97b
Moved projectiles to be displayed by the board and not individual unit
bananu7 5a96b44
WIP on projectiles
bananu7 5034da5
Added a Projectile type
bananu7 5b9bdfd
Fixed build errors
bananu7 c332a10
Merge branch 'main' into projectiles
bananu7 b371fe3
Added projectile creation code
bananu7 070ac91
Projectiles are now created, sent and displayed
bananu7 c6106e5
Revert two small leftovers
bananu7 0ee7d76
Introduce dual projectile target
bananu7 3c19e66
Changed the projectile calculation to be ftime/ftime left
bananu7 94c7632
Hide projectiles that finished flight
bananu7 522ff00
Bumped three to 0.166.1
bananu7 05d45ff
Change default projectile to be a ball
bananu7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ThreeCache } from '../gfx/ThreeCache' | ||
import * as THREE from 'three'; | ||
|
||
import { UnitAction } from '@bananu7-rts/server/src/types' | ||
|
||
const cache = new ThreeCache(); | ||
|
||
const coneGeometry = new THREE.ConeGeometry(0.5, 2, 8); | ||
export function ConeIndicator(props: {action: UnitAction, smoothing: boolean}) { | ||
// TODO - this will be replaced with animations etc | ||
let indicatorColor = 0xeeeeee; | ||
if (props.action === 'Moving') | ||
indicatorColor = 0x55ff55; | ||
else if (props.action === 'Attacking') | ||
indicatorColor = 0xff5555; | ||
else if (props.action === 'Harvesting') | ||
indicatorColor = 0x5555ff; | ||
// indicate discrepancy between server and us | ||
else if (props.smoothing) | ||
indicatorColor = 0xffff55; | ||
|
||
return ( | ||
<mesh | ||
position={[0, 5, 0]} | ||
rotation={[0, 0, -1.57]} | ||
geometry={coneGeometry} | ||
material={cache.getBasicMaterial(indicatorColor)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { useRef } from 'react' | ||
import { useFrame } from '@react-three/fiber' | ||
import * as THREE from 'three'; | ||
|
||
import { Position } from '@bananu7-rts/server/src/types' | ||
import { ThreeCache } from './ThreeCache' | ||
|
||
const cache = new ThreeCache(); | ||
|
||
export type ProjectileProps = { | ||
position: Position, | ||
target: Position, | ||
attackRate: number, // TODO this is just flight time? | ||
} | ||
|
||
export function Projectile3D(props: ProjectileProps) { | ||
const projectileTarget = new THREE.Vector3(50, 0, 50); | ||
const projectilePosition = new THREE.Vector3(props.position.x, 5, props.position.y); | ||
const projectileRef = useRef<THREE.Mesh>(null); | ||
|
||
const tRef = useRef<number>(0); | ||
|
||
useFrame((s, dt) => { | ||
if(!projectileRef.current) | ||
return; | ||
|
||
const attackRate = props.attackRate; | ||
const range = 20; | ||
const e = tRef.current * (1000/attackRate); | ||
const y = parabolaHeight(range, 10, e); | ||
|
||
if (tRef.current === 0) { | ||
projectileRef.current.position.x = props.position.x | ||
projectileRef.current.position.z = props.position.y; | ||
} | ||
|
||
const startPos = new THREE.Vector3(props.position.x, 0, props.position.y); | ||
const targetPos = new THREE.Vector3(props.target.x, 0, props.target.y); | ||
|
||
projectileRef.current.position.lerpVectors(startPos, targetPos, e); | ||
projectileRef.current.position.y = y; | ||
|
||
tRef.current += dt; | ||
if (tRef.current > attackRate / 1000) | ||
tRef.current = 0; | ||
}); | ||
|
||
return ( | ||
<mesh | ||
ref={projectileRef} | ||
material={cache.getBasicMaterial(0xeeeeee)} | ||
geometry={cache.getCylinderGeometry(1.0)} | ||
/> | ||
); | ||
} | ||
|
||
function parabolaHeight(length: number, height: number, epsilon: number) { | ||
const k = length; | ||
const h = height; | ||
|
||
const x = epsilon * k; | ||
|
||
return 4*h * (x/k - (x*x)/(k*k)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,16 +21,19 @@ import { buildPresenceAndBuildingMaps } from './game/presence.js' | |
|
||
export function newGame(matchId: string, board: Board): Game { | ||
const units = createStartingUnits(2, board); | ||
const startingResources = 1500; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. revert |
||
return { | ||
matchId, | ||
state: {id: 'Lobby'}, | ||
tickNumber: 0, | ||
// TODO factor number of players in creation | ||
// TODO handle disconnect separately from elimination | ||
players: [{resources: 50, stillInGame: true}, {resources: 50, stillInGame: true}], | ||
players: [{resources: startingResources, stillInGame: true}, {resources: startingResources, stillInGame: true}], | ||
board, | ||
units, | ||
projectiles: [], | ||
lastUnitId: units.length, | ||
lastProjectileId: 1, | ||
winCondition: 'BuildingElimination', | ||
} | ||
} | ||
|
@@ -235,6 +238,7 @@ export function tick(dt: Milliseconds, g: Game): UpdatePacket[] { | |
units: unitUpdates, | ||
player: p, | ||
state: g.state, | ||
projectiles: g.projectiles, | ||
} | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
leftover