delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/12/16:43:03

Message-Id: <199703122105.VAA01257@post.dialin.co.uk>
From: "Lee Simons" <lee AT dialin DOT co DOT uk>
To: <djgpp AT delorie DOT com>
Subject: allegro problems (gfx + kb)
Date: Wed, 12 Mar 1997 21:26:04 -0000
MIME-Version: 1.0

Hello,

I'm having problems with allegro (because I'm new) and I have a few
questions.  This program compiles with one warning.  The textout function
doesn't print the info I want.  I want it to print the frames integer.  Is
this possible with this function, if so, how? And also, the keyscanning bit
doesn't grab keys all the time.  It sort of skips keys.

Thanks..

Begin lamer code...


---------------------------------------------------

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <math.h>
#include <allegro.h>
#include <dos.h>
#include <time.h>

void draw(void);
void check_kb(void);
void check_limits(void);
void exitl(void);

int frames;
int fps;

clock_t t1, t2, t3;

struct data
{
	int x;
	int y;
}pix;

main()
{
	allegro_init();
	install_keyboard();
	set_gfx_mode(GFX_MODEX, 320, 200, 0, 0);
	clear(screen);

	t1 = clock();

	while(1)
	{
	vsync();
	clear(screen);
	draw();
	frames++;
	check_kb();
	check_limits();
	}

	t2 = clock();

	return 0;
}

void draw()
{
	putpixel(screen, pix.x, pix.y, 1);
	textout(screen, font, frames, SCREEN_W/2, SCREEN_H/2, 1);
}

void check_kb()
{
	int key, i;
	key = readkey();

	if((readkey() >> 8) == KEY_UP && pix.y != 0) 
		{
		for(i = 0; i < 2; i++)    
			pix.y--;
		}
	else if((readkey() >> 8) == KEY_DOWN && pix.y != 200)   
		{
		for(i = 0; i < 2; i++)    
			pix.y++;
		}
	else if((readkey() >> 8) == KEY_LEFT && pix.x != 0)   
		{
		for(i = 0; i < 2; i++)    
			pix.x--;
		}
	else if((readkey() >> 8) == KEY_RIGHT && pix.x != 320)   
		{
		for(i = 0; i < 2; i++)    
			pix.x++;
		}
	else if((readkey() & 0xff) == 3)
		{
		exitl();
		exit(0);
		}
	else if((readkey() >> 8) == KEY_ESC)
		{
		exitl();
		exit(0);
		}
	else
		;
}

void check_limits()
{
	if(pix.x > 319)
		pix.x = 319;
	else if(pix.x < 1)
		pix.x = 1;
	else if(pix.y > 199)
		pix.y = 199;
	else if(pix.y < 1)
		pix.y = 1;
	else
		;
} 

void exitl()
{
	t2 = clock();
	allegro_exit();
	
	t3 = (t2 - t1);

	fps = (t3 / frames);

	printf("\nt1:%d", t1);
	printf("\nt2:%d", t2);
	printf("\nt3:%d", t3);

	printf("\nfps:%d", fps);

	printf("\nframes:%d", frames);
}

---------------------------------------------------

Thanks in advance,

Lee


- Raw text -


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