delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/01/22/03:53:13

From: Damian Yerrick <MYNAMEISd_yerrick AT hotmail DOT comNO2CANNEDHAM>
Newsgroups: comp.os.msdos.djgpp
Subject: Code: Projectile Bouncing off walls
Organization: Pin Eight Software <http://pineight.8m.com/>
Message-ID: <bn6i8scpf5dsbkr7pj20cfj7mu3sg90a18@4ax.com>
References: <3888F4D3 DOT 5EDC8FBC AT geocities DOT com>
X-Newsreader: Forte Agent 1.7/32.534
MIME-Version: 1.0
Lines: 322
X-Trace: /bQfoR+5NmUulgvQIQnDVxdlDFjXN12jdVetAh1gQXlR7xiGnxgv8u4JepLibza0a364sBcSWZiM!AqZ+iFVzcTvAA+OgCHAxAvmj4YXoSiNgVPW4GuKug0KuTZhon/Vno+SzwoUPDU5pSFGcmo9+Dl0=
X-Complaints-To: abuse AT gte DOT net
X-Abuse-Info: Please be sure to forward a copy of ALL headers
X-Abuse-Info: Otherwise we will be unable to process your complaint properly
NNTP-Posting-Date: Sat, 22 Jan 2000 02:57:15 GMT
Distribution: world
Date: Sat, 22 Jan 2000 02:57:15 GMT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Fri, 21 Jan 2000 19:07:47 -0500, Sahab Yazdani
<beyonder69 AT geocities DOT com> wrote:

>Hello I have written a simple trajectory calcutation system using
>Velocity, Angle, wind and gravity. Now lets say I want to make the
>projectile bounce off the wall.. How would I go about doing this???


Here's an Allegro program in which the mouse controls the wind, and
the pointer bounces off the screen edges and is attracted to the
bottom.




/**************************************\
* DJTESTS.C                            *
* Test DJGPP properties                *
* By Damian Yerrick                    *
\**************************************/

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <dos.h>
#include <mem.h>

#include <allegro.h>



/* DY_action_proc() ********************
 * By Damian Yerrick
 * Inherits from d_button_proc()
 * Declare this control as D_EXIT in your dialog item list.
 *
 * When clicked, this button calls the function in dp2:
 *   int foobar(DIALOG *d);
 * Then it un-highlights the button and returns what the callback
returned.
 */
int DY_action_proc(int msg, DIALOG *d, int c)
{
  int ret;

  /* call the parent object */
  ret = d_button_proc(msg, d, c);

  /* trap the close return value and call the function */
  if(ret == D_CLOSE)
  {
    int (*callback)(DIALOG *d);

    // redraw button without highlight
    scare_mouse();
    ret = d_button_proc(MSG_DRAW, d, c);
    unscare_mouse();

    // call the callback function
    callback = d->dp2;
    if(callback != NULL)
      ret |= (*callback)(d);
  }

  /* otherwise just return */
  return ret;
}

int forcemouse(DIALOG *unused1)
{
  int mickeyX, mickeyY;
  fixed xvel = 0, yvel = 0, x = 160 << 16, y = 100 << 16;
  int lastClock = retrace_count;
  char done = 0;

//  show_mouse(NULL);
  clear(screen);

  while(done == 0)
  {
    get_mouse_mickeys(&mickeyX, &mickeyY);
    xvel += mickeyX << 8;
    yvel += mickeyY << 8;
    x += xvel;
    y += yvel;
    xvel -= xvel / 256;
    yvel -= yvel / 256 - 256;

    if(x < 0)
    {
      x = 0;
      xvel = -xvel >> 1;
    }
    if(y < 0)
    {
      y = 0;
      yvel = -yvel >> 1;
    }

    if(x >= 320 << 16)
    {
      x = (320 << 16) - 1;
      xvel = -xvel >> 1;
    }
    if(y >= 200 << 16)
    {
      y = (200 << 16) - 1;
      yvel = -yvel >> 1;
    }
    position_mouse(x >> 16, y >> 16);

    while(lastClock == retrace_count)
      ;
    lastClock = retrace_count;

    if(keypressed())
    {
      readkey();
      done = 1;
    }
  }

//  show_mouse(screen);

  return D_REDRAW;
}

int fileMenu_Open()
{
  char path[128] = ".";

  if(file_select("Play which sound?", path, "WAV;VOC"))
  {
    SAMPLE *wav;

    scare_mouse();
    clear(screen);
    unscare_mouse();
    if(install_sound(DIGI_AUTODETECT, MIDI_NONE, NULL) != 0)
    {
      textout(screen, font, "Couldn't install a wave driver:", 0, 0,
15);
      textout(screen, font, allegro_error, 0, 0, 15);
      return D_REDRAW;
    }

    wav = load_sample(path);
    play_sample(wav, 240, 128, 1000, FALSE);
    readkey();
    destroy_sample(wav);
    remove_sound();
  }

  return D_REDRAW;
}



int fileMenu_Quit()
{
  return D_CLOSE;
}

int sexMenu_Male()
{
  scare_mouse();
  clear(screen);
  text_mode(0);
  textout(screen, font, "chose male", 8, 8, 15);
  unscare_mouse();
  readkey();
  return D_REDRAW;
}

int sexMenu_Female()
{
  scare_mouse();
  clear(screen);
  text_mode(0);
  textout(screen, font, "chose female", 8, 8, 15);
  unscare_mouse();
  readkey();
  return D_REDRAW;
}

MENU fileMenu[] =
{
// text                 proc            child           flags
  {" &New\tCtrl+N",     NULL,           NULL,           0},
  {" &Open...\tCtrl+O", fileMenu_Open,  NULL,           0},
  {" &Save\tCrrl+S",    NULL,           NULL,           0},
  {" Save &As...",      NULL,           NULL,           0},
  {"",                  NULL,           NULL,           0},
  {" &Quit\tCtrl+Q",    fileMenu_Quit,  NULL,           0},
  {NULL,                NULL,           NULL}
};

MENU editMenu[] =
{
// text                 proc            child           flags
  {"Undo\tCtrl+Z",      NULL,           NULL,           0},
  {"",                  NULL,           NULL,           0},
  {"Cu&t\tCtrl+X",      NULL,           NULL,           0},
  {"&Copy\tCtrl+C",     NULL,           NULL,           0},
  {"&Paste\tCtrl+V",    NULL,           NULL,           0},
  {"C&lear\tDel",       NULL,           NULL,           0},
  {"Select &All\tCtrl+A", NULL,         NULL,           0},
  {"",                  NULL,           NULL,           0},
  {"Show Clipboard",    NULL,           NULL,           0},
  {NULL,                NULL,           NULL}
};

MENU sexMenu[] =
{
// text                 proc            child           flags
  {"&Male",             sexMenu_Male,   NULL,           0},
  {"&Female",           sexMenu_Female, NULL,           0},
  {NULL,                NULL,           NULL}
};

MENU TestGUI_menu[] =
{
// text                 proc            child           flags
dp
  {"&File",             NULL,           fileMenu,       0,
NULL},
  {"&Edit",             NULL,           editMenu,       0,
NULL},
  {"&Sex",              NULL,           sexMenu,        0,
NULL},
  {NULL,                NULL,           NULL}
};

int TestGUI(void)
{
  DATAFILE *fnt1;
  int ret;
//  char editText[32] = "SLIM SHADY";
  DIALOG dlg[] =
  {
/*
   // (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key)
(flags)  (d1)  (d2)  (dp)
   { d_clear_proc,      0,    0,    0,    0,    15,   0,    0,    0,
0,    0,    NULL },
   { d_edit_proc,       20,   16,   280,  8,    15,   0,    0,    0,
sizeof(editText)-1, 0, editText },
   { d_list_proc,       192,  64,   106,  106,  15,   0,    0,    0,
0,    0,    GetList },
   { DY_action_proc,    20,   32,   160,  12,   15,   0,    'b',
D_EXIT,  0,    0,    "&Beep", Beep2Me},
   { d_text_proc,       20,   56,   128,  8,    15,   0,    0,    0,
0,    0,    "MIDI Volume"},
   { d_slider_proc,     16,   64,   176,  8,    15,   0,    0,    0,
252,  0,    NULL },
   { d_button_proc,     20,   160,  64,   12,   15,   0,    0,
D_EXIT,  0,    0,    "OK" },
   { d_button_proc,     120,  160,  64,   12,   15,   0,    0,
D_EXIT,  0,    0,    "Cancel" },
   { NULL,              0,    0,    0,    0,    0,    0,    0,    0,
0,    0,    NULL }
*/
   // (dialog proc)     (x)   (y)   (w)   (h)   (fg)  (bg)  (key)
(flags)  (d1)  (d2)  (dp)
   { d_clear_proc,      0,    0,    0,    0,    15,   0,    0,    0,
0,    0,    NULL },
   { DY_action_proc,    20,   56,   160,  12,   15,   0,    'm',
D_EXIT,  0,    0,    "&mouse alternate move", forcemouse},
   { d_button_proc,     20,   160,  64,   12,   15,   0,    0,
D_EXIT,  0,    0,    "Quit" },
   { d_menu_proc,       8,    8,    0,    0,    0,    0,    0,    0,
0,    0,    TestGUI_menu},
   { NULL,              0,    0,    0,    0,    0,    0,    0,    0,
0,    0,    NULL }
  };
//  DIALOG_PLAYER *player;

  if(allegro_init())
    return 254;

  install_keyboard();
  install_timer();
  install_joystick(JOY_TYPE_2PADS);
  puts("The mouse takes a long time to find under DOS");
  install_mouse();
  puts("Loading");
  fnt1 = load_datafile("FNT1.DAT");
  if(!fnt1)
  {
    allegro_exit();
    return 253;
  }
  if(set_gfx_mode(GFX_VGA, 320, 200, 0, 0))
  {
    unload_datafile(fnt1);
    allegro_exit();
    return 252;
  }

  set_palette(desktop_palette);

//  dlg[4].dp2 = fnt1[SMALL_FNT].dat;

  ret = do_dialog(dlg, -1);

  show_mouse(NULL);
  fade_out(2);

  allegro_exit();
  return ret;
}

int main(void)
{
  return TestGUI();
}


-- 
Damian Yerrick  http://yerricde.tripod.com/
View full sig at http://www.rose-hulman.edu/~yerricde/sig.html
Comment on story ideas at http://home1.gte.net/frodo/quickjot.html

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019