Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
Revert "scaled the cars"
Browse files Browse the repository at this point in the history
This reverts commit 140e2fa.
  • Loading branch information
KamilPawel committed May 18, 2022
1 parent 834d3bb commit 0384e2d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 48 deletions.
5 changes: 2 additions & 3 deletions aimmo-game/simulation/map_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ def get_map(self):
always_empty_location = Location(always_empty_edge_x, always_empty_edge_y)

for cell in shuffled(world_map.all_cells()):
if (
cell.location != always_empty_location
and random.random() < self.settings.get("OBSTACLE_RATIO", 0.1)
if cell.location != always_empty_location and random.random() < self.settings.get(
"OBSTACLE_RATIO", 0.1
):
cell.obstacle = Obstacle.make_obstacle()
# So long as all habitable neighbours can still reach each other, then the
Expand Down
12 changes: 6 additions & 6 deletions game_frontend/src/babylon/assetPacks/ancient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TransformNode,
AbstractMesh,
Scene,
Color4,
Color4
} from 'babylonjs'
import AssetPack from './assetPack'

Expand All @@ -15,12 +15,12 @@ export default class AncientAssetPack extends AssetPack {

backgroundColor = new Color4(0.93, 0.89, 0.82)

constructor(era: string, scene: Scene) {
constructor (era: string, scene: Scene) {
super(era, scene)
this.obstacleMaterial = this.makeObstacleMaterial()
}

async createInteractable(
async createInteractable (
name: string,
type: string,
location: Vector3,
Expand All @@ -39,20 +39,20 @@ export default class AncientAssetPack extends AssetPack {
interactable.position = location
interactable.scaling = new Vector3(0.4, 0.4, 0.4)
interactable.metadata = {
type: type,
type: type
}
return interactable
}

makeObstacleMaterial(): StandardMaterial {
makeObstacleMaterial (): StandardMaterial {
const material = new StandardMaterial(this.obstacleInfo.materialName, this.scene)
material.diffuseTexture = new Texture(this.getTextureURL(1), this.scene)
material.specularColor = new Color3(0, 0, 0)
material.diffuseColor = new Color3(1, 1, 1)
return material
}

async createObstacle(
async createObstacle (
name: string,
location: Vector3,
textureChoice: number,
Expand Down
20 changes: 4 additions & 16 deletions game_frontend/src/babylon/assetPacks/modern.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,17 @@ export default class ModernAssetPack extends AssetPack {
): Promise<AbstractMesh> {
const obstacle = await super.createObstacle(name, location, textureChoice, parent)
obstacle.material = this.obstacleMaterials[textureChoice - 1]
obstacle.rotate(Axis.Y, this.createRandomRotation(obstacle), Space.WORLD)
obstacle.scaling = new Vector3(0.75, 1.3, 0.48)
obstacle.rotate(Axis.Y, this.createRandomRotation(), Space.WORLD)
return obstacle
}

/**
* This function returns a random angle in radians
*
* @return {number} a random angle in radians, in increments of half pi
* @return {number} a random angle in radians, in increments of a quarter
*
*/

createRandomRotation(obstacle: any): number {
const angles = {
0: 0, // 0 degrees
1: Math.PI / 2, // 90 degrees
2: Math.PI, // 180 degrees
3: (3 * Math.PI) / 2, // 270 degrees
}

const getRandomInt = (max) => {
return Math.floor(Math.random() * max)
}
return angles[getRandomInt(4)]
createRandomRotation(): number {
return Math.PI / (Math.floor(Math.random() * Math.floor(4)) + 1)
}
}
20 changes: 10 additions & 10 deletions game_frontend/src/babylon/entities/avatarManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
Vector3,
ShaderMaterial,
Scene,
Color3,
Color3
} from 'babylonjs'
import { Environment } from '../environment/environment'
import { DiffItem } from '../diff'
Expand All @@ -28,7 +28,7 @@ export default class AvatarManager implements GameNode, DiffHandling {
importMesh: Function
shaderMaterial: ShaderMaterial

constructor(environment: Environment, importMesh: Function = SceneLoader.ImportMeshAsync) {
constructor (environment: Environment, importMesh: Function = SceneLoader.ImportMeshAsync) {
this.importMesh = importMesh
this.gameStateProcessor = new DiffProcessor(this)

Expand All @@ -41,7 +41,7 @@ export default class AvatarManager implements GameNode, DiffHandling {
this.setupShaderMaterial()
}

setupMarkerMaterial(): void {
setupMarkerMaterial (): void {
this.markerMaterial = new StandardMaterial('avatar marker', this.scene)
this.markerMaterial.diffuseTexture = new Texture(
'/static/babylon/models/avatar_marker_texture.png',
Expand All @@ -50,14 +50,14 @@ export default class AvatarManager implements GameNode, DiffHandling {
this.markerMaterial.specularColor = new Color3(0, 0, 0)
}

setupShaderMaterial(): void {
setupShaderMaterial (): void {
this.shaderMaterial = new ShaderMaterial(
'Avatar shader',
this.scene,
'/static/babylon/models/toonshader',
{
attributes: ['position', 'normal', 'uv'],
uniforms: ['world', 'worldView', 'worldViewProjection', 'view', 'projection'],
uniforms: ['world', 'worldView', 'worldViewProjection', 'view', 'projection']
}
)
this.shaderMaterial.setTexture(
Expand All @@ -66,14 +66,14 @@ export default class AvatarManager implements GameNode, DiffHandling {
)
}

remove(avatar: DiffItem): void {
remove (avatar: DiffItem): void {
const toDelete = this.avatarNode.getChildMeshes(true, function (node): boolean {
return node.name === `avatar: ${avatar.value.id}`
})
toDelete[0].dispose()
}

async add(avatar: DiffItem) {
async add (avatar: DiffItem) {
const { meshes } = await this.importMesh(
'avatar',
'/static/babylon/models/',
Expand All @@ -95,7 +95,7 @@ export default class AvatarManager implements GameNode, DiffHandling {
}
}

edit(avatar: DiffItem): void {
edit (avatar: DiffItem): void {
const avatarToAnimate = this.avatarNode.getChildMeshes(true, function (node): boolean {
return node.name === `avatar: ${avatar.value.id}`
})[0]
Expand All @@ -117,7 +117,7 @@ export default class AvatarManager implements GameNode, DiffHandling {
setOrientation(walkingAvatar, avatar.value.orientation)
}

async attachMarker(avatarMesh: any) {
async attachMarker (avatarMesh: any) {
const { meshes } = await this.importMesh(
'avatar_marker',
'/static/babylon/models/',
Expand All @@ -133,7 +133,7 @@ export default class AvatarManager implements GameNode, DiffHandling {
marker.position = new Vector3(0, MARKER_HEIGHT, 0)
}

setCurrentAvatarID(avatarID: number) {
setCurrentAvatarID (avatarID: number) {
this.currentAvatarID = avatarID
}
}
8 changes: 4 additions & 4 deletions game_frontend/src/babylon/entities/obstacleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export default class ObstacleManager implements GameNode, DiffHandling {
materials: Array<BABYLON.StandardMaterial>
assetPack: AssetPack

constructor(environment: Environment, assetPack: AssetPack) {
constructor (environment: Environment, assetPack: AssetPack) {
this.assetPack = assetPack
this.gameStateProcessor = new DiffProcessor(this)
this.obstacleNode = new BABYLON.TransformNode('Obstacles', environment.scene)
this.object = this.obstacleNode
this.obstacleNode.parent = environment.onTerrainNode
}

remove(obstacle: DiffItem): void {
remove (obstacle: DiffItem): void {
const index = obstacle.id
const toDelete = this.obstacleNode.getChildMeshes(true, function (node): boolean {
return node.name === `obstacle: ${index}`
Expand All @@ -30,7 +30,7 @@ export default class ObstacleManager implements GameNode, DiffHandling {
}
}

edit(obstacle: DiffItem): void {
edit (obstacle: DiffItem): void {
const toEdit = this.obstacleNode.getChildMeshes(true, function (node): boolean {
return node.name === `obstacle: ${obstacle.id}`
})
Expand All @@ -43,7 +43,7 @@ export default class ObstacleManager implements GameNode, DiffHandling {
}
}

async add(obstacle: DiffItem) {
async add (obstacle: DiffItem) {
await this.assetPack.createObstacle(
`obstacle: ${obstacle.id}`,
new BABYLON.Vector3(obstacle.value.location.x, 0, obstacle.value.location.y),
Expand Down
18 changes: 9 additions & 9 deletions game_frontend/src/babylon/gameEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export default class GameEngine {

panHandler: Function

constructor(handleMapPanned: Function, environment: Environment) {
constructor (handleMapPanned: Function, environment: Environment) {
this.environment = environment
this.panHandler = handleMapPanned
}

onUpdate(previousProps: any, currentProps: any) {
onUpdate (previousProps: any, currentProps: any) {
if (currentProps.gameState) {
if (this.environment.era === '') {
this.environment.era = currentProps.gameState.era
Expand All @@ -33,7 +33,7 @@ export default class GameEngine {
}
}

populateMap(): void {
populateMap (): void {
this.assetPack = getAssetPackForEra(this.environment.era, this.environment.scene)
this.sceneRenderer = new SceneRenderer(this.environment)
this.environmentManager = new EnvironmentManager(this.environment, this.assetPack)
Expand All @@ -43,11 +43,11 @@ export default class GameEngine {
this.addPanListener(this.environment.scene)
}

setCurrentAvatarID(props: any) {
setCurrentAvatarID (props: any) {
this.entities.setCurrentAvatarID(props)
}

centerOn(props: any) {
centerOn (props: any) {
if (props.cameraCenteredOnUserAvatar) {
if (this.entities.avatars.currentAvatarMesh) {
this.environmentManager.centerOn(this.entities.avatars.currentAvatarMesh)
Expand All @@ -59,15 +59,15 @@ export default class GameEngine {
}
}

onUpdateGameState(previousGameState: any, currentGameState: any) {
onUpdateGameState (previousGameState: any, currentGameState: any) {
this.entities.onGameStateUpdate(previousGameState, currentGameState)
}

unmount() {
unmount () {
window.removeEventListener('resize', this.environmentManager.resizeBabylonWindow)
}

addPanListener(scene: BABYLON.Scene) {
addPanListener (scene: BABYLON.Scene) {
scene.onPrePointerObservable.add(
() => {
this.panHandler()
Expand All @@ -78,7 +78,7 @@ export default class GameEngine {
)
}

getAvatarLocation(playerID: number, players: any): BABYLON.Vector3 {
getAvatarLocation (playerID: number, players: any): BABYLON.Vector3 {
for (const player in players) {
if (players[player].id === playerID) {
const location = players[player].location
Expand Down

0 comments on commit 0384e2d

Please sign in to comment.