龙腾猫跃 4 лет назад
Родитель
Сommit
d036da6bb5

+ 8 - 0
Assets/Resources/Controls.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: f70ea6d62aa046d46b88a96005c8018c
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Assets/Resources/Controls/Tooltip.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 3683dd6cff6587a4bacbdc9aeb1e6e64
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Assets/Resources/Controls/Tooltip/BasicTooltip.cs

@@ -0,0 +1 @@
+

+ 11 - 0
Assets/Resources/Controls/Tooltip/BasicTooltip.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 61fc6dc11daac7343a01f1f9e8d5535a
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 21 - 0
Assets/Resources/Entities/EnemyController.cs

@@ -0,0 +1,21 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class EnemyController : EntityBase {
+    
+    internal override bool isPressingCrouch() => false;
+    internal override bool isPressingJump() => false;
+    internal override bool isPressingLeft() => false;
+    internal override bool isPressingRight() => true;
+
+    internal override void OnHitBorder() {
+        Destroy(gameObject);
+    }
+    public float knockbackForceH = 30f, knockbackForceV = 15f;
+    internal override void OnHitEnemy(Collision2D collision) {
+        int face = collision.transform.position.x < transform.position.x ? 1 : -1;
+        rb.velocity = new Vector2(face * knockbackForceH, knockbackForceV);
+    }
+
+}

+ 11 - 0
Assets/Resources/Entities/EnemyController.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 39b999b4bcb380647b8ab07c919e5bc8
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 74 - 0
Assets/Resources/Entities/EntityBase.cs

@@ -0,0 +1,74 @@
+using Cinemachine;
+using DG.Tweening;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public abstract class EntityBase : MonoBehaviour {
+    internal Rigidbody2D rb;
+    internal SpriteRenderer sprite;
+    internal BoxCollider2D coll;
+    public Sprite spriteNormal, spriteDown;
+    void Start() {
+        rb = GetComponent<Rigidbody2D>();
+        sprite = GetComponent<SpriteRenderer>();
+        coll = GetComponent<BoxCollider2D>();
+    }
+
+    public float movementSpeed = 10f, jumpForce = 20f, horizontalF = 0.9f, horizontalA = 0.3f, jumpThreshold = 0.1f, downA = 0.3f, fallA = 0.1f;
+    public float jumpBufferTime = 0.2f, jumpWolfTime = 0.2f; internal float jumpBuffer = 0f, jumpWolf = 0f, jumping = 0f;
+    void Update() {
+        // 获取当前情况
+        float speedX = rb.velocity.x, speedY = rb.velocity.y;
+        bool isCrouch = isPressingCrouch();
+        bool isLand = Physics2D.OverlapCircle(transform.position, jumpThreshold, LayerMask.GetMask("Tilemap"));
+        int moveHorizontal = isCrouch ? 0 : // 没有下蹲
+            (isPressingLeft() == isPressingRight() ? 0 : // 没有同时按住左右
+            (isPressingLeft() ? -1 : 1)); // 获取方向
+        // 判断跳跃
+        jumpBuffer -= Time.deltaTime; jumpWolf -= Time.deltaTime; jumping -= Time.deltaTime;
+        if (isPressingJump()) jumpBuffer = jumpBufferTime;
+        if (isLand) jumpWolf = jumpWolfTime;
+        if (!isCrouch && jumpBuffer > 0 && jumpWolf > 0 && jumping < 0) { // 在地面、没有蹲下
+            speedY = jumpForce;
+            jumpBuffer = 0;
+            jumping = 0.5f;
+        } else if (isCrouch) {
+            speedY -= downA;
+            if (speedY > 0) speedY = 0;
+        }
+        // 加速下落
+        if (speedY < 0) speedY -= fallA;
+        // 横向移动
+        if (moveHorizontal != 0) {
+            speedX = speedX * (1 - horizontalA) + movementSpeed * horizontalA * moveHorizontal;
+        }
+        speedX *= horizontalF;
+        // 蹲下
+        if (isCrouch) {
+            sprite.sprite = spriteDown;
+            coll.size = new Vector2(coll.size.x, 0.4f);
+            coll.offset = new Vector2(0, 0.3f);
+        } else {
+            sprite.sprite = spriteNormal;
+            coll.size = new Vector2(coll.size.x, 1.2f);
+            coll.offset = new Vector2(0, 0.7f);
+        }
+        // 设置
+        rb.velocity = new Vector2(speedX, speedY);
+    }
+    internal abstract bool isPressingLeft();
+    internal abstract bool isPressingRight();
+    internal abstract bool isPressingJump();
+    internal abstract bool isPressingCrouch();
+
+    // 碰撞检测
+    private void OnCollisionEnter2D(Collision2D collision) {
+        if (collision.gameObject.CompareTag("Border")) OnHitBorder();
+        if (collision.gameObject.CompareTag("Enemy") && gameObject.CompareTag("Player")) OnHitEnemy(collision);
+        if (collision.gameObject.CompareTag("Player") && gameObject.CompareTag("Enemy")) OnHitEnemy(collision);
+    }
+    internal abstract void OnHitBorder();
+    internal abstract void OnHitEnemy(Collision2D collision);
+
+}

+ 11 - 0
Assets/Resources/Entities/EntityBase.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 5ba58e5c1a8834d4d9a09f9a19288874
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
Assets/Resources/Entities/Lamp.png


+ 134 - 0
Assets/Resources/Entities/Lamp.png.meta

@@ -0,0 +1,134 @@
+fileFormatVersion: 2
+guid: 10f7659f313c52a4da5e95cf35f7955b
+TextureImporter:
+  internalIDToNameTable: []
+  externalObjects: {}
+  serializedVersion: 11
+  mipmaps:
+    mipMapMode: 0
+    enableMipMap: 0
+    sRGBTexture: 1
+    linearTexture: 0
+    fadeOut: 0
+    borderMipMap: 0
+    mipMapsPreserveCoverage: 0
+    alphaTestReferenceValue: 0.5
+    mipMapFadeDistanceStart: 1
+    mipMapFadeDistanceEnd: 3
+  bumpmap:
+    convertToNormalMap: 0
+    externalNormalMap: 0
+    heightScale: 0.25
+    normalMapFilter: 0
+  isReadable: 0
+  streamingMipmaps: 0
+  streamingMipmapsPriority: 0
+  vTOnly: 0
+  ignoreMasterTextureLimit: 0
+  grayScaleToAlpha: 0
+  generateCubemap: 6
+  cubemapConvolution: 0
+  seamlessCubemap: 0
+  textureFormat: 1
+  maxTextureSize: 2048
+  textureSettings:
+    serializedVersion: 2
+    filterMode: 1
+    aniso: 1
+    mipBias: 0
+    wrapU: 1
+    wrapV: 1
+    wrapW: 1
+  nPOTScale: 0
+  lightmap: 0
+  compressionQuality: 50
+  spriteMode: 1
+  spriteExtrude: 1
+  spriteMeshType: 1
+  alignment: 7
+  spritePivot: {x: 0.5, y: 0.5}
+  spritePixelsToUnits: 32
+  spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+  spriteGenerateFallbackPhysicsShape: 1
+  alphaUsage: 1
+  alphaIsTransparency: 1
+  spriteTessellationDetail: -1
+  textureType: 8
+  textureShape: 1
+  singleChannelComponent: 0
+  flipbookRows: 1
+  flipbookColumns: 1
+  maxTextureSizeSet: 0
+  compressionQualitySet: 0
+  textureFormatSet: 0
+  ignorePngGamma: 0
+  applyGammaDecoding: 0
+  platformSettings:
+  - serializedVersion: 3
+    buildTarget: DefaultTexturePlatform
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  - serializedVersion: 3
+    buildTarget: Standalone
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  - serializedVersion: 3
+    buildTarget: Server
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  - serializedVersion: 3
+    buildTarget: WebGL
+    maxTextureSize: 2048
+    resizeAlgorithm: 0
+    textureFormat: -1
+    textureCompression: 1
+    compressionQuality: 50
+    crunchedCompression: 0
+    allowsAlphaSplitting: 0
+    overridden: 0
+    androidETC2FallbackOverride: 0
+    forceMaximumCompressionQuality_BC6H_BC7: 0
+  spriteSheet:
+    serializedVersion: 2
+    sprites: []
+    outline: []
+    physicsShape: []
+    bones: []
+    spriteID: 5e97eb03825dee720800000000000000
+    internalID: 0
+    vertices: []
+    indices: 
+    edges: []
+    weights: []
+    secondaryTextures: []
+    nameFileIdTable: {}
+  spritePackingTag: 
+  pSDRemoveMatte: 0
+  pSDShowRemoveMatteOption: 0
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 29 - 0
Assets/Resources/Entities/PlayerController.cs

@@ -0,0 +1,29 @@
+using Cinemachine;
+using DG.Tweening;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class PlayerController : EntityBase {
+
+    public string keyLeft = "a", keyRight = "d", keyJump = "w", keyDown = "s";
+    internal override bool isPressingCrouch() => Input.GetKey(keyDown);
+    internal override bool isPressingJump() => Input.GetKey(keyJump);
+    internal override bool isPressingLeft() => Input.GetKey(keyLeft);
+    internal override bool isPressingRight() => Input.GetKey(keyRight);
+
+    internal override void OnHitBorder() {
+        Hurt();
+        transform.position = new Vector3(0, 8, 0);
+    }
+    public float knockbackForceH = 30f, knockbackForceV = 15f;
+    internal override void OnHitEnemy(Collision2D collision) {
+        Hurt();
+        int face = collision.transform.position.x < transform.position.x ? 1 : -1;
+        rb.velocity = new Vector2(face * knockbackForceH, knockbackForceV);
+    }
+    public void Hurt() {
+        rb.velocity = Vector2.zero;
+    }
+
+}

+ 0 - 0
Assets/Resources/System/PlayerController.cs.meta → Assets/Resources/Entities/PlayerController.cs.meta


+ 36 - 0
Assets/Resources/Map/Fail.asset

@@ -0,0 +1,36 @@
+%YAML 1.1
+%TAG !u! tag:unity3d.com,2011:
+--- !u!114 &11400000
+MonoBehaviour:
+  m_ObjectHideFlags: 0
+  m_CorrespondingSourceObject: {fileID: 0}
+  m_PrefabInstance: {fileID: 0}
+  m_PrefabAsset: {fileID: 0}
+  m_GameObject: {fileID: 0}
+  m_Enabled: 1
+  m_EditorHideFlags: 0
+  m_Script: {fileID: 13312, guid: 0000000000000000e000000000000000, type: 0}
+  m_Name: Fail
+  m_EditorClassIdentifier: 
+  m_Sprite: {fileID: 21300000, guid: 4284a451a72d9ae4ca1e726d6e2a0295, type: 3}
+  m_Color: {r: 1, g: 0.24905658, b: 0.24905658, a: 1}
+  m_Transform:
+    e00: 1
+    e01: 0
+    e02: 0
+    e03: 0
+    e10: 0
+    e11: 1
+    e12: 0
+    e13: 0
+    e20: 0
+    e21: 0
+    e22: 1
+    e23: 0
+    e30: 0
+    e31: 0
+    e32: 0
+    e33: 1
+  m_InstancedGameObject: {fileID: 0}
+  m_Flags: 1
+  m_ColliderType: 2

+ 8 - 0
Assets/Resources/Map/Fail.asset.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 281cf526574d7dd40ae1a189295ab4ac
+NativeFormatImporter:
+  externalObjects: {}
+  mainObjectFileID: 11400000
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 22 - 8
Assets/Resources/Map/TilePalette.prefab

@@ -51,7 +51,17 @@ Tilemap:
       m_TileColorIndex: 0
       m_TileObjectToInstantiateIndex: 65535
       dummyAlignment: 0
-      m_AllTileFlags: 1073741825
+      m_AllTileFlags: 2147483649
+  - first: {x: -2, y: -1, z: 0}
+    second:
+      serializedVersion: 2
+      m_TileIndex: 2
+      m_TileSpriteIndex: 0
+      m_TileMatrixIndex: 0
+      m_TileColorIndex: 1
+      m_TileObjectToInstantiateIndex: 65535
+      dummyAlignment: 0
+      m_AllTileFlags: 2147483649
   - first: {x: -1, y: -1, z: 0}
     second:
       serializedVersion: 2
@@ -61,20 +71,22 @@ Tilemap:
       m_TileColorIndex: 0
       m_TileObjectToInstantiateIndex: 65535
       dummyAlignment: 0
-      m_AllTileFlags: 1073741825
+      m_AllTileFlags: 1
   m_AnimatedTiles: {}
   m_TileAssetArray:
   - m_RefCount: 1
     m_Data: {fileID: 11400000, guid: 4f95d2d18cbe9ed49ab4b7dd859ff6fe, type: 2}
   - m_RefCount: 1
     m_Data: {fileID: 11400000, guid: 8415aca5ed2fabd418fa41366a33fd69, type: 2}
-  m_TileSpriteArray:
   - m_RefCount: 1
+    m_Data: {fileID: 11400000, guid: 281cf526574d7dd40ae1a189295ab4ac, type: 2}
+  m_TileSpriteArray:
+  - m_RefCount: 2
     m_Data: {fileID: 21300000, guid: 4284a451a72d9ae4ca1e726d6e2a0295, type: 3}
   - m_RefCount: 1
     m_Data: {fileID: 21300000, guid: 0eefa124a369acd48b78c018f5ee31a7, type: 3}
   m_TileMatrixArray:
-  - m_RefCount: 2
+  - m_RefCount: 3
     m_Data:
       e00: 1
       e01: 0
@@ -95,11 +107,13 @@ Tilemap:
   m_TileColorArray:
   - m_RefCount: 2
     m_Data: {r: 1, g: 1, b: 1, a: 1}
+  - m_RefCount: 1
+    m_Data: {r: 1, g: 0.24905658, b: 0.24905658, a: 1}
   m_TileObjectToInstantiateArray: []
   m_AnimationFrameRate: 1
   m_Color: {r: 1, g: 1, b: 1, a: 1}
-  m_Origin: {x: -1, y: -2, z: 0}
-  m_Size: {x: 1, y: 2, z: 1}
+  m_Origin: {x: -2, y: -2, z: 0}
+  m_Size: {x: 2, y: 2, z: 1}
   m_TileAnchor: {x: 0.5, y: 0.5, z: 0}
   m_TileOrientation: 0
   m_TileOrientationMatrix:
@@ -161,7 +175,7 @@ TilemapRenderer:
   m_SortingLayer: 0
   m_SortingOrder: 0
   m_ChunkSize: {x: 32, y: 32, z: 32}
-  m_ChunkCullingBounds: {x: 0, y: 0, z: 0}
+  m_ChunkCullingBounds: {x: 1, y: 1, z: 0}
   m_MaxChunkCount: 16
   m_MaxFrameAge: 16
   m_SortOrder: 0
@@ -213,7 +227,7 @@ Grid:
   m_CellGap: {x: 0, y: 0, z: 0}
   m_CellLayout: 0
   m_CellSwizzle: 0
---- !u!114 &5365738742203450759
+--- !u!114 &4275034300478791382
 MonoBehaviour:
   m_ObjectHideFlags: 0
   m_CorrespondingSourceObject: {fileID: 0}

+ 0 - 61
Assets/Resources/System/PlayerController.cs

@@ -1,61 +0,0 @@
-using Cinemachine;
-using DG.Tweening;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-
-public class PlayerController : MonoBehaviour {
-    private Rigidbody2D rb;
-    private SpriteRenderer sprite;
-    private BoxCollider2D coll;
-    public LayerMask groundLayer;
-    public Sprite spriteNormal, spriteDown;
-    void Start() {
-        rb = GetComponent<Rigidbody2D>();
-        sprite = GetComponent<SpriteRenderer>();
-        coll = GetComponent<BoxCollider2D>();
-    }
-
-    public string keyLeft = "a", keyRight = "d", keyJump = "w", keyDown = "s";
-    public float movementSpeed = 10f, jumpForce = 20f, horizontalF = 0.9f, horizontalA = 0.3f, jumpThreshold = 0.1f, downA = 0.3f;
-    public float jumpBufferTime = 0.2f, jumpWolfTime = 0.2f; private float jumpBuffer = 0f, jumpWolf = 0f, jumping = 0f;
-    void Update() {
-        // 获取当前情况
-        float speedX = rb.velocity.x, speedY = rb.velocity.y;
-        bool isDown = Input.GetKey(keyDown);
-        bool isGround = Physics2D.OverlapCircle(transform.position, jumpThreshold, groundLayer);
-        int moveHorizontal = isDown ? 0 : // 没有下蹲
-            (Input.GetKey(keyLeft) == Input.GetKey(keyRight) ? 0 : // 没有同时按住左右
-            (Input.GetKey(keyLeft) ? -1 : 1)); // 获取方向
-        // 判断跳跃
-        jumpBuffer -= Time.deltaTime; jumpWolf -= Time.deltaTime; jumping -= Time.deltaTime;
-        if (Input.GetKey(keyJump)) jumpBuffer = jumpBufferTime;
-        if (isGround) jumpWolf = jumpWolfTime;
-        if (!isDown && jumpBuffer > 0 && jumpWolf > 0 && jumping < 0) { // 在地面、没有蹲下
-            speedY = jumpForce;
-            jumpBuffer = 0;
-            jumping = 0.5f;
-        } else if (isDown) {
-            speedY -= downA;
-            if (speedY > 0) speedY = 0;
-        }
-        // 横向移动
-        if (moveHorizontal != 0) {
-            speedX = speedX * (1 - horizontalA) + movementSpeed * horizontalA * moveHorizontal;
-        }
-        speedX *= horizontalF;
-        // 蹲下
-        if (isDown) {
-            sprite.sprite = spriteDown;
-            coll.size = new Vector2(coll.size.x, 0.5f);
-            coll.offset = new Vector2(0, 0.35f);
-        } else {
-            sprite.sprite = spriteNormal;
-            coll.size = new Vector2(coll.size.x, 1.2f);
-            coll.offset = new Vector2(0, 0.7f);
-        }
-        // 设置
-        rb.velocity = new Vector2(speedX, speedY);
-    }
-
-}

Разница между файлами не показана из-за своего большого размера
+ 1954 - 12
Assets/Scenes/SceneMain.unity


+ 1 - 1
ProjectSettings/Physics2DSettings.asset

@@ -4,7 +4,7 @@
 Physics2DSettings:
   m_ObjectHideFlags: 0
   serializedVersion: 5
-  m_Gravity: {x: 0, y: -40}
+  m_Gravity: {x: 0, y: -50}
   m_DefaultMaterial: {fileID: 0}
   m_VelocityIterations: 8
   m_PositionIterations: 3

+ 5 - 2
ProjectSettings/TagManager.asset

@@ -3,7 +3,10 @@
 --- !u!78 &1
 TagManager:
   serializedVersion: 2
-  tags: []
+  tags:
+  - Border
+  - Enemy
+  - Bullet
   layers:
   - Default
   - TransparentFX
@@ -14,7 +17,7 @@ TagManager:
   - Camera
   - Player
   - Enemy
-  - 
+  - Border
   - 
   - 
   - 

Некоторые файлы не были показаны из-за большого количества измененных файлов