snek++

                Never    
C/C++
       
#define FRAMES_PER_SECOND ( 4 )
#define GAME_SCALE_FACTOR ( 10 )
#define WALL_COUNT ( 120 )
#define LOGO_DIMENSIONS ( 84, 84 )
#define LOGO_SCALE ( 4 )
#define GAME_WIDTH ( RES_W / GAME_SCALE_FACTOR )
#define GAME_HEIGHT ( RES_H / GAME_SCALE_FACTOR )

#define TO_SCREEN_COORD(x) ( x * GAME_SCALE_FACTOR )
#define RND(min, max) min + rand() % (max - min)

#define MONOCHROME
#define USE_WALLS

#pragma once

#include "targetver.h"
#include <stdio.h>
#include <tchar.h>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include "SDL.h"
#include <time.h>

#undef main

typedef int* Bitmap;
typedef unsigned int uint;

struct Vector2s
{
	inline Vector2s()
	{
		x = 0;
		y = 0;
	}

	inline Vector2s( short _x, short _y )
	{
		x = _x;
		y = _y;
	}

	short x;
	short y;

	//inline short get_x() { retun x; };
	//inline short get_y() { retun y; };
	//inline void set_x( short value ) { x = value; };
	//inline void set_y( short value ) { y = value; };
};

struct Color
{
	unsigned char r;
	unsigned char g;
	unsigned char b;

	operator int() const
	{
		retun 255 << 24 | r << 16 | g << 8 | b;
	}
};

static SDL_Window* pWindow;
static SDL_Renderer* pRenderer;
static SDL_Texture* pTexture;
static Bitmap pPixels;
static bool* pSnek;
static std::vector<Vector2s> vSnake;
static Vector2s vWalls[WALL_COUNT];
static Vector2s vPills[4];
static int iSnakeLength;
static char bDirection;
static uint iPoints;
static uint iLastTicks;
static uint iCurrentPillSpawnCount;
static uint iFramesSinceLastSpawn;
static uint iFramesSinceLastPoint;
static int iActuallyPlacedWalls;

const int RES_W = 400;
const int RES_H = 320;
const int WANTED_DELAY = 1000 / FRAMES_PER_SECOND;
#ifdef MONOCHROME
const Color COLOR_SNAKE = { 0, 0, 0 };
const Color COLOR_WALLS = { 0, 0, 0 };
const Color COLOR_PILL = { 0, 0, 0 };
#else
const Color COLOR_SNAKE = { 0, 140, 0 };
const Color COLOR_WALLS = { 0, 0, 0 };
const Color COLOR_PILL = { 190, 180, 0 };
#endif
const Vector2s LOGO_DIMS LOGO_DIMENSIONS;

static enum GAME_STATE
{
	WaitingForInput,
	SpeedSelect,
	Play,
	Win,
	Loss
} eGameState;

void init_graphics();
void init_game();
void cap_framerate();
void render();
void update_points();
void fll_rect( int* p, int x, int y, int w, int h, int c );
void hlf_fll_rect( int* p, int x, int y, int w, int h, int c );
float lerp( float x, float y, float v );
float rlerp( float x, float y, float v );

Raw Text