public Actor(String name, Tile t,int x,int y) { profile = new Rectangle(); this.name = name; this.position = new Vector2(x,y); tiles = new List<Tile>(); cr = new CollisionRect(int.MaxValue, int.MaxValue); RotateSpeed = 2.7f; AddTile(t, 0, 0); luaEvents = new Dictionary<string, List<LuaFunction>>(); }
public TileMap(Tile defaultTile, int width, int height, SpriteBatch sb = null) { this.width = width; this.height = height; this.data = new Tile[height, width]; for (int i = 0; i < height; i++) for (int j = 0; j < width; j++) { data[i, j] = (Tile)defaultTile.Clone(); data[i, j].position.Y = i * defaultTile.Height; data[i, j].position.X = j * defaultTile.Width; } this.sb = sb; this.mainTile = defaultTile; luaEvents = new Dictionary<string, List<LuaFunction>>(); }
public Button(string Text, GraphicsDevice gd, SpriteBatch sb) : base() { this.sb = sb; title = new Text(Text, sb); title.color = Color.White; title.position.X = 5; title.position.Y = 5; _width = title.Width + 10; _height = title.Height + 10; texture = new Texture2D(gd, _width, _height); bgColor = new Color[_width * _height]; for (int i =0;i<bgColor.Length;i++) bgColor[i] = _backgroundColor; texture.SetData(bgColor); Tile t = new Tile(texture , sb); this.onClick += onButtonClicked; baseTiles.Add(t); }
public bool TryCollision(Tile t, Vector2 tileOffset, Vector2 testOffset, float angle) { if (!CollisionRect.isNear(cr, t.cr)) return false; foreach (Tile myTile in tiles) if (myTile.TryCollision(t, testOffset, tileOffset, angle)) return true; return false; }
public bool TryCollision(Tile t, Vector2 tileOffset, Vector2 testOffset, Vector2 angle) { float tmpAngle = (float)Math.Atan2((angle - position).Y, (angle - position).X); return TryCollision(t, tileOffset, testOffset, tmpAngle); }
public bool Collision(Tile t, Vector2 tileOffset, bool collisionEventFlag = false) { if (!CollisionRect.isNear(cr, t.cr)) return false; foreach (Tile myTile in tiles) if (myTile.Collision(t, this.position, tileOffset)) { if (onCollision != null && collisionEventFlag) onCollision(this, t); if (collisionEventFlag) Raise("oncollision", this, t); return true; } return false; }
public void AddTile(Tile t, float xOffset = 0, int yOffset = 0) { tiles.Add((Tile)t.Clone()); if (t.Width > profile.Width) profile.Width = t.Width; if (t.Height > profile.Height) profile.Height = t.Height; t.position.X = xOffset; t.position.Y = yOffset; }
public void AddObject(Tile t, int x, int y) { AddObject(t, new Vector2(x, y)); }
public void AddObject(Tile t, Vector2 pos) { data[(int)pos.Y, (int)pos.X] = (Tile)t.Clone(); data[(int)pos.Y, (int)pos.X].position.X = pos.X * mainTile.Width; data[(int)pos.Y, (int)pos.X].position.Y = pos.Y * mainTile.Height; }
public bool Collision(Tile t, Vector2 thisOffset, Vector2 offset) { if (t.passable || passable) return false; foreach (Triangle trgl in collisionContur) foreach (Triangle trgl2 in t.collisionContur) if (trgl.Collision(trgl2, thisOffset + position, t.position + offset)) { if (onCollision != null) onCollision(this, t); this.Raise("onCollision",this,t); return true; } return false; }
public bool TryCollision(Tile t, Vector2 thisOffset, Vector2 offset,float angle) { if (t.passable || passable) return false; foreach (Triangle trgl in collisionContur) foreach (Triangle trgl2 in t.collisionContur) if (trgl.Collision(trgl2, thisOffset + position, t.position + offset)) return true; return false; }
public Object Clone() { Tile t = new Tile(); t.img = img; t.contour = new Rectangle(contour.X, contour.Y, contour.Width, contour.Height); t.passable = passable; t.options = options; t.name = String.Copy(name); t.sb = sb; t.position = position; t.collisionContur = new List<Triangle>(); foreach (Triangle tr in collisionContur) t.collisionContur.Add((Triangle)tr.Clone()); t.center = new Vector2(center.X,center.Y); t.angle = angle; imgNum = randomizer.Next(img.Count - 1); t.imgNum = imgNum; t.currFrameRect = new Rectangle(currFrameRect.X, currFrameRect.Y, currFrameRect.Width, currFrameRect.Height); t.animSpeed = animSpeed; t.NeedAnim = NeedAnim; t.luaEvents = new Dictionary<string, List<LuaFunction>>(luaEvents); return t; }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape)) Exit(); if (Mouse.GetState().X < 700) { if (Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { int x = ((Mouse.GetState().X - xdraw) / tilesize); int y = ((Mouse.GetState().Y - ydraw) / tilesize); if (x > -1 && y > -1 && x < tilelist.GetLength(0) && y < tilelist.GetLength(1)) { tilelist[x, y] = new Tile(); tilelist[x, y].tileskin = currentTexture; } } else if ((Mouse.GetState().RightButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)) { if (!drag) { xstart = Mouse.GetState().X; ystart = Mouse.GetState().Y; xdrawstart = xdraw; ydrawstart = ydraw; drag = true; } else { try { xdraw = xdrawstart + (Mouse.GetState().X - xstart); ydraw = ydrawstart + (Mouse.GetState().Y - ystart); } catch { } } } else { drag = false; } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Q)) { if (!firstQ) { firstQ = true; if (tilesize > 10) { tilesize=tilesize-10; xdraw = xdraw+(((Mouse.GetState().X- xdraw)/(tilesize+10))*10); ydraw = ydraw + (((Mouse.GetState().Y - ydraw) / (tilesize + 10)) * 10); } } } else { firstQ = false; } if (Keyboard.GetState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.E)) { if (!firstE) { firstE = true; if (tilesize < 51) { tilesize=tilesize+10; xdraw = xdraw - (((Mouse.GetState().X - xdraw) / (tilesize - 10)) * 10); ydraw = ydraw - (((Mouse.GetState().Y - ydraw) / (tilesize - 10)) * 10); } } } else { firstE = false; } } else if(Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) { foreach (SelectionButton s in selectionMenu) { if ((Mouse.GetState().X>s.x && Mouse.GetState().X < (s.x+s.size)) &&((Mouse.GetState().Y > s.y && Mouse.GetState().Y < (s.y + s.size)))) { currentTexture = s.tileskin; } } } // TODO: Add your update logic here base.Update(gameTime); }
public Tile CreateTile(string name,string filename,int frameWidth = -1) { Tile t; if (frameWidth == -1) t = new Tile(filename); else t = new Tile(filename, null, frameWidth); t.name = name; tileList[name] = t; return t; }
public TileMap CreateMap(string name, Tile defaultTile,int width, int height) { TileMap tm = new TileMap(defaultTile,width,height); mapList[name] = tm; return tm; }
public Actor CreateActor(string name, Tile fromTile,int startX, int startY) { Actor act = new Actor(name, fromTile,startX,startY); actorList[name] = act; return act; }