/// <summary> /// Initializes a new GameObject with the following parameters. /// </summary> /// <param name="game">The CSZone class object.</param> /// <param name="x">The X coordinate to spawn.</param> /// <param name="y">The Y coordinate to spawn.</param> /// <param name="Image">The image file name and format (example.jpg).</param> public GameObject(CSZone game, int x = 0, int y = 0, string Image = "") { this.image = Image; this.key = ("cszonegameobject" + game.GetObjectAmount().ToString()); this.x = x; this.y = y; if (Image != "") { if (!Directory.Exists(@Environment.CurrentDirectory + @"\Images")) { throw new CSZoneImageFolderUnknown(); } else { if (!File.Exists(@Environment.CurrentDirectory + @"\Images\" + Image)) { throw new CSZoneImageUnknown(Image); } else { System.Drawing.Image testImage = System.Drawing.Image.FromFile(@Environment.CurrentDirectory + @"\Images\" + Image); this.width = testImage.Width; this.height = testImage.Height; } } } }
public Form1() { InitializeComponent(); // CODE cszone = new CSZone(this); // Create game engine to current form character = new GameObject(cszone, 0, 0, "test.png"); // Create object cszone.AddObject(character); // Add object to game engine }
/// <summary> /// Draws the current state of the object. /// </summary> /// <param name="game">The CSZone class for reference.</param> public void Draw(CSZone game) { if (this.image != "") { if (draw == null) { draw = Image.FromFile(@Environment.CurrentDirectory + @"\Images\" + this.image); } else { if (game.HasFocus()) { Point focus = game.GetFocusPoint(); if (this.GetKey() == game.GetFocus().GetKey()) { game.Overlap(draw, focus.X, focus.Y, width, height); } else { game.Overlap(draw, (focus.X - (this.x * width)), (focus.Y - (this.y * height)), width, height); } } else { game.Overlap(draw, this.x, this.y, this.width, this.height); } if (!hasSetup) { hasSetup = true; draw = Image.FromFile(@Environment.CurrentDirectory + @"\Images\" + this.image); } } } }
/// <summary> /// Creates a default DirectionInformation class using specified variables. /// </summary> /// <param name="targetPosition">The location to point at.</param> /// <param name="obj">The graphical GameObject.</param> /// <param name="game">The CSZone class object for reference.</param> public DirectionInformation(Point targetPosition, GameObject obj, CSZone game) { int delay = game.GetTimerTickDelay(); }
/// <summary> /// Removes the current object forever. /// <param name="game">The CSZone class for object reference.</param> /// </summary> public void Destroy(CSZone game) { game.OnDestroy(this); }