9 Replies - 2050 Views - Last Post: 11 December 2012 - 04:54 PM Rate Topic: -----

#1 computerguy3100  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 04-June 12

C++ Asteroids

Posted 10 December 2012 - 02:06 AM

Hello,

I have been programming an Asteroids-like game in C++ in Xcode on Mac OSX. The only problem I have run into is that for some reason, Xcode is saying that I have an out-of-line definition, my drawAsteroid declaration, which I believe I have actually declared correctly. Here is the code where this all happens. This is not the full source code of the game, it is just where I believe the error is occurring.

cpp file:

#include "colors.h"
#include <GLUT/glut.h>
#define _USE_MATH_DEFINES
#include <cmath>

void Color::drawAsteroid(float x, float y, float size, float angle, Jet state)
{
    glPushMatrix();
    glTranslatef(x, y, 0);
    glScalef(0, 0, 1);
    glColor3f(0.5, 0.5, 0.5);
    glBegin(GL_POLYGON);
    for (int i = 0; i < 5; ++i)
        glVertex2f(sin(2 * M_PI / 5 * i), cos(2 * M_PI / 5 * i));
    glEnd();
    glPopMatrix();
        
}





And here is the .h file where the code from the .h file where I declare the drawAsteroid declaration

#pragma once
#include "jet.h"
class Color
{
public:
    void drawAsteroid(float x, float y, float size, float angle);
    void drawShip(float x, float y, float angle, Jet );
    void drawBullet(float x, float y);
};



Any help would be much appreciated!!

This post has been edited by computerguy3100: 10 December 2012 - 02:08 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ Asteroids

#2 Atli  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3730
  • View blog
  • Posts: 6,017
  • Joined: 08-June 10

Re: C++ Asteroids

Posted 10 December 2012 - 02:12 AM

Moved to the C & C++ forum. Please try to post your questions in the correct forums. (And especially keep them out of the Caffeine Lounge!)
Was This Post Helpful? 0
  • +
  • -

#3 computerguy3100  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 04-June 12

Re: C++ Asteroids

Posted 10 December 2012 - 02:19 AM

View PostAtli, on 10 December 2012 - 02:12 AM, said:

Moved to the C & C++ forum. Please try to post your questions in the correct forums. (And especially keep them out of the Caffeine Lounge!)

Oh, sorry, must have accidentally selected the wrong forum, derp.....
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6111
  • View blog
  • Posts: 23,671
  • Joined: 23-August 08

Re: C++ Asteroids

Posted 10 December 2012 - 04:31 AM

void Color::drawAsteroid(float x, float y, float size, float angle, Jet state)

void drawAsteroid(float x, float y, float size, float angle);


Do those match?
Was This Post Helpful? 2
  • +
  • -

#5 computerguy3100  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 04-June 12

Re: C++ Asteroids

Posted 10 December 2012 - 01:59 PM

View PostJackOfAllTrades, on 10 December 2012 - 04:31 AM, said:

void Color::drawAsteroid(float x, float y, float size, float angle, Jet state)

void drawAsteroid(float x, float y, float size, float angle);


Do those match?

Yes, those are exactly what I have but it still says out of line declaration....
Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6111
  • View blog
  • Posts: 23,671
  • Joined: 23-August 08

Re: C++ Asteroids

Posted 10 December 2012 - 04:16 PM

When you defined your class, you told the compiler you were going to provide a class method with this signature:

void drawAsteroid(float x, float y, float size, float angle);


when you defined the drawAsteroid method, you defined it like this:

void Color::drawAsteroid(float x, float y, float size, float angle, Jet state)


What you told the compiler in defining the class MUST MATCH what you define when you implement that function. Is that the case here?

You may need to start with more basic stuff than GL programming if this is over your head.

This post has been edited by JackOfAllTrades: 11 December 2012 - 04:09 AM
Reason for edit:: Bolded relevant statement

Was This Post Helpful? 1
  • +
  • -

#7 computerguy3100  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 04-June 12

Re: C++ Asteroids

Posted 10 December 2012 - 11:27 PM

Ok, so I fixed that problem, I figured out why the two voids weren't matching up. But now, in my Asteroid.cpp file there is another error that says, "Too few arguments to function call, expected 5, have 4" Here is the code where this is happening

#include "asteroid.h"
#include "game.h"
#include "colors.h"
#include <cstdlib>

Asteroid::Asteroid(): angel_(rand() % 31400 / 1000.0f) {}

void Asteroid::tick(vector acel)
{
    vx += acel.x * game::DELTA_T / 1000.0f;
    vy += acel.y * game::DELTA_T / 1000.0f;
    x += vx * game::DELTA_T / 1000.0f;
    y += vy * game::DELTA_T / 1000.0f;
    if (x > game::WIDTH / 2)
        y -= game::WIDTH;
    if (y > game::HEIGHT / 2)
        y -= game::HEIGHT;
    if (x < -game::WIDTH / 2)
        x += game::WIDTH;
    if (y < -game::HEIGHT / 2)
        y += game::HEIGHT;
    angel_ += 3.0f * game::DELTA_T / 1000.0f;
}

void Asteroid::draw(Color &p) const
{
    p.drawAsteroid(x, y, size, angel_);
}



It says that right by the "p.drawAsteroid(x, y, size, angel_);". Does anybody know why this might be happening? thanks and sorry, I have programmed games before and programmed in C++ but this is the first game I've made where the computer draws so many objects.
Was This Post Helpful? 0
  • +
  • -

#8 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2153
  • View blog
  • Posts: 3,315
  • Joined: 21-June 11

Re: C++ Asteroids

Posted 11 December 2012 - 03:22 AM

You're getting that error because you've declared your function to take 5 arguments, but you're calling it with only 4. Specifically it's declared to take a 5th argument of type Jet, which you do not supply when calling it.
Was This Post Helpful? 1
  • +
  • -

#9 computerguy3100  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 04-June 12

Re: C++ Asteroids

Posted 11 December 2012 - 11:57 AM

View Postsepp2k, on 11 December 2012 - 03:22 AM, said:

You're getting that error because you've declared your function to take 5 arguments, but you're calling it with only 4. Specifically it's declared to take a 5th argument of type Jet, which you do not supply when calling it.


I figured that, but the strange thing is that I tried putting
p.drawAsteroid(x, y, size, angel_, Jet);
and
p.drawAsteroid(x, y, size, angel_, Jet state);
and for both it just came up with "expected expression" right after the work Jet. How would I put "Jet state" in my p.drawAsteroid()? Thank you.
Was This Post Helpful? 0
  • +
  • -

#10 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6111
  • View blog
  • Posts: 23,671
  • Joined: 23-August 08

Re: C++ Asteroids

Posted 11 December 2012 - 04:54 PM

First I went back and edited my post above to bold this, but it was apparently missed, so I will repost it and actually amplify it here, even though I'm quite sure you don't want to hear it.

You need to start with more basic stuff before moving on to GL programming.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1