diff options
author | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-11-24 19:57:03 +0000 |
---|---|---|
committer | Luke Bratch <l_bratch@yahoo.co.uk> | 2010-11-24 19:57:03 +0000 |
commit | 3383e8be9001826bf0d09f1fb73ad5013cc8627e (patch) | |
tree | 27be0f78ab8672a7187d517c73b4ee22817369cc |
Initial commit
-rw-r--r-- | Creature.cpp | 38 | ||||
-rw-r--r-- | Creature.h | 33 | ||||
-rw-r--r-- | Hazard.cpp | 6 | ||||
-rw-r--r-- | Hazard.h | 14 | ||||
-rw-r--r-- | Level.cpp | 36 | ||||
-rw-r--r-- | Level.h | 28 | ||||
-rw-r--r-- | MapObject.cpp | 11 | ||||
-rw-r--r-- | MapObject.h | 21 | ||||
-rw-r--r-- | Monster.cpp | 13 | ||||
-rw-r--r-- | Monster.h | 17 | ||||
-rw-r--r-- | Pickup.cpp | 6 | ||||
-rw-r--r-- | Pickup.h | 14 | ||||
-rw-r--r-- | Platform.cpp | 6 | ||||
-rw-r--r-- | Platform.h | 14 | ||||
-rw-r--r-- | Player.cpp | 17 | ||||
-rw-r--r-- | Player.h | 19 | ||||
-rw-r--r-- | README | 7 | ||||
-rw-r--r-- | Sprite.cpp | 31 | ||||
-rw-r--r-- | Sprite.h | 35 | ||||
-rw-r--r-- | intensemarcus.h | 4 | ||||
-rw-r--r-- | main.cpp | 63 |
21 files changed, 433 insertions, 0 deletions
diff --git a/Creature.cpp b/Creature.cpp new file mode 100644 index 0000000..0463e5a --- /dev/null +++ b/Creature.cpp @@ -0,0 +1,38 @@ +#include <iostream> +#include "Creature.h" + +Creature::Creature() { + std::cout << "Creature::Creature(): Creature created.\n"; +} + +int Creature::getXVel() { + return xVel; +} + +int Creature::getYVel() { + return yVel; +} + +void Creature::setXVel(int xVel) { + this->xVel = xVel; +} + +void Creature::setYVel(int yVel) { + this->yVel = yVel; +} + +void Creature::incXVel(int xVel) { + this->xVel += xVel; +} + +void Creature::incYVel(int yVel) { + this->yVel += yVel; +} + +int Creature::getHealth() { + return health; +} + +void Creature::setHealth(int h) { + health = h; +} diff --git a/Creature.h b/Creature.h new file mode 100644 index 0000000..4c9197c --- /dev/null +++ b/Creature.h @@ -0,0 +1,33 @@ +#ifndef CREATURE_H +#define CREATURE_H + +#include "Sprite.h" + +class Creature : public Sprite { + public: + Creature(); + + // Get velocities + int getXVel(); + int getYVel(); + + // Set velocities + void setXVel(int xVel); + void setYVel(int yVel); + + // Increment velocities + void incXVel(int xVel); + void incYVel(int yVel); + + int getHealth(); + void setHealth(int h); + + protected: + // Velocities + int xVel, yVel; + + // Health + int health; +}; + +#endif diff --git a/Hazard.cpp b/Hazard.cpp new file mode 100644 index 0000000..9ecc509 --- /dev/null +++ b/Hazard.cpp @@ -0,0 +1,6 @@ +#include <iostream> +#include "Hazard.h" + +Hazard::Hazard() { + std::cout << "Hazard::Hazard(): Hazard created.\n"; +} diff --git a/Hazard.h b/Hazard.h new file mode 100644 index 0000000..4f635d2 --- /dev/null +++ b/Hazard.h @@ -0,0 +1,14 @@ +#ifndef HAZARD_H +#define HAZARD_H + +#include "MapObject.h" + +class Hazard : public MapObject { + public: + Hazard(); + + private: + // Nothing yet! +}; + +#endif diff --git a/Level.cpp b/Level.cpp new file mode 100644 index 0000000..a6cab97 --- /dev/null +++ b/Level.cpp @@ -0,0 +1,36 @@ +#include "Level.h" +#include <iostream> + +#include "Monster.h" +#include "Pickup.h" +#include "Hazard.h" +#include "Platform.h" + +Level::Level() { + std::cout << "Level::Level(): Level created.\n"; +} + +void Level::changeLevel(int levelNo) { + std::cout << "Level::changeLevel(): Loading level " << levelNo << ".\n"; + + // Creating some objects for fun/demonstration purposes + Monster monster1; + Pickup pickup1; + Hazard hazard1; + Platform platform1; + + // Placing the player for fun/demonstration purposes + player.setX(0); + player.setY(0); + + // Checking where the player is for fun/demonstration purposes + std::cout << "Level::changeLevel(): player is at " << player.getX() << ", " << player.getY() << ".\n"; +} + +void Level::move() { + //std::cout << "Level::move(): Moving level items.\n"; +} + +void Level::draw(SDL_Surface *screen) { + //std::cout << "Level::draw(): Drawing into the screen.\n"; +} @@ -0,0 +1,28 @@ +#ifndef LEVEL_H +#define LEVEL_H + +#include "Player.h" +#include "SDL/SDL.h" +#include "SDL/SDL_image.h" + +class Level { + public: + Level(); + + // Load and prepare a new level + void changeLevel(int levelNo); + + // Moves all the level's items around + void move(); + + // Draw the current scene on the screen + void draw(SDL_Surface *screen); + + // The human player + Player player; + + private: + // Nothing yet! +}; + +#endif diff --git a/MapObject.cpp b/MapObject.cpp new file mode 100644 index 0000000..5535bda --- /dev/null +++ b/MapObject.cpp @@ -0,0 +1,11 @@ +#include <iostream> +#include "MapObject.h" + +MapObject::MapObject() { + std::cout << "MapObject::MapObject(): MapObject created.\n"; + isVisible = true; +} + +int MapObject::getType() { + return type; +} diff --git a/MapObject.h b/MapObject.h new file mode 100644 index 0000000..24bc827 --- /dev/null +++ b/MapObject.h @@ -0,0 +1,21 @@ +#ifndef MAPOBJECT_H +#define MAPOBJECT_H + +#include "Sprite.h" + +class MapObject : public Sprite { + public: + MapObject(); + + // Get the numerical type + int getType(); + + // Set the type + void setType(); + + protected: + // The numerical type + int type; +}; + +#endif diff --git a/Monster.cpp b/Monster.cpp new file mode 100644 index 0000000..dea5175 --- /dev/null +++ b/Monster.cpp @@ -0,0 +1,13 @@ +#include <iostream> +#include "Monster.h" + +Monster::Monster() { + std::cout << "Monster::Monster(): Monster created.\n"; + health = 100; +} + +void Monster::kill() { + std::cout << "Monster::kill(): Killing monster.\n"; + health = 0; + isVisible = false; +} diff --git a/Monster.h b/Monster.h new file mode 100644 index 0000000..93fcde9 --- /dev/null +++ b/Monster.h @@ -0,0 +1,17 @@ +#ifndef MONSTER_H +#define MONSTER_H + +#include "Creature.h" + +class Monster : public Creature { + public: + Monster(); + + // Kill the monster, in the game sense + void kill(); + + private: + // Nothing yet! +}; + +#endif diff --git a/Pickup.cpp b/Pickup.cpp new file mode 100644 index 0000000..179e525 --- /dev/null +++ b/Pickup.cpp @@ -0,0 +1,6 @@ +#include <iostream> +#include "Pickup.h" + +Pickup::Pickup() { + std::cout << "Pickup::Pickup(): Pickup created.\n"; +} diff --git a/Pickup.h b/Pickup.h new file mode 100644 index 0000000..de62717 --- /dev/null +++ b/Pickup.h @@ -0,0 +1,14 @@ +#ifndef PICKUP_H +#define PICKUP_H + +#include "MapObject.h" + +class Pickup : public MapObject { + public: + Pickup(); + + private: + // Nothing yet! +}; + +#endif diff --git a/Platform.cpp b/Platform.cpp new file mode 100644 index 0000000..3a01a7a --- /dev/null +++ b/Platform.cpp @@ -0,0 +1,6 @@ +#include <iostream> +#include "Platform.h" + +Platform::Platform() { + std::cout << "Platform::Platform(): Platform created.\n"; +} diff --git a/Platform.h b/Platform.h new file mode 100644 index 0000000..6ad74e2 --- /dev/null +++ b/Platform.h @@ -0,0 +1,14 @@ +#ifndef PLATFORM_H +#define PLATFORM_H + +#include "MapObject.h" + +class Platform : public MapObject { + public: + Platform(); + + private: + // Nothing yet! +}; + +#endif diff --git a/Player.cpp b/Player.cpp new file mode 100644 index 0000000..a7df818 --- /dev/null +++ b/Player.cpp @@ -0,0 +1,17 @@ +#include <iostream> +#include "Player.h" + +Player::Player() { + std::cout << "Player::Player(): Player created.\n"; + health = 100; +} + +void Player::jump() { + std::cout << "Player::jump(): Jumping!.\n"; +} + +void Player::kill() { + std::cout << "Player::kill(): Killing player, resetting to start position.\n"; + health = 0; + // Do resetting stuff +} diff --git a/Player.h b/Player.h new file mode 100644 index 0000000..95e662b --- /dev/null +++ b/Player.h @@ -0,0 +1,19 @@ +#ifndef PLAYER_H +#define PLAYER_H + +#include "Creature.h" + +class Player : public Creature { + public: + Player(); + + void jump(); + + // Kill the player, in the game sense + void kill(); + + private: + // Nothing yet! +}; + +#endif @@ -0,0 +1,7 @@ +To compile: + +g++ *.cpp -lSDL -lSDL_image + +To execute: + +./a.out diff --git a/Sprite.cpp b/Sprite.cpp new file mode 100644 index 0000000..b8a8e72 --- /dev/null +++ b/Sprite.cpp @@ -0,0 +1,31 @@ +#include <iostream> +#include "Sprite.h" + +Sprite::Sprite() { + std::cout << "Sprite::Sprite(): Sprite created.\n"; + isVisible = true; +} + +int Sprite::getX() { + return x; +} + +int Sprite::getY() { + return y; +} + +void Sprite::setX(int x) { + this->x = x; +} + +void Sprite::setY(int y) { + this->y = y; +} + +bool Sprite::visible() { + return isVisible; +} + +bool Sprite::loadImage(std::string path) { + std::cout << "Sprite::loadImage(): Loading sprite " << path << ".\n"; +} diff --git a/Sprite.h b/Sprite.h new file mode 100644 index 0000000..59a4399 --- /dev/null +++ b/Sprite.h @@ -0,0 +1,35 @@ +#ifndef SPRITE_H +#define SPRITE_H + +#include <string> +#include "SDL/SDL.h" +#include "SDL/SDL_image.h" + +class Sprite { + public: + Sprite(); + + // Get coordinates + int getX(); + int getY(); + + // Set coordinates + void setX(int x); + void setY(int y); + + bool visible(); + + // Load in this sprite's image + bool loadImage(std::string path); + // This sprite's image + SDL_Surface image; + + protected: + // Coordinates + int x, y; + + // Visability + bool isVisible; +}; + +#endif diff --git a/intensemarcus.h b/intensemarcus.h new file mode 100644 index 0000000..7c3a330 --- /dev/null +++ b/intensemarcus.h @@ -0,0 +1,4 @@ +const int SCREEN_WIDTH = 800; +const int SCREEN_HEIGHT = 600; +const int SCREEN_BPP = 32; +const int FPS = 30; diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..c2b91fe --- /dev/null +++ b/main.cpp @@ -0,0 +1,63 @@ +#include <iostream> + +#include "intensemarcus.h" +#include "Level.h" +#include "SDL/SDL.h" +#include "SDL/SDL_image.h" + +int main(int argc, char* args[]) { + + // Main SDL event structure + SDL_Event event; + // Ggame window + SDL_Surface *screen; + // Current level number + int levelNo = 1; + // Main loop continues while true + bool loop = true; + // Timer start + Uint32 startTicks = 0; + + // Initialise SDL + if (SDL_Init(SDL_INIT_EVERYTHING) == -1) + return 1; + + // Turn on the main screen + if (!(screen = SDL_SetVideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE))) + return 1; + + // Set window title + SDL_WM_SetCaption("Intense Marcus", NULL); + + Level level; + level.changeLevel(levelNo); + + // Main loop + while (loop) { + // Start FPS timer + startTicks = SDL_GetTicks(); + + // Get input + while (SDL_PollEvent(&event)) { + //std::cout << "Got event.\n"; + + // Handle the user trying to close the window + if (event.type == SDL_QUIT || event.key.keysym.sym == SDLK_ESCAPE) + loop = false; + } + + // Do movement + level.move(); + + // Draw level + level.draw(screen); + + // Update screen + if (SDL_Flip(screen) == -1) + return 1; + + // Set FPS cap to 30 + if ((SDL_GetTicks() - startTicks) < 1000 / FPS) + SDL_Delay((1000 / FPS) - (SDL_GetTicks() - startTicks)); + } +} |