From 76a62a0a263d9deedff112c2df49a3105652f887 Mon Sep 17 00:00:00 2001 From: Kaktus200020 Date: Mon, 19 Aug 2024 18:56:18 +0300 Subject: [PATCH] finishZombie --- ZoFo/Content/MapData/MapSession.tiled-session | 67 ++++++------------- .../Animations/zombie_attack.animation | 2 +- .../Textures/Animations/zombie_walk.animation | 2 +- ZoFo/GameCore/Client.cs | 5 +- .../Entities/LivingEntities/Enemies/Zombie.cs | 53 ++++++++++++--- ZoFo/GameCore/Server.cs | 4 +- 6 files changed, 69 insertions(+), 64 deletions(-) diff --git a/ZoFo/Content/MapData/MapSession.tiled-session b/ZoFo/Content/MapData/MapSession.tiled-session index acfc369..560a26b 100644 --- a/ZoFo/Content/MapData/MapSession.tiled-session +++ b/ZoFo/Content/MapData/MapSession.tiled-session @@ -1,78 +1,49 @@ { - "Map/SizeTest": { - "height": 4300, - "width": 2 - }, "activeFile": "TileMaps/main.tmj", "expandedProjectPaths": [ + "TileMaps", + "Templates", ".", - "TileSets", - "TileMaps" + "TileSets" ], "fileStates": { - "": { - "scaleInDock": 1 - }, - "TileMaps/TileSets/TileSet 1.tsj": { - "scaleInDock": 1 - }, "TileMaps/main.tmj": { - "scale": 0.33, + "scale": 0.75, "selectedLayer": 1, "viewCenter": { - "x": 1010.6060606060606, - "y": 553.0303030303031 + "x": 1860.6666666666665, + "y": 871.3333333333333 } }, - "TileMaps/main.tmj#IconSet": { - "dynamicWrapping": true, - "scaleInEditor": 1 - }, - "TileSets/CollisionTileSet.tsj": { - "scaleInDock": 0.75, - "scaleInEditor": 1 - }, "TileSets/IconSet.tsj": { - "dynamicWrapping": true + "dynamicWrapping": true, + "scaleInDock": 1, + "scaleInEditor": 1 }, "TileSets/TileSet 1.tsj": { "dynamicWrapping": false, - "scaleInDock": 1, - "scaleInEditor": 1.5 + "scaleInDock": 1.5, + "scaleInEditor": 3 }, "TileSets/TilesetNature.tsj": { - "dynamicWrapping": false - "scaleInDock": 1 - }, - "TileSets/WallSet.tsj": { - "scaleInDock": 1, + "scaleInDock": 1.5, "scaleInEditor": 1 }, "TileSets/tileset 1 collision.tsj": { "scaleInDock": 1 } }, - "last.imagePath": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/Textures/icons", - "last.objectTemplatePath": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/MapData/Templates", "openFiles": [ + "TileMaps/main.tmj", + "TileSets/IconSet.tsj", "TileSets/TileSet 1.tsj", - "TileMaps/main.tmj" + "TileSets/TilesetNature.tsj" ], "project": "MapSession.tiled-project", "recentFiles": [ + "TileSets/TilesetNature.tsj", "TileSets/TileSet 1.tsj", - "TileMaps/main.tmj", - "TileSets/CollisionTileSet.tsj", - "TileSets/WallSet.tsj" - ], - "stampsFolder": "D:/C#/Я смотрел ваши ХАКАТОНЫ/ZoFo/ZoFo/Content/MapData/TileStamps", - "tileset.embedInMap": false, - "tileset.lastUsedFormat": "json", - "tileset.margin": 0, - "tileset.spacing": 0, - "tileset.tileSize": { - "height": 16, - "width": 16 - }, - "tileset.type": 1 + "TileSets/IconSet.tsj", + "TileMaps/main.tmj" + ] } diff --git a/ZoFo/Content/Textures/Animations/zombie_attack.animation b/ZoFo/Content/Textures/Animations/zombie_attack.animation index b8129db..5dc21c4 100644 --- a/ZoFo/Content/Textures/Animations/zombie_attack.animation +++ b/ZoFo/Content/Textures/Animations/zombie_attack.animation @@ -1 +1 @@ -{"id":"zombie_attack","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":64,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":3,"isCycle":true,"offset":"0, 0"} +{"id":"zombie_attack","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":64,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":3,"isCycle":false,"offset":"0, 0"} diff --git a/ZoFo/Content/Textures/Animations/zombie_walk.animation b/ZoFo/Content/Textures/Animations/zombie_walk.animation index f6dbfa5..872e797 100644 --- a/ZoFo/Content/Textures/Animations/zombie_walk.animation +++ b/ZoFo/Content/Textures/Animations/zombie_walk.animation @@ -1 +1 @@ -{"id":"zombie_walk","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":32,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":5}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"} +{"id":"zombie_walk","textureName":"Textures/AnimationTextures/Zombie/zombie_spritesheet_v1","startSpriteRectangle":{"X":0,"Y":32,"Width":32,"Height":32},"frameSecond":[{"Item1":0,"Item2":30}],"textureFrameInterval":0,"framesCount":8,"isCycle":true,"offset":"0, 0"} diff --git a/ZoFo/GameCore/Client.cs b/ZoFo/GameCore/Client.cs index 82e5f20..b4966d5 100644 --- a/ZoFo/GameCore/Client.cs +++ b/ZoFo/GameCore/Client.cs @@ -183,8 +183,9 @@ namespace ZoFo.GameCore else if (update is UpdatePosition) { var ent = FindEntityById(update.IdEntity); - - ent.position = (update as UpdatePosition).NewPosition; + + if (ent != null) + ent.position = (update as UpdatePosition).NewPosition; } else if (update is UpdateAnimation) { diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs index 496382f..1eba48e 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Enemies/Zombie.cs @@ -1,24 +1,36 @@ -using Microsoft.Xna.Framework; +using Microsoft.VisualBasic; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GameManagers.CollisionManager; +using ZoFo.GameCore.GameManagers.NetworkManager.Updates.ServerToClient; using ZoFo.GameCore.Graphics; +using ZoFo.GameCore.GUI; namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies { class Zombie : Enemy { public override GraphicsComponent graphicsComponent { get; } = new AnimatedGraphicsComponent(new List { "zombie_damaged", "zombie_walk", "zombie_idle", "zombie_attack", "zombie_death" }, "zombie_walk"); + public bool isAttacking; public Zombie(Vector2 position) : base(position) { health = 5; - speed = 2; + speed = 0.5f; graphicsComponent.ObjectDrawRectangle = new Rectangle(0, 0, 30, 30); collisionComponent.stopRectangle = new Rectangle(10, 20, 10, 10); + isAttacking = false; StartAnimation("zombie_walk"); + collisionComponent.isTrigger = true; + collisionComponent.hasCollision = false; + (graphicsComponent as AnimatedGraphicsComponent).actionOfAnimationEnd += EndAttack; + collisionComponent.OnTriggerZone += OnPlayerClose; + collisionComponent.triggerRectangle = new Rectangle(-5, -5, 40, 40); } public override void Update() @@ -26,18 +38,39 @@ namespace ZoFo.GameCore.GameObjects.Entities.LivingEntities.Enemies Vector2 duration = Vector2.Normalize( AppManager.Instance.server.players[0].position - position ); - velocity += new Vector2(duration.X * speed, duration.Y * speed); - if (Random.Shared.NextDouble() > 0.9) + + + + + if (!isAttacking) { velocity += new Vector2(duration.X * speed, duration.Y * speed); } + + } + public void OnPlayerClose(GameObject sender) + { + + + if(!isAttacking) { - - StartAnimation("zombie_walk"); + StartAnimation("zombie_attack"); + isAttacking = true; } - if (Random.Shared.NextDouble() > 0.9) - { + - //StartAnimation("zombie_idle"); + + } + public void EndAttack(string a) + { + var damagedPlayers=AppManager.Instance.server.collisionManager.GetPlayersInZone(collisionComponent.triggerRectangle.SetOrigin(position)); + //TODO ДАМАЖИТЬ ИГРОКОВ В ЗОНЕ + if (damagedPlayers.Length>0) { DebugHUD.DebugLog("End of" + a); + AppManager.Instance.server.DeleteObject(this); } - + isAttacking = false; + } + public override void Draw(SpriteBatch spriteBatch) + { + DrawDebugRectangle(spriteBatch, collisionComponent.triggerRectangle.SetOrigin(position), Color.Blue); + base.Draw(spriteBatch); } } } diff --git a/ZoFo/GameCore/Server.cs b/ZoFo/GameCore/Server.cs index baa753a..26f7725 100644 --- a/ZoFo/GameCore/Server.cs +++ b/ZoFo/GameCore/Server.cs @@ -162,9 +162,9 @@ namespace ZoFo.GameCore { if (ticks == 3) //ОБРАБАТЫВАЕТСЯ 20 РАЗ В СЕКУНДУ { - foreach (var go in gameObjects) + for (int i = 0; i < gameObjects.Count; i++) { - go.UpdateLogic(); + gameObjects[i].UpdateLogic(); } collisionManager.ResolvePhysics(); ticks = 0;