This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Messages - Matrefeytontias
Pages: 1 ... 111 112 [113 ] 114 115 ... 133
1681
« on: October 05, 2012, 04:11:00 am »
As I said, for now it's only for non-CX calcs -> no colors
1682
« on: October 05, 2012, 02:52:54 am »
Hi guys !
I'm working on my first real Ndless project in C, a port of the mobile game SpeedX 3D !
In this game, you're a ship, a man or whatever (in any case, you don't see yourself) trapped in a tunnel, and you have to run (or fly, if you're a ship
) while avoiding blocks which are in the tunnel. Why are there blocks here ? Who knows ...
It's the really beginning of the project, but I've already done a great part, I meant the 3D tunnel effect !
There is still this moiré I have to remove ...
Share comments, I'll update the thread often !
For now it only works on non-CX calcs !!!
1683
« on: October 02, 2012, 01:25:06 pm »
I don't know this func, how does it work ? (while we're on it)
1684
« on: October 02, 2012, 09:15:53 am »
* Matrefeytontias ups
I re-use this topic to post another similar problem :
I have a huge 16388 elements-array, and whatever the way I use to initialize it, it still doesn't work when I try to access it.
Here's my code (crashes when reach the only line involving texture[][]) :
#include <os.h> #include <common.h> #include <fdlibm.h> #include "utils.h" #include "texture.h" #define TEXTURE_WIDTH 128 #define TEXTURE_HEIGHT 128 int main(void) { char *screen; double (*angle_lut)[240]; double (*depth_lut)[240]; double relativeX, relativeY, tempRelative, angle, textureX, textureY; int w = 240, h = 240, x, y, color, screenX, screenY; angle_lut = malloc(240 * sizeof(*angle_lut)); if(!angle_lut) exit(0); depth_lut = malloc(240 * sizeof(*depth_lut)); if(!depth_lut) { free(angle_lut); exit(0); } screen = malloc(SCREEN_BYTES_SIZE * sizeof(char)); if(!screen) { free(angle_lut); free(depth_lut); exit(0); } for(y = 0; y < h; y++) { for(x = 0; x < w; x++) { relativeX = x - w / 2; relativeY = h / 2 - y; tempRelative = relativeX * relativeX + relativeY * relativeY; if(!tempRelative) depth_lut[x][y] = 0.0; else depth_lut[x][y] = 8388608 / tempRelative; if(!relativeY) { if(relativeX < 0) angle = -64; else angle = 64; } else { angle = atan(relativeX / relativeY) / (2*M_PI) * 128; if(relativeY > 0) angle += 128; } angle_lut[x][y] = angle * 8; } } while(!isKeyPressed(KEY_NSPIRE_ESC)) { clearBuf(screen); for(screenY = 0; screenY < h; screenY++) { for(screenX = 0; screenX < w; screenX++) { x = screenX - w/2; y = h/2 - screenY; // X is the angle, Y is the depth textureX = angle_lut[x][y]; textureY = depth_lut[x][y]; while(x < 0) { x += TEXTURE_WIDTH; } while(y < 0) { y += TEXTURE_HEIGHT; } while(x > TEXTURE_WIDTH) { x -= TEXTURE_WIDTH; } while(y > TEXTURE_HEIGHT) { y -= TEXTURE_HEIGHT; } color = texture[(int)textureY % 128][(int)textureX]; ← crashes when reach this line color %= 256; setPixelBuf(screen, screenX+40, screenY, (int)(abs(color-1)/16)); } } refresh(screen); } free(screen); free(angle_lut); free(depth_lut); return 0; }
And here is texture.h :
Spoiler For Spoiler :
unsigned short texture[128][128] = { { 0x2a01, 0x80, 0x80, 0x0, 0xad54, 0x944f, 0xa4b0, 0xa4b0, 0x9c90, 0xa4b0, 0xa4b0, 0xa4b0, 0xa4b0, 0xa46f, 0x9c6f, 0x942f, 0x9c6f, 0x9c4f, 0x9c6f, 0xa490, 0xacd0, 0xacd0, 0xa4b0, 0xacb0, 0x9c4f, 0xa46f, 0x942e, 0x8bed, 0x8c0e, 0x942f, 0x8bee, 0xa470, 0xa470, 0x9c90, 0x9c4f, 0x942e, 0xa470, 0xa490, 0xa4d0, 0xa4d1, 0xa4d1, 0xa4f1, 0xa4d1, 0xa4d1, 0xa4d1, 0xad11, 0xad32, 0xad12, 0xa4b0, 0xa4d0, 0xa4d0, 0xa4d1, 0xa4b0, 0xa4b0, 0x9cb0, 0xa4f1, 0xacf1, 0xa4f1, 0xa4f1, 0xad11, 0xacf1, 0xa4b1, 0xa4d1, 0xb532, 0xb572, 0xa4d1, 0xa4b1, 0xa4b0, 0x9cb0, 0x9c90, 0xa4b0, 0xa4b0, 0x9c6f, 0x9c90, 0x9c90, 0xa4b0, 0xa4f1, 0xa4d0, 0xa4b0, 0x9cb0, 0xa4d0, 0xacf1, 0xa4f1, 0xa4f0, 0xa4d0, 0xad12, 0xad12, 0xa4d0, 0xa4d1, 0xa4d1, 0xa4b0, 0xad32, 0xb553, 0xad11, 0xa4b0, 0xacf1, 0xb532, 0xb552, 0xb552, 0xbd73, 0xb532, 0xa4d1, 0x9c8f, 0xa4d0, 0xa4b1, 0x9c6f, 0x9c8f, 0x946f, 0x946f, 0x9caf, 0x944f, 0x9470, 0x944f, 0x9c70, 0x946f, 0x948f, 0xa4b0, 0x9c8f, 0x9c6f, 0x944f, 0x946f, 0xacf1, 0xa4d0, 0xa4b0, 0x9c6f, 0x9cb0, 0xa4f1, 0x9c6f }, { 0x944f, 0x944f, 0x944f, 0x83ee, 0x7b8c, 0x5a67, 0x6267, 0x5a67, 0x6aa8, 0x6288, 0x6287, 0x6287, 0x6aa7, 0x6267, 0x5a46, 0x5a26, 0x5a46, 0x5a46, 0x6287, 0x6267, 0x5a46, 0x6287, 0x6267, 0x6267, 0x5206, 0x5a46, 0x5206, 0x41a4, 0x4a05, 0x5226, 0x49c5, 0x5a26, 0x5a46, 0x5a46, 0x5a26, 0x5a46, 0x6287, 0x5a67, 0x6287, 0x6287, 0x6287, 0x62a8, 0x6ac8, 0x62a8, 0x6288, 0x6288, 0x6ac8, 0x62a8, 0x62a7, 0x62a8, 0x5a87, 0x6287, 0x62a7, 0x62a7, 0x62a8, 0x6ae8, 0x62a7, 0x6287, 0x6287, 0x6287, 0x6287, 0x6288, 0x6ac8, 0x62c7, 0x5aa7, 0x6287, 0x6288, 0x5a67, 0x5a67, 0x5a67, 0x62a7, 0x5a67, 0x5a67, 0x6287, 0x5a67, 0x5a67, 0x62a8, 0x6287, 0x5a87, 0x5a47, 0x5a67, 0x62a7, 0x62c8, 0x6ae8, 0x62a8, 0x6ae8, 0x6ac8, 0x6287, 0x5a67, 0x62a7, 0x62a8, 0x6ac8, 0x6ac8, 0x6ae8, 0x62c7, 0x62a7, 0x62c8, 0x6ae9, 0x6b09, 0x6ae8, 0x5aa7, 0x5266, 0x5246, 0x5266, 0x5aa7, 0x5266, 0x5226, 0x5226, 0x5a46, 0x5246, 0x4a06, 0x4a06, 0x49e5, 0x5226, 0x4a26, 0x5226, 0x5246, 0x5246, 0x5a66, 0x5246, 0x5226, 0x5a67, 0x5a47, 0x5246, 0x49e5, 0x5226, 0x6287, 0x5226 }, etcetera ... };
What can it be ?
1685
« on: September 30, 2012, 07:09:50 am »
Hi guys !
I programmed a simple but cool effect of Mode 7 (like the firsts F-Zero or Super Mario Kart) with C and nSDL, and I thank that I should share it
On the gif the program is laggy, but it's because of my bad PC ; on-calc it's way smoother.
Spoiler For "Source code" :
#include <os.h> #include <SDL/SDL.h> #define WIDTH 320 #define HALF_WIDTH 160 // WIDTH / 2 #define HEIGHT 240 #define HALF_HEIGHT 120 // HEIGHT / 2 #define SCALE_FACTOR 6 #define FACTOR 128 //(2<<(SCALE_FACTOR+1)) #define SPEED 4 int main(void) { SDL_Surface *screen; SDL_Rect pixelRect, clearRect; int Xib; short X0 = 0, Y0 = 0; clearRect.x = 0; clearRect.y = HALF_HEIGHT; clearRect.w = WIDTH; clearRect.h = 1; pixelRect.h = (pixelRect.w = 2); SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(WIDTH, HEIGHT, is_cx?16:8, SDL_SWSURFACE); while(!isKeyPressed(KEY_NSPIRE_ESC)) { for(pixelRect.x = 0; pixelRect.x < WIDTH; pixelRect.x += 2) { Xib = (pixelRect.x - HALF_WIDTH) * HEIGHT; for(pixelRect.y = HALF_HEIGHT; pixelRect.y < HEIGHT; pixelRect.y += 2) { if( ( (( (WIDTH - (Xib / pixelRect.y) + X0) >> SCALE_FACTOR) & 1) + (( (2 * (HEIGHT - pixelRect.y) + Y0) >> SCALE_FACTOR) & 1 ) ) & 1) { SDL_FillRect(screen, &pixelRect, (Uint32)0); } } } SDL_FillRect(screen, &clearRect, (Uint32)0); SDL_Flip(screen); SDL_FillRect(screen, NULL, (Uint32)0xffffffff); if(isKeyPressed(KEY_NSPIRE_LEFT)) { X0 = (FACTOR + X0 - SPEED) % FACTOR; } if(isKeyPressed(KEY_NSPIRE_RIGHT)) { X0 = (FACTOR + X0 + SPEED) % FACTOR; } if(isKeyPressed(KEY_NSPIRE_UP)) { Y0 = (FACTOR + Y0 - SPEED) % FACTOR; } if(isKeyPressed(KEY_NSPIRE_DOWN)) { Y0 = (FACTOR + Y0 + SPEED) % FACTOR; } } SDL_FreeSurface(screen); SDL_Quit(); return 0; }
Share comments
1686
« on: September 29, 2012, 11:30:53 am »
Here is the code which doesn't work for me.
In fact, once I try the code I just posted, it works
but just try the one I joined (it's the page 3).
Also, do you know a way to get text from a *.tns ?
1687
« on: September 29, 2012, 10:24:37 am »
Huge up, sorry
I'm having trouble with OCLua : why can't I use a for loop which runs more than 128 times ?
This code brings the calc into an infinite loop :
for i = 0, 128 do end
And this works fine :
for i = 0, 127 do end
1688
« on: September 29, 2012, 10:03:35 am »
In fact it's ok, I just cleaned all the malloc and now it works correctly
I'll keep this thread open in case of another problem
1689
« on: September 25, 2012, 02:40:44 pm »
It crashes if I try to display the available memory in any way, even by the Status menu.
1690
« on: September 25, 2012, 02:27:28 pm »
Okay, I'll take care of that. None of you see what should cause this leak ?
1691
« on: September 25, 2012, 01:25:39 pm »
Oh yeah, I'll correct that and I'll see.
1692
« on: September 25, 2012, 01:02:14 pm »
Hi guys !
I'm programming in C with Ndless, and I'm confused about a thing : I used several variables, I malloc'd all my pointers, I freed them before exiting, I also SDL_FreeSurface'd all the concerned pointers and ... I still have huge memory leaks (leading to a crash)
I post the code here, and if you can see something, please tell me
:
Spoiler For Spoiler :
#include <os.h> #include <SDL/SDL.h> #include <fdlibm.h> int main(void) { SDL_Surface *screen; SDL_Surface **ship; SDL_Surface *shots; SDL_Rect shipPos; SDL_Rect *shotPos; static unsigned short **shipSprites; static unsigned short *shotSprites; int shipAnim = 0; int *activeShot; int currentShot = 0; int shootDelay = 0; int i, j; // Malloc for SDL_Surface *screen screen = malloc(sizeof(SDL_Surface)); if(screen == NULL) exit(0); // Malloc for SDL_Surface *ship[3] ship = malloc(3*sizeof(SDL_Surface)); if(ship == NULL) { free(screen); exit(0); } for(i = 0; i < 3; i++) { ship[i] = malloc(sizeof(SDL_Surface)); if(ship[i] == NULL) { free(screen); for(j = 0; j < i; j++) free(ship[j]); free(ship); exit(0); } } // Malloc for SDL_Surface *shots shots = malloc(sizeof(SDL_Surface)); if(shots == NULL) { free(screen); for(j = 0; j < 3; j++) free(ship[j]); free(ship); exit(0); } // Malloc for SDL_Rect shotPos[128] shotPos = malloc(128 * sizeof(SDL_Rect)); if(shotPos == NULL) { free(screen); for(j = 0; j < 3; j++) free(ship[j]); free(ship); free(shots); exit(0); } // Malloc for int activeShot[128] activeShot = malloc(128 * sizeof(int)); if(activeShot == NULL) { free(screen); for(j = 0; j < 3; j++) free(ship[j]); free(ship); free(shots); free(shotPos); exit(0); } for(i = 0; i < 128; i++) activeShot[i] = 0; // Malloc for static unsigned short shipSprites[3][1408] shipSprites = malloc(3 * sizeof(*shipSprites)); if(shipSprites == NULL) { free(screen); for(j = 0; j < 3; j++) free(ship[j]); free(ship); free(shots); free(activeShot); free(shotPos); exit(0); } for(i = 0; i < 3; i++) { shipSprites[i] = malloc(1408 * sizeof(unsigned short)); if(shipSprites[i] == NULL) { free(screen); for(j = 0; j < 3; j++) free(ship[j]); free(ship); free(shots); for(j = 0; j < i; j++) free(shipSprites[j]); free(shipSprites); free(activeShot); free(shotPos); exit(0); } } #include "shipSpritesC.util" // Malloc for static unsigned short shotSprites[49] shotSprites = malloc(49 * sizeof(unsigned short)); if(shotSprites == NULL) { free(screen); for(j = 0; j < 3; j++) free(ship[j]); free(ship); free(shots); for(i = 0; i < 3; i++) free(shipSprites[i]); free(shipSprites); free(activeShot); free(shotPos); exit(0); } #include "shotSpritesC.util" SDL_Init(SDL_INIT_VIDEO); screen = SDL_SetVideoMode(320, 240, is_cx?16:8, SDL_SWSURFACE); shots = nSDL_LoadImage(shotSprites); for(i = 0; i < 3; i++) ship[i] = nSDL_LoadImage(shipSprites[i]); for(i = 0; i < 127; i++) activeShot[i] = 0; while(!isKeyPressed(KEY_NSPIRE_ESC)) { if(isKeyPressed(KEY_NSPIRE_DOWN) && shipPos.y < 204) shipPos.y++; if(isKeyPressed(KEY_NSPIRE_LEFT) && shipPos.x > 0) shipPos.x--; if(isKeyPressed(KEY_NSPIRE_RIGHT) && shipPos.x < 281) shipPos.x++; if(isKeyPressed(KEY_NSPIRE_UP) && shipPos.y > 0) shipPos.y--; if(isKeyPressed(KEY_NSPIRE_LEFT) && !isKeyPressed(KEY_NSPIRE_RIGHT)) shipAnim = 1; else if (isKeyPressed(KEY_NSPIRE_RIGHT) && !isKeyPressed(KEY_NSPIRE_LEFT)) shipAnim = 2; else shipAnim = 0; if(isKeyPressed(KEY_NSPIRE_CTRL) && !shootDelay) { activeShot[currentShot] = 1; shotPos[currentShot].x = shipPos.x + (ship[shipAnim]->w - shots->w)/2; shotPos[currentShot].y = shipPos.y; currentShot = (currentShot + 1) % 128; shootDelay = 32; } for(i = 0 ; i < 127 ; i++) { if(activeShot[i]) { shotPos[i].y -= 3; SDL_BlitSurface(shots, NULL, screen, &shotPos[i]); if(shotPos[i].y < 4) activeShot[i] = 0; } } SDL_BlitSurface(ship[shipAnim], NULL, screen, &shipPos); SDL_Flip(screen); SDL_FillRect(screen, NULL, (Uint32)0xFFFFFFFF); shootDelay = (shootDelay > 0 ? shootDelay - 1 : 0); } SDL_FreeSurface(shots); SDL_FreeSurface(screen); for(i = 0; i < 3; i++) { SDL_FreeSurface(ship[i]); } free(screen); for(j = 0; j < 3; j++) free(ship[j]); free(ship); free(shots); free(shotSprites); for(i = 0; i < 3; i++) free(shipSprites[i]); free(shipSprites); free(activeShot); free(shotPos); SDL_Quit(); return 0; }
The *.util files is the files where I fill shipSprites and shotSprites with sprites' datas. I'm not doing anything more than repetitively write "shipSprites[blah][blah] = ..."
1693
« on: September 23, 2012, 12:16:00 pm »
Oh yeah, thanks a lot
1694
« on: September 23, 2012, 10:34:47 am »
Hi guys !
I'm working on a raycaster in C for Ndless, but I can't find these funcs :
All I need is a way to use these funcs, and then I'll finish it.
Thanks by advance :)
1695
« on: September 22, 2012, 10:43:55 am »
... Ah
I didn't see this one, but I'll finish mine anyway ^^
EDIT : little update !
When you grab a crate, there now is a little text indicating which weapon you got
Pages: 1 ... 111 112 [113 ] 114 115 ... 133