//------------------------------------------------------------------------------------------------------------------ public void addMyComponents(float x, float y, float time) { this.resetOnCheckpoint = false; //POSITION COMPONENT - Does it have a position? addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true); //DRAW COMPONENT - Does it get drawn to the game world? DrawComponent drawComp = ( DrawComponent )addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true); drawComp.addSprite("Artwork.Foreground.SpikeButton0", "RunningGame.Resources.Artwork.Foreground.SpikeButton0.png", GlobalVars.SWITCH_INACTIVE_SPRITE_NAME); drawComp.addSprite("Artwork.Foreground.SpikeButton0", "RunningGame.Resources.Artwork.Foreground.SpikeButton1.png", GlobalVars.SWITCH_ACTIVE_SPRITE_NAME); drawComp.setSprite(GlobalVars.SWITCH_INACTIVE_SPRITE_NAME); //COLLIDER - Does it hit things? addComponent(new ColliderComponent(this, GlobalVars.SPIKE_SWITCH_COLLIDER), true); //Swich Component - Is it a switch? Yes. addComponent(new SwitchComponent(startingState), true); if (time > -1) { //Timed Switch Component It's a timed switch! addComponent(new TimedSwitchComponent(time), true); } }
public void drawBkgEntity(Entity e) { //Pull out all required components PositionComponent posComp = ( PositionComponent )e.getComponent(GlobalVars.POSITION_COMPONENT_NAME); DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME); if (isInView(posComp)) { if (g != null) { Image img = drawComp.getImage(); //Get center instead of upper left PointF drawPoint = posComp.getLocAsPoint(); drawPoint.X -= (posComp.width / 2.0f); drawPoint.Y -= (posComp.height / 2.0f); drawPoint.X -= this.x; drawPoint.Y -= this.y; drawPoint.X *= wRatio; drawPoint.Y *= hRatio; lock ( img ) { //g.DrawImage(img, new RectangleF(0, 0, width, height), new RectangleF(x, y, width, height), GraphicsUnit.Pixel); g.DrawImage(img, new RectangleF(x, y, width, height), new RectangleF(x, y, width, height), GraphicsUnit.Pixel); } } } }
public void RegisterComponent(DrawComponent comp) { TaskManager.AddTask(comp); componentList.Add(comp); comp.Register(this); comp.Active(); }
//------------------------------------------------------------------------------------------------------------------ //Here's where you add all the components the entity has. //You can just uncomment the ones you want. public void addMyComponents(float x, float y) { /*POSITION COMPONENT - Does it have a position? */ addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true); /*DRAW COMPONENT - Does it get drawn to the game world? */ DrawComponent drawComp = ( DrawComponent )addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true); drawComp.addSprite("Artwork.Resources.Creatures.DeadPlayer", "RunningGame.Resources.Artwork.Creatures.DeadPlayer.png", "Main"); //Add image drawComp.setSprite("Main"); //Set image to active image /* ANIMATION COMPONENT - Does it need animating? * The float that this reads in is the amount of time (in seconds) between frames. * So, if it was 5, you would be on one frame for 5 seconds, then switch to the next, then 5 seconds later * It'd switch to the next etc, etc... */ //addComponent(new AnimationComponent(0.0005f)); /*VELOCITY COMPONENT - Does it move? */ addComponent(new VelocityComponent(0, 0), true); /*COLLIDER - Does it hit things? * The second field is the collider type. Look in GlobalVars for a string with the right name. */ addComponent(new ColliderComponent(this, GlobalVars.BASIC_SOLID_COLLIDER_TYPE), true); /*GRAVITY COMPONENT - Does it have Gravity? * There's a standard gravity in GlobalVars */ addComponent(new GravityComponent(0, GlobalVars.STANDARD_GRAVITY), true); }
// Use this for initialization void Start() { // Initial setup _state = State.Inactive; transform.position = _model.CameraPose.position; transform.rotation = _model.CameraPose.rotation; UpdateFovDistance(); // Prevent opacity flickering on initial load SetMaterialOpacity(ImageQuad.GetComponent <MeshRenderer>().material, 0); SetMaterialOpacity(PyramidMesh.material, 0); // Load image texture TryLoadTexture(); _model.Image.OnUpdate += (sender, args) => TryLoadTexture(); // Create components _drawComponent = ImageQuad.AddComponent <DrawComponent>(); _surfaceDrawComponent = ImageQuad.AddComponent <SurfaceDrawComponent>(); _surfaceDrawComponent.CameraPosition = transform; _surfaceDrawComponent.TargetPosition = TargetPosition; // Attach event listeners _drawComponent.OnNewLines += (sender, list) => _model.DrawLines = list; _surfaceDrawComponent.OnNewLines += (sender, list) => _model.SurfaceDrawLines = list; }
public void createBlockEntity(float x, float y) { if (level.getCollisionSystem().findObjectsBetweenPoints(x - spawnBlockSize / 2, y - spawnBlockSize / 2, x + spawnBlockSize / 2, y + spawnBlockSize / 2).Count > 0) { return; } if (level.getCollisionSystem().findObjectsBetweenPoints(x - spawnBlockSize / 2, y + spawnBlockSize / 2, x + spawnBlockSize / 2, y - spawnBlockSize / 2).Count > 0) { return; } if (spawnBlocks.Count >= maxNumSpawnBlocks) { spawnBlockEntity old = spawnBlocks.Dequeue(); DrawComponent drawComp = ( DrawComponent )old.getComponent(GlobalVars.DRAW_COMPONENT_NAME); AnimationComponent animComp = ( AnimationComponent)old.getComponent(GlobalVars.ANIMATION_COMPONENT_NAME); if (animComp != null && drawComp != null) { ColliderComponent colComp = (ColliderComponent)old.getComponent(GlobalVars.COLLIDER_COMPONENT_NAME); colComp.colliderType = GlobalVars.DESTROYING_SPAWN_BLOCK_COLLIDER_TYPE; drawComp.setSprite(old.blockAnimationName); animComp.animationOn = true; } else { level.removeEntity(old); } } //Entity newEntity = new [YOUR ENTITY HERE](level, x, y); spawnBlockEntity newEntity = new spawnBlockEntity(level, x, y); level.addEntity(newEntity.randId, newEntity); //This should just stay the same spawnBlocks.Enqueue(newEntity); }
public CircularSaw(Scene scene, TransformComponent tc, DrawComponent dc, Ship ship, int damage, double rotationVelocity) : base(scene, tc, dc) { Ship = ship; Damage = damage; RotationVelocity = rotationVelocity; ship.IsInvincible = true; }
//Base character constructor, called by children public Character() { actions = new List <Skill>(); actions.Add(new AttackAction()); Stats = new Stats(); Graphics = new DrawComponent(); }
public Booster(Scene scene, DrawComponent dc, TransformComponent tc, BoosterSpecs specs) : base(scene, tc, dc) { Scene.Game.PM.CreateBoxComponent(new Size(32.0, 32.0), this); Direction = specs.Direction; Velocity = specs.Velocity; LifeSpan = specs.LifeSpan; Type = specs.Type; }
public void setToPreColors() { this.colorOrbObtained = false; foreach (Entity e in sysManager.drawSystem.getApplicableEntities()) { DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME); drawComp.switchToPostColorImage(); } }
public bool isGrass() { if (!this.hasComponent(GlobalVars.DRAW_COMPONENT_NAME)) { return(false); } DrawComponent drawComp = ( DrawComponent )this.getComponent(GlobalVars.DRAW_COMPONENT_NAME); return(drawComp.activeSprite == grassSpriteName || drawComp.activeSprite == drawComp.getPrecolorImageName(grassSpriteName)); }
public Laser(Scene scene, TransformComponent tc, LaserSpecs specs) : base(scene, tc, null) { DC = new DrawComponent(Scene.Game.AM.GetTexture("Laser.png"), new Size(16.0, 16.0)); Scene.Game.PM.CreateBoxComponent(new Size(16.0, 16.0), this); Direction = specs.Direction; Velocity = specs.Velocity; Damage = specs.Damage; LifeSpan = specs.LifeSpan; }
public Asteroid(Scene scene, DrawComponent dc, TransformComponent tc, AsteroidSpecs specs) : base(scene, tc, dc) { Text = new TextComponent(HP.ToString()); Direction = specs.Direction; Velocity = specs.Velocity; RotationVelocity = specs.RotationVelocity; HP = specs.HP; currentHP = specs.HP; }
public Tooltip(Scene scene, TransformComponent tc, TooltipSpecs specs) : base(scene, tc, null) { DC = new DrawComponent(null, new Size(50.0, 8.0)); Direction = specs.Direction; Velocity = specs.Velocity; LifeSpan = specs.LifeSpan; Text = new TextComponent(specs.Text); }
public void addMyComponents(float x, float y) { //position and velocity addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true); DrawComponent drawComp = ( DrawComponent )addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true); //Add image - Use base name for first parameter (everything in file path after Resources. and before the numbers and .png) //Then second parameter is full filepath to a default image drawComp.addSprite("Artwork.Foreground.GreenSplat", "RunningGame.Resources.Artwork.Foreground.GreenSplat.png", "Main"); drawComp.setSprite("Main"); //Set image to active image addComponent(new ColliderComponent(this, GlobalVars.BOUNCE_POSTGROUND_COLLIDER_TYPE, defaultWidth - 4, defaultHeight + 3), true); }
//------------------------------------------------------------------------------------------------------------------ //Here's where you add all the components the entity has. //You can just uncomment the ones you want. public void addMyComponents(float x, float y) { /*POSITION COMPONENT - Does it have a position? */ addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true); /*DRAW COMPONENT - Does it get drawn to the game world? * You'll need to know the address for your image. * It'll probably be something along the lines of "RunningGame.Resources.[ ].png" ONLY png!! * First create the component * Then add the image * Then set the image to the active image */ DrawComponent drawComp = ( DrawComponent )addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true); //Add image - Use base name for first parameter (everything in file path after Resources. and before the numbers and .png) //Then second parameter is full filepath to a default image drawComp.addSprite("Artwork.Other.WhiteSquare", "RunningGame.Resources.Artwork.Other.WhiteSquare.png", "Main"); drawComp.setSprite("Main"); //Set image to active image /* ANIMATION COMPONENT - Does it need animating? * The float that this reads in is the amount of time (in seconds) between frames. * So, if it was 5, you would be on one frame for 5 seconds, then switch to the next, then 5 seconds later * It'd switch to the next etc, etc... */ addComponent(new AnimationComponent(0.2f)); List <string> anim = new List <string>() { "Artwork.Creatures.vision_orb1", "Artwork.Creatures.vision_orb2", }; List <string> animDefaults = new List <string>() { "RunningGame.Resources.Artwork.Creatures.vision_orb1.png", "RunningGame.Resources.Artwork.Creatures.vision_orb2.png", }; drawComp.addAnimatedSprite(anim, animDefaults, "MainAnim"); drawComp.setSprite("MainAnim"); /*COLLIDER - Does it hit things? * The second field is the collider type. Look in GlobalVars for a string with the right name. */ addComponent(new ColliderComponent(this, GlobalVars.VISION_ORB_UNLOCK_COLLIDER), true); /*GRAVITY COMPONENT - Does it have Gravity? * There's a standard gravity in GlobalVars */ addComponent(new GravityComponent(0, GlobalVars.STANDARD_GRAVITY), true); }
public bool doorSwitch(Entity e, bool active) { //Active if (active) { if (e.hasComponent(GlobalVars.COLLIDER_COMPONENT_NAME)) { e.removeComponent(GlobalVars.COLLIDER_COMPONENT_NAME); level.getCollisionSystem().colliderRemoved(e); } DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME); drawComp.setSprite(GlobalVars.DOOR_OPEN_SPRITE_NAME); } //Closed else { //Check for the player within the door. PositionComponent posComp = (PositionComponent)e.getComponent(GlobalVars.POSITION_COMPONENT_NAME); PointF lowerLeft = new PointF(posComp.x - posComp.width / 2, posComp.y + posComp.height / 2); PointF upperRight = new PointF(posComp.x + posComp.width / 2, posComp.y - posComp.height / 2); List <Entity> cols = level.getCollisionSystem().findObjectsBetweenPoints(lowerLeft, upperRight); //Don't close on player. foreach (Entity ent in cols) { if (ent is Player) { VelocityComponent velComp = ( VelocityComponent )ent.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME); PositionComponent playerComp = ( PositionComponent )ent.getComponent(GlobalVars.POSITION_COMPONENT_NAME); float kickOutSpeed = 200.0f; if (playerComp.x > posComp.x) { velComp.setVelocity(kickOutSpeed, velComp.y); } else { velComp.setVelocity(-kickOutSpeed, velComp.y); } return(false); } } if (!e.hasComponent(GlobalVars.COLLIDER_COMPONENT_NAME)) { e.addComponent(new ColliderComponent(e, GlobalVars.BASIC_SOLID_COLLIDER_TYPE)); } DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME); drawComp.setSprite(GlobalVars.DOOR_CLOSED_SPRITE_NAME); } return(true); //Just cuz }
//------------------------------------------------------------------------------------------------------------------ //Here's where you add all the components the entity has. //You can just uncomment the ones you want. public void addMyComponents(float x, float y, int switchId, float width, float height, bool defaultClosed) { this.resetOnCheckpoint = false; /*POSITION COMPONENT - Does it have a position? */ addComponent(new PositionComponent(x, y, width, height, this), true); /*DRAW COMPONENT - Does it get drawn to the game world? * You'll need to know the address for your image. * It'll probably be something along the lines of "RunningGame.Resources.[ ].png" or maybe .bmp */ DrawComponent drawComp = ( DrawComponent )addComponent(new DrawComponent(width, height, level, true), true); if (width <= height) { drawComp.addSprite("Artwork.Foreground.DoorClosed", "RunningGame.Resources.Artwork.Foreground.DoorClosed11.png", GlobalVars.DOOR_CLOSED_SPRITE_NAME); drawComp.addSprite("Artwork.Foreground.DoorOpen", "RunningGame.Resources.Artwork.Foreground.DoorOpen11.png", GlobalVars.DOOR_OPEN_SPRITE_NAME); } else { drawComp.addSprite("Artwork.Foreground.WideDoorClosed", "RunningGame.Resources.Artwork.Foreground.WideDoorClosed11.png", GlobalVars.DOOR_CLOSED_SPRITE_NAME); drawComp.addSprite("Artwork.Foreground.WideDoorOpen", "RunningGame.Resources.Artwork.Foreground.WideDoorOpen11.png", GlobalVars.DOOR_OPEN_SPRITE_NAME); } if (defaultClosed) { drawComp.setSprite(GlobalVars.DOOR_CLOSED_SPRITE_NAME); } else { drawComp.setSprite(GlobalVars.DOOR_OPEN_SPRITE_NAME); } /*COLLIDER - Does it hit things? * The second field is the collider type. Look in GlobalVars for a string with the right name. */ if (defaultClosed) { addComponent(new ColliderComponent(this, GlobalVars.BASIC_SOLID_COLLIDER_TYPE), true); } /*SWITCH LISTENER - It listens for a switch */ string eventType = GlobalVars.DOOR_EVENT_TYPE; if (!defaultClosed) { eventType = GlobalVars.DEFAULT_OPEN_DOOR_EVENT_TYPE; } addComponent(new SwitchListenerComponent(switchId, eventType), true); }
//---------------------------------------------------------------------------------------- public void setFrame(Entity e, int frameNum) { DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME); if (frameNum < drawComp.getSprite().getNumImages()) { drawComp.getSprite().currentImageIndex = frameNum; } else { Console.WriteLine("Trying to change " + e + " sprite to nonexistant frame: " + frameNum); } }
private void UiUpdate() { if (CurrentGameStatus == GameStatus.Running) { DrawComponent.Draw(Map); } else { DrawComponent.DrawCells(new List <TextCell> { new TextCell("NOT Running", Map) }); } }
//------------------------------------------------------------------------------------------------------------------ public void addMyComponents(float x, float y, float velX, float velY) { this.updateOutOfView = true; /*POSITION COMPONENT - Does it have a position? */ addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true); //Gravity addComponent(new GravityComponent(0, GlobalVars.STANDARD_GRAVITY / 4), true); /*DRAW COMPONENT - Does it get drawn to the game world? * NOTE: Was PaintBlob11.png before Bullet11.png */ DrawComponent drawComp = ( DrawComponent )addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true); List <string> bulletAnimation = new List <string>() { "Artwork.Foreground.Bullet.Bullet1", "Artwork.Foreground.Bullet.Bullet2" }; List <string> bulletAnimDefaults = new List <string>() { "RunningGame.Resources.Artwork.Foreground.Bullet.Bullet111", "RunningGame.Resources.Artwork.Foreground.Bullet.Bullet211" }; //drawComp.addSprite( "Artwork.Foreground.Bullet", "RunningGame.Resources.Artwork.Foreground.Bullet11.png", "Main" ); drawComp.addAnimatedSprite(bulletAnimation, bulletAnimDefaults, "Main"); drawComp.setSprite("Main"); /* ANIMATION COMPONENT - Does it need animating? */ addComponent(new AnimationComponent(0.08f), true); /*VELOCITY COMPONENT - Does it move? */ addComponent(new VelocityComponent(velX, velY), true); /*COLLIDER - Does it hit things? */ addComponent(new ColliderComponent(this, GlobalVars.BULLET_COLLIDER_TYPE, 10, 10), true); /* OUT OF SCREEN COOMPONENT - Destroy on exiting screen. */ addComponent(new ScreenEdgeComponent(3, 3, 3, 3), true); }
//When an entity dies, this is called. public void handleDeath(Entity e) { //------- First check for any special cases //Is it the player? If so, reset the level. if (e.hasComponent(GlobalVars.PLAYER_COMPONENT_NAME)) { //If the reset level timer hasn't already been set... if (levelResetTimer < 0) { //Get the player (Who just died) Player pl = ( Player )level.getPlayer(); //Grab all necessary components PositionComponent posComp = ( PositionComponent )pl.getComponent(GlobalVars.POSITION_COMPONENT_NAME); VelocityComponent velComp = ( VelocityComponent )pl.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME); //Create a dead player entity DeadPlayerEntity deadPlayer = new DeadPlayerEntity(level, posComp.x, posComp.y); //Set the dead player entity's velocity equal to the velocity of the old player //VelocityComponent deadVelComp = ( VelocityComponent )deadPlayer.getComponent( GlobalVars.VELOCITY_COMPONENT_NAME ); //deadVelComp.x = velComp.x; //deadVelComp.y = velComp.y; //If the player was looking left, flip the dead player entity's sprite so it's also looking left if (pl.isLookingLeft()) { DrawComponent drawComp = ( DrawComponent )deadPlayer.getComponent(GlobalVars.DRAW_COMPONENT_NAME); drawComp.rotateFlipSprite("Main", System.Drawing.RotateFlipType.RotateNoneFlipX); } //Add the dead player entity level.addEntity(deadPlayer); //Remove the player level.removeEntity(pl); //Start the red flash level.sysManager.drawSystem.setFlash(System.Drawing.Color.DarkRed, resetTime); //Start the reset timer. levelResetTimer = resetTime * 0.6f;; } } //------- Not a special case? Default to simply destroying the entity else { level.removeEntity(e); } }
//------------------------------------------------------------------------------------------------------------------ //Here's where you add all the components the entity has. //You can just uncomment the ones you want. public void addMyComponents(float x, float y, int msg) { string message = "A MSG"; switch (msg) { case (0): message = "Left Click to Shoot!"; break; case (1): message = "Exit the right side of the Level to Continue!"; break; case (2): message = "You can activate switches by shooting them!"; break; case (3): message = "Combine powerups in creative\nways for the best effects!"; break; case (4): message = "Not all enemies are vulnerable to your weapon,\nbut perhaps there are other ways to handle them..."; break; } /*POSITION COMPONENT - Does it have a position? */ addComponent(new PositionComponent(x, y, defaultWidth, defaultHeight, this), true); addComponent(new SignComponent(message), true); /*DRAW COMPONENT - Does it get drawn to the game world? * You'll need to know the address for your image. * It'll probably be something along the lines of "RunningGame.Resources.[ ].png" ONLY png!! * First create the component * Then add the image * Then set the image to the active image */ DrawComponent drawComp = (DrawComponent)addComponent(new DrawComponent(defaultWidth, defaultHeight, level, true), true); // Add image - Use base name for first parameter (everything in file path after Resources. and before the numbers and .png) //Then second parameter is full filepath to a default image drawComp.addSprite("Artwork.Foreground.Sign", "RunningGame.Resources.Artwork.Foreground.Sign10.png", "Main"); drawComp.setSprite("Main"); //Set image to active image /*COLLIDER - Does it hit things? * The second field is the collider type. Look in GlobalVars for a string with the right name. */ addComponent(new ColliderComponent(this, GlobalVars.SIGN_COLLIDER_TYPE), true); }
public void addMyComponents(float x, float y, float width, float height) { //Position Component addComponent(new PositionComponent(x, y, width, height, this), true); if (!GlobalVars.fullForegroundImage) { //Draw component DrawComponent drawComp = new DrawComponent(defaultWidth, defaultHeight, level, true); drawComp.addSprite("Artwork.Foreground.Grass.Dirt", "RunningGame.Resources.Artwork.Foreground.Grass.Dirt61.png", dirtSpriteName); string grassFile = "placeholder"; if (!GlobalVars.simpleGround) { grassFile = "Artwork.Foreground.Grass.Grass0"; Random rand = new Random(this.randId); switch (rand.Next(0, 5)) { case (1): grassFile = "Artwork.Foreground.Grass.Grass1"; break; case (2): grassFile = "Artwork.Foreground.Grass.Grass2"; break; case (3): grassFile = "Artwork.Foreground.Grass.Grass3"; break; case (4): grassFile = "Artwork.Foreground.Grass.Grass4"; break; } } else { grassFile = "Artwork.Foreground.Grass.SimpGrass"; } drawComp.addSprite(grassFile, "RunningGame.Resources.Artwork.Foreground.Grass61.png", grassSpriteName); drawComp.setSprite(dirtSpriteName); addComponent(drawComp, true); } //Collider ColliderComponent c = ( ColliderComponent )addComponent(new ColliderComponent(this, GlobalVars.BASIC_SOLID_COLLIDER_TYPE, defaultWidth - 1, defaultHeight - 1)); c.hasTransparentPixels = false; c.collideOnNoSprite = true; }
protected override void Initialize() { base.Initialize(); player1 = new Entity("Player1"); DrawComponent player1DC = new DrawComponent(player1, Content, "Sprites/paddle", Color.White); PositionComponent player1PC = new PositionComponent(player1); player1PC.position.X = player1PC.origin.X = engine.Width - (player1DC.GetTextureWidth() + 20f); player1PC.position.Y = player1PC.origin.Y = (engine.Height / 2f) - (player1DC.GetTextureHeight() / 2f); player1.AddComponent(player1DC); player1.AddComponent(player1PC); player1.AddCollider(player1PC.origin.X, player1PC.origin.Y, player1DC.GetTextureWidth(), player1DC.GetTextureHeight()); engine.AddEntity(player1); player2 = new Entity("Player2"); DrawComponent player2DC = new DrawComponent(player2, Content, "Sprites/paddle", Color.White); PositionComponent player2PC = new PositionComponent(player2); player2PC.position.X = player2PC.origin.X = 20f; player2PC.position.Y = player2PC.origin.Y = (engine.Height / 2f) - (player2DC.GetTextureHeight() / 2f); player2.AddComponent(player2DC); player2.AddComponent(player2PC); player2.AddCollider(player2PC.origin.X, player2PC.origin.Y, player2DC.GetTextureWidth(), player2DC.GetTextureHeight()); engine.AddEntity(player2); ball = new Entity("Ball"); DrawComponent ballDC = new DrawComponent(ball, Content, "Sprites/ball", Color.White); PositionComponent ballPC = new PositionComponent(ball); ballPC.position.X = ballPC.origin.X = (engine.Width / 2f) - (ballDC.GetTextureWidth() / 2f); ballPC.position.Y = ballPC.origin.Y = (engine.Height / 2f) - (ballDC.GetTextureHeight() / 2f); ball.AddComponent(ballPC); ball.AddComponent(ballDC); ball.AddCollider(ballPC.origin.X, ballPC.origin.Y, ballDC.GetTextureWidth(), ballDC.GetTextureHeight()); engine.AddEntity(ball); Entity centerLine = new Entity("centerLine"); DrawComponent centerLineDC = new DrawComponent(centerLine, Content, "Sprites/center", Color.White); PositionComponent centerLinePC = new PositionComponent(centerLine); centerLinePC.position.X = (engine.Width / 2f) - (centerLineDC.GetTextureWidth() / 2f); centerLinePC.position.Y = 7f; centerLine.AddComponent(centerLineDC); centerLine.AddComponent(centerLinePC); engine.AddEntity(centerLine); Reset(); }
//---------------------------------------------------------------------------------------------- public void beginFire(Entity e, TimedShooterComponent shooterComp, TimerComponent timeComp, DirectionalComponent dir) { fireItem(e, dir); shooterComp.currentBurstNum++; if (shooterComp.currentBurstNum < shooterComp.numShotsPerBurst) { timeComp.addTimer(shooterComp.fireTimerString, shooterComp.timeBetweenShotsInBurst); } else { shooterComp.currentBurstNum = 0; timeComp.addTimer(shooterComp.fireTimerString, shooterComp.timeBetweenBursts); DrawComponent drawComp = ( DrawComponent )e.getComponent(GlobalVars.DRAW_COMPONENT_NAME); drawComp.resetAnimation(); } }
protected override void OnUpdate() { // Reset ResetDebugStreams(); // Set up component to draw if (m_DrawComponent == null) { m_DrawComponent = new GameObject("DebugStream.DrawComponent", typeof(DrawComponent)) { hideFlags = HideFlags.DontSave }.GetComponent <DrawComponent>(); m_DrawComponent.DebugDraw = this; Unity.DebugDisplay.DebugDisplay.Instantiate(); } }
public override void revertToStartingState() { SwitchComponent sc = ( SwitchComponent )getComponent(GlobalVars.SWITCH_COMPONENT_NAME); sc.setActive(startingState, this); DrawComponent drawComp = ( DrawComponent )getComponent(GlobalVars.DRAW_COMPONENT_NAME); if (startingState) { drawComp.setSprite(GlobalVars.SWITCH_ACTIVE_SPRITE_NAME); } else { drawComp.setSprite(GlobalVars.SWITCH_INACTIVE_SPRITE_NAME); } }
public void refreshImage(bool left) { DrawComponent drawComp = ( DrawComponent )this.getComponent(GlobalVars.DRAW_COMPONENT_NAME); int spriteNum = drawComp.getSprite().currentImageIndex; if (left) { drawComp.setSprite(activeLeftImage); } else { drawComp.setSprite(activeRightImage); } drawComp.getSprite().currentImageIndex = spriteNum; }
//You must have this, but it may be empty. //What should the entity do in order to revert to its starting state? //Common things are: //Set position back to startingX and startingY //NOTE: If doing this, you probably want to use the MovementSystem's teleportToNoCollisionCheck() method //rather than the usual changePosition() //Set velocity to 0 in both directions //Note: Some things, like ground, dont move, and really don't need anything here. //Note: Some things, like a bullet, won't ever exist at the start of a level, so you could probably leave this empty. public override void revertToStartingState() { TimedShooterComponent shooterComp = ( TimedShooterComponent )this.getComponent(GlobalVars.TIMED_SHOOTER_COMPONENT_NAME); TimerComponent timerComp = ( TimerComponent )this.getComponent(GlobalVars.TIMER_COMPONENT_NAME); timerComp.clearAllTimers(); timerComp.addTimer(shooterComp.fireTimerString, shooterComp.timeBetweenBursts); PositionComponent posComp = ( PositionComponent )this.getComponent(GlobalVars.POSITION_COMPONENT_NAME); level.getMovementSystem().teleportToNoCollisionCheck(posComp, posComp.startingX, posComp.startingY); VelocityComponent velComp = ( VelocityComponent )this.getComponent(GlobalVars.VELOCITY_COMPONENT_NAME); velComp.setVelocity(0, 0); DrawComponent drawComp = (DrawComponent)this.getComponent(GlobalVars.DRAW_COMPONENT_NAME); drawComp.setSprite(startingSprite, true); }