Skip to content

Instantly share code, notes, and snippets.

@zachelko
zachelko / templatetrick.cpp
Created April 10, 2010 04:01
Template tricks
// resource.h
//
#ifndef _RESOURCE_H
#define _RESOURCE_H
template <typename T>
class Resource
{
protected:
T* data;
@zachelko
zachelko / skater.cpp
Created April 8, 2010 06:23
Basic C/C++ code obfuscator.
// Zach J. Elko
// 2010
// skater.cpp
//
// I've wanted to make one of these for a while now. I got bored and
// whipped this up in about 3 hours. There are a lot of improvements
// that can/should be made, but it's not bad for the short amount of
// time put into it.
//
// Basic C/C++ code obfuscator.
@zachelko
zachelko / rotate.py
Created April 8, 2010 05:25
Roll the ball
# If we need to rotate our player (character is a ball, etc...)
if (self.rotate == True and moveX != 0):
if (moveX < 0): self.image = pygame.transform.rotate(self.image, -90)
else: self.image = pygame.transform.rotate(self.image, 90)
@zachelko
zachelko / fillbeakers.py
Created April 8, 2010 05:18
Progressively filling a container with rain
def render(self, screen):
screen.blit(self.image, (self.rect.x, self.rect.y))
if (self.drops > 0):
x = self.rect.x + 2
rainColor = ()
if (self.full):
level = 1
rainColor = (255,0,0)
else:
@zachelko
zachelko / raindrops.py
Created April 8, 2010 04:14
Exclude rain drops below the beaker
# Find the shortest beaker so we know which drops to check for collisions
# against
beakerHeights = []
shortest = 0
for beaker in level.beakers: beakerHeights.append(beaker.rect.y)
beakerHeights.sort()
if (beakerHeights): shortest = beakerHeights[0]
@zachelko
zachelko / CircularList.hpp
Created April 8, 2010 02:01
Templated list data structure that enables you to toggle 'wrap-around' functionality to achieve a circular list.
// CircularList.hpp
//
// Zach Elko
// 2010
//
// Simple templated data structure that allows you to toggle 'wrap-around' behavior
// to achieve a circular list.
//
#ifndef CIRCULAR_LIST_H
#define CIRCULAR_LIST_H
@zachelko
zachelko / testcase.cpp
Created April 8, 2010 00:52
Test case
//utils.h
#ifndef UTILS_H
#define UTILS_H
#include
struct Point2d
{
float x;
@zachelko
zachelko / reverse2.c
Created April 8, 2010 00:39
Reversing a string the good way
void swap(char str[],
const int firstIndex,
const int secondIndex)
{
char temp = str[firstIndex];
str[firstIndex] = str[secondIndex];
str[secondIndex] = temp;
}
void reverse2(char src[])
@zachelko
zachelko / reverse1.c
Created April 8, 2010 00:37
Reversing a string the bad way
void reverse(char str[])
{
// Add 1 for the terminating character
int len = strlen(str) + 1;
char temp[len];
// Data resides from indices 0-2
int i = len - 2;
for (; i >= 0; --i)
{
@zachelko
zachelko / scope.cpp
Created April 3, 2010 02:20
Arbitary scope
class Foo
{
public:
Foo() { std::cout << "ctor\n"; }
~Foo() { std::cout << "dtor\n"; }
};
int main()
{
std::vector<Foo> foos;
{