I will now start working on the options in the shop and the key commands to make the game more playable.
EDIT: What is the clear key value in C?
Am I getting this code correct so far?
Code: kb_Scan();
if (kb_Data[3] & kb_1) {
game();
main();
}
if (kb_Data[4] & kb_2) {
shop();
main();
}
if (kb_Data[5] & kb_3) {
info();
main();
}
I have made the options, but I cant exit the program. I also have a problem with the info tab. Below you can see the problem.
And here is the full code.
Code: #include <tice.h>
#include <graphx.h>
#include <keypadc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ti/getcsc.h>
#include "gfx/gfx.h"
#include "gfx/hiiii.h"
#include "gfx/subwaysurf.h"
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define REC_SHOP 55
void drawSprite(void) {
gfx_SetPalette(global_palette, sizeof_global_palette, 0);
//bottom right
gfx_ScaledTransparentSprite_NoClip(tree, 241, 150, 2,2);
//botton left tree
gfx_ScaledTransparentSprite_NoClip(tree, -5, 150, 2,2);
gfx_ScaledTransparentSprite_NoClip(hiiii, -9, 0, 5, 5);
}
void shopOptions(void) {
gfx_SetColor(222);
// top row//
gfx_FillRectangle(35,25,REC_SHOP,REC_SHOP);
gfx_FillRectangle(100,25,REC_SHOP,REC_SHOP);
gfx_FillRectangle(165,25,REC_SHOP,REC_SHOP);
gfx_FillRectangle(230,25,REC_SHOP,REC_SHOP);
//2nd row//
gfx_FillRectangle(35,95,REC_SHOP,REC_SHOP);
gfx_FillRectangle(100,95,REC_SHOP,REC_SHOP);
gfx_FillRectangle(165,95,REC_SHOP,REC_SHOP);
gfx_FillRectangle(230,95,REC_SHOP,REC_SHOP);
//3rd row//
gfx_FillRectangle(35,160,REC_SHOP,REC_SHOP);
gfx_FillRectangle(100,160,REC_SHOP,REC_SHOP);
gfx_FillRectangle(165,160,REC_SHOP,REC_SHOP);
gfx_FillRectangle(230,160,REC_SHOP,REC_SHOP);
}
void drawBackground(void) {
gfx_SetColor(31);
gfx_FillScreen(255);
//the sky//
gfx_FillRectangle(0,0,SCREEN_WIDTH,12);
gfx_SetColor(63);
gfx_FillRectangle(0,12,SCREEN_WIDTH,12);
gfx_SetColor(95);
gfx_FillRectangle(0,24,SCREEN_WIDTH,12);
gfx_SetColor(127);
gfx_FillRectangle(0,36,SCREEN_WIDTH,12);
gfx_SetColor(159);
gfx_FillRectangle(0,48,SCREEN_WIDTH,12);
gfx_SetColor(191);
gfx_FillRectangle(0,60,SCREEN_WIDTH,12);
gfx_SetColor(223);
gfx_FillRectangle(0,72,SCREEN_WIDTH,12);
//now the bottom//
gfx_SetColor(34);
gfx_FillRectangle(0,228,SCREEN_WIDTH,12);
gfx_SetColor(35);
gfx_FillRectangle(0,216,SCREEN_WIDTH,12);
gfx_SetColor(36);
gfx_FillRectangle(0,204,SCREEN_WIDTH,12);
gfx_SetColor(37);
gfx_FillRectangle(0,192,SCREEN_WIDTH,12);
gfx_SetColor(38);
gfx_FillRectangle(0,180,SCREEN_WIDTH,12);
gfx_SetColor(70);
gfx_FillRectangle(0,168,SCREEN_WIDTH,12);
gfx_SetColor(39);
gfx_FillRectangle(0,156,SCREEN_WIDTH,12);
//now for a sun//
gfx_SetColor(231);
gfx_FillCircle(300,15,14);
//buildings//
gfx_SetColor(64);
gfx_FillRectangle(0,80,10,76);
gfx_SetColor(40);
gfx_FillRectangle(10,76,10,80);
gfx_SetColor(128);
gfx_FillRectangle(7,100,10,56);
gfx_SetColor(115);
gfx_FillRectangle(20,80,10,76);
gfx_SetColor(171);
gfx_FillRectangle(310,80,10,76);
gfx_SetColor(228);
gfx_FillRectangle(305,110,10,46);
}
/*- color: {index: 0, r: 255, g: 255, b: 255}
- color: {index: 1, r: 255, g: 216, b: 0}*/
void drawTitle(void) {
gfx_SetTextScale(3, 3);
gfx_SetColor(206);
gfx_PrintStringXY("SUBWAY", 90, 1);
gfx_SetColor(141);
gfx_PrintStringXY("SURFERS", 85, 23);
gfx_SetTextScale(2, 1);
gfx_SetColor(226);
gfx_PrintStringXY(">> CE <<", 117, 50);
}
void info(void) {
gfx_Begin();
drawBackground();
gfx_SetTextScale(1,1);
gfx_SetColor(0);
gfx_PrintStringXY("Welcome to Subway Surfers by CalcGeek",1,1);
gfx_PrintStringXY("I wanted to learn the programming language",1,10);
gfx_PrintStringXY("called C, and so I decided I will make a game",1,20);
gfx_PrintStringXY("so I will stay motivated to continue learning C.",1,30);
gfx_PrintStringXY("I saw that there was a lack of the game",1,40);
gfx_PrintStringXY("Subway Surfers in the calculator community ",1,50);
gfx_PrintStringXY("and so I decided that, that will be the game I ",1,60);
gfx_PrintStringXY("will make. Thank you so much to the community on",1,70);
gfx_PrintStringXY("Cemetech for letting me bother them all the",1,80);
gfx_PrintStringXY("time.",1,90);
gfx_PrintStringXY("press enter for the controls.",1,230);
while(!os_GetCSC()){};
drawBackground();
gfx_SetTextScale(1,1);
gfx_SetColor(0);
gfx_PrintStringXY("The controls are simple.",1,10);
gfx_PrintStringXY("The up arrow = jump.",1,30);
gfx_PrintStringXY("The down arrow = crouch.",1,40);
gfx_PrintStringXY("The right arrow = right.",1,50);
gfx_PrintStringXY("The left arrow = left.",1,60);
gfx_PrintStringXY("The second = Hoverboard (not implemented yet)",1,70);
gfx_PrintStringXY("press enter for main menu.",1,230);
}
void shop(void) {
drawBackground();
shopOptions();
}
void game(void) {
}
void drawMenuButton(int x, int y, int width, int height, const char *text, int selected) {
if (selected) {
// Selected: bright neon colors
gfx_SetColor(47);//this color is for the outside selection//
gfx_FillRectangle(x - 3, y - 3, width + 6, height + 6);
gfx_SetColor(192);//this color is for the inside selection//
gfx_FillRectangle(x, y, width, height);
gfx_SetColor(239);//this color is for the middle selection//
} else {
// Unselected: darker colors
gfx_SetColor(71);//this color is for the middle unselection//
gfx_FillRectangle(x, y, width, height);
gfx_SetColor(239);//unselected middle color//
}
gfx_Rectangle(x, y, width, height);
gfx_SetTextScale(1, 1);
gfx_PrintStringXY(text, x + 10, y + 8);
}
int main(void) {
gfx_Begin();
gfx_SetDrawBuffer();
int selected = 0;
int numOptions = 3;
//uint8_t prevKeys = 0;
drawBackground();
drawSprite();
drawTitle();
/*gfx_SetTransparentColor(whatever index your color white is);
gfx_TransparentSprite(sprite, x, y);*/
const char *options[] = {"PLAY GAME", "STORE", "INFO"};
for (int i = 0; i < numOptions; i++) {
int y = 130 + (i * 35);
drawMenuButton(70, y, 180, 28, options[i], (i == selected));
}
gfx_SetTextScale(1, 1);
gfx_SetColor(206);
gfx_PrintStringXY("UP/DOWN | ZOOM exit", 100, 230);
;
gfx_SwapDraw();
/*kb_Scan();
uint8_t currKeys = kb_Data[6];
if ((currKeys & kb_Up) && !(prevKeys & kb_Up)) {
selected--;
if (selected < 0) selected = numOptions -1;
}
if ((currKeys & kb_Down) && !(prevKeys & kb_Down)) {
selected++;
if (selected >= numOptions) selected = 0;
}
if ((currKeys & kb_Clear) && !(prevKeys & kb_Clear)) {
gfx_End();
return 0 ;
}*/
while (1) {
kb_Scan();
if (kb_Data[1] & kb_2nd) {
info();
while(!os_GetCSC()){};
gfx_End();
return 0;
}
if (kb_Data[3] & kb_1) {
game();
while(!os_GetCSC()){};
main();
}
if (kb_Data[4] & kb_2) {
shop();
while(!os_GetCSC()){};
main();
}
if (kb_Data[5] & kb_3) {
info();
while(!os_GetCSC()){};
main();
}
/* Waits for a key
while(!os_GetCSC()){};
gfx_End();
info();
while(!os_GetCSC()){};
shop();
while(!os_GetCSC()){};
End graphics drawing*
gfx_End();
return 0 ;*/
}
}
New pic.