Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


JDCAce

Member Since 11 Nov 2008
Offline Last Active Oct 22 2012 11:13 PM

Topics I've Started

Letting a class see another object's variables

20 October 2012 - 09:47 PM

I have a functional pong game, and I'd like to add powerups (such as increase paddle size). I've created a Powerup class, and I'd like to let it handle all the powerup business. However, I'm not sure how to let my Powerup class see the variables of one of my Paddle class objects. That is, I'd like to use paddleLeft.height += paddleLeft.Height in my Powerup class to double the size of the left paddle (but leave the right paddle alone). However, paddleLeft is an instance of my Paddle class, and it's made in my Game1 class. Is there a way to let my Powerup class know I have a paddleLeft instance, and give my Powerup class access to its variables? I could add parameters to the Powerup constructor, but that doesn't seem efficient. Is there another way?

Trouble conceptualizing power-ups

07 October 2012 - 01:04 AM

I've built a basic pong game, but I'd like to add powerups that will increase or decrease paddle size or ball speed, or do other stuff. However, I'm having trouble coming up with how to implement them in a object-oriented way. Should I make a Powerup class? How do I make different instances have different effects? Should I create a separate class for each type of Powerup?

Still confused about "static"

06 October 2012 - 02:09 AM

I am still perplexed by the use of the "static" keyword. I have read that a static method can be used without creating an instance of the class that contains it, but why is this beneficial? I think an example would really help my understanding. Also, what is the purpose of a declaring a variable as static when the method was not declared static (if there is a purpose)?

Pong Hit Detection

28 September 2012 - 10:26 PM

EDIT: I have solved my problem. All I needed was to change the send and third ifs to if elses. If anyone could tell me why this is, I'd love to know.

I've made a simple pong game, using Rectangle.Intersects(Rectangle) for hit detection. However, I'd like some more variability, so I want the ball to move differently depending on the spot on the paddle it was hit. [Ball movement has an XSpeed value and a YSpeed value, and each Update the ball moves along the X-axis a number of pixels equal to XSpeed; ditto for Y-axis and YSpeed.]

This is what is intended:
If the ball hits the top third of the paddle, YSpeed decreases by 1. If the ball hits the middle third of the paddle, YSpeed doesn't change. If the ball hits the bottom third of the paddle, YSpeed increases by 1. If the ball hits any part of the paddle, the XSpeed is reversed.

However, since I subdivided the paddles into three Rectangles, hit detection no longer functions properly. The ball changes direction only if the middle third of the paddle is hit, and the ball just flies through the top and bottom thirds.

This is really weird. I can not find the error. I've gone over the code several times, but I'm just stuck.


[source lang="csharp"]private void checkHit(){ Rectangle paddle1RectTop = new Rectangle(paddle1.X, paddle1.Y, paddleTexture.Width, paddleTexture.Height / 3); Rectangle paddle1RectMid = new Rectangle(paddle1.X, paddle1.Y + paddleTexture.Height / 3, paddleTexture.Width, paddleTexture.Height / 3); Rectangle paddle1RectBot = new Rectangle(paddle1.X, paddle1.Y + paddleTexture.Height * (2/3), paddleTexture.Width, paddleTexture.Height / 3); Rectangle paddle2RectTop = new Rectangle(paddle2.X, paddle2.Y, paddleTexture.Width, paddleTexture.Height / 3); Rectangle paddle2RectMid = new Rectangle(paddle2.X, paddle2.Y + paddleTexture.Height / 3, paddleTexture.Width, paddleTexture.Height / 3); Rectangle paddle2RectBot = new Rectangle(paddle2.X, paddle2.Y + paddleTexture.Height * (2/3), paddleTexture.Width, paddleTexture.Height / 3); Rectangle ballRect = new Rectangle(ball.X, ball.Y, ballTexture.Width, ballTexture.Height); Boolean hasHitPaddle1Top = paddle1RectTop.Intersects(ballRect); Boolean hasHitPaddle1Mid = paddle1RectMid.Intersects(ballRect); Boolean hasHitPaddle1Bot = paddle1RectBot.Intersects(ballRect); Boolean hasHitPaddle2Top = paddle2RectTop.Intersects(ballRect); Boolean hasHitPaddle2Mid = paddle2RectMid.Intersects(ballRect); Boolean hasHitPaddle2Bot = paddle2RectBot.Intersects(ballRect); if(hasHitPaddle1Top || hasHitPaddle2Top) { ball.XSpeed = -ball.XSpeed; ball.YSpeed = ball.YSpeed - 1; } if(hasHitPaddle1Mid || hasHitPaddle2Mid) { ball.XSpeed = -ball.XSpeed; } if(hasHitPaddle1Bot || hasHitPaddle2Bot) { ball.XSpeed = -ball.XSpeed; ball.YSpeed = ball.YSpeed + 1; }}[/source]

Starting Puzzle With Solution

22 September 2012 - 11:31 PM

I've decided to make a clone of the open-source Android game Scrambled Net, but with XNA and for PCs. (Basically, you have one "power node" and have to rotate wires so all computers are connecting to the power node.) So far, I've been able to put random tiles on the board and have them rotate when clicked. Now comes the daunting task of the puzzle logic. I thought it would be easier to put a "solved" puzzle on the board and simply rotate the tiles randomly from there. (The user will not be able to see the solved state, of course.) That means all the necessary tiles are in their places; the user just needs to rotate them correctly. But I'm stuck: How do I generate a "solution?"

I don't even know where to begin. Is this project too complicated for a beginner? Should I pick something simpler, like tic-tac-toe?

PARTNERS