You are on page 1of 4

/*

* main.c
*
* Created on: 25 nov. 2017
* Author: JESUS
*/
#include <nds.h>
#include <stdio.h>
#include <time.h>

#define TIMER_SPEED (BUS_CLOCK/1024)

// Teselas
#define T_VERDE 0
#define T_ROJO 1
#define T_AMARILLO 2
#define T_BLANCO 3
// Size pantalla
#define SCREEN_NUM_ROWS 24
#define SCREEN_NUM_COLS 32

// Pantallas
#define PANTALLA_SEMAFORO 1

void InicializarPantalla (u16 *mapMemory, int tesela_blanco);


void SeleccionPantalla (int pantalla);

int Juego(int key, u16* mapMemory,


int *coches_row, int *coches_col,
int *peatones_row, int *peatones_col,
uint ticks);

void InicializarPrograma(u16* mapMemory,


int *coches_row, int *coches_col,
int *peatones_row, int *peatones_col);

BG_PALETTE[1]=RGB15(15,4,5);
BG_PALETTE[2]=RGB15(15,18,7);
BG_PALETTE[3]=RGB15(00,00,31);
BG_PALETTE[4]=RGB15(00,00,00);
u8 tesela_verde[64] =
{
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2,
2,2,2,2,2,2,2,2
};

u8 tesela_rojo[64] =
{
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1
};
u8 tesela_amarillo[64] =
{
3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3
};
u8 tesela_blanco[64] =
{
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4
};

VRAM_A_CR = VRAM_ENABLE | VRAM_A_MAIN_BG ;


BGCTRL [0] = BG_32x32 | BG_COLOR_256 | BG_MAP_BASE(0) | BG_TILE_BASE(1);

VRAM_B_CR = VRAM_ENABLE | VRAM_B_LCD;


VRAM_C_CR = VRAM_ENABLE | VRAM_C_LCD;
VRAM_D_CR = VRAM_ENABLE | VRAM_D_LCD;
static u8* tileMemory = (u8*) BG_TILE_RAM(1);
static u16* mapMemory = (u16*) BG_MAP_RAM(0);
dmaCopy(tesela_verde,tileMemory + 0,sizeof(tesela_verde));
dmaCopy(tesela_rojo, tileMemory + 64,sizeof(tesela_rojo));
dmaCopy(tesela_blanco, tileMemory + 64,sizeof(tesela_blanco));
dmaCopy(tesela_amarillo, tileMemory + 64,sizeof(tesela_amarillo));
while(1){
SeleccionPantalla(pantalla);
ticks += timerElapsed(0);
coches_row = 12;
coches_col = 16;
peatones_row= 20;
peatones_col=24
scanKeys();
key = keysDown();
InicializarPrograma(mapMemory,&coches_row, &coches_col,peatones_row,
peatones_col);
pos_memory=(*coches_row)*SCREEN_NUM_COLS+(*coches_col);
mapMemory[pos_memory] = tesela_verde;
pos_memory=(*peatones_row)*SCREEN_NUM_COLS+(*peatones_col);
mapMemory[pos_memory] = tesela_rojo;
if (key & KEY_A && ticks/TIMER_SPEED<100)
{
if(ticks/TIMER_SPEED==30 && ticks/TIMER_SPEED<40){
pos_memory=(*coches_row)*SCREEN_NUM_COLS+(*coches_col);
mapMemory[pos_memory] = tesela_amarillo;
pos_memory=(*peatones_row)*SCREEN_NUM_COLS+(*peatones_col);
mapMemory[pos_memory] = tesela_rojo;
}

else if(ticks/TIMER_SPEED>=40 && ticks/TIMER_SPEED<90){


pos_memory=(*coches_row)*SCREEN_NUM_COLS+(*coches_col);
mapMemory[pos_memory] = tesela_rojo;
pos_memory=(*peatones_row)*SCREEN_NUM_COLS+(*peatones_col);
mapMemory[pos_memory] = tesela_verde;
}
else if(ticks/TIMER_SPEED>=90 && ticks/TIMER_SPEED<100){
if((ticks/TIMER_SPEED)%2==0){
pos_memory=(*peatones_row)*SCREEN_NUM_COLS+(*peatones_col);
mapMemory[pos_memory] = tesela_blanco;
}
else{
pos_memory=(*peatones_row)*SCREEN_NUM_COLS+(*peatones_col);
mapMemory[pos_memory] = tesela_verde;
}

}
else if(ticks/TIMER_SPEED>=100)
pos_memory=(*coches_row)*SCREEN_NUM_COLS+(*coches_col);
mapMemory[pos_memory] = tesela_verde;
pos_memory=(*peatones_row)*SCREEN_NUM_COLS+(*peatones_col);
mapMemory[pos_memory] = tesela_rojo;
}
}
else
{
swiWaitForVBlank();
}
free(coches_row);
free(coches_col);
free(peatones_row);
free(peatones_col);

void InicializarPrograma(u16* mapMemory,


int *coches_row, int *coches_col,
int *peatones_row, int *peatones_col)
{
int pos_memory = (*coches_row)*SCREEN_NUM_COLS+(*coches_col);
mapMemory[pos_memory] = T_VERDE;
int pos_memory1 = (*peatones_row)*SCREEN_NUM_COLS+(*peatones_col);
mapMemory[pos_memory] = T_ROJO;

void InicializarPantalla(u16 *mapMemory, int tesela_blanco)


{
int pos_memory = 0;
int col;
int row;
for(row=0; row<SCREEN_NUM_ROWS; row++)
for(col=0; col<SCREEN_NUM_COLS; col++)
{
mapMemory[pos_memory] = tesela_blanco;
pos_memory ++;
}
}

You might also like