public virtual void Draw(Graphics g, int drawLength, int drawHeight, int[] topLefta) { Bitmap drawImage; int animNumber; if (animated) { animNumber = (Globals.animations[0] + offset) % Globals.MAXFRAMES; } else { animNumber = 0; } drawImage = Globals.ResizeImage(rootImages[animNumber], drawLength / drawRatio, drawHeight / drawRatio); Globals.WriteDebug("Entity->Draw->", "animNumber is " + animNumber + " drawImage Height is" + rootImages[animNumber], false); this.topLeft.X = topLefta[0] + ((drawRatio / 2) * drawImage.Width); this.topLeft.Y = topLefta[1] + ((drawRatio / 2) * drawImage.Height); this.bottomRight.X = topLeft.X + drawImage.Width; this.bottomRight.Y = topLeft.Y + drawImage.Height; g.DrawImage(drawImage, new Point(topLeft.X, topLeft.Y)); if (dying && (Globals.animations[0] + offset) % Globals.MAXFRAMES == Globals.MAXFRAMES - 1) { rootImages[0] = rootImages[Globals.MAXFRAMES - 1]; dying = false; animated = false; } if (Globals.drawOutline) { g.DrawRectangle(new Pen(Color.Red), new Rectangle(topLeft.X, topLeft.Y, drawImage.Width, drawImage.Height)); g.DrawRectangle(new Pen(Color.Cyan), new Rectangle(topLefta[0], topLefta[1], drawLength, drawHeight)); } }
public Entity(String baseFile_p, int setionSize = 400, bool animated = true) { if (dying) { offset = -Globals.animations[0]; } Globals.WriteDebug("Entity -> Constructor -> ", "Base File is " + baseFile_p, true); Bitmap baseFile = (Bitmap)Image.FromFile(baseFile_p); if (animated) { for (int i = 0; i < Globals.MAXFRAMES; i++) { int layer = 0; if (i >= Globals.MAXFRAMES / 2) { layer = 1; } Rectangle section = new Rectangle(new Point(sectionSize * (i % 4) + ((i % (Globals.MAXFRAMES / 2) + 1) * (sectionSize / 20)), (sectionSize * layer) + ((sectionSize / 20) * (layer + 1))), new Size(sectionSize, sectionSize)); rootImages[i] = Globals.CropImage(baseFile, section); } } else { rootImages[0] = baseFile; } }
public void RunProjectile(String command, ref Client thisClient, ref String commandStringsNew, bool server) { int projCount = Int32.Parse(command.Substring(3, 3)); Debug.WriteLine(" Firing " + projCount + " Projectile's "); for (int projCounter = 0; projCounter < projCount; projCounter++) { Debug.WriteLine("------FIRING PROJECTILE--------"); int unitNumber = Int32.Parse(command.Substring((projCounter * 6) + 6, 3)); if (units[unitNumber].projs.Count <= projCounter) { Debug.WriteLine("Unit had less projectiles than counter, ending"); break; } int damage = units[unitNumber].projs[projCounter].GetDamage(); int returnCode = units[unitNumber].projs[projCounter].RunProjecticle(this.cellList); Debug.WriteLine("Form1: " + units[unitNumber].projs[projCounter].name + " returncode is :" + returnCode); if (returnCode > -2) { Debug.WriteLine(units[unitNumber].projs[projCounter].name + "hit something with returnCode" + returnCode); units[unitNumber].projs.RemoveAt(projCounter); projCounter--; } if (returnCode > -1) { Globals.WriteDebug("CommandReader()->RunProjectiles->", String.Format("unitNumber is {0} and projCounter is{1} as palyer {2:000} got hit", unitNumber, projCounter, returnCode), true); String ProjectileHitString = "SHP" + String.Format("{0:000}{1:000}", returnCode, damage) + "^"; if (!Globals.SinglePlayer && server) { Debug.WriteLine("Server sending " + ProjectileHitString); thisClient.Write(ProjectileHitString); } if (Globals.SinglePlayer) { Debug.WriteLine("SinglePlayer sending " + ProjectileHitString); commandStringsNew += ProjectileHitString; } } Debug.WriteLine("------END FIRING PROJECTILE--------"); } }
public static Bitmap ReColorImage(Bitmap inputImage,Color colorToChange, Color colorToChangeTo,String location="Test.png") { DateTime then = DateTime.Now; Globals.WriteDebug("Globals->ReColorImage", "Recolouring", true); for (int i = 0; i < inputImage.Width; i++) { for(int f = 0; f < inputImage.Height; f++) { if (inputImage.GetPixel(i, f).Equals(colorToChange)) { inputImage.SetPixel(i, f, colorToChangeTo); } } } //inputImage.Save(location); TimeSpan span = TimeSpan.FromMilliseconds(DateTime.Now.Millisecond - then.Millisecond); Debug.WriteLine("TIME FOR IMAGE WaS "+span.Milliseconds); return inputImage; }
public int GetProjectileHitResult(Cell[,] cellList) { if (x > -1 && x < cellList.GetLength(0) && y > -1 && y < cellList.GetLength(1)) { if (cellList[x, y].GetMat()) { cellList[x, y].RemoveProjecticle(); return(-1); } if (cellList[x, y].GetPlayer() >= 0) { Debug.WriteLine("Projectile arrived to " + x + "," + y + " hitting player " + cellList[x, y].GetPlayer()); if (!rayCastCreated) { cellList[x, y].RemoveProjecticle(); return(cellList[x, y].GetPlayer()); } } Debug.WriteLine("Projectile arrived to " + x + "," + y); if (rayCastCreated) { Globals.WriteDebug("Projectile.cs -> RunProjectile() -> ", "Raycast Created so changing that", true); rayCastCreated = false; } else if (rayCast) { Globals.WriteDebug("Projectile.cs -> RunProjectile() -> ", "Raycast is reurning -1", true); cellList[x, y].RemoveProjecticle(); return(-1); } return(-2); } return(-1); }
/// <summary> /// /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="d"></param> /// <param name="cellList"></param> /// <param name="distance"></param> /// <param name="searchType">0= Projectiles only, 1= Units only, 2 =Both</param> /// <returns></returns> public static Entity FindFirstEntityInDistance(int x, int y, Directions d, Cell[,] cellList,int distance,int searchType) { Entity returnUnit = null; String tag = "FindFirstEntity"; Globals.WriteDebug(tag, "Running FindFirstEntity", true); int searches = 0; while(searches< distance) { switch (d) { case Directions.DOWN: if (y < cellList.GetLength(1)) { y++; } break; case Directions.UP: if (y > 0) { y--; } break; case Directions.LEFT: if (x > 0) { x--; } break; case Directions.RIGHT: if (x < cellList.GetLength(0)) { x++; } break; } //Globals.WriteDebug(tag, "Checking xy"+x+" "+y , true); if (cellList[x, y].GetMat()) { return null; } if (searchType == 1 || searchType == 2) { if (cellList[x, y].GetUnitOnCell() != null) { Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true); return cellList[x, y].GetUnitOnCell(); } } if (searchType == 0 || searchType == 2) { if (cellList[x, y].GetProjectile() != null) { Globals.WriteDebug(tag, "Return Projectile is " + cellList[x, y].GetProjectile().ToString(), true); return cellList[x, y].GetProjectile(); } } searches++; } Globals.WriteDebug(tag, "Returning Null", true); return returnUnit; }
public static Unit FindFirstUnit(int x, int y, Directions d, Cell[,] cellList) { Unit returnUnit = null; String tag = "FindFirstUnit"; Globals.WriteDebug(tag, "Running FindFirstUnit", true); switch (d) { case Directions.DOWN: while (y < cellList.GetLength(1)) { y++; if (cellList[x, y].GetMat()) { return null; } if (cellList[x, y].GetUnitOnCell() != null) { Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true); return cellList[x, y].GetUnitOnCell(); } } break; case Directions.UP: while (y > 0) { y--; if (cellList[x, y].GetMat()) { return null; } if (cellList[x, y].GetUnitOnCell() != null) { Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true); return cellList[x, y].GetUnitOnCell(); } } break; case Directions.LEFT: while (x > 0) { x--; if (cellList[x, y].GetMat()) { return null; } if (cellList[x, y].GetUnitOnCell() != null) { Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true); return cellList[x, y].GetUnitOnCell(); } } break; case Directions.RIGHT: while (x < cellList.GetLength(0)) { x++; if (cellList[x, y].GetMat()) { return null; } if (cellList[x, y].GetUnitOnCell() != null) { Globals.WriteDebug(tag, "Return Unit is " + cellList[x, y].GetUnitOnCell().GetUnitType(), true); return cellList[x, y].GetUnitOnCell(); } } break; } Globals.WriteDebug(tag, "Returning Null", true); return returnUnit; }