Archive

Posts Tagged ‘c’

Abyss2D Graphics …quick preview.

May 27th, 2010 Rashaud Teague 1 comment

Maris Labs has been working on a graphics engine/framework/library called “Abyss2D”. Abyss2D sits on top of the Simple DirectMedia Layer and it is geared towards small graphic computing trying its best to leave a small footprint on the device it is running on. Abyss2D is being built with C++, with more C style coding in terms of memory management and file i/o… just personal preference.

Right now Abyss2D is in super beta/alpha I should not even be showing you screen shots below of what I’ve done with it in a test space shooter game that uses the basic features of Abyss2D. First I will state some of the features!

  • Interfacing with SDL made easy!
  • Sprite module, to easily blit images to the screen.
  • Sound module, queuing/playing sound affects and music with ease.
  • Portability between Linux (Ubuntu), Windows and Mac OS but sorry Linux first.
  • Safe memory management, you can load objects into the program and we’ll take care of destroying them when no longer needing them.
  • Font module for rendering text to the screen.
  • Animation, create cool animations of an object on the screen.
  • Networking TCP/IP.
  • Frame rate regulation.
  • Much more …

Now here are the screen shots of “Abyss – Spacewars”, a game I created to test some of the features listed above.

Hero [Red colored] Ship fighting their way through “Badies”:

Hero [Red colored] Ship fighting their way through

Game Over:

Game Over

I will try to get more done before the summer ends!

-Rashaud

Converting integers to strings in C

February 13th, 2010 Rashaud Teague No comments

I found a simple way to convert integers into strings the safe and easy way. I used the power of the C Standard Library to help me out (calloc, malloc, memcpy, sprintf).

Here is the source:

/********************************************************************
 * Name: inttostr.c
 * Author: Rashaud Teague
 * Date: 02/13/2010
 * License: GNU LGPL <http://www.gnu.org/licenses/>
 * Description: <description>
 ********************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char * itoa(int i) {
    /* declare/initialize a place holder text */
    char *text = (char *) calloc(256, sizeof(char));
    if (text == NULL) return NULL;
   
    /* declare a return text */
    void *rtext;
   
    /* use sprintf to format the integer into a string */
    sprintf(text, "%d", i);
   
    /*
     * allocate the correct size for the return text (rtext)
     * then copy the block of memory from text to rtext
     * and free text
     */

    if ((rtext = malloc(strlen(text))) == NULL) return NULL;
    memcpy(rtext, (void *)text, strlen(text));
    free(text);
   
    return (char *)rtext;
}

int main(void) {
   
    char *str = itoa(2010);
   
    printf("My string integer: %s\n", str);
   
    return 0;
}

Have fun,
Rashaud

Categories: C/C++ Tags: ,