CodeWalrus

Development => Calculators => Calc Projects, Programming & Tutorials => Topic started by: Unicorn on May 06, 2016, 07:33:30 PM

Title: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Unicorn on May 06, 2016, 07:33:30 PM
For the past week or so, I've been working on porting this (https://play.google.com/store/apps/details?id=com.nopowerup.arrowswipe&hl=en) game to the CE. I've finished it, more or less.

There is only one mode, the main one, and and there is no color mode. It does have a Highscore System, though!
The other gameplay and color modes are planned, and should come out soon :)

Screenshot:
(https://usercontent.irccloud-cdn.com/file/DE4V95h1/SwipeCE.gif)



//--------------------------------------
// Program Name:
// Author:
// License:
// Description:
//--------------------------------------

/* Keep these headers */
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <tice.h>

/* Standard headers - it's recommended to leave them included */
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <graphc.h>
#include <keypadc.h>
#include <debug.h>
#include <fileioc.h>
#include "gfx/sprites.h"
/* Other available headers */
// stdarg.h, setjmp.h, assert.h, ctype.h, float.h, iso646.h, limits.h, errno.h, debug.h

/* Put your function prototypes here */
void spritePal();
void inGame();
void menu();
void loadHS();
void setHS();
/* Put all your globals here. */
int key, key1, keyPress, swipe, rightSwipe, score = 0, color = 255, timer, timerStart, press;
ti_var_t file;
uint8_t highscore;
bool correct, keyTouched;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void main(void) {
loadHS();
menu();
gc_FillScrn(255);
gc_CloseGraph();
pgrm_CleanUp();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setHS(void) {
if (score >= highscore) {
highscore = score;
    /* Close all open file handles before we try any funny business */
    ti_CloseAll();
     
    /* Open a file for writting*/
    file = ti_Open("swipehigh", "w");
     
    /* write some things to the file */
    if (file)
         ti_Write(&highscore, sizeof(highscore), 1, file); 
}
}
void loadHS(void) {
ti_CloseAll();
file = ti_Open("swipehigh", "r");
if (file) {
ti_Read(&highscore, sizeof(highscore), 1, file);
    }   
    else {
    highscore = 0;
    }

}
void menu(void) {
setHS();
gc_InitGraph();
gc_FillScrn(255);
gc_InitGraph();
gc_SetTextColor(0 | (255 << 8));
gc_PrintStringXY("Swipe Arrow", 120, 1);
gc_SetTextColor(192 | (255 << 8));
gc_PrintStringXY("2nd to start", 118, 10);
gc_PrintStringXY("Clear to exit", 117, 20);
gc_PrintStringXY("Highscore:", 117, 50);
gc_SetTextXY(195, 50);
gc_PrintInt(highscore, 3);
gc_SetPalette(sprites_pal, sizeof(sprites_pal));
gc_NoClipDrawTransparentSprite(uparrow,120, 100, 75, 75);
srand(rtc_Time());
score = 0;
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
if (keyPress % 15 == 0) {
if (key1 & kb_2nd)
inGame();
}
keyPress++;
key = kb_ScanGroup(kb_group_7); //Arrow Keys
    key1 = kb_ScanGroup(kb_group_1);  //2nd
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void inGame(void) {
gc_InitGraph();
gc_FillScrn(255);
gc_SetColorIndex(23);
rightSwipe = gc_RandInt(1,8);
timerStart = 30;
timer = timerStart;
while (kb_ScanGroup(kb_group_6) != kb_Clear) {
if (keyPress % 15 == 0) {
timer--;
if (key & kb_Up) {
swipe = 1;
keyTouched = true;
press++;
}
if (key & kb_Down) {
swipe = 2;
keyTouched = true;
press++;
}
if (key & kb_Right) {
swipe = 3;
keyTouched = true;
press++;
}
if (key & kb_Left) {
swipe = 4;
keyTouched = true;
press++;
}
if (key & kb_Up && rightSwipe >= 5) {
swipe = 5;
keyTouched = true;
press++;
}
if (key & kb_Down && rightSwipe >= 5) {
swipe = 6;
keyTouched = true;
press++;
}
if (key & kb_Right && rightSwipe >= 5) {
swipe = 7;
keyTouched = true;
press++;
}
if (key & kb_Left && rightSwipe >= 5) {
swipe = 8;
keyTouched = true;
press++;
}
if (rightSwipe == swipe && keyTouched == true) {
correct = true;
keyTouched = false;
timer = timerStart;
}
if (rightSwipe != swipe && keyTouched == true || timer <= 0) {
keyTouched = false;
gc_InitGraph();
gc_FillScrn(255);
gc_PrintStringXY("You Lost",120,5);
while (kb_ScanGroup(kb_group_1) != kb_2nd) {
}
menu();
}
if (correct == true) {
rightSwipe = gc_RandInt(1,8);
gc_InitGraph();
gc_SetColorIndex(color);
gc_NoClipRectangle(120,80,75,75);
score++;
correct = false;
}
}
if (rightSwipe == 1) {
spritePal();
gc_NoClipDrawTransparentSprite(uparrow,120, 80, 75, 75);
}
if (rightSwipe == 2) {
spritePal();
gc_NoClipDrawTransparentSprite(downarrow,120, 80, 75, 75);
}
if (rightSwipe == 3) {
spritePal();
gc_NoClipDrawTransparentSprite(rightarrow,120, 80, 75, 75);
}
if (rightSwipe == 4) {
spritePal();
gc_NoClipDrawTransparentSprite(leftarrow,120, 80, 75, 75);
}
if (rightSwipe == 6) {
spritePal();
gc_NoClipDrawTransparentSprite(uparrowWrong,120, 80, 75, 75);
}
if (rightSwipe == 5) {
spritePal();
gc_NoClipDrawTransparentSprite(downarrowWrong,120, 80, 75, 75);
}
if (rightSwipe == 8) {
spritePal();
gc_NoClipDrawTransparentSprite(rightarrowWrong,120, 80, 75, 75);
}
if (rightSwipe == 7) {
spritePal();
gc_NoClipDrawTransparentSprite(leftarrowWrong,120, 80, 75, 75);
}
if (press == 10 && timerStart > 7) {
timerStart = timerStart - 5;
press = 0;
}

gc_SetColorIndex(255);
gc_NoClipRectangle(1,1,16,16);
gc_SetTextXY(1,1);
gc_PrintInt(score, 3);
keyPress++;
key = kb_ScanGroup(kb_group_7); //Arrow Keys
    key1 = kb_ScanGroup(kb_group_1);  //2nd
}
menu();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void spritePal(void) {
gc_SetPalette(sprites_pal, sizeof(sprites_pal));
}
/* Put other functions here */
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Dream of Omnimaga on May 06, 2016, 09:33:20 PM
Nice, I never played that gaame before so I need to check how to play before giving feedback, but it seems like a cool idea :3=
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Unicorn on May 07, 2016, 04:50:11 AM
Quote from: DJ Omnimaga on May 06, 2016, 09:33:20 PM
Nice, I never played that gaame before so I need to check how to play before giving feedback, but it seems like a cool idea :3=
Thanks!

I just updated it, I completed the timer and tweaked it, now I need to figure out how to use palettes to change colors...
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Dream of Omnimaga on May 07, 2016, 05:01:57 AM
By the way, I didn't have time to try it yet but is there a time limit to press each arrow? Also how would color-based gameplay work?
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Unicorn on May 07, 2016, 05:54:44 AM
Yup, there is a time limit, which decreases ever 10 points, and color based would just change the colors ever 20 points ;)
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Dream of Omnimaga on May 09, 2016, 09:27:11 PM
I was more curious about what colors actually do in the game. :P
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Unicorn on May 09, 2016, 09:58:37 PM
Update: Added color, I'm working on color changing and other modes.
(https://usercontent.irccloud-cdn.com/file/VCANB5Nv/SwipeCEColor.gif)

Download in the OP
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Dream of Omnimaga on May 09, 2016, 11:13:16 PM
Cool, I'll give it a try soon :)
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: alexgt on May 10, 2016, 02:16:22 AM
Looks nice Unicorn ;)
Title: Re: SwipeCE - A Swipe Arrows Port for the TI 84+ CE
Post by: Dudeman313 on May 12, 2016, 05:19:49 PM
That's cool. :)