I was trying to program a very basic form of pong in C on my computer, and when I sent it to my calculator, it was a fail. I thought I did everything correct, but it seemed not so.
If any of you sees a bug or something that is missing then please let me know. Thanks!
Here is the code:
Code:
If any of you sees a bug or something that is missing then please let me know. Thanks!
Here is the code:
Code:
/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>
/* Standard headers */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <keypadc.h>
/* Put function prototypes here */
void printText(const char *text, uint8_t x, uint8_t y);
void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos);
/* Put all your code here */
void main(void) {
/* uint8_t is an unsigned integer that can range from 0-255. */
/* It performs faster than just an int, so try to use it (or int8_t) when possible */
uint8_t count;
/* Initialize some strings */
const char *ball = "O";
const char *paddle = "---";
int ballX = 1;
int ballY = 1;
int paddleX = 3;
int lose = 0;
int ballXDir = 1;
int ballYDir = 1;
kb_key_t key;
const char *game = "Game Over!";
/* Clear the homescreen */
os_ClrHome();
while(lose==0){
printText(ball, ballX, ballY);
printText(paddle, paddleX, 9);
if (ballY==9 && !(paddleX==ballX || paddleX+1==ballX || paddleX+2==ballX))
lose = 1;
kb_Scan();
if (kb_ScanGroup(kb_group_6) == kb_Clear)
lose=1;
if (kb_ScanGroup(kb_group_6) == kb_Right)
paddleX+=2;
if (kb_ScanGroup(kb_group_6) == kb_Left)
paddleX-=2;
if (ballX=0)
ballXDir=1;
if (ballX=25)
ballXDir=-1;
if (ballY=0)
ballYDir=1;
if (ballY=9)
ballYDir=-1;
ballX+=ballXDir;
ballY+=ballYDir;
while (!os_GetCSC());
}
printText(game,0,0);
}
/* Draw text on the homescreen at the given X/Y location */
void printText(const char *text, uint8_t xpos, uint8_t ypos) {
os_SetCursorPos(ypos, xpos);
os_PutStrFull(text);
}
/* Draw small text at the given X/Y location */
void printTextSmall(const char *text, uint8_t xpos, uint8_t ypos) {
os_FontSelect(0); // sets small font (1 == big, see docs)
os_FontDrawText(text, xpos, ypos);
}