// Public functions. public Player(Scene scene) { textureInfo = new TextureInfo(new Texture2D("/Application/assets/player-spritemap.png", false), new Vector2i(13, 1)); sprite = new SpriteTile(textureInfo); sprite.Position = new Vector2(AppMain.ScreenWidth * .2f, AppMain.ScreenHeight * .5f); sprite.Quad.S = textureInfo.TileSizeInPixelsf; sprite.CenterSprite(TRS.Local.Center); // Player variables isAlive = true; moveState = MoveStatus.Disabled; rotateAngle = .0f; // Attach update fucntion to scheduler sprite.Schedule(Update); // Create animation function sprite.ScheduleInterval((dt) => { if (IsAlive) { int tileIndex = sprite.TileIndex1D < 8 ? sprite.TileIndex1D + 1 : 1; sprite.TileIndex1D = tileIndex; } }, 0.2f); sprite.ScheduleInterval((dt) => { if (!IsAlive) { int tileIndex = sprite.TileIndex1D < 12 ? sprite.TileIndex1D + 1 : 12; sprite.TileIndex1D = tileIndex; } }, 0.16f); // Add to the current scene. scene.AddChild(sprite); }
public Player() { //load the player's sprite var tex1 = new TextureInfo(new Texture2D("/Application/data/tiles/machinegun_fire.png", false) , new Vector2i(14, 1)); tex1.Texture.SetFilter(TextureFilterMode.Disabled); playerBodySprite = new SpriteTile(); playerBodySprite.TextureInfo = tex1; playerBodySprite.TileIndex2D = new Vector2i(0, 0); //playerBodySprite.BlendMode = BlendMode.None; //testing only //set up scale,position ect playerBodySprite.CenterSprite(new Vector2(0.2f, 0.1f)); playerBodySprite.Pivot = new Vector2(0.08f, 0.0f); playerBodySprite.Scale = new Vector2(0.75f, 1.5f); this.AddChild(playerBodySprite); //Position = new Vector2 (MapManager.Instance.currentMap.width/2.0f, MapManager.Instance.currentMap.height/2.0f); var list = MapManager.Instance.currentMap.returnTilesOfType(MapTile.Types.floor); Position = list[Support.random.Next(0, list.Count - 1)].position; //get the local bounds of the sprite bounds = new Bounds2(); playerBodySprite.GetlContentLocalBounds(ref bounds); bounds = new Bounds2(bounds.Min * 0.5f, bounds.Max * 0.5f); }
public Tank(Scene scene) { // Tank Base texture2D = new Texture2D("/Application/Assets/tankBase2.png", false); numTiles = new Vector2i(1, 1); // tiles in the sprite sheet tiles = new Vector2i(0, 0); // tile you are displaying textureInfo = new TextureInfo(texture2D, numTiles); sprite = new SpriteTile(textureInfo); sprite.Quad.S = new Vector2(textureInfo.TextureSizef.X, textureInfo.TextureSizef.Y); sprite.TileIndex2D = tiles; // sets which tile you are viewing sprite.CenterSprite(); // tank turret turretTex = new TextureInfo("/Application/Assets/tankTurret2.png"); turret = new SpriteUV(turretTex); turret.Quad.S = turretTex.TextureSizef; turret.CenterSprite(TRS.Local.Center); if (SceneManager.Instance.rand.NextDouble() > 0.5) { leftRight = true; sprite.Rotate((float)System.Math.PI / 2); //turret.Rotate((float)System.Math.PI/2); } else { leftRight = false; sprite.Rotate(-(float)System.Math.PI / 2); //turret.Rotate(-(float)System.Math.PI/2); } speed = (float)SceneManager.Instance.rand.NextDouble() * 800.0f; position = new Vector2(300.0f, 300.0f); minSpeed = 100; maxSpeed = 200; setRandom(); scene.AddChild(sprite); scene.AddChild(turret); }
public Player() { //load the player's sprite var tex1 = new TextureInfo(new Texture2D("/Application/data/runner2.png", false) , new Vector2i(2, 4)); playerBodySprite = new SpriteTile(); playerBodySprite.TextureInfo = tex1; playerBodySprite.TileIndex2D = new Vector2i(0, 0); //set up scale,position ect playerBodySprite.CenterSprite(new Vector2(0.5f, 0.5f)); //playerBodySprite.Pivot = new Vector2 (0.5f, 0.5f); playerBodySprite.Scale = new Vector2(3.0f, 3.0f); this.AddChild(playerBodySprite); Position = new Vector2(0.0f, 0.0f); }
public static Scene MakeTestActionsScene() { TextureInfo Characters = new TextureInfo(new Texture2D("/Application/Sample/GameEngine2D/FeatureCatalog/data/PlanetCute/Objects.png", false), new Vector2i(7, 3)); float world_scale = 0.036f; var sprite = new SpriteTile(); sprite.TextureInfo = Characters; sprite.TileIndex1D = 2; sprite.Quad.S = sprite.CalcSizeInPixels() * world_scale; sprite.CenterSprite(); sprite.Color = new Vector4(1.0f, 1.0f, 1.0f, 0.75f); sprite.BlendMode = BlendMode.Normal; var scene = new Scene() { Name = "Action tests" }; scene.AddChild(sprite); var pos = new Vector2(0.0f, 0.0f); int writing_color_tag = 333; int writing_position_tag = 65406; AddButton(scene, "MoveTo (0,0)", ref pos, () => { sprite.RunAction(new MoveTo(new Vector2(0.0f, 0.0f), 0.1f)); }); AddButton(scene, "MoveBy (3,0)", ref pos, () => { sprite.RunAction(new MoveBy(new Vector2(3.0f, 0.0f), 0.1f)); }); AddButton(scene, "ScaleBy (2,2)", ref pos, () => { sprite.RunAction(new ScaleBy(new Vector2(2.0f, 2.0f), 0.1f)); }); AddButton(scene, "ScaleBy (0.5,0.5)", ref pos, () => { sprite.RunAction(new ScaleBy(new Vector2(0.5f, 0.5f), 0.1f)); }); AddButton(scene, "TintTo White", ref pos, () => { // prevent from running an other action that writes the color if (sprite.GetActionByTag(writing_color_tag) != null) { sprite.StopActionByTag(writing_color_tag); } sprite.RunAction(new TintTo(Math.SetAlpha(Colors.White, 0.75f), 2.0f) { Tag = writing_color_tag }); } ); AddButton(scene, "TintTo Blue", ref pos, () => { // prevent from running an other action that writes the color if (sprite.GetActionByTag(writing_color_tag) != null) { sprite.StopActionByTag(writing_color_tag); } sprite.RunAction(new TintTo(Math.SetAlpha(Colors.Blue, 0.75f), 2.0f) { Tag = writing_color_tag }); } ); AddButton(scene, "Pingpong colors", ref pos, () => { // prevent from running an other action that writes the color if (sprite.GetActionByTag(writing_color_tag) != null) { sprite.StopActionByTag(writing_color_tag); } var action12 = new TintTo(Colors.Green, 0.5f) { Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f), }; var action13 = new TintTo(Colors.Magenta, 0.5f) { Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f), }; var seq = new Sequence(); seq.Add(action12); seq.Add(action13); var repeat0 = new RepeatForever() { InnerAction = seq, Tag = writing_color_tag }; sprite.RunAction(repeat0); } ); AddButton(scene, "Pingpong position", ref pos, () => { // prevent from running the same action twice // (we could also just hold an Action object somewhere and re-run, so that this check wouldn't be needed) if (sprite.GetActionByTag(writing_position_tag) != null) { sprite.StopActionByTag(writing_position_tag); } var action12 = new MoveTo(new Vector2(-5, 0), 0.5f) { Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f), }; var action13 = new MoveTo(new Vector2(5, 0), 0.5f) { Tween = (t) => FMath.Sin(t * Math.Pi * 0.5f), }; var seq = new Sequence(); seq.Add(action12); seq.Add(action13); var repeat0 = new RepeatForever() { InnerAction = seq, Tag = writing_position_tag }; sprite.RunAction(repeat0); } ); AddButton(scene, "StopAllActions", ref pos, () => sprite.StopAllActions()); scene.RegisterDisposeOnExit((System.IDisposable)Characters); return(scene); }
public BasicEnemy(Vector2 pos, TextureInfo tex) { Position = pos; sprite = new SpriteTile(); sprite.TextureInfo = tex; sprite.Position = pos; sprite.TileIndex2D = new Vector2i(0, 0); sprite.CenterSprite(new Vector2(0.4f, 0.5f)); sprite.Scale = new Vector2(2.0f, 2.0f); //set up the random vector randomMovement = Support.rand.NextVector2(-0.01f, 0.01f); //update the animation frames sprite.Schedule((dt) => { if (FrameCount % 2 == 0) { //if attacking,use all animation frames if (attacking) { //deal damage to the player if (FrameCount % damageDelay == 0) { Player.Instance.Health -= damage; } animationFrame = (animationFrame + 1) % 25; } else { //if not,then use first three animation frames animationFrame = (animationFrame + 1) % 4; } //assign the correct tileindex sprite.TileIndex1D = animationFrame; //if close to the player,then follow,otherwise move randomly if (Player.Instance.Position.Distance(sprite.Position) < 6.0f && Collisions.checkLineOfSight(this, Player.Instance)) { isMovingRandomly = false; step = (Player.Instance.Position - sprite.Position).Normalize() / 15.0f; //check if should be attacking if (Collisions.checkCollisionBetweenEntities(this, Player.Instance)) { //check if is not attacking already if (attacking == false) { attacking = true; //manualy skip the frames animationFrame = 4; } } else { //make sure that attacking is set to false attacking = false; } } else { //player is not within range, move randomly isMovingRandomly = true; step = randomMovement; } } //advance the position by the given Vector2 step sprite.Position += step; //only move when not attacking if (!attacking) { //collision detection on the X axis //create a vector 2 containing a proposed change to the position Vector2 proposedChange = new Vector2(step.X, 0.0f) * speedModifier; //temporary game entity to contain the entity the enemy might have collided with GameEntity tempEntity; //check wall collisions and then collisions with other enemies if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange) && !Collisions.efficientCollisionsCheck(this, proposedChange, out tempEntity)) { //no collision, so we can change the position Position += proposedChange / speedModifier; } else if (isMovingRandomly) { //collided with something,but if the enemy should be moving randomly, then let it move randomMovement.X = -randomMovement.X; } //collision detection on the Y axis proposedChange = new Vector2(0.0f, step.Y) * speedModifier; if (!Collisions.checkWallsCollisions(this, MapManager.Instance.currentMap, ref proposedChange) && !Collisions.efficientCollisionsCheck(this, proposedChange, out tempEntity)) { Position += proposedChange / speedModifier; } else if (isMovingRandomly) { randomMovement.Y = -randomMovement.Y; } //position changed, so we need to remove the entity from the QuadTree and add again //this is because the entity might be in the wrong place in the QuadTree and removing and re-adding is the only way to fix that Game.Instance.quadTree.removeEntity(this); Game.Instance.quadTree.insert(this); } //rotate the sprite to face the direction of walking var angleInRadians = -FMath.Atan2(step.X, step.Y); sprite.Rotation = new Vector2(FMath.Cos(angleInRadians), FMath.Sin(angleInRadians)); //correct for the fact that the sprite is rotated in the texture file sprite.Rotation = sprite.Rotation.Rotate(90.0f); }, -1); //create a shadow texture - temporarily disabled //SpriteUV shadow = new SpriteUV(new TextureInfo(Bullet.fireTexture)); //shadow.CenterSprite(new Vector2(0.5f,0.5f)); //shadow.Color = Sce.PlayStation.HighLevel.GameEngine2D.Base.Math.SetAlpha(Colors.Black,0.5f); //calculate the bounds for the entire sprite bounds = new Bounds2(); sprite.GetlContentLocalBounds(ref bounds); bounds = new Bounds2(bounds.Min * 0.5f, bounds.Max * 0.5f); }