Exemple #1
0
 public override void Draw(GameTime gametime)
 {
     spriteBatch.Begin();
     spriteBatch.Draw(TrashImage.GetImage("bg-organize"), new Rectangle(0, 0, 800, 600), Color.White);
     foreach (var trash in trashes)
     {
         if (trash.Status != TrashStatus.DISPOSED)
         {
             if (trash.Status == TrashStatus.IDLE)
             {
                 spriteBatch.Draw(TrashImage.GetImage(trash.Name), trash.RectDraw, Color.White);
             }
             else
             {
                 Rectangle rect = trash.RectDraw;
                 rect.Width  *= 3; rect.Width /= 2;
                 rect.Height *= 3; rect.Height /= 2;
                 spriteBatch.Draw(TrashImage.GetImage(trash.Name), rect, Color.White);
             }
         }
     }
     foreach (var trashbin in trashbins)
     {
         spriteBatch.Draw(TrashImage.GetImage(trashbin.Name), trashbin.RectDraw, Color.White);
     }
     spriteBatch.DrawString(spriteFont, "Score : " + this.score.ToString(), new Vector2(350, 0), Color.Black);
     spriteBatch.Draw(TrashImage.GetImage("cursor-organize"), TrashImage.GetSize("cursor-organize"), Color.White);
     spriteBatch.End();
 }
Exemple #2
0
        public void SetPosition()
        {
            int x, y, dx, dy;
            int min_x, max_x, min_y, max_y;

            min_x = 5; max_x = 700;
            min_y = 5; max_y = 400;
            x     = 5; y = 5;
            dx    = 130; dy = 130;
            for (int i = 0; i < trashes.Count; i++)
            {
                trashes[i].RectDraw = TrashImage.GetSize(trashes[i].Name);
                trashes[i].RectDraw = new Rectangle(x, y, trashes[i].RectDraw.Width, trashes[i].RectDraw.Height);
                y += dy;
                if (y > max_y)
                {
                    y = min_y; x += dx;
                    if (x > max_x)
                    {
                        x = min_x;
                    }
                }
            }
            for (int i = 0; i < 2; ++i)
            {
                trashbins[i].RectDraw = TrashImage.GetSize(trashbins[i].Name);
                trashbins[i].RectDraw = new Rectangle(i * 500 + 100, 500, trashbins[i].RectDraw.Width, trashbins[i].RectDraw.Height);
            }
        }
        public override void Initialize()
        {
            this.LoadContent();
            //load sebanyak organic dan inorganic
            for (int i = 0; i < norganic + ninorganic; ++i)
            {
                Trash t = new Trash();
                t.Type = (i < norganic) ? TrashType.ORGANIC : TrashType.INORGANIC;
                t.Name = TrashImage.GetRandomImageName(t.Type);
                //t.RectDraw = new Rectangle(10+i*100,400,100,100);
                //t.Pos = new Vector2(10 + i * 105,10);
                trashes.Add(t);
                System.Diagnostics.Debug.WriteLine(t.Name);
            }
            //load 2 tong
            Trashbin tb = new Trashbin(3, 0);

            tb.Name = "organic-bin";
            tb.Type = TrashType.ORGANIC;
            trashbins.Add(tb);

            tb      = new Trashbin(3, 0);
            tb.Name = "inorganic-bin";
            tb.Type = TrashType.INORGANIC;
            trashbins.Add(tb);
            SetPosition();
        }
 public OrganizeTrash(GraphicsDevice dev, Game game, int norganic, int ninorganic)
 {
     device     = dev;
     name       = "OrganizeTrash";
     content    = game.Content;
     trashes    = new List <Trash>();
     trashbins  = new List <Trashbin>();
     trashImage = new TrashImage(game);
     //spriteFont = new SpriteFont();
     this.Norganic   = norganic;
     this.Ninorganic = ninorganic;
 }
Exemple #5
0
 public CollectTrash(GraphicsDevice dev, Game game)
 {
     device     = dev;
     name       = "CollectTrash";
     content    = game.Content;
     character  = new Character();
     trashes    = new List <Trash>();
     collected  = new List <Trash>();
     trashImage = new TrashImage(game);
     trashbins  = new List <Trashbin>();
     sm         = new SoundManager();
 }
Exemple #6
0
        public override void Draw(GameTime gametime)
        {
            spriteBatch.Begin();

            spriteBatch.Draw(asphalt, new Rectangle(leftTile, 0, 900, 100), Color.White);
            for (int i = 0; i < 1000 / TILE_SIZE; i++)
            {
                if ((i + parity) % 2 == 0)
                {
                    spriteBatch.Draw(blackTile, new Rectangle(leftTile + i * TILE_SIZE, 70, TILE_SIZE, 30), Color.White);
                }
                else
                {
                    spriteBatch.Draw(whiteTile, new Rectangle(leftTile + i * TILE_SIZE, 70, TILE_SIZE, 30), Color.White);
                }
            }
            for (int i = 0; i < 1000 / TILE_SIZE; i++)
            {
                for (int j = 0; j < 800 / TILE_SIZE; j++)
                {
                    spriteBatch.Draw(sidewalk, new Rectangle(leftTile + i * TILE_SIZE, 100 + j * TILE_SIZE, TILE_SIZE, TILE_SIZE), Color.White);
                }
            }

            spriteBatch.Draw(character.Image, characterPosition, character.RectDraw, Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, 1);

            foreach (var trash in trashes)
            {
                if (trash.Status != TrashStatus.DISPOSED)
                {
                    spriteBatch.Draw(TrashImage.GetImage(trash.Name), trash.RectDraw, Color.White);
                }
            }

            foreach (var trashbin in trashbins)
            {
                trashbin.RectDraw = new Rectangle(trashbin.Type == TrashType.ORGANIC ? leftBin + 70 : leftBin + 150, 90, TrashImage.GetSize(trashbin.Name).Width, TrashImage.GetSize(trashbin.Name).Height);
                if (trashbin.RectDraw.X < 800)
                {
                    spriteBatch.Draw(TrashImage.GetImage(trashbin.Name), trashbin.RectDraw, Color.White);
                }
            }

            spriteBatch.Draw(TrashImage.GetImage("cursor-organize"), TrashImage.GetSize("cursor-organize"), Color.White);

            //spriteBatch.DrawString(spriteFont, "Organik : " + Norganik + ", Inorganik : " + Ninorganik, new Vector2(350, 0), Color.White);
            spriteBatch.DrawString(spriteFont, "Waktu   : " + (GAME_TIME - gametime.TotalGameTime.Seconds) + " detik", new Vector2(550, 0), Color.White);

            spriteBatch.End();
        }
Exemple #7
0
        public override void Update(GameTime gametime)
        {
            //Kalo udah abis, ganti scene
            if (gametime.TotalGameTime.Seconds >= GAME_TIME)
            {
                OrganizeTrash._trashes = collected;
                SceneManager.Switch("OrganizeTrash");
            }

            leftTile -= (int)((float)gametime.ElapsedGameTime.TotalSeconds * TRASH_SPEED);
            if (leftTile < -TILE_SIZE)
            {
                leftTile += TILE_SIZE;
                parity    = 1 - parity;
            }
            if ((GAME_TIME - gametime.TotalGameTime.TotalSeconds) <= 5)
            {
                leftBin -= (int)((float)gametime.ElapsedGameTime.TotalSeconds * TRASH_SPEED);
            }

            Rectangle bound = new Rectangle((int)characterPosition.X, (int)characterPosition.Y, character.RectDraw.Width, character.RectDraw.Height);

            foreach (var trash in trashes)//(int i = 0; i < trashes.Count; i++)
            {
                if (trash.Status != TrashStatus.DISPOSED)
                {
                    //Gerakin sampah
                    Rectangle position = trash.RectDraw;
                    position.X    -= (int)(TRASH_SPEED * (float)gametime.ElapsedGameTime.TotalSeconds);
                    trash.RectDraw = position;

                    if (bound.Intersects(trash.RectDraw))
                    {
                        trash.Status = TrashStatus.DISPOSED;
                        collected.Add(trash);
                        if (trash.Type == TrashType.ORGANIC)
                        {
                            Norganik++;
                        }
                        else
                        {
                            Ninorganik++;
                        }
                        //bunyi?
                        sm.CueEffect(0);
                    }

                    //hancurin kalo udah nggak keliatan
                    if (trash.RectDraw.X + trash.RectDraw.Width < 0)
                    {
                        trash.Status = TrashStatus.DISPOSED;
                    }
                }
            }

            //make some new trashes
            Random rnd = new Random((int)DateTime.Now.Ticks);

            if (rnd.NextDouble() < TRASH_FREQUENCY * gametime.ElapsedGameTime.TotalSeconds)
            {
                Trash t = new Trash();
                t.Type     = rnd.Next(2) == 1 ? TrashType.ORGANIC : TrashType.INORGANIC;
                t.Name     = TrashImage.GetRandomImageName(t.Type);
                t.RectDraw = TrashImage.GetSize(t.Name);
                do
                {
                    t.RectDraw = new Rectangle(800, rnd.Next(90, 500), t.RectDraw.Width, t.RectDraw.Height);
                } while (t.RectDraw.Intersects(trashbins[0].RectDraw) || t.RectDraw.Intersects(trashbins[1].RectDraw));
                trashes.Add(t);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                if (characterPosition.Y < 450)
                {
                    characterPosition.Y += CHAR_SPEED * (float)gametime.ElapsedGameTime.TotalSeconds;
                }
            }
            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                if (characterPosition.Y > 30)
                {
                    characterPosition.Y -= CHAR_SPEED * (float)gametime.ElapsedGameTime.TotalSeconds;
                }
            }

            character.Update(gametime);

            base.Update(gametime);
        }