screenshots
This commit is contained in:
commit
ce91b12e7f
68
CMakeLists.txt
Executable file
68
CMakeLists.txt
Executable file
@ -0,0 +1,68 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(calamitycobra C)
|
||||
|
||||
set_target_properties(PROPERTIES LINKER_LANGUAGE C)
|
||||
|
||||
include_directories(${PROJECT_SOURCE_DIR}/src)
|
||||
|
||||
file(GLOB src
|
||||
"${PROJECT_SOURCE_DIR}/src/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/engine/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/ending/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/gui/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/info/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/intro/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/collectible/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/enemy/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/gui/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/message/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/pause/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/player/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/shadow/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/spawn/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/tutorial/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/play/wave/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/results/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/results/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/scene/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/game/title/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/sdl/*.c"
|
||||
"${PROJECT_SOURCE_DIR}/src/util/*.c"
|
||||
)
|
||||
|
||||
add_executable(calamitycobra ${src})
|
||||
|
||||
if (EMSCRIPTEN)
|
||||
set (CMAKE_C_FLAGS "-O2 --preload-file res --use-preload-plugins -s NO_DYNAMIC_EXECUTION=1 -s ALLOW_MEMORY_GROWTH=1 -s ASSERTIONS=1 -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0 -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='['png']' -s USE_SDL_MIXER=2 -s SDL2_MIXER_FORMATS='['ogg']' -s USE_SDL_TTF=2")
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set (CMAKE_C_FLAGS "-DDEBUG -g -Wno-unused-command-line-argument" ${CMAKE_C_FLAGS})
|
||||
else()
|
||||
set (CMAKE_BUILD_TyPE "Release")
|
||||
endif()
|
||||
|
||||
set(CMAKE_EXECUTABLE_SUFFIX ".html")
|
||||
else()
|
||||
set (CMAKE_C_FLAGS "-O2")
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
set (CMAKE_C_FLAGS "-DDEBUG -g -O2 -Wno-unused-variable -Wno-unused-parameter -Wall -Wextra -pedantic" ${CMAKE_C_FLAGS})
|
||||
else()
|
||||
set (CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
set (CMAKE_C_FLAGS "-mwindows ${CMAKE_C_FLAGS}")
|
||||
target_link_libraries(${PROJECT_NAME} mingw32 m SDL2main SDL2 SDL2_ttf SDL2_image SDL2_mixer)
|
||||
else()
|
||||
target_link_libraries(${PROJECT_NAME} m SDL2 SDL2_ttf SDL2_image SDL2_mixer)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
message("System: ${CMAKE_SYSTEM_NAME}")
|
||||
message("Project: ${PROJECT_NAME}")
|
||||
message("Build: ${CMAKE_BUILD_TYPE}")
|
||||
message("Flags: ${CMAKE_C_FLAGS}")
|
674
LICENSE
Executable file
674
LICENSE
Executable file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
53
README.md
Executable file
53
README.md
Executable file
@ -0,0 +1,53 @@
|
||||
# "Calamity Cobra in "A Sweet Surprise"
|
||||
|
||||
![1](/screenshots/1.png)
|
||||
|
||||
![2](/screenshots/2.png)
|
||||
|
||||
![3](/screenshots/3.png)
|
||||
|
||||
![4](/screenshots/4.png)
|
||||
|
||||
My entry for the 2022 WeightGaming Gain Jam. A top down arcade shooter with some fetishy elements.
|
||||
|
||||
## Build
|
||||
|
||||
### Dependencies
|
||||
|
||||
- SDL2
|
||||
- SDL_image
|
||||
- SDL_mixer
|
||||
- SDL_ttf
|
||||
- emscripten (Web only)
|
||||
|
||||
### Linux
|
||||
|
||||
This repository uses CMake to compile, so:
|
||||
|
||||
`mkdir build`
|
||||
|
||||
`cd build`
|
||||
|
||||
`cmake ..`
|
||||
|
||||
`make`
|
||||
|
||||
### Windows
|
||||
|
||||
I used MinGW for the Windows build, so basically the same as Linux but you'll need to use MSYS, MinGW, etc. to compile it.
|
||||
|
||||
### Web (Emscripten)
|
||||
|
||||
Make sure you have Emscripten all configured with all the needed ports (see above).
|
||||
|
||||
Then:
|
||||
|
||||
`mkdir build`
|
||||
|
||||
`cd build`
|
||||
|
||||
`emcmake cmake ..`
|
||||
|
||||
`emmake make`
|
||||
|
||||
Make sure you've got the resources folder and that it's placed in the same directory as the executable. You can get that [here](https://shweetz.net/files/games/calamity-cobra-resources-1.2.7z).
|
BIN
screenshots/1.png
Normal file
BIN
screenshots/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 48 KiB |
BIN
screenshots/2.png
Normal file
BIN
screenshots/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 50 KiB |
BIN
screenshots/3.png
Normal file
BIN
screenshots/3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
BIN
screenshots/4.png
Normal file
BIN
screenshots/4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
38
src/COMMON.h
Executable file
38
src/COMMON.h
Executable file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FALSE 0
|
||||
#define TRUE !FALSE
|
||||
|
||||
#define PI 3.14159265358979323846
|
||||
#define SECOND 1000
|
||||
#define MINUTE 60000
|
||||
|
||||
#define RAD_TO_DEG (180 / PI)
|
||||
#define DEG_TO_RAD (PI / 180)
|
||||
|
||||
#define ROTATION_MAX_DEG 360
|
||||
#define ROTATION_MAX_RAD (2 * PI)
|
||||
|
||||
#define FLOOR(x, f) x < f ? f : x
|
||||
#define CEIL(x, c) x > c ? c : x
|
||||
#define CLAMP(x, f, c) FLOOR(CEIL(x, c), f)
|
||||
|
||||
typedef uint8_t u8;
|
||||
typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
typedef int8_t s8;
|
||||
typedef int16_t s16;
|
||||
typedef int32_t s32;
|
||||
typedef int64_t s64;
|
||||
|
||||
typedef float f32;
|
||||
typedef double f64;
|
||||
|
||||
typedef u8 bool_u8;
|
43
src/engine/atlas.c
Executable file
43
src/engine/atlas.c
Executable file
@ -0,0 +1,43 @@
|
||||
#include "atlas.h"
|
||||
|
||||
/*
|
||||
* Initializes a given atlas, provided a
|
||||
* texture, rows, columns, each frame's width, and
|
||||
* each frame's height.
|
||||
*/
|
||||
void
|
||||
atlas_init(Atlas* _a, SDL_Texture* _t, s32 _r, s32 _c, s32 _fW, s32 _fH)
|
||||
{
|
||||
memset(_a, '\0', sizeof(Atlas));
|
||||
|
||||
_a->texture = _t;
|
||||
_a->rows = _r;
|
||||
_a->cols = _c;
|
||||
_a->frameW = _fW;
|
||||
_a->frameH = _fH;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the source rectangle of an atlas provided a frame;
|
||||
* where it's currently "focused" on.
|
||||
*/
|
||||
SDL_Rect
|
||||
atlas_source_rect_get(Atlas* _a, s32 _f)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
r.w = _a->frameW;
|
||||
r.h = _a->frameH;
|
||||
|
||||
if (_a->cols == 1)
|
||||
r.x = 0;
|
||||
else
|
||||
r.x = (_f % _a->cols) * _a->frameW;
|
||||
|
||||
if (_a->rows == 1)
|
||||
r.y = 0;
|
||||
else
|
||||
r.y = (_f / _a->rows) * _a->frameH;
|
||||
|
||||
return r;
|
||||
}
|
18
src/engine/atlas.h
Executable file
18
src/engine/atlas.h
Executable file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "texture.h"
|
||||
|
||||
#define ATLAS_ROWS_DEFAULT 1
|
||||
#define ATLAS_COLUMNS_DEFAULT 1
|
||||
|
||||
typedef struct Atlas
|
||||
{
|
||||
SDL_Texture* texture;
|
||||
s32 rows;
|
||||
s32 cols;
|
||||
s32 frameW;
|
||||
s32 frameH;
|
||||
} Atlas;
|
||||
|
||||
void atlas_init(Atlas* _a, SDL_Texture* _t, s32 _r, s32 _c, s32 _fW, s32 _fH);
|
||||
SDL_Rect atlas_source_rect_get(Atlas* _a, s32 _f);
|
28
src/engine/circle.c
Executable file
28
src/engine/circle.c
Executable file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Circle code.
|
||||
*/
|
||||
|
||||
#include "circle.h"
|
||||
|
||||
/* Are two circles colliding? */
|
||||
bool_u8
|
||||
circle_collide(Circle* _a, Circle* _b)
|
||||
{
|
||||
f64 sum;
|
||||
f64 distance;
|
||||
|
||||
distance = math_distance
|
||||
(
|
||||
_a->x,
|
||||
_a->y,
|
||||
_b->x,
|
||||
_b->y
|
||||
);
|
||||
|
||||
sum = _a->r + _b->r;
|
||||
|
||||
if (distance < sum)
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
18
src/engine/circle.h
Executable file
18
src/engine/circle.h
Executable file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for circle.h.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../util/math.h"
|
||||
#include "../COMMON.h"
|
||||
|
||||
typedef struct Circle
|
||||
{
|
||||
f64 r;
|
||||
f64 x;
|
||||
f64 y;
|
||||
} Circle;
|
||||
|
||||
bool_u8 circle_collide(Circle* _a, Circle* _b);
|
44
src/engine/event.c
Executable file
44
src/engine/event.c
Executable file
@ -0,0 +1,44 @@
|
||||
#include "event.h"
|
||||
|
||||
/* Updates events. */
|
||||
void
|
||||
event_update(Event* _e)
|
||||
{
|
||||
SDL_Event event;
|
||||
|
||||
memcpy(&_e->prev, &_e->curr, EVENT_MAX);
|
||||
memset(&_e->curr, '\0', EVENT_MAX);
|
||||
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
_e->curr[EVENT_QUIT] = TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Is a given event pressed? */
|
||||
bool_u8
|
||||
event_press(Event* _e, EventType _t)
|
||||
{
|
||||
return (_e->curr[_t] && !_e->prev[_t]);
|
||||
}
|
||||
|
||||
/* Is a given event held? */
|
||||
bool_u8
|
||||
event_held(Event* _e, EventType _t)
|
||||
{
|
||||
return (_e->curr[_t] && _e->prev[_t]);
|
||||
}
|
||||
|
||||
/* Is a given event released? */
|
||||
bool_u8
|
||||
event_release(Event* _e, EventType _t)
|
||||
{
|
||||
return (!_e->curr[_t] && _e->prev[_t]);
|
||||
}
|
24
src/engine/event.h
Executable file
24
src/engine/event.h
Executable file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
#define EVENT_MAX 2
|
||||
|
||||
typedef enum EventType
|
||||
{
|
||||
EVENT_NONE,
|
||||
EVENT_QUIT
|
||||
} EventType;
|
||||
|
||||
typedef struct Event
|
||||
{
|
||||
bool_u8 curr[EVENT_MAX];
|
||||
bool_u8 prev[EVENT_MAX];
|
||||
} Event;
|
||||
|
||||
void event_update(Event* _e);
|
||||
bool_u8 event_press(Event* _e, EventType _t);
|
||||
bool_u8 event_held(Event* _e, EventType _t);
|
||||
bool_u8 event_release(Event* _e, EventType _t);
|
15
src/engine/font.c
Executable file
15
src/engine/font.c
Executable file
@ -0,0 +1,15 @@
|
||||
#include "font.h"
|
||||
|
||||
/* Loads a given font, with a filepath and a font size specified. */
|
||||
void
|
||||
font_init(TTF_Font** _x, char* _p, s32 _s)
|
||||
{
|
||||
*_x = TTF_OpenFont(_p, _s);
|
||||
}
|
||||
|
||||
/* Frees a given font. */
|
||||
void
|
||||
font_free(TTF_Font* _x)
|
||||
{
|
||||
TTF_CloseFont(_x);
|
||||
}
|
8
src/engine/font.h
Executable file
8
src/engine/font.h
Executable file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_ttf.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
void font_init(TTF_Font** _x, char* _p, s32 _s);
|
||||
void font_free(TTF_Font* _x);
|
36
src/engine/keyboard.c
Executable file
36
src/engine/keyboard.c
Executable file
@ -0,0 +1,36 @@
|
||||
#include "keyboard.h"
|
||||
|
||||
/* Updates the keyboard. */
|
||||
void
|
||||
keyboard_update(Keyboard* _k)
|
||||
{
|
||||
const u8* state;
|
||||
|
||||
memcpy(&_k->prev, &_k->curr, KEYBOARD_MAX);
|
||||
memset(&_k->curr, '\0', KEYBOARD_MAX);
|
||||
|
||||
state = SDL_GetKeyboardState(NULL);
|
||||
|
||||
memcpy(&_k->curr, state, KEYBOARD_MAX);
|
||||
}
|
||||
|
||||
/* Is the given key pressed? */
|
||||
bool_u8
|
||||
keyboard_press(Keyboard* _k, KeyboardType _t)
|
||||
{
|
||||
return (_k->curr[_t] && !_k->prev[_t]);
|
||||
}
|
||||
|
||||
/* Is the given key held? */
|
||||
bool_u8
|
||||
keyboard_held(Keyboard* _k, KeyboardType _t)
|
||||
{
|
||||
return (_k->curr[_t] && _k->prev[_t]);
|
||||
}
|
||||
|
||||
/* Is the given key released? */
|
||||
bool_u8
|
||||
keyboard_release(Keyboard* _k, KeyboardType _t)
|
||||
{
|
||||
return (!_k->curr[_t] && _k->prev[_t]);
|
||||
}
|
241
src/engine/keyboard.h
Executable file
241
src/engine/keyboard.h
Executable file
@ -0,0 +1,241 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
#define KEYBOARD_MAX 0xFF
|
||||
|
||||
typedef enum KeyboardType
|
||||
{
|
||||
KEYBOARD_UNKNOWN = 0,
|
||||
KEYBOARD_UNKNOWN_TWO = 1,
|
||||
KEYBOARD_UNKNOWN_THREE = 2,
|
||||
KEYBOARD_UNKNOWN_FOUR = 3,
|
||||
KEYBOARD_A = 4,
|
||||
KEYBOARD_B = 5,
|
||||
KEYBOARD_C = 6,
|
||||
KEYBOARD_D = 7,
|
||||
KEYBOARD_E = 8,
|
||||
KEYBOARD_F = 9,
|
||||
KEYBOARD_G = 10,
|
||||
KEYBOARD_H = 11,
|
||||
KEYBOARD_I = 12,
|
||||
KEYBOARD_J = 13,
|
||||
KEYBOARD_K = 14,
|
||||
KEYBOARD_L = 15,
|
||||
KEYBOARD_M = 16,
|
||||
KEYBOARD_N = 17,
|
||||
KEYBOARD_O = 18,
|
||||
KEYBOARD_P = 19,
|
||||
KEYBOARD_Q = 20,
|
||||
KEYBOARD_R = 21,
|
||||
KEYBOARD_S = 22,
|
||||
KEYBOARD_T = 23,
|
||||
KEYBOARD_U = 24,
|
||||
KEYBOARD_V = 25,
|
||||
KEYBOARD_W = 26,
|
||||
KEYBOARD_X = 27,
|
||||
KEYBOARD_Y = 28,
|
||||
KEYBOARD_Z = 29,
|
||||
KEYBOARD_1 = 30,
|
||||
KEYBOARD_2 = 31,
|
||||
KEYBOARD_3 = 32,
|
||||
KEYBOARD_4 = 33,
|
||||
KEYBOARD_5 = 34,
|
||||
KEYBOARD_6 = 35,
|
||||
KEYBOARD_7 = 36,
|
||||
KEYBOARD_8 = 37,
|
||||
KEYBOARD_9 = 38,
|
||||
KEYBOARD_0 = 39,
|
||||
KEYBOARD_RETURN = 40,
|
||||
KEYBOARD_ESCAPE = 41,
|
||||
KEYBOARD_BACKSPACE = 42,
|
||||
KEYBOARD_TAB = 43,
|
||||
KEYBOARD_SPACE = 44,
|
||||
KEYBOARD_MINUS = 45,
|
||||
KEYBOARD_EQUALS = 46,
|
||||
KEYBOARD_LEFTBRACKET = 47,
|
||||
KEYBOARD_RIGHTBRACKET = 48,
|
||||
KEYBOARD_BACKSLASH = 49,
|
||||
KEYBOARD_NONUSHASH = 50,
|
||||
KEYBOARD_SEMICOLON = 51,
|
||||
KEYBOARD_APOSTROPHE = 52,
|
||||
KEYBOARD_GRAVE = 53,
|
||||
KEYBOARD_COMMA = 54,
|
||||
KEYBOARD_PERIOD = 55,
|
||||
KEYBOARD_SLASH = 56,
|
||||
KEYBOARD_CAPSLOCK = 57,
|
||||
KEYBOARD_F1 = 58,
|
||||
KEYBOARD_F2 = 59,
|
||||
KEYBOARD_F3 = 60,
|
||||
KEYBOARD_F4 = 61,
|
||||
KEYBOARD_F5 = 62,
|
||||
KEYBOARD_F6 = 63,
|
||||
KEYBOARD_F7 = 64,
|
||||
KEYBOARD_F8 = 65,
|
||||
KEYBOARD_F9 = 66,
|
||||
KEYBOARD_F10 = 67,
|
||||
KEYBOARD_F11 = 68,
|
||||
KEYBOARD_F12 = 69,
|
||||
KEYBOARD_PRINTSCREEN = 70,
|
||||
KEYBOARD_SCROLLLOCK = 71,
|
||||
KEYBOARD_PAUSE = 72,
|
||||
KEYBOARD_INSERT = 73,
|
||||
KEYBOARD_HOME = 74,
|
||||
KEYBOARD_PAGEUP = 75,
|
||||
KEYBOARD_DELETE = 76,
|
||||
KEYBOARD_END = 77,
|
||||
KEYBOARD_PAGEDOWN = 78,
|
||||
KEYBOARD_RIGHT = 79,
|
||||
KEYBOARD_LEFT = 80,
|
||||
KEYBOARD_DOWN = 81,
|
||||
KEYBOARD_UP = 82,
|
||||
KEYBOARD_NUMLOCKCLEAR = 83,
|
||||
KEYBOARD_KP_DIVIDE = 84,
|
||||
KEYBOARD_KP_MULTIPLY = 85,
|
||||
KEYBOARD_KP_MINUS = 86,
|
||||
KEYBOARD_KP_PLUS = 87,
|
||||
KEYBOARD_KP_ENTER = 88,
|
||||
KEYBOARD_KP_1 = 89,
|
||||
KEYBOARD_KP_2 = 90,
|
||||
KEYBOARD_KP_3 = 91,
|
||||
KEYBOARD_KP_4 = 92,
|
||||
KEYBOARD_KP_5 = 93,
|
||||
KEYBOARD_KP_6 = 94,
|
||||
KEYBOARD_KP_7 = 95,
|
||||
KEYBOARD_KP_8 = 96,
|
||||
KEYBOARD_KP_9 = 97,
|
||||
KEYBOARD_KP_0 = 98,
|
||||
KEYBOARD_KP_PERIOD = 99,
|
||||
KEYBOARD_NONUSBACKSLASH = 100,
|
||||
KEYBOARD_APPLICATION = 101,
|
||||
KEYBOARD_POWER = 102,
|
||||
KEYBOARD_KP_EQUALS = 103,
|
||||
KEYBOARD_F13 = 104,
|
||||
KEYBOARD_F14 = 105,
|
||||
KEYBOARD_F15 = 106,
|
||||
KEYBOARD_F16 = 107,
|
||||
KEYBOARD_F17 = 108,
|
||||
KEYBOARD_F18 = 109,
|
||||
KEYBOARD_F19 = 110,
|
||||
KEYBOARD_F20 = 111,
|
||||
KEYBOARD_F21 = 112,
|
||||
KEYBOARD_F22 = 113,
|
||||
KEYBOARD_F23 = 114,
|
||||
KEYBOARD_F24 = 115,
|
||||
KEYBOARD_EXECUTE = 116,
|
||||
KEYBOARD_HELP = 117,
|
||||
KEYBOARD_MENU = 118,
|
||||
KEYBOARD_SELECT = 119,
|
||||
KEYBOARD_STOP = 120,
|
||||
KEYBOARD_AGAIN = 121,
|
||||
KEYBOARD_UNDO = 122,
|
||||
KEYBOARD_CUT = 123,
|
||||
KEYBOARD_COPY = 124,
|
||||
KEYBOARD_PASTE = 125,
|
||||
KEYBOARD_FIND = 126,
|
||||
KEYBOARD_MUTE = 127,
|
||||
KEYBOARD_VOLUMEUP = 128,
|
||||
KEYBOARD_VOLUMEDOWN = 129,
|
||||
KEYBOARD_LOCKINGCAPSLOCK = 130,
|
||||
KEYBOARD_LOCKINGNUMLOCK = 131,
|
||||
KEYBOARD_LOCKINGSCROLLLOCK = 132,
|
||||
KEYBOARD_KP_COMMA = 133,
|
||||
KEYBOARD_KP_EQUALSAS400 = 134,
|
||||
KEYBOARD_INTERNATIONAL1 = 135,
|
||||
KEYBOARD_INTERNATIONAL2 = 136,
|
||||
KEYBOARD_INTERNATIONAL3 = 137,
|
||||
KEYBOARD_INTERNATIONAL4 = 138,
|
||||
KEYBOARD_INTERNATIONAL5 = 139,
|
||||
KEYBOARD_INTERNATIONAL6 = 140,
|
||||
KEYBOARD_INTERNATIONAL7 = 141,
|
||||
KEYBOARD_INTERNATIONAL8 = 142,
|
||||
KEYBOARD_INTERNATIONAL9 = 143,
|
||||
KEYBOARD_LANG1 = 144,
|
||||
KEYBOARD_LANG2 = 145,
|
||||
KEYBOARD_LANG3 = 146,
|
||||
KEYBOARD_LANG4 = 147,
|
||||
KEYBOARD_LANG5 = 148,
|
||||
KEYBOARD_LANG6 = 149,
|
||||
KEYBOARD_LANG7 = 150,
|
||||
KEYBOARD_LANG8 = 151,
|
||||
KEYBOARD_LANG9 = 152,
|
||||
KEYBOARD_ALTERASE = 153,
|
||||
KEYBOARD_SYSREQ = 154,
|
||||
KEYBOARD_CANCEL = 155,
|
||||
KEYBOARD_CLEAR = 156,
|
||||
KEYBOARD_PRIOR = 157,
|
||||
KEYBOARD_RETURN2 = 158,
|
||||
KEYBOARD_SEPARATOR = 159,
|
||||
KEYBOARD_OUT = 160,
|
||||
KEYBOARD_OPER = 161,
|
||||
KEYBOARD_CLEARAGAIN = 162,
|
||||
KEYBOARD_CRSEL = 163,
|
||||
KEYBOARD_EXSEL = 164,
|
||||
KEYBOARD_KP_00 = 176,
|
||||
KEYBOARD_KP_000 = 177,
|
||||
KEYBOARD_THOUSANDSSEPARATOR = 178,
|
||||
KEYBOARD_DECIMALSEPARATOR = 179,
|
||||
KEYBOARD_CURRENCYUNIT = 180,
|
||||
KEYBOARD_CURRENCYSUBUNIT = 181,
|
||||
KEYBOARD_KP_LEFTPAREN = 182,
|
||||
KEYBOARD_KP_RIGHTPAREN = 183,
|
||||
KEYBOARD_KP_LEFTBRACE = 184,
|
||||
KEYBOARD_KP_RIGHTBRACE = 185,
|
||||
KEYBOARD_KP_TAB = 186,
|
||||
KEYBOARD_KP_BACKSPACE = 187,
|
||||
KEYBOARD_KP_A = 188,
|
||||
KEYBOARD_KP_B = 189,
|
||||
KEYBOARD_KP_C = 190,
|
||||
KEYBOARD_KP_D = 191,
|
||||
KEYBOARD_KP_E = 192,
|
||||
KEYBOARD_KP_F = 193,
|
||||
KEYBOARD_KP_XOR = 194,
|
||||
KEYBOARD_KP_POWER = 195,
|
||||
KEYBOARD_KP_PERCENT = 196,
|
||||
KEYBOARD_KP_LESS = 197,
|
||||
KEYBOARD_KP_GREATER = 198,
|
||||
KEYBOARD_KP_AMPERSAND = 199,
|
||||
KEYBOARD_KP_DBLAMPERSAND = 200,
|
||||
KEYBOARD_KP_VERTICALBAR = 201,
|
||||
KEYBOARD_KP_DBLVERTICALBAR = 202,
|
||||
KEYBOARD_KP_COLON = 203,
|
||||
KEYBOARD_KP_HASH = 204,
|
||||
KEYBOARD_KP_SPACE = 205,
|
||||
KEYBOARD_KP_AT = 206,
|
||||
KEYBOARD_KP_EXCLAM = 207,
|
||||
KEYBOARD_KP_MEMSTORE = 208,
|
||||
KEYBOARD_KP_MEMRECALL = 209,
|
||||
KEYBOARD_KP_MEMCLEAR = 210,
|
||||
KEYBOARD_KP_MEMADD = 211,
|
||||
KEYBOARD_KP_MEMSUBTRACT = 212,
|
||||
KEYBOARD_KP_MEMMULTIPLY = 213,
|
||||
KEYBOARD_KP_MEMDIVIDE = 214,
|
||||
KEYBOARD_KP_PLUSMINUS = 215,
|
||||
KEYBOARD_KP_CLEAR = 216,
|
||||
KEYBOARD_KP_CLEARENTRY = 217,
|
||||
KEYBOARD_KP_BINARY = 218,
|
||||
KEYBOARD_KP_OCTAL = 219,
|
||||
KEYBOARD_KP_DECIMAL = 220,
|
||||
KEYBOARD_KP_HEXADECIMAL = 221,
|
||||
KEYBOARD_LCTRL = 224,
|
||||
KEYBOARD_LSHIFT = 225,
|
||||
KEYBOARD_LALT = 226,
|
||||
KEYBOARD_LGUI = 227,
|
||||
KEYBOARD_RCTRL = 228,
|
||||
KEYBOARD_RSHIFT = 229,
|
||||
KEYBOARD_RALT = 230,
|
||||
KEYBOARD_RGUI = 231
|
||||
} KeyboardType;
|
||||
|
||||
typedef struct Keyboard
|
||||
{
|
||||
bool_u8 curr[KEYBOARD_MAX];
|
||||
bool_u8 prev[KEYBOARD_MAX];
|
||||
} Keyboard;
|
||||
|
||||
void keyboard_update(Keyboard* _k);
|
||||
bool_u8 keyboard_press(Keyboard* _k, KeyboardType _t);
|
||||
bool_u8 keyboard_held(Keyboard* _k, KeyboardType _t);
|
||||
bool_u8 keyboard_release(Keyboard* _k, KeyboardType _t);
|
45
src/engine/mouse.c
Executable file
45
src/engine/mouse.c
Executable file
@ -0,0 +1,45 @@
|
||||
#include "mouse.h"
|
||||
|
||||
/* Updates the mouse. */
|
||||
void
|
||||
mouse_update(Mouse* _m)
|
||||
{
|
||||
s32 state;
|
||||
|
||||
memcpy(&_m->prev, &_m->curr, MOUSE_MAX);
|
||||
memset(&_m->curr, '\0', MOUSE_MAX);
|
||||
|
||||
state = SDL_GetMouseState(NULL, NULL);
|
||||
|
||||
if ((state & SDL_BUTTON_LMASK) != 0)
|
||||
_m->curr[MOUSE_LEFT] = TRUE;
|
||||
|
||||
if ((state & SDL_BUTTON_MMASK) != 0)
|
||||
_m->curr[MOUSE_MIDDLE] = TRUE;
|
||||
|
||||
if ((state & SDL_BUTTON_RMASK) != 0)
|
||||
_m->curr[MOUSE_RIGHT] = TRUE;
|
||||
|
||||
SDL_GetMouseState(&_m->x, &_m->y);
|
||||
}
|
||||
|
||||
/* Is a given mouse button pressed? */
|
||||
bool_u8
|
||||
mouse_press(Mouse* _m, MouseType _t)
|
||||
{
|
||||
return (_m->curr[_t] && !_m->prev[_t]);
|
||||
}
|
||||
|
||||
/* Is a given mouse button held? */
|
||||
bool_u8
|
||||
mouse_held(Mouse* _m, MouseType _t)
|
||||
{
|
||||
return (_m->curr[_t] && _m->prev[_t]);
|
||||
}
|
||||
|
||||
/* Is a given mouse button released? */
|
||||
bool_u8
|
||||
mouse_release(Mouse* _m, MouseType _t)
|
||||
{
|
||||
return (!_m->curr[_t] && _m->prev[_t]);
|
||||
}
|
28
src/engine/mouse.h
Executable file
28
src/engine/mouse.h
Executable file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
#define MOUSE_MAX 4
|
||||
|
||||
typedef enum MouseType
|
||||
{
|
||||
MOUSE_NONE,
|
||||
MOUSE_LEFT,
|
||||
MOUSE_MIDDLE,
|
||||
MOUSE_RIGHT
|
||||
} MouseType;
|
||||
|
||||
typedef struct Mouse
|
||||
{
|
||||
s32 x;
|
||||
s32 y;
|
||||
bool_u8 curr[MOUSE_MAX];
|
||||
bool_u8 prev[MOUSE_MAX];
|
||||
} Mouse;
|
||||
|
||||
void mouse_update(Mouse* _m);
|
||||
bool_u8 mouse_press(Mouse* _m, MouseType _t);
|
||||
bool_u8 mouse_held(Mouse* _m, MouseType _t);
|
||||
bool_u8 mouse_release(Mouse* _m, MouseType _t);
|
39
src/engine/music.c
Executable file
39
src/engine/music.c
Executable file
@ -0,0 +1,39 @@
|
||||
#include "music.h"
|
||||
|
||||
/* Returns music from a filepath. */
|
||||
void
|
||||
music_init(Mix_Music** _x, char* _p)
|
||||
{
|
||||
*_x = Mix_LoadMUS(_p);
|
||||
}
|
||||
|
||||
/* Frees given music. */
|
||||
void
|
||||
music_free(Mix_Music* _x)
|
||||
{
|
||||
Mix_FreeMusic(_x);
|
||||
}
|
||||
|
||||
/* Plays a given music. */
|
||||
void
|
||||
music_play(Mix_Music* _x, bool_u8 _l)
|
||||
{
|
||||
if (_l)
|
||||
Mix_PlayMusic(_x, -1);
|
||||
else
|
||||
Mix_PlayMusic(_x, 0);
|
||||
}
|
||||
|
||||
/* Stops whatever music is playing. */
|
||||
void
|
||||
music_stop(void)
|
||||
{
|
||||
Mix_HaltMusic();
|
||||
}
|
||||
|
||||
/* Is music currently playing? */
|
||||
bool_u8
|
||||
music_playing(void)
|
||||
{
|
||||
return Mix_PlayingMusic();
|
||||
}
|
12
src/engine/music.h
Executable file
12
src/engine/music.h
Executable file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
|
||||
void music_init(Mix_Music** _x, char* _path);
|
||||
void music_free(Mix_Music* _x);
|
||||
void music_play(Mix_Music* _x, bool_u8 _l);
|
||||
void music_stop(void);
|
||||
bool_u8 music_playing(void);
|
30
src/engine/rectangle.c
Executable file
30
src/engine/rectangle.c
Executable file
@ -0,0 +1,30 @@
|
||||
#include "rectangle.h"
|
||||
|
||||
/* Draws a rectangle onto a renderer, given a rectangle and color. */
|
||||
void
|
||||
rectangle_draw(SDL_Rect* _x, SDL_Renderer* _r, SDL_Color _c)
|
||||
{
|
||||
SDL_Color c;
|
||||
|
||||
c = renderer_color_get(_r);
|
||||
|
||||
renderer_color_set(_r, _c);
|
||||
|
||||
SDL_RenderFillRect(_r, _x);
|
||||
|
||||
renderer_color_set(_r, c);
|
||||
}
|
||||
|
||||
/* Is a point colliding with a rectangle? */
|
||||
bool_u8
|
||||
rectangle_point_collide(SDL_Rect* _r, f64 _x, f64 _y)
|
||||
{
|
||||
SDL_Point p;
|
||||
|
||||
p.x = _x;
|
||||
p.y = _y;
|
||||
|
||||
if (SDL_PointInRect(&p, _r))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
6
src/engine/rectangle.h
Executable file
6
src/engine/rectangle.h
Executable file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "renderer.h"
|
||||
|
||||
void rectangle_draw(SDL_Rect* _x, SDL_Renderer* _renderer, SDL_Color _c);
|
||||
bool_u8 rectangle_point_collide(SDL_Rect* _r, f64 _x, f64 _y);
|
88
src/engine/renderer.c
Executable file
88
src/engine/renderer.c
Executable file
@ -0,0 +1,88 @@
|
||||
#include "renderer.h"
|
||||
|
||||
/* Initializes a renderer, given a window and renderer flags. */
|
||||
void
|
||||
renderer_init(SDL_Renderer** _x, SDL_Window* _w, s32 _f)
|
||||
{
|
||||
*_x = SDL_CreateRenderer
|
||||
(
|
||||
_w,
|
||||
-1,
|
||||
_f
|
||||
);
|
||||
|
||||
SDL_SetRenderDrawBlendMode(*_x, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
/* Frees a given renderer. */
|
||||
void
|
||||
renderer_free(SDL_Renderer* _x)
|
||||
{
|
||||
SDL_DestroyRenderer(_x);
|
||||
}
|
||||
|
||||
/* Clears the renderer. */
|
||||
void
|
||||
renderer_clear(SDL_Renderer* _x)
|
||||
{
|
||||
SDL_RenderClear(_x);
|
||||
}
|
||||
|
||||
/* Presents the renderer to the screen. */
|
||||
void
|
||||
renderer_present(SDL_Renderer* _x)
|
||||
{
|
||||
SDL_RenderPresent(_x);
|
||||
}
|
||||
|
||||
/* Gets the renderer's current draw color. */
|
||||
SDL_Color
|
||||
renderer_color_get(SDL_Renderer* _r)
|
||||
{
|
||||
SDL_Color c;
|
||||
|
||||
memset(&c, '\0', sizeof(SDL_Color));
|
||||
|
||||
SDL_GetRenderDrawColor
|
||||
(
|
||||
_r,
|
||||
&c.r,
|
||||
&c.g,
|
||||
&c.b,
|
||||
&c.a
|
||||
);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
/* Sets the renderer's current draw color. */
|
||||
void
|
||||
renderer_color_set(SDL_Renderer* _x, SDL_Color _c)
|
||||
{
|
||||
SDL_SetRenderDrawColor
|
||||
(
|
||||
_x,
|
||||
_c.r,
|
||||
_c.g,
|
||||
_c.b,
|
||||
_c.a
|
||||
);
|
||||
}
|
||||
|
||||
/* Set's the renderer's viewport; e.g., where it's going to be drawing to. */
|
||||
void
|
||||
renderer_viewport_set(SDL_Renderer* _x, SDL_Rect _r)
|
||||
{
|
||||
SDL_RenderSetViewport(_x, &_r);
|
||||
}
|
||||
|
||||
/* Sets the renderer's viewport to the window's. */
|
||||
void
|
||||
renderer_viewport_window_set(SDL_Renderer* _x, SDL_Window* _w)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
r = window_rect_get(_w);
|
||||
|
||||
renderer_viewport_set(_x, r);
|
||||
}
|
12
src/engine/renderer.h
Executable file
12
src/engine/renderer.h
Executable file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "window.h"
|
||||
|
||||
SDL_Color renderer_color_get(SDL_Renderer* _r);
|
||||
void renderer_clear(SDL_Renderer* _x);
|
||||
void renderer_color_set(SDL_Renderer* _x, SDL_Color _c);
|
||||
void renderer_free(SDL_Renderer* _x);
|
||||
void renderer_init(SDL_Renderer** _x, SDL_Window* _w, s32 _f);
|
||||
void renderer_present(SDL_Renderer* _x);
|
||||
void renderer_viewport_set(SDL_Renderer* _x, SDL_Rect _r);
|
||||
void renderer_viewport_window_set(SDL_Renderer* _x, SDL_Window* _w);
|
22
src/engine/sound.c
Executable file
22
src/engine/sound.c
Executable file
@ -0,0 +1,22 @@
|
||||
#include "sound.h"
|
||||
|
||||
/* Initializes a sound from a given filepath. */
|
||||
void
|
||||
sound_init(Mix_Chunk** _x, char* _path)
|
||||
{
|
||||
*_x = Mix_LoadWAV(_path);
|
||||
}
|
||||
|
||||
/* Frees a given sound. */
|
||||
void
|
||||
sound_free(Mix_Chunk* _x)
|
||||
{
|
||||
Mix_FreeChunk(_x);
|
||||
}
|
||||
|
||||
/* Plays a given sound, with its channel specified. */
|
||||
void
|
||||
sound_play(Mix_Chunk* _x, s32 _channel)
|
||||
{
|
||||
Mix_PlayChannel(_channel, _x, 0);
|
||||
}
|
9
src/engine/sound.h
Executable file
9
src/engine/sound.h
Executable file
@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_mixer.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
void sound_init(Mix_Chunk** _x, char* _path);
|
||||
void sound_free(Mix_Chunk* _x);
|
||||
void sound_play(Mix_Chunk* _x, s32 _channel);
|
144
src/engine/sprite.c
Executable file
144
src/engine/sprite.c
Executable file
@ -0,0 +1,144 @@
|
||||
#include "sprite.h"
|
||||
|
||||
/* Gets the sprite's current rectangle. */
|
||||
SDL_Rect
|
||||
sprite_rect_get(Sprite* _x)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
memset(&r, '\0', sizeof(SDL_Rect));
|
||||
|
||||
r.w = _x->w * _x->scale * _x->squash;
|
||||
r.h = _x->h * _x->scale * _x->stretch;
|
||||
|
||||
switch (_x->origin)
|
||||
{
|
||||
case ORIGIN_TOP_LEFT:
|
||||
r.x = _x->x;
|
||||
r.y = _x->y;
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
case ORIGIN_MIDDLE:
|
||||
default:
|
||||
r.x = _x->x - (r.w / 2);
|
||||
r.y = _x->y - (r.h / 2);
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes a sprite with an atlas, its origin,
|
||||
* its width and its height.
|
||||
*/
|
||||
void
|
||||
sprite_atlas_init(Sprite* _x, Atlas* _a, OriginType _o, s32 _w, s32 _h)
|
||||
{
|
||||
memset(_x, '\0', sizeof(Sprite));
|
||||
|
||||
_x->atlas = *_a;
|
||||
_x->origin = _o;
|
||||
_x->w = _w;
|
||||
_x->h = _h;
|
||||
_x->rotation = SPRITE_ROTATION_DEFAULT;
|
||||
_x->frame = SPRITE_FRAME_DEFAULT;
|
||||
_x->scale = SPRITE_SCALE_DEFAULT;
|
||||
_x->squash = SPRITE_SQUASH_DEFAULT;
|
||||
_x->stretch = SPRITE_STRETCH_DEFAULT;
|
||||
_x->color = SPRITE_COLOR_DEFAULT;
|
||||
_x->flip = FLIP_NONE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes a sprite, given a texture, an origin,
|
||||
* its width and its height.
|
||||
*/
|
||||
void
|
||||
sprite_init(Sprite* _x, SDL_Texture* _t, OriginType _o, s32 _w, s32 _h)
|
||||
{
|
||||
Atlas a;
|
||||
|
||||
atlas_init
|
||||
(
|
||||
&a,
|
||||
_t,
|
||||
ATLAS_ROWS_DEFAULT,
|
||||
ATLAS_COLUMNS_DEFAULT,
|
||||
_w,
|
||||
_h
|
||||
);
|
||||
|
||||
sprite_atlas_init
|
||||
(
|
||||
_x,
|
||||
&a,
|
||||
_o,
|
||||
_w,
|
||||
_h
|
||||
);
|
||||
}
|
||||
|
||||
/* Draws the sprite. */
|
||||
void
|
||||
sprite_draw(Sprite* _x, SDL_Renderer* _r)
|
||||
{
|
||||
SDL_Rect sourceRect;
|
||||
SDL_Rect destRect;
|
||||
s32 flip;
|
||||
|
||||
destRect = sprite_rect_get(_x);
|
||||
|
||||
if (_x->atlas.rows == 1 && _x->atlas.cols == 1)
|
||||
{
|
||||
sourceRect.x = 0;
|
||||
sourceRect.y = 0;
|
||||
sourceRect.w = texture_w_get(_x->atlas.texture);
|
||||
sourceRect.h = texture_h_get(_x->atlas.texture);
|
||||
}
|
||||
else
|
||||
sourceRect = atlas_source_rect_get(&_x->atlas, _x->frame);
|
||||
|
||||
switch (_x->flip)
|
||||
{
|
||||
case FLIP_HORIZONTAL:
|
||||
flip = SDL_FLIP_HORIZONTAL;
|
||||
break;
|
||||
case FLIP_VERTICAL:
|
||||
flip = SDL_FLIP_VERTICAL;
|
||||
break;
|
||||
case FLIP_HORIZONTAL_VERTICAL:
|
||||
flip = SDL_FLIP_HORIZONTAL | SDL_FLIP_VERTICAL;
|
||||
break;
|
||||
/* FALLTHROUGH */
|
||||
case FLIP_NONE:
|
||||
default:
|
||||
flip = SDL_FLIP_NONE;
|
||||
break;
|
||||
}
|
||||
|
||||
SDL_SetTextureAlphaMod
|
||||
(
|
||||
_x->atlas.texture,
|
||||
_x->color.a
|
||||
);
|
||||
|
||||
SDL_SetTextureColorMod
|
||||
(
|
||||
_x->atlas.texture,
|
||||
_x->color.r,
|
||||
_x->color.g,
|
||||
_x->color.b
|
||||
);
|
||||
|
||||
SDL_RenderCopyEx
|
||||
(
|
||||
_r,
|
||||
_x->atlas.texture,
|
||||
&sourceRect,
|
||||
&destRect,
|
||||
_x->rotation,
|
||||
NULL,
|
||||
flip
|
||||
);
|
||||
}
|
49
src/engine/sprite.h
Executable file
49
src/engine/sprite.h
Executable file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "atlas.h"
|
||||
|
||||
#define SPRITE_SCALE_DEFAULT 1.0
|
||||
#define SPRITE_SQUASH_DEFAULT 1.0
|
||||
#define SPRITE_STRETCH_DEFAULT 1.0
|
||||
#define SPRITE_FRAME_DEFAULT 0
|
||||
#define SPRITE_ROTATION_DEFAULT 0.0
|
||||
|
||||
typedef enum OriginType
|
||||
{
|
||||
ORIGIN_NONE,
|
||||
ORIGIN_TOP_LEFT,
|
||||
ORIGIN_MIDDLE
|
||||
} OriginType;
|
||||
|
||||
typedef enum FlipType
|
||||
{
|
||||
FLIP_NONE,
|
||||
FLIP_HORIZONTAL,
|
||||
FLIP_VERTICAL,
|
||||
FLIP_HORIZONTAL_VERTICAL
|
||||
} FlipType;
|
||||
|
||||
typedef struct Sprite
|
||||
{
|
||||
FlipType flip;
|
||||
OriginType origin;
|
||||
f64 rotation;
|
||||
f64 scale;
|
||||
f64 squash;
|
||||
f64 stretch;
|
||||
f64 x;
|
||||
f64 y;
|
||||
s32 frame;
|
||||
s32 h;
|
||||
s32 w;
|
||||
Atlas atlas;
|
||||
SDL_Color color;
|
||||
} Sprite;
|
||||
|
||||
static const SDL_Color SPRITE_COLOR_DEFAULT = {255, 255, 255, 255};
|
||||
|
||||
SDL_Rect sprite_rect_get(Sprite* _x);
|
||||
void sprite_atlas_init(Sprite* _x, Atlas* _a, OriginType _o, s32 _w, s32 _h);
|
||||
void sprite_init(Sprite* _x, SDL_Texture* _t, OriginType _o, s32 _w, s32 _h);
|
||||
void sprite_draw(Sprite* _x, SDL_Renderer* _r);
|
||||
void sprite_free(Sprite* _x);
|
100
src/engine/text.c
Executable file
100
src/engine/text.c
Executable file
@ -0,0 +1,100 @@
|
||||
#include "text.h"
|
||||
|
||||
static void text_surface_init(SDL_Surface** _x, SDL_Renderer* _r, TTF_Font* _f, SDL_Color _c, char* _s, s32 _w);
|
||||
static void text_texture_init(SDL_Texture** _x, SDL_Renderer* _r, TTF_Font* _f, SDL_Color _c, char* _s, s32 _w);
|
||||
|
||||
/*
|
||||
* Initializes a SDL_Surface with text, given
|
||||
* a renderer, a font, a color, a string,
|
||||
* and a text wrap width.
|
||||
*/
|
||||
static void
|
||||
text_surface_init
|
||||
(
|
||||
SDL_Surface** _x,
|
||||
SDL_Renderer* _r,
|
||||
TTF_Font* _f,
|
||||
SDL_Color _c,
|
||||
char* _s,
|
||||
s32 _w
|
||||
)
|
||||
{
|
||||
*_x = TTF_RenderText_Blended_Wrapped
|
||||
(
|
||||
_f,
|
||||
_s,
|
||||
_c,
|
||||
_w
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initializes a SDL_Texture with text,
|
||||
* given a renderer, a font, a color, a string, and a
|
||||
* text wrap width.
|
||||
*/
|
||||
static void
|
||||
text_texture_init
|
||||
(
|
||||
SDL_Texture** _x,
|
||||
SDL_Renderer* _r,
|
||||
TTF_Font* _f,
|
||||
SDL_Color _c,
|
||||
char* _s,
|
||||
s32 _w
|
||||
)
|
||||
{
|
||||
SDL_Surface* s;
|
||||
|
||||
text_surface_init
|
||||
(
|
||||
&s,
|
||||
_r,
|
||||
_f,
|
||||
_c,
|
||||
_s,
|
||||
_w
|
||||
);
|
||||
|
||||
*_x = SDL_CreateTextureFromSurface(_r, s);
|
||||
|
||||
SDL_FreeSurface(s);
|
||||
}
|
||||
|
||||
/* Initializes a sprite with text,
|
||||
* given a renderer, a font, a color, a string, an origin,
|
||||
* and a text wrap width.
|
||||
*/
|
||||
void
|
||||
text_sprite_init
|
||||
(
|
||||
Sprite* _x,
|
||||
SDL_Renderer* _r,
|
||||
TTF_Font* _f,
|
||||
SDL_Color _c,
|
||||
OriginType _o,
|
||||
char* _s,
|
||||
s32 _w
|
||||
)
|
||||
{
|
||||
SDL_Texture* t;
|
||||
|
||||
text_texture_init
|
||||
(
|
||||
&t,
|
||||
_r,
|
||||
_f,
|
||||
_c,
|
||||
_s,
|
||||
_w
|
||||
);
|
||||
|
||||
sprite_init
|
||||
(
|
||||
_x,
|
||||
t,
|
||||
_o,
|
||||
texture_w_get(t),
|
||||
texture_h_get(t)
|
||||
);
|
||||
}
|
6
src/engine/text.h
Executable file
6
src/engine/text.h
Executable file
@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "font.h"
|
||||
#include "sprite.h"
|
||||
|
||||
void text_sprite_init(Sprite* _x, SDL_Renderer* _r, TTF_Font* _f, SDL_Color _c, OriginType _o, char* _s, s32 _w);
|
37
src/engine/texture.c
Executable file
37
src/engine/texture.c
Executable file
@ -0,0 +1,37 @@
|
||||
#include "texture.h"
|
||||
|
||||
/* Initializes a texture, given a renderer and a path. */
|
||||
void
|
||||
texture_init(SDL_Texture** _x, SDL_Renderer* _r, char* _p)
|
||||
{
|
||||
*_x = IMG_LoadTexture(_r, _p);
|
||||
}
|
||||
|
||||
/* Frees a given texture. */
|
||||
void
|
||||
texture_free(SDL_Texture* _x)
|
||||
{
|
||||
SDL_DestroyTexture(_x);
|
||||
}
|
||||
|
||||
/* Returns a texture's width. */
|
||||
s32
|
||||
texture_w_get(SDL_Texture* _x)
|
||||
{
|
||||
s32 w;
|
||||
|
||||
SDL_QueryTexture(_x, NULL, NULL, &w, NULL);
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
/* Returns a texture's height. */
|
||||
s32
|
||||
texture_h_get(SDL_Texture* _x)
|
||||
{
|
||||
s32 h;
|
||||
|
||||
SDL_QueryTexture(_x, NULL, NULL, NULL, &h);
|
||||
|
||||
return h;
|
||||
}
|
11
src/engine/texture.h
Executable file
11
src/engine/texture.h
Executable file
@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
void texture_init(SDL_Texture** _x, SDL_Renderer* _r, char* _p);
|
||||
void texture_free(SDL_Texture* _x);
|
||||
s32 texture_w_get(SDL_Texture* _x);
|
||||
s32 texture_h_get(SDL_Texture* _x);
|
11
src/engine/tick.c
Executable file
11
src/engine/tick.c
Executable file
@ -0,0 +1,11 @@
|
||||
#include "tick.h"
|
||||
|
||||
/* Update ticks. */
|
||||
void
|
||||
tick_update(Tick* _x)
|
||||
{
|
||||
_x->prev = _x->curr;
|
||||
_x->curr = SDL_GetTicks64();
|
||||
_x->delta = _x->curr - _x->prev;
|
||||
_x->cum += _x->delta;
|
||||
}
|
15
src/engine/tick.h
Executable file
15
src/engine/tick.h
Executable file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
typedef struct Tick
|
||||
{
|
||||
u64 curr;
|
||||
u64 prev;
|
||||
u64 delta;
|
||||
u64 cum;
|
||||
} Tick;
|
||||
|
||||
void tick_update(Tick* _x);
|
85
src/engine/window.c
Executable file
85
src/engine/window.c
Executable file
@ -0,0 +1,85 @@
|
||||
#include "window.h"
|
||||
|
||||
/*
|
||||
* Initializes a window, given a window title,
|
||||
* a width, a height, and window flags.
|
||||
*/
|
||||
void
|
||||
window_init(SDL_Window** _x, char* _s, s32 _w, s32 _h, s32 _f)
|
||||
{
|
||||
*_x = SDL_CreateWindow
|
||||
(
|
||||
_s,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED,
|
||||
_w,
|
||||
_h,
|
||||
_f
|
||||
);
|
||||
}
|
||||
|
||||
/* Frees a given window. */
|
||||
void
|
||||
window_free(SDL_Window* _x)
|
||||
{
|
||||
SDL_DestroyWindow(_x);
|
||||
}
|
||||
|
||||
/* Gets the window's width. */
|
||||
s32
|
||||
window_w_get(SDL_Window* _x)
|
||||
{
|
||||
s32 w;
|
||||
|
||||
SDL_GetWindowSize(_x, &w, NULL);
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
/* Get's the window's height. */
|
||||
s32
|
||||
window_h_get(SDL_Window* _x)
|
||||
{
|
||||
s32 h;
|
||||
|
||||
SDL_GetWindowSize(_x, NULL, &h);
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
/* Gets the window's rectangle. */
|
||||
SDL_Rect
|
||||
window_rect_get(SDL_Window* _x)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
memset(&r, '\0', sizeof(SDL_Rect));
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.w = window_w_get(_x);
|
||||
r.h = window_h_get(_x);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/* Sets video mode to fullscreen. */
|
||||
void
|
||||
window_fullscreen_enter(SDL_Window* _x)
|
||||
{
|
||||
SDL_SetWindowFullscreen(_x, SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
|
||||
/* Entering fake fullscreen (desktop). */
|
||||
void
|
||||
window_fullscreen_desktop_enter(SDL_Window* _x)
|
||||
{
|
||||
SDL_SetWindowFullscreen(_x, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
}
|
||||
|
||||
/* Exiting fullscreen. */
|
||||
void
|
||||
window_fullscreen_exit(SDL_Window* _x)
|
||||
{
|
||||
SDL_SetWindowFullscreen(_x, 0);
|
||||
}
|
14
src/engine/window.h
Executable file
14
src/engine/window.h
Executable file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include "../COMMON.h"
|
||||
|
||||
void window_init(SDL_Window** _x, char* _s, s32 _w, s32 _h, s32 _f);
|
||||
void window_free(SDL_Window* _x);
|
||||
void window_fullscreen_enter(SDL_Window* _x);
|
||||
void window_fullscreen_desktop_enter(SDL_Window* _x);
|
||||
void window_fullscreen_exit(SDL_Window* _x);
|
||||
s32 window_w_get(SDL_Window* _x);
|
||||
s32 window_h_get(SDL_Window* _x);
|
||||
SDL_Rect window_rect_get(SDL_Window* _x);
|
509
src/game/GAME_COMMON.h
Executable file
509
src/game/GAME_COMMON.h
Executable file
@ -0,0 +1,509 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Common file for "game" directory.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../engine/circle.h"
|
||||
#include "../engine/event.h"
|
||||
#include "../engine/font.h"
|
||||
#include "../engine/keyboard.h"
|
||||
#include "../engine/mouse.h"
|
||||
#include "../engine/music.h"
|
||||
#include "../engine/rectangle.h"
|
||||
#include "../engine/renderer.h"
|
||||
#include "../engine/sound.h"
|
||||
#include "../engine/text.h"
|
||||
#include "../engine/tick.h"
|
||||
#include "../engine/window.h"
|
||||
#include "../util/list.h"
|
||||
#include "../util/math.h"
|
||||
#include "../util/random.h"
|
||||
|
||||
#define TEXTURE_COUNT 46
|
||||
#define SOUND_COUNT 25
|
||||
#define FONT_COUNT 6
|
||||
#define MUSIC_COUNT 8
|
||||
|
||||
#define PLAYER_FATNESS_MAX 3
|
||||
#define PLAYER_FATNESS_THRESHOLD 2
|
||||
|
||||
typedef enum TextureType
|
||||
{
|
||||
TEXTURE_NONE,
|
||||
TEXTURE_LOGO,
|
||||
TEXTURE_GUI_CURSOR,
|
||||
TEXTURE_GUI_SNAKE,
|
||||
TEXTURE_GUI_REDIRECT,
|
||||
TEXTURE_GUI_CASH,
|
||||
TEXTURE_GUI_UPGRADE_SNAKE,
|
||||
TEXTURE_GUI_UPGRADE_LIFETIME,
|
||||
TEXTURE_GUI_UPGRADE_REDIRECT,
|
||||
TEXTURE_GUI_SIGN_SMALL,
|
||||
TEXTURE_GUI_SIGN_BIG,
|
||||
TEXTURE_SHADOW,
|
||||
TEXTURE_ARC,
|
||||
TEXTURE_PLAY_BG,
|
||||
TEXTURE_PLAYER_STAGE_ONE,
|
||||
TEXTURE_PLAYER_STAGE_TWO,
|
||||
TEXTURE_PLAYER_STAGE_THREE,
|
||||
TEXTURE_PLAYER_TAIL_STAGE_ONE,
|
||||
TEXTURE_PLAYER_TAIL_STAGE_TWO,
|
||||
TEXTURE_PLAYER_TAIL_STAGE_THREE,
|
||||
TEXTURE_PLAYER_SNAKE,
|
||||
TEXTURE_ENEMY_CUPPER,
|
||||
TEXTURE_ENEMY_CHIPPER,
|
||||
TEXTURE_ENEMY_CHIP,
|
||||
TEXTURE_ENEMY_CRUMBLER,
|
||||
TEXTURE_COLLECTIBLE_DOLLARS,
|
||||
TEXTURE_COLLECTIBLE_SACK,
|
||||
TEXTURE_COLLECTIBLE_BULLIONS,
|
||||
TEXTURE_COLLECTIBLE_MIRACLE_CURE,
|
||||
TEXTURE_COLLECTIBLE_DYNAMITE,
|
||||
TEXTURE_COLLECTIBLE_BERSERK,
|
||||
TEXTURE_INFO_THEME,
|
||||
TEXTURE_INFO_WILDCARD_ADMIN,
|
||||
TEXTURE_INFO_WILDCARD_PATREON,
|
||||
TEXTURE_INFO_WILDCARD_COMMUNITY,
|
||||
TEXTURE_INTRO_SCENE_ONE,
|
||||
TEXTURE_INTRO_SCENE_TWO,
|
||||
TEXTURE_INTRO_SCENE_THREE,
|
||||
TEXTURE_INTRO_SCENE_FOUR,
|
||||
TEXTURE_INTRO_SCENE_FIVE,
|
||||
TEXTURE_ENDING_FAIL,
|
||||
TEXTURE_ENDING_ONE,
|
||||
TEXTURE_ENDING_TWO,
|
||||
TEXTURE_ENDING_THREE,
|
||||
TEXTURE_TITLE_BACKGROUND,
|
||||
TEXTURE_RESULTS,
|
||||
} TextureType;
|
||||
|
||||
typedef enum SoundType
|
||||
{
|
||||
SOUND_NONE,
|
||||
SOUND_MENU,
|
||||
SOUND_BLIP,
|
||||
SOUND_SNAKE_FIRE,
|
||||
SOUND_SNAKE_REDIRECT,
|
||||
SOUND_SNAKE_RETURN,
|
||||
SOUND_ENEMY_HURT,
|
||||
SOUND_CUPPER_KILL,
|
||||
SOUND_CHIPPER_KILL,
|
||||
SOUND_CRUMBLER_KILL,
|
||||
SOUND_CHIP_KILL,
|
||||
SOUND_RUMBLE,
|
||||
SOUND_COLLECTIBLE,
|
||||
SOUND_DOLLARS,
|
||||
SOUND_SACK,
|
||||
SOUND_BULLIONS,
|
||||
SOUND_PURCHASE,
|
||||
SOUND_MIRACLE_CURE,
|
||||
SOUND_DYNAMITE,
|
||||
SOUND_BERSERK,
|
||||
SOUND_SWALLOW,
|
||||
SOUND_GROWTH,
|
||||
SOUND_ERROR,
|
||||
SOUND_GO,
|
||||
SOUND_SPIT,
|
||||
} SoundType;
|
||||
|
||||
typedef enum MusicType
|
||||
{
|
||||
MUSIC_NONE,
|
||||
MUSIC_WIND,
|
||||
MUSIC_PLAY,
|
||||
MUSIC_WAVE_CLEAR,
|
||||
MUSIC_WAVE_FAIL,
|
||||
MUSIC_RESULTS,
|
||||
MUSIC_TITLE,
|
||||
MUSIC_INTRO,
|
||||
} MusicType;
|
||||
|
||||
typedef enum FontType
|
||||
{
|
||||
FONT_NONE,
|
||||
FONT_TINY,
|
||||
FONT_SMALL,
|
||||
FONT_MEDIUM,
|
||||
FONT_BIG,
|
||||
FONT_MEGA,
|
||||
} FontType;
|
||||
|
||||
typedef enum StateType
|
||||
{
|
||||
STATE_NONE,
|
||||
STATE_TITLE,
|
||||
STATE_INTRO,
|
||||
STATE_PLAY,
|
||||
STATE_INFO,
|
||||
STATE_ENDING_FAIL,
|
||||
STATE_ENDING_ONE,
|
||||
STATE_ENDING_TWO,
|
||||
STATE_ENDING_THREE,
|
||||
STATE_RESULTS
|
||||
} StateType;
|
||||
|
||||
typedef enum EnemyType
|
||||
{
|
||||
ENEMY_NONE,
|
||||
ENEMY_CUPPER,
|
||||
ENEMY_CHIPPER,
|
||||
ENEMY_CRUMBLER,
|
||||
ENEMY_CHIP
|
||||
} EnemyType;
|
||||
|
||||
typedef enum CollectibleType
|
||||
{
|
||||
COLLECTIBLE_NONE,
|
||||
COLLECTIBLE_DOLLARS,
|
||||
COLLECTIBLE_SACK,
|
||||
COLLECTIBLE_BULLIONS,
|
||||
COLLECTIBLE_MIRACLE_CURE,
|
||||
COLLECTIBLE_DYNAMITE,
|
||||
COLLECTIBLE_BERSERK
|
||||
} CollectibleType;
|
||||
|
||||
typedef enum PowerupType
|
||||
{
|
||||
POWERUP_NONE,
|
||||
|
||||
} PowerupType;
|
||||
|
||||
typedef enum Direction
|
||||
{
|
||||
DIRECTION_LEFT,
|
||||
DIRECTION_RIGHT,
|
||||
DIRECTION_UP,
|
||||
DIRECTION_DOWN
|
||||
} Direction;
|
||||
|
||||
typedef enum SnakeFrameType
|
||||
{
|
||||
SNAKE_NONE,
|
||||
SNAKE_REDIRECT,
|
||||
SNAKE_RETURN
|
||||
} SnakeFrameType;
|
||||
|
||||
typedef enum ButtonStateType
|
||||
{
|
||||
BUTTON_STATE_NONE,
|
||||
BUTTON_STATE_HOVER,
|
||||
BUTTON_STATE_HOVERING,
|
||||
BUTTON_STATE_PRESS,
|
||||
BUTTON_STATE_HELD
|
||||
} ButtonStateType;
|
||||
|
||||
typedef enum EndingType
|
||||
{
|
||||
ENDING_FAIL,
|
||||
ENDING_ONE,
|
||||
ENDING_TWO,
|
||||
ENDING_THREE
|
||||
} EndingType;
|
||||
|
||||
typedef struct Game Game;
|
||||
|
||||
typedef struct Button
|
||||
{
|
||||
Sprite sprite;
|
||||
ButtonStateType state;
|
||||
} Button;
|
||||
|
||||
typedef struct Cursor
|
||||
{
|
||||
Sprite sprite;
|
||||
} Cursor;
|
||||
|
||||
typedef struct Snake
|
||||
{
|
||||
Sprite sprite;
|
||||
Circle shadow;
|
||||
Sprite arc;
|
||||
f64 dX;
|
||||
f64 dY;
|
||||
s32 damage;
|
||||
s32 lifetime;
|
||||
s32 animationTimer;
|
||||
s32 returnTimer;
|
||||
s32 redirectCount;
|
||||
s32 redirectTimer;
|
||||
bool_u8 isReturning;
|
||||
} Snake;
|
||||
|
||||
typedef struct Collectible
|
||||
{
|
||||
Sprite sprite;
|
||||
Circle shadow;
|
||||
s32 lifetime;
|
||||
bool_u8 isActive;
|
||||
s32 activeTimer;
|
||||
f64 dX;
|
||||
f64 dY;
|
||||
CollectibleType type;
|
||||
bool_u8 isAttached;
|
||||
Snake* attachedSnake;
|
||||
} Collectible;
|
||||
|
||||
typedef struct Enemy
|
||||
{
|
||||
EnemyType type;
|
||||
Sprite sprite;
|
||||
Circle shadow;
|
||||
bool_u8 isActing;
|
||||
bool_u8 isActive;
|
||||
List snakesHit; /* Snake* */
|
||||
List returnSnakesHit; /* Snake* */
|
||||
f64 range;
|
||||
s32 attackTimer;
|
||||
s32 animationTimer;
|
||||
s32 lifetime;
|
||||
s32 hitTimer;
|
||||
s32 hitTimerMax;
|
||||
s32 health;
|
||||
f64 dX;
|
||||
f64 dY;
|
||||
} Enemy;
|
||||
|
||||
typedef struct Message
|
||||
{
|
||||
Sprite sprite;
|
||||
f64 x;
|
||||
f64 y;
|
||||
f64 dX;
|
||||
f64 dY;
|
||||
f64 dR;
|
||||
s32 lifetime;
|
||||
} Message;
|
||||
|
||||
typedef struct Player
|
||||
{
|
||||
Circle shadow;
|
||||
Direction direction;
|
||||
List snakes;
|
||||
Sprite sprite;
|
||||
Sprite tailSprite;
|
||||
bool_u8 isAbleToFire;
|
||||
bool_u8 isAbleToMove;
|
||||
bool_u8 isBeingFattened;
|
||||
bool_u8 isCashUpdate;
|
||||
bool_u8 isBeingDefeated;
|
||||
bool_u8 isDefeat;
|
||||
bool_u8 isFatnessUpdate;
|
||||
bool_u8 isLifetimeUpgradeUpdate;
|
||||
bool_u8 isPowerUp;
|
||||
bool_u8 isRedirectUpdate;
|
||||
bool_u8 isRedirectUpgradeUpdate;
|
||||
bool_u8 isSnakeUpdate;
|
||||
bool_u8 isSnakeUpgradeUpdate;
|
||||
bool_u8 isTailAnimate;
|
||||
bool_u8 isStationary;
|
||||
bool_u8 isKeyboardMove;
|
||||
f64 dX;
|
||||
f64 dY;
|
||||
s32 cash;
|
||||
s32 enemiesKilled;
|
||||
s32 fatness;
|
||||
s32 fatnessTimer;
|
||||
s32 cashCollected;
|
||||
s32 lifetime;
|
||||
s32 lifetimeUpgradeLevel;
|
||||
s32 powerUpTimer;
|
||||
s32 redirectMax;
|
||||
s32 redirectTimer;
|
||||
s32 redirectUpgradeLevel;
|
||||
s32 redirects;
|
||||
s32 snakeMax;
|
||||
s32 snakeReserve;
|
||||
s32 snakeUpgradeLevel;
|
||||
s32 defeatTimer;
|
||||
s32 tailTimer;
|
||||
s32 waveEnemiesKilled;
|
||||
s32 redirectRechargeTimer;
|
||||
s32 redirectUpgradePrice;
|
||||
s32 snakeUpgradePrice;
|
||||
s32 lifetimeUpgradePrice;
|
||||
} Player;
|
||||
|
||||
typedef struct GUI
|
||||
{
|
||||
Cursor cursor;
|
||||
Sprite snakeSprite;
|
||||
Sprite snakeText;
|
||||
Sprite redirectSprite;
|
||||
Sprite redirectText;
|
||||
Sprite cashSprite;
|
||||
Sprite cashText;
|
||||
Sprite snakeUpgradeText;
|
||||
Sprite lifetimeUpgradeText;
|
||||
Sprite redirectUpgradeText;
|
||||
Sprite upgradeText;
|
||||
Button snakeUpgradeButton;
|
||||
Button lifetimeUpgradeButton;
|
||||
Button redirectUpgradeButton;
|
||||
Button readyButton;
|
||||
Sprite waveText;
|
||||
Sprite snakeUpgradeBackgroundSprite;
|
||||
Sprite redirectUpgradeBackgroundSprite;
|
||||
Sprite lifetimeUpgradeBackgroundSprite;
|
||||
Sprite upgradeBackgroundSprite;
|
||||
Sprite readyBackgroundSprite;
|
||||
Sprite cashBackgroundSprite;
|
||||
Sprite cashTextBackgroundSprite;
|
||||
Sprite waveBackgroundSprite;
|
||||
Sprite bountyBackgroundSprite;
|
||||
Sprite bountyText;
|
||||
} GUI;
|
||||
|
||||
typedef struct Play
|
||||
{
|
||||
struct Game* g;
|
||||
Sprite pauseText;
|
||||
GUI gui;
|
||||
Player player;
|
||||
bool_u8 isWaveFailed;
|
||||
bool_u8 isWaveCleared;
|
||||
bool_u8 isGameCleared;
|
||||
bool_u8 isPaused;
|
||||
bool_u8 isBetweenWaves;
|
||||
bool_u8 isReady;
|
||||
bool_u8 isCountdown;
|
||||
bool_u8 isCountdownComplete;
|
||||
bool_u8 isWaveClearMusicComplete;
|
||||
bool_u8 isWaveUpdate;
|
||||
bool_u8 isUpgradesActive;
|
||||
bool_u8 isUpgradeUpdate;
|
||||
bool_u8 isBountyUpdate;
|
||||
bool_u8 isGameClearing;
|
||||
bool_u8 isGracePeriod;
|
||||
bool_u8 isTutorial;
|
||||
Sprite tutorialText;
|
||||
Sprite bg;
|
||||
s32 gameClearTimer;
|
||||
s32 countdownTimer;
|
||||
s32 tutorialTimer;
|
||||
s32 wave;
|
||||
s32 game;
|
||||
s32 spawnTimer;
|
||||
s32 enemyMax;
|
||||
s32 gracePeriodTimer;
|
||||
List enemies; /* Enemy */
|
||||
List spawnEnemies; /* EnemyType */
|
||||
List collectibles; /* Collectible */
|
||||
List messages; /* Message */
|
||||
} Play;
|
||||
|
||||
typedef struct Title
|
||||
{
|
||||
struct Game* g;
|
||||
Cursor cursor;
|
||||
Sprite startBackgroundSprite;
|
||||
Sprite infoBackgroundSprite;
|
||||
Sprite backgroundSprite;
|
||||
Button startButton;
|
||||
Button infoButton;
|
||||
bool_u8 isInfoPressed;
|
||||
bool_u8 isStartPressed;
|
||||
Sprite logoSprite;
|
||||
} Title;
|
||||
|
||||
typedef struct Scene
|
||||
{
|
||||
char* text;
|
||||
TextureType textureType;
|
||||
} Scene;
|
||||
|
||||
typedef struct SceneHandler
|
||||
{
|
||||
struct Game* g;
|
||||
Scene* scenes;
|
||||
Sprite sprite;
|
||||
Sprite text;
|
||||
bool_u8 isTextEnd;
|
||||
bool_u8 isEnd;
|
||||
s32 updateTimer;
|
||||
s32 sceneCount;
|
||||
s32 sceneIndex;
|
||||
s32 textIndex;
|
||||
s32 textLength;
|
||||
} SceneHandler;
|
||||
|
||||
typedef struct Intro
|
||||
{
|
||||
Game* g;
|
||||
SceneHandler sceneHandler;
|
||||
} Intro;
|
||||
|
||||
typedef struct Info
|
||||
{
|
||||
struct Game* g;
|
||||
bool_u8 isBackPressed;
|
||||
Sprite licenseText;
|
||||
Sprite themeText;
|
||||
Sprite themeSprite;
|
||||
Sprite wildcardAdminSprite;
|
||||
Sprite wildcardAdminText;
|
||||
Sprite wildcardPatreonSprite;
|
||||
Sprite wildcardPatreonText;
|
||||
Sprite wildcardCommunitySprite;
|
||||
Sprite wildcardCommunityText;
|
||||
Sprite backBackgroundSprite;
|
||||
Button backButton;
|
||||
Cursor cursor;
|
||||
} Info;
|
||||
|
||||
typedef struct Ending
|
||||
{
|
||||
Game* g;
|
||||
SceneHandler sceneHandler;
|
||||
EndingType type;
|
||||
Button plusButton;
|
||||
Button endButton;
|
||||
bool_u8 isActualEnding;
|
||||
bool_u8 isNewGamePlus;
|
||||
bool_u8 isResults;
|
||||
Cursor cursor;
|
||||
} Ending;
|
||||
|
||||
typedef struct Results
|
||||
{
|
||||
struct Game* g;
|
||||
bool_u8 isEnd;
|
||||
Sprite highestWave;
|
||||
Sprite cashCollected;
|
||||
Sprite cashHeld;
|
||||
Sprite bountiesHunted;
|
||||
Sprite thanksText;
|
||||
Sprite resultsText;
|
||||
Sprite sprite;
|
||||
} Results;
|
||||
|
||||
typedef struct Game
|
||||
{
|
||||
Ending ending;
|
||||
Event event;
|
||||
Info info;
|
||||
Intro intro;
|
||||
Keyboard keyboard;
|
||||
Mix_Chunk* sounds[SOUND_COUNT];
|
||||
Mix_Music* music[MUSIC_COUNT];
|
||||
Mouse mouse;
|
||||
Play play;
|
||||
Results results;
|
||||
SDL_Renderer* renderer;
|
||||
SDL_Texture* textures[TEXTURE_COUNT];
|
||||
SDL_Window* window;
|
||||
StateType state;
|
||||
StateType stateNext;
|
||||
TTF_Font* fonts[FONT_COUNT];
|
||||
Tick tick;
|
||||
Title title;
|
||||
bool_u8 isStateTransition;
|
||||
bool_u8 isStateTransitioning;
|
||||
bool_u8 isNextStateWillBeInit;
|
||||
bool_u8 isPrevStateWillBeFreed;
|
||||
bool_u8 isNextStateResourcesWillBeInit;
|
||||
bool_u8 isPrevStateResourcesWillBeFreed;
|
||||
bool_u8 isFullScreen;
|
||||
s32 stateTimer;
|
||||
} Game;
|
71
src/game/GAME_STRINGS.h
Executable file
71
src/game/GAME_STRINGS.h
Executable file
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Game's strings, in English.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#define STRING_WINDOW_TITLE "Calamity Cobra in \"A Sweet Surprise\""
|
||||
|
||||
#define STRING_PLAY_WAVE "Wave "
|
||||
#define STRING_PLAY_WAVE_PLUS "+"
|
||||
|
||||
#define STRING_INTRO_SCENE_ONE "On an dry, summer evening in the hottest dunes of the West, a lone silhouette clashes against the gradient of the skyline."
|
||||
#define STRING_INTRO_SCENE_TWO "Calamity Cobra, rugged sharpshooter and bounty hunter extraordinaire, the fiestiest femme fatale in the region, is on the prowl for a new bounty. Clutching a wanted poster within her claws, her shielded eyes read the page...just one more time. Its message is vague; it says something about some troublesome pests that oddly resemble...baked goods?"
|
||||
#define STRING_INTRO_SCENE_THREE "Peering out into the distance, Calamity Cobra spies a lonesome wooden sign with nothing but the words \"Dessert Desert\". The place was covered in assorted sweet goods, and giant towers of pudding adorned the horizon. It was just where the poster said those sugary bastards would be!!"
|
||||
#define STRING_INTRO_SCENE_FOUR "Suddenly, without a moment's notice...herds of those high-calorie vermin burst out into the scene and surround Calamity Cobra!!"
|
||||
#define STRING_INTRO_SCENE_FIVE "With the quickest draw in all of the land, Calamity Cobra arms herself with her very own Snekgun (patent pending), and prepares to bring justice to all the waistlines those high-calorie miscreants have ruined and to remind those not-so-sweet sweets why her name is CALAMITY COBRA!!"
|
||||
|
||||
#define STRING_ENDING_FAIL "Calamity Cobra had misjudged how vicious the denizens of the Dessert Desert would be. Held captive by a thick, mountainous layer of flab, Calamity Cobra lays immobile in the midst of the cream-covered land, helplessly awaiting further feedings...(Try again!!)"
|
||||
#define STRING_ENDING_ONE "Having cleared out all the troublesome treats in her sight, Calamity Cobra departs from the cursed cream-covered lands, with a nice haul to boot. She just wishes that she wouldn't have to spend some of it on a new tailor... (Ending 1. Shoot for $50,000 on hand!!)"
|
||||
#define STRING_ENDING_TWO "After destroying an army's worth of those conniving confections, creamy viscera coated Calamity Cobra's shredded outfit. Absolutely exhausted from her relentless slaughter, Calamity Cobra begins the long trip back to town with her bundles of cash. It's not going to be easy, seeing how she's also got to carry the weight of her sized-up body... (Ending 2. Shoot for $100,000 on hand!)"
|
||||
#define STRING_ENDING_THREE "Did Cecillia do it for the money? Partly. For the fame, for the glory? Sure. But this was the bounty she'd been looking for her whole life, and it brought her something else that those two could hardly bring: immense pleasure. Having suffered the consequences of her vicious, unrelenting slaughter, Cecillia languished her new enormity with pride. Plucking the lollipop from her mouth, Cecilla decided the reward could wait...enjoying her new size was priority number one. (Best Ending. Congratulations!!!)"
|
||||
|
||||
#define STRING_PLAY_UPGRADE "UPGRADES - Use the dough you've earned and buy shweet upgrades for your Snekgun!!"
|
||||
#define STRING_PLAY_UPGRADE_SNAKES "SNAKES+ - You can now have more snakes on screen."
|
||||
#define STRING_PLAY_UPGRADE_LIFETIME "LIFETIME+ - Your snakes will last longer before tiring out."
|
||||
#define STRING_PLAY_UPGRADE_REDIRECT "REDIRECTS+ - You can now redirect your snakes an additional time, for more damage."
|
||||
|
||||
#define STRING_INFO_LICENSES "Thank you for playing Calamity Cobra in \"A Sweet Surprise\"! 2022 Weightgaming.com Gain Jam. Software by @ShweetMagnet licensed under GNU GPLv3. Art licensed under CC0, by @ShweetMagnet. Sound and music licensed under CC0, by @bugsinplanters. \"Jackwrite\" font licensed under OFL, by Jack Daw from dafont.com. \"Sheet of old paper\" graphic licensed under CC0, by Q-x from opengameart.org"
|
||||
|
||||
#define STRING_INFO_THEME "Theme: \"Greed\"\nThe game centers around a greedy miscreant bounty hunter on the hunt. Money can drop from enemies, and greed can be your downfall if you waltz into a hoard of them to collect some chump change or carelessly fire a snake to collect goodies. You can use said money to pay for shweet upgrades, and the endings certainly highlight Calamity Cobra's avarice."
|
||||
|
||||
#define STRING_INFO_WILDCARD_ADMIN "Wildcard (Admin): \"New Game+\"\nAfter beating the first batch of waves, you can start over the beginning, keeping your cash and upgrades. Be wary though, as enemies will be beefier, faster and spawn sooner!! Luckily, you get a cash multiplier and goodies are more common!!"
|
||||
|
||||
#define STRING_INFO_WILDCARD_PATREON "Wildcard (Patreon): \"Progress Through Failure\"\nIf you either screw up (or intentionally get hit), the wave will be instantly cleared, allowing you to proceed to the next one. However, you'll be punished with a fattening, meaning you move slower and become easier to hit!!"
|
||||
|
||||
#define STRING_INFO_WILDCARD_COMMUNITY "Wildcard (Community): \"Minions\"\nCalamity Cobra's patented Snekgun fires friendly serpent minions that can be redirected on her command. Use them to dispatch your foes, and collect goodies, just as good minions should!!"
|
||||
|
||||
#define STRING_INFO_BACK "Back"
|
||||
|
||||
#define STRING_PLAY_TUTORIAL_MOUSE "Hold RIGHT MOUSE to move. Press LEFT MOUSE to fire snakes, and press RIGHT MOUSE/R to redirect snakes, which deal more damage. Collect cash, hunt bounties, and watch your waistline!!"
|
||||
#define STRING_PLAY_TUTORIAL_KEYBOARD "Use arrow keys/WASD to move. Press LEFT MOUSE to fire snakes, and press RIGHT MOUSE/R to redirect snakes, which deal more damage. Collect cash, hunt bounties, and watch your waistline!!"
|
||||
|
||||
#define STRING_PLAY_PAUSE "PAUSE!!"
|
||||
#define STRING_PLAY_GUI_SNAKE_POWER_UP "INFINITE"
|
||||
#define STRING_PLAY_MESSAGE_WAVE_CLEAR "WAVE CLEARED!!"
|
||||
#define STRING_PLAY_MESSAGE_WAVE_FAIL "WAVE FAILED..."
|
||||
#define STRING_PLAY_MESSAGE_PURCHASE_NO_CASH "YOU'RE BROKE!!"
|
||||
#define STRING_PLAY_MESSAGE_PURCHASE_MAXED "MAXED!!"
|
||||
#define STRING_PLAY_MESSAGE_GAME_CLEAR "GAME CLEARED!!"
|
||||
#define STRING_PLAY_MESSAGE_POWER_UP "BERSERK!!"
|
||||
#define STRING_PLAY_MESSAGE_POWER_DOWN "BERSERK OVER..."
|
||||
#define STRING_PLAY_MESSAGE_MIRACLE_CURE "-1 FATNESS!!"
|
||||
#define STRING_PLAY_MESSAGE_DYNAMITE "KABOOM!!"
|
||||
#define STRING_PLAY_GUI_WAVE "WAVE "
|
||||
#define STRING_PLAY_GUI_READY "LET'S WRASSLE!!"
|
||||
#define STRING_PLAY_GUI_BOUNTY_NONE "..."
|
||||
#define STRING_PLAY_GUI_BOUNTY_DEAD "X-X"
|
||||
|
||||
#define STRING_ENDING_NEW_GAME_PLUS "New Game+"
|
||||
#define STRING_ENDING_RESULTS "Forfeit"
|
||||
|
||||
#define STRING_RESULTS "RESULTS"
|
||||
#define STRING_RESULTS_BOUNTIES_HUNTED "Bounties Hunted: "
|
||||
#define STRING_RESULTS_CASH_COLLECTED "Cash Collected: "
|
||||
#define STRING_RESULTS_CASH_HELD "Cash Held:"
|
||||
#define STRING_RESULTS_HIGHEST_WAVE "Highest Wave: "
|
||||
#define STRING_RESULTS_THANKS "Thanks for playing!! c:"
|
||||
|
||||
#define STRING_TITLE_START "Start!!"
|
||||
#define STRING_TITLE_INFO "Credits / Info"
|
164
src/game/ending/ending.c
Executable file
164
src/game/ending/ending.c
Executable file
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Fail ending code.
|
||||
*/
|
||||
|
||||
#include "ending.h"
|
||||
|
||||
/* Initializes ending. */
|
||||
void
|
||||
ending_init(Ending* _e, Game* _g, EndingType _t)
|
||||
{
|
||||
Sprite plusButtonSprite;
|
||||
Sprite endButtonSprite;
|
||||
|
||||
memset(_e, '\0', sizeof(Intro));
|
||||
|
||||
_e->g = _g;
|
||||
_e->type = _t;
|
||||
|
||||
switch (_e->type)
|
||||
{
|
||||
case ENDING_FAIL:
|
||||
scene_init
|
||||
(
|
||||
&_e->sceneHandler,
|
||||
_e->g,
|
||||
(Scene*)ENDING_FAIL_SCENES,
|
||||
ENDING_FAIL_SCENE_COUNT
|
||||
);
|
||||
break;
|
||||
case ENDING_ONE:
|
||||
scene_init
|
||||
(
|
||||
&_e->sceneHandler,
|
||||
_e->g,
|
||||
(Scene*)ENDING_ONE_SCENES,
|
||||
ENDING_ONE_SCENE_COUNT
|
||||
);
|
||||
_e->isActualEnding = TRUE;
|
||||
break;
|
||||
case ENDING_TWO:
|
||||
scene_init
|
||||
(
|
||||
&_e->sceneHandler,
|
||||
_e->g,
|
||||
(Scene*)ENDING_TWO_SCENES,
|
||||
ENDING_TWO_SCENE_COUNT
|
||||
);
|
||||
_e->isActualEnding = TRUE;
|
||||
break;
|
||||
case ENDING_THREE:
|
||||
scene_init
|
||||
(
|
||||
&_e->sceneHandler,
|
||||
_e->g,
|
||||
(Scene*)ENDING_THREE_SCENES,
|
||||
ENDING_THREE_SCENE_COUNT
|
||||
);
|
||||
_e->isActualEnding = TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
text_sprite_init
|
||||
(
|
||||
&plusButtonSprite,
|
||||
_e->g->renderer,
|
||||
_e->g->fonts[FONT_BIG],
|
||||
ENDING_TEXT_COLOR,
|
||||
ORIGIN_MIDDLE,
|
||||
STRING_ENDING_NEW_GAME_PLUS,
|
||||
0
|
||||
);
|
||||
|
||||
plusButtonSprite.x = ENDING_PLUS_BUTTON_OFFSET_X;
|
||||
plusButtonSprite.y = ENDING_PLUS_BUTTON_OFFSET_Y;
|
||||
|
||||
text_sprite_init
|
||||
(
|
||||
&endButtonSprite,
|
||||
_e->g->renderer,
|
||||
_e->g->fonts[FONT_BIG],
|
||||
ENDING_TEXT_COLOR,
|
||||
ORIGIN_MIDDLE,
|
||||
STRING_ENDING_RESULTS,
|
||||
0
|
||||
);
|
||||
|
||||
endButtonSprite.x = ENDING_END_BUTTON_OFFSET_X;
|
||||
endButtonSprite.y = ENDING_END_BUTTON_OFFSET_Y;
|
||||
|
||||
button_init(&_e->plusButton, &plusButtonSprite);
|
||||
button_init(&_e->endButton, &endButtonSprite);
|
||||
|
||||
cursor_init(&_e->cursor, &_e->g->mouse, _e->g->textures[TEXTURE_GUI_CURSOR]);
|
||||
|
||||
music_play(_e->g->music[MUSIC_WIND], TRUE);
|
||||
}
|
||||
|
||||
/* Frees ending. */
|
||||
void
|
||||
ending_free(Ending* _e)
|
||||
{
|
||||
if (_e->plusButton.sprite.atlas.texture)
|
||||
texture_free(_e->plusButton.sprite.atlas.texture);
|
||||
|
||||
if (_e->endButton.sprite.atlas.texture)
|
||||
texture_free(_e->endButton.sprite.atlas.texture);
|
||||
|
||||
scene_free(&_e->sceneHandler, _e->g);
|
||||
}
|
||||
|
||||
/* Updates ending. */
|
||||
void
|
||||
ending_update(Ending* _e)
|
||||
{
|
||||
scene_update(&_e->sceneHandler, _e->g);
|
||||
|
||||
cursor_update(&_e->cursor, &_e->g->mouse);
|
||||
|
||||
if (_e->sceneHandler.isEnd)
|
||||
{
|
||||
if (_e->isActualEnding)
|
||||
{
|
||||
button_update(&_e->plusButton, &_e->g->mouse);
|
||||
button_update(&_e->endButton, &_e->g->mouse);
|
||||
|
||||
if (_e->plusButton.state == BUTTON_STATE_PRESS)
|
||||
{
|
||||
_e->isNewGamePlus = TRUE;
|
||||
sound_play(_e->g->sounds[SOUND_MENU], -1);
|
||||
}
|
||||
else if (_e->endButton.state == BUTTON_STATE_PRESS)
|
||||
{
|
||||
_e->isResults = TRUE;
|
||||
sound_play(_e->g->sounds[SOUND_MENU], -1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mouse_press(&_e->g->mouse, MOUSE_LEFT))
|
||||
{
|
||||
_e->isResults = TRUE;
|
||||
sound_play(_e->g->sounds[SOUND_MENU], -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Draws ending. */
|
||||
void
|
||||
ending_draw(Ending* _e)
|
||||
{
|
||||
scene_draw(&_e->sceneHandler, _e->g);
|
||||
|
||||
cursor_draw(&_e->cursor, _e->g->renderer);
|
||||
|
||||
if (_e->isActualEnding && _e->sceneHandler.isEnd)
|
||||
{
|
||||
button_draw(&_e->plusButton, _e->g->renderer);
|
||||
button_draw(&_e->endButton, _e->g->renderer);
|
||||
}
|
||||
}
|
63
src/game/ending/ending.h
Executable file
63
src/game/ending/ending.h
Executable file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for ending_fail.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../gui/button.h"
|
||||
#include "../gui/cursor.h"
|
||||
#include "../scene/scene.h"
|
||||
#include "../GAME_STRINGS.h"
|
||||
|
||||
#define ENDING_FAIL_SCENE_COUNT 1
|
||||
#define ENDING_ONE_SCENE_COUNT 1
|
||||
#define ENDING_TWO_SCENE_COUNT 1
|
||||
#define ENDING_THREE_SCENE_COUNT 1
|
||||
|
||||
#define ENDING_PLUS_BUTTON_OFFSET_X 150
|
||||
#define ENDING_PLUS_BUTTON_OFFSET_Y 550
|
||||
#define ENDING_END_BUTTON_OFFSET_X 600
|
||||
#define ENDING_END_BUTTON_OFFSET_Y 550
|
||||
|
||||
#define ENDING_TWO_CASH_THRESHOLD 50000
|
||||
#define ENDING_THREE_CASH_THRESHOLD 100000
|
||||
|
||||
static const Scene ENDING_FAIL_SCENES[ENDING_FAIL_SCENE_COUNT] =
|
||||
{
|
||||
{
|
||||
.textureType = TEXTURE_ENDING_FAIL,
|
||||
.text = STRING_ENDING_FAIL
|
||||
}
|
||||
};
|
||||
|
||||
static const Scene ENDING_ONE_SCENES[ENDING_ONE_SCENE_COUNT] =
|
||||
{
|
||||
{
|
||||
.textureType = TEXTURE_ENDING_ONE,
|
||||
.text = STRING_ENDING_ONE
|
||||
}
|
||||
};
|
||||
|
||||
static const Scene ENDING_TWO_SCENES[ENDING_TWO_SCENE_COUNT] =
|
||||
{
|
||||
{
|
||||
.textureType = TEXTURE_ENDING_TWO,
|
||||
.text = STRING_ENDING_TWO
|
||||
}
|
||||
};
|
||||
|
||||
static const Scene ENDING_THREE_SCENES[ENDING_THREE_SCENE_COUNT] =
|
||||
{
|
||||
{
|
||||
.textureType = TEXTURE_ENDING_THREE,
|
||||
.text = STRING_ENDING_THREE
|
||||
}
|
||||
};
|
||||
|
||||
static const SDL_Color ENDING_TEXT_COLOR = {255, 255, 255, 255};
|
||||
|
||||
void ending_update(Ending* _e);
|
||||
void ending_init(Ending* _e, Game* _g, EndingType _t);
|
||||
void ending_draw(Ending* _e);
|
||||
void ending_free(Ending* _e);
|
100
src/game/game.c
Executable file
100
src/game/game.c
Executable file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Main game functions.
|
||||
*/
|
||||
|
||||
#include "game.h"
|
||||
|
||||
static void game_update(Game* _g);
|
||||
static void game_draw(Game* _g);
|
||||
|
||||
/* Updates the game. */
|
||||
static void
|
||||
game_update(Game* _g)
|
||||
{
|
||||
event_update(&_g->event);
|
||||
mouse_update(&_g->mouse);
|
||||
keyboard_update(&_g->keyboard);
|
||||
|
||||
game_state_update(_g);
|
||||
|
||||
/*
|
||||
if (keyboard_press(&_g->keyboard, KEYBOARD_F))
|
||||
{
|
||||
if (_g->isFullScreen)
|
||||
window_fullscreen_enter(_g->window);
|
||||
else
|
||||
window_fullscreen_exit(_g->window);
|
||||
|
||||
|
||||
_g->isFullScreen = !_g->isFullScreen;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/* Draws the game. */
|
||||
static void
|
||||
game_draw(Game* _g)
|
||||
{
|
||||
renderer_color_set(_g->renderer, RENDERER_COLOR);
|
||||
renderer_clear(_g->renderer);
|
||||
|
||||
game_state_draw(_g);
|
||||
|
||||
renderer_present(_g->renderer);
|
||||
}
|
||||
|
||||
/* Initializes game. */
|
||||
void
|
||||
game_init(Game* _g)
|
||||
{
|
||||
memset(_g, '\0', sizeof(Game));
|
||||
|
||||
window_init
|
||||
(
|
||||
&_g->window,
|
||||
WINDOW_TITLE,
|
||||
WINDOW_WIDTH,
|
||||
WINDOW_HEIGHT,
|
||||
WINDOW_FLAGS
|
||||
);
|
||||
|
||||
renderer_init
|
||||
(
|
||||
&_g->renderer,
|
||||
_g->window,
|
||||
RENDERER_FLAGS
|
||||
);
|
||||
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
|
||||
game_state_transition(_g, STATE_TITLE, TRUE, TRUE, TRUE, TRUE);
|
||||
|
||||
_g->stateTimer = STATE_TRANSITION_TIMER_MAX;
|
||||
}
|
||||
|
||||
/* Frees game resources. */
|
||||
void
|
||||
game_free(Game* _g)
|
||||
{
|
||||
game_state_free(_g);
|
||||
game_music_clear(_g);
|
||||
game_font_clear(_g);
|
||||
game_sound_clear(_g);
|
||||
game_texture_clear(_g);
|
||||
}
|
||||
|
||||
/* Main game loop. */
|
||||
void
|
||||
game_loop(Game* _g)
|
||||
{
|
||||
tick_update(&_g->tick);
|
||||
|
||||
while (_g->tick.cum > FRAME_DELAY)
|
||||
{
|
||||
game_update(_g);
|
||||
_g->tick.cum -= FRAME_DELAY;
|
||||
}
|
||||
|
||||
game_draw(_g);
|
||||
}
|
24
src/game/game.h
Executable file
24
src/game/game.h
Executable file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GAME_STRINGS.h"
|
||||
|
||||
#include "game_state.h"
|
||||
|
||||
#define WINDOW_WIDTH 800
|
||||
#define WINDOW_HEIGHT 600
|
||||
#define WINDOW_FLAGS 0
|
||||
#define WINDOW_TITLE STRING_WINDOW_TITLE
|
||||
#define RENDERER_FLAGS SDL_RENDERER_ACCELERATED
|
||||
#define FPS 60
|
||||
#define FRAME_DELAY (SECOND / FPS)
|
||||
|
||||
static const SDL_Color RENDERER_COLOR = {0, 0, 0, 255};
|
||||
|
||||
void game_free(Game* _g);
|
||||
void game_init(Game* _g);
|
||||
void game_loop(Game* _g);
|
102
src/game/game_ending.c
Executable file
102
src/game/game_ending.c
Executable file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* The "Title" state's meta functions.
|
||||
*/
|
||||
|
||||
#include "game_ending.h"
|
||||
|
||||
/* Initializes the Intro state's resources. */
|
||||
void
|
||||
game_ending_init(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < ENDING_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = ENDING_TEXTURES[i];
|
||||
|
||||
game_texture_init(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < ENDING_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = ENDING_SOUNDS[i];
|
||||
|
||||
game_sound_init(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < ENDING_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = ENDING_FONTS[i];
|
||||
|
||||
game_font_init(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < ENDING_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = ENDING_MUSIC[i];
|
||||
|
||||
game_music_init(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Frees the Intro state's resources. */
|
||||
void
|
||||
game_ending_free(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < ENDING_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = ENDING_TEXTURES[i];
|
||||
|
||||
game_texture_free(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < ENDING_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = ENDING_SOUNDS[i];
|
||||
|
||||
game_sound_free(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < ENDING_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = ENDING_FONTS[i];
|
||||
|
||||
game_font_free(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < ENDING_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = ENDING_MUSIC[i];
|
||||
|
||||
game_music_free(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates the Intro state. */
|
||||
void
|
||||
game_ending_update(Game* _g)
|
||||
{
|
||||
ending_update(&_g->ending);
|
||||
}
|
||||
|
||||
/* Draws the Intro state. */
|
||||
void
|
||||
game_ending_draw(Game* _g)
|
||||
{
|
||||
ending_draw(&_g->ending);
|
||||
}
|
49
src/game/game_ending.h
Executable file
49
src/game/game_ending.h
Executable file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_ending.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ending/ending.h"
|
||||
|
||||
#include "game_font.h"
|
||||
#include "game_music.h"
|
||||
#include "game_sound.h"
|
||||
#include "game_texture.h"
|
||||
|
||||
#define ENDING_TEXTURE_COUNT 5
|
||||
#define ENDING_SOUND_COUNT 2
|
||||
#define ENDING_MUSIC_COUNT 1
|
||||
#define ENDING_FONT_COUNT 2
|
||||
|
||||
static const TextureType ENDING_TEXTURES[ENDING_TEXTURE_COUNT] =
|
||||
{
|
||||
TEXTURE_ENDING_FAIL,
|
||||
TEXTURE_ENDING_ONE,
|
||||
TEXTURE_ENDING_TWO,
|
||||
TEXTURE_ENDING_THREE,
|
||||
TEXTURE_GUI_CURSOR
|
||||
};
|
||||
|
||||
static const SoundType ENDING_SOUNDS[ENDING_SOUND_COUNT] =
|
||||
{
|
||||
SOUND_BLIP,
|
||||
SOUND_MENU
|
||||
};
|
||||
|
||||
static const MusicType ENDING_MUSIC[ENDING_MUSIC_COUNT] =
|
||||
{
|
||||
MUSIC_WIND
|
||||
};
|
||||
|
||||
static const FontType ENDING_FONTS[ENDING_FONT_COUNT] =
|
||||
{
|
||||
FONT_SMALL,
|
||||
FONT_BIG
|
||||
};
|
||||
|
||||
void game_ending_draw(Game* _g);
|
||||
void game_ending_free(Game* _g);
|
||||
void game_ending_init(Game* _g);
|
||||
void game_ending_update(Game* _g);
|
37
src/game/game_font.c
Executable file
37
src/game/game_font.c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Loads/frees game fonts.
|
||||
*/
|
||||
|
||||
#include "game_font.h"
|
||||
|
||||
/* Loads a game font. */
|
||||
void
|
||||
game_font_init(Game* _g, FontType _f)
|
||||
{
|
||||
if (!_g->fonts[_f])
|
||||
font_init(&_g->fonts[_f], (char*)FONT_PATHS[_f], (s32)FONT_SIZES[_f]);
|
||||
}
|
||||
|
||||
/* Frees a game font. */
|
||||
void
|
||||
game_font_free(Game* _g, FontType _f)
|
||||
{
|
||||
if (_g->fonts[_f])
|
||||
{
|
||||
font_free(_g->fonts[_f]);
|
||||
_g->fonts[_f] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clears all fonts. */
|
||||
void
|
||||
game_font_clear(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < FONT_COUNT; i++)
|
||||
{
|
||||
if (_g->fonts[i])
|
||||
game_font_free(_g, (FontType)i);
|
||||
}
|
||||
}
|
||||
|
32
src/game/game_font.h
Executable file
32
src/game/game_font.h
Executable file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_font.h.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GAME_COMMON.h"
|
||||
|
||||
static const char* FONT_PATHS[FONT_COUNT] =
|
||||
{
|
||||
"",
|
||||
"res/font/fontJackwrite.ttf",
|
||||
"res/font/fontJackwrite.ttf",
|
||||
"res/font/fontJackwrite.ttf",
|
||||
"res/font/fontJackwrite.ttf",
|
||||
"res/font/fontJackwrite.ttf",
|
||||
};
|
||||
|
||||
static const s32 FONT_SIZES[FONT_COUNT] =
|
||||
{
|
||||
0,
|
||||
12,
|
||||
16,
|
||||
24,
|
||||
32,
|
||||
48
|
||||
};
|
||||
|
||||
void game_font_init(Game* _g, FontType _f);
|
||||
void game_font_free(Game* _g, FontType _f);
|
||||
void game_font_clear(Game* _g);
|
106
src/game/game_info.c
Executable file
106
src/game/game_info.c
Executable file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* The "Info" state's meta functions.
|
||||
*/
|
||||
|
||||
#include "game_info.h"
|
||||
|
||||
/* Initializes the Play state's resources. */
|
||||
void
|
||||
game_info_init(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < INFO_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INFO_TEXTURES[i];
|
||||
|
||||
game_texture_init(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INFO_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INFO_SOUNDS[i];
|
||||
|
||||
game_sound_init(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INFO_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INFO_FONTS[i];
|
||||
|
||||
game_font_init(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INFO_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INFO_MUSIC[i];
|
||||
|
||||
game_music_init(_g, (MusicType)index);
|
||||
}
|
||||
|
||||
info_init(&_g->info, _g);
|
||||
}
|
||||
|
||||
/* Frees the Play state's resources. */
|
||||
void
|
||||
game_info_free(Game* _g)
|
||||
{
|
||||
info_free(&_g->info);
|
||||
|
||||
for (s32 i = 0; i < INFO_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INFO_TEXTURES[i];
|
||||
|
||||
game_texture_free(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INFO_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INFO_SOUNDS[i];
|
||||
|
||||
game_sound_free(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INFO_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INFO_FONTS[i];
|
||||
|
||||
game_font_free(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INFO_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INFO_MUSIC[i];
|
||||
|
||||
game_music_free(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates the Play state. */
|
||||
void
|
||||
game_info_update(Game* _g)
|
||||
{
|
||||
info_update(&_g->info);
|
||||
}
|
||||
|
||||
/* Draws the Play state. */
|
||||
void
|
||||
game_info_draw(Game* _g)
|
||||
{
|
||||
info_draw(&_g->info);
|
||||
}
|
51
src/game/game_info.h
Executable file
51
src/game/game_info.h
Executable file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_info.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "info/info.h"
|
||||
|
||||
#include "game_font.h"
|
||||
#include "game_music.h"
|
||||
#include "game_sound.h"
|
||||
#include "game_texture.h"
|
||||
|
||||
#define INFO_TEXTURE_COUNT 6
|
||||
#define INFO_SOUND_COUNT 1
|
||||
#define INFO_MUSIC_COUNT 1
|
||||
#define INFO_FONT_COUNT 4
|
||||
|
||||
static const TextureType INFO_TEXTURES[INFO_TEXTURE_COUNT] =
|
||||
{
|
||||
TEXTURE_GUI_SIGN_SMALL,
|
||||
TEXTURE_GUI_CURSOR,
|
||||
TEXTURE_INFO_THEME,
|
||||
TEXTURE_INFO_WILDCARD_ADMIN,
|
||||
TEXTURE_INFO_WILDCARD_PATREON,
|
||||
TEXTURE_INFO_WILDCARD_COMMUNITY
|
||||
};
|
||||
|
||||
static const SoundType INFO_SOUNDS[INFO_SOUND_COUNT] =
|
||||
{
|
||||
SOUND_MENU
|
||||
};
|
||||
|
||||
static const MusicType INFO_MUSIC[INFO_MUSIC_COUNT] =
|
||||
{
|
||||
MUSIC_TITLE
|
||||
};
|
||||
|
||||
static const FontType INFO_FONTS[INFO_FONT_COUNT] =
|
||||
{
|
||||
FONT_TINY,
|
||||
FONT_SMALL,
|
||||
FONT_MEDIUM,
|
||||
FONT_BIG
|
||||
};
|
||||
|
||||
void game_info_draw(Game* _g);
|
||||
void game_info_free(Game* _g);
|
||||
void game_info_init(Game* _g);
|
||||
void game_info_update(Game* _g);
|
102
src/game/game_intro.c
Executable file
102
src/game/game_intro.c
Executable file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* The "Title" state's meta functions.
|
||||
*/
|
||||
|
||||
#include "game_intro.h"
|
||||
|
||||
/* Initializes the Intro state's resources. */
|
||||
void
|
||||
game_intro_init(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < INTRO_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INTRO_TEXTURES[i];
|
||||
|
||||
game_texture_init(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INTRO_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INTRO_SOUNDS[i];
|
||||
|
||||
game_sound_init(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INTRO_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INTRO_FONTS[i];
|
||||
|
||||
game_font_init(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INTRO_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INTRO_MUSIC[i];
|
||||
|
||||
game_music_init(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Frees the Intro state's resources. */
|
||||
void
|
||||
game_intro_free(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < INTRO_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INTRO_TEXTURES[i];
|
||||
|
||||
game_texture_free(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INTRO_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INTRO_SOUNDS[i];
|
||||
|
||||
game_sound_free(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INTRO_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INTRO_FONTS[i];
|
||||
|
||||
game_font_free(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < INTRO_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = INTRO_MUSIC[i];
|
||||
|
||||
game_music_free(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates the Intro state. */
|
||||
void
|
||||
game_intro_update(Game* _g)
|
||||
{
|
||||
intro_update(&_g->intro);
|
||||
}
|
||||
|
||||
/* Draws the Intro state. */
|
||||
void
|
||||
game_intro_draw(Game* _g)
|
||||
{
|
||||
intro_draw(&_g->intro);
|
||||
}
|
48
src/game/game_intro.h
Executable file
48
src/game/game_intro.h
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_intro.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "intro/intro.h"
|
||||
|
||||
#include "game_font.h"
|
||||
#include "game_music.h"
|
||||
#include "game_sound.h"
|
||||
#include "game_texture.h"
|
||||
|
||||
#define INTRO_TEXTURE_COUNT 5
|
||||
#define INTRO_SOUND_COUNT 2
|
||||
#define INTRO_MUSIC_COUNT 1
|
||||
#define INTRO_FONT_COUNT 1
|
||||
|
||||
static const TextureType INTRO_TEXTURES[INTRO_TEXTURE_COUNT] =
|
||||
{
|
||||
TEXTURE_INTRO_SCENE_ONE,
|
||||
TEXTURE_INTRO_SCENE_TWO,
|
||||
TEXTURE_INTRO_SCENE_THREE,
|
||||
TEXTURE_INTRO_SCENE_FOUR,
|
||||
TEXTURE_INTRO_SCENE_FIVE,
|
||||
};
|
||||
|
||||
static const SoundType INTRO_SOUNDS[INTRO_SOUND_COUNT] =
|
||||
{
|
||||
SOUND_BLIP,
|
||||
SOUND_MENU
|
||||
};
|
||||
|
||||
static const MusicType INTRO_MUSIC[INTRO_MUSIC_COUNT] =
|
||||
{
|
||||
MUSIC_INTRO
|
||||
};
|
||||
|
||||
static const FontType INTRO_FONTS[INTRO_FONT_COUNT] =
|
||||
{
|
||||
FONT_SMALL
|
||||
};
|
||||
|
||||
void game_intro_draw(Game* _g);
|
||||
void game_intro_free(Game* _g);
|
||||
void game_intro_init(Game* _g);
|
||||
void game_intro_update(Game* _g);
|
36
src/game/game_music.c
Executable file
36
src/game/game_music.c
Executable file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Loads/frees game music.
|
||||
*/
|
||||
|
||||
#include "game_music.h"
|
||||
|
||||
/* Loads a game music. */
|
||||
void
|
||||
game_music_init(Game* _g, MusicType _m)
|
||||
{
|
||||
if (!_g->music[_m])
|
||||
music_init(&_g->music[_m], (char*)MUSIC_PATHS[_m]);
|
||||
}
|
||||
|
||||
/* Frees a game music. */
|
||||
void
|
||||
game_music_free(Game* _g, MusicType _m)
|
||||
{
|
||||
if (_g->music[_m])
|
||||
{
|
||||
music_free(_g->music[_m]);
|
||||
_g->music[_m] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clears all music. */
|
||||
void
|
||||
game_music_clear(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < MUSIC_COUNT; i++)
|
||||
{
|
||||
if (_g->music[i])
|
||||
game_music_free(_g, (MusicType)i);
|
||||
}
|
||||
}
|
24
src/game/game_music.h
Executable file
24
src/game/game_music.h
Executable file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_music.h
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GAME_COMMON.h"
|
||||
|
||||
static const char* MUSIC_PATHS[MUSIC_COUNT] =
|
||||
{
|
||||
"",
|
||||
"res/audio/music/musWind.ogg",
|
||||
"res/audio/music/musPlay.ogg",
|
||||
"res/audio/music/musWaveClear.ogg",
|
||||
"res/audio/music/musWaveFail.ogg",
|
||||
"res/audio/music/musResults.ogg",
|
||||
"res/audio/music/musTitle.ogg",
|
||||
"res/audio/music/musIntro.ogg",
|
||||
};
|
||||
|
||||
void game_music_init(Game* _g, MusicType _m);
|
||||
void game_music_free(Game* _g, MusicType _m);
|
||||
void game_music_clear(Game* _g);
|
103
src/game/game_play.c
Executable file
103
src/game/game_play.c
Executable file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* The "Play" state's meta functions.
|
||||
*/
|
||||
|
||||
#include "game_play.h"
|
||||
|
||||
/* Initializes the Play state's resources. */
|
||||
void
|
||||
game_play_init(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < PLAY_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = PLAY_TEXTURES[i];
|
||||
|
||||
game_texture_init(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < PLAY_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = PLAY_SOUNDS[i];
|
||||
|
||||
game_sound_init(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < PLAY_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = PLAY_FONTS[i];
|
||||
|
||||
game_font_init(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < PLAY_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = PLAY_MUSIC[i];
|
||||
|
||||
game_music_init(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Frees the Play state's resources. */
|
||||
void
|
||||
game_play_free(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < PLAY_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = PLAY_TEXTURES[i];
|
||||
|
||||
game_texture_free(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < PLAY_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = PLAY_SOUNDS[i];
|
||||
|
||||
game_sound_free(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < PLAY_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = PLAY_FONTS[i];
|
||||
|
||||
game_font_free(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < PLAY_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = PLAY_MUSIC[i];
|
||||
|
||||
game_music_free(_g, (MusicType)index);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Updates the Play state. */
|
||||
void
|
||||
game_play_update(Game* _g)
|
||||
{
|
||||
play_update(&_g->play);
|
||||
}
|
||||
|
||||
/* Draws the Play state. */
|
||||
void
|
||||
game_play_draw(Game* _g)
|
||||
{
|
||||
play_draw(&_g->play);
|
||||
}
|
100
src/game/game_play.h
Executable file
100
src/game/game_play.h
Executable file
@ -0,0 +1,100 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_play.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "play/play.h"
|
||||
|
||||
#include "game_font.h"
|
||||
#include "game_music.h"
|
||||
#include "game_sound.h"
|
||||
#include "game_texture.h"
|
||||
|
||||
#define PLAY_TEXTURE_COUNT 29
|
||||
#define PLAY_SOUND_COUNT 23
|
||||
#define PLAY_MUSIC_COUNT 4
|
||||
#define PLAY_FONT_COUNT 5
|
||||
|
||||
static const TextureType PLAY_TEXTURES[PLAY_TEXTURE_COUNT] =
|
||||
{
|
||||
TEXTURE_GUI_CURSOR,
|
||||
TEXTURE_GUI_SNAKE,
|
||||
TEXTURE_GUI_REDIRECT,
|
||||
TEXTURE_GUI_CASH,
|
||||
TEXTURE_GUI_UPGRADE_SNAKE,
|
||||
TEXTURE_GUI_UPGRADE_LIFETIME,
|
||||
TEXTURE_GUI_UPGRADE_REDIRECT,
|
||||
TEXTURE_GUI_SIGN_SMALL,
|
||||
TEXTURE_GUI_SIGN_BIG,
|
||||
TEXTURE_SHADOW,
|
||||
TEXTURE_ARC,
|
||||
TEXTURE_PLAY_BG,
|
||||
TEXTURE_PLAYER_STAGE_ONE,
|
||||
TEXTURE_PLAYER_STAGE_TWO,
|
||||
TEXTURE_PLAYER_STAGE_THREE,
|
||||
TEXTURE_PLAYER_TAIL_STAGE_ONE,
|
||||
TEXTURE_PLAYER_TAIL_STAGE_TWO,
|
||||
TEXTURE_PLAYER_TAIL_STAGE_THREE,
|
||||
TEXTURE_PLAYER_SNAKE,
|
||||
TEXTURE_ENEMY_CUPPER,
|
||||
TEXTURE_ENEMY_CHIPPER,
|
||||
TEXTURE_ENEMY_CHIP,
|
||||
TEXTURE_ENEMY_CRUMBLER,
|
||||
TEXTURE_COLLECTIBLE_DOLLARS,
|
||||
TEXTURE_COLLECTIBLE_SACK,
|
||||
TEXTURE_COLLECTIBLE_BULLIONS,
|
||||
TEXTURE_COLLECTIBLE_MIRACLE_CURE,
|
||||
TEXTURE_COLLECTIBLE_DYNAMITE,
|
||||
TEXTURE_COLLECTIBLE_BERSERK
|
||||
};
|
||||
|
||||
static const SoundType PLAY_SOUNDS[PLAY_SOUND_COUNT] =
|
||||
{
|
||||
SOUND_MENU,
|
||||
SOUND_SNAKE_FIRE,
|
||||
SOUND_SNAKE_REDIRECT,
|
||||
SOUND_SNAKE_RETURN,
|
||||
SOUND_ENEMY_HURT,
|
||||
SOUND_CUPPER_KILL,
|
||||
SOUND_CHIPPER_KILL,
|
||||
SOUND_CRUMBLER_KILL,
|
||||
SOUND_CHIP_KILL,
|
||||
SOUND_RUMBLE,
|
||||
SOUND_COLLECTIBLE,
|
||||
SOUND_DOLLARS,
|
||||
SOUND_SACK,
|
||||
SOUND_BULLIONS,
|
||||
SOUND_PURCHASE,
|
||||
SOUND_MIRACLE_CURE,
|
||||
SOUND_DYNAMITE,
|
||||
SOUND_BERSERK,
|
||||
SOUND_SWALLOW,
|
||||
SOUND_GROWTH,
|
||||
SOUND_ERROR,
|
||||
SOUND_GO,
|
||||
SOUND_SPIT
|
||||
};
|
||||
|
||||
static const MusicType PLAY_MUSIC[PLAY_MUSIC_COUNT] =
|
||||
{
|
||||
MUSIC_WIND,
|
||||
MUSIC_PLAY,
|
||||
MUSIC_WAVE_CLEAR,
|
||||
MUSIC_WAVE_FAIL
|
||||
};
|
||||
|
||||
static const FontType PLAY_FONTS[PLAY_FONT_COUNT] =
|
||||
{
|
||||
FONT_TINY,
|
||||
FONT_SMALL,
|
||||
FONT_MEDIUM,
|
||||
FONT_BIG,
|
||||
FONT_MEGA
|
||||
};
|
||||
|
||||
void game_play_draw(Game* _g);
|
||||
void game_play_free(Game* _g);
|
||||
void game_play_init(Game* _g);
|
||||
void game_play_update(Game* _g);
|
102
src/game/game_results.c
Executable file
102
src/game/game_results.c
Executable file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* The "Title" state's meta functions.
|
||||
*/
|
||||
|
||||
#include "game_results.h"
|
||||
|
||||
/* Initializes the Intro state's resources. */
|
||||
void
|
||||
game_results_init(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < RESULTS_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = RESULTS_TEXTURES[i];
|
||||
|
||||
game_texture_init(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < RESULTS_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = RESULTS_SOUNDS[i];
|
||||
|
||||
game_sound_init(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < RESULTS_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = RESULTS_FONTS[i];
|
||||
|
||||
game_font_init(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < RESULTS_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = RESULTS_MUSIC[i];
|
||||
|
||||
game_music_init(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Frees the Intro state's resources. */
|
||||
void
|
||||
game_results_free(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < RESULTS_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = RESULTS_TEXTURES[i];
|
||||
|
||||
game_texture_free(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < RESULTS_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = RESULTS_SOUNDS[i];
|
||||
|
||||
game_sound_free(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < RESULTS_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = RESULTS_FONTS[i];
|
||||
|
||||
game_font_free(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < RESULTS_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = RESULTS_MUSIC[i];
|
||||
|
||||
game_music_free(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates the Intro state. */
|
||||
void
|
||||
game_results_update(Game* _g)
|
||||
{
|
||||
results_update(&_g->results);
|
||||
}
|
||||
|
||||
/* Draws the Intro state. */
|
||||
void
|
||||
game_results_draw(Game* _g)
|
||||
{
|
||||
results_draw(&_g->results);
|
||||
}
|
44
src/game/game_results.h
Executable file
44
src/game/game_results.h
Executable file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_results.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "results/results.h"
|
||||
|
||||
#include "game_font.h"
|
||||
#include "game_music.h"
|
||||
#include "game_sound.h"
|
||||
#include "game_texture.h"
|
||||
|
||||
#define RESULTS_TEXTURE_COUNT 1
|
||||
#define RESULTS_SOUND_COUNT 1
|
||||
#define RESULTS_MUSIC_COUNT 1
|
||||
#define RESULTS_FONT_COUNT 2
|
||||
|
||||
static const TextureType RESULTS_TEXTURES[RESULTS_TEXTURE_COUNT] =
|
||||
{
|
||||
TEXTURE_RESULTS
|
||||
};
|
||||
|
||||
static const SoundType RESULTS_SOUNDS[RESULTS_SOUND_COUNT] =
|
||||
{
|
||||
SOUND_MENU
|
||||
};
|
||||
|
||||
static const MusicType RESULTS_MUSIC[RESULTS_MUSIC_COUNT] =
|
||||
{
|
||||
MUSIC_RESULTS
|
||||
};
|
||||
|
||||
static const FontType RESULTS_FONTS[RESULTS_FONT_COUNT] =
|
||||
{
|
||||
FONT_BIG,
|
||||
FONT_MEGA
|
||||
};
|
||||
|
||||
void game_results_draw(Game* _g);
|
||||
void game_results_free(Game* _g);
|
||||
void game_results_init(Game* _g);
|
||||
void game_results_update(Game* _g);
|
37
src/game/game_sound.c
Executable file
37
src/game/game_sound.c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Loads/frees game sounds.
|
||||
*/
|
||||
|
||||
#include "game_sound.h"
|
||||
|
||||
/* Loads a game sound. */
|
||||
void
|
||||
game_sound_init(Game* _g, SoundType _s)
|
||||
{
|
||||
if (!_g->sounds[_s])
|
||||
sound_init(&_g->sounds[_s], (char*)SOUND_PATHS[_s]);
|
||||
}
|
||||
|
||||
/* Frees a game sound. */
|
||||
void
|
||||
game_sound_free(Game* _g, SoundType _s)
|
||||
{
|
||||
if (_g->sounds[_s])
|
||||
{
|
||||
sound_free(_g->sounds[_s]);
|
||||
_g->sounds[_s] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clears all sounds. */
|
||||
void
|
||||
game_sound_clear(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < SOUND_COUNT; i++)
|
||||
{
|
||||
if (_g->sounds[i])
|
||||
game_sound_free(_g, (SoundType)i);
|
||||
}
|
||||
}
|
||||
|
41
src/game/game_sound.h
Executable file
41
src/game/game_sound.h
Executable file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_sound.h
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GAME_COMMON.h"
|
||||
|
||||
static const char* SOUND_PATHS[SOUND_COUNT] =
|
||||
{
|
||||
"",
|
||||
"res/audio/sfx/sfxMenu.ogg",
|
||||
"res/audio/sfx/sfxBlip.ogg",
|
||||
"res/audio/sfx/sfxSnakeFire.ogg",
|
||||
"res/audio/sfx/sfxSnakeRedirect.ogg",
|
||||
"res/audio/sfx/sfxSnakeReturn.ogg",
|
||||
"res/audio/sfx/sfxEnemyHurt.ogg",
|
||||
"res/audio/sfx/sfxCupperKill.ogg",
|
||||
"res/audio/sfx/sfxChipperKill.ogg",
|
||||
"res/audio/sfx/sfxCrumblerKill.ogg",
|
||||
"res/audio/sfx/sfxChipKill.ogg",
|
||||
"res/audio/sfx/sfxRumble.ogg",
|
||||
"res/audio/sfx/sfxCollectible.ogg",
|
||||
"res/audio/sfx/sfxDollars.ogg",
|
||||
"res/audio/sfx/sfxSack.ogg",
|
||||
"res/audio/sfx/sfxBullions.ogg",
|
||||
"res/audio/sfx/sfxPurchase.ogg",
|
||||
"res/audio/sfx/sfxMiracleCure.ogg",
|
||||
"res/audio/sfx/sfxDynamite.ogg",
|
||||
"res/audio/sfx/sfxBerserk.ogg",
|
||||
"res/audio/sfx/sfxSwallow.ogg",
|
||||
"res/audio/sfx/sfxGrowth.ogg",
|
||||
"res/audio/sfx/sfxError.ogg",
|
||||
"res/audio/sfx/sfxGo.ogg",
|
||||
"res/audio/sfx/sfxSpit.ogg",
|
||||
};
|
||||
|
||||
void game_sound_init(Game* _g, SoundType _s);
|
||||
void game_sound_free(Game* _g, SoundType _s);
|
||||
void game_sound_clear(Game* _g);
|
381
src/game/game_state.c
Executable file
381
src/game/game_state.c
Executable file
@ -0,0 +1,381 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Game states.
|
||||
*/
|
||||
|
||||
#include "game_state.h"
|
||||
|
||||
static void game_state_transition_update(Game* _g);
|
||||
static void game_state_set(Game* _g, StateType _s);
|
||||
|
||||
/* Update state change transition. */
|
||||
static void
|
||||
game_state_transition_update(Game* _g)
|
||||
{
|
||||
if (_g->isStateTransitioning)
|
||||
{
|
||||
_g->stateTimer++;
|
||||
|
||||
if (_g->stateTimer >= STATE_TRANSITION_TIMER_MAX)
|
||||
{
|
||||
game_state_set(_g, _g->stateNext);
|
||||
_g->stateNext = STATE_NONE;
|
||||
_g->isStateTransitioning = FALSE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_g->stateTimer--;
|
||||
|
||||
if (_g->stateTimer <= 0)
|
||||
_g->isStateTransition = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Sets the game's state to a specified one. */
|
||||
static void
|
||||
game_state_set(Game* _g, StateType _s)
|
||||
{
|
||||
game_state_free(_g);
|
||||
|
||||
_g->state = _s;
|
||||
|
||||
if (_g->isNextStateResourcesWillBeInit)
|
||||
{
|
||||
switch (_g->state)
|
||||
{
|
||||
case STATE_TITLE:
|
||||
game_title_init(_g);
|
||||
break;
|
||||
case STATE_INTRO:
|
||||
game_intro_init(_g);
|
||||
break;
|
||||
case STATE_PLAY:
|
||||
game_play_init(_g);
|
||||
break;
|
||||
case STATE_INFO:
|
||||
game_info_init(_g);
|
||||
break;
|
||||
case STATE_ENDING_FAIL:
|
||||
case STATE_ENDING_ONE:
|
||||
case STATE_ENDING_TWO:
|
||||
case STATE_ENDING_THREE:
|
||||
game_ending_init(_g);
|
||||
break;
|
||||
case STATE_RESULTS:
|
||||
game_results_init(_g);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_g->isNextStateResourcesWillBeInit = FALSE;
|
||||
}
|
||||
|
||||
if (_g->isNextStateWillBeInit)
|
||||
{
|
||||
switch (_g->state)
|
||||
{
|
||||
case STATE_TITLE:
|
||||
title_init(&_g->title, _g);
|
||||
break;
|
||||
case STATE_INTRO:
|
||||
intro_init(&_g->intro, _g);
|
||||
break;
|
||||
case STATE_PLAY:
|
||||
play_init(&_g->play, _g);
|
||||
break;
|
||||
case STATE_INFO:
|
||||
info_init(&_g->info, _g);
|
||||
break;
|
||||
case STATE_ENDING_FAIL:
|
||||
ending_init(&_g->ending, _g, ENDING_FAIL);
|
||||
break;
|
||||
case STATE_ENDING_ONE:
|
||||
ending_init(&_g->ending, _g, ENDING_ONE);
|
||||
break;
|
||||
case STATE_ENDING_TWO:
|
||||
ending_init(&_g->ending, _g, ENDING_TWO);
|
||||
break;
|
||||
case STATE_ENDING_THREE:
|
||||
ending_init(&_g->ending, _g, ENDING_THREE);
|
||||
break;
|
||||
case STATE_RESULTS:
|
||||
results_init(&_g->results, _g);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_g->isNextStateWillBeInit = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Transition the a state type with a fade-in/fade-out. */
|
||||
void
|
||||
game_state_transition(Game* _g, StateType _s, bool_u8 _i, bool_u8 _f, bool_u8 _rI, bool_u8 _rF)
|
||||
{
|
||||
_g->stateTimer = 0;
|
||||
_g->stateNext = _s;
|
||||
_g->isNextStateWillBeInit = _i;
|
||||
_g->isPrevStateWillBeFreed = _f;
|
||||
_g->isNextStateResourcesWillBeInit = _rI;
|
||||
_g->isPrevStateResourcesWillBeFreed = _rF;
|
||||
_g->isStateTransitioning = TRUE;
|
||||
_g->isStateTransition = TRUE;
|
||||
}
|
||||
|
||||
/* Frees everything related to the game's current state. */
|
||||
void
|
||||
game_state_free(Game* _g)
|
||||
{
|
||||
if (_g->isPrevStateResourcesWillBeFreed)
|
||||
{
|
||||
switch (_g->state)
|
||||
{
|
||||
case STATE_TITLE:
|
||||
game_title_free(_g);
|
||||
break;
|
||||
case STATE_INTRO:
|
||||
game_intro_free(_g);
|
||||
break;
|
||||
case STATE_PLAY:
|
||||
game_play_free(_g);
|
||||
break;
|
||||
case STATE_INFO:
|
||||
game_info_free(_g);
|
||||
break;
|
||||
case STATE_ENDING_FAIL:
|
||||
case STATE_ENDING_ONE:
|
||||
case STATE_ENDING_TWO:
|
||||
case STATE_ENDING_THREE:
|
||||
game_ending_free(_g);
|
||||
break;
|
||||
case STATE_RESULTS:
|
||||
game_results_free(_g);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
_g->isPrevStateResourcesWillBeFreed = FALSE;
|
||||
}
|
||||
|
||||
if (_g->isPrevStateWillBeFreed)
|
||||
{
|
||||
switch (_g->state)
|
||||
{
|
||||
case STATE_TITLE:
|
||||
title_free(&_g->title);
|
||||
break;
|
||||
case STATE_INTRO:
|
||||
intro_free(&_g->intro);
|
||||
break;
|
||||
case STATE_PLAY:
|
||||
play_free(&_g->play);
|
||||
break;
|
||||
case STATE_INFO:
|
||||
info_free(&_g->info);
|
||||
break;
|
||||
case STATE_ENDING_FAIL:
|
||||
case STATE_ENDING_ONE:
|
||||
case STATE_ENDING_TWO:
|
||||
case STATE_ENDING_THREE:
|
||||
ending_free(&_g->ending);
|
||||
break;
|
||||
case STATE_RESULTS:
|
||||
results_free(&_g->results);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
_g->isPrevStateWillBeFreed = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates the game's state. */
|
||||
void
|
||||
game_state_update(Game* _g)
|
||||
{
|
||||
if (_g->isStateTransition)
|
||||
game_state_transition_update(_g);
|
||||
|
||||
switch (_g->state)
|
||||
{
|
||||
case STATE_TITLE:
|
||||
game_title_update(_g);
|
||||
|
||||
if
|
||||
(
|
||||
_g->title.isStartPressed &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
{
|
||||
_g->title.isStartPressed = FALSE;
|
||||
game_state_transition(_g, STATE_INTRO, TRUE, TRUE, TRUE, TRUE);
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
_g->title.isInfoPressed &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
{
|
||||
_g->title.isInfoPressed = FALSE;
|
||||
game_state_transition(_g, STATE_INFO, TRUE, TRUE, TRUE, TRUE);
|
||||
}
|
||||
break;
|
||||
case STATE_INTRO:
|
||||
game_intro_update(_g);
|
||||
|
||||
if
|
||||
(
|
||||
_g->intro.sceneHandler.isEnd &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
game_state_transition(_g, STATE_PLAY, TRUE, TRUE, TRUE, TRUE);
|
||||
break;
|
||||
case STATE_PLAY:
|
||||
game_play_update(_g);
|
||||
|
||||
|
||||
if
|
||||
(
|
||||
keyboard_press(&_g->keyboard, KEYBOARD_ESCAPE) &&
|
||||
_g->play.isPaused &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
game_state_transition(_g, STATE_TITLE, TRUE, TRUE, TRUE, TRUE);
|
||||
else if
|
||||
(
|
||||
_g->play.player.isDefeat &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
game_state_transition(_g, STATE_ENDING_FAIL, TRUE, TRUE, TRUE, TRUE);
|
||||
else if
|
||||
(
|
||||
_g->play.isGameCleared &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
{
|
||||
if (_g->play.player.cash >= ENDING_THREE_CASH_THRESHOLD)
|
||||
game_state_transition(_g, STATE_ENDING_THREE, TRUE, FALSE, TRUE, FALSE);
|
||||
else if (_g->play.player.cash >= ENDING_TWO_CASH_THRESHOLD)
|
||||
game_state_transition(_g, STATE_ENDING_TWO, TRUE, FALSE, TRUE, FALSE);
|
||||
else
|
||||
game_state_transition(_g, STATE_ENDING_ONE, TRUE, FALSE, TRUE, FALSE);
|
||||
}
|
||||
break;
|
||||
case STATE_INFO:
|
||||
game_info_update(_g);
|
||||
|
||||
if
|
||||
(
|
||||
_g->info.isBackPressed &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
{
|
||||
_g->info.isBackPressed = FALSE;
|
||||
game_state_transition(_g, STATE_TITLE, TRUE, TRUE, TRUE, TRUE);
|
||||
}
|
||||
break;
|
||||
case STATE_ENDING_FAIL:
|
||||
game_ending_update(_g);
|
||||
|
||||
if
|
||||
(
|
||||
_g->ending.sceneHandler.isEnd &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
game_state_transition(_g, STATE_RESULTS, TRUE, TRUE, TRUE, TRUE);
|
||||
break;
|
||||
case STATE_ENDING_ONE:
|
||||
case STATE_ENDING_TWO:
|
||||
case STATE_ENDING_THREE:
|
||||
game_ending_update(_g);
|
||||
|
||||
if (!_g->isStateTransition)
|
||||
{
|
||||
if (_g->ending.isNewGamePlus)
|
||||
{
|
||||
game_state_transition(_g, STATE_PLAY, FALSE, TRUE, FALSE, FALSE);
|
||||
wave_new_game_plus(&_g->play);
|
||||
_g->ending.isNewGamePlus = FALSE;
|
||||
_g->ending.isActualEnding = FALSE;
|
||||
}
|
||||
else if (_g->ending.isResults)
|
||||
{
|
||||
game_state_transition(_g, STATE_RESULTS, TRUE, TRUE, TRUE, TRUE);
|
||||
_g->ending.isResults = FALSE;
|
||||
_g->ending.isActualEnding = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case STATE_RESULTS:
|
||||
game_results_update(_g);
|
||||
|
||||
if
|
||||
(
|
||||
_g->results.isEnd &&
|
||||
!_g->isStateTransition
|
||||
)
|
||||
game_state_transition(_g, STATE_TITLE, TRUE, TRUE, TRUE, TRUE);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draws the game's state. */
|
||||
void
|
||||
game_state_draw(Game* _g)
|
||||
{
|
||||
switch (_g->state)
|
||||
{
|
||||
case STATE_TITLE:
|
||||
game_title_draw(_g);
|
||||
break;
|
||||
case STATE_INTRO:
|
||||
game_intro_draw(_g);
|
||||
break;
|
||||
case STATE_PLAY:
|
||||
game_play_draw(_g);
|
||||
break;
|
||||
case STATE_INFO:
|
||||
game_info_draw(_g);
|
||||
break;
|
||||
case STATE_ENDING_FAIL:
|
||||
case STATE_ENDING_ONE:
|
||||
case STATE_ENDING_TWO:
|
||||
case STATE_ENDING_THREE:
|
||||
game_ending_draw(_g);
|
||||
break;
|
||||
case STATE_RESULTS:
|
||||
game_results_draw(_g);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (_g->isStateTransition)
|
||||
{
|
||||
f64 progress;
|
||||
SDL_Rect rect;
|
||||
SDL_Color color;
|
||||
|
||||
progress = (f64)_g->stateTimer / STATE_TRANSITION_TIMER_MAX;
|
||||
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.w = STATE_TRANSITION_RECTANGLE_WIDTH;
|
||||
rect.h = STATE_TRANSITION_RECTANGLE_HEIGHT;
|
||||
|
||||
color = STATE_TRANSITION_COLOR;
|
||||
color.a = SDL_ALPHA_OPAQUE * progress;
|
||||
|
||||
rectangle_draw(&rect, _g->renderer, color);
|
||||
}
|
||||
}
|
24
src/game/game_state.h
Executable file
24
src/game/game_state.h
Executable file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_state.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "game_ending.h"
|
||||
#include "game_info.h"
|
||||
#include "game_play.h"
|
||||
#include "game_intro.h"
|
||||
#include "game_title.h"
|
||||
#include "game_results.h"
|
||||
|
||||
#define STATE_TRANSITION_TIMER_MAX 30
|
||||
#define STATE_TRANSITION_RECTANGLE_WIDTH 800
|
||||
#define STATE_TRANSITION_RECTANGLE_HEIGHT 600
|
||||
|
||||
static const SDL_Color STATE_TRANSITION_COLOR = {0, 0, 0, 255};
|
||||
|
||||
void game_state_free(Game* _g);
|
||||
void game_state_update(Game* _g);
|
||||
void game_state_draw(Game* _g);
|
||||
void game_state_transition(Game* _g, StateType _s, bool_u8 _i, bool_u8 _f, bool_u8 _rI, bool_u8 _rF);
|
37
src/game/game_texture.c
Executable file
37
src/game/game_texture.c
Executable file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Loads/frees game textures.
|
||||
*/
|
||||
|
||||
#include "game_texture.h"
|
||||
|
||||
/* Loads a game texture. */
|
||||
void
|
||||
game_texture_init(Game* _g, TextureType _t)
|
||||
{
|
||||
if (!_g->textures[_t])
|
||||
texture_init(&_g->textures[_t], _g->renderer, (char*)TEXTURE_PATHS[_t]);
|
||||
}
|
||||
|
||||
/* Frees a game texture. */
|
||||
void
|
||||
game_texture_free(Game* _g, TextureType _t)
|
||||
{
|
||||
if (_g->textures[_t])
|
||||
{
|
||||
texture_free(_g->textures[_t]);
|
||||
_g->textures[_t] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Clears all textures. */
|
||||
void
|
||||
game_texture_clear(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < TEXTURE_COUNT; i++)
|
||||
{
|
||||
if (_g->textures[i])
|
||||
game_texture_free(_g, (TextureType)i);
|
||||
}
|
||||
}
|
||||
|
62
src/game/game_texture.h
Executable file
62
src/game/game_texture.h
Executable file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_texture.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GAME_COMMON.h"
|
||||
|
||||
static const char* TEXTURE_PATHS[TEXTURE_COUNT] =
|
||||
{
|
||||
"",
|
||||
"res/gfx/title/gfxLogo.png",
|
||||
"res/gfx/gui/gfxGuiCursor.png",
|
||||
"res/gfx/play/gui/gfxGuiSnake.png",
|
||||
"res/gfx/play/gui/gfxGuiRedirect.png",
|
||||
"res/gfx/play/gui/gfxGuiCash.png",
|
||||
"res/gfx/play/gui/gfxGuiUpgradeSnake.png",
|
||||
"res/gfx/play/gui/gfxGuiUpgradeLifetime.png",
|
||||
"res/gfx/play/gui/gfxGuiUpgradeRedirect.png",
|
||||
"res/gfx/gui/gfxGuiSignSmall.png",
|
||||
"res/gfx/gui/gfxGuiSignBig.png",
|
||||
"res/gfx/play/gfxShadow.png",
|
||||
"res/gfx/play/player/gfxArc.png",
|
||||
"res/gfx/play/bg/gfxPlayBG.png",
|
||||
"res/gfx/play/player/gfxPlayerStageOne.png",
|
||||
"res/gfx/play/player/gfxPlayerStageTwo.png",
|
||||
"res/gfx/play/player/gfxPlayerStageThree.png",
|
||||
"res/gfx/play/player/gfxPlayerTailStageOne.png",
|
||||
"res/gfx/play/player/gfxPlayerTailStageTwo.png",
|
||||
"res/gfx/play/player/gfxPlayerTailStageThree.png",
|
||||
"res/gfx/play/player/gfxPlayerSnake.png",
|
||||
"res/gfx/play/enemy/gfxEnemyCupper.png",
|
||||
"res/gfx/play/enemy/gfxEnemyChipper.png",
|
||||
"res/gfx/play/enemy/gfxEnemyChip.png",
|
||||
"res/gfx/play/enemy/gfxEnemyCrumbler.png",
|
||||
"res/gfx/play/collectible/gfxCollectibleDollars.png",
|
||||
"res/gfx/play/collectible/gfxCollectibleSack.png",
|
||||
"res/gfx/play/collectible/gfxCollectibleBullions.png",
|
||||
"res/gfx/play/collectible/gfxCollectibleMiracleCure.png",
|
||||
"res/gfx/play/collectible/gfxCollectibleDynamite.png",
|
||||
"res/gfx/play/collectible/gfxCollectibleBerserk.png",
|
||||
"res/gfx/info/gfxTheme.png",
|
||||
"res/gfx/info/gfxWildcardAdmin.png",
|
||||
"res/gfx/info/gfxWildcardPatreon.png",
|
||||
"res/gfx/info/gfxWildcardCommunity.png",
|
||||
"res/gfx/intro/gfxIntroSceneOne.png",
|
||||
"res/gfx/intro/gfxIntroSceneTwo.png",
|
||||
"res/gfx/intro/gfxIntroSceneThree.png",
|
||||
"res/gfx/intro/gfxIntroSceneFour.png",
|
||||
"res/gfx/intro/gfxIntroSceneFive.png",
|
||||
"res/gfx/ending/gfxEndingFail.png",
|
||||
"res/gfx/ending/gfxEndingOne.png",
|
||||
"res/gfx/ending/gfxEndingTwo.png",
|
||||
"res/gfx/ending/gfxEndingThree.png",
|
||||
"res/gfx/title/gfxTitleBG.png",
|
||||
"res/gfx/results/gfxResults.png",
|
||||
};
|
||||
|
||||
void game_texture_init(Game* _g, TextureType _t);
|
||||
void game_texture_free(Game* _g, TextureType _t);
|
||||
void game_texture_clear(Game* _g);
|
102
src/game/game_title.c
Executable file
102
src/game/game_title.c
Executable file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* The "Title" state's meta functions.
|
||||
*/
|
||||
|
||||
#include "game_title.h"
|
||||
|
||||
/* Initializes the Play state's resources. */
|
||||
void
|
||||
game_title_init(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < TITLE_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = TITLE_TEXTURES[i];
|
||||
|
||||
game_texture_init(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < TITLE_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = TITLE_SOUNDS[i];
|
||||
|
||||
game_sound_init(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < TITLE_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = TITLE_FONTS[i];
|
||||
|
||||
game_font_init(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < TITLE_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = TITLE_MUSIC[i];
|
||||
|
||||
game_music_init(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Frees the Play state's resources. */
|
||||
void
|
||||
game_title_free(Game* _g)
|
||||
{
|
||||
for (s32 i = 0; i < TITLE_TEXTURE_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = TITLE_TEXTURES[i];
|
||||
|
||||
game_texture_free(_g, (TextureType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < TITLE_SOUND_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = TITLE_SOUNDS[i];
|
||||
|
||||
game_sound_free(_g, (SoundType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < TITLE_FONT_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = TITLE_FONTS[i];
|
||||
|
||||
game_font_free(_g, (FontType)index);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < TITLE_MUSIC_COUNT; i++)
|
||||
{
|
||||
s32 index;
|
||||
|
||||
index = TITLE_MUSIC[i];
|
||||
|
||||
game_music_free(_g, (MusicType)index);
|
||||
}
|
||||
}
|
||||
|
||||
/* Updates the Play state. */
|
||||
void
|
||||
game_title_update(Game* _g)
|
||||
{
|
||||
title_update(&_g->title);
|
||||
}
|
||||
|
||||
/* Draws the Play state. */
|
||||
void
|
||||
game_title_draw(Game* _g)
|
||||
{
|
||||
title_draw(&_g->title);
|
||||
}
|
48
src/game/game_title.h
Executable file
48
src/game/game_title.h
Executable file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for game_title.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "title/title.h"
|
||||
|
||||
#include "game_font.h"
|
||||
#include "game_music.h"
|
||||
#include "game_sound.h"
|
||||
#include "game_texture.h"
|
||||
|
||||
#define TITLE_TEXTURE_COUNT 5
|
||||
#define TITLE_SOUND_COUNT 1
|
||||
#define TITLE_MUSIC_COUNT 1
|
||||
#define TITLE_FONT_COUNT 2
|
||||
|
||||
static const TextureType TITLE_TEXTURES[TITLE_TEXTURE_COUNT] =
|
||||
{
|
||||
TEXTURE_LOGO,
|
||||
TEXTURE_GUI_SIGN_SMALL,
|
||||
TEXTURE_GUI_SIGN_BIG,
|
||||
TEXTURE_GUI_CURSOR,
|
||||
TEXTURE_TITLE_BACKGROUND
|
||||
};
|
||||
|
||||
static const SoundType TITLE_SOUNDS[TITLE_SOUND_COUNT] =
|
||||
{
|
||||
SOUND_MENU
|
||||
};
|
||||
|
||||
static const MusicType TITLE_MUSIC[TITLE_MUSIC_COUNT] =
|
||||
{
|
||||
MUSIC_TITLE
|
||||
};
|
||||
|
||||
static const FontType TITLE_FONTS[TITLE_FONT_COUNT] =
|
||||
{
|
||||
FONT_MEDIUM,
|
||||
FONT_BIG
|
||||
};
|
||||
|
||||
void game_title_draw(Game* _g);
|
||||
void game_title_free(Game* _g);
|
||||
void game_title_init(Game* _g);
|
||||
void game_title_update(Game* _g);
|
67
src/game/gui/button.c
Executable file
67
src/game/gui/button.c
Executable file
@ -0,0 +1,67 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Basic GUI button.
|
||||
*/
|
||||
|
||||
#include "button.h"
|
||||
|
||||
/* Initializes a button. */
|
||||
void
|
||||
button_init(Button* _b, Sprite* _s)
|
||||
{
|
||||
memset(_b, '\0', sizeof(Button));
|
||||
|
||||
_b->sprite = *_s;
|
||||
}
|
||||
|
||||
/* Updates a button. */
|
||||
void
|
||||
button_update(Button* _b, Mouse* _m)
|
||||
{
|
||||
SDL_Rect rect;
|
||||
|
||||
rect = sprite_rect_get(&_b->sprite);
|
||||
|
||||
_b->state = BUTTON_STATE_NONE;
|
||||
|
||||
if (rectangle_point_collide(&rect, _m->x, _m->y))
|
||||
{
|
||||
if (_b->state == BUTTON_STATE_HOVER)
|
||||
_b->state = BUTTON_STATE_HOVERING;
|
||||
else
|
||||
_b->state = BUTTON_STATE_HOVER;
|
||||
|
||||
if (mouse_held(_m, MOUSE_LEFT))
|
||||
_b->state = BUTTON_STATE_HELD;
|
||||
else if (mouse_press(_m, MOUSE_LEFT))
|
||||
_b->state = BUTTON_STATE_PRESS;
|
||||
|
||||
}
|
||||
else
|
||||
_b->state = BUTTON_STATE_NONE;
|
||||
|
||||
switch (_b->state)
|
||||
{
|
||||
case BUTTON_STATE_PRESS:
|
||||
_b->sprite.color = BUTTON_PRESS_COLOR;
|
||||
break;
|
||||
case BUTTON_STATE_HELD:
|
||||
_b->sprite.color = BUTTON_HELD_COLOR;
|
||||
break;
|
||||
case BUTTON_STATE_HOVER:
|
||||
case BUTTON_STATE_HOVERING:
|
||||
_b->sprite.color = BUTTON_HOVER_COLOR;
|
||||
break;
|
||||
case BUTTON_STATE_NONE:
|
||||
default:
|
||||
_b->sprite.color = BUTTON_NONE_COLOR;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Draws a button. */
|
||||
void
|
||||
button_draw(Button* _b, SDL_Renderer* _r)
|
||||
{
|
||||
sprite_draw(&_b->sprite, _r);
|
||||
}
|
17
src/game/gui/button.h
Executable file
17
src/game/gui/button.h
Executable file
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for button.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../GAME_COMMON.h"
|
||||
|
||||
static const SDL_Color BUTTON_NONE_COLOR = {255, 255, 255, 255};
|
||||
static const SDL_Color BUTTON_HOVER_COLOR = {192, 192, 192, 255};
|
||||
static const SDL_Color BUTTON_PRESS_COLOR = {128, 128, 128, 255};
|
||||
static const SDL_Color BUTTON_HELD_COLOR = {64, 64, 6, 255};
|
||||
|
||||
void button_init(Button* _b, Sprite* _s);
|
||||
void button_update(Button* _b, Mouse* _m);
|
||||
void button_draw(Button* _b, SDL_Renderer* _r);
|
73
src/game/gui/cursor.c
Executable file
73
src/game/gui/cursor.c
Executable file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Gameplay's cursor.
|
||||
*/
|
||||
|
||||
#include "cursor.h"
|
||||
|
||||
/* Initializes the cursor. */
|
||||
void
|
||||
cursor_init(Cursor* _c, Mouse* _m, SDL_Texture* _t)
|
||||
{
|
||||
Atlas atlas;
|
||||
|
||||
atlas_init
|
||||
(
|
||||
&atlas,
|
||||
_t,
|
||||
CURSOR_ROWS,
|
||||
CURSOR_COLUMNS,
|
||||
CURSOR_FRAME_WIDTH,
|
||||
CURSOR_FRAME_HEIGHT
|
||||
);
|
||||
|
||||
sprite_atlas_init
|
||||
(
|
||||
&_c->sprite,
|
||||
&atlas,
|
||||
ORIGIN_MIDDLE,
|
||||
CURSOR_WIDTH,
|
||||
CURSOR_HEIGHT
|
||||
);
|
||||
|
||||
_c->sprite.frame = 0;
|
||||
_c->sprite.x = _m->x;
|
||||
_c->sprite.y = _m->y;
|
||||
|
||||
_c->sprite.color.a = CURSOR_ALPHA;
|
||||
}
|
||||
|
||||
/* Frees cursor resources. */
|
||||
void
|
||||
cursor_free(Cursor* _c)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* Updates the cursor. */
|
||||
void
|
||||
cursor_update(Cursor* _c, Mouse* _m)
|
||||
{
|
||||
if (mouse_held(_m, MOUSE_LEFT))
|
||||
_c->sprite.frame = 1;
|
||||
else if (mouse_held(_m, MOUSE_RIGHT))
|
||||
_c->sprite.frame = 2;
|
||||
else
|
||||
_c->sprite.frame = 0;
|
||||
|
||||
_c->sprite.x = _m->x;
|
||||
_c->sprite.y = _m->y;
|
||||
|
||||
_c->sprite.x = _c->sprite.x < CURSOR_X_MIN ? CURSOR_X_MIN : _c->sprite.x;
|
||||
_c->sprite.x = _c->sprite.x > CURSOR_X_MAX ? CURSOR_X_MAX : _c->sprite.x;
|
||||
_c->sprite.y = _c->sprite.y < CURSOR_Y_MIN ? CURSOR_Y_MIN : _c->sprite.y;
|
||||
_c->sprite.y = _c->sprite.y > CURSOR_Y_MAX ? CURSOR_Y_MAX : _c->sprite.y;
|
||||
}
|
||||
|
||||
/* Draws the cursor. */
|
||||
void
|
||||
cursor_draw(Cursor* _c, SDL_Renderer* _r)
|
||||
{
|
||||
sprite_draw(&_c->sprite, _r);
|
||||
|
||||
}
|
25
src/game/gui/cursor.h
Executable file
25
src/game/gui/cursor.h
Executable file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for cursor.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../GAME_COMMON.h"
|
||||
|
||||
#define CURSOR_WIDTH 32
|
||||
#define CURSOR_HEIGHT 32
|
||||
#define CURSOR_FRAME_WIDTH 32
|
||||
#define CURSOR_FRAME_HEIGHT 32
|
||||
#define CURSOR_ROWS 1
|
||||
#define CURSOR_COLUMNS 3
|
||||
#define CURSOR_ALPHA 128
|
||||
#define CURSOR_X_MAX 800
|
||||
#define CURSOR_X_MIN 0
|
||||
#define CURSOR_Y_MAX 600
|
||||
#define CURSOR_Y_MIN 0
|
||||
|
||||
void cursor_draw(Cursor* _c, SDL_Renderer* _r);
|
||||
void cursor_free(Cursor* _c);
|
||||
void cursor_init(Cursor* _c, Mouse* _m, SDL_Texture* _t);
|
||||
void cursor_update(Cursor* _c, Mouse* _m);
|
239
src/game/info/info.c
Executable file
239
src/game/info/info.c
Executable file
@ -0,0 +1,239 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Displays game info (credits/licenses).
|
||||
*/
|
||||
|
||||
#include "info.h"
|
||||
|
||||
/* Initialize info. */
|
||||
void
|
||||
info_init(Info* _i, Game* _g)
|
||||
{
|
||||
Sprite buttonSprite;
|
||||
|
||||
memset(_i, '\0', sizeof(Info));
|
||||
|
||||
_i->g = _g;
|
||||
|
||||
cursor_init(&_i->cursor, &_i->g->mouse, _i->g->textures[TEXTURE_GUI_CURSOR]);
|
||||
|
||||
text_sprite_init
|
||||
(
|
||||
&_i->licenseText,
|
||||
_i->g->renderer,
|
||||
_i->g->fonts[FONT_SMALL],
|
||||
INFO_TEXT_COLOR,
|
||||
ORIGIN_MIDDLE,
|
||||
STRING_INFO_LICENSES,
|
||||
INFO_LICENSE_TEXT_WRAP
|
||||
);
|
||||
|
||||
_i->licenseText.x = INFO_LICENSE_TEXT_OFFSET_X;
|
||||
_i->licenseText.y = INFO_LICENSE_TEXT_OFFSET_Y;
|
||||
|
||||
sprite_init
|
||||
(
|
||||
&_i->themeSprite,
|
||||
_i->g->textures[TEXTURE_INFO_THEME],
|
||||
ORIGIN_MIDDLE,
|
||||
INFO_THEME_WIDTH,
|
||||
INFO_THEME_HEIGHT
|
||||
);
|
||||
|
||||
_i->themeSprite.x = INFO_THEME_OFFSET_X;
|
||||
_i->themeSprite.y = INFO_THEME_OFFSET_Y;
|
||||
|
||||
sprite_init
|
||||
(
|
||||
&_i->wildcardAdminSprite,
|
||||
_i->g->textures[TEXTURE_INFO_WILDCARD_ADMIN],
|
||||
ORIGIN_MIDDLE,
|
||||
INFO_WILDCARD_WIDTH,
|
||||
INFO_WILDCARD_HEIGHT
|
||||
);
|
||||
|
||||
_i->wildcardAdminSprite.x = INFO_WILDCARD_ADMIN_OFFSET_X;
|
||||
_i->wildcardAdminSprite.y = INFO_WILDCARD_ADMIN_OFFSET_Y;
|
||||
|
||||
sprite_init
|
||||
(
|
||||
&_i->wildcardPatreonSprite,
|
||||
_i->g->textures[TEXTURE_INFO_WILDCARD_PATREON],
|
||||
ORIGIN_MIDDLE,
|
||||
INFO_WILDCARD_WIDTH,
|
||||
INFO_WILDCARD_HEIGHT
|
||||
);
|
||||
|
||||
_i->wildcardPatreonSprite.x = INFO_WILDCARD_PATREON_OFFSET_X;
|
||||
_i->wildcardPatreonSprite.y = INFO_WILDCARD_PATREON_OFFSET_Y;
|
||||
|
||||
sprite_init
|
||||
(
|
||||
&_i->wildcardCommunitySprite,
|
||||
_i->g->textures[TEXTURE_INFO_WILDCARD_COMMUNITY],
|
||||
ORIGIN_MIDDLE,
|
||||
INFO_WILDCARD_WIDTH,
|
||||
INFO_WILDCARD_HEIGHT
|
||||
);
|
||||
|
||||
_i->wildcardCommunitySprite.x = INFO_WILDCARD_COMMUNITY_OFFSET_X;
|
||||
_i->wildcardCommunitySprite.y = INFO_WILDCARD_COMMUNITY_OFFSET_Y;
|
||||
|
||||
sprite_init
|
||||
(
|
||||
&_i->backBackgroundSprite,
|
||||
_i->g->textures[TEXTURE_GUI_SIGN_SMALL],
|
||||
ORIGIN_MIDDLE,
|
||||
INFO_BUTTON_BACKGROUND_WIDTH,
|
||||
INFO_BUTTON_BACKGROUND_HEIGHT
|
||||
);
|
||||
|
||||
_i->backBackgroundSprite.x = INFO_BUTTON_OFFSET_X;
|
||||
_i->backBackgroundSprite.y = INFO_BUTTON_OFFSET_Y;
|
||||
|
||||
text_sprite_init
|
||||
(
|
||||
&buttonSprite,
|
||||
_i->g->renderer,
|
||||
_i->g->fonts[FONT_MEDIUM],
|
||||
INFO_TEXT_COLOR,
|
||||
ORIGIN_MIDDLE,
|
||||
STRING_INFO_BACK,
|
||||
0
|
||||
);
|
||||
|
||||
buttonSprite.rotation = INFO_BUTTON_TEXT_ROTATION;
|
||||
|
||||
buttonSprite.x = _i->backBackgroundSprite.x;
|
||||
buttonSprite.y = _i->backBackgroundSprite.y;
|
||||
|
||||
button_init(&_i->backButton, &buttonSprite);
|
||||
|
||||
text_sprite_init
|
||||
(
|
||||
&_i->themeText,
|
||||
_i->g->renderer,
|
||||
_i->g->fonts[FONT_TINY],
|
||||
INFO_TEXT_COLOR,
|
||||
ORIGIN_MIDDLE,
|
||||
STRING_INFO_THEME,
|
||||
INFO_THEME_WRAP
|
||||
);
|
||||
|
||||
_i->themeText.x = INFO_THEME_TEXT_OFFSET_X;
|
||||
_i->themeText.y = INFO_THEME_TEXT_OFFSET_Y;
|
||||
|
||||
text_sprite_init
|
||||
(
|
||||
&_i->wildcardAdminText,
|
||||
_i->g->renderer,
|
||||
_i->g->fonts[FONT_TINY],
|
||||
INFO_TEXT_COLOR,
|
||||
ORIGIN_MIDDLE,
|
||||
STRING_INFO_WILDCARD_ADMIN,
|
||||
INFO_WILDCARD_WRAP
|
||||
);
|
||||
|
||||
_i->wildcardAdminText.x = INFO_WILDCARD_ADMIN_TEXT_OFFSET_X;
|
||||
_i->wildcardAdminText.y = INFO_WILDCARD_ADMIN_TEXT_OFFSET_Y;
|
||||
|
||||
text_sprite_init
|
||||
(
|
||||
&_i->wildcardPatreonText,
|
||||
_i->g->renderer,
|
||||
_i->g->fonts[FONT_TINY],
|
||||
INFO_TEXT_COLOR,
|
||||
ORIGIN_MIDDLE,
|
||||
STRING_INFO_WILDCARD_PATREON,
|
||||
INFO_WILDCARD_WRAP
|
||||
);
|
||||
|
||||
_i->wildcardPatreonText.x = INFO_WILDCARD_PATREON_TEXT_OFFSET_X;
|
||||
_i->wildcardPatreonText.y = INFO_WILDCARD_PATREON_TEXT_OFFSET_Y;
|
||||
|
||||
text_sprite_init
|
||||
(
|
||||
&_i->wildcardCommunityText,
|
||||
_i->g->renderer,
|
||||
_i->g->fonts[FONT_TINY],
|
||||
INFO_TEXT_COLOR,
|
||||
ORIGIN_MIDDLE,
|
||||
STRING_INFO_WILDCARD_COMMUNITY,
|
||||
INFO_WILDCARD_WRAP
|
||||
);
|
||||
|
||||
_i->wildcardCommunityText.x = INFO_WILDCARD_COMMUNITY_TEXT_OFFSET_X;
|
||||
_i->wildcardCommunityText.y = INFO_WILDCARD_COMMUNITY_TEXT_OFFSET_Y;
|
||||
}
|
||||
|
||||
/* Frees info. */
|
||||
void
|
||||
info_free(Info* _i)
|
||||
{
|
||||
if (_i->licenseText.atlas.texture)
|
||||
texture_free(_i->licenseText.atlas.texture);
|
||||
|
||||
if (_i->backButton.sprite.atlas.texture)
|
||||
texture_free(_i->backButton.sprite.atlas.texture);
|
||||
|
||||
if (_i->themeText.atlas.texture)
|
||||
texture_free(_i->themeText.atlas.texture);
|
||||
|
||||
if (_i->wildcardAdminText.atlas.texture)
|
||||
texture_free(_i->wildcardAdminText.atlas.texture);
|
||||
|
||||
if (_i->wildcardPatreonText.atlas.texture)
|
||||
texture_free(_i->wildcardPatreonText.atlas.texture);
|
||||
|
||||
if (_i->wildcardCommunityText.atlas.texture)
|
||||
texture_free(_i->wildcardCommunityText.atlas.texture);
|
||||
|
||||
cursor_free(&_i->cursor);
|
||||
}
|
||||
|
||||
/* Updates info. */
|
||||
void
|
||||
info_update(Info* _i)
|
||||
{
|
||||
cursor_update(&_i->cursor, &_i->g->mouse);
|
||||
|
||||
button_update(&_i->backButton, &_i->g->mouse);
|
||||
|
||||
if (_i->backButton.state == BUTTON_STATE_PRESS)
|
||||
{
|
||||
_i->isBackPressed = TRUE;
|
||||
|
||||
sound_play(_i->g->sounds[SOUND_MENU], -1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Draw info. */
|
||||
void
|
||||
info_draw(Info* _i)
|
||||
{
|
||||
SDL_Rect r;
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.w = INFO_RECTANGLE_WIDTH;
|
||||
r.h = INFO_RECTANGLE_HEIGHT;
|
||||
|
||||
rectangle_draw(&r, _i->g->renderer, INFO_BACKGROUND_COLOR);
|
||||
|
||||
sprite_draw(&_i->licenseText, _i->g->renderer);
|
||||
|
||||
sprite_draw(&_i->themeSprite, _i->g->renderer);
|
||||
sprite_draw(&_i->wildcardAdminSprite, _i->g->renderer);
|
||||
sprite_draw(&_i->wildcardPatreonSprite, _i->g->renderer);
|
||||
sprite_draw(&_i->wildcardCommunitySprite, _i->g->renderer);
|
||||
|
||||
sprite_draw(&_i->themeText, _i->g->renderer);
|
||||
sprite_draw(&_i->wildcardAdminText, _i->g->renderer);
|
||||
sprite_draw(&_i->wildcardPatreonText, _i->g->renderer);
|
||||
sprite_draw(&_i->wildcardCommunityText, _i->g->renderer);
|
||||
|
||||
sprite_draw(&_i->backBackgroundSprite, _i->g->renderer);
|
||||
button_draw(&_i->backButton, _i->g->renderer);
|
||||
|
||||
cursor_draw(&_i->cursor, _i->g->renderer);
|
||||
}
|
52
src/game/info/info.h
Executable file
52
src/game/info/info.h
Executable file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for info.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../GAME_STRINGS.h"
|
||||
#include "../gui/button.h"
|
||||
#include "../gui/cursor.h"
|
||||
|
||||
#define INFO_LICENSE_TEXT_OFFSET_X 400
|
||||
#define INFO_BUTTON_OFFSET_X 750
|
||||
#define INFO_BUTTON_OFFSET_Y 50
|
||||
#define INFO_LICENSE_TEXT_OFFSET_X 400
|
||||
#define INFO_LICENSE_TEXT_OFFSET_Y 80
|
||||
#define INFO_BUTTON_TEXT_ROTATION -5
|
||||
#define INFO_BUTTON_BACKGROUND_WIDTH 96
|
||||
#define INFO_BUTTON_BACKGROUND_HEIGHT 96
|
||||
#define INFO_WILDCARD_WIDTH 175
|
||||
#define INFO_WILDCARD_HEIGHT 225
|
||||
#define INFO_THEME_WIDTH 225
|
||||
#define INFO_THEME_HEIGHT 60
|
||||
#define INFO_THEME_OFFSET_X 175
|
||||
#define INFO_THEME_OFFSET_Y 200
|
||||
#define INFO_WILDCARD_ADMIN_OFFSET_X 100
|
||||
#define INFO_WILDCARD_PATREON_OFFSET_X 475
|
||||
#define INFO_WILDCARD_COMMUNITY_OFFSET_X 475
|
||||
#define INFO_WILDCARD_ADMIN_OFFSET_Y 480
|
||||
#define INFO_WILDCARD_PATREON_OFFSET_Y 255
|
||||
#define INFO_WILDCARD_COMMUNITY_OFFSET_Y 480
|
||||
#define INFO_WILDCARD_ADMIN_TEXT_OFFSET_X 290
|
||||
#define INFO_WILDCARD_ADMIN_TEXT_OFFSET_Y 480
|
||||
#define INFO_WILDCARD_COMMUNITY_TEXT_OFFSET_X 675
|
||||
#define INFO_WILDCARD_COMMUNITY_TEXT_OFFSET_Y 480
|
||||
#define INFO_WILDCARD_PATREON_TEXT_OFFSET_X 675
|
||||
#define INFO_WILDCARD_PATREON_TEXT_OFFSET_Y 255
|
||||
#define INFO_THEME_TEXT_OFFSET_X 200
|
||||
#define INFO_THEME_TEXT_OFFSET_Y 300
|
||||
#define INFO_THEME_WRAP 350
|
||||
#define INFO_WILDCARD_WRAP 200
|
||||
#define INFO_LICENSE_TEXT_WRAP 500
|
||||
#define INFO_RECTANGLE_WIDTH 800
|
||||
#define INFO_RECTANGLE_HEIGHT 600
|
||||
|
||||
static const SDL_Color INFO_BACKGROUND_COLOR = {0, 0, 0, 255};
|
||||
static const SDL_Color INFO_TEXT_COLOR = {255, 255, 255, 255};
|
||||
|
||||
void info_draw(Info* _i);
|
||||
void info_free(Info* _i);
|
||||
void info_init(Info* _i, Game* _g);
|
||||
void info_update(Info* _i);
|
46
src/game/intro/intro.c
Executable file
46
src/game/intro/intro.c
Executable file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Intro code.
|
||||
*/
|
||||
|
||||
#include "intro.h"
|
||||
|
||||
/* Initializes intro. */
|
||||
void
|
||||
intro_init(Intro* _i, Game* _g)
|
||||
{
|
||||
memset(_i, '\0', sizeof(Intro));
|
||||
|
||||
_i->g = _g;
|
||||
|
||||
scene_init
|
||||
(
|
||||
&_i->sceneHandler,
|
||||
_i->g,
|
||||
(Scene*)INTRO_SCENES,
|
||||
INTRO_SCENE_COUNT
|
||||
);
|
||||
|
||||
music_play(_i->g->music[MUSIC_INTRO], TRUE);
|
||||
}
|
||||
|
||||
/* Frees intro. */
|
||||
void
|
||||
intro_free(Intro* _i)
|
||||
{
|
||||
scene_free(&_i->sceneHandler, _i->g);
|
||||
}
|
||||
|
||||
/* Updates intro. */
|
||||
void
|
||||
intro_update(Intro* _i)
|
||||
{
|
||||
scene_update(&_i->sceneHandler, _i->g);
|
||||
}
|
||||
|
||||
/* Draws intro. */
|
||||
void
|
||||
intro_draw(Intro* _i)
|
||||
{
|
||||
scene_draw(&_i->sceneHandler, _i->g);
|
||||
}
|
40
src/game/intro/intro.h
Executable file
40
src/game/intro/intro.h
Executable file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for intro.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../scene/scene.h"
|
||||
#include "../GAME_STRINGS.h"
|
||||
|
||||
#define INTRO_SCENE_COUNT 5
|
||||
|
||||
static const Scene INTRO_SCENES[INTRO_SCENE_COUNT] =
|
||||
{
|
||||
{
|
||||
.textureType = TEXTURE_INTRO_SCENE_ONE,
|
||||
.text = STRING_INTRO_SCENE_ONE
|
||||
},
|
||||
{
|
||||
.textureType = TEXTURE_INTRO_SCENE_TWO,
|
||||
.text = STRING_INTRO_SCENE_TWO
|
||||
},
|
||||
{
|
||||
.textureType = TEXTURE_INTRO_SCENE_THREE,
|
||||
.text = STRING_INTRO_SCENE_THREE
|
||||
},
|
||||
{
|
||||
.textureType = TEXTURE_INTRO_SCENE_FOUR,
|
||||
.text = STRING_INTRO_SCENE_FOUR
|
||||
},
|
||||
{
|
||||
.textureType = TEXTURE_INTRO_SCENE_FIVE,
|
||||
.text = STRING_INTRO_SCENE_FIVE
|
||||
}
|
||||
};
|
||||
|
||||
void intro_update(Intro* _i);
|
||||
void intro_init(Intro* _i, Game* _g);
|
||||
void intro_draw(Intro* _i);
|
||||
void intro_free(Intro* _i);
|
35
src/game/play/collectible/berserk.c
Executable file
35
src/game/play/collectible/berserk.c
Executable file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Berserk powerup.
|
||||
*/
|
||||
|
||||
#include "berserk.h"
|
||||
|
||||
/* Initializes the berserk. */
|
||||
void
|
||||
berserk_init(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
sprite_init
|
||||
(
|
||||
&_c->sprite,
|
||||
_p->g->textures[TEXTURE_COLLECTIBLE_BERSERK],
|
||||
ORIGIN_MIDDLE,
|
||||
BERSERK_WIDTH,
|
||||
BERSERK_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
/* What happens when you collect the berserk? */
|
||||
void
|
||||
berserk_collect(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
_p->player.isPowerUp = TRUE;
|
||||
|
||||
_p->player.isSnakeUpdate = TRUE;
|
||||
|
||||
_p->player.powerUpTimer = BERSERK_PLAYER_TIMER_MAX;
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_BERSERK], -1);
|
||||
|
||||
message_power_up_add(_c->sprite.x, _c->sprite.y, _p);
|
||||
}
|
13
src/game/play/collectible/berserk.h
Executable file
13
src/game/play/collectible/berserk.h
Executable file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for berserk.c.
|
||||
*/
|
||||
|
||||
#include "../message/message.h"
|
||||
|
||||
#define BERSERK_WIDTH 64
|
||||
#define BERSERK_HEIGHT 64
|
||||
#define BERSERK_PLAYER_TIMER_MAX 600
|
||||
|
||||
void berserk_init(Collectible* _c, List* _l, Play* _p);
|
||||
void berserk_collect(Collectible* _c, List* _l, Play* _p);
|
29
src/game/play/collectible/bullions.c
Executable file
29
src/game/play/collectible/bullions.c
Executable file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Large money collectible.
|
||||
*/
|
||||
|
||||
#include "bullions.h"
|
||||
|
||||
/* Initializes the bullions. */
|
||||
void
|
||||
bullions_init(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
sprite_init
|
||||
(
|
||||
&_c->sprite,
|
||||
_p->g->textures[TEXTURE_COLLECTIBLE_BULLIONS],
|
||||
ORIGIN_MIDDLE,
|
||||
BULLIONS_WIDTH,
|
||||
BULLIONS_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
/* What happens when you collect the bullions? */
|
||||
void
|
||||
bullions_collect(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
player_cash_acquire(&_p->player, BULLIONS_CASH_VALUE, _p);
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_BULLIONS], -1);
|
||||
}
|
13
src/game/play/collectible/bullions.h
Executable file
13
src/game/play/collectible/bullions.h
Executable file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for bullions.c.
|
||||
*/
|
||||
|
||||
#include "../player/player_cash.h"
|
||||
|
||||
#define BULLIONS_WIDTH 64
|
||||
#define BULLIONS_HEIGHT 64
|
||||
#define BULLIONS_CASH_VALUE 500
|
||||
|
||||
void bullions_init(Collectible* _c, List* _l, Play* _p);
|
||||
void bullions_collect(Collectible* _c, List* _l, Play* _p);
|
158
src/game/play/collectible/collectible.c
Executable file
158
src/game/play/collectible/collectible.c
Executable file
@ -0,0 +1,158 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Collectible code.
|
||||
*/
|
||||
|
||||
#include "collectible.h"
|
||||
|
||||
/* Adds a new collectible. */
|
||||
Collectible*
|
||||
collectible_add(List* _l, CollectibleType _c, f64 _x, f64 _y, Play* _p)
|
||||
{
|
||||
Collectible collectible;
|
||||
f64 angle;
|
||||
|
||||
memset(&collectible, '\0', sizeof(Collectible));
|
||||
|
||||
collectible.type = _c;
|
||||
|
||||
switch (collectible.type)
|
||||
{
|
||||
case COLLECTIBLE_DOLLARS:
|
||||
dollars_init(&collectible, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_SACK:
|
||||
sack_init(&collectible, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_BULLIONS:
|
||||
bullions_init(&collectible, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_MIRACLE_CURE:
|
||||
miracle_cure_init(&collectible, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_DYNAMITE:
|
||||
dynamite_init(&collectible, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_BERSERK:
|
||||
berserk_init(&collectible, _l, _p);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
collectible.sprite.x = _x;
|
||||
collectible.sprite.y = _y;
|
||||
|
||||
collectible.shadow.x = collectible.sprite.x + COLLECTIBLE_SHADOW_OFFSET_Y;
|
||||
collectible.shadow.y = collectible.sprite.y + COLLECTIBLE_SHADOW_OFFSET_Y;
|
||||
|
||||
collectible.shadow.r = COLLECTIBLE_SHADOW_RADIUS;
|
||||
|
||||
collectible.lifetime = COLLECTIBLE_LIFETIME;
|
||||
|
||||
collectible.isActive = FALSE;
|
||||
collectible.activeTimer = COLLECTIBLE_ACTIVE_TIMER_MAX;
|
||||
|
||||
angle = random_f64_in_range_get(0, ROTATION_MAX_RAD);
|
||||
|
||||
collectible.dX = cos(angle) * COLLECTIBLE_VELOCITY;
|
||||
collectible.dY = sin(angle) * COLLECTIBLE_VELOCITY;
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_COLLECTIBLE], -1);
|
||||
|
||||
return (Collectible*)list_append_new(_l, (void*)&collectible, sizeof(Collectible));
|
||||
}
|
||||
|
||||
/* Removes a collectible. */
|
||||
void
|
||||
collectible_remove(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
list_node_from_data_remove(_l, _c, sizeof(Collectible));
|
||||
}
|
||||
|
||||
/* A collectible is collected. */
|
||||
void
|
||||
collectible_collect(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
switch (_c->type)
|
||||
{
|
||||
case COLLECTIBLE_DOLLARS:
|
||||
dollars_collect(_c, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_SACK:
|
||||
sack_collect(_c, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_BULLIONS:
|
||||
bullions_collect(_c, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_MIRACLE_CURE:
|
||||
miracle_cure_collect(_c, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_DYNAMITE:
|
||||
dynamite_collect(_c, _l, _p);
|
||||
break;
|
||||
case COLLECTIBLE_BERSERK:
|
||||
berserk_collect(_c, _l, _p);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
collectible_remove(_c, _l, _p);
|
||||
}
|
||||
|
||||
/* Updates a collectible. */
|
||||
void
|
||||
collectible_update(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
_c->sprite.x += _c->dX;
|
||||
_c->sprite.y += _c->dY;
|
||||
|
||||
_c->shadow.x = _c->sprite.x + COLLECTIBLE_SHADOW_OFFSET_X;
|
||||
_c->shadow.y = _c->sprite.y + COLLECTIBLE_SHADOW_OFFSET_Y;
|
||||
|
||||
_c->dX *= COLLECTIBLE_FRICTION;
|
||||
_c->dY *= COLLECTIBLE_FRICTION;
|
||||
|
||||
_c->lifetime--;
|
||||
|
||||
if (!_c->isActive)
|
||||
{
|
||||
f64 progress;
|
||||
|
||||
_c->activeTimer--;
|
||||
|
||||
progress = (f64)_c->activeTimer / COLLECTIBLE_ACTIVE_TIMER_MAX;
|
||||
|
||||
_c->sprite.color.a = SDL_ALPHA_OPAQUE * (1 - progress);
|
||||
|
||||
if (_c->activeTimer <= 0)
|
||||
{
|
||||
_c->sprite.color.a = SDL_ALPHA_OPAQUE;
|
||||
_c->activeTimer = 0;
|
||||
_c->isActive = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (_c->attachedSnake)
|
||||
{
|
||||
_c->sprite.x = _c->attachedSnake->sprite.x;
|
||||
_c->sprite.y = _c->attachedSnake->sprite.y;
|
||||
}
|
||||
|
||||
if (circle_collide(&_c->shadow, &_p->player.shadow))
|
||||
collectible_collect(_c, _l, _p);
|
||||
else
|
||||
{
|
||||
if (_c->lifetime <= 0)
|
||||
collectible_remove(_c, _l, _p);
|
||||
else if (_c->lifetime <= COLLECTIBLE_DISAPPEAR_THRESHOLD)
|
||||
{
|
||||
if (_c->lifetime % COLLECTIBLE_DISAPPEAR_MODULO == 0)
|
||||
_c->sprite.color.a = 0;
|
||||
else
|
||||
_c->sprite.color.a = SDL_ALPHA_OPAQUE;
|
||||
}
|
||||
}
|
||||
}
|
28
src/game/play/collectible/collectible.h
Executable file
28
src/game/play/collectible/collectible.h
Executable file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for collectible.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "bullions.h"
|
||||
#include "dollars.h"
|
||||
#include "sack.h"
|
||||
#include "berserk.h"
|
||||
#include "dynamite.h"
|
||||
#include "miracle_cure.h"
|
||||
|
||||
#define COLLECTIBLE_ACTIVE_TIMER_MAX 30
|
||||
#define COLLECTIBLE_SHADOW_RADIUS 16
|
||||
#define COLLECTIBLE_SHADOW_OFFSET_X 0
|
||||
#define COLLECTIBLE_SHADOW_OFFSET_Y 16
|
||||
#define COLLECTIBLE_FRICTION 0.90
|
||||
#define COLLECTIBLE_VELOCITY 3
|
||||
#define COLLECTIBLE_DISAPPEAR_THRESHOLD 60
|
||||
#define COLLECTIBLE_DISAPPEAR_MODULO 5
|
||||
#define COLLECTIBLE_LIFETIME 500
|
||||
|
||||
Collectible* collectible_add(List* _l, CollectibleType _c, f64 _x, f64 _y, Play* _p);
|
||||
void collectible_remove(Collectible* _c, List* _l, Play* _p);
|
||||
void collectible_update(Collectible* _c, List* _l, Play* _p);
|
||||
void collectible_collect(Collectible* _c, List* _l, Play* _p);
|
73
src/game/play/collectible/collectibles.c
Executable file
73
src/game/play/collectible/collectibles.c
Executable file
@ -0,0 +1,73 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Collectbles; the money/powerups that come out of enemies.
|
||||
*/
|
||||
|
||||
#include "collectibles.h"
|
||||
|
||||
/* Initializes collectibles. */
|
||||
void
|
||||
collectibles_init(List* _l, Play* _p)
|
||||
{
|
||||
list_init(_l);
|
||||
}
|
||||
|
||||
/* Initializes collectibles. */
|
||||
void
|
||||
collectibles_free(List* _l, Play* _p)
|
||||
{
|
||||
list_free(_l);
|
||||
}
|
||||
|
||||
/* Updates collectibles. */
|
||||
void
|
||||
collectibles_update(List* _l, Play* _p)
|
||||
{
|
||||
Collectible** collectibles;
|
||||
s32 collectibleCount;
|
||||
|
||||
collectibles = (Collectible**)list_data_get(_l);
|
||||
collectibleCount = _l->count;
|
||||
|
||||
for (s32 i = 0; i < collectibleCount; i++)
|
||||
{
|
||||
Collectible* c;
|
||||
|
||||
c = collectibles[i];
|
||||
|
||||
collectible_update(c, _l, _p);
|
||||
}
|
||||
|
||||
free(collectibles);
|
||||
}
|
||||
|
||||
/* Draws all collectibles. */
|
||||
void
|
||||
collectibles_draw(List* _l, Play* _p)
|
||||
{
|
||||
Collectible** collectibles;
|
||||
s32 collectibleCount;
|
||||
|
||||
collectibles = (Collectible**)list_data_get(_l);
|
||||
collectibleCount = _l->count;
|
||||
|
||||
for (s32 i = 0; i < collectibleCount; i++)
|
||||
{
|
||||
Collectible* c;
|
||||
|
||||
c = collectibles[i];
|
||||
|
||||
shadow_draw(&c->shadow, _p);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < collectibleCount; i++)
|
||||
{
|
||||
Collectible* c;
|
||||
|
||||
c = collectibles[i];
|
||||
|
||||
sprite_draw(&c->sprite, _p->g->renderer);
|
||||
}
|
||||
|
||||
free(collectibles);
|
||||
}
|
16
src/game/play/collectible/collectibles.h
Executable file
16
src/game/play/collectible/collectibles.h
Executable file
@ -0,0 +1,16 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for collectibles.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "collectible.h"
|
||||
#include "../shadow/shadow.h"
|
||||
|
||||
static const SDL_Color COLLECTIBLE_SHADOW_COLOR = {0, 0, 0, 64};
|
||||
|
||||
void collectibles_init(List* _l, Play* _p);
|
||||
void collectibles_free(List* _l, Play* _p);
|
||||
void collectibles_update(List* _l, Play* _p);
|
||||
void collectibles_draw(List* _l, Play* _p);
|
29
src/game/play/collectible/dollars.c
Executable file
29
src/game/play/collectible/dollars.c
Executable file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Small money collectible.
|
||||
*/
|
||||
|
||||
#include "dollars.h"
|
||||
|
||||
/* Initializes the dollars. */
|
||||
void
|
||||
dollars_init(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
sprite_init
|
||||
(
|
||||
&_c->sprite,
|
||||
_p->g->textures[TEXTURE_COLLECTIBLE_DOLLARS],
|
||||
ORIGIN_MIDDLE,
|
||||
DOLLARS_WIDTH,
|
||||
DOLLARS_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
/* What happens when you collect the dollars? */
|
||||
void
|
||||
dollars_collect(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
player_cash_acquire(&_p->player, DOLLARS_CASH_VALUE, _p);
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_DOLLARS], -1);
|
||||
}
|
13
src/game/play/collectible/dollars.h
Executable file
13
src/game/play/collectible/dollars.h
Executable file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for dollars.c.
|
||||
*/
|
||||
|
||||
#include "../player/player_cash.h"
|
||||
|
||||
#define DOLLARS_WIDTH 32
|
||||
#define DOLLARS_HEIGHT 32
|
||||
#define DOLLARS_CASH_VALUE 100
|
||||
|
||||
void dollars_init(Collectible* _c, List* _l, Play* _p);
|
||||
void dollars_collect(Collectible* _c, List* _l, Play* _p);
|
46
src/game/play/collectible/dynamite.c
Executable file
46
src/game/play/collectible/dynamite.c
Executable file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Dynamite collectible; blows stuff up.
|
||||
*/
|
||||
|
||||
#include "dynamite.h"
|
||||
|
||||
/* Initializes the dynamite. */
|
||||
void
|
||||
dynamite_init(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
sprite_init
|
||||
(
|
||||
&_c->sprite,
|
||||
_p->g->textures[TEXTURE_COLLECTIBLE_DYNAMITE],
|
||||
ORIGIN_MIDDLE,
|
||||
DYNAMITE_WIDTH,
|
||||
DYNAMITE_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
/* What happens when you collect the dynamite? */
|
||||
void
|
||||
dynamite_collect(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
Enemy** enemies;
|
||||
s32 enemyCount;
|
||||
|
||||
enemies = (Enemy**)list_data_get(&_p->enemies);
|
||||
enemyCount = _p->enemies.count;
|
||||
|
||||
for (s32 i = 0; i < enemyCount; i++)
|
||||
{
|
||||
Enemy* e;
|
||||
|
||||
e = enemies[i];
|
||||
|
||||
enemy_damage(e, DYNAMITE_DAMAGE, &_p->enemies, _p);
|
||||
}
|
||||
|
||||
free(enemies);
|
||||
|
||||
message_dynamite_add(_c->sprite.x, _c->sprite.y, _p);
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_DYNAMITE], 3);
|
||||
}
|
13
src/game/play/collectible/dynamite.h
Executable file
13
src/game/play/collectible/dynamite.h
Executable file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for dynamite.c.
|
||||
*/
|
||||
|
||||
#include "../enemy/enemies.h"
|
||||
|
||||
#define DYNAMITE_WIDTH 64
|
||||
#define DYNAMITE_HEIGHT 64
|
||||
#define DYNAMITE_DAMAGE 10
|
||||
|
||||
void dynamite_init(Collectible* _c, List* _l, Play* _p);
|
||||
void dynamite_collect(Collectible* _c, List* _l, Play* _p);
|
44
src/game/play/collectible/miracle_cure.c
Executable file
44
src/game/play/collectible/miracle_cure.c
Executable file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* "Miracle Cure", heals you for one fatness.
|
||||
*/
|
||||
|
||||
#include "miracle_cure.h"
|
||||
|
||||
/* Initializes the miracle cure. */
|
||||
void
|
||||
miracle_cure_init(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
sprite_init
|
||||
(
|
||||
&_c->sprite,
|
||||
_p->g->textures[TEXTURE_COLLECTIBLE_MIRACLE_CURE],
|
||||
ORIGIN_MIDDLE,
|
||||
MIRACLE_CURE_WIDTH,
|
||||
MIRACLE_CURE_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
/* What happens when you collect the miracle cure? */
|
||||
void
|
||||
miracle_cure_collect(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
_p->player.fatness--;
|
||||
|
||||
_p->player.isFatnessUpdate = TRUE;
|
||||
|
||||
if (_p->player.fatness < 0)
|
||||
{
|
||||
_p->player.fatness = 0;
|
||||
|
||||
player_cash_acquire(&_p->player, MIRACLE_CURE_CASH_VALUE, _p);
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_BULLIONS], -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
message_miracle_cure_add(_c->sprite.x, _c->sprite.y, _p);
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_MIRACLE_CURE], -1);
|
||||
}
|
||||
}
|
13
src/game/play/collectible/miracle_cure.h
Executable file
13
src/game/play/collectible/miracle_cure.h
Executable file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for miracle_cure.c.
|
||||
*/
|
||||
|
||||
#include "../player/player_cash.h"
|
||||
|
||||
#define MIRACLE_CURE_WIDTH 64
|
||||
#define MIRACLE_CURE_HEIGHT 64
|
||||
#define MIRACLE_CURE_CASH_VALUE 1000
|
||||
|
||||
void miracle_cure_init(Collectible* _c, List* _l, Play* _p);
|
||||
void miracle_cure_collect(Collectible* _c, List* _l, Play* _p);
|
29
src/game/play/collectible/sack.c
Executable file
29
src/game/play/collectible/sack.c
Executable file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Medium money collectible.
|
||||
*/
|
||||
|
||||
#include "sack.h"
|
||||
|
||||
/* Initializes the sack. */
|
||||
void
|
||||
sack_init(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
sprite_init
|
||||
(
|
||||
&_c->sprite,
|
||||
_p->g->textures[TEXTURE_COLLECTIBLE_SACK],
|
||||
ORIGIN_MIDDLE,
|
||||
SACK_WIDTH,
|
||||
SACK_HEIGHT
|
||||
);
|
||||
}
|
||||
|
||||
/* What happens when you collect the sack? */
|
||||
void
|
||||
sack_collect(Collectible* _c, List* _l, Play* _p)
|
||||
{
|
||||
player_cash_acquire(&_p->player, SACK_CASH_VALUE, _p);
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_SACK], -1);
|
||||
}
|
13
src/game/play/collectible/sack.h
Executable file
13
src/game/play/collectible/sack.h
Executable file
@ -0,0 +1,13 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for sack.c.
|
||||
*/
|
||||
|
||||
#include "../player/player_cash.h"
|
||||
|
||||
#define SACK_WIDTH 64
|
||||
#define SACK_HEIGHT 64
|
||||
#define SACK_CASH_VALUE 250
|
||||
|
||||
void sack_init(Collectible* _c, List* _l, Play* _p);
|
||||
void sack_collect(Collectible* _c, List* _l, Play* _p);
|
116
src/game/play/enemy/chip.c
Executable file
116
src/game/play/enemy/chip.c
Executable file
@ -0,0 +1,116 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* AI for the "Chip" enemy.
|
||||
*/
|
||||
|
||||
#include "chip.h"
|
||||
|
||||
static s32 chip_health_get(Enemy* _e, List* _l, Play* _p);
|
||||
static f64 chip_velocity_get(Enemy* _e, List* _l, Play* _p);
|
||||
|
||||
/* Gets the health of the Chip. */
|
||||
static s32
|
||||
chip_health_get(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
s32 health;
|
||||
|
||||
health = CHIP_HEALTH_BASE + ((_p->game - 1) * CHIP_HEALTH_GAME_MULTIPLIER);
|
||||
|
||||
health = CEIL(health, CHIP_HEALTH_MAX);
|
||||
|
||||
return health;
|
||||
}
|
||||
|
||||
/* Gets the velocity of the Chip. */
|
||||
static f64
|
||||
chip_velocity_get(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
f64 velocity;
|
||||
|
||||
velocity = CHIP_VELOCITY_BASE + ((_p->game - 1) * CHIP_VELOCITY_GAME_MULTIPLIER);
|
||||
|
||||
velocity = CEIL(velocity, CHIP_VELOCITY_MAX);
|
||||
|
||||
return velocity;
|
||||
}
|
||||
|
||||
/* Initializes Chip. */
|
||||
void
|
||||
chip_init(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
sprite_init
|
||||
(
|
||||
&_e->sprite,
|
||||
_p->g->textures[TEXTURE_ENEMY_CHIP],
|
||||
ORIGIN_MIDDLE,
|
||||
CHIP_WIDTH,
|
||||
CHIP_HEIGHT
|
||||
);
|
||||
|
||||
_e->shadow.r = CHIP_SHADOW_RADIUS;
|
||||
}
|
||||
|
||||
/* Sets the Chip. */
|
||||
void
|
||||
chip_set(Enemy* _e, List* _l, f64 _x, f64 _y, Play* _p)
|
||||
{
|
||||
f64 angle;
|
||||
f64 velocity;
|
||||
|
||||
_e->sprite.x = _x;
|
||||
_e->sprite.y = _y;
|
||||
|
||||
_e->shadow.x = _e->sprite.x + CHIP_SHADOW_OFFSET_X;
|
||||
_e->shadow.y = _e->sprite.y + CHIP_SHADOW_OFFSET_Y;
|
||||
|
||||
_e->sprite.rotation = random_f64_in_range_get(0, ROTATION_MAX_DEG);
|
||||
|
||||
velocity = chip_velocity_get(_e, _l, _p);
|
||||
|
||||
angle = math_atan
|
||||
(
|
||||
_e->shadow.x,
|
||||
_e->shadow.y,
|
||||
_p->player.shadow.x,
|
||||
_p->player.shadow.y
|
||||
);
|
||||
|
||||
_e->dX = -cos(angle) * velocity;
|
||||
_e->dY = -sin(angle) * velocity;
|
||||
|
||||
_e->health = chip_health_get(_e, _l, _p);
|
||||
_e->isActive = TRUE;
|
||||
_e->lifetime = CHIP_LIFETIME;
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates Chip.
|
||||
* Just flies towards the player, and will remove
|
||||
* itself if enough time has passed.
|
||||
*/
|
||||
void
|
||||
chip_update(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
SDL_Rect rect;
|
||||
SDL_Rect windowRect;
|
||||
|
||||
rect = sprite_rect_get(&_e->sprite);
|
||||
windowRect = window_rect_get(_p->g->window);
|
||||
|
||||
_e->lifetime--;
|
||||
|
||||
_e->sprite.x += _e->dX;
|
||||
_e->sprite.y += _e->dY;
|
||||
|
||||
_e->sprite.rotation += CHIP_ROTATION_DELTA;
|
||||
|
||||
_e->shadow.x = _e->sprite.x + CHIP_SHADOW_OFFSET_X;
|
||||
_e->shadow.y = _e->sprite.y + CHIP_SHADOW_OFFSET_Y;
|
||||
|
||||
if
|
||||
(
|
||||
_e->lifetime <= 0 ||
|
||||
(_e->lifetime < CHIP_LIFETIME / 2 && !SDL_HasIntersection(&rect, &windowRect))
|
||||
)
|
||||
enemy_remove(_l, _e, _p);
|
||||
}
|
27
src/game/play/enemy/chip.h
Executable file
27
src/game/play/enemy/chip.h
Executable file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for chip.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../GAME_COMMON.h"
|
||||
#include "enemy.h"
|
||||
|
||||
#define CHIP_HEALTH_BASE 1
|
||||
#define CHIP_HEALTH_GAME_MULTIPLIER 0
|
||||
#define CHIP_HEALTH_MAX 99
|
||||
#define CHIP_VELOCITY_GAME_MULTIPLIER 1
|
||||
#define CHIP_VELOCITY_MAX 10
|
||||
#define CHIP_WIDTH 16
|
||||
#define CHIP_HEIGHT 16
|
||||
#define CHIP_VELOCITY_BASE 3
|
||||
#define CHIP_LIFETIME 300
|
||||
#define CHIP_SHADOW_OFFSET_X 0
|
||||
#define CHIP_SHADOW_OFFSET_Y 32
|
||||
#define CHIP_SHADOW_RADIUS 8
|
||||
#define CHIP_ROTATION_DELTA 5
|
||||
|
||||
void chip_init(Enemy* _e, List* _l, Play* _p);
|
||||
void chip_set(Enemy* _e, List* _l, f64 _x, f64 _y, Play* _p);
|
||||
void chip_update(Enemy* _e, List* _l, Play* _p);
|
209
src/game/play/enemy/chipper.c
Executable file
209
src/game/play/enemy/chipper.c
Executable file
@ -0,0 +1,209 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* AI for the "Chipper" enemy.
|
||||
*/
|
||||
|
||||
#include "chipper.h"
|
||||
|
||||
static s32 chipper_health_get(Enemy* _e, List* _l, Play* _p);
|
||||
static s32 chipper_attack_timer_max_get(Enemy* _e, List* _l, Play* _p);
|
||||
|
||||
/* Gets the Chipper health. */
|
||||
static s32
|
||||
chipper_health_get(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
s32 health;
|
||||
|
||||
health = (s32)(CHIPPER_HEALTH_BASE + ((_p->game - 1) * CHIPPER_HEALTH_GAME_MULTIPLIER));
|
||||
|
||||
health = CEIL(health, CHIPPER_HEALTH_MAX);
|
||||
|
||||
return health;
|
||||
}
|
||||
|
||||
/* Gets the Chipper attack timer max. */
|
||||
static s32
|
||||
chipper_attack_timer_max_get(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
s32 attackTimerMax;
|
||||
|
||||
attackTimerMax = (s32)(CHIPPER_ATTACK_TIMER_MAX_BASE - ((_p->game - 1) * CHIPPER_ATTACK_TIMER_MAX_GAME_MULTIPLIER));
|
||||
|
||||
attackTimerMax = FLOOR(attackTimerMax, CHIPPER_ATTACK_TIMER_MAX_MIN);
|
||||
|
||||
return attackTimerMax;
|
||||
}
|
||||
|
||||
/* Initializes Chipper. */
|
||||
void
|
||||
chipper_init(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
Atlas atlas;
|
||||
|
||||
atlas_init
|
||||
(
|
||||
&atlas,
|
||||
_p->g->textures[TEXTURE_ENEMY_CHIPPER],
|
||||
CHIPPER_ROWS,
|
||||
CHIPPER_COLUMNS,
|
||||
CHIPPER_WIDTH,
|
||||
CHIPPER_HEIGHT
|
||||
);
|
||||
|
||||
sprite_atlas_init
|
||||
(
|
||||
&_e->sprite,
|
||||
&atlas,
|
||||
ORIGIN_MIDDLE,
|
||||
CHIPPER_WIDTH,
|
||||
CHIPPER_HEIGHT
|
||||
);
|
||||
|
||||
_e->shadow.r = CHIPPER_SHADOW_RADIUS;
|
||||
|
||||
_e->sprite.frame = 2;
|
||||
}
|
||||
|
||||
/* Sets the Chipper. */
|
||||
void
|
||||
chipper_set(Enemy* _e, List* _l, f64 _x, f64 _y, Play* _p)
|
||||
{
|
||||
_e->sprite.x = _x;
|
||||
_e->sprite.y = _y;
|
||||
|
||||
_e->shadow.x = _e->sprite.x + CHIPPER_SHADOW_OFFSET_X;
|
||||
_e->shadow.y = _e->sprite.y + CHIPPER_SHADOW_OFFSET_Y;
|
||||
|
||||
_e->isActive = TRUE;
|
||||
_e->isActing = FALSE;
|
||||
_e->range = random_f64_in_range_get(CHIPPER_RANGE_MIN, CHIPPER_RANGE_MAX);
|
||||
_e->attackTimer = chipper_attack_timer_max_get(_e, _l, _p);
|
||||
_e->health = chipper_health_get(_e, _l, _p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates Chipper.
|
||||
* Basically, it's going to slowly approach the player,
|
||||
* get into range of them,
|
||||
* and fire projectiles (chips) at the player.
|
||||
*/
|
||||
void
|
||||
chipper_update(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
f64 distance;
|
||||
f64 angle;
|
||||
SDL_Rect rect;
|
||||
SDL_Rect windowRect;
|
||||
|
||||
rect = sprite_rect_get(&_e->sprite);
|
||||
windowRect = window_rect_get(_p->g->window);
|
||||
|
||||
distance = math_distance
|
||||
(
|
||||
_e->shadow.x,
|
||||
_e->shadow.y,
|
||||
_p->player.shadow.x,
|
||||
_p->player.shadow.y
|
||||
);
|
||||
|
||||
angle = math_atan
|
||||
(
|
||||
_e->shadow.x,
|
||||
_e->shadow.y,
|
||||
_p->player.shadow.x,
|
||||
_p->player.shadow.y
|
||||
);
|
||||
|
||||
if (_p->player.sprite.x < _e->sprite.x)
|
||||
_e->sprite.flip = FLIP_HORIZONTAL;
|
||||
else
|
||||
_e->sprite.flip = FLIP_NONE;
|
||||
|
||||
/* Is this Chipper within range, and is fully on screen? */
|
||||
if
|
||||
(
|
||||
distance <= _e->range &&
|
||||
SDL_HasIntersection(&rect, &windowRect)
|
||||
)
|
||||
{
|
||||
if (!_e->isActing)
|
||||
_e->animationTimer = 0;
|
||||
_e->isActing = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_e->isActing)
|
||||
_e->animationTimer = 0;
|
||||
_e->isActing = FALSE;
|
||||
}
|
||||
|
||||
_e->animationTimer--;
|
||||
|
||||
if (_e->isActing) /* Waiting to shoot */
|
||||
{
|
||||
_e->dX = 0;
|
||||
_e->dY = 0;
|
||||
|
||||
_e->sprite.frame = 1;
|
||||
|
||||
_e->attackTimer--;
|
||||
|
||||
if (_e->animationTimer > 0)
|
||||
{
|
||||
f64 progress;
|
||||
|
||||
_e->sprite.frame = 3;
|
||||
|
||||
progress = 1 - ((f64)_e->animationTimer / CHIPPER_ANIMATION_TIMER_MAX);
|
||||
|
||||
_e->sprite.squash = SPRITE_SQUASH_DEFAULT + (cos(ROTATION_MAX_RAD * progress) * CHIPPER_SQUASH_MULTIPLIER);
|
||||
_e->sprite.stretch = SPRITE_STRETCH_DEFAULT + (cos(ROTATION_MAX_RAD * progress) * CHIPPER_STRETCH_MULTIPLIER);
|
||||
|
||||
if (_e->animationTimer <= 0)
|
||||
{
|
||||
_e->sprite.squash = SPRITE_SQUASH_DEFAULT;
|
||||
_e->sprite.stretch = SPRITE_STRETCH_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
if (_e->attackTimer <= 0) /* Just started shooting */
|
||||
{
|
||||
Enemy* e;
|
||||
|
||||
e = enemy_add(_l, ENEMY_CHIP, _p);
|
||||
enemy_set(_l, e, _e->shadow.x, _e->shadow.y, _p);
|
||||
|
||||
_e->attackTimer = chipper_attack_timer_max_get(_e, _l, _p);
|
||||
|
||||
_e->animationTimer = CHIPPER_ANIMATION_TIMER_MAX;
|
||||
|
||||
_e->sprite.frame = 3;
|
||||
|
||||
_p->enemyMax++;
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_SPIT], -1);
|
||||
}
|
||||
}
|
||||
else /* Walk */
|
||||
{
|
||||
_e->dX = -cos(angle) * CHIPPER_VELOCITY;
|
||||
_e->dY = -sin(angle) * CHIPPER_VELOCITY;
|
||||
|
||||
if (_e->animationTimer % CHIPPER_ANIMATION_MODULO == 0)
|
||||
{
|
||||
_e->sprite.frame++;
|
||||
|
||||
if (_e->sprite.frame > 2)
|
||||
_e->sprite.frame = 0;
|
||||
}
|
||||
|
||||
if (_e->animationTimer <= 0)
|
||||
_e->animationTimer = CHIPPER_ANIMATION_TIMER_MAX;
|
||||
}
|
||||
|
||||
_e->sprite.x += _e->dX;
|
||||
_e->sprite.y += _e->dY;
|
||||
|
||||
_e->shadow.x = _e->sprite.x + CHIPPER_SHADOW_OFFSET_X;
|
||||
_e->shadow.y = _e->sprite.y + CHIPPER_SHADOW_OFFSET_Y;
|
||||
}
|
34
src/game/play/enemy/chipper.h
Executable file
34
src/game/play/enemy/chipper.h
Executable file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for chipper.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../GAME_COMMON.h"
|
||||
#include "enemy.h"
|
||||
|
||||
#define CHIPPER_ANIMATION_MODULO 5
|
||||
#define CHIPPER_ANIMATION_TIMER_MAX 15
|
||||
#define CHIPPER_STRETCH_MULTIPLIER 0.05
|
||||
#define CHIPPER_SQUASH_MULTIPLIER 0.05
|
||||
#define CHIPPER_ATTACK_TIMER_MAX_BASE 120
|
||||
#define CHIPPER_ATTACK_TIMER_MAX_GAME_MULTIPLIER 1
|
||||
#define CHIPPER_ATTACK_TIMER_MAX_MIN 30
|
||||
#define CHIPPER_SHADOW_OFFSET_X 0
|
||||
#define CHIPPER_SHADOW_OFFSET_Y 16
|
||||
#define CHIPPER_SHADOW_RADIUS 24
|
||||
#define CHIPPER_HEALTH_BASE 5
|
||||
#define CHIPPER_HEALTH_GAME_MULTIPLIER 2
|
||||
#define CHIPPER_HEALTH_MAX 99
|
||||
#define CHIPPER_HEIGHT 48
|
||||
#define CHIPPER_ROWS 1
|
||||
#define CHIPPER_COLUMNS 4
|
||||
#define CHIPPER_RANGE_MAX 300
|
||||
#define CHIPPER_RANGE_MIN 200
|
||||
#define CHIPPER_VELOCITY 1
|
||||
#define CHIPPER_WIDTH 64
|
||||
|
||||
void chipper_init(Enemy* _e, List* _l, Play* _p);
|
||||
void chipper_set(Enemy* _e, List* _l, f64 _x, f64 _y, Play* _p);
|
||||
void chipper_update(Enemy* _e, List* _l, Play* _p);
|
125
src/game/play/enemy/crumbler.c
Executable file
125
src/game/play/enemy/crumbler.c
Executable file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* AI for the "Crumbler" enemy.
|
||||
*/
|
||||
|
||||
#include "crumbler.h"
|
||||
|
||||
static s32 crumbler_health_get(Enemy* _e, List* _l, Play* _p);
|
||||
static s32 crumbler_attack_timer_max_get(Enemy* _e, List* _l, Play* _p);
|
||||
|
||||
/* Gets the Crumbler health. */
|
||||
static s32
|
||||
crumbler_health_get(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
s32 health;
|
||||
|
||||
health = CRUMBLER_HEALTH_BASE + ((_p->game - 1) * CRUMBLER_HEALTH_GAME_MULTIPLIER);
|
||||
|
||||
health = CEIL(health, CRUMBLER_HEALTH_MAX);
|
||||
|
||||
return health;
|
||||
}
|
||||
|
||||
/* Gets the Crumbler attack timer max. */
|
||||
static s32
|
||||
crumbler_attack_timer_max_get(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
s32 attackTimerMax;
|
||||
|
||||
attackTimerMax = CRUMBLER_ATTACK_TIMER_MAX_BASE - ((_p->game - 1) * CRUMBLER_ATTACK_TIMER_MAX_GAME_MULTIPLIER);
|
||||
|
||||
attackTimerMax = FLOOR(attackTimerMax, CRUMBLER_ATTACK_TIMER_MAX_MIN);
|
||||
|
||||
return attackTimerMax;
|
||||
}
|
||||
|
||||
/* Initializes the Crumbler. */
|
||||
void
|
||||
crumbler_init(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
Atlas atlas;
|
||||
|
||||
atlas_init
|
||||
(
|
||||
&atlas,
|
||||
_p->g->textures[TEXTURE_ENEMY_CRUMBLER],
|
||||
CRUMBLER_ROWS,
|
||||
CRUMBLER_COLUMNS,
|
||||
CRUMBLER_WIDTH,
|
||||
CRUMBLER_HEIGHT
|
||||
);
|
||||
|
||||
sprite_atlas_init
|
||||
(
|
||||
&_e->sprite,
|
||||
&atlas,
|
||||
ORIGIN_MIDDLE,
|
||||
CRUMBLER_WIDTH,
|
||||
CRUMBLER_HEIGHT
|
||||
);
|
||||
|
||||
_e->shadow.r = 0;
|
||||
_e->sprite.frame = 1;
|
||||
}
|
||||
|
||||
/* Sets the Crumbler. */
|
||||
void
|
||||
crumbler_set(Enemy* _e, List* _l, f64 _x, f64 _y, Play* _p)
|
||||
{
|
||||
_e->shadow.x = _x + CRUMBLER_SHADOW_OFFSET_X;
|
||||
_e->shadow.y = _y + CRUMBLER_SHADOW_OFFSET_Y;
|
||||
|
||||
_e->sprite.x = _e->shadow.x;
|
||||
_e->sprite.y = _e->shadow.y - (CRUMBLER_ATTACK_OFFSET_Y + CRUMBLER_SHADOW_OFFSET_Y);
|
||||
|
||||
_e->isActive = FALSE;
|
||||
_e->isActing = TRUE;
|
||||
_e->attackTimer = crumbler_attack_timer_max_get(_e, _l, _p);
|
||||
_e->health = crumbler_health_get(_e, _l, _p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates Crumbler.
|
||||
* Falls into the arena and then remains stationary.
|
||||
*/
|
||||
void
|
||||
crumbler_update(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
if (_e->isActing)
|
||||
{
|
||||
f64 progress;
|
||||
|
||||
_e->attackTimer--;
|
||||
|
||||
progress = 1 - ((f64)_e->attackTimer / crumbler_attack_timer_max_get(_e, _l, _p));
|
||||
|
||||
_e->shadow.r = CRUMBLER_SHADOW_RADIUS * progress;
|
||||
|
||||
_e->sprite.y = _e->shadow.y - CRUMBLER_SHADOW_OFFSET_Y - (CRUMBLER_ATTACK_OFFSET_Y * (1 - progress));
|
||||
|
||||
if (_e->attackTimer <= 0)
|
||||
{
|
||||
_e->isActing = FALSE;
|
||||
_e->isActive = TRUE;
|
||||
_e->shadow.r = CRUMBLER_SHADOW_RADIUS;
|
||||
_e->sprite.frame = 0;
|
||||
|
||||
sound_play(_p->g->sounds[SOUND_RUMBLE], -1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
f64 progress;
|
||||
|
||||
_e->animationTimer--;
|
||||
|
||||
progress = 1 - ((f64)_e->animationTimer / CRUMBLER_ANIMATION_TIMER_MAX);
|
||||
|
||||
_e->sprite.squash = (SPRITE_SQUASH_DEFAULT + cos((ROTATION_MAX_RAD * progress)) * CRUMBLER_SQUASH_MULTIPLIER);
|
||||
_e->sprite.stretch = (SPRITE_STRETCH_DEFAULT + cos((ROTATION_MAX_RAD * progress)) * CRUMBLER_STRETCH_MULTIPLIER);
|
||||
|
||||
if (_e->animationTimer <= 0)
|
||||
_e->animationTimer = CRUMBLER_ANIMATION_TIMER_MAX;
|
||||
}
|
||||
}
|
31
src/game/play/enemy/crumbler.h
Executable file
31
src/game/play/enemy/crumbler.h
Executable file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for crumbler.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../GAME_COMMON.h"
|
||||
#include "enemy.h"
|
||||
|
||||
#define CRUMBLER_ANIMATION_TIMER_MAX 60
|
||||
#define CRUMBLER_ATTACK_TIMER_MAX_BASE 120
|
||||
#define CRUMBLER_ATTACK_TIMER_MAX_MIN 60
|
||||
#define CRUMBLER_SHADOW_OFFSET_X 0
|
||||
#define CRUMBLER_SHADOW_OFFSET_Y 16
|
||||
#define CRUMBLER_SHADOW_RADIUS 48
|
||||
#define CRUMBLER_HEALTH_BASE 10
|
||||
#define CRUMBLER_HEALTH_MAX 99
|
||||
#define CRUMBLER_HEIGHT 96
|
||||
#define CRUMBLER_ATTACK_OFFSET_Y 1000
|
||||
#define CRUMBLER_SQUASH_MULTIPLIER 0.015
|
||||
#define CRUMBLER_STRETCH_MULTIPLIER 0.025
|
||||
#define CRUMBLER_WIDTH 128
|
||||
#define CRUMBLER_HEALTH_GAME_MULTIPLIER 2
|
||||
#define CRUMBLER_ATTACK_TIMER_MAX_GAME_MULTIPLIER 5
|
||||
#define CRUMBLER_ROWS 1
|
||||
#define CRUMBLER_COLUMNS 2
|
||||
|
||||
void crumbler_init(Enemy* _e, List* _l, Play* _p);
|
||||
void crumbler_set(Enemy* _e, List* _l, f64 _x, f64 _y, Play* _p);
|
||||
void crumbler_update(Enemy* _e, List* _l, Play* _p);
|
151
src/game/play/enemy/cupper.c
Executable file
151
src/game/play/enemy/cupper.c
Executable file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* AI for the "Cupper" enemy.
|
||||
*/
|
||||
|
||||
#include "cupper.h"
|
||||
|
||||
static s32 cupper_health_get(Enemy* _e, List* _l, Play* _p);
|
||||
static s32 cupper_attack_timer_max_get(Enemy* _e, List* _l, Play* _p);
|
||||
|
||||
/* Returns health of a Cupper. */
|
||||
static s32
|
||||
cupper_health_get(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
s32 health;
|
||||
|
||||
health = CUPPER_HEALTH_BASE + ((_p->game - 1) * CUPPER_HEALTH_GAME_MULTIPLIER);
|
||||
|
||||
health = CEIL(health, CUPPER_HEALTH_MAX);
|
||||
|
||||
return health;
|
||||
}
|
||||
|
||||
/* Returns the attack timer max (period in which an attack is performed) of a Cupper. */
|
||||
static s32
|
||||
cupper_attack_timer_max_get(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
s32 attackTimerMax;
|
||||
|
||||
attackTimerMax = CUPPER_ATTACK_TIMER_MAX_BASE - (_p->game * CUPPER_ATTACK_TIMER_MAX_GAME_MULTIPLIER);
|
||||
|
||||
attackTimerMax = FLOOR(attackTimerMax, CUPPER_ATTACK_TIMER_MAX_MIN);
|
||||
|
||||
return attackTimerMax;
|
||||
}
|
||||
|
||||
/* Initializes the Cupper. */
|
||||
void
|
||||
cupper_init(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
Atlas atlas;
|
||||
|
||||
atlas_init
|
||||
(
|
||||
&atlas,
|
||||
_p->g->textures[TEXTURE_ENEMY_CUPPER],
|
||||
CUPPER_ROWS,
|
||||
CUPPER_COLUMNS,
|
||||
CUPPER_WIDTH,
|
||||
CUPPER_HEIGHT
|
||||
);
|
||||
|
||||
sprite_atlas_init
|
||||
(
|
||||
&_e->sprite,
|
||||
&atlas,
|
||||
ORIGIN_MIDDLE,
|
||||
CUPPER_WIDTH,
|
||||
CUPPER_HEIGHT
|
||||
);
|
||||
|
||||
_e->shadow.r = CUPPER_SHADOW_RADIUS;
|
||||
}
|
||||
|
||||
/* Sets the Cupper. */
|
||||
void
|
||||
cupper_set(Enemy* _e, List* _l, f64 _x, f64 _y, Play* _p)
|
||||
{
|
||||
_e->sprite.x = _x;
|
||||
_e->sprite.y = _y;
|
||||
|
||||
_e->shadow.x = _e->sprite.x + CUPPER_SHADOW_OFFSET_X;
|
||||
_e->shadow.y = _e->sprite.y + CUPPER_SHADOW_OFFSET_Y;
|
||||
|
||||
_e->isActive = TRUE;
|
||||
|
||||
_e->health = cupper_health_get(_e, _l, _p);
|
||||
_e->attackTimer = cupper_attack_timer_max_get(_e, _l, _p);
|
||||
}
|
||||
|
||||
/*
|
||||
* Updates Cupper.
|
||||
* Slowly hops towards the player.
|
||||
*/
|
||||
void
|
||||
cupper_update(Enemy* _e, List* _l, Play* _p)
|
||||
{
|
||||
f64 angle;
|
||||
f64 progress;
|
||||
|
||||
_e->attackTimer--;
|
||||
_e->animationTimer--;
|
||||
|
||||
progress = 1 - ((f64)_e->animationTimer / CUPPER_ANIMATION_TIMER_MAX);
|
||||
|
||||
if (_e->animationTimer <= 0)
|
||||
_e->animationTimer = CUPPER_ANIMATION_TIMER_MAX;
|
||||
|
||||
if (_e->isActing)
|
||||
{
|
||||
if (_e->attackTimer <= 0)
|
||||
{
|
||||
_e->dX = 0;
|
||||
_e->dY = 0;
|
||||
_e->isActing = FALSE;
|
||||
_e->attackTimer = cupper_attack_timer_max_get(_e, _l, _p);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_e->attackTimer <= 0)
|
||||
{
|
||||
f64 angle;
|
||||
|
||||
angle = math_atan
|
||||
(
|
||||
_e->shadow.x,
|
||||
_e->shadow.y,
|
||||
_p->player.shadow.x,
|
||||
_p->player.shadow.y
|
||||
);
|
||||
|
||||
_e->dX = -cos(angle) * CUPPER_VELOCITY;
|
||||
_e->dY = -sin(angle) * CUPPER_VELOCITY;
|
||||
|
||||
_e->isActing = TRUE;
|
||||
|
||||
_e->attackTimer = CUPPER_JUMP_TIMER_MAX_BASE;
|
||||
|
||||
if (_p->player.sprite.x < _e->sprite.x)
|
||||
_e->sprite.flip = FLIP_HORIZONTAL;
|
||||
else
|
||||
_e->sprite.flip = FLIP_NONE;
|
||||
|
||||
_e->sprite.frame = 0;
|
||||
}
|
||||
else if (_e->attackTimer <= CUPPER_ATTACK_TIMER_THRESHOLD)
|
||||
_e->sprite.frame = 1;
|
||||
else
|
||||
{
|
||||
_e->sprite.squash = (SPRITE_SQUASH_DEFAULT + cos((ROTATION_MAX_RAD * progress)) * CUPPER_SQUASH_MULTIPLIER);
|
||||
_e->sprite.stretch = (SPRITE_STRETCH_DEFAULT + cos((ROTATION_MAX_RAD * progress)) * CUPPER_STRETCH_MULTIPLIER);
|
||||
}
|
||||
}
|
||||
|
||||
_e->sprite.x += _e->dX;
|
||||
_e->sprite.y += _e->dY;
|
||||
|
||||
_e->shadow.x = _e->sprite.x + CUPPER_SHADOW_OFFSET_X;
|
||||
_e->shadow.y = _e->sprite.y + CUPPER_SHADOW_OFFSET_Y;
|
||||
}
|
33
src/game/play/enemy/cupper.h
Executable file
33
src/game/play/enemy/cupper.h
Executable file
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for cupper.c.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../GAME_COMMON.h"
|
||||
#include "enemy.h"
|
||||
|
||||
#define CUPPER_ANIMATION_TIMER_MAX 30
|
||||
#define CUPPER_ATTACK_TIMER_MAX_BASE 120
|
||||
#define CUPPER_ATTACK_TIMER_MAX_GAME_MULTIPLIER 10
|
||||
#define CUPPER_ATTACK_TIMER_MAX_MIN 30
|
||||
#define CUPPER_ATTACK_TIMER_THRESHOLD 30
|
||||
#define CUPPER_SHADOW_OFFSET_X 0
|
||||
#define CUPPER_SHADOW_OFFSET_Y 16
|
||||
#define CUPPER_SHADOW_RADIUS 24
|
||||
#define CUPPER_COLUMNS 2
|
||||
#define CUPPER_HEALTH_BASE 3
|
||||
#define CUPPER_HEALTH_GAME_MULTIPLIER 2
|
||||
#define CUPPER_HEALTH_MAX 99
|
||||
#define CUPPER_HEIGHT 48
|
||||
#define CUPPER_JUMP_TIMER_MAX_BASE 30
|
||||
#define CUPPER_ROWS 1
|
||||
#define CUPPER_SQUASH_MULTIPLIER 0.05
|
||||
#define CUPPER_STRETCH_MULTIPLIER 0.05
|
||||
#define CUPPER_VELOCITY 3
|
||||
#define CUPPER_WIDTH 48
|
||||
|
||||
void cupper_init(Enemy* _e, List* _l, Play* _p);
|
||||
void cupper_set(Enemy* _e, List* _l, f64 _x, f64 _y, Play* _p);
|
||||
void cupper_update(Enemy* _e, List* _l, Play* _p);
|
95
src/game/play/enemy/enemies.c
Executable file
95
src/game/play/enemy/enemies.c
Executable file
@ -0,0 +1,95 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Game enemies.
|
||||
*/
|
||||
|
||||
#include "enemy.h"
|
||||
|
||||
/* Initializes enemy list. */
|
||||
void
|
||||
enemies_init(List* _l, Play* _p)
|
||||
{
|
||||
list_init(_l);
|
||||
}
|
||||
|
||||
/* Frees enemy list. */
|
||||
void
|
||||
enemies_free(List* _l, Play* _p)
|
||||
{
|
||||
list_free(_l);
|
||||
}
|
||||
|
||||
/* Brutally murders all enemies. */
|
||||
void
|
||||
enemies_defeat(List* _l, Play* _p)
|
||||
{
|
||||
Enemy** enemies;
|
||||
s32 count;
|
||||
|
||||
enemies = (Enemy**)list_data_get(_l);
|
||||
count = _l->count;
|
||||
|
||||
for (s32 i = 0; i < count; i++)
|
||||
{
|
||||
Enemy* e;
|
||||
|
||||
e = enemies[i];
|
||||
|
||||
enemy_defeat(e, _l, _p);
|
||||
}
|
||||
|
||||
free(enemies);
|
||||
}
|
||||
|
||||
/* Updates enemies. */
|
||||
void
|
||||
enemies_update(List* _l, Play* _p)
|
||||
{
|
||||
Enemy** enemies;
|
||||
s32 count;
|
||||
|
||||
enemies = (Enemy**)list_data_get(_l);
|
||||
count = _l->count;
|
||||
|
||||
for (s32 i = 0; i < count; i++)
|
||||
{
|
||||
Enemy* e;
|
||||
|
||||
e = enemies[i];
|
||||
|
||||
enemy_update(e, _l, _p);
|
||||
}
|
||||
|
||||
free(enemies);
|
||||
}
|
||||
|
||||
/* Draws enemies. */
|
||||
void
|
||||
enemies_draw(List* _l, Play* _p)
|
||||
{
|
||||
Enemy** enemies;
|
||||
s32 count;
|
||||
|
||||
enemies = (Enemy**)list_data_get(_l);
|
||||
count = _l->count;
|
||||
|
||||
for (s32 i = 0; i < count; i++)
|
||||
{
|
||||
Enemy* e;
|
||||
|
||||
e = enemies[i];
|
||||
|
||||
shadow_draw(&e->shadow, _p);
|
||||
}
|
||||
|
||||
for (s32 i = 0; i < count; i++)
|
||||
{
|
||||
Enemy* e;
|
||||
|
||||
e = enemies[i];
|
||||
|
||||
sprite_draw(&e->sprite, _p->g->renderer);
|
||||
}
|
||||
|
||||
free(enemies);
|
||||
}
|
15
src/game/play/enemy/enemies.h
Executable file
15
src/game/play/enemy/enemies.h
Executable file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* DESCRIPTION:
|
||||
* Header file for enemy.h
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "enemy.h"
|
||||
#include "../shadow/shadow.h"
|
||||
|
||||
void enemies_init(List* _l, Play* _p);
|
||||
void enemies_free(List* _l, Play* _p);
|
||||
void enemies_update(List* _l, Play* _p);
|
||||
void enemies_defeat(List* _l, Play* _p);
|
||||
void enemies_draw(List* _l, Play* _p);
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user