Courses/CS 491ab/Winter 2008/Hong Ngo

From CSWiki

Jump to: navigation, search

User:Hong Ngo

Contents

[edit] Week 1 - January 4, 2008

[edit] Week 2 - January 11, 2008

SDL (Simple DirectMedia Layer) www.libsdl.org

Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access 
to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer.

It supports Windows, Mac OS, Linux, and many other operating systems.

It is written in C/C++, but there are bindings for other languages such as Java, C#, Perl, and many others.

[edit] Week 3 - January 18, 2008

[edit] Week 4 - January 25, 2008

I am working with SDL to create a simple 2D platform game. So far, I have written classes for sprites, animated sprites, collision detection, and a timer. Nothing significant has been done. Currently the user can move a multi-colored circle left and right, and jump up and down. There is collision detection (very simple using collision boxes), but collision in the x-direction doesn't seem to work for the moment. I will have to rework the collision detection code.

Image:collisionbug.jpg

[edit] Week 5 - February 1, 2008

I won't be able to attend class this week.

Project update:

I have fix the collision problem. There is nothing wrong with the collision detection code itself, but that the collision have to be handled in two steps. First, we have to check for collision in the x-direction. If the object is moved left or right and collided with another object, then we moved the object back, right at the point where they touch but not overlap. Second, we handle collision in the y-direction (because gravity moves the object downward). It doesn't matter what order we do the steps in.

I updated the animated sprite to run at the frame rate of the game instead of it running as fast as possible. If the sprite consist of 10 frames and the game runs at 60fps, then sprite won't update to the next frame until 1/6th of a second has past.

I am currently writing code to load map data from a file. The map file will contain information for what objects to create and their location in the game world.

[edit] Week 6 - February 8, 2008

[edit] Week 7 - February 15, 2008

I have been working on the design of my game as a whole instead of writing code as it comes to my head (as I should have done from the start). I've decided to separate things into modules with each doing a specific purpose.

I have an object manager module to create, destroy, store, and retrieve objects.

Objects now don't have images, nor functions to work with images. They only have references to the image and where to draw on screen.

I have a graphics module to manage images. Given information from objects, it will handle the functions of drawing to the screen.

The collision detection module not only detects collisions, but also handles what is done to the objects.


As for the multi-player aspect of my game, I have been reading material on it from the website gamedev.net. It has a lot of tutorials and resources on not only network programming but all areas related to game programming.

I briefly looked into the Second Life game and only the client is open source. There is a lot of code and I'm still looking through it along with the documentation (which is incomplete).

[edit] Week 8 - February 22, 2008

[edit] Week 9 - February 29, 2008

[edit] Week 10 - March 7, 2008

[edit] Final Report

[edit] Brief project description

A 2D multiplayer platform game where players compete with each other to get hold of an item while navigating the map and jumping from platform to platform to reach an exit. Whoever has the item will be able to exit and win the match.

[edit] Anticipated users

Anyone who likes to play muliplayer games that are simply to play.

[edit] Main conceptual (i.e., user-level) objects

There will be characters that users can choose; items that can be obtained for power-ups and special abilities.

[edit] Primary conceptual (i.e., user-level) operations

The game will allow the user to connect to a server and join the game. It will also let the user to setup a server for others to play. Players will use the keyboard to control their character.

[edit] Why I am interested in this project

I like to play video games and I wanted to see if I can create my own game.

[edit] Status

I've implemented some classes and functions for objects that are in my game using the SDL library. The objects are those of the player character; background objects (ground, walls, platforms, etc); interactive objects (rocks for throwing, item allowing to jumping twice a high).

Networking aspects of the game are in the very early stages. I've been reading articles about TCP, UDP, and packets and their use in video games.

[edit] Status Updates

I played around with sockets and will use it for the networking part of my project. Creating sockets and communicating with is very easy. Here is a simple demo of a server and client. The server listens on a port while the client tries to connect to it. When the client connects, the server sends a "Hello world" message, the client receives the message and prints it out. This is done on localhost (127.0.0.1), but can be change to work with any ip address and port.

Server code:

#include <iostream>
#include "winsock.h"

using namespace std;

int main()
{

    // Must be done at the beginning of every WinSock program
    WSADATA w;    // used to store information about WinSock version
    int error = WSAStartup (0x0202, &w);   // Fill in w

    if (error)
    { // there was an error
        return 1;
    }
    if (w.wVersion != 0x0202)
    { // wrong WinSock version!
        WSACleanup (); // unload ws2_32.dll
        return 1;
    }

    SOCKET sockfd = socket(PF_INET, SOCK_STREAM, 0);
    sockaddr_in my_addr; //address structure for a TCP socket
    sockaddr_in their_addr;
    int sin_size;

    my_addr.sin_family = AF_INET;         // host byte order
    my_addr.sin_port = htons(9877);     // short, network byte order
    my_addr.sin_addr.s_addr = htonl(INADDR_ANY);

    if (bind(sockfd, (sockaddr *)&my_addr, sizeof my_addr) == SOCKET_ERROR)
    { // error
        cout<<"bind error\n";
        int e = WSAGetLastError();
        cout<<"error code: "<<e<<endl;
        WSACleanup();  // unload WinSock
        return 0;         // quit
    }

    SOCKET client;
    sin_size = sizeof their_addr;
    int len, bytes_sent, bytes_recv;
    char buf[80];
    char * msg = "Hello world";

    if (listen(sockfd,5)==SOCKET_ERROR)
    { // error!  unable to listen
        cout<<"listen error\n";
        WSACleanup ();
        return 0;
    }

    client = accept(sockfd, (sockaddr *)&their_addr, &sin_size);
    bytes_sent = send(client, msg, strlen(msg), 0);

    closesocket(client);
    closesocket(sockfd);

    return 0;
}

Client code:

#include <iostream>
#include "winsock.h"

using namespace std;

int main()
{
    // Must be done at the beginning of every WinSock program
    WSADATA w;    // used to store information about WinSock version
    int error = WSAStartup (0x0202, &w);   // Fill in w

    if (error)
    { // there was an error
        return 1;
    }
    if (w.wVersion != 0x0202)
    { // wrong WinSock version!
        WSACleanup (); // unload ws2_32.dll
        return 1;
    }

    int sockfd;
    struct sockaddr_in dest_addr;   // will hold the destination addr

    sockfd = socket(PF_INET, SOCK_STREAM, 0); // do some error checking!

    dest_addr.sin_family = AF_INET;          // host byte order
    dest_addr.sin_port = htons(9877);   // short, network byte order
    dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1");

    // don't forget to error check the connect()!
    if(connect(sockfd, (struct sockaddr *)&dest_addr, sizeof dest_addr) == -1)
    {
        cout<<"Could not connect to server\n";
        return 0;
    }

    // listening…
    char buf[80];

    int bytes_recv = recv(sockfd, buf, sizeof(buf), 0);
    if(bytes_recv == -1)
    {
        cout<<"Nothing received from server\n";
        //int e = WSAGetLastError();
        //cout<<"error code: "<<e<<endl;
    }
    else
    {
        //print message
        for(int i=0; i<bytes_recv; i++)
        {
            cout<<buf[i];
        }
    }
    closesocket(sockfd);

    return 0;
}