Homebrew Shoot

cadw

Active Member
OP
Newcomer
Joined
Apr 13, 2011
Messages
25
Trophies
0
XP
105
Country
Netherlands
Can anyone help me??? I try to make a shooting function. Exactly the same as space invaders. I code in PAlib, but i already have this, but I don't know how to let it shoot:
CODE
#include

#include "all_gfx.h"

s16 framecount;
s32 x = 0; s32 y = 166;
int main(void){
PA_Init();
PA_LoadDefaultText(0, 0);
int bullet.x = 0;
int bullet.y = 180;
PA_LoadSpritePal(0, // Screen
0, // Palette number
(void*)red_Pal); // Palette name
PA_CreateSprite(0, 0, (void*)red_Sprite, OBJ_SIZE_32X32, 1, 0, 0, 160);
while(1){

PA_SetSpriteXY(0, // screen
0, // sprite
x, // x position
y); // y...
if(Pad.Held.Left){
x--;
}
if(Pad.Held.Right){
x++;
}
if(Pad.Newpress.A){
PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
PA_SetSpriteXY(0, 1, bullet.x, bullet.y++);
PA_SetSpriteXY(0, 0, x, 160);
}
if(Pad.Released.A){
PA_SetSpriteXY(0, 0, x, 160);
}
PA_WaitForVBL();
}
return 0;
}
BTW, srry for double post, but it was in the wi-fi folder!
angry.gif
 

Sausage Head

Lord Sausage LXIX
Member
Joined
Oct 28, 2010
Messages
1,675
Trophies
0
Age
21
Location
alanjohn check ur pm
XP
190
Country
Netherlands
I can't help you, but I have a few things to say.
First, don't make duplicate threads. You can use the "Report" button to report the thread to moderators, and they will move it for you.
Second, use CODE or CODEBOX tags. (with [ in front and ] behind)
 

cadw

Active Member
OP
Newcomer
Joined
Apr 13, 2011
Messages
25
Trophies
0
XP
105
Country
Netherlands
Sausage Head said:
I can't help you, but I have a few things to say.
First, don't make duplicate threads. You can use the "Report" button to report the thread to moderators, and they will move it for you.
Second, use CODE or CODEBOX tags. (with [ in front and ] behind)
I didn't know how to move it, can you also delete it?
 

cadw

Active Member
OP
Newcomer
Joined
Apr 13, 2011
Messages
25
Trophies
0
XP
105
Country
Netherlands
cadw said:
Can anyone help me??? I try to make a shooting function. Exactly the same as space invaders. I code in PAlib, but i already have this, but I don't know how to let it shoot:
CODE#include

#include "all_gfx.h"

s16 framecount;
s32 x = 0;ÂÂÂÂs32 y = 166;
int main(void){
PA_Init();
PA_LoadDefaultText(0, 0);
int bullet.x = 0;
int bullet.y = 180;
PA_LoadSpritePal(0, // Screen
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ0, // Palette number
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ(void*)red_Pal);ÂÂÂÂ// Palette nameÂÂÂÂ
PA_CreateSprite(0, 0, (void*)red_Sprite, OBJ_SIZE_32X32, 1, 0, 0, 160);
while(1){

PA_SetSpriteXY(0, // screen
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0, // sprite
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ x, // x position
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ y); // y...
if(Pad.Held.Left){
x--;
}
if(Pad.Held.Right){
x++;
}
if(Pad.Newpress.A){
PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
PA_SetSpriteXY(0, 1, bullet.x, bullet.y++);
PA_SetSpriteXY(0, 0, x, 160);
}
if(Pad.Released.A){
PA_SetSpriteXY(0, 0, x, 160);
}
PA_WaitForVBL();
}
returnÂÂ0;
}
BTW, srry for double post, but it was in the wi-fi folder!
angry.gif
 

Sausage Head

Lord Sausage LXIX
Member
Joined
Oct 28, 2010
Messages
1,675
Trophies
0
Age
21
Location
alanjohn check ur pm
XP
190
Country
Netherlands
No, regular users (you, me and the rest that have a normal black name color) can't move or delete posts. Using the "report" button we either request our posts to be moved, or report rulebreaking material. If something is rulebreaking, it either gets "snipped" away, or the full post gets deleted. If it's a request, it gets moved.

You can use the "Edit" button on the bottom of your post to edit it.
 

cadw

Active Member
OP
Newcomer
Joined
Apr 13, 2011
Messages
25
Trophies
0
XP
105
Country
Netherlands
Sausage Head said:
No, regular users (you, me and the rest that have a normal black name color) can't move or delete posts. Using the "report" button we either request our posts to be moved, or report rulebreaking material. If something is rulebreaking, it either gets "snipped" away, or the full post gets deleted. If it's a request, it gets moved.

You can use the "Edit" button on the bottom of your post to edit it.
I already reported it.
 

YoshiInAVoid

Banned!
Banned
Joined
Jan 10, 2011
Messages
560
Trophies
1
Website
google.com
XP
465
Country
I know how to make it shoot. Your problem lies here:

Code:
if(Pad.Newpress.A){
PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
[u][b]PA_SetSpriteXY(0, 1, bullet.x, bullet.y++);[/b][/u]
PA_SetSpriteXY(0, 0, x, 160);
}

First off it's all in a Pad.Newpress event, meaning it will only happen for one frame which is 1/60'th of a second, each time you press A. Secondly what you are saying is to set the bulet to bullet.y variable + 1, this doesn't change the variable at all so it will always just be one more than bullet.y no matter how hard you press A.

So first of all add a new variable like "ShouldShoot" and it's type needs to be a bool. Next, put it whithin the code quoted above:
Code:
if(Pad.Newpress.A){
PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
[u][b]ShouldShoot = true;[/b][/u]
PA_SetSpriteXY(0, 0, x, 160);
}

This means that the variable will stay at true until you make it go back to false.

Now you need to edit the variable bullet.y when the Shoot variable is true:
Code:
if(ShouldShoot==true){
bullet.y++;
}

Then at the end of the code, put your set position code for the bullet:
Code:
PA_SetSpriteXY(0, 1, bullet.x, bullet.y);




Hope this helps!
 

cadw

Active Member
OP
Newcomer
Joined
Apr 13, 2011
Messages
25
Trophies
0
XP
105
Country
Netherlands
YoshiInAVoid said:
I know how to make it shoot. Your problem lies here:

Code:
if(Pad.Newpress.A){
PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
[u][b]PA_SetSpriteXY(0, 1, bullet.x, bullet.y++);[/b][/u]
PA_SetSpriteXY(0, 0, x, 160);
}

First off it's all in a Pad.Newpress event, meaning it will only happen for one frame which is 1/60'th of a second, each time you press A. Secondly what you are saying is to set the bulet to bullet.y variable + 1, this doesn't change the variable at all so it will always just be one more than bullet.y no matter how hard you press A.

So first of all add a new variable like "ShouldShoot" and it's type needs to be a bool. Next, put it whithin the code quoted above:
Code:
if(Pad.Newpress.A){
PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
[u][b]ShouldShoot = true;[/b][/u]
PA_SetSpriteXY(0, 0, x, 160);
}

This means that the variable will stay at true until you make it go back to false.

Now you need to edit the variable bullet.y when the Shoot variable is true:
Code:
if(ShouldShoot==true){
bullet.y++;
}

Then at the end of the code, put your set position code for the bullet:
Code:
PA_SetSpriteXY(0, 1, bullet.x, bullet.y);




Hope this helps!
This is my new code, but it gives an air message.
CODE#include

#include "all_gfx.h"

s16 framecount;
s32 x = 0;ÂÂÂÂs32 y = 166;
bool ShouldShoot;
int main(void){
PA_Init();
PA_LoadDefaultText(0, 0);
int bullet.x = 0;
int bullet.y = 180;
PA_LoadSpritePal(0, // Screen
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ0, // Palette number
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ(void*)red_Pal);ÂÂÂÂ// Palette nameÂÂÂÂ
PA_CreateSprite(0, 0, (void*)red_Sprite, OBJ_SIZE_32X32, 1, 0, 0, 160);
while(1){

PA_SetSpriteXY(0, // screen
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ 0, // sprite
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ x, // x position
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ y); // y...
if(Pad.Held.Left){
x--;
}
if(Pad.Held.Right){
x++;
}
if(Pad.Newpress.A){
PA_CreateSprite(0, 1, (void*)bullet_Sprite, OBJ_SIZE_8X8, 1, 0, 0, 0);
ShouldShoot = true;
PA_SetSpriteXY(0, 0, x, 160);
}
if(ShouldShoot==true){
bullet.y++;
}
PA_SetSpriteXY(0, 1, bullet.x, bullet.y);
PA_WaitForVBL();
}
returnÂÂ0;
}
 

cadw

Active Member
OP
Newcomer
Joined
Apr 13, 2011
Messages
25
Trophies
0
XP
105
Country
Netherlands
YoshiInAVoid said:
May I ask what that error or "air" message is?
CODENo Maxmod-compatible files were found in the audio folder.
If you are loading the soundbank from the filesystem, ignore this message.

Build process start for project "rpg"...

main.c
c:/devkitPro/PAlib/examples/rpg/source/main.c: In function 'main':
c:/devkitPro/PAlib/examples/rpg/source/main.c:11:11: error: expected '=', ',', '
;', 'asm' or '__attribute__' before '.' token
c:/devkitPro/PAlib/examples/rpg/source/main.c:11:11: error: expected expression
before '.' token
c:/devkitPro/PAlib/examples/rpg/source/main.c:12:11: error: expected '=', ',', '
;', 'asm' or '__attribute__' before '.' token
c:/devkitPro/PAlib/examples/rpg/source/main.c:12:11: error: expected expression
before '.' token
c:/devkitPro/PAlib/examples/rpg/source/main.c:35:1: error: 'bullet' undeclared (
first use in this function)
c:/devkitPro/PAlib/examples/rpg/source/main.c:35:1: note: each undeclared identi
fier is reported only once for each function it appears in
make[1]: *** [main.o] Error 1
make: *** [build] Error 2
Druk op een toets om door te gaan. . .
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Psionic Roshambo @ Psionic Roshambo: @SylverReZ, Indeed lol