Ken-Soft

Software and the World


SDL - Simple Space Shooter Game Demo

Posted under C/C++, Game Development, Programming, Software Development by Kenny on Sunday 20 September 2009 at 8:32 pm

Bookmark and Share

This page contains source code for a simple space shooter game written in C++ using the SDL library. There are no enemies or levels, but only a ship that shoots bullets. This is meant for a beginner who is interested in getting started with SDL for use of making games. (This will be an ongoing tutorial)

All source code can be found in the ZIP file
Version Downloads with project files (All you really need is the source):
Version 3: Enemies, Event Queue(timer based), explosions, bullet & enemy collision, some minor code fixes
Version 2: Animated sprites, uses custom sprite class
New to SDL? Start with Version 1 below
Version 1: Project file for DevCpp (Windows)
Version 1: Project file for Code::Blocks (Linux)

Also, for a Sprite class with rotations, animations, etc. Check out my ongoing Sprite library, also written in C++ using SDL
SDL Sprite Library

Share on Facebook

3D Cube Engine - Java

Posted under Game Development, Java, Programming, Software Development by Kenny on Saturday 27 June 2009 at 10:35 am

Bookmark and Share

This is a recent project of mine for building 3D puzzle games, (like Rubik’s Cubes).

While the code could be optimized quite a bit, this is mainly for those who wish to better understand concepts of 3D programming. For example, one way to create, store, and manipulate a 3D polygon, whether it be a Cube, or an ellipsoid. This project contains code and algorithm’s to rotate 3D polygons, around the origin, and themselves. Ability to draw 3D objects in order of increasing Z-values. Draw wireframe or solid color polygons. Keyboard and Mouse controls to move and alter the Polygons. It is a work in progress and not intended for use in graphic intensive games.

Note: later I will add rotateAroundVector() for more general rotation
Note: Ellipse3D is still very primitive but demonstrates one method creating an ellipsoid
Note: Not all Jar files contain the same versions of code. Each Jar file contains code specific to what it is supposed to do.

All source code can be found in the JAR files
Downloadable Jars (simple to complex):
1. RenderWiredCubes3D-demo.jar: this code rotates 4 rotating cubes about the origin.
2. RenderPolygons3D-demo.jar: this code demonstrates various ellipsoids and cubes rotating around unique axises.
3. Cubes3D-demo.jar: this code demonstrates more of the functionality of the 3D Cube engine by creating a Rubik’s cube like look and feel.
Controls

  • Mouse: click and drag the cube
  • A - reset
  • S - toggle between solid and non-solid mode. (i.e. the inside is filled with cubes or not)
  • D - randomly select an internally defined color scheme
  • F - toggle between random rotate mode. Just try it :)
  • Q - Decrease space between pieces
  • W - Increase space between pieces
  • E - Decrease size of cubes
  • R - Increase size of cubes
  • T - Decrease dimensions. i.e. 4×4x4 -> 3×3x3
  • Y - Increase dimensions. i.e. 4×4x4 -> 5×5x5 (not that if solid mode is true, then it will render slower
  • Arrows - Translate the cubes across the screen

If you’re only interested in the Transformation algorithms, check the below link:
Graph4D - demonstrates methods and actual source code for rotating a 4D vector.
Graph3D - demonstrates methods and actual source code for rotating a 3D vector.

Share on Facebook

SDL Sprite Class in C++

Posted under C/C++, Game Development, Programming, Software Development by Kenny on Friday 2 January 2009 at 9:58 pm

Bookmark and Share

This is a simple Sprite class that I use for game development in C++ using SDL (www.libsdl.org).
Features include sprite animation, rotation, stretching, transparencies, and other commonly used sprite functions.

I hope this is somewhat useful. The source is available and should be fairly simple to work with.
Feel free to modify it however you want. please comment about any bugs are suggestions that you have. Thanks.

Last Updated
2010 July 18 - implemented a builder design to all setter/modifying operations that return void. They now return the object it’s self, (*this). This results in being able to set up a Sprite with less code. i.e.
sprite->setTransparency(0xFF, 0, 0xFF)->flipHorizontal()->reverseAnimation()->zoom(50);
sprite->animate()->draw(screen, 100, 100);
2010 June 1 - fixed some minor bugs

SDL Sprite C++
Version 1d (With demo & source) SDL_Sprite_1d.zip

Individual source files

Sprite.h

Sprite.cpp

Main.h

main.cpp

To view a demo of some of the Sprites classes features, and have access to some sample Bitmap images used with the Sprite library, download the following zip file. It also contains the project settings that I used in Dev C++ and SDL 1.2.12 to compile.

All examples use these sprites

SDL Sprite C++ SDL Sprite C++

Demo using special effects

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    // Initialize SDL, etc
   ...
   ...
   Sprite* s1 = new Sprite("sprites/samus_normal_run.bmp",10,60); // load a BMP that contains 10 frames
                                                // set the animation speed to 60 milliseconds
      // set RGB(255,0,255) as transparent, rotate 180 degrees, flip horizontal and reverse animation
  s1->setTransparency(255,0,255)->rotate180()->flipHorizontal()->reverseAnimation();
   // etc
    ...
    ...
 
    // Main loop
    // clear background to black, RGB(0,0,0)
    SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0));
    // animate and draw the sprite
    s1->animate()->draw(screen,0,0);
    SDL_Flip(screen);
Share on Facebook

Next Page »

Copyright © 2009 www.Ken-Soft.com