Jump to content
  • Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

16 Neutral

About ethancodes

  • Rank

Personal Information

  • Role
  • Interests

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. ethancodes

    Issue with my pick up queue system

    Yes, I want only one active at a time. Checking to see if we should deactivate it each frame made the most sense to me that way if it's done, it can immediately get deactivated and then on the next frame the next one will be activated. I'm certainly open to better options if you've got any ideas.
  2. I'm working on a system for my game that will allow the player to stack pick ups in a queue. As one pick up expires, the next automatically activates. I'm having an issue though where if I pick up the first one, it activates fine, but if i pick up a second directly after it, it overrides the first one, activates the second one, and then once it has run it's course, everything goes back to normal gameplay, no first pick up. I'm not sure why this is happening. Hopefully someone can spot what I'm doing wrong in my code. Here is the code for the pick up manager: // Update is called once per frame void Update () { if (pickUpQueue.Count != 0 && !pickUpActive) { pickUpActive = true; pickUpQueue[0].ActivatePickUp(); } DeactivatePickUp(); } void DeactivatePickUp () { if (pickUpQueue.Count != 0 && pickUpActive) { Destroy (pickUpQueue [0]); pickUpQueue.RemoveAt (0); pickUpActive = false; } } And here is the PickUp: public override void ActivatePickUp () { ball.GetComponent<Ball>().Speed = 2.0f; //increase ball speed... ball.GetComponent<Ball>().StartCoroutine(timer); //...set time that power up is active } There is also a Base Pick Up: public void OnCollisionEnter2D (Collision2D collision) { Vector2 tweak = new Vector2 (Random.Range(0f, 0.2f),Random.Range(0f, 0.2f)); this.gameObject.GetComponent<Rigidbody2D>().velocity += tweak; //if the pickup makes contact with the paddle or ball.... if (collision.gameObject.tag == "Paddle" || collision.gameObject.tag == "Ball") { GameObject.FindObjectOfType<GameManager>().GetComponent<PickUpManager>().pickUpQueue.Add(this); Destroy(gameObject); //...and finally destroy power up object } } As a side note, I am trying to find a solution to this that will work for all of my pickups. Some pickups are ammo based, some are timed.
  3. ethancodes

    examples of how pickups are handled

    I really want to learn the observer pattern, however I think I found a solution that is going to really cut out a lot of code, so I'm going to go with that.
  4. ethancodes

    examples of how pickups are handled

    Hmmmm this is closer I think but it's not always the Paddle it will collide with, sometimes it might be the ball. If I made the PowerUpManager static and put it on the ball and the paddle, would that male it so it would all track in one place no matter which object the pick up hits?
  5. ethancodes

    examples of how pickups are handled

    This was initially how I had the simpler pick ups set up. However, the other pick ups I'm working on do things like "when the main ball comes back and hits the paddle, if a spread shot pick up is active, shoot several balls out from the paddle. And this will be active for a certain number of shots. So I need a way to manage this, as well as managing those extra balls because all the balls will be destroyed on impact (except the last one). Also, my pick ups line up in a queue. So if I have a fast ball active but then I grab a spread shot, I don't want fast ball and spread shot both active. Spread shot would be on stand by in the queue.
  6. ethancodes

    examples of how pickups are handled

    I'm not sure what you mean exactly by that last line. "applies the effect to the player it collides with." I created a PickUpManager and I'm planning on have it track the pick ups in the queue, as well as apply all effects the pick ups do. So the pick ups themselves will basically just be a ball bouncing around until it hits the main ball or the paddle, in which case an instance of the pick up gets added to a list. The update function on the PickUpManager will then find that and activate it accordingly. I'm trying to figure out how to let hte PickUpManager know about the collision between the pickup and ball or paddle. It needs to know that the collision happened and what type of pick up it was. I thought the observer pattern would be a good way to do this, but I'm open to different options.
  7. ethancodes

    examples of how pickups are handled

    I'm trying to figure out the Observer pattern. I haven't used it before but most examples look pretty straight forward. However, some parts of my setup are making it a bit more difficult. I believe I've got the observable item set up correctly, that would be on the BasePickUp class, that way all pick ups that implement that are observable. That is this code here: public event EventHandler PickUpCollected; //Event to raise if pick up is collected protected void OnPickUpCollected (EventArgs e) //Notify observers if event is raised { if (PickUpCollected != null) { PickUpCollected(this, e); } } And I believe what I'm wanting to do is to set up the observer part on the PickUpManager, so that it is notified any time a PickUp is collected. The things I'm not sure about are: 1. The basic structure of the observer, since the pickups will be spawned and are not something that is just hard coded to be subscribed to. 2. how to let the PickUpManager know which pickup was collected so that it may react accordingly. I found this site here: https://www.codeproject.com/Articles/1084848/Implementing-Observer-Pattern-with-Events-Csharp and it does a pretty good idea of explaining the simple version, but I'm still very confused.
  8. ethancodes

    examples of how pickups are handled

    This gives me some ideas and I'm slowly starting to piece this whole thing together. I'm considering using the observer pattern by having a PickUpManager that listens to each of the pick ups. When the pick up gets collected, it destroys itself and sends the info to it's listeners, in this case it would most likely be just the PickUpManager. The PickUpManager will then know which PickUp was destroyed, and can create an instance of that PickUp in it's List<BasePickUp>. When it adds a pickup to the list, it sets a bool hasPickUp to true. Update function will check that bool every frame. If it is false, the game just continues, if it is true, it checks the first item in the list, finds out what kind of pickup it is, and calls a method based on that pick up to activate it. If it is a fast ball pickup, the ball goes faster for a limited time, then goes back to normal speed after the timed coroutine is finished. At this point, the object in the list is destroyed and the next in line steps up, if there is one. If there isn't one, we set hasPickUp to false and the game continues. Where I'm having a hard time is with the multishot pickups. The object in the list could hold information on how many shots there are. But is there a way for me to check if the ball hit the paddle from the PickUpManager? Can I do something that translates to "If multishot pick up is active, watch for ball collision with paddle"? If so, how would I do that? I think if I can figure out this part, I can finally piece this thing together and have a pretty solid base to build off of.
  9. I'm wondering if anyone has any examples or tips/ideas on how to handle pickups in a game. The game is an arkanoid style game. I'm going to have at least 5 different pick up types, and they are going to be in a queue, where only one can be active at a time. Once one pick up is expended, the next one should automatically start up. Some of the pick ups have an immediate effect, such as ball speed. Others will activate when the pickup is hit, but doesn't actually do anything until the ball hits the paddle. Those type of pick ups have a limited number of shots instead of a time limit. What I'm trying to figure out is what kind of structure I should have for a system like this? I'm just curious how these things are handled in other games, especially if anyone has any examples that would be great. Thank you!
  10. ethancodes

    Error for missing Rigidbody2D

    No neither one. It's not even like the LevelManager even spawns the pickups because currently I'm just dropping the prefabs into the hierarchy. One thing that just came to mind, and this is a bit of a long shot but I'll check it when I get home, but I suppose it is possible I dropped the pick ups onto the LevelManager in the hierarchy by accident, making them children of it. That would explain why I didn't get this error before. Could just be a stupid mistake. I'll check tonight.
  11. ethancodes

    Error for missing Rigidbody2D

    It's attached to the BasePickUp class, which is an abstract class. The sub classes of it are the scripts for each of my pick ups.
  12. ethancodes

    Error for missing Rigidbody2D

    I guess I'm confused though as to why it's moving the LevelManager. The script isn't attached to the level manager and I'm not calling it by name or anything anywhere.
  13. Hopefully this is an easy fix, but I'm getting an error for trying to access the Rigidbody2D on my LevelManager gameobject. Now, I would understand this no problem, except I'm not trying to access my LevelManager anywhere. At least not intentionally. I found the line of code that is causing the error is here: void Awake () { this.GetComponent<Rigidbody2D> ().velocity = new Vector2 (2f, 10f); } This is a method on my BasePickUp abstract class. This class has several child classes that are implemented on a few pick ups. I tried changing 'this' to 'gameObject', but got the same results. And the code is doing what I want. If I take it out, the pickups just fall slowly down the screen, put the code back in and the pickups shoot off in a certain direction just like I want. So it is working, but it's also causing this weird error. Any ideas?
  14. I should have said the Ball GameObject will have the Ball script attached to them. Sorry for that. As for the rest, thanks for this. It's given me a better idea on how to break things down and also helped remind me that things don't have to be perfect the first time. They just have to work. Theres always room for refactoring later. After playing with it awhile, I've gotten some decent progress and I think I've almost got it working. Thanks!
  15. I'm trying to make a pick up that add's 4 specials "shots" when it gets picked up. The game is a brick breaker style game and when the ball hits the paddle, if we have any of the special shots left, the original ball should bounce back like normal, but there should be 7 additional balls instantiating in quick succession and those balls should all follow the first ball directly. As the balls hit objects, either bricks, walls, or anything else, they will be destroyed. The last remaining ball will become the new mainBall and will continue the gameplay like normal. All the additional balls that spawn should spawn right from the paddle and then shoot outward. I'm not so concerned about them hitting the exact same place as the first ball, as I am with them moving the same way. So if the player very quickly moves the paddle after impact, the balls may fire in a scattered line. So far, I have come up with the idea of having a Ball class that will be attached to each Ball instance. This should have basic ball behavior or attributes attached to it such as Speed, and then I would have a BallManager class that handles any modifications, spawning, destroying of balls. But I'm not sure what exactly needs to be in the Ball class and what need to be in the BallManager class. And I'm not sure how to handle the spawning and destroying, etc. I've tried to write several different forms of pseudocode to try to come up with something that makes sense, but I keep running into problems. Any ideas?
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!