Ayant vu la lenteur du jeu de la vie en Basic de Clément.7, j'ai voulu développé le mien, mais en un langage nettement plus rapide : le C.
Seulement, il ne fait pas du tout ce que je voudrais qu'il fasse.
Voilà mon code:
le main.c
- Code: Select all
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <tice.h>
#include <math.h>
#include "keys.h"
#include "gc.h"
#include <lib/ce/graphc.h>
#include <lib/ce/fileioc.h>
#include <lib/ce/keypadc.h>
uint16_t globalColor;
void wait(uint16_t t)
{
for (int i = 0 ; i < t ; i++)
boot_WaitShort();
}
void main(void)
{
int lifetab[100][100];
int x_cur = 320/2-50, y_cur = 240/2-50;
gc_InitGraph();
gc_FillScrn(0x0F);
gc_SetTextColor(255);
gc_SetColorIndex(255);
gc_NoClipRectangle(320/2-50,240/2-50,100,100);
while(!isKeyPressed(KEY_2ND))
{
globalColor = 0;
gc_drawPixel(x_cur,y_cur);
if (isKeyPressed(KEY_ALPHA)) lifetab[x_cur - (320 / 2 - 50)][y_cur - (240 / 2 - 50)] = 1;
if (isKeyPressed(KEY_LEFT) && x_cur > 320 / 2 - 50)
{
if (!lifetab[x_cur - (320 / 2 - 50)][y_cur - (240 / 2 - 50)])
{
globalColor = 255;
gc_drawPixel(x_cur, y_cur);
}
x_cur--;
}
if (isKeyPressed(KEY_RIGHT) && x_cur < 320 / 2 + 50)
{
if (!lifetab[x_cur - (320 / 2 - 50)][y_cur - (240 / 2 - 50)])
{
globalColor = 255;
gc_drawPixel(x_cur, y_cur);
}
x_cur++;
}
if (isKeyPressed(KEY_UP) && y_cur > 240 / 2 - 50)
{
if (!lifetab[x_cur - (320 / 2 - 50)][y_cur - (240 / 2 - 50)])
{
globalColor = 255;
gc_drawPixel(x_cur, y_cur);
}
y_cur--;
}
if (isKeyPressed(KEY_DOWN) && y_cur < 240 / 2 + 50)
{
if (!lifetab[x_cur - (320 / 2 - 50)][y_cur - (240 / 2 - 50)])
{
globalColor = 255;
gc_drawPixel(x_cur, y_cur);
}
y_cur++;
}
wait(5);
}
gc_CloseGraph();
}
le keys.h
- Code: Select all
//Tanks to Adriweb for this code
#ifndef INC_2048C_KEYS_H
#define INC_2048C_KEYS_H
#include <stdint.h>
#define startKeys() do { (*(uint8_t*)0xF50000) = 3; } while(0)
#define stopKeys() do { (*(uint8_t*)0xF50000) = 0; } while(0)
// key format : 2 bytes : keys group last addr byte + read mask
#define KEY_2ND 0x1220
#define KEY_MODE 0x1240
#define KEY_DEL 0x1280
#define KEY_ALPHA 0x1480
#define KEY_CLEAR 0x1C40
#define KEY_DOWN 0x1E01
#define KEY_LEFT 0x1E02
#define KEY_RIGHT 0x1E04
#define KEY_UP 0x1E08
#define KEY_ARROWS 0x1E
// 'key' having to be a uint16_t (use the defines above)
#define isKeyPressed(key) ((bool)((*((uint8_t*)(0xF50000 + (uint8_t)((key) >> 8)))) & ((uint8_t)((key) & 0xFF))))
#define isKeyGroupPressed(group) ((bool)((*((uint8_t*)(0xF50000 + (uint8_t)((group)))))))
#endif //INC_2048C_KEYS_H
et le gc.h
- Code: Select all
#ifndef INC_GC_H
#define INC_GC_H
#include <stdint.h>
#define SCR_WIDTH 320
#define SCR_HEIGHT 240
static const uint16_t* screen_buf = (uint16_t*)0xD40000;
static const uint8_t* screen_buf_8bpp = (uint8_t*)0xD40000;
typedef uint16_t color_t;
#define rgb2color(r, g, b) ((color_t)((((r) << 8) & 0xf800) | (((g) << 3) & 0x07e0) | ((b) >> 3)))
#define gc_drawPixel(x, y) *((uint16_t*)(screen_buf + (x) + (y)*SCR_WIDTH)) = globalColor;
#define gc_setColor(c) globalColor = (c);
#define gc_setColorRGB(r, g, b) globalColor = rgb2color((r), (g), (b));
#define gc_drawString(str, x, y) os_FontDrawText((str), (x), (y))
#define gc_drawStringTranp(str, x, y) os_FontDrawTransText((str), (x), (y))
extern color_t globalColor;
#endif //INC_2048C_GC_H
Je n'ai pas de screen à vous montrer, mais le fichier est en pièce jointe.
Merci de votre aide.
