Skip to content

Commit

Permalink
v0.6.13 minimap improvements (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderclarktx authored Jun 17, 2024
1 parent eaaf8d5 commit d9dcd5b
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 76 deletions.
2 changes: 1 addition & 1 deletion core/src/ecs/components/Gun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const Gun = (props: GunProps): Gun => {

const GunBuilder = (props: GunProps) => () => Gun(props);

export const Pistol = GunBuilder({ name: "pistol", damage: 10, speed: 500, clipSize: 7, reloadTime: 1, fireRate: 30 });
export const Pistol = GunBuilder({ name: "pistol", damage: 10, speed: 500, clipSize: 7, reloadTime: 1, fireRate: 40 });
export const Shotgun = GunBuilder({ name: "shotgun", damage: 20, speed: 150, clipSize: 2, reloadTime: 2, fireRate: 2 });
export const MachineGun = GunBuilder({ name: "machinegun", damage: 5, speed: 300, clipSize: 30, reloadTime: 3, fireRate: 10 });
export const Sniper = GunBuilder({ name: "sniper", damage: 50, speed: 400, clipSize: 1, reloadTime: 2, fireRate: 2 });
16 changes: 8 additions & 8 deletions core/src/ecs/entities/terrain/FloorTiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const FloorTiles = ({ color, tint, rows, cols, position = { x: 0, y: 0 },
}
});

export const FloorTilesArray = (dim: number, tileArray: number[]): Entity => Entity({
export const FloorTilesArray = (dim: number, tileMap: number[]): Entity => Entity({
id: "floorTilesArray",
components: {
position: Position(),
Expand All @@ -77,7 +77,7 @@ export const FloorTilesArray = (dim: number, tileArray: number[]): Entity => Ent
for (let x = 0; x < dim; x++) {
for (let y = 0; y < dim; y++) {

const value = tileArray[x * dim + y];
const value = tileMap[x * dim + y];
let tint = 0x7777aa;

if (value === 0 || value === 10) continue;
Expand All @@ -98,16 +98,16 @@ export const FloorTilesArray = (dim: number, tileArray: number[]): Entity => Ent
}
})

export const FloorCollidersArray = (dim: number, tileArray: number[]): Entity[] => {
export const FloorCollidersArray = (dim: number, tileMap: number[]): Entity[] => {
const entities: Entity[] = [];
for (let x = 0; x < dim; x++) {
for (let y = 0; y < dim; y++) {

const value = tileArray[x * dim + y];
const value9 = tileArray[x * dim + y + 1];
const value5 = tileArray[x * dim + y - 1];
const value7 = tileArray[(x - 1) * dim + y];
const value1 = tileArray[(x + 1) * dim + y];
const value = tileMap[x * dim + y];
const value9 = tileMap[x * dim + y + 1];
const value5 = tileMap[x * dim + y - 1];
const value7 = tileMap[(x - 1) * dim + y];
const value1 = tileMap[(x + 1) * dim + y];

if (value !== 0) continue;

Expand Down
10 changes: 6 additions & 4 deletions core/src/ecs/entities/ui/Minimap.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Entity, Position, Renderable, TeamColors } from "@piggo-gg/core";
import { Container, Graphics } from "pixi.js";

export const Minimap = (dim: number, tileArray: number[]): Entity => {
export const Minimap = (dim: number, tileMap: number[]): Entity => {
const container = new Container();
const tileGraphics = new Graphics({ alpha: 0.9, rotation: Math.PI / 4 });

let scale = 0.5;

const Colors: Record<number, number> = {
37: TeamColors[1],
64: TeamColors[2],
Expand All @@ -26,7 +28,7 @@ export const Minimap = (dim: number, tileArray: number[]): Entity => {

const { position } = entity.components;
if (!position) return;
tileGraphics.position.set(-position.data.x / 5.6 + 5, - position.data.y / 2.8 + 2);
tileGraphics.position.set(-position.data.x / 5.6 * scale + 5, - position.data.y / 2.8 * scale + 2);
},
setContainer: async () => {

Expand All @@ -47,9 +49,9 @@ export const Minimap = (dim: number, tileArray: number[]): Entity => {
playerDot.circle(0, 0, 3).fill({ color: 0x00ff00 });

// draw the tiles
const width = 8;
const width = 8 * scale;
let color = 0xccccff
tileArray.forEach((tile, i) => {
tileMap.forEach((tile, i) => {
if (tile === 0) return;

color = Colors[tile] || 0xccccff;
Expand Down
12 changes: 6 additions & 6 deletions core/src/graphics/Camera.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Renderable, Renderer, XY } from "@piggo-gg/core";
import { Renderable, XY } from "@piggo-gg/core";
import { Application, Container } from "pixi.js";

export type Camera = {
c: Container
add: (r: Renderable) => void
rescaleDelta: (delta: number) => void
moveBy: ({ x, y }: XY) => void
moveTo: ({ x, y }: XY) => void
toWorldCoords: ({ x, y }: XY) => XY
moveBy: (_: XY) => void
moveTo: (_: XY) => void
toWorldCoords: (_: XY) => XY
}

// Camera handles the viewport of the game
export const Camera = (app: Application): Camera => {

const renderables: Set<Renderable> = new Set();
const c: Container = new Container({ sortableChildren: true, zIndex: 0, alpha: 1 });
let scale = 1.4;
let scale = 1.6;

const rescale = () => {
const min = 1;
const min = 1.2;
const max = 2;

if (scale < min) scale = min;
Expand Down
2 changes: 1 addition & 1 deletion docs/piggo-gg-min.js

Large diffs are not rendered by default.

Loading

0 comments on commit d9dcd5b

Please # to comment.