[SCM] Trophy racing game - Packaging information branch, master, updated. debian/1.1.7-1-5-g65c4cc4
Andreas Moog
amoog at ubuntu.com
Mon Feb 6 17:49:53 UTC 2012
The following commit has been merged in the master branch:
commit 9f778d573d4b6593dc7995b67bda230b3d8c14bf
Author: Andreas Moog <amoog at ubuntu.com>
Date: Mon Feb 6 18:31:41 2012 +0100
Imported Upstream version 2.0.0
diff --git a/AUTHORS b/AUTHORS
index a77697a..fd9c749 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -1,9 +1,5 @@
Project coordination, main developer:
Andrew Mustun <andrew at mustun.com>
-
-Bug fixes, speed improvements:
- Benjamin Winkler <bentsch at mail.com>
- Colin Pitrat <colin.pitrat at gmail.com>
Developers:
Matthieu Lecesne <matthieulecesne at yahoo.fr>
diff --git a/ChangeLog b/ChangeLog
index 82b9616..60f79d8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,4 @@
-1.1.7 Fix src/Makefile.am from 1.1.6
-
-1.1.6 Adapt makefiles for ClanLib 1.0
+2.0.0 Add championship, shop, key configuration, load/save features and lot of code refactoring
1.1.5 Bugs fixes and code cleanup
diff --git a/INSTALL b/INSTALL
index 02a4a07..8b82ade 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,90 +1,137 @@
+Installation Instructions
+*************************
+
+Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005,
+2006, 2007, 2008 Free Software Foundation, Inc.
+
+ This file is free documentation; the Free Software Foundation gives
+unlimited permission to copy, distribute and modify it.
+
Basic Installation
==================
- These are generic installation instructions.
+ Briefly, the shell commands `./configure; make; make install' should
+configure, build, and install this package. The following
+more-detailed instructions are generic; see the `README' file for
+instructions specific to this package.
The `configure' shell script attempts to guess correct values for
various system-dependent variables used during compilation. It uses
those values to create a `Makefile' in each directory of the package.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
-you can run in the future to recreate the current configuration, a file
-`config.cache' that saves the results of its tests to speed up
-reconfiguring, and a file `config.log' containing compiler output
-(useful mainly for debugging `configure').
+you can run in the future to recreate the current configuration, and a
+file `config.log' containing compiler output (useful mainly for
+debugging `configure').
+
+ It can also use an optional file (typically called `config.cache'
+and enabled with `--cache-file=config.cache' or simply `-C') that saves
+the results of its tests to speed up reconfiguring. Caching is
+disabled by default to prevent problems with accidental use of stale
+cache files.
If you need to do unusual things to compile the package, please try
to figure out how `configure' could check whether to do them, and mail
diffs or instructions to the address given in the `README' so they can
-be considered for the next release. If at some point `config.cache'
-contains results you don't want to keep, you may remove or edit it.
+be considered for the next release. If you are using the cache, and at
+some point `config.cache' contains results you don't want to keep, you
+may remove or edit it.
- The file `configure.in' is used to create `configure' by a program
-called `autoconf'. You only need `configure.in' if you want to change
-it or regenerate `configure' using a newer version of `autoconf'.
+ The file `configure.ac' (or `configure.in') is used to create
+`configure' by a program called `autoconf'. You need `configure.ac' if
+you want to change it or regenerate `configure' using a newer version
+of `autoconf'.
The simplest way to compile this package is:
1. `cd' to the directory containing the package's source code and type
- `./configure' to configure the package for your system. If you're
- using `csh' on an old version of System V, you might need to type
- `sh ./configure' instead to prevent `csh' from trying to execute
- `configure' itself.
+ `./configure' to configure the package for your system.
- Running `configure' takes a while. While running, it prints some
- messages telling which features it is checking for.
+ Running `configure' might take a while. While running, it prints
+ some messages telling which features it is checking for.
2. Type `make' to compile the package.
- 3. Type `make install' to install the programs and any data files and
+ 3. Optionally, type `make check' to run any self-tests that come with
+ the package.
+
+ 4. Type `make install' to install the programs and any data files and
documentation.
- 4. You can remove the program binaries and object files from the
- source code directory by typing `make clean'.
+ 5. You can remove the program binaries and object files from the
+ source code directory by typing `make clean'. To also remove the
+ files that `configure' created (so you can compile the package for
+ a different kind of computer), type `make distclean'. There is
+ also a `make maintainer-clean' target, but that is intended mainly
+ for the package's developers. If you use it, you may have to get
+ all sorts of other programs in order to regenerate files that came
+ with the distribution.
+
+ 6. Often, you can also type `make uninstall' to remove the installed
+ files again.
Compilers and Options
=====================
Some systems require unusual options for compilation or linking that
-the `configure' script does not know about. You can give `configure'
-initial values for variables by setting them in the environment. Using
-a Bourne-compatible shell, you can do that on the command line like
-this:
- CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
+the `configure' script does not know about. Run `./configure --help'
+for details on some of the pertinent environment variables.
+
+ You can give `configure' initial values for configuration parameters
+by setting variables in the command line or in the environment. Here
+is an example:
+
+ ./configure CC=c99 CFLAGS=-g LIBS=-lposix
-Or on systems that have the `env' program, you can do it like this:
- env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
+ *Note Defining Variables::, for more details.
Compiling For Multiple Architectures
====================================
You can compile the package for more than one kind of computer at the
same time, by placing the object files for each architecture in their
-own directory. To do this, you must use a version of `make' that
-supports the `VPATH' variable, such as GNU `make'. `cd' to the
+own directory. To do this, you can use GNU `make'. `cd' to the
directory where you want the object files and executables to go and run
the `configure' script. `configure' automatically checks for the
source code in the directory that `configure' is in and in `..'.
- If you have to use a `make' that does not supports the `VPATH'
-variable, you have to compile the package for one architecture at a time
-in the source code directory. After you have installed the package for
-one architecture, use `make distclean' before reconfiguring for another
-architecture.
+ With a non-GNU `make', it is safer to compile the package for one
+architecture at a time in the source code directory. After you have
+installed the package for one architecture, use `make distclean' before
+reconfiguring for another architecture.
+
+ On MacOS X 10.5 and later systems, you can create libraries and
+executables that work on multiple system types--known as "fat" or
+"universal" binaries--by specifying multiple `-arch' options to the
+compiler but only a single `-arch' option to the preprocessor. Like
+this:
+
+ ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+ CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \
+ CPP="gcc -E" CXXCPP="g++ -E"
+
+ This is not guaranteed to produce working output in all cases, you
+may have to build one architecture at a time and combine the results
+using the `lipo' tool if you have problems.
Installation Names
==================
- By default, `make install' will install the package's files in
-`/usr/local/bin', `/usr/local/man', etc. You can specify an
-installation prefix other than `/usr/local' by giving `configure' the
-option `--prefix=PATH'.
+ By default, `make install' installs the package's commands under
+`/usr/local/bin', include files under `/usr/local/include', etc. You
+can specify an installation prefix other than `/usr/local' by giving
+`configure' the option `--prefix=PREFIX'.
You can specify separate installation prefixes for
architecture-specific files and architecture-independent files. If you
-give `configure' the option `--exec-prefix=PATH', the package will use
-PATH as the prefix for installing programs and libraries.
-Documentation and other data files will still use the regular prefix.
+pass the option `--exec-prefix=PREFIX' to `configure', the package uses
+PREFIX as the prefix for installing programs and libraries.
+Documentation and other data files still use the regular prefix.
+
+ In addition, if you use an unusual directory layout you can give
+options like `--bindir=DIR' to specify different values for particular
+kinds of files. Run `configure --help' for a list of the directories
+you can set and what kinds of files go in them.
If the package supports it, you can cause programs to be installed
with an extra prefix or suffix on their names by giving `configure' the
@@ -105,25 +152,57 @@ find the X include and library files automatically, but if it doesn't,
you can use the `configure' options `--x-includes=DIR' and
`--x-libraries=DIR' to specify their locations.
+Particular systems
+==================
+
+ On HP-UX, the default C compiler is not ANSI C compatible. If GNU
+CC is not installed, it is recommended to use the following options in
+order to use an ANSI C compiler:
+
+ ./configure CC="cc -Ae"
+
+and if that doesn't work, install pre-built binaries of GCC for HP-UX.
+
+ On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot
+parse its `<wchar.h>' header file. The option `-nodtk' can be used as
+a workaround. If GNU CC is not installed, it is therefore recommended
+to try
+
+ ./configure CC="cc"
+
+and if that doesn't work, try
+
+ ./configure CC="cc -nodtk"
+
Specifying the System Type
==========================
- There may be some features `configure' can not figure out
-automatically, but needs to determine by the type of host the package
-will run on. Usually `configure' can figure that out, but if it prints
-a message saying it can not guess the host type, give it the
-`--host=TYPE' option. TYPE can either be a short name for the system
-type, such as `sun4', or a canonical name with three fields:
+ There may be some features `configure' cannot figure out
+automatically, but needs to determine by the type of machine the package
+will run on. Usually, assuming the package is built to be run on the
+_same_ architectures, `configure' can figure that out, but if it prints
+a message saying it cannot guess the machine type, give it the
+`--build=TYPE' option. TYPE can either be a short name for the system
+type, such as `sun4', or a canonical name which has the form:
+
CPU-COMPANY-SYSTEM
-See the file `config.sub' for the possible values of each field. If
+where SYSTEM can have one of these forms:
+
+ OS KERNEL-OS
+
+ See the file `config.sub' for the possible values of each field. If
`config.sub' isn't included in this package, then this package doesn't
-need to know the host type.
+need to know the machine type.
- If you are building compiler tools for cross-compiling, you can also
-use the `--target=TYPE' option to select the type of system they will
-produce code for and the `--build=TYPE' option to select the type of
-system on which you are compiling the package.
+ If you are _building_ compiler tools for cross-compiling, you should
+use the option `--target=TYPE' to select the type of system they will
+produce code for.
+
+ If you want to _use_ a cross compiler, that generates code for a
+platform different from the build platform, you should specify the
+"host" platform (i.e., that on which the generated programs will
+eventually be run) with `--host=TYPE'.
Sharing Defaults
================
@@ -136,32 +215,77 @@ default values for variables like `CC', `cache_file', and `prefix'.
`CONFIG_SITE' environment variable to the location of the site script.
A warning: not all `configure' scripts look for a site script.
-Operation Controls
+Defining Variables
==================
+ Variables not defined in a site shell script can be set in the
+environment passed to `configure'. However, some packages may run
+configure again during the build, and the customized values of these
+variables may be lost. In order to avoid this problem, you should set
+them in the `configure' command line, using `VAR=value'. For example:
+
+ ./configure CC=/usr/local2/bin/gcc
+
+causes the specified `gcc' to be used as the C compiler (unless it is
+overridden in the site shell script).
+
+Unfortunately, this technique does not work for `CONFIG_SHELL' due to
+an Autoconf bug. Until the bug is fixed you can use this workaround:
+
+ CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash
+
+`configure' Invocation
+======================
+
`configure' recognizes the following options to control how it
operates.
+`--help'
+`-h'
+ Print a summary of all of the options to `configure', and exit.
+
+`--help=short'
+`--help=recursive'
+ Print a summary of the options unique to this package's
+ `configure', and exit. The `short' variant lists options used
+ only in the top level, while the `recursive' variant lists options
+ also present in any nested packages.
+
+`--version'
+`-V'
+ Print the version of Autoconf used to generate the `configure'
+ script, and exit.
+
`--cache-file=FILE'
- Use and save the results of the tests in FILE instead of
- `./config.cache'. Set FILE to `/dev/null' to disable caching, for
- debugging `configure'.
+ Enable the cache: use and save the results of the tests in FILE,
+ traditionally `config.cache'. FILE defaults to `/dev/null' to
+ disable caching.
-`--help'
- Print a summary of the options to `configure', and exit.
+`--config-cache'
+`-C'
+ Alias for `--cache-file=config.cache'.
`--quiet'
`--silent'
`-q'
- Do not print messages saying which checks are being made.
+ Do not print messages saying which checks are being made. To
+ suppress all normal output, redirect it to `/dev/null' (any error
+ messages will still be shown).
`--srcdir=DIR'
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
-`--version'
- Print the version of Autoconf used to generate the `configure'
- script, and exit.
+`--prefix=DIR'
+ Use DIR as the installation prefix. *Note Installation Names::
+ for more details, including other options available for fine-tuning
+ the installation locations.
+
+`--no-create'
+`-n'
+ Run the configure checks, but stop before creating any output
+ files.
-`configure' also accepts some other, not widely useful, options.
+`configure' also accepts some other, not widely useful, options. Run
+`configure --help' for more details.
diff --git a/Makefile.in b/Makefile.in
index 5146e05..d25cb55 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -106,6 +106,8 @@ AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
+CLANLIB_CFLAGS = @CLANLIB_CFLAGS@
+CLANLIB_LIBS = @CLANLIB_LIBS@
CLANLIB_MODULES = @CLANLIB_MODULES@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
diff --git a/README b/README
index 10ecfe6..27b16b6 100644
--- a/README
+++ b/README
@@ -18,7 +18,7 @@ like shooting and dropping bombs.
Requirements
------------
-TROPHY requires ClanLib 0.8 to run.
+TROPHY requires ClanLib 0.8 or 1.0 to run.
You can get ClanLib from www.clanlib.org
diff --git a/configure b/configure
index bea127c..a3739b9 100755
--- a/configure
+++ b/configure
@@ -580,6 +580,8 @@ CPPFLAGS
LDFLAGS
CFLAGS
CC
+CLANLIB_LIBS
+CLANLIB_CFLAGS
CLANLIB_MODULES
PKG_CONFIG
am__untar
@@ -652,6 +654,8 @@ enable_dependency_tracking
host_alias
target_alias
PKG_CONFIG
+CLANLIB_CFLAGS
+CLANLIB_LIBS
CC
CFLAGS
LDFLAGS
@@ -1278,6 +1282,10 @@ Optional Features:
Some influential environment variables:
PKG_CONFIG path to pkg-config utility
+ CLANLIB_CFLAGS
+ C compiler flags for CLANLIB, overriding pkg-config
+ CLANLIB_LIBS
+ linker flags for CLANLIB, overriding pkg-config
CC C compiler command
CFLAGS C compiler flags
LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
@@ -2302,7 +2310,7 @@ fi
# Define the identity of the package.
PACKAGE=trophy
- VERSION=1.1.7
+ VERSION=2.0.0
cat >>confdefs.h <<_ACEOF
@@ -2485,12 +2493,192 @@ $as_echo_n "checking ClanLib version... " >&6; }
$as_echo "ClanLib 1.0" >&6; }
CLANLIB_MODULES="clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0"
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CLANLIB" >&5
+$as_echo_n "checking for CLANLIB... " >&6; }
+
+if test -n "$PKG_CONFIG"; then
+ if test -n "$CLANLIB_CFLAGS"; then
+ pkg_cv_CLANLIB_CFLAGS="$CLANLIB_CFLAGS"
+ else
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\"clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0\"\""; } >&5
+ ($PKG_CONFIG --exists --print-errors ""clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0"") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_CLANLIB_CFLAGS=`$PKG_CONFIG --cflags ""clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0"" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ fi
+else
+ pkg_failed=untried
+fi
+if test -n "$PKG_CONFIG"; then
+ if test -n "$CLANLIB_LIBS"; then
+ pkg_cv_CLANLIB_LIBS="$CLANLIB_LIBS"
+ else
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\"clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0\"\""; } >&5
+ ($PKG_CONFIG --exists --print-errors ""clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0"") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_CLANLIB_LIBS=`$PKG_CONFIG --libs ""clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0"" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ fi
+else
+ pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+ _pkg_short_errors_supported=yes
+else
+ _pkg_short_errors_supported=no
+fi
+ if test $_pkg_short_errors_supported = yes; then
+ CLANLIB_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors ""clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0""`
+ else
+ CLANLIB_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors ""clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0""`
+ fi
+ # Put the nasty error message in config.log where it belongs
+ echo "$CLANLIB_PKG_ERRORS" >&5
+
+ as_fn_error "Package requirements (\"clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0\") were not met:
+
+$CLANLIB_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables CLANLIB_CFLAGS
+and CLANLIB_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+" "$LINENO" 5
+elif test $pkg_failed = untried; then
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "The pkg-config script could not be found or is too old. Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables CLANLIB_CFLAGS
+and CLANLIB_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details." "$LINENO" 5; }
+else
+ CLANLIB_CFLAGS=$pkg_cv_CLANLIB_CFLAGS
+ CLANLIB_LIBS=$pkg_cv_CLANLIB_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ :
+fi
else
if test "$have_clan_08" = "yes"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: ClanLib 0.8" >&5
$as_echo "ClanLib 0.8" >&6; }
CLANLIB_MODULES="clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8"
+
+pkg_failed=no
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for CLANLIB" >&5
+$as_echo_n "checking for CLANLIB... " >&6; }
+
+if test -n "$PKG_CONFIG"; then
+ if test -n "$CLANLIB_CFLAGS"; then
+ pkg_cv_CLANLIB_CFLAGS="$CLANLIB_CFLAGS"
+ else
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\"clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8\"\""; } >&5
+ ($PKG_CONFIG --exists --print-errors ""clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8"") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_CLANLIB_CFLAGS=`$PKG_CONFIG --cflags ""clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8"" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ fi
+else
+ pkg_failed=untried
+fi
+if test -n "$PKG_CONFIG"; then
+ if test -n "$CLANLIB_LIBS"; then
+ pkg_cv_CLANLIB_LIBS="$CLANLIB_LIBS"
+ else
+ if test -n "$PKG_CONFIG" && \
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"\"clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8\"\""; } >&5
+ ($PKG_CONFIG --exists --print-errors ""clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8"") 2>&5
+ ac_status=$?
+ $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+ test $ac_status = 0; }; then
+ pkg_cv_CLANLIB_LIBS=`$PKG_CONFIG --libs ""clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8"" 2>/dev/null`
+else
+ pkg_failed=yes
+fi
+ fi
+else
+ pkg_failed=untried
+fi
+
+
+
+if test $pkg_failed = yes; then
+
+if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
+ _pkg_short_errors_supported=yes
+else
+ _pkg_short_errors_supported=no
+fi
+ if test $_pkg_short_errors_supported = yes; then
+ CLANLIB_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors ""clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8""`
+ else
+ CLANLIB_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors ""clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8""`
+ fi
+ # Put the nasty error message in config.log where it belongs
+ echo "$CLANLIB_PKG_ERRORS" >&5
+
+ as_fn_error "Package requirements (\"clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8\") were not met:
+
+$CLANLIB_PKG_ERRORS
+
+Consider adjusting the PKG_CONFIG_PATH environment variable if you
+installed software in a non-standard prefix.
+
+Alternatively, you may set the environment variables CLANLIB_CFLAGS
+and CLANLIB_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+" "$LINENO" 5
+elif test $pkg_failed = untried; then
+ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
+$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+as_fn_error "The pkg-config script could not be found or is too old. Make sure it
+is in your PATH or set the PKG_CONFIG environment variable to the full
+path to pkg-config.
+
+Alternatively, you may set the environment variables CLANLIB_CFLAGS
+and CLANLIB_LIBS to avoid the need to call pkg-config.
+See the pkg-config man page for more details.
+
+To get pkg-config, see <http://pkg-config.freedesktop.org/>.
+See \`config.log' for more details." "$LINENO" 5; }
+else
+ CLANLIB_CFLAGS=$pkg_cv_CLANLIB_CFLAGS
+ CLANLIB_LIBS=$pkg_cv_CLANLIB_LIBS
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+ :
+fi
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
diff --git a/configure.ac b/configure.ac
index c115bb7..795cc52 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@ dnl Process this file with autoconf to produce a configure script.
AC_INIT(src/catrophy.cpp)
-AM_INIT_AUTOMAKE(trophy,1.1.7)
+AM_INIT_AUTOMAKE(trophy,2.0.0)
@@ -14,10 +14,12 @@ AC_MSG_CHECKING(ClanLib version)
if test "$have_clan_10" = "yes"; then
AC_MSG_RESULT(ClanLib 1.0)
AC_SUBST(CLANLIB_MODULES, ["clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0"])
+ PKG_CHECK_MODULES([CLANLIB], ["clanSignals-1.0 clanGL-1.0 clanCore-1.0 clanSound-1.0 clanDisplay-1.0 clanApp-1.0"])
else
if test "$have_clan_08" = "yes"; then
AC_MSG_RESULT(ClanLib 0.8)
AC_SUBST(CLANLIB_MODULES, ["clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8"])
+ PKG_CHECK_MODULES([CLANLIB], ["clanSignals-0.8 clanGL-0.8 clanCore-0.8 clanSound-0.8 clanDisplay-0.8 clanApp-0.8"])
else
AC_MSG_RESULT(no)
AC_MSG_ERROR([Unable to find a compatible version of ClanLib. Check for ClanLib 0.8 or ClanLib 1.0])
diff --git a/doxy.cfg b/doxy.cfg
index d73c7ee..ddeeac3 100644
--- a/doxy.cfg
+++ b/doxy.cfg
@@ -23,7 +23,7 @@ PROJECT_NAME = Trophy
# This could be handy for archiving the generated documentation or
# if some version control system is used.
-PROJECT_NUMBER = 1.1.5
+PROJECT_NUMBER = 2.0.0
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
diff --git a/resources/Makefile.am b/resources/Makefile.am
index e7788ff..d366aa3 100644
--- a/resources/Makefile.am
+++ b/resources/Makefile.am
@@ -1,5 +1,11 @@
pkgdata_DATA = resources.xml
+desktopdir = $(datadir)/applications
+desktop_DATA = trophy.desktop
+
+icondir = $(datadir)/icons
+icon_DATA = trophy.png
+
flash2dir = $(pkgdatadir)/cars/flash2
flash2_DATA = cars/flash2/surface.tga cars/flash2/surface3d.tga
@@ -33,11 +39,11 @@ menu_DATA = menu/bg.tga menu/bar.tga menu/cursorani.tga
miscdir = $(pkgdatadir)/misc
misc_DATA = misc/dust.tga misc/checkflag.tga misc/gunfire.tga misc/cross.tga misc/fog.tga misc/hitpoint.tga \
- misc/carfire.tga misc/light.tga misc/caution.tga misc/info.tga misc/verticalbar.tga
+ misc/carfire.tga misc/light.tga misc/caution.tga misc/info.tga misc/verticalbar.tga misc/flag.tga
paneldir = $(pkgdatadir)/panel
panel_DATA = panel/death.tga panel/turbo.tga panel/label.tga panel/infoview.tga panel/button.tga \
- panel/speed.tga panel/turbolabel.tga panel/life.tga
+ panel/speed.tga panel/turbolabel.tga panel/life.tga panel/bullets.tga
soundsdir = $(pkgdatadir)/sounds
sounds_DATA = sounds/menu.wav sounds/shot.wav sounds/dog.wav sounds/goody_money.wav sounds/goody_life.wav \
@@ -46,6 +52,16 @@ sounds_DATA = sounds/menu.wav sounds/shot.wav sounds/dog.wav sounds/goody_money.
sounds/background01.wav sounds/carhorn.wav sounds/light.wav sounds/goody_bullets.wav \
sounds/slide.wav
+armorsdir = $(pkgdatadir)/upgrades/armors
+armors_DATA = upgrades/armors/armor_1.tga upgrades/armors/armor_2.tga upgrades/armors/armor_3.tga upgrades/armors/armor_4.tga upgrades/armors/armor_5.tga
+
+motorsdir = $(pkgdatadir)/upgrades/motors
+motors_DATA = upgrades/motors/motor_1.tga upgrades/motors/motor_2.tga upgrades/motors/motor_3.tga upgrades/motors/motor_4.tga upgrades/motors/motor_5.tga
+
+tiresdir = $(pkgdatadir)/upgrades/tires
+tires_DATA = upgrades/tires/tires_1.tga upgrades/tires/tires_2.tga upgrades/tires/tires_3.tga upgrades/tires/tires_4.tga upgrades/tires/tires_5.tga
+
+
Downtowndir = $(pkgdatadir)/tracks/Downtown
Downtown_DATA = tracks/Downtown/vmap.tga tracks/Downtown/config.tck tracks/Downtown/bridge.tga tracks/Downtown/fmap.tga tracks/Downtown/thumb.tga
@@ -70,4 +86,4 @@ Zurich_DATA = tracks/Zurich/vmap.tga tracks/Zurich/config.tck tracks/Zurich/fmap
Industrialdir = $(pkgdatadir)/tracks/Industrial
Industrial_DATA = tracks/Industrial/vmap.tga tracks/Industrial/bridge.tga tracks/Industrial/fmap.tga tracks/Industrial/thumb.tga tracks/Industrial/config.tck
-EXTRA_DIST = $(pkgdata_DATA) $(flash2_DATA) $(jeep_DATA) $(vw_DATA) $(z3_DATA) $(cars_DATA) $(fonts_DATA) $(goody_DATA) $(gui_DATA) $(menu_DATA) $(misc_DATA) $(panel_DATA) $(sounds_DATA) $(Downtown_DATA) $(Loops_DATA) $(Moon_DATA) $(Rally_DATA) $(Snake_DATA) $(Zigzag_DATA) $(Zurich_DATA) $(Industrial_DATA)
+EXTRA_DIST = $(desktop_DATA) $(pkgdata_DATA) $(icon_DATA) $(flash2_DATA) $(jeep_DATA) $(vw_DATA) $(z3_DATA) $(cars_DATA) $(fonts_DATA) $(goody_DATA) $(gui_DATA) $(menu_DATA) $(misc_DATA) $(panel_DATA) $(sounds_DATA) $(armors_DATA) $(motors_DATA) $(tires_DATA) $(Downtown_DATA) $(Loops_DATA) $(Moon_DATA) $(Rally_DATA) $(Snake_DATA) $(Zigzag_DATA) $(Zurich_DATA) $(Industrial_DATA)
diff --git a/resources/Makefile.in b/resources/Makefile.in
index 54ea0ae..26db319 100644
--- a/resources/Makefile.in
+++ b/resources/Makefile.in
@@ -68,19 +68,23 @@ am__installdirs = "$(DESTDIR)$(Downtowndir)" \
"$(DESTDIR)$(Industrialdir)" "$(DESTDIR)$(Loopsdir)" \
"$(DESTDIR)$(Moondir)" "$(DESTDIR)$(Rallydir)" \
"$(DESTDIR)$(Snakedir)" "$(DESTDIR)$(Zigzagdir)" \
- "$(DESTDIR)$(Zurichdir)" "$(DESTDIR)$(carsdir)" \
+ "$(DESTDIR)$(Zurichdir)" "$(DESTDIR)$(armorsdir)" \
+ "$(DESTDIR)$(carsdir)" "$(DESTDIR)$(desktopdir)" \
"$(DESTDIR)$(flash2dir)" "$(DESTDIR)$(fontsdir)" \
"$(DESTDIR)$(goodydir)" "$(DESTDIR)$(guidir)" \
- "$(DESTDIR)$(jeepdir)" "$(DESTDIR)$(menudir)" \
- "$(DESTDIR)$(miscdir)" "$(DESTDIR)$(paneldir)" \
+ "$(DESTDIR)$(icondir)" "$(DESTDIR)$(jeepdir)" \
+ "$(DESTDIR)$(menudir)" "$(DESTDIR)$(miscdir)" \
+ "$(DESTDIR)$(motorsdir)" "$(DESTDIR)$(paneldir)" \
"$(DESTDIR)$(pkgdatadir)" "$(DESTDIR)$(soundsdir)" \
- "$(DESTDIR)$(vwdir)" "$(DESTDIR)$(z3dir)"
+ "$(DESTDIR)$(tiresdir)" "$(DESTDIR)$(vwdir)" \
+ "$(DESTDIR)$(z3dir)"
DATA = $(Downtown_DATA) $(Industrial_DATA) $(Loops_DATA) $(Moon_DATA) \
$(Rally_DATA) $(Snake_DATA) $(Zigzag_DATA) $(Zurich_DATA) \
- $(cars_DATA) $(flash2_DATA) $(fonts_DATA) $(goody_DATA) \
- $(gui_DATA) $(jeep_DATA) $(menu_DATA) $(misc_DATA) \
- $(panel_DATA) $(pkgdata_DATA) $(sounds_DATA) $(vw_DATA) \
- $(z3_DATA)
+ $(armors_DATA) $(cars_DATA) $(desktop_DATA) $(flash2_DATA) \
+ $(fonts_DATA) $(goody_DATA) $(gui_DATA) $(icon_DATA) \
+ $(jeep_DATA) $(menu_DATA) $(misc_DATA) $(motors_DATA) \
+ $(panel_DATA) $(pkgdata_DATA) $(sounds_DATA) $(tires_DATA) \
+ $(vw_DATA) $(z3_DATA)
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
@@ -91,6 +95,8 @@ AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
+CLANLIB_CFLAGS = @CLANLIB_CFLAGS@
+CLANLIB_LIBS = @CLANLIB_LIBS@
CLANLIB_MODULES = @CLANLIB_MODULES@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
@@ -172,6 +178,10 @@ top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
pkgdata_DATA = resources.xml
+desktopdir = $(datadir)/applications
+desktop_DATA = trophy.desktop
+icondir = $(datadir)/icons
+icon_DATA = trophy.png
flash2dir = $(pkgdatadir)/cars/flash2
flash2_DATA = cars/flash2/surface.tga cars/flash2/surface3d.tga
jeepdir = $(pkgdatadir)/cars/jeep
@@ -198,11 +208,11 @@ menudir = $(pkgdatadir)/menu
menu_DATA = menu/bg.tga menu/bar.tga menu/cursorani.tga
miscdir = $(pkgdatadir)/misc
misc_DATA = misc/dust.tga misc/checkflag.tga misc/gunfire.tga misc/cross.tga misc/fog.tga misc/hitpoint.tga \
- misc/carfire.tga misc/light.tga misc/caution.tga misc/info.tga misc/verticalbar.tga
+ misc/carfire.tga misc/light.tga misc/caution.tga misc/info.tga misc/verticalbar.tga misc/flag.tga
paneldir = $(pkgdatadir)/panel
panel_DATA = panel/death.tga panel/turbo.tga panel/label.tga panel/infoview.tga panel/button.tga \
- panel/speed.tga panel/turbolabel.tga panel/life.tga
+ panel/speed.tga panel/turbolabel.tga panel/life.tga panel/bullets.tga
soundsdir = $(pkgdatadir)/sounds
sounds_DATA = sounds/menu.wav sounds/shot.wav sounds/dog.wav sounds/goody_money.wav sounds/goody_life.wav \
@@ -211,6 +221,12 @@ sounds_DATA = sounds/menu.wav sounds/shot.wav sounds/dog.wav sounds/goody_money.
sounds/background01.wav sounds/carhorn.wav sounds/light.wav sounds/goody_bullets.wav \
sounds/slide.wav
+armorsdir = $(pkgdatadir)/upgrades/armors
+armors_DATA = upgrades/armors/armor_1.tga upgrades/armors/armor_2.tga upgrades/armors/armor_3.tga upgrades/armors/armor_4.tga upgrades/armors/armor_5.tga
+motorsdir = $(pkgdatadir)/upgrades/motors
+motors_DATA = upgrades/motors/motor_1.tga upgrades/motors/motor_2.tga upgrades/motors/motor_3.tga upgrades/motors/motor_4.tga upgrades/motors/motor_5.tga
+tiresdir = $(pkgdatadir)/upgrades/tires
+tires_DATA = upgrades/tires/tires_1.tga upgrades/tires/tires_2.tga upgrades/tires/tires_3.tga upgrades/tires/tires_4.tga upgrades/tires/tires_5.tga
Downtowndir = $(pkgdatadir)/tracks/Downtown
Downtown_DATA = tracks/Downtown/vmap.tga tracks/Downtown/config.tck tracks/Downtown/bridge.tga tracks/Downtown/fmap.tga tracks/Downtown/thumb.tga
Loopsdir = $(pkgdatadir)/tracks/Loops
@@ -227,7 +243,7 @@ Zurichdir = $(pkgdatadir)/tracks/Zurich
Zurich_DATA = tracks/Zurich/vmap.tga tracks/Zurich/config.tck tracks/Zurich/fmap.tga tracks/Zurich/thumb.tga
Industrialdir = $(pkgdatadir)/tracks/Industrial
Industrial_DATA = tracks/Industrial/vmap.tga tracks/Industrial/bridge.tga tracks/Industrial/fmap.tga tracks/Industrial/thumb.tga tracks/Industrial/config.tck
-EXTRA_DIST = $(pkgdata_DATA) $(flash2_DATA) $(jeep_DATA) $(vw_DATA) $(z3_DATA) $(cars_DATA) $(fonts_DATA) $(goody_DATA) $(gui_DATA) $(menu_DATA) $(misc_DATA) $(panel_DATA) $(sounds_DATA) $(Downtown_DATA) $(Loops_DATA) $(Moon_DATA) $(Rally_DATA) $(Snake_DATA) $(Zigzag_DATA) $(Zurich_DATA) $(Industrial_DATA)
+EXTRA_DIST = $(desktop_DATA) $(pkgdata_DATA) $(icon_DATA) $(flash2_DATA) $(jeep_DATA) $(vw_DATA) $(z3_DATA) $(cars_DATA) $(fonts_DATA) $(goody_DATA) $(gui_DATA) $(menu_DATA) $(misc_DATA) $(panel_DATA) $(sounds_DATA) $(armors_DATA) $(motors_DATA) $(tires_DATA) $(Downtown_DATA) $(Loops_DATA) $(Moon_DATA) $(Rally_DATA) $(Snake_DATA) $(Zigzag_DATA) $(Zurich_DATA) $(Industrial_DATA)
all: all-am
.SUFFIXES:
@@ -421,6 +437,26 @@ uninstall-ZurichDATA:
test -n "$$files" || exit 0; \
echo " ( cd '$(DESTDIR)$(Zurichdir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(Zurichdir)" && rm -f $$files
+install-armorsDATA: $(armors_DATA)
+ @$(NORMAL_INSTALL)
+ test -z "$(armorsdir)" || $(MKDIR_P) "$(DESTDIR)$(armorsdir)"
+ @list='$(armors_DATA)'; test -n "$(armorsdir)" || list=; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(armorsdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(armorsdir)" || exit $$?; \
+ done
+
+uninstall-armorsDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(armors_DATA)'; test -n "$(armorsdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$files" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(armorsdir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(armorsdir)" && rm -f $$files
install-carsDATA: $(cars_DATA)
@$(NORMAL_INSTALL)
test -z "$(carsdir)" || $(MKDIR_P) "$(DESTDIR)$(carsdir)"
@@ -441,6 +477,26 @@ uninstall-carsDATA:
test -n "$$files" || exit 0; \
echo " ( cd '$(DESTDIR)$(carsdir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(carsdir)" && rm -f $$files
+install-desktopDATA: $(desktop_DATA)
+ @$(NORMAL_INSTALL)
+ test -z "$(desktopdir)" || $(MKDIR_P) "$(DESTDIR)$(desktopdir)"
+ @list='$(desktop_DATA)'; test -n "$(desktopdir)" || list=; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(desktopdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(desktopdir)" || exit $$?; \
+ done
+
+uninstall-desktopDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(desktop_DATA)'; test -n "$(desktopdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$files" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(desktopdir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(desktopdir)" && rm -f $$files
install-flash2DATA: $(flash2_DATA)
@$(NORMAL_INSTALL)
test -z "$(flash2dir)" || $(MKDIR_P) "$(DESTDIR)$(flash2dir)"
@@ -521,6 +577,26 @@ uninstall-guiDATA:
test -n "$$files" || exit 0; \
echo " ( cd '$(DESTDIR)$(guidir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(guidir)" && rm -f $$files
+install-iconDATA: $(icon_DATA)
+ @$(NORMAL_INSTALL)
+ test -z "$(icondir)" || $(MKDIR_P) "$(DESTDIR)$(icondir)"
+ @list='$(icon_DATA)'; test -n "$(icondir)" || list=; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(icondir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(icondir)" || exit $$?; \
+ done
+
+uninstall-iconDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(icon_DATA)'; test -n "$(icondir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$files" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(icondir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(icondir)" && rm -f $$files
install-jeepDATA: $(jeep_DATA)
@$(NORMAL_INSTALL)
test -z "$(jeepdir)" || $(MKDIR_P) "$(DESTDIR)$(jeepdir)"
@@ -581,6 +657,26 @@ uninstall-miscDATA:
test -n "$$files" || exit 0; \
echo " ( cd '$(DESTDIR)$(miscdir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(miscdir)" && rm -f $$files
+install-motorsDATA: $(motors_DATA)
+ @$(NORMAL_INSTALL)
+ test -z "$(motorsdir)" || $(MKDIR_P) "$(DESTDIR)$(motorsdir)"
+ @list='$(motors_DATA)'; test -n "$(motorsdir)" || list=; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(motorsdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(motorsdir)" || exit $$?; \
+ done
+
+uninstall-motorsDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(motors_DATA)'; test -n "$(motorsdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$files" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(motorsdir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(motorsdir)" && rm -f $$files
install-panelDATA: $(panel_DATA)
@$(NORMAL_INSTALL)
test -z "$(paneldir)" || $(MKDIR_P) "$(DESTDIR)$(paneldir)"
@@ -641,6 +737,26 @@ uninstall-soundsDATA:
test -n "$$files" || exit 0; \
echo " ( cd '$(DESTDIR)$(soundsdir)' && rm -f" $$files ")"; \
cd "$(DESTDIR)$(soundsdir)" && rm -f $$files
+install-tiresDATA: $(tires_DATA)
+ @$(NORMAL_INSTALL)
+ test -z "$(tiresdir)" || $(MKDIR_P) "$(DESTDIR)$(tiresdir)"
+ @list='$(tires_DATA)'; test -n "$(tiresdir)" || list=; \
+ for p in $$list; do \
+ if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
+ echo "$$d$$p"; \
+ done | $(am__base_list) | \
+ while read files; do \
+ echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(tiresdir)'"; \
+ $(INSTALL_DATA) $$files "$(DESTDIR)$(tiresdir)" || exit $$?; \
+ done
+
+uninstall-tiresDATA:
+ @$(NORMAL_UNINSTALL)
+ @list='$(tires_DATA)'; test -n "$(tiresdir)" || list=; \
+ files=`for p in $$list; do echo $$p; done | sed -e 's|^.*/||'`; \
+ test -n "$$files" || exit 0; \
+ echo " ( cd '$(DESTDIR)$(tiresdir)' && rm -f" $$files ")"; \
+ cd "$(DESTDIR)$(tiresdir)" && rm -f $$files
install-vwDATA: $(vw_DATA)
@$(NORMAL_INSTALL)
test -z "$(vwdir)" || $(MKDIR_P) "$(DESTDIR)$(vwdir)"
@@ -722,7 +838,7 @@ check-am: all-am
check: check-am
all-am: Makefile $(DATA)
installdirs:
- for dir in "$(DESTDIR)$(Downtowndir)" "$(DESTDIR)$(Industrialdir)" "$(DESTDIR)$(Loopsdir)" "$(DESTDIR)$(Moondir)" "$(DESTDIR)$(Rallydir)" "$(DESTDIR)$(Snakedir)" "$(DESTDIR)$(Zigzagdir)" "$(DESTDIR)$(Zurichdir)" "$(DESTDIR)$(carsdir)" "$(DESTDIR)$(flash2dir)" "$(DESTDIR)$(fontsdir)" "$(DESTDIR)$(goodydir)" "$(DESTDIR)$(guidir)" "$(DESTDIR)$(jeepdir)" "$(DESTDIR)$(menudir)" "$(DESTDIR)$(miscdir)" "$(DESTDIR)$(paneldir)" "$(DESTDIR)$(pkgdatadir)" "$(DESTDIR)$(soundsdir)" "$(DESTDIR)$(vwdir)" "$(DESTDIR)$(z3dir)"; do \
+ for dir in "$(DESTDIR)$(Downtowndir)" "$(DESTDIR)$(Industrialdir)" "$(DESTDIR)$(Loopsdir)" "$(DESTDIR)$(Moondir)" "$(DESTDIR)$(Rallydir)" "$(DESTDIR)$(Snakedir)" "$(DESTDIR)$(Zigzagdir)" "$(DESTDIR)$(Zurichdir)" "$(DESTDIR)$(armorsdir)" "$(DESTDIR)$(carsdir)" "$(DESTDIR)$(desktopdir)" "$(DESTDIR)$(flash2dir)" "$(DESTDIR)$(fontsdir)" "$(DESTDIR)$(goodydir)" "$(DESTDIR)$(guidir)" "$(DESTDIR)$(icondir)" "$(DESTDIR)$(jeepdir)" "$(DESTDIR)$(menudir)" "$(DESTDIR)$(miscdir)" "$(DESTDIR)$(motorsdir)" "$(DESTDIR)$(paneldir)" "$(DESTDIR)$(pkgdatadir)" "$(DESTDIR)$(soundsdir)" "$(DESTDIR)$(tiresdir)" "$(DESTDIR)$(vwdir)" "$(DESTDIR)$(z3dir)"; do \
test -z "$$dir" || $(MKDIR_P) "$$dir"; \
done
install: install-am
@@ -773,11 +889,12 @@ info-am:
install-data-am: install-DowntownDATA install-IndustrialDATA \
install-LoopsDATA install-MoonDATA install-RallyDATA \
install-SnakeDATA install-ZigzagDATA install-ZurichDATA \
- install-carsDATA install-flash2DATA install-fontsDATA \
- install-goodyDATA install-guiDATA install-jeepDATA \
- install-menuDATA install-miscDATA install-panelDATA \
- install-pkgdataDATA install-soundsDATA install-vwDATA \
- install-z3DATA
+ install-armorsDATA install-carsDATA install-desktopDATA \
+ install-flash2DATA install-fontsDATA install-goodyDATA \
+ install-guiDATA install-iconDATA install-jeepDATA \
+ install-menuDATA install-miscDATA install-motorsDATA \
+ install-panelDATA install-pkgdataDATA install-soundsDATA \
+ install-tiresDATA install-vwDATA install-z3DATA
install-dvi: install-dvi-am
@@ -824,11 +941,12 @@ ps-am:
uninstall-am: uninstall-DowntownDATA uninstall-IndustrialDATA \
uninstall-LoopsDATA uninstall-MoonDATA uninstall-RallyDATA \
uninstall-SnakeDATA uninstall-ZigzagDATA uninstall-ZurichDATA \
- uninstall-carsDATA uninstall-flash2DATA uninstall-fontsDATA \
- uninstall-goodyDATA uninstall-guiDATA uninstall-jeepDATA \
- uninstall-menuDATA uninstall-miscDATA uninstall-panelDATA \
- uninstall-pkgdataDATA uninstall-soundsDATA uninstall-vwDATA \
- uninstall-z3DATA
+ uninstall-armorsDATA uninstall-carsDATA uninstall-desktopDATA \
+ uninstall-flash2DATA uninstall-fontsDATA uninstall-goodyDATA \
+ uninstall-guiDATA uninstall-iconDATA uninstall-jeepDATA \
+ uninstall-menuDATA uninstall-miscDATA uninstall-motorsDATA \
+ uninstall-panelDATA uninstall-pkgdataDATA uninstall-soundsDATA \
+ uninstall-tiresDATA uninstall-vwDATA uninstall-z3DATA
.MAKE: install-am install-strip
@@ -837,25 +955,28 @@ uninstall-am: uninstall-DowntownDATA uninstall-IndustrialDATA \
install install-DowntownDATA install-IndustrialDATA \
install-LoopsDATA install-MoonDATA install-RallyDATA \
install-SnakeDATA install-ZigzagDATA install-ZurichDATA \
- install-am install-carsDATA install-data install-data-am \
- install-dvi install-dvi-am install-exec install-exec-am \
- install-flash2DATA install-fontsDATA install-goodyDATA \
- install-guiDATA install-html install-html-am install-info \
+ install-am install-armorsDATA install-carsDATA install-data \
+ install-data-am install-desktopDATA install-dvi install-dvi-am \
+ install-exec install-exec-am install-flash2DATA \
+ install-fontsDATA install-goodyDATA install-guiDATA \
+ install-html install-html-am install-iconDATA install-info \
install-info-am install-jeepDATA install-man install-menuDATA \
- install-miscDATA install-panelDATA install-pdf install-pdf-am \
- install-pkgdataDATA install-ps install-ps-am \
- install-soundsDATA install-strip install-vwDATA install-z3DATA \
- installcheck installcheck-am installdirs maintainer-clean \
+ install-miscDATA install-motorsDATA install-panelDATA \
+ install-pdf install-pdf-am install-pkgdataDATA install-ps \
+ install-ps-am install-soundsDATA install-strip \
+ install-tiresDATA install-vwDATA install-z3DATA installcheck \
+ installcheck-am installdirs maintainer-clean \
maintainer-clean-generic mostlyclean mostlyclean-generic pdf \
pdf-am ps ps-am uninstall uninstall-DowntownDATA \
uninstall-IndustrialDATA uninstall-LoopsDATA \
uninstall-MoonDATA uninstall-RallyDATA uninstall-SnakeDATA \
uninstall-ZigzagDATA uninstall-ZurichDATA uninstall-am \
- uninstall-carsDATA uninstall-flash2DATA uninstall-fontsDATA \
- uninstall-goodyDATA uninstall-guiDATA uninstall-jeepDATA \
- uninstall-menuDATA uninstall-miscDATA uninstall-panelDATA \
- uninstall-pkgdataDATA uninstall-soundsDATA uninstall-vwDATA \
- uninstall-z3DATA
+ uninstall-armorsDATA uninstall-carsDATA uninstall-desktopDATA \
+ uninstall-flash2DATA uninstall-fontsDATA uninstall-goodyDATA \
+ uninstall-guiDATA uninstall-iconDATA uninstall-jeepDATA \
+ uninstall-menuDATA uninstall-miscDATA uninstall-motorsDATA \
+ uninstall-panelDATA uninstall-pkgdataDATA uninstall-soundsDATA \
+ uninstall-tiresDATA uninstall-vwDATA uninstall-z3DATA
# Tell versions [3.59,3.63) of GNU make to not export all variables.
diff --git a/resources/cars/flash2/surface3d.tga b/resources/cars/flash2/surface3d.tga
index 760fa5a..47f59a0 100644
Binary files a/resources/cars/flash2/surface3d.tga and b/resources/cars/flash2/surface3d.tga differ
diff --git a/resources/cars/jeep/surface3d.tga b/resources/cars/jeep/surface3d.tga
index be31826..ae7eead 100644
Binary files a/resources/cars/jeep/surface3d.tga and b/resources/cars/jeep/surface3d.tga differ
diff --git a/resources/cars/vw/surface3d.tga b/resources/cars/vw/surface3d.tga
index 136a01d..c70310b 100644
Binary files a/resources/cars/vw/surface3d.tga and b/resources/cars/vw/surface3d.tga differ
diff --git a/resources/cars/z3/surface3d.tga b/resources/cars/z3/surface3d.tga
index be31826..a27f2f2 100644
Binary files a/resources/cars/z3/surface3d.tga and b/resources/cars/z3/surface3d.tga differ
diff --git a/resources/misc/flag.tga b/resources/misc/flag.tga
new file mode 100644
index 0000000..8b3e4db
Binary files /dev/null and b/resources/misc/flag.tga differ
diff --git a/resources/panel/bullets.tga b/resources/panel/bullets.tga
new file mode 100644
index 0000000..00aef4e
Binary files /dev/null and b/resources/panel/bullets.tga differ
diff --git a/resources/resources.xml b/resources/resources.xml
index 4f5adac..fe3032c 100644
--- a/resources/resources.xml
+++ b/resources/resources.xml
@@ -1,6 +1,6 @@
<resources>
<section name="tracks">
- <string name="directories" value="Downtown~Zigzag~Loops~Zurich~Moon~Snake~Rally~Industrial" />
+ <string name="directories" value="Zurich~Downtown~Zigzag~Loops~Moon~Snake~Rally~Industrial" />
</section>
<section name="cars">
<string name="directories" value="vw~jeep~z3~flash2" />
@@ -14,11 +14,14 @@
<integer name="acceleration" value="25" />
<integer name="deceleration" value="50" />
<integer name="steeringPower" value="180" />
- <integer name="slidingFactor" value="75" />
+ <integer name="slidingFactor" value="60" />
<string name="name" value="VW" />
<integer name="price" value="1500" />
+ <integer name="motorPrice" value="500" />
+ <integer name="tiresPrice" value="200" />
+ <integer name="armorPrice" value="300" />
<surface name="surface" file="cars/vw/surface.tga" x="0" y="0" width="64" height="64" />
- <surface name="surface3d" file="cars/vw/surface3d.tga" x="0" y="0" width="95" height="93" />
+ <surface name="surface3d" file="cars/vw/surface3d.tga" x="0" y="0" width="100" height="100" />
</section>
<section name="jeep">
<integer name="length" value="60" />
@@ -29,11 +32,14 @@
<integer name="acceleration" value="30" />
<integer name="deceleration" value="60" />
<integer name="steeringPower" value="200" />
- <integer name="slidingFactor" value="85" />
+ <integer name="slidingFactor" value="65" />
<string name="name" value="Ranger" />
<integer name="price" value="3500" />
+ <integer name="motorPrice" value="750" />
+ <integer name="tiresPrice" value="300" />
+ <integer name="armorPrice" value="500" />
<surface name="surface" file="cars/jeep/surface.tga" x="0" y="0" width="64" height="64" />
- <surface name="surface3d" file="cars/jeep/surface3d.tga" x="0" y="0" width="95" height="93" />
+ <surface name="surface3d" file="cars/jeep/surface3d.tga" x="0" y="0" width="100" height="100" />
</section>
<section name="z3">
<integer name="length" value="61" />
@@ -44,11 +50,14 @@
<integer name="acceleration" value="30" />
<integer name="deceleration" value="60" />
<integer name="steeringPower" value="200" />
- <integer name="slidingFactor" value="85" />
+ <integer name="slidingFactor" value="70" />
<string name="name" value="Z3" />
<integer name="price" value="5500" />
+ <integer name="motorPrice" value="1000" />
+ <integer name="tiresPrice" value="500" />
+ <integer name="armorPrice" value="750" />
<surface name="surface" file="cars/z3/surface.tga" x="0" y="0" width="64" height="64" />
- <surface name="surface3d" file="cars/z3/surface3d.tga" x="0" y="0" width="95" height="93" />
+ <surface name="surface3d" file="cars/z3/surface3d.tga" x="0" y="0" width="100" height="100" />
</section>
<section name="flash2">
<integer name="length" value="60" />
@@ -59,11 +68,38 @@
<integer name="acceleration" value="50" />
<integer name="deceleration" value="60" />
<integer name="steeringPower" value="200" />
- <integer name="slidingFactor" value="90" />
+ <integer name="slidingFactor" value="80" />
<string name="name" value="Flash" />
<integer name="price" value="15000" />
+ <integer name="motorPrice" value="1500" />
+ <integer name="tiresPrice" value="1000" />
+ <integer name="armorPrice" value="1500" />
<surface name="surface" file="cars/flash2/surface.tga" x="0" y="0" width="64" height="64" />
- <surface name="surface3d" file="cars/flash2/surface3d.tga" x="0" y="0" width="95" height="93" />
+ <surface name="surface3d" file="cars/flash2/surface3d.tga" x="0" y="0" width="100" height="100" />
+ </section>
+ </section>
+ <section name="upgrades">
+ <string name="directories" value="motors~tires" />
+ <section name="motors">
+ <surface name="motor1" file="upgrades/motors/motor_1.tga" x="0" y="0" width="100" height="100" />
+ <surface name="motor2" file="upgrades/motors/motor_2.tga" x="0" y="0" width="100" height="100" />
+ <surface name="motor3" file="upgrades/motors/motor_3.tga" x="0" y="0" width="100" height="100" />
+ <surface name="motor4" file="upgrades/motors/motor_4.tga" x="0" y="0" width="100" height="100" />
+ <surface name="motor5" file="upgrades/motors/motor_5.tga" x="0" y="0" width="100" height="100" />
+ </section>
+ <section name="tires">
+ <surface name="tires1" file="upgrades/tires/tires_1.tga" x="0" y="0" width="100" height="100" />
+ <surface name="tires2" file="upgrades/tires/tires_2.tga" x="0" y="0" width="100" height="100" />
+ <surface name="tires3" file="upgrades/tires/tires_3.tga" x="0" y="0" width="100" height="100" />
+ <surface name="tires4" file="upgrades/tires/tires_4.tga" x="0" y="0" width="100" height="100" />
+ <surface name="tires5" file="upgrades/tires/tires_5.tga" x="0" y="0" width="100" height="100" />
+ </section>
+ <section name="armors">
+ <surface name="armor1" file="upgrades/armors/armor_1.tga" x="0" y="0" width="100" height="100" />
+ <surface name="armor2" file="upgrades/armors/armor_2.tga" x="0" y="0" width="100" height="100" />
+ <surface name="armor3" file="upgrades/armors/armor_3.tga" x="0" y="0" width="100" height="100" />
+ <surface name="armor4" file="upgrades/armors/armor_4.tga" x="0" y="0" width="100" height="100" />
+ <surface name="armor5" file="upgrades/armors/armor_5.tga" x="0" y="0" width="100" height="100" />
</section>
</section>
<section name="bullets">
@@ -86,6 +122,7 @@
</section>
<section name="misc">
<surface name="cross" file="misc/cross.tga" x="0" y="0" width="16" height="16" />
+ <surface name="flag" file="misc/flag.tga" x="0" y="0" width="100" height="100" />
<surface name="picture" file="misc/picture.tga" x="0" y="0" width="102" height="128" />
<surface name="info" file="misc/info.tga" x="0" y="0" width="48" height="48" />
<surface name="caution" file="misc/caution.tga" x="0" y="0" width="48" height="48" />
@@ -189,6 +226,11 @@
<grid pos="0,0" size="120,10" array="1,10" />
</image>
</sprite>
+ <sprite name="ammo">
+ <image file="panel/bullets.tga">
+ <grid pos="0,0" size="120,37" array="1,21" />
+ </image>
+ </sprite>
</section>
<section name="fonts">
<sprite name="lcd_13_green_sprite">
diff --git a/resources/tracks/Downtown/vmap.tga b/resources/tracks/Downtown/vmap.tga
index 304bcb6..184dc94 100644
Binary files a/resources/tracks/Downtown/vmap.tga and b/resources/tracks/Downtown/vmap.tga differ
diff --git a/resources/tracks/Industrial/vmap.tga b/resources/tracks/Industrial/vmap.tga
index a17c39e..8e24902 100644
Binary files a/resources/tracks/Industrial/vmap.tga and b/resources/tracks/Industrial/vmap.tga differ
diff --git a/resources/trophy.desktop b/resources/trophy.desktop
new file mode 100644
index 0000000..d1c2316
--- /dev/null
+++ b/resources/trophy.desktop
@@ -0,0 +1,10 @@
+[Desktop Entry]
+Version=1.0
+Type=Application
+Name=Trophy
+GenericName=Racing Game
+Comment=2D car racing game with power-ups
+Icon=trophy.png
+TryExec=trophy
+Exec=trophy
+Categories=Application;Game;ArcadeGame;
diff --git a/resources/trophy.png b/resources/trophy.png
new file mode 100644
index 0000000..9354b5c
Binary files /dev/null and b/resources/trophy.png differ
diff --git a/resources/upgrades/armors/armor_1.tga b/resources/upgrades/armors/armor_1.tga
new file mode 100644
index 0000000..e64b290
Binary files /dev/null and b/resources/upgrades/armors/armor_1.tga differ
diff --git a/resources/upgrades/armors/armor_2.tga b/resources/upgrades/armors/armor_2.tga
new file mode 100644
index 0000000..d0fb67d
Binary files /dev/null and b/resources/upgrades/armors/armor_2.tga differ
diff --git a/resources/upgrades/armors/armor_3.tga b/resources/upgrades/armors/armor_3.tga
new file mode 100644
index 0000000..3f73ac4
Binary files /dev/null and b/resources/upgrades/armors/armor_3.tga differ
diff --git a/resources/upgrades/armors/armor_4.tga b/resources/upgrades/armors/armor_4.tga
new file mode 100644
index 0000000..9a007ba
Binary files /dev/null and b/resources/upgrades/armors/armor_4.tga differ
diff --git a/resources/upgrades/armors/armor_5.tga b/resources/upgrades/armors/armor_5.tga
new file mode 100644
index 0000000..5889c97
Binary files /dev/null and b/resources/upgrades/armors/armor_5.tga differ
diff --git a/resources/upgrades/motors/motor_1.tga b/resources/upgrades/motors/motor_1.tga
new file mode 100644
index 0000000..168ed17
Binary files /dev/null and b/resources/upgrades/motors/motor_1.tga differ
diff --git a/resources/upgrades/motors/motor_2.tga b/resources/upgrades/motors/motor_2.tga
new file mode 100644
index 0000000..c59e637
Binary files /dev/null and b/resources/upgrades/motors/motor_2.tga differ
diff --git a/resources/upgrades/motors/motor_3.tga b/resources/upgrades/motors/motor_3.tga
new file mode 100644
index 0000000..23e461c
Binary files /dev/null and b/resources/upgrades/motors/motor_3.tga differ
diff --git a/resources/upgrades/motors/motor_4.tga b/resources/upgrades/motors/motor_4.tga
new file mode 100644
index 0000000..1fe1813
Binary files /dev/null and b/resources/upgrades/motors/motor_4.tga differ
diff --git a/resources/upgrades/motors/motor_5.tga b/resources/upgrades/motors/motor_5.tga
new file mode 100644
index 0000000..d1ec904
Binary files /dev/null and b/resources/upgrades/motors/motor_5.tga differ
diff --git a/resources/upgrades/tires/tires_1.tga b/resources/upgrades/tires/tires_1.tga
new file mode 100644
index 0000000..b6e6f32
Binary files /dev/null and b/resources/upgrades/tires/tires_1.tga differ
diff --git a/resources/upgrades/tires/tires_2.tga b/resources/upgrades/tires/tires_2.tga
new file mode 100644
index 0000000..57f9b3f
Binary files /dev/null and b/resources/upgrades/tires/tires_2.tga differ
diff --git a/resources/upgrades/tires/tires_3.tga b/resources/upgrades/tires/tires_3.tga
new file mode 100644
index 0000000..3b68275
Binary files /dev/null and b/resources/upgrades/tires/tires_3.tga differ
diff --git a/resources/upgrades/tires/tires_4.tga b/resources/upgrades/tires/tires_4.tga
new file mode 100644
index 0000000..66a2e1e
Binary files /dev/null and b/resources/upgrades/tires/tires_4.tga differ
diff --git a/resources/upgrades/tires/tires_5.tga b/resources/upgrades/tires/tires_5.tga
new file mode 100644
index 0000000..7d71ce9
Binary files /dev/null and b/resources/upgrades/tires/tires_5.tga differ
diff --git a/src/Makefile.am b/src/Makefile.am
index b6fa316..931644e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,17 +1,20 @@
bin_PROGRAMS = trophy
-trophy_SOURCES = cagoody.cpp cainfodialog.cpp camenu.h canetserver.cpp capositiontable.h casoundeffect.cpp \
- cagoody.h cainfodialog.h camenuinput.cpp canetserver.h capositiontableview.cpp casoundeffect.h \
- cagoodytype.h calabel.cpp camenuinput.h capanel.cpp capositiontableview.h castringlist.cpp \
- cacartype.h caimagehueselector.cpp calabel.h camenuitem.cpp capanel.h caresources.cpp castringlist.h \
- cacolor.h caimagehueselector.h calineedit.cpp camenuitem.h caplayer.cpp caresources.h catrack.h \
- cacredits.cpp caimagemanipulation.cpp calineedit.h camenulabel.cpp caplayer.h cascreen.cpp catrophy.cpp \
- cacredits.h caimagemanipulation.h caloadingscreen.cpp camenulabel.h caplayersettingsdialog.cpp cascreen.h \
- catrophy.h cadialog.cpp caimageselector.cpp caloadingscreen.h camenuselect.cpp caplayersettingsdialog.h \
- casignupscreen.cpp cawidget.cpp cadialog.h caimageselector.h camath.cpp camenuselect.h caplayerview.cpp \
- casignupscreen.h cawidget.h cadustclowd.h caimageview.cpp camath.h canetclient.cpp caplayerview.h \
+trophy_SOURCES = cagoody.cpp cainfodialog.cpp caescapedialog.cpp camenu.h canetserver.cpp capositiontable.h casoundeffect.cpp \
+ cagoody.h cainfodialog.h caescapedialog.h camenuinput.cpp canetserver.h capositiontableview.cpp casoundeffect.h shopscreen.h \
+ cagoodytype.h cagoodytype.cpp calabel.cpp camenuinput.h capanel.cpp capositiontableview.h caconfigurekey.cpp shopscreen.cpp \
+ cartype.h cartype.cpp caimagehueselector.cpp calabel.h camenuitem.cpp camenuselect.cpp capanel.h caresources.cpp caconfigurekey.h \
+ utils/hsvcolor.h caimagehueselector.h calineedit.cpp camenuitem.h player.cpp caresources.h track.h track.cpp guibox.h guibox.cpp \
+ cacredits.cpp caimagemanipulation.cpp calineedit.h camenulabel.cpp player.h cascreen.cpp catrophy.cpp cacarupgrades.h cacarupgrades.cpp \
+ cacredits.h caimagemanipulation.h caloadingscreen.cpp camenulabel.h caplayersettingsdialog.cpp cascreen.h cachampionshipscreen.h \
+ catrophy.h cadialog.cpp caimageselector.cpp caloadingscreen.h caplayersettingsdialog.h cachampionshipscreen.cpp \
+ casignupscreen.cpp cawidget.cpp cadialog.h caimageselector.h utils/trophymath.cpp camenuselect.h caplayerview.cpp \
+ casignupscreen.h cawidget.h cadustclowd.h caimageview.cpp utils/trophymath.h canetclient.cpp caplayerview.h \
caslotselectiondialog.cpp cafogbomb.h caimageview.h camenu.cpp canetclient.h capositiontable.cpp \
- caslotselectiondialog.h
+ caslotselectiondialog.h humanplayer.h humanplayer.cpp computerplayer.cpp computerplayer.h \
+ upgradespanel.cpp upgradespanel.h windialog.h windialog.cpp
-AM_LDFLAGS = `pkg-config --libs $(CLANLIB_MODULES)`
-INCLUDES = `pkg-config --cflags $(CLANLIB_MODULES)`
+
+trophy_LDADD = $(CLANLIB_LIBS)
+INCLUDES = $(CLANLIB_CFLAGS)
AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\"
+AM_CXXFLAGS = -Wall
diff --git a/src/Makefile.in b/src/Makefile.in
index 06f56de..bdbabf1 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -45,22 +45,29 @@ CONFIG_CLEAN_VPATH_FILES =
am__installdirs = "$(DESTDIR)$(bindir)"
PROGRAMS = $(bin_PROGRAMS)
am_trophy_OBJECTS = cagoody.$(OBJEXT) cainfodialog.$(OBJEXT) \
- canetserver.$(OBJEXT) casoundeffect.$(OBJEXT) \
- camenuinput.$(OBJEXT) capositiontableview.$(OBJEXT) \
- calabel.$(OBJEXT) capanel.$(OBJEXT) castringlist.$(OBJEXT) \
+ caescapedialog.$(OBJEXT) canetserver.$(OBJEXT) \
+ casoundeffect.$(OBJEXT) camenuinput.$(OBJEXT) \
+ capositiontableview.$(OBJEXT) cagoodytype.$(OBJEXT) \
+ calabel.$(OBJEXT) capanel.$(OBJEXT) caconfigurekey.$(OBJEXT) \
+ shopscreen.$(OBJEXT) cartype.$(OBJEXT) \
caimagehueselector.$(OBJEXT) camenuitem.$(OBJEXT) \
- caresources.$(OBJEXT) calineedit.$(OBJEXT) caplayer.$(OBJEXT) \
- cacredits.$(OBJEXT) caimagemanipulation.$(OBJEXT) \
- camenulabel.$(OBJEXT) cascreen.$(OBJEXT) catrophy.$(OBJEXT) \
+ camenuselect.$(OBJEXT) caresources.$(OBJEXT) \
+ calineedit.$(OBJEXT) player.$(OBJEXT) track.$(OBJEXT) \
+ guibox.$(OBJEXT) cacredits.$(OBJEXT) \
+ caimagemanipulation.$(OBJEXT) camenulabel.$(OBJEXT) \
+ cascreen.$(OBJEXT) catrophy.$(OBJEXT) cacarupgrades.$(OBJEXT) \
caloadingscreen.$(OBJEXT) caplayersettingsdialog.$(OBJEXT) \
cadialog.$(OBJEXT) caimageselector.$(OBJEXT) \
- camenuselect.$(OBJEXT) casignupscreen.$(OBJEXT) \
- cawidget.$(OBJEXT) camath.$(OBJEXT) caplayerview.$(OBJEXT) \
+ cachampionshipscreen.$(OBJEXT) casignupscreen.$(OBJEXT) \
+ cawidget.$(OBJEXT) trophymath.$(OBJEXT) caplayerview.$(OBJEXT) \
caimageview.$(OBJEXT) canetclient.$(OBJEXT) \
caslotselectiondialog.$(OBJEXT) camenu.$(OBJEXT) \
- capositiontable.$(OBJEXT)
+ capositiontable.$(OBJEXT) humanplayer.$(OBJEXT) \
+ computerplayer.$(OBJEXT) upgradespanel.$(OBJEXT) \
+ windialog.$(OBJEXT)
trophy_OBJECTS = $(am_trophy_OBJECTS)
-trophy_LDADD = $(LDADD)
+am__DEPENDENCIES_1 =
+trophy_DEPENDENCIES = $(am__DEPENDENCIES_1)
DEFAULT_INCLUDES = -I. at am__isrc@
depcomp = $(SHELL) $(top_srcdir)/depcomp
am__depfiles_maybe = depfiles
@@ -88,6 +95,8 @@ AWK = @AWK@
CC = @CC@
CCDEPMODE = @CCDEPMODE@
CFLAGS = @CFLAGS@
+CLANLIB_CFLAGS = @CLANLIB_CFLAGS@
+CLANLIB_LIBS = @CLANLIB_LIBS@
CLANLIB_MODULES = @CLANLIB_MODULES@
CPPFLAGS = @CPPFLAGS@
CXX = @CXX@
@@ -168,22 +177,24 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
-trophy_SOURCES = cagoody.cpp cainfodialog.cpp camenu.h canetserver.cpp capositiontable.h casoundeffect.cpp \
- cagoody.h cainfodialog.h camenuinput.cpp canetserver.h capositiontableview.cpp casoundeffect.h \
- cagoodytype.h calabel.cpp camenuinput.h capanel.cpp capositiontableview.h castringlist.cpp \
- cacartype.h caimagehueselector.cpp calabel.h camenuitem.cpp capanel.h caresources.cpp castringlist.h \
- cacolor.h caimagehueselector.h calineedit.cpp camenuitem.h caplayer.cpp caresources.h catrack.h \
- cacredits.cpp caimagemanipulation.cpp calineedit.h camenulabel.cpp caplayer.h cascreen.cpp catrophy.cpp \
- cacredits.h caimagemanipulation.h caloadingscreen.cpp camenulabel.h caplayersettingsdialog.cpp cascreen.h \
- catrophy.h cadialog.cpp caimageselector.cpp caloadingscreen.h camenuselect.cpp caplayersettingsdialog.h \
- casignupscreen.cpp cawidget.cpp cadialog.h caimageselector.h camath.cpp camenuselect.h caplayerview.cpp \
- casignupscreen.h cawidget.h cadustclowd.h caimageview.cpp camath.h canetclient.cpp caplayerview.h \
+trophy_SOURCES = cagoody.cpp cainfodialog.cpp caescapedialog.cpp camenu.h canetserver.cpp capositiontable.h casoundeffect.cpp \
+ cagoody.h cainfodialog.h caescapedialog.h camenuinput.cpp canetserver.h capositiontableview.cpp casoundeffect.h shopscreen.h \
+ cagoodytype.h cagoodytype.cpp calabel.cpp camenuinput.h capanel.cpp capositiontableview.h caconfigurekey.cpp shopscreen.cpp \
+ cartype.h cartype.cpp caimagehueselector.cpp calabel.h camenuitem.cpp camenuselect.cpp capanel.h caresources.cpp caconfigurekey.h \
+ utils/hsvcolor.h caimagehueselector.h calineedit.cpp camenuitem.h player.cpp caresources.h track.h track.cpp guibox.h guibox.cpp \
+ cacredits.cpp caimagemanipulation.cpp calineedit.h camenulabel.cpp player.h cascreen.cpp catrophy.cpp cacarupgrades.h cacarupgrades.cpp \
+ cacredits.h caimagemanipulation.h caloadingscreen.cpp camenulabel.h caplayersettingsdialog.cpp cascreen.h cachampionshipscreen.h \
+ catrophy.h cadialog.cpp caimageselector.cpp caloadingscreen.h caplayersettingsdialog.h cachampionshipscreen.cpp \
+ casignupscreen.cpp cawidget.cpp cadialog.h caimageselector.h utils/trophymath.cpp camenuselect.h caplayerview.cpp \
+ casignupscreen.h cawidget.h cadustclowd.h caimageview.cpp utils/trophymath.h canetclient.cpp caplayerview.h \
caslotselectiondialog.cpp cafogbomb.h caimageview.h camenu.cpp canetclient.h capositiontable.cpp \
- caslotselectiondialog.h
+ caslotselectiondialog.h humanplayer.h humanplayer.cpp computerplayer.cpp computerplayer.h \
+ upgradespanel.cpp upgradespanel.h windialog.h windialog.cpp
-AM_LDFLAGS = `pkg-config --libs $(CLANLIB_MODULES)`
-INCLUDES = `pkg-config --cflags $(CLANLIB_MODULES)`
+trophy_LDADD = $(CLANLIB_LIBS)
+INCLUDES = $(CLANLIB_CFLAGS)
AM_CPPFLAGS = -DPKGDATADIR=\"$(pkgdatadir)\"
+AM_CXXFLAGS = -Wall
all: all-am
.SUFFIXES:
@@ -265,9 +276,14 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cacarupgrades.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cachampionshipscreen.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caconfigurekey.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cacredits.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cadialog.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caescapedialog.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cagoody.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cagoodytype.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caimagehueselector.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caimagemanipulation.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caimageselector.Po at am__quote@
@@ -276,7 +292,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/calabel.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/calineedit.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caloadingscreen.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/camath.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/camenu.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/camenuinput.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/camenuitem.Po at am__quote@
@@ -285,19 +300,27 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/canetclient.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/canetserver.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/capanel.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caplayer.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caplayersettingsdialog.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caplayerview.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/capositiontable.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/capositiontableview.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caresources.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cartype.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cascreen.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/casignupscreen.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/caslotselectiondialog.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/casoundeffect.Po at am__quote@
- at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/castringlist.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/catrophy.Po at am__quote@
@AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/cawidget.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/computerplayer.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/guibox.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/humanplayer.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/player.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/shopscreen.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/track.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/trophymath.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/upgradespanel.Po at am__quote@
+ at AMDEP_TRUE@@am__include@ @am__quote at ./$(DEPDIR)/windialog.Po at am__quote@
.cpp.o:
@am__fastdepCXX_TRUE@ $(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
@@ -313,6 +336,20 @@ distclean-compile:
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'`
+trophymath.o: utils/trophymath.cpp
+ at am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT trophymath.o -MD -MP -MF $(DEPDIR)/trophymath.Tpo -c -o trophymath.o `test -f 'utils/trophymath.cpp' || echo '$(srcdir)/'`utils/trophymath.cpp
+ at am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/trophymath.Tpo $(DEPDIR)/trophymath.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='utils/trophymath.cpp' object='trophymath.o' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o trophymath.o `test -f 'utils/trophymath.cpp' || echo '$(srcdir)/'`utils/trophymath.cpp
+
+trophymath.obj: utils/trophymath.cpp
+ at am__fastdepCXX_TRUE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -MT trophymath.obj -MD -MP -MF $(DEPDIR)/trophymath.Tpo -c -o trophymath.obj `if test -f 'utils/trophymath.cpp'; then $(CYGPATH_W) 'utils/trophymath.cpp'; else $(CYGPATH_W) '$(srcdir)/utils/trophymath.cpp'; fi`
+ at am__fastdepCXX_TRUE@ $(am__mv) $(DEPDIR)/trophymath.Tpo $(DEPDIR)/trophymath.Po
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='utils/trophymath.cpp' object='trophymath.obj' libtool=no @AMDEPBACKSLASH@
+ at AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+ at am__fastdepCXX_FALSE@ $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -c -o trophymath.obj `if test -f 'utils/trophymath.cpp'; then $(CYGPATH_W) 'utils/trophymath.cpp'; else $(CYGPATH_W) '$(srcdir)/utils/trophymath.cpp'; fi`
+
ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
unique=`for i in $$list; do \
diff --git a/src/cacartype.h b/src/cacartype.h
deleted file mode 100644
index e10e48a..0000000
--- a/src/cacartype.h
+++ /dev/null
@@ -1,69 +0,0 @@
-#ifndef CACARTYPE_H
-#define CACARTYPE_H
-
-#include <ClanLib/core.h>
-#include <ClanLib/display.h>
-
-/** Structure for car types.
- @author Andrew Mustun
-*/
-struct CACarType {
- /** Constructor.
- */
- CACarType() {
- surface = 0;
- surface3d = 0;
- }
-
- /** Destructor.
- */
- ~CACarType() {
- if( surface ) {
- delete surface;
- surface = 0;
- }
- if( surface3d ) {
- delete surface3d;
- surface3d = 0;
- }
- }
-
- //! Car name (e.g. "Capri")
- std::string name;
-
- //! Pointer to surface resource (r,g,b,m,y,c)
- CL_Surface* surface;
- //! Pointer to surface resource 3d (r,g,b,m,y,c)
- CL_Surface* surface3d;
-
- //! Current car length in pixel
- int length;
- //! Current car width in pixel
- int width;
- //! Half of the diagonal
- float radius;
- //! Angle to edge
- float angle;
-
- //! Maximum speed in pixels per second
- float maxSpeed;
- //! Minimum speed in pixels per second
- float minSpeed;
- //! Maximum turbo load in pixels
- float maxTurbo;
- //! Acceleration in pixels per square second
- float acceleration;
- //! Deceleration in pixels per square second
- float deceleration;
- //! Steering power in degrees per second
- float steeringPower;
- //! Sliding factor (1=no, 0.8=much, ...)
- float slidingFactor;
-
- //! Price in USD
- int price;
-};
-
-#endif
-
-// EOF
diff --git a/src/cacarupgrades.cpp b/src/cacarupgrades.cpp
new file mode 100644
index 0000000..c55ba20
--- /dev/null
+++ b/src/cacarupgrades.cpp
@@ -0,0 +1,62 @@
+#include "cacarupgrades.h"
+#include "caresources.h"
+#include <sstream>
+
+/** Constructor
+*/
+CACarUpgrades::CACarUpgrades()
+{
+ const std::string upgradesPath = "upgrades";
+ for (int i = 0; i < 5; i++)
+ {
+ std::ostringstream oss;
+ oss << upgradesPath << "/motors/motor" << i+1;
+ motors.push_back ( new CL_Surface( oss.str(), CA_RES->resources ));
+ }
+ for (int i = 0; i < 5; i++)
+ {
+ std::ostringstream oss;
+ oss << upgradesPath << "/tires/tires" << i+1;
+ tires.push_back ( new CL_Surface( oss.str(), CA_RES->resources ));
+ }
+ for (int i = 0; i < 5; i++)
+ {
+ std::ostringstream oss;
+ oss << upgradesPath << "/armors/armor" << i+1;
+ armors.push_back ( new CL_Surface( oss.str(), CA_RES->resources ));
+ }
+}
+
+CACarUpgrades::~CACarUpgrades()
+{
+ for (int i = 0; i < 5; i++)
+ {
+ if (motors[i] != 0)
+ {
+ delete motors[i];
+ motors[i] = 0;
+ }
+ }
+ motors.clear();
+ for (int i = 0; i < 5; i++)
+ {
+ if (tires[i] != 0)
+ {
+ delete tires[i];
+ tires[i] = 0;
+ }
+ }
+ tires.clear();
+ for (int i = 0; i < 5; i++)
+ {
+ if (armors[i] != 0)
+ {
+ delete armors[i];
+ armors[i] = 0;
+ }
+ }
+ armors.clear();
+}
+
+
+// EOF
diff --git a/src/cacarupgrades.h b/src/cacarupgrades.h
new file mode 100644
index 0000000..588e0d9
--- /dev/null
+++ b/src/cacarupgrades.h
@@ -0,0 +1,29 @@
+#ifndef CACARUPGRADES_H
+#define CACARUPGRADES_H
+
+#include <ClanLib/core.h>
+#include <ClanLib/display.h>
+#include <vector>
+
+
+
+
+/** Handler for upgrades ressources
+ @author Matthieu Lecesne
+*/
+class CACarUpgrades
+{
+public:
+ CACarUpgrades();
+ ~CACarUpgrades();
+ CL_Surface* getMotor(const int num) const { return motors[num];}
+ CL_Surface* getTires(const int num) const { return tires[num];}
+ CL_Surface* getArmor(const int num) const { return armors[num];}
+private:
+ std::vector<CL_Surface*> motors;
+ std::vector<CL_Surface*> tires;
+ std::vector<CL_Surface*> armors;
+
+};
+
+#endif
diff --git a/src/cachampionshipscreen.cpp b/src/cachampionshipscreen.cpp
new file mode 100644
index 0000000..9d36de2
--- /dev/null
+++ b/src/cachampionshipscreen.cpp
@@ -0,0 +1,205 @@
+#include "cachampionshipscreen.h"
+#include "catrophy.h"
+#include "player.h"
+#include <functional>
+#include <algorithm>
+
+bool RankPredicate::operator()(const Player* const p1, const Player* const p2)
+ {
+ // In case of level, use alphabetical order
+ if (p1->getTotalPoints() == p2->getTotalPoints())
+ return (p1->getName() < p2->getName());
+ else
+ return (p1->getTotalPoints() > p2->getTotalPoints());
+ }
+
+
+/** Constructor.
+*/
+CAChampionshipScreen::CAChampionshipScreen(Player* humanPlayer, const std::vector<Player*> player, const std::vector<std::vector<Player*> > runningPlayer,
+ CL_Surface* background, CL_Surface* button, CL_Surface* buttonEasy, CL_Surface* buttonMedium, CL_Surface* buttonHard, CL_Font* font)
+ : CAScreen(),
+ m_humanPlayer(humanPlayer),
+ m_player(player),
+ m_runningPlayers(runningPlayer),
+ m_background(background),
+ m_font(font),
+ m_button(button),
+ m_buttonEasy(buttonEasy),
+ m_buttonMedium(buttonMedium),
+ m_buttonHard(buttonHard),
+ m_displayMode(DISPLAY_ADD_POINTS_EASY)
+{
+ left = 0;
+ right = CA_APP->width;
+ top = CA_APP->headerHeight + 30;
+ bottom = CA_APP->headerHeight + 400;
+ barHeight = m_font->get_height() + 6;
+ std::sort(m_player.begin(), m_player.end(), RankPredicate());
+ title = "C H A M P I O N S H I P";
+}
+
+/** Destructor.
+*/
+CAChampionshipScreen::~CAChampionshipScreen()
+{}
+
+
+
+/** Runs the screen.
+*/
+int
+CAChampionshipScreen::run()
+{
+ //CL_Input::chain_button_release.push_back( this );
+ //slot = CL_Input::sig_button_release.connect(thCreateSlot(this, &CAChampionshipScreen::on_button_release));
+ //slot = CL_Input::sig_button_press.connect(this, &CAChampionshipScreen::on_button_release);
+ slot = CL_Keyboard::sig_key_up().connect(this, &CAChampionshipScreen::on_key_released);
+
+ CA_APP->fadeScreen( true, this );
+ done = false;
+ cancel = false;
+
+ // Screen loop:
+ //
+ while( !done )
+ {
+ CA_APP->measureFrameTime( true );
+
+ buildScreen();
+
+ // Play background sound:
+ CASoundEffect::playBackgroundMelody();
+
+ CL_Display::flip(); // Copy framebufer to screen
+ CL_System::keep_alive(); // VERY VITAL for the system!
+
+ CA_APP->measureFrameTime( false );
+ }
+
+ CA_APP->fadeScreen( false, this );
+ CA_APP->waitForSilence();
+
+ //CL_Input::chain_button_release.remove( this );
+
+ CL_Keyboard::sig_key_up().disconnect(slot);
+ if (m_player[0] == m_humanPlayer)
+ return 0;
+ else
+ return 1;
+}
+
+/** Builds the screen.
+*/
+void
+CAChampionshipScreen::buildScreen()
+{
+ // Background:
+ //
+ m_background->draw ( CL_Rect(0, 0, CA_APP->width, CA_APP->height) );
+ displayTitle();
+
+ CL_Display::fill_rect( CL_Rect(left, top, right, bottom), CL_Color(0, 0, 0, 64) );
+
+ const int rankWidth = 30;
+ const int rankLeft = 0;
+
+ const int nameWidth = 200;
+ const int nameLeft = 50;
+
+ const int addPtWidth = 30;
+ const int addPtLeft = 260;
+
+ const int totalPtWidth = 50;
+ const int totalPtLeft = 300;
+
+ const int caWidth = (totalPtLeft + totalPtWidth)*2;
+ const int middleMargin = 30;
+
+
+ const int caHeight = (barHeight * m_player.size())/2;
+ const int marginTop = (top+bottom)/2 - caHeight/2;
+
+ for (unsigned int rank=0; rank < m_player.size(); rank++)
+ {
+ std::ostringstream ossRankStr, ossTotalPoints, ossRacePoints;
+ ossRankStr << rank + 1 << ".";
+ ossTotalPoints << m_player[rank]->getTotalPoints();
+ int marginLeft = (right+left)/2 + middleMargin/2;
+ int upPos = rank - m_player.size()/2;
+ if (rank < m_player.size()/2 )
+ {
+ marginLeft -= caWidth/2 + middleMargin;
+ upPos = rank;
+ }
+ // Buttons:
+ //
+ m_button->draw ( CL_Rect(marginLeft+rankLeft, marginTop+barHeight*upPos, marginLeft+rankLeft+rankWidth, marginTop+(barHeight*(upPos+1))) );
+ m_button->draw ( CL_Rect(marginLeft+nameLeft, marginTop+barHeight*upPos, marginLeft+nameLeft+nameWidth, marginTop+(barHeight*(upPos+1))) );
+ if (m_displayMode != DISPLAY_CHAMPIONSHIP)
+ {
+ for (int i=0; i<= int(m_displayMode); i++)
+ {
+ std::vector<Player*>::const_iterator it = std::find(m_runningPlayers[i].begin(), m_runningPlayers[i].end(), m_player[rank]);
+ if (it != m_runningPlayers[i].end() && m_player[rank]->getRacePoints() != 0)
+ {
+ CL_Surface* buttonToUse = (i==0 ? m_buttonEasy : (i==1)? m_buttonMedium : m_buttonHard); // Choose the button color
+ buttonToUse->draw ( CL_Rect(marginLeft+addPtLeft, marginTop+barHeight*upPos, marginLeft+addPtLeft+addPtWidth, marginTop+(barHeight*(upPos+1))) );
+ ossRacePoints << "+" << m_player[rank]->getRacePoints();
+ }
+ }
+ }
+ m_button->draw ( CL_Rect(marginLeft+totalPtLeft, marginTop+barHeight*upPos, marginLeft+totalPtLeft+totalPtWidth, marginTop+(barHeight*(upPos+1))) );
+
+ // Texts:
+ //
+ const int textPosX = marginLeft;
+ const int textPosY = marginTop + 4 + barHeight*upPos;
+ m_font->set_alignment(origin_top_center, 0, 0);
+ m_font->draw( textPosX+rankLeft+rankWidth/2, textPosY, ossRankStr.str());
+ m_font->draw( textPosX+nameLeft+nameWidth/2, textPosY, m_player[rank]->getName() );
+ m_font->draw( textPosX+addPtLeft+addPtWidth/2, textPosY, ossRacePoints.str() );
+ m_font->draw( textPosX+totalPtLeft+totalPtWidth/2, textPosY, ossTotalPoints.str() );
+ }
+}
+
+/** Called on key release.
+*/
+void
+CAChampionshipScreen::on_key_released (const CL_InputEvent &key)
+{
+ switch( key.id )
+ {
+ // Activate:
+ //
+ case CL_KEY_ENTER:
+ case CL_KEY_SPACE:
+ case CL_KEY_ESCAPE:
+ if (m_displayMode != DISPLAY_CHAMPIONSHIP)
+ {
+ int displayInt = int(m_displayMode) + 1;
+ m_displayMode = DisplayMode(displayInt);
+ if (m_displayMode == DISPLAY_CHAMPIONSHIP)
+ {
+ for (unsigned int pl=0; pl < m_player.size(); pl++)
+ {
+ m_player[pl]->addMoney( m_player[pl]->getRaceMoney() );
+ m_player[pl]->setTotalPoints( m_player[pl]->getTotalPoints() + m_player[pl]->getRacePoints() );
+ m_player[pl]->resetForRace(0, NULL); // Player doesn't belong to a race for now
+ }
+ // players points have changed so we sort the player list again
+ std::sort(m_player.begin(), m_player.end(), RankPredicate());
+ }
+ }
+ else
+ {
+ done = true;
+ }
+ break;
+
+ default:
+ break;
+ }
+}
+
+// EOF
diff --git a/src/cachampionshipscreen.h b/src/cachampionshipscreen.h
new file mode 100644
index 0000000..e90b40e
--- /dev/null
+++ b/src/cachampionshipscreen.h
@@ -0,0 +1,84 @@
+#ifndef CACHAMPIONSHIPSCREEN_H
+#define CACHAMPIONSHIPSCREEN_H
+
+#include <ClanLib/display.h>
+
+#include "cascreen.h"
+
+class Player;
+
+/** The championship screen shown after every race
+ @author Andrew Mustun
+ @author Matthieu Lecesne
+*/
+
+/** Prediate to sort player by rank
+*/
+struct RankPredicate: public std::binary_function<Player*, Player*, bool>
+{
+ bool operator()(const Player* const p1, const Player* const p2);
+};
+
+
+enum DisplayMode
+{
+ DISPLAY_ADD_POINTS_EASY,
+ DISPLAY_ADD_POINTS_MEDIUM,
+ DISPLAY_ADD_POINTS_HARD,
+ DISPLAY_CHAMPIONSHIP
+};
+
+class CAChampionshipScreen : public CAScreen {
+public:
+ CAChampionshipScreen(Player* humanPlayer, const std::vector<Player*> player, const std::vector<std::vector<Player*> > runningPlayer,
+ CL_Surface* background, CL_Surface* button, CL_Surface* button_easy, CL_Surface* button_medium, CL_Surface* button_hard, CL_Font* font);
+ ~CAChampionshipScreen();
+
+ void reset();
+
+ void setOffset( int o );
+
+ virtual int run();
+ virtual void buildScreen();
+
+ virtual void on_key_released (const CL_InputEvent &key);
+
+private:
+
+ //! Left border position.
+ int left;
+ //! Right border position.
+ int right;
+ //! Top border position.
+ int top;
+ //! Bottom border position.
+ int bottom;
+ //! Height of the button
+ int barHeight;
+ //! Pointer to human player
+ Player* m_humanPlayer;
+ //! all players sorted by Totalrank
+ std::vector<Player*> m_player;
+ //! players running in the 3 races
+ std::vector<std::vector <Player*> > m_runningPlayers;
+ //! The Background Surface
+ CL_Surface* m_background;
+ //! The font use for display championship result
+ CL_Font* m_font;
+ //! The button use in the championship table
+ CL_Surface* m_button;
+ //! The button use for easy race point
+ CL_Surface* m_buttonEasy;
+ //! The button use for medium race point
+ CL_Surface* m_buttonMedium;
+ //! The button use for hard race point
+ CL_Surface* m_buttonHard;
+
+ //! display mode (display the point earned in last Race)
+ DisplayMode m_displayMode;
+
+public:
+ CL_Slot slot;
+};
+
+#endif
diff --git a/src/cacolor.h b/src/cacolor.h
deleted file mode 100644
index d1df314..0000000
--- a/src/cacolor.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef CACOLOR_H
-#define CACOLOR_H
-
-#include <ClanLib/core.h>
-
-
-/** Structure for a color.
- Colors in trophy are usually used for
- the modification of red based surfaces.
- @author Andrew Mustun
-*/
-struct CAColor {
-
- /** Constructor for a black color.
- */
- CAColor() {
- h = s = v = 0;
- }
-
-
- /** Constructor for any desired color.
- */
- CAColor( int h, int s, int v ) {
- this->h = h;
- this->s = s;
- this->v = v;
- }
-
-
- /** Operator ==
- */
- inline bool operator==( CAColor c ) {
- return (this->h==c.h && this->s==c.s && this->v==c.v);
- }
-
-
- /** Operator !=
- */
- inline bool operator!=( CAColor c ) {
- //return (this->h!=c.h || this->s!=c.s || this->v!=c.v);
- return !operator==( c );
- }
-
-
- /** Operator =
- */
- inline CAColor operator=( CAColor c ) {
- h = c.h;
- s = c.s;
- v = c.v;
- return *this;
- }
-
- //! Hue of this color
- int h;
- //! Saturation of this color
- int s;
- //! Value of this color
- int v;
-};
-
-#endif
-
-// EOF
diff --git a/src/caconfigurekey.cpp b/src/caconfigurekey.cpp
new file mode 100644
index 0000000..4277004
--- /dev/null
+++ b/src/caconfigurekey.cpp
@@ -0,0 +1,72 @@
+#include "caconfigurekey.h"
+#include "caresources.h"
+#include "caimagemanipulation.h"
+#include "catrophy.h"
+#include "humanplayer.h"
+#include "caconfigurekey.h"
+
+/** Constructor.
+*/
+CAConfigureKey::CAConfigureKey(HumanPlayer* human)
+ : CADialog(),
+ m_human(human),
+ m_keyMode(ConfigureKey::ACCELERATE)
+{
+ resize( 600, 300 ); // a white rectangle
+ title = "Configure Keyboard";
+ using namespace ConfigureKey;
+ m_keyString[ACCELERATE]= "ACCELERATE";
+ m_keyString[BRAKE] = "BRAKE";
+ m_keyString[LEFT] = "STEER LEFT";
+ m_keyString[RIGHT] = "STEER RIGHT";
+ m_keyString[SHOOT] = "SHOOT";
+ m_keyString[BOMB] = "DROP BOMB";
+ m_keyString[BOOST] = "BOOST";
+ m_keyString[HORN] = "HORN";
+}
+
+CAConfigureKey::~CAConfigureKey()
+{ }
+
+void CAConfigureKey::buildScreen()
+{
+ CADialog::buildScreen();
+ const std::string text = std::string ("Press Key For ") + m_keyString[m_keyMode];
+ CA_RES->font_normal_14_white->draw ( (left+32+right-32)/2, (top+32+bottom-32)/2, text );
+}
+
+/** Called on key released.
+*/
+void CAConfigureKey::on_key_released( const CL_InputEvent &key )
+{
+ switch( key.id ) {
+
+ // Cancel (ESC):
+ case CL_KEY_ESCAPE:
+ cancel = true;
+ done = true;
+ break;
+
+ // Activate:
+ case CL_KEY_ENTER:
+ done = true;
+ break;
+
+ // define the key
+ default:
+ m_keyMap[m_keyMode]=key.id;
+ if (m_keyMode != ConfigureKey::HORN)
+ {
+ m_keyMode = ConfigureKey::DefineKey(int(m_keyMode)+1);
+ buildScreen();
+ }
+ else
+ {
+ done = true;
+ m_keyMode = ConfigureKey::ACCELERATE;
+ m_human->setKeyMap(m_keyMap);
+ }
+
+ break;
+ }
+}
\ No newline at end of file
diff --git a/src/caconfigurekey.h b/src/caconfigurekey.h
new file mode 100644
index 0000000..5150f0f
--- /dev/null
+++ b/src/caconfigurekey.h
@@ -0,0 +1,48 @@
+#ifndef CACONFIGUREKEY_H
+#define CACONFIGUREKEY_H
+
+#include <ClanLib/core.h>
+#include <ClanLib/display.h>
+#include "cadialog.h"
+#include <map>
+#include <string>
+
+class HumanPlayer;
+
+namespace ConfigureKey
+{
+ enum DefineKey
+ {
+ ACCELERATE = 0,
+ BRAKE,
+ LEFT,
+ RIGHT,
+ SHOOT,
+ BOMB,
+ BOOST,
+ HORN
+ };
+}
+
+/** Credits screen.
+ @author Matthieu Lecesne
+*/
+class CAConfigureKey : public CADialog {
+public:
+ CAConfigureKey(HumanPlayer* human);
+ ~CAConfigureKey();
+
+ virtual void buildScreen();
+ virtual void on_key_released( const CL_InputEvent &key );
+
+ /*std::map<ConfigureKey::DefineKey, int> getKeyMap()
+ { return m_keyMap; }*/
+
+private:
+ std::map<ConfigureKey::DefineKey, std::string> m_keyString;
+ std::map<ConfigureKey::DefineKey, int> m_keyMap;
+ HumanPlayer* m_human;
+ ConfigureKey::DefineKey m_keyMode;
+};
+
+#endif
diff --git a/src/cacredits.cpp b/src/cacredits.cpp
index 74061fa..89fd954 100644
--- a/src/cacredits.cpp
+++ b/src/cacredits.cpp
@@ -13,42 +13,58 @@ CACredits::CACredits()
title = "C R E D I T S";
scrollPos = 0.0;
- text.setList( "~"
- "- Graphics & Programming -~"
- "~"
- "Andrew Mustun~"
- "andrew at mustun.com~"
- "Colin Pitrat~"
- "colin.pitrat at gmail.com"
- "~"
- "~"
- "- Additional Tracks -~"
- "~"
- "Volker Schatz (Downtown)~"
- "Oliver Luethje (Zigzag, Snake, Rally)"
- "~"
- "~"
- "- Beta Testing / Feedback -~"
- "~"
- "Martin Mustun, Michael Mustun,~"
- "Chris Bruengger, Markus Krieter~"
- "Armijn Hemel, Guus Sliepen, Alfred de Wijn~"
- "Kenneth Gangstoe, Martin Starch Soerensen~"
- "~"
- "~"
- "- Graphics Library ClanLib -~"
- "~"
- "ClanSoft~"
- "http://www.clanlib.org~"
- "~"
- "---~"
- "~"
- "Many thanks to all these people and everyone~"
- "else who contributed something to Trophy!~"
- "~"
- "~" );
+
+ text.push_back("");
+
+ text.push_back("- Programming -");
+ text.push_back("");
+ text.push_back("Andrew Mustun");
+ text.push_back("andrew at mustun.com");
+ text.push_back("Matthieu Lecesne");
+ text.push_back("matthieulecesne at yahoo.fr");
+ text.push_back("Colin Pitrat");
+ text.push_back("colin.pitrat at gmail.com");
+ text.push_back("");
+ text.push_back("");
+ text.push_back("- Graphics -");
+ text.push_back("");
+ text.push_back("Andrew Mustun");
+ text.push_back("andrew at mustun.com");
+ text.push_back("Colin Pitrat");
+ text.push_back("colin.pitrat at gmail.com");
+ text.push_back("");
+ text.push_back("");
+ text.push_back("- Additional Tracks -");
+ text.push_back("");
+ text.push_back("Volker Schatz (Downtown)");
+ text.push_back("Oliver Luethje (Zigzag, Snake, Rally)");
+ text.push_back("");
+ text.push_back("");
+ text.push_back("- Beta Testing / Feedback -");
+ text.push_back("");
+ text.push_back("Martin Mustun, Michael Mustun,");
+ text.push_back("Chris Bruengger, Markus Krieter");
+ text.push_back("Armijn Hemel, Guus Sliepen, Alfred de Wijn");
+ text.push_back("Kenneth Gangstoe, Martin Starch Soerensen");
+ text.push_back("");
+ text.push_back("");
+ text.push_back("- Graphics Library ClanLib -");
+ text.push_back("");
+ text.push_back("ClanSoft");
+ text.push_back("http://www.clanlib.org");
+ text.push_back("");
+ text.push_back("---");
+ text.push_back("");
+ text.push_back("Many thanks to all these people and everyone");
+ text.push_back("else who contributed something to Trophy!");
+ text.push_back("");
+ text.push_back("");
}
+void CACredits::setText(const std::vector<std::string>& newText)
+{
+ text=newText;
+}
/** Destructor.
@@ -64,7 +80,7 @@ CACredits::buildScreen()
{
CADialog::buildScreen();
- int textHeight = 26 * text.count();
+ int textHeight = 26 * text.size();
// Scrolling text:
//
@@ -75,9 +91,9 @@ CACredits::buildScreen()
CL_Display::set_cliprect( crArea );
//CL_Display::fill_rect( left,top, right,bottom, 0.0,0.0,0.0, 0.2 );
- for( int l=0; l<text.count(); ++l )
+ for( unsigned int l=0; l<text.size(); ++l )
{
- const char* item = text.getItem( l );
+ const std::string item = text[l];
CA_RES->font_normal_14_white->set_alignment(origin_top_center, 0, 0);
CA_RES->font_normal_14_white->draw ( (left+32+right-32)/2, (int)(top+32+26-scrollPos+l*26), item );
}
diff --git a/src/cacredits.h b/src/cacredits.h
index 505dcbc..ae5e6f5 100644
--- a/src/cacredits.h
+++ b/src/cacredits.h
@@ -4,7 +4,8 @@
#include <ClanLib/core.h>
#include <ClanLib/display.h>
#include "cadialog.h"
-#include "castringlist.h"
+#include <vector>
+#include <string>
/** Credits screen.
@author Andrew Mustun
@@ -17,13 +18,15 @@ public:
virtual void buildScreen();
virtual void on_key_released( const CL_InputEvent &key );
+protected:
+ void setText(const std::vector<std::string>& newText);
+
private:
//! Position of scrolling text
-
-
float scrollPos;
//! The scrolling text
- CAStringList text;
+ std::vector<std::string> text;
+
};
#endif
diff --git a/src/cadialog.cpp b/src/cadialog.cpp
index 2cb0ea4..b8ccab6 100644
--- a/src/cadialog.cpp
+++ b/src/cadialog.cpp
@@ -1,7 +1,7 @@
#include "cadialog.h"
#include "catrophy.h"
#include "caresources.h"
-#include "camath.h"
+#include "utils/trophymath.h"
/** Constructor.
@@ -10,7 +10,7 @@
\param screen pointer to screen shown in the background if this dialog is modal.
zero if this dialog is not modal (default).
*/
-CADialog::CADialog( bool modal, CAScreen* screen )
+CADialog::CADialog( const bool modal, CAScreen* screen )
: CAScreen() {
width = height = 0;
left = top = right = bottom = 0;
@@ -82,26 +82,7 @@ CADialog::buildScreen() {
//
if( !modal ) CA_RES->menu_bg->draw( CL_Rect(0,0, CA_APP->width,CA_APP->height) );
- int ew = CA_RES->gui_edge2->get_width();
- int eh = CA_RES->gui_edge2->get_height();
- int bw = CA_RES->gui_border2->get_width();
- int bh = CA_RES->gui_border1->get_height();
-
- CL_Display::fill_rect( CL_Rect(left+bw, top+bh, right-bw, bottom-bh), CL_Color(0, 0, 0, 64) );
-
- // Edges:
- //
- CA_RES->gui_edge1->draw( left, top );
- CA_RES->gui_edge2->draw( right-ew, top );
- CA_RES->gui_edge3->draw( left, bottom-eh );
- CA_RES->gui_edge4->draw( right-ew, bottom-eh );
-
- // Borders:
- //
- CA_RES->gui_border1->draw( CL_Rect(left+ew, top, left+ew+width-2*ew, top+bh) );
- CA_RES->gui_border2->draw( CL_Rect(right-bw, top+eh, right-bw+bw, top+eh+height-2*eh) );
- CA_RES->gui_border3->draw( CL_Rect(left+ew, bottom-bh, left+ew+width-2*ew, bottom-bh+bh) );
- CA_RES->gui_border4->draw( CL_Rect(left, top+eh, left+bw, top+eh+height-2*eh) );
+ m_guiBox.display();
}
@@ -117,6 +98,8 @@ CADialog::resize( int w, int h ) {
top = (CA_APP->height - CA_APP->headerHeight - CA_HELPHEIGHT - height) / 2
+ CA_APP->headerHeight;
bottom = top + height;
+
+ m_guiBox.setPosition(left, top, right, bottom);
}
diff --git a/src/cadialog.h b/src/cadialog.h
index 13ce769..5f8c8f3 100644
--- a/src/cadialog.h
+++ b/src/cadialog.h
@@ -5,13 +5,15 @@
#include <ClanLib/signals.h>
#include <ClanLib/display.h>
#include "cascreen.h"
+#include "guibox.h"
/** Base class for dialogs.
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
class CADialog : public CAScreen {
public:
- CADialog( bool modal=false, CAScreen* screen=0 );
+ CADialog( const bool modal=false, CAScreen* screen=0 );
~CADialog();
virtual int run();
@@ -43,6 +45,10 @@ protected:
//! Pointer to screen (if dialog is modal) or NULL if it's not modal.
CAScreen* screen;
+protected:
+ //! The white gui box
+ GUIBox m_guiBox;
+
public:
CL_Slot slot;
};
diff --git a/src/caescapedialog.cpp b/src/caescapedialog.cpp
new file mode 100644
index 0000000..f103d3c
--- /dev/null
+++ b/src/caescapedialog.cpp
@@ -0,0 +1,38 @@
+#include "caescapedialog.h"
+
+CAEscapeDialog::CAEscapeDialog( const std::string& title,
+ const std::string& text,
+ const InfoType type,
+ bool modal,
+ CAScreen* screen )
+ :CAInfoDialog(title, text, type, modal, screen),
+mustQuit(false),
+firstEscape(false)
+{}
+
+void CAEscapeDialog::on_key_released (const CL_InputEvent &key)
+{
+ switch( key.id ) {
+ case CL_KEY_Y:
+ mustQuit = true;
+ done = true;
+ break;
+ case CL_KEY_ESCAPE:
+ if (firstEscape)
+ done = true;
+ firstEscape = true;
+ mustQuit = false;
+ break;
+ case CL_KEY_ENTER:
+ mustQuit = false;
+ done = true;
+ break;
+ default:
+ break;
+ }
+}
+
+bool CAEscapeDialog::isMustQuit()
+{
+ return mustQuit;
+}
\ No newline at end of file
diff --git a/src/caescapedialog.h b/src/caescapedialog.h
new file mode 100644
index 0000000..dbb02ed
--- /dev/null
+++ b/src/caescapedialog.h
@@ -0,0 +1,23 @@
+#ifndef CAESCAPEDIALOG_H
+#define CAESCAPEDIALOG_H
+
+#include "cainfodialog.h"
+
+class CAEscapeDialog : public CAInfoDialog {
+public:
+ CAEscapeDialog( const std::string& title,
+ const std::string& text,
+ const InfoType type=Info,
+ bool modal=false,
+ CAScreen* screen=0 );
+
+ void on_key_released (const CL_InputEvent &key);
+
+bool isMustQuit();
+private:
+ bool mustQuit;
+ bool firstEscape;
+
+};
+
+#endif
diff --git a/src/cagoody.cpp b/src/cagoody.cpp
index bde9b21..c4a543c 100644
--- a/src/cagoody.cpp
+++ b/src/cagoody.cpp
@@ -27,7 +27,7 @@ CAGoody::reset() {
void
CAGoody::display( int offsetX, int offsetY ) {
if( active ) {
- goodyType->surface->draw( x-8 + offsetX, y-8 + offsetY );
+ goodyType->draw( x + offsetX, y + offsetY );
}
}
@@ -49,7 +49,7 @@ CAGoody::advance() {
if( active ) {
if( birthday==0 ) {
birthday = CL_System::get_time();
- } else if( birthday + goodyType->life < CL_System::get_time() ) {
+ } else if( birthday + goodyType->getLife() < CL_System::get_time() ) {
reset();
}
}
diff --git a/src/cagoody.h b/src/cagoody.h
index 97a7d98..293eab2 100644
--- a/src/cagoody.h
+++ b/src/cagoody.h
@@ -6,6 +6,7 @@
/** A goody (life, turbo, ...)
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
class CAGoody {
public:
@@ -47,7 +48,6 @@ public:
private:
//! Goody type
-
CAGoodyType* goodyType;
//! Is the goody currently active?
bool active;
diff --git a/src/cagoodytype.cpp b/src/cagoodytype.cpp
new file mode 100644
index 0000000..7d28155
--- /dev/null
+++ b/src/cagoodytype.cpp
@@ -0,0 +1,76 @@
+#include "cagoodytype.h"
+#include "casoundeffect.h"
+#include "player.h"
+
+CAGoodyType::CAGoodyType (CL_Surface* surface, int life, CASoundEffect* soundEffect):
+ m_surface(surface),
+ m_life(life),
+ m_soundEffect(soundEffect)
+{}
+
+/** Play the sound associated with the goody */
+void CAGoodyType::playSound() const
+{
+ m_soundEffect->play();
+}
+
+/** Play the sound associated with the goody */
+void CAGoodyType::draw(int x, int y) const
+{
+ m_surface->draw( x-8, y-8 );
+}
+
+void CAGoodyType::catchGoodie(Player* pl)
+{
+ if( !pl->isDeath() && !pl->hasFinished() && !pl->isLapped())
+ {
+ action(pl);
+ if( pl->getId()==0) playSound(); // TODO : Only sound of first player is played
+ }
+}
+
+
+
+
+template<TypeGoodie N>
+CAGoodyTypeDerived<N>::CAGoodyTypeDerived (CL_Surface* surface, int life, CASoundEffect* soundEffect)
+: CAGoodyType(surface, life, soundEffect)
+{}
+
+template<>
+void CAGoodyTypeDerived<Turbo>::action(Player* pl)
+{
+ pl->setTurbo (pl->getTurbo() + 1000);
+}
+
+template<>
+void CAGoodyTypeDerived<Life>::action(Player* pl)
+{
+ pl->setLife( pl->getLife()+25.0 );
+}
+
+template<>
+void CAGoodyTypeDerived<Bullets>::action(Player* pl)
+{
+ pl->setBullets( pl->getBullets()+100 );
+}
+
+template<>
+void CAGoodyTypeDerived<FogBombs>::action(Player* pl)
+{
+ pl->setFogBombs( pl->getFogBombs()+1 );
+}
+
+template<>
+void CAGoodyTypeDerived<Money>::action(Player* pl)
+{
+ pl->addRaceMoney(100);
+}
+
+template class CAGoodyTypeDerived<Turbo>;
+template class CAGoodyTypeDerived<Life>;
+template class CAGoodyTypeDerived<Bullets>;
+template class CAGoodyTypeDerived<FogBombs>;
+template class CAGoodyTypeDerived<Money>;
+
+
diff --git a/src/cagoodytype.h b/src/cagoodytype.h
index 4c57acf..f1607ae 100644
--- a/src/cagoodytype.h
+++ b/src/cagoodytype.h
@@ -4,18 +4,51 @@
#include <ClanLib/core.h>
#include <ClanLib/display.h>
+class Player;
+class CASoundEffect;
+
/** Structure for goody types.
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
-struct CAGoodyType {
- //! Goody name
- std::string name;
+class CAGoodyType
+{
+public:
+ CAGoodyType (CL_Surface* surface, int life, CASoundEffect* soundEffect);
+ void catchGoodie(Player* pl);
+ virtual void action(Player* pl) = 0;
+ void playSound() const;
+ void draw(int x, int y) const;
+ int getLife() const { return m_life;}
+
+private:
//! Pixmaps for this goody
- CL_Surface* surface;
+ CL_Surface* m_surface;
//! Life time in milliseconds
- int life;
+ int m_life;
+ //! The sound effect played when the layer catch the goody
+ CASoundEffect* m_soundEffect;
+};
+
+enum TypeGoodie
+{
+ Turbo = 1,
+ Life,
+ Bullets,
+ FogBombs,
+ Money
};
+
+template<TypeGoodie N>
+class CAGoodyTypeDerived : public CAGoodyType
+{
+ public:
+ CAGoodyTypeDerived(CL_Surface* surface, int life, CASoundEffect* soundEffect);
+ void action(Player* pl);
+};
+
+
#endif
// EOF
diff --git a/src/caimagehueselector.cpp b/src/caimagehueselector.cpp
index 8b60cda..fc20f91 100644
--- a/src/caimagehueselector.cpp
+++ b/src/caimagehueselector.cpp
@@ -27,8 +27,8 @@ CAImageHueSelector::CAImageHueSelector( Direction direction )
\param type Selector type (Image, Selector, HueSelector)
\param direction Vertical selector? (Use Up/Down arrows to control)
*/
-CAImageHueSelector::CAImageHueSelector( const char* upperText,
- const char* lowerText,
+CAImageHueSelector::CAImageHueSelector( const std::string upperText,
+ const std::string lowerText,
CL_Surface* image,
bool autoResize,
Direction direction )
@@ -106,7 +106,15 @@ CAImageHueSelector::display( bool active )
displayTextButtons( active );
- if( hueImage ) hueImage->draw (left + (width-hueImage->get_width())/2, top+barHeight);
+ //if( hueImage ) hueImage->draw (left + (width-hueImage->get_width())/2, top+barHeight);
+
+ if (hueImage)
+ {
+ // center the image
+ const int leftPos = left + (width - hueImage->get_width()) /2;
+ const int topPos = top + (height - hueImage->get_height())/2;
+ hueImage->draw(leftPos, topPos);
+ }
displayArrows( active );
diff --git a/src/caimagehueselector.h b/src/caimagehueselector.h
index d692c7c..f1532e5 100644
--- a/src/caimagehueselector.h
+++ b/src/caimagehueselector.h
@@ -13,8 +13,8 @@
class CAImageHueSelector : public CAImageView {
public:
CAImageHueSelector( Direction vertical=Horizontal );
- CAImageHueSelector( const char* upperText,
- const char* lowerText,
+ CAImageHueSelector( const std::string upperText,
+ const std::string lowerText,
CL_Surface* image,
bool autoResize=true,
Direction vertical=Horizontal );
diff --git a/src/caimagemanipulation.cpp b/src/caimagemanipulation.cpp
index 5e26e53..380a3d1 100644
--- a/src/caimagemanipulation.cpp
+++ b/src/caimagemanipulation.cpp
@@ -248,7 +248,7 @@ CAImageManipulation::changeHSV( CL_Surface* surface,
// Change hue:
//
- int r, g, b, a;
+ int r, g, b, a(0);
int h, s, v;
for(int i=0; i<size; i+=bpp )
diff --git a/src/caimageselector.cpp b/src/caimageselector.cpp
index 9e854b1..8211570 100644
--- a/src/caimageselector.cpp
+++ b/src/caimageselector.cpp
@@ -53,8 +53,8 @@ CAImageSelector::setImageSize( int w, int h ) {
\param autoResize Automatic fit size of the widget to image size
*/
void
-CAImageSelector::addImage( const char* upperText,
- const char* lowerText,
+CAImageSelector::addImage( const std::string upperText,
+ const std::string lowerText,
CL_Surface* image,
bool autoResize ) {
this->image[numImages].upperText = upperText;
@@ -64,6 +64,8 @@ CAImageSelector::addImage( const char* upperText,
if( currentImage<0.0 ) {
currentImage = numImages;
newImage = numImages;
+ CAImageView::image.upperText = this->image[newImage].upperText;
+ CAImageView::image.lowerText = this->image[newImage].lowerText;
}
if( numImages<CA_IV_MAXIMAGES ) numImages++;
diff --git a/src/caimageselector.h b/src/caimageselector.h
index f69d72f..f6bfd63 100644
--- a/src/caimageselector.h
+++ b/src/caimageselector.h
@@ -19,13 +19,15 @@ public:
void setImageSize( int w, int h );
- void addImage( const char* upperText,
- const char* lowerText,
+ void addImage( const std::string upperText,
+ const std::string lowerText,
CL_Surface* image,
bool autoResize=true );
void setCurrentImage( int index ) {
currentImage = newImage = index;
+ CAImageView::image.upperText = image[newImage].upperText;
+ CAImageView::image.lowerText = image[newImage].lowerText;
}
int getSelectedImage() {
return newImage;
@@ -36,7 +38,6 @@ public:
private:
//! Pointer to surfaces which can be selected
-
CAImageData image[CA_IV_MAXIMAGES];
//! Number of surfaces
int numImages;
diff --git a/src/caimageview.cpp b/src/caimageview.cpp
index 97cf299..81002fb 100644
--- a/src/caimageview.cpp
+++ b/src/caimageview.cpp
@@ -21,11 +21,13 @@ CAImageView::CAImageView()
\param autoresize Automatically resize the image preview
to fit the image.
*/
-CAImageView::CAImageView( const char* upperText,
- const char* lowerText,
+CAImageView::CAImageView( const std::string& upperText,
+ const std::string& lowerText,
CL_Surface* image,
bool autoResize )
- : CAWidget( CAWidget::Left ) {
+ : CAWidget( CAWidget::Left ),
+ m_autoresize(autoResize)
+{
if( CA_APP->debug ) std::cout << "CAImageView() begin 2" << std::endl;
barHeight = CA_RES->font_normal_14_white->get_height() + 6;
@@ -33,7 +35,8 @@ CAImageView::CAImageView( const char* upperText,
this->image.lowerText = lowerText;
this->image.image = image;
- if( autoResize ) {
+ if( m_autoresize )
+ {
setImageSize( image->get_width(), image->get_height() );
}
@@ -57,6 +60,16 @@ CAImageView::setImageSize( int w, int h ) {
bottom = top + height;
}
+void
+CAImageView::setImage( CL_Surface* image) {
+
+ this->image.image = image;
+ if( m_autoresize )
+ {
+ setImageSize( image->get_width(), image->get_height() );
+ }
+}
+
/** Displays the image view with its current image/ texts.
*/
void
@@ -67,7 +80,15 @@ CAImageView::display( bool active ) {
CL_Display::fill_rect( CL_Rect(left, top, right, bottom), CL_Color(0, 0, 0, 64) );
- if( image.image ) image.image->draw( left, top+barHeight );
+// if( image.image ) image.image->draw( left, top+barHeight );
+
+ if (image.image)
+ {
+ // center the image
+ const int leftPos = left + (width - image.image->get_width()) /2;
+ const int topPos = top + (height - image.image->get_height())/2;
+ image.image->draw(leftPos, topPos);
+ }
displayTextButtons( active );
diff --git a/src/caimageview.h b/src/caimageview.h
index 225687c..0dbba68 100644
--- a/src/caimageview.h
+++ b/src/caimageview.h
@@ -28,19 +28,24 @@ struct CAImageData {
/** An Image with text above and below it.
This class is also used as basis class for image selectors.
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
class CAImageView : public CAWidget {
public:
enum Direction { Vertical, Horizontal };
CAImageView();
- CAImageView( const char* upperText,
- const char* lowerText,
+ CAImageView( const std::string& upperText,
+ const std::string& lowerText,
CL_Surface* image,
bool autoResize=true );
~CAImageView();
virtual void setImageSize( int w, int h );
+ virtual void setImage(CL_Surface* image);
+ virtual void setUpperText(const std::string& upperText) {image.upperText = upperText;}
+ virtual void setLowerText(const std::string& lowerText) {image.lowerText = lowerText;}
+ virtual void setAutoresize(const bool autoresize) {m_autoresize = autoresize;}
virtual void display( bool active=true );
virtual void displayArrows( bool active=true );
@@ -50,10 +55,12 @@ public:
protected:
//! Image data (surface, texts)
CAImageData image;
- //! 'Vertiacl' or 'Horizontal' selector (used for child classes)
+ //! 'Vertical' or 'Horizontal' selector (used for child classes)
Direction direction;
//! Height of top/ bottom bar
int barHeight;
+ //! must autoresize
+ bool m_autoresize;
};
#endif
diff --git a/src/cainfodialog.cpp b/src/cainfodialog.cpp
index a47f72e..dab506e 100644
--- a/src/cainfodialog.cpp
+++ b/src/cainfodialog.cpp
@@ -12,9 +12,9 @@
\param screen pointer to screen shown in the background if this dialog is modal.
zero if this dialog is not modal (default).
*/
-CAInfoDialog::CAInfoDialog( const char* title,
- const char* text,
- InfoType type,
+CAInfoDialog::CAInfoDialog( const std::string& title,
+ const std::string& text,
+ const InfoType type,
bool modal,
CAScreen* screen )
: CADialog( modal, screen ) {
@@ -22,7 +22,12 @@ CAInfoDialog::CAInfoDialog( const char* title,
this->title = title;
this->type = type;
- textList.setList( text );
+
+ std::istringstream iss ( text );
+ std::string temp;
+ while (std::getline(iss,temp, '~'))
+ textList.push_back(temp);
+
switch( type ) {
case Info:
@@ -40,21 +45,12 @@ CAInfoDialog::CAInfoDialog( const char* title,
break;
}
- resize( 400, textList.count()*16 + 96 );
+ resize( 400, textList.size()*16 + 96 );
if( CA_APP->debug ) std::cout << "CAInfoDialog() end" << std::endl;
}
-
-/** Destructor.
-*/
-CAInfoDialog::~CAInfoDialog() {
- //delete icon;
-}
-
-
-
/** Builds the info dialog screen.
*/
void
@@ -66,9 +62,9 @@ CAInfoDialog::buildScreen() {
CA_RES->font_normal_14_white->set_alignment(origin_top_left, 0, 0);
CA_RES->font_normal_14_white->draw (left+x, top+32, title);
- for( int i=0; i<textList.count(); ++i ) {
+ for( unsigned int i=0; i<textList.size(); ++i ) {
CA_RES->font_normal_11_white->set_alignment(origin_top_left, 0, 0);
- CA_RES->font_normal_11_white->draw (left+x, top+64+i*16, textList.getItem(i));
+ CA_RES->font_normal_11_white->draw (left+x, top+64+i*16, textList[i]);
}
if( icon ) {
diff --git a/src/cainfodialog.h b/src/cainfodialog.h
index cc96a19..3f7b975 100644
--- a/src/cainfodialog.h
+++ b/src/cainfodialog.h
@@ -3,7 +3,8 @@
#include <ClanLib/core.h>
#include "cadialog.h"
-#include "castringlist.h"
+#include <vector>
+#include <string>
/** A simple info dialog. Shows a title and a text.
@author Andrew Mustun
@@ -12,23 +13,23 @@ class CAInfoDialog : public CADialog {
public:
enum InfoType { Info, Warning };
- CAInfoDialog( const char* title,
- const char* text,
- InfoType type=Info,
+ CAInfoDialog( const std::string& title,
+ const std::string& text,
+ const InfoType type=Info,
bool modal=false,
CAScreen* screen=0 );
- ~CAInfoDialog();
virtual void buildScreen();
virtual void on_key_released (const CL_InputEvent &key);
private:
//! Text list which contains the dialog text - one item is one line.
- CAStringList textList;
+ std::vector<std::string> textList;
//! Pointer to icon. Created and destroyed in this class.
CL_Surface* icon;
//! Type (Info, Warning).
InfoType type;
};
+
#endif
diff --git a/src/calabel.cpp b/src/calabel.cpp
index 8c38c80..7650c96 100644
--- a/src/calabel.cpp
+++ b/src/calabel.cpp
@@ -5,7 +5,7 @@
\param align Alignment (Left, Right, Center)
\param font Font
*/
-CALabel::CALabel( char* text, Alignment alignment, CL_Font* font )
+CALabel::CALabel( std::string text, Alignment alignment, CL_Font* font )
: CAWidget( alignment ) {
this->text = text;
this->font = font;
diff --git a/src/calabel.h b/src/calabel.h
index 9e76b6a..4fd56c2 100644
--- a/src/calabel.h
+++ b/src/calabel.h
@@ -8,12 +8,12 @@
*/
class CALabel : public CAWidget {
public:
- CALabel( char* text, Alignment alignment, CL_Font* font );
+ CALabel( std::string text, Alignment alignment, CL_Font* font );
~CALabel();
virtual void display( bool active=true );
//! Sets a nwe text for this label.
- void setText( const char* text ) {
+ void setText( const std::string text ) {
this->text = text;
}
diff --git a/src/calineedit.cpp b/src/calineedit.cpp
index a7e3e92..4118062 100644
--- a/src/calineedit.cpp
+++ b/src/calineedit.cpp
@@ -1,5 +1,3 @@
-#include <stdio.h>
-
#include "calineedit.h"
#include "caresources.h"
#include "catrophy.h"
@@ -12,7 +10,7 @@
\param alignment Alignment of text
\param font Font to use for the text
*/
-CALineEdit::CALineEdit( const char* text,
+CALineEdit::CALineEdit( const std::string text,
unsigned int letters,
Alignment alignment,
CL_Font* font )
@@ -24,13 +22,11 @@ CALineEdit::CALineEdit( const char* text,
this->font = font;
cursor = this->text.length();
- char *wString=new char[letters];
- for( unsigned int i=0; i<letters-1; ++i ) wString[i] = 'W';
- wString[letters] = '\0';
+ std::string wString;
+ for( unsigned int i=0; i<letters-1; ++i ) wString.push_back('W');
resize( font->get_width( wString ), font->get_height() );
if( CA_APP->debug ) std::cout << "CALineEdit() end" << std::endl;
- delete[] wString;
}
diff --git a/src/calineedit.h b/src/calineedit.h
index 1267133..7f32a68 100644
--- a/src/calineedit.h
+++ b/src/calineedit.h
@@ -10,14 +10,14 @@
*/
class CALineEdit : public CAWidget {
public:
- CALineEdit( const char* text,
+ CALineEdit( const std::string text,
unsigned int letters,
Alignment alignment,
CL_Font* font );
~CALineEdit();
- const char* getText() {
- return text.c_str();
+ const std::string getText() {
+ return text;
}
virtual void display( bool active=true );
diff --git a/src/camenu.cpp b/src/camenu.cpp
index a98fa77..49ec85f 100644
--- a/src/camenu.cpp
+++ b/src/camenu.cpp
@@ -8,11 +8,10 @@
/** Constructor.
*/
-CAMenu::CAMenu( const char* title )
+CAMenu::CAMenu( const std::string title )
: CAScreen() {
this->title = title;
- numItems = 0;
cursor = 0;
done = false;
cancel = false;
@@ -21,53 +20,46 @@ CAMenu::CAMenu( const char* title )
calcMenuDimensions();
}
-
-
/** Destructor.
*/
CAMenu::~CAMenu() {}
-
-
/** Adds a simple menu label to the menu.
*/
void
-CAMenu::addMenuLabel( const char* label ) {
- item[numItems] = new CAMenuLabel( this, numItems, label );
- if( numItems<CA_MAXMENUITEMS ) numItems++;
+CAMenu::addMenuLabel( const std::string& label )
+{
+ if( item.size()<CA_MAXMENUITEMS )
+ item.push_back( new CAMenuLabel( this, item.size(), label ));
calcMenuDimensions();
}
-
-
/** Adds a menu input to the menu.
Menu inputs let the user input any value (string).
\param label The menu item label.
\param defaultValue Value shown at startup of the menu.
*/
void
-CAMenu::addMenuInput( const char* label, char* result, int maxLength ) {
- item[numItems] = new CAMenuInput( this, numItems, label, result, maxLength );
- if( numItems<CA_MAXMENUITEMS ) numItems++;
+CAMenu::addMenuInput( const std::string& label, std::string result, int maxLength )
+{
+ if( item.size()<CA_MAXMENUITEMS )
+ item.push_back(new CAMenuInput( this, item.size(), label, result, maxLength ));
calcMenuDimensions();
}
-
-
/** Adds a menu input to the menu.
Menu inputs let the user input any value (int).
\param label The menu item label.
\param defaultValue Value shown at startup of the menu.
*/
void
-CAMenu::addMenuInput( const char* label, int* result, int maxLength ) {
- item[numItems] = new CAMenuInput( this, numItems, label, result, maxLength );
- if( numItems<CA_MAXMENUITEMS ) numItems++;
+CAMenu::addMenuInput( const std::string& label, int* result, int maxLength )
+{
+ if( item.size()<CA_MAXMENUITEMS )
+ item.push_back(new CAMenuInput( this, item.size(), label, result, maxLength ));
calcMenuDimensions();
}
-
-
/** Adds a menu select to the menu.
Menu selects let the user choose a value from a given list (string).
\param label The menu item label.
@@ -75,35 +67,18 @@ CAMenu::addMenuInput( const char* label, int* result, int maxLength ) {
\param result Pointer to an int value which stores the selection result.
(0=first value selected)
*/
-void
-CAMenu::addMenuSelect( const char* label, const char* valueList, int* result ) {
- item[numItems] = new CAMenuSelect( this, numItems, label, valueList, result );
- if( numItems<CA_MAXMENUITEMS ) numItems++;
- calcMenuDimensions();
-}
-
-
-
-/** Adds a menu select to the menu.
- Menu selects let the user choose a value from a given list (string).
- \param label The menu item label.
- \param valueList Possible values to choose from.
- \param result Pointer to a bool value which stores the selection result.
- (false=first value selected)
-*/
-void
-CAMenu::addMenuSelect( const char* label, const char* valueList, bool* result ) {
- item[numItems] = new CAMenuSelect( this, numItems, label, valueList, result );
- if( numItems<CA_MAXMENUITEMS ) numItems++;
+template<typename T>
+void CAMenu::addMenuSelect( const std::string& label, const std::string valueList, T* result )
+{
+ if( item.size()<CA_MAXMENUITEMS )
+ item.push_back(new CAMenuSelect<T>( this, item.size(), label, valueList, result ));
calcMenuDimensions();
}
-
/** Runs the menu.
*/
-int
-CAMenu::run() {
+int CAMenu::run() {
//slot = CL_Input::sig_button_press.connect(this, &CAMenu::on_button_press);
// TODO : Connect the right signal
slot = CL_Keyboard::sig_key_up().connect(this, &CAMenu::on_key_pressed);
@@ -141,8 +116,6 @@ CAMenu::run() {
return (cancel ? -1 : cursor);
}
-
-
/** Builds the menu screen.
*/
void
@@ -160,7 +133,7 @@ CAMenu::buildScreen() {
CA_RES->font_normal_14_white->set_alignment(origin_top_center, 0, 0);
CA_RES->font_normal_14_white->draw ((left + right)/2, top + CA_MENUSPACE/2 -10, title);
- for( int n=0; n<numItems; ++n ) {
+ for( int n=0; n<int(item.size()); ++n ) {
if( item[n]->rtti()!=CA_MI_VIRTUAL ) {
item[n]->display( n==cursor );
}
@@ -177,7 +150,7 @@ CAMenu::calcMenuDimensions() {
itemHeight = CA_RES->font_normal_22_white->get_height() + 6;
//headerHeight = CA_RES->menu_itemon->get_height();
headerHeight = 22;
- height = itemHeight * numItems + headerHeight;
+ height = itemHeight * item.size() + headerHeight;
width = CA_MENUWIDTH;
left = (CA_APP->width - width)/2;
@@ -186,8 +159,6 @@ CAMenu::calcMenuDimensions() {
bottom = CA_APP->height - top;
}
-
-
/** Called on key release.
*/
void
@@ -217,7 +188,7 @@ CAMenu::on_key_pressed (const CL_InputEvent &key)
//
case CL_KEY_DOWN:
case CL_KEY_D:
- if( cursor<numItems-1 ) {
+ if( cursor<int(item.size()-1) ) {
cursor++;
if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
}
@@ -242,7 +213,7 @@ CAMenu::on_key_pressed (const CL_InputEvent &key)
item[cursor]->handleKey( key );
}
-
-
-
+template void CAMenu::addMenuSelect<int>( const std::string& label, const std::string valueList, int* result );
+template void CAMenu::addMenuSelect<bool>( const std::string& label, const std::string valueList, bool* result );
+template void CAMenu::addMenuSelect<std::string>( const std::string& label, const std::string valueList, std::string* result );
// EOF
diff --git a/src/camenu.h b/src/camenu.h
index a3bd60d..6592c38 100644
--- a/src/camenu.h
+++ b/src/camenu.h
@@ -1,10 +1,12 @@
#ifndef CAMENU_H
#define CAMENU_H
+#include <vector>
+
#include <ClanLib/core.h>
#include <ClanLib/display.h>
-#include "camath.h"
+#include "utils/trophymath.h"
#include "camenuitem.h"
#include "cascreen.h"
@@ -13,17 +15,17 @@
*/
class CAMenu : public CAScreen {
public:
- CAMenu( const char* title );
+ CAMenu( const std::string title );
~CAMenu();
virtual int run();
virtual void buildScreen();
- void addMenuLabel( const char* label );
- void addMenuInput( const char* label, char* result, int maxLength );
- void addMenuInput( const char* label, int* result, int maxLength );
- void addMenuSelect( const char* label, const char* valueList, int* result );
- void addMenuSelect( const char* label, const char* valueList, bool* result );
+ void addMenuLabel( const std::string& label );
+ void addMenuInput( const std::string& label, std::string result, int maxLength );
+ void addMenuInput( const std::string& label, int* result, int maxLength );
+ template<typename T>
+ void addMenuSelect( const std::string& label, const std::string valueList, T* result );
void calcMenuDimensions();
@@ -76,7 +78,7 @@ public:
}
//! Sets the cursor position (0 is the top entry).
void setCursor( int pos ) {
- if( cursor>=0 && cursor<numItems ) cursor = pos;
+ if( cursor>=0 && cursor<int(item.size()) ) cursor = pos;
}
//! Returns the current cursor position (o is the top position).
int getCursor() {
@@ -108,12 +110,11 @@ protected:
//! Header height
int headerHeight;
+ // TODO: should we delete CAMenuItem?
//! The menu items
- CAMenuItem* item[CA_MAXMENUITEMS];
+ std::vector<CAMenuItem*> item;
//! Menu Title
std::string title;
- //! Number of used menu items
- int numItems;
//! Cursor position (0...numLabels)
int cursor;
diff --git a/src/camenuinput.cpp b/src/camenuinput.cpp
index 4836d77..2cf2fb2 100644
--- a/src/camenuinput.cpp
+++ b/src/camenuinput.cpp
@@ -1,5 +1,3 @@
-#include <stdio.h>
-
#include "camenuinput.h"
#include "camenu.h"
#include "caresources.h"
@@ -7,16 +5,17 @@
/** Constructor which takes a string as result.
*/
CAMenuInput::CAMenuInput( CAMenu* menu,
- int pos, const char* label,
- char* result, int maxLength )
+ int pos, const std::string label,
+ std::string result, int maxLength )
: CAMenuLabel( menu, pos, label ) {
this->maxLength = maxLength;
resultStr = result;
+ resultInt = 0;
+ isInt = false;
edit = new CALineEdit( resultStr,
maxLength, CAWidget::Right,
CA_RES->font_normal_22_gray );
- resultInt = 0;
}
@@ -24,18 +23,19 @@ CAMenuInput::CAMenuInput( CAMenu* menu,
/** Constructor which takes an int as result.
*/
CAMenuInput::CAMenuInput( CAMenu* menu,
- int pos, const char* label,
+ int pos, const std::string label,
int* result, int maxLength )
: CAMenuLabel( menu, pos, label ) {
this->maxLength = maxLength;
resultInt = result;
+ resultStr = "";
+ isInt = false;
char intStr[16];
sprintf( intStr, "%d", *resultInt );
edit = new CALineEdit( intStr,
maxLength, CAWidget::Right,
CA_RES->font_normal_22_gray );
- resultStr = 0;
}
@@ -66,8 +66,8 @@ void
CAMenuInput::handleKey (const CL_InputEvent &key)
{
edit->handleKey( key );
- if( resultStr ) strncpy( resultStr, edit->getText(), maxLength );
- if( resultInt ) *resultInt = atoi( edit->getText() );
+ if( isInt ) *resultInt = atoi( edit->getText().c_str() );
+ else resultStr = edit->getText();
menu->setChanged();
}
diff --git a/src/camenuinput.h b/src/camenuinput.h
index f321f6d..49bc74d 100644
--- a/src/camenuinput.h
+++ b/src/camenuinput.h
@@ -9,8 +9,8 @@
*/
class CAMenuInput : public CAMenuLabel {
public:
- CAMenuInput( CAMenu* menu, int pos, const char* label, char* result, int maxLength );
- CAMenuInput( CAMenu* menu, int pos, const char* label, int* result, int maxLength );
+ CAMenuInput( CAMenu* menu, int pos, const std::string label, std::string result, int maxLength );
+ CAMenuInput( CAMenu* menu, int pos, const std::string label, int* result, int maxLength );
~CAMenuInput();
/** Returns rtti of this menu item.
@@ -28,11 +28,13 @@ private:
CALineEdit* edit;
//! The string typed by the user.
- char* resultStr;
+ std::string resultStr;
//! The int value typed by the user.
int* resultInt;
//! Max number of letters to input.
int maxLength;
+ //! Whether the result should be a int or a string
+ bool isInt;
};
#endif
diff --git a/src/camenuitem.cpp b/src/camenuitem.cpp
index 1a02f9d..f125bfe 100644
--- a/src/camenuitem.cpp
+++ b/src/camenuitem.cpp
@@ -3,7 +3,7 @@
/** Constructor.
*/
-CAMenuItem::CAMenuItem( CAMenu* menu, int pos, const char* label ) {
+CAMenuItem::CAMenuItem( CAMenu* menu, int pos, const std::string label ) {
this->label = label;
this->menu = menu;
this->pos = pos;
diff --git a/src/camenuitem.h b/src/camenuitem.h
index 13ee674..a87047c 100644
--- a/src/camenuitem.h
+++ b/src/camenuitem.h
@@ -16,7 +16,7 @@ class CAMenu;
*/
class CAMenuItem {
public:
- CAMenuItem( CAMenu* menu, int pos, const char* label );
+ CAMenuItem( CAMenu* menu, int pos, const std::string label );
virtual ~CAMenuItem();
/** Returns rtti of this menu item.
@@ -29,7 +29,7 @@ public:
virtual void display( bool highlight ) = 0;
virtual void handleKey( const CL_InputEvent &key ) = 0;
//! Sets a new label for this menu item.
- void setLabel( const char* l ) {
+ void setLabel( const std::string l ) {
label = l;
}
diff --git a/src/camenulabel.cpp b/src/camenulabel.cpp
index 85d3cba..0976dd4 100644
--- a/src/camenulabel.cpp
+++ b/src/camenulabel.cpp
@@ -4,7 +4,7 @@
/** Constructor.
*/
-CAMenuLabel::CAMenuLabel( CAMenu* menu, int pos, const char* label )
+CAMenuLabel::CAMenuLabel( CAMenu* menu, int pos, const std::string label )
: CAMenuItem( menu, pos, label ) {
font=0;
}
diff --git a/src/camenulabel.h b/src/camenulabel.h
index a68b2bb..2238d85 100644
--- a/src/camenulabel.h
+++ b/src/camenulabel.h
@@ -9,7 +9,7 @@
class CAMenuLabel : public CAMenuItem {
public:
- CAMenuLabel( CAMenu* menu, int pos, const char* label );
+ CAMenuLabel( CAMenu* menu, int pos, const std::string label );
~CAMenuLabel();
/** Returns rtti of this menu item.
diff --git a/src/camenuselect.cpp b/src/camenuselect.cpp
index e8c1737..2427a09 100644
--- a/src/camenuselect.cpp
+++ b/src/camenuselect.cpp
@@ -1,96 +1,99 @@
#include "camenu.h"
#include "camenuselect.h"
#include "caresources.h"
+#include <string>
-
-
-/** Constructor for selections of more than two items.
+ /** Constructor for selections of more than two items.
\param menu Pointer to menu
\param pos Position of the item in the menu (0=top position)
\param label Menu item label.
\param valueList List of possible values. Format: "value1~value2~value3~..."
\param result Pointer to store the index of the selected item (0=first item of list)
-*/
-CAMenuSelect::CAMenuSelect( CAMenu* menu,
- int pos,
- const char* label,
- const char* valueList,
- int* result )
- : CAMenuLabel( menu, pos, label ) {
- this->valueList = new CAStringList( valueList );
- selectedItem = (*result);
- intResult = result;
- boolResult = 0;
-}
-
-
-
-/** Constructor for selections of two items.
+ */
+ template<typename T>
+ CAMenuSelect<T>::CAMenuSelect( CAMenu* menu, int pos, const std::string& label, const std::string& nvalueList, T* result )
+ : CAMenuLabel( menu, pos, label ), tResult(result), selectedItem(*result)
+ {
+ std::istringstream iss ( nvalueList );
+ std::string temp;
+ while (std::getline(iss,temp, '~'))
+ valueList.push_back(temp);
+ }
+
+ /** Constructor for selections of more than two items. Specialization for string
\param menu Pointer to menu
\param pos Position of the item in the menu (0=top position)
\param label Menu item label.
- \param valueList List of possible values. Format: "value1~value2"
+ \param valueList List of possible values. Format: "value1~value2~value3~..."
\param result Pointer to store the index of the selected item (0=first item of list)
-*/
-CAMenuSelect::CAMenuSelect( CAMenu* menu,
- int pos,
- const char* label,
- const char* valueList,
- bool* result )
- : CAMenuLabel( menu, pos, label ) {
- this->valueList = new CAStringList( valueList );
- selectedItem = (int)(*result);
- boolResult = result;
- intResult = 0;
-}
-
-
-
-/** Destructor.
-*/
-CAMenuSelect::~CAMenuSelect() {
- delete valueList;
- valueList = 0;
-}
-
-
-
-/** Displays the item.
-*/
-void
-CAMenuSelect::display( bool highlight ) {
- CAMenuLabel::display( highlight );
-
- if( font ) {
- font->set_alignment(origin_top_right, 0, 0);
- font->draw (menu->getRight() - CA_MENUSPACE/2, top + CA_MENUSPACE/2, valueList->getItem(selectedItem));
+ */
+ template<>
+ CAMenuSelect<std::string>::CAMenuSelect( CAMenu* menu, int pos, const std::string& label, const std::string& nvalueList, std::string* result )
+ : CAMenuLabel( menu, pos, label ), tResult(result), selectedItem(0)
+ {
+ std::istringstream iss ( nvalueList );
+ std::string temp;
+ while (std::getline(iss,temp, '~'))
+ valueList.push_back(temp);
+ std::vector<std::string>::const_iterator it = valueList.begin();
+ while (it != valueList.end() && *it != *result)
+ {
+ selectedItem++;
+ it++;
+ }
}
-}
-
-
-/** Handles keys on this label.
-*/
-void
-CAMenuSelect::handleKey (const CL_InputEvent &key)
-{
- if( key.id==CL_KEY_ENTER ||
- key.id==CL_KEY_SPACE ||
- key.id==CL_KEY_RIGHT ) {
- selectedItem++;
- if( selectedItem>=valueList->count() ) selectedItem=0;
+ /** Displays the item.
+ */
+ template<typename T>
+ void CAMenuSelect<T>::display( bool highlight )
+ {
+ CAMenuLabel::display( highlight );
+
+ if( font ) {
+ font->set_alignment(origin_top_right, 0, 0);
+ font->draw (menu->getRight() - CA_MENUSPACE/2, top + CA_MENUSPACE/2, valueList[selectedItem]);
+ }
}
- if( key.id==CL_KEY_LEFT ) {
- selectedItem--;
- if( selectedItem<0 ) selectedItem=valueList->count()-1;
+ /** Handles keys on this label.
+ */
+ template<typename T>
+ void CAMenuSelect<T>::handleKey(const CL_InputEvent &key)
+ {
+ if( key.id==CL_KEY_ENTER ||
+ key.id==CL_KEY_SPACE ||
+ key.id==CL_KEY_RIGHT ) {
+ selectedItem++;
+ if( selectedItem>=int(valueList.size()) ) selectedItem=0;
+ }
+
+ if( key.id==CL_KEY_LEFT ) {
+ selectedItem--;
+ if( selectedItem<0 ) selectedItem=int(valueList.size())-1;
+ }
+
+ updateValue();
+ menu->setChanged();
+ }
+
+ /** Update Value to know the selected item
+ */
+ template<typename T>
+ void CAMenuSelect<T>::updateValue()
+ {
+ *tResult = T(selectedItem);
}
- if( intResult ) *intResult = selectedItem;
- if( boolResult ) *boolResult = (bool)(selectedItem);
- menu->setChanged();
-}
-
+ /** Update Value to know the string of the selected item (Specialization for string)
+ */
+ template<>
+ void CAMenuSelect<std::string>::updateValue()
+ {
+ *tResult = valueList[selectedItem];
+ }
+template class CAMenuSelect<int>;
+template class CAMenuSelect<bool>;
+template class CAMenuSelect<std::string>;
// EOF
-
diff --git a/src/camenuselect.h b/src/camenuselect.h
index ef58121..4dfaa64 100644
--- a/src/camenuselect.h
+++ b/src/camenuselect.h
@@ -2,28 +2,38 @@
#define CAMENUSELECT_H
#include "camenulabel.h"
-#include "castringlist.h"
+#include <vector>
+#include <string>
/** A menu item for selecting a value out of a given value list (strings).
That's kind of a combobox, isn't it?
@author Andrew Mustun
*/
-class CAMenuSelect : public CAMenuLabel {
+template<typename T>
+class CAMenuSelect : public CAMenuLabel
+{
public:
- CAMenuSelect( CAMenu* menu, int pos, const char* label, const char* valueList, int* result );
- CAMenuSelect( CAMenu* menu, int pos, const char* label, const char* valueList, bool* result );
- ~CAMenuSelect();
+
+
+ CAMenuSelect( CAMenu* menu, int pos, const std::string& label, const std::string& nvalueList, T* result );
+
/** Returns rtti of this menu item.
CA_MI_MENUSELECT for menu selects.
*/
- virtual int rtti() {
+ virtual int rtti()
+ {
return CA_MI_MENUSELECT;
}
+
virtual void display( bool highlight );
+
virtual void handleKey (const CL_InputEvent &key);
+
+
+
int getSelectedItem() {
return selectedItem;
}
@@ -32,16 +42,15 @@ public:
}
private:
+ void updateValue();
//! List of values to select.
+ std::vector<std::string> valueList;
+
+ //! Pointer to result given by constructor or 0 if result is boolean.
+ T* tResult;
- CAStringList* valueList;
- //! Index of currently selected item.
+ //! Index of currently selected item.
int selectedItem;
-
- //! Pointer to result given by constructor or 0 if result is boolean.
- int* intResult;
- //! Pointer to result given by constructor or 0 if result is int.
- bool* boolResult;
};
#endif
diff --git a/src/canetclient.cpp b/src/canetclient.cpp
index 83f6e97..a610b1b 100644
--- a/src/canetclient.cpp
+++ b/src/canetclient.cpp
@@ -6,7 +6,7 @@
/** Constructor.
*/
-CANetClient::CANetClient( CAPlayer* player ) {
+CANetClient::CANetClient( Player* player ) {
//netGame = 0;
//this->player = player;
}
@@ -81,7 +81,7 @@ CANetClient::keepUp() {
CL_NetMessage msg = netGame->receive( 0 );
//std::cout << "Server said: " << msg.data.c_str() << std::endl;
- CAStringList slist( msg.data.c_str() );
+ StringList slist( msg.data.c_str() );
// Server tells us id:
//
diff --git a/src/canetclient.h b/src/canetclient.h
index cdb8d44..ff47299 100644
--- a/src/canetclient.h
+++ b/src/canetclient.h
@@ -3,14 +3,14 @@
#include <ClanLib/core.h>
#include <ClanLib/network.h>
-#include "caplayer.h"
+#include "player.h"
/** Net client for multiplayer games.
@author Andrew Mustun
*/
class CANetClient {
public:
- CANetClient( CAPlayer* player );
+ CANetClient( Player* player );
~CANetClient();
bool joinGame();
@@ -20,7 +20,7 @@ protected:
//! Pointer to joined net game or NULL.
//CL_NetGame* netGame;
//! Pointer to playing player.
- //CAPlayer* player;
+ //Player* player;
}
;
diff --git a/src/capanel.cpp b/src/capanel.cpp
index 7633176..f4eb11c 100644
--- a/src/capanel.cpp
+++ b/src/capanel.cpp
@@ -1,19 +1,24 @@
-#include <stdio.h>
-
#include "capanel.h"
#include "catrophy.h"
/** Constructor.
*/
-CAPanel::CAPanel() {
- for( int c=0; c<CA_MAXPLAYERS; ++c ) {
- playerView[c] = new CAPlayerView( CA_APP->player[c] );
+CAPanel::CAPanel()
+{
+ for( int c=0; c<CA_RACEMAXPLAYERS; ++c )
+ {
+ m_playerView.push_back(new CAPlayerView( CA_APP->m_RacePlayer[c] ));
+ }
+}
+
+CAPanel::~CAPanel()
+{
+ for( unsigned int c=0; c<m_playerView.size(); ++c )
+ {
+ delete m_playerView[c];
}
}
-/** Destructor.
-*/
-CAPanel::~CAPanel() {}
/** Displays the panel.
*/
@@ -31,7 +36,7 @@ CAPanel::display()
// Display speed view:
//
- int speedIndex = (int)fabs(CA_APP->player[0]->getSpeed() / CA_APP->player[0]->getCarType()->maxSpeed * 10.0);
+ int speedIndex = (int)fabs(CA_APP->player[0]->getSpeed() / CA_APP->player[0]->getCar()->getMotor()->getMaxSpeed() * 10.0);
if( speedIndex>10 ) speedIndex = 10;
CA_RES->panel_speed->set_frame(speedIndex);
CA_RES->panel_speed->draw (0, 57);
@@ -39,14 +44,20 @@ CAPanel::display()
// Display turbo view:
//
CA_RES->panel_turbolabel->draw (0, 88);
- int turboIndex = (int)fabs(CA_APP->player[0]->getTurbo() / CA_APP->player[0]->getCarType()->maxTurbo * 9.0);
+ int turboIndex = (int)fabs(CA_APP->player[0]->getTurbo() / CA_APP->player[0]->getCar()->maxTurbo * 9.0);
CA_RES->panel_turbo->set_frame(turboIndex);
CA_RES->panel_turbo->draw (0, 100);
+ // Display ammo view
+ int ammoIndex = (int)fabs(CA_APP->player[0]->getBullets() / 500.0 * 20.0);
+ CA_RES->panel_ammo->set_frame(ammoIndex);
+ CA_RES->panel_ammo->draw (0, 110);
+
// Display player views:
//
- for( int c=0; c<CA_MAXPLAYERS; ++c ) {
- playerView[c]->display( c+1 );
+ for( unsigned int c=0; c<m_playerView.size(); ++c )
+ {
+ m_playerView[c]->display( c+1 );
}
// Display frames per second:
diff --git a/src/capanel.h b/src/capanel.h
index 272bd6c..dc982dc 100644
--- a/src/capanel.h
+++ b/src/capanel.h
@@ -4,21 +4,23 @@
#include <ClanLib/core.h>
#include "caplayerview.h"
+#include <vector>
/** Represents the panel on the left of the game.
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
-class CAPanel {
-public:
- CAPanel();
- ~CAPanel();
+class CAPanel
+{
+ public:
+ CAPanel();
+ ~CAPanel();
- void display();
+ void display();
-private:
- //! Pointer array of player views. One shown for each player.
-
- CAPlayerView* playerView[CA_MAXPLAYERS];
+ private:
+ //! Pointer array of player views. One shown for each player.
+ std::vector<CAPlayerView*> m_playerView;
};
#endif
diff --git a/src/caplayersettingsdialog.cpp b/src/caplayersettingsdialog.cpp
index e60e086..089a0c6 100644
--- a/src/caplayersettingsdialog.cpp
+++ b/src/caplayersettingsdialog.cpp
@@ -1,52 +1,47 @@
-#include <stdio.h>
-
#include "caplayersettingsdialog.h"
#include "caimagehueselector.h"
#include "catrophy.h"
#define DEFAULT_CARTYPE 0
+std::string priceToString(const int price)
+{
+ std::ostringstream ossPrice;
+ ossPrice << "$" << price;
+ return ossPrice.str();
+}
+
/** Constructor.
*/
CAPlayerSettingsDialog::CAPlayerSettingsDialog()
- : CADialog() {
+ : CADialog(),
+ nameInput("", 10, CAWidget::Left, CA_RES->font_normal_14_white),
+ carImage(CA_APP->carType[DEFAULT_CARTYPE].name.c_str(),
+ priceToString(CA_APP->carType[DEFAULT_CARTYPE].price),
+ CA_APP->carType[DEFAULT_CARTYPE].surface3d,
+ true,
+ CAImageView::Vertical )
+{
if( CA_APP->debug ) std::cout << "CAPlayerSettingsDialog() begin" << std::endl;
resize( 480, 200 );
- char price[16];
- sprintf( price, "$%d", CA_APP->carType[DEFAULT_CARTYPE].price );
+ std::ostringstream ossPrice;
+ ossPrice << "$" << CA_APP->carType[DEFAULT_CARTYPE].price;
- // Line edit for player name:
- //
- nameInput = new CALineEdit( "", 10, CAWidget::Left, CA_RES->font_normal_14_white );
- nameInput->move( left + 32, (top+bottom)/2 - nameInput->getHeight()/2 );
- // Car-Image:
- //
- carImage = new CAImageHueSelector( CA_APP->carType[DEFAULT_CARTYPE].name.c_str(),
- price,
- CA_APP->carType[DEFAULT_CARTYPE].surface3d,
- true,
- CAImageView::Vertical );
+ nameInput.move( left + 32, (top+bottom)/2 - nameInput.getHeight()/2 );
- carImage->move( right - carImage->getWidth() - 32,
- (top+bottom)/2 - carImage->getHeight()/2 );
+
+ carImage.move( right - carImage.getWidth() - 32,
+ (top+bottom)/2 - carImage.getHeight()/2 );
help = "Type your Nickname and use the Arrow Keys to change your Color.";
if( CA_APP->debug ) std::cout << "CAPlayerSettingsDialog() end" << std::endl;
}
-/** Destructor.
-*/
-CAPlayerSettingsDialog::~CAPlayerSettingsDialog() {
- delete carImage;
- carImage = 0;
- delete nameInput;
- nameInput = 0;
-}
/** Builds the dialog screen.
*/
@@ -57,8 +52,8 @@ CAPlayerSettingsDialog::buildScreen() {
CA_RES->font_normal_14_white->set_alignment(origin_top_left, 0, 0);
CA_RES->font_normal_14_white->draw( left+32, top+58, "Please enter your nickname:" );
- nameInput->display();
- carImage->display();
+ nameInput.display();
+ carImage.display();
displayHelp();
}
@@ -71,8 +66,15 @@ CAPlayerSettingsDialog::on_key_released (const CL_InputEvent &key)
switch( key.id )
{
case CL_KEY_ENTER:
- done = true;
+ {
+ if (nameInput.getText()=="")
+ {
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ }
+ else
+ done = true;
break;
+ }
case CL_KEY_ESCAPE:
done = true;
@@ -81,11 +83,11 @@ CAPlayerSettingsDialog::on_key_released (const CL_InputEvent &key)
case CL_KEY_UP:
case CL_KEY_DOWN:
- carImage->handleKey( key );
+ carImage.handleKey( key );
break;
default:
- nameInput->handleKey( key );
+ nameInput.handleKey( key );
break;
}
@@ -93,16 +95,16 @@ CAPlayerSettingsDialog::on_key_released (const CL_InputEvent &key)
/** Returns the player's name the user has entered.
*/
-const char*
+const std::string
CAPlayerSettingsDialog::getPlayerName() {
- return nameInput->getText();
+ return nameInput.getText();
}
/** Returns the player's color the user has chosen.
*/
int
CAPlayerSettingsDialog::getPlayerHue() {
- return carImage->getHue();
+ return carImage.getHue();
}
// EOF
diff --git a/src/caplayersettingsdialog.h b/src/caplayersettingsdialog.h
index 163c9a2..5a61856 100644
--- a/src/caplayersettingsdialog.h
+++ b/src/caplayersettingsdialog.h
@@ -8,24 +8,23 @@
/** Dialog for adjusting player settings (Name, color, car, face)
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
class CAPlayerSettingsDialog : public CADialog {
public:
CAPlayerSettingsDialog();
- ~CAPlayerSettingsDialog();
virtual void buildScreen();
virtual void on_key_released (const CL_InputEvent &key);
- const char* getPlayerName();
+ const std::string getPlayerName();
int getPlayerHue();
private:
//! Line edit for players name
-
- CALineEdit* nameInput;
+ CALineEdit nameInput;
//! Car image hue selector.
- CAImageHueSelector* carImage;
+ CAImageHueSelector carImage;
};
#endif
diff --git a/src/caplayerview.cpp b/src/caplayerview.cpp
index f864ac3..d1e86c8 100644
--- a/src/caplayerview.cpp
+++ b/src/caplayerview.cpp
@@ -1,5 +1,3 @@
-#include <stdio.h>
-
#include "caimagemanipulation.h"
#include "caplayerview.h"
#include "caresources.h"
@@ -7,7 +5,7 @@
/** Constructor.
\param player Pointer to the appropriate player.
*/
-CAPlayerView::CAPlayerView( CAPlayer* player ) {
+CAPlayerView::CAPlayerView( Player* player ) {
this->player = player;
button = 0;
renderButton();
@@ -24,7 +22,7 @@ CAPlayerView::~CAPlayerView() {
\param defaultPos default position if rank is 0 (race startup)
*/
void
-CAPlayerView::display( int defaultPos ) {
+CAPlayerView::display( const int defaultPos ) {
// Maybe we need to re-render the button sprite:
//
if( currentColor!=player->getColor() ) {
@@ -33,17 +31,14 @@ CAPlayerView::display( int defaultPos ) {
int lap = (int)( floor( player->getPosition() )+1.0 );
int rank = (player->getRaceRank()==0 ? defaultPos : player->getRaceRank());
- char lapStr[2];
- char rankStr[2];
- int y = (rank-1) * 55 + 110;
+ int y = (rank-1) * 55 + 110 + 38; // The turbo jauge + the ammo jauge
if( lap>5 ) lap=5;
- lapStr[0] = ( lap<10 ? lap : 0 ) + 48;
- lapStr[1] = '\0';
-
- rankStr[0] = ( rank<10 ? rank : 0 ) + 48;
- rankStr[1] = '\0';
+ std::ostringstream ossLap, ossRank, ossNumLap;
+ ossLap << lap;
+ ossRank << rank;
+ ossNumLap << CA_NUMLAPS;
// Display color button:
//
@@ -59,13 +54,11 @@ CAPlayerView::display( int defaultPos ) {
//
CA_RES->panel_infoview->draw (0, y+20);
CA_RES->font_lcd_13_green->set_alignment(origin_top_left, 0, 0);
- CA_RES->font_lcd_13_green->draw( 50, y+22, lapStr );
- char numLapsStr[6];
- sprintf( numLapsStr, "%d", CA_NUMLAPS );
+ CA_RES->font_lcd_13_green->draw( 50, y+22, ossLap.str() );
CA_RES->font_lcd_13_green->set_alignment(origin_top_left, 0, 0);
- CA_RES->font_lcd_13_green->draw( 70, y+31, numLapsStr );
+ CA_RES->font_lcd_13_green->draw( 70, y+31, ossNumLap.str() );
CA_RES->font_normal_11_white->set_alignment(origin_top_left, 0, 0);
- CA_RES->font_normal_11_white->draw( 99, y+30, rankStr );
+ CA_RES->font_normal_11_white->draw( 99, y+30, ossRank.str() );
// Display cross for death players:
//
diff --git a/src/caplayerview.h b/src/caplayerview.h
index 7e599bf..c3a70d2 100644
--- a/src/caplayerview.h
+++ b/src/caplayerview.h
@@ -1,30 +1,30 @@
#ifndef CAPLAYERVIEW_H
#define CAPLAYERVIEW_H
-#include "caplayer.h"
-#include "cacolor.h"
+#include "player.h"
+#include "utils/hsvcolor.h"
/** A player view in the panel.
@author Andrew Mustun
*/
class CAPlayerView {
public:
- CAPlayerView( CAPlayer* player );
+ CAPlayerView( Player* player );
~CAPlayerView();
- void display( int defaultPos );
+ void display( const int defaultPos );
void renderButton();
private:
//! Pointer to player.
- CAPlayer* player;
+ Player* player;
//! The button in players color. Created and destroyed by this class.
CL_Surface* button;
/** Current color of this button. Needed for detecting if we must
re-render the button.
*/
- CAColor currentColor;
+ HSVColor currentColor;
};
#endif
diff --git a/src/capositiontable.cpp b/src/capositiontable.cpp
index 2c75e4e..1cbdf50 100644
--- a/src/capositiontable.cpp
+++ b/src/capositiontable.cpp
@@ -1,4 +1,4 @@
-#include "caplayer.h"
+#include "player.h"
#include "capositiontable.h"
#include "catrophy.h"
@@ -36,46 +36,68 @@ CAPositionTable::~CAPositionTable() {}
*/
void
CAPositionTable::resetRace() {
- for( int i=0; i<CA_MAXPLAYERS; ++i ) {
- raceRankList[i] = 0;
- }
- raceRankIndex = 0;
- raceRankIndexBottom = CA_MAXPLAYERS-1;
+ m_raceRankList.clear();
+ m_diedPlayers.clear();
+ m_lappedPlayers.clear();
}
+bool CAPositionTable::isPossibleWin() const
+{
+ if (m_raceRankList.size()==0)
+ return true;
+ else
+ return false;
+}
+
/** Registers a player in the current lap rank list.
The first player who calls this function is the lap winner.
*/
void
-CAPositionTable::playerFinishedRace( CAPlayer* player ) {
- if( raceRankIndex<CA_MAXPLAYERS ) {
- raceRankList[raceRankIndex] = player;
- player->setRaceRank( raceRankIndex+1 );
- int points = 700-100*player->getRaceRank();
- if( points>0 ) {
- player->setRacePoints( points );
- player->setTotalPoints( player->getTotalPoints() + points );
- }
- player->setMoney( (int)(player->getMoney() + (float)CA_PRIZE/CA_MAXPLAYERS*(CA_MAXPLAYERS-player->getRaceRank()+1)) );
- raceRankIndex++;
- }
+CAPositionTable::playerFinishedRace( Player* player )
+{
+ m_raceRankList.push_back(player);
+ player->setRaceRank( m_raceRankList.size() );
+ int points = ((CA_RACEMAXPLAYERS+1)-player->getRaceRank()) * (m_raceLevel +1);
+ if( points>0 )
+ {
+ player->setRacePoints( points );
+ }
+ float priceMoney;
+ if (m_raceLevel == Easy)
+ priceMoney = CA_PRIZE;
+ else if (m_raceLevel == Medium)
+ priceMoney = CA_PRIZE_MEDIUM;
+ else
+ priceMoney = CA_PRIZE_HARD;
+ player->addRaceMoney((float)priceMoney/CA_RACEMAXPLAYERS*(CA_RACEMAXPLAYERS-player->getRaceRank()+1));
}
+/** Registers a player in the current lap rank list if he finish the race lapped
+ No point or money for lapped player
+*/
+void
+CAPositionTable::playerFinishedLapped( Player* player )
+{
+ player->setRaceRank(CA_RACEMAXPLAYERS-m_diedPlayers.size()-m_lappedPlayers.size());
+ m_lappedPlayers.push_back(player);
+}
+
/** Registers a player in the current lap rank list if he died.
The first player who calls this function is the lap looser.
*/
void
-CAPositionTable::playerDied( CAPlayer* player ) {
- if( raceRankIndexBottom>=0 ) {
- raceRankList[raceRankIndexBottom] = player;
- player->setRaceRank( raceRankIndexBottom+1 );
- raceRankIndexBottom--;
- }
+CAPositionTable::playerDied( Player* player )
+{
+ player->setRaceRank(CA_RACEMAXPLAYERS-m_diedPlayers.size()-m_lappedPlayers.size());
+ m_diedPlayers.push_back(player);
+
}
+
+
// EOF
diff --git a/src/capositiontable.h b/src/capositiontable.h
index 84590f5..c8e43ff 100644
--- a/src/capositiontable.h
+++ b/src/capositiontable.h
@@ -1,12 +1,19 @@
#ifndef CAPOSITIONTABLE_H
#define CAPOSITIONTABLE_H
-#include "caplayer.h"
+#include "player.h"
-#define CA_POSITIONTABLE CAPositionTable::getPositionTable()
+
+enum RaceLevel
+{
+ Easy =0,
+ Medium = 1,
+ Hard = 2
+};
/** Controls the position table data.
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
class CAPositionTable {
public:
@@ -14,8 +21,11 @@ public:
~CAPositionTable();
void resetRace();
- void playerFinishedRace( CAPlayer* player );
- void playerDied( CAPlayer* player );
+ void playerFinishedRace( Player* player );
+ void playerDied( Player* player );
+ void playerFinishedLapped(Player* player);
+ void setRaceLevel(const RaceLevel rl) {m_raceLevel = rl;}
+ bool isPossibleWin() const;
private:
CAPositionTable();
@@ -29,11 +39,11 @@ private:
successfully finished the current race.
raceRankList[0] is the first.
*/
- CAPlayer* raceRankList[CA_MAXPLAYERS];
- //! Index of next rank.
- int raceRankIndex;
- //! Index of next rank from bottom
- int raceRankIndexBottom;
+ std::vector<Player*> m_raceRankList;
+ std::vector<Player*> m_diedPlayers;
+ std::vector<Player*> m_lappedPlayers;
+ // Difficulty of actual race
+ RaceLevel m_raceLevel;
};
diff --git a/src/capositiontableview.cpp b/src/capositiontableview.cpp
index a252341..e9ac97e 100644
--- a/src/capositiontableview.cpp
+++ b/src/capositiontableview.cpp
@@ -1,17 +1,18 @@
-#include <stdio.h>
#include "calabel.h"
-#include "caplayer.h"
+#include "player.h"
#include "capositiontableview.h"
#include "catrophy.h"
+#include <string>
+#include <sstream>
+
/** Constructor.
\param race true: lap results / false: total results
*/
-CAPositionTableView::CAPositionTableView( bool race )
+CAPositionTableView::CAPositionTableView()
: CADialog() {
resize( 600, 340 );
- this->race = race;
label = new CALabel( "", CAWidget::Left, CA_RES->font_normal_11_white );
}
@@ -33,47 +34,31 @@ CAPositionTableView::buildScreen() {
int y; // Y-Pos of text line
int pl; // Counter for players
int rank; // Rank of current player
- char rankStr[5]; // Position string
int points; // Points of current player
- char pointStr[16]; // Points string
- char moneyStr[32]; // Money - there's no limit for money
- char timeStr[16]; // Time string
- //bool rankTaken[CA_MAXPLAYERS]; // Rank already taken by another player -> move down
-
- //for( pl=0; pl<CA_MAXPLAYERS; ++pl ) {
- // rankTaken[pl] = false;
- //}
-
- for( pl=0; pl<CA_MAXPLAYERS; ++pl ) {
-
- if(race) {
- rank = CA_APP->player[pl]->getRaceRank();
- points = CA_APP->player[pl]->getRacePoints();
- CAMath::timeToString( timeStr, CA_APP->player[pl]->getRaceTime() );
- } else {
- rank = CA_APP->player[pl]->getTotalRank();
- points = CA_APP->player[pl]->getTotalPoints();
- strcpy( timeStr, "" );
- }
+ std::string timeStr; // Time string
+
- // Rank already taken -> move to the next free below.
- //while( rankTaken[rank-1] && rank-1<CA_MAXPLAYERS ) ++rank;
+ for( pl=0; pl<CA_RACEMAXPLAYERS; ++pl ) {
- //rankTaken[rank-1] = true;
+ rank = CA_APP->m_RacePlayer[pl]->getRaceRank();
+ points = CA_APP->m_RacePlayer[pl]->getRacePoints();
+ TrophyMath::timeToString( timeStr, CA_APP->m_RacePlayer[pl]->getRaceTime() );
- if( rank!=0 ) {
+ if( rank!=0 )
+ {
y = top + 32 + rank*16;
// Rank:
//
- sprintf( rankStr, "%d.", rank );
+ std::ostringstream ossRank;
+ ossRank << rank << ".";
CA_RES->font_normal_11_white->set_alignment(origin_top_right, 0, 0);
- CA_RES->font_normal_11_white->draw( left + 40, y, rankStr );
+ CA_RES->font_normal_11_white->draw( left + 40, y, ossRank.str() );
// Player name:
//
CA_RES->font_normal_11_white->set_alignment(origin_top_left, 0, 0);
- CA_RES->font_normal_11_white->draw( left + 64, y, CA_APP->player[pl]->getName() );
+ CA_RES->font_normal_11_white->draw( left + 64, y, CA_APP->m_RacePlayer[pl]->getName() );
// Race time:
//
@@ -83,22 +68,24 @@ CAPositionTableView::buildScreen() {
// Player points:
//
- sprintf( pointStr, "%d", points );
- label->setText( pointStr );
+ std::ostringstream ossPoint;
+ ossPoint << points;
+ label->setText( ossPoint.str() );
label->move( left + 360, y );
label->display();
// Money:
//
- sprintf( moneyStr, "$%d", CA_APP->player[pl]->getMoney() );
- label->setText( moneyStr );
+ std::ostringstream ossMoney;
+ ossMoney << "$" << CA_APP->m_RacePlayer[pl]->getRaceMoney();
+ label->setText( ossMoney.str() );
label->move( left + 420, y );
label->display();
// Car name:
//
CA_RES->font_normal_11_white->set_alignment(origin_top_left, 0, 0);
- CA_RES->font_normal_11_white->draw( left + 500, y, CA_APP->player[pl]->getCarType()->name );
+ CA_RES->font_normal_11_white->draw( left + 500, y, CA_APP->m_RacePlayer[pl]->getCar()->name );
/*label->setText( CA_APP->player[pl]->getCarType().name );
label->move( left + 420, y );
label->display();*/
diff --git a/src/capositiontableview.h b/src/capositiontableview.h
index c15dd36..d7aff80 100644
--- a/src/capositiontableview.h
+++ b/src/capositiontableview.h
@@ -6,19 +6,17 @@
/**Shows and controls the position table.
*@author Andrew Mustun
+ *@author Matthieu Lecesne
*/
class CAPositionTableView : public CADialog {
public:
- CAPositionTableView( bool rank );
+ CAPositionTableView();
~CAPositionTableView();
virtual void buildScreen();
virtual void on_key_released (const CL_InputEvent &key);
private:
- //! Race or total results
-
- bool race;
//! Label for table output
CALabel* label;
};
diff --git a/src/caresources.cpp b/src/caresources.cpp
index 01b7f65..21df094 100644
--- a/src/caresources.cpp
+++ b/src/caresources.cpp
@@ -35,6 +35,7 @@ CAResources::CAResources() {}
*/
CAResources::~CAResources() {
delete misc_cross;
+ delete misc_flag;
delete misc_light;
delete misc_hitpoint;
delete misc_gunfire;
@@ -78,6 +79,9 @@ CAResources::~CAResources() {
delete gui_border3;
delete gui_border4;
delete gui_button;
+ delete gui_button_red;
+ delete gui_button_green;
+ delete gui_button_blue;
delete gui_arrow_l;
delete gui_arrow_r;
delete gui_arrow_t;
@@ -213,6 +217,7 @@ CAResources::load() {
// Load generic sprites:
//
misc_cross = new CL_Surface( "misc/cross", resources );
+ misc_flag = new CL_Surface( "misc/flag", resources );
misc_light = new CL_Sprite( "misc/light", resources );
misc_hitpoint = new CL_Sprite( "misc/hitpoint", resources );
misc_gunfire = new CL_Sprite( "misc/gunfire", resources );
@@ -262,6 +267,7 @@ CAResources::load() {
panel_speed = new CL_Sprite( "panel/speed", resources );
panel_turbolabel = new CL_Surface( "panel/turbolabel", resources );
panel_turbo = new CL_Sprite( "panel/turbo", resources );
+ panel_ammo = new CL_Sprite( "panel/ammo", resources );
panel_death = new CL_Surface( "panel/death", resources );
CA_APP->loading.setProgress( 45 );
@@ -277,6 +283,12 @@ CAResources::load() {
gui_border3 = new CL_Surface( "gui/border3", resources );
gui_border4 = new CL_Surface( "gui/border4", resources );
gui_button = new CL_Surface( "gui/button", resources );
+ gui_button_red = new CL_Surface("gui/button", resources );
+ gui_button_red->set_color (1.0f, 0.0f, 0.0f);
+ gui_button_green = new CL_Surface("gui/button", resources );
+ gui_button_green->set_color (0.0f, 1.0f, 0.0f);
+ gui_button_blue = new CL_Surface("gui/button", resources );
+ gui_button_blue->set_color (0.0f, 0.0f, 1.0f);
gui_arrow_l = new CL_Surface( "gui/arrow_l", resources );
gui_arrow_r = new CL_Surface( "gui/arrow_r", resources );
gui_arrow_t = new CL_Surface( "gui/arrow_t", resources );
diff --git a/src/caresources.h b/src/caresources.h
index 4bebf74..7d8be7f 100644
--- a/src/caresources.h
+++ b/src/caresources.h
@@ -6,7 +6,7 @@
#include <ClanLib/sound.h>
#include "casoundeffect.h"
-#include "camath.h"
+#include "utils/trophymath.h"
#define CA_RES CAResources::getResources()
@@ -14,6 +14,8 @@
/** Offers global access to all resources.
This way we avoid double loading of resources.
@author Andrew Mustun
+ @author Colin Pitrat
+ @author Matthieu Lecesne
*/
class CAResources {
@@ -54,6 +56,7 @@ public:
CL_Font* font_lcd_13_green;
CL_Surface* misc_cross;
+ CL_Surface* misc_flag;
CL_Sprite* misc_light;
CL_Sprite* misc_hitpoint;
CL_Sprite* misc_gunfire;
@@ -83,6 +86,7 @@ public:
CL_Surface* panel_infoview;
CL_Sprite* panel_speed;
CL_Sprite* panel_turbo;
+ CL_Sprite* panel_ammo;
CL_Surface* panel_turbolabel;
CL_Surface* panel_death;
@@ -95,6 +99,9 @@ public:
CL_Surface* gui_border3;
CL_Surface* gui_border4;
CL_Surface* gui_button;
+ CL_Surface* gui_button_red;
+ CL_Surface* gui_button_green;
+ CL_Surface* gui_button_blue;
CL_Surface* gui_arrow_l;
CL_Surface* gui_arrow_r;
CL_Surface* gui_arrow_t;
diff --git a/src/cartype.cpp b/src/cartype.cpp
new file mode 100644
index 0000000..c9022c0
--- /dev/null
+++ b/src/cartype.cpp
@@ -0,0 +1,174 @@
+#include "cartype.h"
+#include "cacarupgrades.h"
+#include "caimageview.h"
+#include "player.h"
+
+
+CarOption::CarOption(CL_ResourceManager* resources, CACarUpgrades* carUp, int maxOption, const std::string& pathPrice, const std::string& name)
+: m_carUp(carUp), m_current(0), m_maxOpt(maxOption), m_name(name)
+{
+ for (int i=0; i < m_maxOpt; i++)
+ m_PriceList.push_back((i*CL_Integer( pathPrice, resources ))/2+CL_Integer( pathPrice, resources ));
+}
+
+
+CL_Surface* CarOption::getImage() const
+{
+ int imageNum = m_current;
+ if (m_current == m_maxOpt)
+ imageNum--;
+ return getSurface(imageNum);
+}
+
+int CarOption::getPrice () const
+{
+ int price = m_PriceList[m_current];
+ if (m_current == m_maxOpt)
+ {
+ price = 0; // Should be impossible
+ }
+ return price;
+}
+
+bool CarOption::buyOption(Player* pl)
+{
+ bool hasBought = false;
+ if (m_current < m_maxOpt)
+ {
+ if (pl->spendMoney(getPrice()))
+ {
+ m_current++;
+ upgrade(); // increase the value(s) of car settings
+ hasBought = true;
+ }
+ }
+ return hasBought;
+}
+
+std::string CarOption::getPriceString() const
+{
+ int price = m_PriceList[m_current];
+ if (m_current == m_maxOpt)
+ {
+ price = 0;
+ }
+ std::ostringstream oss;
+ oss << "$" << price;
+ return oss.str();
+}
+
+void CarOption::updateImageView(CAImageView* imageView, const int imageViewWidth)
+{
+ imageView->setAutoresize(true);
+ imageView->setImage(getImage());
+ imageView->setUpperText(m_name);
+ imageView->setLowerText(getPriceString());
+ imageView->resize(imageViewWidth, -1);
+}
+
+
+CarMotor::CarMotor(const std::string& mainPath, CL_ResourceManager* resources, CACarUpgrades* carUp)
+: CarOption(resources, carUp, 5, mainPath + "motorPrice", "Engine")
+{
+ std::string path = mainPath + "acceleration";
+ m_acceleration = 6 * CL_Integer( path, resources );
+
+ path = mainPath + "maxSpeed";
+ m_maxSpeed = 6 * CL_Integer( path, resources );
+}
+
+
+void CarMotor::upgrade()
+{
+ m_acceleration += 10;
+ m_maxSpeed += 5;
+}
+
+
+CL_Surface* CarMotor::getSurface(const int imageNum) const
+{
+ return m_carUp->getMotor(imageNum);
+}
+
+
+CarTires::CarTires(const std::string& mainPath, CL_ResourceManager* resources, CACarUpgrades* carUp)
+: CarOption(resources, carUp, 5, mainPath + "tiresPrice", "Tires")
+{
+ std::string path = mainPath + "slidingFactor";
+ m_slidingFactor = 0.01 * CL_Integer( path, resources );
+}
+
+void CarTires::upgrade()
+{
+ m_slidingFactor += 0.05f;
+}
+
+
+CL_Surface* CarTires::getSurface(const int imageNum) const
+{
+ return m_carUp->getTires(imageNum);
+}
+
+
+CarArmor::CarArmor(const std::string& mainPath, CL_ResourceManager* resources, CACarUpgrades* carUp)
+: CarOption(resources, carUp, 5, mainPath + "armorPrice", "Armor")
+{
+ m_armor = 0; //For now all cars start with zero armor, this might change in the future
+}
+
+
+void CarArmor::upgrade()
+{
+ m_armor += 10;
+}
+
+
+CL_Surface* CarArmor::getSurface(const int imageNum) const
+{
+ return m_carUp->getArmor(imageNum);
+}
+
+
+CarType::CarType(const std::string& mainPath, CL_ResourceManager* resources, CACarUpgrades* carUp, const bool debug)
+ :
+ m_motor (mainPath, resources, carUp),
+ m_tires (mainPath, resources, carUp),
+ m_armor (mainPath, resources, carUp)
+{
+ if(debug) std::cout << " name" << std::endl;
+
+ std::string path = mainPath + "name";
+ name = CL_String::load( path, resources );
+
+ if(debug) std::cout << " surface" << std::endl;
+
+ path = mainPath + "surface";
+ surface = new CL_Surface( path, resources );
+
+ if(debug) std::cout << " surface3d" << std::endl;
+
+ path = mainPath + "surface3d";
+ surface3d = new CL_Surface( path, resources );
+
+ path = mainPath + "length";
+ length = CL_Integer( path, resources );
+ path = mainPath + "width";
+ width = CL_Integer( path, resources );
+ path = mainPath + "minSpeed";
+ minSpeed = 6 * CL_Integer( path, resources );
+ path = mainPath + "maxTurbo";
+ maxTurbo = CL_Integer( path, resources );
+ path = mainPath + "acceleration";
+ deceleration = 6 * CL_Integer( path, resources );
+ path = mainPath + "steeringPower";
+ steeringPower = CL_Integer( path, resources );
+ path = mainPath + "price";
+ price = CL_Integer( path, resources );
+
+
+ radius = std::sqrt( (double)width/2 * (double)width/2 + (double)length/2 * (double)length/2 );
+ angle = atan( (double)(width/2) / (double)(length/2) ) * ARAD;
+}
+
+
+// EOF
diff --git a/src/cartype.h b/src/cartype.h
new file mode 100644
index 0000000..0481ab3
--- /dev/null
+++ b/src/cartype.h
@@ -0,0 +1,145 @@
+#ifndef CARTYPE_H
+#define CARTYPE_H
+
+#include <ClanLib/core.h>
+#include <ClanLib/display.h>
+
+#include "utils/trophymath.h"
+#include "cacarupgrades.h"
+#include <string>
+
+class CAImageView;
+class Player;
+
+/** class for car options
+ @author Matthieu Lecesne
+*/
+class CarOption
+{
+ public:
+ CarOption(CL_ResourceManager* resources, CACarUpgrades* carRes, int maxOpt, const std::string& pathPrice, const std::string& name);
+ CL_Surface* getImage() const;
+ int getCurrent() const { return m_current;}
+ void setCurrent(const int current) {m_current = current;} // Must only be use by loadGame
+ int getMax() const { return m_maxOpt;}
+ bool isMax() const { return m_current == m_maxOpt;}
+ int getPrice () const;
+ bool buyOption (Player* pl);
+ std::string getPriceString() const;
+ void updateImageView(CAImageView* imageView, const int imageViewWidth);
+ std::string getName() const {return m_name;}
+ protected:
+ //! Upgrades ressources manager
+ const CACarUpgrades* m_carUp;
+ private:
+ virtual void upgrade() = 0;
+ virtual CL_Surface* getSurface(const int ImageNum) const = 0;
+
+ // ! current option value
+ int m_current;
+ // ! max option value
+ int m_maxOpt;
+ // ! List of the upgrades price
+ std::vector<int> m_PriceList;
+ // ! Name of the option (Engine, Tires, Armor)
+ std::string m_name;
+};
+
+//! Motor change the acceleration and the maxSpeed
+class CarMotor : public CarOption
+{
+ public:
+ CarMotor(const std::string& mainPath, CL_ResourceManager* resources, CACarUpgrades* carUp);
+ inline float getAcceleration() const { return m_acceleration;}
+ inline float getMaxSpeed() const { return m_maxSpeed;}
+ private:
+ void upgrade();
+ CL_Surface* getSurface(const int imageNum) const;
+ //! Acceleration in pixels per square second
+ float m_acceleration;
+ //! Maximum speed in pixels per second
+ float m_maxSpeed;
+};
+
+
+//! Tires change the slidingFactor
+class CarTires : public CarOption
+{
+ public:
+ CarTires(const std::string& mainPath, CL_ResourceManager* resources, CACarUpgrades* carUp);
+ inline float getSlidingFactor() const { return m_slidingFactor; }
+ private:
+ void upgrade();
+ CL_Surface* getSurface(const int imageNum) const;
+ //! Sliding factor (1=no, 0.8=much, ...)
+ float m_slidingFactor;
+};
+
+// ! Armor change the armor ;-)
+class CarArmor: public CarOption
+{
+ public:
+ CarArmor(const std::string& mainPath, CL_ResourceManager* resources, CACarUpgrades* carUp);
+ inline float getArmor() const { return m_armor;}
+ private:
+ void upgrade();
+ CL_Surface* getSurface(const int imageNum) const;
+ // ! Armor value
+ float m_armor;
+};
+
+
+/** class for car types.
+ @author Andrew Mustun
+ @author Matthieu Lecesne
+*/
+class CarType
+{
+ public:
+
+ CarType(const std::string& mainPath, CL_ResourceManager* resources, CACarUpgrades* carUp, const bool debug = false);
+
+ CarMotor* getMotor() {return &m_motor;}
+ CarTires* getTires() {return &m_tires;}
+ CarArmor* getArmor() {return &m_armor;}
+
+ //! Car name (e.g. "Capri")
+ std::string name;
+
+ //! Pointer to surface resource (r,g,b,m,y,c)
+ CL_Surface* surface;
+ //! Pointer to surface resource 3d (r,g,b,m,y,c)
+ CL_Surface* surface3d;
+
+ //! Current car length in pixel
+ int length;
+ //! Current car width in pixel
+ int width;
+ //! Half of the diagonal
+ float radius;
+ //! Angle to edge
+ float angle;
+
+ //! Minimum speed in pixels per second
+ float minSpeed;
+ //! Maximum turbo load in pixels
+ float maxTurbo;
+
+ //! Deceleration in pixels per square second
+ float deceleration;
+ //! Steering power in degrees per second
+ float steeringPower;
+
+ //! Price in USD
+ int price;
+
+ private:
+ CarMotor m_motor;
+ CarTires m_tires;
+ CarArmor m_armor;
+};
+
+
+#endif
+
+// EOF
diff --git a/src/cascreen.cpp b/src/cascreen.cpp
index ff7abb1..13a5499 100644
--- a/src/cascreen.cpp
+++ b/src/cascreen.cpp
@@ -4,11 +4,13 @@
/** Constructor.
*/
-CAScreen::CAScreen() {
- done = false;
- cancel = false;
- title = "";
- help = "";
+CAScreen::CAScreen(const std::string& n_title, const std::string& n_help)
+:
+ done (false),
+ cancel (false),
+ title (n_title),
+ help (n_help)
+{
}
/** Destructor.
diff --git a/src/cascreen.h b/src/cascreen.h
index 52c25f3..bfc2750 100644
--- a/src/cascreen.h
+++ b/src/cascreen.h
@@ -9,7 +9,7 @@
class CAScreen
{
public:
- CAScreen();
+ CAScreen(const std::string& n_title = "", const std::string& n_help = "");
virtual ~CAScreen();
virtual int run() = 0;
diff --git a/src/casignupscreen.cpp b/src/casignupscreen.cpp
index 596effc..d729f44 100644
--- a/src/casignupscreen.cpp
+++ b/src/casignupscreen.cpp
@@ -1,27 +1,88 @@
#include "casignupscreen.h"
#include "catrophy.h"
+#include "player.h"
+#include "upgradespanel.h"
+#include "caimageview.h"
+#include "cachampionshipscreen.h" // For RankPredicate
+#include <vector>
+
+struct FindPlayer:public std::binary_function<std::vector<Player*>, Player*, bool>
+{
+ bool operator()(std::vector<Player*>& racePlayers, Player* player) const
+ {
+ std::vector<Player*>::const_iterator it = std::find(racePlayers.begin(), racePlayers.end(), player);
+ return (it != racePlayers.end());
+ }
+};
/** Constructor.
*/
-CASignUpScreen::CASignUpScreen()
- : CAScreen() {
+CASignUpScreen::CASignUpScreen(std::vector<Player*> player, std::vector<int> trackNumbers)
+ : CAScreen(),
+ m_Player(player)
+{
cursor = 0;
offset = 0;
title = "P R E S S E N T E R T O S I G N U P";
help = "Use Arrow Keys to change selection and press Enter to\nconfirm";
+ m_selected = false;
left = (CA_APP->width - 640)/2;
right = CA_APP->width - left;
- top = CA_APP->headerHeight;
+ top = CA_APP->headerHeight + 30;
bottom = top + 400;
- numTracks = CA_APP->trackList.count();
+ numTracks = CA_APP->trackList.size();
- for( int i=0; i<3; ++i ) {
+ for( int i=0; i<3; ++i )
+ {
image[i] = 0;
racePreview[i] = 0;
}
+ //setOffset( 0 );
+ std::sort(m_Player.begin(), m_Player.end(), RankPredicate()); // We sort player by points
+ int beginRandom = m_Player.size()/2;
+ int endRandom = m_Player.size() -1;
+ for (int race=0; race<3; race++)
+ {
+ int rn = 0;
+ if (trackNumbers.size() == 3)
+ rn = trackNumbers[race];
+ else
+ {
+ std::vector<std::string>::const_iterator it = m_trackList.begin();
+ do
+ {
+ rn = TrophyMath::getRandomNumber( 0, numTracks-1 );
+ it = std::find(m_trackList.begin(), m_trackList.end(), CA_APP->trackList[rn]);
+ }
+ while (it != m_trackList.end());
+ }
+ m_trackList.push_back(CA_APP->trackList[rn]);
+ m_trackNumbers.push_back(rn);
+
+ m_RacePlayer.push_back(std::vector<Player*>());
+ m_StringRacePlayer.push_back(std::vector<std::string>());
+
+ for (int pl=0; pl<CA_RACEMAXPLAYERS; pl++)
+ {
+ std::vector<std::vector<Player*> >::const_iterator it;
+ int rn = 0;
+ do
+ {
+ rn = TrophyMath::getRandomNumber( beginRandom, endRandom );
+ it = std::find_if(m_RacePlayer.begin(), m_RacePlayer.end(), std::bind2nd(FindPlayer(), m_Player[rn]));
+ }
+ while ( it != m_RacePlayer.end() || m_Player[rn] == CA_APP->player[0]);
+ m_RacePlayer[race].push_back(m_Player[rn]);
+ std::ostringstream oss;
+ oss << rn+1 << ") " << m_Player[rn]->getName();
+ m_StringRacePlayer[race].push_back(oss.str());
+ }
+ beginRandom -= m_Player.size()/4;
+ endRandom -= m_Player.size()/4;
+ }
setOffset( 0 );
}
@@ -55,34 +116,37 @@ CASignUpScreen::reset()
\param o New Offset.
*/
void
-CASignUpScreen::setOffset( int o )
+CASignUpScreen::setOffset( int offset )
{
- std::string trackPath = (std::string) "tracks/";
-
- offset = o;
+ std::string trackPath = "tracks/";
+ this->offset = offset;
reset();
for( int i=0; i<3; ++i )
{
- //printf( "\ni: %d", i );
-
if( i<numTracks )
{
- //image[i] = CL_TargaProvider::create( trackPath + CA_APP->trackList.getItem(i+offset) + "/thumb.tga", NULL );
try
{
- image[i] = new CL_Surface (CL_TargaProvider( trackPath + CA_APP->trackList.getItem(i+offset) + "/thumb.tga" ));
+ //image[i] = new CL_Surface (CL_TargaProvider( trackPath + CA_APP->trackList[i+offset] + "/thumb.tga" ));
+ image[i] = new CL_Surface (CL_TargaProvider( trackPath + m_trackList[i] + "/thumb.tga" ));
+
}
catch(CL_Error err)
{
- trackPath = (std::string) "../resources/tracks/";
- image[i] = new CL_Surface (CL_TargaProvider( trackPath + CA_APP->trackList.getItem(i+offset) + "/thumb.tga" ));
+ trackPath = "../resources/tracks/";
+ //image[i] = new CL_Surface (CL_TargaProvider( trackPath + CA_APP->trackList[i+offset] + "/thumb.tga" ));
+ image[i] = new CL_Surface (CL_TargaProvider( trackPath + m_trackList[i] + "/thumb.tga" ));
}
- racePreview[i] = new CAImageView( CA_APP->trackList.getItem(i+offset), "", image[i], false );
+ std::ostringstream oss;
+ oss << "$" << (i==0 ? CA_PRIZE : (i==1 ? CA_PRIZE_MEDIUM : CA_PRIZE_HARD));
+
+ //racePreview[i] = new CAImageView( CA_APP->trackList[i+offset], oss.str(), image[i], false );
+ racePreview[i] = new CAImageView( m_trackList[i], oss.str(), image[i], false );
racePreview[i]->setImageSize( 150, 92 );
- racePreview[i]->move( left + 50 + 195*i, top + 50 );
+ racePreview[i]->move( left + 195*i, top + 50 );
}
else
{
@@ -92,14 +156,44 @@ CASignUpScreen::setOffset( int o )
}
}
+/** get the players in the same race of the player)
+*/
+std::vector<Player*> CASignUpScreen::getRacePlayers()
+{
+ return m_RacePlayer[cursor];
+}
+
+/** get all players running in the 3 races (easy, medium and hard)
+*/
+std::vector<std::vector<Player*> > CASignUpScreen::getAllRunningPlayers()
+{
+ return m_RacePlayer;
+}
+
+
+void CASignUpScreen::addVirtualPoints()
+{
+ for( int i=0; i<3; ++i )
+ {
+ if (i!=cursor)
+ {
+ int random =TrophyMath::getRandomNumber(0,5);
+ unsigned int playerFinished = m_RacePlayer[i].size();
+ if (random <= 0)
+ playerFinished--;
+ if (random <= 1)
+ playerFinished--;
+ for (unsigned int j=0; j<playerFinished; j++)
+ m_RacePlayer[i][j]->setRacePoints (((CA_RACEMAXPLAYERS)-j) * (i +1));
+ }
+ }
+}
+
/** Runs the screen.
*/
int
CASignUpScreen::run()
{
- //CL_Input::chain_button_release.push_back( this );
- //slot = CL_Input::sig_button_release.connect(thCreateSlot(this, &CASignUpScreen::on_button_release));
- //slot = CL_Input::sig_button_press.connect(this, &CASignUpScreen::on_button_release);
slot = CL_Keyboard::sig_key_up().connect(this, &CASignUpScreen::on_key_released);
CA_APP->fadeScreen( true, this );
@@ -117,7 +211,7 @@ CASignUpScreen::run()
// Play background sound:
CASoundEffect::playBackgroundMelody();
- CL_Display::flip(); // Copy framebufer to screen
+ CL_Display::flip(); // Copy framebuffer to screen
CL_System::keep_alive(); // VERY VITAL for the system!
CA_APP->measureFrameTime( false );
@@ -129,7 +223,15 @@ CASignUpScreen::run()
//CL_Input::chain_button_release.remove( this );
CL_Keyboard::sig_key_up().disconnect(slot);
- return (cancel ? -1 : cursor+offset);
+ std::vector<std::string>::const_iterator it = std::find(CA_APP->trackList.begin(), CA_APP->trackList.end(), m_trackList[cursor]);
+
+ //return (cancel ? -1 : cursor+offset);
+ return (cancel ? -1 : it-CA_APP->trackList.begin());
+}
+
+int CASignUpScreen::getRaceLevel()
+{
+ return cursor;
}
/** Builds the screen.
@@ -151,7 +253,7 @@ CASignUpScreen::buildScreen()
// Cursor:
//
- CL_Display::fill_rect( CL_Rect(racePreview[cursor]->getLeft()-12, racePreview[cursor]->getTop()-28,
+ CL_Display::fill_rect( CL_Rect(racePreview[cursor]->getLeft()-12, racePreview[cursor]->getTop()-12,
racePreview[cursor]->getRight()+12, racePreview[cursor]->getBottom()+12),
CL_Color (255, 216, 84, (int)((cursorAnim/2)*255) ));
@@ -159,15 +261,31 @@ CASignUpScreen::buildScreen()
// Race previews:
//
- for( int i=0; i<3; ++i ) {
- if( racePreview[i] ) {
- racePreview[i]->display();
- //CA_RES->font_normal_14_white->print_center( racePreview[i]->getHCenter(),
- // racePreview[i]->getTop()-22,
- // (i==0 ? "Easy" : (i==1 ? "Medium" : "Hard")) );
+ for( int race=0; race<3; ++race )
+ {
+ if( racePreview[race] )
+ {
+ racePreview[race]->display();
+ CA_RES->font_normal_14_white->draw( racePreview[race]->getHCenter(),
+ racePreview[race]->getTop()-22,
+ (race==0 ? "Easy" : (race==1 ? "Medium" : "Hard")) );
+ }
+ if (m_selected == true)
+ {
+ for (unsigned int pl=0; pl<m_RacePlayer[race].size(); pl++)
+ {
+ CA_RES->font_normal_14_white->draw (racePreview[race]->getHCenter(),
+ racePreview[race]->getBottom()+22*(pl+1), m_StringRacePlayer[race][pl] );
+ }
}
-
}
+
+
+ //
+ // UpgradesPanel
+ UpgradesPanel uPanel(CA_APP->player[0], CA_RES->font_normal_14_white, CA_RES->font_lcd_13_green, racePreview[2]->getRight() + 32, racePreview[0]->getTop()-22);
+ uPanel.display();
+
}
/** Called on key release.
@@ -180,20 +298,30 @@ CASignUpScreen::on_key_released (const CL_InputEvent &key)
// Cancel (ESC):
//
case CL_KEY_ESCAPE:
- cancel = true;
- done = true;
+ {
+ if (!m_selected)
+ {
+ cancel = true;
+ done = true;
+ }
+ else
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 ); // do not allow to echap when the user has selected
+ }
break;
// Left:
//
case CL_KEY_LEFT:
case CL_KEY_N:
- if( cursor>0 ) {
- cursor--;
- playSwitchSound();
- } else if( offset>0 ) {
- setOffset( offset-1 );
- playSwitchSound();
+ if (!m_selected)
+ {
+ if( cursor>0 ) {
+ cursor--;
+ playSwitchSound();
+ } /*else if( offset>0 ) {
+ setOffset( offset-1 );
+ playSwitchSound();
+ }*/
}
break;
@@ -201,12 +329,15 @@ CASignUpScreen::on_key_released (const CL_InputEvent &key)
//
case CL_KEY_RIGHT:
case CL_KEY_M:
- if( cursor<2 && cursor<numTracks-1 ) {
- cursor++;
- playSwitchSound();
- } else if( offset<numTracks-3 ) {
- setOffset( offset+1 );
- playSwitchSound();
+ if (!m_selected)
+ {
+ if( cursor<2 && cursor<numTracks-1 ) {
+ cursor++;
+ playSwitchSound();
+ } /*else if( offset<numTracks-3 ) {
+ setOffset( offset+1 );
+ playSwitchSound();
+ }*/
}
break;
@@ -214,7 +345,22 @@ CASignUpScreen::on_key_released (const CL_InputEvent &key)
//
case CL_KEY_ENTER:
case CL_KEY_SPACE:
- done = true;
+ {
+ if (m_selected == true)
+ {
+ done = true;
+ }
+ else
+ {
+ m_RacePlayer[cursor][0] = CA_APP->player[0];
+ std::vector<Player*>::const_iterator it = std::find(m_Player.begin(), m_Player.end(), m_RacePlayer[cursor][0]); // we trying to find the rank of the player
+ std::ostringstream oss;
+ oss << it - m_Player.begin() +1 << ") " << (*it)->getName();
+ m_StringRacePlayer[cursor][0] = oss.str();
+ m_selected = true;
+ help = "press Enter to continue";
+ }
+ }
break;
default:
@@ -227,4 +373,10 @@ CASignUpScreen::playSwitchSound() {
if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
}
+std::vector<int>
+CASignUpScreen::getTrackNumbers() const
+{
+ return m_trackNumbers;
+}
+
// EOF
diff --git a/src/casignupscreen.h b/src/casignupscreen.h
index f003770..7dc6487 100644
--- a/src/casignupscreen.h
+++ b/src/casignupscreen.h
@@ -3,20 +3,25 @@
#include <ClanLib/display.h>
-#include "caimageview.h"
+
#include "cascreen.h"
+#include <vector>
+
+class Player;
+class CAImageView;
/** The sign-up screen shown before the race to choose the track.
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
class CASignUpScreen : public CAScreen {
public:
- CASignUpScreen();
+ CASignUpScreen(std::vector<Player*> player, std::vector<int> trackNumbers);
~CASignUpScreen();
void reset();
- void setOffset( int o );
+ void setOffset( int offset );
virtual int run();
virtual void buildScreen();
@@ -25,6 +30,16 @@ public:
void playSwitchSound();
+ int getRaceLevel();
+
+ std::vector<Player*> getRacePlayers();
+
+ std::vector<std::vector<Player*> > getAllRunningPlayers();
+
+ void addVirtualPoints();
+
+ std::vector<int> getTrackNumbers() const;
+
private:
//! Cursor (selected race)
@@ -45,6 +60,19 @@ private:
int bottom;
//! Number of tracks available
int numTracks;
+ //! to know if the player has selected a race
+ bool m_selected;
+ //! Array of Players
+ std::vector<Player*> m_Player;
+ //! Array of Players who are running in the 3 races
+ std::vector<std::vector<Player*> > m_RacePlayer;
+ //! Array of the string uses to show the competitor of a race
+ std::vector<std::vector<std::string> > m_StringRacePlayer;
+ //! 3 Track directory chosen
+ std::vector<std::string> m_trackList;
+ //! 3 Track number chosen
+ std::vector<int> m_trackNumbers;
+
public:
CL_Slot slot;
diff --git a/src/caslotselectiondialog.cpp b/src/caslotselectiondialog.cpp
index b292c33..55d64ae 100644
--- a/src/caslotselectiondialog.cpp
+++ b/src/caslotselectiondialog.cpp
@@ -1,27 +1,76 @@
#include "caslotselectiondialog.h"
#include "catrophy.h"
+#include "upgradespanel.h"
+#include "humanplayer.h"
+#include <fstream>
/** Constructor.
\param title Title of the dialog (Usually "Save..." or "Load...")
*/
-CASlotSelectionDialog::CASlotSelectionDialog( const char* title )
- : CADialog() {
+CASlotSelectionDialog::CASlotSelectionDialog( const std::string title, CL_Font* font, const std::string& homedir )
+ : CADialog(),
+ m_font(font),
+ m_homedir(homedir)
+{
cursor = 0;
this->title = title;
help = "Use Arrow Keys to change selection and press Enter to\nconfirm";
left = (CA_APP->width - 320)/2;
right = CA_APP->width - left;
- top = CA_APP->headerHeight;
- bottom = top + 400;
+ top = CA_APP->headerHeight+20;
+ bottom = top + 390;
+ // Set the position of the text box on the right side of the car image
+ m_guiBox.setPosition( left, top, right, bottom);
+ // check for existing file
+ for (int i=0; i<10; ++i)
+ {
+ std::ostringstream oss;
+ oss << m_homedir << "trophySave" << i << ".sav";
+ if( CA_APP->debug ) std::cout << "File Saved to " << oss.str() << std::endl;
+ std::ifstream loadFile(oss.str().c_str());
+ if (loadFile)
+ {
+ std::string name;
+ // Version, difficulty, nbTurns, currentTrack1, currentTrack2, currentTrack3, name
+ for (int i =0; i<7; ++i)
+ std::getline( loadFile, name ); // name is on the seventh line
+
+ // TODO: This code should probably be in player.cpp
+ int carNumber, currentMotor, currentTires, currentArmor, h, s, v, money, totalPoints;
+ loadFile >> carNumber >> currentMotor >> currentTires >> currentArmor >> h >> s >> v >> money >> totalPoints;
+ HumanPlayer* player = new HumanPlayer(0, name,carNumber);
+ player->setName(name);
+ player->setCarNumber(carNumber);
+ player->getCar()->getMotor()->setCurrent(currentMotor);
+ player->getCar()->getTires()->setCurrent(currentTires);
+ player->getCar()->getArmor()->setCurrent(currentArmor);
+ HSVColor color(h, s, v);
+ player->setColor(color);
+ player->setMoney(money);
+ player->setTotalPoints(totalPoints);
+
+ m_slotPlayers.push_back(player);
+ m_slotNames.push_back(name);
+ }
+ else
+ {
+ m_slotPlayers.push_back(NULL);
+ m_slotNames.push_back("Free Slot");
+ }
+ }
}
/** Destructor.
*/
-CASlotSelectionDialog::~CASlotSelectionDialog() {}
+CASlotSelectionDialog::~CASlotSelectionDialog()
+{
+ for (unsigned int i=0; i<m_slotPlayers.size(); ++i)
+ delete m_slotPlayers[i];
+}
@@ -34,14 +83,35 @@ CASlotSelectionDialog::buildScreen() {
// Backgroud:
//
- CA_RES->menu_bg->draw ( CL_Rect(0, 0, CA_APP->width, CA_APP->height) );
+ CA_RES->menu_bg->draw ( CL_Rect(0, 0, CA_APP->width, CA_APP->height) ); // TODO don't use CA_APP
// Title / help:
//
displayTitle();
displayHelp();
+ // GuiBox:
+ //
+ m_guiBox.display();
+
+ // Text:
+ //
+ std::string slotsText;
+ for (unsigned int i=0; i<m_slotNames.size(); ++i)
+ {
+ slotsText += m_slotNames[i] + "\n\n";
+ }
+ const int topTxt = m_guiBox.getTop() + CA_RES->gui_border1->get_height() + 10;
+ m_font->draw ( m_guiBox.getHCenter(), topTxt, slotsText);
+ // Cursor
+ //
+ const int fh = m_font->get_height(); //Font Height
+ const int curLeft = m_guiBox.getLeft() + CA_RES->gui_border2->get_width() + 5;
+ const int curTop = cursor*fh*2+topTxt;
+ CA_RES->menu_cursorani->draw (curLeft, curTop);
+ CA_RES->menu_cursorani->update();
+
// Cursor:
//
@@ -51,9 +121,39 @@ CASlotSelectionDialog::buildScreen() {
*/
//CA_RES->advanceAnimation( &cursorAnim, 1, 2.0, CAResources::Revolving );
-}
+
+ //
+ // UpgradesPanel
+ // TODO: Should use something better to know if it's save or load
+ if (title[0] == 'S')
+ {
+ UpgradesPanel uPanelCurrent(CA_APP->player[0], m_font, CA_RES->font_lcd_13_green, m_guiBox.getLeft()-CA_APP->player[0]->getCar()->surface3d->get_width()-32, top+32);
+ uPanelCurrent.display();
+ }
+ if (m_slotPlayers[cursor])
+ {
+ UpgradesPanel uPanel(m_slotPlayers[cursor], m_font, CA_RES->font_lcd_13_green, m_guiBox.getRight()+32, top+32);
+ uPanel.display();
+ }
+
+}
+/** Runs the dialog and return file string
+*/
+std::string
+CASlotSelectionDialog::display()
+{
+ int isDialogOK = CADialog::run();
+ if (isDialogOK)
+ {
+ std::ostringstream oss;
+ oss << "trophySave" << cursor << ".sav";
+ return oss.str();
+ }
+ else
+ return "";
+}
/** Called on key release.
*/
@@ -91,7 +191,12 @@ CASlotSelectionDialog::on_key_released (const CL_InputEvent &key)
//
case CL_KEY_ENTER:
case CL_KEY_SPACE:
- done = true;
+ {
+ if (m_slotPlayers[cursor] || title[0] == 'S')
+ done = true;
+ else
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ }
break;
default:
diff --git a/src/caslotselectiondialog.h b/src/caslotselectiondialog.h
index d63921e..9b53e32 100644
--- a/src/caslotselectiondialog.h
+++ b/src/caslotselectiondialog.h
@@ -3,23 +3,38 @@
#include <ClanLib/core.h>
#include "cadialog.h"
+class HumanPlayer;
/** Dialog which shows the slots for saving or loading a game.
@author Andrew Mustun
*/
class CASlotSelectionDialog : public CADialog {
public:
- CASlotSelectionDialog( const char* title );
+ CASlotSelectionDialog( const std::string title, CL_Font* font, const std::string& homedir );
~CASlotSelectionDialog();
+ std::string display();
virtual void buildScreen();
virtual void on_key_released (const CL_InputEvent &key);
private:
//! Cursor (selected slot)
-
int cursor;
+
+ //! The font use for displaying information
+ CL_Font* m_font;
+
+ //! home directory where the saveFile are
+ const std::string& m_homedir;
+
+ //! PreLoaded Humans Players for all save Slot (use in Upgrade Panel)
+ std::vector<HumanPlayer*> m_slotPlayers;
+
+ // Player names in each save slot
+ std::vector<std::string> m_slotNames;
+
+
};
#endif
diff --git a/src/castringlist.cpp b/src/castringlist.cpp
deleted file mode 100644
index dbd2161..0000000
--- a/src/castringlist.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-#include "castringlist.h"
-
-
-
-/** Constructor.
-*/
-CAStringList::CAStringList( char separator ) {
- this->list = "";
- this->separator = separator;
-}
-
-
-
-/** Constructor.
-*/
-CAStringList::CAStringList( const char* list, char separator ) {
- this->list = list;
- this->separator = separator;
-}
-
-
-
-/** Destructor.
-*/
-CAStringList::~CAStringList() {}
-
-
-
-/** Count.
-*/
-int
-CAStringList::count() {
- int ret=1;
-
- for( unsigned int i = 0; i < list.length(); ++i )
- {
- if( list[i]==separator ) {
- ++ret;
- }
- }
-
- return ret;
-}
-
-
-
-/** Returns item number 'which' of the list.
- \param maxLen Max length of the sting to return. Default: 128
-*/
-const char*
-CAStringList::getItem( int which, int maxLen ) {
- unsigned int i = 0;
- int j = 0;
- int found = 0;
- item = "";
-
- while( i < list.length() && found < which )
- {
- if( list[i]==separator ) {
- ++found;
- }
- ++i;
- }
-
- j = list.find( '~', i );
-
- if( j == -1 )
- {
- j = list.length();
- }
-
- item = list.substr( i, j-i );
-
- return item.c_str();
-}
-
-
-
-// EOF
diff --git a/src/castringlist.h b/src/castringlist.h
deleted file mode 100644
index 6dadf11..0000000
--- a/src/castringlist.h
+++ /dev/null
@@ -1,37 +0,0 @@
-#ifndef CASTRINGLIST_H
-#define CASTRINGLIST_H
-
-#include <ClanLib/core.h>
-
-#define CA_SL_ITEMSIZE 128
-
-/** A simple string list implemented by strings with given separators.
- It's not fast, not good, but simple.
- @author Andrew Mustun
-*/
-class CAStringList {
-public:
- CAStringList( char separator='~' );
- CAStringList( const char* list, char separator='~' );
- ~CAStringList();
-
- /** Sets the string list.
- \param list The new list in format "entry 1~entry2~entry3".
- */
- void setList( const char* list ) {
- this->list = list;
- }
- int count();
- const char* getItem( int which, int maxLen=CA_SL_ITEMSIZE );
-
-private:
- //! The list as one string.
-
- std::string list;
- //! One item. Which depends on the last action.
- std::string item;
- //! Separator character (default: '~').
- char separator;
-};
-
-#endif
diff --git a/src/catrack.h b/src/catrack.h
deleted file mode 100644
index 21e0b28..0000000
--- a/src/catrack.h
+++ /dev/null
@@ -1,42 +0,0 @@
-#ifndef CATRACK_H
-#define CATRACK_H
-
-#include <ClanLib/core.h>
-
-/** Structure for the current track.
- @author Andrew Mustun
-*/
-struct CATrack {
- //! Track number
- int number;
- //! Track directory name (e.g. "Loops")
- std::string file;
- //! Track name
- std::string name;
- //! Version information (e.g. "0.0.1")
- std::string version;
- //! Author of this track
- std::string author;
- //! Initial angle of players (0=right, 90=bottom (!))
- int startAngle;
- //! Route points (Usually 1 route per player with x/y)
- int rp[CA_MAXPLAYERS]
- [CA_MAXROUTEPOINTS]
- [2];
- //! Number of route points in this track
- int routePoints;
- //! Pointer to function map
- // TODO : check that PixelBuffer is really what we want. It could (and I think it does) introduce bugs
- // in AI because PixelBuffer height and width are power of 2
- CL_PixelBuffer* functionMap;
- //! Pointer to visual map
- CL_Surface* visualMap;
- //! Pointer to bridge surface or NULL if there's no bridge
- CL_Surface* bridge;
- //! Bridge position
- int bridgePos[2];
-};
-
-#endif
-
-// EOF
diff --git a/src/catrophy.cpp b/src/catrophy.cpp
index 5183979..70f5e02 100644
--- a/src/catrophy.cpp
+++ b/src/catrophy.cpp
@@ -1,4 +1,3 @@
-#include <stdio.h>
#ifdef W32_BCC551
/* dont include stl.h for Windoof, Borland C++ 5.5.1 */
@@ -11,22 +10,30 @@
#include <ClanLib/core.h>
#include <ClanLib/display.h>
-#include <math.h>
-//#include <unistd.h>
+#include <cmath>
+#include <fstream>
+#include <sstream>
-#include "cacartype.h"
+#include "cartype.h"
#include "cacredits.h"
+#include "caconfigurekey.h"
#include "caimagemanipulation.h"
#include "cainfodialog.h"
+#include "caescapedialog.h"
#include "capositiontable.h"
#include "cagoody.h"
#include "catrophy.h"
-#include "caplayer.h"
+#include "humanplayer.h"
+#include "computerplayer.h"
#include "caplayersettingsdialog.h"
#include "capanel.h"
#include "capositiontableview.h"
#include "camenu.h"
#include "casignupscreen.h"
+#include "cachampionshipscreen.h"
+#include "caslotselectiondialog.h"
+#include "shopscreen.h"
+#include "windialog.h"
// Global instance of the application needed by the ClanLib main():
//
@@ -51,11 +58,12 @@ CATrophy::main( int argc, char** argv )
{
// Default paramters:
//
+ display_window = NULL;
debug = false;
trackInfo = false;
framesPerSec = 40;
- width = CA_WIDTH;
- height = CA_HEIGHT;
+ resolution = CA_RESOLUTION;
+ m_cheatMoney = false;
fullScreen = false;
fast = false;
server = false;
@@ -65,6 +73,11 @@ CATrophy::main( int argc, char** argv )
strcpy( serverIp, "0.0.0.0" );
serverPort = 18805;
difficulty = Medium;
+ m_ConfigureKey = NULL;
+ m_isGameStarted = false;
+ m_nbTurns = 0;
+ m_gameLoopState = 0;
+
// Proccess parameters:
//
@@ -90,6 +103,7 @@ CATrophy::main( int argc, char** argv )
std::cout << "--debug, -d : active debugging information" << std::endl;
std::cout << "--trackinfo" << std::endl;
std::cout << "--help, -h : show this help message" << std::endl;
+ std::cout << "--bigmoney : start with $75,000" << std::endl;
std::cout << "--fullscreen, -f : fullscreen" << std::endl;
std::cout << "--fast" << std::endl;
std::cout << "--640x480, --800x600, --1024x768 : use corresponding resolution" << std::endl;
@@ -100,6 +114,11 @@ CATrophy::main( int argc, char** argv )
exit(0);
}
+ else if( !strcmp(argv[c], "--bigmoney" ) )
+ {
+ m_cheatMoney = true;
+ }
+
// Graphic options:
//
else if( !strcmp(argv[c], "--fullscreen" ) || !strcmp(argv[c], "-f") ) {
@@ -107,14 +126,11 @@ CATrophy::main( int argc, char** argv )
} else if( !strcmp(argv[c], "--fast" ) ) {
fast = true;
} else if( !strcmp(argv[c], "--640x480" ) ) {
- width = 640;
- height = 480;
+ resolution = "640x480";
} else if( !strcmp(argv[c], "--800x600" ) ) {
- width = 800;
- height = 600;
+ resolution = "800x600";
} else if( !strcmp(argv[c], "--1024x768" ) ) {
- width = 1024;
- height = 768;
+ resolution = "1024x768";
}
// Audio options:
@@ -147,15 +163,17 @@ CATrophy::main( int argc, char** argv )
// Some layout things:
//
panelWidth = 120;
- headerHeight = (int)((float)height/4.2f);
+
// Init sound:
//
CL_SetupSound setup_sound;
- CL_SoundOutput sound_output(44100);
+ sound_output = new CL_SoundOutput(44100);
reconfigure();
+ headerHeight = (int)((float)height/4.2f);
+
// Load resources:
//
CAResources::getResources();
@@ -166,18 +184,35 @@ CATrophy::main( int argc, char** argv )
// Init everything:
//
- initCarTypes();
+
+ initUpgrades();
loading.setProgress( 60 );
+ initCarTypes();
initGoodies();
initPlayers();
// initNetwork();
- initPanel();
+ // initPanel();
initTrackList();
- track.visualMap = 0;
- track.functionMap = 0;
- track.bridge = 0;
- track.file = "";
+ // Create user data if needed
+#ifndef WIN32
+ m_homedir = std::string(getenv("HOME"));
+#else
+ m_homedir = std::string(getenv("APPDATA")); // For windows
+#endif
+ m_homedir = m_homedir + "/.trophy/";
+
+ CL_DirectoryScanner checker;
+ if (checker.scan(m_homedir))
+ {
+ if (debug) std::cout << m_homedir << " exists" << std::endl;
+ }
+ else
+ {
+ if (debug) std::cout << m_homedir << " doesn't exist" << std::endl;
+ CL_Directory::create(m_homedir);
+ }
+
loading.end();
@@ -187,12 +222,14 @@ CATrophy::main( int argc, char** argv )
// Deinit everything:
//
- deinitTrack();
- deinitPanel();
+ delete m_track;
+ // deinitPanel();
// deinitNetwork();
deinitPlayers();
deinitGoodies();
+ deinitUpgrades();
deinitCarTypes();
+ delete m_ConfigureKey;
// TODO : The only way I found to restore properly the resolution before exiting
if(fullScreen) display_window->set_windowed();
@@ -216,11 +253,13 @@ CATrophy::main( int argc, char** argv )
/** Gets the application title.
Needed by ClanLib.
*/
-const char*
+const std::string
CATrophy::get_title() {
return "Trophy " VERSION;
}
+
+
/** Initializes car types.
*/
void
@@ -228,69 +267,11 @@ CATrophy::initCarTypes()
{
if(debug) std::cout << "initCarTypes begin" << std::endl;
- for( int i=0; i<CA_NUMCARTYPES; ++i )
- {
- if(debug) std::cout << " car # " << i << std::endl;
-
- std::string mainPath = "cars/";
- std::string path;
- switch( i )
- {
- case 0:
- mainPath += "vw/";
- break;
- case 1:
- mainPath += "jeep/";
- break;
- case 2:
- mainPath += "z3/";
- break;
- case 3:
- mainPath += "flash2/";
- break;
- default:
- break;
- }
-
- if(debug) std::cout << " name" << std::endl;
-
- path = mainPath + "name";
- carType[i].name = CL_String::load( path, CA_RES->resources );
-
- if(debug) std::cout << " surface" << std::endl;
-
- path = mainPath + "surface";
- carType[i].surface = new CL_Surface( path, CA_RES->resources );
-
- if(debug) std::cout << " surface3d" << std::endl;
-
- path = mainPath + "surface3d";
- carType[i].surface3d = new CL_Surface( path, CA_RES->resources );
-
- path = mainPath + "length";
- carType[i].length = CL_Integer( path, CA_RES->resources );
- path = mainPath + "width";
- carType[i].width = CL_Integer( path, CA_RES->resources );
- path = mainPath + "maxSpeed";
- carType[i].maxSpeed = 6 * CL_Integer( path, CA_RES->resources );
- path = mainPath + "minSpeed";
- carType[i].minSpeed = 6 * CL_Integer( path, CA_RES->resources );
- path = mainPath + "maxTurbo";
- carType[i].maxTurbo = CL_Integer( path, CA_RES->resources );
- path = mainPath + "acceleration";
- carType[i].acceleration = 6 * CL_Integer( path, CA_RES->resources );
- path = mainPath + "deceleration";
- carType[i].deceleration = 6 * CL_Integer( path, CA_RES->resources );
- path = mainPath + "steeringPower";
- carType[i].steeringPower = CL_Integer( path, CA_RES->resources );
- path = mainPath + "slidingFactor";
- carType[i].slidingFactor = 0.01 * CL_Integer( path, CA_RES->resources );
- path = mainPath + "price";
- carType[i].price = CL_Integer( path, CA_RES->resources );
-
- carType[i].radius = std::sqrt( (double)carType[i].width/2 * (double)carType[i].width/2 + (double)carType[i].length/2 * (double)carType[i].length/2 );
- carType[i].angle = atan( (double)(carType[i].width/2) / (double)(carType[i].length/2) ) * ARAD;
- }
+ std::string mainPath = "cars/";
+ carType.push_back(CarType(mainPath+"vw/", CA_RES->resources, carUp, debug));
+ carType.push_back(CarType(mainPath+"jeep/", CA_RES->resources, carUp, debug));
+ carType.push_back(CarType(mainPath+"z3/", CA_RES->resources, carUp, debug));
+ carType.push_back(CarType(mainPath+"flash2/", CA_RES->resources, carUp, debug));
if(debug) std::cout << "initCarTypes end" << std::endl;
}
@@ -313,36 +294,46 @@ CATrophy::deinitCarTypes()
if(debug) std::cout << "deinitCarTypes end" << std::endl;
}
-/** Initializes goody types and instances.
+/** Initializes car upgrades
*/
-void
-CATrophy::initGoodies()
+void CATrophy::initUpgrades()
{
- goodyType[0].name = "Turbo";
- goodyType[0].surface = CA_RES->goody_turbo;
- goodyType[0].life = 30000;
-
- goodyType[1].name = "Life";
- goodyType[1].surface = CA_RES->goody_life;
- goodyType[1].life = 30000;
-
- goodyType[2].name = "Money";
- goodyType[2].surface = CA_RES->goody_money;
- goodyType[2].life = 15000;
+ if(debug) std::cout << "initUpgrades begin" << std::endl;
+ carUp = new CACarUpgrades();
+ if(debug) std::cout << "initUpgrades end" << std::endl;
+}
- goodyType[3].name = "Bullets";
- goodyType[3].surface = CA_RES->goody_bullets;
- goodyType[3].life = 30000;
+/** Deinitializes car upgrades
+*/
+void CATrophy::deinitUpgrades()
+{
+ if(debug) std::cout << "deinitUpgrades begin" << std::endl;
+ delete carUp;
+ carUp = 0;
+ if(debug) std::cout << "deinitUpgrades end" << std::endl;
+}
- goodyType[4].name = "Fogbomb";
- goodyType[4].surface = CA_RES->goody_fogbomb;
- goodyType[4].life = 10000;
+/** Initializes goody types and instances.
+*/
+void
+CATrophy::initGoodies()
+{
+ goodyType.push_back(new CAGoodyTypeDerived<Turbo> (CA_RES->goody_turbo, 30000, CA_RES->effectGoodyTurbo));
+ goodyType.push_back(new CAGoodyTypeDerived<Life> (CA_RES->goody_life, 30000, CA_RES->effectGoodyLife));
+ goodyType.push_back(new CAGoodyTypeDerived<Money> (CA_RES->goody_money, 15000, CA_RES->effectGoodyMoney));
+ goodyType.push_back(new CAGoodyTypeDerived<Bullets> (CA_RES->goody_bullets, 30000, CA_RES->effectGoodyBullets));
+ goodyType.push_back(new CAGoodyTypeDerived<FogBombs> (CA_RES->goody_fogbomb, 10000, CA_RES->effectGoodyFogbomb));
+
// Create goody instances:
//
- for( int gt=0; gt<CA_NUMGOODYTYPES; gt++ ) {
- for( int gi=0; gi<CA_NUMGOODIES; gi++ ) {
- goody[gt][gi] = new CAGoody( &goodyType[gt] );
+ for( unsigned int gt=0; gt<goodyType.size(); gt++ )
+ {
+ std::vector<CAGoody*> vecGoody;
+ goody.push_back(vecGoody);
+ for( int gi=0; gi<CA_NUMGOODIES; gi++ )
+ {
+ goody[gt].push_back(new CAGoody( goodyType[gt] ));
}
}
}
@@ -352,12 +343,13 @@ CATrophy::initGoodies()
void
CATrophy::deinitGoodies()
{
- for( int gt=0; gt<CA_NUMGOODYTYPES; gt++ ) {
- for( int gi=0; gi<CA_NUMGOODIES; gi++ ) {
- if( goody[gt][gi] ) delete goody[gt][gi];
- goody[gt][gi] = 0;
- }
- }
+ for( unsigned int gt=0; gt<goody.size(); gt++ )
+ for( unsigned int gi=0; gi<goody[gt].size(); gi++ )
+ if( goody[gt][gi] )
+ {
+ delete goody[gt][gi];
+ goody[gt][gi] = 0;
+ }
}
/** Initializes the players.
@@ -370,26 +362,20 @@ CATrophy::initPlayers()
{
if(debug) std::cout << "initPlayers begin" << std::endl;
- int ct=0;
- for(int pl=0; pl<CA_MAXPLAYERS; ++pl) {
- player[pl] = new CAPlayer( pl, "", 0,
- ((pl==0) ? CAPlayer::Keyboard : CAPlayer::Computer) );
- if( pl!=0 ) {
- int sat = CAMath::getRandomNumber( -90, 20 );
- int val = CAMath::getRandomNumber( -60, 0 );
- player[pl]->setColor( CAColor((int)((float)pl/CA_MAXPLAYERS*360),sat,val) );
+ for(int pl=0; pl<CA_MAXPLAYERS; ++pl)
+ {
+ if (pl == 0)
+ {
+ HumanPlayer* theHumanPlayer = new HumanPlayer( pl, "", 0 );
+ player.push_back( theHumanPlayer );
+ m_ConfigureKey = new CAConfigureKey(theHumanPlayer);
}
- ++ct;
- if( ct>=CA_NUMCARTYPES ) ct=0;
+ else
+ player.push_back ( new ComputerPlayer( pl, "", 0));
+
loading.setProgress( 60.0 + 40.0/CA_MAXPLAYERS*pl );
}
- player[0]->setName( "Andrew" );
- if( CA_MAXPLAYERS>1 ) player[1]->setName( "Greenhorn" );
- if( CA_MAXPLAYERS>2 ) player[2]->setName( "Dark Rider" );
- if( CA_MAXPLAYERS>3 ) player[3]->setName( "Speedy Joe" );
- if( CA_MAXPLAYERS>4 ) player[4]->setName( "Sunnyboy" );
- if( CA_MAXPLAYERS>5 ) player[5]->setName( "Jane" );
if(debug) std::cout << "initPlayers end" << std::endl;
}
@@ -457,157 +443,42 @@ CATrophy::deinitPanel()
void
CATrophy::initTrackList()
{
- trackList.setList( CL_String::load("tracks/directories", CA_RES->resources).c_str() );
- //trackList.setList( "Downtown~Zigzag~Loops~Zurich~Moon~Snake~Rally" );
+ std::istringstream iss ( CL_String::load("tracks/directories", CA_RES->resources).c_str() );
+ std::string temp;
+ while (std::getline(iss,temp, '~'))
+ trackList.push_back(temp);
}
/** Initializes track with given name.
*/
void
-CATrophy::initTrack( std::string trackName )
+CATrophy::initRace( const std::string& trackName )
{
loading.begin();
if(debug) std::cout << "Init track begin" << std::endl;
- // Base path of track files:
- //
- std::string trackPath = std::string("tracks/") + trackName + "/";
-
- // Load visual map:
- //
- std::string vmapPath = trackPath + "vmap.tga";
- if( track.visualMap != NULL ) delete track.visualMap;
- try
- {
- track.visualMap = new CL_Surface(CL_ProviderFactory::load(vmapPath));
- }
- catch(CL_Error err)
- {
- trackPath = std::string("../resources/tracks/") + trackName + "/";
- vmapPath = trackPath + "vmap.tga";
- track.visualMap = new CL_Surface(CL_ProviderFactory::load(vmapPath));
- }
-
- loading.setProgress( 15 );
+ m_track = new Track(trackName, debug);
- // Load functional map:
- //
- std::string fmapPath = trackPath + "fmap.tga";
- if( track.functionMap != NULL ) delete track.functionMap;
- // We need to load a surface and then create the pixelbuffer if we don't want to loose the information
- // about the color. Don't know if it is a bug of ClanLib or the normal behavior.
- track.functionMap = new CL_PixelBuffer( ((CL_Surface)CL_ProviderFactory::load(fmapPath)).get_pixeldata() );
- // TODO : is it OK if we never unlock it ? functionMap is not meant to be drawn
- track.functionMap->lock();
-
- loading.setProgress( 30 );
-
- // Reset bridge:
- //
- if( track.bridge!=0 ) {
- delete track.bridge;
- track.bridge = 0;
- }
-
- // Read config file for this track:
- //
- FILE* fp;
- std::string configFilePath = trackPath + "config.tck";
- // CL_String( "tracks/" ).append( trackName ).append( "/config.tck" );
-
- if(debug) printf( "%s\n", configFilePath.c_str() );
-
- track.routePoints = 0;
+ loading.setProgress( 40 );
- if( (fp = fopen( configFilePath.c_str(), "rt" )) != NULL )
+ std::vector<int> possiblesRn;
+ for( int i=0; i<CA_RACEMAXPLAYERS; i++ )
{
- char c_line[128]; // A line (Author = "Andrew Mustun")
- std::string line; // The line converted to a string
- std::string name; // Name of the value (Author)
- std::string value; // Value (Andrew Mustun)
- int i, j;
- int xv=0, yv=0, zv=0; // Coordinates for following objects
- int iv=0; // Index for followint object (route point)
-
- while ( !feof( fp ) ) {
-
- fgets( c_line, 127, fp );
- line = c_line;
-
- if( line[0]!='#' && line.length()!=0 ) {
-
- i = std::string( line ).find_first_of( " =" );
- name = line.substr( 0, i );
- i = std::string( line ).find ('"', i) + 1;
- j = std::string( line ).find ('"', i);
- value = line.substr( i, j-i );
-
-
- // General track info:
- //
- if( name=="Author" ) track.author = value;
- else if( name=="Version") track.version = value;
- else if( name=="Name" ) track.name = value;
-
- // Coordinates of next object / route point:
- //
- else if( name=="x" ) xv = atoi( value.c_str() );
- else if( name=="y" ) yv = atoi( value.c_str() );
- else if( name=="z" ) zv = atoi( value.c_str() );
- else if( name=="i" ) iv = atoi( value.c_str() );
-
- // Start angle:
- //
- else if( name=="startAngle" ) track.startAngle = atoi( value.c_str() );
-
- // Route points:
- //
- else if( name=="RP" ) {
- int pi = atoi( value.c_str() );
- if (pi<CA_MAXROUTEPOINTS && iv<CA_MAXPLAYERS) {
- track.rp[iv][pi][0] = xv;
- track.rp[iv][pi][1] = yv;
- if (pi+1>track.routePoints) track.routePoints = pi+1;
- }
- }
-
- // Objects:
- //
- else if( name=="Object" ) {
- if( value=="bridge" ) {
- std::string bridgePath = trackPath + value + ".tga";
- track.bridge = new CL_Surface(CL_TargaProvider(bridgePath));
- track.bridgePos[0] = xv;
- track.bridgePos[1] = yv;
- }
- }
- }
- }
- fclose( fp );
+ possiblesRn.push_back(i);
}
- loading.setProgress( 40 );
-
- // Place and reset players:
- //
- for( int pl=0; pl<CA_MAXPLAYERS; pl++ ) {
+ for( int pl=0; pl<CA_RACEMAXPLAYERS; pl++ )
+ {
int rn;
- bool done;
- do {
- done = true;
- rn = CAMath::getRandomNumber( 0, CA_MAXPLAYERS-1 );
- for( int pl2=0; pl2<pl; ++pl2 ) {
- if( player[pl2]->getRouteNumber()==rn ) done=false;
- }
- } while( !done );
-
- player[pl]->resetForRace();
- player[pl]->initPlayer( rn );
-
+ int pos = TrophyMath::getRandomNumber( 0, possiblesRn.size() -1);
+ rn = possiblesRn[pos];
+ possiblesRn.erase(possiblesRn.begin()+pos);
+ m_RacePlayer[pl]->resetForRace( rn, m_track);
loading.setProgress( 50.0 + 50.0/CA_MAXPLAYERS*pl );
}
+
// Reset starting light:
//
lightState = 0;
@@ -615,7 +486,7 @@ CATrophy::initTrack( std::string trackName )
// Reset time:
//
time = 0;
- strcpy( timeString, "00:00.00" );
+ timeString = "00:00.00";
// Reset some other things which must be reset for each lap:
//
@@ -625,28 +496,11 @@ CATrophy::initTrack( std::string trackName )
resetGoodies();
resetFogBombs();
resetDustClowds();
- CA_POSITIONTABLE->resetRace();
+ CAPositionTable::getPositionTable()->resetRace();
if(debug) std::cout << "Init track end" << std::endl;
}
-/** Deinitializes and deletes current track.
-*/
-void
-CATrophy::deinitTrack() {
- if( track.visualMap!=0 ) delete track.visualMap;
- track.visualMap = 0;
-
- if( track.functionMap != NULL )
- {
- delete track.functionMap;
- track.functionMap = NULL;
- }
-
- if( track.bridge!=0 ) delete track.bridge;
- track.bridge = 0;
-}
-
/** Reconfigures parameters. Called by the configure menu.
*/
void
@@ -655,6 +509,12 @@ CATrophy::reconfigure()
static bool firstCall = true;
static bool lastFullScreen = fullScreen;
+ sound_output->set_global_volume(volume/(float)10);
+ std::size_t pos = resolution.find('x');
+ std::istringstream issW (resolution.substr(0, pos));
+ issW >> width;
+ std::istringstream issH (resolution.substr(pos+1));
+ issH >> height;
if(firstCall)
{
try
@@ -668,7 +528,7 @@ CATrophy::reconfigure()
}
lastFullScreen = fullScreen;
}
- else if(lastFullScreen != fullScreen )
+ else if (lastFullScreen != fullScreen )
{
if(fullScreen)
display_window->set_fullscreen(width, height);
@@ -676,6 +536,22 @@ CATrophy::reconfigure()
display_window->set_windowed();
lastFullScreen = fullScreen;
}
+ else
+ {
+ try
+ {
+ display_window->set_size(width, height);
+ input_context = display_window->get_ic();
+ if(fullScreen)
+ display_window->set_fullscreen(width, height);
+ else
+ display_window->set_windowed();
+ }
+ catch( CL_Error err )
+ {
+ std::cout << "Exception caught: " << err.message << std::endl;
+ }
+ }
// Init mouse cursor:
//
@@ -691,8 +567,8 @@ CATrophy::reconfigure()
*/
void
CATrophy::resetGoodies() {
- for( int gt=0; gt<CA_NUMGOODYTYPES; gt++ ) {
- for( int gi=0; gi<CA_NUMGOODIES; gi++ ) {
+ for( unsigned int gt=0; gt<goody.size(); gt++ ) {
+ for( unsigned int gi=0; gi<goody[gt].size(); gi++ ) {
goody[gt][gi]->setActive( false );
}
}
@@ -724,14 +600,80 @@ CATrophy::resetDustClowds() {
(car types, points, money).
*/
void
-CATrophy::resetPlayers() {
- for( int pl=0; pl<CA_MAXPLAYERS; ++pl ) {
+CATrophy::resetPlayers()
+{
+ for( int pl=1; pl<CA_MAXPLAYERS; ++pl )
+ {
player[pl]->reset();
- player[pl]->setCarNumber( 0, player[pl]->getCarNumber()!=0 );
+
+ int sat = TrophyMath::getRandomNumber( -90, 20 );
+ int val = TrophyMath::getRandomNumber( -60, 0 );
+ player[pl]->setColor( HSVColor((int)((float)pl/CA_MAXPLAYERS*360),sat,val) );
+
+ player[pl]->setTotalPoints(pl*4+pl*3);
+ if (pl > 3*CA_MAXPLAYERS/4)
+ {
+ player[pl]->setCarNumber( 3 );
+ player[pl]->getCar()->getTires()->setCurrent(2); // Use value of original 1.1.5 version
+
+ }
+ else if (pl > CA_MAXPLAYERS/2)
+ {
+ player[pl]->setCarNumber( 2 );
+ player[pl]->getCar()->getTires()->setCurrent(3); // Use value of original 1.1.5 version
+ }
+ else if (pl > CA_MAXPLAYERS/4)
+ {
+ player[pl]->setCarNumber( 1 );
+ player[pl]->getCar()->getTires()->setCurrent(4); // Use value of original 1.1.5 version
+ }
+ else
+ {
+ player[pl]->setCarNumber( 0 );
+ player[pl]->getCar()->getTires()->setCurrent(3); // Use value of original 1.1.5 version
+ }
+
+ }
+ player[0]->reset();
+ player[0]->setCarNumber(0); // human player always start with the worst car
+ player[0]->setName( "Andrew" );
+ if( CA_MAXPLAYERS>1 ) player[1]->setName( "Greenhorn" );
+ if( CA_MAXPLAYERS>2 ) player[2]->setName( "Dark Rider" );
+ if( CA_MAXPLAYERS>3 ) player[3]->setName( "Speedy Joe" );
+ if( CA_MAXPLAYERS>4 ) player[4]->setName( "Sunnyboy" );
+ if( CA_MAXPLAYERS>5 ) player[5]->setName( "Jane Zaine" );
+ if( CA_MAXPLAYERS>6 ) player[6]->setName( "John Doe" );
+ if( CA_MAXPLAYERS>7 ) player[7]->setName( "Sky Carter" );
+ if( CA_MAXPLAYERS>8 ) player[8]->setName( "Billy Kid" );
+ if( CA_MAXPLAYERS>9 ) player[9]->setName( "Echotango" );
+ if( CA_MAXPLAYERS>10 ) player[10]->setName( "Cletus Fuego" );
+ if( CA_MAXPLAYERS>11 ) player[11]->setName( "Crazy Slider" );
+ if( CA_MAXPLAYERS>12 ) player[12]->setName( "Stream Jet" );
+ if( CA_MAXPLAYERS>13 ) player[13]->setName( "Firestorm" );
+ if( CA_MAXPLAYERS>14 ) player[14]->setName( "Old Beetle" );
+ if( CA_MAXPLAYERS>15 ) player[15]->setName( "Blaze Shaw" );
+ if( CA_MAXPLAYERS>16 ) player[16]->setName( "Bonnie T." );
+ if( CA_MAXPLAYERS>17 ) player[17]->setName( "Freeze Bee" );
+ if( CA_MAXPLAYERS>18 ) player[18]->setName( "Double Tee" );
+ if( CA_MAXPLAYERS>19 ) player[19]->setName( "Harkness" );
+ if( CA_MAXPLAYERS>20 ) player[20]->setName( "O'Brian" );
+ if( CA_MAXPLAYERS>21 ) player[21]->setName( "Holly Wood" );
+ if( CA_MAXPLAYERS>22 ) player[22]->setName( "Toshiko Ito" );
+ if( CA_MAXPLAYERS>23 ) player[23]->setName( "White Ghost" );
+ if( CA_MAXPLAYERS>24 ) player[24]->setName( "Li Mei Zhao" );
+ if( CA_MAXPLAYERS>25 ) player[25]->setName( "Furious Bird" );
+ if( CA_MAXPLAYERS>26 ) player[26]->setName( "Mister X" );
+ if( CA_MAXPLAYERS>27 ) player[27]->setName( "Longhorn" );
+ if( CA_MAXPLAYERS>28 ) player[28]->setName( "Fast Tracker" );
+ if( CA_MAXPLAYERS>29 ) player[29]->setName( "Bill Speed" );
+ if( CA_MAXPLAYERS>30 ) player[30]->setName( "Thunderspot" );
+ if (m_cheatMoney)
+ {
+ player[0]->addMoney (74000);
}
}
-/** Called by CATrophy::main() to start the menu in an std::endless loop.
+/** Called by CATrophy::main() to start the menu in an endless loop.
*/
void
CATrophy::runMenu()
@@ -746,7 +688,6 @@ CATrophy::runMenu()
CAMenu* mainMenu;
CAMenu* raceMenu;
//CAMenu* netMenu;
- CAMenu* configMenu;
int mainMenuSelection, raceMenuSelection;
//netMenuSelection, configMenuSelection;
@@ -756,7 +697,6 @@ CATrophy::runMenu()
mainMenu->addMenuLabel( "Start Racing" );
//mainMenu->addMenuLabel( "Multiplayer Race" );
mainMenu->addMenuLabel( "Configure" );
- mainMenu->addMenuLabel( "See Hall Of Fame" );
mainMenu->addMenuLabel( "Credits" );
mainMenu->addMenuLabel( "Exit To System" );
@@ -769,42 +709,83 @@ CATrophy::runMenu()
// Start Racing:
//
case 0:
- do
{
- raceMenu = new CAMenu( "Start Racing" );
- raceMenu->addMenuLabel( "Start A New Game" );
- //raceMenu->addMenuLabel( "Load Game" );
- //raceMenu->addMenuLabel( "Save Game" );
- raceMenu->addMenuLabel( "See Statistics" );
- // TODO : Previous Menu ? End Current Game ? Which one is best ?
- // - Previous Menu seems more logic, but it doesn't make it very clear that you lose your game (maybe when there will be save/load ?)
- // - End Current Game doesn't tell us that we're going back to the main menu
- raceMenu->addMenuLabel( "End Current Game" );
- //raceMenu->addMenuLabel( "Previous Menu" );
- raceMenu->run();
- raceMenuSelection = raceMenu->getSelection();
- delete raceMenu;
-
- switch( raceMenuSelection )
+ int nextCursor = 0;
+ do
{
- case 0: // Start new game
-
- startNewGame();
- break;
-
- case 1: // See Statistics
-
- runPositionTable( true );
- break;
-
- case 2: // End current Game (if the number change, raceMenuSelection comparison should also change)
-
- break;
-
- default:
- break;
+ raceMenu = new CAMenu( "Start Racing" );
+ if (m_isGameStarted)
+ raceMenu->addMenuLabel( "Continue Current Game" );
+ else
+ raceMenu->addMenuLabel( "Start A New Game" );
+ raceMenu->addMenuLabel( "Load Game" );
+ raceMenu->addMenuLabel( "Save Game" );
+ // TODO : Previous Menu ? End Current Game ? Which one is best ?
+ // - Previous Menu seems more logic, but it doesn't make it very clear that you lose your game (maybe when there will be save/load ?)
+ // - End Current Game doesn't tell us that we're going back to the main menu
+ raceMenu->addMenuLabel( "End Current Game" );
+ //raceMenu->addMenuLabel( "Previous Menu" );
+ raceMenu->setCursor (nextCursor);
+ raceMenu->run();
+ raceMenuSelection = raceMenu->getSelection();
+ delete raceMenu;
+
+ switch( raceMenuSelection )
+ {
+ case 0: // Start new game / Continue game
+ {
+ nextCursor = 0;
+ if (m_isGameStarted)
+ gameLoop();
+ else
+ startNewGame();
+ }
+ break;
+
+ case 1:
+ {
+ nextCursor = 0;
+ if (loadGame())
+ {
+ gameLoop();
+ }
+ }
+ break;
+
+ case 2:
+ {
+ if (m_isGameStarted)
+ {
+ nextCursor = 0;
+ if (saveGame())
+ gameLoop();
+ }
+ else
+ {
+ nextCursor = 2;
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ }
+
+ }
+ break;
+
+ case 3:// End current Game (if the number change, raceMenuSelection comparison should also change)
+ {
+ nextCursor = 3;
+ m_isGameStarted = false;
+ m_currentTrackNumbers.clear();
+ }
+ break;
+
+ default:
+ {
+ nextCursor = 3;
+ }
+ break;
+ }
}
- } while( raceMenuSelection != 2 );
+ while( raceMenuSelection != 3 );
+ }
break;
// Multiplayer:
@@ -842,54 +823,55 @@ CATrophy::runMenu()
// Configure:
//
case 1:
- configMenu = new CAMenu( "Configure" );
- configMenu->addMenuSelect( "Fullscreen", "off~on", &CA_APP->fullScreen );
- configMenu->addMenuSelect( "Sound", "off~on", &CA_APP->sound );
- configMenu->addMenuSelect( "Sound volume", "0%~10%~20%~30%~40%~50%~60%~70%~80%~90%~100%", &CA_APP->volume );
- configMenu->addMenuLabel( "Previous Menu" );
- configMenu->setConfigureMenu( true );
- configMenu->run();
- delete configMenu;
- break;
-
-
- // See Hall Of Fame:
- //
- case 2:
- runPositionTable( false );
+ {
+ CAMenu configMenu( "Configure" ) ;
+ configMenu.addMenuSelect( "Fullscreen", "off~on", &CA_APP->fullScreen );
+ configMenu.addMenuSelect( "Resolution", "640x480~800x600~1024x768", &CA_APP->resolution);
+ configMenu.addMenuSelect( "Sound", "off~on", &CA_APP->sound );
+ configMenu.addMenuSelect( "Sound volume", "0%~10%~20%~30%~40%~50%~60%~70%~80%~90%~100%", &CA_APP->volume );
+ configMenu.addMenuLabel( "Configure Keyboard" );
+ configMenu.addMenuLabel( "Previous Menu" );
+ configMenu.setConfigureMenu( true );
+ configMenu.run();
+ if (configMenu.getSelection() == 4)
+ {
+ m_ConfigureKey->run();
+ }
+ }
break;
// Credits:
//
- case 3:
+ case 2:
runCreditsScreen();
break;
// Exit:
//
- case 4:
+ case 3:
done=true;
break;
}
} while( !done );
}
-/** Called by CATrophy::runMenu() to start the position table in an std::endless loop.
- \param race true: Show table for last race / false: Total results table
+/** Called by CATrophy::runMenu() to start the position table in an endless loop.
\return true on success (User pressed Enter or Space) otherwise false (User pressed ESC)
*/
bool
-CATrophy::runPositionTable( bool race ) {
- CAPositionTableView positionTableView( race );
+CATrophy::runPositionTable()
+{
+ CAPositionTableView positionTableView;
return positionTableView.run();
}
/** Called by CATrophy::runMenu() to start the credits screen in an std::endless loop.
*/
void
-CATrophy::runCreditsScreen() {
+CATrophy::runCreditsScreen()
+{
CACredits credits;
credits.run();
}
@@ -953,12 +935,6 @@ CATrophy::startNewGame()
{
if( debug ) std::cout << "startNewGame() begin" << std::endl;
- CAMenu* difficultyMenu = new CAMenu( "Select Difficulty:" );
- difficultyMenu->addMenuLabel( "Speed makes me dizzy" );
- difficultyMenu->addMenuLabel( "I live to ride" );
- difficultyMenu->addMenuLabel( "Petrol in my veins" );
- difficultyMenu->setCursor( 1 );
-
resetPlayers();
// Player settings dialog:
@@ -966,38 +942,244 @@ CATrophy::startNewGame()
CAPlayerSettingsDialog playerSettingsDialog;
if( playerSettingsDialog.run()==1 )
{
+ m_nbTurns = 0;
player[0]->setName( playerSettingsDialog.getPlayerName() );
- player[0]->setColor( CAColor( playerSettingsDialog.getPlayerHue(),0,0 ) );
+ player[0]->setColor( HSVColor( playerSettingsDialog.getPlayerHue(),0,0 ) );
// Choose difficulty:
//
+ CAMenu* difficultyMenu = new CAMenu( "Select Difficulty:" );
+ difficultyMenu->addMenuLabel( "Speed makes me dizzy" );
+ difficultyMenu->addMenuLabel( "I live to ride" );
+ difficultyMenu->addMenuLabel( "Petrol in my veins" );
+ difficultyMenu->setCursor( 1 );
+
int dif = difficultyMenu->run();
delete difficultyMenu;
if( dif >= 0 )
{
- difficulty = (Difficulty)dif;
- bool goon=true;
+ difficulty = Difficulty (dif);
+ gameLoop();
+ }
+ }
- // Choose track:
- //
- CASignUpScreen* signUpScreen;
+ if( debug ) std::cout << "startNewGame() end" << std::endl;
+}
+
+
+/** Starts a new game. Called by the menu.
+*/
+bool
+CATrophy::saveGame()
+{
+ bool isOk = false;
+ if( debug ) std::cout << "saveGame() begin" << std::endl;
+ CASlotSelectionDialog slotDialog("Save Game", CA_RES->font_normal_14_white, m_homedir);
+ std::string saveFileName = slotDialog.display();
+ if (saveFileName == "")
+ return isOk; // TODO: handle this (or not)
+ std::string saveFileString = m_homedir + saveFileName;
+ if (debug) std::cout << "saving " << saveFileString << std::endl;
+ std::ofstream saveFile(saveFileString.c_str());
+ if (saveFile)
+ {
+ saveFile << VERSION << std::endl;
+ saveFile << difficulty << std::endl;
+ saveFile << m_nbTurns << std::endl;
+ if (m_currentTrackNumbers.size() != 3)
+ {
+ for (unsigned int i=0; i<3; ++i)
+ saveFile << -1 << std::endl;
+ }
+ else
+ {
+ for (unsigned int i=0; i<3; ++i)
+ saveFile << m_currentTrackNumbers[i] << std::endl;
+ }
+ // TODO: This code should probably be in player.cpp
+ for( unsigned int c=0; c<CA_MAXPLAYERS; ++c )
+ {
+ saveFile << player[c]->getName() << std::endl;
+ saveFile << player[c]->getCarNumber() << std::endl;
+ saveFile << player[c]->getCar()->getMotor()->getCurrent() << std::endl;
+ saveFile << player[c]->getCar()->getTires()->getCurrent() << std::endl;
+ saveFile << player[c]->getCar()->getArmor()->getCurrent() << std::endl;
+ saveFile << player[c]->getColor().h << std::endl;
+ saveFile << player[c]->getColor().s << std::endl;
+ saveFile << player[c]->getColor().v << std::endl;
+ saveFile << player[c]->getMoney() << std::endl;
+ saveFile << player[c]->getTotalPoints() << std::endl;
+ }
+ isOk = true;
+ CAInfoDialog saveOKDlg( "Game Saved",
+ "Press Enter to continue...",
+ CAInfoDialog::Info,
+ false, &slotDialog );
+ saveOKDlg.run();
+ }
+ if( debug ) std::cout << "saveGame() end" << std::endl;
+ return isOk;
+}
+
+/** Starts a new game. Called by the menu.
+*/
+bool
+CATrophy::loadGame()
+{
+ if( debug ) std::cout << "LoadGame() begin" << std::endl;
+ bool isOk = false;
+
+ CASlotSelectionDialog slotDialog("load Game", CA_RES->font_normal_14_white, m_homedir);
+ std::string loadFileName = slotDialog.display();
+
+ if (loadFileName == "")
+ {
+ if (!slotDialog.canceled())
+ std::cerr << "Unable to load Game. File corrupted?" << std::endl; // TODO
+ return isOk; // TODO: handle this
+ }
+
+ std::string loadFileString = m_homedir + loadFileName;
+ if (debug) std::cout << "loading " << loadFileString << std::endl;
+
+ std::ifstream loadFile(loadFileString.c_str());
+ if (loadFile)
+ {
+ std::string version;
+ loadFile >> version;
+
+ int dif;
+ loadFile >> dif;
+ if (dif == 0)
+ difficulty = Easy;
+ else if (dif == 1)
+ difficulty = Medium;
+ else if (dif == 2)
+ difficulty = Hard;
+
+ loadFile >> m_nbTurns;
+
+ m_currentTrackNumbers.clear();
+ for (int i=0; i<3; ++i)
+ {
int trackNumber;
- do
+ loadFile >> trackNumber;
+ if (trackNumber != -1)
+ m_currentTrackNumbers.push_back(trackNumber);
+ }
+
+ // TODO: This code should probably be in player.cpp
+ for( unsigned int c=0; c<CA_MAXPLAYERS; ++c )
+ {
+ std::string name;
+ std::getline( loadFile, name ); // end of line
+ std::getline( loadFile, name ); // name
+ int carNumber, currentMotor, currentTires, currentArmor, h, s, v, money, totalPoints;
+ loadFile >> carNumber >> currentMotor >> currentTires >> currentArmor >> h >> s >> v >> money >> totalPoints;
+ player[c]->setName(name);
+ player[c]->setCarNumber(carNumber);
+ player[c]->getCar()->getMotor()->setCurrent(currentMotor);
+ player[c]->getCar()->getTires()->setCurrent(currentTires);
+ player[c]->getCar()->getArmor()->setCurrent(currentArmor);
+ HSVColor color(h, s, v);
+ player[c]->setColor(color);
+ player[c]->setMoney(money);
+ player[c]->setTotalPoints(totalPoints);
+ }
+ isOk = true;
+ CAInfoDialog loadOKDlg( "Game Loaded",
+ "Press Enter to continue...",
+ CAInfoDialog::Info,
+ false, &slotDialog );
+ loadOKDlg.run();
+ }
+ if( debug ) std::cout << "loadGame() end" << std::endl;
+ return isOk;
+}
+
+
+/** Main game Loop. Called by startNewGame and LoadGame
+*/
+void CATrophy::gameLoop()
+{
+ if( debug ) std::cout << "gameLoop() begin" << std::endl;
+ m_isGameStarted = true;
+ // Choose track:
+ //
+ int trackNumber = 1;
+
+ bool goOn = true;
+ std::vector<std::vector<Player*> > allRunningPlayers;
+
+ while (goOn)
+ {
+ if (m_gameLoopState == 0)
+ {
+ if (m_nbTurns == 0)
+ ++m_gameLoopState; // we don't use Shop at First Race
+ else
{
- signUpScreen = new CASignUpScreen();
- trackNumber = signUpScreen->run();
- delete signUpScreen;
+ ShopScreen myShop(player[0], CA_RES->menu_bg, CA_RES->gui_button, CA_RES->font_normal_14_white, carUp);
+ myShop.run();
+ if (myShop.canceled())
+ {
+ goOn = false;
+ }
+ else
+ ++m_gameLoopState;
+ }
+ }
+ if (m_gameLoopState == 1)
+ {
+ CASignUpScreen signUpScreen(player, m_currentTrackNumbers);
+ trackNumber = signUpScreen.run();
+ m_currentTrackNumbers = signUpScreen.getTrackNumbers();
+ if (signUpScreen.canceled())
+ {
+ if (m_nbTurns == 0)
+ goOn = false;
+ else
+ --m_gameLoopState;
+
+ }
+ else
+ {
+ RaceLevel raceLevel = RaceLevel(signUpScreen.getRaceLevel());
+ m_RacePlayer = signUpScreen.getRacePlayers();
+
if( trackNumber != -1 )
{
- track.file = trackList.getItem( trackNumber );
- run();
- goon = runPositionTable( true );
+ CAPositionTable::getPositionTable()->setRaceLevel(raceLevel);
+ m_trackName = trackList[trackNumber];
+ run(); // This is where the race start
+ m_currentTrackNumbers.clear();
+ runPositionTable();
+ signUpScreen.addVirtualPoints();
+ allRunningPlayers = signUpScreen.getAllRunningPlayers();
+ ++m_gameLoopState;
}
- } while( trackNumber!=-1 && goon );
+ else
+ std::cerr << "Internal Error" << std::endl; // TODO: Check if it is really impossible
+ }
+ }
+ if (m_gameLoopState == 2)
+ {
+ CAChampionshipScreen myChampionShip(player[0], player, allRunningPlayers, CA_RES->menu_bg, CA_RES->gui_button, CA_RES->gui_button_green, CA_RES->gui_button_blue, CA_RES->gui_button_red, CA_RES->font_normal_11_white);
+ if (myChampionShip.run())
+ ++m_gameLoopState;
+ else
+ {
+ WinDialog win(player[0]->getName(), m_nbTurns);
+ win.run();
+ ++m_gameLoopState;
+ goOn = false;
+ }
+
}
- }
- if( debug ) std::cout << "startNewGame() end" << std::endl;
+ m_gameLoopState = m_gameLoopState%3;
+ }
+ if( debug ) std::cout << "gameLoop() end" << std::endl;
}
/** Starts a trophy server on this computer.
@@ -1026,9 +1208,9 @@ CATrophy::addNetPlayer() {
for( int pl=0; pl<CA_MAXPLAYERS; ++pl ) {
if( player[pl] &&
- player[pl]->getControlMode()==CAPlayer::Computer ) {
+ player[pl]->getControlMode()==Player::Computer ) {
ret = pl;
- player[pl]->setControlMode( CAPlayer::Network );
+ player[pl]->setControlMode( Player::Network );
break;
}
}
@@ -1053,18 +1235,16 @@ CATrophy::controlNetPlayer( int id,
}
/** Called by CATrophy::runMenu() to start the
- game in an std::endless loop.
+ game in an endless loop. this is the endless loop of the race
*/
int
CATrophy::run()
{
if(debug) std::cout << "Game Running" << std::endl;
+ m_nbTurns++;
- int gameStartTime; // Race started
+ int gameStartTime; // Race started
int goodyTime; // Last goody placed at...
-
- bool blocked = false; // mouse blocked?
- int rp = 0; // rounting point
int rhythm = 0; // Rhythm for networking.
// Keep up Server on 0, 2, ...
// Keep up Client on 1, 3, ...
@@ -1072,9 +1252,13 @@ CATrophy::run()
bool raceOver = false; // Set to true if race is over
int raceOverTime = 0; // Time stamp at the time when the race was over.
- // Init track:
+ // Init track and choose player for race
+ //
+ initRace( m_trackName );
+
+ // Init the panel
//
- initTrack( track.file );
+ initPanel();
// Init map offset:
//
@@ -1088,15 +1272,16 @@ CATrophy::run()
if( debug ) std::cout << "Start game loop" << std::endl;
- // Loop until 'Q' pressed or race is over:
+ // Loop until 'Escape' pressed or race is over:
//
- while( CL_Keyboard::get_keycode(CL_KEY_Q) == false &&
- CL_Keyboard::get_keycode(CL_KEY_ESCAPE) == false &&
+ bool isEscapePressed = false;
+ while( !isEscapePressed &&
(!raceOver || CL_System::get_time()-raceOverTime<3000) )
{
measureFrameTime( true );
- if( CL_Keyboard::get_keycode(CL_KEY_P) ) {
+ if( CL_Keyboard::get_keycode(CL_KEY_P) )
+ {
pause = !pause;
}
@@ -1105,13 +1290,16 @@ CATrophy::run()
// Control players:
//
raceOver = true;
- for( c=0; c<CA_MAXPLAYERS; ++c ) {
- if( c==0 ) player[c]->keyControl(); // Control Human player
- else player[c]->autoPilot(); // Control Computer player
+ for( c=0; c<CA_RACEMAXPLAYERS; ++c )
+ {
+ m_RacePlayer[c]->pilot();
- if( player[c]->hasFinished() ) { // Check if first player has finished
+ if( m_RacePlayer[c]->hasFinished() )
+ { // Check if first player has finished
firstPlayerFinished = true;
- } else if( c==0 && player[c]->getLife()>0.0 ) { // Check if race is over...
+ }
+ else if( c==0 && !m_RacePlayer[c]->isDeath() && !m_RacePlayer[c]->isLapped() )
+ { // Check if race is over...
raceOver=false;
}
}
@@ -1119,21 +1307,25 @@ CATrophy::run()
// 'Advance' goodies:
//
- for( int gt=0; gt<CA_NUMGOODYTYPES; gt++ ) {
- for( int gi=0; gi<CA_NUMGOODIES; gi++ ) {
+ for( unsigned int gt=0; gt<goody.size(); gt++ )
+ {
+ for( unsigned int gi=0; gi<goody[gt].size(); gi++ )
+ {
goody[gt][gi]->advance();
}
}
// Advance players:
//
- for(c=0; c<CA_MAXPLAYERS; ++c) {
- player[c]->advance();
+ for(c=0; c<CA_RACEMAXPLAYERS; ++c)
+ {
+ m_RacePlayer[c]->advance();
}
// Place goodies:
//
- if( CL_System::get_time() > (unsigned int)(goodyTime+CA_GOODYTIME) ) {
+ if( CL_System::get_time() > (unsigned int)(goodyTime+CA_GOODYTIME) )
+ {
goodyTime = CL_System::get_time();
placeGoody();
}
@@ -1141,7 +1333,7 @@ CATrophy::run()
// Uptime time:
//
time = CL_System::get_time()-gameStartTime;
- CAMath::timeToString( timeString, time );
+ TrophyMath::timeToString( timeString, time );
}
// Find out new ranks:
@@ -1150,34 +1342,10 @@ CATrophy::run()
// Mouse clicks for track creation:
//
- if( debug && trackInfo )
+
+ if( debug && trackInfo ) // TODO: trackInfo should be in Track
{
- if( CL_Mouse::get_keycode(CL_MOUSE_LEFT) )
- {
- if( !blocked )
- {
- blocked = true;
- FILE* fp = fopen( "trackdata.txt", "at" );
- if( fp )
- {
- fprintf( fp, "x = \"%d\"\n", CL_Mouse::get_x()-offsetX );
- fprintf( fp, "y = \"%d\"\n", CL_Mouse::get_y()-offsetY );
- fprintf( fp, "RP = \"%d\"\n\n", rp++ );
- fclose( fp );
- CL_Color fmap_pix = track.functionMap->get_pixel(CL_Mouse::get_x()-offsetX, CL_Mouse::get_y()-offsetY);
- CL_PixelBuffer pixbuf = track.visualMap->get_pixeldata();
- pixbuf.lock();
- CL_Color vmap_pix = pixbuf.get_pixel(CL_Mouse::get_x()-offsetX, CL_Mouse::get_y()-offsetY);
- pixbuf.unlock();
- std::cout << "vmap (r, g, b, a) = (" << vmap_pix.get_red() << ", " << vmap_pix.get_green() << ", " << vmap_pix.get_blue() << ", " << vmap_pix.get_alpha() << ")" << std::endl;
- std::cout << "fmap (r, g, b, a) = (" << fmap_pix.get_red() << ", " << fmap_pix.get_green() << ", " << fmap_pix.get_blue() << ", " << fmap_pix.get_alpha() << ")" << std::endl;
- }
- }
- }
- else
- {
- blocked = false;
- }
+ m_track->handleTrackCreation(offsetX, offsetY);
}
// Scroll to center player 0:
@@ -1202,7 +1370,8 @@ CATrophy::run()
// Allow shooting after 3 seconds:
//
- if( !allowShooting && (CL_System::get_time()-gameStartTime) > 3000 ) {
+ if( !allowShooting && (CL_System::get_time()-gameStartTime) > 3000 )
+ {
allowShooting=true;
}
@@ -1222,6 +1391,25 @@ CATrophy::run()
CL_System::keep_alive(); // VERY VITAL for the system!
measureFrameTime( false );
+ isEscapePressed = CL_Keyboard::get_keycode(CL_KEY_ESCAPE);
+
+ if (isEscapePressed)
+ {
+ CAEscapeDialog escapeDlg( "Quit Race?",
+ "Press Y to quit race",
+ CAInfoDialog::Info,
+ true, this );
+ escapeDlg.run();
+
+ if( escapeDlg.isMustQuit () )
+ {
+ m_RacePlayer[0]->kill();
+ }
+ else
+ {
+ isEscapePressed = false;
+ }
+ }
}
if( debug ) std::cout << "Stop game loop" << std::endl;
@@ -1230,19 +1418,24 @@ CATrophy::run()
// Finish all players manually
//
- for( int rank=1; rank<=CA_MAXPLAYERS; ++rank ) {
+ for( int rank=1; rank<=CA_RACEMAXPLAYERS; ++rank )
+ {
// Players which are alive:
//
- for( c=0; c<CA_MAXPLAYERS; ++c ) {
- if( !player[c]->hasFinished() &&
- !player[c]->isDeath() &&
- player[c]->getRaceRank()==rank ) {
- CA_POSITIONTABLE->playerFinishedRace( player[c] );
+ for( c=0; c<CA_RACEMAXPLAYERS; ++c )
+ {
+ if( !m_RacePlayer[c]->hasFinished() &&
+ !m_RacePlayer[c]->isDeath() &&
+ !m_RacePlayer[c]->isLapped() &&
+ m_RacePlayer[c]->getRaceRank()==rank )
+ {
+ CAPositionTable::getPositionTable()->playerFinishedRace( m_RacePlayer[c] );
break;
}
}
}
+
// Show race over dialog:
//
CAInfoDialog raceOverDlg( "Race over!",
@@ -1251,10 +1444,16 @@ CATrophy::run()
true, this );
raceOverDlg.run();
- buyCars();
-
+ //buyCars();
+ for( int pl=0; pl<CA_MAXPLAYERS; ++pl )
+ {
+ player[pl]->OnRaceOver();
+ }
+
fadeScreen( false, this );
+ deinitPanel();
+
return 0;
}
@@ -1264,11 +1463,11 @@ void
CATrophy::placeGoody() {
int x[4]; // 4 edge-points of new goody
int y[2];
-
- int sx = CAMath::getRandomNumber( 8, track.visualMap->get_width()-8 );
- int sy = CAMath::getRandomNumber( 8, track.visualMap->get_height()-8 );
- int gt = CAMath::getRandomNumber( 0, CA_NUMGOODYTYPES-1 );
- int level = CAMath::getRandomNumber( 0, 1 );
+
+ int sx = TrophyMath::getRandomNumber( 8, m_track->getWidth()-8 );
+ int sy = TrophyMath::getRandomNumber( 8, m_track->getHeight()-8 );
+ int gt = TrophyMath::getRandomNumber( 0, goodyType.size()-1 );
+ int level = TrophyMath::getRandomNumber( 0, 1 );
bool validPlace = true;
int referenceLevel = 0;
@@ -1287,8 +1486,9 @@ CATrophy::placeGoody() {
}
}
+
if( validPlace ) {
- for( int gi=0; gi<CA_NUMGOODIES; gi++ ) {
+ for( unsigned int gi=0; gi<goody[gt].size(); gi++ ) {
if( !goody[gt][gi]->isActive() ) {
goody[gt][gi]->move( sx, sy, (referenceLevel==2 ? level : (referenceLevel==1)) );
goody[gt][gi]->setActive( true );
@@ -1311,12 +1511,13 @@ CATrophy::setRanks() {
// Clear ranks for players in the race and adjust first available rank
//
- for( pl=0; pl<CA_MAXPLAYERS; ++pl ) {
- if( !player[pl]->isDeath() ) {
- if( player[pl]->hasFinished() ) {
- if( player[pl]->getRaceRank()>=rank ) rank = player[pl]->getRaceRank()+1;
+ for( pl=0; pl<CA_RACEMAXPLAYERS; ++pl ) {
+ if( !m_RacePlayer[pl]->isDeath() && !m_RacePlayer[pl]->isLapped()) {
+ if( m_RacePlayer[pl]->hasFinished() ) {
+ if( m_RacePlayer[pl]->getRaceRank()>=rank )
+ rank = m_RacePlayer[pl]->getRaceRank()+1;
} else {
- player[pl]->setRaceRank(0);
+ m_RacePlayer[pl]->setRaceRank(0);
}
}
}
@@ -1324,9 +1525,9 @@ CATrophy::setRanks() {
do {
pos = 0.0;
nextRank=-1;
- for( pl=0; pl<CA_MAXPLAYERS; ++pl ) {
- if( player[pl]->getRaceRank()==0 ) {
- thisPos = player[pl]->getPosition();
+ for( pl=0; pl<CA_RACEMAXPLAYERS; ++pl ) {
+ if( m_RacePlayer[pl]->getRaceRank()==0 ) {
+ thisPos = m_RacePlayer[pl]->getPosition();
if( thisPos>pos ) {
nextRank = pl;
pos = thisPos;
@@ -1335,13 +1536,13 @@ CATrophy::setRanks() {
}
if( nextRank!=-1 ) {
- if( !player[nextRank]->hasFinished() && !player[nextRank]->isDeath() ) {
- player[nextRank]->setRaceRank( rank );
+ if( !m_RacePlayer[nextRank]->hasFinished() && !m_RacePlayer[nextRank]->isDeath() && !m_RacePlayer[nextRank]->isLapped() ) {
+ m_RacePlayer[nextRank]->setRaceRank( rank );
}
}
rank++;
- } while( nextRank!=-1 && rank<=CA_MAXPLAYERS );
+ } while( nextRank!=-1 && rank<=CA_RACEMAXPLAYERS );
}
/** Gets the speed limit for a coordinate of the map
@@ -1349,14 +1550,7 @@ CATrophy::setRanks() {
int
CATrophy::getSpeedLimit( int x, int y )
{
- if( checkCoordinate( x,y ) )
- {
- CL_Color tmp = track.functionMap->get_pixel( x,y );
- unsigned int g = tmp.get_green();
- return ((g)&0xF0)>>4;
- }
-
- return 0;
+ return m_track->getSpeedLimit(x,y);
}
/** Gets the lap part for a coordinate of the map
@@ -1364,14 +1558,7 @@ CATrophy::getSpeedLimit( int x, int y )
int
CATrophy::getLapPart( int x, int y )
{
- if( checkCoordinate( x,y ) )
- {
- CL_Color tmp = track.functionMap->get_pixel( x,y );
- unsigned int b = tmp.get_blue();
- return ((b)&0x1F);
- }
-
- return 0;
+ return m_track->getLapPart(x,y);
}
/** Gets the level for a coordinate of the map.
@@ -1382,15 +1569,7 @@ CATrophy::getLapPart( int x, int y )
int
CATrophy::getLevel( int x, int y )
{
- if( checkCoordinate( x,y ) )
- {
- CL_Color tmp = track.functionMap->get_pixel( x,y );
- unsigned int g = tmp.get_green();
- if( (g&0x02)!=0 ) return 1;
- if( (g&0x01)!=0 ) return 0;
- }
-
- return 2;
+ return m_track->getLevel(x, y);
}
/** Checks if the gifen coordinate is on the map and returns true if so.
@@ -1398,10 +1577,7 @@ CATrophy::getLevel( int x, int y )
bool
CATrophy::checkCoordinate( int x, int y )
{
- // TODO get_width and get_height won't return the right value if the track size isn't a power of 2
- // when functionMap is a PixelBuffer
- //return ( x>=0 && y>=0 && x<(int)track.functionMap->get_width() && y<(int)track.functionMap->get_height() );
- return ( x>=0 && y>=0 && x<(int)track.visualMap->get_width() && y<(int)track.visualMap->get_height() );
+ return m_track->checkCoordinate(x,y);
}
/** Drops a fog bomb on the given place. This function
@@ -1445,9 +1621,12 @@ void
CATrophy::measureFrameTime( bool start ) {
static int frameStart = 0;
- if( start ) {
+ if( start )
+ {
frameStart = CL_System::get_time();
- } else {
+ }
+ else
+ {
int timeElapsed = CL_System::get_time()-frameStart;
if( timeElapsed>0 ) framesPerSec = 1000.0 / timeElapsed;
if( framesPerSec<1.0 ) framesPerSec = 1.0;
@@ -1472,24 +1651,18 @@ CATrophy::waitForSilence() {
/** Distributes cars to players which have enough money.
*/
-void
+/*void
CATrophy::buyCars() {
// Players with a lot of money get new cars:
//
if( debug ) std::cout << "Buy new cars begin" << std::endl;
for( int pl=0; pl<CA_MAXPLAYERS; ++pl ) {
- for( int ca=CA_NUMCARTYPES-1; ca>=0; --ca ) {
- if( player[pl]->getMoney() >= carType[ca].price && player[pl]->getCarNumber()<ca ) {
- player[pl]->setCarNumber( ca );
- player[pl]->setMoney( player[pl]->getMoney()-carType[ca].price );
- player[pl]->setNewCar( true );
- }
- }
+ player[pl]->OnRaceOver();
}
if( debug ) std::cout << "Buy new cars end" << std::endl;
-}
+}*/
/** Builds the whole game screen. ONLY this function is called
for this purpose.
@@ -1505,7 +1678,7 @@ CATrophy::buildScreen()
//
CL_Display::set_cliprect(crField);
- displayMap();
+ m_track->displayMap(offsetX,offsetY);
// Things under bridge:
displayGoodies( false );
@@ -1515,7 +1688,7 @@ CATrophy::buildScreen()
displayFogBombs( false, false );
// Bridge:
- displayBridge();
+ m_track->displayBridge(offsetX, offsetY);
// Things on bridge:
displayGoodies( true );
@@ -1526,9 +1699,8 @@ CATrophy::buildScreen()
// Display tracks for debugging:
//
- if( trackInfo ) {
- displayTrackPoints();
- }
+ if( trackInfo )
+ m_track->displayTrackPoints(offsetX, offsetY);
displayStartingLights();
displayCheckFlag();
@@ -1540,40 +1712,25 @@ CATrophy::buildScreen()
CL_Display::set_cliprect(crAll);
}
-/** Displays the race map.
-*/
-void
-CATrophy::displayMap() {
- track.visualMap->draw (offsetX,offsetY);
-}
/** Displays the goodies.
*/
void
-CATrophy::displayGoodies( bool up ) {
- for( int gt=0; gt<CA_NUMGOODYTYPES; gt++ ) {
- for( int gi=0; gi<CA_NUMGOODIES; gi++ ) {
+CATrophy::displayGoodies( bool up )
+{
+ for( unsigned int gt=0; gt<goody.size(); gt++ )
+ for( unsigned int gi=0; gi<goody[gt].size(); gi++ )
if( goody[gt][gi]->isUp()==up ) goody[gt][gi]->display( offsetX, offsetY );
- }
- }
}
-/** Displays the bridge if there is any.
-*/
-void
-CATrophy::displayBridge() {
- if( track.bridge!=0 ) {
- track.bridge->draw (track.bridgePos[0]+offsetX, track.bridgePos[1]+offsetY);
- }
-}
/** Displays players.
\param up true: Players on bridges / false: Players under bridges
*/
void
CATrophy::displayPlayers( bool up ) {
- for( int c=0; c<CA_MAXPLAYERS; ++c) {
- if( player[c]->isUp()==up ) player[c]->display( offsetX, offsetY );
+ for( int c=0; c<CA_RACEMAXPLAYERS; ++c) {
+ if( m_RacePlayer[c]->isUp()==up ) m_RacePlayer[c]->display( offsetX, offsetY );
}
}
@@ -1593,10 +1750,10 @@ CATrophy::displayFogBombs( bool up, bool bomb ) {
if( !fogBomb[c].exploded && (int)(fogBomb[c].frame)==4 ) {
fogBomb[c].exploded=true;
CA_RES->effectFogBomb->play( 2 );
- for( int pl=0; pl<CA_MAXPLAYERS; ++pl) {
- int dist = (int)CAMath::getDistance( fogBomb[c].x, fogBomb[c].y, player[pl]->getX(), player[pl]->getY() );
- if( player[pl]->isUp()==up && dist<90 ) {
- player[pl]->hit( 30.0-(dist/3.0) );
+ for( int pl=0; pl<CA_RACEMAXPLAYERS; ++pl) {
+ int dist = (int)TrophyMath::getDistance( fogBomb[c].x, fogBomb[c].y, m_RacePlayer[pl]->getX(), m_RacePlayer[pl]->getY() );
+ if( m_RacePlayer[pl]->isUp()==up && dist<90 ) {
+ m_RacePlayer[pl]->hit( 30.0-(dist/3.0) );
}
}
}
@@ -1683,20 +1840,6 @@ CATrophy::displayStartingLights() {
}
}
-/** Displays track points.
-*/
-void
-CATrophy::displayTrackPoints() {
- char str[16];
- for( int r=0; r<track.routePoints; ++r ) {
- for( int t=0; t<CA_MAXPLAYERS; ++t ) {
- sprintf( str, "%d/%d", r, t );
- CA_RES->misc_cross->draw (track.rp[t][r][0]+offsetX-8, track.rp[t][r][1]+offsetY-8);
- CA_RES->font_normal_11_white->set_alignment(origin_top_left, 0, 0);
- CA_RES->font_normal_11_white->draw( track.rp[t][r][0]+offsetX, track.rp[t][r][1]+offsetY+5, str );
- }
- }
-}
/** Fades the screen in (true) or out (false).
\param in Fade in (true) or out (false)
@@ -1737,19 +1880,9 @@ CATrophy::fadeScreen( bool in, CAScreen* screen, bool whole ) {
/** Scrolls the map to center player 0.
*/
-void
-CATrophy::scroll() {
- int maxOffsetX = panelWidth;
- int minOffsetX = -(track.visualMap->get_width()-(width-panelWidth)) + panelWidth;
- int maxOffsetY = 0;
- int minOffsetY = -(track.visualMap->get_height()-height);
-
- offsetX = - ((int)(player[0]->getX()) - (width-panelWidth)/2) + panelWidth;
- offsetY = - ((int)(player[0]->getY()) - height/2);
- if( offsetX>maxOffsetX ) offsetX = maxOffsetX;
- if( offsetX<minOffsetX ) offsetX = minOffsetX;
- if( offsetY>maxOffsetY ) offsetY = maxOffsetY;
- if( offsetY<minOffsetY ) offsetY = minOffsetY;
+void CATrophy::scroll()
+{
+ m_track->scroll(offsetX, offsetY, (int)(player[0]->getX()), (int)(player[0]->getY()), width, height, panelWidth);
}
// EOF
diff --git a/src/catrophy.h b/src/catrophy.h
index 75aed37..60cbe92 100644
--- a/src/catrophy.h
+++ b/src/catrophy.h
@@ -10,24 +10,28 @@
#endif
#include <ClanLib/application.h>
-#include "cacartype.h"
+#include "cartype.h"
#include "cadustclowd.h"
#include "cafogbomb.h"
#include "cagoody.h"
#include "cagoodytype.h"
#include "caloadingscreen.h"
-#include "camath.h"
+#include "utils/trophymath.h"
#include "camenu.h"
// #include "canetclient.h"
// #include "canetserver.h"
+#include "cacarupgrades.h"
#include "caresources.h"
-#include "catrack.h"
+#include "track.h"
#include "cascreen.h"
-#include "castringlist.h"
+#include <vector>
+#include <string>
+
class CATrophy;
-class CAPlayer;
+class Player;
class CAPanel;
+class CAConfigureKey;
#define CA_APP theApp() // Macro for getting a pointer to the application (CATrophy*)
@@ -39,20 +43,23 @@ CATrophy* theApp();
It's usually accessed over the macro CA_APP. E.g.: CA_APP->buildScreen();
This class starts the Game, inits the moduls and displays things.
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
class CATrophy : public CL_ClanApplication,
public CAScreen {
public:
- enum Difficulty { Easy, Medium, Hard };
+ enum Difficulty { Easy = 0, Medium, Hard };
virtual int main( int argc, char** argv );
// Configuration methods:
//
- virtual const char *get_title();
+ virtual const std::string get_title();
void initCarTypes();
void deinitCarTypes();
+ void initUpgrades();
+ void deinitUpgrades();
void initGoodies();
void deinitGoodies();
void initPlayers();
@@ -62,8 +69,7 @@ public:
void initPanel();
void deinitPanel();
void initTrackList();
- void initTrack( std::string trackName );
- void deinitTrack();
+ void initRace( const std::string& trackName );
void reconfigure();
void resetGoodies();
@@ -74,11 +80,12 @@ public:
// Control / actions:
//
void runMenu();
- bool runPositionTable( bool race );
+ bool runPositionTable();
void runCreditsScreen();
void runServerInfo( bool success );
void runClientInfo( bool success );
void startNewGame();
+ void gameLoop();
void startServer();
void chooseNetGame();
@@ -98,19 +105,18 @@ public:
return time;
}
//! Race time as string.
- char* getTimeString() {
+ std::string getTimeString() {
return timeString;
}
void dropFogBomb( int x, int y, bool up );
void makeDustClowd( int x, int y, bool up );
void measureFrameTime( bool start );
void waitForSilence();
- void buyCars();
+ //void buyCars();
// Display / view methods:
//
void buildScreen();
- void displayMap();
void displayPlayers( bool up );
void displayGoodies( bool up );
void displayBridge();
@@ -118,18 +124,16 @@ public:
void displayDustClowds( bool up );
void displayCheckFlag();
void displayStartingLights();
- void displayTrackPoints();
void fadeScreen( bool in, CAScreen* screen, bool whole=true );
void scroll();
// Persistance:
//
- void saveGame();
- void loadGame();
+ bool saveGame();
+ bool loadGame();
public:
//! Loading screen
-
CALoadingScreen loading;
//! Game paused?
@@ -140,6 +144,8 @@ public:
int volume;
//! Fullscreen mode?
bool fullScreen;
+ // ! big Money Mode
+ bool m_cheatMoney;
//! Fast mode (no screen fading) (command line argument --fast)
bool fast;
//! Are we a server (command line argument --server)
@@ -149,34 +155,37 @@ public:
//! Debug mode (command line argument --debug)
bool debug;
//! Show trackinfo (crosses and numbers on track points) (command line argument --trackinfo)
- bool trackInfo;
+ bool trackInfo; // TODO: should be in track
//! Frames per second we can do at maximum
float framesPerSec;
- //! Array of Players. Created and destroed by this class.
- CAPlayer* player[CA_MAXPLAYERS];
+ //! Array of Players. Created and destroyed by this class.
+ std::vector<Player*> player;
+ //! Array of Players who are running in the same Race of the player
+ std::vector<Player*> m_RacePlayer;
//! Array of car types.
- CACarType carType[CA_NUMCARTYPES];
+ std::vector<CarType> carType;
//! Array of goodyTypes.
- CAGoodyType goodyType[CA_NUMGOODYTYPES];
+ std::vector<CAGoodyType*> goodyType;
//! The goody instances. CA_NUMGOODIES of each type.
- CAGoody* goody[CA_NUMGOODYTYPES][CA_NUMGOODIES];
+ std::vector<std::vector<CAGoody*> > goody;
//! Chosen difficulty (easy, medium, hard)
Difficulty difficulty;
// Track:
//! Current track data
- CATrack track;
+ Track* m_track;
+ std::string m_trackName;
//! Track directory names list
- CAStringList trackList;
+ std::vector<std::string> trackList;
//! List of three race prices
- //CAStringList priceList;
- //! Offset of the background map in x.
- int offsetX;
+ //StringList priceList;
+ //! Offset of the background map in x.
+ int offsetX; // TODO : check if we could put in track
//! Offset of the background map in y.
- int offsetY;
+ int offsetY; // TODO : check if we could put in track
//! Panel. Created and destroyed in this class.
CAPanel* panel;
@@ -212,6 +221,9 @@ public:
//! Total height (screen resolution in y)
int height;
+ //! resolution : 800x600, 640x480 or 1024x768
+ std::string resolution;
+
//! Ip set in the net options dialog or "auto"
char serverIp[16];
//! Server port number
@@ -220,15 +232,32 @@ public:
//! Input context
CL_InputContext *input_context;
+ //! Sound output
+ CL_SoundOutput *sound_output;
+
+ //! Upgrades ressources manager
+ CACarUpgrades *carUp;
+
private:
//! Current time in milliseconds since race start
-
int time;
//! Current race time as string (e.g. "02:23")
- char timeString[16];
+ std::string timeString;
CL_DisplayWindow *display_window;
+ CAConfigureKey* m_ConfigureKey;
+
+ std::string m_homedir;
+
+ bool m_isGameStarted;
+
+ std::vector<int> m_currentTrackNumbers;
+
+ int m_nbTurns;
+
+ int m_gameLoopState;
+
//! The server object
// CANetServer* netServer;
//! The client object
diff --git a/src/cawidget.cpp b/src/cawidget.cpp
index 6e946c8..21bdbac 100644
--- a/src/cawidget.cpp
+++ b/src/cawidget.cpp
@@ -51,28 +51,30 @@ CAWidget::move( int x, int y ) {
/** Resizes this widget.
The new position depends also on the alignment.
+ -1 don't resize
*/
void
-CAWidget::resize( int width, int height ) {
- this->width = width;
- this->height = height;
+CAWidget::resize( int width, int height )
+{
+ if (width != -1) this->width = width;
+ if (height != -1) this->height = height;
switch( alignment ) {
case Left:
- right = left+width;
+ right = left+ this->width;
break;
case Right:
- left = right-width;
+ left = right- this->width;
break;
case Center:
- left = (left+right)/2 - width/2;
- right = (left+right)/2 + width/2;
+ left = (left+right)/2 - this->width/2;
+ right = (left+right)/2 + this->width/2;
break;
}
- bottom = top+height;
+ bottom = top + this->height;
}
diff --git a/src/cawidget.h b/src/cawidget.h
index 63a3358..5e22cbf 100644
--- a/src/cawidget.h
+++ b/src/cawidget.h
@@ -56,7 +56,7 @@ public:
return height;
}
-protected:
+public:
//! Left border position.
int left;
diff --git a/src/computerplayer.cpp b/src/computerplayer.cpp
new file mode 100644
index 0000000..fb3d9eb
--- /dev/null
+++ b/src/computerplayer.cpp
@@ -0,0 +1,194 @@
+#include "computerplayer.h"
+#include "caresources.h"
+#include "catrophy.h"
+#include "track.h"
+
+ComputerPlayer::ComputerPlayer(int id, const std::string& name, int carNumber):
+Player(id, name, carNumber),
+m_routePoint(0),
+m_routeNumber(0),
+nxTemp(0.0),
+nyTemp(0.0)
+{}
+
+ComputerPlayer::~ComputerPlayer()
+{}
+
+void ComputerPlayer::display( const int offsetX, const int offsetY )
+{
+ Player::display(offsetX, offsetY);
+ if( CA_APP->trackInfo )
+ CL_Display::draw_line(getX()+offsetX, getY()+offsetY, nxTemp + offsetX, nyTemp + offsetY, CL_Color::white);
+}
+
+/** On Race Over, computers players are checking if they could buy a new car
+*/
+void ComputerPlayer::OnRaceOver()
+{
+ for( int ca=CA_NUMCARTYPES-1; ca>=0; --ca )
+ {
+ if( getMoney() >= CA_APP->carType[ca].price && getCarNumber()<ca )
+ {
+ buyNewCar( ca );
+ }
+ }
+}
+
+
+/** Calculates route of computer players.
+*/
+void ComputerPlayer::pilot()
+{
+ float nx, ny;
+ getCurrentTrack()->getNextRoutePoint(m_routeNumber, m_routePoint, nx, ny);
+
+ // For --trackinfo option
+ //
+ nxTemp = nx;
+ nyTemp = ny;
+
+ // Angle to next route point:
+ //
+ float b = TrophyMath::getAngle( getX(), getY(), nx,ny );
+ float diff = TrophyMath::getAngleDiff( getDirection(), b );
+ float dist = TrophyMath::getDistance( getX(),getY(), nx,ny );
+
+ const bool retard = false; // TODO: useless code (retard is always false)
+
+ // Steer:
+ //
+ // TODO : autoPilot should also take care of functionMap pixel that are under
+ // edges of the car (or better, next to the edges)
+ if (diff<20.0 || diff>340.0) {
+ directionMode = Straight;
+ } else if (diff<180.0) {
+ // TODO : was commented
+ //if( diff>40.0 ) retard=true;
+ directionMode = Right;
+ } else if (diff>180.0) {
+ // TODO : was commented
+ //if( diff<320.0 ) retard=true;
+ directionMode = Left;
+ }
+
+ // Switch to next route point:
+ //
+ // TODO : clean these constants all over the code (original = 120)!
+ // This constant is the distance where the computer take the next route Point
+ if (dist < 120.0) {
+ ++m_routePoint;
+ }
+
+
+
+ // Speed:
+ //
+ if( !isDeath() && !hasFinished() && !isLapped() && !retard )
+ speedMode=Accelerate;
+ else // TODO: useless code (retard is always false)
+ speedMode=Constant;
+
+
+ if( !isDeath() && !hasFinished() && !isLapped() )
+ {
+ // Decide wheter to activate turbo or not:
+ //
+ // TODO : strange ...
+ // CATrophy::Easy -> turboLaunchDistance = 600 or deactivateTurbo() ?
+ if( CA_APP->difficulty!=CATrophy::Easy )
+ {
+ int turboLaunchDistance = 600; // TODO : the turbo is use even before turbo launh distance
+ switch( CA_APP->difficulty )
+ {
+ case CATrophy::Easy:
+ turboLaunchDistance = 600; // TODO : useless : unreachable code
+ break;
+ case CATrophy::Medium:
+ turboLaunchDistance = 200;
+ break;
+ case CATrophy::Hard:
+ turboLaunchDistance = 50;
+ break;
+ }
+ int xt = (int)(getX() + cos( getNewDirection()/ARAD ) * turboLaunchDistance);
+ int yt = (int)(getY() + sin( getNewDirection()/ARAD ) * turboLaunchDistance);
+ int xt2 = (int)((getX() + xt)/2);
+ int yt2 = (int)((getY() + yt)/2);
+ if( getTurbo()>0.0 &&
+ CA_APP->getSpeedLimit(xt,yt)==15 &&
+ CA_APP->getSpeedLimit(xt2,yt2)==15 ) {
+ activateTurbo();
+ } else {
+ deactivateTurbo();
+ }
+ } else {
+ deactivateTurbo();
+ }
+
+ // Decide wheter to shoot or not:
+ //
+ if( CA_APP->allowShooting && getBullets()!=0 )
+ {
+ int distance;
+ int angle;
+ int angleDiff;
+ shootMode = false;
+ for( int pl=0; pl<CA_RACEMAXPLAYERS; ++pl )
+ {
+ if( pl!= getId() )
+ {
+ distance = (int)TrophyMath::getDistance( getX(), getY(), CA_APP->m_RacePlayer[pl]->getX(),CA_APP->m_RacePlayer[pl]->getY() );
+ angle = (int)TrophyMath::getAngle( getX(), getY(), CA_APP->m_RacePlayer[pl]->getX(),CA_APP->m_RacePlayer[pl]->getY() );
+ angleDiff = (int)TrophyMath::getAngleDiff( angle, getNewDirection() );
+ if( distance<CA_SHOOTINGRANGE && (angleDiff < 10.0 || angleDiff > 350.0) )
+ {
+ shoot();
+ break;
+ }
+ }
+ }
+ }
+
+ // Decide wheter to drop a fog bomb or not:
+ //
+ if( CA_APP->allowShooting && getFogBombs()!=0 )
+ {
+ int distance;
+ int angle;
+ int angleDiff;
+ for( int pl=0; pl<CA_RACEMAXPLAYERS; ++pl )
+ {
+ if( pl!=getId() )
+ {
+ distance = (int)TrophyMath::getDistance( getX(), getY(), CA_APP->m_RacePlayer[pl]->getX(), CA_APP->m_RacePlayer[pl]->getY() );
+ angle = (int)TrophyMath::getAngle( getX(), getY(), CA_APP->m_RacePlayer[pl]->getX(), CA_APP->m_RacePlayer[pl]->getY() );
+ angleDiff = (int)TrophyMath::getAngleDiff( angle, getNewDirection() );
+ if( distance > 200 && distance < 202 && angleDiff < 185.0 && angleDiff > 175.0 )
+ {
+ CA_APP->dropFogBomb( int(getX()),int(getY()), isUp() );
+ useFogBomb();
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+/** Reset things before a new race starts.
+*/
+void
+ComputerPlayer::resetForRace(const unsigned int routeNumber, const Track* currentTrack)
+{
+ Player::resetForRace(routeNumber, currentTrack);
+ m_routeNumber = routeNumber;
+ m_routePoint = 1;
+}
+
+
+float ComputerPlayer::getCheckAwayAngle()
+{
+ // Check car away (computer players check away stronger):
+ return 7.5f;
+}
+// EOF
diff --git a/src/computerplayer.h b/src/computerplayer.h
new file mode 100644
index 0000000..794db4b
--- /dev/null
+++ b/src/computerplayer.h
@@ -0,0 +1,35 @@
+#ifndef COMPUTER_PLAYER_H
+#define COMPUTER_PLAYER_H
+
+#include "player.h"
+
+/** Covers specificity for a computer player
+ @author Andrew Mustun
+ @author Matthieu Lecesne
+*/
+class ComputerPlayer : public Player
+{
+public:
+ ComputerPlayer(int id, const std::string& name, int carNumber);
+ ~ComputerPlayer();
+ void pilot();
+ void resetForRace(const unsigned int routeNumber, const Track* currentTrack);
+ void display( const int offsetX, const int offsetY );
+ void OnRaceOver();
+private:
+ float getCheckAwayAngle();
+ //! Index of next route point to drive to
+ unsigned int m_routePoint;
+ //! routeNumber to know which pre-determined path to follow
+ unsigned int m_routeNumber;
+
+ //! x coordinate of next route points (only for --trackinfo option)
+ float nxTemp;
+ //! y coordinate of next route points (only for --trackinfo option)
+ float nyTemp;
+
+};
+
+#endif
+
+// EOF
diff --git a/src/guibox.cpp b/src/guibox.cpp
new file mode 100644
index 0000000..76f49af
--- /dev/null
+++ b/src/guibox.cpp
@@ -0,0 +1,46 @@
+#include "guibox.h"
+#include "caresources.h"
+
+
+GUIBox::GUIBox(const int n_left, const int n_top, const int n_right, const int n_bottom)
+: ew ( CA_RES->gui_edge2->get_width()),
+ eh ( CA_RES->gui_edge2->get_height()),
+ bw ( CA_RES->gui_border2->get_width()),
+ bh ( CA_RES->gui_border1->get_height())
+{
+ setPosition(n_left, n_top, n_right, n_bottom);
+}
+
+
+void GUIBox::setPosition(const int n_left, const int n_top, const int n_right, const int n_bottom)
+{
+ left = n_left;
+ top = n_top;
+ right = n_right;
+ bottom = n_bottom;
+}
+
+
+GUIBox::~GUIBox()
+{
+}
+
+
+void GUIBox::display(bool active)
+{
+ CL_Display::fill_rect( CL_Rect(left+bw, top+bh, right-bw, bottom-bh), CL_Color(0, 0, 0, 64) );
+
+ // Edges:
+ //
+ CA_RES->gui_edge1->draw( left, top );
+ CA_RES->gui_edge2->draw( right-ew, top );
+ CA_RES->gui_edge3->draw( left, bottom-eh );
+ CA_RES->gui_edge4->draw( right-ew, bottom-eh );
+
+ // Borders:
+ //
+ CA_RES->gui_border1->draw( CL_Rect(left+ew, top, right-ew, top+bh) );
+ CA_RES->gui_border2->draw( CL_Rect(right-bw, top+eh, right, bottom-eh) );
+ CA_RES->gui_border3->draw( CL_Rect(left+ew, bottom-bh, right-ew, bottom) );
+ CA_RES->gui_border4->draw( CL_Rect(left, top+eh, left+bw, bottom-eh) );
+}
\ No newline at end of file
diff --git a/src/guibox.h b/src/guibox.h
new file mode 100644
index 0000000..f0386ed
--- /dev/null
+++ b/src/guibox.h
@@ -0,0 +1,30 @@
+#ifndef GUIBOX_H
+#define GUIBOX_H
+
+#include "cawidget.h"
+/** A class utily for displaying a white box
+ @author Matthieu Lecesne
+*/
+
+class GUIBox : public CAWidget
+{
+public:
+ GUIBox(const int n_left=0, const int n_top=0, const int n_right=0, const int n_bottom=0);
+ virtual ~GUIBox();
+
+ void setPosition(const int n_left, const int n_top, const int n_right, const int n_bottom);
+ void display(bool active=true);
+
+private:
+
+ //! width of an edge
+ const int ew;
+ //! height of an edge
+ const int eh;
+ //! width of a border
+ const int bw;
+ //! height of a border
+ const int bh;
+};
+
+#endif
diff --git a/src/humanplayer.cpp b/src/humanplayer.cpp
new file mode 100644
index 0000000..dea9df4
--- /dev/null
+++ b/src/humanplayer.cpp
@@ -0,0 +1,131 @@
+#include "humanplayer.h"
+#include "caresources.h"
+#include "catrophy.h"
+
+/** Constructor
+*/
+HumanPlayer::HumanPlayer( int id, const std::string& name, int carNumber )
+: Player(id, name, carNumber)
+{
+ // default key
+ using namespace ConfigureKey;
+ m_keyMap[ACCELERATE]= CL_KEY_UP;
+ m_keyMap[BRAKE] = CL_KEY_DOWN;
+ m_keyMap[LEFT] = CL_KEY_LEFT;
+ m_keyMap[RIGHT] = CL_KEY_RIGHT;
+ m_keyMap[SHOOT] = CL_KEY_X;
+ m_keyMap[BOMB] = CL_KEY_C;
+ m_keyMap[BOOST] = CL_KEY_A;
+ m_keyMap[HORN] = CL_KEY_SPACE;
+}
+
+HumanPlayer::~HumanPlayer()
+{}
+
+/** Controls the player by keyboard
+*/
+void HumanPlayer::pilot()
+{
+ // We're death and can't drive anymore:
+ //
+ using namespace ConfigureKey;
+ if( isDeath() || hasFinished() || isLapped()) {
+ speedMode = Constant;
+ }
+
+ // We're alive:
+ //
+ else {
+ // Accelerate (E/UP):
+ //
+ if (CL_Keyboard::get_keycode(m_keyMap[ACCELERATE]))
+ {
+ speedMode = Accelerate;
+ }
+
+ // Decelerate (D/DOWN):
+ //
+ else if (CL_Keyboard::get_keycode(m_keyMap[BRAKE]))
+ {
+ speedMode = Decelerate;
+ }
+
+ // Don't change speed:
+ //
+ else {
+ speedMode = Constant;
+ }
+ }
+
+ if( !isDeath() ) {
+ // Steer left:
+ //
+ if (CL_Keyboard::get_keycode(m_keyMap[LEFT]))
+ {
+ directionMode = Left;
+ }
+
+ // Steer right:
+ //
+ else if (CL_Keyboard::get_keycode(m_keyMap[RIGHT]))
+ {
+ directionMode = Right;
+ }
+
+ // Don't change direction:
+ //
+ else {
+ directionMode = Straight;
+ }
+ }
+
+ // Horn:
+ //
+ if (CL_Keyboard::get_keycode(m_keyMap[HORN]))
+ {
+ CA_RES->effectHorn->play();
+ }
+
+ // Shoot:
+ //
+ if (CL_Keyboard::get_keycode(m_keyMap[SHOOT]))
+ {
+ if( !hasFinished() && !isDeath() && !isLapped() && CA_APP->allowShooting && getBullets()>0 ) {
+ CA_RES->effectShoot->play( 2 );
+ shoot();
+ }
+ } else {
+ shootMode = false;
+ }
+
+ // Drop fog bomb:
+ //
+ static bool blockKeyF = false;
+ if (CL_Keyboard::get_keycode(m_keyMap[BOMB]))
+ {
+ if( !hasFinished() && !isDeath() && !isLapped() && CA_APP->allowShooting && !blockKeyF && getFogBombs()!=0 ) {
+ CA_APP->dropFogBomb( int(getX()), int(getY()), isUp() );
+ useFogBomb();
+ blockKeyF = true;
+ }
+ } else {
+ blockKeyF = false;
+ }
+
+ // Turbo:
+ //
+ if (CL_Keyboard::get_keycode(m_keyMap[BOOST]))
+ {
+ activateTurbo();
+ } else {
+ deactivateTurbo();
+ }
+}
+
+float HumanPlayer::getCheckAwayAngle()
+{
+ // Check car away (computer players check away stronger):
+ return 2.5f;
+}
+
+// EOF
diff --git a/src/humanplayer.h b/src/humanplayer.h
new file mode 100644
index 0000000..969dcf8
--- /dev/null
+++ b/src/humanplayer.h
@@ -0,0 +1,33 @@
+#ifndef HUMAN_PLAYER_H
+#define HUMAN_PLAYER_H
+
+#include "caconfigurekey.h"
+#include "player.h"
+#include <map>
+
+/** Covers specificity for a human player
+ @author Andrew Mustun
+ @author Matthieu Lecesne
+*/
+class HumanPlayer : public Player
+{
+public:
+ HumanPlayer( int id, const std::string& name, int carNumber );
+ ~HumanPlayer();
+
+ void pilot();
+
+ void setKeyMap(const std::map<ConfigureKey::DefineKey, int>& keyMap)
+ {
+ m_keyMap = keyMap;
+ }
+
+private:
+ float getCheckAwayAngle();
+ //! key control
+ std::map<ConfigureKey::DefineKey, int> m_keyMap;
+};
+
+#endif
+
+// EOF
diff --git a/src/caplayer.cpp b/src/player.cpp
similarity index 52%
rename from src/caplayer.cpp
rename to src/player.cpp
index 82df275..8f1cb24 100644
--- a/src/caplayer.cpp
+++ b/src/player.cpp
@@ -1,14 +1,11 @@
-#include "caplayer.h"
+#include "player.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <math.h>
-
-#include "cacartype.h"
+#include "cartype.h"
#include "caimagemanipulation.h"
#include "catrophy.h"
-#include "camath.h"
+#include "utils/trophymath.h"
#include "capositiontable.h"
+#include "track.h"
/** Constructor.
\param id Id of this player (for network) or -1 for no id
@@ -17,19 +14,21 @@
\param moving Is this sprite controlled by the player (Keyboard),
the computer (Computer) or a net player (Network)
*/
-CAPlayer::CAPlayer( int id, std::string name,
- int carNumber,
- ControlMode controlMode ) {
- for( int i=0; i<CA_FPR; ++i ) {
+Player::Player( int id, const std::string& name,
+ int carNumber)
+: m_Pcar(CA_APP->carType[carNumber])
+{
+ for( int i=0; i<CA_FPR; ++i )
+ {
sprite[i] = 0;
}
this->id = id;
this->name = name;
- this->controlMode = controlMode;
this->carNumber = carNumber;
- setCarNumber( carNumber, false );
- cMaxSpeed = carType->maxSpeed;
+
+ cMaxSpeed = m_Pcar.getMotor()->getMaxSpeed(); // TODO: chack if cMaxSpeed is increase after an upgrade
+ cAcceleration = m_Pcar.getMotor()->getAcceleration(); // TODO: idem
active = true;
explFrame = 0.0;
@@ -42,9 +41,12 @@ CAPlayer::CAPlayer( int id, std::string name,
/** Destructor.
*/
-CAPlayer::~CAPlayer() {
- for( int i=0; i<CA_FPR; ++i ) {
- if( sprite[i] ) {
+Player::~Player()
+{
+ for( int i=0; i<CA_FPR; ++i )
+ {
+ if( sprite[i] )
+ {
delete sprite[i];
sprite[i] = 0;
}
@@ -54,18 +56,19 @@ CAPlayer::~CAPlayer() {
/** Resets this player.
*/
void
-CAPlayer::reset() {
+Player::reset() {
money = 1000; // Initial money for each player
totalPoints = 0;
- totalRank = 0;
-
- resetForRace();
+ resetForRace(0, NULL); // we set player no tracks
}
/** Reset things before a new race starts.
+ \param routeNumber The initial route number for this player
+ \currentTrack The track where the race is
*/
-void
-CAPlayer::resetForRace() {
+void Player::resetForRace( const unsigned int routeNumber, const Track* currentTrack)
+{
+ m_currentTrack = currentTrack;
active = true;
setFrame( 0 );
@@ -80,29 +83,39 @@ CAPlayer::resetForRace() {
shootMode = false;
life = 100.0;
- armor = 0;
- bullets = 33;
+ bullets = 500;
fogBombs = 2;
racePoints = 0;
raceRank = 0;
raceTime = 0;
+ m_raceMoney = 0;
- turbo = carType->maxTurbo; // Current turbo load (in pixel!)
+ turbo = m_Pcar.maxTurbo; // Current turbo load (in pixel!)
turboActive = 0;
+ cMaxSpeed = m_Pcar.getMotor()->getMaxSpeed(); // TODO: check if cMaxSpeed is increase after an upgrade
+ cAcceleration = m_Pcar.getMotor()->getAcceleration(); // TODO: idem
resetHitPoints();
- routePoint = 1;
- routeNumber = 0;
-
lapNumber = 0;
lapParts = 1;
lastLapPart = 0;
finished = false;
death = false;
+ lapped = false;
- newCar = false;
+ // Put the player on the start grid at the right angle
+ if (m_currentTrack != NULL)
+ {
+ float nx=0; float ny=0;
+ unsigned int routePoint = 0; // At start the route point is always 0
+ unsigned int TempRouteNumber = routeNumber; // to keep routeNumber const
+ m_currentTrack->getNextRoutePoint(TempRouteNumber, routePoint, nx, ny);
+ move( nx, ny );
+ setDirection( m_currentTrack->getStartAngle() );
+ }
+
}
/** Sets a new color for this player.
@@ -110,47 +123,49 @@ CAPlayer::resetForRace() {
\param render Render new sprites?
*/
void
-CAPlayer::setColor( CAColor col, bool render ) {
+Player::setColor( HSVColor col, bool render ) {
if( color!=col || sprite[0]==0 ) {
color = col;
if( render ) renderSprites( color );
}
}
+/** buy a new car (car number 0-CA_NUMCARS)
+ \param carNumber (index of CATrophy::carType)
+ */
+void
+Player::buyNewCar(const int carNumber, const bool render)
+{
+ setCarNumber(carNumber, render);
+ spendMoney( CA_APP->carType[carNumber].price );
+}
+
+
/** Sets a new car for this player.
\param carNumber Car number (index of CATrophy::carType[])
\param render Render new sprites?
*/
void
-CAPlayer::setCarNumber( int carNumber, bool render ) {
- if( carNumber<CA_NUMCARTYPES ) carType = &(CA_APP->carType[carNumber]);
- else carType = &(CA_APP->carType[0]);
-
- this->carNumber = carNumber;
+Player::setCarNumber( const int carNumber,const bool render ) {
+ if( carNumber<CA_NUMCARTYPES ) m_Pcar = CarType(CA_APP->carType[carNumber]);
+ else m_Pcar = CarType(CA_APP->carType[0]);
+ if (this->carNumber != carNumber)
+ {
+ this->carNumber = carNumber;
- if( render ) renderSprites( color );
+ if( render ) renderSprites( color );
+ }
}
-/** Init a computer player. This method moves the player to the start
- point and gives the right direction.
- \param routeNumber The initial route number for this player
-*/
-void
-CAPlayer::initPlayer( int routeNumber ) {
- //reset();
- this->routeNumber = routeNumber;
- move( CA_APP->track.rp[routeNumber][0][0], CA_APP->track.rp[routeNumber][0][1] );
- setDirection( CA_APP->track.startAngle );
-}
/** Renders the sprites for this player. The car image gets
rotated and the color adjusted to 'color'.
*/
void
-CAPlayer::renderSprites( CAColor col )
+Player::renderSprites( HSVColor col )
{
/*
- CL_Surface* tmpSf = CAImageManipulation::changeHSV( carType->surface,
+ CL_Surface* tmpSf = CAImageManipulation::changeHSV( m_Pcar.surface,
color.h, color.s, color.v );
for( int i=0; i<CA_FPR; ++i ) {
if( sprite[i] ) delete sprite[i];
@@ -163,7 +178,7 @@ CAPlayer::renderSprites( CAColor col )
// green as the transparency channel - which results in this
// massive overhead of calculations / waste of memory - sorry.
CL_Surface* tmpSf;
- tmpSf = CAImageManipulation::changeHSV( carType->surface, color.h, color.s, color.v );
+ tmpSf = CAImageManipulation::changeHSV( m_Pcar.surface, color.h, color.s, color.v );
for( int i=0; i<CA_FPR; ++i )
{
if( sprite[i] ) delete sprite[i];
@@ -176,7 +191,7 @@ CAPlayer::renderSprites( CAColor col )
/** Changes the direction and the frame of this sprite.
*/
void
-CAPlayer::setDirection( float dir )
+Player::setDirection( float dir )
{
newDirection=dir;
if( newDirection >= 360.0 ) newDirection-=360.0;
@@ -189,258 +204,42 @@ CAPlayer::setDirection( float dir )
/** Changes the speed of this sprite.
*/
void
-CAPlayer::setSpeed( float sp )
+Player::setSpeed( float sp )
{
speed = sp;
if( speed > cMaxSpeed ) speed = cMaxSpeed;
- if( speed < carType->minSpeed ) speed = carType->minSpeed;
+ if( speed < m_Pcar.minSpeed ) speed = m_Pcar.minSpeed;
+
}
/** Changes the turbo load of this sprite.
*/
void
-CAPlayer::setTurbo( float tb ) {
+Player::setTurbo( const float tb ) {
turbo = tb;
- if( turbo > carType->maxTurbo ) turbo = carType->maxTurbo;
+ if( turbo > m_Pcar.maxTurbo ) turbo = m_Pcar.maxTurbo;
if( turbo < 0 ) turbo = 0;
}
-/** Controls the player by keyboard. Only called for keyboard (human) players.
- Computer players rather call 'autoPilot()'.
-*/
-void
-CAPlayer::keyControl() {
- // We're death and can't drive anymore:
- //
- if( death || finished ) {
- speedMode = Constant;
- }
-
- // We're alive:
- //
- else {
- // Accelerate (E/UP):
- //
- if( CL_Keyboard::get_keycode(CL_KEY_E) ||
- CL_Keyboard::get_keycode(CL_KEY_UP) ) {
- speedMode = Accelerate;
- }
-
- // Decelerate (D/DOWN):
- //
- else if( CL_Keyboard::get_keycode(CL_KEY_D) ||
- CL_Keyboard::get_keycode(CL_KEY_DOWN) ) {
- speedMode = Decelerate;
- }
-
- // Don't change speed:
- //
- else {
- speedMode = Constant;
- }
- }
-
- if( !death ) {
- // Steer left:
- //
- if( CL_Keyboard::get_keycode(CL_KEY_LEFT) ||
- CL_Keyboard::get_keycode(CL_KEY_N)) {
- directionMode = Left;
- }
-
- // Steer right:
- //
- else if( CL_Keyboard::get_keycode(CL_KEY_RIGHT) ||
- CL_Keyboard::get_keycode(CL_KEY_M)) {
- directionMode = Right;
- }
-
- // Don't change direction:
- //
- else {
- directionMode = Straight;
- }
- }
-
- // Horn:
- //
- if( CL_Keyboard::get_keycode(CL_KEY_SPACE) ) {
- CA_RES->effectHorn->play();
- }
-
- // Shoot:
- //
- if( CL_Keyboard::get_keycode(CL_KEY_X) ) {
- if( !finished && !death && CA_APP->allowShooting && bullets>0 ) {
- CA_RES->effectShoot->play( 2 );
- shoot();
- }
- } else {
- shootMode = false;
- }
-
- // Drop fog bomb:
- //
- static bool blockKeyF = false;
- if( CL_Keyboard::get_keycode(CL_KEY_C) ) {
- if( !finished && !death && CA_APP->allowShooting && !blockKeyF && fogBombs!=0 ) {
- CA_APP->dropFogBomb( (int)x,(int)y,up );
- fogBombs--;
- blockKeyF = true;
- }
- } else {
- blockKeyF = false;
- }
-
- // Turbo:
- //
- if( CL_Keyboard::get_keycode(CL_KEY_A) ) {
- activateTurbo();
- } else {
- deactivateTurbo();
- }
-}
-
-/** Calculates route of computer players.
-*/
-void
-CAPlayer::autoPilot()
+bool Player::spendMoney(const int value)
{
- // Choose new route by shuffle:
- //
- if( routePoint >= CA_APP->track.routePoints )
+ bool wasAbleToBuy = false;
+ if (money >= value)
{
- routePoint=0;
- routeNumber = CAMath::getRandomNumber( 0, CA_MAXPLAYERS-1 );
- }
-
- // Next coordinate to locate
- //
- float nx = CA_APP->track.rp[routeNumber][routePoint][0];
- float ny = CA_APP->track.rp[routeNumber][routePoint][1];
-
- // Angle to next route point:
- //
- float b = CAMath::getAngle( x,y, nx,ny );
- float diff = CAMath::getAngleDiff( direction, b );
- float dist = CAMath::getDistance( x,y, nx,ny );
-
- bool retard = false;
-
- // Steer:
- //
- // TODO : autoPilot should also take care of functionMap pixel that are under
- // edges of the car (or better, next to the edges)
- if (diff<20.0 || diff>340.0) {
- directionMode = Straight;
- } else if (diff<180.0) {
- // TODO : was commented
- //if( diff>40.0 ) retard=true;
- directionMode = Right;
- } else if (diff>180.0) {
- // TODO : was commented
- //if( diff<320.0 ) retard=true;
- directionMode = Left;
- }
-
- // Switch to next route point:
- //
- // TODO : clean these constants all over the code (original = 120)!
- if (dist < 120.0) {
- ++routePoint;
- }
-
- // Speed:
- //
- if( !death && !finished && !retard ) speedMode=Accelerate;
- else speedMode=Constant;
-
-
- if( !death && !finished )
- {
- // Decide wheter to activate turbo or not:
- //
- // TODO : strange ...
- // CATrophy::Easy -> turboLaunchDistance = 600 or deactivateTurbo() ?
- if( CA_APP->difficulty!=CATrophy::Easy ) {
- int turboLaunchDistance = 600;
- switch( CA_APP->difficulty ) {
- case CATrophy::Easy:
- turboLaunchDistance = 600;
- break;
- case CATrophy::Medium:
- turboLaunchDistance = 200;
- break;
- case CATrophy::Hard:
- turboLaunchDistance = 50;
- break;
- }
- int xt = (int)(x + cos( newDirection/ARAD ) * turboLaunchDistance);
- int yt = (int)(y + sin( newDirection/ARAD ) * turboLaunchDistance);
- int xt2 = (int)((x + xt)/2);
- int yt2 = (int)((y + yt)/2);
- if( turbo>0.0 &&
- CA_APP->getSpeedLimit(xt,yt)==15 &&
- CA_APP->getSpeedLimit(xt2,yt2)==15 ) {
- activateTurbo();
- } else {
- deactivateTurbo();
- }
- } else {
- deactivateTurbo();
- }
-
- // Decide wheter to shoot or not:
- //
- if( CA_APP->allowShooting && bullets!=0 )
- {
- int distance;
- int angle;
- int angleDiff;
- shootMode = false;
- for( int pl=0; pl<CA_MAXPLAYERS; ++pl ) {
- if( pl!=id ) {
- distance = (int)CAMath::getDistance( x,y, CA_APP->player[pl]->getX(),CA_APP->player[pl]->getY() );
- angle = (int)CAMath::getAngle( x,y, CA_APP->player[pl]->getX(),CA_APP->player[pl]->getY() );
- angleDiff = (int)CAMath::getAngleDiff( angle, newDirection );
- if( distance<CA_SHOOTINGRANGE && (angleDiff < 10.0 || angleDiff > 350.0) ) {
- shoot();
- break;
- }
- }
- }
- }
-
- // Decide wheter to drop a fog bomb or not:
- //
- if( CA_APP->allowShooting && fogBombs!=0 )
- {
- int distance;
- int angle;
- int angleDiff;
- for( int pl=0; pl<CA_MAXPLAYERS; ++pl ) {
- if( pl!=id ) {
- distance = (int)CAMath::getDistance( x,y, CA_APP->player[pl]->getX(),CA_APP->player[pl]->getY() );
- angle = (int)CAMath::getAngle( x,y, CA_APP->player[pl]->getX(),CA_APP->player[pl]->getY() );
- angleDiff = (int)CAMath::getAngleDiff( angle, newDirection );
- if( distance>200 && distance<202 && angleDiff < 185.0 && angleDiff > 175.0 ) {
- CA_APP->dropFogBomb( (int)x,(int)y,up );
- fogBombs--;
- break;
- }
- }
- }
- }
+ money-= value;
+ wasAbleToBuy = true;
}
+ return wasAbleToBuy;
}
+
/** Called on every "step" the game makes.
The Sprite moves according to speed and direction.
*/
void
-CAPlayer::advance()
+Player::advance()
{
// Play engine sound (Volume of engine sound depends on speed):
//
@@ -452,8 +251,8 @@ CAPlayer::advance()
// Slide towards direction:
//
- if( !CAMath::compFloat(direction, newDirection) ) {
- float dirStep = (carType->steeringPower / CA_APP->framesPerSec) * carType->slidingFactor;
+ if( !TrophyMath::compFloat(direction, newDirection) ) {
+ float dirStep = (m_Pcar.steeringPower / CA_APP->framesPerSec) * m_Pcar.getTires()->getSlidingFactor();
if( (newDirection>direction && newDirection-direction<=180.0) ||
(newDirection<direction && direction-newDirection> 180.0) ) {
@@ -494,7 +293,7 @@ CAPlayer::advance()
}
- if( controlMode!=Network && active ) {
+ if( active ) {
// Check collisions with other players / goodies
//
@@ -506,8 +305,8 @@ CAPlayer::advance()
// Regulate Speed:
//
- if( speedMode==Accelerate ) setSpeed( speed + (carType->acceleration / CA_APP->framesPerSec) );
- else if( speedMode==Decelerate ) setSpeed( speed - (carType->deceleration / CA_APP->framesPerSec) );
+ if( speedMode==Accelerate ) setSpeed( speed + (cAcceleration / CA_APP->framesPerSec) );
+ else if( speedMode==Decelerate ) setSpeed( speed - (m_Pcar.deceleration / CA_APP->framesPerSec) );
else {
setSpeed( speed * 0.96 );
if( fabs(speed)<10.0 ) speed=0.0;
@@ -516,7 +315,8 @@ CAPlayer::advance()
// Control direction:
//
// TODO : It seems that the turning problem of cars is here ... maybe when steeringPower < 1.5 ?
- float steeringPower = (carType->steeringPower / CA_APP->framesPerSec) * (speed / carType->maxSpeed);
+ // TODO: examines what happens when speed > getMaxSpeed (ie during turbo)
+ float steeringPower = (m_Pcar.steeringPower / CA_APP->framesPerSec) * (speed / m_Pcar.getMotor()->getMaxSpeed());
//if( steeringPower<1.5 && steeringPower>=0.0 ) steeringPower = 1.5;
if( (steeringPower<200 / CA_APP->framesPerSec) && steeringPower>=0.0 ) steeringPower = 200 / CA_APP->framesPerSec;
@@ -534,20 +334,20 @@ CAPlayer::advance()
// Moving out of map?
//
- if( nx < 0 || nx >= CA_APP->track.visualMap->get_width() ) vx *= -1;
- if( ny < 0 || ny >= CA_APP->track.visualMap->get_height() ) vy *= -1;
+ if( nx < 0 || nx >= m_currentTrack->getWidth() ) vx *= -1;
+ if( ny < 0 || ny >= m_currentTrack->getHeight() ) vy *= -1;
// Unload turbo:
//
if( turboActive && turbo>0.0 ) {
- setTurbo( turbo - CAMath::getDistance( x,y, nx,ny ) );
+ setTurbo( turbo - TrophyMath::getDistance( x,y, nx,ny ) );
if( turbo<=0.0 ) deactivateTurbo();
}
// Auto Reload turbo
//
else {
- setTurbo( turbo + CAMath::getDistance( x,y, nx,ny ) * (carType->maxTurbo/5000.0) );
+ setTurbo( turbo + TrophyMath::getDistance( x,y, nx,ny ) * (m_Pcar.maxTurbo/5000.0) );
}
// Move now:
@@ -563,52 +363,62 @@ CAPlayer::advance()
/** Checks collisions of this sprite with others.
*/
void
-CAPlayer::checkCollisions() {
+Player::checkCollisions()
+{
// Other players:
//
- for( int c=0; c<CA_MAXPLAYERS; ++c ) {
- CAPlayer* pl = CA_APP->player[c];
- if( pl!=this ) {
+ for( int c=0; c<CA_RACEMAXPLAYERS; ++c )
+ {
+ Player* pl = CA_APP->m_RacePlayer[c];
+ if( pl!=this )
+ {
if( x+32 > pl->getX()-32 && x-32 < pl->getX()+32 &&
y+32 > pl->getY()-32 && y-32 < pl->getY()+32 &&
- up == pl->isUp() ) {
+ up == pl->isUp() )
+ {
bool inters = false;
int ix, iy;
- for( int i=0; i<4 && !inters; ++i ) {
+ for( int i=0; i<4 && !inters; ++i )
+ {
int ni = i+1;
if( ni==4 ) ni=0;
- for( int j=0; j<4 && !inters; ++j ) {
+ for( int j=0; j<4 && !inters; ++j )
+ {
int nj = j+1;
if( nj==4 ) nj=0;
- if( CAMath::getIntersection( edge[i][0], edge[i][1], edge[ni][0], edge[ni][1],
+ if( TrophyMath::getIntersection( edge[i][0], edge[i][1], edge[ni][0], edge[ni][1],
pl->edge[j][0], pl->edge[j][1], pl->edge[nj][0], pl->edge[nj][1],
- &ix, &iy) ) {
+ &ix, &iy) )
+ {
inters = true;
}
}
}
- if( inters ) {
-
+ if( inters )
+ {
// Play crash sound:
//
- if( id==0 || pl->getId()==0 ) {
+ if( id==0 || pl->getId()==0 )
+ {
if( CA_APP->sound ) CA_RES->effectCrash->play();
}
- float ang = CAMath::getAngle (x, y, pl->getX(), pl->getY());
- if( pl->checkEdgeState() ) { // Don't check players into borders
+ float ang = TrophyMath::getAngle (x, y, pl->getX(), pl->getY());
+ if( pl->checkEdgeState() )
+ { // Don't check players into borders
pl->move( pl->getX()+cos(ang/ARAD)*4,
pl->getY()+sin(ang/ARAD)*4 );
pl->setSpeed( pl->getSpeed()*0.98 );
pl->hit( 0.1 );
}
- if( checkEdgeState() ) {
+ if( checkEdgeState() )
+ {
move( x-cos(ang/ARAD)*4,
y-sin(ang/ARAD)*4 );
setSpeed( getSpeed()*0.98 );
@@ -622,41 +432,26 @@ CAPlayer::checkCollisions() {
// Goodies:
//
- for( int gt=0; gt<CA_NUMGOODYTYPES; gt++ ) {
- for( int gi=0; gi<CA_NUMGOODIES; gi++ ) {
+ for( unsigned int gt=0; gt<CA_APP->goody.size(); gt++ )
+ for( unsigned int gi=0; gi<CA_APP->goody[gt].size(); gi++ )
+ {
CAGoody* go = CA_APP->goody[gt][gi];
if( go->isActive() ) {
if( go->isUp()==isUp() &&
- CAMath::getDistance( x,y, go->getX(),go->getY() ) < 28.0 ) {
-
- if( go->getType()->name == "Turbo" ) {
- setTurbo( turbo+1000 );
- if( id==0 ) CA_RES->effectGoodyTurbo->play();
- } else if( go->getType()->name == "Life" ) {
- if( !death && !finished ) setLife( life+25.0 );
- if( id==0 ) CA_RES->effectGoodyLife->play();
- } else if (go->getType ()->name == "Bullets") {
- setBullets( bullets+100 );
- if( id==0 ) CA_RES->effectGoodyBullets->play();
- } else if (go->getType ()->name == "Fogbomb") {
- setFogBombs( fogBombs+1 );
- if( id==0 ) CA_RES->effectGoodyFogbomb->play();
- } else if( go->getType()->name == "Money" ) {
- money+=100;
- if( id==0 ) CA_RES->effectGoodyMoney->play();
- }
+ TrophyMath::getDistance( x,y, go->getX(),go->getY() ) < 28.0 ) // TODO: Hard value
+ {
+ go->getType()->catchGoodie(this);
go->reset();
}
}
}
- }
}
/** Checks underlying function map.
*/
void
-CAPlayer::checkFunctionMap()
+Player::checkFunctionMap()
{
// lapParts is a bit pattern of fulfilled lap parts (15 parts total)
// 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 = Lap part 1 and 2 fulfilled
@@ -676,11 +471,11 @@ CAPlayer::checkFunctionMap()
// Car edge is out of map:
//
- if( !CA_APP->checkCoordinate( px,py ) ) continue;
+ if( !m_currentTrack->checkCoordinate( px,py ) ) continue;
// Get the function pixel under this edge:
//
- CL_Color tmp = CA_APP->track.functionMap->get_pixel( edge[i][0],edge[i][1] );
+ CL_Color tmp = m_currentTrack->getFunctionalPixel( edge[i][0],edge[i][1] );
g = tmp.get_green();
// Calculate speed reduction:
@@ -697,22 +492,21 @@ CAPlayer::checkFunctionMap()
{
// Check car away (computer players check away stronger):
//
- float cangle=2.5;
- if( controlMode==Computer ) cangle=7.5;
+ const float cangle = getCheckAwayAngle();
switch(i)
{
default:
case 0:
- if( speed>0 ) setDirection( CAMath::corrAngle(newDirection-cangle) );
+ if( speed>0 ) setDirection( TrophyMath::corrAngle(newDirection-cangle) );
break;
case 1:
- if( speed>0 ) setDirection( CAMath::corrAngle(newDirection+cangle) );
+ if( speed>0 ) setDirection( TrophyMath::corrAngle(newDirection+cangle) );
break;
case 2:
- if( speed<0 ) setDirection( CAMath::corrAngle(newDirection-cangle) );
+ if( speed<0 ) setDirection( TrophyMath::corrAngle(newDirection-cangle) );
break;
case 3:
- if( speed<0 ) setDirection( CAMath::corrAngle(newDirection+cangle) );
+ if( speed<0 ) setDirection( TrophyMath::corrAngle(newDirection+cangle) );
break;
}
direction = newDirection;
@@ -735,7 +529,7 @@ CAPlayer::checkFunctionMap()
if( !CA_APP->checkCoordinate( px,py ) ) return;
- CL_Color tmp = CA_APP->track.functionMap->get_pixel( px,py );
+ CL_Color tmp = m_currentTrack->getFunctionalPixel( px,py );
r = tmp.get_red();
g = tmp.get_green();
b = tmp.get_blue();
@@ -768,7 +562,7 @@ CAPlayer::checkFunctionMap()
// Lap part:
//
- if( lapPart!=0 && !finished && !death )
+ if( lapPart!=0 && !finished && !death && !lapped )
{
// We pass another lap part:
//
@@ -792,8 +586,16 @@ CAPlayer::checkFunctionMap()
if( lapNumber==CA_NUMLAPS ) {
finished = true;
raceTime = CA_APP->getTime();
- CA_POSITIONTABLE->playerFinishedRace( this );
+ CAPositionTable::getPositionTable()->playerFinishedRace( this );
}
+ else if (CAPositionTable::getPositionTable()->isPossibleWin()==false)
+ {
+ lapped = true;
+ raceTime = 0;
+ m_raceMoney = 0;
+ // Player is definitely lapped so we don't allow him finish
+ CAPositionTable::getPositionTable()->playerFinishedLapped(this);
+ }
}
lapParts=1;
}
@@ -805,11 +607,11 @@ CAPlayer::checkFunctionMap()
/** Calculate edges of the sprite
*/
void
-CAPlayer::calcEdges() {
+Player::calcEdges() {
float dx, dy;
- dx = cos( (newDirection + carType->angle) / ARAD ) * carType->radius;
- dy = sin( (newDirection + carType->angle) / ARAD ) * carType->radius;
+ dx = cos( (newDirection + m_Pcar.angle) / ARAD ) * m_Pcar.radius;
+ dy = sin( (newDirection + m_Pcar.angle) / ARAD ) * m_Pcar.radius;
edge[0][0] = (int)(x + dx);
edge[0][1] = (int)(y + dy);
@@ -817,8 +619,8 @@ CAPlayer::calcEdges() {
edge[2][0] = (int)(x - dx);
edge[2][1] = (int)(y - dy);
- dx = cos( (newDirection - carType->angle) / ARAD ) * carType->radius;
- dy = sin( (newDirection - carType->angle) / ARAD ) * carType->radius;
+ dx = cos( (newDirection - m_Pcar.angle) / ARAD ) * m_Pcar.radius;
+ dy = sin( (newDirection - m_Pcar.angle) / ARAD ) * m_Pcar.radius;
edge[1][0] = (int)(x + dx);
edge[1][1] = (int)(y + dy);
@@ -830,10 +632,12 @@ CAPlayer::calcEdges() {
/** Shooting
*/
void
-CAPlayer::shoot() {
+Player::shoot()
+{
// Count down bullets:
//
- if( bullets>0 ) {
+ if( bullets>0 )
+ {
bullets--;
shootMode = true;
@@ -855,19 +659,24 @@ CAPlayer::shoot() {
// Look for a hit player:
//
- for( pl=0; pl<CA_MAXPLAYERS; ++pl ) {
- if( pl!=id && isUp()==CA_APP->player[pl]->isUp() ) {
- for( en=0; en<4; ++en ) {
+ for( pl=0; pl<CA_RACEMAXPLAYERS; ++pl )
+ {
+ if( CA_APP->m_RacePlayer[pl]!=this && isUp()==CA_APP->m_RacePlayer[pl]->isUp() )
+ {
+ for( en=0; en<4; ++en )
+ {
en2 = ((en==3) ? 0 : (en+1));
- inters = CAMath::getIntersection( rayX1, rayY1, rayX2, rayY2,
- CA_APP->player[pl]->edge[en][0],
- CA_APP->player[pl]->edge[en][1],
- CA_APP->player[pl]->edge[en2][0],
- CA_APP->player[pl]->edge[en2][1],
+ inters = TrophyMath::getIntersection( rayX1, rayY1, rayX2, rayY2,
+ CA_APP->m_RacePlayer[pl]->edge[en][0],
+ CA_APP->m_RacePlayer[pl]->edge[en][1],
+ CA_APP->m_RacePlayer[pl]->edge[en2][0],
+ CA_APP->m_RacePlayer[pl]->edge[en2][1],
&ix, &iy );
- if( inters ) {
- dist = (int)CAMath::getDistance( rayX1, rayY1, ix,iy );
- if( dist<minDist ) {
+ if( inters )
+ {
+ dist = (int)TrophyMath::getDistance( rayX1, rayY1, ix,iy );
+ if( dist<minDist )
+ {
minDist = dist;
hitPl = pl;
hitX = ix + (int)(cos( newDirection/ARAD ) * 5);
@@ -878,9 +687,10 @@ CAPlayer::shoot() {
}
}
- if( hitPl>=0 && hitPl<CA_MAXPLAYERS ) {
- CA_APP->player[hitPl]->addHitPoint( hitX, hitY );
- CA_APP->player[hitPl]->hit( 0.8 );
+ if( hitPl>=0 && hitPl<CA_RACEMAXPLAYERS )
+ {
+ CA_APP->m_RacePlayer[hitPl]->addHitPoint( hitX, hitY );
+ CA_APP->m_RacePlayer[hitPl]->hit( 0.16 );
}
}
}
@@ -889,9 +699,9 @@ CAPlayer::shoot() {
\param amount How hard was the hit?
*/
void
-CAPlayer::hit( float amount ) {
- if( !death && !finished ) {
- life -= amount/100.0*(100.0-armor);
+Player::hit( const float amount ) {
+ if( !death && !finished && !lapped) {
+ life -= amount/100.0*(100.0-m_Pcar.getArmor()->getArmor());
if( life<0.1 ) {
kill();
}
@@ -901,35 +711,36 @@ CAPlayer::hit( float amount ) {
/** Player was killed.
*/
void
-CAPlayer::kill() {
+Player::kill() {
if( !death ) {
life=0.0;
death=true;
- CA_POSITIONTABLE->playerDied( this );
+ m_raceMoney = 0;
+ CAPositionTable::getPositionTable()->playerDied( this );
}
}
/** Displays the player on it's current position.
*/
void
-CAPlayer::display( int offsetX, int offsetY )
+Player::display( const int offsetX, const int offsetY )
{
sprite[frame]->draw ( (int)(x+offsetX - sprite[ frame ]->get_width()/2),
- (int)(y+offsetY - sprite[ frame ]->get_height()/2) );
+ (int)(y+offsetY - sprite[ frame ]->get_height()/2) );
// Display hit points:
//
for( int c=0; c<hitPointCounter; ++c )
{
- CA_RES->misc_hitpoint->set_frame(CAMath::getRandomNumber( 0,4 ));
+ CA_RES->misc_hitpoint->set_frame(TrophyMath::getRandomNumber( 0,4 ));
CA_RES->misc_hitpoint->draw ( hitPoint[c][0]+offsetX - CA_RES->misc_hitpoint->get_width()/2,
- hitPoint[c][1]+offsetY - CA_RES->misc_hitpoint->get_height()/2);
+ hitPoint[c][1]+offsetY - CA_RES->misc_hitpoint->get_height()/2);
}
resetHitPoints();
// Display gun fire:
//
- if( !death && !finished && shootMode && bullets>0 )
+ if( !death && !finished && !lapped && shootMode && bullets>0 )
{
int gunX, gunY;
gunX = (int)(x + cos( newDirection/ARAD ) * 18) - CA_RES->misc_gunfire->get_width()/2;
@@ -938,8 +749,8 @@ CAPlayer::display( int offsetX, int offsetY )
CA_RES->misc_gunfire->draw ( gunX+offsetX, gunY+offsetY );
}
- // Display car fire if we're death:
- //
+ // Display car fire if we're death or if we are almost dead:
+ // TODO: differentate death and almost dead
if( death )
{
CA_RES->misc_carfire->set_frame((int)floor(explFrame));
@@ -951,7 +762,7 @@ CAPlayer::display( int offsetX, int offsetY )
/** Reimplemented for moving the shadow with the sprite.
*/
void
-CAPlayer::move( float x, float y ) {
+Player::move( float x, float y ) {
ox = this->x;
oy = this->y;
this->x = x;
@@ -961,9 +772,10 @@ CAPlayer::move( float x, float y ) {
/** Activates turbo mode.
*/
void
-CAPlayer::activateTurbo() {
+Player::activateTurbo() {
if( turbo>0 ) {
- cMaxSpeed = carType->maxSpeed * CA_TURBOFACTOR;
+ cMaxSpeed = m_Pcar.getMotor()->getMaxSpeed() * CA_TURBOFACTOR;
+ cAcceleration = m_Pcar.getMotor()->getAcceleration() * CA_TURBOFACTOR;
turboActive = true;
}
}
@@ -971,8 +783,9 @@ CAPlayer::activateTurbo() {
/** Deactivates turbo mode.
*/
void
-CAPlayer::deactivateTurbo() {
- cMaxSpeed = carType->maxSpeed;
+Player::deactivateTurbo() {
+ cMaxSpeed = m_Pcar.getMotor()->getMaxSpeed();
+ cAcceleration = m_Pcar.getMotor()->getAcceleration();
turboActive =false;
}
@@ -980,7 +793,7 @@ CAPlayer::deactivateTurbo() {
e.g. 3.5 means the player has finished 3.5 laps
*/
float
-CAPlayer::getPosition() {
+Player::getPosition() {
float ret = lapNumber;
int fraction=0;
int leftOut=0;
@@ -1003,14 +816,14 @@ CAPlayer::getPosition() {
/** Resets all hit points. This happens once for every screen.
*/
void
-CAPlayer::resetHitPoints() {
+Player::resetHitPoints() {
hitPointCounter = 0;
}
/** Adds a hit point for the next screen.
*/
void
-CAPlayer::addHitPoint( int x, int y ) {
+Player::addHitPoint( int x, int y ) {
if( hitPointCounter<CA_MAXHITPOINTS ) {
hitPoint[hitPointCounter][0] = x;
hitPoint[hitPointCounter][1] = y;
diff --git a/src/caplayer.h b/src/player.h
similarity index 52%
rename from src/caplayer.h
rename to src/player.h
index 7c7b48e..a35ca9b 100644
--- a/src/caplayer.h
+++ b/src/player.h
@@ -1,275 +1,190 @@
-#ifndef CAPLAYER_H
-#define CAPLAYER_H
+#ifndef PLAYER_H
+#define PLAYER_H
#include <string>
#include <ClanLib/core.h>
#include <ClanLib/display.h>
-#include "cacolor.h"
-#include "camath.h"
+#include "utils/hsvcolor.h"
+#include "utils/trophymath.h"
+#include "cartype.h"
-struct CACarType;
+class Track;
/** Covers all data and methods for a single player.
@author Andrew Mustun
+ @author Matthieu Lecesne
*/
-class CAPlayer {
+// TODO: id is uncesssary (in local game), it is only use to know who is the player
+class Player
+{
public:
- enum ControlMode { Keyboard, Computer, Network };
enum Direction { Left, Right, Straight };
enum Speed { Accelerate, Decelerate, Constant };
- CAPlayer( int id, std::string name,
- int carNumber,
- ControlMode controlMode=Keyboard );
- ~CAPlayer();
+ Player( int id, const std::string& name,
+ int carNumber);
+ virtual ~Player();
void reset();
- void resetForRace();
-
- void initPlayer( int routeNumber );
- void renderSprites( CAColor col );
+ virtual void resetForRace(const unsigned int routeNumber, const Track* currentTrack);
//! Returns ID of this player.
- int getId() const {
- return id;
- }
+ int getId() const { return id; }
//! Sets ID of this player.
- void setId( int i ) {
- id=i;
- }
+ void setId( int i ) { id=i; }
//! Returns name of this player.
- std::string getName() const {
- return name;
- }
+ std::string getName() const { return name; }
//! Sets name of this player.
- void setName( std::string n ) {
- name=n;
- }
+ void setName( const std::string& n ) { name=n; }
//! Returns the color of this player.
- CAColor getColor() const {
- return color;
- }
- void setColor( CAColor c, bool render=true );
+ HSVColor getColor() const { return color; }
+ void setColor( HSVColor c, bool render=true );
- void setCarNumber( int carNumber, bool render=true );
+
+ void buyNewCar(const int carNumber, const bool render = true);
+
+ void setCarNumber(const int carNumber, const bool render = true);
//! Returns current car number (0-CA_NUMCARS).
- int getCarNumber() {
- return carNumber;
- }
-
- /** Sets the newCar flag. Used for showing who has bought
- a new car in the position table.
- */
- void setNewCar( bool nc ) {
- newCar=nc;
- }
- //! Returns the newCar flag.
- bool getNewCar() {
- return newCar;
- }
-
- //! Returns pointer to car type.
- CACarType* getCarType() {
- return carType;
- }
-
- //! Returns control mode of this player (Keyboard, Computer, Network)
- ControlMode getControlMode() {
- return controlMode;
- }
- //! Sets a new control mode for this player.
- void setControlMode( ControlMode cm ) {
- controlMode = cm;
- }
+ int getCarNumber() const { return carNumber; }
+
+ //! Returns pointers to player car
+ CarType* getCar() { return &m_Pcar; }
//! Returns the direction of this player in degrees (0=right, 90=bottom (!)).
- float getDirection() const {
- return direction;
- }
+ float getDirection() const { return direction; }
void setDirection(float dir);
+
//! Returns the current speed of this player.
- float getSpeed() const {
- return speed;
- }
+ float getSpeed() const { return speed; }
void setSpeed( float sp );
//! Returns turbo load left.
- float getTurbo() const {
- return turbo;
- }
- void setTurbo( float tb );
+ float getTurbo() const { return turbo; }
+ void setTurbo( const float tb );
//! Returns true if this player is currently on a bridge, false otherwise.
- bool isUp() {
- return up;
- }
+ bool isUp() const { return up; }
//! Returns the current frame number.
- int getFrame() const {
- return frame;
- }
+ int getFrame() const { return frame; }
//! Sets a new frame number.
- void setFrame( int f ) {
- frame=f;
- }
+ void setFrame( int f ) { frame=f; }
//! Returns true if this player is active (true) or not (false).
- bool isActive() {
- return active;
- }
+ bool isActive() const { return active; }
//! Activates or deactivates this player.
- void activate( bool yes=true ) {
- active=yes;
- }
+ void activate( bool yes=true ) { active=yes; }
//! Returns true if this player has finished the race successfully.
- bool hasFinished() {
- return finished;
- }
+ bool hasFinished() const { return finished; }
//! Returns true if this player died.
- bool isDeath() {
- return death;
- }
+ bool isDeath() const { return death; }
+
+ //! Returns true if this player is lapped
+ bool isLapped() const { return lapped; }
//! Returns the life this player has. (0-100)
- float getLife() const {
- return life;
- }
+ float getLife() const { return life; }
//! Sets a new life amount.
- void setLife( float l ) {
- life = (l>100 ? 100 : l);
- }
+ void setLife( float l ) { life = (l>100 ? 100 : l); }
//! Returns number of bullets left.
- int getBullets() const {
- return bullets;
- }
+ int getBullets() const { return bullets; }
//! Sets number of bullets left.
- void setBullets(int b) {
- bullets = (b>100 ? 100 : b);
- }
+ void setBullets(int b) { bullets = (b>500 ? 500 : b); }
//! Returns number of fog bombs left (0-3).
- int getFogBombs() const {
- return fogBombs;
- }
+ int getFogBombs() const { return fogBombs; }
//! Sets number of fog bombs left (0-3).
- void setFogBombs(int f) {
- fogBombs = (f>3 ? 3 : f);
- }
+ void setFogBombs(int f) { fogBombs = (f>3 ? 3 : f); }
+ //! use a fog bombs
+ void useFogBomb() { fogBombs--;}
//! Returns current rank of this player in the current/last race.
- int getRaceRank() const {
- return raceRank;
- }
+ int getRaceRank() const { return raceRank; }
//! Sets rank for this player.
- void setRaceRank(int r) {
- raceRank = r;
- }
+ void setRaceRank(int r) { raceRank = r; }
//! Returns time used for the last race in millisecnds.
- int getRaceTime() {
- return raceTime;
- }
+ int getRaceTime() const { return raceTime; }
//! Sets time used for the last race in millisecnds.
- void setRaceTime( int t ) {
- raceTime = t;
- }
+ void setRaceTime( int t ) { raceTime = t; }
//! Returns points for the last race.
- int getRacePoints() {
- return racePoints;
- }
+ int getRacePoints() const { return racePoints; }
//! Sets points for the last race.
- void setRacePoints( int p ) {
- racePoints = p;
- }
-
- //! Returns current rank of this player over all.
- int getTotalRank() const {
- return totalRank;
- }
- //! Sets current rank of this player over all.
- void setTotalRank(int r) {
- totalRank = r;
- }
+ void setRacePoints( int p ) { racePoints = p; }
//! Returns total points over all.
- int getTotalPoints() {
- return totalPoints;
- }
+ int getTotalPoints() const { return totalPoints; }
//! Sets total points over all.
- void setTotalPoints( int p ) {
- totalPoints = p;
- }
+ void setTotalPoints( int p ) { totalPoints = p; }
//! Returns the players money.
- int getMoney() const {
- return money;
- }
- //! Sets the players money.
- void setMoney( int m ) {
- money = m;
- }
-
- void keyControl();
- void autoPilot();
+ int getMoney() const { return money; }
+ //! Give Money to player
+ void addMoney(const int value) { money+= value;}
+ //! set Money to player
+ void setMoney(const int value) { money = value;}
+ //! Take Money from player return true if the player had enough money
+ bool spendMoney(const int value);
+
+ //! Returns the money that the player has won in the race
+ int getRaceMoney() const { return m_raceMoney; }
+ //! Give Race Money to player
+ void addRaceMoney(const int value) { m_raceMoney+= value;}
+
+ virtual void pilot() = 0;
void advance();
void checkCollisions();
void checkFunctionMap();
//! Returns true if all edges of the car are on the road.
- bool checkEdgeState() {
- return (edgeState[0] && edgeState[1] && edgeState[2] && edgeState[3]);
- }
+ bool checkEdgeState() { return (edgeState[0] && edgeState[1] && edgeState[2] && edgeState[3]); }
void calcEdges();
void shoot();
- void hit( float amount );
+ void hit( const float amount );
void kill();
- void display( int offsetX, int offsetY );
+ virtual void display( const int offsetX, const int offsetY );
void move( float x, float y );
//! Returns the players position in xp and yp.
- void getPosition( float &xp, float &yp ) {
- xp=x;
- yp=y;
- }
+ void getPosition( float &xp, float &yp ) const { xp=x; yp=y; }
//! Returns the x position
- float getX() {
- return x;
- }
+ float getX() const { return x; }
//! Returns the y position
- float getY() {
- return y;
- }
+ float getY() const { return y; }
void activateTurbo();
void deactivateTurbo();
float getPosition();
//! Returns current lap number.
- int getLapNumber() {
- return lapNumber;
- }
- //! Returns current route number. Routes are programmed ways for computer players.
- int getRouteNumber() {
- return routeNumber;
- }
+ int getLapNumber() const { return lapNumber; }
void addHitPoint( int x, int y );
void resetHitPoints();
+ //! Notification of Race Over
+ virtual void OnRaceOver() {}
+
+protected:
+ //! Returns the new direction of this player in degrees (0=right, 90=bottom (!)).
+ float getNewDirection() const { return newDirection; }
+
+ const Track* getCurrentTrack() {return m_currentTrack;}
private:
+ virtual float getCheckAwayAngle() = 0;
+ void renderSprites( HSVColor col );
//! Player id
-
- int id;
+ int id;
//! Player nick name
std::string name;
//! Active
@@ -279,31 +194,26 @@ private:
//! Current frame (sprite number)
int frame;
//! Players color (HSV model)
- CAColor color;
+ HSVColor color;
//! Current car type
- CACarType* carType;
+ CarType m_Pcar;
//! Car number (index of CA_Trophy::carType[])
int carNumber;
- //! Flag which tells us if that player has bought a new car.
- bool newCar;
//! Rendered sprites for this player (rotated and color-cycled)
CL_Surface* sprite[CA_FPR];
- /** Is this sprite moved by keyboard or controlled
- over network or by the computer
- */
- ControlMode controlMode;
-
//! current speed in pixel per second
float speed;
- //! Current max speed. This might differ from maxSpeed.
+ //! Current max speed. This might differ from maxSpeed (ie during turbo).
float cMaxSpeed;
+ //! Current acceleration speed. This might differ for accelaration (ie during turbo).
+ float cAcceleration;
//! Direction we want to have (but maybe we still slide towards it)
float newDirection;
/** Current direction (angle in deg). We drive in that direction
although the sprite might not point towards that direction.
- */
+ */
float direction;
//! Block direction? (if we're in collision state)
bool blockDirection;
@@ -329,21 +239,16 @@ private:
//! Current velocity in y
float vy;
- //! Index of next route point to drive to
- int routePoint;
- //! Route number
- int routeNumber;
-
//! Life (0-100)
float life;
- //! Armor (0-100)
- int armor;
//! Turbo (counts down to 0, 0 = no more turbo left)
float turbo;
//! Is the turbo active? (left shift pressed)
bool turboActive;
//! Money (0-?)
int money;
+ //! Race money
+ int m_raceMoney;
//! Munition left (100-0)
int bullets;
//! Fogbombs (0-3)
@@ -359,14 +264,14 @@ private:
bool finished;
//! Died before finishing the race
bool death;
+ //! lapped before finishing the race
+ bool lapped;
//! Total race time of last race in milliseconds
int raceTime;
//! Current rank of this player in current race
int raceRank;
//! Points in current race
int racePoints;
- //! Current rank in total ranking
- int totalRank;
//! Total points of all races
int totalPoints;
@@ -374,10 +279,12 @@ private:
int hitPoint[CA_MAXHITPOINTS][2];
//! current index for the hitPoint array.
int hitPointCounter;
+ // ! The track where the player is assigned
+ const Track* m_currentTrack;
-public:
- //! speed mode. Accelerate, Decelerate, Constant
+protected:
+ //! speed mode. Accelerate, Decelerate, Constant
Speed speedMode;
//! direction mode. Left, Right, Straight
Direction directionMode;
diff --git a/src/shopscreen.cpp b/src/shopscreen.cpp
new file mode 100644
index 0000000..8f8d4dc
--- /dev/null
+++ b/src/shopscreen.cpp
@@ -0,0 +1,484 @@
+#include "shopscreen.h"
+#include "catrophy.h"
+#include "player.h"
+#include "caimagehueselector.h"
+#include "caimageselector.h"
+#include "caresources.h" // TODO : A enlever
+#include "upgradespanel.h"
+
+#include <cctype>
+#include <algorithm>
+
+/** Constructor.
+*/
+ShopScreen::ShopScreen(Player* player, CL_Surface* background, CL_Surface* button, CL_Font* font, CACarUpgrades* carRes)
+: CAScreen("T H E S H O P", "Choose a new car and press Enter to confirm"),
+ m_player (player),
+ m_background (background),
+ m_button (button),
+ m_font (font),
+ m_carRes (carRes),
+ left (0),
+ right (CA_APP->width - left),
+ top (CA_APP->headerHeight + 30),
+ bottom (CA_APP->headerHeight + 400),
+ m_guiBox (),
+ m_barHeight (m_font->get_height() + 6),
+ m_confirmMode (false),
+ m_cursor (0),
+ m_isAbleToBuy (false),
+ m_curWidth (12)
+{
+ m_font->set_alignment(origin_top_center, 0, 0);
+ m_carImage = new CAImageSelector();
+ m_carImage->move(left + 16, top + 32);
+
+ for (int carNum=0; carNum<CA_NUMCARTYPES; carNum++)
+ {
+ std::ostringstream ossPrice;
+ ossPrice << "$" << CA_APP->carType[carNum].price;
+
+ m_carImage->addImage(CA_APP->carType[carNum].name,
+ ossPrice.str(),
+ CA_APP->carType[carNum].surface3d,
+ true);
+ }
+ if (m_player->getCarNumber() != CA_NUMCARTYPES-1)
+ {
+ m_carImage->setCurrentImage(m_player->getCarNumber()+1);
+ }
+ else
+ {
+ m_carImage->setCurrentImage(m_player->getCarNumber());
+ }
+
+ m_imageView[0] = new CAImageView();
+ m_imageView[1] = new CAImageView();
+ m_imageView[2] = new CAImageView();
+
+ m_player->getCar()->getMotor()->updateImageView(m_imageView[0], m_carImage->getWidth());
+ m_player->getCar()->getTires()->updateImageView(m_imageView[1], m_carImage->getWidth());
+ m_player->getCar()->getArmor()->updateImageView(m_imageView[2], m_carImage->getWidth());
+
+ m_continue = new CAImageView ( "Continue", "", CA_RES->misc_flag/*m_carRes->getMotor(4)*/, true );
+ m_continue->resize(m_carImage->getWidth(), -1);
+
+ for (int i = 0; i < 3; i++)
+ {
+ m_imageView[i]->move(m_carImage->getLeft() + (m_carImage->getWidth()+32)*i, m_carImage->getBottom() + 32);
+ }
+ m_continue->move(m_carImage->getLeft() + (m_carImage->getWidth()+32)*3, m_carImage->getBottom() + 32);
+
+ // Set the position of the text box on the right side of the car image
+ m_guiBox.setPosition( m_carImage->getRight()+32, m_carImage->getTop(), m_continue->getRight(), m_carImage->getBottom());
+
+ updateText();
+
+ m_focus = m_carImage;
+}
+
+/** Destructor.
+*/
+ShopScreen::~ShopScreen()
+{
+ delete m_carImage;
+ for (int i = 0; i < 3; i++)
+ {
+ delete m_imageView[i];
+ }
+ delete m_continue;
+}
+
+
+
+/** Runs the screen.
+*/
+int
+ShopScreen::run()
+{
+ slot = CL_Keyboard::sig_key_up().connect(this, &ShopScreen::on_key_released);
+
+ CA_APP->fadeScreen( true, this );
+ done = false;
+ cancel = false;
+
+ // Screen loop:
+ //
+ while( !done )
+ {
+ CA_APP->measureFrameTime( true );
+
+ buildScreen();
+
+ // Play background sound:
+ CASoundEffect::playBackgroundMelody();
+
+ CL_Display::flip(); // Copy framebufer to screen
+ CL_System::keep_alive(); // VERY VITAL for the system!
+
+ CA_APP->measureFrameTime( false );
+ }
+
+ CA_APP->fadeScreen( false, this );
+ CA_APP->waitForSilence();
+
+ //CL_Input::chain_button_release.remove( this );
+
+ CL_Keyboard::sig_key_up().disconnect(slot);
+ return (cancel);
+}
+
+/** Builds the screen.
+*/
+void
+ShopScreen::buildScreen()
+{
+ // Background:
+ //
+ m_background->draw ( CL_Rect(0, 0, CA_APP->width, CA_APP->height) );
+ displayTitle();
+ displayHelp();
+
+ // Background
+ //
+ CL_Display::fill_rect( CL_Rect(left, top, right, bottom), CL_Color(0, 0, 0, 64) );
+
+ // GuiBox:
+ //
+ m_guiBox.display();
+
+ // Text:
+ //
+ const int topTxt = m_guiBox.getTop() + 8;
+ m_font->draw ( m_guiBox.getHCenter(), topTxt, m_text );
+
+ // Cursor:
+ //
+ static float cursorAnim = 0.0; // Counter for cursor animation:
+
+ // We need to display four blinking rectangles around the widget (we don't want blinking inside the blended part of the widget)
+ const CL_Color blinkColor = CL_Color (255, 216, 84, (int)((cursorAnim/2)*255) );
+
+ CL_Display::fill_rect( CL_Rect(m_focus->getLeft(), m_focus->getTop()-m_curWidth,
+ m_focus->getRight()+m_curWidth, m_focus->getTop()),
+ blinkColor);
+
+ CL_Display::fill_rect( CL_Rect(m_focus->getLeft()-m_curWidth, m_focus->getTop()-m_curWidth,
+ m_focus->getLeft(), m_focus->getBottom()),
+ blinkColor);
+
+ CL_Display::fill_rect( CL_Rect(m_focus->getLeft()-m_curWidth, m_focus->getBottom(),
+ m_focus->getRight(), m_focus->getBottom()+m_curWidth),
+ blinkColor);
+
+ CL_Display::fill_rect( CL_Rect(m_focus->getRight(), m_focus->getTop(),
+ m_focus->getRight()+m_curWidth, m_focus->getBottom()+m_curWidth),
+ blinkColor);
+
+ CA_RES->advanceAnimation( &cursorAnim, 1, 2.0, CAResources::Revolving );
+
+
+
+ // Buying Cursor
+ //
+ if (m_isAbleToBuy)
+ {
+ const int fh = m_font->get_height(); //Font Height
+ const int curLeft = m_guiBox.getLeft() + CA_RES->gui_border2->get_width() + 5;
+ const int curTop = m_cursor*fh*2+topTxt+fh*2;
+ CA_RES->menu_cursorani->draw (curLeft, curTop);
+ CA_RES->menu_cursorani->update();
+ }
+
+ // Cars to buy
+ //
+ m_carImage->display();
+
+ //
+ // Upgrades
+ for (int i = 0; i<3 ; i++)
+ {
+ m_imageView[i]->display();
+ }
+
+ //
+ // Continue
+ m_continue->display();
+
+ //
+ // UpgradesPanel
+ UpgradesPanel uPanel(m_player, m_font, CA_RES->font_lcd_13_green, m_guiBox.getRight()+32, top+32);
+ uPanel.display();
+
+}
+
+/** Called on key release.
+*/
+void
+ShopScreen::on_key_released (const CL_InputEvent &key)
+{
+ switch( key.id )
+ {
+ // Cancel (ESC):
+ //
+ case CL_KEY_ESCAPE:
+ if (m_confirmMode == false)
+ {
+ done = true;
+ cancel = true;
+ }
+ else
+ {
+ m_confirmMode = false;
+ m_isAbleToBuy = false;
+ }
+ // No cancel in this mode
+ break;
+
+ // Activate:
+ //
+ case CL_KEY_ENTER:
+ case CL_KEY_SPACE:
+ {
+ // TODO
+ if (m_focus == m_carImage)
+ {
+ if (m_confirmMode == false)
+ m_confirmMode = true;
+ else
+ {
+ m_confirmMode = false;
+ if ((m_cursor == 0) && m_isAbleToBuy)
+ {
+ m_player->buyNewCar (m_carImage->getSelectedImage());
+ m_player->getCar()->getMotor()->updateImageView(m_imageView[0], m_carImage->getWidth());
+ m_player->getCar()->getTires()->updateImageView(m_imageView[1], m_carImage->getWidth());
+ m_player->getCar()->getArmor()->updateImageView(m_imageView[2], m_carImage->getWidth());
+ }
+ }
+ m_isAbleToBuy = false;
+ }
+ else if (m_focus == m_imageView[0])
+ {
+ if (m_player->getCar()->getMotor()->buyOption(m_player))
+ {
+ m_player->getCar()->getMotor()->updateImageView(m_imageView[0], m_carImage->getWidth());
+ if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
+ }
+ else
+ {
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ }
+ }
+ else if (m_focus == m_imageView[1])
+ {
+ if (m_player->getCar()->getTires()->buyOption(m_player))
+ {
+ m_player->getCar()->getTires()->updateImageView(m_imageView[1], m_carImage->getWidth());
+ if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
+ }
+ else
+ {
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ }
+ }
+ else if (m_focus == m_imageView[2])
+ {
+ if (m_player->getCar()->getArmor()->buyOption(m_player))
+ {
+ m_player->getCar()->getArmor()->updateImageView(m_imageView[2], m_carImage->getWidth());
+ if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
+ }
+ else
+ {
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ }
+ }
+ else if (m_focus == m_continue)
+ {
+ done = true;
+ }
+ else
+ {
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ }
+ }
+ break;
+
+ case CL_KEY_UP:
+ case CL_KEY_DOWN:
+ {
+ if (m_focus == m_carImage)
+ {
+ if (m_confirmMode == true && m_isAbleToBuy)
+ {
+ m_cursor = (m_cursor+1)%2;
+ if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
+ }
+ else if (key.id == CL_KEY_DOWN)
+ {
+ m_focus = m_imageView[0];
+ if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
+ }
+
+ }
+ else if (m_focus == m_imageView[0] && key.id == CL_KEY_UP)
+ {
+ m_focus = m_carImage;
+ if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
+ }
+ }
+ break;
+
+ case CL_KEY_LEFT:
+ case CL_KEY_RIGHT:
+ {
+ if (m_focus == m_carImage)
+ {
+ if (m_confirmMode == false || m_isAbleToBuy == false)
+ {
+ m_carImage->handleKey( key );
+ m_confirmMode = false;
+ }
+ }
+ else
+ {
+ if (m_focus == m_continue && key.id == CL_KEY_LEFT)
+ {
+ m_focus = m_imageView[2];
+ if( CA_APP->sound ) CA_RES->effectMenu->play( 2 );
+ }
+ else if (m_focus != m_continue)
+ {
+ if( CA_APP->sound ) CA_RES->effectMenu->play( 2 ); // we will make a change
+
+ int focusNum = 0;
+ for (int i=0; i<3; i++)
+ if (m_imageView[i] == m_focus)
+ focusNum = i;
+
+ if (key.id == CL_KEY_LEFT)
+ {
+ focusNum--;
+ }
+ else if (key.id == CL_KEY_RIGHT)
+ {
+ focusNum++;
+ }
+
+ if (focusNum < 0)
+ {
+ m_focus = m_carImage;
+ }
+ else if (focusNum > 2)
+ {
+ m_focus = m_continue;
+ }
+ else
+ {
+ m_focus = m_imageView[focusNum];
+ }
+ }
+ }
+ }
+ break;
+ }
+
+ // change have been made so we update Text
+ updateText();
+}
+
+
+/** Prepare the text displayed in the textBox
+ */
+void ShopScreen::updateText()
+{
+
+ const int carNum = m_carImage->getSelectedImage();
+ std::ostringstream oss;
+
+ if (m_confirmMode == false)
+ {
+
+ if (m_focus == m_imageView[0])
+ {
+ if ( m_player->getCar()->getMotor()->isMax() == false)
+ {
+ oss << "Buy engine class " << m_player->getCar()->getMotor()->getCurrent() + 1 << "\n";
+ oss << "You should buy this engine" << "\n";
+ }
+ else
+ {
+ oss << "Perfect is Perfect !!" << "\n";
+ oss << "You already have the best engine" << "\n";
+ }
+ }
+ else if (m_focus == m_imageView[1])
+ {
+ if ( m_player->getCar()->getTires()->isMax() == false)
+ {
+ oss << "Buy tires model " << m_player->getCar()->getTires()->getCurrent() + 1 << "\n";
+ oss << "You should buy those tires" << "\n";
+ }
+ else
+ {
+ oss << "Perfect is Perfect !!" << "\n";
+ oss << "You already have the best available tires" << "\n";
+ }
+ }
+ else if (m_focus == m_imageView[2])
+ {
+ if (m_player->getCar()->getArmor()->isMax() == false )
+ {
+ oss << "Buy armor model " << m_player->getCar()->getArmor()->getCurrent() + 1 << "\n";
+ oss << "You should buy this armor" << "\n";
+ }
+ else
+ {
+ oss << "Perfect is Perfect !!" << "\n";
+ oss << "You already have the best available armor" << "\n";
+ }
+
+ }
+ else
+ {
+ oss << "Buy a "<< CA_APP->carType[carNum].name << " car\n";
+ /*oss << "TODO: Add a nice description for " << CA_APP->carType[carNum].name << " car\n";
+ oss << "Max speed : " << CA_APP->carType[carNum].getMotor()->getMaxSpeed() << " px/s\n";
+ oss << "Max turbo : " << CA_APP->carType[carNum].maxTurbo << " px\n";
+ oss << "Acceleration : " << CA_APP->carType[carNum].getMotor()->getAcceleration() << " px/(s*s)\n";*/
+ }
+ }
+ else
+ {
+ m_isAbleToBuy = false;
+ if (carNum != m_player->getCarNumber())
+ {
+ if (m_player->getMoney() >= CA_APP->carType[carNum].price)
+ {
+ oss << "Would you like to buy a " << CA_APP->carType[carNum].name << " for " << CA_APP->carType[carNum].price << "$ ?\n";
+ oss << "\n Yes\n";
+ oss << "\n No\n";
+ m_isAbleToBuy = true;
+ }
+ else
+ {
+ m_isAbleToBuy = false;
+ oss << "You don't have enough money.\nYou are " << CA_APP->carType[carNum].price - m_player->getMoney() << "$ short\n";
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ m_confirmMode = false;
+ }
+ }
+ else
+ {
+ m_isAbleToBuy = false;
+ oss << "You already have a " << CA_APP->carType[carNum].name;
+ if( CA_APP->sound ) CA_RES->effectHorn->play( 2 );
+ m_confirmMode = false;
+ }
+ }
+ m_text = oss.str();
+}
+
+
+// EOF
diff --git a/src/shopscreen.h b/src/shopscreen.h
new file mode 100644
index 0000000..25843f0
--- /dev/null
+++ b/src/shopscreen.h
@@ -0,0 +1,82 @@
+#ifndef SHOPSCREEN_H
+#define SHOPSCREEN_H
+
+#include <ClanLib/display.h>
+
+#include "cascreen.h"
+#include "utils/trophymath.h"
+#include "guibox.h"
+
+class Player;
+class CAImageHueSelector;
+class CAImageSelector;
+class CAImageView;
+class CACarUpgrades;
+
+/** The shop screen shown after every race where players can buy upgrade and new cars
+ @author Matthieu Lecesne
+*/
+
+class ShopScreen : public CAScreen
+{
+public:
+ ShopScreen(Player* player, CL_Surface* background, CL_Surface* button, CL_Font* font, CACarUpgrades* carRes);
+ virtual ~ShopScreen();
+
+ virtual int run();
+ virtual void buildScreen();
+
+ virtual void on_key_released (const CL_InputEvent &key);
+
+private:
+ void updateText();
+
+
+ //! the human player
+ Player* m_player;
+ //! The Background Surface
+ CL_Surface* m_background;
+ //! The button use
+ CL_Surface* m_button;
+ //! The font use for display car information
+ CL_Font* m_font;
+ //! Upgrades ressources manager
+ CACarUpgrades* m_carRes;
+
+ //! Left border position.
+ int left;
+ //! Right border position.
+ int right;
+ //! Top border position.
+ int top;
+ //! Bottom border position.
+ int bottom;
+
+ //! Car image selector.
+ CAImageSelector* m_carImage;
+
+ //! the 3 bottom boxes (upgrades)
+ CAImageView* m_imageView[3];
+ // ! the continue box
+ CAImageView* m_continue;
+
+ //! the widget which have focus
+ CAWidget* m_focus;
+
+ //! White Box
+ GUIBox m_guiBox;
+
+ int m_barHeight;
+
+ std::string m_text;
+
+ bool m_confirmMode;
+ int m_cursor;
+ bool m_isAbleToBuy;
+ const int m_curWidth;
+
+public:
+ CL_Slot slot;
+};
+
+#endif
diff --git a/src/track.cpp b/src/track.cpp
new file mode 100644
index 0000000..5cb46a6
--- /dev/null
+++ b/src/track.cpp
@@ -0,0 +1,283 @@
+#include "track.h"
+#include "utils/trophymath.h"
+#include "caresources.h"
+#include <ClanLib/core.h>
+#include <ClanLib/display.h>
+#include <fstream>
+
+Track::Track(const std::string& trackName, const bool debug):
+ m_functionMap(0),
+ m_visualMap(0),
+ m_bridge(0),
+ m_blocked(false),
+ m_rp_number(0)
+{
+ // Base path of track files:
+ std::string trackPath = std::string("tracks/") + trackName + "/";
+
+ // Load visual map:
+ //
+ std::string vmapPath = trackPath + "vmap.tga";
+ try
+ {
+ m_visualMap.reset(new CL_Surface(CL_ProviderFactory::load(vmapPath)));
+ }
+ catch(CL_Error err)
+ {
+ trackPath = std::string("../resources/tracks/") + trackName + "/";
+ vmapPath = trackPath + "vmap.tga";
+ m_visualMap.reset(new CL_Surface(CL_ProviderFactory::load(vmapPath)));
+ }
+
+ // loading.setProgress( 15 ); TODO
+
+ // Load functional map:
+ //
+ std::string fmapPath = trackPath + "fmap.tga";
+ // We need to load a surface and then create the pixelbuffer if we don't want to loose the information
+ // about the color. Don't know if it is a bug of ClanLib or the normal behavior.
+ m_functionMap.reset(new CL_PixelBuffer( ((CL_Surface)CL_ProviderFactory::load(fmapPath)).get_pixeldata() ));
+ // TODO : is it OK if we never unlock it ? functionMap is not meant to be drawn
+ m_functionMap->lock();
+
+ // loading.setProgress( 30 ); TODO
+
+
+ // Read config file for this track:
+ //
+ std::string configFilePath = trackPath + "config.tck";
+
+ if(debug) printf( "%s\n", configFilePath.c_str() );
+
+ std::ifstream tckFile (configFilePath.c_str());
+ if ( tckFile )
+ {
+ std::string line; // The line converted to a string
+ std::string name; // Name of the value (Author)
+ std::string value; // Value (Andrew Mustun)
+ unsigned int xv=0, yv=0, zv=0; // Coordinates for following objects
+ unsigned int iv=0; // Index for following object (route point)
+ while (std::getline(tckFile, line))
+ {
+ if (line.size()!=0)
+ if (line[0]!='#')
+ {
+ int i = std::string( line ).find_first_of( " =" );
+ name = line.substr( 0, i );
+ i = std::string( line ).find ('"', i) + 1;
+ int j = std::string( line ).find ('"', i);
+ value = line.substr( i, j-i );
+
+ std::istringstream iss(value);
+ // General track info:
+ //
+ if( name=="Author" ) iss >> m_author;
+ else if( name=="Version") iss >> m_version;
+ else if( name=="Name" ) iss >> m_name;
+
+ // Coordinates of next object / route point:
+ //
+ else if( name=="x" ) iss >> xv;
+ else if( name=="y" ) iss >> yv;
+ else if( name=="z" ) iss >> zv;
+ else if( name=="i" ) iss >> iv;
+
+ // Start angle:
+ //
+ else if( name=="startAngle" ) iss >> m_startAngle;
+
+ // Route points:
+ //
+ else if( name=="RP" )
+ {
+ int pi;
+ iss >> pi; // TODO : sort RP
+ while (m_rp.size() <= iv)
+ {
+ m_rp.push_back(std::vector<RP>());
+ }
+
+ RP rp(xv, yv);
+ m_rp[iv].push_back(rp);
+ }
+
+ // Objects:
+ //
+ else if( name=="Object" && value=="bridge") {
+ std::string bridgePath = trackPath + value + ".tga";
+ m_bridge.reset(new CL_Surface(CL_TargaProvider(bridgePath)));
+ m_bridgePos[0] = xv;
+ m_bridgePos[1] = yv;
+ }
+ }
+ }
+ tckFile.close();
+ }
+}
+
+void Track::handleTrackCreation(const int offsetX, const int offsetY)
+{
+ if( CL_Mouse::get_keycode(CL_MOUSE_LEFT) )
+ {
+ if( !m_blocked )
+ {
+ m_blocked = true;
+ FILE* fp = fopen( "trackdata.txt", "at" );
+ if( fp )
+ {
+ fprintf( fp, "x = \"%d\"\n", CL_Mouse::get_x()-offsetX );
+ fprintf( fp, "y = \"%d\"\n", CL_Mouse::get_y()-offsetY );
+ fprintf( fp, "RP = \"%d\"\n\n", m_rp_number++ );
+ fclose( fp );
+ CL_Color fmap_pix = m_functionMap->get_pixel(CL_Mouse::get_x()-offsetX, CL_Mouse::get_y()-offsetY);
+ CL_PixelBuffer pixbuf = m_visualMap->get_pixeldata();
+ pixbuf.lock();
+ CL_Color vmap_pix = pixbuf.get_pixel(CL_Mouse::get_x()-offsetX, CL_Mouse::get_y()-offsetY);
+ pixbuf.unlock();
+ std::cout << "vmap (r, g, b, a) = (" << vmap_pix.get_red() << ", " << vmap_pix.get_green() << ", " << vmap_pix.get_blue() << ", " << vmap_pix.get_alpha() << ")" << std::endl;
+ std::cout << "fmap (r, g, b, a) = (" << fmap_pix.get_red() << ", " << fmap_pix.get_green() << ", " << fmap_pix.get_blue() << ", " << fmap_pix.get_alpha() << ")" << std::endl;
+ }
+ }
+ }
+ else
+ {
+ m_blocked = false;
+ }
+}
+
+
+/** Checks if the given coordinate is on the map and returns true if so.
+*/
+bool Track::checkCoordinate( const int x, const int y ) const
+{
+ return ( x>=0 && y>=0 && x<(int)m_visualMap->get_width() && y<(int)m_visualMap->get_height() );
+}
+
+/** Displays the race map.
+*/
+void Track::displayMap(const int offsetX, const int offsetY) const
+{
+ m_visualMap->draw (offsetX,offsetY);
+}
+
+
+void Track::scroll(int& offsetX, int& offsetY, const int posX, const int posY, const int width, const int height, const int panelWidth)
+{
+ const int maxOffsetX = panelWidth;
+ const int minOffsetX = -(m_visualMap->get_width()-(width-panelWidth)) + panelWidth;
+ const int maxOffsetY = 0;
+ const int minOffsetY = -(m_visualMap->get_height()-height);
+
+ offsetX = - ((int)(posX) - (width-panelWidth)/2) + panelWidth;
+ offsetY = - ((int)(posY) - height/2);
+ if( offsetX>maxOffsetX ) offsetX = maxOffsetX;
+ if( offsetX<minOffsetX ) offsetX = minOffsetX;
+ if( offsetY>maxOffsetY ) offsetY = maxOffsetY;
+ if( offsetY<minOffsetY ) offsetY = minOffsetY;
+}
+
+/** Gets the speed limit for a coordinate of the map
+*/
+int Track::getSpeedLimit( const int x, const int y ) const
+{
+ if( checkCoordinate( x,y ) )
+ {
+ CL_Color tmp = m_functionMap->get_pixel( x,y );
+ unsigned int g = tmp.get_green();
+ return ((g)&0xF0)>>4;
+ }
+
+ return 0;
+}
+
+/** Gets the lap part for a coordinate of the map
+*/
+int Track::getLapPart( const int x, const int y ) const
+{
+ if( checkCoordinate( x,y ) )
+ {
+ CL_Color tmp = m_functionMap->get_pixel( x,y );
+ unsigned int b = tmp.get_blue();
+ return ((b)&0x1F);
+ }
+
+ return 0;
+}
+
+/** Gets the level for a coordinate of the map.
+ \return 0: Level on the point is down
+ 1: Level on the point is up
+ 2: Level on the point is not defined
+*/
+int Track::getLevel( const int x, const int y ) const
+{
+ if( checkCoordinate( x,y ) )
+ {
+ CL_Color tmp = m_functionMap->get_pixel( x,y );
+ unsigned int g = tmp.get_green();
+ if( (g&0x02)!=0 ) return 1;
+ if( (g&0x01)!=0 ) return 0;
+ }
+
+ return 2;
+}
+
+/** Displays track points.
+*/
+void Track::displayTrackPoints(const int& offsetX, const int& offsetY) const
+{
+ char str[16];
+ for( unsigned int t=0; t<m_rp.size(); ++t )
+ {
+ for( unsigned int r=0; r<m_rp[t].size(); ++r )
+ {
+ sprintf( str, "%d/%d", r, t );
+ CA_RES->misc_cross->draw (m_rp[t][r].getX()+offsetX-8, m_rp[t][r].getY()+offsetY-8);
+ CA_RES->font_normal_11_white->set_alignment(origin_top_left, 0, 0);
+ CA_RES->font_normal_11_white->draw( m_rp[t][r].getX()+offsetX, m_rp[t][r].getY()+offsetY+5, str );
+ }
+ }
+}
+
+/** Displays the bridge if there is any.
+*/
+void Track::displayBridge(const int& offsetX, const int& offsetY) const
+{
+ if( m_bridge.get() != NULL )
+ {
+ m_bridge->draw (m_bridgePos[0]+offsetX, m_bridgePos[1]+offsetY);
+ }
+}
+
+
+void Track::getNextRoutePoint(unsigned int& routeNumber, unsigned int& routePoint, float& nx, float& ny) const
+{
+ // Choose new route by shuffle:
+ //
+ if( routePoint >= m_rp[routeNumber].size() )
+ {
+ routePoint=0;
+ routeNumber = TrophyMath::getRandomNumber( 0, m_rp.size()-1 );
+ }
+
+ // Next coordinate to locate
+ //
+ nx = m_rp[routeNumber][routePoint].getX();
+ ny = m_rp[routeNumber][routePoint].getY();
+}
+
+
+CL_Color Track::getFunctionalPixel(int x, int y) const
+{
+ return m_functionMap->get_pixel(x, y);
+}
+
+int Track::getWidth() const
+{
+ return m_visualMap->get_width();
+}
+
+int Track::getHeight() const
+{
+ return m_visualMap->get_height();
+}
diff --git a/src/track.h b/src/track.h
new file mode 100644
index 0000000..96af3bf
--- /dev/null
+++ b/src/track.h
@@ -0,0 +1,94 @@
+#ifndef TRACK_H
+#define TRACK_H
+
+
+#include "utils/trophymath.h"
+#include <string>
+#include <ClanLib/core.h>
+#include <ClanLib/application.h>
+#include <memory>
+#ifdef USE_SDL
+ #include <ClanLib/sdl.h>
+#else
+ #include <ClanLib/gl.h>
+#endif
+
+/** Structure for the current track.
+ @author Andrew Mustun
+ @author Matthieu Lecesne
+*/
+class Track
+{
+
+public:
+ class RP
+{
+ public:
+ RP(const int nx, const int ny) : x(nx), y(ny) {}
+ int getX() const { return x;}
+ int getY() const { return y;}
+ private:
+ int x;
+ int y;
+};
+ Track(const std::string& trackName, const bool debug = false);
+
+ bool checkCoordinate( const int x, const int y ) const;
+
+ void handleTrackCreation(const int offsetX, const int offsetY);
+
+ void scroll(int& offsetX, int& offsetY, const int posX, const int posY, const int width, const int height, const int panelWidth);
+
+ void displayMap(const int offsetX, const int offsetY) const;
+
+ int getSpeedLimit( const int x, const int y ) const;
+
+ int getLapPart( const int x, const int y ) const;
+
+ int getLevel( const int x, const int y ) const;
+
+ void displayTrackPoints(const int& offsetX, const int& offsetY) const;
+
+ void displayBridge(const int& offsetX, const int& offsetY) const;
+
+ void getNextRoutePoint(unsigned int& routeNumber, unsigned int& routePoint, float& nx, float& ny) const;
+
+ int getStartAngle() const {return m_startAngle;}
+
+ CL_Color getFunctionalPixel(int x, int y) const;
+
+ int getWidth() const;
+
+ int getHeight() const;
+ private:
+ //! Track number
+ int m_number;
+ //! Track name
+ std::string m_name;
+ //! Version information (e.g. "0.0.1")
+ std::string m_version;
+ //! Author of this track
+ std::string m_author;
+ //! Initial angle of players (0=right, 90=bottom (!))
+ int m_startAngle;
+ //! Route points (Usually 1 route per player with x/y)
+ std::vector< std::vector<RP> > m_rp;
+ //! Pointer to function map
+ // TODO : check that PixelBuffer is really what we want. It could (and I think it does) introduce bugs
+ // in AI because PixelBuffer height and width are power of 2
+ std::auto_ptr<CL_PixelBuffer> m_functionMap;
+ //! Pointer to visual map
+ std::auto_ptr<CL_Surface> m_visualMap;
+ //! Pointer to bridge surface or NULL if there's no bridge
+ std::auto_ptr<CL_Surface> m_bridge;
+ //! Bridge position
+ int m_bridgePos[2];
+
+ int m_blocked;
+ //! Routing Point (use only for track creation)
+ int m_rp_number;
+};
+
+#endif
+
+// EOF
diff --git a/src/upgradespanel.cpp b/src/upgradespanel.cpp
new file mode 100644
index 0000000..bbfebc1
--- /dev/null
+++ b/src/upgradespanel.cpp
@@ -0,0 +1,63 @@
+
+#include "upgradespanel.h"
+#include "caimageview.h"
+#include <sstream>
+
+UpgradesPanel::UpgradesPanel( Player* player, CL_Font* carFont, CL_Font* upgradeFont, const int nvLeft, const int nvTop ):
+ m_player (player),
+ m_carfont (carFont),
+ m_upgradesFont (upgradeFont),
+ m_barHeight (m_carfont->get_height() + 6),
+ m_curTop(nvTop)
+{
+ m_carfont->set_alignment(origin_top_center, 0, 0);
+ m_upgradesFont->set_alignment(origin_top_center, 0, 0);
+ left = nvLeft;
+ top = nvTop;
+ width = m_player->getCar()->surface3d->get_width();
+ right = left + width;
+ m_center = (left+right)/2;
+}
+
+
+void UpgradesPanel::display(const bool active)
+{
+ std::ostringstream ossMoney;
+ ossMoney << "$" << m_player->getMoney();
+ CAImageView carView(m_player->getName(), ossMoney.str(), m_player->getCar()->surface3d);
+ carView.move(left, top);
+ carView.display();
+
+ // PlayerUpgrade
+ //
+ m_curTop += carView.getHeight() + 0.5*m_barHeight;
+ displayBarOption(m_player->getCar()->getMotor());
+
+ m_curTop += 1.5*m_barHeight;
+ displayBarOption(m_player->getCar()->getTires());
+
+ m_curTop += 1.5*m_barHeight;
+ displayBarOption(m_player->getCar()->getArmor());
+}
+
+
+void UpgradesPanel::displayBarOption(CarOption* carOption)
+{
+ std::string final = carOption->getName();
+ std::transform(final.begin(), final.end(), final.begin(), (int(*)(int)) std::toupper);
+ m_upgradesFont->draw(m_center, m_curTop, final);
+ const int barTop = m_curTop + m_upgradesFont->get_height();
+ CL_Color tempColor;
+ const int barMax = carOption->getMax();
+ for (int i=0; i < barMax; i++)
+ {
+ if (i < carOption->getCurrent())
+ tempColor = CL_Color (255, 0, 0, 255); // red
+ else
+ tempColor = CL_Color (125, 125, 125, 255); // gray
+ CL_Display::fill_rect( CL_Rect(left+i*(right-left)/barMax + 1, barTop, right - (barMax-1-i)*(right-left)/barMax -1, barTop + 0.5*m_barHeight),
+ tempColor);
+ }
+}
+
+// EOF
diff --git a/src/upgradespanel.h b/src/upgradespanel.h
new file mode 100644
index 0000000..80be985
--- /dev/null
+++ b/src/upgradespanel.h
@@ -0,0 +1,44 @@
+#ifndef UPGRADES_PANEL_H
+#define UPGRADES_PANEL_H
+
+
+#include "player.h"
+#include "cawidget.h"
+#include <ClanLib/display.h>
+#include <sstream>
+
+
+/** This panel is shown to see the car and the upgrades of the player
+ @author Matthieu Lecesne
+*/
+
+class UpgradesPanel : public CAWidget
+{
+ public:
+ UpgradesPanel( Player* player, CL_Font* carFont, CL_Font* upgradeFont, const int nvLeft, const int nvTop );
+
+ virtual ~UpgradesPanel() {}
+
+ void display(const bool active = true);
+
+ void displayBarOption(CarOption* carOption);
+
+ private:
+ //! the human player
+ Player* m_player;
+ //! the font uses in the panel
+ CL_Font* m_carfont;
+ //! the font uses for the upgrades
+ CL_Font* m_upgradesFont;
+ //! the center of the bar
+ int m_center;
+ //! height of a bar
+ int m_barHeight;
+ // current top Position
+ int m_curTop;
+};
+
+
+#endif
+
+// EOF
diff --git a/src/utils/hsvcolor.h b/src/utils/hsvcolor.h
new file mode 100644
index 0000000..20161ff
--- /dev/null
+++ b/src/utils/hsvcolor.h
@@ -0,0 +1,47 @@
+#ifndef HSVCOLOR_H
+#define HSVCOLOR_H
+
+#include <ClanLib/core.h>
+
+/** Structure for a color.
+ Colors in trophy are usually used for
+ the modification of red based surfaces.
+ @author Andrew Mustun
+ */
+class HSVColor
+{
+ public:
+ /** Constructor for a black color.
+ */
+ HSVColor()
+ {
+ h = s = v = 0;
+ }
+
+ /** Constructor for any desired color.
+ */
+ HSVColor( int h, int s, int v )
+ {
+ this->h = h;
+ this->s = s;
+ this->v = v;
+ }
+
+ /** Operator !=
+ */
+ inline bool operator!=( const HSVColor& c )
+ {
+ return (this->h!=c.h || this->s!=c.s || this->v!=c.v);
+ }
+
+ //! Hue of this color
+ int h;
+ //! Saturation of this color
+ int s;
+ //! Value of this color
+ int v;
+};
+
+#endif
+
+// EOF
diff --git a/src/camath.cpp b/src/utils/trophymath.cpp
similarity index 63%
rename from src/camath.cpp
rename to src/utils/trophymath.cpp
index e9cde48..e4ada3d 100644
--- a/src/camath.cpp
+++ b/src/utils/trophymath.cpp
@@ -1,47 +1,53 @@
-#include <stdio.h>
#include <time.h>
-#include "camath.h"
+#include "trophymath.h"
+#include <sstream>
+#include <iomanip>
/** Compares two float values.
\return true if the two values differ less than the tolerance value.
*/
bool
-CAMath::compFloat( float f1, float f2, float tol ) {
+TrophyMath::compFloat( const float f1, const float f2, const float tol )
+{
float delta = f2-f1;
return( delta>-tol && delta<tol );
}
-
/** Corrects an angle (to the range of 0-360)
\return The corrected angle
*/
float
-CAMath::corrAngle( float ang ) {
+TrophyMath::corrAngle( const float ang )
+{
float ret=ang;
while(ret< 0.0) ret+=360.0;
while(ret>=360.0) ret-=360.0;
return ret;
}
-
-
/** Returns the angle (in degrees) from one point to an other.
*/
float
-CAMath::getAngle( float x1, float y1, float x2, float y2 ) {
+TrophyMath::getAngle( const float x1, const float y1, const float x2, const float y2 )
+{
float xdist, ydist, angle;
xdist=x2-x1;
ydist=y2-y1;
- if(compFloat(xdist, 0.0)) {
+ if(compFloat(xdist, 0.0))
+ {
if(y2<y1) angle=270.0;
else angle=90.0;
- } else if(compFloat(ydist, 0.0)) {
+ }
+ else if(compFloat(ydist, 0.0))
+ {
if(x2<x1) angle=180.0;
else angle=0.0;
- } else {
+ }
+ else
+ {
angle = atan(ydist/xdist)*ARAD;
if(angle<0.0) angle*=-1.0;
if(x2>x1 && y2>y1) angle = 0.0 + angle; // 1. Quadrant
@@ -53,12 +59,11 @@ CAMath::getAngle( float x1, float y1, float x2, float y2 ) {
return angle;
}
-
-
/** Returns the distance from one point to an other.
*/
float
-CAMath::getDistance( float x1, float y1, float x2, float y2 ) {
+TrophyMath::getDistance( const float x1, const float y1, const float x2, const float y2 )
+{
float xd2 = (x2-x1)*(x2-x1);
float yd2 = (y2-y1)*(y2-y1);
float d = xd2+yd2;
@@ -66,14 +71,13 @@ CAMath::getDistance( float x1, float y1, float x2, float y2 ) {
return(std::sqrt(d));
}
-
-
/** Get Angle difference between _a1 and _a2
(Which angle must I add to _a1 to get _a2)
All angles in degrees.
*/
float
-CAMath::getAngleDiff( float a1, float a2 ) {
+TrophyMath::getAngleDiff( const float a1, float a2 )
+{
float ret;
if( a1>=a2 ) a2+=360.0;
@@ -83,16 +87,15 @@ CAMath::getAngleDiff( float a1, float a2 ) {
return ret;
}
-
-
/** Calculates the intersection point of two lines.
*/
bool
-CAMath::getIntersection( int ax1, int ay1, int ax2, int ay2,
- int bx1, int by1, int bx2, int by2,
- int* ix, int* iy ) {
- if( ix && iy ) {
-
+TrophyMath::getIntersection( const int ax1, const int ay1, const int ax2, const int ay2,
+ const int bx1, const int by1, const int bx2, const int by2,
+ int* ix, int* iy )
+{
+ if( ix && iy )
+ {
int amaxx = MAX(ax1, ax2);
int aminx = MIN(ax1, ax2);
int amaxy = MAX(ay1, ay2);
@@ -103,8 +106,7 @@ CAMath::getIntersection( int ax1, int ay1, int ax2, int ay2,
int bmaxy = MAX(by1, by2);
int bminy = MIN(by1, by2);
- if( amaxx<bminx || aminx>bmaxx ||
- amaxy<bminy || aminy>bmaxy ) return false;
+ if( amaxx<bminx || aminx>bmaxx || amaxy<bminy || aminy>bmaxy ) return false;
int t2_divisor,
t2_dividend;
@@ -112,15 +114,16 @@ CAMath::getIntersection( int ax1, int ay1, int ax2, int ay2,
t2_dividend = (bx2-bx1)*(ay2-ay1) - (by2-by1)*(ax2-ax1);
- if( t2_dividend!=0 ) {
+ if( t2_dividend!=0 )
+ {
t2_divisor = ax1*ay2
- - ay1*ax2
- - bx1*(ay2-ay1)
- + by1*(ax2-ax1);
+ - ay1*ax2
+ - bx1*(ay2-ay1)
+ + by1*(ax2-ax1);
t2 = (float)(t2_divisor) / t2_dividend;
- } else {
+ }
+ else
t2 = 0.0;
- }
*ix = (int)( bx1 + t2 * (bx2 - bx1) );
*iy = (int)( by1 + t2 * (by2 - by1) );
@@ -128,23 +131,22 @@ CAMath::getIntersection( int ax1, int ay1, int ax2, int ay2,
if( ((*ix<=ax1 && *ix>=ax2) || (*ix<=ax2 && *ix>=ax1)) &&
((*ix<=bx1 && *ix>=bx2) || (*ix<=bx2 && *ix>=bx1)) &&
((*iy<=ay1 && *iy>=ay2) || (*iy<=ay2 && *iy>=ay1)) &&
- ((*iy<=by1 && *iy>=by2) || (*iy<=by2 && *iy>=by1)) ) {
+ ((*iy<=by1 && *iy>=by2) || (*iy<=by2 && *iy>=by1)) )
return true;
- } else {
+ else
return false;
- }
}
-
return true;
}
-
/** Gets a random number from 'min' to 'max'
*/
int
-CAMath::getRandomNumber( int min, int max ) {
+TrophyMath::getRandomNumber( const int min, const int max )
+{
static int counter=0;
- if( counter==1000 || counter==0 ) {
+ if( counter==1000 || counter==0 )
+ {
srand( time( NULL ) );
counter = 0;
}
@@ -152,22 +154,22 @@ CAMath::getRandomNumber( int min, int max ) {
return ( (int)/*rint */( (float)(max-min + 1) / RAND_MAX * rand() ) + min );
}
-
-/** Converts a time in millisecs to a string in the format <minutes>:<seconds>.<hundredth>. (e.g. "5:02.23")
- 'string' must have at least place for 9 characters.
+/** Converts a time in millisecs to a str in the format <minutes>:<seconds>.<hundredth>. (e.g. "5:02.23")
+ 'str' must have at least place for 9 characters.
*/
void
-CAMath::timeToString( char* string, int time ) {
+TrophyMath::timeToString( std::string& timeStr, const int time )
+{
float min = (int)floor( (float)((time)/60000.0) );
float sec = (float)((time)%60000)/1000.0;
float hun = ((sec-floor(sec))*100);
- sprintf( string,
- "%02d:%02d.%02d",
- (int)min,
- (int)floor( sec ),
- (int)floor( hun ) );
-}
+ std::ostringstream ossTime;
+ ossTime << std::setw(2) << std::setfill('0') << int(min) << ":";
+ ossTime << std::setw(2) << std::setfill('0') << int(sec) << ".";
+ ossTime << std::setw(2) << std::setfill('0') << int(hun);
+ timeStr = ossTime.str();
+}
// EOF
diff --git a/src/camath.h b/src/utils/trophymath.h
similarity index 54%
rename from src/camath.h
rename to src/utils/trophymath.h
index 1255adf..2ca9293 100644
--- a/src/camath.h
+++ b/src/utils/trophymath.h
@@ -1,5 +1,5 @@
-#ifndef CAMATH_H
-#define CAMATH_H
+#ifndef TROPHYMATH_H
+#define TROPHYMATH_H
#include <math.h>
#include <stdlib.h>
@@ -10,14 +10,12 @@
#define MAX(A,B) (A>=B ? A : B)
#define MIN(A,B) (A<=B ? A : B)
-
// Version dependent settings:
#define CA_MAXTRACKS 64 // Max number of tracks
#define CA_NUMCARTYPES 4 // Max number of car types
-#define CA_WIDTH 800 // Width of screen
-#define CA_HEIGHT 600 // Height "
+#define CA_RESOLUTION "800x600" //resolution
#define CA_HELPHEIGHT 50 // Height of help-frame at the bottom
@@ -27,43 +25,41 @@
#define CA_MAXFOGBOMBS 10 // Max number of fog bombs
#define CA_MAXDUSTCLOWDS 50 // Max number of dust clowds
-#define CA_NUMGOODYTYPES 5 // Number of different goodie items
#define CA_NUMGOODIES 6 // Number of goodies of each type (max)
#define CA_GOODYTIME 250 // Pace a goody all ... millisecs
-#define CA_MAXPLAYERS 6 // Max number of players in total
+#define CA_MAXPLAYERS 30 // Max number of players in total
+#define CA_RACEMAXPLAYERS 6 // Max number of players in a race
#define CA_TURBOFACTOR 1.5 // Speed factor for turbo
#define CA_SHOOTINGRANGE 200 // Shooting range in pixel
#define CA_MAXHITPOINTS 5 // Max number of hit points for one screen and one player
-#define CA_MAXROUTEPOINTS 32 // Max number of route points for computer players
-
#define CA_NUMLAPS 5 // Number of laps to do for each race
#define CA_NUMSLOTS 10 // Number of slots for saving games.
#define CA_FPR 72 // Number of frames used for one rotation of the sprite
-#define CA_PRIZE 3000 // Money for first player
-
-
+#define CA_PRIZE 3000 // Money for easy race
+#define CA_PRIZE_MEDIUM 7500 // Money for medium race
+#define CA_PRIZE_HARD 15000 // Money for hard race
/** Mathematical methods for generic use.
@author Andrew Mustun
*/
-class CAMath {
-public:
- static bool compFloat( float f1, float f2, float tol=0.001 );
- static float corrAngle( float ang );
- static float getAngle( float x1, float y1, float x2, float y2 );
- static float getDistance( float x1, float y1, float x2, float y2 );
- static float getAngleDiff( float a1, float a2 );
- static bool getIntersection( int ax1, int ay1, int ax2, int ay2,
- int bx1, int by1, int bx2, int by2,
- int* ix, int* iy );
- static int getRandomNumber( int min, int max );
- static void timeToString( char* string, int time );
+namespace TrophyMath
+{
+ bool compFloat( const float f1, const float f2, const float tol=0.001 );
+ float corrAngle( const float ang );
+ float getAngle( const float x1, const float y1, const float x2, const float y2 );
+ float getDistance( const float x1, const float y1, const float x2, const float y2 );
+ float getAngleDiff( const float a1, float a2 );
+ bool getIntersection( const int ax1, const int ay1, const int ax2, const int ay2,
+ const int bx1, const int by1, const int bx2, const int by2,
+ int* ix, int* iy );
+ int getRandomNumber( const int min, const int max );
+ void timeToString( std::string& timeStr, const int time );
};
#endif
diff --git a/src/windialog.cpp b/src/windialog.cpp
new file mode 100644
index 0000000..03542f1
--- /dev/null
+++ b/src/windialog.cpp
@@ -0,0 +1,28 @@
+#include "windialog.h"
+#include "catrophy.h"
+#include <sstream>
+
+
+/** Constructor.
+*/
+WinDialog::WinDialog(const std::string& playerName, const int nbTurns)
+ : CACredits() {
+ wintext.push_back("C O N G R A T U L A T I O N S");
+ wintext.push_back("");
+ wintext.push_back("You are the new 'trophy' champion");
+ wintext.push_back("");
+ std::ostringstream oss;
+ oss << playerName << " champion in " << nbTurns << " turns";
+ wintext.push_back(oss.str());
+ wintext.push_back("");
+ wintext.push_back("");
+ wintext.push_back("================== TROPHY ==================");
+ wintext.push_back("Thanks for playing !!!");
+ wintext.push_back("");
+ wintext.push_back("");
+ wintext.push_back("");
+ wintext.push_back("");
+ wintext.push_back("");
+ wintext.push_back("");
+ setText(wintext);
+}
\ No newline at end of file
diff --git a/src/windialog.h b/src/windialog.h
new file mode 100644
index 0000000..fc7732f
--- /dev/null
+++ b/src/windialog.h
@@ -0,0 +1,19 @@
+#ifndef WINDIALOG_H
+#define WINDIALOG_H
+
+
+#include "cacredits.h"
+
+/** Text that is display when the player wins
+ @author Matthieu Lecesne
+*/
+class WinDialog : public CACredits {
+public:
+ WinDialog(const std::string& playerName, const int nbTurns);
+
+private:
+ std::vector<std::string> wintext;
+
+};
+
+#endif
--
Trophy racing game - Packaging information
More information about the Pkg-games-commits
mailing list