Skip to content

Commit

Permalink
v0.8.1 the minecraft pivot (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderclarktx authored Sep 27, 2024
1 parent ce2933d commit 0684ffe
Show file tree
Hide file tree
Showing 46 changed files with 703 additions and 339 deletions.
219 changes: 113 additions & 106 deletions core/main.ts
Original file line number Diff line number Diff line change
@@ -1,106 +1,113 @@
export * from "./src/runtime/Game";
export * from "./src/runtime/IsometricGame";
export * from "./src/runtime/IsometricWorld";
export * from "./src/runtime/StateBuffer";
export * from "./src/runtime/World";
export * from "./src/graphics/Camera";
export * from "./src/graphics/Renderer";
export * from "./src/ecs/Component";
export * from "./src/ecs/System";
export * from "./src/ecs/Entity";
export * from "./src/ecs/systems/core/ActionSystem";
export * from "./src/ecs/systems/core/CommandSystem";
export * from "./src/ecs/systems/core/ControlSystem";
export * from "./src/ecs/systems/core/CooldownSystem";
export * from "./src/ecs/systems/core/DamageSystem";
export * from "./src/ecs/systems/core/EffectsSystem";
export * from "./src/ecs/systems/core/ExpiresSystem";
export * from "./src/ecs/systems/core/FogSystem";
export * from "./src/ecs/systems/core/NPCSystem";
export * from "./src/ecs/systems/core/PhysicsSystem";
export * from "./src/ecs/systems/core/SightSystem";
export * from "./src/ecs/systems/gameplay/ZomiSpawnSystem";
export * from "./src/ecs/systems/gameplay/GunSystem";
export * from "./src/ecs/systems/gameplay/SkellySpawnSystem";
export * from "./src/ecs/systems/net/NetClientSystem";
export * from "./src/ecs/systems/net/NetServerSystem";
export * from "./src/net/Client";
export * from "./src/net/DelaySyncer";
export * from "./src/net/NetProtocol";
export * from "./src/ecs/systems/ui/ChatBubbleSystem";
export * from "./src/ecs/systems/ui/ClickableSystem";
export * from "./src/ecs/systems/ui/DebugSystem";
export * from "./src/ecs/systems/ui/HealthBarSystem";
export * from "./src/ecs/systems/ui/InputSystem";
export * from "./src/ecs/systems/ui/NametagSystem";
export * from "./src/ecs/systems/ui/RenderSystem";
export * from "./src/ecs/entities/buttons/ConnectButton";
export * from "./src/ecs/entities/buttons/FullscreenButton";
export * from "./src/ecs/entities/buttons/HomeButton";
export * from "./src/ecs/entities/buttons/ShopButton";
export * from "./src/ecs/entities/characters/Skelly";
export * from "./src/ecs/entities/characters/Spaceship";
export * from "./src/ecs/entities/characters/Zomi";
export * from "./src/ecs/entities/players/Noob";
export * from "./src/ecs/entities/SystemEntity";
export * from "./src/ecs/entities/objects/Ball";
export * from "./src/ecs/entities/objects/InviteStone";
export * from "./src/ecs/entities/objects/Goal";
export * from "./src/ecs/entities/objects/Portal";
export * from "./src/ecs/entities/objects/Projectile";
export * from "./src/ecs/entities/terrain/Background";
export * from "./src/ecs/entities/terrain/FloorTiles";
export * from "./src/ecs/entities/terrain/LineWall";
export * from "./src/ecs/entities/ui/HUD";
export * from "./src/ecs/entities/ui/Chat";
export * from "./src/ecs/entities/ui/Cursor";
export * from "./src/ecs/entities/ui/FpsText";
export * from "./src/ecs/entities/ui/Joystick";
export * from "./src/ecs/renderables/Button";
export * from "./src/ecs/renderables/DebugBounds";
export * from "./src/ecs/renderables/HealthBar";
export * from "./src/ecs/entities/ui/Shop";
export * from "./src/ecs/entities/ui/Minimap";
export * from "./src/ecs/entities/ui/Scoreboard";
export * from "./src/ecs/entities/ui/ScorePanel";
export * from "./src/ecs/renderables/TextBox";
export * from "./src/ecs/commands/DebugCommand";
export * from "./src/ecs/commands/GameCommand";
export * from "./src/ecs/commands/SpawnCommand";
export * from "./src/ecs/components/Actions";
export * from "./src/ecs/components/Clickable";
export * from "./src/ecs/components/Collider";
export * from "./src/ecs/components/Effects";
export * from "./src/ecs/components/Data";
export * from "./src/ecs/components/Debug";
export * from "./src/ecs/components/Expires";
export * from "./src/ecs/components/Gun";
export * from "./src/ecs/components/Health";
export * from "./src/ecs/components/Input";
export * from "./src/ecs/components/Networked";
export * from "./src/ecs/components/NPC";
export * from "./src/ecs/components/Player";
export * from "./src/ecs/components/Position";
export * from "./src/ecs/components/Renderable";
export * from "./src/ecs/components/Team";
export * from "./src/ecs/components/Money";
export * from "./src/ecs/actions/abilities/Boost";
export * from "./src/ecs/actions/PlayerActions";
export * from "./src/ecs/actions/ToggleVisible";
export * from "./src/ecs/actions/abilities/IceWall";
export * from "./src/ecs/actions/attacks/Reload";
export * from "./src/ecs/actions/attacks/Shoot";
export * from "./src/ecs/actions/attacks/ZomiAttack";
export * from "./src/ecs/actions/movement/Point";
export * from "./src/ecs/actions/movement/Chase";
export * from "./src/ecs/actions/movement/Head";
export * from "./src/ecs/actions/movement/Move";
export * from "./src/ecs/actions/movement/WASDInputMap";
export * from "./src/ecs/actions/movement/VehicleMovement";
export * from "./src/ecs/components/Controlling";
export * from "./src/sound/Sounds";
export * from "./src/utils/MathUtils";
export * from "./src/utils/PixiUtils";
export * from "./src/utils/RapierUtils";
export * from "./src/utils/StringUtils";
export * from "./src/utils/SystemUtils";
export * from "./src/runtime/Game"
export * from "./src/runtime/IsometricGame"
export * from "./src/runtime/IsometricWorld"
export * from "./src/runtime/StateBuffer"
export * from "./src/runtime/World"
export * from "./src/graphics/Camera"
export * from "./src/graphics/Renderer"
export * from "./src/ecs/Component"
export * from "./src/ecs/System"
export * from "./src/ecs/Entity"
export * from "./src/ecs/systems/core/ActionSystem"
export * from "./src/ecs/systems/core/CommandSystem"
export * from "./src/ecs/systems/core/ControlSystem"
export * from "./src/ecs/systems/core/CooldownSystem"
export * from "./src/ecs/systems/core/DamageSystem"
export * from "./src/ecs/systems/core/EffectsSystem"
export * from "./src/ecs/systems/core/ExpiresSystem"
export * from "./src/ecs/systems/core/FogSystem"
export * from "./src/ecs/systems/core/NPCSystem"
export * from "./src/ecs/systems/core/PhysicsSystem"
export * from "./src/ecs/systems/core/SightSystem"
export * from "./src/ecs/systems/gameplay/ZomiSpawnSystem"
export * from "./src/ecs/systems/gameplay/GunSystem"
export * from "./src/ecs/systems/gameplay/SkellySpawnSystem"
export * from "./src/ecs/systems/net/NetClientSystem"
export * from "./src/ecs/systems/net/NetServerSystem"
export * from "./src/net/Client"
export * from "./src/net/DelaySyncer"
export * from "./src/net/NetProtocol"
export * from "./src/ecs/systems/ui/ChatBubbleSystem"
export * from "./src/ecs/systems/ui/ClickableSystem"
export * from "./src/ecs/systems/ui/DebugSystem"
export * from "./src/ecs/systems/ui/HealthBarSystem"
export * from "./src/ecs/systems/ui/InputSystem"
export * from "./src/ecs/systems/ui/NametagSystem"
export * from "./src/ecs/systems/ui/RenderSystem"
export * from "./src/ecs/entities/buttons/ConnectButton"
export * from "./src/ecs/entities/buttons/FullscreenButton"
export * from "./src/ecs/entities/buttons/HomeButton"
export * from "./src/ecs/entities/buttons/ShopButton"
export * from "./src/ecs/entities/characters/Piggo"
export * from "./src/ecs/entities/characters/Skelly"
export * from "./src/ecs/entities/characters/Spaceship"
export * from "./src/ecs/entities/characters/Zomi"
export * from "./src/ecs/entities/players/Noob"
export * from "./src/ecs/entities/SystemEntity"
export * from "./src/ecs/entities/objects/Ball"
export * from "./src/ecs/entities/objects/InviteStone"
export * from "./src/ecs/entities/objects/Goal"
export * from "./src/ecs/entities/objects/Portal"
export * from "./src/ecs/entities/objects/Projectile"
export * from "./src/ecs/entities/objects/Tree"
export * from "./src/ecs/entities/terrain/Background"
export * from "./src/ecs/entities/terrain/FloorTiles"
export * from "./src/ecs/entities/terrain/LineWall"
export * from "./src/ecs/entities/ui/HUD"
export * from "./src/ecs/entities/ui/Chat"
export * from "./src/ecs/entities/ui/Cursor"
export * from "./src/ecs/entities/ui/FpsText"
export * from "./src/ecs/entities/ui/Joystick"
export * from "./src/ecs/renderables/Button"
export * from "./src/ecs/renderables/DebugBounds"
export * from "./src/ecs/renderables/HealthBar"
export * from "./src/ecs/entities/ui/Shop"
export * from "./src/ecs/entities/ui/Minimap"
export * from "./src/ecs/entities/ui/Scoreboard"
export * from "./src/ecs/entities/ui/ScorePanel"
export * from "./src/ecs/renderables/TextBox"
export * from "./src/ecs/commands/DebugCommand"
export * from "./src/ecs/commands/GameCommand"
export * from "./src/ecs/commands/SpawnCommand"
export * from "./src/ecs/components/Actions"
export * from "./src/ecs/components/Clickable"
export * from "./src/ecs/components/Collider"
export * from "./src/ecs/components/Effects"
export * from "./src/ecs/components/Edible"
export * from "./src/ecs/components/Data"
export * from "./src/ecs/components/Debug"
export * from "./src/ecs/components/Expires"
export * from "./src/ecs/components/Gun"
export * from "./src/ecs/components/Health"
export * from "./src/ecs/components/Input"
export * from "./src/ecs/components/Inventory"
export * from "./src/ecs/components/Name"
export * from "./src/ecs/components/Networked"
export * from "./src/ecs/components/NPC"
export * from "./src/ecs/components/Player"
export * from "./src/ecs/components/Position"
export * from "./src/ecs/components/Renderable"
export * from "./src/ecs/components/Team"
export * from "./src/ecs/components/Money"
export * from "./src/ecs/actions/abilities/Boost"
export * from "./src/ecs/actions/PlayerActions"
export * from "./src/ecs/actions/ToggleVisible"
export * from "./src/ecs/actions/abilities/IceWall"
export * from "./src/ecs/actions/attacks/Reload"
export * from "./src/ecs/actions/attacks/Shoot"
export * from "./src/ecs/actions/attacks/ZomiAttack"
export * from "./src/ecs/actions/movement/Point"
export * from "./src/ecs/actions/movement/Chase"
export * from "./src/ecs/actions/movement/Head"
export * from "./src/ecs/actions/movement/Move"
export * from "./src/ecs/actions/movement/WASDInputMap"
export * from "./src/ecs/actions/movement/VehicleMovement"
export * from "./src/ecs/entities/items/Axe"
export * from "./src/ecs/entities/items/GunItems"
export * from "./src/ecs/components/Controlling"
export * from "./src/sound/Sounds"
export * from "./src/utils/MathUtils"
export * from "./src/utils/PixiUtils"
export * from "./src/utils/RapierUtils"
export * from "./src/utils/StringUtils"
export * from "./src/utils/SystemUtils"
13 changes: 7 additions & 6 deletions core/src/ecs/Component.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import {
Actions, Clickable, Collider, Controlling, Data, Debug,
Effects, Expires, Gun, Health, Input, NPC, Networked,
Player, Position, Renderable, Team, Money, XY, entries, keys
Actions, Clickable, Collider, Controlling, Data, Debug, Name,
Effects, Expires, Gun, Health, Input, NPC, Networked, Player,
Position, Renderable, Team, Money, XY, entries, keys, Inventory,
Edible
} from "@piggo-gg/core";

export type ComponentTypes =
Actions | Clickable | Collider | Controlling |
Data | Debug | Effects | Expires | Health |
Input | Team | Networked | NPC | Player |
Position | Renderable | Gun | Money
Data | Debug | Effects | Expires | Health | Edible |
Input | Team | Networked | NPC | Player | Name |
Position | Renderable | Gun | Money | Inventory

export type NetworkedComponentData = Record<string, boolean | string | number | string[] | number[] | XY>

Expand Down
2 changes: 1 addition & 1 deletion core/src/ecs/Entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const Entity = <T extends ComponentTypes>(protoEntity: ProtoEntity<T>): E
const entity = {
...protoEntity,
extend: (components: ComponentTypes[]) => {
components.forEach((component) => {
components.forEach(component => {
// @ts-expect-error
entity.components[component.type] = component;
});
Expand Down
47 changes: 24 additions & 23 deletions core/src/ecs/actions/attacks/Shoot.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
import { Action, Gun, KeyMouse, PositionProps, Projectile, Team, TeamColors, onHitTeam, playSound, random } from "@piggo-gg/core";
import { Action, Character, Gun, KeyMouse, PositionProps, Projectile, Team, TeamColors, onHitTeam, playSound, random } from "@piggo-gg/core"

export const Shoot = Action<KeyMouse & { id: number }>(({ world, params, entity }) => {
export const Shoot = Action<KeyMouse & { id: number, character: Character }>(({ world, params, entity }) => {

if (!entity) return;
if (!entity) return

const { gun, position, team } = entity.components;
if (!gun || !position || !team) return;
const { position, team } = params.character.components
const { gun } = entity.components
if (!gun || !position || !team) return

if (gun.canShoot(world, params.tick, params.mouse.hold)) {
gun.didShoot(world);
gun.didShoot(world)

const { x, y } = position.data;
const { speed } = gun;
const { x, y } = position.data
const { speed } = gun

// distance to mouse
let dx = params.mouse.x - x;
let dy = params.mouse.y - y;
let dx = params.mouse.x - x
let dy = params.mouse.y - y

// normalize
const hyp = Math.sqrt(dx * dx + dy * dy);
let vx = dx / hyp * speed;
let vy = dy / hyp * speed;
const hyp = Math.sqrt(dx * dx + dy * dy)
let vx = dx / hyp * speed
let vy = dy / hyp * speed

// spawn bullet at offset
const offset = 30;
const Xoffset = offset * (vx / Math.sqrt(vx * vx + vy * vy));
const Yoffset = offset * (vy / Math.sqrt(vx * vx + vy * vy));
const offset = 30
const Xoffset = offset * (vx / Math.sqrt(vx * vx + vy * vy))
const Yoffset = offset * (vy / Math.sqrt(vx * vx + vy * vy))

const pos: PositionProps = { x: x + Xoffset, y: y + Yoffset, velocity: { x: vx, y: vy } };
const pos: PositionProps = { x: x + Xoffset, y: y + Yoffset, velocity: { x: vx, y: vy } }

world.actionBuffer.push(world.tick + 3, entity.id, { action: "spawnBullet", params: { team, gun, ...pos, id: params.id } });
world.actionBuffer.push(world.tick + 3, entity.id, { action: "spawnBullet", params: { team, gun, ...pos, id: params.id } })

playSound(world.client?.sounds[gun.name]);
playSound(world.client?.sounds[gun.name])

// auto reload
if (gun.data.clip === 0) {
const reload = entity.components.actions?.actionMap["reload"];
if (reload) world.actionBuffer.push(world.tick + 1, entity.id, { action: "reload" });
const reload = entity.components.actions?.actionMap["reload"]
if (reload) world.actionBuffer.push(world.tick + 1, entity.id, { action: "reload" })
}
}
})

export const SpawnBullet = Action<PositionProps & { team: Team, gun: Gun, id: number }>(({ world, params }) => {

const { team, gun } = params;
const { team, gun } = params

world.addEntity(Projectile({
id: `projectile-${random()}`,
pos: params,
radius: gun.bulletSize,
color: TeamColors[team.data.team],
onHit: onHitTeam(team.data.team, gun.damage)
}));
}))
})
1 change: 1 addition & 0 deletions core/src/ecs/components/Actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const Action = <T extends {} = {}>(invoke: Action<T>["invoke"], cooldown?
export type InvokedAction<A extends string = string, P extends {} = {}> = {
action: A,
playerId?: string | undefined,
entityId?: string | undefined
params?: P
}

Expand Down
18 changes: 18 additions & 0 deletions core/src/ecs/components/Edible.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Component } from "@piggo-gg/core"

export type Edible = Component<"edible"> & {
data: {
hunger: number
}
}

export type EdibleProps = {
hunger: number
}

export const Edible = (props: EdibleProps): Edible => ({
type: "edible",
data: {
hunger: props.hunger
}
})
4 changes: 2 additions & 2 deletions core/src/ecs/components/Gun.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, World, random, round } from "@piggo-gg/core";
import { Component, World, randomInt } from "@piggo-gg/core";

export type GunNames = "deagle" | "ak" | "awp";

Expand Down Expand Up @@ -37,7 +37,7 @@ export const Gun = (props: GunProps): Gun => {
const gun: Gun = {
type: "gun",
data: {
id: round(random() * 100000),
id: randomInt(100000),
clip: props.clipSize,
ammo: props.ammo
},
Expand Down
2 changes: 1 addition & 1 deletion core/src/ecs/components/Health.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Sound, ValidSounds } from "@piggo-gg/core";
import { Component, ValidSounds } from "@piggo-gg/core";

export type Health = Component<"health", { health: number, maxHealth: number }> & {
showHealthBar: boolean
Expand Down
1 change: 1 addition & 0 deletions core/src/ecs/components/Input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type InputState = {
tick?: number
entity: Entity
world: World
character?: Character
}

export type KeyHandler = (_: InputState) => null | InvokedAction<string, {}>
Expand Down
Loading

0 comments on commit 0684ffe

Please # to comment.