› Foros › Multiplataforma › Desarrollo
JSL escribió:La duda que tengo ahora es si hay un listado con los caracteres especiales que puede mostrar la GB, es decir, a parte de /n y el /t si se pueden usar otros.
DarkRyoga escribió:Yo tengo desde hace tiempo este PDF: http://gbdk.sourceforge.net/doc/gbdk-doc.pdf , que es un buen resumen pero al que le faltan bastantes explicaciones (cosa que según vaya avanzando con las entradas relacionadas con el desarrollo para GameBoy voy a intentar ir corrigiendo). Por otro lado suelo visitar bastante esta web aunque hay que tener en cuenta que tiene bastantes enlaces caidos: http://www.devrs.com/gb/ccode.php
tuviello escribió:
Precisamente esa documentación era la que estuve viendo ayer, todo bien hasta que llegas a la mayoría de secciones y lo único que lees es "blah" xD
/*
Ejemplo de entrada y salida en GameBoy.
*/
#include <gb/gb.h>
#include <string.h>
#include <ctype.h>
#include <gb/drawing.h>
#include <stdio.h>
#include <gb/console.h>
char string[11];
char password[]="PROGRAMMING";
void clscr(){
int x, y;
for(y = 0; y < 20; y++)
for(x = 0; x < 30; x++){
gotoxy(x, y);
setchar(' ');
}
gotoxy(0,0);
}
void main(){
char c='a';
int x=0;
gotoxy(1,1);
puts("\t\t\t\t\t\t\t\tRYOGA\t\t\t\t\t\t\t");
puts("I/O in GB");
gotoxy(1,5);
puts("Login Password :\n");
gets(string);
while(c){
c = string[x];
c = toupper(c);
string[x] = c;
x++;
}
clscr();
x=strcmp(string,password);
if(x==0){
puts("Correct Password !");
puts("This is a simple example to control input and output");
puts("");
}else {
puts("\n\n Incorrect");
}
}
#include <string.h>
#include <ctype.h>
#include <gb/drawing.h>
#include <gb/console.h>
char string[11];
char password[]="PROGRAMMING";
void clscr(){
int x, y;
for(y = 0; y < 20; y++)
for(x = 0; x < 30; x++){
gotoxy(x, y);
setchar(' ');
}
gotoxy(0,0);
}
void main(){
char c='a';
int x=0;
gotoxy(1,1);
puts("\t\t\t\t\t\t\t\tRYOGA\t\t\t\t\t\t\t");
puts("I/O in GB");
gotoxy(1,5);
puts("Login Password :\n");
gets(string);
while(c){
c = string[x];
c = toupper(c);
string[x] = c;
x++;
}
clscr();
x=strcmp(string,password);
if(x==0){
puts("Correct Password !");
puts("This is a simple example to control input and output");
puts("");
}else {
puts("\n\n Incorrect");
}
}
DarkRyoga escribió:Podeis hacer algún que otro ejercicio adicional para controlar el resto de botones de la consola, o que se muestren textos alternativos en función del botón del PAD pulsado y cosas así para ir practicando antes de la siguiente entrada.
JSL escribió:Antes de ponerme con el segundo tutorial:DarkRyoga escribió:Podeis hacer algún que otro ejercicio adicional para controlar el resto de botones de la consola, o que se muestren textos alternativos en función del botón del PAD pulsado y cosas así para ir practicando antes de la siguiente entrada.
¿Podrías poner un ejemplo de como se haría eso?
J_START
J_SELECT
J_B
J_A
J_DOWN
J_UP
J_LEFT
J_RIGHT
include <gb.h>
void main(){
int key;
while(1){
key=joypad();
if(key & J_RIGHT) {
gotoxy(0,0);
puts("Has pulsado DERECHA ! ");
}
if(key & J_LEFT)
{
gotoxy(0,0);
puts("Has pulsado IZQUIERDA ! ");
}
if(key & J_UP)
{
gotoxy(0,0);
puts("Has pulsado ARRIBA ! ");
}
if(key & J_DOWN)
{
gotoxy(0,0);
puts("Has pulsado ABAJO ! ");
}
if(key & J_A)
{
gotoxy(0,0);
puts("Has pulsado A ! ");
}
if(key & J_B)
{
gotoxy(0,0);
puts("Has pulsado B ! ");
}
if(key & J_START)
{
gotoxy(0,0);
puts("Has pulsado Start ! ");
}
if(key & J_SELECT)
{
gotoxy(0,0);
puts("Has pulsado Select ! ");
}
}
}
JSL escribió:Perfecto, muchas gracias, ahora ya sí. El tema es que hasta ahora solo conocía para input el waitpad y me estaba bloqueando. También en las guías de C que he estado viendo usan mucho el scanf, cosa que no se puede usar en GB. Sin embargo, esto que enseñas en el segundo tutorial parece que se puede usar como sustituto del scanf (con alguna limitación quizás). Bueno, con esto ya tengo material para seguir trasteando. También echaré un vistazo a las diferencias entre el printf y el puts aunque creo que ya he visto por donde van los tiros.
Saludos.
//****************************************************
// Magic Screen for GameBoy.
// Programmed by jduranmaster a.k.a. Ryoga
//****************************************************
#include <gb/gb.h>
#include <stdio.h>
#include <ctype.h>
#include <gb/console.h>
#include <gb/drawing.h>
unsigned char x = 10;
unsigned char y = 10;
int drawing_control = 0;
void clscr();
void cursor();
void print_title();
void print_marquee();
void print_solid_marquee();
void print_message_INTRO();
void print_message_usage();
void print_messageAtXY(int x, int y, char *c);
int main(){
print_marquee();
print_title();
print_message_INTRO();
waitpad(J_START);
clscr();
print_solid_marquee();
cursor();
return 0;
}
void cursor(){
gotoxy(10, 10);
while(1){
if(joypad() == J_UP){
y--;
}
if(joypad() == J_DOWN){
y++;
}
if(joypad() == J_LEFT){
x--;
}
if(joypad() == J_RIGHT){
x++;
}
if(joypad() == J_SELECT){
clscr();
print_solid_marquee();
gotoxy(0,0);
}
if(joypad() == J_A){
if(drawing_control == 0){
drawing_control = 1;
color(WHITE, WHITE, SOLID);
}else{
drawing_control = 0;
color(BLACK, WHITE, SOLID);
}
}
if(joypad() == J_B){
if(drawing_control == 1){
drawing_control = 0;
color(BLACK, WHITE, SOLID);
}else{
drawing_control = 1;
color(WHITE, WHITE, SOLID);
}
}
if(joypad() == J_START){
clscr();
print_marquee();
print_title();
print_message_usage();
waitpad(J_START);
clscr();
print_solid_marquee();
cursor();
}
plot_point(x,y);
delay(35);
}
}
void print_marquee(){
gotoxy(0, 0);
color(BLACK, WHITE, SOLID);
box(156,140,2,2,M_NOFILL);
box(154,138,4,4,M_NOFILL);
box(152,136,6,6,M_NOFILL);
}
void print_solid_marquee(){
gotoxy(0, 0);
color(BLACK, WHITE, SOLID);
box(156,140,2,2,M_NOFILL);
box(155,139,3,3,M_NOFILL);
box(154,138,4,4,M_NOFILL);
box(153,137,5,5,M_NOFILL);
box(152,136,6,6,M_NOFILL);
}
void print_messageAtXY(int x, int y, char *c){
gotogxy(x,y);
gprintf(c);
}
void print_title(){
print_messageAtXY(4,1,"Magic Screen");
}
void print_message_usage(){
print_messageAtXY(1,3,"Controls:");
print_messageAtXY(1,4,"");
print_messageAtXY(1,5,"A - EN. cursor");
print_messageAtXY(1,6,"B - DIS. cursor");
print_messageAtXY(1,7,"SELECT - Erase SCR");
print_messageAtXY(1,8,"START - HOW TO...");
print_messageAtXY(4,11,"PRESS START!");
print_messageAtXY(8,14,"2014");
print_messageAtXY(4,15,"Programmed by");
print_messageAtXY(8,16,"Ryoga");
}
void print_message_INTRO(){
print_messageAtXY(1,3,"This is a homebrew");
print_messageAtXY(1,4,"software for the");
print_messageAtXY(1,5,"Game Boy console.");
print_messageAtXY(1,6," ");
print_messageAtXY(1,7,"Controls:");
print_messageAtXY(2,8,"A - EN. cursor");
print_messageAtXY(2,9,"B - DIS. cursor");
print_messageAtXY(4,11,"PRESS START!");
print_messageAtXY(8,14,"2014");
print_messageAtXY(4,15,"Programmed by");
print_messageAtXY(8,16,"Ryoga");
}
void clscr(){
int x, y;
for(y = 0; y < 20; y++){
for(x = 0; x < 30; x++){
gotoxy(x, y);
gprintf(" ");
}
}
gotoxy(0,0);
}
void print_marquee(){
gotoxy(0, 0);
color(BLACK, WHITE, SOLID);
box(156,140,2,2,M_NOFILL);
box(154,138,4,4,M_NOFILL);
box(152,136,6,6,M_NOFILL);
}
void print_solid_marquee(){
gotoxy(0, 0);
color(BLACK, WHITE, SOLID);
box(156,140,2,2,M_NOFILL);
box(155,139,3,3,M_NOFILL);
box(154,138,4,4,M_NOFILL);
box(153,137,5,5,M_NOFILL);
box(152,136,6,6,M_NOFILL);
}
void print_messageAtXY(int x, int y, char *c){
gotogxy(x,y);
gprintf(c);
}
void cursor(){
gotoxy(10, 10);
while(1){
if(joypad() == J_UP){
y--;
}
if(joypad() == J_DOWN){
y++;
}
if(joypad() == J_LEFT){
x--;
}
if(joypad() == J_RIGHT){
x++;
}
if(joypad() == J_SELECT){
clscr();
print_solid_marquee();
gotoxy(0,0);
}
if(joypad() == J_A){
if(drawing_control == 0){
drawing_control = 1;
color(WHITE, WHITE, SOLID);
}else{
drawing_control = 0;
color(BLACK, WHITE, SOLID);
}
}
if(joypad() == J_B){
if(drawing_control == 1){
drawing_control = 0;
color(BLACK, WHITE, SOLID);
}else{
drawing_control = 1;
color(WHITE, WHITE, SOLID);
}
}
if(joypad() == J_START){
clscr();
print_marquee();
print_title();
print_message_usage();
waitpad(J_START);
clscr();
print_solid_marquee();
cursor();
}
plot_point(x,y);
delay(35);
}
}
int main(){
print_marquee();
print_title();
print_message_INTRO();
waitpad(J_START);
clscr();
print_solid_marquee();
cursor();
return 0;
}
AirMaster escribió:Me he quedado flipado viendo este último programa para gameboy. Si lo hubiese tenido que hacer yo desde cero seguro que la hubiese liado. Muy buenas explicaciones tio y gracias por compartir el código para que podamos practicar. Este hilo va mejorando y mira que era difícil.
tuviello escribió:Yo estoy en stand by, voy viendo todo, pero tengo que mejorar mi "C", da un poco de vergüenza ajena xD. Así que ando con tutos y ejercicios de C.
DarkRyoga escribió:Bueno poco a poco. De momento para que os vayais haciendo un poco a la idea tengo pensado escribir bastantes más entradas relacionadas con Game Boy y Game Boy Color de las que tenía pensado hacer en un principio. Entre ellas: manejo de textos con formato en GB, un clón del PONG, un clón del TETRIS, manejo de audio en la gameboy, quizás un clón del típico SNAKE y para terminar como manejar y controlar los sprites de un personaje en la GB/GBC para moverlo en pantalla con colisiones y todo. Y luego por supuesto podeis añadir todo lo que hagais vosotros y querais compartir con los demás.
Saludos.
//*****************************************
// Random Generator for GameBoy.
// Programmed by jduranmaster a.k.a. Ryoga
//*****************************************
#include <gb/gb.h>
#include <stdio.h>
#include <ctype.h>
#include <rand.h>
#include <gb/console.h>
#include <gb/drawing.h>
#include "pc18966_2.h"
unsigned int r,seed,key;
void clscr();
void main_loop();
void print_title();
void print_marquee();
void print_solid_marquee();
void print_message_INTRO();
void print_message_usage();
void print_messageAtXY(int x, int y, char *c);
void plot_intro_image(unsigned char *tile_data, unsigned char *map_data);
void main(){
plot_intro_image(pc18966_2_tile_data, pc18966_2_map_data);
print_marquee();
print_title();
print_message_INTRO();
waitpad(J_START);
clscr();
print_solid_marquee();
main_loop();
}
void main_loop(){
seed=0;
key=0;
r=0;
while(1){
print_messageAtXY(1,2, "Press A Button !");
if(joypad() == J_A){
while(joypad() == J_A){seed++; if(seed>=255)seed=1;}
initrand(seed);
print_messageAtXY(1,4, " ");
gprintf("Seed = %u ",seed);
if(!0){
r=rand();
print_messageAtXY(1,5, " ");
gprintf("Rand = %u ",r);
}
}
if(joypad() == J_B){
// do nothing
}
if(joypad() == J_SELECT){
clscr();
print_solid_marquee();
}
if(joypad() == J_START){
clscr();
print_marquee();
print_title();
print_message_usage();
waitpad(J_START);
clscr();
print_solid_marquee();
}
delay(35);
}
}
void print_marquee(){
gotoxy(0, 0);
color(BLACK, WHITE, SOLID);
box(156,140,2,2,M_NOFILL);
box(154,138,4,4,M_NOFILL);
box(152,136,6,6,M_NOFILL);
}
void print_solid_marquee(){
gotoxy(0, 0);
color(BLACK, WHITE, SOLID);
box(156,140,2,2,M_NOFILL);
box(155,139,3,3,M_NOFILL);
box(154,138,4,4,M_NOFILL);
box(153,137,5,5,M_NOFILL);
box(152,136,6,6,M_NOFILL);
}
void plot_intro_image(unsigned char *tile_data, unsigned char *map_data){
set_bkg_data(0, 0, tile_data);
set_bkg_tiles(0, 0, 20, 18, map_data);
SHOW_BKG;
DISPLAY_ON;
delay(5000);
clscr();
}
void print_messageAtXY(int x, int y, char *c){
gotogxy(x,y);
gprintf(c);
}
void print_title(){
print_messageAtXY(3,1,"Rand Generator");
}
void print_message_usage(){
print_messageAtXY(1,3,"Controls:");
print_messageAtXY(1,4,"");
print_messageAtXY(1,5,"A - Gen. Number");
print_messageAtXY(1,7,"SELECT - Erase SCR");
print_messageAtXY(1,8,"START - HOW TO...");
print_messageAtXY(4,11,"PRESS START!");
print_messageAtXY(8,14,"2014");
print_messageAtXY(4,15,"Programmed by");
print_messageAtXY(8,16,"Ryoga");
}
void print_message_INTRO(){
print_messageAtXY(1,3,"This is a homebrew");
print_messageAtXY(1,4,"software for the");
print_messageAtXY(1,5,"Game Boy console.");
print_messageAtXY(1,6," ");
print_messageAtXY(1,7,"Controls:");
print_messageAtXY(2,8,"A - Gen. Number");
print_messageAtXY(4,11,"PRESS START!");
print_messageAtXY(8,14,"2014");
print_messageAtXY(4,15,"Programmed by");
print_messageAtXY(8,16,"Ryoga");
}
void clscr(){
int x, y;
for(y = 0; y < 20; y++){
for(x = 0; x < 30; x++){
gotoxy(x, y);
gprintf(" ");
}
}
gotoxy(0,0);
}
void plot_intro_image(unsigned char *tile_data, unsigned char *map_data);
// ///////////////////////
// // //
// // File Attributes //
// // //
// ///////////////////////
// Filename: pc18966_2.jpg
// Pixel Width: 160px
// Pixel Height: 144px
// /////////////////
// // //
// // Constants //
// // //
// /////////////////
const int pc18966_2_tile_map_size = 0x0168;
const int pc18966_2_tile_map_width = 0x14;
const int pc18966_2_tile_map_height = 0x12;
const int pc18966_2_tile_data_size = 0x0D80;
const int pc18966_2_tile_count = 0x0168;
// ////////////////
// // //
// // Map Data //
// // //
// ////////////////
const unsigned char pc18966_2_map_data[] ={
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0E,
0x0E,0x0E,0x0E,0x0F,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,
0x1B,0x1C,0x0E,0x0E,0x0E,0x1D,0x1E,0x1F,0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,
0x28,0x29,0x1B,0x1B,0x1B,0x1B,0x2A,0x0E,0x2B,0x2C,0x2D,0x2E,0x2F,0x30,0x31,0x32,
0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x1B,0x1B,0x1B,0x3A,0x1D,0x3B,0x3C,0x3D,0x3E,
0x3F,0x40,0x41,0x42,0x41,0x1B,0x43,0x44,0x45,0x46,0x47,0x1B,0x1B,0x1B,0x48,0x49,
0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x4F,0x53,0x54,0x55,0x56,0x57,0x58,
.....
"CONTINUA"
};
// /////////////////
// // //
// // Tile Data //
// // //
// /////////////////
const unsigned char pc18966_2_tile_data[] ={
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x7F,0xFF,0x7F,0xFF,
0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x00,0xFF,0x21,0xFF,0xF1,0xFF,0xF3,0xFF,
0x00,0xFF,0x00,0xFF,0x01,0xFF,0x00,0xFF,0x00,0xFF,0x02,0xFF,0xFF,0xFF,0xF7,0xFF,
"CONTINUA"
};
void plot_intro_image(unsigned char *tile_data, unsigned char *map_data);
void plot_intro_image(unsigned char *tile_data, unsigned char *map_data){
set_bkg_data(0, 0, tile_data);
set_bkg_tiles(0, 0, 20, 18, map_data);
SHOW_BKG;
DISPLAY_ON;
delay(5000);
clscr();
}
set_bkg_data(0, 0, tile_data);
set_bkg_tiles(0, 0, 20, 18, map_data);
SHOW_BKG;
DISPLAY_ON;
delay(5000);
clscr();
#include "pc18966_2.h"
void PLOT_BACKGROUND_IMAGE(int coord_X, int coord_Y, int tam_tile_X,int tam_tile_Y,unsigned char *tile_data, unsigned char *map_data)
SefirotDios2 escribió:Mil gracias por tu dedicación e estos tutoriales! Estoy aprendiendo mucho gracias a ti!
Un Saludo!
Bossma escribió:Muchísimas gracias por los tutoriales, están de lujo. Si me lo permites, dejo un enlace del taller que dio Pocket_Lucho en la Universidad de Alicante sobre programación en Game Boy, para complementar tus tutoriales.
//*****************************************
// SoundEffects for GameBoy.
// Programmed by jduranmaster a.k.a. Ryoga
//*****************************************
#include <gb/gb.h>
#include <gb/drawing.h>
#include "_SFX.h"
UBYTE tile_offset = 1;
UBYTE tile_height = 18;
static const unsigned char TEXT_cEMPTY[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void PRINT_MAIN_SFX_MENU(void);
void PLAY_A_SOUND_EFFECT(void);
void PLAY_B_SOUND_EFFECT(void);
void CLEAR_SCREEN_LINE (UBYTE y);
void CLEAR_SCREEN_BACKGROUND (void);
void PLAY_CURSOR_SOUND_EFFECT(void);
void PLAY_SELECT_SOUND_EFFECT(void);
void INIT_REGISTERS_SOUND_EFECTS(void);
void PRINT_MESSAGE(int x, int y, char *c);
UBYTE PLAY_START_SOUND_EFFECT(UBYTE sfx_two_notes_on);
void PLOT_BACKGROUND_IMAGE(int coord_X, int coord_Y, int tam_tile_X, int tam_tile_Y, unsigned char *tile_data, unsigned char *map_data);
void main(){
UBYTE key_pressed = 0;
UBYTE sfx_on = 0;
UBYTE sfx_two_notes_on = 0;
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, _SFX_tile_data, _SFX_map_data);
PRINT_MAIN_SFX_MENU();
INIT_REGISTERS_SOUND_EFECTS();
while(1){
key_pressed = joypad();
if( key_pressed & (J_START) && sfx_on == 0){
PRINT_MESSAGE(9,9,"P ");
delay(200);
sfx_on = 1;
sfx_two_notes_on = PLAY_START_SOUND_EFFECT(sfx_two_notes_on);
}else{
PRINT_MESSAGE(9,9,"NP");
}
if(sfx_two_notes_on){
sfx_two_notes_on = PLAY_START_SOUND_EFFECT(sfx_two_notes_on);
}
if( key_pressed & (J_SELECT) && sfx_on == 0){
PRINT_MESSAGE(9,10,"P ");
delay(200);
PLAY_SELECT_SOUND_EFFECT();
sfx_on = 1;
}else{
PRINT_MESSAGE(9,10,"NP");
}
if( key_pressed & (J_UP) && sfx_on == 0){
PRINT_MESSAGE(9,5,"P ");
delay(200);
PLAY_CURSOR_SOUND_EFFECT();
sfx_on = 1;
}else{
PRINT_MESSAGE(9,5,"NP");
}
if( key_pressed & (J_DOWN) && sfx_on == 0){
PRINT_MESSAGE(9,6,"P ");
delay(200);
PLAY_CURSOR_SOUND_EFFECT();
sfx_on = 1;
}else{
PRINT_MESSAGE(9,6,"NP");
}
if( key_pressed & (J_LEFT) && sfx_on == 0){
PRINT_MESSAGE(9,7,"P ");
delay(200);
PLAY_CURSOR_SOUND_EFFECT();
sfx_on = 1;
}else{
PRINT_MESSAGE(9,7,"NP");
}
if( key_pressed & (J_RIGHT) && sfx_on == 0){
PRINT_MESSAGE(9,8,"P ");
delay(200);
PLAY_CURSOR_SOUND_EFFECT();
sfx_on = 1;
}else{
PRINT_MESSAGE(9,8,"NP");
}
if( key_pressed & (J_A) && sfx_on == 0){
PRINT_MESSAGE(9,11,"P ");
delay(200);
PLAY_A_SOUND_EFFECT();
sfx_on = 1;
}else{
PRINT_MESSAGE(9,11,"NP");
}
if( key_pressed & (J_B) && sfx_on == 0){
PRINT_MESSAGE(9,12,"P ");
delay(200);
PLAY_B_SOUND_EFFECT();
sfx_on = 1;
}else{
PRINT_MESSAGE(9,12,"NP");
}
if( !( key_pressed & J_SELECT ) && !( key_pressed & J_A ) && !( key_pressed & J_START ) && !( key_pressed & J_B )
&& !( key_pressed & J_UP ) && !( key_pressed & J_DOWN ) && !( key_pressed & J_RIGHT ) && !( key_pressed & J_LEFT ) && sfx_on == 1 ){
sfx_on = 0;
}
}
}
void PRINT_MAIN_SFX_MENU(void){
PRINT_MESSAGE(1, 1, "----------------");
PRINT_MESSAGE(1, 2, "SFX FOR GAMEBOY");
PRINT_MESSAGE(1, 3, "----------------");
PRINT_MESSAGE(1, 5,"Up : NP");
PRINT_MESSAGE(1, 6,"Down : NP");
PRINT_MESSAGE(1, 7,"Left : NP");
PRINT_MESSAGE(1, 8,"Right : NP");
PRINT_MESSAGE(1, 9,"Start : NP");
PRINT_MESSAGE(1, 10,"Select: NP");
PRINT_MESSAGE(1, 11,"A : NP");
PRINT_MESSAGE(1, 12,"B : NP");
PRINT_MESSAGE(1, 14, "----------------");
PRINT_MESSAGE(4, 15, "RYOGA 2014");
PRINT_MESSAGE(1, 16, "----------------");
}
void INIT_REGISTERS_SOUND_EFECTS(void){
NR52_REG = 0xF8U;
NR51_REG = 0x00U;
NR50_REG = 0x77U;
}
void PLAY_A_SOUND_EFFECT(void){
NR10_REG = 0x34U;
NR11_REG = 0x70U;
NR12_REG = 0xF0U;
NR13_REG = 0x0AU;
NR14_REG = 0xC6U;
NR51_REG |= 0x11;
}
void PLAY_B_SOUND_EFFECT(void){
NR10_REG = 0x34U;
NR11_REG = 0x80U;
NR12_REG = 0xF0U;
NR13_REG = 0x0AU;
NR14_REG = 0xC6U;
NR51_REG |= 0x11;
}
void PLAY_SELECT_SOUND_EFFECT(void){
NR10_REG = 0x04U;
NR11_REG = 0xFEU;
NR12_REG = 0xA1U;
NR13_REG = 0x8FU;
NR14_REG = 0x86U;
NR51_REG = 0xF7;
}
UBYTE PLAY_START_SOUND_EFFECT(UBYTE sfx_two_notes_on){
if( NR52_REG & 0x02 ){
return 0x01;
}else if( sfx_two_notes_on ){
//segunda nota
NR21_REG = 0x80U;
NR22_REG = 0x73U;
NR23_REG = 0x9FU;
NR24_REG = 0xC7U;
NR51_REG |= 0x22;
return 0x00;
}else{
// primera nota.
NR21_REG = 0xAEU;
NR22_REG = 0x68U;
NR23_REG = 0xDBU;
NR24_REG = 0xC7U;
NR51_REG |= 0x22;
return 0x01;
}
}
void PLAY_CURSOR_SOUND_EFFECT(void){
NR10_REG = 0x38U;
NR11_REG = 0x70U;
NR12_REG = 0xE0U;
NR13_REG = 0x0AU;
NR14_REG = 0xC6U;
NR51_REG |= 0x11;
}
void PRINT_MESSAGE(int x, int y, char *c){
gotogxy(x,y);
gprintf(c);
}
void CLEAR_SCREEN_LINE ( UBYTE y ){
UBYTE x;
for (x = y*20 ; x < (y+1)*20 ; x++ ){
set_bkg_data (x+tile_offset,1,(unsigned char *)TEXT_cEMPTY);
}
}
void CLEAR_SCREEN_BACKGROUND(void){
UBYTE x;
for ( x = 0 ; x < tile_height ; x++ ){
CLEAR_SCREEN_LINE ( x );
}
}
void PLOT_BACKGROUND_IMAGE(int coord_X, int coord_Y, int tam_tile_X, int tam_tile_Y, unsigned char *tile_data, unsigned char *map_data){
set_bkg_data(coord_X, coord_Y, tile_data);
set_bkg_tiles(coord_X, coord_Y, tam_tile_X, tam_tile_Y, map_data);
SHOW_BKG;
DISPLAY_ON;
delay(2000);
}
void INIT_REGISTERS_SOUND_EFECTS(void){
NR52_REG = 0xF8U;
NR51_REG = 0x00U;
NR50_REG = 0x77U;
}
void PLAY_A_SOUND_EFFECT(void){
NR10_REG = 0x34U;
NR11_REG = 0x70U;
NR12_REG = 0xF0U;
NR13_REG = 0x0AU;
NR14_REG = 0xC6U;
NR51_REG |= 0x11;
}
void PLAY_B_SOUND_EFFECT(void){
NR10_REG = 0x34U;
NR11_REG = 0x80U;
NR12_REG = 0xF0U;
NR13_REG = 0x0AU;
NR14_REG = 0xC6U;
NR51_REG |= 0x11;
}
void PLAY_SELECT_SOUND_EFFECT(void){
NR10_REG = 0x04U;
NR11_REG = 0xFEU;
NR12_REG = 0xA1U;
NR13_REG = 0x8FU;
NR14_REG = 0x86U;
NR51_REG = 0xF7;
}
void PLAY_CURSOR_SOUND_EFFECT(void){
NR10_REG = 0x38U;
NR11_REG = 0x70U;
NR12_REG = 0xE0U;
NR13_REG = 0x0AU;
NR14_REG = 0xC6U;
NR51_REG |= 0x11;
}
UBYTE PLAY_START_SOUND_EFFECT(UBYTE sfx_two_notes_on){
if(NR52_REG & 0x02){
return 0x01;
}else if(sfx_two_notes_on){
//segunda nota
NR21_REG = 0x80U;
NR22_REG = 0x73U;
NR23_REG = 0x9FU;
NR24_REG = 0xC7U;
NR51_REG |= 0x22;
return 0x00;
}else{
// primera nota.
NR21_REG = 0xAEU;
NR22_REG = 0x68U;
NR23_REG = 0xDBU;
NR24_REG = 0xC7U;
NR51_REG |= 0x22;
return 0x01;
}
}
if( !( key_pressed & J_SELECT ) && !( key_pressed & J_A ) && !( key_pressed & J_START ) && !( key_pressed & J_B )
&& !( key_pressed & J_UP ) && !( key_pressed & J_DOWN ) && !( key_pressed & J_RIGHT ) && !( key_pressed & J_LEFT ) && sfx_on == 1 ){
sfx_on = 0;
}
//*****************************************
// testSoundMusic for GameBoy.
// Programmed by jduranmaster a.k.a. Ryoga
//*****************************************
#include <gb/gb.h>
#include <gb/drawing.h>
#include "gbt_player.h"
#include "_SMUSIC.h"
UBYTE tile_offset = 1;
UBYTE tile_height = 18;
static const unsigned char TEXT_cEMPTY[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
extern const unsigned char * song_Data[];
extern const unsigned char * Song_Data[];
void PRINT_MAIN_SFX_MENU(void);
void CLEAR_SCREEN_LINE (UBYTE y);
void PLAY_SONG_FROM_MBC1_BANK_1();
void PLAY_SONG_FROM_MBC1_BANK_2();
void STOP_SONG_FROM_MBC1_BANK_X();
void CLEAR_SCREEN_BACKGROUND (void);
void PRINT_MESSAGE(int x, int y, char *c);
void PLOT_BACKGROUND_IMAGE(int coord_X, int coord_Y, int tam_tile_X, int tam_tile_Y, unsigned char *tile_data, unsigned char *map_data);
void main(){
UBYTE key_pressed = 0;
UBYTE gbt_update_released = 0;
UBYTE MBC_BANK_ID = 0;
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, _SMUSIC_tile_data, _SMUSIC_map_data);
PRINT_MAIN_SFX_MENU();
while(1){
key_pressed = joypad();
if(key_pressed & (J_A)){
MBC_BANK_ID = 0;
STOP_SONG_FROM_MBC1_BANK_X();
PLAY_SONG_FROM_MBC1_BANK_2();
PRINT_MESSAGE(1, 6,"MBC1-Bank1 B : NP");
PRINT_MESSAGE(1, 10,"Playing MBC1-BANK 2");
PRINT_MESSAGE(1, 7,"MBC1-Bank2 A : P ");
if(gbt_update_released == 0){
gbt_update_released = 1;
add_VBL(gbt_update);
}
}
if(key_pressed & (J_B)){
MBC_BANK_ID = 1;
STOP_SONG_FROM_MBC1_BANK_X();
PLAY_SONG_FROM_MBC1_BANK_1();
PRINT_MESSAGE(1, 6,"MBC1-Bank1 B : P ");
PRINT_MESSAGE(1, 10,"Playing MBC1-BANK 1");
PRINT_MESSAGE(1, 7,"MBC1-Bank2 A : NP");
if(gbt_update_released == 0){
gbt_update_released = 1;
add_VBL(gbt_update);
}
}
if(key_pressed & (J_START)){
STOP_SONG_FROM_MBC1_BANK_X();
PRINT_MESSAGE(1, 6,"MBC1-Bank1 B : NP");
PRINT_MESSAGE(1, 7,"MBC1-Bank2 A : NP");
PRINT_MESSAGE(1, 10," ");
if(MBC_BANK_ID){
PRINT_MESSAGE(1, 10,"Stopping MBC1-Bank1");
}else{
PRINT_MESSAGE(1, 10,"Stopping MBC1-Bank2");
}
delay(1000);
PRINT_MESSAGE(1, 10," ");
}
wait_vbl_done();
}
}
void PLAY_SONG_FROM_MBC1_BANK_1(){
SWITCH_ROM_MBC1(1);
gbt_play(song_Data, 1, 7);
gbt_loop(0);
}
void PLAY_SONG_FROM_MBC1_BANK_2(){
SWITCH_ROM_MBC1(2);
gbt_play(song_Data, 2, 7);
gbt_loop(0);
}
void STOP_SONG_FROM_MBC1_BANK_X(){
gbt_stop();
}
void PRINT_MAIN_SFX_MENU(void){
PRINT_MESSAGE(0, 1, "-------------------");
PRINT_MESSAGE(0, 2, " MUSIC FOR GAMEBOY");
PRINT_MESSAGE(0, 3, "-------------------");
PRINT_MESSAGE(1, 6,"MBC1-Bank1 B : NP");
PRINT_MESSAGE(1, 7,"MBC1-Bank2 A : NP");
PRINT_MESSAGE(2, 14, "----------------");
PRINT_MESSAGE(5, 15, "RYOGA 2014");
PRINT_MESSAGE(2, 16, "----------------");
}
void PRINT_MESSAGE(int x, int y, char *c){
gotogxy(x,y);
gprintf(c);
}
void CLEAR_SCREEN_LINE ( UBYTE y ){
UBYTE x;
for (x = y*20 ; x < (y+1)*20 ; x++ ){
set_bkg_data (x+tile_offset,1,(unsigned char *)TEXT_cEMPTY);
}
}
void CLEAR_SCREEN_BACKGROUND(void){
UBYTE x;
for ( x = 0 ; x < tile_height ; x++ ){
CLEAR_SCREEN_LINE ( x );
}
}
void PLOT_BACKGROUND_IMAGE(int coord_X, int coord_Y, int tam_tile_X, int tam_tile_Y, unsigned char *tile_data, unsigned char *map_data){
set_bkg_data(coord_X, coord_Y, tile_data);
set_bkg_tiles(coord_X, coord_Y, tam_tile_X, tam_tile_Y, map_data);
SHOW_BKG;
DISPLAY_ON;
delay(2000);
}
#define SWITCH_ROM_MBC1(b) \
*(unsigned char *)0x2000 = (b)
lcc -Wf-bo2 -c -o music.o music.c
0. ROM ONLY
1. ROM+MBC1
2. ROM+MBC1+RAM
3. ROM+MBC1+RAM+BATTERY
5. ROM+MBC2
6. ROM+MBC2+BATTERY
while(1){
key_pressed = joypad();
if(key_pressed & (J_A)){
MBC_BANK_ID = 0;
STOP_SONG_FROM_MBC1_BANK_X();
PLAY_SONG_FROM_MBC1_BANK_2();
PRINT_MESSAGE(1, 6,"MBC1-Bank1 B : NP");
PRINT_MESSAGE(1, 10,"Playing MBC1-BANK 2");
PRINT_MESSAGE(1, 7,"MBC1-Bank2 A : P ");
if(gbt_update_released == 0){
gbt_update_released = 1;
add_VBL(gbt_update);
}
}
if(key_pressed & (J_B)){
MBC_BANK_ID = 1;
STOP_SONG_FROM_MBC1_BANK_X();
PLAY_SONG_FROM_MBC1_BANK_1();
PRINT_MESSAGE(1, 6,"MBC1-Bank1 B : P ");
PRINT_MESSAGE(1, 10,"Playing MBC1-BANK 1");
PRINT_MESSAGE(1, 7,"MBC1-Bank2 A : NP");
if(gbt_update_released == 0){
gbt_update_released = 1;
add_VBL(gbt_update);
}
}
if(key_pressed & (J_START)){
STOP_SONG_FROM_MBC1_BANK_X();
PRINT_MESSAGE(1, 6,"MBC1-Bank1 B : NP");
PRINT_MESSAGE(1, 7,"MBC1-Bank2 A : NP");
PRINT_MESSAGE(1, 10," ");
if(MBC_BANK_ID){
PRINT_MESSAGE(1, 10,"Stopping MBC1-Bank1");
}else{
PRINT_MESSAGE(1, 10,"Stopping MBC1-Bank2");
}
delay(1000);
PRINT_MESSAGE(1, 10," ");
}
wait_vbl_done();
}
if(key_pressed & (J_A)){
MBC_BANK_ID = 0;
STOP_SONG_FROM_MBC1_BANK_X();
PLAY_SONG_FROM_MBC1_BANK_2();
PRINT_MESSAGE(1, 6,"MBC1-Bank1 B : NP");
PRINT_MESSAGE(1, 10,"Playing MBC1-BANK 2");
PRINT_MESSAGE(1, 7,"MBC1-Bank2 A : P ");
if(gbt_update_released == 0){
gbt_update_released = 1;
add_VBL(gbt_update);
}
}
void STOP_SONG_FROM_MBC1_BANK_X(){
gbt_stop();
}
void PLAY_SONG_FROM_MBC1_BANK_2(){
SWITCH_ROM_MBC1(2);
gbt_play(song_Data, 2, 7);
gbt_loop(0);
}
if(gbt_update_released == 0){
gbt_update_released = 1;
add_VBL(gbt_update);
}
mod2gbt .\mods\cave_story.mod song -c 2
ren output.c output_bank2.c
mod2gbt .\mods\template.mod songb -c 1
ren output.c output_bank1.c
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -c -o testSoundMusic.o testSoundMusic.c
lcc -Wf-bo2 -c -o output_bank2.o output_bank2.c
lcc -Wf-bo1 -c -o output_bank1.o output_bank1.c
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -c -o gbt_player.o gbt_player.s
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -c -o gbt_player_bank1.o gbt_player_bank1.s
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wl-yt1 -Wl-yo4 -Wl-ya0 -o SoundMusic-simpleBankingMBC1-20141109.gb testSoundMusic.o output_bank2.o output_bank1.o gbt_player.o gbt_player_bank1.o
del *.o *.lst *.map *.sym
pause
#include <gb/gb.h>
#include <gb/drawing.h>
#include gbt_player.h"
extern const unsigned char * song_Data[];
void main(){
gbt_play(song_Data, 2, 7);
gbt_loop(0);
add_VBL(gbt_update);
PRINT_MESSAGE(1, 1,"GAMEBOY MUSIC TEST");
PRINT_MESSAGE(1, 2,"------------------");
while(1){
wait_vbl_done();
}
}
void PRINT_MESSAGE(int x, int y, char *c){
gotogxy(x,y);
gprintf(c);
}
Spartark escribió:Menuda pasada. En principio me parece que hay que coger algo de nivel para ir haciéndolo todo correctamente pero creo que es viable usar este procedimiento para hacer música para la gameboy. ¿La otra alternativa sería usar algún tracker tipo nanoloop o bien usar la otra técnica que explicabas en la entrada anterior para los efectos FX? Es decir, ¿de otra forma habría que ir registro a registro metiendo las notas que nos interesen?
Sigue así tio.
AirMaster escribió:Impresionante. Y si, yo creo que la música que suena cuando cambias al banco de memoria 2 es la del Cave Story en una versión de 4 canales. Una vez más gracias por los tutoriales tio. Están cojonudos.
AirMaster escribió:Genial. Ya hay ganas de que llegue la nueva entrada.
//*****************************************
// Ping Pong Diplomacy for GameBoy.
// Programmed by jduranmaster a.k.a. Ryoga
//*****************************************
#include <gb/gb.h>
#include <stdio.h>
#include <ctype.h>
#include <gb/console.h>
#include <gb/drawing.h>
#include "images/_blank_text.h"
#include "images/x_congrats_win.h"
#include "images/hammer_keyboard_.h"
#include "images/x_production_first.h"
#include "images/x_production_second.h"
#include "images/x_pongdiplomacy_logo.h"
static const unsigned char TEXT_cEMPTY[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
unsigned char backgroundcharacters[] = {
//esquina superior izquierda
0xFF,0xFF,0xFF,0xFF,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
//esquina superior derecha
0xFF,0xFF,0xFF,0xFF,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
//esquina inferior izquierda
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xC0,0xFF,0xFF,0xFF,0xFF,
//esquina inferior derecha
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0xFF,0xFF,0xFF,0xFF,
//pared de arriba
0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
//pared derecha
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
//pared de abajo
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,
//pared izquierda
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0,
//relleno
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
signed char spritetiles[] = {
//paddle
255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,
//bola
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
//null
0x00,0x00,0x18,0x18,0x24,0x24,0x24,0x24,
0x24,0x24,0x24,0x24,0x18,0x18,0x00,0x00,
//1
0x00,0x00,0x08,0x08,0x18,0x18,0x28,0x28,
0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
//2
0x00,0x00,0x18,0x18,0x24,0x24,0x08,0x08,
0x10,0x10,0x20,0x20,0x3C,0x3C,0x00,0x00,
//3
0x38,0x38,0x04,0x04,0x04,0x04,0x38,0x38,
0x04,0x04,0x04,0x04,0x38,0x38,0x00,0x00,
//4
0x08,0x08,0x10,0x10,0x20,0x20,0x48,0x48,
0x7C,0x7C,0x08,0x08,0x08,0x08,0x00,0x00,
//5
0x00,0x00,0x3C,0x3C,0x20,0x20,0x38,0x38,
0x04,0x04,0x04,0x04,0x38,0x38,0x00,0x00,
//6
0x00,0x00,0x1C,0x1C,0x20,0x20,0x20,0x20,
0x3C,0x3C,0x24,0x24,0x3C,0x3C,0x00,0x00,
//7
0x00,0x00,0x3C,0x3C,0x04,0x04,0x08,0x08,
0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
//8
0x18,0x18,0x24,0x24,0x24,0x24,0x18,0x18,
0x24,0x24,0x24,0x24,0x18,0x18,0x00,0x00,
//9
0x18,0x18,0x24,0x24,0x24,0x24,0x1C,0x1C,
0x04,0x04,0x04,0x04,0x18,0x18,0x00,0x00,
//10
0x26,0x26,0x69,0x69,0xA9,0xA9,0x29,0x29,
0x29,0x29,0x29,0x29,0x26,0x26,0x00,0x00
};
signed char collision_left_up[] = {
3,-1,1,0,
3,-1,1,0,
3,-1,1,0,
3,-1,1,0,
//--
3,-1,2,-1,
3,-1,2,-1,
3,-1,2,-1,
3,-1,2,-1,
//--
3,-2,2,-1,
3,-2,2,-1,
3,-2,2,-1,
3,-2,2,-1,
//--
3,-2,2,-1,
3,-2,2,-1,
3,-2,2,-1,
3,-2,2,-1
};
signed char collision_left_down[] = {
3,1,1,0,
3,1,1,0,
3,1,1,0,
3,1,1,0,
//--
3,1,2,1,
3,1,2,1,
3,1,2,1,
3,1,2,1,
//--
3,2,2,1,
3,2,2,1,
3,2,2,1,
3,2,2,1,
//--
3,2,3,1,
3,2,3,1,
3,2,3,1,
3,2,3,1
};
signed char collision_right_up[] = {
-3,-1,-1,0,
-3,-1,-1,0,
-3,-1,-1,0,
-3,-1,-1,0,
//--
-3,-1,-2,-1,
-3,-1,-2,-1,
-3,-1,-2,-1,
-3,-1,-2,-1,
//--
-3,-2,-2,-1,
-3,-2,-2,-1,
-3,-2,-2,-1,
-3,-2,-2,-1,
//--
-3,-2,-3,-1,
-3,-2,-3,-1,
-3,-2,-3,-1,
-3,-2,-3,-1
};
signed char collision_right_down[] = {
-3,1,-1,0,
-3,1,-1,0,
-3,1,-1,0,
-3,1,-1,0,
//--
-3,1,-2,1,
-3,1,-2,1,
-3,1,-2,1,
-3,1,-2,1,
//--
-3,2,-2,1,
-3,2,-2,1,
-3,2,-2,1,
-3,2,-2,1,
//--
-3,2,-3,1,
-3,2,-3,1,
-3,2,-3,1,
-3,2,-3,1
};
signed char bgmap[] = {
//bgmap
0,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,1,
7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,5,
2,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,3,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
};
//variables globales del programa.
UBYTE counter,y1,y2,y3,y4,y5,y6;
UBYTE ball_pos_x;
UBYTE ball_pos_y;
BYTE ball_vector_x1;
BYTE ball_vector_x2;
BYTE ball_vector_y1;
BYTE ball_vector_y2;
UBYTE vector_pointer;
UBYTE game_status;
UBYTE colx;
UBYTE coly;
BYTE temp1;
BYTE temp2;
UBYTE col0;
UBYTE col1;
BYTE* col_table;
BYTE score_p1;
BYTE score_p2;
BYTE score_counter_p1;
BYTE score_counter_p2;
int controller = 0;
// variables de control del texto.
UBYTE tile_offset = 1;
UBYTE tile_height = 18;
// funciones del programa.
void RESET_TENNIS_COURT_BACKGROUND(void);
void RESET_COORDS();
void CLEAR_SCREEN_TEXT();
void PRINT_SOLID_MARQUEE();
void PLOT_SET_BACKGROUND_LOGO();
void CLEAR_SCREEN_LINE (UBYTE y);
void CLEAR_SCREEN_BACKGROUND(void);
void PLAY_PADDLE_SOUND_EFFECT(void);
void PLAY_UL_WALL_SOUND_EFFECT(void);
void PLAY_LR_WALL_SOUND_EFFECT(void);
void INIT_REGISTERS_SOUND_EFECTS(void);
void PRINT_MESSAGE(int x, int y, char *c);
UBYTE CHECK_COLLISION_BALL_PADDLE(UBYTE paddleNr);
void PLOT_BACKGROUND_IMAGE(int coord_X, int coord_Y, int tam_tile_X, int tam_tile_Y, unsigned char *tile_data, unsigned char *map_data, int millis);
void main(){
PLOT_SET_BACKGROUND_LOGO();
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, x_pongdiplomacy_logo_tile_data, x_pongdiplomacy_logo_map_data, 2000);
waitpad(J_START);
///// COMIENZA EL BLOQUE BITMAP DONDE SE MUESTRA EL TEXTO DEL JUEGO.
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, _blank_text_tile_data, _blank_text_map_data, 2000);
waitpad(J_START);
///// TERMINA EL BLOQUE BITMAP DONDE SE MUESTRA EL TEXTO DEL JUEGO.
disable_interrupts();
DISPLAY_OFF;
RESET_COORDS();
//fijar las puntuaciones a cero.
score_p1 = 0;
score_p2 = 0;
score_counter_p1 = 0;
score_counter_p2 = 0;
//background
set_bkg_data(0,10,backgroundcharacters);
//background
set_bkg_tiles(0, 0, 20, 1, bgmap);
//background
for(counter=1;counter<=13;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
set_bkg_tiles(0,14,20,1,bgmap+40);
for(counter=15;counter<=17;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
set_bkg_tiles(0,14,20,1,bgmap+40);
//cargar los sprites.
SPRITES_8x8;
//cargar los tiles del paddle.
set_sprite_data(0, 1, spritetiles);
//cargar los tiles de la bola.
set_sprite_data(1, 1, spritetiles+16);
//cargar los tiles de las puntuaciones.
set_sprite_data(2, 1, spritetiles+32);
set_sprite_data(3, 1, spritetiles+48);
set_sprite_data(4, 1, spritetiles+64);
set_sprite_data(5, 1, spritetiles+80);
set_sprite_data(6, 1, spritetiles+96);
set_sprite_data(7, 1, spritetiles+112);
set_sprite_data(8, 1, spritetiles+128);
set_sprite_data(9, 1, spritetiles+144);
set_sprite_data(10, 1, spritetiles+160);
set_sprite_data(11, 1, spritetiles+176);
set_sprite_data(12, 1, spritetiles+192);
//paddle 0. Controlada por el usuario. [China].
set_sprite_tile(0,0);
set_sprite_tile(1,0);
set_sprite_tile(2,0);
//paddle 1. Controlado por la CPU. [USA].
set_sprite_tile(3,0);
set_sprite_tile(4,0);
set_sprite_tile(5,0);
//bola.
set_sprite_tile(6,1);
//activar fondos y sprites.
SHOW_BKG;
SHOW_SPRITES;
DISPLAY_ON;
enable_interrupts();
INIT_REGISTERS_SOUND_EFECTS();
//Control del programa.
while(1) {
wait_vbl_done();
set_sprite_tile(7,2+score_counter_p1);
set_sprite_tile(8,2+score_counter_p2);
if((score_p1 == 10 || score_p2 == 10) || controller == 1){
if((score_counter_p2 == 10 || score_counter_p1 == 10)){
HIDE_SPRITES;
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, x_congrats_win_tile_data, x_congrats_win_map_data, 1000);
waitpad(J_START);
CLEAR_SCREEN_BACKGROUND();
RESET_COORDS();
controller = 0;
}
if(controller == 1){
score_p1 = 0;
score_p2 = 0;
set_sprite_tile(7,2+score_counter_p1);
set_sprite_tile(8,2+score_counter_p2);
}else{
score_p1 = 0;
score_p2 = 0;
score_counter_p1 = 0;
score_counter_p2 = 0;
ball_vector_x1 = 1;
ball_vector_x2 = 1;
ball_vector_y1 = 1;
ball_vector_y2 = 1;
set_bkg_data(0,10,backgroundcharacters);
set_bkg_tiles(0, 0, 20, 1, bgmap);
for(counter=1;counter<=13;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
set_bkg_tiles(0,14,20,1,bgmap+40);
for(counter=15;counter<=17;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
set_bkg_tiles(0,14,20,1,bgmap+40);
SPRITES_8x8;
set_sprite_data(0, 1, spritetiles);
set_sprite_data(1, 1, spritetiles+16);
set_sprite_data(2, 1, spritetiles+32);
set_sprite_data(3, 1, spritetiles+48);
set_sprite_data(4, 1, spritetiles+64);
set_sprite_data(5, 1, spritetiles+80);
set_sprite_data(6, 1, spritetiles+96);
set_sprite_data(7, 1, spritetiles+112);
set_sprite_data(8, 1, spritetiles+128);
set_sprite_data(9, 1, spritetiles+144);
set_sprite_data(10, 1, spritetiles+160);
set_sprite_data(11, 1, spritetiles+176);
set_sprite_data(12, 1, spritetiles+192);
SHOW_SPRITES;
game_status = 1;
controller = 0;
}
}
counter = joypad();
// movimiento del paddle 0.
if(counter & J_UP && y1>=20){
y1-=1;
y2-=1;
y3-=1;
if(CHECK_COLLISION_BALL_PADDLE(0)<16){
y1+=1;
y2+=1;
y3+=1;
}
}
if(counter & J_DOWN && y3<=124){
y1+=1;
y2+=1;
y3+=1;
if(CHECK_COLLISION_BALL_PADDLE(0)<16){
y1-=1;
y2-=1;
y3-=1;
}
}
// movimiento del paddle 1.
if(y5 > ball_pos_y && y4 >= 20){
y4-=1;
y5-=1;
y6-=1;
if(CHECK_COLLISION_BALL_PADDLE(1)<16){
y4+=1;
y5+=1;
y6+=1;
}
}
if(y5 < ball_pos_y && y6 <= 124){
y4+=1;
y5+=1;
y6+=1;
if(CHECK_COLLISION_BALL_PADDLE(1)<16){
y4-=1;
y5-=1;
y6-=1;
}
}
if(counter & J_START && game_status==0){
//si el juego ha terminado, se reinicia.
if(score_counter_p2 == 10 || score_counter_p1 == 10){
score_p1 = 0;
score_p2 = 0;
score_counter_p2 = 0;
score_counter_p1 = 0;
}
ball_vector_x1 = 1;
ball_vector_x2 = 1;
ball_vector_y1 = 1;
ball_vector_y2 = 1;
game_status = 1; //el juego comienza de nuevo.
}
// movimiento de la bola.
if(vector_pointer==0){
temp1 = ball_vector_x1;
temp2 = ball_vector_y1;
vector_pointer = 1;
}
else{
temp1 = ball_vector_x2;
temp2 = ball_vector_y2;
vector_pointer = 0;
}
ball_pos_x+=temp1;
ball_pos_y+=temp2;
col0=CHECK_COLLISION_BALL_PADDLE(0);
if(col0<16){
while(temp1!=0 || temp2!=0){
if(temp1>0){
temp1--;
ball_pos_x--;
}
if(temp1<0){
temp1++;
ball_pos_x++;
}
if(temp2>0){
temp2--;
ball_pos_y--;
}
if(temp2<0){
temp2++;
ball_pos_y++;
}
if (CHECK_COLLISION_BALL_PADDLE(0)>=16) break;
}
PLAY_PADDLE_SOUND_EFFECT();
}
col1=CHECK_COLLISION_BALL_PADDLE(1);
if (col1 < 16){
while(temp1!=0 || temp2!=0){
if(temp1 > 0){
temp1--;
ball_pos_x--;
}
if(temp1 < 0){
temp1++;
ball_pos_x++;
}
if(temp2 > 0){
temp2--;
ball_pos_y--;
}
if(temp2 < 0){
temp2++;
ball_pos_y++;
}
if (CHECK_COLLISION_BALL_PADDLE(1)>=16) break;
}
PLAY_PADDLE_SOUND_EFFECT();
}
// detección de colisiones.
// pared izquierda.
if(ball_pos_x<9){
RESET_COORDS();
score_p2++;
PLAY_UL_WALL_SOUND_EFFECT();
score_counter_p2++;
//el jugador 2 anota un tanto.
controller = 1;
}
// pared derecha.
if(ball_pos_x>163){
RESET_COORDS();
score_p1++;
score_counter_p1++;
PLAY_UL_WALL_SOUND_EFFECT();
//el jugador 1 anota un tanto.
controller = 1;
}
// pared superior.
if(ball_pos_y < 19){
ball_pos_y = 19;
ball_vector_y1--;
ball_vector_y1=ball_vector_y1 ^ 255;
ball_vector_y2--;
ball_vector_y2=ball_vector_y2 ^ 255;
PLAY_LR_WALL_SOUND_EFFECT();
}
// pared inferior.
if(ball_pos_y > 125){
ball_pos_y = 125;
ball_vector_y1--;
ball_vector_y1=ball_vector_y1 ^ 255;
ball_vector_y2--;
ball_vector_y2=ball_vector_y2 ^ 255;
PLAY_LR_WALL_SOUND_EFFECT();
}
if(col0<16 && ball_pos_x == 23){
// la bola se desplaza arriba.
if(ball_vector_y1<0 || ball_vector_y2<0) col_table = &collision_left_up;
// la bola se desplaza abajo.
else col_table = &collision_left_down;
col_table+=col0*4;
ball_vector_x1 = *col_table;
ball_vector_y1 = *(col_table+1);
ball_vector_x2 = *(col_table+2);
ball_vector_y2 = *(col_table+3);
}
if(col1<16 && ball_pos_x==145){
// la bola se desplaza arriba.
if(ball_vector_y1<0 || ball_vector_y2<0) col_table = &collision_right_up;
// la bola se desplaza abajo.
else col_table = &collision_right_down;
col_table+=col1*4;
ball_vector_x1 = *col_table;
ball_vector_y1 = *(col_table+1);
ball_vector_x2 = *(col_table+2);
ball_vector_y2 = *(col_table+3);
}
//caso especial col0
if(col0<16 && ball_pos_x!=23){
ball_vector_y1--;
ball_vector_y2--;
ball_vector_y1=ball_vector_y1^255;
ball_vector_y2=ball_vector_y2^255;
}
//caso especial col1
if(col1<16 && ball_pos_x!=145){
ball_vector_y1--;
ball_vector_y2--;
ball_vector_y1=ball_vector_y1^255;
ball_vector_y2=ball_vector_y2^255;
}
//repintar sprite del paddle0 en función de su posición actual.
move_sprite(0,15,y1);
move_sprite(1,15,y2);
move_sprite(2,15,y3);
//repintar sprite del paddle1 en función de su posición actual.
move_sprite(3,153,y4);
move_sprite(4,153,y5);
move_sprite(5,153,y6);
////repintar bola en función de su posición actual.
move_sprite(6,ball_pos_x,ball_pos_y);
//repintar puntuaciones.
move_sprite(7,15,140);
move_sprite(8,153,140);
}
}
void PLOT_BACKGROUND_IMAGE(int coord_X, int coord_Y, int tam_tile_X, int tam_tile_Y, unsigned char *tile_data, unsigned char *map_data, int millis){
set_bkg_data(coord_X, coord_Y, tile_data);
set_bkg_tiles(coord_X, coord_Y, tam_tile_X, tam_tile_Y, map_data);
SHOW_BKG;
DISPLAY_ON;
delay(millis);
}
void PLOT_SET_BACKGROUND_LOGO(){
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, x_production_first_tile_data, x_production_first_map_data, 2000);
CLEAR_SCREEN_BACKGROUND();
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, hammer_keyboard__tile_data, hammer_keyboard__map_data, 2000);
CLEAR_SCREEN_BACKGROUND();
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, x_production_second_tile_data, x_production_second_map_data, 2000);
CLEAR_SCREEN_BACKGROUND();
}
void PRINT_SOLID_MARQUEE(){
gotoxy(0, 0);
color(BLACK, WHITE, SOLID);
box(156,140,2,2,M_NOFILL);
box(155,139,3,3,M_NOFILL);
box(154,138,4,4,M_NOFILL);
box(153,137,5,5,M_NOFILL);
box(152,136,6,6,M_NOFILL);
}
void INIT_REGISTERS_SOUND_EFECTS(void){
NR52_REG = 0xF8U;
NR51_REG = 0x00U;
NR50_REG = 0x77U;//0xFFU;
}
void PLAY_PADDLE_SOUND_EFFECT(void){
NR10_REG = 0x34U;
NR11_REG = 0x80U;
NR12_REG = 0xF0U;
NR13_REG = 0x0AU;
NR14_REG = 0xC6U;
NR51_REG |= 0x11;
}
void PLAY_UL_WALL_SOUND_EFFECT(void){
NR41_REG = 0x00;//0x1FU;
NR42_REG = 0xE1;//0xF7U;
NR43_REG = 0x22;//0x24U;
NR44_REG = 0xC3;//0x80U;
NR51_REG = 0x88U;
}
void PLAY_LR_WALL_SOUND_EFFECT(void){
NR10_REG = 0x04U;
NR11_REG = 0xFEU;
NR12_REG = 0xA1U;
NR13_REG = 0x8FU;
NR14_REG = 0x86U;
NR51_REG = 0xF7;
}
void RESET_COORDS(){
//pos inicial paddle0.
y1 = 65;
y2 = 73;
y3 = 81;
//pos inicial paddle1.
y4 = 65;
y5 = 73;
y6 = 81;
//pos inicial bola.
ball_pos_x=80;
ball_pos_y=77;
//inicializar el vector de movimiento.
ball_vector_x1 = 0;
ball_vector_x2 = 0;
ball_vector_y1 = 0;
ball_vector_y2 = 0;
vector_pointer = 0;
// juego en pausa.
game_status = 0;
return;
}
UBYTE CHECK_COLLISION_BALL_PADDLE(UBYTE paddleNr){
//paddle0
if(paddleNr==0){
if(ball_pos_x>=15)
colx = ball_pos_x - 15;
else
colx = 15 - ball_pos_x;
if (colx<8){
if (ball_pos_y >= y2) coly = ball_pos_y - y2;
else coly = y2 - ball_pos_y;
return coly;
}
return 16;
}
//paddle1
else{
if(ball_pos_x>=153)
colx = ball_pos_x - 153;
else
colx = 153 - ball_pos_x;
if (colx<8){
if (ball_pos_y >= y5) coly = ball_pos_y - y5;
else coly = y5 - ball_pos_y;
return coly;
}
return 16;
}
}
void PRINT_MESSAGE(int x, int y, char *c){
gotogxy(x,y);
gprintf(c);
}
void CLEAR_SCREEN_LINE ( UBYTE y ){
UBYTE x;
for (x = y*20 ; x < (y+1)*20 ; x++ ){
set_bkg_data (x+tile_offset,1,(unsigned char *)TEXT_cEMPTY);
}
}
void CLEAR_SCREEN_BACKGROUND ( void ){
UBYTE x;
for ( x = 0 ; x < tile_height ; x++ ){
CLEAR_SCREEN_LINE ( x );
}
}
void CLEAR_SCREEN_TEXT(){
int x, y;
for(y = 0; y < 20; y++){
for(x = 0; x < 30; x++){
gotoxy(x, y);
gprintf(" ");
}
}
gotoxy(0,0);
}
signed char spritetiles[] = {
//paddle
255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,
//bola
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
//null
0x00,0x00,0x18,0x18,0x24,0x24,0x24,0x24,
0x24,0x24,0x24,0x24,0x18,0x18,0x00,0x00,
//1
0x00,0x00,0x08,0x08,0x18,0x18,0x28,0x28,
0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x00,
//2
0x00,0x00,0x18,0x18,0x24,0x24,0x08,0x08,
0x10,0x10,0x20,0x20,0x3C,0x3C,0x00,0x00,
//3
0x38,0x38,0x04,0x04,0x04,0x04,0x38,0x38,
0x04,0x04,0x04,0x04,0x38,0x38,0x00,0x00,
//4
0x08,0x08,0x10,0x10,0x20,0x20,0x48,0x48,
0x7C,0x7C,0x08,0x08,0x08,0x08,0x00,0x00,
//5
0x00,0x00,0x3C,0x3C,0x20,0x20,0x38,0x38,
0x04,0x04,0x04,0x04,0x38,0x38,0x00,0x00,
//6
0x00,0x00,0x1C,0x1C,0x20,0x20,0x20,0x20,
0x3C,0x3C,0x24,0x24,0x3C,0x3C,0x00,0x00,
//7
0x00,0x00,0x3C,0x3C,0x04,0x04,0x08,0x08,
0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00,
//8
0x18,0x18,0x24,0x24,0x24,0x24,0x18,0x18,
0x24,0x24,0x24,0x24,0x18,0x18,0x00,0x00,
//9
0x18,0x18,0x24,0x24,0x24,0x24,0x1C,0x1C,
0x04,0x04,0x04,0x04,0x18,0x18,0x00,0x00,
//10
0x26,0x26,0x69,0x69,0xA9,0xA9,0x29,0x29,
0x29,0x29,0x29,0x29,0x26,0x26,0x00,0x00
};
PLOT_SET_BACKGROUND_LOGO();
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, x_pongdiplomacy_logo_tile_data, x_pongdiplomacy_logo_map_data, 2000);
waitpad(J_START);
///// COMIENZA EL BLOQUE BITMAP DONDE SE MUESTRA EL TEXTO DEL JUEGO.
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, _blank_text_tile_data, _blank_text_map_data, 2000);
waitpad(J_START);
///// TERMINA EL BLOQUE BITMAP DONDE SE MUESTRA EL TEXTO DEL JUEGO.
disable_interrupts();
DISPLAY_OFF;
RESET_COORDS();
//fijar las puntuaciones a cero.
score_p1 = 0;
score_p2 = 0;
score_counter_p1 = 0;
score_counter_p2 = 0;
//background
set_bkg_data(0,10,backgroundcharacters);
//background
set_bkg_tiles(0, 0, 20, 1, bgmap);
//background
for(counter=1;counter<=13;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
set_bkg_tiles(0,14,20,1,bgmap+40);
for(counter=15;counter<=17;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
set_bkg_tiles(0,14,20,1,bgmap+40);
//cargar los sprites.
SPRITES_8x8;
//cargar los tiles del paddle.
set_sprite_data(0, 1, spritetiles);
//cargar los tiles de la bola.
set_sprite_data(1, 1, spritetiles+16);
//cargar los tiles de las puntuaciones.
set_sprite_data(2, 1, spritetiles+32);
set_sprite_data(3, 1, spritetiles+48);
set_sprite_data(4, 1, spritetiles+64);
set_sprite_data(5, 1, spritetiles+80);
set_sprite_data(6, 1, spritetiles+96);
set_sprite_data(7, 1, spritetiles+112);
set_sprite_data(8, 1, spritetiles+128);
set_sprite_data(9, 1, spritetiles+144);
set_sprite_data(10, 1, spritetiles+160);
set_sprite_data(11, 1, spritetiles+176);
set_sprite_data(12, 1, spritetiles+192);
//paddle 0. Controlada por el usuario. [China].
set_sprite_tile(0,0);
set_sprite_tile(1,0);
set_sprite_tile(2,0);
//paddle 1. Controlado por la CPU. [USA].
set_sprite_tile(3,0);
set_sprite_tile(4,0);
set_sprite_tile(5,0);
//bola.
set_sprite_tile(6,1);
//activar fondos y sprites.
SHOW_BKG;
SHOW_SPRITES;
DISPLAY_ON;
enable_interrupts();
INIT_REGISTERS_SOUND_EFECTS();
void RESET_COORDS(){
//pos inicial paddle0.
y1 = 65;
y2 = 73;
y3 = 81;
//pos inicial paddle1.
y4 = 65;
y5 = 73;
y6 = 81;
//pos inicial bola.
ball_pos_x=80;
ball_pos_y=77;
//inicializar el vector de movimiento.
ball_vector_x1 = 0;
ball_vector_x2 = 0;
ball_vector_y1 = 0;
ball_vector_y2 = 0;
vector_pointer = 0;
// juego en pausa.
game_status = 0;
return;
}
//cargar los sprites.
SPRITES_8x8;
//cargar los tiles del paddle.
set_sprite_data(0, 1, spritetiles);
//cargar los tiles de la bola.
set_sprite_data(1, 1, spritetiles+16);
//cargar los tiles de las puntuaciones.
set_sprite_data(2, 1, spritetiles+32);
set_sprite_data(3, 1, spritetiles+48);
set_sprite_data(4, 1, spritetiles+64);
set_sprite_data(5, 1, spritetiles+80);
set_sprite_data(6, 1, spritetiles+96);
set_sprite_data(7, 1, spritetiles+112);
set_sprite_data(8, 1, spritetiles+128);
set_sprite_data(9, 1, spritetiles+144);
set_sprite_data(10, 1, spritetiles+160);
set_sprite_data(11, 1, spritetiles+176);
set_sprite_data(12, 1, spritetiles+192);
//paddle 0. Controlada por el usuario. [China].
set_sprite_tile(0,0);
set_sprite_tile(1,0);
set_sprite_tile(2,0);
//paddle 1. Controlado por la CPU. [USA].
set_sprite_tile(3,0);
set_sprite_tile(4,0);
set_sprite_tile(5,0);
//bola.
set_sprite_tile(6,1);
//activar fondos y sprites.
SHOW_BKG;
SHOW_SPRITES;
DISPLAY_ON;
enable_interrupts();
INIT_REGISTERS_SOUND_EFECTS();
if((score_p1 == 10 || score_p2 == 10) || controller == 1){
if((score_counter_p2 == 10 || score_counter_p1 == 10)){
HIDE_SPRITES;
PLOT_BACKGROUND_IMAGE(0, 0, 20, 18, x_congrats_win_tile_data, x_congrats_win_map_data, 1000);
waitpad(J_START);
CLEAR_SCREEN_BACKGROUND();
RESET_COORDS();
controller = 0;
}
if(controller == 1){
score_p1 = 0;
score_p2 = 0;
set_sprite_tile(7,2+score_counter_p1);
set_sprite_tile(8,2+score_counter_p2);
}else{
score_p1 = 0;
score_p2 = 0;
score_counter_p1 = 0;
score_counter_p2 = 0;
ball_vector_x1 = 1;
ball_vector_x2 = 1;
ball_vector_y1 = 1;
ball_vector_y2 = 1;
set_bkg_data(0,10,backgroundcharacters);
set_bkg_tiles(0, 0, 20, 1, bgmap);
for(counter=1;counter<=13;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
set_bkg_tiles(0,14,20,1,bgmap+40);
for(counter=15;counter<=17;counter++) set_bkg_tiles(0,counter,20,1,bgmap+20);
set_bkg_tiles(0,14,20,1,bgmap+40);
SPRITES_8x8;
set_sprite_data(0, 1, spritetiles);
set_sprite_data(1, 1, spritetiles+16);
set_sprite_data(2, 1, spritetiles+32);
set_sprite_data(3, 1, spritetiles+48);
set_sprite_data(4, 1, spritetiles+64);
set_sprite_data(5, 1, spritetiles+80);
set_sprite_data(6, 1, spritetiles+96);
set_sprite_data(7, 1, spritetiles+112);
set_sprite_data(8, 1, spritetiles+128);
set_sprite_data(9, 1, spritetiles+144);
set_sprite_data(10, 1, spritetiles+160);
set_sprite_data(11, 1, spritetiles+176);
set_sprite_data(12, 1, spritetiles+192);
SHOW_SPRITES;
game_status = 1;
controller = 0;
}
}
UBYTE CHECK_COLLISION_BALL_PADDLE(UBYTE paddleNr){
//paddle0
if(paddleNr==0){
if(ball_pos_x>=15)
colx = ball_pos_x - 15;
else
colx = 15 - ball_pos_x;
if (colx<8){
//from x point of view there might be a collision
if (ball_pos_y >= y2) coly = ball_pos_y - y2;
else coly = y2 - ball_pos_y;
//check the y point of view
return coly;
}
return 16;
}
//paddle1
else{
if(ball_pos_x>=153)
colx = ball_pos_x - 153;
else
colx = 153 - ball_pos_x;
if (colx<8){
//from x point of view there might be a collision
if (ball_pos_y >= y5) coly = ball_pos_y - y5;
else coly = y5 - ball_pos_y;
//check the y point of view
return coly;
}
return 16;
}
}UBYTE CHECK_COLLISION_BALL_PADDLE(UBYTE paddleNr){
//paddle0
if(paddleNr==0){
if(ball_pos_x>=15)
colx = ball_pos_x - 15;
else
colx = 15 - ball_pos_x;
if (colx<8){
if (ball_pos_y >= y2) coly = ball_pos_y - y2;
else coly = y2 - ball_pos_y;
return coly;
}
return 16;
}
//paddle1
else{
if(ball_pos_x>=153)
colx = ball_pos_x - 153;
else
colx = 153 - ball_pos_x;
if (colx<8){
if (ball_pos_y >= y5) coly = ball_pos_y - y5;
else coly = y5 - ball_pos_y;
return coly;
}
return 16;
}
}
// detección de colisiones.
// pared izquierda.
if(ball_pos_x<9){
RESET_COORDS();
score_p2++;
PLAY_UL_WALL_SOUND_EFFECT();
score_counter_p2++;
//el jugador 2 anota un tanto.
controller = 1;
}
// pared derecha.
if(ball_pos_x>163){
RESET_COORDS();
score_p1++;
score_counter_p1++;
PLAY_UL_WALL_SOUND_EFFECT();
//el jugador 1 anota un tanto.
controller = 1;
}
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -c -o PingPongDiplomacy.o PingPongDiplomacy.c
lcc -Wa-l -Wl-m -Wl-j -DUSE_SFR_FOR_REG -Wl-yt1 -Wl-yo4 -Wl-ya0 -o PingPongDiplomacy-20141214.gb PingPongDiplomacy.o
del *.o *.lst *.map *.sym
pause