Added GPL Arcade Volleyball sources

This commit is contained in:
pelya
2010-11-12 13:32:08 +02:00
parent b9e424ea10
commit e0ae5a62ab
105 changed files with 8693 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
# The application settings for Android libSDL port
AppSettingVersion=14
LibSdlVersion=1.2
AppName="GPL Arcade Voleyball"
AppFullName=net.gav.sdl
ScreenOrientation=h
InhibitSuspend=n
AppDataDownloadUrl="Data files size is 1 Mb|http://anddev.at.ua/data/gav-data.zip"
SdlVideoResize=y
SdlVideoResizeKeepAspect=n
NeedDepthBuffer=n
AppUsesMouse=n
AppNeedsTwoButtonMouse=n
AppNeedsArrowKeys=y
AppNeedsTextInput=y
AppUsesJoystick=n
AppHandlesJoystickSensitivity=n
AppUsesMultitouch=n
NonBlockingSwapBuffers=n
RedefinedKeys="RETURN LSHIFT RSHIFT LCTRL RETURN"
AppTouchscreenKeyboardKeysAmount=3
AppTouchscreenKeyboardKeysAmountAutoFire=0
MultiABI=n
AppVersionCode=12001
AppVersionName="2.2.01"
CompiledLibraries="jpeg png sdl_image sdl_net"
CustomBuildScript=n
AppCflags=''
AppLdflags=''
AppSubdirsBuild=''
AppUseCrystaXToolchain=y
ReadmeText='^You may press "Home" now - the data will be downloaded in background'

View File

@@ -0,0 +1,21 @@
#!/bin/sh
LOCAL_PATH=`dirname $0`
LOCAL_PATH=`cd $LOCAL_PATH && pwd`
# Hacks for broken configure scripts
#rm -rf $LOCAL_PATH/../../obj/local/armeabi/libSDL_*.so
#rm -rf $LOCAL_PATH/../../obj/local/armeabi/libsdl_main.so
# Uncomment if your configure expects SDL libraries in form "libSDL_name.so"
#if [ -e $LOCAL_PATH/../../obj/local/armeabi/libsdl_mixer.so ] ; then
# ln -sf libsdl_mixer.so $LOCAL_PATH/../../obj/local/armeabi/libSDL_Mixer.so
#fi
#for F in $LOCAL_PATH/../../obj/local/armeabi/libsdl_*.so; do
# LIBNAME=`echo $F | sed "s@$LOCAL_PATH/../../obj/local/armeabi/libsdl_\(.*\)[.]so@\1@"`
# ln -sf libsdl_$LIBNAME.so $LOCAL_PATH/../../obj/local/armeabi/libSDL_$LIBNAME.so
#done
../setEnvironment.sh make -C gav-0.9.0 -j2
cp -f gav-0.9.0/gav libapplication.so

View File

@@ -0,0 +1,400 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Ball.h"
#define PI 3.14158
#define GRAVITY 250
#define MAX_TOUCHES 3
#define MIN(a,b) ((a<b)?a:b)
#define MAX(a,b) ((a>b)?a:b)
using namespace std;
bool Ball::approaching(int spdx, float spdy) {
int sgnx = (spdx>0)?1:(spdx<0)?-1:0;
int sgny = (spdy>0)?1:(spdy<0)?-1:0;
if ( ((spdx - _spdx) * sgnx) >= 0 ) return(true);
if ( ((spdy - _spdy) * sgny) >= 0 ) return(true);
return(false);
}
// evaluates a collision ("sprite"-wise)
bool Ball::spriteCollide(Player *p) {
SDL_Rect r;
r.x = _x;
r.y = _y;
return(p->collidesWith(_frames, _frameIdx, &r));
}
// evaluate a collision
bool Ball::collide(Player *p) {
return( approaching(p->speedX(), - p->speedY()) &&
spriteCollide(p) );
}
void Ball::update_internal(Player * pl) {
int cplx = pl->x() + pl->width() / 2;
int cply = pl->y() + pl->height() / 2;
int cbx = _x + _frames->width() / 2;
int cby = _y + _frames->height() / 2;
int dx = (cplx - cbx);
int dy = (cply - cby);
float beta = dx?atan((float) dy/ (float) dx):(PI/2);
float sinb = sin(-beta);
float cosb = cos(-beta);
float x1, y1;
/* service patch */
if (!_spdy && !_spdx) {
_spdy = -200;
//_spdx = (_x > configuration.NET_X)?-100:100;
}
y1 = _spdx * sinb + (- _spdy) * cosb;
x1 = configuration.ballAmplify * (pl->speedX() * cosb - pl->speedY() * sinb);
int oldspdy = _spdy;
_spdx = (int) (x1 * cos(beta) - y1 * sin(beta));
_spdy = (int) (- (x1 * sin(beta) + y1 * cos(beta)));
if ( (pl->speedX() - _spdx) * dx < 0)
_spdx = pl->speedX();
if ( (pl->speedY() - _spdy) * dy > 0)
_spdy = (int) pl->speedY();
#define MIN_POS_SPD 100
if ( (_spdy < MIN_POS_SPD) && (cby < cply) )
_spdy = (int) ((1.1 * ELASTIC_SMOOTH) * abs(oldspdy));
}
void Ball::assignPoint(int side, Team *t) {
if ( _side == side ) {
t->score();
#ifdef AUDIO
soundMgr->playSound(SND_SCORE);
#endif // AUDIO
} else {
#ifdef AUDIO
soundMgr->playSound(SND_SERVICECHANGE);
#endif // AUDIO
}
_side = side;
_x = (configuration.NET_X) +
side * (configuration.SCREEN_WIDTH/4) - _radius;
//((configuration.SCREEN_WIDTH * _side) / 4);
_y = ((configuration.SCREEN_HEIGHT * 2) / 3) - _radius ;
_spdx = _spdy = _accelY = 0;
_scorerSide = 0;
resetCollisionCount();
}
void Ball::resetCollisionCount() {
for (map<Team *, int>::iterator it = _collisionCount.begin();
it != _collisionCount.end(); it++ ) {
it->second = 0;
}
}
void Ball::resetPos(int x, int y) {
_side = -1;
_scorerSide = 0;
_x = x; _y = y; _spdx = _spdy = 0; _accelY = 0;
resetCollisionCount();
}
void Ball::draw(SDL_Surface *scr) {
SDL_Rect rect;
rect.x = _x;
rect.y = _y;
_frames->blit(_frameIdx, scr, &rect);
}
float
Ball::distance(int x, int y)
{
int bx = _x + _frames->width()/2; // center of the ball
int by = _y + _frames->height()/2;
return(sqrt((double) (x - bx)*(x - bx) + (y - by) * (y - by)));
}
bool
Ball::netPartialCollision(int x, int y)
{
int xmin, xmax, ymin, ymax;
xmin = MIN(x, _oldx);
xmax = MAX(x, _oldx);
ymin = MIN(y, _oldy);
ymax = MAX(y, _oldy);
if ((xmin < configuration.NET_X) && (xmax > configuration.NET_X)) {
int collisionY = (configuration.NET_X - xmin) *
(ymax - ymin)/(xmax - xmin) + ymin;
if ( (collisionY < configuration.NET_Y ) &&
(collisionY > configuration.NET_Y - _frames->height()/2) )
return true;
}
return((x + _frames->width() > configuration.NET_X) &&
(x < configuration.NET_X) &&
( distance(configuration.NET_X, configuration.NET_Y) <
(_frames->width()/2)) );
/* (y + _frames->height()/2 < configuration.NET_Y) &&
(y + _frames->height() > configuration.NET_Y)); */
}
bool
Ball::netFullCollision(int x, int y)
{
int xmin, xmax, ymin, ymax;
xmin = MIN(x, _oldx);
xmax = MAX(x, _oldx);
ymin = MIN(y, _oldy);
ymax = MAX(y, _oldy);
if ((xmin < configuration.NET_X) && (xmax > configuration.NET_X)) {
int collisionY = (configuration.NET_X - xmin) *
(ymax - ymin)/(xmax - xmin) + ymin;
if ( collisionY > configuration.NET_Y )
return true;
}
return((x + _frames->width() > configuration.NET_X) &&
(x < configuration.NET_X) &&
(y + _frames->height()/2 >= configuration.NET_Y));
}
void Ball::updateFrame(int passed) {
static int overallPassed = 0;
overallPassed += passed;
if (overallPassed > (configuration.ballFrameConf.ballPeriod/
configuration.ballFrameConf.nBallFrames)) {
overallPassed = 0;
_frameIdx = (_frameIdx + 1) % configuration.ballFrameConf.nBallFrames;
}
}
// updates the ball position, knowing 'passed' milliseconds went
// away
void Ball::update(int passed, Team *tleft, Team *tright) {
int dx, dy;
updateFrame(passed);
_oldx = _x;
_oldy = _y;
if ( _scorerSide ) {
_scoredTime += passed;
if ( _scoredTime > 650 ) {
assignPoint(_scorerSide, (_scorerSide<0)?tleft:tright);
return;
}
}
if ( !netPartialCollision(_x, _y) ) // if it's not network supported
update_direction(passed);
dx = (int) (_spdx * ((float) passed / 1000.0));
dy = (int) (_spdy * ((float) passed / 1000.0));
_x += dx;
_y -= dy; // usual problem with y
//ball hits upper wall
if ( _y < configuration.CEILING ) {
_y = configuration.CEILING;
_spdy = - (int) (_spdy * ELASTIC_SMOOTH);
#ifdef AUDIO
soundMgr->playSound(SND_BOUNCE);
#endif // AUDIO
}
//ball hits left wall
if ( _x < configuration.LEFT_WALL ) {
_x = configuration.LEFT_WALL;
_spdx = - (int) (_spdx * ELASTIC_SMOOTH);
if ( _collisionCount[tright] )
resetCollisionCount();
#ifdef AUDIO
soundMgr->playSound(SND_BOUNCE);
#endif // AUDIO
}
//ball hits right wall
if ( _x > (configuration.RIGHT_WALL -_frames->width()) ) {
_x = configuration.RIGHT_WALL - _frames->width();
_spdx = - (int) (_spdx * ELASTIC_SMOOTH);
if ( _collisionCount[tleft] )
resetCollisionCount();
#ifdef AUDIO
soundMgr->playSound(SND_BOUNCE);
#endif // AUDIO
}
// net collision
if ( netFullCollision(_x, _y) && !netFullCollision(_oldx, _oldy)) {
_spdx = (int) ((- _spdx) * ELASTIC_SMOOTH);
if ( _oldx > _x )
_x = 2 * configuration.NET_X - _x; // moves ball out of the net
// by the right amount
else
_x = 2* configuration.NET_X - 2*_frames->width() - _x;
#ifdef AUDIO
soundMgr->playSound(SND_FULLNET);
#endif // AUDIO
} else if ( netPartialCollision(_x, _y) ) {
if ( !netPartialCollision(_oldx,
configuration.NET_Y - 3*_frames->height()/4) ) {
if ( _oldy < _y ) { // hits from the top
if ( (_x + _frames->width()/8 < configuration.NET_X) &&
(_x + 7*_frames->width()/8 > configuration.NET_X) )
_spdx = - _spdx;
}
_spdx = (int) (_spdx * ELASTIC_SMOOTH * ELASTIC_SMOOTH * ELASTIC_SMOOTH);
}
_y -= _frames->height()/4; //(int) (_frames->height() -
//(4*distance(configuration.NET_X, configuration.NET_Y) / _frames->height()));
_spdy = (int) fabs(_spdy * ELASTIC_SMOOTH * ELASTIC_SMOOTH);
// ball stuck on the net "feature" ;-)
if (_x == _oldx) {
if (_spdx > 0)
_x += 5;
else
_x -= 5;
}
#ifdef AUDIO
soundMgr->playSound(SND_PARTIALNET);
#endif // AUDIO
}
//ball hits floor
if ( _y > (configuration.FLOOR_ORD - _frames->height() ) ) {
_y = (configuration.FLOOR_ORD - _frames->height() );
_spdy = - (int) (_spdy * ELASTIC_SMOOTH);
if ( !_scorerSide ) {
// oldx, so we're safe from collisions against
// the net
_scorerSide = (_oldx < configuration.NET_X)?1:-1;
_scoredTime = 0;
}
#ifdef AUDIO
soundMgr->playSound(SND_BOUNCE);
#endif // AUDIO
}
// collisions with the players
for ( int teami = 0; !_scorerSide && (teami < 2); teami ++ ) {
Team *team = (teami?tright:tleft);
vector<Player *> plv = team->players();
for ( vector<Player *>::const_iterator it = plv.begin();
it != plv.end(); it++ ) {
// cout << "xy" << (*it)->x() << " " << (*it)->y() << endl;
if ( collide(*it) ) {
if ( _inCollisionWith != *it ) {
_inCollisionWith = *it;
// cerr << "collide " << passed << "\n";
if ( !_collisionCount[team] )
resetCollisionCount();
_collisionCount[team]++;
#ifdef AUDIO
soundMgr->playSound(SND_PLAYERHIT);
#endif // AUDIO
if ( _collisionCount[team] > MAX_TOUCHES ) {
_scorerSide = (team == tleft)?1:-1;
_scoredTime = 0;
}
// cerr << "CollisionCount " << string(teami?"R: ":"L: ") <<
//_collisionCount[team] << endl;
update_internal(*it);
while (collide(*it)) {
int newx = _x + ((_spdx>0)?1:-1);
_y -= (_spdy>0)?1:-1; // usual problem with y
if (!netFullCollision(newx, _y) &&
!netPartialCollision(newx, _y)) _x = newx;
}
//_inCollisionWith = NULL;
} else {
while (collide(*it)) {
int newx = _x + ((_spdx>0)?1:-1);
_y -= (_spdy>0)?1:-1; // usual problem with y
if (!netFullCollision(newx, _y) &&
!netPartialCollision(newx, _y)) _x = newx;
}
}
} else if ( _inCollisionWith == *it )
_inCollisionWith = NULL;
}
}
// to activate 'gravity'
if ( !_accelY && (abs(_spdx) + abs(_spdy)) )
_accelY = GRAVITY;
/*
// over net test
if (!_spdx && !_spdy) {
_x = configuration.NET_X;
_y = configuration.NET_Y - 30;
_spdy = 5;
}
*/
/*
// stuck test
{
static int ini = 1;
if (ini && !_spdx && !_spdy) {
ini = 0;
_x = configuration.NET_X - 20;
_y = configuration.NET_Y - 50;
_spdy = 5;
}
}
*/
}

View File

@@ -0,0 +1,146 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _BALL_H_
#define _BALL_H_
#include <SDL.h>
#include <math.h>
#include <map>
#include "FrameSeq.h"
#include "Team.h"
#include "globals.h"
#include "Theme.h"
#define ELASTIC_SMOOTH (0.8)
#define MIN_NET_SPEED (10)
//#define NET_X (312)
//#define NET_X (configuration.SCREEN_WIDTH / 2 - 8)
//#define NET_Y (configuration.SCREEN_HEIGHT /2 + ((3*configuration.SCREEN_HEIGHT)/200))
//#define CEILING_Y 24
//#define LEFT_WALL 7
//#define RIGHT_WALL(bw) (configuration.SCREEN_WIDTH - bw - 16)
typedef enum {
BALL_ORIG
} ball_t;
class Ball {
private:
FrameSeq * _frames;
int _speed;
float _angle;
int _spdx, _spdy;
int _x, _y;
int _oldx, _oldy;
int _frameIdx;
int _radius;
int _beginning;
int _accelY;
int _side;
int _scorerSide;
int _scoredTime;
std::map<Team *, int> _collisionCount;
Player * _inCollisionWith;
void loadFrameSeq(ball_t t) {
switch (t) {
case BALL_ORIG:
_frames = new LogicalFrameSeq(CurrentTheme->ball(),
configuration.ballFrameConf.nBallFrames);
break;
}
}
void assignPoint(int side, Team *t);
bool approaching(int spdx, float spdy);
// evaluates a collision ("sprite"-wise)
bool spriteCollide(Player *p);
// evaluate a collision
bool collide(Player *p);
void update_internal(Player * pl);
// void assignPoint(int side, Team *t);
bool netPartialCollision(int, int);
bool netFullCollision(int, int);
inline void update_direction(int ticks)
{
_spdy -= (_accelY * ticks / 1000);
}
void resetCollisionCount();
public:
Ball(ball_t t, int x = -1, int y = -1) : _x(x), _y(y), _frameIdx(0) {
_spdy = 0;
_spdx = 0;
loadFrameSeq(t);
_radius = _frames->width() / 2;
//cerr << "radius: " << _radius << endl;
_beginning = 0;
_accelY = 0; // as soon as the speed becomes <> 0, it becomes 500
_inCollisionWith = NULL;
_side = -1;
if ( _x < 0 )
_x = (configuration.SCREEN_WIDTH / 2) +
((configuration.SCREEN_WIDTH * _side) / 4) ;
if ( _y < 0 )
_y = (configuration.SCREEN_HEIGHT * 2) / 3;
_scorerSide = _scoredTime = 0;
}
void resetPos(int x, int y);
inline int speed() { return _speed; }
inline void speed(int v) { _speed = v; }
inline int x() { return _x; }
inline int y() { return _y; }
inline int radius() { return _radius; }
inline float angle() { return _angle; }
inline void angle(float v) { _angle = v; }
inline int spdx() { return _spdx; }
inline int spdy() { return _spdy; }
inline int frame() { return _frameIdx; }
inline void setX(int x) { _x = x; }
inline void setY(int y) { _y = y; }
inline int gravity() { return _accelY; }
void updateFrame(int passed);
void update(int passed, Team *tleft, Team *tright);
float distance(int, int);
void draw(SDL_Surface *scr = screen);
~Ball() {
delete(_frames);
}
};
#endif // _BALL_H_

View File

@@ -0,0 +1,54 @@
Current CVS:
- successfully compiled on Mac OS X, files for build added
- preferences are stored to $HOME/.gav if $HOME exists, to
./gav.ini otherwise.
- size of the window can be set by the -w and -h commandline parameters
- joystick support
- a couple of leaks removed from the code
- now network game with different themes works correctly
- network connection phase no longer blocking
- the network protocol has changed! no longer compatible with old versions
Version 0.8.0 changes:
- (we hope) *FINAL* patch for stuck on the net problem
- patch for ball passing over the net bug
- collision mechanisms improved
- sound support added (sounds can be found in theme packages)
- Players classes hierarchy re-designed
- AI Player improved
- added default service change and scoring sounds.
Version 0.7.3 added:
- patch for stuck on the net problem
- advanced themes configuration support (check the naive theme
for an example)
Version 0.7.2 added:
- char specified as signed (for other architectures than x86)
- ball speed selectable
Version 0.7.1 added:
- lots of bugs fixed (collisions, etc.)
- AI improved in multiplayer mode
Version 0.7.0 added:
- Networking game, in client/server mode
- modified collisions
- several themes provided by friendly users
- selectable "larger" background
- adjustable frame rate and frame skip values
- configurable end score
- vintage monitor effect (works ok only with the default theme)
Version 0.6.0 added:
- Theme support via the 'Extra' menu entry
Only a silly modification of the classic theme is
available so far, if you are interested in developing
more, please do, and let us know!
- Keys redefinition works
- You can now activate menu items using the enter key (wow!)
- You can play more than one-a-side. Cooperative games are supported.
- Fullscreen can now be triggered via a menu entry

View File

@@ -0,0 +1,41 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
CWD = $(shell pwd)
GAV_ROOT = $(CWD:%/$(RELPATH)=%)
#comment the following line if you do not want network support
NET = true
LD = arm-eabi-ld
CXX = arm-eabi-g++
CXXFLAGS= `sdl-config --cflags` -fpic -mthumb-interwork -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -DANDROID -Wno-psabi -march=armv5te -mtune=xscale -msoft-float -fexceptions -fno-rtti -mthumb -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -g -Wall -DAUDIO -I/home/lubomyr/src/endless_space/android-ndk-r4-crystax/build/platforms/android-8/arch-arm/usr/include -I/home/lubomyr/project/jni/sdl-1.2/include -I/home/lubomyr/project/jni/sdl_image/include -I/home/lubomyr/project/jni/sdl_net/include
ifndef NET
CXXFLAGS+= -DNONET
endif
ifdef NET
LDFLAGS= `sdl-config --libs` -nostdlib -Wl,-soname,libapplication.so -Wl,-shared,-Bsymbolic -Wl,--whole-archive -Wl,--no-whole-archive /home/lubomyr/src/endless_space/android-ndk-r4-crystax/build/prebuilt/linux-x86/arm-eabi-4.4.0/arm-eabi/lib/libstdc++.a /home/lubomyr/src/endless_space/android-ndk-r4-crystax/build/platforms/android-8/arch-arm/usr/lib/libc.a -L/home/lubomyr/project/obj/local/armeabi -lsdl-1.2 -lsdl_image -lsdl_net -lm -llog -lgcc -L/home/lubomyr/src/endless_space/android-ndk-r4-crystax/build/platforms/android-8/arch-arm/usr/lib
else
LDFLAGS= `sdl-config --libs` -nostdlib -Wl,-soname,libapplication.so -Wl,-shared,-Bsymbolic -Wl,--whole-archive -Wl,--no-whole-archive -L/home/lubomyr/project/obj/local/armeabi -lsdl-1.2 -lsdl_image -lm -L/home/lubomyr/src/endless_space/android-ndk-r4-crystax/build/platforms/android-8/arch-arm/usr/lib
endif
SRCS = $(wildcard *.cpp)
OFILES = $(SRCS:%.cpp=%.o)

View File

@@ -0,0 +1,241 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Configuration options */
#include <stdlib.h>
#include <string>
#include <iostream>
#include "Configuration.h"
#include "ControlsArray.h"
using namespace std;
Configuration configuration;
Aargh aargh;
int Configuration::loadConfiguration() {
string fname = confFileName();
if ( !aargh.loadConf(fname.c_str()) )
return(-1);
string value;
if ( aargh.getArg("left_nplayers", value) )
configuration.left_nplayers = atoi(value.c_str());
if ( aargh.getArg("right_nplayers", value) )
configuration.right_nplayers = atoi(value.c_str());
if ( aargh.getArg("monitor_type", value) ) {
if ( value == "normal" )
configuration.monitor_type = MONITOR_NORMAL;
else if ( value == "old" )
configuration.monitor_type = MONITOR_OLD;
else if ( value == "very_old")
configuration.monitor_type = MONITOR_VERYOLD;
else if ( value == "very_very_old")
configuration.monitor_type = MONITOR_VERYVERYOLD;
else
cerr << "Unrecognized monitor type \"" << value << "\"\n";
}
if ( aargh.getArg("frame_skip", value) )
configuration.frame_skip = atoi(value.c_str());
if ( aargh.getArg("fps", value) )
configuration.setFps(atoi(value.c_str()));
for ( int i = 0; i < left_nplayers; i++ )
if ( aargh.getArg(("left_player" + toString(i)), value) )
if ( value == "human")
configuration.left_players[i] = PLAYER_HUMAN;
else if ( value == "computer")
configuration.left_players[i] = PLAYER_COMPUTER;
else
cerr << "Unrecognized player type \"" << value << "\"\n";
for ( int i = 0; i < MAX_PLAYERS/2; i++ ) {
string arg1, arg2, arg3;
arg1 = "left_player" + toString(i) + "left";
arg2 = "left_player" + toString(i) + "right";
arg3 = "left_player" + toString(i) + "jump";
if ( aargh.getArg(arg1) && aargh.getArg(arg2) && aargh.getArg(arg3) ) {
string lval, rval, jval;
controls_t ctrls;
aargh.getArg(arg1, lval);
aargh.getArg(arg2, rval);
aargh.getArg(arg3, jval);
ctrls.left_key = atoi(lval.c_str());
ctrls.right_key = atoi(rval.c_str());
ctrls.jump_key = atoi(jval.c_str());
controlsArray->setControls(i*2, ctrls);
}
}
for ( int i = 0; i < right_nplayers; i++ )
if ( aargh.getArg(("right_player" + toString(i)), value) )
if ( value == "human" )
configuration.right_players[i] = PLAYER_HUMAN;
else if ( value == "computer")
configuration.right_players[i] = PLAYER_COMPUTER;
else
cerr << "Unrecognized player type \"" << value << "\"\n";
for ( int i = 0; i < MAX_PLAYERS/2; i++ ) {
string arg1, arg2, arg3;
arg1 = "right_player" + toString(i) + "left";
arg2 = "right_player" + toString(i) + "right";
arg3 = "right_player" + toString(i) + "jump";
if ( aargh.getArg(arg1) && aargh.getArg(arg2) && aargh.getArg(arg3) ) {
string lval, rval, jval;
controls_t ctrls;
aargh.getArg(arg1, lval);
aargh.getArg(arg2, rval);
aargh.getArg(arg3, jval);
ctrls.left_key = atoi(lval.c_str());
ctrls.right_key = atoi(rval.c_str());
ctrls.jump_key = atoi(jval.c_str());
controlsArray->setControls(i*2 + 1, ctrls);
}
}
if ( aargh.getArg("big_background", value) )
configuration.bgBig = (value=="yes");
if ( aargh.getArg("fullscreen", value) )
configuration.fullscreen = (value=="yes");
if ( aargh.getArg("ball_speed", value) )
if ( value == "normal" )
configuration.ballAmplify = DEFAULT_BALL_AMPLIFY;
else if ( value == "fast" )
configuration.ballAmplify = DEFAULT_BALL_AMPLIFY + BALL_SPEED_INC;
else if ( value == "very_fast" )
configuration.ballAmplify = DEFAULT_BALL_AMPLIFY + 2*BALL_SPEED_INC;
else
cerr << "Unrecognized ball speed \"" << value << "\"\n";
if ( aargh.getArg("theme", value) )
configuration.currentTheme = value;
if ( aargh.getArg("sound", value) )
configuration.sound = (value == "yes");
if ( aargh.getArg("winning_score", value) )
configuration.winning_score = atoi(value.c_str());
return 0;
}
/* we'll use aargh's dump feature! Yiipeee!! */
int Configuration::saveConfiguration(string fname) {
// cerr << "saving to: " << fname << endl;
string tosave;
aargh.dump(tosave);
FILE *fp;
if ( (fp = fopen(fname.c_str(), "w")) == NULL )
return(-1);
fputs(tosave.c_str(), fp);
fclose(fp);
return 0;
}
/* unfortunately, I *HAVE* to go through all the settings...
This function puts configuration parameters inside aargh, and then
dumps it. */
int Configuration::createConfigurationFile() {
string fname = confFileName();
Configuration c = configuration; /* for short :) */
aargh.reset();
aargh.setArg("left_nplayers", c.left_nplayers);
aargh.setArg("right_nplayers", c.right_nplayers);
switch ( c.monitor_type ) {
case MONITOR_NORMAL:
aargh.setArg("monitor_type", "normal"); break;
case MONITOR_OLD:
aargh.setArg("monitor_type", "old"); break;
case MONITOR_VERYOLD:
aargh.setArg("monitor_type", "very_old"); break;
case MONITOR_VERYVERYOLD:
aargh.setArg("monitor_type", "very_very_old"); break;
}
aargh.setArg("frame_skip", c.frame_skip);
aargh.setArg("fps", c.fps);
for ( int i = 0; i < left_nplayers; i++ ) {
switch ( c.left_players[i] ) {
case PLAYER_HUMAN:
aargh.setArg("left_player" + toString(i), "human"); break;
case PLAYER_COMPUTER:
aargh.setArg("left_player" + toString(i), "computer"); break;
}
}
for ( int i = 0; i < right_nplayers; i++ ) {
switch ( c.right_players[i] ) {
case PLAYER_HUMAN:
aargh.setArg("right_player" + toString(i), "human"); break;
case PLAYER_COMPUTER:
aargh.setArg("right_player" + toString(i), "computer"); break;
}
}
aargh.setArg("big_background", c.bgBig?"yes":"no");
aargh.setArg("fullscreen", (c.fullscreen?"yes":"no"));
if ( c.ballAmplify == DEFAULT_BALL_AMPLIFY + BALL_SPEED_INC )
aargh.setArg("ball_speed", "fast");
else if ( c.ballAmplify == DEFAULT_BALL_AMPLIFY + 2*BALL_SPEED_INC )
aargh.setArg("ball_speed", "very_fast");
else if ( c.ballAmplify == DEFAULT_BALL_AMPLIFY )
aargh.setArg("ball_speed", "normal");
aargh.setArg("theme", c.currentTheme);
aargh.setArg("sound", c.sound?"yes":"no");
aargh.setArg("winning_score", c.winning_score);
for ( int i = 0; i < MAX_PLAYERS/2; i++ ) {
controls_t ct = controlsArray->getControls(i*2);
aargh.setArg("left_player" + toString(i) + "left", ct.left_key);
aargh.setArg("left_player" + toString(i) + "right", ct.right_key);
aargh.setArg("left_player" + toString(i) + "jump", ct.jump_key);
}
for ( int i = 0; i < MAX_PLAYERS/2; i++ ) {
controls_t ct = controlsArray->getControls(i*2 + 1);
aargh.setArg("right_player" + toString(i) + "left", ct.left_key);
aargh.setArg("right_player" + toString(i) + "right", ct.right_key);
aargh.setArg("right_player" + toString(i) + "jump", ct.jump_key);
}
return(saveConfiguration(fname));
}
string Configuration::confFileName() {
string ret;
const char *home = getenv("HOME");
if ( home ) {
ret = (string(home) + "/" + DEFAULT_CONF_FILENAME);
} else { /* gav.ini in the current directory */
ret = string(ALTERNATIVE_CONF_FILENAME);
}
return ret;
}

View File

@@ -0,0 +1,237 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Configuration options */
#include <string>
#include <sstream>
#include "aarg.h"
#ifndef __CONFIGURATION_H__
#define __CONFIGURATION_H__
#define MAX_PLAYERS (4)
#define DEFAULT_FPS (50)
#define DEFAULT_WINNING_SCORE (15)
#define DEFAULT_BALL_AMPLIFY 5
#define DEFAULT_FRAME_SKIP 0
#define DEFAULT_THEME "classic"
#define DEFAULT_FULLSCREEN false
#define DEFAULT_SOUND true
#define DEFAULT_NPLAYERFRAMES 4
#define DEFAULT_PLAYERSTILLB 1
#define DEFAULT_PLAYERSTILLE 1
#define DEFAULT_PLAYERSTILLP 0
#define DEFAULT_PLAYERRUNB 2
#define DEFAULT_PLAYERRUNE 3
#define DEFAULT_PLAYERRUNP 250
#define DEFAULT_PLAYERJMPB 4
#define DEFAULT_PLAYERJMPE 4
#define DEFAULT_PLAYERJMPP 0
#define DEFAULT_NBALLFRAMES 4
#define DEFAULT_BALLPERIOD 1000
#define BALL_SPEED_INC 3
#define DEFAULT_CONF_FILENAME ".gav"
#define ALTERNATIVE_CONF_FILENAME "gav.ini"
#define ENVIRONMENT_WIDTH (640)
#define ENVIRONMENT_HEIGHT (400)
#define BIG_ENVIRONMENT_WIDTH (1000)
#define BIG_ENVIRONMENT_HEIGHT (400)
enum { PLAYER_NONE, PLAYER_HUMAN, PLAYER_COMPUTER};
enum { MONITOR_NORMAL, MONITOR_OLD, MONITOR_VERYOLD, MONITOR_VERYVERYOLD};
typedef struct PlayerFrameConf_s {
unsigned short nPlayerFrames;
unsigned short playerStillB;
unsigned short playerStillE;
unsigned short playerStillP;
unsigned short playerRunB;
unsigned short playerRunE;
unsigned short playerRunP;
unsigned short playerJmpB;
unsigned short playerJmpE;
unsigned short playerJmpP;
} PlayerFrameConf_t;
typedef struct BallFrameConf_s {
unsigned short nBallFrames;
unsigned short ballPeriod;
} BallFrameConf_t;
typedef struct Resolution_s {
unsigned short x;
unsigned short y;
float ratioX;
float ratioY;
} Resolution_t;
typedef struct Environment_s {
unsigned short w;
unsigned short h;
} Environment_t;
class Configuration {
public:
int left_nplayers;
int right_nplayers;
int left_players[MAX_PLAYERS/2];
int right_players[MAX_PLAYERS/2];
PlayerFrameConf_t playerFrameConf;
BallFrameConf_t ballFrameConf;
Resolution_t resolution;
Resolution_t desiredResolution;
Environment_t env;
std::string currentTheme;
/* Constants that depend on the screen size */
int SCREEN_WIDTH;
int SCREEN_HEIGHT;
float SPEEDY;
int FLOOR_ORD;
int SPEED_MULTIPLIER;
int NET_X;
int NET_Y;
int CEILING;
int LEFT_WALL;
int RIGHT_WALL;
int DEFAULT_SPEED;
/* To add: something meaningful to record the controls... */
bool sound;
int winning_score;
int monitor_type;
unsigned int frame_skip; // one every frame_skip + 1 are actually drawn
unsigned int fps; // fps of the update (not graphical)
unsigned int mill_per_frame; // caches the # of msecs per frame (1000/fps)
bool bgBig; // if the background is big
bool fullscreen;
unsigned int ballAmplify;
Configuration() : left_nplayers(1), right_nplayers(1),
sound(DEFAULT_SOUND),
winning_score(DEFAULT_WINNING_SCORE) {
monitor_type = MONITOR_NORMAL;
frame_skip = DEFAULT_FRAME_SKIP;
fps = DEFAULT_FPS;
mill_per_frame = 1000 / fps;
left_players[0] = PLAYER_HUMAN;
right_players[0] = PLAYER_COMPUTER;
for ( int i = 1; i < MAX_PLAYERS/2; i++ ) {
left_players[i] = PLAYER_NONE;
right_players[i] = PLAYER_NONE;
}
bgBig = false;
fullscreen = DEFAULT_FULLSCREEN;
ballAmplify = DEFAULT_BALL_AMPLIFY;
setDefaultFrameConf();
currentTheme = "classic";
scaleFactors(ENVIRONMENT_WIDTH, ENVIRONMENT_HEIGHT);
env.w = ENVIRONMENT_WIDTH;
env.h = ENVIRONMENT_HEIGHT;
setDesiredResolution(ENVIRONMENT_WIDTH, ENVIRONMENT_HEIGHT);
setResolution(ENVIRONMENT_WIDTH, ENVIRONMENT_HEIGHT);
}
void scaleFactors(int width, int height) {
SCREEN_WIDTH = width;
SCREEN_HEIGHT = height;
SPEEDY = ((float) SCREEN_HEIGHT / 2.5);
FLOOR_ORD = SCREEN_HEIGHT -(SCREEN_HEIGHT / 200);
NET_X = width / 2 - width / 80;
NET_Y = height / 2 + ( 3*height / 200 );
CEILING = (int) (height / 17);
LEFT_WALL = (int) (width / 80);
RIGHT_WALL = (int) (width - width / 40);
DEFAULT_SPEED = (int) (bgBig)?(width/4):(25*width/64);
}
inline void setResolution(int w, int h) {
resolution.x = w;
resolution.y = h;
resolution.ratioX = (float) resolution.x / (float) env.w;
resolution.ratioY = (float) resolution.y / (float) env.h;
}
inline void setResolutionToDesired() {
setResolution(desiredResolution.x, desiredResolution.y);
}
inline void setDesiredResolution(int w, int h) {
desiredResolution.x = w;
desiredResolution.y = h;
desiredResolution.ratioX = (float) desiredResolution.x / (float) env.w;
desiredResolution.ratioY = (float) desiredResolution.y / (float) env.h;
}
inline void setDefaultFrameConf() {
playerFrameConf.nPlayerFrames = DEFAULT_NPLAYERFRAMES;
playerFrameConf.playerStillB = DEFAULT_PLAYERSTILLB;
playerFrameConf.playerStillE = DEFAULT_PLAYERSTILLE;
playerFrameConf.playerStillP = DEFAULT_PLAYERSTILLP;
playerFrameConf.playerRunB = DEFAULT_PLAYERRUNB;
playerFrameConf.playerRunE = DEFAULT_PLAYERRUNE;
playerFrameConf.playerRunP = DEFAULT_PLAYERRUNP;
playerFrameConf.playerJmpB = DEFAULT_PLAYERJMPB;
playerFrameConf.playerJmpE = DEFAULT_PLAYERJMPE;
playerFrameConf.playerJmpP = DEFAULT_PLAYERJMPP;
ballFrameConf.nBallFrames = DEFAULT_NBALLFRAMES;
ballFrameConf.ballPeriod = DEFAULT_BALLPERIOD;
}
inline void setFps(int val) {
fps = val;
mill_per_frame = 1000 / val;
}
std::string toString(int v) {
std::ostringstream os;
os << v;
return os.str();
}
int loadConfiguration();
int saveConfiguration(std::string fname);
int createConfigurationFile();
std::string confFileName();
//void scaleFactors(int width, int height);
};
#endif

View File

@@ -0,0 +1,100 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <SDL.h>
#include "InputState.h"
#include "ControlsArray.h"
#include "vector"
#include "Player.h"
#include "Team.h"
#include "PlayerAI.h"
#ifndef NONET
#include "NetServer.h"
#endif
#define JOY_THRESHOLD (10000)
void ControlsArray::initializeControls() {
_keyMapping[0].left_key = SDLK_z;
_keyMapping[0].right_key = SDLK_c;
_keyMapping[0].jump_key = SDLK_LSHIFT;
_keyMapping[1].left_key = SDLK_LEFT;
_keyMapping[1].right_key = SDLK_RIGHT;
_keyMapping[1].jump_key = SDLK_UP;
_keyMapping[2].left_key = SDLK_h;
_keyMapping[2].right_key = SDLK_k;
_keyMapping[2].jump_key = SDLK_u;
_keyMapping[3].left_key = SDLK_s;
_keyMapping[3].right_key = SDLK_f;
_keyMapping[3].jump_key = SDLK_e;
// _joyMapping[0] = SDL_JoystickOpen(0);
}
void ControlsArray::setControlsState(InputState *is, Team * tl, Team * tr) {
Uint8 *keystate = is->getKeyState();
int i = 0;
std::vector<Player *> players;
SDL_JoystickUpdate();
#ifndef NONET
int player;
char cmd;
if (nets)
while ( nets->ReceiveCommand(&player, &cmd) != -1 ) {
_inputs[player].left = cmd & CNTRL_LEFT;
_inputs[player].right = cmd & CNTRL_RIGHT;
_inputs[player].jump = cmd & CNTRL_JUMP;
}
#endif
players = tl->players();
for (i = 0; i < 2; i++) {
for ( std::vector<Player *>::const_iterator it = players.begin();
it != players.end(); it++ ) {
if ( (*it)->getCtrl() == PL_CTRL_HUMAN ) {
int plId = (*it)->id();
/* first check the keyboard */
_inputs[plId].left = keystate[_keyMapping[plId].left_key];
_inputs[plId].right = keystate[_keyMapping[plId].right_key];
_inputs[plId].jump = keystate[_keyMapping[plId].jump_key];
/* then check the joystick */
SDL_Joystick *js = _joyMapping[plId];
if ( js ) {
_inputs[plId].left |= (SDL_JoystickGetAxis(js, 0) < -JOY_THRESHOLD);
_inputs[plId].right |= (SDL_JoystickGetAxis(js, 0) > JOY_THRESHOLD);
_inputs[plId].jump |= SDL_JoystickGetButton(js, 0);
}
} else if ( (*it)->getCtrl() == PL_CTRL_AI ) {
_inputs[(*it)->id()] = ((PlayerAI *) (*it))->planAction();
}
}
players = tr->players();
}
}

View File

@@ -0,0 +1,104 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __CONTROLSARRAY_H__
#define __CONTROLSARRAY_H__
#include <string.h>
#include "InputState.h"
#include "globals.h"
class Team;
typedef struct {
int left_key;
int right_key;
int jump_key;
} controls_t;
#define MAX_JOYS (4)
typedef enum { CNTRL_LEFT = 1, CNTRL_RIGHT = 2, CNTRL_JUMP = 4} cntrl_t;
class ControlsArray {
triple_t _inputs[MAX_PLAYERS];
controls_t _keyMapping[MAX_PLAYERS];
/* vector from playerId to SDL_Joystick * */
SDL_Joystick *_joyMapping[MAX_PLAYERS];
Uint8 _f[12];
int _nJoys;
SDL_Joystick *_joys[MAX_JOYS];
public:
ControlsArray() {
memset(_inputs, 0, MAX_PLAYERS * sizeof(triple_t));
memset(_f, 0, 12);
for ( int i = 0; i < MAX_PLAYERS; i++ )
_joyMapping[i] = NULL;
_nJoys = SDL_NumJoysticks();
if ( _nJoys > MAX_JOYS)
_nJoys = MAX_JOYS;
for ( int i = 0; i < _nJoys; i++ )
_joys[i] = SDL_JoystickOpen(i);
initializeControls();
}
controls_t getControls(int plId) {
return _keyMapping[plId];
}
void setControls(int plId, controls_t ctrls) {
_keyMapping[plId] = ctrls;
}
int getNJoysticks() { return _nJoys; }
void assignJoystick(int plId, int joyId) {
if ( joyId == -1 )
_joyMapping[plId] = NULL;
else
_joyMapping[plId] = _joys[joyId%_nJoys];
}
// void addChannel(){}
void setControl(int plId, cntrl_t cntrl, int keysym) {
controls_t *t = &_keyMapping[plId];
switch ( cntrl ) {
case CNTRL_LEFT:
t->left_key = keysym;
break;
case CNTRL_RIGHT:
t->right_key = keysym;
break;
case CNTRL_JUMP:
t->jump_key = keysym;
break;
}
}
void initializeControls();
void setControlsState(InputState *is, Team * tl, Team * tr);
inline triple_t getCommands(int idx) { return _inputs[idx];}
};
#endif // __CONROLSARRAY_H__

View File

@@ -0,0 +1,116 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <iostream>
#include "FrameSeq.h"
#define max(x, y) ((x)>(y)?(x):(y))
#define min(x, y) ((x)<(y)?(x):(y))
void FrameSeq::blitRect(int idx, SDL_Surface * dest, SDL_Rect * rect) {
SDL_Rect r;
r.x = (idx % _nframes) * _width;
r.y = 0;
r.w = rect->w;
r.h = rect->h;
SDL_BlitSurface(_surface, &r, dest, rect);
}
void FrameSeq::blit(int idx, SDL_Surface * dest, SDL_Rect * rect) {
SDL_Rect r;
r.x = (idx % _nframes) * _width;
r.y = 0;
r.w = _width;
r.h = _surface->h;
SDL_BlitSurface(_surface, &r, dest, rect);
}
Uint32 CreateHicolorPixel(SDL_PixelFormat *fmt, Uint8 red,
Uint8 green, Uint8 blue) {
return( ((red >> fmt->Rloss) << fmt->Rshift) +
((green >> fmt->Gloss) << fmt->Gshift) +
((blue >> fmt->Bloss) << fmt->Bshift) );
}
inline Uint32 getPix(void *v, int i, Uint8 bpp) {
switch ( bpp ) {
case 4: return (Uint32) ((Uint32 *)v)[i]; break;
case 3:
std::cerr << "Unsupported pixel format: please, report to the GAV team!\n";
exit(0);
break;
//(Uint32) ((Uint24 *)v)[i]; break; there's no such thing as Uint24!
case 2: return (Uint32) ((Uint16 *)v)[i]; break;
case 1: return (Uint32) ((Uint8 *)v)[i]; break;
}
std::cerr << "Unsupported pixel format (" << bpp <<
"): please, report to the GAV team!\n";
exit(0);
return 0;
}
bool
FrameSeq::collidesWith(FrameSeq *fs, int idx1, int idx2, SDL_Rect * rect1,
SDL_Rect * rect2) {
int xmin = max(rect1->x, rect2->x);
int xmax = min(rect1->x + _width, rect2->x + fs->_width);
int ymin = max(rect1->y, rect2->y);
int ymax = min(rect1->y + _height, rect2->y + fs->_height);
if ( (xmin > xmax) || (ymin > ymax) ) return(false);
void *pix1 = _surface->pixels;
void *pix2 = fs->_surface->pixels;
Uint8 pixfmt = screen->format->BytesPerPixel;
Uint32 empty_pixel = 0;
// faster than CreateHicolorPixel(screen->format, 0, 0, 0);
int sp1 = _surface->pitch / pixfmt;
int sp2 = fs->_surface->pitch / pixfmt;
int xdisp1 = ((idx1 % _nframes) * _width);
int xdisp2 = ((idx2 % fs->_nframes) * fs->_width);
while ( ymin < ymax ) { // was ymin <= ymax
int xrun = xmin;
while ( xrun < xmax ) { // was xrun <= xmax
int p1off = sp1 * (ymin - rect1->y) + xdisp1 + (xrun - rect1->x);
int p2off = sp2 * (ymin - rect2->y) + xdisp2 + (xrun - rect2->x);
if ( ( getPix(pix1, p1off, pixfmt) != empty_pixel ) &&
( getPix(pix2, p2off, pixfmt) != empty_pixel) ) {
return(true);
}
xrun++;
}
ymin++;
}
return(false);
}

View File

@@ -0,0 +1,87 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __FRAMESEQ_H__
#define __FRAMESEQ_H__
#include <stdlib.h>
#include <SDL.h>
#include <SDL_image.h>
extern SDL_Surface *screen;
class FrameSeq {
protected:
SDL_Surface * _surface;
int _nframes;
int _width;
int _height;
void setSurfaceAndFrames(SDL_Surface *sfc, int nframes, bool useAlpha) {
_surface = SDL_DisplayFormat(sfc);
if ( useAlpha )
SDL_SetColorKey(_surface, SDL_SRCCOLORKEY,
(Uint32) SDL_MapRGB(screen->format, 0, 0, 0));
SDL_FreeSurface(sfc);
_nframes = nframes;
_width = _surface->w / _nframes;
_height = _surface->h;
}
public:
FrameSeq (const char * filename, int nframes, bool useAlpha) {
SDL_Surface * temp;
if ((temp = IMG_Load(filename)) == NULL) {
fprintf(stderr, "FrameSeq: cannot load %s\n", filename);
exit(-1);
}
setSurfaceAndFrames(temp, nframes, useAlpha);
}
FrameSeq(SDL_Surface *sfc, int nframes, bool useAlpha) {
setSurfaceAndFrames(sfc, nframes, useAlpha);
}
virtual ~FrameSeq() {
SDL_FreeSurface(_surface);
}
virtual SDL_Surface *surface() { return _surface; }
inline int width() { return _width; }
inline int height() { return _height; }
/* Blits an entire frame to screen */
virtual void blit(int idx, SDL_Surface * dest, SDL_Rect * rect);
/* Blits part of a frame to screen */
void blitRect(int idx, SDL_Surface * dest, SDL_Rect * rect);
bool collidesWith(FrameSeq *fs, int idx1, int idx2, SDL_Rect * rect1,
SDL_Rect * rect2);
virtual FrameSeq *getActualFrameSeq() { return this; } // bit ugly
virtual int screenWidth() { return _width; } // bit ugly
};
#endif

View File

@@ -0,0 +1,47 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <math.h>
#include "GameRenderer.h"
using namespace std;
GameRenderer * gameRenderer = NULL;
SDL_Rect GameRenderer::convertCoordinates(SDL_Rect *rect) {
// Compute the actual coordinates in the display realm
SDL_Rect r;
r.x = (int) round(rect->x * _ratioX);
r.y = (int) round(rect->y * _ratioY);
r.w = (int) round(rect->w * _ratioX);
r.h = (int) round(rect->h * _ratioY);
return r;
}
void GameRenderer::display(SDL_Surface *dest, SDL_Rect *rect,
FrameSeq *what, int frame) {
SDL_Rect r = convertCoordinates(rect);
what->blit(frame, dest, &r);
}

View File

@@ -0,0 +1,53 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _GAMERENDERER_H_
#define _GAMERENDERER_H_
#include <SDL.h>
#include "FrameSeq.h"
#include "globals.h"
class GameRenderer {
float _ratioX;
float _ratioY;
public:
GameRenderer() {
_ratioX = 1.0;
_ratioY = 1.0;
}
GameRenderer(int aw, int ah, int lw, int lh) {
_ratioX = (float) aw / (float) lw;
_ratioY = (float) ah / (float) lh;
}
// if the frame param is omitted, the whole surface is blitted to dest
void display(SDL_Surface *dest, SDL_Rect *rect, FrameSeq *what,
int frame = 0);
SDL_Rect convertCoordinates(SDL_Rect *rect);
};
#endif // _GAMERENDERER_H_

View File

@@ -0,0 +1,50 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <SDL.h>
#include "InputState.h"
SDL_Event InputState::getEventWaiting() {
SDL_Event e;
SDL_WaitEvent(&e);
return(e);
}
void InputState::getInput() {
SDL_PumpEvents();
/* Grab a snapshot of the keyboard. */
keystate = SDL_GetKeyState(NULL); // SHOULD THIS BE DELETED AT SOME POINT??
if ( SDL_PollEvent(&event) ) {
if (event.type == SDL_QUIT)
exit(0);
}
for ( int i = 0; i < 12; i++ )
_f[i] = keystate[SDLK_F1 + i];
}
InputState::~InputState() {
}

View File

@@ -0,0 +1,47 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __INPUTSTATE_H__
#define __INPUTSTATE_H__
#include <string.h>
#include <SDL.h>
#include "globals.h"
class InputState {
private:
Uint8 _f[12];
Uint8 *keystate;
SDL_Event event;
public:
InputState() {}
virtual void getInput();
virtual Uint8 *getF() { return _f; }
virtual Uint8 *getKeyState() { return keystate; }
virtual SDL_Event getEvent() { return event; }
virtual SDL_Event getEventWaiting();
virtual ~InputState();
};
#endif

View File

@@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@@ -0,0 +1,62 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "LogicalFrameSeq.h"
#include "GameRenderer.h"
#include "globals.h"
using namespace std;
/*
start - the starting width
zoom - the zoom factor calculated from background ratio
step - the new width must be a 'step' multiple
returns the zoom factor nearest to 'zoom', in order to obtain a 'step'
multiple.
*/
double exactScaleFactor(int startw, double zoom, int step) {
if ( step == 1 ) return zoom;
double corr = 0.0;
double ratio = 1/zoom;
double fract = (double) startw / ratio;
int temp = (int) round(fract / step);
int adjustedResize = temp * step;
// printf("W: %d NP: %d\n", startw, temp);
double adjustedRatio = (double) startw / (double) adjustedResize;
/*
int tmp2 = (int) (startw / adjustedRatio);
// printf ("ar: %g tmp2: %d\n", adjustedRatio, tmp2);
if ( tmp2 < adjustedResize )
corr = 0.5;
*/
return (1/adjustedRatio + (corr/(double) startw));
}
void LogicalFrameSeq::blit(int idx, SDL_Surface *dest,
SDL_Rect *rect) {
gameRenderer->display(dest, rect, _actualFrameSeq, idx);
}

View File

@@ -0,0 +1,80 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __LOGICALFRAMESEQ_H__
#define __LOGICALFRAMESEQ_H__
#include <stdlib.h>
#include <SDL.h>
#include <SDL_image.h>
#include <math.h>
//#include <SDL_rotozoom.h>
#include "ResizeSurface.h"
#include "globals.h"
#include "FrameSeq.h"
double exactScaleFactor(int startw, double zoom, int step);
class LogicalFrameSeq : public FrameSeq {
protected:
FrameSeq *_actualFrameSeq;
public:
LogicalFrameSeq(const char * filename, int nframes, bool useAlpha = true)
: FrameSeq(filename, nframes, useAlpha) {
// if ( ratioX == 0.0 )
float ratioX = ::configuration.resolution.ratioX;
// if ( ratioY == 0.0 )
float ratioY = ::configuration.resolution.ratioY;
ratioX = exactScaleFactor(_surface->w, ratioX, nframes);
// SDL_Surface *as = zoomSurface(_surface, ratioX, ratioY, SMOOTHING_OFF);
SDL_Surface *as = resizeSurface(_surface, (int) round(ratioX*_surface->w),
(int) round(ratioY*_surface->h));
//printf("NS->w: %d\n", as->w);
_actualFrameSeq = new FrameSeq(as, nframes, useAlpha);
/* Modify _width according to the new computed ratioX */
_width = (int) (((double) _actualFrameSeq->width()) / ratioX);
}
virtual ~LogicalFrameSeq() {
delete(_actualFrameSeq);
}
virtual SDL_Surface *surface() { return _actualFrameSeq->surface(); }
virtual void blit(int idx, SDL_Surface * dest, SDL_Rect * rect);
/* These two functions are needed when it is required to reason in terms of actual
pixels (as in ScreenFonts to make sure the font is nicely laid out. In order
to be able to exchange between FrameSeq and LogicalFrameSeq, however, it has been
necessary to add these to FrameSeq as well. Should have worked that out better... */
virtual FrameSeq *getActualFrameSeq() { return _actualFrameSeq; }
virtual int screenWidth() { return _actualFrameSeq->width(); }
};
#endif // __LOGICALFRAMESEQ_H__

View File

@@ -0,0 +1,70 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include CommonHeader
ROOT=
SUBDIRS = menu automa net
CXXFLAGS += $(foreach DIR, $(SUBDIRS), -I$(DIR)) -I.
ALL_OBJ = $(foreach DIR, $(SUBDIRS), $(DIR)/$(DIR:%=%_module.o))
DEPEND = Makefile.depend
.PHONY: depend clean all $(SUBDIRS)
all: $(SUBDIRS) gav
$(SUBDIRS):
$(MAKE) -C $@
$(ALL_OBJ):
$(MAKE) -C $(@D:%_module.o=%)
gav: $(ALL_OBJ) $(OFILES)
$(CXX) -o gav $(OFILES) $(ALL_OBJ) $(LDFLAGS)
strip gav
clean:
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i clean;\
done
rm -f *~ *.o gav $(DEPEND)
bindist: all
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i clean;\
done
rm -f *~ *.o
install: all
install gav $(ROOT)/usr/bin
install -d $(ROOT)/usr/share/games/gav/themes
cp -r themes/* $(ROOT)/usr/share/games/gav/themes
depend:
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i depend;\
done
$(RM) $(DEPEND)
$(CXX) -M $(CXXFLAGS) $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,70 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include CommonHeader
ROOT=
SUBDIRS = menu automa net
CXXFLAGS += $(foreach DIR, $(SUBDIRS), -I$(DIR)) -I.
ALL_OBJ = $(foreach DIR, $(SUBDIRS), $(DIR)/$(DIR:%=%_module.o))
DEPEND = Makefile.depend
.PHONY: depend clean all $(SUBDIRS)
all: $(SUBDIRS) gav
$(SUBDIRS):
$(MAKE) -C $@
$(ALL_OBJ):
$(MAKE) -C $(@D:%_module.o=%)
gav: $(ALL_OBJ) $(OFILES)
$(CXX) -o gav $(OFILES) $(ALL_OBJ) $(LDFLAGS)
strip gav
clean:
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i clean;\
done
rm -f *~ *.o gav $(DEPEND)
bindist: all
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i clean;\
done
rm -f *~ *.o
install: all
install gav $(ROOT)/usr/bin
install -d $(ROOT)/usr/share/games/gav/themes
cp -r themes/* $(ROOT)/usr/share/games/gav/themes
depend:
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i depend;\
done
$(RM) $(DEPEND)
$(CXX) -M $(CXXFLAGS) $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,64 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
include CommonHeader
ROOT=
SUBDIRS = menu automa net
CXXFLAGS += $(foreach DIR, $(SUBDIRS), -I$(DIR)) -I. -Dmain=SDL_main
SUBDIRS_SRCS = $(foreach DIR, $(SUBDIRS), $(wildcard $(DIR)/*.cpp))
ALL_OBJ = $(SUBDIRS_SRCS:%.cpp=%.o)
DEPEND = Makefile.depend
.PHONY: depend clean all $(SUBDIRS)
all: $(SUBDIRS) gav.exe
$(SUBDIRS):
$(MAKE) -C $@
gav.exe: $(ALL_OBJ) $(OFILES)
$(CXX) -o gav.exe $(OFILES) $(ALL_OBJ) $(LDFLAGS)
strip gav.exe
clean:
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i clean;\
done
rm -f *~ *.o gav gav.exe $(DEPEND)
bindist: all
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i clean;\
done
rm -f *~ *.o
depend:
for i in $(SUBDIRS) ; do \
$(MAKE) -C $$i depend;\
done
$(RM) $(DEPEND)
$(CXX) -M $(CXXFLAGS) $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,183 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Player.h"
#include "ControlsArray.h"
#include <math.h>
#include "Team.h"
#define SPEED_FACT_CONST (5)
int Player::maxX() { return _team->xmax(); }
int Player::minX() { return _team->xmin(); }
int Player::minY() { return _team->ymin(); }
int Player::speedX() {
if ( (_speedX > 0) &&
(_x < (_team->xmax() - _frames->width())) )
return(_speedX);
if ( (_speedX < 0) &&
(_x > _team->xmin()) )
return(_speedX);
return(0);
}
bool Player::setState(pl_state_t st, bool force) {
if ((_state == st) && !force) return false;
_state = st;
switch (st) {
case PL_STATE_JUMP:
_currFrameB = configuration.playerFrameConf.playerJmpB - 1;
_currFrameE = configuration.playerFrameConf.playerJmpE - 1;
if ( (_currFrameB == _currFrameE) ||
(configuration.playerFrameConf.playerJmpP == 0) )
_currStateFrameDelay = 0;
else
_currStateFrameDelay = configuration.playerFrameConf.playerJmpP/
( _currFrameE - _currFrameB);
break;
case PL_STATE_STILL:
_currFrameB = configuration.playerFrameConf.playerStillB - 1;
_currFrameE = configuration.playerFrameConf.playerStillE - 1;
if ( (_currFrameB == _currFrameE) ||
(configuration.playerFrameConf.playerStillP == 0) )
_currStateFrameDelay = 0;
else
_currStateFrameDelay = configuration.playerFrameConf.playerStillP/
( _currFrameE - _currFrameB);
break;
case PL_STATE_WALK:
_currFrameB = configuration.playerFrameConf.playerRunB - 1;
_currFrameE = configuration.playerFrameConf.playerRunE - 1;
if ( (_currFrameB == _currFrameE) ||
(configuration.playerFrameConf.playerRunP == 0) )
_currStateFrameDelay = 0;
else
_currStateFrameDelay = configuration.playerFrameConf.playerRunP/
( _currFrameE - _currFrameB);
break;
}
return true;
}
void Player::updateFrame(int ticks, bool changed) {
_overallPassed += ticks;
if ( changed ) {
_overallPassed = 0;
_frameIdx = _currFrameB;
} else if ( _currStateFrameDelay &&
(_overallPassed > _currStateFrameDelay) ) {
// update _frameIdx
if ( ++_frameIdx > _currFrameE )
_frameIdx = _currFrameB;
_overallPassed = 0;
}
}
/* Invoked by the network client in order to draw the proper
animation frame */
void Player::updateClient(int ticks, pl_state_t st) {
updateFrame(ticks, setState(st));
}
void Player::update(int ticks, ControlsArray *ca) {
triple_t input = ca->getCommands(_plId);
int dx = 0;
bool firstTime = (_overallPassed == 0);
if ( input.left )
dx--;
if ( input.right )
dx++;
_speedX = dx?(dx * _speed):0;
_displx += (float) dx * (_speed * ticks / 1000.0);
if ( fabs(_displx) >= 1.0 ) {
_x += (int) _displx;
_displx -= (int) _displx;
}
if ( _x > (_team->xmax() - _frames->width()) )
_x = (_team->xmax() - _frames->width());
else if ( _x < _team->xmin() )
_x = _team->xmin();
if ( _y == GROUND_LEVEL() && input.jump ) {
_speedY = -(configuration.SPEEDY);
}
if ( _y > GROUND_LEVEL() ) {
_y = GROUND_LEVEL();
_speedY = 0;
}
_disply = (float) (_speedY * SPEED_FACT_CONST * ((float) ticks / 1000.0));
if ( fabs(_disply) >= 1.0 ) {
_y += (int) _disply;
_disply -= (int) _disply;
}
if ( _y < GROUND_LEVEL() )
_speedY +=
(float) (configuration.SPEEDY * SPEED_FACT_CONST * ticks) / 1000.0;
int _oldState = _state;
/* detect state changes */
if ( _y < GROUND_LEVEL() ) {
setState(PL_STATE_JUMP); // jumping
} else if (firstTime || (!dx)) { // player still
setState(PL_STATE_STILL, firstTime);
} else if ( dx ) { // player running
setState(PL_STATE_WALK);
}
updateFrame(ticks, (_oldState != _state));
}
void Player::draw(SDL_Surface * screen) {
SDL_Rect rect;
rect.x = _x;
rect.y = _y;
_frames->blit(_frameIdx, screen, &rect);
}
bool
Player::collidesWith(FrameSeq *fs, int idx, SDL_Rect *rect)
{
SDL_Rect myRect;
myRect.x = _x;
myRect.y = _y;
return(_frames->collidesWith(fs, _state, idx, &myRect, rect));
}

View File

@@ -0,0 +1,182 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __PLAYER_H__
#define __PLAYER_H__
#include <SDL.h>
#include "FrameSeq.h"
#include <string>
#include "Theme.h"
#include "globals.h"
#define RESET_WALK_SEQUENCE (100000)
class Team;
class ControlsArray;
#define NUM_TYPES (5)
typedef enum {
PL_TYPE_MALE_LEFT = 1,
PL_TYPE_FEMALE_LEFT,
PL_TYPE_MALE_RIGHT,
PL_TYPE_FEMALE_RIGHT
} pl_type_t;
#define NUM_STATES (3)
typedef enum {
PL_STATE_STILL = 0,
PL_STATE_WALK,
PL_STATE_JUMP
} pl_state_t;
typedef enum {
PL_CTRL_HUMAN,
PL_CTRL_AI,
PL_CTRL_REMOTE
} pl_ctrl_t;
class Player {
protected:
FrameSeq * _frames;
std::string _name;
pl_type_t _type;
pl_state_t _state;
int _frameIdx;
int _speed;
int _x, _y;
int _speedX; // actual x speed
float _speedY;
int _plId;
int _oif;
int _currStateFrameDelay, _currFrameB, _currFrameE;
Team *_team;
int _overallPassed;
float _displx, _disply;
char *_fileNames[NUM_TYPES];
public:
Player() {};
Player(Team *team, std::string name, pl_type_t type, int idx, int speed) {
init(team, name, type, idx, speed);
}
void init(Team *team, std::string name, pl_type_t type, int idx, int speed) {
_fileNames[PL_TYPE_MALE_LEFT] =
(char *)malloc(sizeof(char)*(MAXPATHLENGTH+1));
strncpy(_fileNames[PL_TYPE_MALE_LEFT],
CurrentTheme->leftmale(), MAXPATHLENGTH);
_fileNames[PL_TYPE_MALE_RIGHT] =
(char *)malloc(sizeof(char)*(MAXPATHLENGTH+1));
strncpy(_fileNames[PL_TYPE_MALE_RIGHT],
CurrentTheme->rightmale(), MAXPATHLENGTH);
_fileNames[PL_TYPE_FEMALE_LEFT] =
(char *)malloc(sizeof(char)*(MAXPATHLENGTH+1));
strncpy(_fileNames[PL_TYPE_FEMALE_LEFT],
CurrentTheme->leftfemale(), MAXPATHLENGTH);
_fileNames[PL_TYPE_FEMALE_RIGHT] =
(char *)malloc(sizeof(char)*(MAXPATHLENGTH+1));
strncpy(_fileNames[PL_TYPE_FEMALE_RIGHT],
CurrentTheme->rightfemale(), MAXPATHLENGTH);
_team = team;
_name = name;
_plId = idx;
_oif = -1;
_type = type;
_state = PL_STATE_STILL;
_frameIdx = configuration.playerFrameConf.playerStillB - 1;
_speed = speed;
_speedX = 0;
_speedY = 0.0;
_overallPassed = 0;
_displx = _disply = 0.0;
Player::loadFrames();
_y = GROUND_LEVEL();
}
virtual ~Player() {
free(_fileNames[PL_TYPE_MALE_LEFT]);
free(_fileNames[PL_TYPE_MALE_RIGHT]);
free(_fileNames[PL_TYPE_FEMALE_LEFT]);
free(_fileNames[PL_TYPE_FEMALE_RIGHT]);
delete(_frames);
}
inline int GROUND_LEVEL() { return(configuration.FLOOR_ORD -_frames->height());} // (346)
inline std::string name() {return _name;}
inline int id() { return _plId; }
inline int orderInField() { return _oif; }
inline void setOIF(int oif) { _oif = oif; }
inline pl_type_t type() {return _type;}
inline pl_state_t state() {return _state;}
bool setState(pl_state_t s, bool force = false);
inline int speed() {return _speed;}
inline void setSpeed(int s) {_speed = s;}
inline float speedY() {return _speedY;}
inline void setSpeedY(float s) {_speedY = s;}
int speedX();
inline int x() {return _x;}
inline void setX(int x) {_x = x;}
inline int y() {return _y;}
inline void setY(int y) {_y = y;}
inline Team *team() {return(_team);}
void loadFrames() {
_frames = new LogicalFrameSeq(_fileNames[_type],
configuration.playerFrameConf.nPlayerFrames);
}
void updateFrame(int ticks, bool changed);
void updateClient(int ticks, pl_state_t state);
void update(int ticks, ControlsArray *ca);
void draw(SDL_Surface * screen);
inline int width() { return _frames->width(); }
inline int height() { return _frames->height(); }
int minX();
int maxX();
int minY();
bool collidesWith(FrameSeq *fs, int idx, SDL_Rect *rect);
virtual pl_ctrl_t getCtrl() { return PL_CTRL_HUMAN; };
};
#endif

View File

@@ -0,0 +1,244 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "PlayerAI.h"
#include "Ball.h"
#define JUMP_LIMIT ( (int) (configuration.SCREEN_HEIGHT / 1.82) )
#define JUMPING_TIME ( 150 )
#define NEWPL_SIDE (-1)
triple_t PlayerAI::planAction() {
int jmp = 0;
//int i;
int side = (team())->side();
int nplrs = (team())->nplayers();
int px, bx, fs, mp, bsx, net, wall, xt, xs; /* Normalized values */
int mypos, minslot, maxslot;
float slotsize;
int move, pw;
triple_t ret;
int ttime;
net = fs = abs(maxX() - minX());
wall = 0;
mp = fs/2;
/* Normalize player x position, ball x position and ball x speed:
Reasoning as it plays on the left, net=fs, wall=0 */
px = (side>0)?(maxX()-x()-width()/2):
(x()+width()/2-minX());
pw = width();
bx = (side>0)?(maxX()-(_b->radius()+_b->x())):
(_b->radius()+_b->x()-minX());
bsx = -side*_b->spdx();
xs = bx;
/* if ( (_y > _highestpoint) ){
printf("_y: %d, hp: %d\n",_y, _highestpoint);
_highestpoint = _y;
}*/
if ( !_b->gravity() ) {
xt = (side>0)?(maxX()-(_b->radius()/2+_b->x())):
(_b->radius()/2+_b->x()-minX());
} else {
//xt = bx; /* The old one
int exp_y = _b->y();
int exp_x = _b->x();
int sx = _b->spdx();
int sy = _b->spdy();
// printf("I(%d,%d) -> (%d,%d)\n",exp_x,exp_y,sx,sy);
ttime=0;
while (exp_y < 240) {
int passed=20;
int px = exp_x;
int py = exp_y;
ttime += passed;
exp_x += (int)(sx * ((float) passed/1000.0));
exp_y -= (int)(sy * ((float) passed/1000.0));
sy = (int)(sy-((float) passed*_b->gravity()/1000.0));
if ( exp_y < configuration.CEILING ) {
exp_y = configuration.CEILING;
sy = - (int ) (sy*ELASTIC_SMOOTH);
}
if ( exp_x < configuration.LEFT_WALL ) {
exp_x = configuration.LEFT_WALL;
sx = - (int ) (sx*ELASTIC_SMOOTH);
}
if ( exp_x > configuration.RIGHT_WALL - (_b->radius()*2) ) {
exp_x = configuration.RIGHT_WALL - (_b->radius()*2);
sx = - (int ) (sx*ELASTIC_SMOOTH);
}
int minx = (exp_x < px)?exp_x:px;
if ( (minx > (configuration.NET_X-_b->radius()*2)) &&
( minx < configuration.NET_X ) ) {
/* The ball crossed the net region */
if ( ( exp_y > configuration.NET_Y ) ||
( py > configuration.NET_Y ) ) {
/* Probably the ball will hit the net,
consider a full collision */
exp_x = (minx == exp_x)?configuration.NET_X-_b->radius()*2:configuration.NET_X;
sx = - (int ) (sx*ELASTIC_SMOOTH);
if (!sx) sx = side*20;/*SMALL_SPD_X*/
}
}
// printf("+(%d,%d) -> (%d,%d)\n", exp_x, exp_y, sx, sy);
}
xt = exp_x+_b->radius();
xt = (side>0)?(maxX()-xt):(xt-minX());
// printf("Expected X: %d (bsx: %d, bsy: %d, bx: %d, by: %d (radius: %d, rw:%d, hp: %d)\n",xt, _b->spdx(), _b->spdy(), _b->x(), _b->y(), _b->radius(), RIGHT_WALL(2*_b->radius()),_highestpoint);
// printf("HP: %d\n"u, _highestpoint);
}
//Expected X: 80061 (bsx: -624, bsy: 679, bx: 455, by: 241 (radius: 25)
slotsize = net/nplrs;
if (nplrs > 1) {
std::vector<Player *> plv = (team())->players();
/* Look for my id */
std::vector<Player *>::iterator it;
int myidx = orderInField(), i;
/* If nobody set the Order In Field I will do for all the team */
if (orderInField() < 0) {
for ( it = plv.begin(), i=0;
it != plv.end();
it++,i++ )
(*it)->setOIF(i);
myidx = orderInField();
}
mypos = (int)(slotsize*(myidx+0.5));
Player *closerp;
int minxsearching = net, minopx, opx, closer;
for ( it = plv.begin();
it != plv.end();
it++ ) {
opx = (side>0)?((*it)->maxX()-(*it)->x()-(*it)->width()/2):
((*it)->x()+(*it)->width()/2-(*it)->minX());
if ( ( (*it)->id() != id() ) &&
( abs(opx-mypos) < minxsearching ) ){
closer=(*it)->id();
closerp=(*it);
minxsearching=abs(opx-mypos);
minopx=opx;
}
}
/* Someone is inside my slot over the 15% the slot size */
if (minxsearching < (slotsize*0.35)) {
myidx = closerp->orderInField();
closerp->setOIF(orderInField());
setOIF(myidx);
}
mypos = (int )(slotsize*(myidx+0.5));
minslot = (int )(slotsize*myidx);
maxslot = (int )(slotsize*(myidx+1));
} else {
minslot = wall;
mypos = mp-50; // behind the middle point
maxslot = net;
}
/* My rest position has been chosen, and the slot determined */
// int hd = 3*_b->radius()/4;
int hd = (_b->radius()+width())/2;
int minhd = 0;
if ( !_b->gravity() ) {
if (hd/2 >= 12)
minhd = rand()%(hd/2-10)+10;
hd = rand()%(hd-minhd)+minhd+1;
}
/* When I consider closer, is the closer to the falling point */
/* I care whether I'm the closer only when it's "service time" */
int closest = 1;
if ( !_b->gravity() ) {
int opx;
std::vector<Player *> plv = (team())->players();
/* Look for my id */
std::vector<Player *>::iterator it;
for ( it = plv.begin();
it != plv.end();
it++ ) {
opx = (side>0)?((*it)->maxX()-(*it)->x()-(*it)->width()/2):
((*it)->x()+(*it)->width()/2-(*it)->minX());
if ( abs(px-xt) > abs(opx-xt) )
closest = 0;
}
}
// printf("%d\n", _b->spdy());
// if (abs(bsx) < 160) hd += 7;
if ( _b->gravity() ) {
if ( ( (abs(px - bx)) <= hd ) && // is the ball close?
//(abs(_b->spdy()) > 10) && // is the ball going down too slow?
//( abs(px-bx) > 5 ) && // am I to close to the ball center?
// Can I reach the ball jumping, or am I missing the ball?
(_b->y() > ((_b->spdy() > 20)?JUMP_LIMIT:(JUMP_LIMIT+20)))
) {
jmp = 1;
}
} else { // I serve only forward
jmp = ( (minhd < (bx - px) && ((bx - px) <= hd) ) );
}
// printf("hd: %d - %d (%d - %d)\n",hd, abs(bx-px), _b->spdy(), _b->y());
// if I'm the closest player I serve (when it's "service time").
// if the ball is (too) outside my slot I do not go for it.
double concern = (nplrs>1)?(slotsize*1.05):slotsize;
if ( (abs(xt-mypos) < concern) && closest) {
if ( _b->gravity() ) {
move = xt-hd-px;
} else { // I serve only forward
move = bx-hd-px;
}
if ( ( ttime < JUMPING_TIME ) ){
jmp = 1;
move = (bx-px);
}
} else {
move = mypos-px;
}
move=-side*(move);
ret.left = ret.right = ret.jump = 0;
if ( abs(move) > 2) {
if ( move < 0 )
ret.left = 1;
if ( move > 0 )
ret.right = 1;
}
if ( jmp )
ret.jump = 1;
return ret;
}

View File

@@ -0,0 +1,50 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __PLAYERAI_H__
#define __PLAYERAI_H__
#include "Player.h"
#include "ControlsArray.h"
class Ball;
class PlayerAI : public Player {
Ball * _b;
protected:
int _highestpoint;
public:
PlayerAI(Team *team, std::string name,
pl_type_t type, int idx, int speed,
Ball *b) {
init(team, name, type, idx, speed);
_b = b;
_highestpoint = 0;
}
virtual pl_ctrl_t getCtrl() { return PL_CTRL_AI; }
virtual triple_t planAction();
};
#endif

View File

@@ -0,0 +1,39 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __PLAYERHUMAN_H__
#define __PLAYERHUMAN_H__
#include "Player.h"
class PlayerHuman : public Player {
public:
PlayerHuman(Team *team, std::string name,
pl_type_t type, int idx, int speed) {
init(team, name, type, idx, speed);
}
pl_ctrl_t getCtrl() { return PL_CTRL_HUMAN; }
};
#endif

View File

@@ -0,0 +1,39 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __PLAYERREMOTE_H__
#define __PLAYERREMOTE_H__
#include "Player.h"
class PlayerRemote : public Player {
public:
PlayerRemote(Team *team, std::string name,
pl_type_t type, int idx, int speed) {
init(team, name, type, idx, speed);
}
pl_ctrl_t getCtrl() { return PL_CTRL_REMOTE; }
};
#endif

View File

@@ -0,0 +1,61 @@
Welcome to GAV, a GPL rendition of the popular Arcade Volleyball.
Some menu items might not be implemtented yet.
See CHANGELOG for recent modifications.
Keys:
default keys are:
Left player: z, c and left shift
Right player: left, right and up cursor keys.
use the arrow keys to navigate the menus, spacebar or enter to activate
items, F10 to switch to fullscreen mode while playing.
Network Game:
One of the programs must function as server. The server determines
the parameters of the game (except for the theme, which might be
different from client to client). Whatever player the server configures
as "Keyboard/Joy" is local to the server, "Computer/Net" players are controlled
either by the computer or by a remote client. Starting the server, you
specify how many clients will attach: each of them will replace a computer
player. This way, you can play in several different ways: a local player
against a remote one, a local and AI player against 2 remote ones, an AI
player against a local and a remote one... Bear in mind that players 1 and 3
play on the left side, and 2 and 4 on the right side.
The client need not select anything about the players: just the side it
will play on (left or right). Currently, only one player per client is
allowed (while more than one can play on the server). The client's player
is always controlled by Player 1's controls.
Installing themes:
themes default to the /usr/share/games/gav/themes directory, but if a
directory ./themes exists, they are looked for in such a directory. This
might cause problem if you start GAV from a directory that contains
a 'themes' subdirectory, but no classic theme, which is the
default.
Sounds:
Sounds are looked for in the current theme's directory. If no sound is
found there, they are looked for in the "default sound" directory,
which is the directory "sounds" at the same level as the "themes"
directory. Provided with the game by default (as long as theme
creators do not come with appropriate sounds for their themes) are the
default sounds (two 'whistles' at different pitch indicating the
service change and the scoring of a point). Theme creators interesting in
setting up sounds, can find the sound filenames, associated with the various
events, in the array "sound_fnames", found in SoundMgr.cpp.
Thanks:
- Marius Andreiana, who provided the gnome menu entry.
- Mark Whittington, who provided patches to compile
under Win32, and working on an installer.
- Fernando "Yisus" Notari, who provided the Yisus, Yisus2 and unnamed themes.
- El Fabio, who provided the fabeach theme.
- Serge S. Fukanchik for his feedback and his precious aid to increase
GAV efficiency.
- Aleksander Kam for provinding a useful patch
Authors:
To contact the authors, please refer to the Sourceforge project page
http://www.sourceforge.net/projects/gav

View File

@@ -0,0 +1 @@
2005-12-27 PRESCALE (before the scale feature)

View File

@@ -0,0 +1,13 @@
Welcome to GAV, a GPL rendition of the popular Arcade Volleyball.
Some of the menu items have not been implemented yet. Themes
support is there, but unaccessible if not from the code.
The keys are:
left player: z, c and left shift
right player: <-, -> and cursor up.
To activate a menu item, SPACE.
To exit from the game and go back to the menu, ESC
To switch to fullscreen (much faster), F10

View File

@@ -0,0 +1,198 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* These functions are derived from SDL_buffer.
*/
#include <stdlib.h>
#include "ResizeSurface.h"
typedef struct tColorRGBA {
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 a;
} tColorRGBA;
/*
* 32bit Zoomer with optional anti-aliasing by bilinear interpolation.
* Zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface.
* Forked from SDL_rotozoom.c, LGPL (c) A. Schiffler
*/
static int zoomSurfaceRGBA (SDL_Surface * src, SDL_Surface * dst)
{
int x, y, //current dst->x and dst->y
xscale, yscale, //src/dst proportions * 65536
*sx_offset, *sy_offset, //row/columnt increment tables
*csx_offset, *csy_offset, //pointers to current row/columnt increment element
csx, csy,
sgap, dgap;
tColorRGBA *sp, *csp, *dp;
// Variables setup
xscale = (int) (65536.0 * (double) src->w / (double) dst->w);
yscale = (int) (65536.0 * (double) src->h / (double) dst->h);
// Allocate memory for row increments
sx_offset = (int*)malloc((dst->w + 1) * sizeof(Uint32));
sy_offset = (int*)malloc((dst->h + 1) * sizeof(Uint32));
if (sx_offset == NULL || sy_offset == NULL) {
free(sx_offset);
free(sy_offset);
return -1;
}
// Precalculate row increments
csx = 0;
csx_offset = sx_offset;
for (x = 0; x <= dst->w; x++) {
*csx_offset = csx;
csx_offset++;
csx &= 0xffff;
csx += xscale;
}
csy = 0;
csy_offset = sy_offset;
for (y = 0; y <= dst->h; y++) {
*csy_offset = csy;
csy_offset++;
csy &= 0xffff;
csy += yscale;
}
// Pointer setup
sp = csp = (tColorRGBA *) src->pixels;
dp = (tColorRGBA *) dst->pixels;
sgap = src->pitch - src->w * 4;
dgap = dst->pitch - dst->w * 4;
// Switch between interpolating and non-interpolating code
// Non-Interpolating Zoom
csy_offset = sy_offset;
for (y = 0; y < dst->h; y++) {
sp = csp;
csx_offset = sx_offset;
for (x = 0; x < dst->w; x++) {
// Draw
*dp = *sp;
// Advance source pointers
csx_offset++;
sp += (*csx_offset >> 16);
// Advance destination pointer
dp++;
}
// Advance source pointer
csy_offset++;
csp = (tColorRGBA *) ((Uint8 *) csp + (*csy_offset >> 16) * src->pitch);
// Advance destination pointers
dp = (tColorRGBA *) ((Uint8 *) dp + dgap);
}
// Remove temp arrays
free(sx_offset);
free(sy_offset);
return 0;
}
SDL_Surface * resizeSurface (SDL_Surface * buf, int width, int height) {
SDL_PixelFormat * format = buf->format;
int dst_w, dst_h;
Uint32 Rmask,Gmask,Bmask,Amask;
SDL_Surface * dest;
SDL_Surface * tmp;
bool toFree = false;
if (format->BitsPerPixel == 32) {
Rmask = format->Rmask;
Gmask = format->Gmask;
Bmask = format->Bmask;
Amask = format->Amask;
} else {
Rmask = 0x000000ff;
Gmask = 0x0000ff00;
Bmask = 0x00ff0000;
Amask = 0xff000000;
}
if (format->BitsPerPixel != 32 ||
format->Rmask != Rmask ||
format->Gmask != Gmask ||
format->Bmask != Bmask) {
// New source surface is 32bit with defined RGBA ordering.
// Note that Amask has been ignored in test
tmp = SDL_CreateRGBSurface (SDL_SWSURFACE, buf->w, buf->h, 32,
Rmask, Gmask, Bmask, Amask);
SDL_BlitSurface (buf, NULL, tmp, NULL);
toFree = true;
} else
tmp = buf;
dst_w = width;
dst_h = height;
// Alloc space to completely contain the zoomed surface
// Target surface is 32bit with source RGBA/ABGR ordering
// (note that buf->zoom is already NULL)
dest = SDL_CreateRGBSurface (SDL_SWSURFACE, width, height, 32,
Rmask, Gmask, Bmask, Amask);
SDL_LockSurface(tmp);
SDL_LockSurface(dest);
zoomSurfaceRGBA(tmp, dest);
// Turn on source-alpha support
SDL_SetAlpha(dest, SDL_SRCALPHA, 255);
SDL_UnlockSurface(tmp);
SDL_UnlockSurface(dest);
if (toFree) SDL_FreeSurface(tmp);
// Return destination surface
return dest;
}

View File

@@ -0,0 +1,29 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __RESIZESURFACE_H__
#define __RESIZESURFACE_H__
#include <SDL.h>
SDL_Surface * resizeSurface (SDL_Surface * buf, int width, int height);
#endif

View File

@@ -0,0 +1,67 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <string.h>
#include "globals.h"
#include "GameRenderer.h"
#include "ScreenFont.h"
/* Converts to SCREEN coordinates! Should me moved into GameRenderer or something! */
void ScreenFont::printXY(SDL_Surface *dest, SDL_Rect *rect, const char * str,
bool wrapAround, FrameSeq *bg)
{
SDL_Rect r;
int _charWid = _frames->screenWidth();
r = gameRenderer->convertCoordinates(rect);
r.h = _frames->getActualFrameSeq()->height();
r.w = _frames->getActualFrameSeq()->width();
const char *run = str;
while ( *run ) {
if ( wrapAround )
//r.x = (r.x + dest->w) % dest->w;
r.x = (r.x + configuration.resolution.x) % configuration.resolution.x;
if ( ((*run) >= _fst) && ((*run) < (_fst + _nchars)) ) {
if ( bg )
bg->getActualFrameSeq()->blitRect(0, dest, &r);
_frames->getActualFrameSeq()->blit((int) ((*run) - _fst), dest, &r);
}
run++;
r.x += _charWid;
}
}
void ScreenFont::printRow(SDL_Surface *dest, int row, const char *str,
FrameSeq *bg)
{
SDL_Rect rect;
/* draw menu items labels */
rect.y = configuration.CEILING + configuration.env.h/100 +
row * charHeight();
rect.x = (configuration.env.w / 2) - strlen(str)*(charWidth())/2;
printXY(dest, &rect, str, false, bg);
}

View File

@@ -0,0 +1,58 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _SCREENFONT_H_
#define _SCREENFONT_H_
#include <SDL.h>
#include "LogicalFrameSeq.h"
#define FONT_FIRST_CHAR ' '
#define FONT_NUMBER 104
class FrameSeq;
class ScreenFont {
private:
FrameSeq *_frames;
char _fst; // first character
unsigned char _nchars;
public:
ScreenFont(const char *fname, char fst, unsigned char n) :
_fst(fst), _nchars(n) {
_frames = new LogicalFrameSeq(fname, (int) n);
}
~ScreenFont() {
delete(_frames);
}
void printXY(SDL_Surface *dest, SDL_Rect *r, const char * str,
bool wrapAround = true, FrameSeq *background = NULL);
void printRow(SDL_Surface *dest, int row, const char *str,
FrameSeq *bg = NULL);
inline int charWidth() { return(_frames->width()); }
inline int charHeight() { return(_frames->height()); }
};
#endif // _SCREENFONT_H_

View File

@@ -0,0 +1,99 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "Sound.h"
#include <string.h>
#ifdef AUDIO
int Sound::loadAndConvertSound(const char *filename, SDL_AudioSpec *spec,sound_p sound)
{
SDL_AudioCVT cvt;
SDL_AudioSpec loaded;
Uint8 *new_buf;
// printf("loading sound: %s\n", filename);
if(SDL_LoadWAV(filename, &loaded,&sound->samples, &sound->length)==NULL) {
printf("Cannot load the wav file %s\n", filename);
return 1;
}
if (SDL_BuildAudioCVT(&cvt, loaded.format, loaded.channels,loaded.freq,spec->format,
spec->channels,spec->freq)<0)
{
printf("Cannot convert the sound file %s\n", filename);
}
cvt.len =sound->length;
new_buf = (Uint8 *) malloc(cvt.len*cvt.len_mult);
memcpy(new_buf,sound->samples,sound->length);
cvt.buf = new_buf;
if(SDL_ConvertAudio(&cvt)<0) {
printf("Audio conversion failed for file %s\n", filename);
free(new_buf);
SDL_FreeWAV(sound->samples);
return 1;
}
SDL_FreeWAV(sound->samples);
sound->samples = new_buf;
sound->length = sound->length * cvt.len_mult;
return 0;
}
int Sound::playSound(bool loop)
{
int i;
for(i=0;i<MAX_PLAYING_SOUNDS;i++)
{
if(playing[i].active==0)
break;
}
if(i==MAX_PLAYING_SOUNDS)
return 1;
id = i;
SDL_LockAudio();
playing[i].active=1;
playing[i].sound=&this_sound;
playing[i].position=0;
playing[i].loop = loop;
SDL_UnlockAudio();
return 0;
}
void Sound::stopSound() {
playing[id].active = 0;
}
#endif //AUDIO

View File

@@ -0,0 +1,48 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __SOUND_H__
#define __SOUND_H__
#include <SDL.h>
#include "globals.h"
#ifdef AUDIO
class Sound {
private:
int id; // id in playing vector
sound_t this_sound;
int loadAndConvertSound(const char *filename, SDL_AudioSpec *spec,sound_p sound);
public:
Sound(const char *filename) {
loadAndConvertSound(filename,&obtained,&this_sound);
}
Sound() {};
int loadSound(const char *fname) {
return loadAndConvertSound(fname,&obtained,&this_sound);
}
int playSound(bool loop);
void stopSound();
};
#endif
#endif //_SOUND_H_

View File

@@ -0,0 +1,96 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "SoundMgr.h"
#ifdef AUDIO
/* this should be synchronized with enum SND_* in global.h */
char *sound_fnames[] = {
"bounce.wav",
"select.wav",
"activate.wav",
"score.wav",
"victory.wav",
"partialnet.wav",
"fullnet.wav",
"servicechange.wav",
"playerhit.wav",
"background_playing.wav",
"background_menu.wav",
NULL
};
SoundMgr::SoundMgr(const char *dir, const char *defdir)
{
memset(sounds, 0, sizeof(Sound *) * MAX_SOUNDS);
const char *actualdir = dir?dir:defdir;
struct stat sbuf;
if ( dir && stat(dir, &sbuf) )
actualdir = defdir;
char fname[100];
int sndidx = 0;
for ( sndidx = SND_BOUNCE; sound_fnames[sndidx] && (sndidx <= SND_BACKGROUND_MENU);
sndidx++ ) {
sprintf(fname, "%s/%s", actualdir, sound_fnames[sndidx]);
FILE *fp = fopen(fname, "r");
if ( !fp ) continue;
printf("sound: %s\n", fname);
fclose(fp);
sounds[sndidx] = new Sound();
if ( sounds[sndidx]->loadSound(fname) ) {
delete(sounds[sndidx]);
sounds[sndidx] = NULL;
}
}
nsounds = sndidx;
}
SoundMgr::~SoundMgr()
{
int sndidx = 0;
for ( sndidx = SND_BOUNCE; (sndidx <= SND_PLAYERHIT); sndidx++ )
if ( sounds[sndidx] )
delete(sounds[sndidx]);
}
int SoundMgr::playSound(int which, bool loop) {
if ( sounds[which] && configuration.sound )
return sounds[which]->playSound(loop);
else
return 0;
}
void SoundMgr::stopSound(int which) {
if ( sounds[which] && configuration.sound )
sounds[which]->stopSound();
}
#endif

View File

@@ -0,0 +1,48 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __SOUNDMGR_H__
#define __SOUNDMGR_H__
#include <SDL.h>
#include "globals.h"
#include "Sound.h"
#ifdef AUDIO
#define MAX_SOUNDS 16
class SoundMgr {
private:
Sound *sounds[MAX_SOUNDS];
int nsounds;
public:
SoundMgr(const char *dir, const char *defdir);
~SoundMgr();
int playSound(int which, bool loop = false);
void stopSound(int which);
};
#endif
#endif //_SOUNDMGR_H_

View File

@@ -0,0 +1,169 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _TEAM_H_
#define _TEAM_H_
#include <SDL.h>
#include <vector>
#include "Player.h"
#include "PlayerHuman.h"
#include "PlayerAI.h"
#include "PlayerRemote.h"
#include "ControlsArray.h"
#include "ScreenFont.h"
#include "globals.h"
class Ball;
extern ScreenFont *cga;
class Team {
private:
std::vector<Player *> _players;
int _xmin;
int _xmax;
int _ymin;
int _ymax;
int _score;
int _side;
int _nplayers;
int _playerNumInc;
inline void addPlayer(Player * p) {
_players.push_back(p);
for(unsigned int i = 0; i < _players.size(); i++)
_players[i]->setX((i+1) * (_xmax + _xmin) / (_players.size()+1) -
(p->width() / 2));
p->setY(p->GROUND_LEVEL());
_nplayers++;
}
public:
// side < 0: left, > 0 right
Team(int side = -1) : _side(side) {
_score = 0;
_nplayers = 0;
_playerNumInc = (side<0)?0:1;
_xmin =
(side<0)?(configuration.LEFT_WALL+1):(configuration.SCREEN_WIDTH / 2) ;
//304 the real half field width
// _xmax = _xmin + 304 ;
// _xmax = _xmin + (configuration.SCREEN_WIDTH / 2) - 16;
_xmax = _xmin + ((304*configuration.SCREEN_WIDTH)/640);
_ymin = 0;
_ymax = 0;
}
inline void score() {
_score++;
}
inline void setScore(int v) {
_score = v;
}
inline int getScore() {
return(_score);
}
inline Player * addPlayerHuman(std::string name,
pl_type_t type,
int speed = configuration.DEFAULT_SPEED) {
Player *p = new PlayerHuman(this, name, type,
_nplayers * 2 + _playerNumInc, speed);
addPlayer(p);
return p;
}
inline Player * addPlayerRemote(std::string name,
pl_type_t type,
int speed = configuration.DEFAULT_SPEED) {
Player *p = new PlayerRemote(this, name, type,
_nplayers * 2 + _playerNumInc, speed);
addPlayer(p);
return p;
}
inline Player * addPlayerAI(std::string name,
pl_type_t type, Ball * b,
int speed = configuration.DEFAULT_SPEED) {
Player *p = new PlayerAI(this, name, type,
_nplayers * 2 + _playerNumInc, speed, b);
addPlayer(p);
return p;
}
inline std::vector<Player *> players() {
return(_players);
}
inline int xmax() { return _xmax; }
inline int xmin() { return _xmin; }
inline int ymax() { return _ymax; }
inline int ymin() { return _ymin; }
inline int side() { return _side; }
inline int nplayers() { return _nplayers; }
inline void xmax(int v) { _xmax = v; }
inline void xmin(int v) { _xmin = v; }
inline void ymax(int v) { _ymax = v; }
inline void ymin(int v) { _ymin = v; }
void draw(SDL_Surface *scr = screen) {
SDL_Rect r;
r.x = (_xmin < (configuration.SCREEN_WIDTH/3))?100:(_xmax - 100);
r.y = 0;
for ( std::vector<Player *>::const_iterator it = _players.begin();
it != _players.end(); it++ )
(*it)->draw(scr);
char s[100];
sprintf(s, "%d", _score);
cga->printXY(scr, &r, s);
}
void update(int ticks, ControlsArray *ca) {
for ( std::vector<Player *>::const_iterator it = _players.begin();
it != _players.end(); it++ ) {
(*it)->update(ticks, ca);
}
}
~Team() {
Player *pl[_players.size()];
int i = 0;
for ( std::vector<Player *>::const_iterator it = _players.begin();
it != _players.end(); it++ ) {
pl[i++] = (*it);
}
for ( int j = 0; j < i; j++ ) {
delete pl[j];
}
}
};
#endif // _TEAM_H_

View File

@@ -0,0 +1,137 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef WIN32
#include <unistd.h>
#else
#include <sys/types.h>
#include <sys/stat.h>
#endif /* WIN32 */
#include <string>
#include <iostream>
#include "Theme.h"
using namespace std;
Theme *CurrentTheme;
string ThemeDir;
void errorOn(string file) {
throw Theme:: ThemeErrorException("Error accessing file " + file);
}
bool Theme::_checkTheme() {
bool r;
_hasConfFile = true;
#ifndef WIN32
cerr << "Verifying Theme `" << _name << "' [" << ThemeDir << "/" << _name << "/]:\n";
if ( access(_CCS(_background), R_OK) ) {
if (!_bigBackground)
_background = TD + TH_BACKGROUND_JPG;
else
_background = TD + TH_BACKGROUND_BIG_JPG;
if ( access(_CCS(_background), R_OK) ) errorOn("background.{jpg,png}");
}
if ( access(_CCS(_font), R_OK) ) errorOn(TH_FONT);
if ( access(_CCS(_fontinv), R_OK) ) errorOn(TH_FONTINV);
if ( access(_CCS(_leftmale), R_OK) ) errorOn(TH_LEFTMALE);
if ( access(_CCS(_rightmale), R_OK) ) errorOn(TH_RIGHTMALE);
if ( access(_CCS(_leftfemale), R_OK) ) errorOn(TH_LEFTFEMALE);
if ( access(_CCS(_rightfemale), R_OK) ) errorOn(TH_RIGHTFEMALE);
if ( access(_CCS(_ball), R_OK) ) errorOn(TH_BALL);
if ( access(_CCS(_confFile), R_OK) ) _hasConfFile = false;
r = (access(_CCS(_net), R_OK) == 0);
#else
struct _stat sStat ;
cerr << "Verifying Theme `" << _name << "' [" << ThemeDir << "\\" << _name << "\\]:\n";
if (_stat (_background.c_str(), &sStat)) {
if (!_bigBackground)
_background = TD + TH_BACKGROUND_JPG;
else
_background = TD + TH_BACKGROUND_BIG_JPG;
if (_stat (_background.c_str(), &sStat)) errorOn("background.{jpg,png}");
}
if (_stat (_font.c_str(), &sStat)) errorOn (TH_FONT) ;
if (_stat (_fontinv.c_str(), &sStat)) errorOn (TH_FONTINV) ;
if (_stat (_leftmale.c_str(), &sStat)) errorOn (TH_LEFTMALE) ;
if (_stat (_rightmale.c_str(), &sStat)) errorOn (TH_RIGHTMALE) ;
if (_stat (_leftfemale.c_str(), &sStat)) errorOn (TH_LEFTFEMALE) ;
if (_stat (_rightfemale.c_str(), &sStat)) errorOn (TH_RIGHTFEMALE) ;
if (_stat (_ball.c_str(), &sStat)) errorOn (TH_BALL) ;
if ( _stat(_confFile.c_str(), &sStat) ) _hasConfFile = false;
r = (_stat (_net.c_str(), &sStat) == 0) ;
#endif /* WIN32 */
if ( !r ) cerr << "Warning: No net for this theme!\n";
cerr << "OK!\n";
configuration.setDefaultFrameConf();
if ( _hasConfFile ) {
cerr << "Using configuration file theme.conf\n";
loadConf();
} else {
cerr << "No theme.conf\n";
}
return(r);
}
void Theme::loadConf()
{
Aargh myAargh; /* I want a new one, 'cause the global one is used by
configuration */
myAargh.loadConf(_confFile.c_str());
/* now set things up in configuration */
string value;
if ( myAargh.getArg("NPlayerFrames", value) )
configuration.playerFrameConf.nPlayerFrames = atoi(value.c_str());
if ( myAargh.getArg("PlayerStillB", value) )
configuration.playerFrameConf.playerStillB = atoi(value.c_str());
if ( myAargh.getArg("PlayerStillE", value) )
configuration.playerFrameConf.playerStillE = atoi(value.c_str());
if ( myAargh.getArg("PlayerStillP", value) )
configuration.playerFrameConf.playerStillP = atoi(value.c_str());
if ( myAargh.getArg("PlayerRunB", value) )
configuration.playerFrameConf.playerRunB = atoi(value.c_str());
if ( myAargh.getArg("PlayerRunE", value) )
configuration.playerFrameConf.playerRunE = atoi(value.c_str());
if ( myAargh.getArg("PlayerRunP", value) )
configuration.playerFrameConf.playerRunP = atoi(value.c_str());
if ( myAargh.getArg("PlayerJumpB", value) )
configuration.playerFrameConf.playerJmpB = atoi(value.c_str());
if ( myAargh.getArg("PlayerJumpE", value) )
configuration.playerFrameConf.playerJmpE = atoi(value.c_str());
if ( myAargh.getArg("PlayerJumpP", value) )
configuration.playerFrameConf.playerJmpP = atoi(value.c_str());
if ( myAargh.getArg("NBallFrames", value) )
configuration.ballFrameConf.nBallFrames = atoi(value.c_str());
if ( myAargh.getArg("BallPeriod", value) )
configuration.ballFrameConf.ballPeriod = atoi(value.c_str());
}

View File

@@ -0,0 +1,229 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _THEMES_H_
#define _THEMES_H_
#include <string>
#include <iostream>
#include <sys/types.h>
#ifndef WIN32
#include <dirent.h>
#else
#include <windows.h>
#endif /* WIN32 */
#include <SDL.h>
#include <SDL_image.h>
#include "SoundMgr.h"
#include "globals.h"
#include "GameRenderer.h"
#include "Menu.h"
#include "MenuItem.h"
#include "MenuItemMonitor.h"
#define TH_DIR "themes"
#define TH_NET "net.png"
#define TH_LEFTMALE "plml.png"
#define TH_RIGHTMALE "plmr.png"
#define TH_LEFTFEMALE "plfl.png"
#define TH_RIGHTFEMALE "plfr.png"
#define TH_BACKGROUND_JPG "background.jpg"
#define TH_BACKGROUND_PNG "background.png"
#define TH_BACKGROUND_BIG_JPG "background_big.jpg"
#define TH_BACKGROUND_BIG_PNG "background_big.png"
#define TH_BALL "ball.png"
#define TH_FONT "Font.png"
#define TH_FONTINV "FontInv.png"
#define TH_CONFNAME "theme.conf"
extern std::string ThemeDir;
class Theme {
private:
std::string _name;
bool _hasnet; // To possibly add the image of the net (not used yet)
std::string _background;
std::string _net;
std::string _font;
std::string _fontinv;
std::string _leftmale;
std::string _rightmale;
std::string _leftfemale;
std::string _rightfemale;
std::string _ball;
std::string _confFile;
std::string TD;
bool _hasConfFile;
bool _bigBackground;
bool _checkTheme(); // Theme Validation
public:
Theme(std::string name) {
#ifndef WIN32
DIR *dir;
if ((dir = opendir(ThemeDir.c_str())) == NULL) {
ThemeDir = "/usr/share/games/gav/" + ThemeDir;
if ((dir = opendir(ThemeDir.c_str())) == NULL) {
std::cerr << "Cannot find themes directory\n";
exit(0);
} else
closedir(dir);
} else
closedir(dir);
configuration.currentTheme = name;
TD = ThemeDir + "/" + name + "/";
#else
HANDLE hFindFile ;
WIN32_FIND_DATA ffdData ;
hFindFile = FindFirstFile (ThemeDir.c_str(), &ffdData) ;
if (hFindFile == INVALID_HANDLE_VALUE)
{
std::cerr << "Cannot find themes directory\n" ;
exit(0) ;
}
FindClose (hFindFile) ;
TD = ThemeDir + "\\" + name + "\\" ;
#endif /* WIN32 */
_name = name;
_bigBackground = configuration.bgBig;
if ( _bigBackground ) {
printf("Big Background hack: FIX IT!\n");
configuration.env.w = BIG_ENVIRONMENT_WIDTH;
configuration.env.h = BIG_ENVIRONMENT_HEIGHT;
double rat = ((double) configuration.desiredResolution.y) /
(double) BIG_ENVIRONMENT_HEIGHT;
int w = (int) (rat * BIG_ENVIRONMENT_WIDTH);
int h = configuration.desiredResolution.y;
configuration.setResolution(w, h);
configuration.scaleFactors(BIG_ENVIRONMENT_WIDTH,
BIG_ENVIRONMENT_HEIGHT);
} else {
configuration.env.w = ENVIRONMENT_WIDTH;
configuration.env.h = ENVIRONMENT_HEIGHT;
configuration.setResolutionToDesired();
configuration.scaleFactors(ENVIRONMENT_WIDTH, ENVIRONMENT_HEIGHT);
}
_net = TD + TH_NET;
if (!_bigBackground)
_background = TD + TH_BACKGROUND_PNG;
else
_background = TD + TH_BACKGROUND_BIG_PNG;
_font = TD + TH_FONT;
_fontinv = TD + TH_FONTINV;
_leftmale = TD + TH_LEFTMALE;
_rightmale = TD + TH_RIGHTMALE;
_leftfemale = TD + TH_LEFTFEMALE;
_rightfemale = TD + TH_RIGHTFEMALE;
_confFile = TD + TH_CONFNAME;
_ball = TD + TH_BALL;
_hasnet = Theme::_checkTheme();
// ::background = IMG_Load(background());
// TODO: fetch the environment size (and therefore the ratios)
// from the background image
//if ( CurrentTheme->hasnet() ) IMG_Load(CurrentTheme->net());
//screenFlags = SDL_DOUBLEBUF|SDL_HWSURFACE;
//screenFlags |= SDL_DOUBLEBUF;
screen = SDL_SetVideoMode(configuration.resolution.x,
configuration.resolution.y,
videoinfo->vfmt->BitsPerPixel,
screenFlags);
::background = new LogicalFrameSeq(background(), 1, false);
gameRenderer = new GameRenderer(configuration.resolution.x,
configuration.resolution.y,
configuration.env.w,
configuration.env.h);
cga = new ScreenFont(font(), FONT_FIRST_CHAR, FONT_NUMBER);
cgaInv = new ScreenFont(fontinv(), FONT_FIRST_CHAR, FONT_NUMBER);
MenuItemMonitor().apply();
#ifdef AUDIO
if ( soundMgr )
delete(soundMgr);
soundMgr = new SoundMgr((TD+"sounds").c_str(),
(ThemeDir+"/../sounds").c_str());
#endif // AUDIO
}
~Theme() {
delete(::background);
delete(cga);
delete(cgaInv);
delete(gameRenderer);
}
#define _CCS(str) ((str).c_str())
inline const char * name() { return( _CCS(_name) );}
inline bool hasnet() { return( _hasnet );}
inline bool bigBackground() { return( _bigBackground );}
inline const char * background() { return( _CCS(_background) );}
inline const char * net() { return( _CCS(_net) );}
inline const char * font() { return( _CCS(_font) );}
inline const char * fontinv() { return( _CCS(_fontinv) );}
inline const char * leftmale() { return( _CCS(_leftmale) );}
inline const char * rightmale() { return( _CCS(_rightmale) );}
inline const char * leftfemale() { return( _CCS(_leftfemale) );}
inline const char * rightfemale(){ return( _CCS(_rightfemale) );}
inline const char * ball() { return( _CCS(_ball) );}
void loadConf();
class ThemeErrorException {
public:
std::string message;
ThemeErrorException(std::string msg) {
message = msg;
}
};
};
extern Theme *CurrentTheme;
inline void setThemeDir(std::string h) { ThemeDir = h; }
#endif

View File

@@ -0,0 +1,179 @@
/* -*- C++ -*- */
#ifndef _AARG_H_
#define _AARG_H_
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <map>
#include <string>
#include <sstream>
class Aargh
{
public:
Aargh ()
{
}
// questo costruttore serve per avere i parametri caricati
// prima dell'avvio di main, cosi' da poter chiamare i
// costruttori degli oggetti globali che dipendono da
// dei parametri
Aargh (char *filename)
{
loadConf (filename);
}
// questi altri due costruttori sono meno necessari ma
// sono comunque utili
Aargh (int argc, char **argv)
{
parseArgs (argc, argv);
}
// vedi sopra
Aargh (int argc, char **argv, char *filename)
{
parseArgs (argc, argv);
loadConf (filename);
}
// parametri accettati
// -qualcosa
// -qualcosa valore
bool parseArgs (int argc, char **argv)
{
bool allright = true;
std::string base = "";
for (int i = 1; i < argc; ++i)
{
if (argv[i][0] == '-')
{
base = std::string (argv[i]);
argmap[base] = "_Aargh";
}
else
{
if (base != "")
{
argmap[base] = std::string (argv[i]);
base = "";
}
else
allright = false;
}
}
return allright;
}
bool loadConf (const char *filename)
{
bool allright = true;
FILE *fp;
char ln[128];
if ((fp = fopen (filename, "r")) == NULL)
return (false);
while (fgets (ln, 128, fp))
if (*ln != '#' && *ln != '\n')
{
char *key = ln;
char *value = ln;
while ((*value != ' ') && (*value != '\t') && (*value != '\n'))
value++; // finds the first space or tab
if (*value == '\n')
{
*value = '\0';
argmap[key] = "_Aargh";
continue;
}
// removes spaces and tabs
while ((*value == ' ') || (*value == '\t'))
{
*value = '\0';
value++;
}
char *end = value;
while ((*end != '\n') && (*end))
end++;
*end = '\0'; // null terminates value (fgets puts a '\n' at the end)
// now, key is a null terminated string holding the key, and value is everything which
// is found after the first series of spaces or tabs.
if (strcmp (key, "") && strcmp (value, ""))
argmap[key] = value;
}
return allright;
}
bool getArg (std::string name)
{
return (argmap.find (name) != argmap.end ());
}
bool getArg (std::string name, std::string & value)
{
if (argmap.find (name) != argmap.end ())
{
value = argmap[name];
return true;
}
else
return false;
}
bool getArg (std::string name, std::string & value, const char* def)
{
if ( getArg(name, value) )
return true;
else
value = std::string(def);
return false;
}
bool setArg (std::string name, std::string value)
{
bool ret = (argmap.find (name) != argmap.end ());
// std::cerr << "Setting " << name << " to: " << value << std::endl;
argmap[name] = value;
return(ret);
}
bool setArg (std::string name, int intvalue)
{
std::ostringstream value;
value << intvalue;
bool ret = (argmap.find (value.str()) != argmap.end ());
// std::cerr << "Setting " << name << " to: " << value.str() << std::endl;
argmap[name] = value.str();
return(ret);
}
void dump (std::string & out)
{
std::map < std::string, std::string >::const_iterator b = argmap.begin ();
std::map < std::string, std::string >::const_iterator e = argmap.end ();
out = "";
while (b != e)
{
out += b->first + ' ' + b->second + '\n';
++b;
}
}
void reset() {
argmap.clear();
}
private:
std::map < std::string, std::string > argmap;
};
extern Aargh aargh;
#endif // _AARG_H_

View File

@@ -0,0 +1,55 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _AUTOMA_H_
#define _AUTOMA_H_
#include <vector>
#include "State.h"
#define NO_TRANSITION (0)
class Automa {
protected:
State *_states[100]; // max 100 states
int _curr; // current state index
int _prev;
int _size;
public:
Automa() {
_size = 0;
for ( int i = 0; i < 100; _states[i++] = NULL );
};
virtual int addState(int idx, State *state) {
_states[idx] = state;
return(_size++);
}
virtual int start() { return(0); }
virtual ~Automa() {
for ( int i = 0; i < 100; i++ )
if ( _states[i] )
delete(_states[i]);
}
};
#endif // _AUTOMA_H_

View File

@@ -0,0 +1,113 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <SDL.h>
#include "AutomaMainLoop.h"
#include "InputState.h"
#include "globals.h"
#include "StateMenu.h"
#include "StatePlaying.h"
#include "MenuItemFullScreen.h"
#ifndef NONET
#include "StateClient.h"
#endif
AutomaMainLoop::AutomaMainLoop()
{
_is = new InputState();
StateMenu *sm = new StateMenu();
addState(STATE_MENU, sm);
_curr = STATE_MENU;
StatePlaying *sp = new StatePlaying();
addState(STATE_PLAYING, sp);
#ifndef NONET
StateClient *sc = new StateClient();
addState(STATE_CLIENT, sc);
#endif
_prev = -1;
}
int AutomaMainLoop::transition(int retval)
{
if ( retval == NO_TRANSITION )
return(_curr);
#if 0
switch ( _curr ) {
case STATE_MENU:
return STATE_PLAYING;
break;
case STATE_PLAYING:
return STATE_MENU;
break;
#ifndef NONET
case STATE_CLIENT:
return STATE_MENU;
break;
#endif
}
#endif
return retval; // _curr;
}
int AutomaMainLoop::start()
{
unsigned int prevTicks = 0;
// unsigned int prevDrawn = 0;
unsigned int frames = 0;
unsigned int milliseconds;
while ( 1 ) {
int ticks = SDL_GetTicks();
if ( prevTicks == 0 ) {
prevTicks = ticks;
continue;
}
frames++;
milliseconds += ticks - prevTicks;
if ( milliseconds >= 1000 )
frames = milliseconds = 0;
_is->getInput();
if ( _is->getF()[9] ) {
std::stack<Menu *> s;
MenuItemFullScreen().execute(s);
}
// execute the _curr state's code, and transact
int retval = _states[_curr]->execute(_is,
ticks, prevTicks,
(_prev != _curr));
_prev = _curr;
_curr = transition(retval);
if ( (ticks - prevTicks) < configuration.mill_per_frame )
SDL_Delay(configuration.mill_per_frame - (ticks - prevTicks));
prevTicks = ticks;
}
return(0);
}

View File

@@ -0,0 +1,47 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <SDL.h>
#include "Automa.h"
#include "InputState.h"
#include "globals.h"
#ifndef _AUTOMAMAINLOOP_H_
#define _AUTOMAMAINLOOP_H_
enum { STATE_MENU = 1, // navigate menu tree
STATE_PLAYING, // play the game
STATE_CLIENT // start the game as a client
};
class AutomaMainLoop : public Automa {
private:
InputState *_is;
int transition(int retval);
public:
AutomaMainLoop();
virtual int start();
};
#endif

View File

@@ -0,0 +1,48 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = automa
include ../CommonHeader
NAME = automa
MODULE_NAME = $(NAME)_module.o
CXXFLAGS += -I$(GAV_ROOT) -I$(GAV_ROOT)/menu -I$(GAV_ROOT)/net -I$(GAV_ROOT)/automa
DEPEND = Makefile.depend
.PHONY: all
all: $(MODULE_NAME)
$(MODULE_NAME): $(OFILES)
$(LD) -r $(OFILES) -o $(MODULE_NAME)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,48 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = automa
include ../CommonHeader
NAME = automa
MODULE_NAME = $(NAME)_module.o
CXXFLAGS += -I$(GAV_ROOT) -I$(GAV_ROOT)/menu -I$(GAV_ROOT)/net -I$(GAV_ROOT)/automa
DEPEND = Makefile.depend
.PHONY: all
all: $(MODULE_NAME)
$(MODULE_NAME): $(OFILES)
$(LD) -r $(OFILES) -o $(MODULE_NAME)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,44 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = automa
include ../CommonHeader
NAME = automa
CXXFLAGS += -I$(GAV_ROOT) -I$(GAV_ROOT)/menu -I$(GAV_ROOT)/net -I$(GAV_ROOT)/automa
DEPEND = Makefile.depend
.PHONY: all
all: $(OFILES)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,46 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _STATE_H_
#define _STATE_H_
#include<string>
#include<iostream>
#include "InputState.h"
class State {
public:
std::string _name; // for debug
State() {};
inline void setName(char *name) { _name = std::string(name); }
inline std::string getName() { return(_name); }
virtual int execute(InputState *is, unsigned int ticks,
unsigned int prevticks, int firstTime) {
std::cout << "unextended state: " << _name << std::endl;
return(0); // NO_TRANSITION
};
virtual ~State() {};
};
#endif // _STATE_H_

View File

@@ -0,0 +1,231 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <SDL.h>
#include "StateClient.h"
#include "AutomaMainLoop.h"
#ifndef NONET
#include "NetClient.h"
#endif //NONET
using namespace std;
int StateClient::setupConnection(InputState *is) {
#ifndef NONET
bool configured = false;
string saddress = "";
signed char ch;
string ports = "";
int port;
char ti;
while ( !configured ) {
/* first, delete the screen... */
SDL_Rect r;
r.x = r.y = 0;
r.h = background->height();
r.w = background->width();
background->blit(0, screen, &r);
//SDL_BlitSurface(background, &r, screen, &r);
SDL_Flip(screen);
/* now, ask for server address, port and team side */
cga->printRow(screen, 0, "Please type server address");
SDL_Flip(screen);
while ( (ch = getKeyPressed(is)) != SDLK_RETURN ) {
if ( ch == SDLK_BACKSPACE ) {
saddress = deleteOneChar(saddress); // should be backspace...
cga->printRow(screen, 1, " ", background);
} else {
char w[2];
w[0] = (char)ch;
w[1] = 0;
saddress = saddress + w;
}
cga->printRow(screen, 1, saddress.c_str(), background);
SDL_Flip(screen);
}
char msg[100];
sprintf(msg, "Please type port number [%d]", SERVER_PORT);
cga->printRow(screen, 2, msg);
SDL_Flip(screen);
while ( (ch = getKeyPressed(is)) != SDLK_RETURN ) {
if ( ch == SDLK_BACKSPACE ) {
ports = deleteOneChar(ports); // should be backspace...
cga->printRow(screen, 3, " ", background);
} else {
char w[2];
w[0] = (char)ch;
w[1] = 0;
ports = ports + w;
}
cga->printRow(screen, 3, ports.c_str(), background);
SDL_Flip(screen);
}
port = atoi(ports.c_str());
if ( !port )
port = SERVER_PORT;
string team = "";
cga->printRow(screen, 4, "Left or right team? (l/r)");
SDL_Flip(screen);
while ( (ch = getKeyPressed(is)) != SDLK_RETURN ) {
if ( ch == SDLK_BACKSPACE ) {
team = deleteOneChar(team); // should be backspace...
cga->printRow(screen, 5, " ", background);
} else {
char w[2];
w[0] = (char)ch;
w[1] = 0;
team = team + w;
}
cga->printRow(screen, 5, team.c_str(), background);
SDL_Flip(screen);
}
ti = (*(team.c_str())=='l')?NET_TEAM_LEFT:NET_TEAM_RIGHT;
configured = true;
}
netc = new NetClient();
cga->printRow(screen, 6, "connecting...");
SDL_Flip(screen);
if ( netc->ConnectToServer(is, &_lp, &_rp, ti, saddress.c_str(),
port) == -1 ) {
delete(netc);
cga->printRow(screen, 7, "host unreachable");
SDL_Flip(screen);
SDL_Delay(1000);
netc = NULL;
return(STATE_MENU);
}
cga->printRow(screen, 7, "connected. Waiting for other clients...");
SDL_Flip(screen);
/* ok, I'm connected and I'm waiting for the game start */
netc->WaitGameStart();
#endif //!NONET
return(0);
}
// executes one step of the game's main loop for a network client.
// before the game loop actually begins, connection must be set up
// Returns NO_TRANSITION if the game continues, the next state otherwise
int StateClient::execute(InputState *is, unsigned int ticks,
unsigned int prevTicks, int firstTime)
{
#ifndef NONET
if ( firstTime ) {
int ret = 0;
if ( (ret = setupConnection(is)) )
return(ret);
#ifdef AUDIO
soundMgr->stopSound(SND_BACKGROUND_MENU);
soundMgr->playSound(SND_BACKGROUND_PLAYING, true);
#endif // AUDIO
/*
First time we change to execute state: we should
probably create players here instead of in the constructor,
and think of a clever way to destroy them once we're done.
*/
prevDrawn = ticks;
tl = new Team(-1);
tr = new Team(1);
b = new Ball(BALL_ORIG);
for ( int j = 0; j < _lp; j++ ) {
string name = "Pippo-" + j;
Player * pl = tl->addPlayerHuman(name.c_str(), PL_TYPE_MALE_LEFT);
pl->setState(PL_STATE_STILL, true);
}
for ( int j = 0; j < _rp; j++ ) {
string name = "Pluto-" + j;
Player * pl = tr->addPlayerHuman(name.c_str(), PL_TYPE_MALE_RIGHT);
pl->setState(PL_STATE_STILL, true);
}
tl->setScore(0);
tr->setScore(0);
b->resetPos((int) (configuration.SCREEN_WIDTH * 0.25),
(int) (configuration.SCREEN_HEIGHT * 0.66));
}
if ( is->getKeyState()[SDLK_ESCAPE] ) {
delete(tl);
delete(tr);
delete(b);
delete(netc);
netc = NULL;
#ifdef AUDIO
soundMgr->stopSound(SND_BACKGROUND_PLAYING);
#endif
return(STATE_MENU);
}
controlsArray->setControlsState(is, tl, tr);
triple_t input = controlsArray->getCommands(0);
netc->SendCommand((input.left?CNTRL_LEFT:0)|
(input.right?CNTRL_RIGHT:0)|
(input.jump?CNTRL_JUMP:0));
while ( netc->ReceiveSnapshot(tl, tr, b, ticks - prevTicks) != -1 );
if ( (ticks - prevDrawn) >
(unsigned int) (FPS - (FPS / (configuration.frame_skip + 1)) ) ) {
SDL_Rect r;
r.x = r.y = 0;
r.h = background->height();
r.w = background->width();
//SDL_BlitSurface(background, &r, screen, &r);
background->blit(0, screen, &r);
tl->draw();
tr->draw();
b->draw();
SDL_Flip(screen);
prevDrawn = ticks;
}
if ( ((tl->getScore() >= configuration.winning_score) &&
(tl->getScore() > (tr->getScore()+1))) ||
((tr->getScore() >= configuration.winning_score) &&
(tr->getScore() > (tl->getScore()+1))) ) {
/* Deallocate teams, ball and players */
delete(tl);
delete(tr);
delete(b);
delete(netc);
netc = NULL;
#ifdef AUDIO
soundMgr->stopSound(SND_BACKGROUND_PLAYING);
#endif
return(STATE_MENU); // end of the game
}
#endif // !NONET
return(NO_TRANSITION);
}

View File

@@ -0,0 +1,49 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _STATECLIENT_H_
#define _STATECLIENT_H_
#include "State.h"
#include "StateWithInput.h"
#include "InputState.h"
#include "Team.h"
#include "Ball.h"
class StateClient : public State, public StateWithInput {
private:
Team *tl, *tr; // team left and team right
Ball *b;
unsigned int prevDrawn;
int _lp, _rp;
public:
StateClient() : prevDrawn(0) {}
virtual int execute(InputState *is, unsigned int ticks,
unsigned int prevTicks, int firstTime);
private:
int setupConnection(InputState *is);
};
#endif // _STATEPLAYING_H_

View File

@@ -0,0 +1,76 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __STATEMENU_H__
#define __STATEMENU_H__
#include <iostream>
#include "globals.h"
#include "State.h"
#include "Automa.h"
#include "MenuRoot.h"
#include "Menu.h"
#include "MenuItem.h"
#include "MenuItemSubMenu.h"
#include "MenuItemPlay.h"
#include "MenuItemExit.h"
#include "MenuItemNotImplemented.h"
#include "SoundMgr.h"
class StateMenu : public State {
private:
MenuRoot *_mr;
public:
StateMenu() {
_mr = mroot;
};
int execute(InputState *is, unsigned int ticks, unsigned int prevTicks,
int firstTime) {
static int lastExec = ticks;
#ifdef AUDIO
if ( firstTime )
soundMgr->playSound(SND_BACKGROUND_MENU, true);
#endif // AUDIO
if ( (ticks - lastExec) > 50 ) {
SDL_Rect r;
r.x = r.y = 0;
r.h = background->height();
r.w = background->width();
background->blit(0, screen, &r);
//SDL_BlitSurface(background, &r, screen, &r);
int ret = _mr->execute(is);
SDL_Flip(screen);
lastExec = ticks;
return(ret);
}
if ( is->getF()[0] ) {
return(NO_TRANSITION + 1);
}
return(NO_TRANSITION);
}
};
#endif // __STATEMENU_H__

View File

@@ -0,0 +1,260 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <SDL.h>
#include "StatePlaying.h"
#include "Automa.h"
#include "AutomaMainLoop.h"
#ifndef NONET
#include "NetServer.h"
#endif
#include "StateWithInput.h"
using namespace std;
int StatePlaying::setupConnection(InputState *is) {
#ifndef NONET
std::string clinumb = "";
int nclients = 0;
signed char ch;
//nets = new NetServer();
/* first, delete the screen... */
SDL_Rect r;
r.x = r.y = 0;
r.h = background->height();
r.w = background->width();
//SDL_BlitSurface(background, &r, screen, &r);
background->blit(0, screen, &r);
SDL_Flip(screen);
/* now, ask for the port to listen on */
char msg[100];
string ports = "";
int port;
sprintf(msg, "What port to listen on? [%d]", SERVER_PORT);
cga->printRow(screen, 0, msg);
SDL_Flip(screen);
while ( (ch = getKeyPressed(is)) != SDLK_RETURN ) {
if ( ch == SDLK_BACKSPACE ) {
ports = deleteOneChar(ports); // should be backspace...
cga->printRow(screen, 1, " ", background);
} else {
char w[2];
w[0] = (char)ch;
w[1] = 0;
ports = ports + w;
}
cga->printRow(screen, 1, ports.c_str(), background);
SDL_Flip(screen);
}
port = atoi(ports.c_str());
if ( !port )
port = SERVER_PORT;
cga->printRow(screen, 2, "How many clients to wait? [1]");
SDL_Flip(screen);
while ( (ch = getKeyPressed(is)) != SDLK_RETURN ) {
if ( ch == SDLK_BACKSPACE ) {
clinumb = deleteOneChar(clinumb); // should be backspace...
cga->printRow(screen, 3, " ", background);
} else {
char w[2];
w[0] = (char)ch;
w[1] = 0;
clinumb = clinumb + w;
}
cga->printRow(screen, 3, clinumb.c_str(), background);
SDL_Flip(screen);
}
nclients = atoi(clinumb.c_str());
if ( !nclients )
nclients = 1;
nets->StartServer(port);
cga->printRow(screen, 4, "Server OK. Waiting for clients...",
background);
SDL_Flip(screen);
int remaining = nclients;
do {
remaining = nets->WaitClients(is, remaining);
char msg[100];
sprintf(msg, " %d connection(s) to go ", remaining);
cga->printRow(screen, 5, msg, background);
SDL_Flip(screen);
} while ( remaining > 0 );
return remaining;
#else //!NONET
return 0;
#endif
}
// executes one step of the game's main loop
// Returns NO_TRANSITION if the game continues, the next state otherwise
int StatePlaying::execute(InputState *is, unsigned int ticks,
unsigned int prevTicks, int firstTime)
{
if ( firstTime ) {
#ifndef NONET
if ( nets ) {
if (setupConnection(is) < 0) {
delete(nets);
nets = NULL;
return(STATE_MENU);
}
}
#endif
#ifdef AUDIO
soundMgr->stopSound(SND_BACKGROUND_MENU);
soundMgr->playSound(SND_BACKGROUND_PLAYING, true);
#endif
/*
First time we change to execute state: we should
probably create players here instead of in the constructor,
and think of a clever way to destroy them once we're done.
*/
prevDrawn = ticks;
tl = new Team(-1);
tr = new Team(1);
b = new Ball(BALL_ORIG);
for ( int i = 0, j = 0; i < configuration.left_nplayers; j++ ) {
if ( configuration.left_players[j] == PLAYER_NONE ) {
continue;
}
string name = "Pippo-" + j;
if ( configuration.left_players[j] == PLAYER_HUMAN ) {
tl->addPlayerHuman(name.c_str(), PL_TYPE_MALE_LEFT);
} else {
#ifndef NONET
if (!nets || !(nets->isRemote(j*2)))
#endif
tl->addPlayerAI(name.c_str(), PL_TYPE_MALE_LEFT, b);
#ifndef NONET
else
tl->addPlayerRemote(name.c_str(), PL_TYPE_MALE_LEFT);
#endif
}
i++;
}
for ( int i = 0, j = 0; i < configuration.right_nplayers; j++ ) {
if ( configuration.right_players[j] == PLAYER_NONE ) {
continue;
}
string name = "Pluto-" + j;
if ( configuration.right_players[j] == PLAYER_HUMAN ) {
tr->addPlayerHuman(name.c_str(), PL_TYPE_MALE_RIGHT);
} else {
#ifndef NONET
if (!nets || !(nets->isRemote(j*2+1)))
#endif
tr->addPlayerAI(name.c_str(), PL_TYPE_MALE_RIGHT, b);
#ifndef NONET
else
tr->addPlayerRemote(name.c_str(), PL_TYPE_MALE_RIGHT);
#endif
}
i++;
}
tl->setScore(0);
tr->setScore(0);
b->resetPos((int) (configuration.SCREEN_WIDTH * 0.25),
(int) (configuration.SCREEN_HEIGHT * 0.66));
}
controlsArray->setControlsState(is, tl, tr);
if ( is->getKeyState()[SDLK_ESCAPE] ) {
delete(tl);
delete(tr);
delete(b);
#ifndef NONET
if ( nets ) {
delete(nets);
nets = NULL;
}
#endif
#ifdef AUDIO
soundMgr->stopSound(SND_BACKGROUND_PLAYING);
#endif
return(STATE_MENU);
}
tl->update(ticks - prevTicks, controlsArray);
tr->update(ticks - prevTicks, controlsArray);
b->update(ticks - prevTicks, tl, tr);
if ( (ticks - prevDrawn) >
(unsigned int) (FPS - (FPS / (configuration.frame_skip + 1)) ) ) {
SDL_Rect r;
r.x = r.y = 0;
r.h = background->height();
r.w = background->width();
//SDL_BlitSurface(background, &r, screen, &r);
background->blit(0, screen, &r);
tl->draw();
tr->draw();
b->draw();
#ifndef NONET
if (nets)
nets->SendSnapshot(tl, tr, b);
#endif
SDL_Flip(screen);
prevDrawn = ticks;
}
if ( ((tl->getScore() >= configuration.winning_score) &&
(tl->getScore() > (tr->getScore()+1))) ||
((tr->getScore() >= configuration.winning_score) &&
(tr->getScore() > (tl->getScore()+1))) ) {
#ifdef AUDIO
soundMgr->playSound(SND_VICTORY);
#endif // AUDIO
/* Deallocate teams, ball and players */
delete(tl);
delete(tr);
delete(b);
#ifndef NONET
if ( nets ) {
delete(nets);
nets = NULL;
}
#endif
#ifdef AUDIO
soundMgr->stopSound(SND_BACKGROUND_PLAYING);
#endif
return(STATE_MENU); // end of game
}
return(NO_TRANSITION);
}

View File

@@ -0,0 +1,48 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _STATEPLAYING_H_
#define _STATEPLAYING_H_
#include "State.h"
#include "InputState.h"
#include "Team.h"
#include "Ball.h"
#include "StateWithInput.h"
class StatePlaying : public State, public StateWithInput {
private:
Team *tl, *tr; // team left and team right
Ball *b;
unsigned int prevDrawn;
public:
StatePlaying() : prevDrawn(0) {}
virtual int execute(InputState *is, unsigned int ticks,
unsigned int prevTicks, int firstTime);
private:
int setupConnection(InputState *is);
};
#endif // _STATEPLAYING_H_

View File

@@ -0,0 +1,75 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __STATENET_H__
#define __STATENET_H__
#include <SDL.h>
#include "AutomaMainLoop.h"
#include <string>
class StateWithInput {
public:
StateWithInput() {}
std::string deleteOneChar(std::string s) {
if ( s.length() < 1 )
return(s);
char s2[s.length()];
strncpy(s2, s.c_str(), s.length() - 1);
s2[s.length() - 1] = 0;
return(std::string(s2));
}
short getKeyPressed(InputState *is, bool blocking = true) {
SDL_keysym keysym;
SDL_Event event;
while ( 1 ) {
if (!blocking && (!SDL_PollEvent(NULL)))
return -1;
if ( (event = is->getEventWaiting()).type != SDL_KEYDOWN ) {
continue;
}
keysym = event.key.keysym;
while ( is->getEventWaiting().type != SDL_KEYUP );
char *kn = SDL_GetKeyName(keysym.sym);
// printf("\"%s\"\n", kn);
if ( strlen(kn) == 1 )
return((signed char)(*kn));
else if ( !strcmp(kn, "return") )
return(SDLK_RETURN);
else if ( !strcmp(kn, "backspace") )
return(SDLK_BACKSPACE);
else if ( !strcmp(kn, "escape") )
return(SDLK_ESCAPE);
else
continue;
}
return -1;
}
};
#endif

View File

@@ -0,0 +1,5 @@
make clean
cp Makefile.Linux Makefile
cp automa/Makefile.Linux automa/Makefile
cp menu/Makefile.Linux menu/Makefile
cp net/Makefile.Linux net/Makefile

View File

@@ -0,0 +1,5 @@
rm -rf gav.app
mkdir -p gav.app/Contents/MacOS
cp gav gav.app/Contents/MacOS
echo "APPL????" >gav.app/Contents/PkgInfo
cp osx-info.plist gav.app/Contents/Info.plist

View File

@@ -0,0 +1,5 @@
make clean
cp Makefile.cross.w32 Makefile
cp automa/Makefile.cross.w32 automa/Makefile
cp menu/Makefile.cross.w32 menu/Makefile
cp net/Makefile.cross.w32 net/Makefile

View File

@@ -0,0 +1,43 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Global data */
#include "globals.h"
SDL_Surface *screen;
FrameSeq *background;
ScreenFont *cga, *cgaInv;
int screenFlags = 0;
const SDL_VideoInfo *videoinfo;
MenuRoot *mroot;
ControlsArray *controlsArray = NULL;
#ifndef NONET
NetServer * nets = NULL;
NetClient * netc = NULL;
#endif

View File

@@ -0,0 +1,113 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _GLOBALS_H_
#define _GLOBALS_H_
#include <SDL.h>
#include "Configuration.h"
#define FPS (50)
class MenuRoot;
class ControlsArray;
class FrameSeq;
class ScreenFont;
extern SDL_Surface *screen;
extern FrameSeq *background;
extern ScreenFont *cga, *cgaInv;
extern int screenFlags;
extern const SDL_VideoInfo *videoinfo;
extern ControlsArray *controlsArray;
extern MenuRoot *mroot;
extern Configuration configuration;
class GameRenderer;
extern GameRenderer *gameRenderer;
#ifndef NONET
class NetClient;
class NetServer;
#endif
class SoundMgr;
#ifndef NONET
extern NetServer * nets;
extern NetClient * netc;
#endif
extern SoundMgr * soundMgr;
#ifdef AUDIO
extern SDL_AudioSpec desired,obtained;
typedef struct sound_s {
Uint8 *samples;
Uint32 length;
} sound_t, *sound_p;
typedef struct playing_s {
int active;
sound_p sound;
Uint32 position;
bool loop;
} playing_t, *playing_p;
#define MAX_PLAYING_SOUNDS 10
extern playing_t playing [MAX_PLAYING_SOUNDS];
#define VOLUME_PER_SOUND SDL_MIX_MAXVOLUME / 2
/* this should be synchronized with char *sound_fnames[] in SoundMgr.cpp */
enum {
SND_BOUNCE = 0,
SND_MENU_SELECT,
SND_MENU_ACTIVATE,
SND_SCORE,
SND_VICTORY,
SND_PARTIALNET,
SND_FULLNET,
SND_SERVICECHANGE,
SND_PLAYERHIT,
SND_BACKGROUND_PLAYING,
SND_BACKGROUND_MENU // last item is used in SoundMgr.cpp as a limit
};
#endif //AUDIO
typedef struct {
Uint8 left;
Uint8 right;
Uint8 jump;
} triple_t;
#define MAXPATHLENGTH (1024)
#endif // _GLOBALS_H_

View File

@@ -0,0 +1,302 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <SDL.h>
#include <sys/types.h>
#include <dirent.h>
#include "globals.h"
#include "ScreenFont.h"
#include "AutomaMainLoop.h"
#include "StatePlaying.h"
#include "StateMenu.h"
#include "MenuRoot.h"
#include "Menu.h"
#include "MenuItem.h"
#include "MenuItemSubMenu.h"
#include "MenuItemPlay.h"
#include "MenuItemExit.h"
#include "MenuItemPlayer.h"
#include "MenuItemSound.h"
#include "MenuItemNotImplemented.h"
#include "MenuItemNotCompiled.h"
#include "MenuKeys.h"
#include "MenuItemBack.h"
#include "MenuItemTheme.h"
#include "MenuItemFullScreen.h"
#include "MenuItemFrameSkip.h"
#include "MenuItemFPS.h"
#include "MenuItemScore.h"
#include "MenuItemMonitor.h"
#include "MenuItemBigBackground.h"
#include "MenuItemBallSpeed.h"
#include "MenuItemSave.h"
#include "MenuItemJoystick.h"
#ifndef NONET
#include "MenuItemClient.h"
#include "MenuItemServer.h"
#endif
#include "Theme.h"
#include "Sound.h"
#ifndef NONET
#include "NetClient.h"
#include "NetServer.h"
#endif
#define BPP 16
using namespace std;
#ifdef AUDIO
SDL_AudioSpec desired,obtained;
SoundMgr * soundMgr = NULL;
playing_t playing[MAX_PLAYING_SOUNDS];
void AudioCallBack(void *user_data,Uint8 *audio,int length)
{
int i;
//memset(audio,0 , length);
if (!configuration.sound) return;
for(i=0; i <MAX_PLAYING_SOUNDS;i++)
{
if(playing[i].active) {
Uint8 *sound_buf;
Uint32 sound_len;
sound_buf = playing[i].sound->samples;
sound_buf += playing[i].position;
if((playing[i].position +length)>playing[i].sound->length){
sound_len = playing[i].sound->length - playing[i].position;
} else {
sound_len=length;
}
SDL_MixAudio(audio,sound_buf,sound_len,VOLUME_PER_SOUND);
playing[i].position+=length;
if(playing[i].position>=playing[i].sound->length){
if (!playing[i].loop)
playing[i].active=0;
else
playing[i].position = 0;
}
}
}
}
void initJoysticks()
{
for ( int i = 0; i < SDL_NumJoysticks(); i++ ) {
}
}
void ClearPlayingSounds(void)
{
int i;
for(i=0;i<MAX_PLAYING_SOUNDS;i++)
{
playing[i].active=0;
}
}
#endif
/* applies the changes loaded with the configuration when needed */
void applyConfiguration() {
MenuItemFullScreen().apply();
CurrentTheme = new Theme(configuration.currentTheme);
}
void
init()
{
if ( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) ) {
cerr << "Cannot initialize SDL, exiting." << endl;
exit(1);
}
SDL_ShowCursor(SDL_DISABLE);
atexit(SDL_Quit);
#ifndef NONET
if(SDLNet_Init()==-1) {
cerr << "SDLNet_Init: " << SDLNet_GetError() << endl;
exit(2);
}
#endif
#ifdef AUDIO
atexit(SDL_CloseAudio);
desired.freq=44100;//22050;
desired.format = AUDIO_S16;
desired.samples=512;//4096;
desired.channels=1;
desired.callback=AudioCallBack;
desired.userdata=NULL;
if(SDL_OpenAudio(&desired,&obtained)<0){
printf("Cannot open the audio device\n");
}
ClearPlayingSounds();
SDL_PauseAudio(0);
#endif
SDL_WM_SetCaption("GPL Arcade Volleyball", "GAV");
setThemeDir(TH_DIR);
videoinfo = SDL_GetVideoInfo();
controlsArray = new ControlsArray(); /* could be modified by loadConf */
if ( configuration.loadConfiguration() == -1 ) {
cerr << "Configuration file " << configuration.confFileName() <<
" not found: creating.\n";
if ( configuration.createConfigurationFile() == -1 )
perror("creation failed: ");
}
applyConfiguration();
}
#ifdef AUDIO
Sound * Prova;
#endif
#include <unistd.h>
void
parseArgs(int argc, char *argv[]) {
int i = 1;
int resx = -1;
int resy = -1;
for ( ; i < argc; i++ ) {
if ( !strcmp("-w", argv[i]) ) {
resx = atoi(argv[++i]);
} else if ( !strcmp("-h", argv[i]) ) {
resy = atoi(argv[++i]);
}
}
if ( (resx > 0) && (resy >0) )
configuration.setDesiredResolution(resx, resy);
}
int main(int argc, char *argv[]) {
parseArgs(argc, argv);
init();
#ifdef AUDIO
#if 0
Prova = new Sound("rocket.wav");
Prova->playSound();
#endif
#endif
/* initialize menus */
Menu m;
MenuItemPlay miplay;
MenuItemExit miexit;
Menu *menuExtra = new Menu();
Menu *menuThemes = new Menu();
Menu *menuJoystick = new Menu();
#ifndef NONET
Menu *menuNetwork = new Menu();
#endif
MenuItemBack *mib = new MenuItemBack("back");
DIR *dir;
if ((dir = opendir(ThemeDir.c_str())) == NULL) {
std::cerr << "Cannot find themes directory\n";
exit(0);
}
struct dirent *themeDir;
do {
themeDir = readdir(dir);
if ( themeDir && (themeDir->d_name[0] != '.') )
menuThemes->add(new MenuItemTheme(string(themeDir->d_name)));
} while (themeDir);
closedir(dir);
menuThemes->add(mib);
#ifndef NONET
menuNetwork->add(new MenuItemServer());
menuNetwork->add(new MenuItemClient());
menuNetwork->add(mib);
#endif
menuExtra->add(new MenuItemSubMenu(menuThemes, string("Theme")));
#ifndef NONET
menuExtra->add(new MenuItemSubMenu(menuNetwork, string("Network game")));
#endif
menuExtra->add(new MenuItemPlayer(TEAM_LEFT, 1));
menuExtra->add(new MenuItemPlayer(TEAM_RIGHT, 1));
menuExtra->add(new MenuItemSubMenu(new MenuKeys(1),
string("Define Keys")));
menuExtra->add(new MenuItemFPS());
menuExtra->add(new MenuItemFrameSkip());
menuExtra->add(new MenuItemScore());
menuExtra->add(new MenuItemMonitor());
menuExtra->add(new MenuItemBallSpeed());
menuExtra->add(new MenuItemBigBackground());
menuExtra->add(new MenuItemFullScreen());
menuExtra->add(new MenuItemSave());
menuExtra->add(mib);
for (int plId = 0; plId < MAX_PLAYERS; plId++ ) {
menuJoystick->add(new MenuItemJoystick(plId, -1));
}
menuJoystick->add(mib);
m.add(&miplay);
m.add(new MenuItemPlayer(TEAM_LEFT, 0));
m.add(new MenuItemPlayer(TEAM_RIGHT, 0));
#ifdef AUDIO
m.add(new MenuItemSound());
#else // AUDIO
m.add(new MenuItemNotCompiled(string("Sound: Off")));
#endif // AUDIO
m.add(new MenuItemSubMenu(new MenuKeys(0),
string("Define Keys")));
m.add(new MenuItemSubMenu(menuJoystick,
string("Set Joystick")));
m.add(new MenuItemSubMenu(menuExtra,
string("Extra")));
m.add(&miexit);
mroot = new MenuRoot();
mroot->add(&m);
AutomaMainLoop *a = new AutomaMainLoop();
a->start();
return 0;
}

View File

@@ -0,0 +1,48 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = menu
include ../CommonHeader
NAME = menu
MODULE_NAME = $(NAME)_module.o
CXXFLAGS += -I$(GAV_ROOT)
DEPEND = Makefile.depend
.PHONY: all
all: $(MODULE_NAME)
$(MODULE_NAME): $(OFILES)
$(LD) -r $(OFILES) -o $(MODULE_NAME)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,48 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = menu
include ../CommonHeader
NAME = menu
MODULE_NAME = $(NAME)_module.o
CXXFLAGS += -I$(GAV_ROOT)
DEPEND = Makefile.depend
.PHONY: all
all: $(MODULE_NAME)
$(MODULE_NAME): $(OFILES)
$(LD) -r $(OFILES) -o $(MODULE_NAME)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,44 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = menu
include ../CommonHeader
NAME = menu
CXXFLAGS += -I$(GAV_ROOT)
DEPEND = Makefile.depend
.PHONY: all
all: $(OFILES)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,94 @@
#include "Menu.h"
#include <string.h>
#include "SoundMgr.h"
using namespace std;
void Menu::add(MenuItem * mi)
{
if (currentItem < 0)
currentItem = 0;
if ((mi->getLabel()).length() > maxLabelLength)
maxLabelLength = (mi->getLabel()).length();
items.push_back(mi);
}
int Menu::execute(InputState *is, std::stack<Menu *> &s)
{
SDL_Rect rect;
const char * label;
ScreenFont * font;
static bool spacePressed = false;
static bool PrevUp = false;
static bool PrevDown = false;
// Up
if (is->getKeyState()[SDLK_UP]) {
if (!PrevUp) {
if (currentItem > 0) {
currentItem--;
#ifdef AUDIO
soundMgr->playSound (SND_MENU_SELECT);
#endif
} else {
currentItem=(int)(items.size()-1);
#ifdef AUDIO
soundMgr->playSound (SND_MENU_SELECT);
#endif
}
PrevUp = true;
}
} else
PrevUp =false;
// Down
if (is->getKeyState()[SDLK_DOWN]) {
if (!PrevDown) {
if (currentItem < (int)(items.size()-1)) {
currentItem++;
#ifdef AUDIO
soundMgr->playSound (SND_MENU_SELECT);
#endif
} else {
currentItem=0;
#ifdef AUDIO
soundMgr->playSound (SND_MENU_SELECT);
#endif
}
PrevDown = true;
}
} else
PrevDown = false;
// draw menu items labels
rect.y = configuration.CEILING + configuration.env.h/100;
for ( unsigned int it = 0; it < items.size(); it++ ) {
label = items[it]->getLabel().c_str();
rect.x = (configuration.env.w / 2) -
strlen(label)*(cga->charWidth())/2; // UGLY
if (it == (unsigned int) currentItem)
font = cgaInv;
else
font = cga;
font->printXY(screen, &rect, items[it]->getLabel().c_str());
rect.y += font->charHeight();
}
// call the execute method of the current item, if an event occurred
if ( (is->getKeyState()[SDLK_SPACE]) ||
(is->getKeyState()[SDLK_RETURN]) ) {
spacePressed = true;
}
if ( spacePressed && !(is->getKeyState()[SDLK_SPACE]) &&
!(is->getKeyState()[SDLK_RETURN]) ) {
spacePressed = false;
#ifdef AUDIO
soundMgr->playSound(SND_MENU_ACTIVATE);
#endif // AUDIO
return items[currentItem]->execute(s);
}
return 0;
}

View File

@@ -0,0 +1,46 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENU_H__
#define __MENU_H__
#include <SDL.h>
#include <vector>
#include "MenuItem.h"
#include "ScreenFont.h"
#include "InputState.h"
class Menu {
std::vector<MenuItem *> items;
int currentItem;
unsigned int maxLabelLength;
public:
Menu():
currentItem(-1), maxLabelLength(0) {}
virtual void add(MenuItem * mi);
virtual int execute(InputState *is, std::stack<Menu *> &s);
virtual ~Menu() {}
};
#endif

View File

@@ -0,0 +1,43 @@
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEM_H__
#define __MENUITEM_H__
#include <string>
#include <stack>
#include "InputState.h"
class Menu;
class MenuItem {
protected:
std::string label;
public:
MenuItem() {}
inline void setLabel(std::string l) {label = l;}
virtual std::string getLabel() {return label;}
virtual int execute(std::stack<Menu *> &s) = 0;
virtual ~MenuItem() {}
};
#endif

View File

@@ -0,0 +1,42 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMBACK_H__
#define __MENUITEMBACK_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemBack: public MenuItem {
public:
MenuItemBack(std::string l) {
label = l;
}
int execute(std::stack<Menu *> &s) {
s.pop();
return(0);
}
};
#endif

View File

@@ -0,0 +1,65 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMBALLSPEED_H__
#define __MENUITEMBALLSPEED_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
#define BALL_SPEED_ITEMS 3
class MenuItemBallSpeed: public MenuItem {
char * _item[BALL_SPEED_ITEMS];
int _currItem;
public:
MenuItemBallSpeed() {
if (configuration.ballAmplify == DEFAULT_BALL_AMPLIFY)
_currItem = 0;
else if ( configuration.ballAmplify ==
DEFAULT_BALL_AMPLIFY + BALL_SPEED_INC )
_currItem = 1;
else
_currItem = 2;
_item[0] = "Normal";
_item[1] = "Fast";
_item[2] = "Too Fast!";
setLabel();
}
void setLabel() {
label = std::string("Ball Speed: ") +
std::string(_item[_currItem]);
}
int execute(std::stack<Menu *> &s) {
_currItem = (_currItem + 1) % BALL_SPEED_ITEMS;
configuration.ballAmplify =
DEFAULT_BALL_AMPLIFY + BALL_SPEED_INC * _currItem;
setLabel();
return(0);
}
};
#endif

View File

@@ -0,0 +1,57 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMBIGBACKGROUND_H__
#define __MENUITEMBIGBACKGROUND_H__
#include <SDL.h>
#include <iostream>
#include "MenuItem.h"
#include "globals.h"
class MenuItemBigBackground: public MenuItem {
public:
MenuItemBigBackground() {
label = std::string("Big Background: ") + (configuration.bgBig?"Yes":"No");
}
int execute(std::stack<Menu *> &s) {
const char * currThemeName;
configuration.bgBig = !configuration.bgBig;
label = std::string(configuration.bgBig?"Big Background: Yes":"Big Background: No");
currThemeName = CurrentTheme->name();
try {
delete(CurrentTheme);
CurrentTheme = new Theme(currThemeName);
} catch (Theme::ThemeErrorException te) {
std::cerr << te.message << std::endl;
configuration.bgBig = !configuration.bgBig;
label = std::string(configuration.bgBig?"Big Background: Yes":"Big Background: No");
CurrentTheme = new Theme(currThemeName);
}
return(0);
}
};
#endif

View File

@@ -0,0 +1,35 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMCLIENT_H__
#define __MENUITEMCLIENT_H__
#include "MenuItem.h"
#include "AutomaMainLoop.h"
class MenuItemClient: public MenuItem {
public:
MenuItemClient() {label = (std::string)"Start as client";}
int execute(std::stack<Menu *> &s) { return STATE_CLIENT; }
};
#endif

View File

@@ -0,0 +1,35 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMEXIT_H__
#define __MENUITEMEXIT_H__
#include "MenuItem.h"
#include <stdlib.h>
class MenuItemExit: public MenuItem {
public:
MenuItemExit() {label = (std::string)"Exit";}
int execute(std::stack<Menu *> &s) {exit(0);}
};
#endif

View File

@@ -0,0 +1,50 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMFPS_H__
#define __MENUITEMFPS_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemFPS: public MenuItem {
public:
MenuItemFPS() {
setLabel();
}
void setLabel() {
char fs[10];
sprintf(fs, "%d", configuration.fps);
label = std::string("Frames per second: ") + std::string(fs);
}
int execute(std::stack<Menu *> &s) {
configuration.setFps((configuration.fps % 100) + 10);
setLabel();
return(0);
}
};
#endif

View File

@@ -0,0 +1,51 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMFRAMESKIP_H__
#define __MENUITEMFRAMESKIP_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemFrameSkip: public MenuItem {
public:
MenuItemFrameSkip() {
setLabel();
}
void setLabel() {
char fs[10];
sprintf(fs, "%d", configuration.frame_skip);
label = std::string("Frameskip: ") + std::string(fs);
}
int execute(std::stack<Menu *> &s) {
configuration.frame_skip =
(configuration.frame_skip + 1)%10;
setLabel();
return(0);
}
};
#endif

View File

@@ -0,0 +1,60 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMFULLSCREEN_H__
#define __MENUITEMFULLSCREEN_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemFullScreen: public MenuItem {
public:
MenuItemFullScreen() {
}
std::string getLabel() {
return configuration.fullscreen?"Fullscreen: Yes":"Fullscreen: No";
}
void apply() {
if ( configuration.fullscreen )
screenFlags |= SDL_FULLSCREEN;
else
screenFlags = (screenFlags & ~SDL_FULLSCREEN);
}
int execute(std::stack<Menu *> &s) {
SDL_FreeSurface(screen);
configuration.fullscreen = !configuration.fullscreen;
apply();
screen = SDL_SetVideoMode(configuration.resolution.x,
// SCREEN_HEIGHT(), BPP, screenFlags);
configuration.resolution.y,
videoinfo->vfmt->BitsPerPixel,
screenFlags);
return(0);
}
};
#endif

View File

@@ -0,0 +1,68 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMJOYSTICK_H__
#define __MENUITEMJOYSTICK_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemJoystick: public MenuItem {
int _joyId;
int _plId;
char nstr[10];
public:
MenuItemJoystick(int plId, int init) {
_joyId = init;
_plId = plId;
setLabel();
}
void setLabel() {
label = "Player ";
sprintf(nstr, "%d", _plId/2 + 1);
label += std::string(nstr);
if ( _plId % 2 )
label += " right: ";
else
label += " left: ";
if ( _joyId == -1 )
label += "Not Present";
else {
sprintf(nstr, "%d", _joyId);
label += "Joystick " + std::string(nstr);
}
}
int execute(std::stack<Menu *> &s) {
_joyId = (_joyId+1+1)%(controlsArray->getNJoysticks()+1) - 1;
controlsArray->assignJoystick(_plId, _joyId);
setLabel();
return(0);
}
};
#endif // __MENUITEMJOYSTICK_H__

View File

@@ -0,0 +1,75 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMMONITOR_H__
#define __MENUITEMMONITOR_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemMonitor: public MenuItem {
public:
MenuItemMonitor() {
setLabel();
}
void setLabel() {
std::string monitor;
switch ( configuration.monitor_type ) {
case MONITOR_NORMAL:
monitor = "Normal";
break;
case MONITOR_OLD:
monitor = "Old";
break;
case MONITOR_VERYOLD:
monitor = "Very old";
break;
case MONITOR_VERYVERYOLD:
monitor = "Very, very old";
break;
}
label = std::string("Monitor Type: ") + monitor;
}
void apply() {
if ( !configuration.monitor_type )
SDL_SetAlpha(background->surface(), 0, 0);
else
SDL_SetAlpha(background->surface(), SDL_SRCALPHA | SDL_RLEACCEL,
128 - (configuration.monitor_type * 30));
}
int execute(std::stack<Menu *> &s) {
configuration.monitor_type =
(configuration.monitor_type + 1)%4;
apply();
setLabel();
return(0);
}
};
#endif

View File

@@ -0,0 +1,48 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMNOTCOMPILED_H__
#define __MENUITEMNOTCOMPILED_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemNotCompiled: public MenuItem {
std::string msg;
public:
MenuItemNotCompiled(std::string l) {
label = l;
msg = (std::string)"Functionality not compiled";
}
int execute(std::stack<Menu *> &s) {
SDL_Rect r;
r.x = (screen->w / 2) - msg.length()*(cga->charWidth())/2;
r.y = screen->h * 2/3;
cga->printXY(screen, &r, msg.c_str());
SDL_Flip(screen);
SDL_Delay(1000);
return(0);
}
};
#endif

View File

@@ -0,0 +1,48 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMNOTIMPLEMENTED_H__
#define __MENUITEMNOTIMPLEMENTED_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemNotImplemented: public MenuItem {
std::string msg;
public:
MenuItemNotImplemented(std::string l) {
label = l;
msg = (std::string)"Menu Item Not Yet Implemented";
}
int execute(std::stack<Menu *> &s) {
SDL_Rect r;
r.x = (screen->w / 2) - msg.length()*(cga->charWidth())/2;
r.y = screen->h * 2/3;
cga->printXY(screen, &r, msg.c_str());
SDL_Flip(screen);
SDL_Delay(1000);
return(0);
}
};
#endif

View File

@@ -0,0 +1,35 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMPLAY_H__
#define __MENUITEMPLAY_H__
#include "MenuItem.h"
#include "AutomaMainLoop.h"
class MenuItemPlay: public MenuItem {
public:
MenuItemPlay() {label = (std::string)"Play";}
int execute(std::stack<Menu *> &s) {return STATE_PLAYING;}
};
#endif

View File

@@ -0,0 +1,102 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMPLAYER_H__
#define __MENUITEMPLAYER_H__
#include <stdio.h>
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
enum { TEAM_LEFT = 0, TEAM_RIGHT};
class MenuItemPlayer: public MenuItem {
private:
std::string prefix;
int team;
int index;
public:
MenuItemPlayer(int tm, int idx) {
team = tm;
index = idx;
char numb[10];
sprintf(numb, "%d", idx*2 + tm + 1);
prefix = std::string("Player ") + numb + ": ";
setLabel();
}
void setLabel() {
int *src =
(team == TEAM_LEFT)?configuration.left_players:configuration.right_players;
std::string postfix;
switch ( src[index] ) {
case PLAYER_NONE:
postfix = std::string("None");
break;
case PLAYER_COMPUTER:
postfix = std::string("Computer / Net");
break;
case PLAYER_HUMAN:
postfix = std::string("Keyboard / Joy");
break;
}
label = prefix + postfix;
}
int execute(std::stack<Menu *> &s) {
int *src =
(team == TEAM_LEFT)?configuration.left_players:configuration.right_players;
switch ( src[index] ) {
case PLAYER_NONE:
src[index] = PLAYER_HUMAN;
if ( team == TEAM_LEFT )
configuration.left_nplayers++;
else
configuration.right_nplayers++;
break;
case PLAYER_HUMAN:
src[index] = PLAYER_COMPUTER;
break;
case PLAYER_COMPUTER:
if ( index ) {
src[index] = PLAYER_NONE;
if ( team == TEAM_LEFT )
configuration.left_nplayers--;
else
configuration.right_nplayers--;
} else
src[index] = PLAYER_HUMAN;
break;
}
setLabel();
return(0);
}
};
#endif

View File

@@ -0,0 +1,51 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMSAVE_H__
#define __MENUITEMSAVE_H__
#include <SDL.h>
#include <iostream>
#include "MenuItem.h"
#include "globals.h"
class MenuItemSave: public MenuItem {
public:
MenuItemSave() {
label = std::string("Save Preferences");
}
int execute(std::stack<Menu *> &s) {
std::string msg = "Configuration saved.";
if ( configuration.createConfigurationFile() == -1 )
msg = "Could not save configuration";
SDL_Rect r;
r.x = (screen->w / 2) - msg.length()*(cga->charWidth())/2;
r.y = screen->h * 2/3;
cga->printXY(screen, &r, msg.c_str());
SDL_Flip(screen);
SDL_Delay(1000);
return(0);
}
};
#endif

View File

@@ -0,0 +1,49 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMSCORE_H__
#define __MENUITEMSCORE_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemScore: public MenuItem {
public:
MenuItemScore() {
setLabel();
}
void setLabel() {
label = "Winning Score: " +
configuration.toString(configuration.winning_score);
}
int execute(std::stack<Menu *> &s) {
configuration.winning_score =
(configuration.winning_score%50)+5;
setLabel();
return(0);
}
};
#endif

View File

@@ -0,0 +1,43 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMSERVER_H__
#define __MENUITEMSERVER_H__
#include "MenuItem.h"
#include "AutomaMainLoop.h"
#ifndef NONET
#include "NetServer.h"
#endif
class MenuItemServer: public MenuItem {
public:
MenuItemServer() {label = (std::string)"Start as server";}
int execute(std::stack<Menu *> &s) {
#ifndef NONET
nets = new NetServer();
#endif
return STATE_PLAYING;
}
};
#endif

View File

@@ -0,0 +1,43 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMSOUND_H__
#define __MENUITEMSOUND_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuItemSound: public MenuItem {
public:
MenuItemSound() {
label = std::string(configuration.sound?"Sound: On":"Sound: Off");
}
int execute(std::stack<Menu *> &s) {
configuration.sound = (!configuration.sound);
label = std::string(configuration.sound?"Sound: On":"Sound: Off");
return(0);
}
};
#endif // __MENUITEMSOUND_H__

View File

@@ -0,0 +1,36 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMSUBMENU_H__
#define __MENUITEMSUBMENU_H__
#include "Menu.h"
#include "MenuItem.h"
class MenuItemSubMenu: public MenuItem {
Menu * submenu;
public:
MenuItemSubMenu(Menu * m, std::string l): submenu(m) {label = l;}
int execute(std::stack<Menu *> &s) {s.push(submenu); return 0;}
};
#endif

View File

@@ -0,0 +1,53 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUITEMTHEME_H__
#define __MENUITEMTHEME_H__
#include <SDL.h>
#include <iostream>
#include "MenuItem.h"
#include "globals.h"
class MenuItemTheme: public MenuItem {
public:
MenuItemTheme(std::string l) {
label = l;
}
int execute(std::stack<Menu *> &s) {
std::string oldName;
oldName = CurrentTheme->name();
try {
delete(CurrentTheme);
CurrentTheme = new Theme(label);
} catch (Theme::ThemeErrorException te) {
std::cerr << te.message << std::endl;
CurrentTheme = new Theme(oldName);
}
return(0);
}
};
#endif

View File

@@ -0,0 +1,117 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUKEYS_H__
#define __MENUKEYS_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
enum { PL1L, PL1R, PL1J, PL2L, PL2R, PL2J };
class MenuKeys: public Menu {
int state;
bool isPressed, isStillPressed;
int _base;
public:
MenuKeys(int base) {
_base = base;
state = PL1L;
isPressed = false;
isStillPressed = false;
}
virtual int execute(InputState *is, std::stack<Menu *> &s) {
char numb[20];
SDL_Rect rect;
SDL_Event event = is->getEvent();
rect.y = 30;
rect.x = 30;
isStillPressed = (isPressed && (event.type == SDL_KEYDOWN));
if ( !isStillPressed )
isPressed = false;
sprintf(numb, "Player %d ", 2*_base + ((state <= PL1J)?1:2));
std::string st(numb);
switch ( state ) {
case PL1L:
st += "Left: ";
cga->printXY(screen, &rect, st.c_str());
if ( ( event.type != SDL_KEYDOWN ) || isStillPressed )
return(0);
controlsArray->setControl(2*_base, CNTRL_LEFT, event.key.keysym.sym);
break;
case PL1R:
st += "Right: ";
cga->printXY(screen, &rect, st.c_str());
if ( ( event.type != SDL_KEYDOWN ) || isStillPressed )
return(0);
controlsArray->setControl(2*_base, CNTRL_RIGHT, event.key.keysym.sym);
break;
case PL1J:
st += "Jump: ";
cga->printXY(screen, &rect, st.c_str());
if ( ( event.type != SDL_KEYDOWN ) || isStillPressed )
return(0);
controlsArray->setControl(2*_base, CNTRL_JUMP, event.key.keysym.sym);
break;
case PL2L:
st += "Left: ";
cga->printXY(screen, &rect, st.c_str());
if ( ( event.type != SDL_KEYDOWN ) || isStillPressed )
return(0);
controlsArray->setControl(2*_base + 1, CNTRL_LEFT, event.key.keysym.sym);
break;
case PL2R:
st += "Right: ";
cga->printXY(screen, &rect, st.c_str());
if ( ( event.type != SDL_KEYDOWN ) || isStillPressed )
return(0);
controlsArray->setControl(2*_base + 1, CNTRL_RIGHT, event.key.keysym.sym);
// event.key.keysym.sym
break;
case PL2J:
st += "Jump: ";
cga->printXY(screen, &rect, st.c_str());
if ( ( event.type != SDL_KEYDOWN ) || isStillPressed )
return(0);
controlsArray->setControl(2*_base + 1, CNTRL_JUMP, event.key.keysym.sym);
// event.key.keysym.sym
break;
}
isPressed = ( event.type == SDL_KEYDOWN );
if ( state == PL2J ) {
s.pop();
state = 0;
} else
state++;
return(NO_TRANSITION);
}
};
#endif

View File

@@ -0,0 +1,41 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUROOT_H__
#define __MENUROOT_H__
#include <stack>
#include "Menu.h"
#include "InputState.h"
class MenuRoot {
std::stack<Menu *> menus;
public:
MenuRoot() {}
inline void add(Menu * m) {menus.push(m);}
int execute(InputState *is) {
return (menus.top())->execute(is, menus);
}
};
#endif

View File

@@ -0,0 +1,50 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __MENUTHEMES_H__
#define __MENUTHEMES_H__
#include <SDL.h>
#include "MenuItem.h"
#include "globals.h"
class MenuThemes: public Menu {
bool firstTime;
public:
MenuThemes(ScreenFont *nf, ScreenFont *rf) {
normal_font = nf;
selected_font = rf;
firstTime = false;
}
virtual int execute(InputState *is, std::stack<Menu *> &s) {
if ( firstTime ) {
DIR *dir;
if ((dir = opendir(ThemeDir.c_str())) )
}
Menu::execute(is, s);
}
};
#endif

View File

@@ -0,0 +1,48 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = net
include ../CommonHeader
NAME = net
MODULE_NAME = $(NAME)_module.o
CXXFLAGS += -I$(GAV_ROOT) -I$(GAV_ROOT)/menu -I$(GAV_ROOT)/net
DEPEND = Makefile.depend
.PHONY: all
all: $(MODULE_NAME)
$(MODULE_NAME): $(OFILES)
$(LD) -r $(OFILES) -o $(MODULE_NAME)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,48 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = net
include ../CommonHeader
NAME = net
MODULE_NAME = $(NAME)_module.o
CXXFLAGS += -I$(GAV_ROOT) -I$(GAV_ROOT)/menu -I$(GAV_ROOT)/net
DEPEND = Makefile.depend
.PHONY: all
all: $(MODULE_NAME)
$(MODULE_NAME): $(OFILES)
$(LD) -r $(OFILES) -o $(MODULE_NAME)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,44 @@
# GAV - Gpl Arcade Volleyball
# Copyright (C) 2002
# GAV team (http://sourceforge.net/projects/gav/)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
RELPATH = net
include ../CommonHeader
NAME = net
CXXFLAGS += -I$(GAV_ROOT) -I$(GAV_ROOT)/menu -I$(GAV_ROOT)/net
DEPEND = Makefile.depend
.PHONY: all
all: $(OFILES)
($OFILES): $(SRCS)
$(CXX) -c $(CXXFLAGS) $<
clean:
rm -f *.o *.bin *~ $(DEPEND)
depend:
$(RM) $(DEPEND)
$(CXX) $(CXXFLAGS) -M $(SRCS) >> $(DEPEND)
ifeq ($(wildcard $(DEPEND)),$(DEPEND))
include $(DEPEND)
endif

View File

@@ -0,0 +1,102 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NET_H__
#define __NET_H__
#ifndef NONET
#include <SDL_net.h>
#include <vector>
#include "Configuration.h"
#include "Ball.h"
#include "Team.h"
#include "automa/StateWithInput.h"
#define PLAYER_FOR_TEAM_IN_NET_GAME 2
#define SERVER_PORT 7145
/* The ID of a client is a char with the higher order 2 bits indicating
the team, the left 6 bits say the player number. When a client wants to
register itself, it sends a register request with id equal to
NET_TEAM_LEFT or NET_TEAM_RIGHT. The server fills the others 6 bits
and sends the id back to the client.
*/
#define NET_TEAM_LEFT 0x80 // 10xxxxxx
#define NET_TEAM_RIGHT 0x40 // 01xxxxxx
typedef struct {
Uint16 x;
Uint16 y;
Uint16 frame;
} net_object_snapshot_t;
typedef struct {
//unsigned int timestamp;
net_object_snapshot_t teaml[PLAYER_FOR_TEAM_IN_NET_GAME];
net_object_snapshot_t teamr[PLAYER_FOR_TEAM_IN_NET_GAME];
net_object_snapshot_t ball;
unsigned char scorel;
unsigned char scorer;
} net_game_snapshot_t;
typedef struct {
//unsigned int timestamp;
unsigned char id; // the client ID
unsigned char command;
} net_command_t;
typedef struct {
unsigned char id;
unsigned char nplayers_l;
unsigned char nplayers_r;
unsigned char bgBig; // 0 or 1
unsigned char winning_score;
} net_register_t;
class Net : public StateWithInput{
protected:
UDPsocket mySock;
UDPpacket * packetCmd;
UDPpacket * packetSnap;
UDPpacket * packetRegister;
public:
Net() {
packetSnap = SDLNet_AllocPacket(sizeof(net_game_snapshot_t));
packetSnap->len = packetSnap->maxlen;
packetCmd = SDLNet_AllocPacket(sizeof(net_command_t));
packetCmd->len = packetCmd->maxlen;
packetRegister = SDLNet_AllocPacket(sizeof(net_register_t));
packetRegister->len = packetRegister->maxlen;
}
~Net() {
SDLNet_FreePacket(packetSnap);
SDLNet_FreePacket(packetCmd);
}
};
#endif // NONET
#endif

View File

@@ -0,0 +1,128 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef NONET
#include "NetClient.h"
#include "MenuItemBigBackground.h"
using namespace std;
int NetClient::ConnectToServer(InputState * is, int * pl, int * pr, char team,
const char * hostname, int port) {
/* open the socket */
mySock = SDLNet_UDP_Open(0);
/* resolve the server name */
if (SDLNet_ResolveHost(&ipaddress, (char*) hostname, port) == -1) {
fprintf(stderr, "SDLNet_ResolveHost: %s\n", SDLNet_GetError());
return -1;
}
/* bind */
channel=SDLNet_UDP_Bind(mySock, -1, &ipaddress);
if(channel==-1) {
fprintf(stderr, "SDLNet_UDP_Bind: %s\n", SDLNet_GetError());
return -1;
}
packetRegister->address = packetSnap->address =
packetCmd->address = ipaddress;
((net_register_t*)(packetRegister->data))->id = team;
SDLNet_UDP_Send(mySock, -1, packetRegister);
while (!SDLNet_UDP_Recv(mySock, packetRegister)) {
if (getKeyPressed(is, false) == SDLK_ESCAPE) {
return -1;
}
}
_id = ((net_register_t*)(packetRegister->data))->id;
_nplayers_l = ((net_register_t*)(packetRegister->data))->nplayers_l;
_nplayers_r = ((net_register_t*)(packetRegister->data))->nplayers_r;
if (((net_register_t*)(packetRegister->data))->bgBig !=
configuration.bgBig) {
MenuItemBigBackground menuBG;
std::stack<Menu *> st;
menuBG.execute(st);
}
configuration.winning_score =
((net_register_t*)(packetRegister->data))->winning_score;
*pl = (int)_nplayers_l;
*pr = (int)_nplayers_r;
return 0;
}
int NetClient::WaitGameStart() {
while (SDLNet_UDP_Recv(mySock, packetSnap) == 0) SDL_Delay(500);
return 0;
}
inline int NetClient::receiveData(Uint16 *data) {
int v = (int)SDLNet_Read16(data);
return v;
}
int NetClient::ReceiveSnapshot(Team *tleft, Team *tright, Ball * ball,
int passed) {
net_game_snapshot_t * snap;
std::vector<Player *> plv;
unsigned int i;
if (SDLNet_UDP_Recv(mySock, packetSnap) != 0) {
snap = (net_game_snapshot_t*)packetSnap->data;
/* fill the left team informations */
plv = tleft->players();
for (i = 0; i < plv.size(); i++) {
plv[i]->setX(receiveData(&(snap->teaml)[i].x));
plv[i]->setY(receiveData(&(snap->teaml)[i].y));
plv[i]->updateClient(passed, (pl_state_t)receiveData(&(snap->teaml)[i].frame));
}
/* fill the right team informations */
plv = tright->players();
for (i = 0; i < plv.size(); i++) {
plv[i]->setX(receiveData(&(snap->teamr)[i].x));
plv[i]->setY(receiveData(&(snap->teamr)[i].y));
plv[i]->updateClient(passed, (pl_state_t)receiveData(&(snap->teamr)[i].frame));
}
/* fill the ball informations */
ball->setX(receiveData(&(snap->ball).x));
ball->setY(receiveData(&(snap->ball).y));
ball->updateFrame(passed);
/* fill the score information */
tleft->setScore(snap->scorel);
tright->setScore(snap->scorer);
return 0;
}
return -1;
}
int NetClient::SendCommand(char cmd) {
net_command_t * command = (net_command_t *)(packetCmd->data);
command->id = _id;
command->command = cmd;
return SDLNet_UDP_Send(mySock, -1, packetCmd)?0:-1;
}
#endif // NONET

View File

@@ -0,0 +1,61 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NETCLIENT_H__
#define __NETCLIENT_H__
#ifndef NONET
#include "Net.h"
class NetClient: public Net {
IPaddress ipaddress;
int channel; // the channel assigned to client
char _id; // if I'm a client I've an id
char _nplayers_l;
char _nplayers_r;
private:
int receiveData(Uint16 *data);
public:
NetClient() {
}
~NetClient() {
SDLNet_UDP_Unbind(mySock, channel);
SDLNet_UDP_Close(mySock);
}
/* client methods */
int ConnectToServer(InputState * is, int * pl, int * pr, char team,
const char * hostname, int port = SERVER_PORT);
int WaitGameStart();
int ReceiveSnapshot(Team *tleft, Team *tright, Ball * ball, int passed);
int SendCommand(char cmd);
inline char id() { return _id; }
};
#endif // NONET
#endif

View File

@@ -0,0 +1,168 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef NONET
#include "NetServer.h"
#include "Player.h"
using namespace std;
int NetServer::StartServer(int port) {
/* open the socket */
mySock = SDLNet_UDP_Open((Uint16)port);
if(!mySock) {
fprintf(stderr, "SDLNet_UDP_Open: %s\n", SDLNet_GetError());
return -1;
}
return 0;
}
int NetServer::ComputePlayerID(char id) {
unsigned char tm ,pl;
tm = (id & NET_TEAM_LEFT)?0:1;
pl = id & 0x3F;
return ((pl << 1) | tm);
}
int NetServer::WaitClients(InputState * is, int nclients) {
IPaddress * ipa;
//char nleft = 0;
//char nright = 0;
unsigned char * id;
int i;
bool inserted = false;
char pl;
_nclients = nclients;
while ( !inserted ) { // (nright + nleft) != nclients) {
inserted = false;
if (SDLNet_UDP_Recv(mySock, packetRegister) != 0) {
ipa = (IPaddress*)malloc(sizeof(IPaddress));
memcpy(ipa, &(packetRegister->address), sizeof(IPaddress));
id = &(((net_register_t*)(packetRegister->data))->id);
if (*id & NET_TEAM_LEFT) {
for (i = 0; (i < configuration.left_nplayers) && !inserted; i++)
if ((configuration.left_players[i] == PLAYER_COMPUTER) &&
!_players[2*i]) {
inserted = true;
pl = (char)i;
}
if (inserted) {
*id |= pl;
//nleft++;
} else
continue;
} else if (*id & NET_TEAM_RIGHT) {
for (i = 0; (i < configuration.right_nplayers) && !inserted; i++)
if ((configuration.right_players[i] == PLAYER_COMPUTER) &&
!_players[2*i+1]) {
inserted = true;
pl = (char)i;
}
if (inserted) {
*id |= pl;
//nright++;
} else
continue;
}
_players[ComputePlayerID(*id)] = 1;
clientIP.push_back(ipa);
/* send the ID back to client */
((net_register_t*)(packetRegister->data))->nplayers_l =
configuration.left_nplayers;
((net_register_t*)(packetRegister->data))->nplayers_r =
configuration.right_nplayers;
((net_register_t*)(packetRegister->data))->bgBig =
configuration.bgBig;
((net_register_t*)(packetRegister->data))->winning_score =
configuration.winning_score;
SDLNet_UDP_Send(mySock, -1, packetRegister);
} else {
if (getKeyPressed(is, false) == SDLK_ESCAPE) {
return -1;
}
SDL_Delay(500);
}
}
return (nclients-1);
}
//Uint16 NetServer::NormalizeCurrentFrame(
int NetServer::SendSnapshot(Team *tleft, Team *tright, Ball * ball) {
unsigned int i;
net_game_snapshot_t * snap = (net_game_snapshot_t *)(packetSnap->data);
std::vector<Player *> plv;
snap->scorel = tleft->getScore();
snap->scorer = tright->getScore();
/* fill the left team informations */
plv = tleft->players();
for (i = 0; i < plv.size(); i++) {
SDLNet_Write16(plv[i]->x(), &((snap->teaml)[i].x));
SDLNet_Write16(plv[i]->y(), &((snap->teaml)[i].y));
SDLNet_Write16(plv[i]->state(), &((snap->teaml)[i].frame));
}
/* fill the right team informations */
plv = tright->players();
for (i = 0; i < plv.size(); i++) {
SDLNet_Write16(plv[i]->x(), &((snap->teamr)[i].x));
SDLNet_Write16(plv[i]->y(), &((snap->teamr)[i].y));
SDLNet_Write16(plv[i]->state(), &((snap->teamr)[i].frame));
}
/* fill the ball informations */
SDLNet_Write16(ball->x(), &((snap->ball).x));
SDLNet_Write16(ball->y(), &((snap->ball).y));
// ball has just one state
//SDLNet_Write16(ball->frame(), &((snap->ball).frame));
/* send the snapshot to all clients */
for (i = 0; i < clientIP.size(); i++) {
packetSnap->address = *(clientIP[i]);
SDLNet_UDP_Send(mySock, -1, packetSnap);
}
return 0;
}
int NetServer::ReceiveCommand(int * player, char * cmd) {
if (SDLNet_UDP_Recv(mySock, packetCmd) != 0) {
net_command_t * c = (net_command_t*)(packetCmd->data);
*player = ComputePlayerID(c->id);
*cmd = c->command;
return 0;
}
return -1;
}
int NetServer::isRemote(int pl) {
return _players[pl];
}
#endif

View File

@@ -0,0 +1,62 @@
/* -*- C++ -*- */
/*
GAV - Gpl Arcade Volleyball
Copyright (C) 2002
GAV team (http://sourceforge.net/projects/gav/)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __NETSERVER_H__
#define __NETSERVER_H__
#ifndef NONET
#include "Net.h"
#include <string.h>
class NetServer: public Net {
std::vector<IPaddress*> clientIP;
int _nclients;
int _players[MAX_PLAYERS];
public:
NetServer() {
memset(_players, 0, MAX_PLAYERS * sizeof(int));
}
~NetServer() {
unsigned int i;
/* deallocation of clientIP elements */
for (i = 0; i < clientIP.size(); i++)
free(clientIP[i]);
SDLNet_UDP_Close(mySock);
}
/* server methods */
int StartServer(int port = SERVER_PORT);
int WaitClients(InputState * is, int nclients = 1);
int SendSnapshot(Team *tleft, Team *tright, Ball * ball);
int ReceiveCommand(int * player, char * cmd);
int ComputePlayerID(char id);
int isRemote(int pl);
inline int nclients() { return _nclients; }
};
#endif // NONET
#endif

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>gav</string>
<key>CFBundleIdentifier</key>
<string>com.gavproject.gav</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0.0d1</string>
</dict>
</plist>

Some files were not shown because too many files have changed in this diff Show More