public Trigger(Rectangle rect, Texture2D tex, WorldObject w) : base(rect, tex, ObjectType.Trigger, false, false) { drawRect = rect; drawTex = tex; attachedTo = w; }
public void Draw(SpriteBatch spriteBatch, WorldObject selectedObject, SpriteFont font) { selectedObj = selectedObject; spriteBatch.Draw(menuTex, menuRect, Color.White); spriteBatch.Draw(highlightTex, highlightRect, Color.White); spriteBatch.Draw(exportButtonTex, exportButtonRect, Color.White); spriteBatch.Draw(openButtonTex, openButtonRect, Color.White); spriteBatch.Draw(platformIconTex, platformIconRect, Color.White); spriteBatch.Draw(hazardousPlatformIconTex, hazardousPlatformIconRect, Color.White); spriteBatch.Draw(enemyIconTex, enemyIconRect, Color.White); spriteBatch.Draw(doodadIconTex, doodadIconRect, Color.White); spriteBatch.Draw(itemIconTex, itemIconRect, Color.White); spriteBatch.Draw(startIconTex, startIconRect, Color.White); spriteBatch.Draw(goalIconTex, goalIconRect, Color.White); spriteBatch.Draw(commandsButtonTex, commandsButtonRect, Color.White); spriteBatch.Draw(backgroundButtonTex, backgroundButtonRect, Color.White); spriteBatch.Draw(ropeIconTex, ropeIconRect, Color.White); if (showObjectInfo && selectedObject != null) { spriteBatch.Draw(addTriggerTex, addTriggerRect, Color.White); spriteBatch.DrawString(font, "Rect:" + selectedObject.drawRect.X + "," + selectedObject.drawRect.Y, new Vector2(swidth - 190, 10), Color.Black); spriteBatch.DrawString(font, " ," + selectedObject.drawRect.Width + "," + selectedObject.drawRect.Height, new Vector2(swidth - 100, 10), Color.Black); spriteBatch.DrawString(font, "(C)Copy", new Vector2(swidth - 190, 25), Color.Black); spriteBatch.DrawString(font, "(R)Resize", new Vector2(swidth - 190, 40), Color.Black); spriteBatch.DrawString(font, "(G)Gravity:" + selectedObject.hasGravity, new Vector2(swidth - 190, 60), Color.Black); spriteBatch.DrawString(font, "(T)Tiled:" + selectedObject.isTiled, new Vector2(swidth - 190, 80), Color.Black); spriteBatch.DrawString(font, "(Y)GoThrough:" + selectedObject.goThrough, new Vector2(swidth - 190, 100), Color.Black); int counter = 1; foreach (PatrolPoint p in selectedObject.points) { counter++; spriteBatch.DrawString(font, "" + p.getX() + " " + p.getY() + " " + p.getTime(), new Vector2(swidth - 160, 110 + counter * 25), Color.Black); spriteBatch.Draw(xTex, selectedObject.xRect[counter - 1], Color.White); spriteBatch.Draw(yTex, selectedObject.yRect[counter - 1], Color.White); spriteBatch.Draw(tTex, selectedObject.tRect[counter - 1], Color.White); } spriteBatch.DrawString(font, "Textures:", new Vector2(swidth - 190, 350), Color.Black); for (int i = 0; i < NUM_TEXTURES[objectChosen]; i++) { spriteBatch.Draw(texturesTex[i,objectChosen], texturesRect[i,objectChosen], Color.White); } if (selectedObject.type == Util.ObjectType.Platform || selectedObject.type == Util.ObjectType.Enemy || selectedObject.type == Util.ObjectType.HazardPlatform) { spriteBatch.DrawString(font, "Patrol Points:", new Vector2(swidth - 190, 120), Color.Black); spriteBatch.Draw(pointButtonTex, pointButtonRect, Color.White); spriteBatch.Draw(plusTex, plusRect, Color.White); spriteBatch.Draw(minusTex, minusRect, Color.White); } } else if (showCommandInfo) { for (int i = 0; i < NUM_COMMANDS; i++) { spriteBatch.DrawString(font, " " + counter[i], new Vector2(commandsButtonRect.X+30, ICON_SPLIT + i * 30), Color.Black); spriteBatch.Draw(commandTex[i], commandRect[i], Color.White); } spriteBatch.Draw(plusTex, plusRect, Color.White); spriteBatch.Draw(minusTex, minusRect, Color.White); } else if (showBackgroundInfo) { for (int i = 0; i < NUM_BACKGROUNDS; i++) { spriteBatch.Draw(backgroundTex[i], backgroundRect[i], Color.White); } } }
public void parseDoodads(LinkedList<WorldObject> objects, Texture2D[,] textures) { String content; using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(fileName)) { r.MoveToContent(); r.ReadToFollowing("objects"); r.ReadToFollowing("doodads"); content = r.ReadElementContentAsString(); content = content.Trim(); // "\n rec 160,530,490,100\n nogravity\n nopatrol\n tex 0\n " r.Close(); } String[] properties = content.Split('\n'); if (properties.Length > 1) { for (int i = 0; i < properties.Length; i++) { properties[i] = properties[i].Trim(); } for (int i = 0; i < properties.Length; i += 2) { String[] platformDim = new String[5]; platformDim = properties[i].Split(','); platformDim[0] = platformDim[0].Substring(4); Rectangle platformRect = new Rectangle(Convert.ToInt32(platformDim[0]), Convert.ToInt32(platformDim[1]), Convert.ToInt32(platformDim[2]), Convert.ToInt32(platformDim[3])); String textName = properties[i + 1].Substring(4); int texNum = Convert.ToInt32(textName); Texture2D enemyTex = textures[texNum, 2]; WorldObject w = new WorldObject(platformRect, enemyTex, Util.ObjectType.Doodad, texNum, false, false); objects.AddFirst(w); } } }
public void parsePlatforms(LinkedList<WorldObject> objects, Texture2D[,] textures) { String content; int platformVars = 8; using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(fileName)) { r.MoveToContent(); r.ReadToFollowing("objects"); r.ReadToFollowing("platforms"); content = r.ReadElementContentAsString(); content = content.Trim(); // "\n rec 160,530,490,100\n nogravity\n ptl x1vel,y1vel,time1,x2vel,y2vel,time2\n tex 0\n " r.Close(); } // TODO: add properties for hazardous here to level load String[] properties = content.Split('\n'); if (properties.Length > 1) { for (int i = 0; i < properties.Length; i++) { properties[i] = properties[i].Trim(); } for (int i = 0; i < properties.Length; i += platformVars) { String[] platformDim = new String[5]; platformDim = properties[i].Split(','); platformDim[0] = platformDim[0].Substring(4); Rectangle platformRect = new Rectangle(Convert.ToInt32(platformDim[0]), Convert.ToInt32(platformDim[1]), Convert.ToInt32(platformDim[2]), Convert.ToInt32(platformDim[3])); String textName = ""; // String textName = properties[i + 4].Substring(4); // int texNum = Convert.ToInt32(textName); if (properties[i + 4][0] == 'p') { textName = properties[i + 4].Substring(8); } else if (properties[i+4][0] == 'h') { textName = properties[i + 4].Substring(9); } int texNum = Convert.ToInt32(textName)-1; String isHazardous = properties[i + 3]; Texture2D platformTex = textures[texNum, 0]; WorldObject w; bool goThrough; bool tile; if (properties[i+6].Equals("through")) goThrough = true; else goThrough = false; if (properties[i + 7].Equals("tile")) tile = true; else tile = false; if (isHazardous.Equals("hazardous")) { platformTex = textures[texNum, 3]; w = new WorldObject(platformRect, platformTex, Util.ObjectType.HazardPlatform, texNum, goThrough, tile); } else { w = new WorldObject(platformRect, platformTex, Util.ObjectType.Platform, texNum, goThrough, tile); } String hasGravity = properties[i + 1]; if (hasGravity.Equals("yesgravity")) w.hasGravity = true; else w.hasGravity = false; String s = properties[i + 2]; s = s.Substring(4); String [] ptlPoints = s.Split(','); for (int j = 0; j < ptlPoints.Length-1; j += 3) { PatrolPoint p = new PatrolPoint(Convert.ToInt32(ptlPoints[j]), Convert.ToInt32(ptlPoints[j + 1]), Convert.ToInt32(ptlPoints[j + 2])); w.points.AddLast(p); w.numPoints++; } String s2 = properties[i + 5]; s2 = s2.Substring(8); String[] triggerPoints = s2.Split(','); for (int j = 0; j < triggerPoints.Length - 1; j += 4) { Trigger t = new Trigger(new Rectangle(Convert.ToInt32(triggerPoints[j]), Convert.ToInt32(triggerPoints[j+1]), Convert.ToInt32(triggerPoints[j+2]), Convert.ToInt32(triggerPoints[j+3])), cm.Load<Texture2D>("trigger")); w.triggers.AddLast(t); } objects.AddLast(w); } } }
public void parseEnemies(LinkedList<WorldObject> objects, Texture2D[,] textures) { String content; using (System.Xml.XmlReader r = System.Xml.XmlReader.Create(fileName)) { r.MoveToContent(); r.ReadToFollowing("objects"); r.ReadToFollowing("enemies"); content = r.ReadElementContentAsString(); content = content.Trim(); // "\n rec 160,530,490,100\n nogravity\n nopatrol\n tex 0\n " r.Close(); } String[] properties = content.Split('\n'); if (properties.Length > 1) { for (int i = 0; i < properties.Length; i++) { properties[i] = properties[i].Trim(); } for (int i = 0; i < properties.Length; i += 3) { String[] platformDim = new String[5]; platformDim = properties[i].Split(','); platformDim[0] = platformDim[0].Substring(4); Rectangle platformRect = new Rectangle(Convert.ToInt32(platformDim[0]), Convert.ToInt32(platformDim[1]), Convert.ToInt32(platformDim[2]), Convert.ToInt32(platformDim[3])); String textName = properties[i + 2].Substring(4); int texNum = Convert.ToInt32(textName); Texture2D enemyTex = textures[texNum, 1]; WorldObject w = new WorldObject(platformRect, enemyTex, Util.ObjectType.Enemy, texNum, false, false); String s = properties[i + 1]; s = s.Substring(4); String[] ptlPoints = s.Split(','); for (int j = 0; j < ptlPoints.Length - 1; j += 3) { PatrolPoint p = new PatrolPoint(Convert.ToInt32(ptlPoints[j]), Convert.ToInt32(ptlPoints[j + 1]), Convert.ToInt32(ptlPoints[j + 2])); w.points.AddLast(p); w.numPoints++; } objects.AddLast(w); } } }
public void placeWorldObject() { KeyboardState key = Keyboard.GetState(); int xPos = mouseStateCurrent.X - mouseStateCurrent.X % TILE_SIZE; int yPos = mouseStateCurrent.Y - mouseStateCurrent.Y % TILE_SIZE; WorldObject o = null; if (openMenu && yPos < 50) { return; } if (addPlatform) { o = new WorldObject(new Rectangle(xPos, yPos, TILE_SIZE, TILE_SIZE), platformTexture, Util.ObjectType.Platform, true, true); objects.AddFirst(o); } else if (addHazardousPlatform) { o = new WorldObject(new Rectangle(xPos, yPos, TILE_SIZE, TILE_SIZE), platformTexture, Util.ObjectType.HazardPlatform, true, true); o.isHazardous = true; objects.AddFirst(o); } else if (addStart) { o = new WorldObject(new Rectangle(xPos, yPos, 50, 75), startTexture, Util.ObjectType.Start, false, false); objects.AddFirst(o); } else if (addGoal) { o = new WorldObject(new Rectangle(xPos, yPos, 50, 50), finishTexture, Util.ObjectType.Goal, false, false); objects.AddFirst(o); } else if (addEnemy) { o = new WorldObject(new Rectangle(xPos, yPos, 20, 50), enemyTexture, Util.ObjectType.Enemy, false, false); objects.AddFirst(o); } else if (key.IsKeyDown(Keys.Z)) { o = new WorldObject(new Rectangle(xPos, yPos, 20, 20), shurikenTex, Util.ObjectType.Shuriken, false, false); objects.AddFirst(o); } else if (key.IsKeyDown(Keys.X) || addItem) { o = new WorldObject(new Rectangle(xPos, yPos, 20, 20), swordTex, Util.ObjectType.Sword, false, false); objects.AddFirst(o); } else if (addDoodad) { o = new WorldObject(new Rectangle(xPos, yPos, 20, 20), doodadTex, Util.ObjectType.Doodad, false, false); objects.AddFirst(o); } else if (addRope) { o = new WorldObject(new Rectangle(xPos, yPos, TILE_SIZE/4, TILE_SIZE), ropeTex, Util.ObjectType.Rope, true, false); objects.AddFirst(o); } if (o != null) { selectedObject = o; drawHighlight(o); } checkBounds(xPos, yPos); }
public void drawHighlight(WorldObject w) { if (w != null) { highlightRect.X = w.drawRect.X - 1; highlightRect.Y = w.drawRect.Y - 1; highlightRect.Width = w.drawRect.Width + 2; highlightRect.Height = w.drawRect.Height + 2; } }
public void checkPicking() { int move_dist = TILE_SIZE/4; // if already picking something up then keep picking it up if (showBounds) { if (pickDiff.X == 0) { pickDiff.X = mouseStateCurrent.X - boundsRect.X; pickDiff.Y = mouseStateCurrent.Y - boundsRect.Y; } boundsRect.X = (mouseStateCurrent.X - (int)pickDiff.X) - (mouseStateCurrent.X - (int)pickDiff.X) % move_dist; boundsRect.Y = (mouseStateCurrent.Y - (int)pickDiff.Y) - (mouseStateCurrent.Y - (int)pickDiff.Y) % move_dist; } else { if (selectedObject != null) { foreach (Trigger t in selectedObject.triggers) { if (t.checkPicked(mouseStateCurrent.X, mouseStateCurrent.Y)) { selectedObject = t; pickedUpObject = t; } } } if (pickedUpObject != null) { if (pickDiff.X == 0) { pickDiff.X = mouseStateCurrent.X - pickedUpObject.drawRect.X; pickDiff.Y = mouseStateCurrent.Y - pickedUpObject.drawRect.Y; } if (pickedUpObject.type == Util.ObjectType.Start) { move_dist /= 2; } pickedUpObject.drawRect.X = (mouseStateCurrent.X - (int)pickDiff.X) - (mouseStateCurrent.X - (int)pickDiff.X) % move_dist; pickedUpObject.drawRect.Y = (mouseStateCurrent.Y - (int)pickDiff.Y) - (mouseStateCurrent.Y - (int)pickDiff.Y) % move_dist; drawHighlight(pickedUpObject); } else { // check for picking foreach (WorldObject w in objects) { if (w.checkPicked(mouseStateCurrent.X, mouseStateCurrent.Y)) { menu.showObjectInfo = true; pickedUpObject = w; selectedObject = w; if (selectedObject.type == Util.ObjectType.Platform) { menu.setObjectChosen(0); } else if (selectedObject.type == Util.ObjectType.Enemy) { menu.setObjectChosen(1); } else if (selectedObject.type == Util.ObjectType.Doodad) { menu.setObjectChosen(2); } else if (selectedObject.type == Util.ObjectType.HazardPlatform) { menu.setObjectChosen(3); } else { menu.setObjectChosen(4); } addPlatform = addEnemy = addDoodad = addItem = addHazardousPlatform = addGoal = addStart = addRope = false; break; } } } } }
public void checkMouseClicks() { // left click used for selecting if (mouseStateCurrent.LeftButton == ButtonState.Pressed && mouseStateCurrent.X < SCREEN_WIDTH - 200) { if (showBounds && resizing) { boundsRect.Width = (mouseStateCurrent.X - boundsRect.X - (mouseStateCurrent.X - boundsRect.X) % (TILE_SIZE / 4)); boundsRect.Height = (mouseStateCurrent.Y - boundsRect.Y - (mouseStateCurrent.Y - boundsRect.Y) % (TILE_SIZE / 4)); } // add a platform to the list else if (selectedObject != null && resizing) { if (selectedObject.type == Util.ObjectType.Platform || selectedObject.type == Util.ObjectType.HazardPlatform) { selectedObject.drawRect.Width = (mouseStateCurrent.X - selectedObject.drawRect.X - (mouseStateCurrent.X - selectedObject.drawRect.X) % TILE_SIZE); selectedObject.drawRect.Height = (mouseStateCurrent.Y - selectedObject.drawRect.Y - (mouseStateCurrent.Y - selectedObject.drawRect.Y) % TILE_SIZE); } else { selectedObject.drawRect.Width = (mouseStateCurrent.X - selectedObject.drawRect.X - (mouseStateCurrent.X - selectedObject.drawRect.X) % (TILE_SIZE / 4)); selectedObject.drawRect.Height = (mouseStateCurrent.Y - selectedObject.drawRect.Y - (mouseStateCurrent.Y - selectedObject.drawRect.Y) % (TILE_SIZE / 4)); } } else if (!resizing) { if (!openMenu && mouseStateCurrent.X < SCREEN_WIDTH - 200) checkPicking(); addObject = true; checkIconClick(); } drawHighlight(selectedObject); } else if (mouseStateCurrent.LeftButton == ButtonState.Released) { if (addObject == true) { placeWorldObject(); addObject = false; } resizing = false; } // right click used for moving if (mouseStateCurrent.LeftButton == ButtonState.Pressed && !resizing && mouseStateCurrent.X < SCREEN_WIDTH - 200) { checkPicking(); } else if (mouseStateCurrent.LeftButton == ButtonState.Released) { pickedUpObject = null; pickDiff = new Vector2(0, 0); } if (mouseStateCurrent.ScrollWheelValue != newScrollValue) { newScrollValue = mouseStateCurrent.ScrollWheelValue; } if (newScrollValue > oldScrollValue) { zoom_scale += 0.1f; oldScrollValue = newScrollValue; } else if (newScrollValue < oldScrollValue) { if (zoom_scale>1.1) zoom_scale -= 0.1f; oldScrollValue = newScrollValue; } }
public void checkKeyClicks() { KeyboardState key = Keyboard.GetState(); // resize if (key.IsKeyDown(Keys.R)) { resizing = true; } // delete else if (key.IsKeyDown(Keys.Delete) || key.IsKeyDown(Keys.Back)) { objects.Remove(selectedObject); selectedObject = null; highlightRect = new Rectangle(0, 0, 0, 0); } else if (key.IsKeyDown(Keys.Space) && !keyDown) { showBounds = !showBounds; keyDown = true; } else if (key.IsKeyDown(Keys.G) && !keyDown && selectedObject != null) { selectedObject.hasGravity = !selectedObject.hasGravity; keyDown = true; } else if (key.IsKeyDown(Keys.T) && !keyDown && selectedObject != null) { selectedObject.isTiled = !selectedObject.isTiled; keyDown = true; } else if (key.IsKeyDown(Keys.Y) && !keyDown && selectedObject != null) { selectedObject.goThrough = !selectedObject.goThrough; keyDown = true; } else if (key.IsKeyDown(Keys.D) && !keyDown && selectedObject != null) { if (selectedObject.points.Count != 0) { selectedObject.points.RemoveLast(); selectedObject.numPoints--; } keyDown = true; } // copy else if (key.IsKeyDown(Keys.C)) { // this doesnt really work right now if (selectedObject != null) { WorldObject w = new WorldObject(selectedObject.drawRect, selectedObject.drawTex, selectedObject.type, selectedObject.goThrough, selectedObject.isTiled); w.points = selectedObject.points; w.numPoints = selectedObject.numPoints; w.textNum = selectedObject.textNum; objects.AddFirst(w); selectedObject = null; } } else if (key.IsKeyDown(Keys.Left)) { backgroundRect.X -= (TILE_SIZE/4); boundsRect.X += (TILE_SIZE/4); foreach (WorldObject w in objects) { w.setLocation(w.drawRect.X + (TILE_SIZE/4), w.drawRect.Y); foreach (Trigger t in w.triggers) { t.setLocation(t.drawRect.X + (TILE_SIZE/4), t.drawRect.Y); } } highlightRect.X = highlightRect.X + (TILE_SIZE/4); } else if (key.IsKeyDown(Keys.Up)) { backgroundRect.Y -= (TILE_SIZE/4); boundsRect.Y += (TILE_SIZE/4); foreach (WorldObject w in objects) { w.setLocation(w.drawRect.X, w.drawRect.Y + (TILE_SIZE/4)); foreach (Trigger t in w.triggers) { t.setLocation(t.drawRect.X, t.drawRect.Y + (TILE_SIZE/4)); } } highlightRect.Y = highlightRect.Y + (TILE_SIZE/4); } else if (key.IsKeyDown(Keys.Right)) { backgroundRect.X += (TILE_SIZE/4); boundsRect.X -= (TILE_SIZE/4); foreach (WorldObject w in objects) { w.setLocation(w.drawRect.X - (TILE_SIZE/4), w.drawRect.Y); foreach (Trigger t in w.triggers) { t.setLocation(t.drawRect.X - (TILE_SIZE/4), t.drawRect.Y); } } highlightRect.X = highlightRect.X - (TILE_SIZE/4); // xAdd += (TILE_SIZE/4); } else if (key.IsKeyDown(Keys.Down)) { backgroundRect.Y += (TILE_SIZE/4); boundsRect.Y -= (TILE_SIZE/4); foreach (WorldObject w in objects) { w.setLocation(w.drawRect.X, w.drawRect.Y - (TILE_SIZE/4)); foreach (Trigger t in w.triggers) { t.setLocation(t.drawRect.X, t.drawRect.Y - (TILE_SIZE/4)); } } highlightRect.Y = highlightRect.Y - (TILE_SIZE/4); } if (key.IsKeyUp(Keys.Space) && key.IsKeyUp(Keys.G) && key.IsKeyUp(Keys.T) && key.IsKeyUp(Keys.Y)&& key.IsKeyUp(Keys.D)) keyDown = false; }