Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
Hey all!

I was looking into learning some C so I can make more complicated and better looking programs. Only one problem: I have no experience in C. My goal for late June (I get out of school in the first week of June) is to make a game similar to the arrow swipe game on phones, which can be seen here.

Thanks to all who reply!
This is great idea! You may want to look at Unicorn's game which is sort of similar; and see if you can improve it and add more features Smile

https://www.cemetech.net/programs/index.php?mode=file&path=/84pce/asm/games/SwipeCE.zip
Guess I didn't see that program when looking into what I can attempt to make. I definitely know I would not be able to optimize Unicorn's game, so I'll probably look into a game similar to Zig Zag https://play.google.com/store/apps/details?id=com.ketchapp.zigzaggame
MateoConLechuga wrote:
This is great idea! You may want to look at Unicorn's game which is sort of similar; and see if you can improve it and add more features Smile

https://www.cemetech.net/programs/index.php?mode=file&path=/84pce/asm/games/SwipeCE.zip

Haha, that game needs some help Razz

Quote:
Guess I didn't see that program when looking into what I can attempt to make. I definitely know I would not be able to optimize Unicorn's game, so I'll probably look into a game similar to Zig Zag https://play.google.com/store/apps/details?id=com.ketchapp.zigzaggame


I suggest you attempt to optimize this game as some sort of exercise or something Razz I made that quite a while ago, and it needs quite a bit of help. Razz (I need to update it with the source, but yeah, please try to make it better)
So I was looking through the C Header Documentations and I could not find a way of making a sprite move. Ex. If I press left the sprite will move left. Hope you can help Very Happy

Edit: Right now, I have my sprite being re-drawn in a while loop but that does not get rid of the previous sprite
matkeller19 wrote:
So I was looking through the C Header Documentations and I could not find a way of making a sprite move. Ex. If I press left the sprite will move left. Hope you can help Very Happy

Well, the sprite drawing routines just draw a sprite. Movement is handled by the programmer; as in most other languages such as Basic. So, some code to read the keypad and move a sprite (Let's say you have a sprite named 'player_sprite'), would look like this in C:


Code:
    int x = 0;
    int y = 0;

    while(1) {
        kb_Scan();
       
        if (kb_Data[kb_group_7] == kb_Left) {
             x = x + 1;
        }
        gfx_Sprite(player_sprite, x, y);
    };


x and y are variables; which are initially set to 0. Inside of the infinite loop, we scan the keypad, and then check if the data register in the keypad is the left key. If it is; then we can change the x value. After that; we then draw the sprite with gfx_Sprite.

Feel free to ask any questions if you have them! Smile

EDIT:

If you want to get rid of the previous sprite; the easiest way is to just redraw the whole screen. Or alternatively if you have a transparent background, you can look into partial redraw:
https://github.com/CE-Programming/toolchain/wiki/GraphX-Library:-Partial-Redraw
Now, whenever I attempt to build, I keep getting the output message:

WARNING (724) --> Symbol _kb_Scan (obj\main.obj) is not defined.

In my code, I have keypadc included
There's now a wiki page for that Razz

https://github.com/CE-Programming/toolchain/wiki/Linking-Dynamic-C-Libraries
School is finally over so I can actually get to work on this project Very Happy
Now for my question. Whenever I use convpng on my 16x16 sprite, the resulting C file contains the pallet but nothing else. Is there something I am forgetting or not understanding?


Code:
#GroupC            : sphere1
#TranspColor       : 255,255,255,255
#PNGImages         : sphere1



Code:
// Converted using ConvPNG
#include <stdint.h>
#include "sphere1.h"

uint16_t sphere1_pal[88] = {
 0xFFFF,  // 00 :: rgba(255,255,255,255)
 0x2000,  // 01 :: rgba(68,0,0,210)
 0x2C00,  // 02 :: rgba(91,0,0,9)
 0x2800,  // 03 :: rgba(79,0,0,117)
 0x2400,  // 04 :: rgba(72,0,0,228)
 0x2000,  // 05 :: rgba(69,0,0,93)
 0x3400,  // 06 :: rgba(103,0,0,48)
 0x2400,  // 07 :: rgba(70,0,0,39)
 0x2000,  // 08 :: rgba(69,0,0,6)
 0x2400,  // 09 :: rgba(75,0,0,12)
 0x3800,  // 10 :: rgba(117,0,0,21)
 0x2400,  // 11 :: rgba(76,0,0,153)
 0x2800,  // 12 :: rgba(86,0,0,174)
 0x3400,  // 13 :: rgba(110,0,0,234)
 0x2400,  // 14 :: rgba(71,0,0,150)
 0x2C00,  // 15 :: rgba(94,0,0,216)
 0x3C00,  // 16 :: rgba(126,0,0,132)
 0x2800,  // 17 :: rgba(83,0,0,96)
 0xD54A,  // 18 :: rgba(170,84,84,33)
 0x514A,  // 19 :: rgba(167,79,79,84)
 0x4442,  // 20 :: rgba(136,16,16,189)
 0xD108,  // 21 :: rgba(161,67,67,36)
 0x3000,  // 22 :: rgba(95,0,0,180)
 0xC884,  // 23 :: rgba(146,37,37,195)
 0xC000,  // 24 :: rgba(129,3,3,72)
 0x3800,  // 25 :: rgba(116,0,0,27)
 0x4484,  // 26 :: rgba(143,31,31,27)
 0xD109,  // 27 :: rgba(163,70,70,249)
 0x4CE7,  // 28 :: rgba(155,55,55,150)
 0x514A,  // 29 :: rgba(168,80,80,147)
 0x514A,  // 30 :: rgba(167,79,79,243)
 0x5129,  // 31 :: rgba(164,73,73,198)
 0x3400,  // 32 :: rgba(106,0,0,135)
 0x3C00,  // 33 :: rgba(120,0,0,243)
 0x4442,  // 34 :: rgba(136,17,17,240)
 0xC8A6,  // 35 :: rgba(151,46,46,144)
 0xCCE7,  // 36 :: rgba(158,60,60,195)
 0xFC43,  // 37 :: rgba(255,22,22,255)
 0x5000,  // 38 :: rgba(166,0,0,255)
 0x3800,  // 39 :: rgba(112,0,0,255)
 0x2C00,  // 40 :: rgba(93,0,0,255)
 0x3400,  // 41 :: rgba(111,0,0,255)
 0x5800,  // 42 :: rgba(179,0,0,255)
 0x5000,  // 43 :: rgba(162,0,0,255)
 0x3800,  // 44 :: rgba(115,0,0,255)
 0x3C00,  // 45 :: rgba(126,0,0,255)
 0x3800,  // 46 :: rgba(119,0,0,255)
 0x6C21,  // 47 :: rgba(223,7,7,255)
 0x4800,  // 48 :: rgba(144,0,0,255)
 0x5C00,  // 49 :: rgba(187,0,0,255)
 0x6C00,  // 50 :: rgba(225,0,0,255)
 0x5C00,  // 51 :: rgba(191,0,0,255)
 0x4800,  // 52 :: rgba(146,0,0,255)
 0x5400,  // 53 :: rgba(170,0,0,255)
 0x4C00,  // 54 :: rgba(156,0,0,255)
 0x4C00,  // 55 :: rgba(155,0,0,255)
 0x6929,  // 56 :: rgba(214,73,73,255)
 0x7400,  // 57 :: rgba(236,0,0,255)
 0xF108,  // 58 :: rgba(231,67,67,255)
 0x6400,  // 59 :: rgba(209,0,0,255)
 0x7084,  // 60 :: rgba(229,31,31,255)
 0xE8C6,  // 61 :: rgba(210,53,53,255)
 0x7C00,  // 62 :: rgba(251,0,0,255)
 0x5000,  // 63 :: rgba(164,0,0,255)
 0x5800,  // 64 :: rgba(177,0,0,255)
 0x7C21,  // 65 :: rgba(255,10,10,255)
 0x7800,  // 66 :: rgba(245,0,0,255)
 0x6800,  // 67 :: rgba(216,0,0,255)
 0xFC84,  // 68 :: rgba(255,37,37,255)
 0x6800,  // 69 :: rgba(215,0,0,255)
 0xFCE7,  // 70 :: rgba(255,59,59,255)
 0xFCA6,  // 71 :: rgba(255,46,46,255)
 0x7000,  // 72 :: rgba(232,0,0,255)
 0x7CC6,  // 73 :: rgba(255,48,48,255)
 0x7108,  // 74 :: rgba(234,63,63,255)
 0x6400,  // 75 :: rgba(203,0,0,255)
 0x6C00,  // 76 :: rgba(219,0,0,255)
 0x6400,  // 77 :: rgba(202,0,0,255)
 0xFC22,  // 78 :: rgba(255,13,13,255)
 0xFC01,  // 79 :: rgba(255,5,5,255)
 0x7000,  // 80 :: rgba(229,0,0,255)
 0x70C6,  // 81 :: rgba(231,49,49,255)
 0x7800,  // 82 :: rgba(249,0,0,255)
 0x7C84,  // 83 :: rgba(255,31,31,255)
 0x6484,  // 84 :: rgba(202,33,33,255)
 0x5C00,  // 85 :: rgba(188,0,0,255)
 0x5400,  // 86 :: rgba(176,0,0,255)
 0x0000,  // 87 :: rgba(0,0,0,0)
};
You didn't put it on a new line. Please try looking at the examples that came with the toolchain Smile
I was looking into the partial redraw page that you sent me (Here) and was working on understanding what the code was doing. If I understand correctly, the MallocSprite line is creating room for a sprite under the name *name so that it can be used later. My problem is that when I format it for my program:

Code:
gfx_image_t *backball = gfx_MallocSprite(16,16);

I keep on getting the output:

Code:
E:\CALC\CEDEV\ZIGZAG\SRC\MAIN.C (28,18) :       ERROR (108) Identifier "gfx_image_t" is not a variable or enumeration constant name
E:\CALC\CEDEV\ZIGZAG\SRC\MAIN.C (28,28) :       ERROR (128) Identifier "backball" not defined within current scope

I have tried moving around this line and changing it, but this error continues to come up. Hopefully you can point me in how it should really look like Good Idea
That is the correct format Smile You just need to make sure you add #include <graphx.h> to the top of your source file I believe Smile Also in this style of C you need to make sure all of your variables are declared at the top of the block; not inserted within your code; for example:


Code:
// BAD CODE
void func(void) {
    int x = 2;
    x = 3;
    int y = 3;
}

// GOOD CODE
void func(void) {
    int x = 2;
    int y = 3;
    x = 3;
}


If you have any more issues, feel free to post the whole code; that's usually a lot easier to understand Smile
So I've only had a little bit of time to work on this project even though I got out of school a week ago. I got the movement working the way I would like it to, for now, and it actually works in CEmu. However, when I run the same program on my physical CE, it only allows one key input before failing.

Here is the code:

Code:
void main(void) {
    int a = -1;
    int b = 80;
    int c = 0;
    gfx_image_t *backball = gfx_MallocSprite(16,16);

    gfx_Begin(gfx_8bpp);
    gfx_SetColor(gfx_white);
    gfx_GetSprite(backball, 80, 80);
    gfx_TransparentSprite(sphere, 80, 80);

    while (kb_Data[kb_group_6] != kb_Enter) {

        if (kb_Data[kb_group_1] != kb_2nd) {

            kb_Scan();

            if ((kb_Data[kb_group_1] == kb_2nd)) {
                a = -1 * a;
                c++;
            }
        }

        gfx_Sprite(backball, 80, b);

        b = b + a;

        gfx_TransparentSprite(sphere, 80, b);
        gfx_ShiftLeft(1);


Here is the program running on CEmu
And here it is on a physical CE (Gif made on CEmu, shows what really happens on CE)
kb_Scan(); needs to go outside of the if statement; placed somewhere in the main loop Smile

Also: Wink


Code:
a = -a;
By changing it to look like this

Code:
    while (kb_Data[kb_group_6] != kb_Enter) {

        kb_Scan();

        if (kb_Data[kb_group_1] == kb_2nd) {
            a = -a;
            c++;
        }

It does partially accomplish what I wanted it to do, but not fully. My goal was to make it so each time 2nd is pressed, the ball will change directions. The problem is that it will often read a press as two presses once it loops back around and not change directions.

Edit: The numbers in the top left of this show how many times it has been scanned
That's because the keypad data is always on when held; and off when not held. A simple solution to detect a rising edge would be like this:


Code:
key = kb_Data[kb_group_1] == kb_2nd;

if (key && !prevkey) {
    a = -a;
    c++;
}
prevkey = key;


key and prevkey are both type 'bool'. Smile
So I decided I was happy with the movement system and began to work on the randomly generated path. I'm using d = randInt(0,1) to determine whether or not the path should go up or down. This line is working perfectly fine when alone, but when I add
Code:
        if (d = 1) {
            e++;
        }

        if (d = 0) {
            e = e-1;
        }

the randInt for d is ALWAYS 1. I'm just wondering what I can do to fix this error Very Happy
You used = rather than == Smile Also keep in mind there is such a thing as 'else', and 'e--' Wink


Code:
        if (!d) {
            e--;
        } else {
            e++;
        }


Or even shorter: Razz


Code:
e += d ? 1 : -1;
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement