Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 112 users online: 5 members, 76 guests and 31 bots. Members: CalebHansberry, flyingfisch, gbl08ma, LuxenD. Bots: VoilaBot (1), Spinn3r (2), Magpie Crawler (4), VoilaBot (3), Googlebot (21).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
|
| Author |
Message |
|
Spenceboy98

Super-Expert

Joined: 06 Jan 2012 Posts: 823 Location: In the TARDIS
|
Posted: 22 Apr 2012 06:56:03 pm Post subject: Bullet Code Problems |
|
|
Bullet is the name of the game I'm making, but the code is being spo annoying. I can't figure out what's wrong. Help please:
Code: #include "keyboard.hpp"
#include "color.h"
#include "display.h"
#include "keyboard_syscalls.h"
#include "PictureData.h"
#include "stdlib.h"
void CopySprite(const void* datar, int x, int y, int width, int height) {
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
*(VRAM++) = *(data++);
}
VRAM += LCD_WIDTH_PX-width;
}
}
void CopySpriteMasked(const void*datar, int x, int y, int width, int height, int maskcolor) {
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
if (*(data) != maskcolor) {
*(VRAM++) = *(data++);
} else { VRAM++; data++; }
}
VRAM += LCD_WIDTH_PX-width;
}
}
int PRGM_GetKey(){
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
struct Coord {
int x;
int y;
};
int keydown(int basic_keycode)
{
const unsigned short* keyboard_register = (unsigned short*)0xA44B0000;
int row, col, word, bit;
row = basic_keycode%10;
col = basic_keycode/10-1;
word = row>>1;
bit = col + 8*(row&1);
return (0 != (keyboard_register[word] & 1<<bit));
}
void moveCursor(struct Coord* cursor) {
if( keydown(KEY_PRGM_LEFT) && cursor->x>45) cursor->x-=8;
if( keydown(KEY_PRGM_RIGHT) && cursor->x<302) cursor->x+=8;
}
int main() {
int y = 129;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
CopySprite(BulletMenu, 0, 0, 384, 216);
CopySpriteMasked(BulletMenuSelector, 7, y, 18, 16, COLOR_RED);
if(keydown(KEY_PRGM_UP) && y>129)
y-=16;
if(keydown(KEY_PRGM_DOWN) && y<145)
y+=16;
if(keydown(KEY_PRGM_SHIFT) && y == 129) {
while(1) {
struct Coord cur;
cur.x = 128;
int w = rand()%(340-45+1) + 45;
int b = rand()%(340-45+1) + 45;
int j = 0;
int s = 0;
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BulletBackground, 0, 0, 384, 216);
CopySpriteMasked(SpenBullet, cur.x, 159, 38, 43, COLOR_RED);
CopySpriteMasked(Banana, w, j, 75, 80, COLOR_RED);
CopySpriteMasked(LSDOMG, b, j, 34, 34, COLOR_RED);
if(w == cur.x && j == 159)
break;
if(b == cur.x && j == 159)
s++;
j+=8;
if(j >= 216) {
j = 0;
w = rand()%(340-45+1) + 45;
b = rand()%(340-45+1) + 45;
}
if(keydown(KEY_PRGM_EXIT))
break;
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
} }
if(keydown(KEY_PRGM_SHIFT) && y == 145) {
while(1) {
CopySprite(Instructions, 0, 0, 384, 216);
if(keydown(KEY_PRGM_EXIT))
break;
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
}
return 0;
}
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
}
return 0;
}
Help fix it. PLEASE! |
|
| Back to top |
|
|
souvik1997

Guru-in-Training

Joined: 19 Apr 2010 Posts: 2870
|
Posted: 22 Apr 2012 06:57:41 pm Post subject: |
|
|
What's happening with your code? We can't just magically fix it if you don't tell us what's wrong. _________________ CALCnet Tournament-38%
deviantArt
 |
|
| Back to top |
|
|
Spenceboy98

Super-Expert

Joined: 06 Jan 2012 Posts: 823 Location: In the TARDIS
|
Posted: 22 Apr 2012 07:00:03 pm Post subject: |
|
|
When I put it on my Prizm, the Banana/LSDOMG sprites jerk around the top of the screen. Even though it is supposed to make them scroll to the bottom of the screen and regenerate somewhere else at the top.
Edit:
Here is the g3a file. Enjoy.....
http://www.mediafire.com/?79bchn1nyyfcyv2 |
|
| Back to top |
|
|
souvik1997

Guru-in-Training

Joined: 19 Apr 2010 Posts: 2870
|
Posted: 22 Apr 2012 07:08:19 pm Post subject: |
|
|
| Quote: | int w = rand()%(340-45+1) + 45;
int b = rand()%(340-45+1) + 45;
int j = 0;
int s = 0;
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BulletBackground, 0, 0, 384, 216);
CopySpriteMasked(SpenBullet, cur.x, 159, 38, 43, COLOR_RED);
CopySpriteMasked(Banana, w, j, 75, 80, COLOR_RED);
CopySpriteMasked(LSDOMG, b, j, 34, 34, COLOR_RED); |
You're setting the coordinates for the sprites every time the loop repeats. Set the variables outside the loop. _________________ CALCnet Tournament-38%
deviantArt
 |
|
| Back to top |
|
|
Spenceboy98

Super-Expert

Joined: 06 Jan 2012 Posts: 823 Location: In the TARDIS
|
Posted: 22 Apr 2012 07:15:50 pm Post subject: |
|
|
| Now how will I make it detect if the banana or coin(LSDOMG) hits it or not?......... |
|
| Back to top |
|
|
souvik1997

Guru-in-Training

Joined: 19 Apr 2010 Posts: 2870
|
|
| Back to top |
|
|
Spenceboy98

Super-Expert

Joined: 06 Jan 2012 Posts: 823 Location: In the TARDIS
|
Posted: 22 Apr 2012 07:21:10 pm Post subject: |
|
|
| Yes, but it only detects when it is exactly the same coordinates. |
|
| Back to top |
|
|
Ashbad

... I think redheaded girls are kind of cool

Joined: 01 Dec 2010 Posts: 2417 Location: Stomp Stomp Stomp, The Idiot Convention
|
Posted: 22 Apr 2012 07:22:23 pm Post subject: |
|
|
| Spenceboy98 wrote: | | Yes, but it only detects when it is exactly the same coordinates. |
Seems you're going to need to check if it's in a box of a certain size, using position offsets and the >, <, >=, <= operators instead of the == operator. _________________ -Ashbad |
|
| Back to top |
|
|
_player1537

Guru-in-Training

Joined: 25 Nov 2009 Posts: 2957
|
Posted: 22 Apr 2012 07:24:28 pm Post subject: |
|
|
Or you could use the absolute value trick. Such as: if (abs(bulletX - playerX) <= 10) { /* within 10 pixels on either side */ }. _________________ http://tanner.myserverathome.com
 |
|
| Back to top |
|
|
Spenceboy98

Super-Expert

Joined: 06 Jan 2012 Posts: 823 Location: In the TARDIS
|
Posted: 23 Apr 2012 06:17:20 pm Post subject: |
|
|
| _player1537 wrote: | | Or you could use the absolute value trick. Such as: if (abs(bulletX - playerX) <= 10) { /* within 10 pixels on either side */ }. |
Now it says
Code: main.c:99:5: warning: implicit declaration of function 'abs' [-Wimplicit-functio
n-declaration]
Now what? |
|
| Back to top |
|
|
Ashbad

... I think redheaded girls are kind of cool

Joined: 01 Dec 2010 Posts: 2417 Location: Stomp Stomp Stomp, The Idiot Convention
|
Posted: 23 Apr 2012 06:19:37 pm Post subject: |
|
|
you need to define abs.
Code: inline int abs(int a) { return (a < 0) ? (-a) : (a); }
_________________ -Ashbad |
|
| Back to top |
|
|
Spenceboy98

Super-Expert

Joined: 06 Jan 2012 Posts: 823 Location: In the TARDIS
|
Posted: 23 Apr 2012 06:26:32 pm Post subject: |
|
|
| Now, whenever you are underneath the bullet coming toward you, it exits anyways. No matter how far away from it you are. |
|
| Back to top |
|
|
KermMartian

Site Admin

Joined: 14 Mar 2005 Posts: 55742 Location: Earth, Sol, Milky Way
|
|
| Back to top |
|
|
blue_bear_94
Member

Joined: 20 Apr 2012 Posts: 162
|
Posted: 24 Apr 2012 05:00:17 pm Post subject: |
|
|
I think the abs( function was already defined in stdlib.h. _________________ Do NOT click any links! |
|
| Back to top |
|
|
Ashbad

... I think redheaded girls are kind of cool

Joined: 01 Dec 2010 Posts: 2417 Location: Stomp Stomp Stomp, The Idiot Convention
|
Posted: 24 Apr 2012 05:01:16 pm Post subject: |
|
|
| blue_bear_94 wrote: | | I think the abs( function was already defined in stdlib.h. |
Unfortunately, the PrizmSDK's C standard library is far from being completely filled in; abs() isn't defined there officially yet. _________________ -Ashbad |
|
| Back to top |
|
|
merthsoft
File Archiver

Joined: 09 May 2010 Posts: 2735
|
Posted: 24 Apr 2012 05:02:01 pm Post subject: |
|
|
| KermMartian wrote: | | Ashbad wrote: | you need to define abs.
Code: inline int abs(int a) { return (a < 0) ? (-a) : (a); }
| There's a better way to do this:
Code: #define abs(a) ((a) < 0 ? (-(a)):(a)) This will work for any numeric data type.  | And breaks for abs(someFuncThatReturnsAValue()) and abs(x++), right? I remember benryves and Catherine talking about this last night. In any case, I prefer functions to macros. Macros feel dirty. _________________ Shaun |
|
| Back to top |
|
|
Tari

Systems Integrator

Joined: 03 Jul 2006 Posts: 2107 Location: Always-winter, Michigan
|
|
| Back to top |
|
|
Spenceboy98

Super-Expert

Joined: 06 Jan 2012 Posts: 823 Location: In the TARDIS
|
Posted: 28 Apr 2012 03:12:48 pm Post subject: |
|
|
I'm guessing that it is too big to compile:
Code: /prizmsdk-0.3/prizmsdk-0.3/bin/../lib/gcc/sh3eb-elf/4.6.0/../../../../sh3eb-
elf/bin/ld.exe: region `rom' overflowed by 159776 bytes
collect2: ld returned 1 exit status
make: *** [Bullet.bin] Error 1
|
|
| Back to top |
|
|
Ashbad

... I think redheaded girls are kind of cool

Joined: 01 Dec 2010 Posts: 2417 Location: Stomp Stomp Stomp, The Idiot Convention
|
Posted: 28 Apr 2012 03:16:29 pm Post subject: |
|
|
| Spenceboy98 wrote: | I'm guessing that it is too big to compile:
Code: /prizmsdk-0.3/prizmsdk-0.3/bin/../lib/gcc/sh3eb-elf/4.6.0/../../../../sh3eb-
elf/bin/ld.exe: region `rom' overflowed by 159776 bytes
collect2: ld returned 1 exit status
make: *** [Bullet.bin] Error 1
|
What did you stick in it, 3 screen-sized textures? If you want to make it bigger, change your "rom: l=500K" (or something like that) in Prizm.ld in the "common" folder of the SDK to "l=1250K", which is a safe number. _________________ -Ashbad |
|
| Back to top |
|
|
Spenceboy98

Super-Expert

Joined: 06 Jan 2012 Posts: 823 Location: In the TARDIS
|
Posted: 30 Apr 2012 09:05:43 pm Post subject: |
|
|
It doesn't display the pic at the end. Here's code:
Code: int main() {
int y = 129;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
CopySprite(BulletMenu, 0, 0, 384, 216);
CopySpriteMasked(BulletMenuSelector, 7, y, 18, 16, COLOR_RED);
if(keydown(KEY_PRGM_UP) && y>129)
y-=16;
if(keydown(KEY_PRGM_DOWN) && y<145)
y+=16;
if(keydown(KEY_PRGM_SHIFT) && y == 129) {
struct Coord cur;
cur.x = 128;
cur.y = 159;
int w = rand()%(265-45+1) + 45;
int b = rand()%(306-45+1) + 45;
int j = -80;
int m = -34;
int s = 0;
int t = 0;
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
moveCursor(&cur);
CopySprite(BulletBackground, 0, 0, 384, 216);
CopySpriteMasked(SpenBullet, cur.x, cur.y, 38, 43, COLOR_RED);
CopySpriteMasked(Banana, w, j, 75, 80, COLOR_RED);
CopySpriteMasked(LSDOMG, b, m, 34, 34, COLOR_RED);
if ((cur.x >= w+10 && cur.x <= w+59) && (cur.y >= j+15 && cur.y <= j+71))
break;
if ((cur.x >= b+4 && cur.x <= b+30) && (cur.y >= m+4 && cur.y <= m+30)) {
s++;
m = -34;
b = rand()%(340-45+1) + 45;}
j+=8;
m+=8;
if(j > 216) {
j = -80;
w = rand()%(340-45+1) + 45; }
if(m > 216) {
m = -34;
b = rand()%(340-45+1) + 45;}
if(keydown(KEY_PRGM_EXIT))
break;
t++;
if(t >= 1000){
CopySprite(BulletPerson, 0, 0, 384, 216);
break;}
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
} }
if(keydown(KEY_PRGM_SHIFT) && y == 145) {
while(1) {
CopySprite(Instructions, 0, 0, 384, 216);
if(keydown(KEY_PRGM_EXIT))
break;
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
}
}
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
}
return 0;
}
|
|
| Back to top |
|
|
|
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.
» Go to Registration page
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.043422 seconds.
|