PDA

View Full Version : Noob Question



thehumanidiot
September 30th, 2007, 22:57
this is probaly very easy to answer and very noobie, but how do you make stuff move(like an image)with C for the psp???

yaustar
September 30th, 2007, 23:50
Change where you blit the image on the screen. Store these co-ordinates in variables, read the input of the controls and change the value of the co-ordinates accordingly. Then finally use these co-ordinates to blit the image on the screen.

thehumanidiot
October 1st, 2007, 11:17
ok thank you very much
EDIT::It moves, but it strecthes the picture, like i would need to remove the previous ones how do i do that?

dangee
October 1st, 2007, 13:41
...It moves, but it strecthes the picture, like i would need to remove the previous ones how do i do that?

try clearing the screen (or refreshing the background image) before blitting the sprite to its new position.

thehumanidiot
October 1st, 2007, 21:25
how do i do that?

dangee
October 1st, 2007, 23:00
how do i do that?

draw a filled rectangle the size of the screen, or blit the background image, before you blit the sprite.

thehumanidiot
October 2nd, 2007, 00:15
yes i know that would work, but couldn't that overload the psp's RAM after a while?
EDIT:: i actually tried that but it didn't work, how do you clear the screen?

dangee
October 2nd, 2007, 21:24
it didn't work

So sad my suggestions couldnt help you get stuff moving

thehumanidiot
October 2nd, 2007, 22:04
stop making fun of me, is there a code that willl just clear the screen?

thehumanidiot
October 3rd, 2007, 01:36
ok SOMEONE must know how to do this, i have seen plenty of homebrew where people ACTUALLY MOVE!(amazing isn't it?)so plz help me i want to start making psp games!

dangee
October 3rd, 2007, 09:35
stop making fun of me, is there a code that willl just clear the screen?

I did not intend to make fun of you.
I spent a good amount of time yesterday trying to think
of a way to guide you, without becoming your
personal debugging djinni.
I couldnt find a way, and to recognize and accept
this personal phail made me sad.
The best I can suggest now is that
you find , and study some existing source code

yaustar
October 3rd, 2007, 10:35
What dangee said to clear the screen is the concept method that most games do. How you actually clear the screen depends on the API, libraries, platform you are programming on.

thehumanidiot
October 3rd, 2007, 12:08
I did not intend to make fun of you.
I spent a good amount of time yesterday trying to think
of a way to guide you, without becoming your
personal debugging djinni.
I couldnt find a way, and to recognize and accept
this personal phail made me sad.
The best I can suggest now is that
you find , and study some existing source code

well im very sorry it just sounded that way, i was looking for source codes and couldn't find anything and stilll looking.
and what exactly does that mean yaustar?

splodger15
October 3rd, 2007, 12:25
No offense but do you really think you should be starting on C when you have no knowledge what so ever on the language. If you wish to start learning C I reckon you should get a book from your local library and study it

thehumanidiot
October 3rd, 2007, 21:11
ok i was reading a C++ book because i wanted to learn about it, and i did those tutoials on psp-programming. I also know actionscript, so i am only half noob right now

thehumanidiot
October 3rd, 2007, 23:02
i will clear up what exactly i am doing. I am using psp dev i have the libaries that the libinstaller for pspdev installed. i was following this tutorial
http://www.psp-programming.com/tutorials/c/lesson04.htm
i finished it and the tutorials following it, i have added some things to the code that will make it move, i try reblitting the images whenever i push one of the arrows, that works, but then the image that was there before it is still showing, i want to learn how to remove this or if i should do something else
i have atached the code files i thank if you deicde to take a look or help me.

yaustar
October 4th, 2007, 11:28
Clarification: You are using the graphics and framebuffer code from PSP-programming tutorials.

Look at the header file of graphics.h. It shows all the functions you can use from the graphics.c source. Look for a function that clears the screen.

SpooForBrains
October 4th, 2007, 11:33
Also, those tutorials are in C, not C++.

thehumanidiot
October 4th, 2007, 20:55
ok i found one but im not sure how to use
extern void clearImage(Color color, Image* image);

i defined a color as "Black"(tell if thats not was i was supoosed to do)
I typed my code like this

clearImage(Black, Black, Image* ourImage);

here are the errors i get
main.c<63> : error: syntax error berfore 'Image'

SpooForBrains i knew that, but what is the difference

thehumanidiot
October 6th, 2007, 14:59
ok i tried dangees method again, and this time, IT WORKED!!!! thank you all very much for helping me solve my problem!!

splodger15
October 6th, 2007, 20:38
The difference between C and C++ is as follows:

C++ has Object Oriented programming (such as Classes and polymophism)...in essence objects of things are defined and shaped...it more matches real-world representation and makes development more elegant and faster to create.

C is the predecessor older language which was strictly structured programming....which just means you did everything in functions with no true collectiveness grouping among them


C++ is a far more powerfull language

thehumanidiot
October 6th, 2007, 23:32
ok thank you for explaining that, But i have another question about coding, how do i detect hits? i am making a space invaders clone, i made the ship, got it to move and shoot, but now i need to learn to know when it hits stuff like an alien.

dangee
October 7th, 2007, 19:16
so good to hear you got stuff moving.
the common method of hit detection involves using the
screen position (x,y) , and
size (width,height) properties of your
sprite objects to find if any of them overlap.
(eg using the inequality operators )

thehumanidiot
October 8th, 2007, 02:04
how exactly would i type that?
EDIT::i tired it this way, i made it so that whenever the laser's x and y posistion are greater than or lesser than a certain number, it works, but if there is a better way to do this please tell me. Here is what it looks like
if(lx > 15 && lx < 45 && ly < 135 && ly > 105){
inv1stat = 0;
}

dangee
October 8th, 2007, 11:03
Just so.
At this stage in the programs dev. cycle, its useful to establish
all the main() flow control blocks and data objects, before
enhancements and optimisation.
You can add more tests inside the conditional statement body at any
stage.

eg. Test whether pixel coordinate
(lx-sprite.x,ly-sprite.y)
of the sprite image is see-thru.

thehumanidiot
October 8th, 2007, 21:13
now im having another problem, but this one might be a bit harder to answer.i have sucessfully gotten the ship to move and shoot, i have a row of 10 aliens which i can shoot and they will dissappear. My problem is getting them all to move correctly. i have tried different methods, but none of them work. I will keep looking for more ways myself, but if any of you know how to do this, all help will be greatly appreciated.

dangee
October 8th, 2007, 22:59
space invaders...
dont they kinda shuffle across till you
shoot the end one , then they all change direction...

.. or was that the Galaxians

thehumanidiot
October 8th, 2007, 23:19
http://www.thepcmanwebsite.com/media/flash_space_invaders/

dangee
October 9th, 2007, 11:32
thx, thats a good model to work from
but, you'll have to be a little less vague
about how your
Invader Attack Block (IAB) object
aint moving correctly

thehumanidiot
October 11th, 2007, 00:33
ok i decided to stop working on the space invaders(i got bored and i dont know how to do). Now this might sound surprising, but i have decided to work on an Ad-Hoc Messenger. I have found some code that will help me code the ad hoc functions.
http://forums.qj.net/f-guides-development-45/t-adhoc-tutorial-55788.html
im working on the menu and interface right now, now this is probably an easy question to answer. I working on a keyboard, and i need it to move one square when i push a button, i will explain here is the code i have now.

if(pad.Buttons & PSP_CTRL_RIGHT && selectorx < 210){
selectorx += 5;
}

this is what i want it to do, BUT i want it so that when i hold in the right button it still only move 5 pixels ONCE, instead of keep moving across the screen.

thehumanidiot
October 12th, 2007, 00:42
does anyone know how to do this??
please?
EDIT::Looked at some source code, fixed it

thehumanidiot
October 12th, 2007, 23:10
Ok im sorry im asking so many questions but now i have ANOTHER problem. How do i edit and add onto strings??

message += "a";

i try it like this, but it doesnt work, how would i code this correctly???

jamotto
October 13th, 2007, 04:25
Use strncat


char *strncat(char * restrict s1,const char * restrict s2, size_t n);

The strncat function appends not more than n characters (a null character and characters that follow it are not appended) from the array pointed to by s2 to the end of the string pointed to by s1. The initial character of s2 overwrites the null character at the end of s1. A terminating null character is always appended to the result.Thus, the maximum number of characters that can end up in the array pointed to by s1 is strlen(s1)+n+1. If copying takes place between objects that overlap, the behavior is undefined.

titch.ryan
October 13th, 2007, 07:55
try learning lua its alot easier

thehumanidiot
October 13th, 2007, 17:41
thank you very jamoot, it works, and ticth, i don't want to learn lua right now because im only 13 and might be a video game designer so it might help if i know the basics of C.
EDIT::How would I clear a string??

thehumanidiot
October 14th, 2007, 02:45
Please?????

jamotto
October 14th, 2007, 05:28
It would help if you show us a little bit of code, so people can see exactly what it is your doing.

thehumanidiot
October 14th, 2007, 12:48
Ok, im trying to make an ad-hoc messenger, i just started coding for the psp so im not very good. For the ad-hoc stuff i will be using this tutorial.
forums.qj.net/archive/index.php/t-55788.html so you dont need to worry about that.
I wanted to do this because i have not found one of these and would like one(if there is one plz tell me) I am now working one the text editing stuff, right now only one letter works(but i know how to make them all work) and i need to now how to backspace or clear the text or something, ive included my source code, makefile, and images.

dangee
October 14th, 2007, 15:22
I think you should use your Space Invader Assault Ship
to shoot the letters ,
so they disappear..

thehumanidiot
October 14th, 2007, 15:24
Why?!?!?!?

dangee
October 14th, 2007, 15:39
Why?!?!?!?

1: "to clear the text or something" .
2: you already have the code,
3: its more fun than a cursor,
4: when you code your next game you'll have
a readymade hiScore name entry system..

thehumanidiot
October 14th, 2007, 17:52
i was looking around, and i found this

strset

its suppossed to set all the letters of a text to a letter, but i don;t know how to use it.

jamotto
October 15th, 2007, 03:59
It takes two arguments, the first is a pointer to the null terminated string, the second argument is the numerical value you wish to use to overwrite the string up to the null character.

thehumanidiot
October 15th, 2007, 12:08
can you give me an example??i keep getting an error

thehumanidiot
October 15th, 2007, 21:30
ok i decided to look around some more , i found this function

strcpy();

and it works! But is there any way to copy the character to the last letter of the destination string??

Mashphealh
October 16th, 2007, 20:43
Strcpy is used for pass the data of string to other string.

Strcat is for past string in the final of another one.

jamotto
October 16th, 2007, 22:30
It might be easier if you forgo the string functions and manage the message buffer yourself.

You could create a index that would start at message[0]. As users type letters insert that letter where the index points, then increment index. When your ready to print the string out insert a null character at the end.

You would need to make sure index never exceeds the size of the message buffer.

thehumanidiot
October 17th, 2007, 21:54
is there any easy way just to remove the last charecter of a string??

jamotto
October 17th, 2007, 23:38
Inserting a null should do what you want to do.

thehumanidiot
October 18th, 2007, 00:13
how would i do that??

jamotto
October 18th, 2007, 01:51
Find the end of your string using strlen, for example, then assign a null character.


int string_length = 0;

char my_string[] = {"boat"};

printf("%s\n", my_string);

/* outputs boat */

string_length = strlen(my_string);

/*string_length equals 4*/

my_string[3] = '\0';

/*insert null character at the end of the string*/

printf("%s\n", my_string);

/* outputs boa */

yaustar
October 18th, 2007, 10:11
my_string[3] = '\0';

should be

my_string[string_length-1] = '\0';

thehumanidiot
October 18th, 2007, 11:56
yes i just figured that out and it WORKS!!! thank you very much!!

jamotto
October 18th, 2007, 23:00
my_string[3] = '\0';

should be

my_string[string_length-1] = '\0';

Thanks for catching my mistake. :)

thehumanidiot
October 24th, 2007, 21:51
ok now im having ANOTHER problem, im working on the ad-hoc part, and as i have told you i was following this tutorial.
http://forums.qj.net/f-guides-develo...ial-55788.html
(right now im using the eboot of this program)it sends the size of the message correctly, but it doesn't send the actual message right. I believe that the problem is that it sends the message as void, but then it doesn't get changed to a string or something, does anyone know how to do this???