Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8939897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:55:01+00:00 2026-06-15T10:55:01+00:00

Here is the gameplay. There is three condition. The player step on a Switch-Tile

  • 0

Here is the gameplay. There is three condition.

The player step on a Switch-Tile and it became false.

1) When the Enemy step on it (trapped) AND the player step on it too, the Enemy will be destroyed.

2) But when the Enemy step on it AND the player DIDN’T step on it too, the Enemy will be escaped.

3) If the Switch-Tile condition is true then nothing happened. The effect is activated when the Switch tile is false (player step on the Switch-Tile).

Because there are a lot of Enemy and a lot of Switch-Tile, I have to use foreach loop.

The problem is after the Enemy is ESCAPED (case 2) and step on another Switch-Tile again, nothing happened to the enemy!

I didn’t know what’s wrong. The effect should be the same, but the Enemy pass the Switch tile like nothing happened (They should be trapped)

Can someone tell me what’s wrong?

Here is the code :

public static void switchUpdate(GameTime gameTime)
        {
            foreach (SwitchTile switch in switchTiles)
            {
                foreach (Enemy enemy in EnemyManager.Enemies)
                {
                    if (switch.Active == false)
                    {                    
                        if (!enemy.Destroyed)
                        {                                
                            if (switch.IsCircleColliding(enemy.EnemyBase.WorldCenter,
                                enemy.EnemyBase.CollisionRadius))
                            {                                    
                                enemy.EnemySpeed = 10; //reducing Enemy Speed if it enemy is step on the Tile (for about two seconds)
                                enemy.Trapped = true;
                                float elapsed = (float)gameTime.ElapsedGameTime.Milliseconds;
                                moveCounter += elapsed;
                                if (moveCounter> minMoveTime)
                                {
//After two seconds, if the player didn't step on Switch-Tile.
//The Enemy escaped and its speed back to normal
                                    enemy.EnemySpeed = 60f;
                                    enemy.Trapped = false;
                                }
                            }
                        }
                    }

                    else if (switch.Active == true && enemy.Trapped == true
                        && switch.IsCircleColliding(enemy.EnemyBase.WorldCenter,
                                enemy.EnemyBase.CollisionRadius)
                        )
                    {
//When the Player step on Switch-Tile and 
//there is an enemy too on this tile which was trapped = Destroy Enemy  

                        enemy.Destroyed = true;                            
                    }
                }

            }
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:55:02+00:00Added an answer on June 15, 2026 at 10:55 am
               else if (switch.Active == true && enemy.Trapped == true
                    && switch.IsCircleColliding(enemy.EnemyBase.WorldCenter,
                            enemy.EnemyBase.CollisionRadius)
                    )
                {
                    //When the Player step on Switch-Tile and 
                    //there is an enemy too on this tile which was trapped = Destroy Enemy  
    
                    enemy.Destroyed = true;                            
                }
    

    This code will never be true since you set whether the enemy is trapped or not only if the switch is not active. Once you set it to true you should really break out the loop and then test again to see whether you should destroy the enemy or not.

    Rethink the logic you want to do, and ensure that at each stage you can gain access to the correct information for the enemy etc.

    P.S You do NOT need to use a foreach loop. You could easily use a for loop and iterate over the container or if you were really sadistic you could simple hardcode for every enemy yourself. Foreach loops are simply one way to solve this kind of issue, just because they can be used, doesnt mean you need to use them 😉

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make td elements clickable. Here's my HTML: <td id=A3 class= open-square><a href=/gameplay/A3></a></td>
In my spelling game new words will be added all the time so there
Here is my GamePlay.as package com.work.scripts { import flash.display.Stage; import flash.events.Event; import flash.utils.Timer; import
Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is my work environment: Eclipse Juno as IDE with maven2 plugin on it
Here is what I am currently doing. PHP echo's out the recent post in
Here is the Javascript I currently have <script type=text/javascript> $(function() { $('.slideshow').hover( function() {

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.