The thing is I want it to be randomly generated. Im guessing that I should just add the tileset to the project. I also wanna know if I should add every sprite separately or I should add the whole tilemap.
If you're going to procedurally generate the maps, I'm not sure where the question comes from--add the tileset, you won't have a map to add anyway. If you're using the tilemap as a tilemap, best to add it as a tilemap. Tilemaps are ultimately a collection of sprites anyway.
Can I add the tilemap and then seperate each sprite?
The tilemap is an array of sprites, so you can index into that array to access individual tiles as sprites, if needed.
Does that mean I should add the tilemap, or a .png format pic of the tilemap?
I'm not sure what you mean by "add the tilemap" other than adding it as a png. Check out how the Tilemap example does it in the toolchain. You'll have a png of your tiles, and an entry in your convimg file that defines the tilemap. Then when it's built you will have a tilemap you can reference in your code.
Project Builder has a converter yaml, so I can use that.
I want to know if this is correct.

AND.

Here is the newest code. First is the convimg.yaml and then the main code.

Code:
palettes:
  - name: global_palette
    fixed-entries:
      - color: {index: 0, r: 255, g: 255, b: 255}
      - color: {index: 1, r: 255, g: 216, b: 0}
    images: automatic

converts:
  - name: tileset
    palette: global_palette
    tilesets:
      tile-width: 16
      tile-height: 16
      images:
        - subwaysurf.png

outputs:
  - type: c
    include-file: gfx.h
    palettes:
      - global_palette
    converts:
      - tileset

Now for the main.

Code:
#include <tice.h>
#include <graphx.h>
#include <keypadc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gfx/gfx.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240

void drawBackground(void) {
    gfx_SetColor(0);
    gfx_FillScreen(0);

    // Bright neon sky gradient
    for (int y = 0; y < 100; y++) {
        int color = 128 + (y / 12);
        gfx_SetColor(color);
        gfx_HorizLine(0, y, SCREEN_WIDTH);
    }

    // Dark ground
    gfx_SetColor(16);
    gfx_FillRectangle(0, 100, SCREEN_WIDTH, 140);
}

void drawTrain(void) {
    // ===== MAIN BODY (TALL & NARROW) =====
    gfx_SetColor(200);
    gfx_FillRectangle(110, 100, 100, 85);
    gfx_SetColor(255);
    gfx_Rectangle(110, 100, 100, 85);

    // Dark stripe at top
    gfx_SetColor(51);
    gfx_FillRectangle(115, 100, 90, 10);

    // ===== ROOF DETAIL =====
    gfx_SetColor(180);
    gfx_FillRectangle(110, 98, 100, 2);

    // ===== THREE LARGE WINDOWS (STACKED VERTICALLY) =====
    // Top window
    gfx_SetColor(16);
    gfx_FillRectangle(120, 112, 80, 12);
    gfx_SetColor(180);
    gfx_FillRectangle(125, 115, 70, 8);

    // Middle window
    gfx_SetColor(16);
    gfx_FillRectangle(120, 128, 80, 12);
    gfx_SetColor(180);
    gfx_FillRectangle(125, 131, 70, 8);

    // Bottom window
    gfx_SetColor(16);
    gfx_FillRectangle(120, 144, 80, 12);
    gfx_SetColor(180);
    gfx_FillRectangle(125, 147, 70, 8);

    // ===== HEADLIGHTS =====
    gfx_SetColor(226);
    gfx_FillCircle(115, 108, 5);
    gfx_FillCircle(205, 108, 5);
    gfx_SetColor(255);
    gfx_FillCircle(115, 108, 2);
    gfx_FillCircle(205, 108, 2);
}

void drawTitle(void) {
    gfx_SetTextScale(3, 3);
    gfx_SetColor(206);
    gfx_PrintStringXY("SUBWAY", 90, 15);
    gfx_SetColor(141);
    gfx_PrintStringXY("SURFERS", 85, 35);

    gfx_SetTextScale(1, 1);
    gfx_SetColor(226);
    gfx_PrintStringXY(">> CE <<", 135, 55);
}

void drawMenuButton(int x, int y, int width, int height, const char *text, int selected) {
    if (selected) {
        // Selected: bright neon colors
        gfx_SetColor(206);
        gfx_FillRectangle(x - 3, y - 3, width + 6, height + 6);
        gfx_SetColor(141);
        gfx_FillRectangle(x, y, width, height);
        gfx_SetColor(255);
    } else {
        // Unselected: darker colors
        gfx_SetColor(16);
        gfx_FillRectangle(x, y, width, height);
        gfx_SetColor(200);
    }

    gfx_Rectangle(x, y, width, height);

    gfx_SetTextScale(1, 1);
    gfx_PrintStringXY(text, x + 10, y + 8);
}

void drawMenuBackground(void) {
    // Semi-transparent dark overlay - lighter so train shows through
    gfx_SetColor(40);
    for (int i = 0; i < 3; i++) {
        gfx_FillRectangle(0, 130 + (i * 35), SCREEN_WIDTH, 28);
    }
}

int main(void) {
    gfx_Begin();
    gfx_SetDrawBuffer();

    int selected = 0;
    int numOptions = 3;
    //uint8_t prevKeys = 0;//

    while (1) {
        drawBackground();
        drawTrain();
        drawTitle();
        drawMenuBackground();

        const char *options[] = {"PLAY GAME", "SETTINGS", "EXIT"};

        for (int i = 0; i < numOptions; i++) {
            int y = 140 + (i * 35);
            drawMenuButton(70, y, 180, 28, options[i], (i == selected));
        }

        gfx_SetTextScale(1, 1);
        gfx_SetColor(206);
        gfx_PrintStringXY("UP/DOWN | CLEAR exit", 100, 235);

        gfx_SwapDraw();

        kb_Scan();
        if(kb_IsDown(kb_KeyUp)) {

        if (kb_IsDown(kb_KeyUp)) while(kb_AnyKey())
            if (selected < 0) selected = numOptions - 1;
        }

        if(kb_IsDown(kb_KeyUp)) {
            selected++;
            if (selected >= numOptions) selected = 0;
        }

        if (kb_IsDown(kb_Clear)) while(kb_AnyKey()) {
            break;
        }

        while(kb_AnyKey());
    }

    gfx_End();
    return 0;
}

You can also find a link to the project here.
You need a ti planet account to enter that link.
Can someone tell me what I should do next? I also need to fix the clear button. I need that to exit the program, can someone show me how to do it? One more thing that's not so relevant but since people in SAX were wondering which websites to use when it comes to image sharing on a school computer; Here is a website that works for most people Image2url
EDIT: How do I convert to different pics into convimg.yaml and also convert them to two different types of format.
Why is this happening. Look at the convimg.yaml I uploaded another pic and it just goes all white.

And here is the pic I am trying to upload
That picture looks much too high resolution for the CE, what is it being used for?
Background of the homescreen. Do you think it's doable?
I guess that if it works, it works. Make sure, as 320*240 is the resolution of the CE, maybe try scaling the image to something like 300*200 and see if that helps, maybe the entire screen isn't fully usable (this is the case on monochrome calcs with TI-Basic).
calcgeek wrote:
Background of the homescreen. Do you think it's doable?

What is the resolution of the image (width and height)? It usually has to stay equal to or above 320x240 pixels on the CE, if any of those values are higher than that limit, then you have to stretch or shrink the image to make it fit.
Thanks. I just got it to work. The pixels is 320x240 so it's all good.
EDIT: The reason it wasnt porting was because I was using a weird pallette. I figured that out and now it works.
EDIT 2: What should I convert the pic to in convimg.yaml, what are my options?
I have now added the pic as the background.
Or I thought I did. Please help. How do I get that pic to be the background?
Graphx only supports pictures up to 255x255. If you want a full screen 320x240 picture then you'll need to split the picture in half. This means you end up with two 160x240 pictures. From there you can use gfx_sprite() to display each picture normally. You can follow the C Libraries example on how to display a sprite.

A more advanced option that would save a lot of space would be to reduce your picture's resolution from 320x240 to 160x120. Then you can use the function gfx_scaledsprite_noclip to double the picture's size which will make it 320x240: https://ce-programming.github.io/toolchain/libraries/graphx.html?highlight=scaledsprite_#_CPPv423gfx_ScaledSprite_NoClipPK12gfx_sprite_t8uint24_t7uint8_t7uint8_t7uint8_t

You see that horrible looking train in the back, so I want to replace it with that subway surfers pic as the background.
Can someone also help me with convimg.yaml?

Thank you Adriweb for slaving away. We finally got everything to work so now I can continue.
I am now working on adding the background and the menu selections.
One technique I've tested is using a image that is 160x240, such that the original image is squashed horizontally but is full-resolution vertically, since it makes best use of the 255x255 size limit with integer scaling. I was able to render out a scene in Blender at half-width to produce this. Then in code, you'd have to scale it 2x horizontally. The results were decently nice, though the non-square pixels were slightly distracting. However, for something like this, a 160x120 image background is plenty good.
  
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 4 of 5
» All times are UTC - 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