8 Replies - 958 Views - Last Post: 17 April 2014 - 01:52 PM Rate Topic: -----

#1 PESOF   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-April 14

Need help for my project

Posted 15 April 2014 - 03:06 PM

Hello every body
first of all please don't laugh at my english :D
i am at the first year computer engineering and our professor gave us a project
(i am saying this just to let you know i might get lost in advanced stuff please try to make it simple for me :))
i am not going to ask you guys to do my project sure and i dont want you to think that
i just want some guid from you because really i dont know where to start from
our professor wants us to make a game (fat-slice) which main idea is a ball moving inside a shape and the user have to cut this shape without cutting the ball until certain level
but...he want it in c language using graphic.h (winbgim)
i know that graphic.h is 20 years old now and i know that you might hate me for this question but its my professor not me :S
i think my project is about (ball collision,and slicing shapes)
i searched relly well before asking this question but..again...i got lost
i found this code on internet about a bouncing ball i thought i can start from it
  #include <stdio.h>
  #include <conio.h>
  #include <graphics.h>
  #include <dos.h>

  int main() {
        /* request auto detection */
        int gdriver = DETECT, gmode, err;
        int i = 0, x = 0, y = 0, flag = 0;

        /* initialize graphic mode */
        initgraph(&gdriver, &gmode, "C:/TURBOC3/BGI");
        err = graphresult();

        if (err != grOk) {
                /* error happened */
                printf("Graphics Error: %s\n",
                                grapherrormsg(err));
                return 0;
        }

        /* ball movement */
        while (x <= getmaxx() && !kbhit()) {

                /* set the current drawing color */
                setcolor(LIGHTRED);
                /* fill the ball with given pattern & color */
                setfillstyle(SOLID_FILL, LIGHTRED);

                /* ball with light red color */
                pieslice(x, y, 0, 360, 12);

                /* ball movement towards x-axis */
                if (i % 5 == 0) {
                        /* left to right */
                        x = x + 3;
                        i = 0;
                }


                /* ball movement towards y-axis */
                if (flag) {
                        /* bottom to top */
                        y = y - 10;
                } else {
                        /* top to bottom */
                        y = y + 10;
                }

                /* check whether ball reached y-axis maximum */
                if (y >= getmaxy()) {
                        flag = 1;
                } else if (y <= 0) {
                        flag = 0;
                }

                /* sleeps for 50 milliseconds */
                delay(50);
                /* clear the graphic screen */
                cleardevice();
                i++;
        }

        getch();

        /* deallocate memory allocated for graphic system */
        closegraph();

        return 0;
  }

i tried it on Visual Studio 2010 , it worked and i understand 90% of it
what i dont understand is the *check whether ball reached y-axis maximum* part because actually i don't know what is flag and i searched google alot !
but i got really really lost after reading about it
what i need from you guys is please take a look at this code
do i need it for my project ?
if i do can you please make my life easier by explaining me what's happening there
because my professor didnt teach me what's flag


i know this is just the beginning of my problems and i will need much more help later but i will work hard if you helped me guys.

Is This A Good Question/Topic? 0
  • +

Replies To: Need help for my project

#2 #define   User is offline

  • Duke of Err
  • member icon

Reputation: 1853
  • View blog
  • Posts: 6,671
  • Joined: 19-February 09

Re: Need help for my project

Posted 15 April 2014 - 03:21 PM

Hi. Welcome to DIC.

The flag variable is a boolean variable so can be true or false, in C 0 is used for false and any other number for true often 1. A flag can be up or down.

flag starts at 0 (false) and on line 47 y increases when this is so.

When max y is reached the flag is set to 1 (true) and line 44 is executed decreasing y.

So the flag tells which direction the ball is moving and is changed when a limit is reached.
Was This Post Helpful? 0
  • +
  • -

#3 PESOF   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-April 14

Re: Need help for my project

Posted 17 April 2014 - 01:00 PM

thank you so much for your help:)
i got the idea now :)
and finally got something to work with
but i need your help in another thing
my professor told me to make a 2d array of 0 and 1
and draw the shape by ones
so the ball move only inside the ones and bounce back when it hits the zeros
please i couldnt find anything on internet like this
just tell me the steps and i will do it
if i declare a 2d array of 0s and 1s how can i make the ball move inside it
any help will be welcomed :)
Was This Post Helpful? 0
  • +
  • -

#4 infernorthor   User is offline

  • D.I.C Lover

Reputation: 362
  • View blog
  • Posts: 1,718
  • Joined: 07-February 14

Re: Need help for my project

Posted 17 April 2014 - 01:08 PM

What is the problem with a 2D array , have you looked how to make one.
Was This Post Helpful? 0
  • +
  • -

#5 PESOF   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-April 14

Re: Need help for my project

Posted 17 April 2014 - 01:31 PM

View Postinfernorthor, on 17 April 2014 - 01:08 PM, said:

What is the problem with a 2D array , have you looked how to make one.

sure i know how to make on
but i dont know how to connect this with the ball movement part
i
Was This Post Helpful? 0
  • +
  • -

#6 infernorthor   User is offline

  • D.I.C Lover

Reputation: 362
  • View blog
  • Posts: 1,718
  • Joined: 07-February 14

Re: Need help for my project

Posted 17 April 2014 - 01:36 PM

he wants the 2D to be a buffer to make it easier to calculate the bounce.

loop:
   calculate move;
   put in 2D buffer;
   show buffer with graphics.h;


Was This Post Helpful? 0
  • +
  • -

#7 PESOF   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-April 14

Re: Need help for my project

Posted 17 April 2014 - 01:43 PM

View Postinfernorthor, on 17 April 2014 - 01:36 PM, said:

he wants the 2D to be a buffer to make it easier to calculate the bounce.

loop:
   calculate move;
   put in 2D buffer;
   show buffer with graphics.h;


normally we make the movement part using coordinates
now what you are saying is (in general) to declare a 2d array
make the loop to check if the element is 0 or 1

but what makes me confused
how can i use the array elements like coordinates
Was This Post Helpful? 0
  • +
  • -

#8 infernorthor   User is offline

  • D.I.C Lover

Reputation: 362
  • View blog
  • Posts: 1,718
  • Joined: 07-February 14

Re: Need help for my project

Posted 17 April 2014 - 01:47 PM

I would've though it were obvious.
Pixels are 0,0 in top left and go up. Arrays start are 0 a double array starts are 0 0
Was This Post Helpful? 0
  • +
  • -

#9 PESOF   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 15-April 14

Re: Need help for my project

Posted 17 April 2014 - 01:52 PM

View Postinfernorthor, on 17 April 2014 - 01:47 PM, said:

I would've though it were obvious.
Pixels are 0,0 in top left and go up. Arrays start are 0 a double array starts are 0 0

OMG i think i got it some how :)
i will work on my code now
and to be honest
you are the only guy who accepted to help me :)
i have 4 years until i graduate and i think i will be a full time visitor in this website:)
thanks alot man i will work on it now and post if any thing came through :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1