Author Topic: Mode 7 with Ndless !  (Read 16748 times)

0 Members and 1 Guest are viewing this topic.

Offline Matrefeytontias

  • Axe roxxor (kinda)
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1982
  • Rating: +310/-12
  • Axe roxxor
    • View Profile
    • RMV Pixel Engineers
Mode 7 with Ndless !
« 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":
Code: [Select]
#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 :)

Offline Alex

  • LV2 Member (Next: 40)
  • **
  • Posts: 32
  • Rating: +3/-0
    • View Profile
Re: Mode 7 with Ndless !
« Reply #1 on: September 30, 2012, 08:02:30 am »
C'est sympas matref. Continue :)

Offline Lionel Debroux

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2135
  • Rating: +290/-45
    • View Profile
    • TI-Chess Team
Re: Mode 7 with Ndless !
« Reply #2 on: September 30, 2012, 11:13:11 am »
Je suis tout à fait d'accord, mais english spoken here ;)
Member of the TI-Chess Team.
Co-maintainer of GCC4TI (GCC4TI online documentation), TILP and TIEmu.
Co-admin of TI-Planet.

Offline annoyingcalc

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1953
  • Rating: +140/-72
  • Found in Eclipse.exe
    • View Profile
Re: Mode 7 with Ndless !
« Reply #3 on: September 30, 2012, 12:04:52 pm »
NICE!
This used to contain a signature.

Offline cyanophycean314

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 363
  • Rating: +43/-1
  • It's You!
    • View Profile
Re: Mode 7 with Ndless !
« Reply #4 on: September 30, 2012, 09:08:25 pm »
Looks really nice!  :)

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: Mode 7 with Ndless !
« Reply #5 on: September 30, 2012, 11:11:45 pm »
Hey that looks pretty cool :D

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline Sorunome

  • Fox Fox Fox Fox Fox Fox Fox!
  • Support Staff
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 7920
  • Rating: +374/-13
  • Derpy Hooves
    • View Profile
    • My website! (You might lose the game)
Re: Mode 7 with Ndless !
« Reply #6 on: September 30, 2012, 11:43:32 pm »
That's looking awesome! :D

THE GAME
Also, check out my website
If OmnomIRC is screwed up, blame me!
Click here to give me an internet!

Offline tr1p1ea

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 647
  • Rating: +110/-0
    • View Profile
Re: Mode 7 with Ndless !
« Reply #7 on: October 01, 2012, 03:33:42 am »
Looking good, have you put any thought into rotations?
"My world is Black & White. But if I blink fast enough, I see it in Grayscale."


Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Mode 7 with Ndless !
« Reply #8 on: October 01, 2012, 03:36:07 am »
O.O looks really sweet! I wonder how it will look like with actual sprites?

Offline aeTIos

  • Nonbinary computing specialist
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3915
  • Rating: +184/-32
    • View Profile
    • wank.party
Re: Mode 7 with Ndless !
« Reply #9 on: October 01, 2012, 03:48:05 am »
code in spoiler <_<
Looks nice :D
I'm not a nerd but I pretend:

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Mode 7 with Ndless !
« Reply #10 on: October 01, 2012, 06:58:52 am »
That looks nice Matref :D
Also, you have +83 ratings :P

code in spoiler <_<
Did you mean "Chrome <_<" ? jk :P
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Alex

  • LV2 Member (Next: 40)
  • **
  • Posts: 32
  • Rating: +3/-0
    • View Profile
Re: Mode 7 with Ndless !
« Reply #11 on: October 01, 2012, 02:08:11 pm »
Je suis tout à fait d'accord, mais english spoken here ;)
Ok Hayleia, sorry ^^

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Mode 7 with Ndless !
« Reply #12 on: October 01, 2012, 05:51:42 pm »
Looks great!  Excellent work!


Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Mode 7 with Ndless !
« Reply #13 on: October 02, 2012, 01:16:41 am »
Je suis tout à fait d'accord, mais english spoken here ;)
Ok Hayleia, sorry ^^
??? That was not me :P
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Mode 7 with Ndless !
« Reply #14 on: October 02, 2012, 03:36:40 pm »
code in spoiler <_<
Not his fault if Chrome manages to be worse than Internet Explorer in certain ways :P