public static EgoComponent GenerateGun() { EntityBuilder entity = EntityBuilder.Generate().WithPhysics(typeof(BoxCollider2D), .5f).WithGraphics("Images/gun"); Interactive c = Ego.AddComponent <Interactive>(entity); c.InteractAction = e => EgoEvents <AttachEvent> .AddEvent(new AttachEvent(c.GetComponent <EgoComponent>(), e)); Ego.AddComponent <Mountpoint>(entity); Useable u = Ego.AddComponent <Useable>(entity); u.UseAction = e => { Transform transform = u.transform; double theta = transform.rotation.eulerAngles.z * Mathf.Deg2Rad; Vector2 force = new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)); force.Normalize(); // generate new projectile, add motion in direction at speed EgoComponent bullet = Ego.AddGameObject(GenerateBullet().gameObject); bullet.transform.rotation = transform.rotation; bullet.transform.position = transform.position; bullet.gameObject.SetActive(true); EgoEvents <SetVelocityByEvent> .AddEvent(new SetVelocityByEvent(bullet, force)); }; return(entity); }
protected override void Execute() { parent.isPregnant = false; if (parent.childPart == null) { child = Ego.AddGameObject(Object.Instantiate <GameObject>(parent.snakePrefab)).GetComponent <SnakePartComponent>(); child.snakePrefab = parent.snakePrefab; child.transform.position = position; child.transform.rotation = parent.transform.rotation; child.transform.parent = parent.container; child.container = parent.container; parent.childPart = child; //child.parentPart = parent; createdNew = true; } else { createdNew = false; if (!parent.childPart.isPregnant) { parent.childPart.isPregnant = true; var commandEvent = new CommandEvent(new PregnancyCommand(parent.childPart, position, true), 1); EgoEvents <CommandEvent> .AddEvent(commandEvent); } } }
// Use this for initialization void Start() { // TODO: Replace with spawning logic Ego.AddGameObject(EntityFactory.GeneratePlayer().gameObject); Ego.AddGameObject(EntityFactory.GenerateGun().gameObject); //Ego.AddGameObject(EntityFactory.generate ("Laser Gun", TemplateEntities.laserGun)); //EntityFactory.generate ("Zombie", TemplateEntities.zombie).SetActive (true); }
private void Reset_The_Opponents() { // // Creation of Opponents under OpponentContainer // constraint.ForEachGameObject( (egoComp, transform, opponents) => { // // Player's car is the origin of the spawn point for all others // The opponents use the Player's car as offset to place themselves // var spawnX = opponents.spawnOrigin.position.x + Mathf.Abs(opponents.spawnOrigin.position.x / 2.0f); var spawnY = opponents.spawnOrigin.position.y; // // destroy all the kids (if any) // for (int i = 0; i < transform.childCount; i++) { Ego.DestroyGameObject(transform.GetChild(i).GetComponent <EgoComponent>()); } // // Setup of opponent cars as children // for (int cnt = 0; cnt < opponents.maxCars; cnt++) { // // create object from prefabs in Assets/Resources folder // Give it a name starting with "Opps_" plust a number // Give it a sprite renderer so it can be displayed // Give it a position offset on x-axis from the player car // GameObject oppsObj = GameObject.Instantiate(Resources.Load("Opponent", typeof(GameObject))) as GameObject; oppsObj.name = "Opps_" + cnt.ToString(); oppsObj.transform.parent = transform; // // Get the sprite renderer component & change the location // SpriteRenderer oppsRender = oppsObj.GetComponent <Renderer>() as SpriteRenderer; // // Add spawn X to width of the car multiply by count // var x = (spawnX) + ((oppsRender.bounds.extents.x * 3.0f) * cnt); var y = spawnY; oppsRender.transform.localPosition = new Vector2(x, y); // // Add OpponentCarComponent & SpeedComponent to this GameObject // oppsObj.AddComponent <OpponentCarComponent>(); oppsObj.AddComponent <SpeedComponent>(); // // Get the SpeedComponent var sc = oppsObj.GetComponent <SpeedComponent>(); sc.speed = (Random.value * 0.02f); // // Tell EgoCS about this GameObject // var oppsEgo = Ego.AddGameObject(oppsObj); } } ); }
private EntityBuilder(GameObject entity) { Entity = Ego.AddGameObject(entity); }