Cow Game

Adventures of a Cow

Introduction

Peter has taken the Simple DirectMedia Layer software in his stride and has produced for his first SDL game the entertaining Adventures of a Cow. This five-level platform game features the appropriate use of a range of SDL functions. Examples of these functions and their uses are:
  • SDL_PumpEvents - gathers all the pending input information from devices and place it on the event queue
  • SDL_PollEvent - checks for an event such as the press of a key or a mouse button
  • SDL_GetKeyState - reads the keyboard
  • SDL_BlitSurface - copies images
  • SDL_FillRect - creates a different background colour for each level
  • filledPolygonColor (in the SDL_gfx library) - draws the background
  • rotozoomSurface (in the SDL_gfx library) - angles the cow at right angles to the ground to be more realistic when walking/running uphill and downhill

The robust code is helpfully commented and should prove to be useful for reference.

Start the game by double clicking the level you have reached on the opening screen then control the cow with the arrow keys. Watch those legs move! In Level One you need to avoid being crushed by large jumping elephants:
Level One in action

Level One in action

Eventually, you reach the cup:
Reaching the cup

Reaching the cup

Later levels introduce cliffs over a poisonous sea and bomb-dropping blimps. The following is a screenshot from Level Four. The reviewer is not prepared to disclose how many attempts he took to reach this level without cheating! See if you can work out from the code how to use key presses to use the built-in cheat mechanism to start at an advanced level.

Level Four in action

Level Four in action

Download here a zip file containing the main code (cowgame.txt) and a folder named associatedFiles containing images and a text file to record the level status. You should unzip the files so that associatedFiles is in the program folder. In order to run the program you will need to use SDL files and additional libraries. (See Getting Started with SDL for download details of SDL.dll, SDL.pas) and other Pascal header files.

The program requires the libraries SDL.dll, SDL_gfx.dll and SDL_image.dll. You can put these files in the program folder or with thousands of other libraries in your system folder. Download SDL_gfx.dll from the Freepascal meets SDL site. SDL_image-1.2.10-win32.zip from the SDL_image 1.2 page on the SDL site contains SDL_image.dll.

The Program

program CowGame;
{
    Copyright (c) 2011 Peter Hearnshaw

    Licensed under the Apache License, Version 2.0 (the "License"); you may not
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/
}
{$APPTYPE GUI}
uses
  CRT,
  SDL,
  SDL_IMAGE,
  SDL_GFX,
  sdlutils,
  strutils,
  SysUtils,
  Math;

type
  TElephant = record
    relavtiveX : integer;
    EleGravity : real;
    ypos : integer;
  end;

type
  TBomb = record
    dropping : boolean;
    Xpos : integer;
    Ypos : integer;
    gravity : real;
    droppedAtX : integer;
  end;

var
  rotated_width, rotated_height, newCowHeight, IntCheat : integer;
  screen, picture, rotatedPicture, MainMenu, cup, levelDone, died,
  ele, sea, blimp, bomb, MainMenu1, MainMenu2, MainMenu3, MainMenu4,
  MainMenu5, walk1R, walk2R, walk3R, walk4R, walk5R, walk1L,
  walk2L, walk3L, walk4L, walk5L, stoodL, stoodR, jumpR, jumpL : pSDL_SURFACE;
  myEvent, gameEvent: TSDL_Event;
  leaveProg, leaveDiedScreen, leaveDoneLevelScreen: boolean;
  SrcRect, mainMenuRect, CupRect, LevelDoneRect, diedRect, ElephRect,
  seaRect, blimpRect, offset, bombRect : TSDL_Rect;
  allBombs: array [1 .. 5] of TBomb;
  positionOfCup, positionOfEle, positionOfSea, blimpXpos, bombId,
  newestLevelUnlocked, walkingStage : integer;
  escape, hasDied : boolean;
  cowFacingDirection : string;
  landValues: array [1 .. 5, 1 .. 1300] of
  integer = ((50, 50, 51, 52, 52, 51, 49, 48, 48, 47, 45, 42, 38, 35,
    33, 30, 27, 25, 23, 21, 20, 18, 17, 17, 19, 21, 22, 22, 21, 21,
    20, 20, 20, 20, 20, 21, 21, 22, 24, 27, 29, 30, 32, 35, 37, 40,
    43, 47, 50, 52, 54, 55, 57, 59, 61, 64, 66, 68, 71, 75, 80, 84,
    88, 91, 94, 97, 98, 98, 97, 96, 94, 90, 87, 84, 80, 75, 70, 66,
    63, 60, 58, 55, 52, 48, 43, 37, 32, 28, 24, 19, 15, 13, 11, 10,
    12, 14, 17, 20, 22, 24, 26, 28, 29, 30, 30, 30, 31, 31, 31, 31,
    32, 34, 36, 38, 40, 43, 45, 46, 47, 47, 47, 46, 45, 43, 40, 38, 37,
    35, 34, 34, 33, 32, 32, 32, 31, 29, 28, 26, 23, 20, 17, 14, 12,
    12, 14, 16, 19, 23, 28, 32, 36, 40, 45, 49, 52, 56, 61, 66, 70,
    75, 79, 82, 86, 91, 96, 101, 105, 107, 108, 109, 108, 107, 104,
    100, 95, 88, 80, 73, 65, 57, 50, 42, 35, 27, 20, 12, 10, 12, 15, 19,
    24, 28, 31, 34, 38, 43, 48, 53, 58, 62, 67, 71, 76, 81, 86, 92,
    98, 103, 106, 108, 108, 108, 106, 103, 98, 92, 84, 77, 71, 65,
    59, 52, 46, 39, 31, 24, 16, 10, 10, 12, 15, 20, 25, 29, 32, 34,
    37, 41, 46, 50, 53, 55, 58, 61, 64, 67, 69, 70, 70, 71, 72, 72, 73,
    74, 75, 76, 76, 75, 75, 76, 76, 75, 74, 74, 73, 72, 72, 71, 70,
    70, 69, 69, 69, 69, 70, 71, 72, 73, 73, 73, 73, 74, 74, 73, 71,
    68, 65, 62, 59, 56, 53, 51, 48, 45, 43, 41, 38, 34, 29, 24, 18,
    13, 10, 10, 11, 14, 18, 23, 29, 35, 42, 50, 57, 63, 68, 72, 75,
    78, 80, 82, 85, 88, 92, 94, 95, 94, 92, 90, 89, 87, 86, 84, 81,
    78, 76, 75, 75, 75, 74, 74, 75, 75, 74, 74, 75, 76, 76, 77, 78,
    80, 82, 85, 88, 90, 91, 91, 91, 90, 89, 87, 84, 80, 75, 69, 62, 54,
    45, 37, 30, 23, 15, 10, 10, 12, 14, 17, 22, 28, 34, 39, 43, 46,
    48, 51, 55, 58, 62, 65, 69, 72, 74, 76, 78, 79, 79, 78, 78, 78,
    77, 77, 76, 75, 75, 74, 72, 70, 68, 67, 65, 62, 58, 53, 49, 45,
    40, 34, 27, 19, 12, 10, 11, 14, 19, 25, 30, 34, 37, 39, 41, 42, 43,
    44, 44, 44, 43, 41, 40, 38, 36, 35, 35, 34, 32, 29, 26, 22, 17,
    13, 10, 10, 10, 12, 16, 22, 28, 34, 40, 45, 49, 52, 56, 61, 67,
    73, 78, 82, 87, 91, 95, 97, 99, 101, 102, 102, 100, 96, 90, 83,
    76, 70, 64, 57, 51, 46, 41, 37, 34, 30, 26, 22, 19, 16, 13, 10, 10,
    12, 16, 20, 23, 26, 29, 31, 34, 37, 40, 44, 48, 52, 55, 57, 58,
    60, 63, 65, 68, 70, 71, 73, 74, 76, 78, 79, 80, 82, 83, 83, 84,
    86, 87, 89, 92, 93, 93, 93, 92, 91, 89, 87, 86, 84, 81, 77, 73,
    70, 66, 62, 57, 52, 47, 41, 35, 28, 20, 12, 10, 10, 10, 10, 10, 10,
    11, 14, 19, 26, 34, 42, 50, 59, 68, 77, 85, 93, 101, 109, 115,
    121, 127, 132, 136, 140, 143, 146, 147, 146, 144, 141, 138, 133,
    126, 117, 107, 95, 81, 68, 54, 39, 24, 10, 10, 10, 11, 13, 16, 20,
    24, 29, 33, 38, 42, 46, 51, 57, 62, 68, 73, 77, 80, 82, 84, 86, 87,
    89, 90, 90, 91, 92, 93, 94, 94, 94, 93, 90, 88, 87, 86, 86, 86,
    87, 89, 92, 93, 93, 92, 90, 89, 87, 84, 82, 81, 79, 76, 72, 69,
    66, 64, 61, 57, 54, 50, 46, 42, 37, 32, 27, 23, 19, 17, 15, 14,
    15, 16, 18, 21, 23, 26, 29, 31, 32, 32, 33, 35, 36, 36, 36, 35,
    34, 33, 32, 31, 31, 30, 30, 29, 27, 26, 24, 22, 19, 18, 18, 18,
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
    18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18,
    18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
    (80, 78, 75, 70, 63, 56, 50, 43, 38, 31, 25, 18, 13, 10, 10, 13,
    18, 26, 36, 46, 56, 66, 74, 82, 88, 96, 105, 116, 129, 142, 155,
    160, 164, 167, 168, 169, 167, 165, 162, 160, 158, 155, 152, 147,
    145, 142, 140, 142, 143, 144, 147, 150, 152, 154, 155, 152, 147,
    139, 131, 123, 116, 109, 103, 97, 89, 81, 73, 64, 54, 46, 38, 30,
    22, 15, 10, 10, 10, 10, 10, 10, 10, 13, 16, 20, 24, 30, 37, 46,
    54, 61, 67, 72, 75, 79, 84, 90, 98, 107, 115, 122, 129, 138, 146,
    151, 153, 155, 157, 160, 160, 157, 151, 142, 133, 124, 113, 101,
    90, 78, 67, 54, 41, 27, 15, 10, 10, 12, 13, 14, 16, 20, 24, 31,
    36, 41, 45, 48, 52, 58, 65, 73, 80, 89, 98, 108, 117, 120, 122,
    125, 125, 130, 220, 220, 220, 220, 220, 220, 220, 220, 130, 125,
    125, 122, 120, 120, 113, 103, 95, 85, 74, 63, 51, 38, 23, 11, 10,
    13, 19, 27, 34, 39, 42, 45, 49, 54, 58, 64, 71, 76, 81, 88, 95,
    102, 111, 121, 133, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 140, 140, 136, 132, 123, 116, 100, 83, 64,
    46, 29, 11, 10, 10, 12, 14, 17, 20, 25, 31, 36, 41, 45, 51, 55, 57,
    61, 63, 65, 69, 75, 80, 87, 96, 107, 120, 132, 144, 156, 165, 173,
    178, 182, 184, 185, 184, 182, 179, 174, 167, 161, 153, 145, 136,
    128, 118, 110, 101, 93, 87, 82, 78, 75, 73, 69, 63, 59, 56, 55,
    56, 56, 57, 56, 57, 58, 59, 60, 59, 56, 52, 48, 42, 34, 27, 23, 20,
    17, 17, 17, 17, 19, 20, 20, 19, 20, 23, 25, 29, 36, 42, 46, 52,
    57, 63, 67, 69, 72, 73, 73, 72, 69, 67, 65, 64, 63, 62, 61, 61,
    59, 56, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 13, 10, 12, 16, 20, 24, 31, 40, 48, 55, 61, 69, 78, 86,
    94, 100, 105, 112, 118, 126, 133, 138, 140, 139, 135, 129, 122,
    115, 107, 97, 86, 77, 68, 57, 48, 39, 29, 18, 10, 12, 13, 16, 19,
    24, 29, 35, 40, 47, 56, 66, 74, 82, 89, 96, 103, 109, 113, 117,
    120, 121, 121, 119, 119, 117, 113, 107, 102, 96, 88, 82, 78, 76, 72,
    69, 68, 68, 68, 70, 70, 70, 72, 74, 75, 75, 73, 73, 75, 78, 83,
    86, 90, 94, 99, 103, 109, 117, 124, 132, 140, 145, 151, 155, 158,
    160, 159, 158, 154, 149, 142, 133, 124, 114, 105, 97, 87, 76, 65,
    54, 41, 29, 18, 10, 10, 11, 11, 14, 17, 20, 23, 28, 36, 46, 55, 64,
    74, 85, 98, 113, 126, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 126, 114, 102, 88,
    73, 57, 42, 28, 15, 10, 12, 16, 23, 31, 40, 48, 56, 64, 72, 81,
    90, 98, 107, 115, 125, 136, 145, 152, 160, 166, 172, 176, 180, 181,
    183, 183, 183, 180, 177, 175, 171, 166, 162, 157, 150, 144, 137,
    131, 123, 117, 113, 107, 100, 91, 83, 74, 64, 53, 43, 33, 21, 10,
    10, 13, 19, 27, 35, 42, 51, 60, 69, 80, 90, 102, 114, 125, 138,
    149, 159, 168, 177, 184, 192, 195, 197, 197, 196, 195, 194, 193,
    191, 187, 184, 182, 181, 180, 180, 182, 184, 185, 188, 192, 190,
    189, 188, 187, 184, 182, 179, 176, 172, 165, 155, 142, 129, 116,
    103, 88, 72, 58, 43, 26, 10, 11, 15, 22, 28, 37, 45, 55, 64, 71,
    78, 87, 95, 101, 108, 116, 124, 132, 139, 146, 151, 154, 154, 155,
    155, 156, 157, 157, 154, 151, 147, 144, 139, 135, 131, 126, 122, 119,
    115, 112, 220, 220, 220, 220, 220, 220, 220, 220, 220, 90, 87,
    85, 85, 86, 87, 89, 93, 99, 103, 109, 117, 123, 130, 137, 141,
    143, 146, 149, 152, 152, 151, 148, 146, 145, 143, 140, 137, 135,
    130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130,
    130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130,
    130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130,
    130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130,
    130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130,
    130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130,
    130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 130,
    130, 130, 130, 130, 130, 130, 130, 130, 130, 130, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0,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0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (
    80, 77, 74, 71, 68, 67, 63, 56, 50, 43, 38, 31, 22, 13, 10, 12,
    16, 21, 28, 37, 45, 54, 66, 77, 89, 102, 116, 130, 144, 154, 160,
    164, 169, 174, 176, 174, 168, 161, 155, 145, 134, 122, 110, 96,
    81, 65, 51, 35, 21, 10, 10, 11, 11, 13, 18, 23, 29, 37, 44, 48, 52,
    54, 56, 59, 61, 62, 61, 57, 54, 51, 46, 38, 30, 22, 11, 10, 14,
    16, 17, 16, 18, 21, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 70, 71, 72, 74, 78, 82, 89, 99, 109, 116, 122, 126, 128,
    128, 128, 128, 130, 130, 132, 133, 132, 127, 122, 118, 110, 103,
    97, 88, 82, 73, 61, 48, 35, 23, 10, 10, 13, 14, 17, 24, 33, 41,
    50, 61, 70, 78, 87, 96, 104, 114, 123, 130, 135, 141, 149, 159,
    165, 171, 173, 175, 178, 179, 181, 180, 176, 171, 168, 162, 154,
    142, 128, 115, 102, 88, 73, 61, 50, 36, 25, 16, 10, 10, 10, 14, 20,
    24, 30, 36, 44, 49, 53, 55, 59, 61, 60, 59, 61, 61, 61, 61, 61,
    61, 59, 55, 48, 42, 37, 29, 22, 14, 10, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 25, 23, 24, 26, 31, 39, 50, 59, 66, 76, 89,
    101, 113, 123, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 120, 115, 110,
    113, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 110, 100, 85, 72, 60, 43, 30, 22, 17, 22, 24,
    25, 23, 18, 12, 10, 10, 10, 13, 16, 18, 21, 22, 22, 19, 19, 22,
    27, 31, 36, 41, 49, 54, 61, 71, 84, 96, 107, 119, 132, 143, 153, 162,
    167, 171, 172, 171, 170, 168, 164, 162, 156, 149, 140, 131, 120,
    111, 102, 92, 80, 65, 48, 31, 16, 10, 12, 17, 21, 25, 30, 32, 36,
    43, 51, 61, 72, 83, 93, 99, 103, 109, 115, 121, 125, 127, 131,
    132, 134, 134, 135, 132, 129, 124, 118, 108, 96, 86, 73, 62, 51, 38,
    26, 11, 10, 10, 10, 10, 13, 16, 18, 23, 28, 35, 39, 46, 52, 56,
    60, 64, 68, 75, 81, 84, 90, 97, 103, 106, 105, 103, 102, 101, 101,
    101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
    101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
    101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
    101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
    101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
    101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
    101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101, 101,
    101, 101, 101, 101, 101, 101, 101, 101, 101, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (
    80, 78, 74, 70, 67, 65, 61, 56, 50, 42, 36, 33, 29, 22, 16, 10,
    11, 15, 18, 18, 21, 23, 23, 23, 22, 23, 25, 29, 32, 38, 46, 56,
    65, 77, 88, 100, 110, 123, 136, 149, 164, 176, 181, 184, 189, 190,
    190, 188, 185, 180, 173, 167, 158, 150, 138, 123, 109, 95, 84, 71,
    55, 42, 30, 15, 10, 13, 13, 14, 12, 11, 10, 12, 11, 10, 12, 17, 19,
    24, 32, 38, 43, 47, 49, 53, 59, 66, 70, 74, 75, 75, 74, 72, 69,
    68, 68, 67, 67, 220, 220, 220, 220, 220, 220, 220, 220, 220, 107,
    108, 110, 115, 120, 126, 129, 134, 136, 139, 142, 143, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 135, 128, 120, 107, 98, 88, 77, 74, 72, 71,
    72, 74, 75, 76, 80, 84, 88, 89, 87, 85, 84, 80, 75, 70, 65, 63,
    62, 61, 62, 62, 63, 62, 62, 60, 57, 54, 54, 55, 54, 55, 57, 58,
    62, 68, 71, 75, 76, 76, 76, 78, 83, 88, 94, 100, 107, 113, 117, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    130, 120, 115, 112, 113, 118, 125, 140, 220, 220, 220, 220, 220,
    220, 220, 150, 142, 138, 145, 155, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 150, 146, 141, 129, 118, 108, 99,
    92, 83, 76, 69, 59, 48, 34, 23, 13, 10, 12, 14, 13, 14, 12, 10,
    10, 10, 12, 14, 15, 18, 18, 20, 20, 18, 17, 13, 12, 14, 18, 21,
    25, 31, 34, 34, 36, 41, 45, 51, 60, 68, 78, 88, 93, 97, 103, 110,
    116, 123, 131, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 135, 127, 123, 119, 117, 115,
    115, 116, 116, 116, 114, 111, 111, 113, 117, 124, 131, 135, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 121, 111, 108, 98, 84, 73, 61,
    48, 32, 21, 14, 13, 14, 14, 16, 20, 23, 27, 29, 32, 32, 29, 24, 19,
    13, 10, 10, 12, 13, 14, 13, 10, 10, 10, 12, 16, 21, 27, 35, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 126,
    115, 123, 133, 145, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 138, 128,
    118, 109, 101, 97, 89, 82, 73, 61, 48, 35, 21, 10, 11, 13, 16,
    17, 17, 18, 18, 15, 13, 11, 10, 10, 10, 11, 15, 20, 24, 25, 26,
    29, 29, 30, 34, 40, 47, 54, 60, 69, 76, 85, 94, 102, 111, 116, 120,
    124, 131, 135, 136, 137, 139, 139, 139, 139, 140, 141, 141, 142, 145,
    147, 146, 143, 138, 130, 121, 110, 100, 103, 111, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 92,
    84, 71, 66, 72, 220, 220, 220, 220, 220, 220, 220, 220, 77, 62,
    45, 33, 35, 39, 43, 47, 48, 52, 59, 64, 69, 73, 76, 80, 83, 88, 90,
    95, 99, 100, 103, 109, 114, 116, 118, 118, 121, 123, 123, 123,
    125, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 115, 110, 103, 98, 93, 87, 80, 71, 61, 54, 44, 31, 15, 10,
    10, 12, 14, 16, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 34,
    32, 28, 27, 23, 18, 15, 15, 18, 23, 28, 36, 42, 49, 54, 56, 58,
    59, 61, 66, 71, 73, 76, 79, 85, 88, 90, 93, 99, 103, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 37, 32, 26, 21, 17, 10, 10, 10, 10, 11, 12,
    12, 11, 10, 10, 10, 12, 12, 13, 14, 17, 18, 17, 16, 16, 19, 22,
    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
    24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
    24, 24, 24, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0,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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (120, 122, 121, 124,
    128, 129, 133, 141, 143, 142, 141, 143, 142, 138, 130, 127, 123,
    122, 123, 121, 122, 123, 125, 127, 127, 125, 124, 121, 116, 114,
    110, 102, 95, 91, 85, 83, 79, 73, 66, 63, 56, 51, 50, 45, 38, 35,
    30, 26, 24, 23, 21, 17, 14, 10, 10, 10, 10, 10, 10, 10, 13, 15,
    16, 15, 13, 10, 14, 14, 14, 17, 18, 16, 17, 17, 19, 23, 31, 35,
    39, 40, 37, 34, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 56, 66, 75, 83,
    88, 94, 98, 99, 103, 103, 104, 108, 112, 115, 121, 126, 135, 146,
    160, 171, 174, 174, 175, 174, 175, 175, 173, 173, 176, 178, 176,
    172, 170, 166, 162, 160, 156, 152, 151, 150, 146, 139, 132, 128, 125,
    122, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 85,
    92, 99, 107, 110, 113, 115, 115, 119, 123, 131, 135, 138, 144,
    149, 149, 148, 148, 149, 147, 143, 142, 144, 142, 142, 142, 142,
    144, 149, 155, 159, 158, 158, 158, 157, 159, 159, 162, 165, 170, 176,
    177, 175, 168, 164, 163, 160, 155, 152, 148, 140, 134, 126, 117,
    112, 103, 91, 78, 62, 49, 35, 28, 19, 13, 10, 10, 13, 16, 19, 19,
    18, 17, 18, 22, 24, 26, 28, 29, 32, 38, 45, 56, 65, 71, 77, 86,
    93, 96, 97, 100, 103, 105, 108, 110, 113, 115, 119, 122, 124, 126,
    131, 133, 136, 135, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 23, 10, 10, 12, 14, 16, 14, 15, 17, 15, 15, 16, 21, 25, 30,
    38, 45, 50, 53, 55, 58, 59, 61, 64, 67, 72, 75, 78, 85, 91, 101,
    115, 132, 146, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 157, 146, 135,
    126, 117, 108, 102, 93, 87, 78, 72, 69, 69, 72, 73, 72, 69, 70,
    75, 80, 85, 91, 95, 95, 94, 92, 93, 90, 90, 91, 92, 96, 98, 99,
    98, 96, 90, 89, 92, 95, 97, 101, 109, 121, 134, 140, 148, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 149, 135, 130, 123, 113, 104,
    97, 96, 95, 91, 85, 82, 77, 69, 59, 50, 41, 35, 27, 20, 10, 10,
    10, 14, 18, 25, 30, 39, 43, 44, 47, 54, 59, 67, 78, 90, 98, 110,
    121, 126, 127, 128, 129, 132, 134, 134, 131, 129, 128, 127, 127,
    131, 134, 135, 134, 130, 129, 131, 131, 132, 129, 124, 120, 117,
    110, 107, 104, 103, 103, 106, 112, 122, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 120, 114, 105, 93, 84, 71, 66, 62, 59, 59,
    61, 65, 67, 67, 64, 61, 61, 60, 62, 67, 72, 79, 82, 83, 82, 81,
    83, 88, 95, 100, 109, 114, 119, 127, 136, 143, 143, 140, 141, 144,
    147, 149, 148, 146, 146, 143, 139, 138, 136, 135, 132, 126, 117,
    108, 105, 103, 99, 91, 80, 72, 65, 61, 61, 62, 66, 68, 69, 74, 83,
    96, 108, 116, 123, 125, 125, 121, 113, 108, 107, 106, 105, 107,
    113, 122, 135, 140, 141, 143, 143, 145, 143, 139, 139, 136, 134,
    136, 137, 134, 135, 137, 138, 135, 134, 132, 133, 133, 137, 138,
    139, 143, 146, 152, 157, 161, 161, 162, 160, 157, 150, 141, 135, 125,
    117, 107, 97, 83, 66, 57, 49, 45, 44, 45, 44, 44, 44, 44, 48, 49,
    53, 54, 55, 58, 59, 62, 61, 62, 63, 64, 68, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 68, 65, 62, 60, 59, 57, 54, 47, 43,
    36, 25, 12, 10, 11, 10, 10, 12, 16, 22, 30, 38, 50, 64, 74, 80, 84,
    88, 95, 103, 109, 110, 108, 105, 104, 102, 101, 96, 91, 83, 72,
    57, 46, 39, 33, 24, 12, 10, 11, 13, 16, 17, 19, 21, 21, 22, 24,
    24, 25, 27, 31, 36, 40, 47, 57, 67, 73, 79, 82, 85, 88, 88, 87,
    85, 80, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 22, 19, 17, 19, 18,
    18, 19, 24, 26, 31, 33, 39, 40, 43, 44, 43, 39, 36, 36, 34, 28,
    20, 15, 14, 10, 10, 10, 10, 10, 12, 12, 14, 17, 24, 29, 30, 30,
    34, 41, 51, 56, 60, 67, 75, 79, 83, 88, 90, 93, 99, 107, 115, 119,
    119, 118, 113, 112, 108, 101, 92, 89, 83, 80, 77, 70, 59, 51, 45,
    40, 38, 35, 36, 35, 38, 40, 38, 32, 23, 16, 11, 10, 13, 14, 15,
    18, 19, 16, 16, 17, 16, 13, 12, 13, 16, 19, 18, 14, 14, 10, 10, 14,
    22, 28, 31, 35, 38, 43, 45, 48, 55, 58, 63, 67, 75, 80, 88, 95,
    101, 108, 119, 134, 142, 147, 151, 152, 155, 157, 156, 153, 146,
    142, 135, 124, 114, 103, 94, 87, 77, 66, 59, 53, 52, 52, 52, 55,
    58, 60, 59, 62, 61, 57, 50, 45, 41, 34, 24, 15, 10, 14, 22, 32, 43,
    58, 70, 79, 89, 101, 111, 114, 113, 113, 116, 118, 121, 123, 127,
    127, 128, 130, 132, 132, 128, 124, 119, 112, 108, 103, 95, 83,
    70, 56, 45, 41, 33, 22, 10, 10, 10, 11, 13, 18, 20, 18, 18, 17,
    18, 15, 11, 10, 10, 10, 10, 10, 10, 10, 11, 13, 11, 11, 10, 14, 18,
    21, 22, 27, 34, 41, 50, 56, 62, 72, 84, 90, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 137, 124, 109, 104, 99, 92,
    88, 84, 81, 77, 71, 63, 51, 39, 25, 11, 10, 11, 10, 10, 11, 11, 12,
    10, 11, 12, 12, 15, 15, 13, 15, 19, 23, 23, 21, 20, 16, 15, 16,
    17, 15, 16, 17, 16, 11, 10, 11, 10, 10, 13, 13, 16, 23, 32, 37,
    39, 42, 45, 47, 45, 39, 36, 34, 34, 33, 33, 33, 31, 30, 30, 30,
    34, 41, 48, 53, 58, 63, 66, 65, 64, 65, 65, 61, 54, 52, 48, 47, 43,
    36, 27, 14, 10, 11, 11, 10, 11, 13, 13, 13, 13, 14, 17, 18, 21,
    23, 28, 31, 34, 36, 35, 36, 35, 32, 33, 30, 29, 30, 33, 37, 45,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220,
    220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 220, 150, 144, 133,
    128, 123, 121, 122, 125, 131, 136, 141, 142, 139, 139, 135, 132,
    132, 129, 126, 127, 129, 130, 134, 137, 141, 147, 149, 151, 154,
    153, 152, 147, 140, 135, 132, 131, 133, 137, 140, 140, 140, 140,
    140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
    140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
    140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
    140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
    140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
    140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
    140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140, 140,
    140, 140, 140, 140, 140, 140, 140));
  levelArrLengthsArr : array [1 .. 5] of integer = (800, 800, 500, 800, 1300);
  i, a, backgroundX : integer;
  gravity : real;
  seaPositions : array[1 .. 5, 1 .. 26] of
  integer = ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0), (1946, 2600, 2876, 4500, 4776, 6800,
    7076, 9600, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
    (932, 2777, 3080, 3356, 3632, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0), (1160, 1490, 1766, 2612, 2888,
    3164, 3440, 4196, 4472, 4724, 5000, 5648, 5924, 6200, 6476, 7298,
    7574, 7850, 8222, 8498, 8684, 8960, 9236, 9476, 9752, 10028),
    (929, 1205, 1919, 3668, 4300, 4576, 5340, 5616, 6737, 7013, 9311,
    9587, 10763, 11039, 14558, 14834, 16700, 16976, 0, 0, 0, 0, 0, 0, 0, 0));
  keystates : PUint8;
  gradY1, gradY2 : integer;
  rotation : real;
  newangle_value, angle_value, zoom_value : double;
  onGround : boolean = False;
  blimpChance : array [1 .. 5] of integer = (0, 0, 500, 250, 100);
  key : Uint32;
  x_array2 : array[0 .. 200] of SINT16;
  y_array2 : array[0 .. 200] of SINT16;
  levelArrLength : integer = 800;
  allElephants : array[1 .. 5, 1 .. 14] of TElephant;
  blimpRunning : boolean = False;

const
  COWLENGTH = 52;
  COWHEIGHT = 32;

function checkNewestUnlockedLevel : integer;
var
  f: Text;
  strValue: string;
begin
  assignFile(f, 'associatedFiles\programData.txt');
  reset(f);
  readln(f, strValue);
  Close(f);
  checkNewestUnlockedLevel := StrToInt(strValue);
end;

procedure setNewestUnlockedLevel(newValue: integer);
var
  f : Text;
begin
  assignFile(f, 'associatedFiles\programData.txt');
  rewrite(f);
  Write(f, IntToStr(newValue));
  Close(f);
end;

procedure drawBackground(thisLevelArrLength: integer; levelNum: integer);
var
  a : integer;
begin
  a := 1;
  i := 2;

  while i < thisLevelArrLength do
    begin
      Inc(i);
      if ((i * 15) + backgroundX < 500) and (((i * 15) + backgroundX > 0)) then
        //only draw what is inside the screen (which is 500px across)
        begin

          if ((((i - 1) * 15) + backgroundX <= 0)) then
            //this is the first on screen i value
            begin
              //after this code is run, the y value will be plotted again but at x value (i*15)+backgroundX
              x_array2[a] := 0;
              y_array2[a] := landValues[levelNum][i] + 300;
              Inc(a);
            end;
          if ((((i + 1) * 15) + backgroundX >= 500)) then
            //this is the last on screen i value
            begin
              x_array2[a] := 500;
              y_array2[a] := landValues[levelNum][i] + 300;
              Inc(a);
            end
          else
            begin
              //this runs a lot because it is how points on the polygon are plotted to make up the land
              x_array2[a] := (i * 15) + backgroundX;
              y_array2[a] := landValues[levelNum][i] + 300;
              Inc(a);
              x_array2[a] := (i * 15) + backgroundX + 7;
              y_array2[a] := round(
                (landValues[levelNum][i] + landValues[levelNum][i + 1]) / 2) + 300;
              Inc(a);
            end;
        end;
    end;
  x_array2[a] := 500;
  y_array2[a] := 500;
  Inc(a);
  x_array2[a] := 0;
  y_array2[a] := 500;
  Inc(a);
  x_array2[a] := x_array2[0];
  y_array2[a] := y_array2[0];

  case levelNum of
    1 : FILLEDPOLYGONCOLOR(screen, @x_array2[0], @y_array2[0],
          round(500 / 7) + 30, $6FFF2FFF);
    2 : FILLEDPOLYGONCOLOR(screen, @x_array2[0], @y_array2[0],
          round(500 / 7) + 30, $9ACD32FF);
    3 : FILLEDPOLYGONCOLOR(screen, @x_array2[0], @y_array2[0],
          round(500 / 7) + 30, $7171C6FF);
    4 : FILLEDPOLYGONCOLOR(screen, @x_array2[0], @y_array2[0],
          round(500 / 7) + 30, $C0FF3EFF);
    5 : FILLEDPOLYGONCOLOR(screen, @x_array2[0], @y_array2[0],
          round(500 / 7) + 30, $CD853FFF);
  end;
end;


procedure SETUPWINDOW;
begin
  SDL_INIT(SDL_INIT_VIDEO);
  screen := SDL_SETVIDEOMODE(500, 500, 32, SDL_SWSURFACE);
  SDL_WM_SetCaption('Adventures of a Cow', nil);
end;

procedure LOADLEVEL(levelNum: integer);
begin
  //reset all our variables when we enter a level
  backgroundX    := -500;
  SrcRect.x      := 250 - round(COWLENGTH / 2);
  SrcRect.y      := landValues[levelNum][-round((backgroundX - 250) / 15)] +
                    300 - COWHEIGHT;
  SrcRect.w      := COWLENGTH;
  SrcRect.h      := COWHEIGHT;
  CupRect.x      := 0;
  CupRect.y      := 0;
  CupRect.w      := 154;
  CupRect.h      := 205;
  ElephRect.x    := 0;
  ElephRect.y    := 0;
  ElephRect.w    := 139;
  ElephRect.h    := 90;
  seaRect.x      := 0;
  seaRect.y      := 0;
  seaRect.w      := 276;
  seaRect.h      := 77;
  blimpRect.x    := 0;
  blimpRect.y    := 0;
  blimpRect.w    := 266;
  blimpRect.h    := 83;
  bombRect.x     := 0;
  bombRect.y     := 0;
  bombRect.w     := 8;
  bombRect.h     := 8;
  blimpRunning   := False;
  rotated_width  := COWLENGTH;
  rotated_height := COWHEIGHT;

  walk1R := SDL_LOADBMP('associatedFiles\walk1R.bmp');
  walk2R := SDL_LOADBMP('associatedFiles\walk2R.bmp');
  walk3R := SDL_LOADBMP('associatedFiles\walk3R.bmp');
  walk4R := SDL_LOADBMP('associatedFiles\walk4R.bmp');
  walk5R := SDL_LOADBMP('associatedFiles\walk5R.bmp');
  walk1L := SDL_LOADBMP('associatedFiles\walk1L.bmp');
  walk2L := SDL_LOADBMP('associatedFiles\walk2L.bmp');
  walk3L := SDL_LOADBMP('associatedFiles\walk3L.bmp');
  walk4L := SDL_LOADBMP('associatedFiles\walk4L.bmp');
  walk5L := SDL_LOADBMP('associatedFiles\walk5L.bmp');
  stoodR := SDL_LOADBMP('associatedFiles\stoodR.bmp');
  stoodL := SDL_LOADBMP('associatedFiles\stoodL.bmp');
  jumpL  := SDL_LOADBMP('associatedFiles\jumpL.bmp');
  jumpR  := SDL_LOADBMP('associatedFiles\jumpR.bmp');
  cup    := SDL_LOADBMP('associatedFiles\cup.bmp');
  died   := SDL_LOADBMP('associatedFiles\dead.bmp');

  bombId  := 1;
  leaveDiedScreen := False;
  leaveDoneLevelScreen := False;
  cowFacingDirection := 'stoodright';
  angle_value := 0.0;
  escape  := False;
  gravity := 0;
  onGround := False;
  walkingStage := 1;
  ele     := SDL_LOADBMP('associatedFiles\elephant.bmp');
  sea     := SDL_LOADBMP('associatedFiles\sea.bmp');
  blimp   := SDL_LOADBMP('associatedFiles\blimp.bmp');
  bomb    := SDL_LOADBMP('associatedFiles\bomb.bmp');
  hasDied := False;

  for a := 1 to 5 do
    begin
      for i := 1 to 14 do
        begin
          allElephants[a][i].relavtiveX := 0;
          allElephants[a][i].EleGravity := 0;
          allElephants[a][i].YPos := 0;
        end;
    end;

  for i := 1 to 5 do //go through each bomb
    begin
      allBombs[i].dropping := False;
    end;

  allElephants[1][1].relavtiveX := 1315;
  allElephants[1][2].relavtiveX := 2848;
  allElephants[1][3].relavtiveX := 3698;
  allElephants[1][4].relavtiveX := 3945;
  allElephants[1][5].relavtiveX := 4920;
  allElephants[1][6].relavtiveX := 7754;
  allElephants[1][7].relavtiveX := 10081;

  allElephants[2][1].relavtiveX := 850;
  allElephants[2][2].relavtiveX := 3900;
  allElephants[2][3].relavtiveX := 4162;
  allElephants[2][4].relavtiveX := 5725;
  allElephants[2][5].relavtiveX := 6000;
  allElephants[2][6].relavtiveX := 7718;
  allElephants[2][7].relavtiveX := 9392;
  allElephants[2][8].relavtiveX := 10011;

  allElephants[3][1].relavtiveX := 2567;

  allElephants[5][1].relavtiveX  := 604;
  allElephants[5][2].relavtiveX  := 1605;
  allElephants[5][3].relavtiveX  := 2450;
  allElephants[5][4].relavtiveX  := 2619;
  allElephants[5][5].relavtiveX  := 3887;
  allElephants[5][6].relavtiveX  := 6337;
  allElephants[5][7].relavtiveX  := 8573;
  allElephants[5][8].relavtiveX  := 11498;
  allElephants[5][9].relavtiveX  := 12395;
  allElephants[5][10].relavtiveX := 14293;
  allElephants[5][11].relavtiveX := 15242;
  allElephants[5][12].relavtiveX := 15437;
  allElephants[5][13].relavtiveX := 15625;
  allElephants[5][14].relavtiveX := 15904;

  repeat
    if (levelNum >= 3) then  //blimps only occur in levels 3,4,5
      begin
        for i := 1 to 5 do //go through each bomb
          begin
            if (allBombs[i].dropping = True) then
              begin
                with allBombs[i] do
                  begin
                    gravity := gravity * 1.1;
                    Ypos    := Ypos + round(gravity);
                    Xpos    := backgroundX - droppedAtX + 250;
                    bombRect.x := Xpos;
                    bombRect.y := Ypos;
                    bombRect.w := 22;
                    bombRect.h := 25;
                    key     := SDL_MAPRGB(bomb^.format, 255, 255, 255);
                    SDL_SetColorKey(bomb, SDL_SRCCOLORKEY, key);
                    SDL_Blitsurface(bomb, nil, screen, @bombRect);
                    if (Ypos > 500) then
                      begin
                        dropping := False;
                      end;
                    if (Xpos > 230) and (Xpos < 270) and
                      (Ypos > SrcRect.y + (COWHEIGHT / 2) - 30) and (Ypos <
                      SrcRect.y + (COWHEIGHT / 2) + 30) then
                      hasDied := True;
                  end;
              end;
            end;
        if (blimpRunning = False) and (random(blimpChance[levelNum]) = 1) then
          //add a new blimp at random. chance differs for each level.
          begin
            blimpRunning := True;
            blimpXpos    := -266;
          end;
        if (blimpRunning = True) then
          begin
            blimpXpos := blimpXpos + 8;

            key := SDL_MAPRGB(blimp^.format, 255, 255, 255);
            SDL_SetColorKey(blimp, SDL_SRCCOLORKEY, key);

            if (blimpXpos > 500) then
              begin
                blimpRunning := False;
              end;

            if (random(10) = 1) then //add a new bomb at random times 20!!
              begin
                Inc(bombId);
                if (bombId = 6) then
                  bombId := 1;
                with allBombs[bombId] do
                  begin
                    dropping := True;
                    Xpos     := 0; //this is overwritten later
                    Ypos     := 80;
                    gravity  := 10;
                    droppedAtX := backgroundX - blimpXpos + 133;
                  end;
              end;

            offset.x := blimpXpos;
            offset.y := 5;
            SDL_BlitSurface(blimp, nil, screen, @offset);

            if (blimpRect.x > 500) then
              blimpRunning := False;
          end;
      end;

    for i := 1 to 14 do
      begin
        if (allElephants[levelNum][i].relavtiveX <> 0) then
          begin
            with allElephants[levelNum][i] do
              begin
                positionOfEle := relavtiveX;
                ElephRect.x := backgroundX + positionOfEle + 250;
                EleGravity := EleGravity + 0.5;
                YPos := YPos + round(EleGravity);
                if (YPos + 90 > (300 + landValues[levelNum][-round(
                  (-positionOfEle - 250) / 15)])) then
                  EleGravity := -15;
                ElephRect.y  := YPos;
                if (ElephRect.x < 700) and (ElephRect.x > -200) then
                  begin
                    key := SDL_MAPRGB(ele^.format, 255, 255, 255);
                    SDL_SetColorKey(ele, SDL_SRCCOLORKEY, key);
                    SDL_Blitsurface(ele, nil, screen, @ElephRect);
                  end;
                if (ElephRect.x > 100) and (ElephRect.x < 250) and
                     (SrcRect.y > ElephRect.y + 90 - 14) and
                     (SrcRect.y < ElephRect.y + 90 + 14) then
                  hasDied := True;   //if the cow is around the feet of the elephant
              end;
            end;
      end;

    for i := 1 to 25 do
      begin
        positionOfSea := seaPositions[levelnum][i];
        if (positionOfSea <> 0) then
          begin
            SeaRect.x := backgroundX + positionOfSea + 250;
            SeaRect.y := 455;
            key := SDL_MAPRGB(sea^.format, 255, 255, 255);
            SDL_SetColorKey(sea, SDL_SRCCOLORKEY, key);
            SDL_Blitsurface(sea, nil, screen, @SeaRect);
          end;
       end;

    //if the cow goes too far to the left where it shouldn't go
    if (backgroundX > -100) then
      backgroundX := -100;
    if (SrcRect.y > 455) and
       (landValues[levelNum][-round((backgroundX - 250) / 15)] = 220) then
      hasDied := True;
    //this makes the cow die if it lands in the poisonous water
    //it has to be below 455 px down and over the water (which
    //always has a landValue of 220)
    gravity   := gravity + 1.5;
    //make the cow stand still on the ground and not sink

    newAngle_value := angle_value;
    if (newAngle_value > 180) then
      newAngle_value := 360 - angle_value;
    newCowHeight := COWHEIGHT + round(22 * sin((newAngle_value * 3.1412) / 180));
    //this is to predict the distance from the top of the cow to
    //between its legs where it touches the ground, at any rotation.
    if (SrcRect.y + newCowHeight > landValues[levelNum][-round(
       (backgroundX - 250) / 15)] + 300) then
      begin
        if (SrcRect.y + newCowHeight < landValues[levelNum][-round(
           (backgroundX - 250) / 15)] + 300 + 50) then
          begin
            SrcRect.y := landValues[levelNum][-round((backgroundX - 250) / 15)] +
              300 - newCowHeight + round(gravity);
            gravity   := 0;
            onGround  := True;
            //stop the cow from having a jumping image when reaching the ground
            picture   := stoodR;  //load right unless facing left
            if ((pos('left', cowFacingDirection) > 0)) then
              picture := stoodL;
          end
        else
          begin
            if ((pos('left', cowFacingDirection) > 0)) then
              backgroundX := backgroundX - 100;
            if ((pos('right', cowFacingDirection) > 0)) then
              backgroundX := backgroundX + 100;
          end;
      end;
    SrcRect.y := SrcRect.y + round(gravity);
    //code to make the cow look like it's walking
    Inc(walkingStage);
    if (walkingStage = 6) then
      walkingStage := 1;

    if (cowFacingDirection = 'stoodleft') then
      picture := stoodL;
    if (cowFacingDirection = 'stoodright') then
      picture := stoodR;
    if (cowFacingDirection = 'right') then
      begin
        case (walkingStage) of
          1 : picture := walk1R;
          2 : picture := walk2R;
          3 : picture := walk3R;
          4 : picture := walk4R;
          5 : picture := walk5R;
        end;
        backgroundX := backgroundX - 13;
      end;
    if (cowFacingDirection = 'left') then
      begin
        case (walkingStage) of
          1: picture := walk1L;
          2: picture := walk2L;
          3: picture := walk3L;
          4: picture := walk4L;
          5: picture := walk5L;
        end;
        backgroundX := backgroundX + 13;
      end;
    if (pos('right', cowFacingDirection) > 0) and (onGround = False) then
      picture := jumpR;
    if (pos('left', cowFacingDirection) > 0) and (onGround = False) then
      picture := jumpL;
    rotatedPicture := SDL_DisplayFormat(picture);
    key := SDL_MAPRGB(rotatedPicture^.format, 255, 255, 255);
    SDL_SetColorKey(rotatedPicture, SDL_SRCCOLORKEY, key);

    //ALL ABOUT ROTATING THE COW
    if (onGround = True) then
      begin
        gradY1 := landValues[levelNum][round(
          (-backgroundX + 250 - round(COWLENGTH / 2)) / 15)];
        //gradY1 := round((gradY1 + landValues[levelNum][round((-backgroundX + 260 - round(COWLENGTH / 2)) / 15)])/2);
        gradY2 := landValues[levelNum][round(
          (-backgroundX + 250 + round(COWLENGTH / 2)) / 15)];
        //gradY2 := round((gradY2 + landValues[levelNum][round((-backgroundX + 240 + round(COWLENGTH / 2)) / 15)])/2);
        //these two selection statements make sure that if the cow is perched over a ledge then the rotation doesn't make the cow face head downwards
        if (gradY2 = 220) then
          //at a stupid angle
          gradY2 := gradY1;
        if (gradY1 = 220) then
          gradY1 := gradY2;
        rotation := (52 * ((gradY2 - gradY1) / -COWLENGTH));
        if (rotation < 0) then
          rotation  := 360 + rotation;
        angle_value := rotation;
        zoom_value  := 1;
        SrcRect.x   := 250 - round(COWLENGTH / 2);
        if angle_value >= 359 then
          angle_value := 0.0;
      end;

    rotatedPicture := ROTOZOOMSURFACE(rotatedPicture, angle_value, zoom_value, 1);
    rotozoomSurfaceSize(COWLENGTH, COWHEIGHT, angle_value, zoom_value,
                        rotated_width, rotated_height);
    levelArrLength := levelArrLengthsArr[levelNum];
    //the array of the background is 1300 for every level, but the actual level lengths vary
    //hence why lots of the array is made of zeroes to fill up to 1300
    //but this makes sure the drawBackground procedure doesn't bother with the empty spaces
    drawBackground(levelArrLength, levelNum);

    SDL_Blitsurface(rotatedPicture, nil, screen, @SrcRect);
    SDL_Flip(screen);
    SDL_Delay(50);
    //different colour background for each level
    case levelNum of
      1: SDL_FillRect(screen, pSDLRect(0, 0, 500, 500), $63B8FFFF);
      2: SDL_FillRect(screen, pSDLRect(0, 0, 500, 500), $2A8ADDFF);
      3: SDL_FillRect(screen, pSDLRect(0, 0, 500, 500), $FFCCCCCC);
      4: SDL_FillRect(screen, pSDLRect(0, 0, 500, 500), $FFFFFFA3);
      5: SDL_FillRect(screen, pSDLRect(0, 0, 500, 500), $FFDDA0DD);
    end;

    //CHECKING KEY PRESSES
    keystates := (SDL_GetKeyState(nil));
    SDL_PumpEvents();
    if (keystates[SDLK_LEFT] <> 0) then
      begin
        cowFacingDirection := 'left';
      end;
    if (keystates[SDLK_RIGHT] <> 0) then
      begin
        cowFacingDirection := 'right';
      end;
    if (keystates[SDLK_RIGHT] = 0) and (keystates[SDLK_LEFT] = 0) then
      cowFacingDirection := 'stood' + cowFacingDirection;
    if (keystates[SDLK_UP] <> 0) then
      begin
        if (onGround = True) then
          begin
            gravity   := -22;
            SrcRect.y := SrcRect.y - 10;
            onGround  := False;
          end;
      end;
    if (keystates[SDLK_ESCAPE] <> 0) then
      begin
        escape := True;
      end;
    while SDL_PollEvent(@gameEvent) > 0 do
      begin
        if (gameEvent.type_ = SDL_QUITEV) then
          //checking if the X button on the window has been pressed
          begin
            escape    := True;
            leaveProg := True;
          end;
      end;

    //ALL ABOUT CUP AND END OF LEVEL
    //adapting for the different lengths of the levels
    case levelNum of
      1 : positionOfCup := 10812;
      2 : positionOfCup := 10812;
      3 : positionOfCup := 6758;
      4 : positionOfCup := 10812;
      5 : positionOfCup := 18770;
    end;
    CupRect.x := backgroundX + positionOfCup + 250;
    CupRect.y := landValues[levelNum][-round((-positionOfCup - 250) / 15)] + 90;
    key := SDL_MAPRGB(cup^.format, 255, 255, 255);
    SDL_SetColorKey(cup, SDL_SRCCOLORKEY, key);
    SDL_Blitsurface(cup, nil, screen, @CupRect);
    //if the cow reaches the cup
    if (backgroundX < -positionOfCup) then
      begin
        escape := True;
        if (newestLevelUnlocked = levelNum) and (levelNum <> 5) then
          Inc(newestLevelUnlocked);
        setNewestUnlockedLevel(newestLevelUnlocked);
        //this proc records this value in a file for later when the prog is reopened
        LevelDoneRect.x := 67;
        LevelDoneRect.y := 182;
        LevelDoneRect.w := 336;
        LevelDoneRect.h := 135;
        case levelNum of
          1 : levelDone := SDL_LOADBMP('associatedFiles\complete1.bmp');
          2 : levelDone := SDL_LOADBMP('associatedFiles\complete2.bmp');
          3 : levelDone := SDL_LOADBMP('associatedFiles\complete3.bmp');
          4 : levelDone := SDL_LOADBMP('associatedFiles\complete4.bmp');
          5 : levelDone := SDL_LOADBMP('associatedFiles\complete5.bmp');
        end;
        SDL_FillRect(screen, pSDLRect(0, 0, 500, 500), $B0E2FFFF);
        SDL_Blitsurface(levelDone, nil, screen, @LevelDoneRect);
        SDL_Flip(screen);
        repeat
          SDL_PollEvent(@myEvent);
          leaveDoneLevelScreen :=
            (myEvent.type_ = SDL_MOUSEBUTTONDOWN) and (myEvent.Motion.x > 178) and
            (myEvent.Motion.x < 304) and (myEvent.Motion.y > 261) and
            (myEvent.Motion.y < 287);
          escape := True;
          if (myEvent.type_ = SDL_QUITEV) then   //lets the program out to let it quit
            begin
              leaveProg := True;
              leaveDoneLevelScreen := True;
            end;
          SDL_PollEvent(@myEvent);
        until leaveDoneLevelScreen = True;
      end;
    //CHECKING IF DIED
    if (hasDied = True) then
      begin
        escape     := True;
        DiedRect.x := 67;
        DiedRect.y := 182;
        DiedRect.w := 336;
        DiedRect.h := 135;
        SDL_FillRect(screen, pSDLRect(0, 0, 500, 500), $FFE4B5FF);
        SDL_Blitsurface(died, nil, screen, @DiedRect);
        SDL_Flip(screen);
        repeat
          SDL_PollEvent(@myEvent);
          leaveDiedScreen :=
            (myEvent.type_ = SDL_MOUSEBUTTONDOWN) and (myEvent.Motion.x > 125) and
            (myEvent.Motion.x < 376) and (myEvent.Motion.y > 279) and
            (myEvent.Motion.y < 296);
          escape := True;
          if (myEvent.type_ = SDL_QUITEV) then
            //lets the program out to let it quit
            begin
              leaveProg := True;
              leaveDiedScreen := True;
            end;
        until leaveDiedScreen = True;
      end;
  until escape = True;
end;

begin
  randomize;
  SETUPWINDOW;
  IntCheat  := 0;
  mainMenuRect.x := 0;
  mainMenuRect.y := 0;
  mainMenuRect.w := 500;
  mainMenuRect.h := 500;
  MainMenu  := SDL_LOADBMP('associatedFiles\front1.bmp');
  newestLevelUnlocked := checkNewestUnlockedLevel;
  leaveProg := False;
  MainMenu1 := SDL_LOADBMP('associatedFiles\front1.bmp');
  MainMenu2 := SDL_LOADBMP('associatedFiles\front2.bmp');
  MainMenu3 := SDL_LOADBMP('associatedFiles\front3.bmp');
  MainMenu4 := SDL_LOADBMP('associatedFiles\front4.bmp');
  MainMenu5 := SDL_LOADBMP('associatedFiles\front5.bmp');

  repeat
    SDL_Blitsurface(MainMenu, nil, screen, @mainMenuRect);
    SDL_Flip(screen);
    SDL_Delay(100);

    while SDL_PollEvent(@MyEvent) > 0 do
      begin
        if MyEvent.type_ = SDL_KeyDown then
          begin
            case (myevent.key.keysym.sym) of
              SDLK_E : begin
                         if (IntCheat = 0) then
                           begin
                             Inc(IntCheat);
                           end
                        else
                           begin
                             IntCheat := 0;
                           end;
                       end;
              SDLK_R : begin
                         if (IntCheat = 1) then
                           begin
                             Inc(IntCheat);
                           end
                         else
                           begin
                             IntCheat := 0;
                           end;
                       end;
              SDLK_P : begin
                         if (IntCheat = 2) then
                           begin
                             Inc(IntCheat);
                           end
                         else
                           begin
                             IntCheat := 0;
                           end;
                       end;
              else
                IntCheat := 0;
            end;
            if (IntCheat = 3) then
              begin
                newestLevelUnlocked := 5;
                IntCheat := 0;
              end;
          end;
        if MyEvent.type_ = SDL_MOUSEBUTTONDOWN then
          begin
            if (MyEvent.motion.x >= 145) and (MyEvent.motion.x <= 331) and
              (MyEvent.motion.y >= 478) and (MyEvent.motion.y <= 493) then
              begin
                setNewestUnlockedLevel(1);
                newestLevelUnlocked := 1;
              end;
            if (MyEvent.motion.x >= 65) and (MyEvent.motion.x <= 434) then
              begin
                if (newestLevelUnlocked >= 1) and (MyEvent.motion.y >= 183) and
                   (MyEvent.motion.y <= 220) then
                  begin
                    LOADLEVEL(1);
                  end
                else if (newestLevelUnlocked >= 2) and (MyEvent.motion.y >= 246) and
                        (MyEvent.motion.y <= 281) then
                  begin
                    LOADLEVEL(2);
                  end
                else if (newestLevelUnlocked >= 3) and (MyEvent.motion.y >= 308) and
                        (MyEvent.motion.y <= 343) then
                  begin
                    LOADLEVEL(3);
                  end
                else if (newestLevelUnlocked >= 4) and (MyEvent.motion.y >= 369) and
                        (MyEvent.motion.y <= 405) then
                  begin
                    LOADLEVEL(4);
                  end
                else if (newestLevelUnlocked >= 5) and (MyEvent.motion.y >= 432) and
                        (MyEvent.motion.y <= 467) then
                  begin
                    LOADLEVEL(5);
                  end;
              end;
          end;
      end;
    case newestLevelUnlocked of
      1 : MainMenu := MainMenu1;
      2 : MainMenu := MainMenu2;
      3 : MainMenu := MainMenu3;
      4 : MainMenu := MainMenu4;
      5 : MainMenu := MainMenu5;
    end;
    if (MyEvent.type_ = SDL_QUITEV) then
      begin
        leaveProg := True;
      end;
  until leaveProg = True;
  SDL_FREESURFACE(picture);
  SDL_FREESURFACE(screen);
  SDL_QUIT;
end.

Remarks

Could you use this program to help you to code your own platform game?

Programming - a skill for life!

Fourteen programs (with five web versions) including 3D-Driving, GASP and Knowledge by Peter Hearnshaw