• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

nichos

Members
  • Content count

    7
  • Joined

  • Last visited

Community Reputation

134 Neutral

About nichos

  • Rank
    Newbie
  1. #include <stdio.h> #include <stdlib.h> #include "list.h" /* * List implementation */ typedef struct listnode listnode_t; struct listnode { listnode_t *next; void *item; }; struct list { listnode_t *head; int numitems; }; // Create new list list_t *list_create(void) { // Implement me list_t *listHead = (list_t*)malloc(sizeof(list_t)); listHead->head = NULL; listHead->numitems = 0; return listHead; } // Free list. items not freed. void list_destroy(list_t *list) { // Implement me free(list); } // Insert item first in list int list_addfirst(list_t *list, void *item) { // Implement me listnode_t *node = (listnode_t *)malloc(sizeof(listnode_t)); node->item = item; //Set the next element to be the first element node->next = list->head; list->head = node; list->numitems++; return 0; } // Insert item last in list. int list_addlast(list_t *list, void *item) { // Implement me list->numitems++; return 0; } // Remove item from list void list_remove(list_t *list, void *item) { // Implement me free(item); list->numitems--; } // Return # of items in list int list_size(list_t *list) { // Implement me printf("Number of items in list: %d\n",list->numitems); return 0; } /* * Iterator implementation */ struct list_iterator { listnode_t *next; list_t *list; }; // Create new list iterator list_iterator_t *list_createiterator(list_t *list) { // Implement me list_iterator_t *iterator = (list_iterator_t*)malloc(sizeof(list_iterator_t)); //point the iterator to the first element iterator->next = list->head; return iterator; } // Free iterator void list_destroyiterator(list_iterator_t *iter) { // Implement me free(iter); } // Move iterator to next item in list and return current. void *list_next(list_iterator_t *iter) { // Implement me if(iter->next == NULL){ //end of list printf("Reached end of the list"); } else{ printf("Going through the list"); iter = iter->next; } } // Let iterator point to first item in list again void list_resetiterator(list_iterator_t *iter) { // Implement me iter->next = iter->list->head; } Thanks for all your help so far! I'm having some issue with resetiterator and list_next. When I call resetiterator i get a segment fault and list_next it never moves to the next object in the list.Do you see what i'm doing wrong here?
  2. I see! Thanks. Linked lists are entirely new to us so I'm having a little bit of struggle with that. This is the list.c that was included.    typedef struct listnode listnode_t; struct listnode { listnode_t *next; void *item; }; struct list { listnode_t *head; int numitems; }; // Create new list list_t *list_create(void) { // Implement me list_t *myHead; myHead->next = NULL; <- this is as far as i have gotten with the lists } // Free list. items not freed. void list_destroy(list_t *list) { // Implement me } // Insert item first in list int list_addfirst(list_t *list, void *item) { // Implement me } // Insert item last in list. int list_addlast(list_t *list, void *item) { // Implement me } // Remove item from list void list_remove(list_t *list, void *item) { // Implement me } // Return # of items in list int list_size(list_t *list) { // Implement me } /* * Iterator implementation */ struct list_iterator { listnode_t *next; list_t *list; }; // Create new list iterator list_iterator_t *list_createiterator(list_t *list) { // Implement me } // Free iterator void list_destroyiterator(list_iterator_t *iter) { // Implement me } // Move iterator to next item in list and return current. void *list_next(list_iterator_t *iter) { // Implement me } // Let iterator point to first item in list again void list_resetiterator(list_iterator_t *iter) { // Implement me } So, what I do know about lists, is that the head should contain a pointer to the first node? Further, all nodes should contain pointers to the next node? I do have a book on linked lists, but it only has 1 list and not one type for the iterator and one for the node. Any tips perhaps?   Also, in the loop i posted in the first post, does this seem about right? list_t *myList = list_create(); int i; for(i = 0; i < SPHERE_NUMTRIANGLES; i++){ object = CreateObject(screen,&sphere_model[i],SPHERE_NUMTRIANGLES); //save each object into the list list_addfirst(myList,object); } and in the list.c list_t *list_create(void){ list_t *myList = (list_t *) malloc(sizeof(list_t)); mylist->head = NULL; numitems -> not sure about this one. }
  3. Hello! So I've got this assignement from my school to create a Bouncing Ball animation using SDL.   I have been provided a header file which contains an array of all the triangles that make up the ball.  Also I have been provided some empty methods that needs implementation.   Each ball must be represented as a separate object data structure (see "object.h" in the zip file). The object data structure contains all variables pertinent to rendering the object on the screen (translation, scale, model coordinates, etc.). Note that the object data structure uses floats to represent translation coordinates. This is to make it easier to handle very small movements (at points, a ball might be moving at a speed less than a pixel). Cast the translation coordinates into integers before drawing the triangles on the screen.   Your code must keep track of objects (balls) by placing the object data structures in a linked list. You need to create your own linked list implementation. Below is a brief description of the object programming interface:   CreateObject - Create a new object. The function accepts as input parameters a pointer to the SDL screen, a pointer to a model triangle array, and a variable telling the size of the model triangle array. The function returns a pointer to a new object data structure. The model triangle array specified as input parameter should not be shared across objects. (Not sharing the model triangle array allows e.g. objects to have different colors.) Perform the necessary memory allocation and copying.   DestroyObject - Free object. The function accepts as input parameters a pointer to an object data structure. The function should free all memory allocated to represent the object (memory allocated for the model triangle array and the object data structure itself).   Drawobject - Draw object on screen. The function accepts as input parameters a pointer to an object data structure. The function must draw the object on the screen by calling DrawTriangle on each of the model triangles. Remember to update scale, translation, etc., in each triangle data structure before invoking DrawTriangle.     This is my assignment. I dont want anyone to post entire code, because I want to learn myself. So far I have 1 single ball on the screen(not moving yet) However I'm having some difficulties with storing the Objects. To make 1 ball i need to iterate with a for loop through the entire triangle array. int i; for(i = 0; i < SPHERE_NUMTRIANGLES; i++){ object = CreateObject(screen,&sphere_model[i],SPHERE_NUMTRIANGLES); DrawObject(object); } This creates 1 ball, but then i need to save my object into a linked list. How do i store my entire object into ONE object? instead of storing each object for each sphere_model[i]? The reason is because i need to create multiple balls to be shown on the screen at once.  object_t *CreateObject(SDL_Surface *screen, triangle_t *model, int numtriangles) { // Implement me object_t *object = malloc(sizeof(object_t)); object->model = malloc(sizeof(triangle_t) * numtriangles); object->screen = screen; object->ttl = 5000; //TODO: ADD RANDOM SPEED object->speedx = 10; object->speedy = 5; object->model = model; object->model->scale = 0.1f; object->model->tx = screen->w/2.f; object->model->ty = 70.0f; return object;
  4. Sorry i mixed up rectangles and triangles. I need to fill triangles and not rectangles.  Yes I have a wireframe of the triangles drawn on screen and want to fill them with color.  I changed my code around a little bit by something i found online and altered it to match my code. int x = 0, y = 0; int minx = minimum(triangle->sx1,triangle->sx2,triangle->sx3); int maxx = maximum(triangle->sx1,triangle->sx2,triangle->sx3); int miny = minimum(triangle->sy1,triangle->sy2,triangle->sy3); int maxy = maximum(triangle->sy1,triangle->sy2,triangle->sy3); for(y = miny;y < maxy; y++){ for(x = minx; x < maxx; x++){ if((triangle->sx1 - triangle->sx2) * (y - triangle->sy1) - (triangle->sy1 - triangle->sy2) * (x - triangle->sx1) > 0 && (triangle->sx2 - triangle->sx3) * (y - triangle->sy2) - (triangle->sy2 - triangle->sy3) * (x - triangle->sx2) > 0 && (triangle->sx3 - triangle->sx1) * (y - triangle->sy3) - (triangle->sy3 - triangle->sy1) * (x - triangle->sx3) > 0) { SetPixel(screen,x,y,triangle->fillcolor); } } } However this does not fill ALL the triangles, there are some glitches. 
  5. Hello!   So I've gotten this assignement to combine an array of trianglesinto a image of a teapot.  I also have to translate, scale, calculate bounding box of the triangle and fill it with a color.   I have gotten so far that the translation of the coords and scale is ok. The teapot is being drawn but im getting some difficulty while calculating the bounding boxes and also filling the triangle with a color. The program window is made with SDL.   The filling of the triangles.  The triangles are a struct, and a total of 1092 are drawn on the screen, each with its specific color. Now im getting to understand that i need to travers the pixels on the screen, and then looking for their wireframe color which has a rgb value of 187.    What i have done is  SDL_Color color; Uint32 pixel = 0; int x = 0, y = 0; pixel = GetPixel(screen,x,y); SDL_GetRGB(pixel,screen->format,&color.r,&color.g,&color.b); I have made a for loop which traverses the entire screen in x and y and looking for pixels with the wireframe color, but im doing something wrong since my program just freezes. Think its running out of memory. I must be doing something wrong in my for loop.    What I think i need to do: for(x = 0; x < screen->w; x++){ if(color.r == 187){ // if i find a pixel with the wireframe color while(color.r == 187){ //do this until i get 1 pixel after the red, so im inside the //triangle. x++; // increase x coord. pixel = GetPixel(screen,x,y); SDL_GetRGB(pixel,screen->format,&color.r,&color.g,&color.b);//get color from new pixel } SetPixel(screen,x,y,triangle->fillcolor); if(x == screen->w){ x = 0; y++; } } } Im seeing that this is a infinite loop though. Still it doestn color anything properly.    Any help would be appreciated : ) ps. Its C.
  6. Fixed it, thanks man! : D On to something completley different. My character has a white area around it which is overlapping the background. Im not really sure how to colorkey it so that the white color goes away.
  7. Hey there. So I've started to learn c++ with SDL, and so far i have managed to make the program add the floor on which the hero is supposed to run on. This is a 2d game. Just a single picture where the only images to be displayed are a background, the floor, and the hero. My hero can move, however when he moves the program doesnt move the picture, it simply adds the same picture of the hero on the new position. In the loop im calling to myHero::show() which is a method for applying the surface. apply_surface(x,y,player,screen); simple as that. The movement works fine, but it just creates a new picture without removing the old one. Anyone who may help me please? : )