public bool tick() { if (cronometro.tick()) { UserInterface.FPSLabel.Edit(getTime()); string str = "health: " + SBGame.getPlayer().getHealth() + " "; UserInterface.HealthLabel.Edit(str); return(true); } else { return(false); } }
// check for reference in map public bool checkCollision() { Entity target = SBGame.getMap().getMap(Position_x, Position_y); // map populated only by units, no bullets if (target != null && target.Team != this.Team) { ((Unit)target).receiveDamage(attackDamage); delete(); return(true); } else { return(false); } }
// main method public static void setInterface() { AbstractForm userInterface = new AbstractForm( SBGame.getMainScreen(), SBGame.getMainScreen().Size_x - 50, 0); InstructionsLabel = new Label(userInterface, 5, 5, "move: up down keys, left key to stop", "toggle fire: F", "exit esc"); HealthLabel = new Label(userInterface, 5, 15, new String(' ', 13)); FPSLabel = new Label(userInterface, 5, 20, new String(' ', 35)); // initialize in frame InstructionsLabel.Print(); }
// spawn a single enemy based on wave properties public static void spawn(wave wave) { // values string type = wave.type; int damage = wave.damage; int AS = wave.attackSpeed; int hp = wave.hp; int limit_x = SBGame.getMap().Size_x - 5; int limit_y = SBGame.getMap().Size_y - 5; int x = generator.Next(10, limit_x); int y = generator.Next(0, limit_y); Unit u = new Unit(x, y, 50, false, type, hp); Weapon.loadUnit(u, damage, AS, false, wave.type); }
// return false and move if it wouldnt leave map bool checkBounded() { int new_x = Position_x + horizontalSpeed; int new_y = Position_y + verticalSpeed; int dimension_y = Texture.GetLength(false); if (new_x < 0 || new_x >= SBGame.getMap().Size_x) { return(false); } else if (new_y < 0 || new_y + dimension_y > SBGame.getMap().Size_y) { // main ship will stop before lower part of texture return(false); } else { return(true); } }
//constructor protected Entity(int pos_x, int pos_y, int moveDelay, bool team, string textureKey) : base(moveDelay) { Position_x = pos_x; Position_y = pos_y; ConsoleColor fcolor; ConsoleColor bcolor = Terminal.DefaultBackColor; if (team) { fcolor = ConsoleColor.Cyan; } else { fcolor = ConsoleColor.Magenta; } // initialize texture based on key and parameter colors Texture = new Texture(Database.assignTexture(textureKey), bcolor, fcolor); Team = team; Parent = SBGame.getBattle().guiMap; Parent.updateprint(this, Position_x, Position_y); }
// not used // spawn a single enemy public static void spawn(string textureKey) { Unit u = new Unit(SBGame.getMap().Size_x - 50, SBGame.getMap().Size_y / 2, 1, false, "major", 2000); }
public bool removeFromQueue() { return(SBGame.getQueue().removeFromQueue(this)); }
// Queue.List<IChronometric> interaction public void addToQueue() { SBGame.getQueue().addToQueue(this); }
// main print method public static void printdelete(IPrintable entity, int rel_x, int rel_y, Screen screen, bool print) { // params: printable (with texture), relative position in form hierarchy, // screen (with its position), bool to print or not to print // defines reference and colors to print // color and reference IPrintable reference; ConsoleColor bcolor; ConsoleColor fcolor; // print defines action to either print or delete on console and reference map if (print) { reference = entity; bcolor = entity.Texture.BackgroundColor; fcolor = entity.Texture.ForegroundColor; } else { reference = null; bcolor = Terminal.DefaultBackColor; fcolor = Terminal.DefaultForeColor; } // other values and references int pos_x = rel_x; int pos_y = rel_y; int map_x = screen.FrameBuffer.Size_x; int map_y = screen.FrameBuffer.Size_y; // loop and limit start as values for a normal for-loop, // equal to 0 and max value respectively. // they change based on offset to only print code inside map int loop_x = 0; int loop_y = 0; int limit_x = entity.Texture.GetLength(true); int limit_y = entity.Texture.GetLength(false); // calc offset // limit and loop both as input and outputs Render.calcOffset(map_x, pos_x, ref limit_x, out loop_x); Render.calcOffset(map_y, pos_y, ref limit_y, out loop_y); // loop from loop_x to limit. changes based on offset for (int y = loop_y; y < limit_y; y++) { // print each line to console on outter loop // both x and y locations are based off of current loop_x/y. but loop_x stays 0 int printPosition_x = pos_x + screen.Position_x + loop_x; int printPosition_y = pos_y + screen.Position_y + y /* current loop_y */; string printLine; if (print) { printLine = Render.getPrintable(entity.Texture.getCode(y), loop_x, limit_x); } else { printLine = new string(new char[limit_x - loop_x]); } Terminal.PrintString(printLine, printPosition_x, printPosition_y, bcolor, fcolor); if (entity is Unit) { // checks until custom length, because of shorter arrays for (int x = loop_x; x < entity.Texture.getCode(y).Length; x++) { char code = entity.Texture.getCode(y, x); if (code != '\0' && code != ' ') { SBGame.getMap().setMap((Entity)reference, pos_x + x, pos_y + y); } } } } }