Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        public void UpdateStatus()
        {
            var     isLeftPressed   = Mouse.GetState().LeftButton == ButtonState.Pressed;
            Vector2 mousePos        = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            var     isMouseInObject = Trash.IsInRect(mousePos, rectDraw);

            switch (this.status)
            {
            case TrashStatus.DISPOSED:
                break;

            case TrashStatus.SELECTED:
                if (!isLeftPressed)
                {
                    this.status = TrashStatus.IDLE;
                    hasSelected = false;
                }
                break;

            case TrashStatus.IDLE:
                if (isLeftPressed && isMouseInObject && !hasSelected)
                {
                    this.status = TrashStatus.SELECTED;
                    hasSelected = true;
                }
                break;
            }
        }
Esempio n. 3
0
 public int Score(Trash trash)
 {
     if (trash.Type == this.Type)
     {
         return(this.correctScore);
     }
     else
     {
         return(this.wrongScore);
     }
 }
Esempio n. 4
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);
        }