gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Use both screens for breakout?

#40331 - chrissieboy - Sun Apr 17, 2005 5:13 pm

HI all,

im making a game like breakout, and with use of the touch screen.
Everything was going really well, but now i got a weird problem..

My ball is moving on the touch screen, and when it lefts the touchscreen and goes to the up screen the problems begin.

I made this collision code to detect if the touchscreen is leaving and that my sprite must going furthur on the upscreen.

i made this code :
Code:

      // x as touchscreen
      
         if (sprites[ball_on_touchscreen].x>236<<8)
            {
            sprites[ball_on_touchscreen]xSpeed=(-speed);
            }
            
         if (sprites[ball_on_touchscreen]x<4<<8)
            {
            sprites[ball_on_touchscreen].xSpeed=(speed);
            }
            
         // y as   touchscreen
         
         if (sprites[ball_on_touchscreen].y>172<<8)
            {
            sprites[ball_on_touchscreen].ySpeed=(-speed);
            }
            
         if (sprites[ball_on_touchscreen].y<4<<8)
            {
            sprites[ball_on_touchscreen].x=sprites[ball_on_touchscreen].x;
            sprites[ball_on_touchscreen].y=170<<8;
            sprites[ball_on_touchscreen].xSpeed = sprites[ball_on_touchscreen].xSpeed;
            sprites[ball_on_touchscreen].ySpeed = sprites[ball_on_touchscreen].xSpeed;
            }
            
         if (sprites[ball_on_touchscreen].y>1<<8 && sprites[ball_on_touchscreen].y<170<<8)
            {
            ball_moves_on_touchscreen = true;
            }
//----------------------------------------------------
      // The up screen

         if (sprites[ball_on_upscreen].x>236<<8)
            {
            sprites[ball_on_upscreen].xSpeed=(-speed);
            }
            
         if (sprites[ball_on_upscreen].x<4<<8)
            {
            sprites[ball_on_upscreen].xSpeed=(speed);
            }
            
         // y as   touchscreen
         
         if (sprites[ball_on_upscreen].y>172<<8)
            {
            sprites[ball_on_upscreen].ySpeed=(-speed);
            }
            
         if (sprites[ball_on_upscreen].y<2<<8)
            {
            sprites[ball_on_upscreen].ySpeed=(speed);
            }
         
         if (sprites[ball_on_upscreen].y<140<<8)
            {
            ball_moves_on_touchscreen = false;
            }



speed is the speed i declared that is 2<<8

But the problem is that when it is in the up screen and it bounced to the top of that screen, then it bounces down.
And on a half of the screen the ball disapears and starts again from point 172<<8??

I dont know whats the problem with this script??
Im busy with it for a whole day know..
So i had take a look on josath his page and downloaded the birds demo.
Because this one uses both screens, and i saw that he had made a code for it.
But i had use aronroogers.com his nds dev setup, but i cant compile the birds demo it gives a lot of errors.
And in his text files i saw that it would not compile with this setup.

So PLEASE can someone help me or you josath?????

Very much thanx!!


Last edited by chrissieboy on Sun Apr 17, 2005 6:36 pm; edited 2 times in total

#40336 - sajiimori - Sun Apr 17, 2005 6:19 pm

It's hard to understand your code because of the magic numbers and the unclear interaction between the screens.

I suggest doing smaller tasks, one at a time. Try making a ball that just moves up from the bottom screen to the top, or from the top to the bottom, with no bouncing.

If you're interested in simplifying your logic at all, remember what you're simulating: a single space with a single ball moving through it. Each screen is like a window into that space. Your data structures should reflect that.
Code:

enum
{
  SCREEN_TOP,
  SCREEN_BOTTOM,
  SCREEN_NUM
};

typedef s32 Fixed;

struct Vector2
{
  Fixed x, y;
};

Vector2 cameraPositions[SCREEN_NUM];

struct Ball
{
  Vector2 position;
  Vector2 velocity;
};

Ball ball;

struct Rectangle
{
  Vector2 topLeft;
  Vector2 size;
};

Rectangle boardArea;

In the logic code, the ball moves at its velocity, and bounces off the edges of the boardArea rectangle. The logic doesn't care that there are two screens.

In the drawing code, you subtract the camera location from an object's world position to get its screen position.

#40338 - chrissieboy - Sun Apr 17, 2005 6:30 pm

im sorry for the magic numbers i shall edit it.

But you suggest that i must make a code that see the 2 screens of 256 * 190 as a big screen of 512 * 380???

Thats a good idea! I saw that on josath's code of birds he does the same.
Only that would not work for me??
But josath had to compile it but i can't compile it???

Do you have a code that i can use for both screens as one screen that can compile with aaronrogers.com tutorial of dev setup?

And i had take a look at your code but im very new to C.
I always used visual basic, so it says nothing to me?? So i think i must read alot...

But thanx anyway for your code, i think im now going to read everything i dont understand on google, from your code.

I'll edit my code one moment please

#40356 - dagamer34 - Sun Apr 17, 2005 11:11 pm

chrissieboy wrote:
im sorry for the magic numbers i shall edit it.

But you suggest that i must make a code that see the 2 screens of 256 * 190 as a big screen of 512 * 380???

Thats a good idea! I saw that on josath's code of birds he does the same.
Only that would not work for me??
But josath had to compile it but i can't compile it???

Do you have a code that i can use for both screens as one screen that can compile with aaronrogers.com tutorial of dev setup?

And i had take a look at your code but im very new to C.
I always used visual basic, so it says nothing to me?? So i think i must read alot...

But thanx anyway for your code, i think im now going to read everything i dont understand on google, from your code.

I'll edit my code one moment please


The number of horizontal pixels don't change. Just pretend it's a large 256*384 screen
_________________
Little kids and Playstation 2's don't mix. :(

#40386 - chrissieboy - Mon Apr 18, 2005 9:20 am

yeah you're right!! its 512 384 with 4 displays !! Stupid from me!!

#40391 - tepples - Mon Apr 18, 2005 2:22 pm

Anyway, I think you should treat it as 256x480 or something with a 96-pixel or so gap between the screens because there's a gap between the actual screens.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#40403 - dagamer34 - Mon Apr 18, 2005 6:26 pm

tepples wrote:
Anyway, I think you should treat it as 256x480 or something with a 96-pixel or so gap between the screens because there's a gap between the actual screens.


I wish emulators would somehow compensate for that by using a picture of a Nintendo DS and have the emulator screens where the real screens would be. That way we can get a real look at perspective differences without having to use hardware.

In otherwords, for example, if one were able to emulate Metroid Prime Hunters: First Hunt, the opening video wouldn't look correct because of the space between the screens
_________________
Little kids and Playstation 2's don't mix. :(