private void OnCollision(Spartacus.Game.Object p_object1, Spartacus.Game.Object p_object2) { if ((p_object1.v_name == "B" && p_object2.v_name == "BU") || (p_object1.v_name == "BU" && p_object2.v_name == "B")) { v_ball_y = 10; } else if ((p_object1.v_name == "B" && p_object2.v_name == "BD") || (p_object1.v_name == "BD" && p_object2.v_name == "B")) { v_ball_y = -10; } else if ((p_object1.v_name == "B" && p_object2.v_name == "RL") || (p_object1.v_name == "RL" && p_object2.v_name == "B")) { v_ball_x = 10; } else if ((p_object1.v_name == "B" && p_object2.v_name == "RR") || (p_object1.v_name == "RR" && p_object2.v_name == "B")) { v_ball_x = -10; } else if ((p_object1.v_name == "B" && p_object2.v_name == "BL") || (p_object1.v_name == "BL" && p_object2.v_name == "B")) { v_score_right.v_message = (int.Parse(v_score_right.v_message) + 1).ToString(); v_ball.SetPosition(v_window.v_width / 2, v_window.v_height / 2); } else if ((p_object1.v_name == "B" && p_object2.v_name == "BR") || (p_object1.v_name == "BR" && p_object2.v_name == "B")) { v_score_left.v_message = (int.Parse(v_score_left.v_message) + 1).ToString(); v_ball.SetPosition(v_window.v_width / 2, v_window.v_height / 2); } }
public void Initialize() { v_window = new Spartacus.Forms.Window("Spartacus Pong", 800, 600); v_racket_left = new Spartacus.Game.Object("RL", 20, (v_window.v_height - 100) / 2, 20, 100); v_racket_left.AddImage("racket.png"); v_racket_right = new Spartacus.Game.Object("RR", v_window.v_width - 40, (v_window.v_height - 100) / 2, 20, 100); v_racket_right.AddImage("racket.png"); v_ball = new Spartacus.Game.Object("B", v_window.v_width / 2, v_window.v_height / 2, 15, 15); v_ball.AddImage("ball.png"); v_ball_x = 10; v_ball_y = 10; v_bound_up = new Spartacus.Game.Object("BU", 0, 0, v_window.v_width, 10); v_bound_down = new Spartacus.Game.Object("BD", 0, v_window.v_height - 10, v_window.v_width, 10); v_bound_left = new Spartacus.Game.Object("BL", 0, 0, 10, v_window.v_height); v_bound_right = new Spartacus.Game.Object("BR", v_window.v_width - 10, 0, 10, v_window.v_height); v_score_left = new Spartacus.Game.Text(80, 10, "Courier New", 14, 255, 255, 255, 255); v_score_left.SetMessage("0"); v_score_right = new Spartacus.Game.Text(v_window.v_width - 100, 10, "Courier New", 14, 255, 255, 255, 255); v_score_right.SetMessage("0"); v_text_paused = new Spartacus.Game.Text((v_window.v_width - 50) / 2, 10, "Courier New", 14, 255, 255, 255, 255); v_text_paused.SetMessage(""); v_paused = false; v_layer = new Spartacus.Game.Layer(); v_layer.AddObject(v_racket_left); v_layer.AddObject(v_racket_right); v_layer.AddObject(v_ball); v_layer.AddObject(v_bound_up); v_layer.AddObject(v_bound_down); v_layer.AddObject(v_bound_left); v_layer.AddObject(v_bound_right); v_layer.AddText(v_score_left); v_layer.AddText(v_score_right); v_layer.AddText(v_text_paused); v_layer.Collision += this.OnCollision; v_keyboard = new Spartacus.Game.Keyboard(v_window); v_keyboard.KeyDown += this.OnKeyDown; v_keyboard.KeyPress += this.OnKeyPress; v_keyboard.Start(60); v_level = new Spartacus.Game.Level(v_window); v_level.AddLayer(v_layer); v_level.Time += this.OnTime; v_level.Start(30); v_window.Run(); }
private void OnMapMouseClick(Spartacus.Game.Object p_object) { if (this.v_selected >= 0 && string.IsNullOrWhiteSpace(p_object.v_name) && this.v_action != "" && p_object.v_border != null) { switch (this.v_action) { case "walk": this.v_soldiers[this.v_selected].Walk(p_object.v_rectangle.X / this.v_tile_size, p_object.v_rectangle.Y / this.v_tile_size, this.v_mapview_x, this.v_mapview_y); break; case "run": this.v_soldiers[this.v_selected].Run(p_object.v_rectangle.X / this.v_tile_size, p_object.v_rectangle.Y / this.v_tile_size, this.v_mapview_x, this.v_mapview_y); break; case "throw": break; default: break; } if (this.v_soldiers[this.v_selected].v_actions > 0) { this.v_soldiers[this.v_selected].v_object.SetBorder(System.Drawing.Color.White, this.v_border_width); } else { this.v_soldiers[this.v_selected].v_object.SetBorder(System.Drawing.Color.Black, this.v_border_width); } this.v_guiview.v_texts[0].SetMessage(this.v_soldiers[this.v_selected].v_name); this.v_guiview.v_texts[1].SetMessage(string.Format("{0:000}/{1:000}", this.v_soldiers[this.v_selected].v_health, this.v_maxhealth)); this.v_guiview.v_texts[2].SetMessage(string.Format("{0:0}/{1:0}", this.v_soldiers[this.v_selected].v_actions, this.v_maxactions)); this.v_guiview.v_texts[3].SetMessage(string.Format("{0:000}/{1:000}", this.v_soldiers[this.v_selected].v_stamina, this.v_maxstamina)); this.v_guiview.v_texts[4].SetMessage(string.Format("{0:00}/{1:00}", this.v_soldiers[this.v_selected].v_ammo, this.v_maxammo)); this.v_guiview.v_texts[5].SetMessage(string.Format("{0:0}/{1:0}", this.v_soldiers[this.v_selected].v_grenades, this.v_maxgrenades)); if (this.v_action != "shoot") { this.v_selected = -1; } for (int x = 0; x < this.v_mapview_width; x++) { for (int y = 0; y < this.v_mapview_height; y++) { this.v_mapview.v_objects[x * this.v_mapview_width + y].RemoveBorder(); } } } }
private void OnGuiMouseClick(Spartacus.Game.Object p_object) { for (int k = 0; k < this.v_guiview.v_objects.Count; k++) { if (p_object.v_name == "stop" || p_object.v_name == "walk" || p_object.v_name == "run" || p_object.v_name == "shoot" || p_object.v_name == "throw") { this.v_action = p_object.v_name; if (p_object.v_name == this.v_guiview.v_objects[k].v_name) { this.v_guiview.v_objects[k].v_currentimage = this.v_guiview.v_objects[k].v_images[1]; } else { this.v_guiview.v_objects[k].v_currentimage = this.v_guiview.v_objects[k].v_images[0]; } } else if (p_object.v_name == "endturn") { this.v_action = p_object.v_name; } } if (this.v_selected >= 0) { if (this.v_soldiers[this.v_selected].v_actions > 0) { this.v_soldiers[this.v_selected].v_object.SetBorder(System.Drawing.Color.White, this.v_border_width); } else { this.v_soldiers[this.v_selected].v_object.SetBorder(System.Drawing.Color.Black, this.v_border_width); } } this.v_selected = -1; for (int x = 0; x < this.v_mapview_width; x++) { for (int y = 0; y < this.v_mapview_height; y++) { this.v_mapview.v_objects[x * this.v_mapview_width + y].RemoveBorder(); } } }
private void BuildMapView() { Spartacus.Game.Object v_object; this.v_mapview.v_objects.Clear(); this.v_soldiersview.v_objects.Clear(); for (int x = 0; x < this.v_mapview_width; x++) { for (int y = 0; y < this.v_mapview_height; y++) { v_object = new Spartacus.Game.Object(this.v_tile_size * x, this.v_tile_size * y, this.v_tile_size, this.v_tile_size); v_object.AddImage(this.v_tileset[this.v_mapview_x + x, this.v_mapview_y + y].GetImage()); this.v_mapview.AddObject(v_object); for (int w = 0; w < this.v_soldiers.Length; w++) { if (this.v_soldiers[w].v_mapx == (this.v_mapview_x + x) && this.v_soldiers[w].v_mapy == (this.v_mapview_y + y)) { this.v_soldiers[w].v_object.SetPosition(this.v_tile_size * x, this.v_tile_size * y); this.v_soldiersview.AddObject(this.v_soldiers[w].v_object); if (this.v_soldiers[w].v_color == this.v_turn) { if (this.v_soldiers[w].v_actions > 0) { this.v_soldiers[w].v_object.SetBorder(System.Drawing.Color.White, this.v_border_width); } else { this.v_soldiers[w].v_object.SetBorder(System.Drawing.Color.Black, this.v_border_width); } } } } } } }
private void OnCollision(Spartacus.Game.Object p_object1, Spartacus.Game.Object p_object2) { }
private void OnSoldierMouseClick(Spartacus.Game.Object p_object) { if (this.v_selected < 0 && !string.IsNullOrWhiteSpace(p_object.v_name) && p_object.v_name.StartsWith(this.v_player)) { for (int w = 0; w < this.v_soldiers.Length; w++) { if (this.v_soldiers[w].v_object.v_name == p_object.v_name && this.v_soldiers[w].v_health > 0 && this.v_soldiers[w].v_actions > 0 && this.v_action != "") { switch (this.v_action) { case "stop": this.v_soldiers[w].v_object.SetBorder(System.Drawing.Color.Black, this.v_border_width); this.v_soldiers[w].Greet(); this.v_soldiers[w].Stop(); break; case "walk": this.v_soldiers[w].v_object.SetBorder(this.v_playercolor, this.v_border_width); this.v_soldiers[w].Greet(); for (int x = 0; x < this.v_mapview_width; x++) { for (int y = 0; y < this.v_mapview_height; y++) { if (this.v_range.CanWalk(this.v_soldiers, this.v_soldiers[w], this.v_mapview_x + x, this.v_mapview_y + y)) { this.v_mapview.v_objects[x * this.v_mapview_width + y].SetBorder(this.v_playercolor, this.v_border_width); } } } break; case "run": if (this.v_soldiers[w].v_stamina >= 10) { this.v_soldiers[w].v_object.SetBorder(this.v_playercolor, this.v_border_width); this.v_soldiers[w].Greet(); for (int x = 0; x < this.v_mapview_width; x++) { for (int y = 0; y < this.v_mapview_height; y++) { if (this.v_range.CanRun(this.v_soldiers, this.v_soldiers[w], this.v_mapview_x + x, this.v_mapview_y + y)) { this.v_mapview.v_objects[x * this.v_mapview_width + y].SetBorder(this.v_playercolor, this.v_border_width); } } } } break; case "shoot": if (this.v_soldiers[w].v_ammo > 0) { this.v_soldiers[w].v_object.SetBorder(this.v_playercolor, this.v_border_width); this.v_soldiers[w].Greet(); for (int x = 0; x < this.v_mapview_width; x++) { for (int y = 0; y < this.v_mapview_height; y++) { if (this.v_range.CanShoot(this.v_soldiers, this.v_soldiers[w], this.v_mapview_x + x, this.v_mapview_y + y)) { this.v_mapview.v_objects[x * this.v_mapview_width + y].SetBorder(this.v_playercolor, this.v_border_width); } } } } break; case "throw": if (this.v_soldiers[w].v_grenades > 0) { this.v_soldiers[w].v_object.SetBorder(this.v_playercolor, this.v_border_width); this.v_soldiers[w].Greet(); for (int x = 0; x < this.v_mapview_width; x++) { for (int y = 0; y < this.v_mapview_height; y++) { if (this.v_range.CanThrow(this.v_soldiers, this.v_soldiers[w], this.v_mapview_x + x, this.v_mapview_y + y)) { this.v_mapview.v_objects[x * this.v_mapview_width + y].SetBorder(this.v_playercolor, this.v_border_width); } } } } break; default: break; } this.v_guiview.v_texts[0].SetMessage(this.v_soldiers[w].v_name); this.v_guiview.v_texts[1].SetMessage(string.Format("{0:000}/{1:000}", this.v_soldiers[w].v_health, this.v_maxhealth)); this.v_guiview.v_texts[2].SetMessage(string.Format("{0:0}/{1:0}", this.v_soldiers[w].v_actions, this.v_maxactions)); this.v_guiview.v_texts[3].SetMessage(string.Format("{0:000}/{1:000}", this.v_soldiers[w].v_stamina, this.v_maxstamina)); this.v_guiview.v_texts[4].SetMessage(string.Format("{0:00}/{1:00}", this.v_soldiers[w].v_ammo, this.v_maxammo)); this.v_guiview.v_texts[5].SetMessage(string.Format("{0:0}/{1:0}", this.v_soldiers[w].v_grenades, this.v_maxgrenades)); this.v_selected = w; } } } else if (this.v_selected >= 0 && !string.IsNullOrWhiteSpace(p_object.v_name) && !p_object.v_name.StartsWith(this.v_player)) { for (int w = 0; w < this.v_soldiers.Length; w++) { if (this.v_soldiers[w].v_object.v_name == p_object.v_name && this.v_soldiers[w].v_health > 0 && this.v_soldiers[w].v_actions > 0 && this.v_action != "") { if (this.v_action == "shoot") { this.v_soldiers[this.v_selected].Shoot(p_object.v_rectangle.X / this.v_tile_size, p_object.v_rectangle.Y / this.v_tile_size, this.v_mapview_x, this.v_mapview_y); /*this.DrawLine( * this.v_soldiers[this.v_selected].v_object.v_rectangle.X/this.v_tile_size, * this.v_soldiers[this.v_selected].v_object.v_rectangle.Y/this.v_tile_size, * //p_object.v_rectangle.X/this.v_tile_size, * this.v_soldiers[w].v_object.v_rectangle.X/this.v_tile_size, * //p_object.v_rectangle.Y/this.v_tile_size * this.v_soldiers[w].v_object.v_rectangle.Y/this.v_tile_size * );*/ } } } } }
private void BuidGuiView() { Spartacus.Game.Object v_object; Spartacus.Game.Text v_text; // 0 - Soldier Name v_text = new Spartacus.Game.Text(700, 100, "Courier New", 16, 255, 255, 255, 255); //v_text.SetMessage("Soldier 1"); this.v_guiview.AddText(v_text); // 1 - Soldier Health v_text = new Spartacus.Game.Text(880, 155, "Courier New", 12, 255, 255, 255, 255); //v_text.SetMessage("100/100"); this.v_guiview.AddText(v_text); // 2 - Soldier Actions v_text = new Spartacus.Game.Text(920, 205, "Courier New", 12, 255, 255, 255, 255); //v_text.SetMessage("3/3"); this.v_guiview.AddText(v_text); // 3 - Soldier Stamina v_text = new Spartacus.Game.Text(880, 355, "Courier New", 12, 255, 255, 255, 255); //v_text.SetMessage("100/100"); this.v_guiview.AddText(v_text); // 4 - Soldier Ammo v_text = new Spartacus.Game.Text(900, 405, "Courier New", 12, 255, 255, 255, 255); //v_text.SetMessage("20/20"); this.v_guiview.AddText(v_text); // 5 - Soldier Grenades v_text = new Spartacus.Game.Text(920, 455, "Courier New", 12, 255, 255, 255, 255); //v_text.SetMessage("2/2"); this.v_guiview.AddText(v_text); v_object = new Spartacus.Game.Object("health", 700, 150, 32, 32); v_object.AddImage("gui/health.png"); this.v_guiview.AddObject(v_object); v_text = new Spartacus.Game.Text(750, 155, "Courier New", 12, 255, 255, 255, 255); v_text.SetMessage("Health"); this.v_guiview.AddText(v_text); v_object = new Spartacus.Game.Object("actions", 700, 200, 32, 32); v_object.AddImage("gui/actions.png"); this.v_guiview.AddObject(v_object); v_text = new Spartacus.Game.Text(750, 205, "Courier New", 12, 255, 255, 255, 255); v_text.SetMessage("Actions"); this.v_guiview.AddText(v_text); v_object = new Spartacus.Game.Object("stop", 700, 250, 32, 32); v_object.AddImage("gui/stop.png"); v_object.AddImage("gui/stop_" + this.v_player + ".png"); this.v_guiview.AddObject(v_object); v_text = new Spartacus.Game.Text(750, 255, "Courier New", 12, 255, 255, 255, 255); v_text.SetMessage("Stop"); this.v_guiview.AddText(v_text); v_object = new Spartacus.Game.Object("walk", 700, 300, 32, 32); v_object.AddImage("gui/walk.png"); v_object.AddImage("gui/walk_" + this.v_player + ".png"); this.v_guiview.AddObject(v_object); v_text = new Spartacus.Game.Text(750, 305, "Courier New", 12, 255, 255, 255, 255); v_text.SetMessage("Walk"); this.v_guiview.AddText(v_text); v_object = new Spartacus.Game.Object("run", 700, 350, 32, 32); v_object.AddImage("gui/run.png"); v_object.AddImage("gui/run_" + this.v_player + ".png"); this.v_guiview.AddObject(v_object); v_text = new Spartacus.Game.Text(750, 355, "Courier New", 12, 255, 255, 255, 255); v_text.SetMessage("Run"); this.v_guiview.AddText(v_text); v_object = new Spartacus.Game.Object("shoot", 700, 400, 32, 32); v_object.AddImage("gui/shoot.png"); v_object.AddImage("gui/shoot_" + this.v_player + ".png"); this.v_guiview.AddObject(v_object); v_text = new Spartacus.Game.Text(750, 405, "Courier New", 12, 255, 255, 255, 255); v_text.SetMessage("Shoot"); this.v_guiview.AddText(v_text); v_object = new Spartacus.Game.Object("throw", 700, 450, 32, 32); v_object.AddImage("gui/throw.png"); v_object.AddImage("gui/throw_" + this.v_player + ".png"); this.v_guiview.AddObject(v_object); v_text = new Spartacus.Game.Text(750, 455, "Courier New", 12, 255, 255, 255, 255); v_text.SetMessage("Throw"); this.v_guiview.AddText(v_text); v_object = new Spartacus.Game.Object("endturn", 700, 500, 32, 32); v_object.AddImage("gui/endturn.png"); this.v_guiview.AddObject(v_object); v_text = new Spartacus.Game.Text(750, 505, "Courier New", 12, 255, 255, 255, 255); v_text.SetMessage("End Turn"); this.v_guiview.AddText(v_text); }
/* * switch(this.v_direction) * { * case Direction.SOUTH: * break; * case Direction.SOUTHWEST: * break; * case Direction.WEST: * break; * case Direction.NORTHWEST: * break; * case Direction.NORTH: * break; * case Direction.NORTHEAST: * break; * case Direction.EAST: * break; * case Direction.SOUTHEAST: * break; * } */ public Soldier( Spartacus.Database.Generic p_database, TeamColor p_color, string p_name, int p_mapx, int p_mapy ) { Spartacus.Game.Animation v_animation; Direction[] v_directions = new Direction[] { Direction.SOUTH, Direction.SOUTHWEST, Direction.WEST, Direction.NORTHWEST, Direction.NORTH, Direction.NORTHEAST, Direction.EAST, Direction.SOUTHEAST }; int k, f; this.v_color = p_color; switch (p_color) { case TeamColor.GREEN: this.v_prefix = "soldiers/green/"; break; case TeamColor.RED: this.v_prefix = "soldiers/red/"; break; case TeamColor.BLUE: this.v_prefix = "soldiers/blue/"; break; case TeamColor.YELLOW: this.v_prefix = "soldiers/yellow/"; break; default: break; } this.v_mapx = p_mapx; this.v_mapy = p_mapy; this.v_name = p_name; this.v_health = 100; this.v_actions = 5; this.v_stamina = 100; this.v_ammo = 20; this.v_grenades = 2; this.v_object = new Spartacus.Game.Object(p_name, 0, 0, 96, 96); foreach (System.Data.DataRow r in p_database.Query("select * from animations order by id", "ANIMATIONS").Rows) { if (r["id"].ToString() == "1") { k = 0; foreach (Direction d in v_directions) { this.v_object.AddImage(this.v_prefix + r["name"].ToString() + string.Format("{0:0000}", k) + ".png", true); k++; } } else { foreach (Direction d in v_directions) { v_animation = new Spartacus.Game.Animation(r["name"].ToString(), false); k = 0; f = 2; for (int s = 0; s < int.Parse(r["steps"].ToString()); s++) { this.v_object.AddImage(this.v_prefix + r["name"].ToString() + "_" + this.DirectionToString(d) + string.Format("{0:0000}", k) + ".png", true); v_animation.AddStep(this.v_object.v_images.Count - 1, f); k++; f += 2; } switch (d) { case Direction.SOUTH: v_animation.AddStep(0, f); break; case Direction.SOUTHWEST: v_animation.AddStep(1, f); break; case Direction.WEST: v_animation.AddStep(2, f); break; case Direction.NORTHWEST: v_animation.AddStep(3, f); break; case Direction.NORTH: v_animation.AddStep(4, f); break; case Direction.NORTHEAST: v_animation.AddStep(5, f); break; case Direction.EAST: v_animation.AddStep(6, f); break; case Direction.SOUTHEAST: v_animation.AddStep(7, f); break; } this.v_object.AddAnimation(v_animation); } } } this.v_random = new System.Random(); this.v_direction = v_directions[this.v_random.Next(v_directions.Length)]; this.Start(); }
public void FireMouseClick(Spartacus.Game.Object p_object) { this.MouseClick(p_object); }
public void AddObject(Spartacus.Game.Object p_object) { p_object.SetLayer(this); this.v_objects.Add(p_object); }