Projectiles, angles

This commit is contained in:
Martin 2022-12-15 11:14:35 +01:00
parent d989ead748
commit 9c3299ebfe
15 changed files with 2779 additions and 1870 deletions

View File

@ -139,7 +139,7 @@
"fileId": "cfXyVJoitMGp/0liEUZfNP"
},
{
"__type__": "cc.CircleCollider2D",
"__type__": "7a536G2OudFtpTsoF8yLXiW",
"_name": "",
"_objFlags": 0,
"node": {
@ -149,35 +149,6 @@
"__prefab": {
"__id__": 7
},
"tag": 0,
"_group": 16,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_radius": 14,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "75WVRoLrtKLrJihCVsxa4D"
},
{
"__type__": "7a536G2OudFtpTsoF8yLXiW",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": false,
"__prefab": {
"__id__": 9
},
"_id": ""
},
{
@ -193,7 +164,7 @@
},
"_enabled": false,
"__prefab": {
"__id__": 11
"__id__": 9
},
"playOnLoad": true,
"_clips": [
@ -212,6 +183,39 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "3ag4rexLNJW6A/sp6OpwZ8"
},
{
"__type__": "cc.BoxCollider2D",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 11
},
"tag": 0,
"_group": 1,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 1.1,
"y": 0
},
"_size": {
"__type__": "cc.Size",
"width": 18,
"height": 18
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "b5zZIKDzhK3q3Rd8OiKUPa"
},
{
"__type__": "cc.PrefabInfo",
"root": {

View File

@ -139,7 +139,7 @@
"fileId": "cfXyVJoitMGp/0liEUZfNP"
},
{
"__type__": "cc.CircleCollider2D",
"__type__": "7a536G2OudFtpTsoF8yLXiW",
"_name": "",
"_objFlags": 0,
"node": {
@ -149,35 +149,6 @@
"__prefab": {
"__id__": 7
},
"tag": 0,
"_group": 16,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_radius": 12,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "75WVRoLrtKLrJihCVsxa4D"
},
{
"__type__": "7a536G2OudFtpTsoF8yLXiW",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": false,
"__prefab": {
"__id__": 9
},
"_id": ""
},
{
@ -193,7 +164,7 @@
},
"_enabled": true,
"__prefab": {
"__id__": 11
"__id__": 9
},
"playOnLoad": true,
"_clips": [
@ -212,6 +183,39 @@
"__type__": "cc.CompPrefabInfo",
"fileId": "3ag4rexLNJW6A/sp6OpwZ8"
},
{
"__type__": "cc.BoxCollider2D",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 11
},
"tag": 0,
"_group": 1,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_size": {
"__type__": "cc.Size",
"width": 9,
"height": 14
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "67joCa7ptP34A+uWLWHsEf"
},
{
"__type__": "cc.PrefabInfo",
"root": {

View File

@ -160,7 +160,7 @@
"x": 0,
"y": 0
},
"_radius": 12,
"_radius": 6,
"_id": ""
},
{

View File

@ -160,7 +160,7 @@
"x": 0,
"y": 0
},
"_radius": 12,
"_radius": 6,
"_id": ""
},
{

View File

@ -160,7 +160,7 @@
"x": 0,
"y": 0
},
"_radius": 12,
"_radius": 6,
"_id": ""
},
{

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
{
"ver": "1.1.40",
"importer": "prefab",
"imported": true,
"uuid": "27c97ec7-9bb8-4e4e-a264-ce49f2ae9843",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "Player"
}
}

View File

@ -77,8 +77,8 @@
},
"_contentSize": {
"__type__": "cc.Size",
"width": 15,
"height": 15
"width": 8,
"height": 4
},
"_anchorPoint": {
"__type__": "cc.Vec2",
@ -113,7 +113,7 @@
"a": 255
},
"_spriteFrame": {
"__uuid__": "9bebe8fc-7ccd-4376-a6ff-f9e471b40fcb@f9941",
"__uuid__": "1ed8c850-646c-4883-97ae-022e97a5e58e@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
@ -136,7 +136,7 @@
"fileId": "46qOXlbU5GmbOpfjiX4jGV"
},
{
"__type__": "cc.CircleCollider2D",
"__type__": "6a24eYAhmtMDZo5Wb8iLC5Q",
"_name": "",
"_objFlags": 0,
"node": {
@ -146,6 +146,26 @@
"__prefab": {
"__id__": 7
},
"collider": {
"__id__": 8
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "a81ki8NjhA4KniWAiobzy2"
},
{
"__type__": "cc.BoxCollider2D",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 9
},
"tag": 0,
"_group": 32,
"_density": 1,
@ -157,32 +177,16 @@
"x": 0,
"y": 0
},
"_radius": 13,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "7cR5oa68RG/oqkiwJ9HQ3X"
},
{
"__type__": "6a24eYAhmtMDZo5Wb8iLC5Q",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 9
},
"collider": {
"__id__": 6
"_size": {
"__type__": "cc.Size",
"width": 8,
"height": 4
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "a81ki8NjhA4KniWAiobzy2"
"fileId": "62/HqD70FPyKT1OoTRCuXS"
},
{
"__type__": "cc.PrefabInfo",

File diff suppressed because it is too large Load Diff

View File

@ -24,11 +24,11 @@
"_active": true,
"_components": [],
"_prefab": {
"__id__": 25
"__id__": 33
},
"autoReleaseAssets": false,
"_globals": {
"__id__": 26
"__id__": 34
},
"_id": "1a3bccb5-bbb7-4058-846c-ed41b52415b0"
},
@ -153,21 +153,24 @@
},
{
"__id__": 13
},
{
"__id__": 21
}
],
"_active": true,
"_components": [
{
"__id__": 21
"__id__": 29
},
{
"__id__": 22
"__id__": 30
},
{
"__id__": 23
"__id__": 31
},
{
"__id__": 24
"__id__": 32
}
],
"_prefab": null,
@ -579,6 +582,300 @@
"__prefab": null,
"_id": "8d2ldk4JNJYKGBH48A9kCb"
},
{
"__type__": "cc.Node",
"_name": "UpgradesBtn",
"_objFlags": 0,
"_parent": {
"__id__": 10
},
"_children": [
{
"__id__": 22
}
],
"_active": true,
"_components": [
{
"__id__": 25
},
{
"__id__": 26
},
{
"__id__": 27
},
{
"__id__": 28
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": -47,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "68jGDMx3tIYp00FOQuFhUE"
},
{
"__type__": "cc.Node",
"_name": "Label",
"_objFlags": 512,
"_parent": {
"__id__": 21
},
"_children": [],
"_active": true,
"_components": [
{
"__id__": 23
},
{
"__id__": 24
}
],
"_prefab": null,
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": "14tp79FO5HlbxUE2NXOcEF"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 22
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "f25nqGTehMw4pL7uv4uOnM"
},
{
"__type__": "cc.Label",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 22
},
"_enabled": true,
"__prefab": null,
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 0,
"g": 0,
"b": 0,
"a": 255
},
"_string": "Upgrade",
"_horizontalAlign": 1,
"_verticalAlign": 1,
"_actualFontSize": 20,
"_fontSize": 20,
"_fontFamily": "Arial",
"_lineHeight": 40,
"_overflow": 1,
"_enableWrapText": false,
"_font": null,
"_isSystemFontUsed": true,
"_spacingX": 0,
"_isItalic": false,
"_isBold": false,
"_isUnderline": false,
"_underlineHeight": 2,
"_cacheMode": 0,
"_id": "a6pM9EFa1JnoBLTshXcD+3"
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 21
},
"_enabled": true,
"__prefab": null,
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 40
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": "1e3MN6eWxEvZYrv/QH5yMz"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 21
},
"_enabled": true,
"__prefab": null,
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "20835ba4-6145-4fbc-a58a-051ce700aa3e@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 1,
"_fillType": 0,
"_sizeMode": 0,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": "7dz1lVaZdKjK3xB06aSZWO"
},
{
"__type__": "cc.Button",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 21
},
"_enabled": true,
"__prefab": null,
"clickEvents": [],
"_interactable": true,
"_transition": 2,
"_normalColor": {
"__type__": "cc.Color",
"r": 214,
"g": 214,
"b": 214,
"a": 255
},
"_hoverColor": {
"__type__": "cc.Color",
"r": 211,
"g": 211,
"b": 211,
"a": 255
},
"_pressedColor": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_disabledColor": {
"__type__": "cc.Color",
"r": 124,
"g": 124,
"b": 124,
"a": 255
},
"_normalSprite": {
"__uuid__": "20835ba4-6145-4fbc-a58a-051ce700aa3e@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_hoverSprite": {
"__uuid__": "20835ba4-6145-4fbc-a58a-051ce700aa3e@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_pressedSprite": {
"__uuid__": "544e49d6-3f05-4fa8-9a9e-091f98fc2ce8@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_disabledSprite": {
"__uuid__": "951249e0-9f16-456d-8b85-a6ca954da16b@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_duration": 0.1,
"_zoomScale": 1.2,
"_target": {
"__id__": 21
},
"_id": "02km9/CjtM4LntV5ZcaVeR"
},
{
"__type__": "55e5f5nQ8dHiL5fPWjgdXbH",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 21
},
"_enabled": true,
"__prefab": null,
"_id": "17dRwdDH1DH7KDpkjt3c0f"
},
{
"__type__": "cc.UITransform",
"_name": "",
@ -656,6 +953,9 @@
"playBtn": {
"__id__": 20
},
"upgradeBtn": {
"__id__": 28
},
"_id": "12ZDz/3H9Ff76Ay4iDl43K"
},
{
@ -670,19 +970,19 @@
{
"__type__": "cc.SceneGlobals",
"ambient": {
"__id__": 27
"__id__": 35
},
"shadows": {
"__id__": 28
"__id__": 36
},
"_skybox": {
"__id__": 29
"__id__": 37
},
"fog": {
"__id__": 30
"__id__": 38
},
"octree": {
"__id__": 31
"__id__": 39
}
},
{

View File

@ -1,4 +1,4 @@
import { CircleCollider2D, Collider2D, Component, Contact2DType, _decorator } from "cc";
import { Collider2D, Component, Contact2DType, Vec3, _decorator } from "cc";
import { ISignal } from "../../Services/EventSystem/ISignal";
import { Signal } from "../../Services/EventSystem/Signal";
import { ProjectileCollision } from "./ProjectileCollision";
@ -6,7 +6,7 @@ const { ccclass, property } = _decorator;
@ccclass("Projectile")
export class Projectile extends Component {
@property(CircleCollider2D) private collider: CircleCollider2D;
@property(Collider2D) private collider: Collider2D;
private contactBeginEvent = new Signal<ProjectileCollision>();
private piercesDepletedEvent = new Signal<Projectile>();
@ -15,7 +15,7 @@ export class Projectile extends Component {
private piercesLeft = 0;
private damage = 0;
public init(damage: number, pierces: number): void {
public init(damage: number, pierces: number, angle: number): void {
this.piercesLeft = pierces;
this.damage = damage;
@ -23,6 +23,8 @@ export class Projectile extends Component {
this.isContactListenerSet = true;
this.collider.on(Contact2DType.BEGIN_CONTACT, this.onColliderContactBegin, this);
}
this.node.setRotationFromEuler(new Vec3(0, 0, angle));
}
public pierce(): void {

View File

@ -4,6 +4,7 @@ import { Signal } from "../../../../Services/EventSystem/Signal";
import { GameTimer } from "../../../../Services/GameTimer";
import { ObjectPool } from "../../../../Services/ObjectPool";
import { delay } from "../../../../Services/Utils/AsyncUtils";
import { getDegreeAngleFromDirection } from "../../../../Services/Utils/MathUtils";
import { ProjectileLauncherSettings } from "../../../Data/GameSettings";
import { IProjectileCollisionSignaler } from "../../../Projectile/IProjectileCollisionSignaler";
import { Projectile } from "../../../Projectile/Projectile";
@ -90,7 +91,7 @@ export class ProjectileLauncher extends Component implements IProjectileCollisio
private fireProjectile(direction: Vec2): void {
const projectile: Projectile = this.projectilePool.borrow();
projectile.init(this.projectileData.damage, this.projectileData.pierces);
projectile.init(this.projectileData.damage, this.projectileData.pierces, getDegreeAngleFromDirection(direction.x, direction.y));
projectile.node.setWorldPosition(this.playerNode.worldPosition);
projectile.node.active = true;
projectile.ContactBeginEvent.on(this.onProjectileCollision, this);

View File

@ -1,4 +1,5 @@
import { _decorator, Component, Node, Button } from "cc";
import { type } from "os";
import { UIButton } from "../Services/UI/Button/UIButton";
import { GameRunner } from "./GameRunner";
@ -7,8 +8,18 @@ const { ccclass, property } = _decorator;
@ccclass("Menu")
export class Menu extends Component {
@property(UIButton) private playBtn: UIButton;
@property(UIButton) private upgradeBtn: UIButton;
public async start(): Promise<void> {
this.playBtn.InteractedEvent.on(() => GameRunner.Instance.playGame(), this);
this.playBtn.InteractedEvent.on(this.startGame, this);
this.upgradeBtn.InteractedEvent.on(this.openUpgradesWindow, this);
}
private startGame(): void {
GameRunner.Instance.playGame();
}
private openUpgradesWindow(): void {}
}

View File

@ -5,3 +5,8 @@ export function roundToOneDecimal(num: number): number {
export function randomPositiveOrNegative(): number {
return Math.random() < 0.5 ? 1 : -1;
}
export function getDegreeAngleFromDirection(x: number, y: number): number {
const radianAngle = Math.atan2(y, x);
return (radianAngle / Math.PI) * 180;
}

View File

@ -0,0 +1,16 @@
import { getDegreeAngleFromDirection } from "../../assets/Scripts/Services/Utils/MathUtils";
const testCases: { x: number; y: number; expectedAngle: number }[] = [
{ x: 0.5, y: 0.5, expectedAngle: 45 },
{ x: 0, y: 1, expectedAngle: 90 },
{ x: -0.5, y: -0.5, expectedAngle: 225 }
];
for (const testCase of testCases) {
test(`returns correct degree angle for direction [X: ${testCase.x} , Y: ${testCase.y}] (${testCase.expectedAngle} degrees)`, () => {
let angle = getDegreeAngleFromDirection(testCase.x, testCase.y);
if (angle < 0) angle += 360;
expect(angle).toBe(testCase.expectedAngle);
});
}