5 Replies - 636 Views - Last Post: 29 November 2011 - 10:50 AM Rate Topic: -----

#1 JEdN   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-November 11

OpenGL game questions

Posted 29 November 2011 - 06:53 AM

I have to create a game in OpenGL with C# for some coursework and I hope someone can help me. Not too much as i'm sure you'll agree I do need to learn not just copy.

The game is basically a pie in the centre of the screen and bugs (which you have to squash) attacking the pie.

I have two current problems:

the first is that I have managed to create a bug texture to load randomly and move but I cannot get more than to appear randomly on the screen. only on top of each other. Here is what I have done wrong.

public World() 
        {
            for (float numBugs = 0; numBugs < 2; ++numBugs)
            {
                // Creates a random integer, either -2,-1,0,1,2
                m_BugPosition.X = rand.Next(-2, 2);
                m_BugPosition.Y = rand.Next(-2, 2);

                Bug bug = new Bug(
                                    new Vector2d(m_BugPosition.X, m_BugPosition.Y),
                                    new Vector2d(0.0f, 0.0f));
                m_Bugs.Add(bug);
            }
        }  


So as you can see i am creating a random for now (i will be generating a double once I've sorted it) and a new bug should appear in one of those co-ordinates.


The next problem I have is making the bug actually disappear when I click on it with my animated mallet.

Here is my code;

if (pButtons == MouseButtons.Left)
                    {
                        mouseState = MouseState.MouseClicked;

                        foreach (Bug bug in m_Bugs)
                        {
                            if (( m_Point1.X < m_BugPosition.X + 0.2f)
                            && (m_Point1.X > m_BugPosition.X - 0.2f)
                            && (m_Point1.Y < m_BugPosition.Y + 0.2f)
                            && (m_Point1.Y > m_BugPosition.Y - 0.2f))
                           
                            {
                                Bug.Remove();
                            }
                        }  
                    }

So here I am clicking with my left mouse the state changes to mouseclick so the texture changes and within that arrear it should detect the bug and remove it

Hope someone can help

thanks

This post has been edited by tlhIn`toq: 29 November 2011 - 07:44 AM
Reason for edit:: Added code tags


Is This A Good Question/Topic? 0
  • +

Replies To: OpenGL game questions

#2 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: OpenGL game questions

Posted 29 November 2011 - 07:43 AM

Reminder to all: This is course homework. We do NOT provided completed code for homework. We can help the OP understand specific concepts they are having trouble with or specific errors they don't understand.

Of course they have to tell us the specific errors first, and not just "Can you help me with my homework, its due soon."

The stages of asking for homework help on a forum
Was This Post Helpful? 0
  • +
  • -

#3 JEdN   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-November 11

Re: OpenGL game questions

Posted 29 November 2011 - 07:48 AM

View PosttlhIn`toq, on 29 November 2011 - 07:43 AM, said:

Reminder to all: This is course homework. We do NOT provided completed code for homework. We can help the OP understand specific concepts they are having trouble with or specific errors they don't understand.

Of course they have to tell us the specific errors first, and not just "Can you help me with my homework, its due soon."

The stages of asking for homework help on a forum


Of course I understand this!! Can you not read my second sentence saying I dont want too much help as I need to learn it, not copy. I would just require a point in the right direction. A brief explanation of were I need to look to change and fix something. I'm not trying to cheat. I'm asking for advice off people that know alot more than me.
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: OpenGL game questions

Posted 29 November 2011 - 07:55 AM

Could you please fill in the missing words of this sentence so we understand the problem better? This doesn't really make sense yet seems to be the core of your dilemma.

Quote

but I cannot get more than to appear randomly on the screen. only on top of each other.


I'm not sure what you are doing with this math
m_Point1.X > m_BugPosition.X - 0.2f

What is it you think .2f is going to do for you? Positining is in pixels. .2 of a pixel isn't even going to get you to the next pixel.

Position 5,5 and 5.2, 5.2 really aren't different locations.

I would recommend you put a breakpoint at the top of your foreach loop and look at the values of those .x and .y locations. I think you'll find they aren't what you think they are.

Attached Image

This is probably also part of your placement problem. You only have a variance of 4 pixels in the placement of your bugs; if I am following your code correctly.
Was This Post Helpful? 0
  • +
  • -

#5 tlhIn`toq   User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6537
  • View blog
  • Posts: 14,450
  • Joined: 02-June 10

Re: OpenGL game questions

Posted 29 November 2011 - 08:03 AM

View PostJEdN, on 29 November 2011 - 08:48 AM, said:

View PosttlhIn`toq, on 29 November 2011 - 07:43 AM, said:

Reminder to all: This is course homework. We do NOT provided completed code for homework. We can help the OP understand specific concepts they are having trouble with or specific errors they don't understand.

Of course they have to tell us the specific errors first, and not just "Can you help me with my homework, its due soon."

The stages of asking for homework help on a forum


Of course I understand this!! Can you not read my second sentence saying I dont want too much help as I need to learn it, not copy. I would just require a point in the right direction. A brief explanation of were I need to look to change and fix something. I'm not trying to cheat. I'm asking for advice off people that know alot more than me.


Congratulations rookie. You just lost my help. I don't like being yelled at and talked down to by newbies. Of course I can read that. As I said, the message was to all, which really means to other rookies who don't realize we aren't here to do other people's homework. All too often the new members of our board are anxious to help and jump in with massive amounts of completed/fixed code even when it isn't the right thing to do.

You'll also notice that I had to ask you to complete your problem description because of missing words that make it hard/impossible to follow what the actual problem is. Further you might like to work on your English skills. When you don't know the difference between 'were' and 'where' it adds to the difficulty of reading your posts. After a certain point struggling through the reading of your post just reaches a point where the reader says "Frak it" and closes the browser tab.

I'm unsubscribing from this thread now. Best of luck with your homework.


The stages of asking for homework help on a forum


tlhIn`toq said:

The three different kinds of rookie posters on DIC.

Spoiler

Was This Post Helpful? 0
  • +
  • -

#6 JEdN   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 29-November 11

Re: OpenGL game questions

Posted 29 November 2011 - 10:50 AM

Quote

Could you please fill in the missing words of this sentence so we understand the problem better? This doesn't really make sense yet seems to be the core of your dilemma.


Quote

but I cannot get more than to appear randomly on the screen. only on top of each other.


What I ws trying to say was that I am trying to make alot of the same texture appear on the screen in random places individually. But I was only creating one with all the textures bunched on top.


I've made a big change and deleted everything and put in a particle generator and assigned each particle to the texture which seems to work well now.

Thankyou anyway
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1