public PowerUp(Vector2 spawn, PowerUp.TYPE type) { this.type = type; this.spawn = spawn; switch (type) { case TYPE.big: animation = Animation.createSingleFrameAnimation("player/powerbig", spawn, 1.0f); pULight = new Light(new Color(0.2f, 0.2f, 1f), animation.position, Constants.POWERUPLIGHTPOWER * 2, Constants.POWERUPLIGHTSIZE); break; case TYPE.pierce: animation = Animation.createSingleFrameAnimation("player/powerpierce", spawn, 1.0f); pULight = new Light(new Color(1f, 1f, 0.2f), animation.position, Constants.POWERUPLIGHTPOWER * 2, Constants.POWERUPLIGHTSIZE); break; case TYPE.shield: animation = Animation.createSingleFrameAnimation("player/powershield", spawn, 1.0f); pULight = new Light(new Color(0.2f, 1f, 0.2f), animation.position, Constants.POWERUPLIGHTPOWER * 2, Constants.POWERUPLIGHTSIZE); break; case TYPE.speed: animation = Animation.createSingleFrameAnimation("player/powerspeed", spawn, 1.0f); pULight = new Light(new Color(1f, 0.2f, 0.2f), animation.position, Constants.POWERUPLIGHTPOWER * 2, Constants.POWERUPLIGHTSIZE); break; } this.activeTime = Constants.POWERUPTIMER; this.respawnTimer = Constants.POWERUPRESPAWN; animation.setScale(Constants.POWERUPSCALE); }
public Disk(Player p, String name, Vector2 position, Color light) { player = p; animation = Animation.createSingleFrameAnimation(name, position, 0.85f); disklight = new Light(light, animation.position, Constants.DISKLIGHTPOWER * 2, Constants.DISKLIGHTSIZE); diskVelocity = Constants.DISKVELOCITY; diskRadius = Constants.DISKRADIUS; diskPierce = false; }
public Particle(Animation anim, float time, Vector2 velocity, Vector2 acceleration, bool decay) { this.anim = anim; this.time = time; totaltime = time; this.velocity = velocity; this.acceleration = acceleration; this.decay = decay; }
public Player(Vector2[] spawn, int num, GameState gameState) { this.num = num; this.spawn = spawn; this.gameState = gameState; switch (num) { case 1: animation = Animation.createSingleFrameAnimation("player/redplayer", spawn[num-1], 0.9f); disk = new Disk(this, "player/reddisk", spawn[num - 1] + new Vector2(0, 20), new Color(0.8f, 0.1f, 0.1f)); playerlight = new Light(new Color(1f, 0.2f, 0.2f), animation.position, Constants.PLAYERLIGHTPOWER * 2, Constants.PLAYERLIGHTSIZE); break; case 2: animation = Animation.createSingleFrameAnimation("player/yellowplayer", spawn[num - 1], 0.9f); disk = new Disk(this, "player/yellowdisk", spawn[num - 1] + new Vector2(0, 20), new Color(0.8f, 0.8f, 0.1f)); playerlight = new Light(new Color(1f, 1f, 0.2f), animation.position, Constants.PLAYERLIGHTPOWER, Constants.PLAYERLIGHTSIZE); break; case 3: animation = Animation.createSingleFrameAnimation("player/greenplayer", spawn[num - 1], 0.9f); disk = new Disk(this, "player/greendisk", spawn[num - 1] + new Vector2(0, 20), new Color(0.1f, 0.8f, 0.1f)); playerlight = new Light(new Color(0.2f, 1f, 0.2f), animation.position, Constants.PLAYERLIGHTPOWER, Constants.PLAYERLIGHTSIZE); break; case 4: animation = Animation.createSingleFrameAnimation("player/blueplayer", spawn[num - 1], 0.9f); disk = new Disk(this, "player/bluedisk", spawn[num - 1] + new Vector2(0, 20), new Color(0.1f, 0.1f, 0.8f)); playerlight = new Light(new Color(0.2f, 0.2f, 1f), animation.position, Constants.PLAYERLIGHTPOWER * 2, Constants.PLAYERLIGHTSIZE); break; } speedPUAnimation = Animation.createSingleFrameAnimation("player/orangepowerup", spawn[num - 1], 0.95f); speedPUAnimation.setVisible(false); shieldPUAnimation = Animation.createSingleFrameAnimation("player/shieldpu", spawn[num - 1], 1.0f); shieldPUAnimation.setVisible(false); shieldPUAnimation.setScale(20f); animation.setScale(Constants.PLAYERSCALE); disk.setScale(Constants.PLAYERSCALE); speedPUAnimation.setScale(Constants.PLAYERSCALE); shieldPUAnimation.setScale(Constants.PLAYERSCALE); powerUps = new List<PowerUp>(); random = new Random(num); }
/// <summary> /// Adds a given animation to the User Interface /// Animations that are part of the UI are drawn in absolute screen coordinates /// </summary> /// <param name="anim">The anination to add to the UI</param> public void addAnimation(Animation anim) { animations.Add(anim); anim.setAsUI(); }
/// <summary> /// Removes a given animation from the UI and rendering engine /// </summary> /// <param name="anim">The animation to remove</param> public void removeAnimation(Animation anim) { anim.removeFromRenderingEngine(); animations.Remove(anim); }
public Tile(TILE type, float x, float y, WALL wall) { this.type = type; this.wall = wall; switch (type) { case TILE.floor: anim = Animation.createSingleFrameAnimation("tiles/floor", new Vector2(x, y), 0.1f); break; case TILE.wall: switch (wall) { case WALL.bounce: anim = Animation.createSingleFrameAnimation("tiles/stickwall", new Vector2(x, y), 0.1f); break; case WALL.destr: anim = Animation.createSingleFrameAnimation("tiles/breakwall", new Vector2(x, y), 0.1f); break; case WALL.pass: anim = Animation.createSingleFrameAnimation("tiles/passwall", new Vector2(x, y), 1.0f); break; default: anim = Animation.createSingleFrameAnimation("tiles/wall", new Vector2(x, y), 0.1f); break; } break; } }
public Tile(TILE type, float x, float y) { this.type = type; switch (type) { case TILE.floor: anim = Animation.createSingleFrameAnimation("tiles/floor", new Vector2(x, y), 0.1f); break; case TILE.wall: anim = Animation.createSingleFrameAnimation("tiles/wall", new Vector2(x, y), 0.1f); break; } }
/// <summary> /// Checks to see if an animation is on screen. O(1) complexity, though not very efficient: /// checks 9 points in and around the animation to see if any of them are on screen /// </summary> /// <param name="anim">The animation to check</param> /// <returns>whether the animation is on screen</returns> private bool checkOnScreen(Animation anim) { Vector2 bb = (anim.position - camera.getRefPoint()) * camera.getScale() + new Vector2(w / 2, h / 2); if (!checkNearby(bb)) return false; Vector2 aa = (anim.position - camera.getRefPoint() + new Vector2(anim.getWidth() / 2, anim.getHeight() / 2)) * camera.getScale() + new Vector2(w / 2, h / 2); Vector2 ab = (anim.position - camera.getRefPoint() + new Vector2(0, anim.getHeight() / 2)) * camera.getScale() + new Vector2(w / 2, h / 2); Vector2 ac = (anim.position - camera.getRefPoint() + new Vector2(-anim.getWidth() / 2, anim.getHeight())) * camera.getScale() + new Vector2(w / 2, h / 2); Vector2 ba = (anim.position - camera.getRefPoint() + new Vector2(anim.getWidth() / 2, 0)) * camera.getScale() + new Vector2(w / 2, h / 2); Vector2 bc = (anim.position - camera.getRefPoint() + new Vector2(-anim.getWidth() / 2, 0)) * camera.getScale() + new Vector2(w / 2, h / 2); Vector2 ca = (anim.position - camera.getRefPoint() + new Vector2(anim.getWidth() / 2, -anim.getHeight() / 2)) * camera.getScale() + new Vector2(w / 2, h / 2); Vector2 cb = (anim.position - camera.getRefPoint() + new Vector2(0, -anim.getHeight() / 2)) * camera.getScale() + new Vector2(w / 2, h / 2); Vector2 cc = (anim.position - camera.getRefPoint() + new Vector2(-anim.getWidth() / 2, -anim.getHeight() / 2)) * camera.getScale() + new Vector2(w / 2, h / 2); if (checkOnScreen(aa) || checkOnScreen(ab) || checkOnScreen(ac) || checkOnScreen(ba) || checkOnScreen(bb) || checkOnScreen(bc) || checkOnScreen(ca) || checkOnScreen(cb) || checkOnScreen(cc)) return true; return false; }
/// <summary> /// Removes the given animation from the rendering engine /// </summary> /// <param name="item">The animation to be removed</param> public void removeAnimation(Animation item) { animations.Remove(item); }
/// <summary> /// Makes sure the provided animation exists in RenderingEngine (adds it if not) /// </summary> /// <param name="anim">the animation to be made sure is part of the engine</param> public void ensureAdded(Animation anim) { if (!animations.Contains(anim)) animations.Add(anim); }
/// <summary> /// Adds a single-frame animation to the rendering engine /// </summary> /// <param name="anim">the animation to add (should be single-frame)</param> /// <param name="colorname">the name of the color map file</param> /// <param name="normalname">the name of the normal map file</param> public void addAnimation(Animation anim, String colorname, String normalname) { animations.Add(anim); if (!singletextures.ContainsKey(colorname)) singletextures[colorname] = requestTexture(colorname); if (!singletextures.ContainsKey(normalname)) singletextures[normalname] = requestTexture(normalname); anim.setSingleColorSheet(singletextures[colorname]); anim.setSingleNormalsSheet(singletextures[normalname]); }
/// <summary> /// Adds an animation to the rendering engine (so it can be rendered) /// </summary> /// <param name="anim">The animation to be added</param> /// <returns>The spritesheet the animation will need to use</returns> public SpriteSheet addAnimation(Animation anim) { animations.Add(anim); if (sheetmap.ContainsKey(anim.sheetname)) { return sheetmap[anim.sheetname]; } else { sheetmap[anim.sheetname] = new SpriteSheet(anim.sheetname); return sheetmap[anim.sheetname]; } }
/// <summary> /// Rudimentary collision detection between two animation /// </summary> /// <param name="other">The animation to check this one against</param> /// <returns>whether the two animation hit</returns> public bool checkHit(Animation other) { if (other == null) return false; float top1 = position.Y - getHeight() / 2, top2 = other.position.Y - other.getHeight() / 2; float bot1 = position.Y + getHeight() / 2, bot2 = other.position.Y + other.getHeight() / 2; float l1 = position.X - getWidth() / 2, l2 = other.position.X - other.getWidth() / 2; float r1 = position.X + getWidth() / 2, r2 = other.position.X + other.getWidth() / 2; if (top1 < bot2 && bot1 > top2 && l1 < r2 && r1 > l2) return true; return false; }