コード例 #1
0
ファイル: Particle.cs プロジェクト: Koneke/SpaceAce
 public static void Explosion(Game1 super, int amount, Vector2 position)
 {
     for(int r = 0;r<amount;r++) {
         float angle = (float)super.random.NextDouble()*360f;
         float speed = 4+(float)super.random.NextDouble();
         Particle p =
             new Particle(
                 super, 7+(int)(3*super.random.NextDouble()), position,
                 new Vector2(
                     (float)Math.Cos(MathHelper.ToRadians(angle))*speed,
                     (float)Math.Sin(MathHelper.ToRadians(angle))*speed),
                 new Vector2(2,2));
         p.color = new Color(255, super.random.NextDouble()>0.5?255:0, 0);
         super.particles.Add(p);
     }
 }
コード例 #2
0
ファイル: Player.cs プロジェクト: Koneke/SpaceAce
        public void Update()
        {
            time++;
            if(super.gps.IsConnected || (super.kbs.IsKeyDown(Keys.Enter) && !super.okbs.IsKeyDown(Keys.Enter))) {
                if(super.gps.Buttons.Start == ButtonState.Pressed || super.kbs.IsKeyDown(Keys.Enter)) {
                    super.restart();
                }
            }
            if(dead) return;
            //logic
            bulletTimer-=1;
            if(bulletTimer <= 0) {
                bullets = bulletsMax;
                bulletTimer = bulletTimerFreq;
            }

            if(rollTimer > 0) rollTimer-=1;
            if(rollTimer <= 0 && rolling) {
                rollframe += rolldir;
                if(rolldir == -1 && rollframe == 1) {
                    rolling = false;
                    rollframe = 1;
                }
                if(rolldir == 1 && rollframe == 5) {
                    rolling = false;
                    rollframe = 1;
                }
                rollTimer = rollTimerFreq;
            }

            for(int i = 0;i<super.bullets.Count;i++) {
                Bullet b = super.bullets[i];
                if(b.playerBullet) continue;
                if(!(
                    position.X-size.X/2 > b.position.X+b.size.X/2 ||
                    position.X+size.X/2 < b.position.X-b.size.X/2 ||
                    position.Y-size.Y/2 > b.position.Y+b.size.Y/2 ||
                    position.Y+size.Y/2 < b.position.Y-b.size.Y/2)) {
                    if(!rolling) {
                        hit();
                        super.bullets.Remove(b);
                    } else {
                        super.score += (int)(graceScore*super.multiplier);
                    }
                } }

            for(int i = 0;i<super.enemies.Count;i++) {
                Enemy e = super.enemies[i];
                if(!(
                    position.X-size.X/2 > e.position.X+e.size.X/2 ||
                    position.X+size.X/2 < e.position.X-e.size.X/2 ||
                    position.Y-size.Y/2 > e.position.Y+e.size.Y/2 ||
                    position.Y+size.Y/2 < e.position.Y-e.size.Y/2)) {
                    if(!rolling) {
                        hit();
                        e.die();
                    } else {
                        super.score += (int)(graceScore*super.multiplier);
                    }
                } }

            for(int i = 0;i<super.asteroids.Count;i++) {
                Asteroid a = super.asteroids[i];
                if(!(
                    position.X-size.X/2 > a.position.X+a.size.X/2 ||
                    position.X+size.X/2 < a.position.X-a.size.X/2 ||
                    position.Y-size.Y/2 > a.position.Y+a.size.Y/2 ||
                    position.Y+size.Y/2 < a.position.Y-a.size.Y/2)) {
                    if(!rolling) {
                        hit();
                        super.asteroids.Remove(a);
                    } else {
                        super.score += (int)(graceScore*super.multiplier);
                    }
                } }

            //input
            Vector2 velocity = Vector2.Zero;
            if(super.gps.IsConnected) {
                velocity = new Vector2(
                    super.gps.ThumbSticks.Left.X*speed*(rolling?1.5f:1),
                    -super.gps.ThumbSticks.Left.Y*speed*(rolling?1.5f:1));
            }

            if(super.kbs.IsKeyDown(Keys.Down)) { velocity = new Vector2(0, speed*(rolling?1.5f:1)); }
            if(super.kbs.IsKeyDown(Keys.Up)) { velocity = new Vector2(0, -speed*(rolling?1.5f:1)); }
            if(super.kbs.IsKeyDown(Keys.Left)) { velocity = new Vector2(-speed*(rolling?1.5f:1),0); }
            if(super.kbs.IsKeyDown(Keys.Right)) { velocity = new Vector2(speed*(rolling?1.5f:1),0); }

            position+=(drunken?-1:1)*velocity;

            if(position.X > super.roomSize.X || position.X < 0) {
                position.X-=(drunken?-1:1)*velocity.X;
            }
            if(position.Y > super.roomSize.Y || position.Y < 0) {
                position.Y-=(drunken?-1:1)*velocity.Y;
            }

            for(int i = 0;i<8;i++) {
                Particle p = new Particle(
                    super, 4, position-new Vector2(4,0), -velocity-new Vector2(1,1)+new Vector2((float)super.random.NextDouble(),(float)super.random.NextDouble()), new Vector2(2,2));
                p.color = i>4?new Color(1f,0f,0f):new Color(1f,1f,0f);
                super.particles.Add(p);
            }

            if(super.gps.IsConnected || super.kbs.IsKeyDown(Keys.Z)) {
                if(super.gps.Buttons.A == ButtonState.Pressed || super.kbs.IsKeyDown(Keys.Z)) {
                    if(bullets > 0 && !rolling) {
                        Bullet b = new Bullet(super, position, new Vector2(8,0), new Vector2(8,8));
                        b.texture = super.texture_bullet1;
                        b.playerBullet = true;
                        super.bullets.Add(b);
                        bullets-=1;
                        float pitch = (float)Math.Sin(MathHelper.ToRadians(5f*60*(time%60)));
                        super.sound_shot.Play(1.0f, pitch, 0f);
                    }
                }
            }

            if(super.gps.IsConnected || super.kbs.IsKeyDown(Keys.X)) {
                if((super.gps.Buttons.B == ButtonState.Pressed || super.kbs.IsKeyDown(Keys.X)) && !rolling) {
                    if(Math.Abs(super.gps.ThumbSticks.Left.Y) > 0.4 || super.kbs.IsKeyDown(Keys.X)) {
                        rolldir = Math.Sign(super.gps.ThumbSticks.Left.Y)==-1?(short)1:(short)-1;
                        rollframe = rolldir==-1?4:2;
                        rollTimer = rollTimerFreq;
                        rolling = true;
                        super.sound_roll.Play(super.EffectVolume,0f,0f);
                    }
                }
            }
        }
コード例 #3
0
ファイル: Enemy.cs プロジェクト: Koneke/SpaceAce
        public void Update()
        {
            for(int i = 0;i<8;i++) {
                Particle p = new Particle(
                    super, 4, position+new Vector2(4,0), -velocity-new Vector2(1,1)+new Vector2((float)super.random.NextDouble()*3,(float)super.random.NextDouble()), new Vector2(2,2));
                p.color = i>4?new Color(1f,0f,0f):new Color(1f,1f,0f);
                super.particles.Add(p);
            }

            for(int i = 0;i<super.bullets.Count;i++) {
                Bullet b = super.bullets[i];
                if(!b.playerBullet) continue;
                if(!(
                    position.X-size.X/2 > b.position.X+b.size.X/2 ||
                    position.X+size.X/2 < b.position.X-b.size.X/2 ||
                    position.Y-size.Y/2 > b.position.Y+b.size.Y/2 ||
                    position.Y+size.Y/2 < b.position.Y-b.size.Y/2)) {
                    super.bullets.RemoveAt(i);
                    health-=1;
                    if(health <= 0) {
                        die();
                    } else {
                        super.sound_hit.Play(super.EffectVolume*0.4f, 0f, 0f);
                        float angle = (float)super.random.NextDouble()*360f;
                        Particle p =
                            new Particle(
                                super, 10, position,
                                new Vector2(
                                    (float)Math.Cos(angle)*5,
                                    (float)Math.Sin(angle*5)),
                                new Vector2(2,2));
                        p.color = new Color(255, super.random.NextDouble()>0.5?255:0, 0);
                        super.particles.Add(p);
                    }
                }
            }
            if((position+velocity).Y < 0 || (position+velocity).Y > super.roomSize.Y) {
                velocity.Y*=-1;
            }
            this.position += this.velocity;

            if(position.X < -100) {
                super.killsSinceLeak = 0;
                super.enemies.Remove(this);
            }

            if(super.Difficulty == Game1.Difficulties.SpaceAce) {
                bulletTimer--;
                if(bulletTimer <= 0) {
                    Bullet b = new Bullet(
                        super, position, new Vector2(-8, 0), new Vector2(8,8));
                    b.texture = super.texture_bullet1;
                    super.bullets.Add(b);
                    bullets++;
                    super.sound_shot.Play(super.EffectVolume,0f,0f);
                    if(bullets >= bulletsMax) {
                        bulletTimer = bulletTimerFreq;
                        bullets = 0;
                    }
                }
            }
        }