2D draw methods/ Java -> C++

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

2D draw methods/ Java -> C++

Post by Nine_Masquerade_ »

Hi, i am completely new to C++ coming entirely from a Java background and was wondering which C++/PSP lib functions would do the following:

-Created a buffered image with set width and height.

-Draw an image to an x and y coordinate on that buffered image.

-Blit the buffered image to the PSP screen.

So far i have come this far with my code using the files from this page (files are found in the second paragraph):

http://www.psp-programming.com/tutorial ... on04-2.htm

Code: Select all

#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include "graphics.h"

PSP_MODULE_INFO&#40;"Image Display Program", 0, 1, 1&#41;;

#define printf pspDebugScreenPrintf

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
          sceKernelExitGame&#40;&#41;;
          return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
          int cbid;

          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
          sceKernelRegisterExitCallback&#40;cbid&#41;;

          sceKernelSleepThreadCB&#40;&#41;;

          return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
          int thid = 0;

          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
          if&#40;thid >= 0&#41; &#123;
                    sceKernelStartThread&#40;thid, 0, 0&#41;;
          &#125;

          return thid;
&#125;

int main&#40;&#41; &#123;
	char buffer&#91;200&#93;;
	Image* ourImage;
	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	initGraphics&#40;&#41;;
	sprintf&#40;buffer, "cylus.png"&#41;;
	ourImage = loadImage&#40;buffer&#41;;
	int x = 240;
	int y = 136;
	sceDisplayWaitVblankStart&#40;&#41;;
	SceCtrlData pad;
	while&#40;1&#41;
	&#123;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons & PSP_CTRL_LEFT&#41;
			x--;
		if&#40;pad.Buttons & PSP_CTRL_RIGHT&#41;
				x++;
		if&#40;pad.Buttons & PSP_CTRL_UP&#41;
				y--;
		if&#40;pad.Buttons & PSP_CTRL_DOWN&#41;
				y++;
		if&#40;pad.Buttons & PSP_CTRL_TRIANGLE&#41;
				break;
		blitAlphaImageToScreen&#40;0 ,0 ,16 , 20, ourImage, x, y&#41;;
		flipScreen&#40;&#41;;
	&#125;
	sceKernelSleepThread&#40;&#41;;
	return 0;
&#125;
The problem is, the sprite draws to the screen and successfully moves, but the screen does not refresh to being blank before the next coordinate is drawn. Redrawing to a buffered image 480x272 and then blitting that to the screen would avoid this and is the method i usually use in my Java programs.

Any help is greatly appreciated!
Last edited by Nine_Masquerade_ on Tue Jul 21, 2009 12:25 pm, edited 1 time in total.
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

You have to clear the draw buffer.
use
clearScreen(0);
before drawing

>Redrawing to a buffered image 480x272 and then blitting that to the screen would avoid this and is the method i usually use in my Java programs.

That would be to avoid flickering and the pspgu uses double buffering, you'd still have to clear the screen.
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Thanks! It works perfectly.

A couple other questions:

-How do you define a custom color (through RBG values) and then set the background as that color?

-is it possible to have a constructor take main as a parameter so that i can do main.blitImageToScreen(blah, blah, blah); as the draw method within a object?

-Also i have both .c files and .cpp files in my project folder. can C and C++ files be used together??
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

>How do you define a custom color (through RBG values) and then set the background as that color?

open up graphics.c and go to the clearScreen and add
sceGuClearColor(color);
before
sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

then
when calling clearScreen, pass the colour you want to use as the background colour.
use GU_RGBA(r,g,b,a) to make your colour from red,green, blue ,and alpha values.
if you get an undefined reference to GU_RGBA add
#include <pspgu.h> to you code.

>Also i have both .c files and .cpp files in my project folder. can C and C++ files be used together??

Sure

>is it possible to have a constructor take main as a parameter so that i can do main.blitImageToScreen(blah, blah, blah); as the draw method within a object?

what?
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Thanks for your very prompt and comprehensible tips psPea; it works great!

What I meant by this:

>is it possible to have a constructor take main as a parameter so that i can do main.blitImageToScreen(blah, blah, blah); as the draw method within a object?

Is this:

Suppose I had a class called "You". In the java version of my game, the constructor takes in an "Applet".

Code: Select all

public You&#40;Applet myApplet&#41;
	&#123;
	code
	&#125;
So in the Applet itself, when you declare the You object, you see:

Code: Select all

y = new You&#40;this&#41;;
In the java version "You" gets the character/blood images through myApplet like so:

Code: Select all

		for&#40;int i = 0; i < 8; i++&#41;
		&#123;
		img = myApplet.getImage&#40;myApplet.getCodeBase&#40;&#41;, "blood"+i+".png"&#41;;
		blood.add&#40;img&#41;;
		&#125;
The Applet that is being passed into "You" in the java version is basically main.c for the C/C++ version (both contain the main method for the program).

So my question is (in regards to the C/C++ version)... can i pass main.c into "You"'s constructor as a parameter like so:

Code: Select all

You&#58;&#58;You&#40;main m&#41;
&#123;
code
&#125;
so as to then call

Code: Select all

sprintf&#40;buffer, "cylus.png"&#41;;
	ourImage = loadImage&#40;buffer&#41;;
and

Code: Select all

blitAlphaImageToScreen&#40;0 ,0 ,16 , 20, ourImage, x, y&#41;;
so that "You" can instantiate and govern its own .pngs and have its own "draw" method yet do it by using main.c?

Basically what I am asking is can main.c be passed as a parameter and then used in methods inside of other objects?
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Nine_Masquerade_ wrote:Basically what I am asking is can main.c be passed as a parameter and then used in methods inside of other objects?
No. You need to go review your C++ a bit. Remember that C++ is the same on the PSP as on any other platform. If you can/can't do it on a PC, you can/can't do it on the PSP.
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

I've never used applets in Java so I have no clue what you're talking about.

>So my question is (in regards to the C/C++ version)... can i pass main.c into "You"'s constructor as a parameter like so:

I'm not sure what you mean, but I'm certain the answer is no.

If you want "You" to instantiate and govern its own .pngs and have its own "draw" method, then do it, you don't need main.

Code: Select all

class You&#123;
.
.
.
public&#58;
         You&#40;&#41;&#123;
          for&#40;int i = 0; i < 8; i++&#41; &#123; 
            char file&#91;100&#93;;     
            sprintf&#40;file, "blood%d.png", i&#41;;                
            Image img = loadImage&#40;file&#41;; 
            blood.insert&#40;img&#41;; 
          &#125;
         &#125;
         draw&#40;int srcx ,int srcy ,int width, int height, Image *ourImage, int x, int y&#41;&#123;
            blitAlphaImageToScreen&#40;srcx ,srcy ,width, height, ourImage, x, y&#41;;
         &#125;
.
.
.
&#125;;
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

lol i agree J.F.. I do need to review my C++ a bit. Ive realized what i was trying to do didnt make too much sense, so what im trying now is this (just an example from within "You.h"):

Code: Select all

		for&#40; int i = 0; i < 6; i++ &#41;
		&#123;
			sprintf&#40;buffer, "cylus"+i+".png"&#41;;
			img = loadImage&#40;buffer&#41;;
			playerPics&#91;i&#93; = im;
		&#125;
Im currently still making changes, but ill let you know if what im trying works. And I apologize if it is at times annoying that i am not too adept with C++. Ive found that the fastest way to learn and retain a language is through trial and error and i appreciate all of the help ive been given more than you guys can imagine :)
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

I was just gonna try that psPea.
Working on it now...
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Almost done.
Quick question though.

Can i make ArrayLists in C++ like i can in Java?

Im almost positive i cant, but its strange because dont have any syntax errors for lines like this:

Code: Select all

	ArrayList<Image> flamethrower = new ArrayList<Image>&#40;&#41;;
yet for some reason when i try making an ArrayList of ArrayLists like this:

Code: Select all

ArrayList<ArrayList<Image>> weapon = new ArrayList<ArrayList<Image>>&#40;&#41;;
i get a syntax error.
Please let me know if im wrong about ArrayLists in C++ and if im not, it would help a bunch if you know why im getting this error.
Last edited by Nine_Masquerade_ on Tue Jul 21, 2009 11:15 am, edited 1 time in total.
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

put a space between the two >
change >>
to > >

also I didn't know there was ArrayList in C++
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

lol thats why i changed my post to "im almost positive i cant".
The error went away when i did what you said, but i did a little test, where i misspell "ArrayList", save, and no errors show up...

Im not sure why its not detecting a syntax error when i misspell ArrayList.

Ill see what happens when i finish transcoding it to C++ and try and compile.

Fingers are crossed.
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Hmm found something worth looking at.
I ran my java source through a java -> C++ translator and it changed the ArrayLists like this:

Code: Select all

ArrayList<Image> flamethrower = new ArrayList<Image>&#40;&#41;;
is now

Code: Select all

std&#58;&#58;vector<Image*> flamethrower = std&#58;&#58;vector<Image*>&#40;&#41;;
I am not too sure what this means. Could someone enlighten me?
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

http://www.cplusplus.com/reference/stl/vector/
and
http://www.cplusplus.com/reference/

one thing to note in Java object variables store reference to objects, in C++ that's not the case, notice how they changed Image to Image*.
If you add an object to any of those containers they add a copy of it and not the object itself, so making the vector type a pointer to the object may be more desireable.
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Thank you. This helps tremendously.

I am using eclipse Galileo and i know for a fact there are many syntax errors that are not being shown. Having realized this, this process may take a couple more days :( but im up to the task. Is there something I can change in my eclipse preferences so these errors will show?

Also, in java as you probably know there is a built in Rectangle object, which i use extensively for collision tests in my code. Do you know if C++ has a Rectangle object that contains functions which tell if something is inside the Rectangle, on its border, etc.?
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

Do you know if C++ has a Rectangle object that contains functions which tell if something is inside the Rectangle, on its border, etc.?

why not try running the rectangle class through the converter?


>I am using eclipse Galileo and i know for a fact there are many syntax errors that are not being shown. Having realized this, this process may take a couple more days :( but im up to the task. Is there something I can change in my eclipse preferences so these errors will show?

I don't know about eclipse, but why not try compiling it?
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

All i found for the java Rectangle class source was this:

http://kickjava.com/src/java/awt/Rectangle.java.htm

I also found this

http://www.gtkmm.org/docs/gtkmm-2.4/doc ... angle.html

Which i think might prove to be more practical. But since im developing under MinPSPw, im not sure how to install these packages. Any ideas?
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Im just going to make my own rectangle class using this algorithm:


In the case of axis-aligned ones, there are at most four checks you need to perform:
1. Check if box A is completely to the left of box B (a.left <= b.right). If so, then quit the process: they don't intersect.
2. Otherwise, check if it's completely to the right (a.right >= b.left). If so, quit the process.
3. If not, check if it's completely above box B (a.bottom >= b.top). If so, quit.
4. If not, check if it's completely beneath box B (a.top <= b.bottom). If so, quit.
If not, then the boxes intersect.
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

As I've said before, im not too adept in C++, and therefore i cannot figure out what i am doing wrong here :(. When i try to compile this test code i get these errors:


**** Build of configuration Default for project ITAWAS ****

make all
psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150 -c -o main.o main.c
In file included from main.c:10:
./Rectangle.h:9:20: error: iostream: No such file or directory
In file included from main.c:10:
./Rectangle.h:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'Rectangle'
main.c: In function 'main':
main.c:56: error: 'Rectangle' undeclared (first use in this function)
main.c:56: error: (Each undeclared identifier is reported only once
main.c:56: error: for each function it appears in.)
main.c:56: error: expected ';' before 'r'
make: *** [main.o] Error 1

Here is Rectangle.h:

Code: Select all

#ifndef RECTANGLE_H_
#define RECTANGLE_H_



class Rectangle
&#123;
public&#58;
	int X;
	int Y;
	int WIDTH;
	int HEIGHT;
	int bottom;
	int right;

	Rectangle&#40;int x, int y, int width, int height&#41;
	&#123;
		X = x;
		Y = y;
		WIDTH = width;
		HEIGHT = height;
		right = X + WIDTH;
		bottom = Y + HEIGHT;
	&#125;

	virtual void setRect&#40;int x, int y, int width, int height&#41;
	&#123;
		X = x;
		Y = y;
		WIDTH = width;
		HEIGHT = height;
		right = X + WIDTH;
		bottom = Y + HEIGHT;
	&#125;

	virtual bool intersects&#40;Rectangle r&#41;
	&#123;
		if&#40;X >= r.getRight&#40;&#41;&#41;
			return false;
		else if&#40;right <= r.getX&#40;&#41;&#41;
			return false;
		else if&#40;Y >= r.getBottom&#40;&#41;&#41;
			return false;
		else if&#40;bottom <= r.getY&#40;&#41;&#41;
			return false;
		else return true;
	&#125;

	virtual int getX&#40;&#41;
	&#123;
		return X;
	&#125;

	virtual int getY&#40;&#41;
	&#123;
		return Y;
	&#125;

	virtual int getBottom&#40;&#41;
	&#123;
		return bottom;
	&#125;

	virtual int getRight&#40;&#41;
	&#123;
		return right;
	&#125;
&#125;;
#endif /* RECTANGLE_H_ */

And here is main.c:

Code: Select all

#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspkernel.h>
#include <pspdebug.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include "graphics.h"
#include <stdbool.h>





PSP_MODULE_INFO&#40;"Image Display Program", 0, 1, 1&#41;;

#define printf pspDebugScreenPrintf

/* Exit callback */
int exit_callback&#40;int arg1, int arg2, void *common&#41; &#123;
          sceKernelExitGame&#40;&#41;;
          return 0;
&#125;

/* Callback thread */
int CallbackThread&#40;SceSize args, void *argp&#41; &#123;
          int cbid;

          cbid = sceKernelCreateCallback&#40;"Exit Callback", exit_callback, NULL&#41;;
          sceKernelRegisterExitCallback&#40;cbid&#41;;

          sceKernelSleepThreadCB&#40;&#41;;

          return 0;
&#125;

/* Sets up the callback thread and returns its thread id */
int SetupCallbacks&#40;void&#41; &#123;
          int thid = 0;

          thid = sceKernelCreateThread&#40;"update_thread", CallbackThread, 0x11, 0xFA0, 0, 0&#41;;
          if&#40;thid >= 0&#41; &#123;
                    sceKernelStartThread&#40;thid, 0, 0&#41;;
          &#125;

          return thid;
&#125;

int main&#40;&#41; &#123;
	//Direction Booleans
	bool LEFT;
	bool RIGHT;
	bool RTRIGGER;
	bool CROSS;
	bool START;
	Rectangle r&#40;0, 0, 0, 0&#41;;


	pspDebugScreenInit&#40;&#41;;
	SetupCallbacks&#40;&#41;;
	initGraphics&#40;&#41;;
	sceDisplayWaitVblankStart&#40;&#41;;
	SceCtrlData pad;
	while&#40;1&#41;
	&#123;
		sceCtrlReadBufferPositive&#40;&pad, 1&#41;;
		if&#40;pad.Buttons & PSP_CTRL_LEFT&#41;
				LEFT = true;
		else LEFT = false;
		if&#40;pad.Buttons & PSP_CTRL_RIGHT&#41;
				RIGHT = true;
		else RIGHT = false;
		if&#40;pad.Buttons & PSP_CTRL_CROSS&#41;
				CROSS = true;
		else CROSS = false;
		if&#40;pad.Buttons & PSP_CTRL_START&#41;
				START = true;
		else START = false;
		if&#40;pad.Buttons & PSP_CTRL_RTRIGGER&#41;
				RTRIGGER = true;
		else RTRIGGER = false;

		clearScreen&#40;GU_RGBA&#40;181, 186, 254, 1&#41;&#41;;
		flipScreen&#40;&#41;;


	&#125;
	sceKernelSleepThread&#40;&#41;;
	return 0;
&#125;
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

change main.c to main.cpp
and add -lstdc++ to LIBS in your makefile
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Thanks for your continued help psPea.

I renamed main.c to main.cpp and added -lstdc++ to LIBS.

Now i get this error:


**** Build of configuration Default for project ITAWAS ****

make all
psp-g++ -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150 -c -o main.o main.cpp
main.cpp: In function 'int main()':
main.cpp:57: error: 'Rectangle' was not declared in this scope
main.cpp:57: error: expected `;' before 'r'
make: *** [main.o] Error 1

EDIT 1:

For the heck of it, after making the changes i commented out the line where i construct the Rectangle and then tried compiling. Then i get these errors:

**** Build of configuration Default for project ITAWAS ****

make all
psp-gcc -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -D_PSP_FW_VERSION=150 -L. -LC:/pspsdk/psp/sdk/lib main.o graphics.o framebuffer.o -lpspgu -lpng -lz -lm -lstdc++ -lpspdebug -lpspdisplay -lpspge -lpspctrl -lpspsdk -lc -lpspnet -lpspnet_inet -lpspnet_apctl -lpspnet_resolver -lpsputility -lpspuser -lpspkernel -o hello.elf
main.o: In function `main':
main.cpp:(.text+0x74): undefined reference to `initGraphics()'
main.cpp:(.text+0x98): undefined reference to `clearScreen(unsigned int)'
main.cpp:(.text+0xa0): undefined reference to `flipScreen()'
collect2: ld returned 1 exit status
make: *** [hello.elf] Error 1
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

I'm now reading your code and I see that Rectangle.h isn't included in main

also I believe graphics.h isn't wrapped in an extern "C"
so
change
#include "graphics.h"
to
extern "C"
{
#include "graphics.h"
}
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Yes that did solve that error, but now sadly i am getting more...

I did some cleanup and reduced the errors as much as i could, but now i've got some i can't figure out. In all i have 9 classes and each are experiencing similar errors when i try to compile. So solving them in one class will help me solve the rest. Ill show You.h's errors:

./You.h:46: error: ISO C++ forbids declaration of 'Rectangle' with no type
./You.h:46: error: expected ';' before '*' token
./You.h:47: error: ISO C++ forbids declaration of 'Rectangle' with no type
./You.h:47: error: expected ';' before '*' token
./You.h:48: error: ISO C++ forbids declaration of 'Rectangle' with no type
./You.h:48: error: expected ';' before '*' token
./You.h:49: error: ISO C++ forbids declaration of 'Rectangle' with no type
./You.h:49: error: expected ';' before '*' token
./You.h:50: error: ISO C++ forbids declaration of 'Rectangle' with no type
./You.h:50: error: expected ';' before '*' token
./You.h:113: error: 'Terrain' was not declared in this scope
./You.h:113: error: template argument 1 is invalid
./You.h:113: error: template argument 2 is invalid
./You.h:126: error: ISO C++ forbids declaration of 'Rectangle' with no type
./You.h:126: error: 'Rectangle' declared as a 'virtual' field
./You.h:126: error: expected ';' before '*' token
./You.h:137: error: 'Terrain' was not declared in this scope
./You.h:137: error: template argument 1 is invalid
./You.h:137: error: template argument 2 is invalid
./You.h:137: error: 'Projectile' was not declared in this scope
./You.h:137: error: template argument 1 is invalid
./You.h:137: error: template argument 2 is invalid
./You.h:137: error: 'object' was not declared in this scope
./You.h:137: error: template argument 1 is invalid
./You.h:137: error: template argument 2 is invalid

Here is You.h:

Code: Select all

#pragma once
#include <string>
#include <vector>
#include <cmath>
#include <Enemy.h>
#include <LevelPack.h>
#include <Object.h>
#include <Projectile.h>
#include <Rectangle.h>
#include <Shop.h>
#include <Terrain.h>
#include <TextOverlay.h>


class You
&#123;

public&#58;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int WIDTH;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int HEIGHT;
	int pX;
	int pY;
	int deltaD;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int xPos;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int yPos;
	int animateY;
	Image *im;
	//Blood
	Image *img;
	int xBlood;
	int yBlood;
	int bloodCount;
	int bL;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int healthMax;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int health;
	int money;
	bool dead;

//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	Rectangle *r;
	Rectangle *r0;
	Rectangle *r1;
	Rectangle *rL;
	Rectangle *rR;
//ORIGINAL LINE&#58; Image&#91;&#93; playerPics;
//INSTANT C++ WARNING&#58; Since the array size is not known in this declaration, Instant C++ has converted this array to a pointer.  You will need to call 'delete&#91;&#93;' where appropriate&#58;
	Image *playerPics;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	std&#58;&#58;vector<Image*> blood;
	//Projectile variables
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	std&#58;&#58;string P_TYPE;
	int M_TYPE;
	//Physics related variables
	bool grounded;
	//initial jump dir&#58; 0 = L, 1 = R, -5 = not jumping
	int iJump;
	bool maintain;
	int dir;
	int t;
	int v;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int a;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int MAX;



	//Creates the player
	You&#40;&#41;;

	//Set Your Current Position
	virtual void setPos&#40;&#41;;

	//Sets old 
	virtual void setPre&#40;&#41;;

	//Set Pos for level
	virtual void setXY&#40;int x, int y&#41;;

	virtual void setMoney&#40;int i&#41;;
	//Draws You
	virtual void draw&#40;&#41;;



	//Tests for L and sets xPos and animation type
	virtual int walkL&#40;bool buttonEventL&#41;;





	//Tests for R and sets xPos and animation type
	virtual int walkR&#40;bool buttonEventR&#41;;




	//Tests for S and sets yPos
	virtual void jump&#40;bool buttonEventS&#41;;




	//Tests if you are in free fall and sets yPos
	virtual void gravity&#40;std&#58;&#58;vector<Terrain*> &pack&#41;;

	//Return methods
	virtual int getX&#40;&#41;;

	virtual int getY&#40;&#41;;

	virtual std&#58;&#58;string getPType&#40;&#41;;

	virtual int getMType&#40;&#41;;

	virtual int getAnim&#40;&#41;;

	virtual Rectangle *getRect&#40;&#41;;

	virtual int getVel&#40;&#41;;

	virtual int getHealth&#40;&#41;;

	virtual bool getStatus&#40;&#41;;

	virtual int getMoney&#40;&#41;;


	virtual void colTestTer&#40;std&#58;&#58;vector<Terrain*> &pack, std&#58;&#58;vector<Projectile*> &proj, std&#58;&#58;vector<object*> &pickups&#41;;

	//Determines death- prevents all movement and loops through blood sequence.
	virtual void healthTest&#40;&#41;;


&#125;;
I am extremely grateful for any help people can offer.
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

I'm thinking your header files aren't found
are they in the same folder as you.h
if so change
#include <header.h>
to
#include "header.h"
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Thanks! Yea, the header files are all in the same directory. That helped me narrow down the error log to this:

You.h:46: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:46: error: expected ';' before '*' token
You.h:47: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:47: error: expected ';' before '*' token
You.h:48: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:48: error: expected ';' before '*' token
You.h:49: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:49: error: expected ';' before '*' token
You.h:50: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:50: error: expected ';' before '*' token
You.h:126: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:126: error: 'Rectangle' declared as a 'virtual' field
You.h:126: error: expected ';' before '*' token
You.h:137: error: 'Projectile' was not declared in this scope
You.h:137: error: template argument 1 is invalid
You.h:137: error: template argument 2 is invalid
You.h:137: error: 'object' was not declared in this scope
You.h:137: error: template argument 1 is invalid
You.h:137: error: template argument 2 is invalid

There's three basic areas where errors are arising from. I Put asterisks to the right of these lines:

Code: Select all

#pragma once
#include <string>
#include <vector>
#include <cmath>
#include "Enemy.h"
#include "LevelPack.h"
#include "Object.h"
#include "Projectile.h"
#include "Rectangle.h"
#include "Shop.h"
#include "TextOverlay.h"
#include "Terrain.h"


class You
&#123;

public&#58;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int WIDTH;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int HEIGHT;
	int pX;
	int pY;
	int deltaD;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int xPos;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int yPos;
	int animateY;
	Image *im;
	//Blood
	Image *img;
	int xBlood;
	int yBlood;
	int bloodCount;
	int bL;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int healthMax;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int health;
	int money;
	bool dead;

//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	Rectangle *r;        ****ERROR
	Rectangle *r0;      ****ERROR
	Rectangle *r1;      ****ERROR
	Rectangle *rL;      ****ERROR
	Rectangle *rR;      ****ERROR
//ORIGINAL LINE&#58; Image&#91;&#93; playerPics;
//INSTANT C++ WARNING&#58; Since the array size is not known in this declaration, Instant C++ has converted this array to a pointer.  You will need to call 'delete&#91;&#93;' where appropriate&#58;
	Image *playerPics;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	std&#58;&#58;vector<Image*> blood;
	//Projectile variables
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	std&#58;&#58;string P_TYPE;
	int M_TYPE;
	//Physics related variables
	bool grounded;
	//initial jump dir&#58; 0 = L, 1 = R, -5 = not jumping
	int iJump;
	bool maintain;
	int dir;
	int t;
	int v;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int a;
//INSTANT C++ TODO TASK&#58; Native C++ only allows initialization of static const integral fields in their declarations&#58;
	int MAX;



	//Creates the player
	You&#40;&#41;;

	//Set Your Current Position
	virtual void setPos&#40;&#41;;

	//Sets old 
	virtual void setPre&#40;&#41;;

	//Set Pos for level
	virtual void setXY&#40;int x, int y&#41;;

	virtual void setMoney&#40;int i&#41;;
	//Draws You
	virtual void draw&#40;&#41;;



	//Tests for L and sets xPos and animation type
	virtual int walkL&#40;bool buttonEventL&#41;;





	//Tests for R and sets xPos and animation type
	virtual int walkR&#40;bool buttonEventR&#41;;




	//Tests for S and sets yPos
	virtual void jump&#40;bool buttonEventS&#41;;




	//Tests if you are in free fall and sets yPos
	virtual void gravity&#40;std&#58;&#58;vector<Terrain*> &pack&#41;;

	//Return methods
	virtual int getX&#40;&#41;;

	virtual int getY&#40;&#41;;

	virtual std&#58;&#58;string getPType&#40;&#41;;

	virtual int getMType&#40;&#41;;

	virtual int getAnim&#40;&#41;;

	virtual Rectangle *getRect&#40;&#41;;      ****ERROR

	virtual int getVel&#40;&#41;;

	virtual int getHealth&#40;&#41;;

	virtual bool getStatus&#40;&#41;;

	virtual int getMoney&#40;&#41;;


	virtual void colTestTer&#40;std&#58;&#58;vector<Terrain*> &pack, std&#58;&#58;vector<Projectile*> &proj, std&#58;&#58;vector<object*> &pickups&#41;;      ****ERROR

	//Determines death- prevents all movement and loops through blood sequence.
	virtual void healthTest&#40;&#41;;


&#125;;
Let me know if you need to see more code if itll help.
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

>Let me know if you need to see more code if itll help.

the whole compile log would be useful too
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Sure. Here is the whole log:


**** Build of configuration Default for project ITAWAS ****

make all
psp-g++ -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -I. -IC:/pspsdk/psp/sdk/include -O2 -G0 -Wall -fno-exceptions -fno-rtti -D_PSP_FW_VERSION=150 -c -o main.o main.cpp
In file included from You.h:12,
from TextOverlay.h:9,
from Shop.h:9,
from Rectangle.h:13,
from Projectile.h:9,
from Object.h:5,
from LevelPack.h:5,
from Enemy.h:5,
from main.cpp:12:
Terrain.h:17: error: ISO C++ forbids declaration of 'Rectangle' with no type
Terrain.h:17: error: expected ';' before '*' token
Terrain.h:29: error: ISO C++ forbids declaration of 'Rectangle' with no type
Terrain.h:29: error: 'Rectangle' declared as a 'virtual' field
Terrain.h:29: error: expected ';' before '*' token
In file included from TextOverlay.h:9,
from Shop.h:9,
from Rectangle.h:13,
from Projectile.h:9,
from Object.h:5,
from LevelPack.h:5,
from Enemy.h:5,
from main.cpp:12:
You.h:46: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:46: error: expected ';' before '*' token
You.h:47: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:47: error: expected ';' before '*' token
You.h:48: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:48: error: expected ';' before '*' token
You.h:49: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:49: error: expected ';' before '*' token
You.h:50: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:50: error: expected ';' before '*' token
You.h:126: error: ISO C++ forbids declaration of 'Rectangle' with no type
You.h:126: error: 'Rectangle' declared as a 'virtual' field
You.h:126: error: expected ';' before '*' token
You.h:137: error: 'Projectile' was not declared in this scope
You.h:137: error: template argument 1 is invalid
You.h:137: error: template argument 2 is invalid
You.h:137: error: 'object' was not declared in this scope
You.h:137: error: template argument 1 is invalid
You.h:137: error: template argument 2 is invalid
In file included from Object.h:5,
from LevelPack.h:5,
from Enemy.h:5,
from main.cpp:12:
Projectile.h:44: error: 'Enemy' has not been declared
In file included from Enemy.h:5,
from main.cpp:12:
LevelPack.h:23: error: 'Enemy' was not declared in this scope
LevelPack.h:23: error: template argument 1 is invalid
LevelPack.h:23: error: template argument 2 is invalid
LevelPack.h:57: error: 'Enemy' has not been declared
LevelPack.h:66: error: 'Enemy' was not declared in this scope
LevelPack.h:66: error: template argument 1 is invalid
LevelPack.h:66: error: template argument 2 is invalid
LevelPack.h:74: error: 'Enemy' was not declared in this scope
LevelPack.h:74: error: template argument 1 is invalid
LevelPack.h:74: error: template argument 2 is invalid
make: *** [main.o] Error 1
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

You're trying to use classes before they are defined(I think)

If you upload all the files I could take a look at it.
Nine_Masquerade_
Posts: 26
Joined: Thu Jun 18, 2009 10:30 am

Post by Nine_Masquerade_ »

Thanks pspPea
I could email you the project... just pm me your email address.

EDIT
Is it cool if i send it to this address: [email protected] ?
psPea
Posts: 60
Joined: Sat Sep 01, 2007 12:51 pm

Post by psPea »

>Is it cool if i send it to this address: [email protected] ?

sure, I don't know who would get it though AS ITS NOT MINE

I sent you a pm with my email address
just change -at- to @ and -dot- to .

or you could upload it to mediafire or some other free file hosting site and post the link here.
Post Reply