This is currently my version of the Breakout game on the FX-9860GII. It is super simple right now, I plan on adding a rotating map list and power ups. The code has redundancy because some parts are either left over or have not been implemented yet or just poorly written.
The map is a 10x5 with fixed block sizes but I think I might add another size (vertical block)
I'd add the executable but I don't know how.
Also, I have not heavily commented yet, so the code might not be easy to figure out its function
video:https://youtu.be/sOmuUH4pjUA
/*****************************************************************/
/* */
/* CASIO fx-9860G SDK Library */
/* */
/* File name : [ProjectName].c */
/* */
/* Copyright (c) 2006 CASIO COMPUTER CO., LTD. */
/* */
/*****************************************************************/
#include "fxlib.h"
#include "stdio.h"
//****************************************************************************
// AddIn_main (Sample program main function)
//
// param : isAppli : 1 = This application is launched by MAIN MENU.
// : 0 = This application is launched by a strip in eACT application.
//
// OptionNum : Strip number (0~3)
// (This parameter is only used when isAppli parameter is 0.)
//
// retval : 1 = No error / 0 = Error
//
//****************************************************************************
/********************
*********************
Variables
*********************
********************/
//Global variables
unsigned short score, level, highscore, life, powerups, destroyed;
struct objects {
unsigned char x, y, xx, yy, active, type;
} object[100];
struct ball {
unsigned short x, y, xx, yy, up, left, life;
} ball;
unsigned char index;
//Map data:
struct player {
unsigned short x, y, xx, direction, middle; //direction = 0 (left), 1 (right), 2 (not moving)
} player;
//Maps
const char map1[] = { //all maps are 15 wide, 6 down
1,1,1,1,1,1,1,1,1,1,
1,0,1,1,1,1,1,0,1,1,
1,1,0,0,1,0,0,1,1,1,
1,0,1,1,1,1,1,0,1,1,
1,1,1,1,1,1,1,1,1,1
};
/********************
*********************
End of Variables
*********************
********************/
//prototype functions; The F### is the id of the function, just search that and it will take you to the beginnding of it (esear for me)
void intro(); //F1
void load_next_level(unsigned char*); //F2
void draw_ball(); //F3
void initialize_objects(); // F4
void initialize_ball(); // F5
void object_generate(unsigned short, unsigned short, unsigned short, unsigned short); // F6
void draw_objects(); // F7
void draw_player(); //F8
void move_ball(); //F9
void initialize_game(); //F10
int move_player(); //F11
void game_loop(); //F12
void control(); //F13
//end of prototype functions
/***************
****************
Intro
****************
***************/
void intro() //F1
{
Bdisp_AllClr_DDVRAM();
PrintXY(0,0,"Breakout Game",0);
PrintXY(0,20,"Made By: GodOfCows",0);
Bdisp_PutDisp_DD();
Sleep(2000);
Bdisp_AllClr_DDVRAM();
}
/***************
****************
End of the intre
****************
***************/
/**************
***************
Draw Level Number
***************
**************/
void load_next_level(unsigned char* map) //F2
{
unsigned char i, x, y, xx, yy;
unsigned char string[20];
Bdisp_AllClr_DDVRAM();
initialize_objects();
initialize_ball();
KillTimer(1);
sprintf(&string, "Current Score: %d", score);
PrintXY(0,0,"Next Level, Coming Up!", 0);
PrintXY(0,20,string,0);
Bdisp_PutDisp_DD();
Sleep(2000);
Bdisp_AllClr_DDVRAM();
x = 8;
y = 0;
xx = 16;
yy = 5;
for (i = 0; i < 50; i++)///
{
if (map[i])
object_generate(x,y,xx,yy);
//
//add in special abilities here
//
x+=10;
xx+=10;
if (i == 9 || i == 19 || i == 29 || i == 39 || i == 49)
{
y+=7;
yy+=7;
x = 8;
xx = 16;
}
}
draw_objects();
SetTimer(1,50,game_loop);
}
/*************
**************
End of draw level number function
**************
*************/
/*************
**************
Draw Ball function
**************
*************/
void draw_ball(unsigned short x, unsigned short y, unsigned char put) //F3
{
if (put)
{
Bdisp_SetPoint_VRAM(x,y,1);Bdisp_SetPoint_VRAM(x+1,y,1);Bdisp_SetPoint_VRAM(x+2,y,1);
Bdisp_SetPoint_VRAM(x,y+1,1);Bdisp_SetPoint_VRAM(x+1,y+1,1);Bdisp_SetPoint_VRAM(x+2,y+1,1);
Bdisp_SetPoint_VRAM(x,y+2,1);Bdisp_SetPoint_VRAM(x+1,y+2,1);Bdisp_SetPoint_VRAM(x+2,y+2,1);
} else
{
Bdisp_SetPoint_VRAM(x,y,0);Bdisp_SetPoint_VRAM(x+1,y,0);Bdisp_SetPoint_VRAM(x+2,y,0);
Bdisp_SetPoint_VRAM(x,y+1,0);Bdisp_SetPoint_VRAM(x+1,y+1,0);Bdisp_SetPoint_VRAM(x+2,y+1,0);
Bdisp_SetPoint_VRAM(x,y+2,0);Bdisp_SetPoint_VRAM(x+1,y+2,0);Bdisp_SetPoint_VRAM(x+2,y+2,0);
}
}
/************
*************
End of Draw Ball
*************
************/
/***********
************
Initializing functions
************
***********/
void initialize_objects() //F4
{
unsigned char i;
index = 0;
for (i = 0; i <= 100; i++)
{
object[i].x = object[i].y = object[i].xx = object[i].yy = object[i].active = object[i].type = 0; //all variables in the structure set to zero
}
} //end of initialize_objects()
//////////
void initialize_ball() //F5
{
ball.x = 63;
ball.y = 51;
ball.xx = 65;
ball.yy = 53;
ball.up = 1;
ball.left = 0;
ball.life = 1;
} //end of initialize_ball
/***********
************
End of Initializing functions
************
***********/
/**********
***********
Object Generate
***********
**********/
void object_generate(unsigned short x, unsigned short y, unsigned short xx, unsigned short yy) //F6
{
object[index].x = x;
object[index].y = y;
object[index].xx = xx;
object[index].yy = yy;
object[index].active = 1;
index++;
}
/*********
**********
End of object_generate
**********
*********/
/*********
**********
Draw Objects
**********
*********/
void draw_objects() //F7
{
unsigned char i;
unsigned short x, y; //cordinates to draw the boxes
for (i = 0; i <= index; i++)
{
if (object[i].active)
{
for (x = 0; x <= object[i].xx-object[i].x; x++) //draw the top and bottom
{
/*
Bdisp_SetPoint_VRAM(object[i].x+x,object[i].y,0);// top
Bdisp_SetPoint_VRAM(object[i].x+x,object[i].yy,0);// bottom
*/ //If I needed to call draw_box multiple times I would delete this to erease the last iteration
Bdisp_SetPoint_VRAM(object[i].x+x,object[i].y,1);// top
Bdisp_SetPoint_VRAM(object[i].x+x,object[i].yy,1); // bottom
}
for (y = 0; y <= object[i].yy-object[i].y; y++)
{
/*
Bdisp_SetPoint_VRAM(object[i].x,object[i].y+y,0); //left
Bdisp_SetPoint_VRAM(object[i].xx,object[i].y+y,0); //bottom
*/ // same as above
Bdisp_SetPoint_VRAM(object[i].x,object[i].y+y,1); //left
Bdisp_SetPoint_VRAM(object[i].xx,object[i].y+y,1); //right
}
}
}
Bdisp_PutDisp_DD();
}
/*********
**********
End of Draw Objects
**********
*********/
/*********
**********
Draw Player
**********
*********/
void draw_player(unsigned char erease) //F8
{
if (!erease)
{
Bdisp_SetPoint_VRAM(player.x-1,player.y,0);
Bdisp_SetPoint_VRAM(player.x,player.y,0);
Bdisp_SetPoint_VRAM(player.x+1,player.y,0);
Bdisp_SetPoint_VRAM(player.x+2,player.y,0);
Bdisp_SetPoint_VRAM(player.x+3,player.y,0);
Bdisp_SetPoint_VRAM(player.x+4,player.y,0);
Bdisp_SetPoint_VRAM(player.x+5,player.y,0);
Bdisp_SetPoint_VRAM(player.x+6,player.y,0);
Bdisp_SetPoint_VRAM(player.x+7,player.y,0);
Bdisp_SetPoint_VRAM(player.x+9,player.y,0);
Bdisp_SetPoint_VRAM(player.x+10,player.y,0);
Bdisp_SetPoint_VRAM(player.x+11,player.y,0);
Bdisp_SetPoint_VRAM(player.x+12,player.y,0);
Bdisp_SetPoint_VRAM(player.x+13,player.y,0);
Bdisp_SetPoint_VRAM(player.x+14,player.y,0);
Bdisp_SetPoint_VRAM(player.x+15,player.y,0);
Bdisp_SetPoint_VRAM(player.x+16,player.y,0);
Bdisp_SetPoint_VRAM(player.x+17,player.y,0);
Bdisp_SetPoint_VRAM(player.x+18,player.y,0);
Bdisp_SetPoint_VRAM(player.x+19,player.y,0);
Bdisp_SetPoint_VRAM(player.x+20,player.y,0);
Bdisp_SetPoint_VRAM(player.x+21,player.y,0);
}
if (erease)
{
Bdisp_SetPoint_VRAM(player.x,player.y,1);
Bdisp_SetPoint_VRAM(player.x+1,player.y,1);
Bdisp_SetPoint_VRAM(player.x+2,player.y,1);
Bdisp_SetPoint_VRAM(player.x+3,player.y,1);
Bdisp_SetPoint_VRAM(player.x+4,player.y,1);
Bdisp_SetPoint_VRAM(player.x+5,player.y,1);
Bdisp_SetPoint_VRAM(player.x+6,player.y,1);
Bdisp_SetPoint_VRAM(player.x+7,player.y,1);
Bdisp_SetPoint_VRAM(player.x+8,player.y,1);
Bdisp_SetPoint_VRAM(player.x+9,player.y,1);
Bdisp_SetPoint_VRAM(player.x+10,player.y,1);
Bdisp_SetPoint_VRAM(player.x+11,player.y,1);
Bdisp_SetPoint_VRAM(player.x+12,player.y,1);
Bdisp_SetPoint_VRAM(player.x+13,player.y,1);
Bdisp_SetPoint_VRAM(player.x+14,player.y,1);
Bdisp_SetPoint_VRAM(player.x+15,player.y,1);
Bdisp_SetPoint_VRAM(player.x+16,player.y,1);
Bdisp_SetPoint_VRAM(player.x+17,player.y,1);
Bdisp_SetPoint_VRAM(player.x+18,player.y,1);
Bdisp_SetPoint_VRAM(player.x+19,player.y,1);
Bdisp_SetPoint_VRAM(player.x+20,player.y,1);
}
}
/*********
**********
End of draw player
**********
*********/
/*********
**********
Move Ball
**********
*********/
void move_ball() //F9
{
unsigned char i, x, y;
if (ball.x <= 2)
ball.left = 0;
if (ball.xx >= 125)
ball.left = 1;
if (ball.y <= 3)
ball.up = 0;
if (ball.yy >= 63)
{
ball.life = 0;
}
//Hit play?
if (ball.xx > player.x && ball.xx < player.middle && ball.yy == player.y+1)
{
ball.left = 1;
ball.up = 1;
} else if (ball.x > player.middle && ball.x < player.xx && ball.yy == player.y+1)
{
ball.left = 0;
ball.up = 1;
} else if (ball.x > player.x && ball.xx < player.xx && ball.yy == player.y+1)
{
ball.up = 1;
}
for (i = 0; i <= index; i++)
{
if (object[i].active)
{
if (!(ball.xx < object[i].x) && !(ball.x > object[i].xx) && !(ball.yy < object[i].y) && !(ball.y > object[i].yy))
{
score+=10;
destroyed++;
if (score > highscore)
highscore = score;
object[i].active = 0;
if (ball.yy <= object[i].y || ball.y >= object[i].yy)
if (ball.x >= object[i].x || ball.xx <= object[i].xx)
{
if (ball.up)
ball.up = 0;
else ball.up = 1;
}
if (ball.xx <= object[i].x || ball.x >= object[i].xx)
if (ball.y <= object[i].yy || ball.yy >= object[i].y)
{
if (ball.left)
ball.left = 0;
else ball.left = 1;
}
for (x = 0; x <= object[i].xx-object[i].x; x++)
{
Bdisp_SetPoint_VRAM(object[i].x+x,object[i].y,0);
Bdisp_SetPoint_VRAM(object[i].x+x,object[i].yy,0);
}
for (y = 0; y <= object[i].yy-object[i].y; y++)
{
Bdisp_SetPoint_VRAM(object[i].x,object[i].y+y,0);
Bdisp_SetPoint_VRAM(object[i].xx,object[i].y+y,0);
}
}
}
}
draw_ball(ball.x,ball.y,0);
if (ball.up)
{
ball.y--;
ball.yy--;
} else {
ball.y++;
ball.yy++;
}
if (ball.left)
{
ball.x--;
ball.xx--;
} else {
ball.x++;
ball.xx++;
}
draw_ball(ball.x,ball.y,1);
Bdisp_PutDisp_DD();
}
/*********
**********
End of Move Ball
**********
*********/
/***********
************
Initialize Game
************
***********/
void initialize_game() //F10
{
Bdisp_AllClr_DDVRAM();
initialize_objects();
initialize_ball();
destroyed = 0;
player.x = 58;
player.middle = player.x+10;
player.y = 60;
player.xx = 78;
player.direction = 2;
score = highscore = powerups = 0;
level = 1;
life = 5;
}
/***********
************
End of Initialize Game
************
***********/
/***********
************
Move Player
************
***********/
int move_player() //F11
{
if (player.direction == 2)
return 0;
else if (player.direction == 0 && player.x >= 4)
{
draw_player(0);
player.x-=4;
player.xx-=4;
player.middle-=4;
player.direction = 2;
draw_player(1);
} else if (player.direction == 1 && player.xx < 123)
{
draw_player(0);
player.x+=4;
player.xx+=4;
player.middle+=4;
player.direction = 2;
draw_player(1);
}
}
/***********
************
End of Move Player
************
***********/
/***********
************
Game Loop
************
***********/
void game_loop() //F12
{
unsigned char string[20];
move_ball();
move_player();
draw_player(0);
draw_player(1);
if (ball.life == 0)
{
Bdisp_AllClr_DDVRAM();
initialize_ball();
draw_objects();
life--;
}
if (destroyed == index)
{
destroyed = 0;
level++;
load_next_level(&map1); //replace later
}
if (!life)
{
KillTimer(1); //KILL GAME LOOP // WHERE WE LEFT OFF
Bdisp_AllClr_DDVRAM();
PrintXY(0,0,"Game Over!", 0);
sprintf(&string, "Your Score: %d", score);
PrintXY(0,20,string,0);
Bdisp_PutDisp_DD();
Sleep(3000);
initialize_game();
SetTimer(1,50,game_loop);
}
}
/***********
************
End of Game Loop
************
***********/
void control() //F13
{
unsigned int key;
while (1)
{
GetKey(&key);
switch (key)
{
case KEY_CTRL_LEFT:
if (player.x != 0)
{
player.direction = 0;
}
break;
case KEY_CTRL_RIGHT:
if (player.xx != 126)
{
player.direction = 1;
}
break;
}
} //while end
} //void end
int AddIn_main(int isAppli, unsigned short OptionNum)
{
while(1){
intro();
initialize_game();
load_next_level(&map1);
SetTimer(1,50,game_loop);
control();
}
return 1;
}
//****************************************************************************
//************** ****************
//************** Notice! ****************
//************** ****************
//************** Please do not change the following source. ****************
//************** ****************
//****************************************************************************
#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
//****************************************************************************
// InitializeSystem
//
// param : isAppli : 1 = Application / 0 = eActivity
// OptionNum : Option Number (only eActivity)
//
// retval : 1 = No error / 0 = Error
//
//****************************************************************************
int InitializeSystem(int isAppli, unsigned short OptionNum)
{
return INIT_ADDIN_APPLICATION(isAppli, OptionNum);
}
#pragma section



