delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/14/21:50:29

From: visage AT yourmom DOT com (Visage)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Coding problems from an extreme C newbie...
Date: Sun, 15 Nov 1998 02:37:23 GMT
Organization: Your Mom.Com
Lines: 173
Message-ID: <364e3dd2.16051218@news.flash.net>
References: <199811150003 DOT AAA16294 AT remus DOT clara DOT net>
NNTP-Posting-Host: ip128.toledo2.oh.pub-ip.psi.net
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

On Sun, 15 Nov 1998 00:02:30 -0000, "Arthur" <arfa AT clara DOT net> wrote:

>You can't use readkey, but if the keyboard handler's installed, an external
>array is used to keep track of key presses. Try this:
>
>if(key[KEY_UP]) move_up();
>if(key[KEY_DOWN]) move_down();
>..
>and so on.

>> 2. (a general coding question) How can I return back to a specific
>> point in a function? (without using GOTO of course. :))
>
>The only stylistically acceptable way of doing this is within a
>for(...;...;...){} loop, a do{}while(); loop, or a while(){}; loop. Anything
>else is generally put down to bad structure.

>> and 3. (using Allegro) What's the best way to peoperly remove a sprite
>> (not a bitmap) when I'm done with it?  Right now, I just call the
>> original bitmap back from memory before it had any sprites plopped on
>> it, but that's probably not good.
>
>That's a perfectly valid method of doing it. The "dirty rectangles" method
>is sometimes quicker, although it really does depend on what your game does.

Okay, here comes some really, really horrible code from me, so try not
to laugh too much...:)

---BEGIN CODE BELOW---
#include <stdio.h>
#include "allegro.h"

BITMAP *bmenu;
BITMAP *finger;
PALETTE bmenu_palette;

/*
Mental note...
    First four pointer positions are...
    (  7,381) = Attack
    (  7,402) = Magic
    (  7,423) = Skill
    (  7,444) = Item
*/

int draw_battle_menu;

int main()
{
    allegro_init();
    install_keyboard();
    set_gfx_mode(GFX_S3, 640, 480, 0, 0);

    bmenu = load_bitmap("bmenu-e.lbm", bmenu_palette);
    finger = load_bitmap("pointer.lbm", bmenu_palette);

    set_palette(bmenu_palette);
    draw_image(draw_battle_menu);
    draw_sprite(screen, finger, 7, 381);   /* Pointer is at "Attack"
*/
    get_key_attack();

    return 0;
}

int draw_image()    /* Draw the battle menu on the screen */
{
    blit(bmenu, screen, 0, 0, (SCREEN_W-bmenu->w)/2,
        (SCREEN_H-bmenu->h)/2, bmenu->w, bmenu->h);
}

int get_key_attack()    /* While the pointer is at "Attack" */
{
    do
    {
        while (key[KEY_DOWN])
        {
            draw_image(draw_battle_menu);
            draw_sprite(screen, finger, 7, 402); /* Pointer is at
"Magic" */
            get_key_magic();
        } 
        while (key[KEY_UP])
        {
            draw_image(draw_battle_menu);
            draw_sprite(screen, finger, 7, 444); /* Pointer is at
"Item" */
            get_key_item();
        } 
    } while (!key[KEY_ESC]);
    the_end();
}

int get_key_magic()    /* While the pointer is at "Magic" */
{
    do
    {
        while (key[KEY_DOWN])
        {
            draw_image(draw_battle_menu);
            draw_sprite(screen, finger, 7, 423); /* Pointer is at
"Skill" */
            get_key_magic();
        }
        while (key[KEY_UP])
        {
            draw_image(draw_battle_menu);
            draw_sprite(screen, finger, 7, 381); /* Pointer is at
"Attack" */
            get_key_item();
        }
    } while (!key[KEY_ESC]);
    the_end();
}

int get_key_skill()    /* While the pointer is at "Skill" */
{
    do
    {
        while (key[KEY_DOWN])
        {
            draw_image(draw_battle_menu);
            draw_sprite(screen, finger, 7, 444); /* Pointer is at
"Item" */
            get_key_magic();
        }
        while (key[KEY_UP])
        {
            draw_image(draw_battle_menu);
            draw_sprite(screen, finger, 7, 402); /* Pointer is at
"Magic" */
            get_key_item();
        }
    } while (!key[KEY_ESC]);
    the_end();
}

int get_key_item()    /* While the pointer is at "Item" */
{
    do
    {
        while (key[KEY_DOWN])
        {
            draw_image(draw_battle_menu);
            draw_sprite(screen, finger, 7, 381); /* Pointer is at
"Attack" */
            get_key_magic();
        }
        while (key[KEY_UP])
        {
            draw_image(draw_battle_menu);
            draw_sprite(screen, finger, 7, 423); /* Pointer is at
"Skill" */
            get_key_item();
        }
    } while (!key[KEY_ESC]);
    the_end();
}

int the_end()
{
    /* End program */
    fade_out(16);
    destroy_bitmap(finger);
    destroy_bitmap(bmenu);
}
---CODE ENDS HERE---

Okay, now after reading through that junk, tell me what I did wrong.
:)

- Steve

- Raw text -


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