Add original source, circa 2006

This commit is contained in:
2026-05-18 12:47:34 -04:00
commit 0343ac3995
158 changed files with 4707 additions and 0 deletions

41
src/.svn/all-wcprops Executable file
View File

@@ -0,0 +1,41 @@
K 25
svn:wc:ra_dav:version-url
V 46
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src
END
MogCommon.h
K 25
svn:wc:ra_dav:version-url
V 58
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/MogCommon.h
END
main.cpp
K 25
svn:wc:ra_dav:version-url
V 55
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/main.cpp
END
Actor.cpp
K 25
svn:wc:ra_dav:version-url
V 56
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/Actor.cpp
END
Makefile
K 25
svn:wc:ra_dav:version-url
V 55
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/Makefile
END
Actor.h
K 25
svn:wc:ra_dav:version-url
V 54
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/Actor.h
END
bugs.txt
K 25
svn:wc:ra_dav:version-url
V 55
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/bugs.txt
END

238
src/.svn/entries Executable file
View File

@@ -0,0 +1,238 @@
10
dir
44
https://127.0.0.1/svn/aklabs/trunk/MogsAdventure/src
https://127.0.0.1/svn/aklabs
2007-05-26T21:27:56.375027Z
4
andrew
eb184899-6090-47d4-a65b-558f62f6ea1c
MogCommon.h
file
2010-02-05T03:37:53.385748Z
c9039651571ef772060dcaea834d191d
2007-05-26T21:27:56.375027Z
4
andrew
368
main.cpp
file
2010-02-05T03:37:53.385748Z
5c499c5fcea733b2d91b22f213eab9b6
2007-05-26T21:27:56.375027Z
4
andrew
5094
Actor.cpp
file
2010-02-05T03:37:53.385748Z
6b86c5a89316fceb407a1b040d8c2ab6
2007-05-26T21:27:56.375027Z
4
andrew
11006
CVS
dir
exampleINI
dir
Makefile
file
2010-02-05T03:37:53.385748Z
dd1afb701dd2545bd1d3af3e9e683881
2007-05-26T21:27:56.375027Z
4
andrew
1844
Actor.h
file
2010-02-05T03:37:53.401373Z
5babb2aa6f5116d57bc7090275c82383
2007-05-26T21:27:56.375027Z
4
andrew
3320
bugs.txt
file
2010-02-05T03:37:53.401373Z
57445286ad8b926d083c2852877554ac
2007-05-26T21:27:56.375027Z
4
andrew
171

View File

@@ -0,0 +1,496 @@
/*******************************************************************
*
* DESCRIPTION: Code for actors and sprites
*
* AUTHOR: Andrew Kesterson andrew@aklabs.net
*
* HISTORY: $Log: Actor.cpp,v $
* HISTORY: Revision 1.2 2006/01/01 19:10:00 andrew
* HISTORY: Added Robert's STLINI library and started work on the ConfigEngine. Moved some definitions around, and changed the order of includes to prevent broken declaration/definitions.
* HISTORY:
*
* DATE:12/31/2005
*
*******************************************************************/
/** include files **/
#include "MogCommon.h"
#warning This file still contains FIXMEs.
/** local definitions **/
/* default settings */
/** external functions **/
/** external data **/
/** internal functions **/
// returns true if flag y in bitmask x
#define HASBIT(x, y) (x & y == y)
// toggles flag y in bitmask x
#define TOGGLEBIT(x, y) (x = x ^ y)
void moveBBox(BoundingBox *bbox, int x, int y);
/** public data **/
/** private data **/
/** public functions **/
/** private functions **/
void moveBBox(BoundingBox *bbox, int x, int y)
{
if (bbox != NULL) {
bbox->sx += x;
bbox->sy += y;
}
}
ActorCmd::ActorCmd()
{
this->cmd = 0;
this->cmdFlags = 0;
this->target = 0;
}
ActorCmd::ActorCmd(unsigned int c, unsigned int cf, void *t)
{
this->cmd = c;
this->cmdFlags = cf;
this->target = t;
}
Sprite2D::Sprite2D()
{
this->bitmap = NULL;
this->fh = 0;
this->fw = 0;
this->numframes = 0;
this->frameticks = 0;
}
Sprite2D::Sprite2D(char *gfxname, long ticks, int frames, int fw, int fh)
{
this->init(gfxname,ticks ,frames ,fw ,fh);
}
void Sprite2D::init(char *gfxname, long ticks, int frames, int fw, int fh)
{
this->bitmap = IMG_Load(gfxname);
if ( this->bitmap == NULL ) {
cout << "failed to load bitmap : " << gfxname << ".\n";
exit(1);
}
else {
this->fh = fh;
this->fw = fw;
this->numframes = frames;
this->frameticks = ticks;
}
}
int Sprite2D::getfh()
{
return this->fh;
}
int Sprite2D::getfw()
{
return this->fw;
}
int Sprite2D::getframes()
{
return this->numframes;
}
int Sprite2D::getticks()
{
return this->frameticks;
}
void Sprite2D::drawFrame(SDL_Surface *canvas, int frame, int px, int py, int flip)
{
int sx, sy;
sx = 0 + (this->fw * frame);
sy = 0;
if ( this->bitmap == NULL ) {
cout << "I was passed a NULL bitmap. EEK! (the cat)\n";
}
// check for out of bounds image copy
if ( sx > this->bitmap->w || sy > this->bitmap->h) {
// EEK! (the cat)
// re-call this with frame 0 and return
drawFrame(canvas, 0,px,py, flip);
return;
}
if ( flip == 0) {
// don't flip
// (deprecated, I need to get rid of this)
SDL_Rect srcrect = {sx, sy, this->fw, this->fh};
SDL_Rect dstrect = {px, py, this->fw, this->fh};
SDL_BlitSurface(this->bitmap, &srcrect, canvas , &dstrect);
}
else if ( flip == 1 ) {
// mirror X
}
else if ( flip == 2 ) {
// flip Y
}
}
Sprite2D::~Sprite2D()
{
if ( this->bitmap != NULL ) {
SDL_FreeSurface(this->bitmap);
}
}
Actor2D::Actor2D()
{
this->sprite = NULL;
this->init(NULL, 0);
}
Actor2D::Actor2D(Sprite2D *spr, float speedOverride)
{
this->init(spr,speedOverride );
}
// FIXME: change the speedOverride stuff to use the new array, instead of
// a constant override.
void Actor2D::init(Sprite2D *spr, float speedOverride)
{
for ( int i = 0; i < NUMSTATES; i++ ) {
this->stateSprites[i] = NULL;
// NULL sprites in the stateSprites will make
// the sprite use its default sprite (spr)
}
if ( spr != NULL ) {
this->sprite = spr;
this->bbox.w = this->sprite->getfw();
this->bbox.h = this->sprite->getfh();
}
//this->animSpeedOverride = speedOverride;
this->animCurrFrame = 0;
this->animCurrTicks = 0;
this->bbox.sx = this->px = 0;
this->bbox.sy = this->py = 0;
this->lastTicks = 0;
this->vx = 0;
this->vy = 0;
this->state = 0;
}
int Actor2D::getpx()
{
return px;
}
int Actor2D::getpy()
{
return py;
}
int Actor2D::getvx()
{
return vx;
}
int Actor2D::getvy()
{
return vy;
}
void Actor2D::move(int x, int y)
{
px += x;
py += y;
}
void Actor2D::moveAbs(int x, int y)
{
px = x;
py = y;
}
void Actor2D::setVelocity(int x, int y)
{
vx = x;
vy = y;
}
void Actor2D::update()
{
//long newticks = SDL_GetTicks();
long newticks = clock();
long elapsed = newticks - this->lastTicks;
this->lastTicks = newticks;
static long lastState = this->state;
lastState = this->state;
this->procQueue();
if ( this->hasState(ACTOR_MOVELEFT) ) this->px -= this->vx;
if ( this->hasState(ACTOR_MOVERIGHT) ) this->px += this->vx;
if ( this->hasState(ACTOR_MOVEDOWN) ) this->py += this->vy;
if ( this->hasState(ACTOR_MOVEUP) ) this->py -= this->vy;
// FIXME: Sprite timing is semi-broken.
if ( elapsed >= sprite->getticks() && sprite->getframes() > 1 && sprite != NULL ) {
this->animCurrFrame++;
if ( this->animCurrFrame >= sprite->getframes() ) {
this->animCurrFrame = 0;
}
}
moveBBox(&this->bbox, this->vx, this->vy);
}
void Actor2D::render(SDL_Surface *canvas)
{
this->sprite->drawFrame(canvas, this->animCurrFrame,
this->px, this->py, 0);
}
long Actor2D::getState()
{
return this->state;
}
void Actor2D::setState(long state)
{
this->state = state;
}
void Actor2D::addState(long newstate)
{
if (this->hasState(newstate)) return;
else this->state = this->state | newstate;
}
void Actor2D::delState(long oldstate)
{
if ( this->hasState(oldstate) ) {
this->state = this->state ^ oldstate;
}
else {
return;
}
}
int Actor2D::hasState(long checkstate)
{
if ( (this->state & checkstate) == checkstate) {
return true;
}
else {
return false;
}
}
void Actor2D::setSprite(Sprite2D *spr)
{
if ( this->sprite != spr && spr != NULL ) {
this->sprite = spr;
this->animCurrTicks = 0;
this->animCurrFrame = 0;
this->lastTicks = 0;
}
}
void Actor2D::setStateSprite(Sprite2D *spr, long state)
{
if ( spr != NULL ) {
this->stateSprites[state] = spr;
}
}
void Actor2D::command(int cmd, int flags, void *target)
{
this->cmdList.push(ActorCmd(cmd, flags, target));
}
void Actor2D::command(ActorCmd cmd)
{
this->cmdList.push(cmd);
}
void Actor2D::procQueue()
{
ActorCmd cmd;
Sprite2D *n = NULL;
// process the actor's command queue
while ( !this->cmdList.empty() ) {
cmd = this->cmdList.front();
switch ( cmd.cmd ) {
case ACTOR_MOVELEFT:
this->addState(ACTOR_MOVELEFT);
this->setSprite(this->stateSprites[ACTOR_MOVELEFT]);
break;
case ACTOR_MOVERIGHT:
this->addState(ACTOR_MOVERIGHT);
this->setSprite(this->stateSprites[ACTOR_MOVERIGHT]);
break;
case ACTOR_MOVEDOWN:
this->addState(ACTOR_MOVEDOWN);
this->setSprite(this->stateSprites[ACTOR_MOVEDOWN]);
break;
case ACTOR_MOVEUP:
this->addState(ACTOR_MOVEUP);
this->setSprite(this->stateSprites[ACTOR_MOVEUP]);
break;
case ACTOR_ATTACK:
this->addState(ACTOR_ATTACK);
this->setSprite(this->stateSprites[ACTOR_ATTACK]);
break;
case ACTOR_IDLE:
// stop all of the current states
if ( !cmd.cmdFlags ) {
this->setState(ACTOR_IDLE);
}
// (or) get rid of any states outlined in the cmdFlags
else this->delState(cmd.cmdFlags);
if ( this->hasState(ACTOR_MOVELEFT) ) {
n = this->stateSprites[SPR_STILLLEFT];
}
else if (this->hasState(ACTOR_MOVERIGHT) ) {
n = this->stateSprites[SPR_STILLRIGHT];
}
else if (this->hasState(ACTOR_MOVEUP) ) {
n = this->stateSprites[SPR_STILLUP];
}
else if ( this->hasState(ACTOR_MOVEDOWN) ) {
n = this->stateSprites[SPR_STILLDOWN];
}
if ( n != NULL ) this->setSprite(n);
break;
case ACTOR_SEEK:
this->addState(ACTOR_SEEK);
break;
case ACTOR_SET_TYPE:
this->addState(cmd.cmdFlags);
break;
default:
break;
}
this->cmdList.pop();;
}
}
bool Actor2D::collidesWith(Actor2D *actor)
{
if ( ((actor->bbox.sx > this->bbox.sx &&
actor->bbox.sx < this->bbox.sx + this->bbox.w) &&
(actor->bbox.sy > this->bbox.sy &&
actor->bbox.sy < this->bbox.sy + this->bbox.h)) ) {
// ^^^ actor is inside of this
return false;
}
else if ((this->bbox.sx > actor->bbox.sx &&
this->bbox.sx < actor->bbox.sx + actor->bbox.w) &&
(this->bbox.sy > actor->bbox.sy &&
this->bbox.sy < actor->bbox.sy + actor->bbox.h)){
// ^^^ this is inside of actor
return false;
}
else return true;
}
// FIXME: change the speedOverride stuff to use the new array, instead of
// a constant override.
AIActor::AIActor(Sprite2D *spr, float speedOverride,
unsigned int target, unsigned int maxrange)
{
this->primTarget = target;
this->range = maxrange;
this->target = NULL;
this->sprite = NULL;
this->setSprite(spr);
//this->animSpeedOverride = speedOverride;
}
// FIXME: ugly.
void AIActor::updateAI(std::vector<Actor2D *> actorList)
{
// check the state and position of each actor within range of the AI
// to see if we need to react to them (ie, if they will change our state)
// this is the "default" AI that will wander in the given area until
// a creature of the appropriate type walks into the area, and then it will
// move to it to attack it
Actor2D *actor = NULL;
unsigned int dist;
double dX = 0.00;
double dY = 0.00;
if ( this->target == NULL || (this->target != NULL && this->target->hasState(ACTOR_DEAD))) {
for (unsigned int i = 0; i < actorList.size() ; i++ ) {
actor = actorList.at(i);
if ( actor->hasState(this->primTarget) ) {
this->target = actor;
break;
}
else continue;
}
}
if ( this->target == NULL ) {
this->command(ACTOR_IDLE, 0, NULL);
return;
}
// the distance is calculated as the hypotenuse of a triangle between the two sprites and
// an imaginary third converging point somewhere at a right angle. There's probly a faster way to
// do this.
dX = this->px - this->target->getpx();
dX *= dX;
dY = this->py - this->target->getpy();
dY *= dY;
dist = (unsigned int) sqrt( dX + dY );
if ( dist < this->range || this->target == actor) {
if ( !this->collidesWith(this->target) ) {
this->command(ACTOR_IDLE, 0, NULL);
if ( this->target->getpx() > this->px ) {
this->command(ACTOR_MOVERIGHT, 0, NULL);
}
else if ( this->target->getpx() < this->px ) {
this->command(ACTOR_MOVELEFT, 0, NULL);
}
if ( this->target->getpy() > this->py ) {
this->command(ACTOR_MOVEDOWN, 0, NULL);
}
if ( this->target->getpy() < this->py ) {
this->command(ACTOR_MOVEUP, 0, NULL);
}
this->command(ACTOR_SEEK, 0, this->target);
// do a little cheating here.... (stop the "jitter" effect)
if ( dist < (unsigned int) this->vx ) {
this->px = target->getpx();
}
if ( dist < (unsigned int) this->vy ) {
this->py = target->getpy();
}
}
else {
this->command(ACTOR_ATTACK, 0, this->target);
}
}
}

View File

@@ -0,0 +1,136 @@
#ifndef _ACTOR_H_
#define _ACTOR_H_
// no, I will NOT use #pragma once. It's not standard. don't ask.
// sprite defines
#define SPRANIMS 12 // number of different animations per sprite
// stills
#define SPR_STILLDOWN 0
#define SPR_STILLUP 1
#define SPR_STILLLEFT 2
#define SPR_STILLRIGHT 3
// walkers
#define SPR_MOVEDOWN 4
#define SPR_MOVEUP 5
#define SPR_MOVELEFT 6
#define SPR_MOVERIGHT 7
// states
#define SPR_ATTACK 8
#define SPR_DEAD 9
#define SPR_USE 10
#define SPR_TAKEDAMAGE 11
// state defines
#define NUMSTATES 20
#define ACTOR_MOVELEFT 2
#define ACTOR_MOVERIGHT 4
#define ACTOR_MOVEUP 8
#define ACTOR_MOVEDOWN 16
#define ACTOR_IDLE 32
#define ACTOR_ATTACK 64
#define ACTOR_HIDE 128
#define ACTOR_SEEK 256
#define ACTOR_DEAD 512
#define ACTOR_USE 1024
// end the AI+Sprite states, start type states
#define ACTOR_TYPE_PLAYER 2048
#define ACTOR_TYPE_BADDIE 4096
#define ACTOR_TYPE_ITEM 8192
#define ACTOR_TYPE_EFFECT 16384
// these aren't really states, they're commands
#define ACTOR_TAKEDAMAGE 32768
#define ACTOR_SET_TYPE 65536
typedef struct
{
unsigned int sx, sy, w, h;
} BoundingBox;
struct ActorCmd {
unsigned int cmd;
unsigned int cmdFlags;
void *target;
ActorCmd();
ActorCmd(unsigned int c, unsigned int cf, void *target);
};
class Sprite2D
{
protected:
SDL_Surface *bitmap;
unsigned int fw, fh;
unsigned long frameticks;
unsigned int numframes;
public:
Sprite2D();
Sprite2D(char *gfxname, long ticks, int frames, int fw, int fh);
void init(char *gfxname, long ticks, int frames, int fw, int fh);
void drawFrame(SDL_Surface *canvas, int frame, int px, int py, int flip);
int getfw();
int getfh();
int getticks();
int getframes();
~Sprite2D();
};
class Actor2D
{
protected:
int px, py;
int vx, vy;
int animCurrFrame;
int animCurrTicks;
unsigned long lastTicks;
float animSpeedOverride;
long state;
Sprite2D *sprite; // the default sprite
Sprite2D *stateSprites[NUMSTATES]; // the per-state sprites
std::queue<ActorCmd> cmdList; // FIFO command queue for the actor
void setState(long state);
void addState(long state);
void delState(long state);
void procQueue();
public:
BoundingBox bbox;
Actor2D();
Actor2D(Sprite2D *spr, float speedOverride);
void init(Sprite2D *spr, float speedOverride);
int getpx();
int getpy();
int getvx();
int getvy();
// state manipulation
long getState();
int hasState(long state);
// position and velocity manipulation
void move(int x, int y);
void moveAbs(int x, int y);
void setVelocity(int x, int y);
void update();
bool collidesWith(Actor2D *actor);
// rendering and sprite manipulation
void setSprite(Sprite2D *spr);
void render(SDL_Surface *canvas);
void setStateSprite(Sprite2D *spr, long state);
// other stuff
void command(int cmd, int flags, void *target);
void command(ActorCmd cmd);
};
class AIActor : public Actor2D
{
protected:
unsigned int primTarget; // type of actor it targets
unsigned int range; // the range it will pursue the target at
Actor2D *target; // the target it's currently moving to
public:
AIActor(Sprite2D *spr, float speedOverride,
unsigned int target, unsigned int maxrange);
void updateAI(std::vector<Actor2D *> actorList);
};
#endif // _ACTOR_H_

View File

@@ -0,0 +1,92 @@
# Visual SlickEdit generated file. Do not edit this file except in designated areas.
# -----Begin user-editable area-----
# -----End user-editable area-----
# Make command to use for dependencies
MAKECMD=gmake
# If no configuration is specified, "Debug" will be used
ifndef "CFG"
CFG=Debug
endif
#
# Configuration: Debug
#
ifeq "$(CFG)" "Debug"
OUTDIR=Debug
OUTFILE=$(OUTDIR)/Mogs-Adventure
CFG_INC=
CFG_LIB=-lSDL_mixer -lSDL_sound -lSDL_flic -lSDL_net -lSDL_image
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/Actor.o $(OUTDIR)/main.o
OBJ=$(COMMON_OBJ) $(CFG_OBJ)
COMPILE=g++ -c -DLINUX -O0 -g3 -ggdb -p -pg -Wall -o "$(OUTDIR)/$(*F).o" $(CFG_INC) "$<" `sdl-config --cflags`
LINK=g++ -O0 -g3 -ggdb -p -pg -Wall -o "$(OUTFILE)" $(OBJ) $(CFG_LIB) `sdl-config --libs`
# Pattern rules
$(OUTDIR)/%.o : src/%.cpp
$(COMPILE)
# Build rules
all: $(OUTFILE)
$(OUTFILE): $(OUTDIR) $(OBJ)
$(LINK)
$(OUTDIR):
mkdir -p "$(OUTDIR)"
# Rebuild this project
rebuild: cleanall all
# Clean this project
clean:
rm -f $(OUTFILE)
rm -f $(OBJ)
# Clean this project and all dependencies
cleanall: clean
endif
#
# Configuration: Release
#
ifeq "$(CFG)" "Release"
OUTDIR=Release
OUTFILE=$(OUTDIR)/Mogs-Adventure
CFG_INC=
CFG_LIB=-lSDL_mixer -lSDL_sound -lSDL_flic -lSDL_net -lSDL_image
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/Actor.o $(OUTDIR)/main.o
OBJ=$(COMMON_OBJ) $(CFG_OBJ)
COMPILE=g++ -c -DLINUX -O2 -o "$(OUTDIR)/$(*F).o" $(CFG_INC) "$<" `sdl-config --cflags`
LINK=g++ -O2 -o "$(OUTFILE)" $(OBJ) $(CFG_LIB) `sdl-config --libs`
# Pattern rules
$(OUTDIR)/%.o : src/%.cpp
$(COMPILE)
# Build rules
all: $(OUTFILE)
$(OUTFILE): $(OUTDIR) $(OBJ)
$(LINK)
$(OUTDIR):
mkdir -p "$(OUTDIR)"
# Rebuild this project
rebuild: cleanall all
# Clean this project
clean:
rm -f $(OUTFILE)
rm -f $(OBJ)
# Clean this project and all dependencies
cleanall: clean
endif

View File

@@ -0,0 +1,21 @@
#ifndef _MOGCOMMON_H_
#define _MOGCOMMON_H_
#include <SDL.h>
#include <SDL_image.h>
// won't need these until later .....
//#include <SDL_flic.h>
//#include <SDL/SDL_mixer.h>
//#include <SDL/SDL_net.h>
//#include <SDL/SDL_sound.h>
#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include "Actor.h"
using std::cout;
#endif // _MOGCOMMON_H_

View File

@@ -0,0 +1,3 @@
Sprite timing is off; sprites will sometimes hold one frame forever, or animate extremely quickly.
accessing Actor2D::cmdList causes segfault. But only for AIActor ... ?

View File

@@ -0,0 +1,179 @@
#include "MogCommon.h"
SDL_Surface *screen;
Sprite2D sprites[50];
Sprite2D **sprind;
char *gfxFiles[] = {
"gfx/Mog - Front.gif",
"gfx/Mog - Back.gif",
"gfx/Mog - Left.gif",
"gfx/Mog - Right.gif",
"gfx/Mog - Walk Front.gif",
"gfx/Mog - Walk Back.gif",
"gfx/Mog - Walk Left.gif",
"gfx/Mog - Walk Right.gif",
"gfx/Deceased - Down.gif",
"gfx/Deceased - Up.gif",
"gfx/Deceased - Left.gif",
"gfx/Deceased - Right.gif",
"gfx/Deceased - Walk Front.gif",
"gfx/Deceased - Walk Back.gif",
"gfx/Deceased - Walk Left.gif",
"gfx/Deceased - Walk Right.gif",
"gfx/Deceased - Attack Front.gif",
"gfx/Deceased - Attack Rear.gif",
"gfx/Deceased - Dead.gif"
};
int main(int argc, char **argv)
{
bool running = true;
SDL_Event nextEvent;
int i = 0;
if ( SDL_Init(SDL_INIT_EVERYTHING) < 0) {
cout << "Couldn't init SDL!!\n";
cout << SDL_GetError();
exit(-1);
}
screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (!screen) {
cout << "Couldn't get screen!\n";
cout << SDL_GetError();
exit(-1);
}
SDL_WM_SetCaption("KUPO! : Mog's Adventure (debug proof pre-0.1a)", NULL);
/* everything from here down is just a proof for now */
SDL_Rect s = {0, 0, 640, 480};
// do the stills
for (i = 0; i < 4 ; i++ ) {
sprites[i].init(gfxFiles[i], 45, 0, 32, 44);
}
// do the walkers
for (i = 4; i < 8 ; i++ ) {
sprites[i].init(gfxFiles[i], 45, 4, 32, 44);
}
// do the stills
for (i = 8; i < 12 ; i++ ) {
sprites[i].init(gfxFiles[i], 45, 0, 68, 60);
}
// do the walkers
for (i = 12; i < 16 ; i++ ) {
sprites[i].init(gfxFiles[i], 45, 4, 68, 60);
}
Sprite2D theBackground("gfx/samplebg.jpg", 0, 1, 640, 480);
Actor2D theActor(&sprites[SPR_STILLDOWN], 0.0f);
theActor.move(90, 90);
theActor.setVelocity(4, 4);
theActor.setStateSprite(&sprites[SPR_MOVEDOWN],
SPR_MOVEDOWN);
theActor.setStateSprite(&sprites[SPR_MOVELEFT],
SPR_MOVELEFT);
theActor.setStateSprite(&sprites[SPR_MOVERIGHT],
SPR_MOVERIGHT);
theActor.setStateSprite(&sprites[SPR_MOVEUP],
SPR_MOVEUP);
theActor.setStateSprite(&sprites[SPR_STILLDOWN],
SPR_STILLDOWN);
theActor.setStateSprite(&sprites[SPR_STILLLEFT],
SPR_STILLLEFT);
theActor.setStateSprite(&sprites[SPR_STILLRIGHT],
SPR_STILLRIGHT);
theActor.command(ACTOR_SET_TYPE, ACTOR_TYPE_PLAYER, NULL);
AIActor theBaddie(&sprites[8+SPR_STILLDOWN], 0.0f, ACTOR_TYPE_PLAYER, 500);
theBaddie.move(50,50);
theBaddie.setStateSprite(&sprites[8+SPR_MOVEDOWN],
SPR_MOVEDOWN);
theBaddie.setStateSprite(&sprites[8+SPR_MOVELEFT],
SPR_MOVELEFT);
theBaddie.setStateSprite(&sprites[8+SPR_MOVERIGHT],
SPR_MOVERIGHT);
theBaddie.setStateSprite(&sprites[8+SPR_MOVEUP],
SPR_MOVEUP);
theBaddie.setStateSprite(&sprites[8+SPR_STILLDOWN],
SPR_STILLDOWN);
theBaddie.setStateSprite(&sprites[8+SPR_STILLLEFT],
SPR_STILLLEFT);
theBaddie.setStateSprite(&sprites[8+SPR_STILLRIGHT],
SPR_STILLRIGHT);
theBaddie.setVelocity(3, 3);
theBaddie.command(ACTOR_SET_TYPE, ACTOR_TYPE_BADDIE, NULL);
theBaddie.command(ACTOR_IDLE, 0, NULL);
std::vector<Actor2D *> actorList;
actorList.clear();
actorList.push_back(&theActor);
actorList.push_back(&theBaddie);
while ( running == true ) {
theBackground.drawFrame(screen, 0, 0, 0, 0);
theActor.render(screen);
theActor.update();
theBaddie.render(screen);
theBaddie.updateAI(actorList);
theBaddie.update();
SDL_Flip(screen);
SDL_FillRect(screen, &s, 0);
SDL_PumpEvents();
if ( SDL_PollEvent(&nextEvent) > 0 ) {
switch (nextEvent.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
switch (nextEvent.key.state) {
case SDL_PRESSED:
if ( nextEvent.key.keysym.sym == SDLK_UP ) {
theActor.command(ACTOR_MOVEUP, 0, NULL);
}
else if ( nextEvent.key.keysym.sym == SDLK_DOWN) {
theActor.command(ACTOR_MOVEDOWN, 0, NULL);
}
else if ( nextEvent.key.keysym.sym == SDLK_RIGHT ) {
theActor.command(ACTOR_MOVERIGHT, 0, NULL);
}
else if ( nextEvent.key.keysym.sym == SDLK_LEFT) {
theActor.command(ACTOR_MOVELEFT, 0, NULL);
}
else if ( nextEvent.key.keysym.sym == SDLK_ESCAPE) {
running = false;
}
break;
case SDL_RELEASED:
if ( nextEvent.key.keysym.sym == SDLK_DOWN
&& theActor.hasState(ACTOR_MOVEDOWN)) {
theActor.command(ACTOR_IDLE, ACTOR_MOVEDOWN, NULL);
}
if ( nextEvent.key.keysym.sym == SDLK_UP
&& theActor.hasState(ACTOR_MOVEUP) ) {
theActor.command(ACTOR_IDLE, ACTOR_MOVEUP, NULL);
}
if ( nextEvent.key.keysym.sym == SDLK_LEFT
&& theActor.hasState(ACTOR_MOVELEFT) ) {
theActor.command(ACTOR_IDLE, ACTOR_MOVELEFT, NULL);
}
if ( nextEvent.key.keysym.sym == SDLK_RIGHT
&& theActor.hasState(ACTOR_MOVERIGHT) ) {
theActor.command(ACTOR_IDLE, ACTOR_MOVERIGHT, NULL);
}
break;
}
break;
case SDL_QUIT:
SDL_Quit();
return 0;
}
}
}
}

496
src/Actor.cpp Executable file
View File

@@ -0,0 +1,496 @@
/*******************************************************************
*
* DESCRIPTION: Code for actors and sprites
*
* AUTHOR: Andrew Kesterson andrew@aklabs.net
*
* HISTORY: $Log: Actor.cpp,v $
* HISTORY: Revision 1.2 2006/01/01 19:10:00 andrew
* HISTORY: Added Robert's STLINI library and started work on the ConfigEngine. Moved some definitions around, and changed the order of includes to prevent broken declaration/definitions.
* HISTORY:
*
* DATE:12/31/2005
*
*******************************************************************/
/** include files **/
#include "MogCommon.h"
#warning This file still contains FIXMEs.
/** local definitions **/
/* default settings */
/** external functions **/
/** external data **/
/** internal functions **/
// returns true if flag y in bitmask x
#define HASBIT(x, y) (x & y == y)
// toggles flag y in bitmask x
#define TOGGLEBIT(x, y) (x = x ^ y)
void moveBBox(BoundingBox *bbox, int x, int y);
/** public data **/
/** private data **/
/** public functions **/
/** private functions **/
void moveBBox(BoundingBox *bbox, int x, int y)
{
if (bbox != NULL) {
bbox->sx += x;
bbox->sy += y;
}
}
ActorCmd::ActorCmd()
{
this->cmd = 0;
this->cmdFlags = 0;
this->target = 0;
}
ActorCmd::ActorCmd(unsigned int c, unsigned int cf, void *t)
{
this->cmd = c;
this->cmdFlags = cf;
this->target = t;
}
Sprite2D::Sprite2D()
{
this->bitmap = NULL;
this->fh = 0;
this->fw = 0;
this->numframes = 0;
this->frameticks = 0;
}
Sprite2D::Sprite2D(char *gfxname, long ticks, int frames, int fw, int fh)
{
this->init(gfxname,ticks ,frames ,fw ,fh);
}
void Sprite2D::init(char *gfxname, long ticks, int frames, int fw, int fh)
{
this->bitmap = IMG_Load(gfxname);
if ( this->bitmap == NULL ) {
cout << "failed to load bitmap : " << gfxname << ".\n";
exit(1);
}
else {
this->fh = fh;
this->fw = fw;
this->numframes = frames;
this->frameticks = ticks;
}
}
int Sprite2D::getfh()
{
return this->fh;
}
int Sprite2D::getfw()
{
return this->fw;
}
int Sprite2D::getframes()
{
return this->numframes;
}
int Sprite2D::getticks()
{
return this->frameticks;
}
void Sprite2D::drawFrame(SDL_Surface *canvas, int frame, int px, int py, int flip)
{
int sx, sy;
sx = 0 + (this->fw * frame);
sy = 0;
if ( this->bitmap == NULL ) {
cout << "I was passed a NULL bitmap. EEK! (the cat)\n";
}
// check for out of bounds image copy
if ( sx > this->bitmap->w || sy > this->bitmap->h) {
// EEK! (the cat)
// re-call this with frame 0 and return
drawFrame(canvas, 0,px,py, flip);
return;
}
if ( flip == 0) {
// don't flip
// (deprecated, I need to get rid of this)
SDL_Rect srcrect = {sx, sy, this->fw, this->fh};
SDL_Rect dstrect = {px, py, this->fw, this->fh};
SDL_BlitSurface(this->bitmap, &srcrect, canvas , &dstrect);
}
else if ( flip == 1 ) {
// mirror X
}
else if ( flip == 2 ) {
// flip Y
}
}
Sprite2D::~Sprite2D()
{
if ( this->bitmap != NULL ) {
SDL_FreeSurface(this->bitmap);
}
}
Actor2D::Actor2D()
{
this->sprite = NULL;
this->init(NULL, 0);
}
Actor2D::Actor2D(Sprite2D *spr, float speedOverride)
{
this->init(spr,speedOverride );
}
// FIXME: change the speedOverride stuff to use the new array, instead of
// a constant override.
void Actor2D::init(Sprite2D *spr, float speedOverride)
{
for ( int i = 0; i < NUMSTATES; i++ ) {
this->stateSprites[i] = NULL;
// NULL sprites in the stateSprites will make
// the sprite use its default sprite (spr)
}
if ( spr != NULL ) {
this->sprite = spr;
this->bbox.w = this->sprite->getfw();
this->bbox.h = this->sprite->getfh();
}
//this->animSpeedOverride = speedOverride;
this->animCurrFrame = 0;
this->animCurrTicks = 0;
this->bbox.sx = this->px = 0;
this->bbox.sy = this->py = 0;
this->lastTicks = 0;
this->vx = 0;
this->vy = 0;
this->state = 0;
}
int Actor2D::getpx()
{
return px;
}
int Actor2D::getpy()
{
return py;
}
int Actor2D::getvx()
{
return vx;
}
int Actor2D::getvy()
{
return vy;
}
void Actor2D::move(int x, int y)
{
px += x;
py += y;
}
void Actor2D::moveAbs(int x, int y)
{
px = x;
py = y;
}
void Actor2D::setVelocity(int x, int y)
{
vx = x;
vy = y;
}
void Actor2D::update()
{
//long newticks = SDL_GetTicks();
long newticks = clock();
long elapsed = newticks - this->lastTicks;
this->lastTicks = newticks;
static long lastState = this->state;
lastState = this->state;
this->procQueue();
if ( this->hasState(ACTOR_MOVELEFT) ) this->px -= this->vx;
if ( this->hasState(ACTOR_MOVERIGHT) ) this->px += this->vx;
if ( this->hasState(ACTOR_MOVEDOWN) ) this->py += this->vy;
if ( this->hasState(ACTOR_MOVEUP) ) this->py -= this->vy;
// FIXME: Sprite timing is semi-broken.
if ( elapsed >= sprite->getticks() && sprite->getframes() > 1 && sprite != NULL ) {
this->animCurrFrame++;
if ( this->animCurrFrame >= sprite->getframes() ) {
this->animCurrFrame = 0;
}
}
moveBBox(&this->bbox, this->vx, this->vy);
}
void Actor2D::render(SDL_Surface *canvas)
{
this->sprite->drawFrame(canvas, this->animCurrFrame,
this->px, this->py, 0);
}
long Actor2D::getState()
{
return this->state;
}
void Actor2D::setState(long state)
{
this->state = state;
}
void Actor2D::addState(long newstate)
{
if (this->hasState(newstate)) return;
else this->state = this->state | newstate;
}
void Actor2D::delState(long oldstate)
{
if ( this->hasState(oldstate) ) {
this->state = this->state ^ oldstate;
}
else {
return;
}
}
int Actor2D::hasState(long checkstate)
{
if ( (this->state & checkstate) == checkstate) {
return true;
}
else {
return false;
}
}
void Actor2D::setSprite(Sprite2D *spr)
{
if ( this->sprite != spr && spr != NULL ) {
this->sprite = spr;
this->animCurrTicks = 0;
this->animCurrFrame = 0;
this->lastTicks = 0;
}
}
void Actor2D::setStateSprite(Sprite2D *spr, long state)
{
if ( spr != NULL ) {
this->stateSprites[state] = spr;
}
}
void Actor2D::command(int cmd, int flags, void *target)
{
this->cmdList.push(ActorCmd(cmd, flags, target));
}
void Actor2D::command(ActorCmd cmd)
{
this->cmdList.push(cmd);
}
void Actor2D::procQueue()
{
ActorCmd cmd;
Sprite2D *n = NULL;
// process the actor's command queue
while ( !this->cmdList.empty() ) {
cmd = this->cmdList.front();
switch ( cmd.cmd ) {
case ACTOR_MOVELEFT:
this->addState(ACTOR_MOVELEFT);
this->setSprite(this->stateSprites[ACTOR_MOVELEFT]);
break;
case ACTOR_MOVERIGHT:
this->addState(ACTOR_MOVERIGHT);
this->setSprite(this->stateSprites[ACTOR_MOVERIGHT]);
break;
case ACTOR_MOVEDOWN:
this->addState(ACTOR_MOVEDOWN);
this->setSprite(this->stateSprites[ACTOR_MOVEDOWN]);
break;
case ACTOR_MOVEUP:
this->addState(ACTOR_MOVEUP);
this->setSprite(this->stateSprites[ACTOR_MOVEUP]);
break;
case ACTOR_ATTACK:
this->addState(ACTOR_ATTACK);
this->setSprite(this->stateSprites[ACTOR_ATTACK]);
break;
case ACTOR_IDLE:
// stop all of the current states
if ( !cmd.cmdFlags ) {
this->setState(ACTOR_IDLE);
}
// (or) get rid of any states outlined in the cmdFlags
else this->delState(cmd.cmdFlags);
if ( this->hasState(ACTOR_MOVELEFT) ) {
n = this->stateSprites[SPR_STILLLEFT];
}
else if (this->hasState(ACTOR_MOVERIGHT) ) {
n = this->stateSprites[SPR_STILLRIGHT];
}
else if (this->hasState(ACTOR_MOVEUP) ) {
n = this->stateSprites[SPR_STILLUP];
}
else if ( this->hasState(ACTOR_MOVEDOWN) ) {
n = this->stateSprites[SPR_STILLDOWN];
}
if ( n != NULL ) this->setSprite(n);
break;
case ACTOR_SEEK:
this->addState(ACTOR_SEEK);
break;
case ACTOR_SET_TYPE:
this->addState(cmd.cmdFlags);
break;
default:
break;
}
this->cmdList.pop();;
}
}
bool Actor2D::collidesWith(Actor2D *actor)
{
if ( ((actor->bbox.sx > this->bbox.sx &&
actor->bbox.sx < this->bbox.sx + this->bbox.w) &&
(actor->bbox.sy > this->bbox.sy &&
actor->bbox.sy < this->bbox.sy + this->bbox.h)) ) {
// ^^^ actor is inside of this
return false;
}
else if ((this->bbox.sx > actor->bbox.sx &&
this->bbox.sx < actor->bbox.sx + actor->bbox.w) &&
(this->bbox.sy > actor->bbox.sy &&
this->bbox.sy < actor->bbox.sy + actor->bbox.h)){
// ^^^ this is inside of actor
return false;
}
else return true;
}
// FIXME: change the speedOverride stuff to use the new array, instead of
// a constant override.
AIActor::AIActor(Sprite2D *spr, float speedOverride,
unsigned int target, unsigned int maxrange)
{
this->primTarget = target;
this->range = maxrange;
this->target = NULL;
this->sprite = NULL;
this->setSprite(spr);
//this->animSpeedOverride = speedOverride;
}
// FIXME: ugly.
void AIActor::updateAI(std::vector<Actor2D *> actorList)
{
// check the state and position of each actor within range of the AI
// to see if we need to react to them (ie, if they will change our state)
// this is the "default" AI that will wander in the given area until
// a creature of the appropriate type walks into the area, and then it will
// move to it to attack it
Actor2D *actor = NULL;
unsigned int dist;
double dX = 0.00;
double dY = 0.00;
if ( this->target == NULL || (this->target != NULL && this->target->hasState(ACTOR_DEAD))) {
for (unsigned int i = 0; i < actorList.size() ; i++ ) {
actor = actorList.at(i);
if ( actor->hasState(this->primTarget) ) {
this->target = actor;
break;
}
else continue;
}
}
if ( this->target == NULL ) {
this->command(ACTOR_IDLE, 0, NULL);
return;
}
// the distance is calculated as the hypotenuse of a triangle between the two sprites and
// an imaginary third converging point somewhere at a right angle. There's probly a faster way to
// do this.
dX = this->px - this->target->getpx();
dX *= dX;
dY = this->py - this->target->getpy();
dY *= dY;
dist = (unsigned int) sqrt( dX + dY );
if ( dist < this->range || this->target == actor) {
if ( !this->collidesWith(this->target) ) {
this->command(ACTOR_IDLE, 0, NULL);
if ( this->target->getpx() > this->px ) {
this->command(ACTOR_MOVERIGHT, 0, NULL);
}
else if ( this->target->getpx() < this->px ) {
this->command(ACTOR_MOVELEFT, 0, NULL);
}
if ( this->target->getpy() > this->py ) {
this->command(ACTOR_MOVEDOWN, 0, NULL);
}
if ( this->target->getpy() < this->py ) {
this->command(ACTOR_MOVEUP, 0, NULL);
}
this->command(ACTOR_SEEK, 0, this->target);
// do a little cheating here.... (stop the "jitter" effect)
if ( dist < (unsigned int) this->vx ) {
this->px = target->getpx();
}
if ( dist < (unsigned int) this->vy ) {
this->py = target->getpy();
}
}
else {
this->command(ACTOR_ATTACK, 0, this->target);
}
}
}

136
src/Actor.h Executable file
View File

@@ -0,0 +1,136 @@
#ifndef _ACTOR_H_
#define _ACTOR_H_
// no, I will NOT use #pragma once. It's not standard. don't ask.
// sprite defines
#define SPRANIMS 12 // number of different animations per sprite
// stills
#define SPR_STILLDOWN 0
#define SPR_STILLUP 1
#define SPR_STILLLEFT 2
#define SPR_STILLRIGHT 3
// walkers
#define SPR_MOVEDOWN 4
#define SPR_MOVEUP 5
#define SPR_MOVELEFT 6
#define SPR_MOVERIGHT 7
// states
#define SPR_ATTACK 8
#define SPR_DEAD 9
#define SPR_USE 10
#define SPR_TAKEDAMAGE 11
// state defines
#define NUMSTATES 20
#define ACTOR_MOVELEFT 2
#define ACTOR_MOVERIGHT 4
#define ACTOR_MOVEUP 8
#define ACTOR_MOVEDOWN 16
#define ACTOR_IDLE 32
#define ACTOR_ATTACK 64
#define ACTOR_HIDE 128
#define ACTOR_SEEK 256
#define ACTOR_DEAD 512
#define ACTOR_USE 1024
// end the AI+Sprite states, start type states
#define ACTOR_TYPE_PLAYER 2048
#define ACTOR_TYPE_BADDIE 4096
#define ACTOR_TYPE_ITEM 8192
#define ACTOR_TYPE_EFFECT 16384
// these aren't really states, they're commands
#define ACTOR_TAKEDAMAGE 32768
#define ACTOR_SET_TYPE 65536
typedef struct
{
unsigned int sx, sy, w, h;
} BoundingBox;
struct ActorCmd {
unsigned int cmd;
unsigned int cmdFlags;
void *target;
ActorCmd();
ActorCmd(unsigned int c, unsigned int cf, void *target);
};
class Sprite2D
{
protected:
SDL_Surface *bitmap;
unsigned int fw, fh;
unsigned long frameticks;
unsigned int numframes;
public:
Sprite2D();
Sprite2D(char *gfxname, long ticks, int frames, int fw, int fh);
void init(char *gfxname, long ticks, int frames, int fw, int fh);
void drawFrame(SDL_Surface *canvas, int frame, int px, int py, int flip);
int getfw();
int getfh();
int getticks();
int getframes();
~Sprite2D();
};
class Actor2D
{
protected:
int px, py;
int vx, vy;
int animCurrFrame;
int animCurrTicks;
unsigned long lastTicks;
float animSpeedOverride;
long state;
Sprite2D *sprite; // the default sprite
Sprite2D *stateSprites[NUMSTATES]; // the per-state sprites
std::queue<ActorCmd> cmdList; // FIFO command queue for the actor
void setState(long state);
void addState(long state);
void delState(long state);
void procQueue();
public:
BoundingBox bbox;
Actor2D();
Actor2D(Sprite2D *spr, float speedOverride);
void init(Sprite2D *spr, float speedOverride);
int getpx();
int getpy();
int getvx();
int getvy();
// state manipulation
long getState();
int hasState(long state);
// position and velocity manipulation
void move(int x, int y);
void moveAbs(int x, int y);
void setVelocity(int x, int y);
void update();
bool collidesWith(Actor2D *actor);
// rendering and sprite manipulation
void setSprite(Sprite2D *spr);
void render(SDL_Surface *canvas);
void setStateSprite(Sprite2D *spr, long state);
// other stuff
void command(int cmd, int flags, void *target);
void command(ActorCmd cmd);
};
class AIActor : public Actor2D
{
protected:
unsigned int primTarget; // type of actor it targets
unsigned int range; // the range it will pursue the target at
Actor2D *target; // the target it's currently moving to
public:
AIActor(Sprite2D *spr, float speedOverride,
unsigned int target, unsigned int maxrange);
void updateAI(std::vector<Actor2D *> actorList);
};
#endif // _ACTOR_H_

23
src/CVS/.svn/all-wcprops Executable file
View File

@@ -0,0 +1,23 @@
K 25
svn:wc:ra_dav:version-url
V 50
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/CVS
END
Repository
K 25
svn:wc:ra_dav:version-url
V 61
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/CVS/Repository
END
Root
K 25
svn:wc:ra_dav:version-url
V 55
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/CVS/Root
END
Entries
K 25
svn:wc:ra_dav:version-url
V 58
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/CVS/Entries
END

130
src/CVS/.svn/entries Executable file
View File

@@ -0,0 +1,130 @@
10
dir
44
https://127.0.0.1/svn/aklabs/trunk/MogsAdventure/src/CVS
https://127.0.0.1/svn/aklabs
2007-05-26T21:27:56.375027Z
4
andrew
eb184899-6090-47d4-a65b-558f62f6ea1c
Repository
file
2010-02-05T03:37:53.073248Z
bd8570ec02ca79e90b9e69ee4ae41d36
2007-05-26T21:27:56.375027Z
4
andrew
24
Root
file
2010-02-05T03:37:53.073248Z
7af14a164593104c1e7a07a572dd352a
2007-05-26T21:27:56.375027Z
4
andrew
24
Entries
file
2010-02-05T03:37:53.073248Z
bec34991a8f1e32c337b7b0319f40f64
2007-05-26T21:27:56.375027Z
4
andrew
286

View File

@@ -0,0 +1,7 @@
/Actor.cpp/1.2/Sun Jan 1 19:10:00 2006//
/Actor.h/1.1.1.1/Sat Dec 31 23:55:08 2005//
/Makefile/1.1.1.1/Sat Dec 31 23:55:08 2005//
/MogCommon.h/1.1.1.1/Sat Dec 31 23:55:08 2005//
/bugs.txt/1.1.1.1/Sat Dec 31 23:55:08 2005//
/main.cpp/1.1.1.1/Sat Dec 31 23:55:08 2005//
D/exampleINI////

View File

@@ -0,0 +1 @@
games/MogsAdventure/src

View File

@@ -0,0 +1 @@
andrew@gabbo:/home/cvsd

7
src/CVS/Entries Executable file
View File

@@ -0,0 +1,7 @@
/Actor.cpp/1.2/Sun Jan 1 19:10:00 2006//
/Actor.h/1.1.1.1/Sat Dec 31 23:55:08 2005//
/Makefile/1.1.1.1/Sat Dec 31 23:55:08 2005//
/MogCommon.h/1.1.1.1/Sat Dec 31 23:55:08 2005//
/bugs.txt/1.1.1.1/Sat Dec 31 23:55:08 2005//
/main.cpp/1.1.1.1/Sat Dec 31 23:55:08 2005//
D/exampleINI////

1
src/CVS/Repository Executable file
View File

@@ -0,0 +1 @@
games/MogsAdventure/src

1
src/CVS/Root Executable file
View File

@@ -0,0 +1 @@
andrew@gabbo:/home/cvsd

92
src/Makefile Executable file
View File

@@ -0,0 +1,92 @@
# Visual SlickEdit generated file. Do not edit this file except in designated areas.
# -----Begin user-editable area-----
# -----End user-editable area-----
# Make command to use for dependencies
MAKECMD=gmake
# If no configuration is specified, "Debug" will be used
ifndef "CFG"
CFG=Debug
endif
#
# Configuration: Debug
#
ifeq "$(CFG)" "Debug"
OUTDIR=Debug
OUTFILE=$(OUTDIR)/Mogs-Adventure
CFG_INC=
CFG_LIB=-lSDL_mixer -lSDL_sound -lSDL_flic -lSDL_net -lSDL_image
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/Actor.o $(OUTDIR)/main.o
OBJ=$(COMMON_OBJ) $(CFG_OBJ)
COMPILE=g++ -c -DLINUX -O0 -g3 -ggdb -p -pg -Wall -o "$(OUTDIR)/$(*F).o" $(CFG_INC) "$<" `sdl-config --cflags`
LINK=g++ -O0 -g3 -ggdb -p -pg -Wall -o "$(OUTFILE)" $(OBJ) $(CFG_LIB) `sdl-config --libs`
# Pattern rules
$(OUTDIR)/%.o : src/%.cpp
$(COMPILE)
# Build rules
all: $(OUTFILE)
$(OUTFILE): $(OUTDIR) $(OBJ)
$(LINK)
$(OUTDIR):
mkdir -p "$(OUTDIR)"
# Rebuild this project
rebuild: cleanall all
# Clean this project
clean:
rm -f $(OUTFILE)
rm -f $(OBJ)
# Clean this project and all dependencies
cleanall: clean
endif
#
# Configuration: Release
#
ifeq "$(CFG)" "Release"
OUTDIR=Release
OUTFILE=$(OUTDIR)/Mogs-Adventure
CFG_INC=
CFG_LIB=-lSDL_mixer -lSDL_sound -lSDL_flic -lSDL_net -lSDL_image
CFG_OBJ=
COMMON_OBJ=$(OUTDIR)/Actor.o $(OUTDIR)/main.o
OBJ=$(COMMON_OBJ) $(CFG_OBJ)
COMPILE=g++ -c -DLINUX -O2 -o "$(OUTDIR)/$(*F).o" $(CFG_INC) "$<" `sdl-config --cflags`
LINK=g++ -O2 -o "$(OUTFILE)" $(OBJ) $(CFG_LIB) `sdl-config --libs`
# Pattern rules
$(OUTDIR)/%.o : src/%.cpp
$(COMPILE)
# Build rules
all: $(OUTFILE)
$(OUTFILE): $(OUTDIR) $(OBJ)
$(LINK)
$(OUTDIR):
mkdir -p "$(OUTDIR)"
# Rebuild this project
rebuild: cleanall all
# Clean this project
clean:
rm -f $(OUTFILE)
rm -f $(OBJ)
# Clean this project and all dependencies
cleanall: clean
endif

21
src/MogCommon.h Executable file
View File

@@ -0,0 +1,21 @@
#ifndef _MOGCOMMON_H_
#define _MOGCOMMON_H_
#include <SDL.h>
#include <SDL_image.h>
// won't need these until later .....
//#include <SDL_flic.h>
//#include <SDL/SDL_mixer.h>
//#include <SDL/SDL_net.h>
//#include <SDL/SDL_sound.h>
#include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include "Actor.h"
using std::cout;
#endif // _MOGCOMMON_H_

3
src/bugs.txt Executable file
View File

@@ -0,0 +1,3 @@
Sprite timing is off; sprites will sometimes hold one frame forever, or animate extremely quickly.
accessing Actor2D::cmdList causes segfault. But only for AIActor ... ?

View File

@@ -0,0 +1,5 @@
K 25
svn:wc:ra_dav:version-url
V 57
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/exampleINI
END

31
src/exampleINI/.svn/entries Executable file
View File

@@ -0,0 +1,31 @@
10
dir
44
https://127.0.0.1/svn/aklabs/trunk/MogsAdventure/src/exampleINI
https://127.0.0.1/svn/aklabs
2007-05-26T21:27:56.375027Z
4
andrew
eb184899-6090-47d4-a65b-558f62f6ea1c
CVS
dir

View File

@@ -0,0 +1,23 @@
K 25
svn:wc:ra_dav:version-url
V 61
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/exampleINI/CVS
END
Repository
K 25
svn:wc:ra_dav:version-url
V 72
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/exampleINI/CVS/Repository
END
Root
K 25
svn:wc:ra_dav:version-url
V 66
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/exampleINI/CVS/Root
END
Entries
K 25
svn:wc:ra_dav:version-url
V 69
/svn/aklabs/!svn/ver/4/trunk/MogsAdventure/src/exampleINI/CVS/Entries
END

130
src/exampleINI/CVS/.svn/entries Executable file
View File

@@ -0,0 +1,130 @@
10
dir
44
https://127.0.0.1/svn/aklabs/trunk/MogsAdventure/src/exampleINI/CVS
https://127.0.0.1/svn/aklabs
2007-05-26T21:27:56.375027Z
4
andrew
eb184899-6090-47d4-a65b-558f62f6ea1c
Repository
file
2010-02-05T03:37:53.323248Z
3e285ef3fe728804ac79b647c491685d
2007-05-26T21:27:56.375027Z
4
andrew
35
Root
file
2010-02-05T03:37:53.323248Z
7af14a164593104c1e7a07a572dd352a
2007-05-26T21:27:56.375027Z
4
andrew
24
Entries
file
2010-02-05T03:37:53.323248Z
57b8d745384127342f95660d97e1c9c2
2007-05-26T21:27:56.375027Z
4
andrew
2

View File

@@ -0,0 +1 @@
D

View File

@@ -0,0 +1 @@
games/MogsAdventure/src/exampleINI

View File

@@ -0,0 +1 @@
andrew@gabbo:/home/cvsd

1
src/exampleINI/CVS/Entries Executable file
View File

@@ -0,0 +1 @@
D

1
src/exampleINI/CVS/Repository Executable file
View File

@@ -0,0 +1 @@
games/MogsAdventure/src/exampleINI

1
src/exampleINI/CVS/Root Executable file
View File

@@ -0,0 +1 @@
andrew@gabbo:/home/cvsd

179
src/main.cpp Executable file
View File

@@ -0,0 +1,179 @@
#include "MogCommon.h"
SDL_Surface *screen;
Sprite2D sprites[50];
Sprite2D **sprind;
char *gfxFiles[] = {
"gfx/Mog - Front.gif",
"gfx/Mog - Back.gif",
"gfx/Mog - Left.gif",
"gfx/Mog - Right.gif",
"gfx/Mog - Walk Front.gif",
"gfx/Mog - Walk Back.gif",
"gfx/Mog - Walk Left.gif",
"gfx/Mog - Walk Right.gif",
"gfx/Deceased - Down.gif",
"gfx/Deceased - Up.gif",
"gfx/Deceased - Left.gif",
"gfx/Deceased - Right.gif",
"gfx/Deceased - Walk Front.gif",
"gfx/Deceased - Walk Back.gif",
"gfx/Deceased - Walk Left.gif",
"gfx/Deceased - Walk Right.gif",
"gfx/Deceased - Attack Front.gif",
"gfx/Deceased - Attack Rear.gif",
"gfx/Deceased - Dead.gif"
};
int main(int argc, char **argv)
{
bool running = true;
SDL_Event nextEvent;
int i = 0;
if ( SDL_Init(SDL_INIT_EVERYTHING) < 0) {
cout << "Couldn't init SDL!!\n";
cout << SDL_GetError();
exit(-1);
}
screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
if (!screen) {
cout << "Couldn't get screen!\n";
cout << SDL_GetError();
exit(-1);
}
SDL_WM_SetCaption("KUPO! : Mog's Adventure (debug proof pre-0.1a)", NULL);
/* everything from here down is just a proof for now */
SDL_Rect s = {0, 0, 640, 480};
// do the stills
for (i = 0; i < 4 ; i++ ) {
sprites[i].init(gfxFiles[i], 45, 0, 32, 44);
}
// do the walkers
for (i = 4; i < 8 ; i++ ) {
sprites[i].init(gfxFiles[i], 45, 4, 32, 44);
}
// do the stills
for (i = 8; i < 12 ; i++ ) {
sprites[i].init(gfxFiles[i], 45, 0, 68, 60);
}
// do the walkers
for (i = 12; i < 16 ; i++ ) {
sprites[i].init(gfxFiles[i], 45, 4, 68, 60);
}
Sprite2D theBackground("gfx/samplebg.jpg", 0, 1, 640, 480);
Actor2D theActor(&sprites[SPR_STILLDOWN], 0.0f);
theActor.move(90, 90);
theActor.setVelocity(4, 4);
theActor.setStateSprite(&sprites[SPR_MOVEDOWN],
SPR_MOVEDOWN);
theActor.setStateSprite(&sprites[SPR_MOVELEFT],
SPR_MOVELEFT);
theActor.setStateSprite(&sprites[SPR_MOVERIGHT],
SPR_MOVERIGHT);
theActor.setStateSprite(&sprites[SPR_MOVEUP],
SPR_MOVEUP);
theActor.setStateSprite(&sprites[SPR_STILLDOWN],
SPR_STILLDOWN);
theActor.setStateSprite(&sprites[SPR_STILLLEFT],
SPR_STILLLEFT);
theActor.setStateSprite(&sprites[SPR_STILLRIGHT],
SPR_STILLRIGHT);
theActor.command(ACTOR_SET_TYPE, ACTOR_TYPE_PLAYER, NULL);
AIActor theBaddie(&sprites[8+SPR_STILLDOWN], 0.0f, ACTOR_TYPE_PLAYER, 500);
theBaddie.move(50,50);
theBaddie.setStateSprite(&sprites[8+SPR_MOVEDOWN],
SPR_MOVEDOWN);
theBaddie.setStateSprite(&sprites[8+SPR_MOVELEFT],
SPR_MOVELEFT);
theBaddie.setStateSprite(&sprites[8+SPR_MOVERIGHT],
SPR_MOVERIGHT);
theBaddie.setStateSprite(&sprites[8+SPR_MOVEUP],
SPR_MOVEUP);
theBaddie.setStateSprite(&sprites[8+SPR_STILLDOWN],
SPR_STILLDOWN);
theBaddie.setStateSprite(&sprites[8+SPR_STILLLEFT],
SPR_STILLLEFT);
theBaddie.setStateSprite(&sprites[8+SPR_STILLRIGHT],
SPR_STILLRIGHT);
theBaddie.setVelocity(3, 3);
theBaddie.command(ACTOR_SET_TYPE, ACTOR_TYPE_BADDIE, NULL);
theBaddie.command(ACTOR_IDLE, 0, NULL);
std::vector<Actor2D *> actorList;
actorList.clear();
actorList.push_back(&theActor);
actorList.push_back(&theBaddie);
while ( running == true ) {
theBackground.drawFrame(screen, 0, 0, 0, 0);
theActor.render(screen);
theActor.update();
theBaddie.render(screen);
theBaddie.updateAI(actorList);
theBaddie.update();
SDL_Flip(screen);
SDL_FillRect(screen, &s, 0);
SDL_PumpEvents();
if ( SDL_PollEvent(&nextEvent) > 0 ) {
switch (nextEvent.type) {
case SDL_KEYDOWN:
case SDL_KEYUP:
switch (nextEvent.key.state) {
case SDL_PRESSED:
if ( nextEvent.key.keysym.sym == SDLK_UP ) {
theActor.command(ACTOR_MOVEUP, 0, NULL);
}
else if ( nextEvent.key.keysym.sym == SDLK_DOWN) {
theActor.command(ACTOR_MOVEDOWN, 0, NULL);
}
else if ( nextEvent.key.keysym.sym == SDLK_RIGHT ) {
theActor.command(ACTOR_MOVERIGHT, 0, NULL);
}
else if ( nextEvent.key.keysym.sym == SDLK_LEFT) {
theActor.command(ACTOR_MOVELEFT, 0, NULL);
}
else if ( nextEvent.key.keysym.sym == SDLK_ESCAPE) {
running = false;
}
break;
case SDL_RELEASED:
if ( nextEvent.key.keysym.sym == SDLK_DOWN
&& theActor.hasState(ACTOR_MOVEDOWN)) {
theActor.command(ACTOR_IDLE, ACTOR_MOVEDOWN, NULL);
}
if ( nextEvent.key.keysym.sym == SDLK_UP
&& theActor.hasState(ACTOR_MOVEUP) ) {
theActor.command(ACTOR_IDLE, ACTOR_MOVEUP, NULL);
}
if ( nextEvent.key.keysym.sym == SDLK_LEFT
&& theActor.hasState(ACTOR_MOVELEFT) ) {
theActor.command(ACTOR_IDLE, ACTOR_MOVELEFT, NULL);
}
if ( nextEvent.key.keysym.sym == SDLK_RIGHT
&& theActor.hasState(ACTOR_MOVERIGHT) ) {
theActor.command(ACTOR_IDLE, ACTOR_MOVERIGHT, NULL);
}
break;
}
break;
case SDL_QUIT:
SDL_Quit();
return 0;
}
}
}
}