public static void AddToSpawnListNew(OmniObject o, int id) { if (id < 0) { return; } else { o.id = id; if (id >= instance.SpawnedObjectsNew.Count-1) { for (int i = 0; i <= (id - instance.SpawnedObjectsNew.Count)+3; i++) { instance.SpawnedObjectsNew.Add(null); } } if (instance.SpawnedObjectsNew[id] != null) instance.SpawnedObjectsNew[id].destroy(true); instance.SpawnedObjectsNew[id] = o; } o.spawned = true; o.item.Spawned(o); }
public static void InterpolatePos(OmniObject owner) { int chX = (int)(owner.lastPos.x / OmniTerrain.chunkSize); int chX2 = (int)(owner.bounds.x / OmniTerrain.chunkSize); int chY = (int)(owner.lastPos.y / OmniTerrain.chunkSize); int chY2 = (int)(owner.bounds.y / OmniTerrain.chunkSize); if (chX == 0 && chX2 == OmniTerrain.Width - 1) // lerp over the boundary { owner.lastPos.x = (OmniTerrain.Width * OmniTerrain.chunkSize) + owner.lastPos.x; } else if (chX == OmniTerrain.Width - 1 && chX2 == 0) // lerp over the boundary { owner.lastPos.x = owner.lastPos.x - (OmniTerrain.Width * OmniTerrain.chunkSize); } if (chY == 0 && chY2 == OmniTerrain.Height - 1) // lerp over the boundary { owner.lastPos.y = (OmniTerrain.Height * OmniTerrain.chunkSize) + owner.lastPos.y; } else if (chY == OmniTerrain.Height - 1 && chY2 == 0) // lerp over the boundary { owner.lastPos.y = owner.lastPos.y - (OmniTerrain.Height * OmniTerrain.chunkSize); } lerp.Set(owner.bounds.x, owner.bounds.y, 0); float l = OmniWorld.updateCounter / OmniWorld.timeStep; Vector3 result = Vector3.Lerp(owner.lastPos, lerp, l); owner.Position = result; }
public DmgTxt(int dmg,Vector3 pos,OmniObject dmged) { this.Dmg = ""+dmg; this.g = new GUIContent(Dmg); this.pos = pos; this.dmged = dmged; this.bounds = new Rect(); }
public static float getAngle(OmniObject obj, Vector3 pos, out float len) { float x2 = ((int)pos.x + 0.5f) - ((int)obj.bounds.x + 0.5f); float y2 = ((int)pos.y + 0.5f) - ((int)obj.bounds.y + 0.5f); float angle = Mathf.Atan2(y2, x2); len = new Vector2(x2, y2).magnitude; return angle; }
public override void OnStop(OmniObject player) { if (player is PhysicsObject) { int m = (1 << MovementFlags.Floating); ((PhysicsObject)player).movementMask &= ~m; ((PhysicsObject)player).accel.y = 0; } }
public DamageEvent(int tick, OmniObject damaged, OmniObject attacker, OmniItemType itemType,Vector2 vel) : base(tick) { this.damaged = damaged; this.attacker = attacker; this.itemType = itemType; this.vel = vel; type = NetworkSendType.ServerCommandAll; if (Network.isServer) hp = new Vector2(damaged.HP, attacker.HP); }
public override void OnUseTick(OmniObject player, Vector3 pos) { if (rapidFire) { if (player.mount2 >= 0) { player.mount2time = 10; Fire(player); } } }
public override void Anim(OmniObject player, float time, OmniAnimation.Type type, params Vector3[] mount) { Vector3 pos = player.position; pos.y += player.item.animList[0].mountPoint[0].y * player.item.scale.x; if (player.flipped) { pos.x += player.item.scale.x; } OmniWorld.instance.particleEmitter.Emit(pos, new Vector3(0, 0, 0), 1, 3, Color.red, (Time.realtimeSinceStartup*1000) % 360, 0); }
public override void OnTerrainCollision(OmniObject player, int x, int y) { if (OmniWorld.isDebugging) Debug.Log("OnTerrainCollision called by " + player.Name); OmniTerrain.terrainUpdates.Add(new terrainDmg(player, this,x,y)); /* BlockEvent e = new BlockEvent(OmniWorld.tick, x, y, BlockEventType.Damaged, mineSpeed); OmniEvents.AddEvent(e); * */ }
public override void Anim(OmniObject player,float time,OmniAnimation.Type type, params Vector3[] mount) { Vector3 pos = player.position; pos.y += player.item.animList[0].mountPoint[0].y * player.item.scale.x; if (player.flipped) { pos.x += player.item.scale.x; } OmniWorld.instance.particleEmitter.Emit(pos, new Vector3(0, -2, 0), 1, 15, Color.red,360 * Random.value,0); }
public override void Dead(OmniObject attacker) { base.Dead(attacker); for (int i = 0; i < mountObjects.Count; i++) { MountEvent e = new MountEvent(OmniWorld.tick + 5); e.mounting = false; e.id = mountObjects[i].obj.id; e.to = this.id; OmniEvents.AddEvent(e); } }
public override void Mount(OmniObject mountTo, int mid) { base.Mount(mountTo, mid); item.OnMount(this, mountTo); mountTo.item.OnMount(mountTo, this); mountLoc = mid; mountedTo = mountTo; mountPos = mountTo.item.animList[0].skeletonRects[mountLoc].mountPoint[0] * mountTo.item.Size; mountObject mobj = new mountObject(); mobj.obj = this; mobj.location = mountLoc; mobj.offset = mountPos; }
public virtual void Damage(OmniObject attacker,int dmg) { HP -= dmg; if (HP <= 0) { if (!isDead) { Dead(attacker); isDead = true; } } }
public override void OnStop(OmniObject player) { base.OnStop(player); if (player.mount2 < 0) return; if (!rapidFire) Fire(player); player.mount2 = -1; player.mount2time = 0; }
public virtual void Dead(OmniObject attacker) { stateTime = 0; stun = 10; rotSpeed = 900; if (!Respawnable) { DestroyEvent e = new DestroyEvent(OmniWorld.tick+10); e.objid = id; stateTime = 0; OmniEvents.AddEvent(e); } }
public void Fire(OmniObject player) { if (Network.isClient) return; Vector2 vel = new Vector2(Mathf.Cos(player.fireAngle * Mathf.Deg2Rad) * (player.mount2time * 3) * str, Mathf.Sin(player.fireAngle * Mathf.Deg2Rad) * (player.mount2time * 3) * str); if (player.flipped) vel.x *= -1; Matrix4x4 tr = player.itemMatrix[0]; Vector3 pos = tr.MultiplyPoint(Vector3.zero); SpawnEvent e = new SpawnEvent(OmniWorld.tick, OmniItems.itemTypes[player.mount2].name, pos, vel, -1, true, typeof(DamageableObject)); OmniEvents.AddEvent(e); }
public override void OmniUpdate(OmniObject owner, float delta) { base.OmniUpdate(owner, delta); if ((owner.inputMask & (1 << OmniInput.Left)) != 0) { owner.rotation += turnSpeed; } else if ((owner.inputMask & (1 << OmniInput.Right)) != 0) { owner.rotation -= turnSpeed; } if ((owner.inputMask & (1 << OmniInput.Up)) != 0) { owner.accel.y = Acceleration; } else owner.accel.y = 0; }
public override void OnClicked(OmniObject owner, OmniObject clicker) { if ((clicker.movementMask & (1 << MovementFlags.Mounted)) == 0) { clicker.movementMask |= 1 << MovementFlags.Mounted; MountEvent e = new MountEvent(OmniWorld.tick); e.mounting = true; e.id = clicker.id; e.to = owner.id; e.mid = 0; OmniEvents.AddEvent(e); } else { int m = 1 << MovementFlags.Mounted; clicker.movementMask = 0; MountEvent e = new MountEvent(OmniWorld.tick); e.mounting = false; e.id = clicker.id; e.to = owner.id; OmniEvents.AddEvent(e); } base.OnClicked(owner, clicker); }
public override void OnDamage(OmniObject damaged, OmniObject attacker, OmniItemType itemType, Vector2 vel) { Vector2 pos = damaged.Position; pos.x += damaged.item.Size / 2; pos.y += damaged.item.Size + 0.5f; int dmg = (int)(itemType.str * (vel.magnitude * 0.3f)); if (damaged is PhysicsObject) { PhysicsObject p = (PhysicsObject)damaged; p.vel += vel; if (damaged == attacker) //fall damage { dmg = (int)p.vel.magnitude*2; } } OmniInventory.drawDamageGUI(dmg, pos, damaged); if (damaged is DamageableObject) { ((DamageableObject)damaged).Damage(attacker, dmg); } }
public virtual void CheckBounds(OmniObject owner) { if (owner is PhysicsObject) { PhysicsObject physowner = (PhysicsObject)owner; animList[0].GetBoundsPos((PhysicsObject)owner, scale, owner.mount0time); physowner.numBounds = animList[0].boundsList.Length; if (owner.mount0time < 0.06) return; collisionTest((PhysicsObject)owner); int maskx = 0; int masky = 0; for (int i = 0; i < r.Count; i++) { for (int j = 0; j < physowner.numBounds; j++) { if (physowner.itemBounds[j].Overlaps(r[i])) { int xx = (int)r[i].x; int yy = (int)r[i].y; if (xx < 0) xx = OmniTerrain.Width * OmniTerrain.chunkSize + xx; else if (xx >= OmniTerrain.Width * OmniTerrain.chunkSize) { xx = (xx - (OmniTerrain.Width * OmniTerrain.chunkSize)); } if (yy < 0) yy = OmniTerrain.Height * OmniTerrain.chunkSize + yy; else if (yy >= OmniTerrain.Height * OmniTerrain.chunkSize) { yy = (yy - (OmniTerrain.Height * OmniTerrain.chunkSize)); } OnTerrainCollision(owner, xx, yy); } } } for (int i = 0; i < physowner.numBounds; i++) { for (int k = 0; k < activeChunks.Count; k++) { for (int j = 0; j < activeChunks[k].objects.Count; j++) { if (activeChunks[k].objects[j].id != owner.id) { CheckIfPlayerHit(owner.itemBounds[i], i, owner, activeChunks[k].objects[j]); if (owner.itemBounds[i].x < 0) { Rect r = owner.itemBounds[i]; r.x = OmniTerrain.Width * OmniTerrain.chunkSize + r.x; CheckIfPlayerHit(r, i, owner, activeChunks[k].objects[j]); } else if (owner.itemBounds[i].x + owner.itemBounds[i].width >= OmniTerrain.Width * OmniTerrain.chunkSize) { Rect r = owner.itemBounds[i]; r.x = r.x - (OmniTerrain.Width * OmniTerrain.chunkSize-1); CheckIfPlayerHit(r, i, owner, activeChunks[k].objects[j]); } if (owner.itemBounds[i].y < 0) { Rect r = owner.itemBounds[i]; r.y = OmniTerrain.Height * OmniTerrain.chunkSize + r.y; CheckIfPlayerHit(r, i, owner, activeChunks[k].objects[j]); } else if (owner.itemBounds[i].y + owner.itemBounds[i].height >= OmniTerrain.Height * OmniTerrain.chunkSize) { Rect r = owner.itemBounds[i]; r.y = r.y - (OmniTerrain.Height * OmniTerrain.chunkSize - 1); CheckIfPlayerHit(r, i, owner, activeChunks[k].objects[j]); } } } } } } /* bounds.width = animList[0].boundsScale.x * Size; bounds.height = animList[0].boundsScale.y * Size; Vector3 pos = new Vector3(owner.bounds.x, owner.bounds.y, 0); if (owner.flipped) { pos = animList[0].GetBoundsPos(owner, scale, owner.mount0time); bounds.x = pos.x - bounds.width;// -bounds.width / 2; bounds.y = pos.y;// -bounds.height / 2; } else { pos = animList[0].GetBoundsPos(owner, scale, owner.mount0time); bounds.x = pos.x;// -bounds.width / 2; bounds.y = pos.y;// -bounds.height / 2; } * */ }
public virtual void Anim(OmniObject player, float time,OmniAnimation.Type type,params Vector3[] mount) { animList[0].drawFrame(player, time, scale,type,mount); }
int getLimbHit(OmniObject player, Rect r, ref Vector2 pos) { if (player.skeleton == null) return -1; Rect b = new Rect(); for (int i = 0; i < player.skeleton.Length; i++) { if (player.skeleton[i].name == "bounds") continue; b.x = player.bounds.x; b.y = player.bounds.y; b.x += player.skeleton[i].bounds.x * player.item.Size; b.y += player.skeleton[i].bounds.y * player.item.Size; b.width = player.skeleton[i].bounds.width * player.item.Size; b.height = player.skeleton[i].bounds.height * player.item.Size; if (r.Overlaps(b)) { pos = new Vector2(r.x - b.x, r.y - b.y); return i; } } return -1; }
void CheckIfPlayerHit(Rect b,int i,OmniObject owner,OmniObject victim) { if (b.Overlaps(victim.bounds)) { Vector2 vel = Vector2.zero; if (owner is ControllableObject) vel = owner.itemBoundsVel[i].normalized * Mathf.Abs(((ControllableObject)owner).fireVel * 0.01f); if (owner is PhysicsObject) { PhysicsObject p = ((PhysicsObject)owner); Vector2 pos = Vector2.zero; if (p.isProjectile) { vel = p.vel * 0.3f; int limb = getLimbHit(victim, owner.itemBounds[i], ref pos); owner.item.OnHit(owner, victim, vel, pos, limb); } else { if (owner.mount0 >= 0) OmniItems.itemTypes[owner.mount0].OnHit(owner, victim, vel, new Vector2(owner.itemBounds[i].x, owner.itemBounds[i].y), getLimbHit(owner, owner.itemBounds[i], ref pos)); } } } }
public virtual void Spawned(OmniObject player) { player.Spawned(); player.skeleton = new AnimSkeleton[animList[0].skeletonRects.Length]; for (int i = 0; i < animList[0].skeletonRects.Length; i++) { player.skeleton[i] = new AnimSkeleton(animList[0].skeletonRects[i]); if (player.skeleton[i].name == "bounds") player.skelBoundsId = i; } }
public virtual void OnUseTick(OmniObject player, Vector3 pos) { }
public virtual void OnTerrainCollision(OmniObject player, int x, int y) { }
public virtual void OnStop(OmniObject player) { }
public virtual void OnMount(OmniObject owner, OmniObject mountObj) { }
public virtual void OnHit(OmniObject player, OmniObject hitPlayer, Vector2 vel,Vector2 pos,int location) { }
public virtual void OnFlip(OmniObject owner) { }