Compare commits
112 Commits
v1.07
...
2ac425483b
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ac425483b | |||
| fc01676df2 | |||
| e361d295c1 | |||
| f6098a479b | |||
| 7a0bc5c9ae | |||
| 5f68c6256f | |||
| debcc3409e | |||
| c86a6496b3 | |||
| 6bb877b510 | |||
| ec73c5fa30 | |||
| 4dd6c94730 | |||
| e1d6aff724 | |||
| bcb2e96069 | |||
| e23f6b5ed9 | |||
| 9cb57e2ff2 | |||
| cc0f050c50 | |||
| d75a733985 | |||
| 33d91dab55 | |||
| bd6807d655 | |||
| c6d15bb96f | |||
| e20cc3b4bb | |||
| 0baf7e5e2c | |||
| d9d4818d8a | |||
| 944784b329 | |||
| df4c1366fe | |||
| 1ee1ea560b | |||
| 5c7f72253c | |||
| e2e41cf435 | |||
| 674323d445 | |||
| f4e2c11f1b | |||
| 1b130feb85 | |||
| 5f3ecbbd79 | |||
| 250efd69bf | |||
| 7cd5fec3f8 | |||
| 8e612aaa2e | |||
| 2d045642ff | |||
| 01dff96fdc | |||
| 62d1a566c0 | |||
| 39016a3912 | |||
| 866cb56f1b | |||
| 6de3050255 | |||
| f602b5ff7a | |||
| c34b4d8944 | |||
| c835f943b5 | |||
| 9b265c6cca | |||
| 6a526df9b3 | |||
| 3def97bcb8 | |||
| 0a07edcb5c | |||
| 62d90a605f | |||
| d718e20767 | |||
| 20c63c7ef5 | |||
| a68ffa8e21 | |||
| 693939a6d5 | |||
| 031e4b99f4 | |||
| 1a095d292f | |||
| d51d564642 | |||
| bafde2a778 | |||
| 7dcc1d7809 | |||
| 38aadb984d | |||
| e259313cc9 | |||
| c49323cfdf | |||
| 619acbc9b4 | |||
| e39806f1a3 | |||
| e2618f40db | |||
| 97a6ba474f | |||
| 07054544e4 | |||
| 99f6ea7dd4 | |||
| 45b75dc75f | |||
| a4fd00794d | |||
| ee261f4509 | |||
| eb713006c6 | |||
| a07eeff6e4 | |||
| cce0ccba76 | |||
| 0ea7eb0b9c | |||
| 4a2d27dc59 | |||
| 71be364141 | |||
| 16cc725cb3 | |||
| a05dbc7581 | |||
| 2db0b43d23 | |||
| d6c100379e | |||
| 22e8579337 | |||
| d0c0715640 | |||
| 38e0573a0e | |||
| f259fbb3a5 | |||
| 663e1ed32e | |||
| b1887fe6da | |||
| 3fcf3b23e0 | |||
| 284f7d5bad | |||
| adab0b420c | |||
| 4f9d8bec42 | |||
| 31e657d138 | |||
| 8b3d257baf | |||
| d1143b9dfe | |||
| 68ebff722e | |||
| 3be9d4459c | |||
| 76e928e21d | |||
| 9c6924d7bb | |||
| 5007bea835 | |||
| 5e7be1c2fb | |||
| faf2e69b63 | |||
| 4c3c844ccf | |||
| 48b8ae049a | |||
| c0d4eddde7 | |||
| f590101047 | |||
| c7fcbd0258 | |||
| b2061c86d2 | |||
| 510a6ca718 | |||
| ec8209265a | |||
| e963251fd9 | |||
| a2f1efd2a6 | |||
| 8959b7bcce | |||
| 4d8bb46a52 |
5
.gitignore
vendored
@@ -11,3 +11,8 @@ thumbs.db
|
|||||||
*.zip
|
*.zip
|
||||||
*.app
|
*.app
|
||||||
*_debug*
|
*_debug*
|
||||||
|
sync_jail_engine.sh
|
||||||
|
jaildoctors_dilemma*
|
||||||
|
todo
|
||||||
|
build/
|
||||||
|
linux_utils/
|
||||||
85
CMakeLists.txt
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
# CMakeLists.txt
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(jaildoctors_dilemma VERSION 1.00)
|
||||||
|
|
||||||
|
# Configuración de compilador para MinGW en Windows, si es necesario
|
||||||
|
if(WIN32 AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
||||||
|
set(CMAKE_CXX_COMPILER "g++")
|
||||||
|
set(CMAKE_C_COMPILER "gcc")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Establecer estándar de C++
|
||||||
|
set(CMAKE_CXX_STANDARD 20)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
|
||||||
|
# Configuración global de flags de compilación
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Os -ffunction-sections -fdata-sections")
|
||||||
|
|
||||||
|
# Define el directorio de los archivos fuente
|
||||||
|
set(DIR_SOURCES "${CMAKE_SOURCE_DIR}/source")
|
||||||
|
|
||||||
|
# Cargar todos los archivos fuente en DIR_SOURCES
|
||||||
|
file(GLOB SOURCES "${DIR_SOURCES}/*.cpp")
|
||||||
|
|
||||||
|
# Verificar si se encontraron archivos fuente
|
||||||
|
if(NOT SOURCES)
|
||||||
|
message(FATAL_ERROR "No se encontraron archivos fuente en ${DIR_SOURCES}. Verifica que el directorio existe y contiene archivos .cpp.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Configuración de SDL2
|
||||||
|
find_package(SDL2 REQUIRED)
|
||||||
|
if(SDL2_FOUND)
|
||||||
|
message(STATUS "SDL2 encontrado: ${SDL2_INCLUDE_DIRS}")
|
||||||
|
include_directories(${SDL2_INCLUDE_DIRS})
|
||||||
|
link_directories(${SDL2_LIBDIR})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "SDL2 no encontrado")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Incluye rutas de SDL2 obtenidas con pkg-config
|
||||||
|
include_directories(/usr/local/include /usr/local/include/SDL2)
|
||||||
|
link_directories(/usr/local/lib)
|
||||||
|
|
||||||
|
# Definir las bibliotecas comunes
|
||||||
|
set(LIBS SDL2)
|
||||||
|
|
||||||
|
# Configuración común de salida de ejecutables en el directorio raíz
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
# Añadir ejecutable principal
|
||||||
|
add_executable(${PROJECT_NAME} ${SOURCES})
|
||||||
|
|
||||||
|
# Añadir definiciones de compilación dependiendo del tipo de build
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:DEBUG VERBOSE>)
|
||||||
|
|
||||||
|
# Enlazar bibliotecas
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${LIBS})
|
||||||
|
|
||||||
|
# Configuración específica para cada plataforma
|
||||||
|
if(WIN32)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE WINDOWS_BUILD)
|
||||||
|
target_link_libraries(${PROJECT_NAME} mingw32 opengl32 gdi32 winmm imm32 ole32 version)
|
||||||
|
elseif(APPLE)
|
||||||
|
set(LIBS ${LIBS} "-framework OpenGL")
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE MACOS_BUILD)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
|
||||||
|
# Configurar compilación para Apple Silicon
|
||||||
|
set(CMAKE_OSX_ARCHITECTURES "arm64")
|
||||||
|
elseif(UNIX AND NOT APPLE)
|
||||||
|
set(LIBS ${LIBS} GL)
|
||||||
|
target_compile_definitions(${PROJECT_NAME} PRIVATE LINUX_BUILD)
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${LIBS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Añadir OpenGL a las bibliotecas enlazadas
|
||||||
|
if(NOT WIN32)
|
||||||
|
find_package(OpenGL REQUIRED)
|
||||||
|
if(OPENGL_FOUND)
|
||||||
|
message(STATUS "OpenGL encontrado: ${OPENGL_LIBRARIES}")
|
||||||
|
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES})
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "OpenGL no encontrado")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
232
LICENSE.txt
@@ -1,232 +0,0 @@
|
|||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright © 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>.
|
|
||||||
33
Makefile
@@ -1,8 +1,8 @@
|
|||||||
executable = jaildoctors_dilemma
|
executable = jaildoctors_dilemma
|
||||||
source = source/*.cpp source/common/*.cpp
|
source = source/*.cpp
|
||||||
appName = JailDoctor's Dilemma
|
appName = JailDoctor's Dilemma
|
||||||
releaseFolder = jdd_release
|
releaseFolder = jdd_release
|
||||||
version = v1.07
|
version = v1.09
|
||||||
|
|
||||||
# Release names
|
# Release names
|
||||||
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
windowsRelease = $(executable)-$(version)-win32-x64.zip
|
||||||
@@ -10,14 +10,17 @@ macosIntelRelease = $(executable)-$(version)-macos-intel.dmg
|
|||||||
macosAppleSiliconRelease = $(executable)-$(version)-macos-apple-silicon.dmg
|
macosAppleSiliconRelease = $(executable)-$(version)-macos-apple-silicon.dmg
|
||||||
linuxRelease = $(executable)-$(version)-linux.tar.gz
|
linuxRelease = $(executable)-$(version)-linux.tar.gz
|
||||||
|
|
||||||
|
# Specify the C++ standard
|
||||||
|
cpp_standard = c++20
|
||||||
|
|
||||||
windows:
|
windows:
|
||||||
@echo off
|
@echo off
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe"
|
g++ $(source) -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable).exe"
|
||||||
strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(executable).exe" --strip-unneeded
|
||||||
|
|
||||||
windows_debug:
|
windows_debug:
|
||||||
@echo off
|
@echo off
|
||||||
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable)_debug.exe"
|
g++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(executable)_debug.exe"
|
||||||
strip -s -R .comment -R .gnu.version "$(executable)_debug.exe" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(executable)_debug.exe" --strip-unneeded
|
||||||
|
|
||||||
windows_release:
|
windows_release:
|
||||||
@@ -33,12 +36,12 @@ windows_release:
|
|||||||
powershell if (Test-Path "$(releaseFolder)\data\room\standard.tsx") {Remove-Item "$(releaseFolder)\data\room\standard.tsx" -Recurse -Force}
|
powershell if (Test-Path "$(releaseFolder)\data\room\standard.tsx") {Remove-Item "$(releaseFolder)\data\room\standard.tsx" -Recurse -Force}
|
||||||
|
|
||||||
# Copy root files
|
# Copy root files
|
||||||
powershell Copy-Item "LICENSE.txt" -Destination "$(releaseFolder)"
|
powershell Copy-Item "LICENSE" -Destination "$(releaseFolder)"
|
||||||
powershell Copy-Item "README.md" -Destination "$(releaseFolder)"
|
powershell Copy-Item "README.md" -Destination "$(releaseFolder)"
|
||||||
powershell Copy-Item "release\*.dll" -Destination "$(releaseFolder)"
|
powershell Copy-Item "release\*.dll" -Destination "$(releaseFolder)"
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe"
|
g++ $(source) -std=$(cpp_standard) -Wall -Os -lmingw32 -lws2_32 -lSDL2main -lSDL2 -lopengl32 -ffunction-sections -fdata-sections -Wl,--gc-sections -static-libstdc++ -Wl,-subsystem,windows -o "$(releaseFolder)/$(executable).exe"
|
||||||
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable).exe" --strip-unneeded
|
||||||
|
|
||||||
# Create ZIP
|
# Create ZIP
|
||||||
@@ -49,10 +52,10 @@ windows_release:
|
|||||||
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
|
powershell if (Test-Path "$(releaseFolder)") {Remove-Item "$(releaseFolder)" -Recurse -Force}
|
||||||
|
|
||||||
macos:
|
macos:
|
||||||
clang++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)"
|
clang++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(executable)"
|
||||||
|
|
||||||
macos_debug:
|
macos_debug:
|
||||||
clang++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -o "$(executable)_debug"
|
clang++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL2 -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(executable)_debug"
|
||||||
|
|
||||||
macos_release:
|
macos_release:
|
||||||
# Remove data and possible data from previous builds
|
# Remove data and possible data from previous builds
|
||||||
@@ -80,14 +83,14 @@ macos_release:
|
|||||||
# Copy files
|
# Copy files
|
||||||
cp release/*.icns "$(releaseFolder)/$(appName).app/Contents/Resources"
|
cp release/*.icns "$(releaseFolder)/$(appName).app/Contents/Resources"
|
||||||
cp release/Info.plist "$(releaseFolder)/$(appName).app/Contents"
|
cp release/Info.plist "$(releaseFolder)/$(appName).app/Contents"
|
||||||
cp LICENSE.txt "$(releaseFolder)"
|
cp LICENSE "$(releaseFolder)"
|
||||||
cp README.md "$(releaseFolder)"
|
cp README.md "$(releaseFolder)"
|
||||||
|
|
||||||
# Create links
|
# Create links
|
||||||
ln -s /Applications "$(releaseFolder)"/Applications
|
ln -s /Applications "$(releaseFolder)"/Applications
|
||||||
|
|
||||||
# Build INTEL
|
# Build INTEL
|
||||||
clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
|
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target x86_64-apple-macos10.12
|
||||||
|
|
||||||
# Build INTEL DMG
|
# Build INTEL DMG
|
||||||
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
||||||
@@ -95,7 +98,7 @@ macos_release:
|
|||||||
rm -f tmp.dmg
|
rm -f tmp.dmg
|
||||||
|
|
||||||
# Build APPLE SILICON
|
# Build APPLE SILICON
|
||||||
clang++ $(source) -D MACOS_BUNDLE -std=c++11 -Wall -Os -framework SDL2 -F ./Frameworks -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
|
clang++ $(source) -D MACOS_BUNDLE -std=$(cpp_standard) -Wall -Os -framework SDL2 -F ./Frameworks -framework OpenGL -Wno-deprecated -ffunction-sections -fdata-sections -o "$(releaseFolder)/$(appName).app/Contents/MacOS/$(executable)" -rpath @executable_path/../Frameworks/ -target arm64-apple-macos11
|
||||||
|
|
||||||
# Build APPLE SILICON DMG
|
# Build APPLE SILICON DMG
|
||||||
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
hdiutil create tmp.dmg -ov -volname "$(appName)" -fs HFS+ -srcfolder "$(releaseFolder)"
|
||||||
@@ -107,11 +110,11 @@ macos_release:
|
|||||||
rm -rdf "$(releaseFolder)"
|
rm -rdf "$(releaseFolder)"
|
||||||
|
|
||||||
linux:
|
linux:
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
|
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)"
|
||||||
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(executable)" --strip-unneeded
|
||||||
|
|
||||||
linux_debug:
|
linux_debug:
|
||||||
g++ $(source) -D DEBUG -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
|
g++ $(source) -D DEBUG -std=$(cpp_standard) -Wall -Os -lSDL2 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(executable)_debug"
|
||||||
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(executable)_debug" --strip-unneeded
|
||||||
|
|
||||||
linux_release:
|
linux_release:
|
||||||
@@ -123,7 +126,7 @@ linux_release:
|
|||||||
|
|
||||||
# Copy data
|
# Copy data
|
||||||
cp -R data "$(releaseFolder)"
|
cp -R data "$(releaseFolder)"
|
||||||
cp LICENSE.txt "$(releaseFolder)"
|
cp LICENSE "$(releaseFolder)"
|
||||||
cp README.md "$(releaseFolder)"
|
cp README.md "$(releaseFolder)"
|
||||||
|
|
||||||
# Delete data
|
# Delete data
|
||||||
@@ -131,7 +134,7 @@ linux_release:
|
|||||||
rm -f "$(releaseFolder)/data/room/standard.tsx"
|
rm -f "$(releaseFolder)/data/room/standard.tsx"
|
||||||
|
|
||||||
# Build
|
# Build
|
||||||
g++ $(source) -std=c++11 -Wall -Os -lSDL2 -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
|
g++ $(source) -std=$(cpp_standard) -Wall -Os -lSDL2 -lGL -ffunction-sections -fdata-sections -Wl,--gc-sections -o "$(releaseFolder)/$(executable)"
|
||||||
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable)" --strip-unneeded
|
strip -s -R .comment -R .gnu.version "$(releaseFolder)/$(executable)" --strip-unneeded
|
||||||
|
|
||||||
# Pack files
|
# Pack files
|
||||||
|
|||||||
100
README.md
@@ -1,87 +1,65 @@
|
|||||||
# JailDoctor's Dilemma (v1.07)
|
# JailDoctor's Dilemma
|
||||||
|
|
||||||
JailDoc es un Jailer. A los Jailers les gusta empezar proyectos. A nadie le gusta terminarlos. Los Jailers viven en la Jail. A la Jail va uno a empezar proyectos. A la Jail va uno a enseñar sus proyectos. A la Jail va uno a aprender como empezar nuevos proyectos. A la Jail va uno a ayudar a sus compañeros a que empiecen nuevos proyectos.
|
JailDoc és un Jailer. Als Jailers els agrada començar projectes. A ningú li agrada acabar-los. Els Jailers viuen a la Jail. A la Jail s'hi va a començar projectes. A la Jail s'hi va a ensenyar els projectes. A la Jail s'hi va a aprendre com començar nous projectes. A la Jail s'hi va a ajudar els companys a començar nous projectes.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
JailDoc és un Jailer destacat entre els Jailers. Té més projectes començats que ningú i és qui més ajuda als altres a iniciar els seus.
|
||||||
|
|
||||||

|
Però un dia, va passar una cosa inesperada. Algú va acabar un projecte. Algú va alliberar el *Puzzle Jail Facker*. Un autèntic desaprensiu.
|
||||||
|
|
||||||
|
Això va fer que JailDoc prenguera una decisió: acabaria i lliuraria un dels seus projectes. Però, quin? *JailBattle*? *Sigmasuá*? *Calculín Doom*? Quin dilema! Finalment, es va arromangar i va decidir acabar i lliurar **tots** els seus projectes inacabats. Ho aconseguirà?
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
JailDoc es un Jailer destacado entre los Jailers. Tiene más proyectos empezados que nadie y es el que más ayuda a que los demas empiecen los suyos.
|
## Jugabilitat
|
||||||
|
|
||||||
|
Ajuda a JailDoc a recuperar les peces dels seus projectes, que estan escampades per qualsevol racó de l'Univers Jailer. Hi ha més de **150 peces** repartides en **60 pantalles**. Algunes són senzilles, però en altres hauràs de calcular molt bé els teus moviments si no vols acabar com un *arounder* més.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Un día, ocurrió algo. Alguien terminó un proyecto. Alguien liberó el *Puzzle Jail Facker*. Algún desaprensivo.
|
Quan hages recuperat la major part de les peces, dirigeix-te a la Jail per mostrar als Jailers com es finalitza un projecte. Però compte! Bry no et deixarà entrar així com així. Només aquells que han creat un *Fire Effect* o un *Facedor de Tornejos* són dignes d'aquesta fita.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Controls
|
||||||
|
|
||||||
Esto hizo que JailDoc decidiera terminar y entregar uno de sus proyectos, pero, ¿cual? ¿JailBattle? ¿Sigmasuá? ¿Calculín Doom? Menudo dilema. JailDoc se arremangó y decidió finalizar y entregar todos sus proyectos inacabados. ¿Lo logrará?
|
El joc permet tant l'ús del teclat com d'un comandament. Les tecles per a jugar són les següents:
|
||||||
|
|
||||||
|
- **Cursors**: Per moure's a l'esquerra o dreta i per saltar. Es poden modificar les tecles en el fitxer de configuració, triant entre aquestes opcions:
|
||||||
|
- O, P per moure's i Q per saltar.
|
||||||
|
- A, D per moure's i W per saltar.
|
||||||
|
|
||||||
|
- **Tecla M**: Activa o desactiva la música.
|
||||||
|
- **Tecla P**: Pausa el joc.
|
||||||
|
- **Tecla ESC**: Ix del joc si estàs jugant. Tanca el programa en qualsevol altra circumstància.
|
||||||
|
- **Tecla F1**: Disminueix la mida de la finestra.
|
||||||
|
- **Tecla F2**: Augmenta la mida de la finestra.
|
||||||
|
- **Tecla F3**: Alterna entre el mode de pantalla completa i el mode finestra.
|
||||||
|
- **Tecla F4**: Activa o desactiva els shaders
|
||||||
|
- **Tecla F5**: Canvia la paleta de colors del joc.
|
||||||
|
- **Tecla B**: Activa o desactiva el marge de colors en mode finestra.
|
||||||
|
|
||||||
## Jugabilidad
|

|
||||||
|
|
||||||
Ayuda a JailDoc a recuperar las partes de su proyecto que estan desperdigadas por cualquier lugar del Universo Jailer. Hay mas de **150 piezas** desperdigadas por **60 pantallas**. Algunas son un paseo, pero en otras tendras que calcular muy bien tus movimientos si no quieres acabar como un arounder del montón.
|
---
|
||||||
|
|
||||||
|
## Dades del programa
|
||||||
|
|
||||||
|
El programa guarda automàticament la configuració del mode de vídeo i les estadístiques del joc a la teua carpeta personal del sistema. La ubicació d'aquesta carpeta depén del sistema operatiu que utilitzes:
|
||||||
|
|
||||||

|
- **Windows**: `C:\Users\<nom_d'usuari>\AppData\Roaming\jailgames\jaildoctors_dilemma`
|
||||||
|
- **MacOS**: `~/Library/Application Support/jailgames/jaildoctors_dilemma`
|
||||||
|
- **Linux**: `~/.jailgames/jaildoctors_dilemma`
|
||||||
|
|
||||||
|
Dins de la carpeta es troba el fitxer de configuració `config.txt`, on es pot modificar la configuració per connectar-se al servei en línia, i els fitxers `stats.csv` i `stats_buffer.csv`, que contenen informació sobre les estadístiques del joc.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
Cuando consigas recuperar gran parte de las piezas desperdigadas, dirigete a la Jail a mostrar a los Jailers como se termina un proyecto. Ten en cuenta que Bry no te dejará entrar. Solo aquellos que han realizado un *Fire Effect* o un *Facedor de Tornejos* son dignos de tal privilegio.
|
## Agraïments
|
||||||
|
|
||||||
|
Gràcies, com sempre, a tots els Jailers per motivar-me a crear aquest joc i per ajudar-me en els moments de dubte en escriure el codi. I, com sempre, un agraïment especial a JailDoc per la seua unitat de *Jail_Audio* i per qualsevol altre codi, ajuda o ensenyament que haja necessitat per a completar el programa.
|
||||||
|
|
||||||
|
Si no he perdut el compte, aquest és el quart joc que aconseguisc crear.
|
||||||
|
|
||||||
## Controles
|
*13 de novembre de 2022, JailDesigner*
|
||||||
|
|
||||||
El juego permite tanto el uso del teclado como de un mando de control. Las teclas para manejar el juego son las siguientes:
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- **Cursores**: Para mover a izquierda o derecha a JailDoc y para saltar. En el fichero de configuración se pueden cambiar las teclas por otras opciones prefijadas: O, P para moverse y Q para saltar o A, D para moverse y W para saltar.
|
|
||||||
|
|
||||||
- **Tecla M**: Activa o desactiva la música
|
|
||||||
|
|
||||||
- **Tecla P**: Pone en pausa el juego
|
|
||||||
|
|
||||||
- **Tecla ESC**: Sale del juego si estas jugando. Sale del programa en cualquier otra circunstancia
|
|
||||||
|
|
||||||
- **Tecla F**: Cambia a modo de pantalla completa o de ventana
|
|
||||||
|
|
||||||
- **Teclas F1 a F4**: Cambian el tamaño de la ventana
|
|
||||||
|
|
||||||
- **Tecla B**: Activa o desactiva el borde de colores de la pantalla cuando el programa se ejecuta en modo de ventana
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## Datos del programa
|
|
||||||
El programa guarda automáticamente la configuración del modo de video y las estadísticas de juego en tu carpeta personal del sistema. Esta carpeta tiene una ubicación distinta en función del sistema operativo que utilices.
|
|
||||||
|
|
||||||
En **Windows** se encuentra en:
|
|
||||||
`C:\Users\<nombre_de_usuario>\AppData\Roaming\jaildoctors_dilemma`
|
|
||||||
|
|
||||||
En **MacOS** se encuentra en:
|
|
||||||
`~/Library/Application Support/jaildoctors_dilemma`
|
|
||||||
|
|
||||||
En **Linux** se encuentra en:
|
|
||||||
`~/.jaildoctors_dilemma`
|
|
||||||
|
|
||||||
La primera vez, el juego te pregunta por tu identificador online. Esta información se guarda para futuras partidas.
|
|
||||||
|
|
||||||
En la carpeta está el fichero de configuración `config.txt` donde se puede modificar la configuración para conectarse al servicio online y los ficheros `stats.csv` y `stats_buffer.csv` con información de las estadisticas de juego.
|
|
||||||
|
|
||||||
## Agradecimientos
|
|
||||||
|
|
||||||
Agradecimientos como siempre a todos los Jailers por motivarme a hacer el juego y ayudarme en los momentos de duda a la hora de escribir el código. Y, como siempre, en especial a JailDoc por su unidad de Jail_Audio y cualquier otro código/ayuda/enseñanzas que haya necesitado para terminar el programa.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Si no me he descontado, este es el cuarto juego que consigo crear.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
*13 de noviembre de 2022, JailDesigner*
|
|
||||||
|
|||||||
BIN
data/font/gauntlet.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
194
data/font/gauntlet.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
8
|
||||||
|
# box height
|
||||||
|
8
|
||||||
|
# 32 espacio ( )
|
||||||
|
6
|
||||||
|
# 33 !
|
||||||
|
2
|
||||||
|
# 34 "
|
||||||
|
5
|
||||||
|
# 35 #
|
||||||
|
6
|
||||||
|
# 36 $
|
||||||
|
6
|
||||||
|
# 37 %
|
||||||
|
7
|
||||||
|
# 38 &
|
||||||
|
7
|
||||||
|
# 39 '
|
||||||
|
2
|
||||||
|
# 40 (
|
||||||
|
4
|
||||||
|
# 41 )
|
||||||
|
4
|
||||||
|
# 42 *
|
||||||
|
6
|
||||||
|
# 43 +
|
||||||
|
8
|
||||||
|
# 44 ,
|
||||||
|
2
|
||||||
|
# 45 -
|
||||||
|
7
|
||||||
|
# 46 .
|
||||||
|
2
|
||||||
|
# 47 /
|
||||||
|
7
|
||||||
|
# 48 0
|
||||||
|
7
|
||||||
|
# 49 1
|
||||||
|
6
|
||||||
|
# 50 2
|
||||||
|
6
|
||||||
|
# 51 3
|
||||||
|
6
|
||||||
|
# 52 4
|
||||||
|
7
|
||||||
|
# 53 5
|
||||||
|
6
|
||||||
|
# 54 6
|
||||||
|
6
|
||||||
|
# 55 7
|
||||||
|
6
|
||||||
|
# 56 8
|
||||||
|
6
|
||||||
|
# 57 9
|
||||||
|
6
|
||||||
|
# 58 :
|
||||||
|
2
|
||||||
|
# 59 ;
|
||||||
|
2
|
||||||
|
# 60 <
|
||||||
|
5
|
||||||
|
# 61 =
|
||||||
|
6
|
||||||
|
# 62 >
|
||||||
|
5
|
||||||
|
# 63 ?
|
||||||
|
6
|
||||||
|
# 64 @
|
||||||
|
6
|
||||||
|
# 65 A
|
||||||
|
6
|
||||||
|
# 66 B
|
||||||
|
7
|
||||||
|
# 67 C
|
||||||
|
7
|
||||||
|
# 68 D
|
||||||
|
7
|
||||||
|
# 69 E
|
||||||
|
7
|
||||||
|
# 70 F
|
||||||
|
7
|
||||||
|
# 71 G
|
||||||
|
7
|
||||||
|
# 72 H
|
||||||
|
6
|
||||||
|
# 73 I
|
||||||
|
6
|
||||||
|
# 74 J
|
||||||
|
7
|
||||||
|
# 75 K
|
||||||
|
7
|
||||||
|
# 76 L
|
||||||
|
7
|
||||||
|
# 77 M
|
||||||
|
7
|
||||||
|
# 78 N
|
||||||
|
7
|
||||||
|
# 79 O
|
||||||
|
7
|
||||||
|
# 80 P
|
||||||
|
7
|
||||||
|
# 81 Q
|
||||||
|
7
|
||||||
|
# 82 R
|
||||||
|
7
|
||||||
|
# 83 S
|
||||||
|
6
|
||||||
|
# 84 T
|
||||||
|
6
|
||||||
|
# 85 U
|
||||||
|
6
|
||||||
|
# 86 V
|
||||||
|
6
|
||||||
|
# 87 W
|
||||||
|
7
|
||||||
|
# 88 X
|
||||||
|
7
|
||||||
|
# 89 Y
|
||||||
|
6
|
||||||
|
# 90 Z
|
||||||
|
7
|
||||||
|
# 91 [
|
||||||
|
8
|
||||||
|
# 92 \
|
||||||
|
3
|
||||||
|
# 93 ]
|
||||||
|
7
|
||||||
|
# 94 ^
|
||||||
|
7
|
||||||
|
# 95 _
|
||||||
|
8
|
||||||
|
# 96 `
|
||||||
|
0
|
||||||
|
# 97 a
|
||||||
|
6
|
||||||
|
# 98 b
|
||||||
|
7
|
||||||
|
# 99 c
|
||||||
|
7
|
||||||
|
# 100 d
|
||||||
|
7
|
||||||
|
# 101 e
|
||||||
|
7
|
||||||
|
# 102 f
|
||||||
|
7
|
||||||
|
# 103 g
|
||||||
|
7
|
||||||
|
# 104 h
|
||||||
|
6
|
||||||
|
# 105 i
|
||||||
|
6
|
||||||
|
# 106 j
|
||||||
|
7
|
||||||
|
# 107 k
|
||||||
|
7
|
||||||
|
# 108 l
|
||||||
|
7
|
||||||
|
# 109 m
|
||||||
|
7
|
||||||
|
# 110 n
|
||||||
|
7
|
||||||
|
# 111 o
|
||||||
|
7
|
||||||
|
# 112 p
|
||||||
|
7
|
||||||
|
# 113 q
|
||||||
|
7
|
||||||
|
# 114 r
|
||||||
|
7
|
||||||
|
# 115 s
|
||||||
|
6
|
||||||
|
# 116 t
|
||||||
|
6
|
||||||
|
# 117 u
|
||||||
|
6
|
||||||
|
# 118 v
|
||||||
|
6
|
||||||
|
# 119 w
|
||||||
|
7
|
||||||
|
# 120 x
|
||||||
|
7
|
||||||
|
# 121 y
|
||||||
|
6
|
||||||
|
# 122 z
|
||||||
|
7
|
||||||
|
# 123 {
|
||||||
|
0
|
||||||
|
# 124 |
|
||||||
|
0
|
||||||
|
# 125 }
|
||||||
|
0
|
||||||
|
# 126 ~
|
||||||
|
0
|
||||||
BIN
data/font/subatomic.png
Normal file
|
After Width: | Height: | Size: 902 B |
194
data/font/subatomic.txt
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
# box width
|
||||||
|
7
|
||||||
|
# box height
|
||||||
|
7
|
||||||
|
# 32 espacio ( )
|
||||||
|
4
|
||||||
|
# 33 !
|
||||||
|
1
|
||||||
|
# 34 "
|
||||||
|
3
|
||||||
|
# 35 #
|
||||||
|
5
|
||||||
|
# 36 $
|
||||||
|
5
|
||||||
|
# 37 %
|
||||||
|
5
|
||||||
|
# 38 &
|
||||||
|
6
|
||||||
|
# 39 '
|
||||||
|
1
|
||||||
|
# 40 (
|
||||||
|
2
|
||||||
|
# 41 )
|
||||||
|
2
|
||||||
|
# 42 *
|
||||||
|
5
|
||||||
|
# 43 +
|
||||||
|
5
|
||||||
|
# 44 ,
|
||||||
|
1
|
||||||
|
# 45 -
|
||||||
|
5
|
||||||
|
# 46 .
|
||||||
|
1
|
||||||
|
# 47 /
|
||||||
|
5
|
||||||
|
# 48 0
|
||||||
|
5
|
||||||
|
# 49 1
|
||||||
|
2
|
||||||
|
# 50 2
|
||||||
|
5
|
||||||
|
# 51 3
|
||||||
|
5
|
||||||
|
# 52 4
|
||||||
|
5
|
||||||
|
# 53 5
|
||||||
|
5
|
||||||
|
# 54 6
|
||||||
|
5
|
||||||
|
# 55 7
|
||||||
|
5
|
||||||
|
# 56 8
|
||||||
|
5
|
||||||
|
# 57 9
|
||||||
|
5
|
||||||
|
# 58 :
|
||||||
|
1
|
||||||
|
# 59 ;
|
||||||
|
2
|
||||||
|
# 60 <
|
||||||
|
3
|
||||||
|
# 61 =
|
||||||
|
5
|
||||||
|
# 62 >
|
||||||
|
3
|
||||||
|
# 63 ?
|
||||||
|
4
|
||||||
|
# 64 @
|
||||||
|
5
|
||||||
|
# 65 A
|
||||||
|
5
|
||||||
|
# 66 B
|
||||||
|
5
|
||||||
|
# 67 C
|
||||||
|
5
|
||||||
|
# 68 D
|
||||||
|
5
|
||||||
|
# 69 E
|
||||||
|
4
|
||||||
|
# 70 F
|
||||||
|
5
|
||||||
|
# 71 G
|
||||||
|
5
|
||||||
|
# 72 H
|
||||||
|
5
|
||||||
|
# 73 I
|
||||||
|
1
|
||||||
|
# 74 J
|
||||||
|
5
|
||||||
|
# 75 K
|
||||||
|
5
|
||||||
|
# 76 L
|
||||||
|
2
|
||||||
|
# 77 M
|
||||||
|
5
|
||||||
|
# 78 N
|
||||||
|
5
|
||||||
|
# 79 O
|
||||||
|
5
|
||||||
|
# 80 P
|
||||||
|
5
|
||||||
|
# 81 Q
|
||||||
|
5
|
||||||
|
# 82 R
|
||||||
|
5
|
||||||
|
# 83 S
|
||||||
|
5
|
||||||
|
# 84 T
|
||||||
|
5
|
||||||
|
# 85 U
|
||||||
|
5
|
||||||
|
# 86 V
|
||||||
|
5
|
||||||
|
# 87 W
|
||||||
|
5
|
||||||
|
# 88 X
|
||||||
|
5
|
||||||
|
# 89 Y
|
||||||
|
5
|
||||||
|
# 90 Z
|
||||||
|
5
|
||||||
|
# 91 [
|
||||||
|
2
|
||||||
|
# 92 \
|
||||||
|
5
|
||||||
|
# 93 ]
|
||||||
|
2
|
||||||
|
# 94 ^
|
||||||
|
3
|
||||||
|
# 95 _
|
||||||
|
5
|
||||||
|
# 96 `
|
||||||
|
2
|
||||||
|
# 97 a
|
||||||
|
4
|
||||||
|
# 98 b
|
||||||
|
4
|
||||||
|
# 99 c
|
||||||
|
3
|
||||||
|
# 100 d
|
||||||
|
4
|
||||||
|
# 101 e
|
||||||
|
4
|
||||||
|
# 102 f
|
||||||
|
3
|
||||||
|
# 103 g
|
||||||
|
4
|
||||||
|
# 104 h
|
||||||
|
4
|
||||||
|
# 105 i
|
||||||
|
1
|
||||||
|
# 106 j
|
||||||
|
2
|
||||||
|
# 107 k
|
||||||
|
3
|
||||||
|
# 108 l
|
||||||
|
1
|
||||||
|
# 109 m
|
||||||
|
5
|
||||||
|
# 110 n
|
||||||
|
4
|
||||||
|
# 111 o
|
||||||
|
4
|
||||||
|
# 112 p
|
||||||
|
4
|
||||||
|
# 113 q
|
||||||
|
4
|
||||||
|
# 114 r
|
||||||
|
3
|
||||||
|
# 115 s
|
||||||
|
4
|
||||||
|
# 116 t
|
||||||
|
2
|
||||||
|
# 117 u
|
||||||
|
4
|
||||||
|
# 118 v
|
||||||
|
4
|
||||||
|
# 119 w
|
||||||
|
5
|
||||||
|
# 120 x
|
||||||
|
3
|
||||||
|
# 121 y
|
||||||
|
4
|
||||||
|
# 122 z
|
||||||
|
4
|
||||||
|
# 123 {
|
||||||
|
0
|
||||||
|
# 124 |
|
||||||
|
0
|
||||||
|
# 125 }
|
||||||
|
0
|
||||||
|
# 126 ~
|
||||||
|
0
|
||||||
BIN
data/notifications/notify.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
234
data/shaders/crtpi_192.glsl
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
/*
|
||||||
|
crt-pi - A Raspberry Pi friendly CRT shader.
|
||||||
|
|
||||||
|
Copyright (C) 2015-2016 davej
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the Free
|
||||||
|
Software Foundation; either version 2 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
This shader is designed to work well on Raspberry Pi GPUs (i.e. 1080P @ 60Hz on a game with a 4:3 aspect ratio). It pushes the Pi's GPU hard and enabling some features will slow it down so that it is no longer able to match 1080P @ 60Hz. You will need to overclock your Pi to the fastest setting in raspi-config to get the best results from this shader: 'Pi2' for Pi2 and 'Turbo' for original Pi and Pi Zero. Note: Pi2s are slower at running the shader than other Pis, this seems to be down to Pi2s lower maximum memory speed. Pi2s don't quite manage 1080P @ 60Hz - they drop about 1 in 1000 frames. You probably won't notice this, but if you do, try enabling FAKE_GAMMA.
|
||||||
|
|
||||||
|
SCANLINES enables scanlines. You'll almost certainly want to use it with MULTISAMPLE to reduce moire effects. SCANLINE_WEIGHT defines how wide scanlines are (it is an inverse value so a higher number = thinner lines). SCANLINE_GAP_BRIGHTNESS defines how dark the gaps between the scan lines are. Darker gaps between scan lines make moire effects more likely.
|
||||||
|
|
||||||
|
GAMMA enables gamma correction using the values in INPUT_GAMMA and OUTPUT_GAMMA. FAKE_GAMMA causes it to ignore the values in INPUT_GAMMA and OUTPUT_GAMMA and approximate gamma correction in a way which is faster than true gamma whilst still looking better than having none. You must have GAMMA defined to enable FAKE_GAMMA.
|
||||||
|
|
||||||
|
CURVATURE distorts the screen by CURVATURE_X and CURVATURE_Y. Curvature slows things down a lot.
|
||||||
|
|
||||||
|
By default the shader uses linear blending horizontally. If you find this too blury, enable SHARPER.
|
||||||
|
|
||||||
|
BLOOM_FACTOR controls the increase in width for bright scanlines.
|
||||||
|
|
||||||
|
MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how much the mask type darkens the screen.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma parameter CURVATURE_X "Screen curvature - horizontal" 0.10 0.0 1.0 0.01
|
||||||
|
#pragma parameter CURVATURE_Y "Screen curvature - vertical" 0.15 0.0 1.0 0.01
|
||||||
|
#pragma parameter MASK_BRIGHTNESS "Mask brightness" 0.70 0.0 1.0 0.01
|
||||||
|
#pragma parameter SCANLINE_WEIGHT "Scanline weight" 6.0 0.0 15.0 0.1
|
||||||
|
#pragma parameter SCANLINE_GAP_BRIGHTNESS "Scanline gap brightness" 0.12 0.0 1.0 0.01
|
||||||
|
#pragma parameter BLOOM_FACTOR "Bloom factor" 1.5 0.0 5.0 0.01
|
||||||
|
#pragma parameter INPUT_GAMMA "Input gamma" 2.4 0.0 5.0 0.01
|
||||||
|
#pragma parameter OUTPUT_GAMMA "Output gamma" 2.2 0.0 5.0 0.01
|
||||||
|
|
||||||
|
// Haven't put these as parameters as it would slow the code down.
|
||||||
|
#define SCANLINES
|
||||||
|
#define MULTISAMPLE
|
||||||
|
#define GAMMA
|
||||||
|
//#define FAKE_GAMMA
|
||||||
|
//#define CURVATURE
|
||||||
|
//#define SHARPER
|
||||||
|
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
|
||||||
|
#define MASK_TYPE 2
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef GL_ES
|
||||||
|
#define COMPAT_PRECISION mediump
|
||||||
|
precision mediump float;
|
||||||
|
#else
|
||||||
|
#define COMPAT_PRECISION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PARAMETER_UNIFORM
|
||||||
|
uniform COMPAT_PRECISION float CURVATURE_X;
|
||||||
|
uniform COMPAT_PRECISION float CURVATURE_Y;
|
||||||
|
uniform COMPAT_PRECISION float MASK_BRIGHTNESS;
|
||||||
|
uniform COMPAT_PRECISION float SCANLINE_WEIGHT;
|
||||||
|
uniform COMPAT_PRECISION float SCANLINE_GAP_BRIGHTNESS;
|
||||||
|
uniform COMPAT_PRECISION float BLOOM_FACTOR;
|
||||||
|
uniform COMPAT_PRECISION float INPUT_GAMMA;
|
||||||
|
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
|
||||||
|
#else
|
||||||
|
#define CURVATURE_X 0.05
|
||||||
|
#define CURVATURE_Y 0.1
|
||||||
|
#define MASK_BRIGHTNESS 0.80
|
||||||
|
#define SCANLINE_WEIGHT 6.0
|
||||||
|
#define SCANLINE_GAP_BRIGHTNESS 0.12
|
||||||
|
#define BLOOM_FACTOR 3.5
|
||||||
|
#define INPUT_GAMMA 2.4
|
||||||
|
#define OUTPUT_GAMMA 2.2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* COMPATIBILITY
|
||||||
|
- GLSL compilers
|
||||||
|
*/
|
||||||
|
|
||||||
|
//uniform vec2 TextureSize;
|
||||||
|
#if defined(CURVATURE)
|
||||||
|
varying vec2 screenScale;
|
||||||
|
#endif
|
||||||
|
varying vec2 TEX0;
|
||||||
|
varying float filterWidth;
|
||||||
|
|
||||||
|
#if defined(VERTEX)
|
||||||
|
//uniform mat4 MVPMatrix;
|
||||||
|
//attribute vec4 VertexCoord;
|
||||||
|
//attribute vec2 TexCoord;
|
||||||
|
//uniform vec2 InputSize;
|
||||||
|
//uniform vec2 OutputSize;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
#if defined(CURVATURE)
|
||||||
|
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
||||||
|
#endif
|
||||||
|
filterWidth = (768.0 / 192.0) / 3.0;
|
||||||
|
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
|
||||||
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||||
|
}
|
||||||
|
#elif defined(FRAGMENT)
|
||||||
|
|
||||||
|
uniform sampler2D Texture;
|
||||||
|
|
||||||
|
#if defined(CURVATURE)
|
||||||
|
vec2 Distort(vec2 coord)
|
||||||
|
{
|
||||||
|
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
|
||||||
|
// Barrel distortion shrinks the display area a bit, this will allow us to counteract that.
|
||||||
|
vec2 barrelScale = 1.0 - (0.23 * CURVATURE_DISTORTION);
|
||||||
|
coord *= screenScale;
|
||||||
|
coord -= vec2(0.5);
|
||||||
|
float rsq = coord.x * coord.x + coord.y * coord.y;
|
||||||
|
coord += coord * (CURVATURE_DISTORTION * rsq);
|
||||||
|
coord *= barrelScale;
|
||||||
|
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
|
||||||
|
coord = vec2(-1.0); // If out of bounds, return an invalid value.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
coord += vec2(0.5);
|
||||||
|
coord /= screenScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
return coord;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float CalcScanLineWeight(float dist)
|
||||||
|
{
|
||||||
|
return max(1.0-dist*dist*SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
float CalcScanLine(float dy)
|
||||||
|
{
|
||||||
|
float scanLineWeight = CalcScanLineWeight(dy);
|
||||||
|
#if defined(MULTISAMPLE)
|
||||||
|
scanLineWeight += CalcScanLineWeight(dy-filterWidth);
|
||||||
|
scanLineWeight += CalcScanLineWeight(dy+filterWidth);
|
||||||
|
scanLineWeight *= 0.3333333;
|
||||||
|
#endif
|
||||||
|
return scanLineWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 TextureSize = vec2(256.0, 192.0);
|
||||||
|
#if defined(CURVATURE)
|
||||||
|
vec2 texcoord = Distort(TEX0);
|
||||||
|
if (texcoord.x < 0.0)
|
||||||
|
gl_FragColor = vec4(0.0);
|
||||||
|
else
|
||||||
|
#else
|
||||||
|
vec2 texcoord = TEX0;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
vec2 texcoordInPixels = texcoord * TextureSize;
|
||||||
|
#if defined(SHARPER)
|
||||||
|
vec2 tempCoord = floor(texcoordInPixels) + 0.5;
|
||||||
|
vec2 coord = tempCoord / TextureSize;
|
||||||
|
vec2 deltas = texcoordInPixels - tempCoord;
|
||||||
|
float scanLineWeight = CalcScanLine(deltas.y);
|
||||||
|
vec2 signs = sign(deltas);
|
||||||
|
deltas.x *= 2.0;
|
||||||
|
deltas = deltas * deltas;
|
||||||
|
deltas.y = deltas.y * deltas.y;
|
||||||
|
deltas.x *= 0.5;
|
||||||
|
deltas.y *= 8.0;
|
||||||
|
deltas /= TextureSize;
|
||||||
|
deltas *= signs;
|
||||||
|
vec2 tc = coord + deltas;
|
||||||
|
#else
|
||||||
|
float tempY = floor(texcoordInPixels.y) + 0.5;
|
||||||
|
float yCoord = tempY / TextureSize.y;
|
||||||
|
float dy = texcoordInPixels.y - tempY;
|
||||||
|
float scanLineWeight = CalcScanLine(dy);
|
||||||
|
float signY = sign(dy);
|
||||||
|
dy = dy * dy;
|
||||||
|
dy = dy * dy;
|
||||||
|
dy *= 8.0;
|
||||||
|
dy /= TextureSize.y;
|
||||||
|
dy *= signY;
|
||||||
|
vec2 tc = vec2(texcoord.x, yCoord + dy);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vec3 colour = texture2D(Texture, tc).rgb;
|
||||||
|
|
||||||
|
#if defined(SCANLINES)
|
||||||
|
#if defined(GAMMA)
|
||||||
|
#if defined(FAKE_GAMMA)
|
||||||
|
colour = colour * colour;
|
||||||
|
#else
|
||||||
|
colour = pow(colour, vec3(INPUT_GAMMA));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
scanLineWeight *= BLOOM_FACTOR;
|
||||||
|
colour *= scanLineWeight;
|
||||||
|
|
||||||
|
#if defined(GAMMA)
|
||||||
|
#if defined(FAKE_GAMMA)
|
||||||
|
colour = sqrt(colour);
|
||||||
|
#else
|
||||||
|
colour = pow(colour, vec3(1.0/OUTPUT_GAMMA));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if MASK_TYPE == 0
|
||||||
|
gl_FragColor = vec4(colour, 1.0);
|
||||||
|
#else
|
||||||
|
#if MASK_TYPE == 1
|
||||||
|
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.5);
|
||||||
|
vec3 mask;
|
||||||
|
if (whichMask < 0.5)
|
||||||
|
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
|
||||||
|
else
|
||||||
|
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
|
||||||
|
#elif MASK_TYPE == 2
|
||||||
|
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.3333333);
|
||||||
|
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
|
||||||
|
if (whichMask < 0.3333333)
|
||||||
|
mask.x = 1.0;
|
||||||
|
else if (whichMask < 0.6666666)
|
||||||
|
mask.y = 1.0;
|
||||||
|
else
|
||||||
|
mask.z = 1.0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gl_FragColor = vec4(colour * mask, 1.0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
234
data/shaders/crtpi_240.glsl
Normal file
@@ -0,0 +1,234 @@
|
|||||||
|
/*
|
||||||
|
crt-pi - A Raspberry Pi friendly CRT shader.
|
||||||
|
|
||||||
|
Copyright (C) 2015-2016 davej
|
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or modify it
|
||||||
|
under the terms of the GNU General Public License as published by the Free
|
||||||
|
Software Foundation; either version 2 of the License, or (at your option)
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
This shader is designed to work well on Raspberry Pi GPUs (i.e. 1080P @ 60Hz on a game with a 4:3 aspect ratio). It pushes the Pi's GPU hard and enabling some features will slow it down so that it is no longer able to match 1080P @ 60Hz. You will need to overclock your Pi to the fastest setting in raspi-config to get the best results from this shader: 'Pi2' for Pi2 and 'Turbo' for original Pi and Pi Zero. Note: Pi2s are slower at running the shader than other Pis, this seems to be down to Pi2s lower maximum memory speed. Pi2s don't quite manage 1080P @ 60Hz - they drop about 1 in 1000 frames. You probably won't notice this, but if you do, try enabling FAKE_GAMMA.
|
||||||
|
|
||||||
|
SCANLINES enables scanlines. You'll almost certainly want to use it with MULTISAMPLE to reduce moire effects. SCANLINE_WEIGHT defines how wide scanlines are (it is an inverse value so a higher number = thinner lines). SCANLINE_GAP_BRIGHTNESS defines how dark the gaps between the scan lines are. Darker gaps between scan lines make moire effects more likely.
|
||||||
|
|
||||||
|
GAMMA enables gamma correction using the values in INPUT_GAMMA and OUTPUT_GAMMA. FAKE_GAMMA causes it to ignore the values in INPUT_GAMMA and OUTPUT_GAMMA and approximate gamma correction in a way which is faster than true gamma whilst still looking better than having none. You must have GAMMA defined to enable FAKE_GAMMA.
|
||||||
|
|
||||||
|
CURVATURE distorts the screen by CURVATURE_X and CURVATURE_Y. Curvature slows things down a lot.
|
||||||
|
|
||||||
|
By default the shader uses linear blending horizontally. If you find this too blury, enable SHARPER.
|
||||||
|
|
||||||
|
BLOOM_FACTOR controls the increase in width for bright scanlines.
|
||||||
|
|
||||||
|
MASK_TYPE defines what, if any, shadow mask to use. MASK_BRIGHTNESS defines how much the mask type darkens the screen.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma parameter CURVATURE_X "Screen curvature - horizontal" 0.10 0.0 1.0 0.01
|
||||||
|
#pragma parameter CURVATURE_Y "Screen curvature - vertical" 0.15 0.0 1.0 0.01
|
||||||
|
#pragma parameter MASK_BRIGHTNESS "Mask brightness" 0.70 0.0 1.0 0.01
|
||||||
|
#pragma parameter SCANLINE_WEIGHT "Scanline weight" 6.0 0.0 15.0 0.1
|
||||||
|
#pragma parameter SCANLINE_GAP_BRIGHTNESS "Scanline gap brightness" 0.12 0.0 1.0 0.01
|
||||||
|
#pragma parameter BLOOM_FACTOR "Bloom factor" 1.5 0.0 5.0 0.01
|
||||||
|
#pragma parameter INPUT_GAMMA "Input gamma" 2.4 0.0 5.0 0.01
|
||||||
|
#pragma parameter OUTPUT_GAMMA "Output gamma" 2.2 0.0 5.0 0.01
|
||||||
|
|
||||||
|
// Haven't put these as parameters as it would slow the code down.
|
||||||
|
#define SCANLINES
|
||||||
|
#define MULTISAMPLE
|
||||||
|
#define GAMMA
|
||||||
|
//#define FAKE_GAMMA
|
||||||
|
//#define CURVATURE
|
||||||
|
//#define SHARPER
|
||||||
|
// MASK_TYPE: 0 = none, 1 = green/magenta, 2 = trinitron(ish)
|
||||||
|
#define MASK_TYPE 2
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef GL_ES
|
||||||
|
#define COMPAT_PRECISION mediump
|
||||||
|
precision mediump float;
|
||||||
|
#else
|
||||||
|
#define COMPAT_PRECISION
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef PARAMETER_UNIFORM
|
||||||
|
uniform COMPAT_PRECISION float CURVATURE_X;
|
||||||
|
uniform COMPAT_PRECISION float CURVATURE_Y;
|
||||||
|
uniform COMPAT_PRECISION float MASK_BRIGHTNESS;
|
||||||
|
uniform COMPAT_PRECISION float SCANLINE_WEIGHT;
|
||||||
|
uniform COMPAT_PRECISION float SCANLINE_GAP_BRIGHTNESS;
|
||||||
|
uniform COMPAT_PRECISION float BLOOM_FACTOR;
|
||||||
|
uniform COMPAT_PRECISION float INPUT_GAMMA;
|
||||||
|
uniform COMPAT_PRECISION float OUTPUT_GAMMA;
|
||||||
|
#else
|
||||||
|
#define CURVATURE_X 0.05
|
||||||
|
#define CURVATURE_Y 0.1
|
||||||
|
#define MASK_BRIGHTNESS 0.80
|
||||||
|
#define SCANLINE_WEIGHT 6.0
|
||||||
|
#define SCANLINE_GAP_BRIGHTNESS 0.12
|
||||||
|
#define BLOOM_FACTOR 3.5
|
||||||
|
#define INPUT_GAMMA 2.4
|
||||||
|
#define OUTPUT_GAMMA 2.2
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* COMPATIBILITY
|
||||||
|
- GLSL compilers
|
||||||
|
*/
|
||||||
|
|
||||||
|
//uniform vec2 TextureSize;
|
||||||
|
#if defined(CURVATURE)
|
||||||
|
varying vec2 screenScale;
|
||||||
|
#endif
|
||||||
|
varying vec2 TEX0;
|
||||||
|
varying float filterWidth;
|
||||||
|
|
||||||
|
#if defined(VERTEX)
|
||||||
|
//uniform mat4 MVPMatrix;
|
||||||
|
//attribute vec4 VertexCoord;
|
||||||
|
//attribute vec2 TexCoord;
|
||||||
|
//uniform vec2 InputSize;
|
||||||
|
//uniform vec2 OutputSize;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
#if defined(CURVATURE)
|
||||||
|
screenScale = vec2(1.0, 1.0); //TextureSize / InputSize;
|
||||||
|
#endif
|
||||||
|
filterWidth = (768.0 / 240.0) / 3.0;
|
||||||
|
TEX0 = vec2(gl_MultiTexCoord0.x, 1.0-gl_MultiTexCoord0.y)*1.0001;
|
||||||
|
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||||
|
}
|
||||||
|
#elif defined(FRAGMENT)
|
||||||
|
|
||||||
|
uniform sampler2D Texture;
|
||||||
|
|
||||||
|
#if defined(CURVATURE)
|
||||||
|
vec2 Distort(vec2 coord)
|
||||||
|
{
|
||||||
|
vec2 CURVATURE_DISTORTION = vec2(CURVATURE_X, CURVATURE_Y);
|
||||||
|
// Barrel distortion shrinks the display area a bit, this will allow us to counteract that.
|
||||||
|
vec2 barrelScale = 1.0 - (0.23 * CURVATURE_DISTORTION);
|
||||||
|
coord *= screenScale;
|
||||||
|
coord -= vec2(0.5);
|
||||||
|
float rsq = coord.x * coord.x + coord.y * coord.y;
|
||||||
|
coord += coord * (CURVATURE_DISTORTION * rsq);
|
||||||
|
coord *= barrelScale;
|
||||||
|
if (abs(coord.x) >= 0.5 || abs(coord.y) >= 0.5)
|
||||||
|
coord = vec2(-1.0); // If out of bounds, return an invalid value.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
coord += vec2(0.5);
|
||||||
|
coord /= screenScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
return coord;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
float CalcScanLineWeight(float dist)
|
||||||
|
{
|
||||||
|
return max(1.0-dist*dist*SCANLINE_WEIGHT, SCANLINE_GAP_BRIGHTNESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
float CalcScanLine(float dy)
|
||||||
|
{
|
||||||
|
float scanLineWeight = CalcScanLineWeight(dy);
|
||||||
|
#if defined(MULTISAMPLE)
|
||||||
|
scanLineWeight += CalcScanLineWeight(dy-filterWidth);
|
||||||
|
scanLineWeight += CalcScanLineWeight(dy+filterWidth);
|
||||||
|
scanLineWeight *= 0.3333333;
|
||||||
|
#endif
|
||||||
|
return scanLineWeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec2 TextureSize = vec2(320.0, 240.0);
|
||||||
|
#if defined(CURVATURE)
|
||||||
|
vec2 texcoord = Distort(TEX0);
|
||||||
|
if (texcoord.x < 0.0)
|
||||||
|
gl_FragColor = vec4(0.0);
|
||||||
|
else
|
||||||
|
#else
|
||||||
|
vec2 texcoord = TEX0;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
vec2 texcoordInPixels = texcoord * TextureSize;
|
||||||
|
#if defined(SHARPER)
|
||||||
|
vec2 tempCoord = floor(texcoordInPixels) + 0.5;
|
||||||
|
vec2 coord = tempCoord / TextureSize;
|
||||||
|
vec2 deltas = texcoordInPixels - tempCoord;
|
||||||
|
float scanLineWeight = CalcScanLine(deltas.y);
|
||||||
|
vec2 signs = sign(deltas);
|
||||||
|
deltas.x *= 2.0;
|
||||||
|
deltas = deltas * deltas;
|
||||||
|
deltas.y = deltas.y * deltas.y;
|
||||||
|
deltas.x *= 0.5;
|
||||||
|
deltas.y *= 8.0;
|
||||||
|
deltas /= TextureSize;
|
||||||
|
deltas *= signs;
|
||||||
|
vec2 tc = coord + deltas;
|
||||||
|
#else
|
||||||
|
float tempY = floor(texcoordInPixels.y) + 0.5;
|
||||||
|
float yCoord = tempY / TextureSize.y;
|
||||||
|
float dy = texcoordInPixels.y - tempY;
|
||||||
|
float scanLineWeight = CalcScanLine(dy);
|
||||||
|
float signY = sign(dy);
|
||||||
|
dy = dy * dy;
|
||||||
|
dy = dy * dy;
|
||||||
|
dy *= 8.0;
|
||||||
|
dy /= TextureSize.y;
|
||||||
|
dy *= signY;
|
||||||
|
vec2 tc = vec2(texcoord.x, yCoord + dy);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
vec3 colour = texture2D(Texture, tc).rgb;
|
||||||
|
|
||||||
|
#if defined(SCANLINES)
|
||||||
|
#if defined(GAMMA)
|
||||||
|
#if defined(FAKE_GAMMA)
|
||||||
|
colour = colour * colour;
|
||||||
|
#else
|
||||||
|
colour = pow(colour, vec3(INPUT_GAMMA));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
scanLineWeight *= BLOOM_FACTOR;
|
||||||
|
colour *= scanLineWeight;
|
||||||
|
|
||||||
|
#if defined(GAMMA)
|
||||||
|
#if defined(FAKE_GAMMA)
|
||||||
|
colour = sqrt(colour);
|
||||||
|
#else
|
||||||
|
colour = pow(colour, vec3(1.0/OUTPUT_GAMMA));
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
#if MASK_TYPE == 0
|
||||||
|
gl_FragColor = vec4(colour, 1.0);
|
||||||
|
#else
|
||||||
|
#if MASK_TYPE == 1
|
||||||
|
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.5);
|
||||||
|
vec3 mask;
|
||||||
|
if (whichMask < 0.5)
|
||||||
|
mask = vec3(MASK_BRIGHTNESS, 1.0, MASK_BRIGHTNESS);
|
||||||
|
else
|
||||||
|
mask = vec3(1.0, MASK_BRIGHTNESS, 1.0);
|
||||||
|
#elif MASK_TYPE == 2
|
||||||
|
float whichMask = fract((gl_FragCoord.x*1.0001) * 0.3333333);
|
||||||
|
vec3 mask = vec3(MASK_BRIGHTNESS, MASK_BRIGHTNESS, MASK_BRIGHTNESS);
|
||||||
|
if (whichMask < 0.3333333)
|
||||||
|
mask.x = 1.0;
|
||||||
|
else if (whichMask < 0.6666666)
|
||||||
|
mask.y = 1.0;
|
||||||
|
else
|
||||||
|
mask.z = 1.0;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
gl_FragColor = vec4(colour * mask, 1.0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 6.9 KiB |
|
Before Width: | Height: | Size: 4.7 KiB After Width: | Height: | Size: 7.1 KiB |
BIN
data/title/loading_screen_color.gif
Normal file
|
After Width: | Height: | Size: 4.5 KiB |
|
Before Width: | Height: | Size: 6.3 KiB After Width: | Height: | Size: 5.4 KiB |
|
Before Width: | Height: | Size: 6.5 KiB After Width: | Height: | Size: 8.9 KiB |
BIN
data/title/title_logo.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
@@ -11,9 +11,9 @@
|
|||||||
<key>CFBundleExecutable</key>
|
<key>CFBundleExecutable</key>
|
||||||
<string>jaildoctors_dilemma</string>
|
<string>jaildoctors_dilemma</string>
|
||||||
<key>CFBundleIconFile</key>
|
<key>CFBundleIconFile</key>
|
||||||
<string>jaildoctors_dilemma</string>
|
<string>icon</string>
|
||||||
<key>CFBundleIconName</key>
|
<key>CFBundleIconName</key>
|
||||||
<string>jaildoctors_dilemma</string>
|
<string>icon</string>
|
||||||
<key>CFBundleIdentifier</key>
|
<key>CFBundleIdentifier</key>
|
||||||
<string>org.jailgames.jaildoctors_dilemma</string>
|
<string>org.jailgames.jaildoctors_dilemma</string>
|
||||||
<key>CFBundleInfoDictionaryVersion</key>
|
<key>CFBundleInfoDictionaryVersion</key>
|
||||||
@@ -23,11 +23,11 @@
|
|||||||
<key>CFBundlePackageType</key>
|
<key>CFBundlePackageType</key>
|
||||||
<string>APPL</string>
|
<string>APPL</string>
|
||||||
<key>CFBundleShortVersionString</key>
|
<key>CFBundleShortVersionString</key>
|
||||||
<string>1.0.7</string>
|
<string>1.09</string>
|
||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>1.0.7</string>
|
<string>1.09</string>
|
||||||
<key>CSResourcesFileMapped</key>
|
<key>CSResourcesFileMapped</key>
|
||||||
<true/>
|
<true/>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#include "animatedsprite.h"
|
#include "animatedsprite.h"
|
||||||
|
#include <fstream> // Para basic_ostream, operator<<, basic_istream, basic...
|
||||||
|
#include <iostream> // Para cout
|
||||||
|
#include <sstream> // Para basic_stringstream
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
|
||||||
// Carga la animación desde un fichero
|
// Carga la animación desde un fichero
|
||||||
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
|
animatedSprite_t loadAnimationFromFile(Texture *texture, std::string filePath, bool verbose)
|
||||||
@@ -1,15 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include "movingsprite.h"
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
#include <fstream>
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
#include <iostream>
|
#include <string> // Para string
|
||||||
#include <sstream>
|
#include <vector> // Para vector
|
||||||
#include <string>
|
#include "movingsprite.h" // Para MovingSprite
|
||||||
#include <vector>
|
class Texture;
|
||||||
|
|
||||||
#ifndef ANIMATEDSPRITE_H
|
|
||||||
#define ANIMATEDSPRITE_H
|
|
||||||
|
|
||||||
struct animation_t
|
struct animation_t
|
||||||
{
|
{
|
||||||
@@ -99,5 +96,3 @@ public:
|
|||||||
// Reinicia la animación
|
// Reinicia la animación
|
||||||
void resetAnimation();
|
void resetAnimation();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,25 +1,41 @@
|
|||||||
#include "asset.h"
|
#include "asset.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL_rwops.h> // Para SDL_RWFromFile, SDL_RWclose, SDL_RWops
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para SDL_max
|
||||||
|
#include <stddef.h> // Para size_t
|
||||||
|
#include <iostream> // Para basic_ostream, operator<<, cout, endl
|
||||||
|
|
||||||
// Constructor
|
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
|
||||||
Asset::Asset(std::string executablePath)
|
Asset *Asset::asset_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
void Asset::init(const std::string &executable_path)
|
||||||
{
|
{
|
||||||
this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/"));
|
Asset::asset_ = new Asset(executable_path);
|
||||||
longestName = 0;
|
}
|
||||||
verbose = true;
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
void Asset::destroy()
|
||||||
|
{
|
||||||
|
delete Asset::asset_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
Asset *Asset::get()
|
||||||
|
{
|
||||||
|
return Asset::asset_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
void Asset::add(std::string file, enum assetType type, bool required, bool absolute)
|
||||||
{
|
{
|
||||||
item_t temp;
|
item_t temp;
|
||||||
temp.file = absolute ? file : executablePath + file;
|
temp.file = absolute ? file : executable_path_ + file;
|
||||||
temp.type = type;
|
temp.type = type;
|
||||||
temp.required = required;
|
temp.required = required;
|
||||||
fileList.push_back(temp);
|
fileList.push_back(temp);
|
||||||
|
|
||||||
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
const std::string filename = file.substr(file.find_last_of("\\/") + 1);
|
||||||
longestName = SDL_max(longestName, filename.size());
|
longest_name_ = SDL_max(longest_name_, filename.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
// Devuelve el fichero de un elemento de la lista a partir de una cadena
|
||||||
@@ -36,7 +52,7 @@ std::string Asset::get(std::string text)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
std::cout << "Warning: file " << text.c_str() << " not found" << std::endl;
|
||||||
}
|
}
|
||||||
@@ -48,11 +64,11 @@ bool Asset::check()
|
|||||||
{
|
{
|
||||||
bool success = true;
|
bool success = true;
|
||||||
|
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
std::cout << "\n** Checking files" << std::endl;
|
std::cout << "\n** Checking files" << std::endl;
|
||||||
|
|
||||||
std::cout << "Executable path is: " << executablePath << std::endl;
|
std::cout << "Executable path is: " << executable_path_ << std::endl;
|
||||||
std::cout << "Sample filepath: " << fileList.back().file << std::endl;
|
std::cout << "Sample filepath: " << fileList.back().file << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +89,7 @@ bool Asset::check()
|
|||||||
// Si hay ficheros de ese tipo, comprueba si existen
|
// Si hay ficheros de ese tipo, comprueba si existen
|
||||||
if (any)
|
if (any)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl;
|
std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl;
|
||||||
}
|
}
|
||||||
@@ -89,7 +105,7 @@ bool Asset::check()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Resultado
|
// Resultado
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
if (success)
|
if (success)
|
||||||
{
|
{
|
||||||
@@ -123,11 +139,11 @@ bool Asset::checkFile(std::string path)
|
|||||||
SDL_RWclose(file);
|
SDL_RWclose(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
std::cout.setf(std::ios::left, std::ios::adjustfield);
|
||||||
std::cout << "Checking file: ";
|
std::cout << "Checking file: ";
|
||||||
std::cout.width(longestName + 2);
|
std::cout.width(longest_name_ + 2);
|
||||||
std::cout.fill('.');
|
std::cout.fill('.');
|
||||||
std::cout << filename + " ";
|
std::cout << filename + " ";
|
||||||
std::cout << " [" + result + "]" << std::endl;
|
std::cout << " [" + result + "]" << std::endl;
|
||||||
@@ -186,5 +202,5 @@ std::string Asset::getTypeName(int type)
|
|||||||
// Establece si ha de mostrar texto por pantalla
|
// Establece si ha de mostrar texto por pantalla
|
||||||
void Asset::setVerbose(bool value)
|
void Asset::setVerbose(bool value)
|
||||||
{
|
{
|
||||||
verbose = value;
|
verbose_ = value;
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <string> // Para string
|
||||||
#include <string>
|
#include <vector> // Para vector
|
||||||
#include <vector>
|
#include "utils.h"
|
||||||
|
|
||||||
#ifndef ASSET_H
|
|
||||||
#define ASSET_H
|
|
||||||
|
|
||||||
enum assetType
|
enum assetType
|
||||||
{
|
{
|
||||||
@@ -25,20 +22,22 @@ enum assetType
|
|||||||
class Asset
|
class Asset
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
// [SINGLETON] Objeto asset privado
|
||||||
|
static Asset *asset_;
|
||||||
|
|
||||||
// Estructura para definir un item
|
// Estructura para definir un item
|
||||||
struct item_t
|
struct item_t
|
||||||
{
|
{
|
||||||
std::string file; // Ruta del fichero desde la raiz del directorio
|
std::string file; // Ruta del fichero desde la raiz del directorio
|
||||||
enum assetType type; // Indica el tipo de recurso
|
enum assetType type; // Indica el tipo de recurso
|
||||||
bool required; // Indica si es un fichero que debe de existir
|
bool required; // Indica si es un fichero que debe de existir
|
||||||
//bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int longestName; // Contiene la longitud del nombre de fichero mas largo
|
int longest_name_ = 0; // Contiene la longitud del nombre de fichero mas largo
|
||||||
std::vector<item_t> fileList; // Listado con todas las rutas a los ficheros
|
std::vector<item_t> fileList; // Listado con todas las rutas a los ficheros
|
||||||
std::string executablePath; // Ruta al ejecutable
|
std::string executable_path_; // Ruta al ejecutable
|
||||||
bool verbose; // Indica si ha de mostrar información por pantalla
|
bool verbose_ = true; // Indica si ha de mostrar información por pantalla
|
||||||
|
|
||||||
// Comprueba que existe un fichero
|
// Comprueba que existe un fichero
|
||||||
bool checkFile(std::string executablePath);
|
bool checkFile(std::string executablePath);
|
||||||
@@ -46,9 +45,22 @@ private:
|
|||||||
// Devuelve el nombre del tipo de recurso
|
// Devuelve el nombre del tipo de recurso
|
||||||
std::string getTypeName(int type);
|
std::string getTypeName(int type);
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Asset(std::string path);
|
explicit Asset(const std::string &executable_path)
|
||||||
|
: executable_path_(getPath(executable_path)) {}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Asset() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
static void init(const std::string &executable_path);
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
static Asset *get();
|
||||||
|
|
||||||
// Añade un elemento a la lista
|
// Añade un elemento a la lista
|
||||||
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
void add(std::string file, enum assetType type, bool required = true, bool absolute = false);
|
||||||
@@ -62,5 +74,3 @@ public:
|
|||||||
// Establece si ha de mostrar texto por pantalla
|
// Establece si ha de mostrar texto por pantalla
|
||||||
void setVerbose(bool value);
|
void setVerbose(bool value);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,13 +1,199 @@
|
|||||||
#include "cheevos.h"
|
#include "cheevos.h"
|
||||||
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
|
#include <SDL2/SDL_rwops.h> // Para SDL_RWFromFile, SDL_RWclose, SDL_RWwrite
|
||||||
|
#include <stddef.h> // Para NULL
|
||||||
|
#include <iostream> // Para basic_ostream, operator<<, cout, endl
|
||||||
|
#include "notifier.h" // Para Screen
|
||||||
|
#include "utils.h" // Para options_t
|
||||||
|
#include "options.h"
|
||||||
|
#include <fstream> // Para fstream
|
||||||
|
|
||||||
|
// [SINGLETON]
|
||||||
|
Cheevos *Cheevos::cheevos_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
void Cheevos::init(const std::string &file)
|
||||||
|
{
|
||||||
|
Cheevos::cheevos_ = new Cheevos(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
void Cheevos::destroy()
|
||||||
|
{
|
||||||
|
delete Cheevos::cheevos_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
Cheevos *Cheevos::get()
|
||||||
|
{
|
||||||
|
return Cheevos::cheevos_;
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Cheevos::Cheevos(options_t *options)
|
Cheevos::Cheevos(const std::string &file)
|
||||||
|
: file_(file)
|
||||||
{
|
{
|
||||||
this->options = options;
|
init();
|
||||||
|
loadFromFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Cheevos::~Cheevos()
|
Cheevos::~Cheevos()
|
||||||
{
|
{
|
||||||
|
saveToFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa los logros
|
||||||
|
void Cheevos::init()
|
||||||
|
{
|
||||||
|
cheevos_list_.clear();
|
||||||
|
cheevos_list_.emplace_back(1, "SHINY THINGS", "Get 25% of the items", 2);
|
||||||
|
cheevos_list_.emplace_back(2, "HALF THE WORK", "Get 50% of the items", 2);
|
||||||
|
cheevos_list_.emplace_back(3, "GETTING THERE", "Get 75% of the items", 2);
|
||||||
|
cheevos_list_.emplace_back(4, "THE COLLECTOR", "Get 100% of the items", 2);
|
||||||
|
cheevos_list_.emplace_back(5, "WANDERING AROUND", "Visit 20 rooms", 2);
|
||||||
|
cheevos_list_.emplace_back(6, "I GOT LOST", "Visit 40 rooms", 2);
|
||||||
|
cheevos_list_.emplace_back(7, "I LIKE TO EXPLORE", "Visit all rooms", 2);
|
||||||
|
cheevos_list_.emplace_back(8, "FINISH THE GAME", "Complete the game", 2);
|
||||||
|
cheevos_list_.emplace_back(9, "I WAS SUCKED BY A HOLE", "Complete the game without entering the jail", 2);
|
||||||
|
cheevos_list_.emplace_back(10, "MY LITTLE PROJECTS", "Complete the game with all items", 2);
|
||||||
|
cheevos_list_.emplace_back(11, "I LIKE MY MULTICOLOURED FRIENDS", "Complete the game without dying", 2);
|
||||||
|
cheevos_list_.emplace_back(12, "SHIT PROJECTS DONE FAST", "Complete the game in under 30 minutes", 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Busca un logro por id y devuelve el indice
|
||||||
|
int Cheevos::find(int id)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < (int)cheevos_list_.size(); ++i)
|
||||||
|
{
|
||||||
|
if (cheevos_list_[i].id == id)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Desbloquea un logro
|
||||||
|
void Cheevos::unlock(int id)
|
||||||
|
{
|
||||||
|
const int index = find(id);
|
||||||
|
|
||||||
|
// Si el índice es inválido, el logro no es válido, ya está completado o el sistema de logros no está habilitado, no hacemos nada
|
||||||
|
if (index == -1 || !cheevos_list_.at(index).valid || cheevos_list_.at(index).completed || !enabled_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Marcar el logro como completado
|
||||||
|
cheevos_list_.at(index).completed = true;
|
||||||
|
// Mostrar notificación en la pantalla
|
||||||
|
Notifier::get()->show("ACHIEVEMENT UNLOCKED!", cheevos_list_.at(index).caption, cheevos_list_.at(index).icon);
|
||||||
|
// Guardar el estado de los logros
|
||||||
|
saveToFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invalida un logro
|
||||||
|
void Cheevos::invalidate(int id)
|
||||||
|
{
|
||||||
|
const int index = find(id);
|
||||||
|
|
||||||
|
// Si el índice es válido, se invalida el logro
|
||||||
|
if (index != -1)
|
||||||
|
{
|
||||||
|
cheevos_list_.at(index).valid = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga el estado de los logros desde un fichero
|
||||||
|
void Cheevos::loadFromFile()
|
||||||
|
{
|
||||||
|
std::ifstream file(this->file_, std::ios::binary);
|
||||||
|
|
||||||
|
// El fichero no existe
|
||||||
|
if (!file)
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "Warning: Unable to open file! Creating new file..." << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea el fichero en modo escritura (binario)
|
||||||
|
std::ofstream newFile(this->file_, std::ios::binary);
|
||||||
|
|
||||||
|
if (newFile)
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "New file created!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guarda la información
|
||||||
|
for (const auto &cheevo : cheevos_list_)
|
||||||
|
{
|
||||||
|
newFile.write(reinterpret_cast<const char *>(&cheevo.completed), sizeof(bool));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cerr << "Error: Unable to create file!" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// El fichero existe
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "Reading file...!" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Carga los datos
|
||||||
|
for (auto &cheevo : cheevos_list_)
|
||||||
|
{
|
||||||
|
file.read(reinterpret_cast<char *>(&cheevo.completed), sizeof(bool));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Guarda el estado de los logros en un fichero
|
||||||
|
void Cheevos::saveToFile()
|
||||||
|
{
|
||||||
|
// Abre el fichero en modo escritura (binario)
|
||||||
|
SDL_RWops *file = SDL_RWFromFile(this->file_.c_str(), "w+b");
|
||||||
|
if (file != NULL)
|
||||||
|
{
|
||||||
|
// Guarda la información
|
||||||
|
for (int i = 0; i < (int)cheevos_list_.size(); ++i)
|
||||||
|
{
|
||||||
|
SDL_RWwrite(file, &cheevos_list_[i].completed, sizeof(bool), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
SDL_RWclose(file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "Error: Unable to save file! " << SDL_GetError() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Devuelve el número total de logros desbloqueados
|
||||||
|
int Cheevos::unlocked()
|
||||||
|
{
|
||||||
|
int count = 0;
|
||||||
|
for (auto cheevo : cheevos_list_)
|
||||||
|
{
|
||||||
|
if (cheevo.completed)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
}
|
}
|
||||||
@@ -1,27 +1,81 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
#include <string> // Para string
|
||||||
#include "common/utils.h"
|
#include <vector> // Para vector
|
||||||
#include <string>
|
class Screen;
|
||||||
#include <vector>
|
struct options_t;
|
||||||
|
|
||||||
#ifndef CHEEVOS_H
|
// Struct para los logros
|
||||||
#define CHEEVOS_H
|
struct Achievement
|
||||||
|
{
|
||||||
|
int id; // Identificador del logro
|
||||||
|
std::string caption; // Texto con el nombre del logro
|
||||||
|
std::string description; // Texto que describe el logro
|
||||||
|
int icon; // Indice del icono a utilizar en la notificación
|
||||||
|
bool completed; // Indica si se ha obtenido el logro
|
||||||
|
bool valid; // Indica si se puede obtener el logro
|
||||||
|
|
||||||
|
// Constructor vacío
|
||||||
|
Achievement() : id(0), icon(0), completed(false), valid(true) {}
|
||||||
|
|
||||||
|
// Constructor parametrizado
|
||||||
|
Achievement(int id, const std::string &caption, const std::string &description, int icon, bool completed = false, bool valid = true)
|
||||||
|
: id(id), caption(caption), description(description), icon(icon), completed(completed), valid(valid) {}
|
||||||
|
};
|
||||||
|
|
||||||
class Cheevos
|
class Cheevos
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Punteros y objetos
|
// [SINGLETON] Objeto privado
|
||||||
options_t *options;
|
static Cheevos *cheevos_;
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
|
std::vector<Achievement> cheevos_list_; // Listado de logros
|
||||||
|
bool enabled_ = true; // Indica si los logros se pueden obtener
|
||||||
|
std::string file_; // Fichero donde leer/almacenar el estado de los logros
|
||||||
|
|
||||||
|
// Inicializa los logros
|
||||||
|
void init();
|
||||||
|
|
||||||
|
// Busca un logro por id y devuelve el índice
|
||||||
|
int find(int id);
|
||||||
|
|
||||||
|
// Carga el estado de los logros desde un fichero
|
||||||
|
void loadFromFile();
|
||||||
|
|
||||||
|
// Guarda el estado de los logros en un fichero
|
||||||
|
void saveToFile();
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Cheevos(options_t *options);
|
Cheevos(const std::string &file);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Cheevos();
|
~Cheevos();
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
static void init(const std::string &file);
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
static Cheevos *get();
|
||||||
|
|
||||||
|
// Desbloquea un logro
|
||||||
|
void unlock(int id);
|
||||||
|
|
||||||
|
// Invalida un logro
|
||||||
|
void invalidate(int id);
|
||||||
|
|
||||||
|
// Habilita o deshabilita los logros
|
||||||
|
void enable(bool value) { enabled_ = value; }
|
||||||
|
|
||||||
|
// Lista los logros
|
||||||
|
std::vector<Achievement> list() { return cheevos_list_; }
|
||||||
|
|
||||||
|
// Devuelve el número total de logros desbloqueados
|
||||||
|
int unlocked();
|
||||||
|
|
||||||
|
// Devuelve el número total de logros
|
||||||
|
int count() { return cheevos_list_.size(); }
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,106 +0,0 @@
|
|||||||
#include "debug.h"
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Debug::Debug(SDL_Renderer *renderer, Screen *screen, Asset *asset)
|
|
||||||
{
|
|
||||||
// Copia la dirección de los objetos
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
|
||||||
texture = new Texture(renderer, asset->get("debug.png"));
|
|
||||||
text = new Text(asset->get("debug.txt"), texture, renderer);
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Debug::~Debug()
|
|
||||||
{
|
|
||||||
delete texture;
|
|
||||||
delete text;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void Debug::update()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja en pantalla
|
|
||||||
void Debug::render()
|
|
||||||
{
|
|
||||||
int y = this->y;
|
|
||||||
int w = 0;
|
|
||||||
|
|
||||||
for (auto s : slot)
|
|
||||||
{
|
|
||||||
text->write(x, y, s);
|
|
||||||
w = (std::max(w, (int)s.length()));
|
|
||||||
y += text->getCharacterSize() + 1;
|
|
||||||
if (y > 192 - text->getCharacterSize())
|
|
||||||
{
|
|
||||||
y = this->y;
|
|
||||||
x += w * text->getCharacterSize() + 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
y = 0;
|
|
||||||
for (auto l : log)
|
|
||||||
{
|
|
||||||
text->writeColored(x + 10, y, l, {255, 255, 255});
|
|
||||||
y += text->getCharacterSize() + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece la posición donde se colocará la información de debug
|
|
||||||
void Debug::setPos(SDL_Point p)
|
|
||||||
{
|
|
||||||
x = p.x;
|
|
||||||
y = p.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Añade un texto para mostrar
|
|
||||||
void Debug::add(std::string text)
|
|
||||||
{
|
|
||||||
slot.push_back(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Borra la información de debug
|
|
||||||
void Debug::clear()
|
|
||||||
{
|
|
||||||
slot.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Añade un texto para mostrar en el apartado log
|
|
||||||
void Debug::addToLog(std::string text)
|
|
||||||
{
|
|
||||||
log.push_back(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Borra la información de debug del apartado log
|
|
||||||
void Debug::clearLog()
|
|
||||||
{
|
|
||||||
log.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void Debug::setEnabled(bool value)
|
|
||||||
{
|
|
||||||
enabled = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool Debug::getEnabled()
|
|
||||||
{
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el valor de la variable
|
|
||||||
void Debug::switchEnabled()
|
|
||||||
{
|
|
||||||
enabled = !enabled;
|
|
||||||
}
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "../const.h"
|
|
||||||
#include "asset.h"
|
|
||||||
#include "screen.h"
|
|
||||||
#include "text.h"
|
|
||||||
#include "texture.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef DEBUG_H
|
|
||||||
#define DEBUG_H
|
|
||||||
|
|
||||||
// Clase Debug
|
|
||||||
class Debug
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
// Objetos y punteros
|
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
|
||||||
Text *text; // Objeto encargado de escribir texto en pantalla
|
|
||||||
Texture *texture; // Textura para el texto
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
std::vector<std::string> slot; // Vector con los textos a escribir
|
|
||||||
std::vector<std::string> log; // Vector con los textos a escribir
|
|
||||||
int x; // Posicion donde escribir el texto de debug
|
|
||||||
int y; // Posición donde escribir el texto de debug
|
|
||||||
bool enabled; // Indica si esta activo el modo debug
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Debug(SDL_Renderer *renderer, Screen *screen, Asset *asset);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Debug();
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Dibuja en pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Establece la posición donde se colocará la información de debug
|
|
||||||
void setPos(SDL_Point p);
|
|
||||||
|
|
||||||
// Añade un texto para mostrar
|
|
||||||
void add(std::string text);
|
|
||||||
|
|
||||||
// Borra la información de debug
|
|
||||||
void clear();
|
|
||||||
|
|
||||||
// Añade un texto para mostrar en el apartado log
|
|
||||||
void addToLog(std::string text);
|
|
||||||
|
|
||||||
// Borra la información de debug del apartado log
|
|
||||||
void clearLog();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setEnabled(bool value);
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
bool getEnabled();
|
|
||||||
|
|
||||||
// Cambia el valor de la variable
|
|
||||||
void switchEnabled();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,111 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef INPUT_H
|
|
||||||
#define INPUT_H
|
|
||||||
|
|
||||||
#define INPUT_NULL 0
|
|
||||||
#define INPUT_UP 1
|
|
||||||
#define INPUT_DOWN 2
|
|
||||||
#define INPUT_LEFT 3
|
|
||||||
#define INPUT_RIGHT 4
|
|
||||||
#define INPUT_ACCEPT 5
|
|
||||||
#define INPUT_CANCEL 6
|
|
||||||
#define INPUT_BUTTON_1 7
|
|
||||||
#define INPUT_BUTTON_2 8
|
|
||||||
#define INPUT_BUTTON_3 9
|
|
||||||
#define INPUT_BUTTON_4 10
|
|
||||||
#define INPUT_BUTTON_5 11
|
|
||||||
#define INPUT_BUTTON_6 12
|
|
||||||
#define INPUT_BUTTON_7 13
|
|
||||||
#define INPUT_BUTTON_8 14
|
|
||||||
#define INPUT_BUTTON_PAUSE 15
|
|
||||||
#define INPUT_BUTTON_ESCAPE 16
|
|
||||||
|
|
||||||
#define REPEAT_TRUE true
|
|
||||||
#define REPEAT_FALSE false
|
|
||||||
|
|
||||||
#define INPUT_USE_KEYBOARD 0
|
|
||||||
#define INPUT_USE_GAMECONTROLLER 1
|
|
||||||
#define INPUT_USE_ANY 2
|
|
||||||
|
|
||||||
enum i_disable_e
|
|
||||||
{
|
|
||||||
d_notDisabled,
|
|
||||||
d_forever,
|
|
||||||
d_keyPressed
|
|
||||||
};
|
|
||||||
|
|
||||||
class Input
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
struct keyBindings_t
|
|
||||||
{
|
|
||||||
Uint8 scancode; // Scancode asociado
|
|
||||||
bool active; // Indica si está activo
|
|
||||||
};
|
|
||||||
|
|
||||||
struct GameControllerBindings_t
|
|
||||||
{
|
|
||||||
SDL_GameControllerButton button; // GameControllerButton asociado
|
|
||||||
bool active; // Indica si está activo
|
|
||||||
};
|
|
||||||
|
|
||||||
// Objetos y punteros
|
|
||||||
std::vector<SDL_GameController *> connectedControllers; // Vector con todos los mandos conectados
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
std::vector<keyBindings_t> keyBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
|
||||||
std::vector<GameControllerBindings_t> gameControllerBindings; // Vector con las teclas asociadas a los inputs predefinidos
|
|
||||||
std::vector<std::string> controllerNames; // Vector con los nombres de los mandos
|
|
||||||
int numGamepads; // Numero de mandos conectados
|
|
||||||
std::string dbPath; // Ruta al archivo gamecontrollerdb.txt
|
|
||||||
bool verbose; // Indica si ha de mostrar mensajes
|
|
||||||
i_disable_e disabledUntil; // Tiempo que esta deshabilitado
|
|
||||||
bool enabled; // Indica si está habilitado
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Input(std::string file);
|
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Asigna inputs a teclas
|
|
||||||
void bindKey(Uint8 input, SDL_Scancode code);
|
|
||||||
|
|
||||||
// Asigna inputs a botones del mando
|
|
||||||
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
|
||||||
bool checkInput(Uint8 input, bool repeat, int device = INPUT_USE_ANY, int index = 0);
|
|
||||||
|
|
||||||
// Comprueba si hay almenos un input activo
|
|
||||||
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);
|
|
||||||
|
|
||||||
// Busca si hay un mando conectado
|
|
||||||
bool discoverGameController();
|
|
||||||
|
|
||||||
// Comprueba si hay algun mando conectado
|
|
||||||
bool gameControllerFound();
|
|
||||||
|
|
||||||
// Obten el numero de mandos conectados
|
|
||||||
int getNumControllers();
|
|
||||||
|
|
||||||
// Obten el nombre de un mando de juego
|
|
||||||
std::string getControllerName(int index);
|
|
||||||
|
|
||||||
// Establece si ha de mostrar mensajes
|
|
||||||
void setVerbose(bool value);
|
|
||||||
|
|
||||||
// Deshabilita las entradas durante un periodo de tiempo
|
|
||||||
void disableUntil(i_disable_e value);
|
|
||||||
|
|
||||||
// Hablita las entradas
|
|
||||||
void enable();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,251 +0,0 @@
|
|||||||
#ifndef JA_USESDLMIXER
|
|
||||||
#include "jail_audio.h"
|
|
||||||
#include "stb_vorbis.c"
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define JA_MAX_SIMULTANEOUS_CHANNELS 5
|
|
||||||
|
|
||||||
struct JA_Sound_t {
|
|
||||||
Uint32 length {0};
|
|
||||||
Uint8* buffer {NULL};
|
|
||||||
};
|
|
||||||
|
|
||||||
struct JA_Channel_t {
|
|
||||||
JA_Sound_t *sound;
|
|
||||||
int pos {0};
|
|
||||||
int times {0};
|
|
||||||
JA_Channel_state state { JA_CHANNEL_FREE };
|
|
||||||
};
|
|
||||||
|
|
||||||
struct JA_Music_t {
|
|
||||||
int samples {0};
|
|
||||||
int pos {0};
|
|
||||||
int times {0};
|
|
||||||
short* output {NULL};
|
|
||||||
JA_Music_state state {JA_MUSIC_INVALID};
|
|
||||||
};
|
|
||||||
|
|
||||||
JA_Music_t *current_music{NULL};
|
|
||||||
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
|
||||||
|
|
||||||
int JA_freq {48000};
|
|
||||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
|
||||||
Uint8 JA_channels {2};
|
|
||||||
int JA_volume = 128;
|
|
||||||
SDL_AudioDeviceID sdlAudioDevice = 0;
|
|
||||||
|
|
||||||
void audioCallback(void * userdata, uint8_t * stream, int len) {
|
|
||||||
SDL_memset(stream, 0, len);
|
|
||||||
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING) {
|
|
||||||
const int size = SDL_min(len, current_music->samples*2-current_music->pos);
|
|
||||||
SDL_MixAudioFormat(stream, (Uint8*)(current_music->output+current_music->pos), AUDIO_S16, size, JA_volume);
|
|
||||||
current_music->pos += size/2;
|
|
||||||
if (size < len) {
|
|
||||||
if (current_music->times != 0) {
|
|
||||||
SDL_MixAudioFormat(stream+size, (Uint8*)current_music->output, AUDIO_S16, len-size, JA_volume);
|
|
||||||
current_music->pos = (len-size)/2;
|
|
||||||
if (current_music->times > 0) current_music->times--;
|
|
||||||
} else {
|
|
||||||
current_music->pos = 0;
|
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Mixar els channels mi amol
|
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
|
||||||
if (channels[i].state == JA_CHANNEL_PLAYING) {
|
|
||||||
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
|
||||||
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_volume/2);
|
|
||||||
channels[i].pos += size;
|
|
||||||
if (size < len) {
|
|
||||||
if (channels[i].times != 0) {
|
|
||||||
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len-size, JA_volume/2);
|
|
||||||
channels[i].pos = len-size;
|
|
||||||
if (channels[i].times > 0) channels[i].times--;
|
|
||||||
} else {
|
|
||||||
JA_StopChannel(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
|
||||||
JA_freq = freq;
|
|
||||||
JA_format = format;
|
|
||||||
JA_channels = channels;
|
|
||||||
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
|
|
||||||
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice);
|
|
||||||
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_Quit() {
|
|
||||||
SDL_PauseAudioDevice(sdlAudioDevice, 1);
|
|
||||||
if (sdlAudioDevice != 0) SDL_CloseAudioDevice(sdlAudioDevice);
|
|
||||||
sdlAudioDevice = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Music_t *JA_LoadMusic(const char* filename) {
|
|
||||||
int chan, samplerate;
|
|
||||||
|
|
||||||
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
|
||||||
FILE *f = fopen(filename, "rb");
|
|
||||||
fseek(f, 0, SEEK_END);
|
|
||||||
long fsize = ftell(f);
|
|
||||||
fseek(f, 0, SEEK_SET);
|
|
||||||
Uint8 *buffer = (Uint8*)malloc(fsize + 1);
|
|
||||||
if (fread(buffer, fsize, 1, f)!=1) return NULL;
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
JA_Music_t *music = new JA_Music_t();
|
|
||||||
|
|
||||||
music->samples = stb_vorbis_decode_memory(buffer, fsize, &chan, &samplerate, &music->output);
|
|
||||||
free(buffer);
|
|
||||||
// [RZC 28/08/22] Abans el descomprimiem mentre el teniem obert
|
|
||||||
// music->samples = stb_vorbis_decode_filename(filename, &chan, &samplerate, &music->output);
|
|
||||||
|
|
||||||
SDL_AudioCVT cvt;
|
|
||||||
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
|
||||||
if (cvt.needed) {
|
|
||||||
cvt.len = music->samples * chan * 2;
|
|
||||||
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
|
||||||
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
|
||||||
SDL_ConvertAudio(&cvt);
|
|
||||||
free(music->output);
|
|
||||||
music->output = (short*)cvt.buf;
|
|
||||||
}
|
|
||||||
music->pos = 0;
|
|
||||||
music->state = JA_MUSIC_STOPPED;
|
|
||||||
|
|
||||||
return music;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
|
||||||
if (current_music != NULL) {
|
|
||||||
current_music->pos = 0;
|
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
|
||||||
}
|
|
||||||
current_music = music;
|
|
||||||
current_music->pos = 0;
|
|
||||||
current_music->state = JA_MUSIC_PLAYING;
|
|
||||||
current_music->times = loop;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PauseMusic() {
|
|
||||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
|
||||||
current_music->state = JA_MUSIC_PAUSED;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_ResumeMusic() {
|
|
||||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
|
||||||
current_music->state = JA_MUSIC_PLAYING;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_StopMusic() {
|
|
||||||
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID) return;
|
|
||||||
current_music->pos = 0;
|
|
||||||
current_music->state = JA_MUSIC_STOPPED;
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Music_state JA_GetMusicState() {
|
|
||||||
if (current_music == NULL) return JA_MUSIC_INVALID;
|
|
||||||
return current_music->state;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_DeleteMusic(JA_Music_t *music) {
|
|
||||||
if (current_music == music) current_music = NULL;
|
|
||||||
free(music->output);
|
|
||||||
delete music;
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
|
||||||
JA_Sound_t *sound = new JA_Sound_t();
|
|
||||||
sound->buffer = buffer;
|
|
||||||
sound->length = length;
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Sound_t *JA_LoadSound(const char* filename) {
|
|
||||||
JA_Sound_t *sound = new JA_Sound_t();
|
|
||||||
SDL_AudioSpec wavSpec;
|
|
||||||
SDL_LoadWAV(filename, &wavSpec, &sound->buffer, &sound->length);
|
|
||||||
|
|
||||||
SDL_AudioCVT cvt;
|
|
||||||
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
|
||||||
cvt.len = sound->length;
|
|
||||||
cvt.buf = (Uint8 *) SDL_malloc(cvt.len * cvt.len_mult);
|
|
||||||
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
|
|
||||||
SDL_ConvertAudio(&cvt);
|
|
||||||
SDL_FreeWAV(sound->buffer);
|
|
||||||
sound->buffer = cvt.buf;
|
|
||||||
sound->length = cvt.len_cvt;
|
|
||||||
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
|
||||||
int channel = 0;
|
|
||||||
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE) { channel++; }
|
|
||||||
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS) channel = 0;
|
|
||||||
|
|
||||||
channels[channel].sound = sound;
|
|
||||||
channels[channel].times = loop;
|
|
||||||
channels[channel].pos = 0;
|
|
||||||
channels[channel].state = JA_CHANNEL_PLAYING;
|
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_DeleteSound(JA_Sound_t *sound) {
|
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
|
||||||
if (channels[i].sound == sound) JA_StopChannel(i);
|
|
||||||
}
|
|
||||||
SDL_free(sound->buffer);
|
|
||||||
delete sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PauseChannel(const int channel) {
|
|
||||||
if (channel == -1) {
|
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
|
||||||
if (channels[i].state == JA_CHANNEL_PLAYING) channels[i].state = JA_CHANNEL_PAUSED;
|
|
||||||
}
|
|
||||||
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
|
||||||
if (channels[channel].state == JA_CHANNEL_PLAYING) channels[channel].state = JA_CHANNEL_PAUSED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_ResumeChannel(const int channel) {
|
|
||||||
if (channel == -1) {
|
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
|
||||||
if (channels[i].state == JA_CHANNEL_PAUSED) channels[i].state = JA_CHANNEL_PLAYING;
|
|
||||||
}
|
|
||||||
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
|
||||||
if (channels[channel].state == JA_CHANNEL_PAUSED) channels[channel].state = JA_CHANNEL_PLAYING;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_StopChannel(const int channel) {
|
|
||||||
if (channel == -1) {
|
|
||||||
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++) {
|
|
||||||
channels[i].state = JA_CHANNEL_FREE;
|
|
||||||
channels[i].pos = 0;
|
|
||||||
channels[i].sound = NULL;
|
|
||||||
}
|
|
||||||
} else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS) {
|
|
||||||
channels[channel].state = JA_CHANNEL_FREE;
|
|
||||||
channels[channel].pos = 0;
|
|
||||||
channels[channel].sound = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Channel_state JA_GetChannelState(const int channel) {
|
|
||||||
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS) return JA_CHANNEL_INVALID;
|
|
||||||
return channels[channel].state;
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_SetVolume(int volume) {
|
|
||||||
JA_volume = volume > 128 ? 128 : volume < 0 ? 0 : volume;
|
|
||||||
return JA_volume;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
|
|
||||||
enum JA_Channel_state { JA_CHANNEL_INVALID, JA_CHANNEL_FREE, JA_CHANNEL_PLAYING, JA_CHANNEL_PAUSED };
|
|
||||||
enum JA_Music_state { JA_MUSIC_INVALID, JA_MUSIC_PLAYING, JA_MUSIC_PAUSED, JA_MUSIC_STOPPED };
|
|
||||||
|
|
||||||
struct JA_Sound_t;
|
|
||||||
struct JA_Music_t;
|
|
||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels);
|
|
||||||
void JA_Quit();
|
|
||||||
|
|
||||||
JA_Music_t *JA_LoadMusic(const char* filename);
|
|
||||||
void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
|
|
||||||
void JA_PauseMusic();
|
|
||||||
void JA_ResumeMusic();
|
|
||||||
void JA_StopMusic();
|
|
||||||
JA_Music_state JA_GetMusicState();
|
|
||||||
void JA_DeleteMusic(JA_Music_t *music);
|
|
||||||
|
|
||||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length);
|
|
||||||
JA_Sound_t *JA_LoadSound(const char* filename);
|
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
|
|
||||||
void JA_PauseChannel(const int channel);
|
|
||||||
void JA_ResumeChannel(const int channel);
|
|
||||||
void JA_StopChannel(const int channel);
|
|
||||||
JA_Channel_state JA_GetChannelState(const int channel);
|
|
||||||
void JA_DeleteSound(JA_Sound_t *sound);
|
|
||||||
|
|
||||||
int JA_SetVolume(int volume);
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
#ifdef JA_USESDLMIXER
|
|
||||||
#include "jail_audio.h"
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include <SDL2/SDL_mixer.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
struct JA_Sound_t {}; // Dummy structs
|
|
||||||
struct JA_Music_t {};
|
|
||||||
|
|
||||||
int JA_freq {48000};
|
|
||||||
SDL_AudioFormat JA_format {AUDIO_S16};
|
|
||||||
Uint8 JA_channels {2};
|
|
||||||
|
|
||||||
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels) {
|
|
||||||
JA_freq = freq;
|
|
||||||
JA_format = format;
|
|
||||||
JA_channels = channels;
|
|
||||||
Mix_OpenAudio(JA_freq, JA_format, JA_channels, 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_Quit() {
|
|
||||||
Mix_CloseAudio();
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Music_t *JA_LoadMusic(const char* filename) {
|
|
||||||
return (JA_Music_t*)Mix_LoadMUS(filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PlayMusic(JA_Music_t *music, const int loop) {
|
|
||||||
Mix_PlayMusic((Mix_Music*)music, loop);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PauseMusic() {
|
|
||||||
Mix_PauseMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_ResumeMusic() {
|
|
||||||
Mix_ResumeMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_StopMusic() {
|
|
||||||
Mix_HaltMusic();
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Music_state JA_GetMusicState() {
|
|
||||||
if (Mix_PausedMusic()) {
|
|
||||||
return JA_MUSIC_PAUSED;
|
|
||||||
} else if (Mix_PlayingMusic()) {
|
|
||||||
return JA_MUSIC_PLAYING;
|
|
||||||
} else {
|
|
||||||
return JA_MUSIC_STOPPED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_DeleteMusic(JA_Music_t *music) {
|
|
||||||
Mix_FreeMusic((Mix_Music*)music);
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Sound_t *JA_LoadSound(const char* filename) {
|
|
||||||
JA_Sound_t *sound = (JA_Sound_t*)Mix_LoadWAV(filename);
|
|
||||||
return sound;
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_PlaySound(JA_Sound_t *sound, const int loop) {
|
|
||||||
return Mix_PlayChannel(-1, (Mix_Chunk*)sound, loop);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_DeleteSound(JA_Sound_t *sound) {
|
|
||||||
Mix_FreeChunk((Mix_Chunk*)sound);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_PauseChannel(const int channel) {
|
|
||||||
Mix_Pause(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_ResumeChannel(const int channel) {
|
|
||||||
Mix_Resume(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
void JA_StopChannel(const int channel) {
|
|
||||||
Mix_HaltChannel(channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_Channel_state JA_GetChannelState(const int channel) {
|
|
||||||
if (Mix_Paused(channel)) {
|
|
||||||
return JA_CHANNEL_PAUSED;
|
|
||||||
} else if (Mix_Playing(channel)) {
|
|
||||||
return JA_CHANNEL_PLAYING;
|
|
||||||
} else {
|
|
||||||
return JA_CHANNEL_FREE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int JA_SetVolume(int volume) {
|
|
||||||
return Mix_Volume(-1, volume);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -1,154 +0,0 @@
|
|||||||
#include "jscore.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <winsock2.h>
|
|
||||||
#else
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#endif
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
namespace jscore {
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
struct user {
|
|
||||||
string name;
|
|
||||||
int points;
|
|
||||||
};
|
|
||||||
vector<user> score;
|
|
||||||
|
|
||||||
#define bzero(b,len) (memset((b), '\0', (len)), (void) 0)
|
|
||||||
int sock;
|
|
||||||
struct sockaddr_in client;
|
|
||||||
|
|
||||||
int PORT = 9911;
|
|
||||||
string HOST = "jaildoctor.duckdns.org";
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
WSADATA WsaData;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool jscore_error = false;
|
|
||||||
string error_message;
|
|
||||||
|
|
||||||
void init(std::string host, const int port) {
|
|
||||||
PORT = port;
|
|
||||||
HOST = host;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setErrorMessage(string message) {
|
|
||||||
jscore_error = true;
|
|
||||||
error_message = message;
|
|
||||||
}
|
|
||||||
|
|
||||||
string sendRequest(const string request) {
|
|
||||||
#ifdef WIN32
|
|
||||||
int ret = WSAStartup(0x101,&WsaData);
|
|
||||||
if (ret != 0) return 0;
|
|
||||||
#endif
|
|
||||||
struct hostent * host = gethostbyname(HOST.c_str());
|
|
||||||
|
|
||||||
if ( (host == NULL) || (host->h_addr == NULL) ) {
|
|
||||||
setErrorMessage("Error retrieving DNS information.\n");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
bzero(&client, sizeof(client));
|
|
||||||
client.sin_family = AF_INET;
|
|
||||||
client.sin_port = htons( PORT );
|
|
||||||
memcpy(&client.sin_addr, host->h_addr, host->h_length);
|
|
||||||
|
|
||||||
sock = socket(AF_INET, SOCK_STREAM, 0);
|
|
||||||
|
|
||||||
if (sock < 0) {
|
|
||||||
setErrorMessage("Error creating socket.\n");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( connect(sock, (struct sockaddr *)&client, sizeof(client)) < 0 ) {
|
|
||||||
close(sock);
|
|
||||||
setErrorMessage("Could not connect\n");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
string r = request + " HTTP/1.1\r\nHost: "+HOST+"\r\nConnection: close\r\n\r\n\r\n";
|
|
||||||
if (send(sock, r.c_str(), r.length(), 0) != (int)r.length()) {
|
|
||||||
setErrorMessage("Error sending request.\n");
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
char cur;
|
|
||||||
char start[5]="\r\n\r\n";
|
|
||||||
int pos = 0;
|
|
||||||
while ( recv(sock, &cur, 1,0) > 0 ) {
|
|
||||||
if (cur==start[pos]) { pos++; if (pos == 4) break; } else { pos = 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
char buffer[1024]; buffer[0]=0; pos=0;
|
|
||||||
while ( recv(sock, &cur, 1,0) > 0 ) {
|
|
||||||
buffer[pos] = cur;
|
|
||||||
pos++;
|
|
||||||
}
|
|
||||||
#ifdef WIN32
|
|
||||||
WSACleanup();
|
|
||||||
#endif
|
|
||||||
buffer[pos]=0;
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool initOnlineScore(string game) {
|
|
||||||
string strbuff = sendRequest("GET /score-list.php?game=" + game);
|
|
||||||
if (jscore_error) return not jscore_error;
|
|
||||||
|
|
||||||
user u;
|
|
||||||
char buffer[1024];
|
|
||||||
strcpy(buffer, strbuff.c_str());
|
|
||||||
char *str = buffer;
|
|
||||||
char *p = str;
|
|
||||||
score.clear();
|
|
||||||
while (*p!=0) {
|
|
||||||
while (*p!=',') {p++;}
|
|
||||||
*p=0; u.name = str; p++; str=p;
|
|
||||||
while (*p!='\n') {p++;}
|
|
||||||
*p=0; u.points = atoi(str); p++; str=p;
|
|
||||||
score.push_back(u);
|
|
||||||
}
|
|
||||||
return not jscore_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int getNumUsers() {
|
|
||||||
return score.size();
|
|
||||||
}
|
|
||||||
string getUserName(const int index) {
|
|
||||||
return score[index].name;
|
|
||||||
}
|
|
||||||
const int getPoints(const int index) {
|
|
||||||
return score[index].points;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bool updateUserPoints(string game, string user, const int points) {
|
|
||||||
string strbuff = sendRequest("GET /score-update.php?game=" + game + "&user=" + user + "&points=" + to_string(points));
|
|
||||||
initOnlineScore(game);
|
|
||||||
return not jscore_error;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int getUserPoints(string game, std::string user) {
|
|
||||||
return atoi(sendRequest("GET /getuserpoints.php?game=" + game + "&user=" + user).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
string getUserData(string game, string user) {
|
|
||||||
return sendRequest("GET /getuserdata.php?game=" + game + "&user=" + user);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setUserData(string game, string user, string data) {
|
|
||||||
sendRequest("GET /setuserdata.php?game=" + game + "&user=" + user + "&data=" + data);
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace jscore {
|
|
||||||
void init(std::string host, const int port);
|
|
||||||
const bool initOnlineScore(std::string game);
|
|
||||||
const int getNumUsers();
|
|
||||||
std::string getUserName(const int index);
|
|
||||||
const int getPoints(const int index);
|
|
||||||
const int getUserPoints(std::string game, std::string user);
|
|
||||||
|
|
||||||
const bool updateUserPoints(std::string game, std::string user, const int points);
|
|
||||||
std::string getUserData(std::string game, std::string user);
|
|
||||||
void setUserData(std::string game, std::string user, std::string data);
|
|
||||||
};
|
|
||||||
|
|
||||||
@@ -1,982 +0,0 @@
|
|||||||
#include "../const.h"
|
|
||||||
#include "menu.h"
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Menu::Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, std::string file)
|
|
||||||
{
|
|
||||||
// Copia punteros
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->asset = asset;
|
|
||||||
this->input = input;
|
|
||||||
|
|
||||||
// Inicializa punteros
|
|
||||||
soundMove = nullptr;
|
|
||||||
soundAccept = nullptr;
|
|
||||||
soundCancel = nullptr;
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
name = "";
|
|
||||||
selector.index = 0;
|
|
||||||
itemSelected = MENU_NO_OPTION;
|
|
||||||
x = 0;
|
|
||||||
y = 0;
|
|
||||||
w = 0;
|
|
||||||
rectBG.rect = {0, 0, 0, 0};
|
|
||||||
rectBG.color = {0, 0, 0};
|
|
||||||
rectBG.a = 0;
|
|
||||||
backgroundType = MENU_BACKGROUND_SOLID;
|
|
||||||
isCenteredOnX = false;
|
|
||||||
isCenteredOnY = false;
|
|
||||||
areElementsCenteredOnX = false;
|
|
||||||
centerX = 0;
|
|
||||||
centerY = 0;
|
|
||||||
widestItem = 0;
|
|
||||||
colorGreyed = {128, 128, 128};
|
|
||||||
defaultActionWhenCancel = 0;
|
|
||||||
font_png = "";
|
|
||||||
font_txt = "";
|
|
||||||
|
|
||||||
// Selector
|
|
||||||
selector.originY = 0;
|
|
||||||
selector.targetY = 0;
|
|
||||||
selector.despY = 0;
|
|
||||||
selector.originH = 0;
|
|
||||||
selector.targetH = 0;
|
|
||||||
selector.incH = 0;
|
|
||||||
selector.y = 0.0f;
|
|
||||||
selector.h = 0.0f;
|
|
||||||
selector.numJumps = 8;
|
|
||||||
selector.moving = false;
|
|
||||||
selector.resizing = false;
|
|
||||||
selector.rect = {0, 0, 0, 0};
|
|
||||||
selector.color = {0, 0, 0};
|
|
||||||
selector.itemColor = {0, 0, 0};
|
|
||||||
selector.a = 255;
|
|
||||||
|
|
||||||
// Inicializa las variables desde un fichero
|
|
||||||
if (file != "")
|
|
||||||
{
|
|
||||||
load(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deja el cursor en el primer elemento
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
Menu::~Menu()
|
|
||||||
{
|
|
||||||
renderer = nullptr;
|
|
||||||
asset = nullptr;
|
|
||||||
input = nullptr;
|
|
||||||
|
|
||||||
if (soundMove)
|
|
||||||
{
|
|
||||||
JA_DeleteSound(soundMove);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (soundAccept)
|
|
||||||
{
|
|
||||||
JA_DeleteSound(soundAccept);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (soundCancel)
|
|
||||||
{
|
|
||||||
JA_DeleteSound(soundCancel);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (text != nullptr)
|
|
||||||
{
|
|
||||||
delete text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carga la configuración del menu desde un archivo de texto
|
|
||||||
bool Menu::load(std::string file_path)
|
|
||||||
{
|
|
||||||
// Indicador de éxito en la carga
|
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
// Indica si se ha creado ya el objeto de texto
|
|
||||||
bool textAllocated = false;
|
|
||||||
|
|
||||||
const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1);
|
|
||||||
std::string line;
|
|
||||||
std::ifstream file(file_path);
|
|
||||||
|
|
||||||
// El fichero se puede abrir
|
|
||||||
if (file.good())
|
|
||||||
{
|
|
||||||
// Procesa el fichero linea a linea
|
|
||||||
std::cout << "Reading file " << filename.c_str() << std::endl;
|
|
||||||
while (std::getline(file, line))
|
|
||||||
{
|
|
||||||
if (line == "[item]")
|
|
||||||
{
|
|
||||||
item_t item;
|
|
||||||
item.label = "";
|
|
||||||
item.hPaddingDown = 1;
|
|
||||||
item.selectable = true;
|
|
||||||
item.greyed = false;
|
|
||||||
item.linkedDown = false;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
// Lee la siguiente linea
|
|
||||||
std::getline(file, line);
|
|
||||||
|
|
||||||
// Encuentra la posición del caracter '='
|
|
||||||
int pos = line.find("=");
|
|
||||||
|
|
||||||
// Procesa las dos subcadenas
|
|
||||||
if (!setItem(&item, line.substr(0, pos), line.substr(pos + 1, line.length())))
|
|
||||||
{
|
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (line != "[/item]");
|
|
||||||
|
|
||||||
addItem(item.label, item.hPaddingDown, item.selectable, item.greyed, item.linkedDown);
|
|
||||||
}
|
|
||||||
|
|
||||||
// En caso contrario se parsea el fichero para buscar las variables y los valores
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// Encuentra la posición del caracter '='
|
|
||||||
int pos = line.find("=");
|
|
||||||
// Procesa las dos subcadenas
|
|
||||||
if (!setVars(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
|
||||||
{
|
|
||||||
std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl;
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crea el objeto text tan pronto como se pueda. Necesario para añadir items
|
|
||||||
if (font_png != "" && font_txt != "" && !textAllocated)
|
|
||||||
{
|
|
||||||
text = new Text(resource->getOffset(font_txt), resource->getTexture(font_png), renderer);
|
|
||||||
textAllocated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cierra el fichero
|
|
||||||
std::cout << "Closing file " << filename.c_str() << std::endl;
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
// El fichero no se puede abrir
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl;
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
|
||||||
bool Menu::setItem(item_t *item, std::string var, std::string value)
|
|
||||||
{
|
|
||||||
// Indicador de éxito en la asignación
|
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
if (var == "text")
|
|
||||||
{
|
|
||||||
item->label = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "hPaddingDown")
|
|
||||||
{
|
|
||||||
item->hPaddingDown = std::stoi(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "selectable")
|
|
||||||
{
|
|
||||||
item->selectable = value == "true" ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "greyed")
|
|
||||||
{
|
|
||||||
item->greyed = value == "true" ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "linkedDown")
|
|
||||||
{
|
|
||||||
item->linkedDown = value == "true" ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if ((var == "") || (var == "[/item]"))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
|
||||||
bool Menu::setVars(std::string var, std::string value)
|
|
||||||
{
|
|
||||||
// Indicador de éxito en la asignación
|
|
||||||
bool success = true;
|
|
||||||
|
|
||||||
if (var == "font_png")
|
|
||||||
{
|
|
||||||
font_png = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "font_txt")
|
|
||||||
{
|
|
||||||
font_txt = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "sound_cancel")
|
|
||||||
{
|
|
||||||
soundCancel = JA_LoadSound(asset->get(value).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "sound_accept")
|
|
||||||
{
|
|
||||||
soundAccept = JA_LoadSound(asset->get(value).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "sound_move")
|
|
||||||
{
|
|
||||||
soundMove = JA_LoadSound(asset->get(value).c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "name")
|
|
||||||
{
|
|
||||||
name = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "x")
|
|
||||||
{
|
|
||||||
x = std::stoi(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "centerX")
|
|
||||||
{
|
|
||||||
centerX = std::stoi(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "centerY")
|
|
||||||
{
|
|
||||||
centerY = std::stoi(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "y")
|
|
||||||
{
|
|
||||||
y = std::stoi(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "backgroundType")
|
|
||||||
{
|
|
||||||
backgroundType = std::stoi(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "backgroundColor")
|
|
||||||
{
|
|
||||||
// Se introducen los valores separados por comas en un vector
|
|
||||||
std::stringstream ss(value);
|
|
||||||
std::string tmp;
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
rectBG.color.r = std::stoi(tmp);
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
rectBG.color.g = std::stoi(tmp);
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
rectBG.color.b = std::stoi(tmp);
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
rectBG.a = std::stoi(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "selector_color")
|
|
||||||
{
|
|
||||||
// Se introducen los valores separados por comas en un vector
|
|
||||||
std::stringstream ss(value);
|
|
||||||
std::string tmp;
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
selector.color.r = std::stoi(tmp);
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
selector.color.g = std::stoi(tmp);
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
selector.color.b = std::stoi(tmp);
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
selector.a = std::stoi(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "selector_text_color")
|
|
||||||
{
|
|
||||||
// Se introducen los valores separados por comas en un vector
|
|
||||||
std::stringstream ss(value);
|
|
||||||
std::string tmp;
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
selector.itemColor.r = std::stoi(tmp);
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
selector.itemColor.g = std::stoi(tmp);
|
|
||||||
getline(ss, tmp, ',');
|
|
||||||
selector.itemColor.b = std::stoi(tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "areElementsCenteredOnX")
|
|
||||||
{
|
|
||||||
areElementsCenteredOnX = value == "true" ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "isCenteredOnX")
|
|
||||||
{
|
|
||||||
isCenteredOnX = value == "true" ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "isCenteredOnY")
|
|
||||||
{
|
|
||||||
isCenteredOnY = value == "true" ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "defaultActionWhenCancel")
|
|
||||||
{
|
|
||||||
defaultActionWhenCancel = std::stoi(value);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (var == "")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Carga los ficheros de audio
|
|
||||||
void Menu::loadAudioFile(std::string file, int sound)
|
|
||||||
{
|
|
||||||
switch (sound)
|
|
||||||
{
|
|
||||||
case SOUND_ACCEPT:
|
|
||||||
soundAccept = JA_LoadSound(file.c_str());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SOUND_CANCEL:
|
|
||||||
soundCancel = JA_LoadSound(file.c_str());
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SOUND_MOVE:
|
|
||||||
soundMove = JA_LoadSound(file.c_str());
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el nombre del menu
|
|
||||||
std::string Menu::getName()
|
|
||||||
{
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
int Menu::getItemSelected()
|
|
||||||
{
|
|
||||||
// Al llamar a esta funcion, se obtiene el valor y se borra
|
|
||||||
const int temp = itemSelected;
|
|
||||||
itemSelected = MENU_NO_OPTION;
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la posicion y el estado del selector
|
|
||||||
void Menu::updateSelector()
|
|
||||||
{
|
|
||||||
if (selector.moving)
|
|
||||||
{
|
|
||||||
// Calcula el desplazamiento en Y
|
|
||||||
selector.y += selector.despY;
|
|
||||||
if (selector.despY > 0) // Va hacia abajo
|
|
||||||
{
|
|
||||||
if (selector.y > selector.targetY) // Ha llegado al destino
|
|
||||||
{
|
|
||||||
selector.originY = selector.y = selector.targetY;
|
|
||||||
selector.moving = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (selector.despY < 0) // Va hacia arriba
|
|
||||||
{
|
|
||||||
if (selector.y < selector.targetY) // Ha llegado al destino
|
|
||||||
{
|
|
||||||
selector.originY = selector.y = selector.targetY;
|
|
||||||
selector.moving = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selector.rect.y = int(selector.y);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
selector.rect.y = int(selector.y);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selector.resizing)
|
|
||||||
{
|
|
||||||
// Calcula el incremento en H
|
|
||||||
selector.h += selector.incH;
|
|
||||||
if (selector.incH > 0) // Crece
|
|
||||||
{
|
|
||||||
if (selector.h > selector.targetH) // Ha llegado al destino
|
|
||||||
{
|
|
||||||
// selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
|
|
||||||
selector.originH = selector.h = selector.targetH;
|
|
||||||
selector.resizing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (selector.incH < 0) // Decrece
|
|
||||||
{
|
|
||||||
if (selector.h < selector.targetH) // Ha llegado al destino
|
|
||||||
{
|
|
||||||
// selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
|
|
||||||
selector.originH = selector.h = selector.targetH;
|
|
||||||
selector.resizing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selector.rect.h = int(selector.h);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
selector.rect.h = getSelectorHeight(selector.index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Coloca el selector en una posición específica
|
|
||||||
void Menu::setSelectorPos(int index)
|
|
||||||
{
|
|
||||||
if (index < (int)item.size())
|
|
||||||
{
|
|
||||||
selector.index = index;
|
|
||||||
selector.rect.y = selector.y = selector.originY = selector.targetY = item[selector.index].rect.y;
|
|
||||||
selector.rect.w = rectBG.rect.w;
|
|
||||||
selector.rect.x = rectBG.rect.x;
|
|
||||||
selector.originH = selector.targetH = selector.rect.h = getSelectorHeight(selector.index);
|
|
||||||
selector.moving = false;
|
|
||||||
selector.resizing = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtiene la anchura del elemento más ancho del menu
|
|
||||||
int Menu::getWidestItem()
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
// Obtenemos la anchura del item mas ancho
|
|
||||||
for (auto &i : item)
|
|
||||||
{
|
|
||||||
result = std::max(result, i.rect.w);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deja el menu apuntando al primer elemento
|
|
||||||
void Menu::reset()
|
|
||||||
{
|
|
||||||
itemSelected = MENU_NO_OPTION;
|
|
||||||
selector.index = 0;
|
|
||||||
selector.originY = selector.targetY = selector.y = item[0].rect.y;
|
|
||||||
selector.originH = selector.targetH = item[0].rect.h;
|
|
||||||
selector.moving = false;
|
|
||||||
selector.resizing = false;
|
|
||||||
|
|
||||||
// Si el primer elemento no es seleccionable, incrementa el selector
|
|
||||||
if (!item[selector.index].selectable)
|
|
||||||
{
|
|
||||||
increaseSelectorIndex();
|
|
||||||
setSelectorPos(selector.index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
|
||||||
void Menu::reorganize()
|
|
||||||
{
|
|
||||||
setRectSize();
|
|
||||||
|
|
||||||
if (isCenteredOnX)
|
|
||||||
{
|
|
||||||
centerMenuOnX(centerX);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isCenteredOnY)
|
|
||||||
{
|
|
||||||
centerMenuOnY(centerY);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (areElementsCenteredOnX)
|
|
||||||
{
|
|
||||||
centerMenuElementsOnX();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deja el menu apuntando al siguiente elemento
|
|
||||||
bool Menu::increaseSelectorIndex()
|
|
||||||
{
|
|
||||||
// Obten las coordenadas del elemento actual
|
|
||||||
selector.y = selector.originY = item[selector.index].rect.y;
|
|
||||||
selector.h = selector.originH = getSelectorHeight(selector.index);
|
|
||||||
|
|
||||||
// Calcula cual es el siguiente elemento
|
|
||||||
++selector.index %= item.size();
|
|
||||||
while (!item[selector.index].selectable)
|
|
||||||
{
|
|
||||||
++selector.index %= item.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece las coordenadas y altura de destino
|
|
||||||
selector.targetY = item[selector.index].rect.y;
|
|
||||||
selector.despY = (selector.targetY - selector.originY) / selector.numJumps;
|
|
||||||
|
|
||||||
selector.targetH = getSelectorHeight(selector.index);
|
|
||||||
selector.incH = (selector.targetH - selector.originH) / selector.numJumps;
|
|
||||||
|
|
||||||
selector.moving = true;
|
|
||||||
if (selector.incH != 0)
|
|
||||||
{
|
|
||||||
selector.resizing = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deja el menu apuntando al elemento anterior
|
|
||||||
bool Menu::decreaseSelectorIndex()
|
|
||||||
{
|
|
||||||
// Obten las coordenadas del elemento actual
|
|
||||||
selector.y = selector.originY = item[selector.index].rect.y;
|
|
||||||
selector.h = selector.originH = getSelectorHeight(selector.index);
|
|
||||||
|
|
||||||
// Calcula cual es el siguiente elemento
|
|
||||||
if (selector.index == 0)
|
|
||||||
{
|
|
||||||
selector.index = item.size() - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
selector.index--;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!item[selector.index].selectable)
|
|
||||||
{
|
|
||||||
if (selector.index == 0)
|
|
||||||
{
|
|
||||||
selector.index = item.size() - 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
selector.index--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece las coordenadas y altura de destino
|
|
||||||
selector.targetY = item[selector.index].rect.y;
|
|
||||||
selector.despY = (selector.targetY - selector.originY) / selector.numJumps;
|
|
||||||
|
|
||||||
selector.targetH = getSelectorHeight(selector.index);
|
|
||||||
selector.incH = (selector.targetH - selector.originH) / selector.numJumps;
|
|
||||||
|
|
||||||
selector.moving = true;
|
|
||||||
if (selector.incH != 0)
|
|
||||||
{
|
|
||||||
selector.resizing = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza la logica del menu
|
|
||||||
void Menu::update()
|
|
||||||
{
|
|
||||||
checkInput();
|
|
||||||
updateSelector();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pinta el menu en pantalla
|
|
||||||
void Menu::render()
|
|
||||||
{
|
|
||||||
// Rendereritza el fondo del menu
|
|
||||||
if (backgroundType == MENU_BACKGROUND_SOLID)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer, rectBG.color.r, rectBG.color.g, rectBG.color.b, rectBG.a);
|
|
||||||
SDL_RenderFillRect(renderer, &rectBG.rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renderiza el rectangulo del selector
|
|
||||||
const SDL_Rect temp = {selector.rect.x, selector.rect.y - 1, selector.rect.w, selector.rect.h + 1};
|
|
||||||
SDL_SetRenderDrawColor(renderer, selector.color.r, selector.color.g, selector.color.b, selector.a);
|
|
||||||
SDL_RenderFillRect(renderer, &temp);
|
|
||||||
|
|
||||||
// Renderiza el borde del fondo
|
|
||||||
if (backgroundType == MENU_BACKGROUND_SOLID)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer, rectBG.color.r, rectBG.color.g, rectBG.color.b, 255);
|
|
||||||
SDL_RenderDrawRect(renderer, &rectBG.rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Renderiza el texto
|
|
||||||
for (int i = 0; i < (int)item.size(); ++i)
|
|
||||||
{
|
|
||||||
if (i == selector.index)
|
|
||||||
{
|
|
||||||
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
|
|
||||||
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (item[i].selectable)
|
|
||||||
{
|
|
||||||
text->write(item[i].rect.x, item[i].rect.y, item[i].label);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (item[i].greyed)
|
|
||||||
{
|
|
||||||
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, colorGreyed);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{ // No seleccionable
|
|
||||||
if ((item[i].linkedUp) && (i == selector.index + 1))
|
|
||||||
{
|
|
||||||
const color_t color = {selector.itemColor.r, selector.itemColor.g, selector.itemColor.b};
|
|
||||||
text->writeColored(item[i].rect.x, item[i].rect.y, item[i].label, color);
|
|
||||||
}
|
|
||||||
else // No enlazado con el de arriba
|
|
||||||
{
|
|
||||||
text->write(item[i].rect.x, item[i].rect.y, item[i].label);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el rectangulo de fondo del menu y el selector
|
|
||||||
void Menu::setRectSize(int w, int h)
|
|
||||||
{
|
|
||||||
// Establece el ancho
|
|
||||||
if (w == 0)
|
|
||||||
{ // Si no se pasa un valor, se busca si hay uno prefijado
|
|
||||||
if (this->w == 0)
|
|
||||||
{ // Si no hay prefijado, coge el item mas ancho
|
|
||||||
rectBG.rect.w = findWidth() + text->getCharacterSize();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Si hay prefijado, coge ese
|
|
||||||
rectBG.rect.w = this->w;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Si se pasa un valor, se usa y se prefija
|
|
||||||
rectBG.rect.w = w;
|
|
||||||
this->w = w;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el alto
|
|
||||||
if (h == 0)
|
|
||||||
{ // Si no se pasa un valor, se busca de manera automatica
|
|
||||||
rectBG.rect.h = findHeight() + text->getCharacterSize();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Si se pasa un valor, se aplica
|
|
||||||
rectBG.rect.h = h;
|
|
||||||
}
|
|
||||||
|
|
||||||
// La posición X es la del menú menos medio caracter
|
|
||||||
if (this->w != 0)
|
|
||||||
{ // Si el ancho esta prefijado, la x coinccide
|
|
||||||
rectBG.rect.x = x;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Si el ancho es automatico, se le da un poco de margen
|
|
||||||
rectBG.rect.x = x - (text->getCharacterSize() / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// La posición Y es la del menu menos la altura de medio caracter
|
|
||||||
rectBG.rect.y = y - (text->getCharacterSize() / 2);
|
|
||||||
|
|
||||||
// Establecemos los valores del rectangulo del selector a partir de los valores del rectangulo de fondo
|
|
||||||
setSelectorPos(selector.index);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el color del rectangulo de fondo
|
|
||||||
void Menu::setBackgroundColor(color_t color, int alpha)
|
|
||||||
{
|
|
||||||
rectBG.color = color;
|
|
||||||
rectBG.a = alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el color del rectangulo del selector
|
|
||||||
void Menu::setSelectorColor(color_t color, int alpha)
|
|
||||||
{
|
|
||||||
selector.color = color;
|
|
||||||
selector.a = alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el color del texto del selector
|
|
||||||
void Menu::setSelectorTextColor(color_t color)
|
|
||||||
{
|
|
||||||
selector.itemColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Centra el menu respecto un punto en el eje X
|
|
||||||
void Menu::centerMenuOnX(int value)
|
|
||||||
{
|
|
||||||
isCenteredOnX = true;
|
|
||||||
if (value != 0)
|
|
||||||
{
|
|
||||||
centerX = value;
|
|
||||||
}
|
|
||||||
else if (centerX == 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece la nueva posición centrada en funcion del elemento más ancho o del ancho fijo del menu
|
|
||||||
if (w != 0)
|
|
||||||
{ // Si se ha definido un ancho fijo
|
|
||||||
x = (centerX) - (w / 2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Si se actua en función del elemento más ancho
|
|
||||||
x = (centerX) - (findWidth() / 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el rectangulo de fondo y del selector
|
|
||||||
rectBG.rect.x = x;
|
|
||||||
selector.rect.x = x;
|
|
||||||
|
|
||||||
// Reposiciona los elementos del menu
|
|
||||||
for (auto &i : item)
|
|
||||||
{
|
|
||||||
i.rect.x = x;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recalcula el rectangulo de fondo
|
|
||||||
setRectSize();
|
|
||||||
|
|
||||||
// Vuelve a centrar los elementos si fuera el caso
|
|
||||||
if (areElementsCenteredOnX)
|
|
||||||
{
|
|
||||||
centerMenuElementsOnX();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Centra el menu respecto un punto en el eje Y
|
|
||||||
void Menu::centerMenuOnY(int value)
|
|
||||||
{
|
|
||||||
isCenteredOnY = true;
|
|
||||||
centerY = value;
|
|
||||||
|
|
||||||
// Establece la nueva posición centrada en funcion del elemento más ancho
|
|
||||||
y = (value) - (findHeight() / 2);
|
|
||||||
|
|
||||||
// Reposiciona los elementos del menu
|
|
||||||
replaceElementsOnY();
|
|
||||||
|
|
||||||
// Recalcula el rectangulo de fondo
|
|
||||||
setRectSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Centra los elementos del menu en el eje X
|
|
||||||
void Menu::centerMenuElementsOnX()
|
|
||||||
{
|
|
||||||
areElementsCenteredOnX = true;
|
|
||||||
|
|
||||||
for (auto &i : item)
|
|
||||||
{
|
|
||||||
i.rect.x = (centerX - (i.rect.w / 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Añade un item al menu
|
|
||||||
void Menu::addItem(std::string text, int hPaddingDown, bool selectable, bool greyed, bool linkedDown)
|
|
||||||
{
|
|
||||||
item_t temp;
|
|
||||||
|
|
||||||
if (item.empty())
|
|
||||||
{ // Si es el primer item coge la posición en el eje Y del propio menu
|
|
||||||
temp.rect.y = y;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // En caso contrario, coge la posición en el eje Y a partir del último elemento
|
|
||||||
temp.rect.y = item.back().rect.y + item.back().rect.h + item.back().hPaddingDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
temp.rect.x = x;
|
|
||||||
temp.hPaddingDown = hPaddingDown;
|
|
||||||
temp.selectable = selectable;
|
|
||||||
temp.greyed = greyed;
|
|
||||||
temp.linkedDown = linkedDown;
|
|
||||||
|
|
||||||
item.push_back(temp);
|
|
||||||
|
|
||||||
setItemCaption(item.size() - 1, text);
|
|
||||||
|
|
||||||
if (item.size() > 1)
|
|
||||||
{
|
|
||||||
if (item[item.size() - 2].linkedDown)
|
|
||||||
{
|
|
||||||
item.back().linkedUp = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
centerX = x + (findWidth() / 2);
|
|
||||||
reorganize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el texto de un item
|
|
||||||
void Menu::setItemCaption(int index, std::string text)
|
|
||||||
{
|
|
||||||
item[index].label = text;
|
|
||||||
item[index].rect.w = this->text->lenght(item[index].label);
|
|
||||||
item[index].rect.h = this->text->getCharacterSize();
|
|
||||||
reorganize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el indice del itemm que se usará por defecto al cancelar el menu
|
|
||||||
void Menu::setDefaultActionWhenCancel(int item)
|
|
||||||
{
|
|
||||||
defaultActionWhenCancel = item;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gestiona la entrada de teclado y mando durante el menu
|
|
||||||
void Menu::checkInput()
|
|
||||||
{
|
|
||||||
if (input->checkInput(INPUT_UP, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
if (decreaseSelectorIndex())
|
|
||||||
{
|
|
||||||
if (soundMove)
|
|
||||||
{
|
|
||||||
JA_PlaySound(soundMove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input->checkInput(INPUT_DOWN, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
if (increaseSelectorIndex())
|
|
||||||
{
|
|
||||||
if (soundMove)
|
|
||||||
{
|
|
||||||
JA_PlaySound(soundMove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input->checkInput(INPUT_ACCEPT, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
itemSelected = selector.index;
|
|
||||||
if (soundAccept)
|
|
||||||
{
|
|
||||||
JA_PlaySound(soundAccept);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (input->checkInput(INPUT_CANCEL, REPEAT_FALSE))
|
|
||||||
{
|
|
||||||
itemSelected = defaultActionWhenCancel;
|
|
||||||
if (soundCancel)
|
|
||||||
{
|
|
||||||
JA_PlaySound(soundCancel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula el ancho del menu
|
|
||||||
int Menu::findWidth()
|
|
||||||
{
|
|
||||||
return getWidestItem();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula el alto del menu
|
|
||||||
int Menu::findHeight()
|
|
||||||
{
|
|
||||||
int height = 0;
|
|
||||||
|
|
||||||
// Obtenemos la altura de la suma de alturas de los items
|
|
||||||
for (auto &i : item)
|
|
||||||
{
|
|
||||||
height += i.rect.h + i.hPaddingDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
return height - item.back().hPaddingDown;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Recoloca los elementos del menu en el eje Y
|
|
||||||
void Menu::replaceElementsOnY()
|
|
||||||
{
|
|
||||||
item[0].rect.y = y;
|
|
||||||
|
|
||||||
for (int i = 1; i < (int)item.size(); i++)
|
|
||||||
{
|
|
||||||
item[i].rect.y = item[i - 1].rect.y + item[i - 1].rect.h + item[i - 1].hPaddingDown;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el estado seleccionable de un item
|
|
||||||
void Menu::setSelectable(int index, bool value)
|
|
||||||
{
|
|
||||||
item[index].selectable = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el estado agrisado de un item
|
|
||||||
void Menu::setGreyed(int index, bool value)
|
|
||||||
{
|
|
||||||
item[index].greyed = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el estado de enlace de un item
|
|
||||||
void Menu::setLinkedDown(int index, bool value)
|
|
||||||
{
|
|
||||||
item[index].linkedDown = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Calcula la altura del selector
|
|
||||||
int Menu::getSelectorHeight(int value)
|
|
||||||
{
|
|
||||||
if (item[value].linkedDown)
|
|
||||||
{
|
|
||||||
return item[value].rect.h + item[value].hPaddingDown + item[value + 1].rect.h;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return item[value].rect.h;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el nombre del menu
|
|
||||||
void Menu::setName(std::string name)
|
|
||||||
{
|
|
||||||
this->name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece la posición del menu
|
|
||||||
void Menu::setPos(int x, int y)
|
|
||||||
{
|
|
||||||
this->x = x;
|
|
||||||
this->y = y;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el tipo de fondo del menu
|
|
||||||
void Menu::setBackgroundType(int value)
|
|
||||||
{
|
|
||||||
backgroundType = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece la fuente de texto que se utilizará
|
|
||||||
void Menu::setText(std::string font_png, std::string font_txt)
|
|
||||||
{
|
|
||||||
if (!text)
|
|
||||||
{
|
|
||||||
text = new Text(resource->getOffset(font_txt), resource->getTexture(font_png), renderer);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,226 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "asset.h"
|
|
||||||
#include "input.h"
|
|
||||||
#include "jail_audio.h"
|
|
||||||
#include "resource.h"
|
|
||||||
#include "sprite.h"
|
|
||||||
#include "text.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef MENU_H
|
|
||||||
#define MENU_H
|
|
||||||
|
|
||||||
// Tipos de fondos para el menu
|
|
||||||
#define MENU_BACKGROUND_TRANSPARENT 0
|
|
||||||
#define MENU_BACKGROUND_SOLID 1
|
|
||||||
|
|
||||||
// Tipos de archivos de audio
|
|
||||||
#define SOUND_ACCEPT 0
|
|
||||||
#define SOUND_MOVE 1
|
|
||||||
#define SOUND_CANCEL 2
|
|
||||||
|
|
||||||
// Opciones de menu
|
|
||||||
#define MENU_NO_OPTION -1
|
|
||||||
|
|
||||||
// Clase Menu
|
|
||||||
class Menu
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
struct rectangle_t
|
|
||||||
{
|
|
||||||
SDL_Rect rect; // Rectangulo
|
|
||||||
color_t color; // Color
|
|
||||||
int a; // Transparencia
|
|
||||||
};
|
|
||||||
|
|
||||||
struct item_t
|
|
||||||
{
|
|
||||||
std::string label; // Texto
|
|
||||||
SDL_Rect rect; // Rectangulo que delimita el elemento
|
|
||||||
int hPaddingDown; // Espaciado bajo el elemento
|
|
||||||
bool selectable; // Indica si se puede seleccionar
|
|
||||||
bool greyed; // Indica si ha de aparecer con otro color mas oscuro
|
|
||||||
bool linkedDown; // Indica si el elemento actual y el siguiente se tratan como uno solo. Afecta al selector
|
|
||||||
bool linkedUp; // Indica si el elemento actual y el anterior se tratan como uno solo. Afecta al selector
|
|
||||||
};
|
|
||||||
|
|
||||||
struct selector_t
|
|
||||||
{
|
|
||||||
float originY; // Coordenada de origen
|
|
||||||
float targetY; // Coordenada de destino
|
|
||||||
float despY; // Cantidad de pixeles que se desplaza el selector en cada salto: (target - origin) / numJumps
|
|
||||||
bool moving; // Indica si el selector está avanzando hacia el destino
|
|
||||||
float originH; // Altura de origen
|
|
||||||
float targetH; // Altura de destino
|
|
||||||
float incH; // Cantidad de pixels que debe incrementar o decrementar el selector en cada salto
|
|
||||||
bool resizing; // Indica si el selector está cambiando de tamaño
|
|
||||||
float y; // Coordenada actual, usado para el desplazamiento
|
|
||||||
float h; // Altura actual, usado para el cambio de tamaño
|
|
||||||
int numJumps; // Numero de pasos preestablecido para llegar al destino
|
|
||||||
int index; // Elemento del menu que tiene el foco
|
|
||||||
SDL_Rect rect; // Rectangulo del selector
|
|
||||||
color_t color; // Color del selector
|
|
||||||
color_t itemColor; // Color del item
|
|
||||||
int a; // Cantidad de transparencia para el rectangulo del selector
|
|
||||||
};
|
|
||||||
|
|
||||||
// Objetos y punteros
|
|
||||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
|
||||||
Resource *resource; // Objeto con los recursos
|
|
||||||
Asset *asset; // Objeto para gestionar los ficheros de recursos
|
|
||||||
Text *text; // Texto para poder escribir los items del menu
|
|
||||||
Input *input; // Gestor de eventos de entrada de teclado o gamepad
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
std::string name; // Nombre del menu
|
|
||||||
int x; // Posición en el eje X de la primera letra del primer elemento
|
|
||||||
int y; // Posición en el eje Y de la primera letra del primer elemento
|
|
||||||
int h; // Altura del menu
|
|
||||||
int w; // Anchura del menu
|
|
||||||
int itemSelected; // Índice del item del menu que ha sido seleccionado
|
|
||||||
int defaultActionWhenCancel; // Indice del item del menu que se selecciona cuando se cancela el menu
|
|
||||||
int backgroundType; // Tipo de fondo para el menu
|
|
||||||
int centerX; // Centro del menu en el eje X
|
|
||||||
int centerY; // Centro del menu en el eje Y
|
|
||||||
bool isCenteredOnX; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje X
|
|
||||||
bool isCenteredOnY; // Variable para saber si el menu debe estar centrado respecto a un punto en el eje Y
|
|
||||||
bool areElementsCenteredOnX; // Variable para saber si los elementos van centrados en el eje X
|
|
||||||
int widestItem; // Anchura del elemento más ancho
|
|
||||||
JA_Sound_t* soundAccept; // Sonido al aceptar o elegir una opción del menu
|
|
||||||
JA_Sound_t* soundCancel; // Sonido al cancelar el menu
|
|
||||||
JA_Sound_t* soundMove; // Sonido al mover el selector
|
|
||||||
color_t colorGreyed; // Color para los elementos agrisados
|
|
||||||
rectangle_t rectBG; // Rectangulo de fondo del menu
|
|
||||||
std::vector<item_t> item; // Estructura para cada elemento del menu
|
|
||||||
selector_t selector; // Variables para pintar el selector del menu
|
|
||||||
std::string font_png;
|
|
||||||
std::string font_txt;
|
|
||||||
|
|
||||||
// Carga la configuración del menu desde un archivo de texto
|
|
||||||
bool load(std::string file_path);
|
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
|
||||||
bool setVars(std::string var, std::string value);
|
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
|
||||||
bool setItem(item_t *item, std::string var, std::string value);
|
|
||||||
|
|
||||||
// Actualiza el menu para recolocarlo correctamente y establecer el tamaño
|
|
||||||
void reorganize();
|
|
||||||
|
|
||||||
// Deja el menu apuntando al siguiente elemento
|
|
||||||
bool increaseSelectorIndex();
|
|
||||||
|
|
||||||
// Deja el menu apuntando al elemento anterior
|
|
||||||
bool decreaseSelectorIndex();
|
|
||||||
|
|
||||||
// Actualiza la posicion y el estado del selector
|
|
||||||
void updateSelector();
|
|
||||||
|
|
||||||
// Obtiene la anchura del elemento más ancho del menu
|
|
||||||
int getWidestItem();
|
|
||||||
|
|
||||||
// Gestiona la entrada de teclado y mando durante el menu
|
|
||||||
void checkMenuInput(Menu *menu);
|
|
||||||
|
|
||||||
// Calcula el ancho del menu
|
|
||||||
int findWidth();
|
|
||||||
|
|
||||||
// Calcula el alto del menu
|
|
||||||
int findHeight();
|
|
||||||
|
|
||||||
// Recoloca los elementos del menu en el eje Y
|
|
||||||
void replaceElementsOnY();
|
|
||||||
|
|
||||||
// Calcula la altura del selector
|
|
||||||
int getSelectorHeight(int value);
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Menu(SDL_Renderer *renderer, Resource *resource, Asset *asset, Input *input, std::string file = "");
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Menu();
|
|
||||||
|
|
||||||
// Carga los ficheros de audio
|
|
||||||
void loadAudioFile(std::string file, int sound);
|
|
||||||
|
|
||||||
// Obtiene el nombre del menu
|
|
||||||
std::string getName();
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
int getItemSelected();
|
|
||||||
|
|
||||||
// Deja el menu apuntando al primer elemento
|
|
||||||
void reset();
|
|
||||||
|
|
||||||
// Gestiona la entrada de teclado y mando durante el menu
|
|
||||||
void checkInput();
|
|
||||||
|
|
||||||
// Actualiza la logica del menu
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Pinta el menu en pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Establece el color del rectangulo de fondo
|
|
||||||
void setBackgroundColor(color_t color, int alpha);
|
|
||||||
|
|
||||||
// Establece el color del rectangulo del selector
|
|
||||||
void setSelectorColor(color_t color, int alpha);
|
|
||||||
|
|
||||||
// Establece el color del texto del selector
|
|
||||||
void setSelectorTextColor(color_t color);
|
|
||||||
|
|
||||||
// Centra el menu respecto a un punto en el eje X
|
|
||||||
void centerMenuOnX(int value = 0);
|
|
||||||
|
|
||||||
// Centra el menu respecto a un punto en el eje Y
|
|
||||||
void centerMenuOnY(int value);
|
|
||||||
|
|
||||||
// Centra los elementos del menu en el eje X
|
|
||||||
void centerMenuElementsOnX();
|
|
||||||
|
|
||||||
// Añade un item al menu
|
|
||||||
void addItem(std::string text, int hPaddingDown = 1, bool selectable = true, bool greyed = false, bool linkedDown = false);
|
|
||||||
|
|
||||||
// Cambia el texto de un item
|
|
||||||
void setItemCaption(int index, std::string text);
|
|
||||||
|
|
||||||
// Establece el indice del item que se usará por defecto al cancelar el menu
|
|
||||||
void setDefaultActionWhenCancel(int item);
|
|
||||||
|
|
||||||
// Coloca el selector en una posición específica
|
|
||||||
void setSelectorPos(int index);
|
|
||||||
|
|
||||||
// Establece el estado seleccionable de un item
|
|
||||||
void setSelectable(int index, bool value);
|
|
||||||
|
|
||||||
// Establece el estado agrisado de un item
|
|
||||||
void setGreyed(int index, bool value);
|
|
||||||
|
|
||||||
// Establece el estado de enlace de un item
|
|
||||||
void setLinkedDown(int index, bool value);
|
|
||||||
|
|
||||||
// Establece el nombre del menu
|
|
||||||
void setName(std::string name);
|
|
||||||
|
|
||||||
// Establece la posición del menu
|
|
||||||
void setPos(int x, int y);
|
|
||||||
|
|
||||||
// Establece el tipo de fondo del menu
|
|
||||||
void setBackgroundType(int value);
|
|
||||||
|
|
||||||
// Establece la fuente de texto que se utilizará
|
|
||||||
void setText(std::string font_png, std::string font_txt);
|
|
||||||
|
|
||||||
// Establece el rectangulo de fondo del menu
|
|
||||||
void setRectSize(int w = 0, int h = 0);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,223 +0,0 @@
|
|||||||
#include "notify.h"
|
|
||||||
#include <string>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Notify::Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options)
|
|
||||||
{
|
|
||||||
// Inicializa variables
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->options = options;
|
|
||||||
bgColor = options->notifications.color;
|
|
||||||
waitTime = 300;
|
|
||||||
|
|
||||||
// Crea objetos
|
|
||||||
texture = new Texture(renderer, bitmapFile);
|
|
||||||
text = new Text(textFile, texture, renderer);
|
|
||||||
sound = JA_LoadSound(soundFile.c_str());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Notify::~Notify()
|
|
||||||
{
|
|
||||||
// Libera la memoria de los objetos
|
|
||||||
delete texture;
|
|
||||||
delete text;
|
|
||||||
JA_DeleteSound(sound);
|
|
||||||
|
|
||||||
for (auto notification : notifications)
|
|
||||||
{
|
|
||||||
delete notification.sprite;
|
|
||||||
delete notification.texture;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja las notificaciones por pantalla
|
|
||||||
void Notify::render()
|
|
||||||
{
|
|
||||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
notifications[i].sprite->render();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el estado de las notificaiones
|
|
||||||
void Notify::update()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < (int)notifications.size(); ++i)
|
|
||||||
{
|
|
||||||
notifications[i].counter++;
|
|
||||||
|
|
||||||
// Comprueba los estados
|
|
||||||
if (notifications[i].state == ns_rising)
|
|
||||||
{
|
|
||||||
const float step = ((float)notifications[i].counter / notifications[i].travelDist);
|
|
||||||
const int alpha = 255 * step;
|
|
||||||
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
notifications[i].rect.y++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notifications[i].rect.y--;
|
|
||||||
}
|
|
||||||
notifications[i].texture->setAlpha(alpha);
|
|
||||||
|
|
||||||
if (notifications[i].rect.y == notifications[i].y)
|
|
||||||
{
|
|
||||||
notifications[i].state = ns_stay;
|
|
||||||
notifications[i].texture->setAlpha(255);
|
|
||||||
notifications[i].counter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (notifications[i].state == ns_stay)
|
|
||||||
{
|
|
||||||
if (notifications[i].counter == waitTime)
|
|
||||||
{
|
|
||||||
notifications[i].state = ns_vanishing;
|
|
||||||
notifications[i].counter = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (notifications[i].state == ns_vanishing)
|
|
||||||
{
|
|
||||||
|
|
||||||
const float step = (notifications[i].counter / (float)notifications[i].travelDist);
|
|
||||||
const int alpha = 255 * (1 - step);
|
|
||||||
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
notifications[i].rect.y--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notifications[i].rect.y++;
|
|
||||||
}
|
|
||||||
notifications[i].texture->setAlpha(alpha);
|
|
||||||
|
|
||||||
if (notifications[i].rect.y == notifications[i].y - notifications[i].travelDist)
|
|
||||||
{
|
|
||||||
notifications[i].state = ns_finished;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications[i].sprite->setRect(notifications[i].rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
clearFinishedNotifications();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Elimina las notificaciones finalizadas
|
|
||||||
void Notify::clearFinishedNotifications()
|
|
||||||
{
|
|
||||||
for (int i = (int)notifications.size() - 1; i >= 0; --i)
|
|
||||||
{
|
|
||||||
if (notifications[i].state == ns_finished)
|
|
||||||
{
|
|
||||||
delete notifications[i].sprite;
|
|
||||||
delete notifications[i].texture;
|
|
||||||
notifications.erase(notifications.begin() + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
|
||||||
void Notify::showText(std::string text)
|
|
||||||
{
|
|
||||||
// Inicializa variables
|
|
||||||
const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2);
|
|
||||||
const int height = this->text->getCharacterSize() * 2;
|
|
||||||
const int padding = (this->text->getCharacterSize() / 2);
|
|
||||||
|
|
||||||
// Posición horizontal
|
|
||||||
int despH = 0;
|
|
||||||
if (options->notifications.posH == pos_left)
|
|
||||||
{
|
|
||||||
despH = padding;
|
|
||||||
}
|
|
||||||
else if (options->notifications.posH == pos_middle)
|
|
||||||
{
|
|
||||||
despH = ((options->screen.windowWidth * options->windowSize) / 2 - (width / 2));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
despH = (options->screen.windowWidth * options->windowSize) - width - padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Posición vertical
|
|
||||||
int despV = 0;
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
despV = padding;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
despV = (options->screen.windowHeight * options->windowSize) - height - padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
const int travelDist = height + padding;
|
|
||||||
|
|
||||||
// Offset
|
|
||||||
int offset = 0;
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
offset = (int)notifications.size() > 0 ? notifications.back().y + travelDist : despV;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
offset = (int)notifications.size() > 0 ? notifications.back().y - travelDist : despV;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crea la notificacion
|
|
||||||
notification_t n;
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
n.y = offset;
|
|
||||||
n.travelDist = travelDist;
|
|
||||||
n.counter = 0;
|
|
||||||
n.state = ns_rising;
|
|
||||||
n.text = text;
|
|
||||||
if (options->notifications.posV == pos_top)
|
|
||||||
{
|
|
||||||
n.rect = {despH, offset - travelDist, width, height};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
n.rect = {despH, offset + travelDist, width, height};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Crea la textura
|
|
||||||
n.texture = new Texture(renderer);
|
|
||||||
n.texture->createBlank(renderer, width, height, SDL_TEXTUREACCESS_TARGET);
|
|
||||||
n.texture->setAsRenderTarget(renderer);
|
|
||||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
|
||||||
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, padding, text, 1, {255, 255, 255}, 1, {0, 0, 0});
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
// Crea el sprite
|
|
||||||
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
|
||||||
|
|
||||||
// Añade la notificación a la lista
|
|
||||||
notifications.push_back(n);
|
|
||||||
|
|
||||||
// Reproduce el sonido de la notificación
|
|
||||||
if (options->notifications.sound)
|
|
||||||
{
|
|
||||||
JA_PlaySound(sound);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
|
||||||
bool Notify::active()
|
|
||||||
{
|
|
||||||
if ((int)notifications.size() > 0)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@@ -1,85 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "jail_audio.h"
|
|
||||||
#include "sprite.h"
|
|
||||||
#include "text.h"
|
|
||||||
#include "texture.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef NOTIFY_H
|
|
||||||
#define NOTIFY_H
|
|
||||||
|
|
||||||
class Notify
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
enum notification_state_e
|
|
||||||
{
|
|
||||||
ns_rising,
|
|
||||||
ns_stay,
|
|
||||||
ns_vanishing,
|
|
||||||
ns_finished
|
|
||||||
};
|
|
||||||
|
|
||||||
enum notification_position_e
|
|
||||||
{
|
|
||||||
upperLeft,
|
|
||||||
upperCenter,
|
|
||||||
upperRight,
|
|
||||||
middleLeft,
|
|
||||||
middleRight,
|
|
||||||
bottomLeft,
|
|
||||||
bottomCenter,
|
|
||||||
bottomRight
|
|
||||||
};
|
|
||||||
|
|
||||||
struct notification_t
|
|
||||||
{
|
|
||||||
std::string text;
|
|
||||||
int counter;
|
|
||||||
notification_state_e state;
|
|
||||||
notification_position_e position;
|
|
||||||
Texture *texture;
|
|
||||||
Sprite *sprite;
|
|
||||||
SDL_Rect rect;
|
|
||||||
int y;
|
|
||||||
int travelDist;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Objetos y punteros
|
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
Texture *texture; // Textura para la fuente de las notificaciones
|
|
||||||
Text *text; // Objeto para dibujar texto
|
|
||||||
options_t *options; // Variable con todas las opciones del programa
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
color_t bgColor; // Color de fondo de las notificaciones
|
|
||||||
int waitTime; // Tiempo que se ve la notificación
|
|
||||||
std::vector<notification_t> notifications; // La lista de notificaciones activas
|
|
||||||
JA_Sound_t* sound; // Sonido a reproducir cuando suena la notificación
|
|
||||||
|
|
||||||
// Elimina las notificaciones finalizadas
|
|
||||||
void clearFinishedNotifications();
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Dibuja las notificaciones por pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Actualiza el estado de las notificaiones
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Notify(SDL_Renderer *renderer, std::string bitmapFile, std::string textFile, std::string soundFile, options_t *options);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Notify();
|
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
|
||||||
void showText(std::string text);
|
|
||||||
|
|
||||||
// Indica si hay notificaciones activas
|
|
||||||
bool active();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,413 +0,0 @@
|
|||||||
#include "screen.h"
|
|
||||||
#include <string>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
|
||||||
{
|
|
||||||
// Inicializa variables
|
|
||||||
this->window = window;
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->options = options;
|
|
||||||
this->asset = asset;
|
|
||||||
|
|
||||||
// Crea los objetos
|
|
||||||
notify = new Notify(renderer, asset->get("smb2.png"), asset->get("smb2.txt"), asset->get("notify.wav"), options);
|
|
||||||
|
|
||||||
gameCanvasWidth = options->gameWidth;
|
|
||||||
gameCanvasHeight = options->gameHeight;
|
|
||||||
borderWidth = options->borderWidth * 2;
|
|
||||||
borderHeight = options->borderHeight * 2;
|
|
||||||
notificationLogicalWidth = gameCanvasWidth;
|
|
||||||
notificationLogicalHeight = gameCanvasHeight;
|
|
||||||
|
|
||||||
iniFade();
|
|
||||||
iniSpectrumFade();
|
|
||||||
|
|
||||||
// Define el color del borde para el modo de pantalla completa
|
|
||||||
borderColor = {0x00, 0x00, 0x00};
|
|
||||||
|
|
||||||
// Crea la textura donde se dibujan los graficos del juego
|
|
||||||
gameCanvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, gameCanvasWidth, gameCanvasHeight);
|
|
||||||
if (gameCanvas == nullptr)
|
|
||||||
{
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << "TitleSurface could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el modo de video
|
|
||||||
setVideoMode(options->videoMode);
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
notifyActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Screen::~Screen()
|
|
||||||
{
|
|
||||||
delete notify;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
void Screen::clean(color_t color)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
void Screen::start()
|
|
||||||
{
|
|
||||||
SDL_SetRenderTarget(renderer, gameCanvas);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
void Screen::blit()
|
|
||||||
{
|
|
||||||
// Vuelve a dejar el renderizador en modo normal
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
|
|
||||||
// Borra el contenido previo
|
|
||||||
SDL_SetRenderDrawColor(renderer, borderColor.r, borderColor.g, borderColor.b, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
// Copia la textura de juego en el renderizador en la posición adecuada
|
|
||||||
SDL_RenderCopy(renderer, gameCanvas, nullptr, &dest);
|
|
||||||
|
|
||||||
// Dibuja las notificaciones
|
|
||||||
renderNotifications();
|
|
||||||
|
|
||||||
// Muestra por pantalla el renderizador
|
|
||||||
SDL_RenderPresent(renderer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el modo de video
|
|
||||||
void Screen::setVideoMode(int videoMode)
|
|
||||||
{
|
|
||||||
// Muestra el puntero
|
|
||||||
SDL_ShowCursor(SDL_ENABLE);
|
|
||||||
|
|
||||||
// Aplica el modo de video
|
|
||||||
SDL_SetWindowFullscreen(window, videoMode);
|
|
||||||
|
|
||||||
// Si está activo el modo ventana quita el borde
|
|
||||||
if (videoMode == 0)
|
|
||||||
{
|
|
||||||
if (options->borderEnabled)
|
|
||||||
{
|
|
||||||
windowWidth = gameCanvasWidth + borderWidth;
|
|
||||||
windowHeight = gameCanvasHeight + borderHeight;
|
|
||||||
dest = {0 + (borderWidth / 2), 0 + (borderHeight / 2), gameCanvasWidth, gameCanvasHeight};
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
windowWidth = gameCanvasWidth;
|
|
||||||
windowHeight = gameCanvasHeight;
|
|
||||||
dest = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modifica el tamaño del renderizador y de la ventana
|
|
||||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
|
||||||
SDL_SetWindowSize(window, windowWidth * options->windowSize, windowHeight * options->windowSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Si está activo el modo de pantalla completa añade el borde
|
|
||||||
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
|
||||||
{
|
|
||||||
// Oculta el puntero
|
|
||||||
SDL_ShowCursor(SDL_DISABLE);
|
|
||||||
|
|
||||||
// Obten el alto y el ancho de la ventana
|
|
||||||
SDL_GetWindowSize(window, &windowWidth, &windowHeight);
|
|
||||||
|
|
||||||
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
|
||||||
if (options->integerScale)
|
|
||||||
{
|
|
||||||
// Calcula el tamaño de la escala máxima
|
|
||||||
int scale = 0;
|
|
||||||
while (((gameCanvasWidth * (scale + 1)) <= windowWidth) && ((gameCanvasHeight * (scale + 1)) <= windowHeight))
|
|
||||||
{
|
|
||||||
scale++;
|
|
||||||
}
|
|
||||||
|
|
||||||
dest.w = gameCanvasWidth * scale;
|
|
||||||
dest.h = gameCanvasHeight * scale;
|
|
||||||
dest.x = (windowWidth - dest.w) / 2;
|
|
||||||
dest.y = (windowHeight - dest.h) / 2;
|
|
||||||
}
|
|
||||||
else if (options->keepAspect)
|
|
||||||
{
|
|
||||||
float ratio = (float)gameCanvasWidth / (float)gameCanvasHeight;
|
|
||||||
if ((windowWidth - gameCanvasWidth) >= (windowHeight - gameCanvasHeight))
|
|
||||||
{
|
|
||||||
dest.h = windowHeight;
|
|
||||||
dest.w = (int)((windowHeight * ratio) + 0.5f);
|
|
||||||
dest.x = (windowWidth - dest.w) / 2;
|
|
||||||
dest.y = (windowHeight - dest.h) / 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dest.w = windowWidth;
|
|
||||||
dest.h = (int)((windowWidth / ratio) + 0.5f);
|
|
||||||
dest.x = (windowWidth - dest.w) / 2;
|
|
||||||
dest.y = (windowHeight - dest.h) / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dest.w = windowWidth;
|
|
||||||
dest.h = windowHeight;
|
|
||||||
dest.x = dest.y = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Modifica el tamaño del renderizador
|
|
||||||
SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las opciones
|
|
||||||
options->videoMode = videoMode;
|
|
||||||
options->screen.windowWidth = windowWidth;
|
|
||||||
options->screen.windowHeight = windowHeight;
|
|
||||||
|
|
||||||
// Establece el tamaño de las notificaciones
|
|
||||||
setNotificationSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
|
||||||
void Screen::switchVideoMode()
|
|
||||||
{
|
|
||||||
options->videoMode = (options->videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
|
||||||
setVideoMode(options->videoMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el tamaño de la ventana
|
|
||||||
void Screen::setWindowSize(int size)
|
|
||||||
{
|
|
||||||
options->windowSize = size;
|
|
||||||
setVideoMode(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el color del borde
|
|
||||||
void Screen::setBorderColor(color_t color)
|
|
||||||
{
|
|
||||||
borderColor = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el tipo de mezcla
|
|
||||||
void Screen::setBlendMode(SDL_BlendMode blendMode)
|
|
||||||
{
|
|
||||||
SDL_SetRenderDrawBlendMode(renderer, blendMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el tamaño del borde
|
|
||||||
void Screen::setBorderWidth(int s)
|
|
||||||
{
|
|
||||||
options->borderWidth = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el tamaño del borde
|
|
||||||
void Screen::setBorderHeight(int s)
|
|
||||||
{
|
|
||||||
options->borderHeight = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece si se ha de ver el borde en el modo ventana
|
|
||||||
void Screen::setBorderEnabled(bool value)
|
|
||||||
{
|
|
||||||
options->borderEnabled = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia entre borde visible y no visible
|
|
||||||
void Screen::switchBorder()
|
|
||||||
{
|
|
||||||
options->borderEnabled = !options->borderEnabled;
|
|
||||||
setVideoMode(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activa el fade
|
|
||||||
void Screen::setFade()
|
|
||||||
{
|
|
||||||
fade = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el fade
|
|
||||||
bool Screen::fadeEnded()
|
|
||||||
{
|
|
||||||
if (fade || fadeCounter > 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activa el spectrum fade
|
|
||||||
void Screen::setspectrumFade()
|
|
||||||
{
|
|
||||||
spectrumFade = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el spectrum fade
|
|
||||||
bool Screen::spectrumFadeEnded()
|
|
||||||
{
|
|
||||||
if (spectrumFade || spectrumFadeCounter > 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade
|
|
||||||
void Screen::iniFade()
|
|
||||||
{
|
|
||||||
fade = false;
|
|
||||||
fadeCounter = 0;
|
|
||||||
fadeLenght = 200;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el fade
|
|
||||||
void Screen::updateFade()
|
|
||||||
{
|
|
||||||
if (!fade)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
fadeCounter++;
|
|
||||||
if (fadeCounter > fadeLenght)
|
|
||||||
{
|
|
||||||
iniFade();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja el fade
|
|
||||||
void Screen::renderFade()
|
|
||||||
{
|
|
||||||
if (!fade)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const SDL_Rect rect = {0, 0, gameCanvasWidth, gameCanvasHeight};
|
|
||||||
color_t color = {0, 0, 0};
|
|
||||||
const float step = (float)fadeCounter / (float)fadeLenght;
|
|
||||||
const int alpha = 0 + (255 - 0) * step;
|
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, alpha);
|
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade spectrum
|
|
||||||
void Screen::iniSpectrumFade()
|
|
||||||
{
|
|
||||||
spectrumFade = false;
|
|
||||||
spectrumFadeCounter = 0;
|
|
||||||
spectrumFadeLenght = 50;
|
|
||||||
|
|
||||||
spectrumColor.clear();
|
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
|
||||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
|
||||||
for (auto v : vColors)
|
|
||||||
{
|
|
||||||
spectrumColor.push_back(stringToColor(options->palette, v));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el spectrum fade
|
|
||||||
void Screen::updateSpectrumFade()
|
|
||||||
{
|
|
||||||
if (!spectrumFade)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
spectrumFadeCounter++;
|
|
||||||
if (spectrumFadeCounter > spectrumFadeLenght)
|
|
||||||
{
|
|
||||||
iniSpectrumFade();
|
|
||||||
SDL_SetTextureColorMod(gameCanvas, 255, 255, 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja el spectrum fade
|
|
||||||
void Screen::renderSpectrumFade()
|
|
||||||
{
|
|
||||||
if (!spectrumFade)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const float step = (float)spectrumFadeCounter / (float)spectrumFadeLenght;
|
|
||||||
const int max = spectrumColor.size() - 1;
|
|
||||||
const int index = max + (0 - max) * step;
|
|
||||||
const color_t c = spectrumColor[index];
|
|
||||||
SDL_SetTextureColorMod(gameCanvas, c.r, c.g, c.b);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza los efectos
|
|
||||||
void Screen::updateFX()
|
|
||||||
{
|
|
||||||
updateFade();
|
|
||||||
updateSpectrumFade();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja los efectos
|
|
||||||
void Screen::renderFX()
|
|
||||||
{
|
|
||||||
renderFade();
|
|
||||||
renderSpectrumFade();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza el notificador
|
|
||||||
void Screen::updateNotifier()
|
|
||||||
{
|
|
||||||
notify->update();
|
|
||||||
notifyActive = notify->active();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
|
||||||
void Screen::showNotification(std::string text)
|
|
||||||
{
|
|
||||||
notify->showText(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja las notificaciones
|
|
||||||
void Screen::renderNotifications()
|
|
||||||
{
|
|
||||||
if (!notifyActive)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//SDL_RenderSetLogicalSize(renderer, notificationLogicalWidth, notificationLogicalHeight);
|
|
||||||
notify->render();
|
|
||||||
//SDL_RenderSetLogicalSize(renderer, windowWidth, windowHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Establece el tamaño de las notificaciones
|
|
||||||
void Screen::setNotificationSize()
|
|
||||||
{
|
|
||||||
if (options->videoMode == 0)
|
|
||||||
{
|
|
||||||
if (options->windowSize == 3)
|
|
||||||
{
|
|
||||||
notificationLogicalWidth = (windowWidth * 3) / 2;
|
|
||||||
notificationLogicalHeight = (windowHeight * 3) / 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
notificationLogicalWidth = windowWidth * 2;
|
|
||||||
notificationLogicalHeight = windowHeight * 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
|
||||||
{
|
|
||||||
notificationLogicalWidth = windowWidth / 3;
|
|
||||||
notificationLogicalHeight = windowHeight / 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,138 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "asset.h"
|
|
||||||
#include "notify.h"
|
|
||||||
#include "utils.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef SCREEN_H
|
|
||||||
#define SCREEN_H
|
|
||||||
|
|
||||||
#define FILTER_NEAREST 0
|
|
||||||
#define FILTER_LINEAL 1
|
|
||||||
|
|
||||||
class Screen
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
// Objetos y punteros
|
|
||||||
SDL_Window *window; // Ventana de la aplicación
|
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
Asset *asset; // Objeto con el listado de recursos
|
|
||||||
SDL_Texture *gameCanvas; // Textura para completar la ventana de juego hasta la pantalla completa
|
|
||||||
options_t *options; // Variable con todas las opciones del programa
|
|
||||||
Notify *notify; // Dibuja notificaciones por pantalla
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
int windowWidth; // Ancho de la pantalla o ventana
|
|
||||||
int windowHeight; // Alto de la pantalla o ventana
|
|
||||||
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
|
||||||
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
|
||||||
int borderWidth; // Anchura del borde
|
|
||||||
int borderHeight; // Anltura del borde
|
|
||||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
|
||||||
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
|
||||||
bool notifyActive; // Indica si hay notificaciones activas
|
|
||||||
int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
|
|
||||||
int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla
|
|
||||||
|
|
||||||
// Variables - Efectos
|
|
||||||
bool fade; // Indica si esta activo el efecto de fade
|
|
||||||
int fadeCounter; // Temporizador para el efecto de fade
|
|
||||||
int fadeLenght; // Duración del fade
|
|
||||||
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
|
||||||
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
|
||||||
int spectrumFadeLenght; // Duración del fade spectrum
|
|
||||||
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade
|
|
||||||
void iniFade();
|
|
||||||
|
|
||||||
// Actualiza el fade
|
|
||||||
void updateFade();
|
|
||||||
|
|
||||||
// Dibuja el fade
|
|
||||||
void renderFade();
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade spectrum
|
|
||||||
void iniSpectrumFade();
|
|
||||||
|
|
||||||
// Actualiza el spectrum fade
|
|
||||||
void updateSpectrumFade();
|
|
||||||
|
|
||||||
// Dibuja el spectrum fade
|
|
||||||
void renderSpectrumFade();
|
|
||||||
|
|
||||||
// Dibuja las notificaciones
|
|
||||||
void renderNotifications();
|
|
||||||
|
|
||||||
// Establece el tamaño de las notificaciones
|
|
||||||
void setNotificationSize();
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Screen();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
void clean(color_t color = {0x00, 0x00, 0x00});
|
|
||||||
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
void start();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
void blit();
|
|
||||||
|
|
||||||
// Establece el modo de video
|
|
||||||
void setVideoMode(int videoMode);
|
|
||||||
|
|
||||||
// Camibia entre pantalla completa y ventana
|
|
||||||
void switchVideoMode();
|
|
||||||
|
|
||||||
// Cambia el tamaño de la ventana
|
|
||||||
void setWindowSize(int size);
|
|
||||||
|
|
||||||
// Cambia el color del borde
|
|
||||||
void setBorderColor(color_t color);
|
|
||||||
|
|
||||||
// Cambia el tipo de mezcla
|
|
||||||
void setBlendMode(SDL_BlendMode blendMode);
|
|
||||||
|
|
||||||
// Establece el tamaño del borde
|
|
||||||
void setBorderWidth(int s);
|
|
||||||
void setBorderHeight(int s);
|
|
||||||
|
|
||||||
// Establece si se ha de ver el borde en el modo ventana
|
|
||||||
void setBorderEnabled(bool value);
|
|
||||||
|
|
||||||
// Cambia entre borde visible y no visible
|
|
||||||
void switchBorder();
|
|
||||||
|
|
||||||
// Activa el fade
|
|
||||||
void setFade();
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el fade
|
|
||||||
bool fadeEnded();
|
|
||||||
|
|
||||||
// Activa el spectrum fade
|
|
||||||
void setspectrumFade();
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el spectrum fade
|
|
||||||
bool spectrumFadeEnded();
|
|
||||||
|
|
||||||
// Actualiza los efectos
|
|
||||||
void updateFX();
|
|
||||||
|
|
||||||
// Dibuja los efectos
|
|
||||||
void renderFX();
|
|
||||||
|
|
||||||
// Actualiza el notificador
|
|
||||||
void updateNotifier();
|
|
||||||
|
|
||||||
// Muestra una notificación de texto por pantalla;
|
|
||||||
void showNotification(std::string text);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,200 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "texture.h"
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifndef UTILS_H
|
|
||||||
#define UTILS_H
|
|
||||||
|
|
||||||
// Estructura para definir un circulo
|
|
||||||
struct circle_t
|
|
||||||
{
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
int r;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para definir una linea horizontal
|
|
||||||
struct h_line_t
|
|
||||||
{
|
|
||||||
int x1, x2, y;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para definir una linea vertical
|
|
||||||
struct v_line_t
|
|
||||||
{
|
|
||||||
int x, y1, y2;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para definir una linea diagonal
|
|
||||||
struct d_line_t
|
|
||||||
{
|
|
||||||
int x1, y1, x2, y2;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para definir una linea
|
|
||||||
struct line_t
|
|
||||||
{
|
|
||||||
int x1, y1, x2, y2;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para definir un color
|
|
||||||
struct color_t
|
|
||||||
{
|
|
||||||
Uint8 r;
|
|
||||||
Uint8 g;
|
|
||||||
Uint8 b;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Tipos de paleta
|
|
||||||
enum palette_e
|
|
||||||
{
|
|
||||||
p_zxspectrum,
|
|
||||||
p_zxarne
|
|
||||||
};
|
|
||||||
|
|
||||||
// Posiciones de las notificaciones
|
|
||||||
enum not_pos_e
|
|
||||||
{
|
|
||||||
pos_top,
|
|
||||||
pos_bottom,
|
|
||||||
pos_left,
|
|
||||||
pos_middle,
|
|
||||||
pos_right
|
|
||||||
};
|
|
||||||
|
|
||||||
// Tipos de control de teclado
|
|
||||||
enum ctrl_schem_e
|
|
||||||
{
|
|
||||||
ctrl_cursor,
|
|
||||||
ctrl_opqa,
|
|
||||||
ctrl_wasd
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para las opciones de las notificaciones
|
|
||||||
struct op_notification_t
|
|
||||||
{
|
|
||||||
not_pos_e posH; // Ubicación de las notificaciones en pantalla
|
|
||||||
not_pos_e posV; // Ubicación de las notificaciones en pantalla
|
|
||||||
bool sound; // Indica si las notificaciones suenan
|
|
||||||
color_t color; // Color de las notificaciones
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para saber la seccion y subseccion del programa
|
|
||||||
struct section_t
|
|
||||||
{
|
|
||||||
Uint8 name;
|
|
||||||
Uint8 subsection;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para albergar trucos
|
|
||||||
struct cheat_t
|
|
||||||
{
|
|
||||||
bool infiniteLives; // Indica si el jugador dispone de vidas infinitas
|
|
||||||
bool invincible; // Indica si el jugador puede morir
|
|
||||||
bool jailEnabled; // Indica si la Jail está abierta
|
|
||||||
bool altSkin; // Indicxa si se usa una skin diferente para el jugador
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para el servicio online
|
|
||||||
struct online_t
|
|
||||||
{
|
|
||||||
bool enabled; // Indica si se quiere usar el modo online o no
|
|
||||||
bool sessionEnabled; // Indica ya se ha hecho login
|
|
||||||
std::string server; // Servidor para los servicios online
|
|
||||||
int port; // Puerto del servidor
|
|
||||||
std::string gameID; // Identificador del juego para los servicios online
|
|
||||||
std::string jailerID; // Identificador del jugador para los servicios online
|
|
||||||
int score; // Puntuación almacenada online
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura para almacenar estadísticas
|
|
||||||
struct op_stats_t
|
|
||||||
{
|
|
||||||
int rooms; // Cantidad de habitaciones visitadas
|
|
||||||
int items; // Cantidad de items obtenidos
|
|
||||||
std::string worstNightmare; // Habitación con más muertes acumuladas
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura con opciones de la pantalla
|
|
||||||
struct op_screen_t
|
|
||||||
{
|
|
||||||
int windowWidth; // Ancho de la ventana
|
|
||||||
int windowHeight; // Alto de la ventana
|
|
||||||
};
|
|
||||||
|
|
||||||
// Estructura con todas las opciones de configuración del programa
|
|
||||||
struct options_t
|
|
||||||
{
|
|
||||||
std::string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
|
|
||||||
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
|
|
||||||
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
|
||||||
Uint32 filter; // Filtro usado para el escalado de la imagen
|
|
||||||
bool vSync; // Indica si se quiere usar vsync o no
|
|
||||||
int gameWidth; // Ancho de la resolucion nativa del juego
|
|
||||||
int gameHeight; // Alto de la resolucion nativa del juego
|
|
||||||
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
|
||||||
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
|
||||||
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
|
||||||
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
|
|
||||||
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
|
|
||||||
palette_e palette; // Paleta de colores a usar en el juego
|
|
||||||
bool console; // Indica si ha de mostrar información por la consola de texto
|
|
||||||
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
|
||||||
op_stats_t stats; // Datos con las estadisticas de juego
|
|
||||||
online_t online; // Datos del servicio online
|
|
||||||
op_notification_t notifications; // Opciones relativas a las notificaciones;
|
|
||||||
op_screen_t screen; // Opciones relativas a la clase screen
|
|
||||||
ctrl_schem_e keys; // Teclas usadas para jugar
|
|
||||||
};
|
|
||||||
|
|
||||||
// Calcula el cuadrado de la distancia entre dos puntos
|
|
||||||
double distanceSquared(int x1, int y1, int x2, int y2);
|
|
||||||
|
|
||||||
// Detector de colisiones entre dos circulos
|
|
||||||
bool checkCollision(circle_t &a, circle_t &b);
|
|
||||||
|
|
||||||
// Detector de colisiones entre un circulo y un rectangulo
|
|
||||||
bool checkCollision(circle_t &a, SDL_Rect &b);
|
|
||||||
|
|
||||||
// Detector de colisiones entre un dos rectangulos
|
|
||||||
bool checkCollision(SDL_Rect &a, SDL_Rect &b);
|
|
||||||
|
|
||||||
// Detector de colisiones entre un punto y un rectangulo
|
|
||||||
bool checkCollision(SDL_Point &p, SDL_Rect &r);
|
|
||||||
|
|
||||||
// Detector de colisiones entre una linea horizontal y un rectangulo
|
|
||||||
bool checkCollision(h_line_t &l, SDL_Rect &r);
|
|
||||||
|
|
||||||
// Detector de colisiones entre una linea vertical y un rectangulo
|
|
||||||
bool checkCollision(v_line_t &l, SDL_Rect &r);
|
|
||||||
|
|
||||||
// Detector de colisiones entre una linea horizontal y un punto
|
|
||||||
bool checkCollision(h_line_t &l, SDL_Point &p);
|
|
||||||
|
|
||||||
// Detector de colisiones entre dos lineas
|
|
||||||
SDL_Point checkCollision(line_t &l1, line_t &l2);
|
|
||||||
|
|
||||||
// Detector de colisiones entre dos lineas
|
|
||||||
SDL_Point checkCollision(d_line_t &l1, v_line_t &l2);
|
|
||||||
|
|
||||||
// Detector de colisiones entre un punto y una linea diagonal
|
|
||||||
bool checkCollision(SDL_Point &p, d_line_t &l);
|
|
||||||
|
|
||||||
// Normaliza una linea diagonal
|
|
||||||
void normalizeLine(d_line_t &l);
|
|
||||||
|
|
||||||
// Devuelve un color_t a partir de un string
|
|
||||||
color_t stringToColor(palette_e pal, std::string str);
|
|
||||||
|
|
||||||
// Convierte una cadena en un valor booleano
|
|
||||||
bool stringToBool(std::string str);
|
|
||||||
|
|
||||||
// Convierte un valor booleano en una cadena
|
|
||||||
std::string boolToString(bool value);
|
|
||||||
|
|
||||||
// Compara dos colores
|
|
||||||
bool colorAreEqual(color_t color1, color_t color2);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -2,70 +2,66 @@
|
|||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "common/utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#ifndef CONST_H
|
|
||||||
#define CONST_H
|
|
||||||
|
|
||||||
// Textos
|
// Textos
|
||||||
#define WINDOW_CAPTION "JailDoctor's Dilemma"
|
constexpr const char* WINDOW_CAPTION = "JailDoctor's Dilemma";
|
||||||
#define TEXT_COPYRIGHT "@2022 JailDesigner"
|
constexpr const char* TEXT_COPYRIGHT = "@2022 JailDesigner";
|
||||||
#define VERSION "0.7"
|
constexpr const char* VERSION = "0.7";
|
||||||
|
|
||||||
// Tamaño de bloque
|
// Tamaño de bloque
|
||||||
#define BLOCK 8
|
constexpr int BLOCK = 8;
|
||||||
#define HALF_BLOCK 4
|
constexpr int HALF_BLOCK = 4;
|
||||||
|
|
||||||
// Tamaño de la pantalla virtual
|
// Tamaño de la pantalla virtual
|
||||||
#define GAMECANVAS_WIDTH 256
|
constexpr int GAMECANVAS_WIDTH = 256;
|
||||||
#define GAMECANVAS_HEIGHT 192
|
constexpr int GAMECANVAS_HEIGHT = 192;
|
||||||
|
|
||||||
// Zona de juego
|
// Zona de juego
|
||||||
const int PLAY_AREA_TOP = (0 * BLOCK);
|
constexpr int PLAY_AREA_TOP = (0 * BLOCK);
|
||||||
const int PLAY_AREA_BOTTOM = (16 * BLOCK);
|
constexpr int PLAY_AREA_BOTTOM = (16 * BLOCK);
|
||||||
const int PLAY_AREA_LEFT = (0 * BLOCK);
|
constexpr int PLAY_AREA_LEFT = (0 * BLOCK);
|
||||||
const int PLAY_AREA_RIGHT = (32 * BLOCK);
|
constexpr int PLAY_AREA_RIGHT = (32 * BLOCK);
|
||||||
const int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
constexpr int PLAY_AREA_WIDTH = PLAY_AREA_RIGHT - PLAY_AREA_LEFT;
|
||||||
const int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
constexpr int PLAY_AREA_HEIGHT = PLAY_AREA_BOTTOM - PLAY_AREA_TOP;
|
||||||
const int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
constexpr int PLAY_AREA_CENTER_X = PLAY_AREA_LEFT + (PLAY_AREA_WIDTH / 2);
|
||||||
const int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
|
constexpr int PLAY_AREA_CENTER_FIRST_QUARTER_X = (PLAY_AREA_WIDTH / 4);
|
||||||
const int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
|
constexpr int PLAY_AREA_CENTER_THIRD_QUARTER_X = (PLAY_AREA_WIDTH / 4) * 3;
|
||||||
const int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
|
constexpr int PLAY_AREA_CENTER_Y = PLAY_AREA_TOP + (PLAY_AREA_HEIGHT / 2);
|
||||||
const int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
constexpr int PLAY_AREA_FIRST_QUARTER_Y = PLAY_AREA_HEIGHT / 4;
|
||||||
const int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
constexpr int PLAY_AREA_THIRD_QUARTER_Y = (PLAY_AREA_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
#define BORDER_TOP 0
|
constexpr int BORDER_TOP = 0;
|
||||||
#define BORDER_RIGHT 1
|
constexpr int BORDER_RIGHT = 1;
|
||||||
#define BORDER_BOTTOM 2
|
constexpr int BORDER_BOTTOM = 2;
|
||||||
#define BORDER_LEFT 3
|
constexpr int BORDER_LEFT = 3;
|
||||||
|
|
||||||
// Anclajes de pantalla
|
// Anclajes de pantalla
|
||||||
const int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
|
constexpr int GAMECANVAS_CENTER_X = GAMECANVAS_WIDTH / 2;
|
||||||
const int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
|
constexpr int GAMECANVAS_FIRST_QUARTER_X = GAMECANVAS_WIDTH / 4;
|
||||||
const int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
|
constexpr int GAMECANVAS_THIRD_QUARTER_X = (GAMECANVAS_WIDTH / 4) * 3;
|
||||||
const int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
constexpr int GAMECANVAS_CENTER_Y = GAMECANVAS_HEIGHT / 2;
|
||||||
const int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
constexpr int GAMECANVAS_FIRST_QUARTER_Y = GAMECANVAS_HEIGHT / 4;
|
||||||
const int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
constexpr int GAMECANVAS_THIRD_QUARTER_Y = (GAMECANVAS_HEIGHT / 4) * 3;
|
||||||
|
|
||||||
// Secciones del programa
|
// Secciones del programa
|
||||||
#define SECTION_PROG_LOGO 0
|
constexpr int SECTION_LOGO = 0;
|
||||||
#define SECTION_PROG_INTRO 1
|
constexpr int SECTION_LOADING_SCREEN = 1;
|
||||||
#define SECTION_PROG_TITLE 2
|
constexpr int SECTION_TITLE = 2;
|
||||||
#define SECTION_PROG_CREDITS 3
|
constexpr int SECTION_CREDITS = 3;
|
||||||
#define SECTION_PROG_GAME 4
|
constexpr int SECTION_GAME = 4;
|
||||||
#define SECTION_PROG_DEMO 5
|
constexpr int SECTION_DEMO = 5;
|
||||||
#define SECTION_PROG_GAME_OVER 6
|
constexpr int SECTION_GAME_OVER = 6;
|
||||||
#define SECTION_PROG_ENDING 7
|
constexpr int SECTION_ENDING = 7;
|
||||||
#define SECTION_PROG_ENDING2 8
|
constexpr int SECTION_ENDING2 = 8;
|
||||||
#define SECTION_PROG_ENTER_ID 9
|
constexpr int SECTION_QUIT = 9;
|
||||||
#define SECTION_PROG_QUIT 10
|
|
||||||
|
|
||||||
// Subsecciones
|
// Subsecciones
|
||||||
#define SUBSECTION_LOGO_TO_INTRO 0
|
constexpr int SUBSECTION_LOGO_TO_INTRO = 0;
|
||||||
#define SUBSECTION_LOGO_TO_TITLE 1
|
constexpr int SUBSECTION_LOGO_TO_TITLE = 1;
|
||||||
|
constexpr int SUBSECTION_TITLE_WITH_LOADING_SCREEN = 2;
|
||||||
|
constexpr int SUBSECTION_TITLE_WITHOUT_LOADING_SCREEN = 3;
|
||||||
|
|
||||||
// Colores
|
// Colores
|
||||||
const color_t borderColor = {0x27, 0x27, 0x36};
|
const color_t borderColor = {0x27, 0x27, 0x36};
|
||||||
const color_t black = {0xFF, 0xFF, 0xFF};
|
const color_t black = {0xFF, 0xFF, 0xFF};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,55 +1,62 @@
|
|||||||
#include "credits.h"
|
#include "credits.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
|
#include <algorithm> // Para min
|
||||||
|
#include <iostream> // Para char_traits, basic_ostream, operator<<
|
||||||
|
#include "animatedsprite.h" // Para AnimatedSprite
|
||||||
|
#include "const.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
||||||
|
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "resource.h" // Para Resource
|
||||||
|
#include "screen.h" // Para Screen
|
||||||
|
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
|
||||||
|
#include "asset.h"
|
||||||
|
#include "options.h"
|
||||||
|
class Asset;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
|
Credits::Credits()
|
||||||
|
: screen_(Screen::get()),
|
||||||
|
renderer_(Screen::get()->getRenderer()),
|
||||||
|
resource_(Resource::get()),
|
||||||
|
asset_(Asset::get()),
|
||||||
|
input_(Input::get())
|
||||||
{
|
{
|
||||||
// Copia la dirección de los objetos
|
|
||||||
this->resource = resource;
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
eventHandler = new SDL_Event();
|
text_ = new Text(resource_->getOffset("smb2.txt"), resource_->getTexture("smb2.png"), renderer_);
|
||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
sprite_ = new AnimatedSprite(renderer_, resource_->getAnimation("shine.ani"));
|
||||||
sprite = new AnimatedSprite(renderer, resource->getAnimation("shine.ani"));
|
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
counter = 0;
|
options.section.name = SECTION_CREDITS;
|
||||||
counterEnabled = true;
|
options.section.subsection = 0;
|
||||||
subCounter = 0;
|
sprite_->setRect({194, 174, 8, 8});
|
||||||
section.name = SECTION_PROG_CREDITS;
|
|
||||||
section.subsection = 0;
|
|
||||||
ticks = 0;
|
|
||||||
ticksSpeed = 15;
|
|
||||||
sprite->setRect({194, 174, 8, 8});
|
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
screen_->setBorderColor(stringToColor(options.palette, "black"));
|
||||||
|
|
||||||
// Crea la textura para el texto que se escribe en pantalla
|
// Crea la textura para el texto que se escribe en pantalla
|
||||||
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
text_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||||
if (textTexture == nullptr)
|
if (text_texture_ == nullptr)
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Crea la textura para cubrir el rexto
|
// Crea la textura para cubrir el rexto
|
||||||
coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
cover_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
||||||
if (coverTexture == nullptr)
|
if (cover_texture_ == nullptr)
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_SetTextureBlendMode(coverTexture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(cover_texture_, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
fillTexture();
|
fillTexture();
|
||||||
@@ -58,75 +65,65 @@ Credits::Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
|
|||||||
// Destructor
|
// Destructor
|
||||||
Credits::~Credits()
|
Credits::~Credits()
|
||||||
{
|
{
|
||||||
delete eventHandler;
|
delete text_;
|
||||||
delete text;
|
delete sprite_;
|
||||||
delete sprite;
|
SDL_DestroyTexture(text_texture_);
|
||||||
SDL_DestroyTexture(textTexture);
|
SDL_DestroyTexture(cover_texture_);
|
||||||
SDL_DestroyTexture(coverTexture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void Credits::checkEventHandler()
|
void Credits::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.name = SECTION_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
// Comprueba las entradas
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
void Credits::checkInput()
|
||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.scancode)
|
|
||||||
|
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
options.section.name = SECTION_QUIT;
|
||||||
section.name = SECTION_PROG_QUIT;
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||||
screen->switchBorder();
|
{
|
||||||
resource->reLoadTextures();
|
screen_->toggleBorder();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F:
|
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||||
screen->switchVideoMode();
|
{
|
||||||
resource->reLoadTextures();
|
screen_->toggleVideoMode();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(1);
|
{
|
||||||
resource->reLoadTextures();
|
screen_->decWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F2:
|
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(2);
|
{
|
||||||
resource->reLoadTextures();
|
screen_->incWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F3:
|
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
screen->setWindowSize(3);
|
{
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
switchPalette();
|
switchPalette();
|
||||||
break;
|
}
|
||||||
|
|
||||||
default:
|
else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE))
|
||||||
section.name = SECTION_PROG_TITLE;
|
{
|
||||||
section.subsection = 0;
|
options.section.name = SECTION_TITLE;
|
||||||
break;
|
options.section.subsection = 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,11 +131,11 @@ void Credits::checkEventHandler()
|
|||||||
void Credits::iniTexts()
|
void Credits::iniTexts()
|
||||||
{
|
{
|
||||||
std::string keys = "";
|
std::string keys = "";
|
||||||
if (options->keys == ctrl_cursor)
|
if (options.keys == ctrl_cursor)
|
||||||
{
|
{
|
||||||
keys = "CURSORS";
|
keys = "CURSORS";
|
||||||
}
|
}
|
||||||
else if (options->keys == ctrl_opqa)
|
else if (options.keys == ctrl_opqa)
|
||||||
{
|
{
|
||||||
keys = "O,P AND Q";
|
keys = "O,P AND Q";
|
||||||
}
|
}
|
||||||
@@ -147,34 +144,65 @@ void Credits::iniTexts()
|
|||||||
keys = "A,D AND W";
|
keys = "A,D AND W";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef GAME_CONSOLE
|
||||||
|
texts_.clear();
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"INSTRUCTIONS:", stringToColor(options.palette, "yellow")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"HIS PROJECTS AND GO TO THE", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"JAIL TO FINISH THEM", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
|
||||||
|
texts_.push_back({"KEYS:", stringToColor(options.palette, "yellow")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({keys + " TO MOVE AND JUMP", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"M TO SWITCH THE MUSIC", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"H TO PAUSE THE GAME", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"F1-F2 TO CHANGE WINDOWS SIZE", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"F3 TO SWITCH TO FULLSCREEN", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"B TO TOOGLE THE BORDER SCREEN", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
|
||||||
|
texts_.push_back({"A GAME BY JAILDESIGNER", stringToColor(options.palette, "yellow")});
|
||||||
|
texts_.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options.palette, "yellow")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
|
||||||
|
texts_.push_back({"I LOVE JAILGAMES! ", stringToColor(options.palette, "white")});
|
||||||
|
texts_.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
#else
|
||||||
texts.clear();
|
texts.clear();
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"INSTRUCTIONS:", stringToColor(options->palette, "yellow")});
|
texts.push_back({"INSTRUCTIONS:", stringToColor(options.palette, "yellow")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor(options->palette, "white")});
|
texts.push_back({"HELP JAILDOC TO GET BACK ALL", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"HIS PROJECTS AND GO TO THE", stringToColor(options->palette, "white")});
|
texts.push_back({"HIS PROJECTS AND GO TO THE", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"JAIL TO FINISH THEM", stringToColor(options->palette, "white")});
|
texts.push_back({"JAIL TO FINISH THEM", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
|
||||||
texts.push_back({"KEYS:", stringToColor(options->palette, "yellow")});
|
texts.push_back({"KEYS:", stringToColor(options.palette, "yellow")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({keys + " TO MOVE AND JUMP", stringToColor(options->palette, "white")});
|
texts.push_back({"B TO JUMP", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"M TO TURN ON/OFF THE MUSIC", stringToColor(options->palette, "white")});
|
texts.push_back({"R TO SWITCH THE MUSIC", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"H TO HOLD/PAUSE THE GAME", stringToColor(options->palette, "white")});
|
texts.push_back({"L TO SWAP THE COLOR PALETTE", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"F1-F4 TO CHANGE WINDOWS SIZE", stringToColor(options->palette, "white")});
|
texts.push_back({"START TO PAUSE", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"F TO SWITCH TO FULLSCREEN", stringToColor(options->palette, "white")});
|
texts.push_back({"SELECT TO EXIT", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"B TO SWITCH THE BORDER SCREEN", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
|
||||||
texts.push_back({"A GAME BY JAILDESIGNER", stringToColor(options->palette, "yellow")});
|
texts.push_back({"A GAME BY JAILDESIGNER", stringToColor(options.palette, "yellow")});
|
||||||
texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options->palette, "yellow")});
|
texts.push_back({"MADE ON SUMMER/FALL 2022", stringToColor(options.palette, "yellow")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
|
||||||
texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options->palette, "white")});
|
texts.push_back({"I LOVE JAILGAMES! ", stringToColor(options.palette, "white")});
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
texts.push_back({"", stringToColor(options.palette, "white")});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
@@ -184,82 +212,82 @@ void Credits::fillTexture()
|
|||||||
iniTexts();
|
iniTexts();
|
||||||
|
|
||||||
// Rellena la textura de texto
|
// Rellena la textura de texto
|
||||||
SDL_SetRenderTarget(renderer, textTexture);
|
SDL_SetRenderTarget(renderer_, text_texture_);
|
||||||
color_t c = stringToColor(options->palette, "black");
|
color_t c = stringToColor(options.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
const int size = text->getCharacterSize();
|
const int size = text_->getCharacterSize();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (auto t : texts)
|
for (auto t : texts_)
|
||||||
{
|
{
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, i * size, t.label, 1, t.color);
|
text_->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, i * size, t.label, 1, t.color);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el corazón
|
// Escribe el corazón
|
||||||
const int textLenght = text->lenght(texts[22].label, 1) - text->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio
|
const int textLenght = text_->lenght(texts_[22].label, 1) - text_->lenght(" ", 1); // Se resta el ultimo caracter que es un espacio
|
||||||
const int posX = ((PLAY_AREA_WIDTH - textLenght) / 2) + textLenght;
|
const int posX = ((PLAY_AREA_WIDTH - textLenght) / 2) + textLenght;
|
||||||
text->writeColored(posX, 176, "}", stringToColor(options->palette, "bright_red"));
|
text_->writeColored(posX, 176, "}", stringToColor(options.palette, "bright_red"));
|
||||||
|
|
||||||
// Recoloca el sprite del brillo
|
// Recoloca el sprite del brillo
|
||||||
sprite->setPosX(posX + 2);
|
sprite_->setPosX(posX + 2);
|
||||||
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
|
|
||||||
// Rellena la textura que cubre el texto con color transparente
|
// Rellena la textura que cubre el texto con color transparente
|
||||||
SDL_SetRenderTarget(renderer, coverTexture);
|
SDL_SetRenderTarget(renderer_, cover_texture_);
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0x00);
|
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0x00);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Los primeros 8 pixels crea una malla
|
// Los primeros 8 pixels crea una malla
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, c.r, c.g, c.b, 0xFF);
|
||||||
for (int i = 0; i < 256; i += 2)
|
for (int i = 0; i < 256; i += 2)
|
||||||
{
|
{
|
||||||
SDL_RenderDrawPoint(renderer, i, 0);
|
SDL_RenderDrawPoint(renderer_, i, 0);
|
||||||
SDL_RenderDrawPoint(renderer, i, 2);
|
SDL_RenderDrawPoint(renderer_, i, 2);
|
||||||
SDL_RenderDrawPoint(renderer, i, 4);
|
SDL_RenderDrawPoint(renderer_, i, 4);
|
||||||
SDL_RenderDrawPoint(renderer, i, 6);
|
SDL_RenderDrawPoint(renderer_, i, 6);
|
||||||
|
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 5);
|
SDL_RenderDrawPoint(renderer_, i + 1, 5);
|
||||||
SDL_RenderDrawPoint(renderer, i + 1, 7);
|
SDL_RenderDrawPoint(renderer_, i + 1, 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
// El resto se rellena de color sólido
|
// El resto se rellena de color sólido
|
||||||
SDL_Rect rect = {0, 8, 256, 192};
|
SDL_Rect rect = {0, 8, 256, 192};
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
void Credits::updateCounter()
|
void Credits::updateCounter()
|
||||||
{
|
{
|
||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
if (counterEnabled)
|
if (counter_enabled_)
|
||||||
{
|
{
|
||||||
counter++;
|
counter_++;
|
||||||
if (counter == 224 || counter == 544 || counter == 672)
|
if (counter_ == 224 || counter_ == 544 || counter_ == 672)
|
||||||
{
|
{
|
||||||
counterEnabled = false;
|
counter_enabled_ = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
subCounter++;
|
sub_counter_++;
|
||||||
if (subCounter == 100)
|
if (sub_counter_ == 100)
|
||||||
{
|
{
|
||||||
counterEnabled = true;
|
counter_enabled_ = true;
|
||||||
subCounter = 0;
|
sub_counter_ = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha terminado la sección
|
// Comprueba si ha terminado la sección
|
||||||
if (counter > 1200)
|
if (counter_ > 1200)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_DEMO;
|
options.section.name = SECTION_DEMO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,24 +295,23 @@ void Credits::updateCounter()
|
|||||||
void Credits::update()
|
void Credits::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba las entradas
|
||||||
checkEventHandler();
|
checkInput();
|
||||||
|
|
||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
updateCounter();
|
updateCounter();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
screen_->update();
|
||||||
screen->updateNotifier();
|
|
||||||
|
|
||||||
// Actualiza el sprite con el brillo
|
// Actualiza el sprite con el brillo
|
||||||
if (counter > 770)
|
if (counter_ > 770)
|
||||||
{
|
{
|
||||||
sprite->update();
|
sprite_->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,45 +320,44 @@ void Credits::update()
|
|||||||
void Credits::render()
|
void Credits::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
screen_->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean();
|
screen_->clean();
|
||||||
|
|
||||||
if (counter < 1150)
|
if (counter_ < 1150)
|
||||||
{
|
{
|
||||||
// Dibuja la textura con el texto en pantalla
|
// Dibuja la textura con el texto en pantalla
|
||||||
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
SDL_RenderCopy(renderer_, text_texture_, nullptr, nullptr);
|
||||||
|
|
||||||
// Dibuja la textura que cubre el texto
|
// Dibuja la textura que cubre el texto
|
||||||
const int offset = std::min(counter / 8, 192 / 2);
|
const int offset = std::min(counter_ / 8, 192 / 2);
|
||||||
SDL_Rect srcRect = {0, 0, 256, 192 - (offset * 2)};
|
SDL_Rect srcRect = {0, 0, 256, 192 - (offset * 2)};
|
||||||
SDL_Rect dstRect = {0, offset * 2, 256, 192 - (offset * 2)};
|
SDL_Rect dstRect = {0, offset * 2, 256, 192 - (offset * 2)};
|
||||||
SDL_RenderCopy(renderer, coverTexture, &srcRect, &dstRect);
|
SDL_RenderCopy(renderer_, cover_texture_, &srcRect, &dstRect);
|
||||||
|
|
||||||
// Dibuja el sprite con el brillo
|
// Dibuja el sprite con el brillo
|
||||||
sprite->render();
|
sprite_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el logo del juego
|
// Bucle para el logo del juego
|
||||||
section_t Credits::run()
|
void Credits::run()
|
||||||
{
|
{
|
||||||
while (section.name == SECTION_PROG_CREDITS)
|
while (options.section.name == SECTION_CREDITS)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Credits::switchPalette()
|
void Credits::switchPalette()
|
||||||
{
|
{
|
||||||
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
options.palette = options.palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||||
fillTexture();
|
fillTexture();
|
||||||
}
|
}
|
||||||
@@ -1,20 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include "common/jail_audio.h"
|
#include <string> // Para basic_string, string
|
||||||
#include "common/resource.h"
|
#include <vector> // Para vector
|
||||||
#include "common/screen.h"
|
#include "utils.h" // Para color_t
|
||||||
#include "common/sprite.h"
|
class AnimatedSprite;
|
||||||
#include "common/text.h"
|
class Asset;
|
||||||
#include "common/texture.h"
|
class Input;
|
||||||
#include "common/utils.h"
|
class Resource;
|
||||||
#include "const.h"
|
class Screen;
|
||||||
#include <vector>
|
class Text;
|
||||||
|
|
||||||
#ifndef CREDITS_H
|
|
||||||
#define CREDITS_H
|
|
||||||
|
|
||||||
class Credits
|
class Credits
|
||||||
{
|
{
|
||||||
@@ -26,25 +23,23 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource_; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
Asset *asset_; // Objeto con los ficheros de recursos
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
Input *input_; // Objeto pata gestionar la entrada
|
||||||
Text *text; // Objeto para escribir texto en pantalla
|
Text *text_; // Objeto para escribir texto en pantalla
|
||||||
SDL_Texture *textTexture; // Textura para dibujar el texto
|
SDL_Texture *text_texture_; // Textura para dibujar el texto
|
||||||
SDL_Texture *coverTexture; // Textura para cubrir el texto
|
SDL_Texture *cover_texture_; // Textura para cubrir el texto
|
||||||
AnimatedSprite *sprite; // Sprite para el brillo del corazón
|
AnimatedSprite *sprite_; // Sprite para el brillo del corazón
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int counter; // Contador
|
int counter_ = 0; // Contador
|
||||||
bool counterEnabled; // Indica si esta activo el contador
|
bool counter_enabled_ = true; // Indica si esta activo el contador
|
||||||
int subCounter; // Contador secundario
|
int sub_counter_ = 0; // Contador secundario
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
std::vector<captions_t> texts_; // Vector con los textos
|
||||||
std::vector<captions_t> texts; // Vector con los textos
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void update();
|
void update();
|
||||||
@@ -53,7 +48,10 @@ private:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void checkEventHandler();
|
void checkEvents();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
void updateCounter();
|
void updateCounter();
|
||||||
@@ -69,13 +67,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Credits(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
Credits();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Credits();
|
~Credits();
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
128
source/debug.cpp
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
#include "debug.h"
|
||||||
|
#include <algorithm> // Para max
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "text.h" // Para Text
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "utils.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "asset.h"
|
||||||
|
|
||||||
|
// [SINGLETON]
|
||||||
|
Debug *Debug::debug_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
void Debug::init()
|
||||||
|
{
|
||||||
|
Debug::debug_ = new Debug();
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
void Debug::destroy()
|
||||||
|
{
|
||||||
|
delete Debug::debug_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
Debug *Debug::get()
|
||||||
|
{
|
||||||
|
return Debug::debug_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Debug::Debug()
|
||||||
|
// Copia la dirección de los objetos
|
||||||
|
: screen_(Screen::get()),
|
||||||
|
renderer_(Screen::get()->getRenderer()),
|
||||||
|
asset_(Asset::get())
|
||||||
|
{
|
||||||
|
// Reserva memoria para los punteros
|
||||||
|
texture_ = new Texture(renderer_, asset_->get("debug.png"));
|
||||||
|
text_ = new Text(asset_->get("debug.txt"), texture_, renderer_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Debug::~Debug()
|
||||||
|
{
|
||||||
|
delete texture_;
|
||||||
|
delete text_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void Debug::update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void Debug::render()
|
||||||
|
{
|
||||||
|
int y = y_;
|
||||||
|
int w = 0;
|
||||||
|
|
||||||
|
for (auto s : slot_)
|
||||||
|
{
|
||||||
|
text_->write(x_, y, s);
|
||||||
|
w = (std::max(w, (int)s.length()));
|
||||||
|
y += text_->getCharacterSize() + 1;
|
||||||
|
if (y > 192 - text_->getCharacterSize())
|
||||||
|
{
|
||||||
|
y = y_;
|
||||||
|
x_ += w * text_->getCharacterSize() + 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
y = 0;
|
||||||
|
for (auto l : log_)
|
||||||
|
{
|
||||||
|
text_->writeColored(x_ + 10, y, l, color_t(255, 255, 255));
|
||||||
|
y += text_->getCharacterSize() + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece la posición donde se colocará la información de debug
|
||||||
|
void Debug::setPos(SDL_Point p)
|
||||||
|
{
|
||||||
|
x_ = p.x;
|
||||||
|
y_ = p.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Añade un texto para mostrar
|
||||||
|
void Debug::add(std::string text)
|
||||||
|
{
|
||||||
|
slot_.push_back(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Borra la información de debug
|
||||||
|
void Debug::clear()
|
||||||
|
{
|
||||||
|
slot_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Añade un texto para mostrar en el apartado log
|
||||||
|
void Debug::addToLog(std::string text)
|
||||||
|
{
|
||||||
|
log_.push_back(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Borra la información de debug del apartado log
|
||||||
|
void Debug::clearLog()
|
||||||
|
{
|
||||||
|
log_.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void Debug::setEnabled(bool value)
|
||||||
|
{
|
||||||
|
enabled_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool Debug::getEnabled()
|
||||||
|
{
|
||||||
|
return enabled_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el valor de la variable
|
||||||
|
void Debug::switchEnabled()
|
||||||
|
{
|
||||||
|
enabled_ = !enabled_;
|
||||||
|
}
|
||||||
78
source/debug.h
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||||
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
|
#include <string> // Para string
|
||||||
|
#include <vector> // Para vector
|
||||||
|
class Asset;
|
||||||
|
class Screen;
|
||||||
|
class Text;
|
||||||
|
class Texture;
|
||||||
|
|
||||||
|
// Clase Debug
|
||||||
|
class Debug
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto privado
|
||||||
|
static Debug *debug_;
|
||||||
|
|
||||||
|
// Objetos y punteros
|
||||||
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
|
Asset *asset_; // Objeto con los ficheros de recursos
|
||||||
|
Text *text_; // Objeto encargado de escribir texto en pantalla
|
||||||
|
Texture *texture_; // Textura para el texto
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
std::vector<std::string> slot_; // Vector con los textos a escribir
|
||||||
|
std::vector<std::string> log_; // Vector con los textos a escribir
|
||||||
|
int x_ = 0; // Posicion donde escribir el texto de debug
|
||||||
|
int y_ = 0; // Posición donde escribir el texto de debug
|
||||||
|
bool enabled_ = false; // Indica si esta activo el modo debug
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Debug();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Debug();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
static void init();
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
static Debug *get();
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Establece la posición donde se colocará la información de debug
|
||||||
|
void setPos(SDL_Point p);
|
||||||
|
|
||||||
|
// Añade un texto para mostrar
|
||||||
|
void add(std::string text);
|
||||||
|
|
||||||
|
// Borra la información de debug
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
// Añade un texto para mostrar en el apartado log
|
||||||
|
void addToLog(std::string text);
|
||||||
|
|
||||||
|
// Borra la información de debug del apartado log
|
||||||
|
void clearLog();
|
||||||
|
|
||||||
|
// Establece el valor de la variable
|
||||||
|
void setEnabled(bool value);
|
||||||
|
|
||||||
|
// Obtiene el valor de la variable
|
||||||
|
bool getEnabled();
|
||||||
|
|
||||||
|
// Cambia el valor de la variable
|
||||||
|
void switchEnabled();
|
||||||
|
};
|
||||||
158
source/demo.cpp
@@ -1,7 +1,27 @@
|
|||||||
#include "demo.h"
|
#include "demo.h"
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
|
#include <iostream> // Para basic_ostream, basic_ios, operator<<, cout
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "const.h" // Para BLOCK, PLAY_AREA_WIDTH, SECTION_DEMO
|
||||||
|
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "item_tracker.h" // Para ItemTracker
|
||||||
|
#include "resource.h" // Para Resource
|
||||||
|
#include "room.h" // Para Room
|
||||||
|
#include "screen.h" // Para Screen
|
||||||
|
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
|
||||||
|
#include "utils.h" // Para color_t, stringToColor, options_t, secti...
|
||||||
|
#include "options.h"
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Debug *debug)
|
Demo::Demo()
|
||||||
|
: screen(Screen::get()),
|
||||||
|
renderer(Screen::get()->getRenderer()),
|
||||||
|
resource(Resource::get()),
|
||||||
|
asset(Asset::get()),
|
||||||
|
input(Input::get()),
|
||||||
|
debug(Debug::get())
|
||||||
{
|
{
|
||||||
// Inicia algunas variables
|
// Inicia algunas variables
|
||||||
board.iniClock = SDL_GetTicks();
|
board.iniClock = SDL_GetTicks();
|
||||||
@@ -17,19 +37,10 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
roomIndex = 0;
|
roomIndex = 0;
|
||||||
currentRoom = rooms[roomIndex];
|
currentRoom = rooms[roomIndex];
|
||||||
|
|
||||||
// Copia los punteros
|
|
||||||
this->resource = resource;
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->asset = asset;
|
|
||||||
this->screen = screen;
|
|
||||||
this->debug = debug;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
itemTracker = new ItemTracker();
|
itemTracker = new ItemTracker();
|
||||||
scoreboard = new ScoreBoard(renderer, resource, asset, options, &board);
|
scoreboard = new Scoreboard(&board);
|
||||||
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, false, debug);
|
room = new Room(resource->getRoom(currentRoom), itemTracker, &board.items, false);
|
||||||
eventHandler = new SDL_Event();
|
|
||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||||
|
|
||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
@@ -44,8 +55,8 @@ Demo::Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
|
|||||||
board.music = true;
|
board.music = true;
|
||||||
setScoreBoardColor();
|
setScoreBoardColor();
|
||||||
|
|
||||||
section.name = SECTION_PROG_DEMO;
|
options.section.name = SECTION_DEMO;
|
||||||
section.subsection = 0;
|
options.section.subsection = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Demo::~Demo()
|
Demo::~Demo()
|
||||||
@@ -54,86 +65,78 @@ Demo::~Demo()
|
|||||||
delete itemTracker;
|
delete itemTracker;
|
||||||
delete scoreboard;
|
delete scoreboard;
|
||||||
delete room;
|
delete room;
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
delete text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos de la cola
|
// Comprueba los eventos de la cola
|
||||||
void Demo::checkEventHandler()
|
void Demo::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.name = SECTION_QUIT;
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
screen->setBorderColor(stringToColor(options.palette, "black"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
// Comprueba las entradas
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
void Demo::checkInput()
|
||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.scancode)
|
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
options.section.name = SECTION_QUIT;
|
||||||
section.name = SECTION_PROG_QUIT;
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||||
screen->switchBorder();
|
{
|
||||||
|
screen->toggleBorder();
|
||||||
reLoadTextures();
|
reLoadTextures();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F:
|
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||||
screen->switchVideoMode();
|
{
|
||||||
|
screen->toggleVideoMode();
|
||||||
reLoadTextures();
|
reLoadTextures();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(1);
|
{
|
||||||
|
screen->decWindowSize();
|
||||||
reLoadTextures();
|
reLoadTextures();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F2:
|
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(2);
|
{
|
||||||
|
screen->incWindowSize();
|
||||||
reLoadTextures();
|
reLoadTextures();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F3:
|
else if (input->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
screen->setWindowSize(3);
|
{
|
||||||
reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
switchPalette();
|
switchPalette();
|
||||||
break;
|
}
|
||||||
|
|
||||||
default:
|
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE))
|
||||||
section.name = SECTION_PROG_TITLE;
|
{
|
||||||
section.subsection = 0;
|
options.section.name = SECTION_TITLE;
|
||||||
break;
|
options.section.subsection = 0;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
section_t Demo::run()
|
void Demo::run()
|
||||||
{
|
{
|
||||||
while (section.name == SECTION_PROG_DEMO)
|
while (options.section.name == SECTION_DEMO)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
@@ -145,8 +148,8 @@ void Demo::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba los eventos de la cola
|
// Comprueba las entradas
|
||||||
checkEventHandler();
|
checkInput();
|
||||||
|
|
||||||
// Actualiza los objetos
|
// Actualiza los objetos
|
||||||
room->update();
|
room->update();
|
||||||
@@ -154,8 +157,7 @@ void Demo::update()
|
|||||||
screen->updateFX();
|
screen->updateFX();
|
||||||
checkRoomChange();
|
checkRoomChange();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
screen->update();
|
||||||
screen->updateNotifier();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +176,7 @@ void Demo::render()
|
|||||||
screen->renderFX();
|
screen->renderFX();
|
||||||
|
|
||||||
// Actualiza la pantalla
|
// Actualiza la pantalla
|
||||||
screen->blit();
|
screen->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Escribe el nombre de la pantalla
|
// Escribe el nombre de la pantalla
|
||||||
@@ -182,7 +184,7 @@ void Demo::renderRoomName()
|
|||||||
{
|
{
|
||||||
// Texto en el centro de la pantalla
|
// Texto en el centro de la pantalla
|
||||||
SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2};
|
SDL_Rect rect = {0, 16 * BLOCK, PLAY_AREA_WIDTH, BLOCK * 2};
|
||||||
color_t color = stringToColor(options->palette, "white");
|
color_t color = stringToColor(options.palette, "white");
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
|
||||||
@@ -192,7 +194,7 @@ void Demo::renderRoomName()
|
|||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
void Demo::reLoadTextures()
|
void Demo::reLoadTextures()
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "** RELOAD REQUESTED" << std::endl;
|
std::cout << "** RELOAD REQUESTED" << std::endl;
|
||||||
}
|
}
|
||||||
@@ -205,13 +207,13 @@ void Demo::reLoadTextures()
|
|||||||
void Demo::switchPalette()
|
void Demo::switchPalette()
|
||||||
{
|
{
|
||||||
// Modifica la variable
|
// Modifica la variable
|
||||||
if (options->palette == p_zxspectrum)
|
if (options.palette == p_zxspectrum)
|
||||||
{
|
{
|
||||||
options->palette = p_zxarne;
|
options.palette = p_zxarne;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
options->palette = p_zxspectrum;
|
options.palette = p_zxspectrum;
|
||||||
}
|
}
|
||||||
|
|
||||||
room->reLoadPalette();
|
room->reLoadPalette();
|
||||||
@@ -234,7 +236,7 @@ bool Demo::changeRoom(std::string file)
|
|||||||
room = nullptr;
|
room = nullptr;
|
||||||
|
|
||||||
// Crea un objeto habitación nuevo a partir del fichero
|
// Crea un objeto habitación nuevo a partir del fichero
|
||||||
room = new Room(resource->getRoom(file), renderer, screen, asset, options, itemTracker, &board.items, false, debug);
|
room = new Room(resource->getRoom(file), itemTracker, &board.items, false);
|
||||||
|
|
||||||
// Pone el color del marcador en función del color del borde de la habitación
|
// Pone el color del marcador en función del color del borde de la habitación
|
||||||
setScoreBoardColor();
|
setScoreBoardColor();
|
||||||
@@ -255,8 +257,8 @@ void Demo::checkRoomChange()
|
|||||||
roomIndex++;
|
roomIndex++;
|
||||||
if (roomIndex == (int)rooms.size())
|
if (roomIndex == (int)rooms.size())
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_LOGO;
|
options.section.name = SECTION_LOGO;
|
||||||
section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
options.section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -272,10 +274,10 @@ void Demo::setScoreBoardColor()
|
|||||||
const color_t c = room->getBorderColor();
|
const color_t c = room->getBorderColor();
|
||||||
|
|
||||||
// Si el color es negro lo cambia a blanco
|
// Si el color es negro lo cambia a blanco
|
||||||
const color_t cBlack = stringToColor(options->palette, "black");
|
const color_t cBlack = stringToColor(options.palette, "black");
|
||||||
board.color = colorAreEqual(c, cBlack) ? stringToColor(options->palette, "white") : c;
|
board.color = colorAreEqual(c, cBlack) ? stringToColor(options.palette, "white") : c;
|
||||||
|
|
||||||
// Si el color es negro brillante lo cambia a blanco
|
// Si el color es negro brillante lo cambia a blanco
|
||||||
const color_t cBrightBlack = stringToColor(options->palette, "bright_black");
|
const color_t cBrightBlack = stringToColor(options.palette, "bright_black");
|
||||||
board.color = colorAreEqual(c, cBrightBlack) ? stringToColor(options->palette, "white") : c;
|
board.color = colorAreEqual(c, cBrightBlack) ? stringToColor(options.palette, "white") : c;
|
||||||
}
|
}
|
||||||
@@ -1,44 +1,40 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include "common/debug.h"
|
#include <string> // Para string, basic_string
|
||||||
#include "common/input.h"
|
#include <vector> // Para vector
|
||||||
#include "common/resource.h"
|
#include "scoreboard.h" // Para board_t
|
||||||
#include "common/screen.h"
|
class Asset;
|
||||||
#include "common/sprite.h"
|
class Debug;
|
||||||
#include "common/text.h"
|
class Input;
|
||||||
#include "common/utils.h"
|
class ItemTracker;
|
||||||
#include "const.h"
|
class Resource;
|
||||||
#include "item_tracker.h"
|
class Room;
|
||||||
#include "room_tracker.h"
|
class Screen;
|
||||||
#include "room.h"
|
class Text;
|
||||||
#include "scoreboard.h"
|
struct options_t;
|
||||||
|
struct section_t;
|
||||||
#ifndef DEMO_H
|
|
||||||
#define DEMO_H
|
|
||||||
|
|
||||||
class Demo
|
class Demo
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
|
||||||
Screen *screen; // Objeto encargado de manejar el renderizador
|
Screen *screen; // Objeto encargado de manejar el renderizador
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Room *room; // Objeto encargado de gestionar cada habitación del juego
|
Room *room; // Objeto encargado de gestionar cada habitación del juego
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
|
Input *input; // Objeto pata gestionar la entrada
|
||||||
Text *text; // Objeto para los textos del juego
|
Text *text; // Objeto para los textos del juego
|
||||||
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
|
Scoreboard *scoreboard; // Objeto encargado de gestionar el marcador
|
||||||
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
|
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
|
||||||
Debug *debug; // Objeto para gestionar la información de debug
|
Debug *debug; // Objeto para gestionar la información de debug
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
section_t section; // Seccion actual dentro del juego
|
|
||||||
std::string currentRoom; // Fichero de la habitación actual
|
std::string currentRoom; // Fichero de la habitación actual
|
||||||
board_t board; // Estructura con los datos del marcador
|
board_t board; // Estructura con los datos del marcador
|
||||||
int counter; // Contador para el modo demo
|
int counter; // Contador para el modo demo
|
||||||
@@ -53,7 +49,10 @@ private:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba los eventos de la cola
|
// Comprueba los eventos de la cola
|
||||||
void checkEventHandler();
|
void checkEvents();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
// Escribe el nombre de la pantalla
|
// Escribe el nombre de la pantalla
|
||||||
void renderRoomName();
|
void renderRoomName();
|
||||||
@@ -75,13 +74,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Demo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Debug *debug);
|
Demo();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Demo();
|
~Demo();
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
section_t run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
1623
source/director.cpp
@@ -1,82 +1,38 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "common/asset.h"
|
|
||||||
#include "common/debug.h"
|
|
||||||
#include "common/input.h"
|
|
||||||
#include "common/jail_audio.h"
|
|
||||||
#include "common/movingsprite.h"
|
|
||||||
#include "common/resource.h"
|
|
||||||
#include "common/sprite.h"
|
|
||||||
#include "common/text.h"
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include "credits.h"
|
|
||||||
#include "demo.h"
|
|
||||||
#include "ending.h"
|
|
||||||
#include "ending2.h"
|
|
||||||
#include "enter_id.h"
|
|
||||||
#include "game_over.h"
|
|
||||||
#include "game.h"
|
|
||||||
#include "intro.h"
|
|
||||||
#include "logo.h"
|
|
||||||
#include "title.h"
|
|
||||||
|
|
||||||
#ifndef DIRECTOR_H
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#define DIRECTOR_H
|
#include <SDL2/SDL_video.h> // for SDL_Window
|
||||||
|
#include <string> // for string
|
||||||
|
class Asset; // lines 6-6
|
||||||
|
class Debug; // lines 8-8
|
||||||
|
class Input; // lines 14-14
|
||||||
|
class Resource; // lines 17-17
|
||||||
|
class Screen; // lines 18-18
|
||||||
|
struct JA_Music_t; // lines 20-20
|
||||||
|
struct options_t; // lines 21-21
|
||||||
|
struct section_t; // lines 22-22
|
||||||
|
|
||||||
class Director
|
class Director
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Window *window; // La ventana donde dibujamos
|
SDL_Window *window_; // La ventana donde dibujamos
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
Resource *resource; // Objeto con los recursos
|
|
||||||
Asset *asset; // Objeto que gestiona todos los ficheros de recursos
|
|
||||||
Input *input; // Objeto Input para gestionar las entradas
|
|
||||||
Game *game; // Objeto para gestionar la sección del juego
|
|
||||||
Logo *logo; // Objeto para gestionar la sección del logo del programa
|
|
||||||
Title *title; // Objeto para gestionar la pantalla de título
|
|
||||||
Intro *intro; // Objeto para gestionar la introducción del juego
|
|
||||||
Credits *credits; // Objeto para gestionar los creditos del juego
|
|
||||||
Demo *demo; // Objeto para gestionar el modo demo, en el que se ven pantallas del juego
|
|
||||||
EnterID *enterID; // Objeto para gestionar la sección donde se solicita el ID online al usuario
|
|
||||||
Ending *ending; // Objeto para gestionar el final del juego
|
|
||||||
Ending2 *ending2; // Objeto para gestionar el final del juego
|
|
||||||
GameOver *gameOver; // Objeto para gestionar el final de la partida
|
|
||||||
Debug *debug; // Objeto para getsionar la información de debug
|
|
||||||
struct options_t *options; // Variable con todas las opciones del programa
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
section_t section; // Sección y subsección actual del programa;
|
JA_Music_t *title_music_; // Musica del titulo
|
||||||
JA_Music_t* music; // Musica del titulo
|
std::string executable_path_; // Path del ejecutable
|
||||||
std::string executablePath; // Path del ejecutable
|
std::string system_folder_; // Carpeta del sistema donde guardar datos
|
||||||
std::string systemFolder; // Carpeta del sistema donde guardar datos
|
|
||||||
|
|
||||||
// Crea e inicializa las opciones del programa
|
|
||||||
void initOptions();
|
|
||||||
|
|
||||||
// Inicializa los servicios online
|
|
||||||
void initOnline();
|
|
||||||
|
|
||||||
// Comprueba los parametros del programa
|
// Comprueba los parametros del programa
|
||||||
void checkProgramArguments(int argc, char *argv[]);
|
std::string checkProgramArguments(int argc, const char *argv[]);
|
||||||
|
|
||||||
// Carga el fichero de configuración
|
|
||||||
bool loadConfig();
|
|
||||||
|
|
||||||
// Guarda el fichero de configuración
|
|
||||||
bool saveConfig();
|
|
||||||
|
|
||||||
// Crea la carpeta del sistema donde guardar datos
|
// Crea la carpeta del sistema donde guardar datos
|
||||||
void createSystemFolder();
|
void createSystemFolder(const std::string &folder);
|
||||||
|
|
||||||
// Carga los recursos
|
// Carga los recursos
|
||||||
void loadResources(section_t section);
|
void loadResources(section_t section);
|
||||||
|
|
||||||
// Asigna variables a partir de dos cadenas
|
|
||||||
bool setOptions(options_t *options, std::string var, std::string value);
|
|
||||||
|
|
||||||
// Inicializa jail_audio
|
// Inicializa jail_audio
|
||||||
void initJailAudio();
|
void initJailAudio();
|
||||||
|
|
||||||
@@ -89,20 +45,11 @@ private:
|
|||||||
// Crea el indice de ficheros
|
// Crea el indice de ficheros
|
||||||
bool setFileList();
|
bool setFileList();
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 getSubsection();
|
|
||||||
|
|
||||||
// Obtiene el valor de la variable
|
|
||||||
Uint8 getSection();
|
|
||||||
|
|
||||||
// Establece el valor de la variable
|
|
||||||
void setSection(section_t section);
|
|
||||||
|
|
||||||
// Ejecuta la seccion de juego con el logo
|
// Ejecuta la seccion de juego con el logo
|
||||||
void runLogo();
|
void runLogo();
|
||||||
|
|
||||||
// Ejecuta la seccion de juego de la introducción
|
// Ejecuta la seccion de juego de la pantalla de carga
|
||||||
void runIntro();
|
void runLoadingScreen();
|
||||||
|
|
||||||
// Ejecuta la seccion de juego con el titulo y los menus
|
// Ejecuta la seccion de juego con el titulo y los menus
|
||||||
void runTitle();
|
void runTitle();
|
||||||
@@ -113,9 +60,6 @@ private:
|
|||||||
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
|
// Ejecuta la seccion de la demo, donde se ven pantallas del juego
|
||||||
void runDemo();
|
void runDemo();
|
||||||
|
|
||||||
// Ejecuta la seccion en la que se solicita al usuario su ID online
|
|
||||||
void runEnterID();
|
|
||||||
|
|
||||||
// Ejecuta la seccion del final del juego
|
// Ejecuta la seccion del final del juego
|
||||||
void runEnding();
|
void runEnding();
|
||||||
|
|
||||||
@@ -130,13 +74,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Director(int argc, char *argv[]);
|
Director(int argc, const char *argv[]);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Director();
|
~Director();
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
void run();
|
int run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
#include "ending.h"
|
#include "ending.h"
|
||||||
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
|
#include <algorithm> // Para min
|
||||||
|
#include <iostream> // Para basic_ostream, operator<<, basic_ios
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "const.h" // Para GAMECANVAS_HEIGHT, GAMECANVAS_WIDTH
|
||||||
|
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // Para JA_SetVolume, JA_DeleteMusic, JA_Loa...
|
||||||
|
#include "resource.h" // Para Resource
|
||||||
|
#include "screen.h" // Para Screen
|
||||||
|
#include "sprite.h" // Para Sprite
|
||||||
|
#include "text.h" // Para Text, TXT_STROKE
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "utils.h" // Para color_t, stringToColor, options_t
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
|
Ending::Ending()
|
||||||
|
: screen(Screen::get()),
|
||||||
|
renderer(Screen::get()->getRenderer()),
|
||||||
|
resource(Resource::get()),
|
||||||
|
asset(Asset::get()),
|
||||||
|
input(Input::get())
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->resource = resource;
|
|
||||||
this->asset = asset;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros a objetos
|
// Reserva memoria para los punteros a objetos
|
||||||
eventHandler = new SDL_Event();
|
|
||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||||
music = JA_LoadMusic(asset->get("ending1.ogg").c_str());
|
music = JA_LoadMusic(asset->get("ending1.ogg").c_str());
|
||||||
|
|
||||||
@@ -19,8 +34,8 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
|
|||||||
counter = -1;
|
counter = -1;
|
||||||
preCounter = 0;
|
preCounter = 0;
|
||||||
coverCounter = 0;
|
coverCounter = 0;
|
||||||
section.name = SECTION_PROG_ENDING;
|
options.section.name = SECTION_ENDING;
|
||||||
section.subsection = 0;
|
options.section.subsection = 0;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
scene = 0;
|
scene = 0;
|
||||||
@@ -35,13 +50,13 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
|
|||||||
iniScenes();
|
iniScenes();
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
screen->setBorderColor(stringToColor(options.palette, "black"));
|
||||||
|
|
||||||
// Crea la textura para cubrir el rexto
|
// Crea la textura para cubrir el rexto
|
||||||
coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8);
|
coverTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT + 8);
|
||||||
if (coverTexture == nullptr)
|
if (coverTexture == nullptr)
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Error: canvasTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
@@ -56,7 +71,6 @@ Ending::Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset
|
|||||||
Ending::~Ending()
|
Ending::~Ending()
|
||||||
{
|
{
|
||||||
// Libera la memoria de los objetos
|
// Libera la memoria de los objetos
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
delete text;
|
||||||
SDL_DestroyTexture(coverTexture);
|
SDL_DestroyTexture(coverTexture);
|
||||||
|
|
||||||
@@ -89,8 +103,8 @@ void Ending::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba las entradas
|
||||||
checkEventHandler();
|
checkInput();
|
||||||
|
|
||||||
// Actualiza el contador
|
// Actualiza el contador
|
||||||
updateCounters();
|
updateCounters();
|
||||||
@@ -104,8 +118,7 @@ void Ending::update()
|
|||||||
// Actualiza el volumen de la musica
|
// Actualiza el volumen de la musica
|
||||||
updateMusicVolume();
|
updateMusicVolume();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
screen->update();
|
||||||
screen->updateNotifier();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +129,7 @@ void Ending::render()
|
|||||||
screen->start();
|
screen->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(stringToColor(options->palette, "black"));
|
screen->clean(stringToColor(options.palette, "black"));
|
||||||
|
|
||||||
// Dibuja las imagenes de la escena
|
// Dibuja las imagenes de la escena
|
||||||
spritePics[scene].sprite->render();
|
spritePics[scene].sprite->render();
|
||||||
@@ -138,69 +151,57 @@ void Ending::render()
|
|||||||
// text->write(0, 0, std::to_string(counter));
|
// text->write(0, 0, std::to_string(counter));
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void Ending::checkEventHandler()
|
void Ending::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.name = SECTION_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
// Comprueba las entradas
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
void Ending::checkInput()
|
||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.scancode)
|
|
||||||
|
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
options.section.name = SECTION_LOGO;
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||||
screen->switchBorder();
|
{
|
||||||
resource->reLoadTextures();
|
screen->toggleBorder();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F:
|
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||||
screen->switchVideoMode();
|
{
|
||||||
resource->reLoadTextures();
|
screen->toggleVideoMode();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(1);
|
{
|
||||||
resource->reLoadTextures();
|
screen->decWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F2:
|
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(2);
|
{
|
||||||
resource->reLoadTextures();
|
screen->incWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F3:
|
else if (input->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
screen->setWindowSize(3);
|
{
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
switchPalette();
|
switchPalette();
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,7 +255,7 @@ void Ending::iniTexts()
|
|||||||
endingTexture_t st;
|
endingTexture_t st;
|
||||||
const int width = text->lenght(t.caption, 1) + 2 + 2;
|
const int width = text->lenght(t.caption, 1) + 2 + 2;
|
||||||
const int height = text->getCharacterSize() + 2 + 2;
|
const int height = text->getCharacterSize() + 2 + 2;
|
||||||
color_t c = stringToColor(options->palette, "black");
|
color_t c = stringToColor(options.palette, "black");
|
||||||
|
|
||||||
// Crea la texture
|
// Crea la texture
|
||||||
st.texture = new Texture(renderer);
|
st.texture = new Texture(renderer);
|
||||||
@@ -278,7 +279,7 @@ void Ending::iniTexts()
|
|||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Los primeros 8 pixels crea una malla
|
// Los primeros 8 pixels crea una malla
|
||||||
c = stringToColor(options->palette, "black");
|
c = stringToColor(options.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||||
for (int i = 0; i < width; i += 2)
|
for (int i = 0; i < width; i += 2)
|
||||||
{
|
{
|
||||||
@@ -293,7 +294,7 @@ void Ending::iniTexts()
|
|||||||
|
|
||||||
// El resto se rellena de color sólido
|
// El resto se rellena de color sólido
|
||||||
SDL_Rect rect = {0, 8, width, height};
|
SDL_Rect rect = {0, 8, width, height};
|
||||||
c = stringToColor(options->palette, "black");
|
c = stringToColor(options.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
|
||||||
@@ -316,7 +317,7 @@ void Ending::iniPics()
|
|||||||
// Vector con las rutas y la posición
|
// Vector con las rutas y la posición
|
||||||
std::vector<textAndPos_t> pics;
|
std::vector<textAndPos_t> pics;
|
||||||
|
|
||||||
if (options->palette == p_zxspectrum)
|
if (options.palette == p_zxspectrum)
|
||||||
{
|
{
|
||||||
pics.push_back({"ending1.png", 48});
|
pics.push_back({"ending1.png", 48});
|
||||||
pics.push_back({"ending2.png", 26});
|
pics.push_back({"ending2.png", 26});
|
||||||
@@ -366,7 +367,7 @@ void Ending::iniPics()
|
|||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Los primeros 8 pixels crea una malla
|
// Los primeros 8 pixels crea una malla
|
||||||
color_t c = stringToColor(options->palette, "black");
|
color_t c = stringToColor(options.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||||
for (int i = 0; i < width; i += 2)
|
for (int i = 0; i < width; i += 2)
|
||||||
{
|
{
|
||||||
@@ -381,7 +382,7 @@ void Ending::iniPics()
|
|||||||
|
|
||||||
// El resto se rellena de color sólido
|
// El resto se rellena de color sólido
|
||||||
SDL_Rect rect = {0, 8, width, height};
|
SDL_Rect rect = {0, 8, width, height};
|
||||||
c = stringToColor(options->palette, "black");
|
c = stringToColor(options.palette, "black");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer, &rect);
|
||||||
|
|
||||||
@@ -482,20 +483,19 @@ void Ending::iniScenes()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t Ending::run()
|
void Ending::run()
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music);
|
JA_PlayMusic(music);
|
||||||
|
|
||||||
while (section.name == SECTION_PROG_ENDING)
|
while (options.section.name == SECTION_ENDING)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
JA_SetVolume(128);
|
JA_SetVolume(128);
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los contadores
|
// Actualiza los contadores
|
||||||
@@ -571,7 +571,7 @@ void Ending::checkChangeScene()
|
|||||||
if (scene == 5)
|
if (scene == 5)
|
||||||
{
|
{
|
||||||
// Termina el bucle
|
// Termina el bucle
|
||||||
section.name = SECTION_PROG_ENDING2;
|
options.section.name = SECTION_ENDING2;
|
||||||
|
|
||||||
// Mantiene los valores anteriores
|
// Mantiene los valores anteriores
|
||||||
scene = 4;
|
scene = 4;
|
||||||
@@ -589,7 +589,7 @@ void Ending::fillCoverTexture()
|
|||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
// Los primeros 8 pixels crea una malla
|
// Los primeros 8 pixels crea una malla
|
||||||
const color_t c = stringToColor(options->palette, "brack");
|
const color_t c = stringToColor(options.palette, "brack");
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
||||||
for (int i = 0; i < 256; i += 2)
|
for (int i = 0; i < 256; i += 2)
|
||||||
{
|
{
|
||||||
@@ -635,9 +635,9 @@ void Ending::updateMusicVolume()
|
|||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Ending::switchPalette()
|
void Ending::switchPalette()
|
||||||
{
|
{
|
||||||
if (options->palette == p_zxspectrum)
|
if (options.palette == p_zxspectrum)
|
||||||
{
|
{
|
||||||
options->palette = p_zxarne;
|
options.palette = p_zxarne;
|
||||||
|
|
||||||
spritePics[0].sprite->setTexture(resource->getTexture("ending1_zxarne.png"));
|
spritePics[0].sprite->setTexture(resource->getTexture("ending1_zxarne.png"));
|
||||||
spritePics[1].sprite->setTexture(resource->getTexture("ending2_zxarne.png"));
|
spritePics[1].sprite->setTexture(resource->getTexture("ending2_zxarne.png"));
|
||||||
@@ -647,7 +647,7 @@ void Ending::switchPalette()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
options->palette = p_zxspectrum;
|
options.palette = p_zxspectrum;
|
||||||
|
|
||||||
spritePics[0].sprite->setTexture(resource->getTexture("ending1.png"));
|
spritePics[0].sprite->setTexture(resource->getTexture("ending1.png"));
|
||||||
spritePics[1].sprite->setTexture(resource->getTexture("ending2.png"));
|
spritePics[1].sprite->setTexture(resource->getTexture("ending2.png"));
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "common/asset.h"
|
|
||||||
#include "common/jail_audio.h"
|
|
||||||
#include "common/resource.h"
|
|
||||||
#include "common/screen.h"
|
|
||||||
#include "common/sprite.h"
|
|
||||||
#include "common/sprite.h"
|
|
||||||
#include "common/text.h"
|
|
||||||
#include "common/texture.h"
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef ENDING_H
|
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||||
#define ENDING_H
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
|
#include <string> // Para basic_string, string
|
||||||
|
#include <vector> // Para vector
|
||||||
|
class Asset;
|
||||||
|
class Input;
|
||||||
|
class Resource;
|
||||||
|
class Screen;
|
||||||
|
class Sprite;
|
||||||
|
class Text;
|
||||||
|
class Texture;
|
||||||
|
struct JA_Music_t;
|
||||||
|
struct options_t;
|
||||||
|
struct section_t;
|
||||||
|
|
||||||
class Ending
|
class Ending
|
||||||
{
|
{
|
||||||
@@ -50,12 +50,11 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
options_t *options; // Puntero a las opciones del juego
|
Input *input; // Objeto pata gestionar la entrada
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
|
||||||
Text *text; // Objeto para escribir texto en pantalla
|
Text *text; // Objeto para escribir texto en pantalla
|
||||||
SDL_Texture *coverTexture; // Textura para cubrir el texto
|
SDL_Texture *coverTexture; // Textura para cubrir el texto
|
||||||
|
|
||||||
@@ -63,7 +62,6 @@ private:
|
|||||||
int counter; // Contador
|
int counter; // Contador
|
||||||
int preCounter; // Contador previo
|
int preCounter; // Contador previo
|
||||||
int coverCounter; // Contador para la cortinilla
|
int coverCounter; // Contador para la cortinilla
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
std::vector<endingTexture_t> spriteTexts; // Vector con los sprites de texto con su cortinilla
|
std::vector<endingTexture_t> spriteTexts; // Vector con los sprites de texto con su cortinilla
|
||||||
@@ -79,7 +77,10 @@ private:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void checkEventHandler();
|
void checkEvents();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
// Inicializa los textos
|
// Inicializa los textos
|
||||||
void iniTexts();
|
void iniTexts();
|
||||||
@@ -113,13 +114,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
Ending();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Ending();
|
~Ending();
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,18 +1,29 @@
|
|||||||
#include "ending2.h"
|
#include "ending2.h"
|
||||||
#include <algorithm>
|
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <algorithm> // for max, min, replace
|
||||||
|
#include "animatedsprite.h" // for AnimatedSprite
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "const.h" // for GAMECANVAS_HEIGHT, GAMECANVAS_CENTER_X
|
||||||
|
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // for JA_SetVolume, JA_DeleteMusic, JA_Loa...
|
||||||
|
#include "movingsprite.h" // for MovingSprite
|
||||||
|
#include "resource.h" // for Resource
|
||||||
|
#include "screen.h" // for Screen
|
||||||
|
#include "text.h" // for Text
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
#include "utils.h" // for color_t, stringToColor, options_t
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
|
Ending2::Ending2()
|
||||||
|
: screen(Screen::get()),
|
||||||
|
renderer(Screen::get()->getRenderer()),
|
||||||
|
resource(Resource::get()),
|
||||||
|
asset(Asset::get()),
|
||||||
|
input(Input::get())
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->resource = resource;
|
|
||||||
this->asset = asset;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros a objetos
|
// Reserva memoria para los punteros a objetos
|
||||||
eventHandler = new SDL_Event();
|
|
||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||||
music = JA_LoadMusic(asset->get("ending2.ogg").c_str());
|
music = JA_LoadMusic(asset->get("ending2.ogg").c_str());
|
||||||
|
|
||||||
@@ -21,8 +32,8 @@ Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
|
|||||||
preCounter = 0;
|
preCounter = 0;
|
||||||
postCounter = 0;
|
postCounter = 0;
|
||||||
postCounterEnabled = false;
|
postCounterEnabled = false;
|
||||||
section.name = SECTION_PROG_ENDING2;
|
options.section.name = SECTION_ENDING2;
|
||||||
section.subsection = 0;
|
options.section.subsection = 0;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
distSpriteText = 8;
|
distSpriteText = 8;
|
||||||
@@ -35,11 +46,11 @@ Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
|
|||||||
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||||
for (auto cl : colorList)
|
for (auto cl : colorList)
|
||||||
{
|
{
|
||||||
colors.push_back(stringToColor(options->palette, cl));
|
colors.push_back(stringToColor(options.palette, cl));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
screen->setBorderColor(stringToColor(options.palette, "black"));
|
||||||
|
|
||||||
// Inicializa la lista de sprites
|
// Inicializa la lista de sprites
|
||||||
iniSpriteList();
|
iniSpriteList();
|
||||||
@@ -61,7 +72,6 @@ Ending2::Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Ass
|
|||||||
Ending2::~Ending2()
|
Ending2::~Ending2()
|
||||||
{
|
{
|
||||||
// Libera la memoria de los objetos
|
// Libera la memoria de los objetos
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
delete text;
|
||||||
JA_DeleteMusic(music);
|
JA_DeleteMusic(music);
|
||||||
|
|
||||||
@@ -79,8 +89,8 @@ void Ending2::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba las entradas
|
||||||
checkEventHandler();
|
checkInput();
|
||||||
|
|
||||||
// Actualiza los contadores
|
// Actualiza los contadores
|
||||||
updateCounters();
|
updateCounters();
|
||||||
@@ -103,8 +113,7 @@ void Ending2::update()
|
|||||||
// Actualiza el volumen de la musica
|
// Actualiza el volumen de la musica
|
||||||
updateMusicVolume();
|
updateMusicVolume();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
screen->update();
|
||||||
screen->updateNotifier();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +124,7 @@ void Ending2::render()
|
|||||||
screen->start();
|
screen->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean(stringToColor(options->palette, "black"));
|
screen->clean(stringToColor(options.palette, "black"));
|
||||||
|
|
||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
renderSprites();
|
renderSprites();
|
||||||
@@ -172,87 +181,74 @@ void Ending2::render()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void Ending2::checkEventHandler()
|
void Ending2::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.name = SECTION_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
// Comprueba las entradas
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
void Ending2::checkInput()
|
||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.scancode)
|
|
||||||
|
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
options.section.name = SECTION_LOGO;
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||||
screen->switchBorder();
|
{
|
||||||
resource->reLoadTextures();
|
screen->toggleBorder();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F:
|
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||||
screen->switchVideoMode();
|
{
|
||||||
resource->reLoadTextures();
|
screen->toggleVideoMode();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(1);
|
{
|
||||||
resource->reLoadTextures();
|
screen->decWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F2:
|
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(2);
|
{
|
||||||
resource->reLoadTextures();
|
screen->incWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F3:
|
else if (input->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
screen->setWindowSize(3);
|
{
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
switchPalette();
|
switchPalette();
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t Ending2::run()
|
void Ending2::run()
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music);
|
JA_PlayMusic(music);
|
||||||
|
|
||||||
while (section.name == SECTION_PROG_ENDING2)
|
while (options.section.name == SECTION_ENDING2)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
JA_SetVolume(128);
|
JA_SetVolume(128);
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los contadores
|
// Actualiza los contadores
|
||||||
@@ -275,8 +271,8 @@ void Ending2::updateCounters()
|
|||||||
|
|
||||||
if (postCounter > 600)
|
if (postCounter > 600)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_LOGO;
|
options.section.name = SECTION_LOGO;
|
||||||
section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
options.section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,7 +410,7 @@ void Ending2::updateTexts()
|
|||||||
// Dibuja los sprites
|
// Dibuja los sprites
|
||||||
void Ending2::renderSprites()
|
void Ending2::renderSprites()
|
||||||
{
|
{
|
||||||
const color_t color = stringToColor(options->palette, "red");
|
const color_t color = stringToColor(options.palette, "red");
|
||||||
for (auto sprite : sprites)
|
for (auto sprite : sprites)
|
||||||
{
|
{
|
||||||
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
||||||
@@ -427,7 +423,7 @@ void Ending2::renderSprites()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el ultimo elemento de otro color
|
// Pinta el ultimo elemento de otro color
|
||||||
const color_t c = stringToColor(options->palette, "white");
|
const color_t c = stringToColor(options.palette, "white");
|
||||||
sprites.back()->getTexture()->setColor(c.r, c.g, c.b);
|
sprites.back()->getTexture()->setColor(c.r, c.g, c.b);
|
||||||
sprites.back()->render();
|
sprites.back()->render();
|
||||||
}
|
}
|
||||||
@@ -435,7 +431,7 @@ void Ending2::renderSprites()
|
|||||||
// Dibuja los sprites con el texto
|
// Dibuja los sprites con el texto
|
||||||
void Ending2::renderSpriteTexts()
|
void Ending2::renderSpriteTexts()
|
||||||
{
|
{
|
||||||
const color_t color = stringToColor(options->palette, "white");
|
const color_t color = stringToColor(options.palette, "white");
|
||||||
for (auto sprite : spriteTexts)
|
for (auto sprite : spriteTexts)
|
||||||
{
|
{
|
||||||
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
const bool a = sprite->getRect().y + sprite->getRect().h > 0;
|
||||||
@@ -642,5 +638,5 @@ void Ending2::updateMusicVolume()
|
|||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Ending2::switchPalette()
|
void Ending2::switchPalette()
|
||||||
{
|
{
|
||||||
options->palette = (options->palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
|
options.palette = (options.palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,32 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "common/animatedsprite.h"
|
|
||||||
#include "common/asset.h"
|
|
||||||
#include "common/jail_audio.h"
|
|
||||||
#include "common/resource.h"
|
|
||||||
#include "common/screen.h"
|
|
||||||
#include "common/sprite.h"
|
|
||||||
#include "common/text.h"
|
|
||||||
#include "common/texture.h"
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifndef ENDING2_H
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#define ENDING2_H
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
|
#include <string> // for string
|
||||||
|
#include <vector> // for vector
|
||||||
|
class AnimatedSprite; // lines 9-9
|
||||||
|
class Asset; // lines 10-10
|
||||||
|
class Input; // lines 11-11
|
||||||
|
class MovingSprite; // lines 12-12
|
||||||
|
class Resource; // lines 13-13
|
||||||
|
class Screen; // lines 14-14
|
||||||
|
class Text; // lines 15-15
|
||||||
|
struct JA_Music_t; // lines 16-16
|
||||||
|
struct color_t;
|
||||||
|
struct options_t;
|
||||||
|
struct section_t;
|
||||||
|
|
||||||
class Ending2
|
class Ending2
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
|
||||||
Resource *resource; // Objeto con los recursos
|
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
Resource *resource; // Objeto con los recursos
|
||||||
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
|
Input *input; // Objeto pata gestionar la entrada
|
||||||
Text *text; // Objeto para escribir texto en pantalla
|
Text *text; // Objeto para escribir texto en pantalla
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
std::vector<AnimatedSprite *> sprites; // Vector con todos los sprites a dibujar
|
std::vector<AnimatedSprite *> sprites; // Vector con todos los sprites a dibujar
|
||||||
std::vector<MovingSprite *> spriteTexts; // Vector con los sprites de texto de los sprites
|
std::vector<MovingSprite *> spriteTexts; // Vector con los sprites de texto de los sprites
|
||||||
std::vector<MovingSprite *> texts; // Vector con los sprites de texto
|
std::vector<MovingSprite *> texts; // Vector con los sprites de texto
|
||||||
@@ -36,7 +36,6 @@ private:
|
|||||||
int preCounter; // Contador previo
|
int preCounter; // Contador previo
|
||||||
int postCounter; // Contador posterior
|
int postCounter; // Contador posterior
|
||||||
bool postCounterEnabled; // Indica si está habilitado el contador
|
bool postCounterEnabled; // Indica si está habilitado el contador
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
JA_Music_t *music; // Musica que suena durante el final
|
JA_Music_t *music; // Musica que suena durante el final
|
||||||
@@ -57,7 +56,10 @@ private:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void checkEventHandler();
|
void checkEvents();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
// Actualiza los contadores
|
// Actualiza los contadores
|
||||||
void updateCounters();
|
void updateCounters();
|
||||||
@@ -115,13 +117,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Ending2(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
Ending2();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Ending2();
|
~Ending2();
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
#include "enemy.h"
|
#include "enemy.h"
|
||||||
|
#include <stdlib.h> // Para rand
|
||||||
|
#include <algorithm> // Para min
|
||||||
|
#include "animatedsprite.h" // Para AnimatedSprite
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Enemy::Enemy(enemy_t enemy)
|
Enemy::Enemy(enemy_t enemy)
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
#include "common/asset.h"
|
#include <string> // Para basic_string, string
|
||||||
#include "common/utils.h"
|
#include "utils.h" // Para palette_e, color_t
|
||||||
#include <string>
|
class AnimatedSprite;
|
||||||
|
struct animatedSprite_t;
|
||||||
#ifndef ENEMY_H
|
|
||||||
#define ENEMY_H
|
|
||||||
|
|
||||||
// Estructura para pasar los datos de un enemigo
|
// Estructura para pasar los datos de un enemigo
|
||||||
struct enemy_t
|
struct enemy_t
|
||||||
@@ -78,5 +76,3 @@ public:
|
|||||||
// Asigna la paleta
|
// Asigna la paleta
|
||||||
void setPalette(palette_e pal);
|
void setPalette(palette_e pal);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,319 +0,0 @@
|
|||||||
#include "common/jail_audio.h"
|
|
||||||
#include "common/jscore.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include "enter_id.h"
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
EnterID::EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t section)
|
|
||||||
{
|
|
||||||
// Copia la dirección de los objetos
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
|
||||||
eventHandler = new SDL_Event();
|
|
||||||
texture = new Texture(renderer, asset->get("smb2.png"));
|
|
||||||
text = new Text(asset->get("smb2.txt"), texture, renderer);
|
|
||||||
|
|
||||||
// Crea la textura para el texto que se escribe en pantalla
|
|
||||||
textTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, GAMECANVAS_HEIGHT);
|
|
||||||
if (textTexture == nullptr)
|
|
||||||
{
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << "Error: textTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
counter = 0;
|
|
||||||
ticks = 0;
|
|
||||||
ticksSpeed = 15;
|
|
||||||
pos = 0;
|
|
||||||
name[pos] = 0;
|
|
||||||
maxLenght = 15;
|
|
||||||
this->section.subsection = section.subsection;
|
|
||||||
|
|
||||||
if (options->online.enabled && options->online.jailerID == "")
|
|
||||||
{
|
|
||||||
this->section.name = SECTION_PROG_ENTER_ID;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
endSection();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
|
||||||
fillTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
EnterID::~EnterID()
|
|
||||||
{
|
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
|
||||||
delete texture;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bucle para el logo del juego
|
|
||||||
section_t EnterID::run()
|
|
||||||
{
|
|
||||||
// Detiene la música
|
|
||||||
JA_StopMusic();
|
|
||||||
|
|
||||||
while (section.name == SECTION_PROG_ENTER_ID)
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
|
||||||
void EnterID::checkEventHandler()
|
|
||||||
{
|
|
||||||
// Comprueba los eventos que hay en la cola
|
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
|
||||||
{
|
|
||||||
// Evento de salida de la aplicación
|
|
||||||
if (eventHandler->type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// El ENTER solo se comprueba cuando se suelta, para no saltarse la siguiente sección
|
|
||||||
if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP))
|
|
||||||
{
|
|
||||||
if (eventHandler->key.keysym.scancode == SDL_SCANCODE_RETURN)
|
|
||||||
{
|
|
||||||
options->online.jailerID = (std::string)name;
|
|
||||||
endSection();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
|
||||||
{
|
|
||||||
if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_A && eventHandler->key.keysym.scancode <= SDL_SCANCODE_Z)
|
|
||||||
{ // Si pulsa una letra
|
|
||||||
if (pos < maxLenght)
|
|
||||||
{
|
|
||||||
name[pos++] = eventHandler->key.keysym.scancode + 61;
|
|
||||||
name[pos] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode >= SDL_SCANCODE_1 && eventHandler->key.keysym.scancode <= SDL_SCANCODE_9)
|
|
||||||
{ // Si pulsa un número
|
|
||||||
if (pos < maxLenght)
|
|
||||||
{ // En ascii el '0' va antes del '1', pero en scancode el '0' va despues de '9'
|
|
||||||
name[pos++] = eventHandler->key.keysym.scancode + 19;
|
|
||||||
name[pos] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_0)
|
|
||||||
{
|
|
||||||
if (pos < maxLenght)
|
|
||||||
{
|
|
||||||
name[pos++] = 48;
|
|
||||||
name[pos] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_BACKSPACE)
|
|
||||||
{
|
|
||||||
if (pos > 0)
|
|
||||||
{
|
|
||||||
name[--pos] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_ESCAPE)
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F1)
|
|
||||||
{
|
|
||||||
screen->setWindowSize(1);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F2)
|
|
||||||
{
|
|
||||||
screen->setWindowSize(2);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F3)
|
|
||||||
{
|
|
||||||
screen->setWindowSize(3);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F4)
|
|
||||||
{
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (eventHandler->key.keysym.scancode == SDL_SCANCODE_F5)
|
|
||||||
{
|
|
||||||
switchPalette();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void EnterID::update()
|
|
||||||
{
|
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
|
||||||
{
|
|
||||||
// Actualiza el contador de ticks
|
|
||||||
ticks = SDL_GetTicks();
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
|
||||||
checkEventHandler();
|
|
||||||
|
|
||||||
// Actualiza el contador
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
// Actualiza el cursor
|
|
||||||
cursor = (counter % 20 >= 10) ? " " : "_";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja en pantalla
|
|
||||||
void EnterID::render()
|
|
||||||
{
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
screen->clean();
|
|
||||||
|
|
||||||
// Dibuja la textura con el texto en pantalla
|
|
||||||
SDL_RenderCopy(renderer, textTexture, nullptr, nullptr);
|
|
||||||
|
|
||||||
// Escribe el jailerID
|
|
||||||
const std::string jailerID = (std::string)name + cursor;
|
|
||||||
const color_t color = stringToColor(options->palette, "white");
|
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, (16 * 8 + 1), jailerID, 1, color);
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa los textos
|
|
||||||
void EnterID::iniTexts()
|
|
||||||
{
|
|
||||||
texts.clear();
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"ONLINE CONFIGURATION:", stringToColor(options->palette, "red")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"YOU HAVE NOT SPECIFIED ANY ID", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"FOR THE ONLINE SERVICE", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"PLEASE ENTER AN ID OR", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"LEAVE BLANK FOR OFFLINE MODE", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"JAILER_ID:", stringToColor(options->palette, "red")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
texts.push_back({"", stringToColor(options->palette, "white")});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
|
||||||
void EnterID::fillTexture()
|
|
||||||
{
|
|
||||||
// Inicializa los textos
|
|
||||||
iniTexts();
|
|
||||||
|
|
||||||
// Rellena la textura de texto
|
|
||||||
SDL_SetRenderTarget(renderer, textTexture);
|
|
||||||
color_t c = stringToColor(options->palette, "black");
|
|
||||||
SDL_SetRenderDrawColor(renderer, c.r, c.g, c.b, 0xFF);
|
|
||||||
SDL_RenderClear(renderer);
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
|
||||||
const int size = text->getCharacterSize();
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for (auto t : texts)
|
|
||||||
{
|
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, PLAY_AREA_CENTER_X, i * size, t.label, 1, t.color);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia la paleta
|
|
||||||
void EnterID::switchPalette()
|
|
||||||
{
|
|
||||||
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
|
||||||
fillTexture();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa los servicios online
|
|
||||||
void EnterID::initOnline()
|
|
||||||
{
|
|
||||||
if (options->online.sessionEnabled)
|
|
||||||
{ // Si ya ha iniciado la sesión, que no continue
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options->online.jailerID == "")
|
|
||||||
{ // Jailer ID no definido
|
|
||||||
|
|
||||||
options->online.enabled = false;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{ // Jailer ID iniciado
|
|
||||||
|
|
||||||
options->online.enabled = options->online.sessionEnabled = true;
|
|
||||||
jscore::init(options->online.server, options->online.port);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
const std::string caption = options->online.jailerID + " IS LOGGED IN (DEBUG)";
|
|
||||||
#else
|
|
||||||
const std::string caption = options->online.jailerID + " IS LOGGED IN";
|
|
||||||
#endif
|
|
||||||
screen->showNotification(caption);
|
|
||||||
if (options->console)
|
|
||||||
{
|
|
||||||
std::cout << caption << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Termina la sección
|
|
||||||
void EnterID::endSection()
|
|
||||||
{
|
|
||||||
initOnline();
|
|
||||||
section.name = (section.subsection == SUBSECTION_LOGO_TO_INTRO) ? SECTION_PROG_INTRO : SECTION_PROG_TITLE;
|
|
||||||
section.subsection = 0;
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "common/asset.h"
|
|
||||||
#include "common/screen.h"
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include "common/text.h"
|
|
||||||
#include "common/texture.h"
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef ENTER_ID_H
|
|
||||||
#define ASK_ME_H
|
|
||||||
|
|
||||||
class EnterID
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
struct captions_t
|
|
||||||
{
|
|
||||||
std::string label; // Texto a escribir
|
|
||||||
color_t color; // Color del texto
|
|
||||||
};
|
|
||||||
|
|
||||||
// Punteros y objetos
|
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
SDL_Texture *textTexture; // Textura para dibujar el texto
|
|
||||||
Text *text; // Objeto para escribir texto en pantalla
|
|
||||||
Texture *texture; // Textura para la fuente para el texto
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
int counter; // Contador
|
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
std::vector<captions_t> texts; // Vector con los textos
|
|
||||||
std::string cursor; // Contiene el caracter que se muestra como cursor
|
|
||||||
|
|
||||||
char name[15];
|
|
||||||
int pos;
|
|
||||||
int maxLenght; // Tamaño máximo del jailerID
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Dibuja en pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
|
||||||
void checkEventHandler();
|
|
||||||
|
|
||||||
// Inicializa los textos
|
|
||||||
void iniTexts();
|
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
|
||||||
void fillTexture();
|
|
||||||
|
|
||||||
// Cambia la paleta
|
|
||||||
void switchPalette();
|
|
||||||
|
|
||||||
// Inicializa los servicios online
|
|
||||||
void initOnline();
|
|
||||||
|
|
||||||
// Termina la sección
|
|
||||||
void endSection();
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
EnterID(SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, section_t section);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~EnterID();
|
|
||||||
|
|
||||||
// Bucle principal
|
|
||||||
section_t run();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
629
source/game.cpp
@@ -1,144 +1,162 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL_blendmode.h> // for SDL_BLENDMODE_BLEND
|
||||||
|
#include <SDL2/SDL_error.h> // for SDL_GetError
|
||||||
|
#include <SDL2/SDL_pixels.h> // for SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <SDL2/SDL_scancode.h> // for SDL_SCANCODE_A, SDL_SCANCODE_D, SDL_...
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <iostream> // for basic_ostream, operator<<, cout, endl
|
||||||
|
#include <vector> // for vector
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "cheevos.h" // for Cheevos
|
||||||
|
#include "const.h" // for PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH
|
||||||
|
#include "debug.h" // for Debug
|
||||||
|
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "item_tracker.h" // for ItemTracker
|
||||||
|
#include "jail_audio.h" // for JA_PauseMusic, JA_PlaySound, JA_Resu...
|
||||||
|
#include "resource.h" // for Resource, res_room_t
|
||||||
|
#include "room.h" // for Room, room_t
|
||||||
|
#include "room_tracker.h" // for RoomTracker
|
||||||
|
#include "screen.h" // for Screen
|
||||||
|
#include "stats.h" // for Stats
|
||||||
|
#include "text.h" // for Text, TXT_CENTER, TXT_COLOR
|
||||||
|
#include "utils.h" // for options_t, cheat_t, stringToColor
|
||||||
|
#include "options.h"
|
||||||
|
#include "notifier.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug)
|
Game::Game()
|
||||||
|
: screen_(Screen::get()),
|
||||||
|
renderer_(Screen::get()->getRenderer()),
|
||||||
|
asset_(Asset::get()),
|
||||||
|
input_(Input::get()),
|
||||||
|
resource_(Resource::get()),
|
||||||
|
debug_(Debug::get())
|
||||||
{
|
{
|
||||||
// Inicia algunas variables
|
// Inicia algunas variables
|
||||||
board.iniClock = SDL_GetTicks();
|
board_.iniClock = SDL_GetTicks();
|
||||||
currentRoom = "03.room";
|
#ifdef DEBUG
|
||||||
|
current_room_ = "03.room";
|
||||||
const int x = 25;
|
const int x = 25;
|
||||||
const int y = 13;
|
const int y = 13;
|
||||||
spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
spawn_point_ = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||||
|
debug_->setEnabled(false);
|
||||||
// Copia los punteros
|
#else
|
||||||
this->resource = resource;
|
current_room_ = "03.room";
|
||||||
this->renderer = renderer;
|
const int x = 25;
|
||||||
this->asset = asset;
|
const int y = 13;
|
||||||
this->screen = screen;
|
spawn_point_ = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
||||||
this->input = input;
|
|
||||||
this->debug = debug;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
currentRoom = "01.room";
|
|
||||||
const int x1 = 25;
|
|
||||||
const int y1 = 13;
|
|
||||||
spawnPoint = {x1 * 8, y1 * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Crea los objetos
|
// Crea los objetos
|
||||||
scoreboard = new ScoreBoard(renderer, resource, asset, options, &board);
|
cheevos_ = Cheevos::get();
|
||||||
itemTracker = new ItemTracker();
|
scoreboard_ = new Scoreboard(&board_);
|
||||||
roomTracker = new RoomTracker();
|
item_tracker_ = new ItemTracker();
|
||||||
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, false, debug);
|
room_tracker_ = new RoomTracker();
|
||||||
const std::string playerPNG = options->cheat.altSkin ? "player2.png" : "player.png";
|
room_ = new Room(resource_->getRoom(current_room_), item_tracker_, &board_.items, false);
|
||||||
const std::string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png";
|
||||||
const player_t player = {spawnPoint, playerPNG, playerANI, renderer, resource, asset, options, input, room, debug};
|
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
|
||||||
this->player = new Player(player);
|
const player_t player = {spawn_point_, playerPNG, playerANI, room_};
|
||||||
eventHandler = new SDL_Event();
|
player_ = new Player(player);
|
||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
text_ = new Text(resource_->getOffset("smb2.txt"), resource_->getTexture("smb2.png"), renderer_);
|
||||||
music = JA_LoadMusic(asset->get("game.ogg").c_str());
|
music_ = JA_LoadMusic(asset_->get("game.ogg").c_str());
|
||||||
deathSound = JA_LoadSound(asset->get("death.wav").c_str());
|
death_sound_ = JA_LoadSound(asset_->get("death.wav").c_str());
|
||||||
stats = new Stats(asset->get("stats.csv"), asset->get("stats_buffer.csv"), options);
|
stats_ = new Stats(asset_->get("stats.csv"), asset_->get("stats_buffer.csv"));
|
||||||
|
|
||||||
// Crea la textura para poner el nombre de la habitación
|
// Crea la textura para poner el nombre de la habitación
|
||||||
roomNameTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, text->getCharacterSize() * 2);
|
room_name_texture_ = SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, GAMECANVAS_WIDTH, text_->getCharacterSize() * 2);
|
||||||
if (roomNameTexture == nullptr)
|
if (room_name_texture_ == nullptr)
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "Error: roomNameTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Error: roomNameTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el blend mode de la textura
|
// Establece el blend mode de la textura
|
||||||
SDL_SetTextureBlendMode(roomNameTexture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(room_name_texture_, SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
// Establece el destino de la textura
|
// Establece el destino de la textura
|
||||||
roomNameRect = {0, PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH, text->getCharacterSize() * 2};
|
room_name_rect_ = {0, PLAY_AREA_HEIGHT, GAMECANVAS_WIDTH, text_->getCharacterSize() * 2};
|
||||||
|
|
||||||
// Pone el nombre de la habitación en la textura
|
// Pone el nombre de la habitación en la textura
|
||||||
fillRoomNameTexture();
|
fillRoomNameTexture();
|
||||||
|
|
||||||
// Inicializa el resto de variables
|
// Inicializa el resto de variables
|
||||||
ticks = 0;
|
ticks_ = 0;
|
||||||
ticksSpeed = 15;
|
ticks_speed_ = 15;
|
||||||
board.lives = 9;
|
board_.lives = 9;
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
board.lives = 9;
|
board_.lives = 9;
|
||||||
#endif
|
#endif
|
||||||
board.items = 0;
|
board_.items = 0;
|
||||||
board.rooms = 1;
|
board_.rooms = 1;
|
||||||
board.music = true;
|
board_.music = true;
|
||||||
board.jailEnabled = options->cheat.jailEnabled;
|
board_.jailEnabled = options.cheat.jailEnabled;
|
||||||
setScoreBoardColor();
|
setScoreBoardColor();
|
||||||
roomTracker->addRoom(currentRoom);
|
room_tracker_->addRoom(current_room_);
|
||||||
paused = false;
|
paused_ = false;
|
||||||
blackScreen = false;
|
black_screen_ = false;
|
||||||
blackScreenCounter = 0;
|
black_screen_counter_ = 0;
|
||||||
totalItems = getTotalItems();
|
total_items_ = getTotalItems();
|
||||||
initStats();
|
initStats();
|
||||||
stats->addVisit(room->getName());
|
stats_->addVisit(room_->getName());
|
||||||
|
const bool cheats = options.cheat.infiniteLives || options.cheat.invincible || options.cheat.jailEnabled;
|
||||||
|
cheevos_->enable(!cheats); // Deshabilita los logros si hay trucos activados
|
||||||
|
|
||||||
section.name = SECTION_PROG_GAME;
|
options.section.name = SECTION_GAME;
|
||||||
section.subsection = 0;
|
options.section.subsection = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game()
|
||||||
{
|
{
|
||||||
// Libera la memoria de los objetos
|
// Libera la memoria de los objetos
|
||||||
delete scoreboard;
|
delete scoreboard_;
|
||||||
delete itemTracker;
|
delete item_tracker_;
|
||||||
delete roomTracker;
|
delete room_tracker_;
|
||||||
delete room;
|
delete room_;
|
||||||
delete player;
|
delete player_;
|
||||||
delete eventHandler;
|
delete text_;
|
||||||
delete text;
|
delete stats_;
|
||||||
delete stats;
|
|
||||||
|
|
||||||
SDL_DestroyTexture(roomNameTexture);
|
SDL_DestroyTexture(room_name_texture_);
|
||||||
|
|
||||||
JA_DeleteMusic(music);
|
JA_DeleteMusic(music_);
|
||||||
JA_DeleteSound(deathSound);
|
JA_DeleteSound(death_sound_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba los eventos de la cola
|
// Comprueba los eventos de la cola
|
||||||
void Game::checkEventHandler()
|
void Game::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.name = SECTION_QUIT;
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
screen_->setBorderColor(stringToColor(options.palette, "black"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET)
|
if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
|
||||||
{
|
{
|
||||||
reLoadTextures();
|
reLoadTextures();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((eventHandler->type == SDL_KEYDOWN) and (eventHandler->key.repeat == 0))
|
if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
|
||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.scancode)
|
switch (event.key.keysym.scancode)
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
|
||||||
section.name = SECTION_PROG_TITLE;
|
|
||||||
break;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
case SDL_SCANCODE_G:
|
case SDL_SCANCODE_G:
|
||||||
debug->switchEnabled();
|
debug_->switchEnabled();
|
||||||
options->cheat.invincible = debug->getEnabled();
|
options.cheat.invincible = debug_->getEnabled();
|
||||||
board.music = !debug->getEnabled();
|
board_.music = !debug_->getEnabled();
|
||||||
board.music ? JA_ResumeMusic() : JA_PauseMusic();
|
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_R:
|
case SDL_SCANCODE_R:
|
||||||
resource->reLoad();
|
resource_->reLoad();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_W:
|
case SDL_SCANCODE_W:
|
||||||
@@ -158,53 +176,21 @@ void Game::checkEventHandler()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_SCANCODE_F6:
|
case SDL_SCANCODE_F6:
|
||||||
screen->showNotification("MAMA MIRA! SIN MANOS!");
|
Notifier::get()->show("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 2);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F7:
|
||||||
|
Notifier::get()->show("ACHIEVEMENT UNLOCKED!", "I LIKE MY MULTICOLOURED FRIENDS", 3);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F8:
|
||||||
|
Notifier::get()->show("JAILDESIGNER IS LOGGED IN", "", 4);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_F9:
|
||||||
|
Notifier::get()->show("JAILDESIGNER IS LOGGED IN", "", 5);
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
case SDL_SCANCODE_M:
|
|
||||||
board.music = !board.music;
|
|
||||||
board.music ? JA_ResumeMusic() : JA_PauseMusic();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_H:
|
|
||||||
switchPause();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
|
||||||
screen->switchBorder();
|
|
||||||
reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F:
|
|
||||||
screen->switchVideoMode();
|
|
||||||
reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
|
||||||
screen->setWindowSize(1);
|
|
||||||
reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F2:
|
|
||||||
screen->setWindowSize(2);
|
|
||||||
reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F3:
|
|
||||||
screen->setWindowSize(3);
|
|
||||||
reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
switchPalette();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -212,45 +198,98 @@ void Game::checkEventHandler()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el juego
|
// Comprueba el teclado
|
||||||
section_t Game::run()
|
void Game::checkInput()
|
||||||
{
|
{
|
||||||
JA_PlayMusic(music);
|
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||||
if (!board.music)
|
{
|
||||||
|
options.section.name = SECTION_TITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_toggle_music, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
board_.music = !board_.music;
|
||||||
|
board_.music ? JA_ResumeMusic() : JA_PauseMusic();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_pause, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
switchPause();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->toggleBorder();
|
||||||
|
reLoadTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->toggleVideoMode();
|
||||||
|
reLoadTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_toggle_shaders, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->toggleShaders();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->decWindowSize();
|
||||||
|
reLoadTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->incWindowSize();
|
||||||
|
reLoadTextures();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
switchPalette();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle para el juego
|
||||||
|
void Game::run()
|
||||||
|
{
|
||||||
|
JA_PlayMusic(music_);
|
||||||
|
if (!board_.music)
|
||||||
{
|
{
|
||||||
JA_PauseMusic();
|
JA_PauseMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
while (section.name == SECTION_PROG_GAME)
|
while (options.section.name == SECTION_GAME)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
void Game::update()
|
void Game::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba los eventos de la cola
|
// Comprueba el teclado
|
||||||
checkEventHandler();
|
checkInput();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug->clear();
|
debug_->clear();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Actualiza los objetos
|
// Actualiza los objetos
|
||||||
room->update();
|
room_->update();
|
||||||
player->update();
|
player_->update();
|
||||||
checkPlayerOnBorder();
|
checkPlayerOnBorder();
|
||||||
checkPlayerAndItems();
|
checkPlayerAndItems();
|
||||||
checkPlayerAndEnemies();
|
checkPlayerAndEnemies();
|
||||||
@@ -258,13 +297,13 @@ void Game::update()
|
|||||||
checkGameOver();
|
checkGameOver();
|
||||||
checkEndGame();
|
checkEndGame();
|
||||||
checkRestoringJail();
|
checkRestoringJail();
|
||||||
scoreboard->update();
|
checkSomeCheevos();
|
||||||
input->update();
|
scoreboard_->update();
|
||||||
|
input_->update();
|
||||||
|
|
||||||
updateBlackScreen();
|
updateBlackScreen();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
screen_->update();
|
||||||
screen->updateNotifier();
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
updateDebugInfo();
|
updateDebugInfo();
|
||||||
@@ -276,15 +315,15 @@ void Game::update()
|
|||||||
void Game::render()
|
void Game::render()
|
||||||
{
|
{
|
||||||
// Prepara para dibujar el frame
|
// Prepara para dibujar el frame
|
||||||
screen->start();
|
screen_->start();
|
||||||
|
|
||||||
// Dibuja los elementos del juego en orden
|
// Dibuja los elementos del juego en orden
|
||||||
room->renderMap();
|
room_->renderMap();
|
||||||
room->renderEnemies();
|
room_->renderEnemies();
|
||||||
room->renderItems();
|
room_->renderItems();
|
||||||
player->render();
|
player_->render();
|
||||||
renderRoomName();
|
renderRoomName();
|
||||||
scoreboard->render();
|
scoreboard_->render();
|
||||||
renderBlackScreen();
|
renderBlackScreen();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -293,45 +332,45 @@ void Game::render()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Actualiza la pantalla
|
// Actualiza la pantalla
|
||||||
screen->blit();
|
screen_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Pasa la información de debug
|
// Pasa la información de debug
|
||||||
void Game::updateDebugInfo()
|
void Game::updateDebugInfo()
|
||||||
{
|
{
|
||||||
debug->add("X = " + std::to_string((int)player->x) + ", Y = " + std::to_string((int)player->y));
|
debug_->add("X = " + std::to_string(static_cast<int>(player_->x)) + ", Y = " + std::to_string(static_cast<int>(player_->y)));
|
||||||
debug->add("VX = " + std::to_string(player->vx).substr(0, 4) + ", VY = " + std::to_string(player->vy).substr(0, 4));
|
debug_->add("VX = " + std::to_string(player_->vx).substr(0, 4) + ", VY = " + std::to_string(player_->vy).substr(0, 4));
|
||||||
debug->add("STATE = " + std::to_string(player->state));
|
debug_->add("STATE = " + std::to_string(player_->state));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone la información de debug en pantalla
|
// Pone la información de debug en pantalla
|
||||||
void Game::renderDebugInfo()
|
void Game::renderDebugInfo()
|
||||||
{
|
{
|
||||||
if (!debug->getEnabled())
|
if (!debug_->getEnabled())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Borra el marcador
|
// Borra el marcador
|
||||||
SDL_Rect rect = {0, 18 * BLOCK, PLAY_AREA_WIDTH, GAMECANVAS_HEIGHT - PLAY_AREA_HEIGHT};
|
SDL_Rect rect = {0, 18 * BLOCK, PLAY_AREA_WIDTH, GAMECANVAS_HEIGHT - PLAY_AREA_HEIGHT};
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 255);
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
// Pinta la rejilla
|
// Pinta la rejilla
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 32);
|
SDL_SetRenderDrawColor(renderer_, 255, 255, 255, 32);
|
||||||
for (int i = 0; i < PLAY_AREA_BOTTOM; i += 8)
|
for (int i = 0; i < PLAY_AREA_BOTTOM; i += 8)
|
||||||
{ // Lineas horizontales
|
{ // Lineas horizontales
|
||||||
SDL_RenderDrawLine(renderer, 0, i, PLAY_AREA_RIGHT, i);
|
SDL_RenderDrawLine(renderer_, 0, i, PLAY_AREA_RIGHT, i);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < PLAY_AREA_RIGHT; i += 8)
|
for (int i = 0; i < PLAY_AREA_RIGHT; i += 8)
|
||||||
{ // Lineas verticales
|
{ // Lineas verticales
|
||||||
SDL_RenderDrawLine(renderer, i, 0, i, PLAY_AREA_BOTTOM - 1);
|
SDL_RenderDrawLine(renderer_, i, 0, i, PLAY_AREA_BOTTOM - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el texto
|
// Pinta el texto
|
||||||
debug->setPos({1, 18 * 8});
|
debug_->setPos({1, 18 * 8});
|
||||||
debug->render();
|
debug_->render();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -339,7 +378,7 @@ void Game::renderDebugInfo()
|
|||||||
void Game::renderRoomName()
|
void Game::renderRoomName()
|
||||||
{
|
{
|
||||||
// Dibuja la textura con el nombre de la habitación
|
// Dibuja la textura con el nombre de la habitación
|
||||||
SDL_RenderCopy(renderer, roomNameTexture, nullptr, &roomNameRect);
|
SDL_RenderCopy(renderer_, room_name_texture_, nullptr, &room_name_rect_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia de habitación
|
// Cambia de habitación
|
||||||
@@ -352,14 +391,14 @@ bool Game::changeRoom(std::string file)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verifica que exista el fichero que se va a cargar
|
// Verifica que exista el fichero que se va a cargar
|
||||||
if (asset->get(file) != "")
|
if (asset_->get(file) != "")
|
||||||
{
|
{
|
||||||
// Elimina la habitación actual
|
// Elimina la habitación actual
|
||||||
delete room;
|
delete room_;
|
||||||
room = nullptr;
|
room_ = nullptr;
|
||||||
|
|
||||||
// Crea un objeto habitación nuevo a partir del fichero
|
// Crea un objeto habitación nuevo a partir del fichero
|
||||||
room = new Room(resource->getRoom(file), renderer, screen, asset, options, itemTracker, &board.items, board.jailEnabled, debug);
|
room_ = new Room(resource_->getRoom(file), item_tracker_, &board_.items, board_.jailEnabled);
|
||||||
|
|
||||||
// Pone el nombre de la habitación en la textura
|
// Pone el nombre de la habitación en la textura
|
||||||
fillRoomNameTexture();
|
fillRoomNameTexture();
|
||||||
@@ -367,18 +406,18 @@ bool Game::changeRoom(std::string file)
|
|||||||
// Pone el color del marcador en función del color del borde de la habitación
|
// Pone el color del marcador en función del color del borde de la habitación
|
||||||
setScoreBoardColor();
|
setScoreBoardColor();
|
||||||
|
|
||||||
if (roomTracker->addRoom(file))
|
if (room_tracker_->addRoom(file))
|
||||||
{
|
{
|
||||||
// Incrementa el contador de habitaciones visitadas
|
// Incrementa el contador de habitaciones visitadas
|
||||||
board.rooms++;
|
board_.rooms++;
|
||||||
options->stats.rooms = board.rooms;
|
options.stats.rooms = board_.rooms;
|
||||||
|
|
||||||
// Actualiza las estadisticas
|
// Actualiza las estadisticas
|
||||||
stats->addVisit(room->getName());
|
stats_->addVisit(room_->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pasa la nueva habitación al jugador
|
// Pasa la nueva habitación al jugador
|
||||||
player->setRoom(room);
|
player_->setRoom(room_);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -389,14 +428,14 @@ bool Game::changeRoom(std::string file)
|
|||||||
// Comprueba si el jugador esta en el borde de la pantalla
|
// Comprueba si el jugador esta en el borde de la pantalla
|
||||||
void Game::checkPlayerOnBorder()
|
void Game::checkPlayerOnBorder()
|
||||||
{
|
{
|
||||||
if (player->getOnBorder())
|
if (player_->getOnBorder())
|
||||||
{
|
{
|
||||||
const std::string roomName = room->getRoom(player->getBorder());
|
const std::string roomName = room_->getRoom(player_->getBorder());
|
||||||
if (changeRoom(roomName))
|
if (changeRoom(roomName))
|
||||||
{
|
{
|
||||||
player->switchBorders();
|
player_->switchBorders();
|
||||||
currentRoom = roomName;
|
current_room_ = roomName;
|
||||||
spawnPoint = player->getSpawnParams();
|
spawn_point_ = player_->getSpawnParams();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -404,7 +443,7 @@ void Game::checkPlayerOnBorder()
|
|||||||
// Comprueba las colisiones del jugador con los enemigos
|
// Comprueba las colisiones del jugador con los enemigos
|
||||||
bool Game::checkPlayerAndEnemies()
|
bool Game::checkPlayerAndEnemies()
|
||||||
{
|
{
|
||||||
const bool death = room->enemyCollision(player->getCollider());
|
const bool death = room_->enemyCollision(player_->getCollider());
|
||||||
if (death)
|
if (death)
|
||||||
{
|
{
|
||||||
killPlayer();
|
killPlayer();
|
||||||
@@ -415,13 +454,13 @@ bool Game::checkPlayerAndEnemies()
|
|||||||
// Comprueba las colisiones del jugador con los objetos
|
// Comprueba las colisiones del jugador con los objetos
|
||||||
void Game::checkPlayerAndItems()
|
void Game::checkPlayerAndItems()
|
||||||
{
|
{
|
||||||
room->itemCollision(player->getCollider());
|
room_->itemCollision(player_->getCollider());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si el jugador esta vivo
|
// Comprueba si el jugador esta vivo
|
||||||
void Game::checkIfPlayerIsAlive()
|
void Game::checkIfPlayerIsAlive()
|
||||||
{
|
{
|
||||||
if (!player->isAlive())
|
if (!player_->isAlive())
|
||||||
{
|
{
|
||||||
killPlayer();
|
killPlayer();
|
||||||
}
|
}
|
||||||
@@ -430,79 +469,82 @@ void Game::checkIfPlayerIsAlive()
|
|||||||
// Comprueba si ha terminado la partida
|
// Comprueba si ha terminado la partida
|
||||||
void Game::checkGameOver()
|
void Game::checkGameOver()
|
||||||
{
|
{
|
||||||
if (board.lives < 0 && blackScreenCounter > 17)
|
if (board_.lives < 0 && black_screen_counter_ > 17)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_GAME_OVER;
|
options.section.name = SECTION_GAME_OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mata al jugador
|
// Mata al jugador
|
||||||
void Game::killPlayer()
|
void Game::killPlayer()
|
||||||
{
|
{
|
||||||
if (options->cheat.invincible)
|
if (options.cheat.invincible)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resta una vida al jugador
|
// Resta una vida al jugador
|
||||||
if (!options->cheat.infiniteLives)
|
if (!options.cheat.infiniteLives)
|
||||||
{
|
{
|
||||||
board.lives--;
|
board_.lives--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las estadisticas
|
// Actualiza las estadisticas
|
||||||
stats->addDeath(room->getName());
|
stats_->addDeath(room_->getName());
|
||||||
|
|
||||||
|
// Invalida el logro de pasarse el juego sin morir
|
||||||
|
cheevos_->invalidate(11);
|
||||||
|
|
||||||
// Destruye la habitacion y el jugador
|
// Destruye la habitacion y el jugador
|
||||||
delete room;
|
delete room_;
|
||||||
delete this->player;
|
delete this->player_;
|
||||||
|
|
||||||
// Sonido
|
// Sonido
|
||||||
JA_PlaySound(deathSound);
|
JA_PlaySound(death_sound_);
|
||||||
|
|
||||||
// Pone la pantalla en negro un tiempo
|
// Pone la pantalla en negro un tiempo
|
||||||
setBlackScreen();
|
setBlackScreen();
|
||||||
|
|
||||||
// Crea la nueva habitación y el nuevo jugador
|
// Crea la nueva habitación y el nuevo jugador
|
||||||
room = new Room(resource->getRoom(currentRoom), renderer, screen, asset, options, itemTracker, &board.items, board.jailEnabled, debug);
|
room_ = new Room(resource_->getRoom(current_room_),item_tracker_, &board_.items, board_.jailEnabled);
|
||||||
const std::string playerPNG = options->cheat.altSkin ? "player2.png" : "player.png";
|
const std::string playerPNG = options.cheat.altSkin ? "player2.png" : "player.png";
|
||||||
const std::string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
|
||||||
const player_t player = {spawnPoint, playerPNG, playerANI, renderer, resource, asset, options, input, room, debug};
|
const player_t player = {spawn_point_, playerPNG, playerANI, room_};
|
||||||
this->player = new Player(player);
|
this->player_ = new Player(player);
|
||||||
|
|
||||||
// Pone los objetos en pausa mientras esta la habitación en negro
|
// Pone los objetos en pausa mientras esta la habitación en negro
|
||||||
room->pause();
|
room_->pause();
|
||||||
this->player->pause();
|
this->player_->pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga todas las texturas
|
// Recarga todas las texturas
|
||||||
void Game::reLoadTextures()
|
void Game::reLoadTextures()
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "** RELOAD REQUESTED" << std::endl;
|
std::cout << "** RELOAD REQUESTED" << std::endl;
|
||||||
}
|
}
|
||||||
player->reLoadTexture();
|
player_->reLoadTexture();
|
||||||
room->reLoadTexture();
|
room_->reLoadTexture();
|
||||||
scoreboard->reLoadTexture();
|
scoreboard_->reLoadTexture();
|
||||||
text->reLoadTexture();
|
text_->reLoadTexture();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Game::switchPalette()
|
void Game::switchPalette()
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "** PALETTE SWITCH REQUESTED" << std::endl;
|
std::cout << "** PALETTE SWITCH REQUESTED" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modifica la variable
|
// Modifica la variable
|
||||||
options->palette = (options->palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
|
options.palette = (options.palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
|
||||||
|
|
||||||
// Recarga las paletas
|
// Recarga las paletas
|
||||||
room->reLoadPalette();
|
room_->reLoadPalette();
|
||||||
player->reLoadPalette();
|
player_->reLoadPalette();
|
||||||
scoreboard->reLoadPalette();
|
scoreboard_->reLoadPalette();
|
||||||
|
|
||||||
// Pone el color del marcador en función del color del borde de la habitación
|
// Pone el color del marcador en función del color del borde de la habitación
|
||||||
setScoreBoardColor();
|
setScoreBoardColor();
|
||||||
@@ -511,23 +553,23 @@ void Game::switchPalette()
|
|||||||
// Establece la pantalla en negro
|
// Establece la pantalla en negro
|
||||||
void Game::setBlackScreen()
|
void Game::setBlackScreen()
|
||||||
{
|
{
|
||||||
blackScreen = true;
|
black_screen_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables relativas a la pantalla en negro
|
// Actualiza las variables relativas a la pantalla en negro
|
||||||
void Game::updateBlackScreen()
|
void Game::updateBlackScreen()
|
||||||
{
|
{
|
||||||
if (blackScreen)
|
if (black_screen_)
|
||||||
{
|
{
|
||||||
blackScreenCounter++;
|
black_screen_counter_++;
|
||||||
if (blackScreenCounter > 20)
|
if (black_screen_counter_ > 20)
|
||||||
{
|
{
|
||||||
blackScreen = false;
|
black_screen_ = false;
|
||||||
blackScreenCounter = 0;
|
black_screen_counter_ = 0;
|
||||||
|
|
||||||
player->resume();
|
player_->resume();
|
||||||
room->resume();
|
room_->resume();
|
||||||
screen->setBorderColor(room->getBorderColor());
|
screen_->setBorderColor(room_->getBorderColor());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -535,10 +577,10 @@ void Game::updateBlackScreen()
|
|||||||
// Dibuja la pantalla negra
|
// Dibuja la pantalla negra
|
||||||
void Game::renderBlackScreen()
|
void Game::renderBlackScreen()
|
||||||
{
|
{
|
||||||
if (blackScreen)
|
if (black_screen_)
|
||||||
{
|
{
|
||||||
screen->clean();
|
screen_->clean();
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
screen_->setBorderColor(stringToColor(options.palette, "black"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -546,30 +588,33 @@ void Game::renderBlackScreen()
|
|||||||
void Game::setScoreBoardColor()
|
void Game::setScoreBoardColor()
|
||||||
{
|
{
|
||||||
// Obtiene el color del borde
|
// Obtiene el color del borde
|
||||||
const color_t colorBorder = room->getBorderColor();
|
const color_t colorBorder = room_->getBorderColor();
|
||||||
|
|
||||||
const bool isBlack = colorAreEqual(colorBorder, stringToColor(options->palette, "black"));
|
const bool isBlack = colorAreEqual(colorBorder, stringToColor(options.palette, "black"));
|
||||||
const bool isBrightBlack = colorAreEqual(colorBorder, stringToColor(options->palette, "bright_black"));
|
const bool isBrightBlack = colorAreEqual(colorBorder, stringToColor(options.palette, "bright_black"));
|
||||||
|
|
||||||
// Si el color del borde es negro o negro brillante cambia el texto del marcador a blanco
|
// Si el color del borde es negro o negro brillante cambia el texto del marcador a blanco
|
||||||
board.color = isBlack || isBrightBlack ? stringToColor(options->palette, "white") : colorBorder;
|
board_.color = isBlack || isBrightBlack ? stringToColor(options.palette, "white") : colorBorder;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si ha finalizado el juego
|
// Comprueba si ha finalizado el juego
|
||||||
bool Game::checkEndGame()
|
bool Game::checkEndGame()
|
||||||
{
|
{
|
||||||
const bool isOnTheRoom = room->getName() == "THE JAIL"; // Estar en la habitación que toca
|
const bool isOnTheRoom = room_->getName() == "THE JAIL"; // Estar en la habitación que toca
|
||||||
const bool haveTheItems = board.items >= int(totalItems * 0.9f) || options->cheat.jailEnabled; // Con mas del 90% de los items recogidos
|
const bool haveTheItems = board_.items >= int(total_items_ * 0.9f) || options.cheat.jailEnabled; // Con mas del 90% de los items recogidos
|
||||||
const bool isOnTheDoor = player->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
|
const bool isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
|
||||||
|
|
||||||
if (haveTheItems)
|
if (haveTheItems)
|
||||||
{
|
{
|
||||||
board.jailEnabled = true;
|
board_.jailEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (haveTheItems && isOnTheRoom && isOnTheDoor)
|
if (haveTheItems && isOnTheRoom && isOnTheDoor)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_ENDING;
|
// Comprueba los logros de completar el juego
|
||||||
|
checkEndGameCheevos();
|
||||||
|
|
||||||
|
options.section.name = SECTION_ENDING;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -581,7 +626,7 @@ int Game::getTotalItems()
|
|||||||
{
|
{
|
||||||
int items = 0;
|
int items = 0;
|
||||||
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
||||||
rooms = resource->getAllRooms();
|
rooms = resource_->getAllRooms();
|
||||||
|
|
||||||
for (auto room : *rooms)
|
for (auto room : *rooms)
|
||||||
{
|
{
|
||||||
@@ -594,52 +639,60 @@ int Game::getTotalItems()
|
|||||||
// Va a la habitación designada
|
// Va a la habitación designada
|
||||||
void Game::goToRoom(int border)
|
void Game::goToRoom(int border)
|
||||||
{
|
{
|
||||||
const std::string roomName = room->getRoom(border);
|
const std::string roomName = room_->getRoom(border);
|
||||||
if (changeRoom(roomName))
|
if (changeRoom(roomName))
|
||||||
{
|
{
|
||||||
currentRoom = roomName;
|
current_room_ = roomName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone el juego en pausa
|
// Pone el juego en pausa
|
||||||
void Game::switchPause()
|
void Game::switchPause()
|
||||||
{
|
{
|
||||||
if (paused)
|
if (paused_)
|
||||||
{
|
{
|
||||||
player->resume();
|
player_->resume();
|
||||||
room->resume();
|
room_->resume();
|
||||||
scoreboard->resume();
|
scoreboard_->resume();
|
||||||
paused = false;
|
paused_ = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
player->pause();
|
player_->pause();
|
||||||
room->pause();
|
room_->pause();
|
||||||
scoreboard->pause();
|
scoreboard_->pause();
|
||||||
paused = true;
|
paused_ = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Da vidas al jugador cuando está en la Jail
|
// Da vidas al jugador cuando está en la Jail
|
||||||
void Game::checkRestoringJail()
|
void Game::checkRestoringJail()
|
||||||
{
|
{
|
||||||
if (room->getName() != "THE JAIL" || board.lives == 9)
|
if (room_->getName() != "THE JAIL" || board_.lives == 9)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
|
|
||||||
if (!paused)
|
if (!paused_)
|
||||||
{
|
{
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Incrementa el numero de vidas
|
||||||
if (counter == 100)
|
if (counter == 100)
|
||||||
{
|
{
|
||||||
counter = 0;
|
counter = 0;
|
||||||
board.lives++;
|
board_.lives++;
|
||||||
JA_PlaySound(deathSound);
|
JA_PlaySound(death_sound_);
|
||||||
|
|
||||||
|
// Invalida el logro de completar el juego sin entrar a la jail
|
||||||
|
const bool haveTheItems = board_.items >= int(total_items_ * 0.9f);
|
||||||
|
if (!haveTheItems)
|
||||||
|
{
|
||||||
|
cheevos_->invalidate(9);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -647,30 +700,100 @@ void Game::checkRestoringJail()
|
|||||||
void Game::initStats()
|
void Game::initStats()
|
||||||
{
|
{
|
||||||
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
|
||||||
rooms = resource->getAllRooms();
|
rooms = resource_->getAllRooms();
|
||||||
|
|
||||||
for (auto room : *rooms)
|
for (auto room : *rooms)
|
||||||
{
|
{
|
||||||
stats->addDictionary(room.room->number, room.room->name);
|
stats_->addDictionary(room.room->number, room.room->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
stats->init();
|
stats_->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea la textura con el nombre de la habitación
|
// Crea la textura con el nombre de la habitación
|
||||||
void Game::fillRoomNameTexture()
|
void Game::fillRoomNameTexture()
|
||||||
{
|
{
|
||||||
// Pone la textura como destino de renderizado
|
// Pone la textura como destino de renderizado
|
||||||
SDL_SetRenderTarget(renderer, roomNameTexture);
|
SDL_SetRenderTarget(renderer_, room_name_texture_);
|
||||||
|
|
||||||
// Rellena la textura de color
|
// Rellena la textura de color
|
||||||
const color_t color = stringToColor(options->palette, "white");
|
const color_t color = stringToColor(options.palette, "white");
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
// Escribe el texto en la textura
|
// Escribe el texto en la textura
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, text->getCharacterSize() / 2, room->getName(), 1, room->getBGColor());
|
text_->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, text_->getCharacterSize() / 2, room_->getName(), 1, room_->getBGColor());
|
||||||
|
|
||||||
// Deja el renderizador por defecto
|
// Deja el renderizador por defecto
|
||||||
SDL_SetRenderTarget(renderer, nullptr);
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba algunos logros
|
||||||
|
void Game::checkSomeCheevos()
|
||||||
|
{
|
||||||
|
// Logros sobre la cantidad de items
|
||||||
|
if (board_.items == total_items_)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(4);
|
||||||
|
cheevos_->unlock(3);
|
||||||
|
cheevos_->unlock(2);
|
||||||
|
cheevos_->unlock(1);
|
||||||
|
}
|
||||||
|
else if (board_.items >= total_items_ * 0.75f)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(3);
|
||||||
|
cheevos_->unlock(2);
|
||||||
|
cheevos_->unlock(1);
|
||||||
|
}
|
||||||
|
else if (board_.items >= total_items_ * 0.5f)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(2);
|
||||||
|
cheevos_->unlock(1);
|
||||||
|
}
|
||||||
|
else if (board_.items >= total_items_ * 0.25f)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logros sobre las habitaciones visitadas
|
||||||
|
if (board_.rooms >= 60)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(7);
|
||||||
|
cheevos_->unlock(6);
|
||||||
|
cheevos_->unlock(5);
|
||||||
|
}
|
||||||
|
else if (board_.rooms >= 40)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(6);
|
||||||
|
cheevos_->unlock(5);
|
||||||
|
}
|
||||||
|
else if (board_.rooms >= 20)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba los logros de completar el juego
|
||||||
|
void Game::checkEndGameCheevos()
|
||||||
|
{
|
||||||
|
// "Complete the game"
|
||||||
|
cheevos_->unlock(8);
|
||||||
|
|
||||||
|
// "Complete the game without entering the jail"
|
||||||
|
cheevos_->unlock(9);
|
||||||
|
|
||||||
|
// "Complete the game with all items"
|
||||||
|
if (board_.items == total_items_)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// "Complete the game without dying"
|
||||||
|
cheevos_->unlock(11);
|
||||||
|
|
||||||
|
// "Complete the game in under 30 minutes"
|
||||||
|
if (scoreboard_->getMinutes() < 30)
|
||||||
|
{
|
||||||
|
cheevos_->unlock(12);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
116
source/game.h
@@ -1,62 +1,61 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
#include "common/debug.h"
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include "common/input.h"
|
#include <string> // Para string, basic_string
|
||||||
#include "common/jail_audio.h"
|
#include "player.h" // Para playerSpawn_t
|
||||||
#include "common/resource.h"
|
#include "scoreboard.h" // Para board_t
|
||||||
#include "common/screen.h"
|
class Asset;
|
||||||
#include "common/sprite.h"
|
class Cheevos;
|
||||||
#include "common/text.h"
|
class Debug;
|
||||||
#include "common/utils.h"
|
class Input;
|
||||||
#include "const.h"
|
class ItemTracker;
|
||||||
#include "item_tracker.h"
|
class Resource;
|
||||||
#include "player.h"
|
class Room;
|
||||||
#include "room_tracker.h"
|
class RoomTracker;
|
||||||
#include "room.h"
|
class Screen;
|
||||||
#include "scoreboard.h"
|
class Stats;
|
||||||
#include "stats.h"
|
class Text;
|
||||||
|
struct JA_Music_t;
|
||||||
#ifndef GAME_H
|
struct JA_Sound_t;
|
||||||
#define GAME_H
|
struct options_t;
|
||||||
|
struct section_t;
|
||||||
|
|
||||||
class Game
|
class Game
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
Screen *screen_; // Objeto encargado de manejar el renderizador
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Screen *screen; // Objeto encargado de manejar el renderizador
|
Room *room_; // Objeto encargado de gestionar cada habitación del juego
|
||||||
Room *room; // Objeto encargado de gestionar cada habitación del juego
|
Player *player_; // Objeto con el jugador
|
||||||
Player *player; // Objeto con el jugador
|
ItemTracker *item_tracker_; // Lleva el control de los objetos recogidos
|
||||||
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
|
RoomTracker *room_tracker_; // Lleva el control de las habitaciones visitadas
|
||||||
RoomTracker *roomTracker; // Lleva el control de las habitaciones visitadas
|
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
Input *input_; // Objeto pata gestionar la entrada
|
||||||
Input *input; // Objeto pata gestionar la entrada
|
Text *text_; // Objeto para los textos del juego
|
||||||
Text *text; // Objeto para los textos del juego
|
Scoreboard *scoreboard_; // Objeto encargado de gestionar el marcador
|
||||||
ScoreBoard *scoreboard; // Objeto encargado de gestionar el marcador
|
Cheevos *cheevos_; // Objeto encargado de gestionar los logros del juego
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource_; // Objeto con los recursos
|
||||||
Debug *debug; // Objeto para gestionar la información de debug
|
Debug *debug_; // Objeto para gestionar la información de debug
|
||||||
options_t *options; // Puntero a las opciones del juego
|
Stats *stats_; // Objeto encargado de gestionar las estadísticas
|
||||||
Stats *stats; // Objeto encargado de gestionar las estadísticas
|
SDL_Texture *room_name_texture_; // Textura para escribir el nombre de la habitación
|
||||||
SDL_Texture *roomNameTexture; // Textura para escribir el nombre de la habitación
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
JA_Music_t *music; // Musica que suena durante el juego
|
JA_Music_t *music_; // Musica que suena durante el juego
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticks_speed_; // Velocidad a la que se repiten los bucles del programa
|
||||||
section_t section; // Seccion actual dentro del juego
|
std::string current_room_; // Fichero de la habitación actual
|
||||||
std::string currentRoom; // Fichero de la habitación actual
|
playerSpawn_t spawn_point_; // Lugar de la habitación donde aparece el jugador
|
||||||
playerSpawn_t spawnPoint; // Lugar de la habitación donde aparece el jugador
|
JA_Sound_t *death_sound_; // Sonido a reproducir cuando muere el jugador
|
||||||
JA_Sound_t *deathSound; // Sonido a reproducir cuando muere el jugador
|
board_t board_; // Estructura con los datos del marcador
|
||||||
board_t board; // Estructura con los datos del marcador
|
bool paused_; // Indica si el juego se encuentra en pausa
|
||||||
bool paused; // Indica si el juego se encuentra en pausa
|
bool black_screen_; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
|
||||||
bool blackScreen; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador
|
int black_screen_counter_; // Contador para temporizar la pantalla en negro
|
||||||
int blackScreenCounter; // Contador para temporizar la pantalla en negro
|
int total_items_; // Cantidad total de items que hay en el mapeado del juego
|
||||||
int totalItems; // Cantidad total de items que hay en el mapeado del juego
|
SDL_Rect room_name_rect_; // Rectangulo donde pintar la textura con el nombre de la habitación
|
||||||
SDL_Rect roomNameRect; // Rectangulo donde pintar la textura con el nombre de la habitación
|
|
||||||
|
|
||||||
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
// Actualiza el juego, las variables, comprueba la entrada, etc.
|
||||||
void update();
|
void update();
|
||||||
@@ -65,7 +64,7 @@ private:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba los eventos de la cola
|
// Comprueba los eventos de la cola
|
||||||
void checkEventHandler();
|
void checkEvents();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
// Pone la información de debug en pantalla
|
// Pone la información de debug en pantalla
|
||||||
@@ -81,6 +80,9 @@ private:
|
|||||||
// Cambia de habitación
|
// Cambia de habitación
|
||||||
bool changeRoom(std::string file);
|
bool changeRoom(std::string file);
|
||||||
|
|
||||||
|
// Comprueba el teclado
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
// Comprueba si el jugador esta en el borde de la pantalla y actua
|
// Comprueba si el jugador esta en el borde de la pantalla y actua
|
||||||
void checkPlayerOnBorder();
|
void checkPlayerOnBorder();
|
||||||
|
|
||||||
@@ -138,15 +140,19 @@ private:
|
|||||||
// Pone el nombre de la habitación en la textura
|
// Pone el nombre de la habitación en la textura
|
||||||
void fillRoomNameTexture();
|
void fillRoomNameTexture();
|
||||||
|
|
||||||
|
// Comprueba algunos logros
|
||||||
|
void checkSomeCheevos();
|
||||||
|
|
||||||
|
// Comprueba los logros de completar el juego
|
||||||
|
void checkEndGameCheevos();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug);
|
Game();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Game();
|
~Game();
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
section_t run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,17 +1,27 @@
|
|||||||
#include "game_over.h"
|
#include "game_over.h"
|
||||||
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
|
#include <algorithm> // Para min, max
|
||||||
|
#include <string> // Para basic_string, operator+, to_string, char...
|
||||||
|
#include "animatedsprite.h" // Para AnimatedSprite
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "const.h" // Para GAMECANVAS_CENTER_X, SECTION_GAME_OVER
|
||||||
|
#include "input.h" // Para Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // Para JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic
|
||||||
|
#include "resource.h" // Para Resource
|
||||||
|
#include "screen.h" // Para Screen
|
||||||
|
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
|
GameOver::GameOver()
|
||||||
|
: screen(Screen::get()),
|
||||||
|
renderer(Screen::get()->getRenderer()),
|
||||||
|
resource(Resource::get()),
|
||||||
|
asset(Asset::get()),
|
||||||
|
input(Input::get())
|
||||||
{
|
{
|
||||||
// Copia los punteros
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->resource = resource;
|
|
||||||
this->asset = asset;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros a objetos
|
// Reserva memoria para los punteros a objetos
|
||||||
eventHandler = new SDL_Event();
|
|
||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||||
playerSprite = new AnimatedSprite(renderer, resource->getAnimation("player_game_over.ani"));
|
playerSprite = new AnimatedSprite(renderer, resource->getAnimation("player_game_over.ani"));
|
||||||
tvSprite = new AnimatedSprite(renderer, resource->getAnimation("tv.ani"));
|
tvSprite = new AnimatedSprite(renderer, resource->getAnimation("tv.ani"));
|
||||||
@@ -20,8 +30,8 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
|
|||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
preCounter = 0;
|
preCounter = 0;
|
||||||
counter = 0;
|
counter = 0;
|
||||||
section.name = SECTION_PROG_GAME_OVER;
|
options.section.name = SECTION_GAME_OVER;
|
||||||
section.subsection = 0;
|
options.section.subsection = 0;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
ticksSpeed = 15;
|
ticksSpeed = 15;
|
||||||
endSection = 400;
|
endSection = 400;
|
||||||
@@ -36,7 +46,7 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
|
|||||||
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
|
||||||
for (auto cl : colorList)
|
for (auto cl : colorList)
|
||||||
{
|
{
|
||||||
colors.push_back(stringToColor(options->palette, cl));
|
colors.push_back(stringToColor(options.palette, cl));
|
||||||
}
|
}
|
||||||
color = colors.back();
|
color = colors.back();
|
||||||
}
|
}
|
||||||
@@ -45,7 +55,6 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
|
|||||||
GameOver::~GameOver()
|
GameOver::~GameOver()
|
||||||
{
|
{
|
||||||
// Libera la memoria de los objetos
|
// Libera la memoria de los objetos
|
||||||
delete eventHandler;
|
|
||||||
delete text;
|
delete text;
|
||||||
delete playerSprite;
|
delete playerSprite;
|
||||||
delete tvSprite;
|
delete tvSprite;
|
||||||
@@ -61,8 +70,8 @@ void GameOver::update()
|
|||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba las entradas
|
||||||
checkEventHandler();
|
checkInput();
|
||||||
|
|
||||||
// Actualiza el color usado para renderizar los textos e imagenes
|
// Actualiza el color usado para renderizar los textos e imagenes
|
||||||
updateColor();
|
updateColor();
|
||||||
@@ -74,8 +83,7 @@ void GameOver::update()
|
|||||||
playerSprite->update();
|
playerSprite->update();
|
||||||
tvSprite->update();
|
tvSprite->update();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
screen->update();
|
||||||
screen->updateNotifier();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,93 +107,79 @@ void GameOver::render()
|
|||||||
renderSprites();
|
renderSprites();
|
||||||
|
|
||||||
// Escribe el texto con las habitaciones y los items
|
// Escribe el texto con las habitaciones y los items
|
||||||
const std::string itemsTxt = std::to_string(options->stats.items / 100) + std::to_string((options->stats.items % 100) / 10) + std::to_string(options->stats.items % 10);
|
const std::string itemsTxt = std::to_string(options.stats.items / 100) + std::to_string((options.stats.items % 100) / 10) + std::to_string(options.stats.items % 10);
|
||||||
const std::string roomsTxt = std::to_string(options->stats.rooms / 100) + std::to_string((options->stats.rooms % 100) / 10) + std::to_string(options->stats.rooms % 10);
|
const std::string roomsTxt = std::to_string(options.stats.rooms / 100) + std::to_string((options.stats.rooms % 100) / 10) + std::to_string(options.stats.rooms % 10);
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 80, "ITEMS: " + itemsTxt, 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 80, "ITEMS: " + itemsTxt, 1, color);
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 90, "ROOMS: " + roomsTxt, 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 90, "ROOMS: " + roomsTxt, 1, color);
|
||||||
|
|
||||||
// Escribe el texto con "Tu peor pesadilla"
|
// Escribe el texto con "Tu peor pesadilla"
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 110, "YOUR WORST NIGHTMARE IS", 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 110, "YOUR WORST NIGHTMARE IS", 1, color);
|
||||||
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options->stats.worstNightmare, 1, color);
|
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options.stats.worstNightmare, 1, color);
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void GameOver::checkEventHandler()
|
void GameOver::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.name = SECTION_QUIT;
|
||||||
section.subsection = 0;
|
options.section.subsection = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
// Comprueba las entradas
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
void GameOver::checkInput()
|
||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.scancode)
|
|
||||||
|
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
options.section.name = SECTION_QUIT;
|
||||||
section.name = SECTION_PROG_QUIT;
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||||
screen->switchBorder();
|
{
|
||||||
resource->reLoadTextures();
|
screen->toggleBorder();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F:
|
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||||
screen->switchVideoMode();
|
{
|
||||||
resource->reLoadTextures();
|
screen->toggleVideoMode();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(1);
|
{
|
||||||
resource->reLoadTextures();
|
screen->decWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F2:
|
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(2);
|
{
|
||||||
resource->reLoadTextures();
|
screen->incWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F3:
|
else if (input->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
screen->setWindowSize(3);
|
{
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
switchPalette();
|
switchPalette();
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t GameOver::run()
|
void GameOver::run()
|
||||||
{
|
{
|
||||||
while (section.name == SECTION_PROG_GAME_OVER)
|
while (options.section.name == SECTION_GAME_OVER)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el color usado para renderizar los textos e imagenes
|
// Actualiza el color usado para renderizar los textos e imagenes
|
||||||
@@ -195,7 +189,6 @@ void GameOver::updateColor()
|
|||||||
|
|
||||||
if (counter < half)
|
if (counter < half)
|
||||||
{
|
{
|
||||||
// const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
|
|
||||||
const float step = std::min(counter, fadeLenght) / (float)fadeLenght;
|
const float step = std::min(counter, fadeLenght) / (float)fadeLenght;
|
||||||
const int index = (colors.size() - 1) - int((colors.size() - 1) * step);
|
const int index = (colors.size() - 1) - int((colors.size() - 1) * step);
|
||||||
color = colors[index];
|
color = colors[index];
|
||||||
@@ -240,13 +233,13 @@ void GameOver::updateCounters()
|
|||||||
// Comprueba si ha terminado la sección
|
// Comprueba si ha terminado la sección
|
||||||
else if (counter == endSection)
|
else if (counter == endSection)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_LOGO;
|
options.section.name = SECTION_LOGO;
|
||||||
section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
options.section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void GameOver::switchPalette()
|
void GameOver::switchPalette()
|
||||||
{
|
{
|
||||||
options->palette = (options->palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
|
options.palette = (options.palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
|
||||||
}
|
}
|
||||||
@@ -1,30 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "common/animatedsprite.h"
|
|
||||||
#include "common/asset.h"
|
|
||||||
#include "common/jail_audio.h"
|
|
||||||
#include "common/resource.h"
|
|
||||||
#include "common/screen.h"
|
|
||||||
#include "common/sprite.h"
|
|
||||||
#include "common/text.h"
|
|
||||||
#include "common/texture.h"
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef GAME_OVER_H
|
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||||
#define GAME_OVER_H
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
|
#include <vector> // Para vector
|
||||||
|
#include "utils.h" // Para color_t
|
||||||
|
class AnimatedSprite;
|
||||||
|
class Asset;
|
||||||
|
class Input;
|
||||||
|
class Resource;
|
||||||
|
class Screen;
|
||||||
|
class Text;
|
||||||
|
struct JA_Music_t;
|
||||||
|
|
||||||
class GameOver
|
class GameOver
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
Asset *asset; // Objeto con los ficheros de recursos
|
||||||
options_t *options; // Puntero a las opciones del juego
|
Input *input; // Objeto pata gestionar la entrada
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
|
||||||
Text *text; // Objeto para escribir texto en pantalla
|
Text *text; // Objeto para escribir texto en pantalla
|
||||||
AnimatedSprite *playerSprite; // Sprite con el jugador
|
AnimatedSprite *playerSprite; // Sprite con el jugador
|
||||||
AnimatedSprite *tvSprite; // Sprite con el televisor
|
AnimatedSprite *tvSprite; // Sprite con el televisor
|
||||||
@@ -32,7 +29,6 @@ private:
|
|||||||
// Variables
|
// Variables
|
||||||
int preCounter; // Contador previo
|
int preCounter; // Contador previo
|
||||||
int counter; // Contador
|
int counter; // Contador
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
||||||
std::vector<color_t> colors; // Vector con los colores para el fade
|
std::vector<color_t> colors; // Vector con los colores para el fade
|
||||||
@@ -49,7 +45,10 @@ private:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void checkEventHandler();
|
void checkEvents();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
// Actualiza el color usado para renderizar los textos e imagenes
|
// Actualiza el color usado para renderizar los textos e imagenes
|
||||||
void updateColor();
|
void updateColor();
|
||||||
@@ -65,13 +64,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
GameOver();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~GameOver();
|
~GameOver();
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
478
source/gif.c
Normal file
@@ -0,0 +1,478 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
#define EXTENSION_INTRODUCER 0x21
|
||||||
|
#define IMAGE_DESCRIPTOR 0x2C
|
||||||
|
#define TRAILER 0x3B
|
||||||
|
|
||||||
|
#define GRAPHIC_CONTROL 0xF9
|
||||||
|
#define APPLICATION_EXTENSION 0xFF
|
||||||
|
#define COMMENT_EXTENSION 0xFE
|
||||||
|
#define PLAINTEXT_EXTENSION 0x01
|
||||||
|
|
||||||
|
#define READ(dst, size) memcpy(dst, buffer, size); buffer += size
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned short width;
|
||||||
|
unsigned short height;
|
||||||
|
unsigned char fields;
|
||||||
|
unsigned char background_color_index;
|
||||||
|
unsigned char pixel_aspect_ratio;
|
||||||
|
}
|
||||||
|
screen_descriptor_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned char r;
|
||||||
|
unsigned char g;
|
||||||
|
unsigned char b;
|
||||||
|
}
|
||||||
|
rgb;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned short image_left_position;
|
||||||
|
unsigned short image_top_position;
|
||||||
|
unsigned short image_width;
|
||||||
|
unsigned short image_height;
|
||||||
|
unsigned char fields;
|
||||||
|
}
|
||||||
|
image_descriptor_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned char byte;
|
||||||
|
int prev;
|
||||||
|
int len;
|
||||||
|
}
|
||||||
|
dictionary_entry_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned char extension_code;
|
||||||
|
unsigned char block_size;
|
||||||
|
}
|
||||||
|
extension_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned char fields;
|
||||||
|
unsigned short delay_time;
|
||||||
|
unsigned char transparent_color_index;
|
||||||
|
}
|
||||||
|
graphic_control_extension_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned char application_id[ 8 ];
|
||||||
|
unsigned char version[ 3 ];
|
||||||
|
}
|
||||||
|
application_extension_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
unsigned short left;
|
||||||
|
unsigned short top;
|
||||||
|
unsigned short width;
|
||||||
|
unsigned short height;
|
||||||
|
unsigned char cell_width;
|
||||||
|
unsigned char cell_height;
|
||||||
|
unsigned char foreground_color;
|
||||||
|
unsigned char background_color;
|
||||||
|
}
|
||||||
|
plaintext_extension_t;
|
||||||
|
|
||||||
|
//static unsigned short width = 0;
|
||||||
|
//static unsigned short height = 0;
|
||||||
|
//static unsigned char* uncompressed_data = NULL;
|
||||||
|
|
||||||
|
void uncompress( int code_length,
|
||||||
|
const unsigned char *input,
|
||||||
|
int input_length,
|
||||||
|
unsigned char *out )
|
||||||
|
{
|
||||||
|
//int maxbits;
|
||||||
|
int i, bit;
|
||||||
|
int code, prev = -1;
|
||||||
|
dictionary_entry_t *dictionary;
|
||||||
|
int dictionary_ind;
|
||||||
|
unsigned int mask = 0x01;
|
||||||
|
int reset_code_length;
|
||||||
|
int clear_code; // This varies depending on code_length
|
||||||
|
int stop_code; // one more than clear code
|
||||||
|
int match_len;
|
||||||
|
|
||||||
|
clear_code = 1 << ( code_length );
|
||||||
|
stop_code = clear_code + 1;
|
||||||
|
// To handle clear codes
|
||||||
|
reset_code_length = code_length;
|
||||||
|
|
||||||
|
// Create a dictionary large enough to hold "code_length" entries.
|
||||||
|
// Once the dictionary overflows, code_length increases
|
||||||
|
dictionary = ( dictionary_entry_t * )
|
||||||
|
malloc( sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
||||||
|
|
||||||
|
// Initialize the first 2^code_len entries of the dictionary with their
|
||||||
|
// indices. The rest of the entries will be built up dynamically.
|
||||||
|
|
||||||
|
// Technically, it shouldn't be necessary to initialize the
|
||||||
|
// dictionary. The spec says that the encoder "should output a
|
||||||
|
// clear code as the first code in the image data stream". It doesn't
|
||||||
|
// say must, though...
|
||||||
|
for ( dictionary_ind = 0;
|
||||||
|
dictionary_ind < ( 1 << code_length );
|
||||||
|
dictionary_ind++ )
|
||||||
|
{
|
||||||
|
dictionary[ dictionary_ind ].byte = dictionary_ind;
|
||||||
|
// XXX this only works because prev is a 32-bit int (> 12 bits)
|
||||||
|
dictionary[ dictionary_ind ].prev = -1;
|
||||||
|
dictionary[ dictionary_ind ].len = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2^code_len + 1 is the special "end" code; don't give it an entry here
|
||||||
|
dictionary_ind++;
|
||||||
|
dictionary_ind++;
|
||||||
|
|
||||||
|
// TODO verify that the very last byte is clear_code + 1
|
||||||
|
while ( input_length )
|
||||||
|
{
|
||||||
|
code = 0x0;
|
||||||
|
// Always read one more bit than the code length
|
||||||
|
for ( i = 0; i < ( code_length + 1 ); i++ )
|
||||||
|
{
|
||||||
|
// This is different than in the file read example; that
|
||||||
|
// was a call to "next_bit"
|
||||||
|
bit = ( *input & mask ) ? 1 : 0;
|
||||||
|
mask <<= 1;
|
||||||
|
|
||||||
|
if ( mask == 0x100 )
|
||||||
|
{
|
||||||
|
mask = 0x01;
|
||||||
|
input++;
|
||||||
|
input_length--;
|
||||||
|
}
|
||||||
|
|
||||||
|
code = code | ( bit << i );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( code == clear_code )
|
||||||
|
{
|
||||||
|
code_length = reset_code_length;
|
||||||
|
dictionary = ( dictionary_entry_t * ) realloc( dictionary,
|
||||||
|
sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
||||||
|
|
||||||
|
for ( dictionary_ind = 0;
|
||||||
|
dictionary_ind < ( 1 << code_length );
|
||||||
|
dictionary_ind++ )
|
||||||
|
{
|
||||||
|
dictionary[ dictionary_ind ].byte = dictionary_ind;
|
||||||
|
// XXX this only works because prev is a 32-bit int (> 12 bits)
|
||||||
|
dictionary[ dictionary_ind ].prev = -1;
|
||||||
|
dictionary[ dictionary_ind ].len = 1;
|
||||||
|
}
|
||||||
|
dictionary_ind++;
|
||||||
|
dictionary_ind++;
|
||||||
|
prev = -1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if ( code == stop_code )
|
||||||
|
{
|
||||||
|
/*if ( input_length > 1 )
|
||||||
|
{
|
||||||
|
fprintf( stderr, "Malformed GIF (early stop code)\n" );
|
||||||
|
exit( 0 );
|
||||||
|
}*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update the dictionary with this character plus the _entry_
|
||||||
|
// (character or string) that came before it
|
||||||
|
if ( ( prev > -1 ) && ( code_length < 12 ) )
|
||||||
|
{
|
||||||
|
if ( code > dictionary_ind )
|
||||||
|
{
|
||||||
|
fprintf( stderr, "code = %.02x, but dictionary_ind = %.02x\n",
|
||||||
|
code, dictionary_ind );
|
||||||
|
exit( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Special handling for KwKwK
|
||||||
|
if ( code == dictionary_ind )
|
||||||
|
{
|
||||||
|
int ptr = prev;
|
||||||
|
|
||||||
|
while ( dictionary[ ptr ].prev != -1 )
|
||||||
|
{
|
||||||
|
ptr = dictionary[ ptr ].prev;
|
||||||
|
}
|
||||||
|
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int ptr = code;
|
||||||
|
while ( dictionary[ ptr ].prev != -1 )
|
||||||
|
{
|
||||||
|
ptr = dictionary[ ptr ].prev;
|
||||||
|
}
|
||||||
|
dictionary[ dictionary_ind ].byte = dictionary[ ptr ].byte;
|
||||||
|
}
|
||||||
|
|
||||||
|
dictionary[ dictionary_ind ].prev = prev;
|
||||||
|
|
||||||
|
dictionary[ dictionary_ind ].len = dictionary[ prev ].len + 1;
|
||||||
|
|
||||||
|
dictionary_ind++;
|
||||||
|
|
||||||
|
// GIF89a mandates that this stops at 12 bits
|
||||||
|
if ( ( dictionary_ind == ( 1 << ( code_length + 1 ) ) ) &&
|
||||||
|
( code_length < 11 ) )
|
||||||
|
{
|
||||||
|
code_length++;
|
||||||
|
|
||||||
|
dictionary = ( dictionary_entry_t * ) realloc( dictionary,
|
||||||
|
sizeof( dictionary_entry_t ) * ( 1 << ( code_length + 1 ) ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prev = code;
|
||||||
|
|
||||||
|
// Now copy the dictionary entry backwards into "out"
|
||||||
|
match_len = dictionary[ code ].len;
|
||||||
|
while ( code != -1 )
|
||||||
|
{
|
||||||
|
out[ dictionary[ code ].len - 1 ] = dictionary[ code ].byte;
|
||||||
|
if ( dictionary[ code ].prev == code )
|
||||||
|
{
|
||||||
|
fprintf( stderr, "Internal error; self-reference." );
|
||||||
|
exit( 0 );
|
||||||
|
}
|
||||||
|
code = dictionary[ code ].prev;
|
||||||
|
}
|
||||||
|
|
||||||
|
out += match_len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int read_sub_blocks( unsigned char* buffer, unsigned char **data )
|
||||||
|
{
|
||||||
|
int data_length;
|
||||||
|
int index;
|
||||||
|
unsigned char block_size;
|
||||||
|
|
||||||
|
// Everything following are data sub-blocks, until a 0-sized block is
|
||||||
|
// encountered.
|
||||||
|
data_length = 0;
|
||||||
|
*data = NULL;
|
||||||
|
index = 0;
|
||||||
|
|
||||||
|
while ( 1 )
|
||||||
|
{
|
||||||
|
READ(&block_size, 1);
|
||||||
|
|
||||||
|
if ( block_size == 0 ) // end of sub-blocks
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
data_length += block_size;
|
||||||
|
*data = (unsigned char*)realloc( *data, data_length );
|
||||||
|
|
||||||
|
// TODO this could be split across block size boundaries
|
||||||
|
READ(*data + index, block_size);
|
||||||
|
|
||||||
|
index += block_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data_length;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char* process_image_descriptor( unsigned char* buffer,
|
||||||
|
rgb *gct,
|
||||||
|
int gct_size,
|
||||||
|
int resolution_bits )
|
||||||
|
{
|
||||||
|
image_descriptor_t image_descriptor;
|
||||||
|
int compressed_data_length;
|
||||||
|
unsigned char *compressed_data = NULL;
|
||||||
|
unsigned char lzw_code_size;
|
||||||
|
int uncompressed_data_length = 0;
|
||||||
|
unsigned char *uncompressed_data = NULL;
|
||||||
|
|
||||||
|
// TODO there could actually be lots of these
|
||||||
|
READ(&image_descriptor, 9);
|
||||||
|
|
||||||
|
// TODO if LCT = true, read the LCT
|
||||||
|
|
||||||
|
READ(&lzw_code_size, 1);
|
||||||
|
|
||||||
|
compressed_data_length = read_sub_blocks( buffer, &compressed_data );
|
||||||
|
|
||||||
|
// width = image_descriptor.image_width;
|
||||||
|
// height = image_descriptor.image_height;
|
||||||
|
uncompressed_data_length = image_descriptor.image_width *
|
||||||
|
image_descriptor.image_height;
|
||||||
|
uncompressed_data = (unsigned char*)malloc( uncompressed_data_length );
|
||||||
|
|
||||||
|
uncompress( lzw_code_size, compressed_data, compressed_data_length,
|
||||||
|
uncompressed_data );
|
||||||
|
|
||||||
|
if ( compressed_data ) free( compressed_data );
|
||||||
|
|
||||||
|
//if ( uncompressed_data )
|
||||||
|
// free( uncompressed_data );
|
||||||
|
|
||||||
|
return uncompressed_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param gif_file the file descriptor of a file containing a
|
||||||
|
* GIF-encoded file. This should point to the first byte in
|
||||||
|
* the file when invoked.
|
||||||
|
*/
|
||||||
|
#define rb (*(buffer++))
|
||||||
|
|
||||||
|
uint32_t* LoadPalette(unsigned char *buffer) {
|
||||||
|
unsigned char header[7];
|
||||||
|
screen_descriptor_t screen_descriptor;
|
||||||
|
//int color_resolution_bits;
|
||||||
|
|
||||||
|
int global_color_table_size = 0; // number of entries in global_color_table
|
||||||
|
uint32_t *global_color_table = NULL;
|
||||||
|
|
||||||
|
READ(header, 6);
|
||||||
|
READ(&screen_descriptor, 7);
|
||||||
|
|
||||||
|
//color_resolution_bits = ((screen_descriptor.fields & 0x70) >> 4) + 1;
|
||||||
|
global_color_table = (uint32_t *)calloc(1, 1024);
|
||||||
|
|
||||||
|
if (screen_descriptor.fields & 0x80) {
|
||||||
|
global_color_table_size = 1 << (((screen_descriptor.fields & 0x07) + 1));
|
||||||
|
|
||||||
|
//global_color_table = (rgb *)malloc(3 * global_color_table_size);
|
||||||
|
//READ(global_color_table, 3 * global_color_table_size);
|
||||||
|
for (int i=0; i<global_color_table_size;++i) {
|
||||||
|
global_color_table[i] = (buffer[0]<<16) + (buffer[1]<<8) + buffer[2];
|
||||||
|
buffer+=3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return global_color_table;
|
||||||
|
}
|
||||||
|
|
||||||
|
static unsigned char* process_gif_stream(unsigned char *buffer, unsigned short* w, unsigned short* h)
|
||||||
|
{
|
||||||
|
unsigned char header[ 7 ];
|
||||||
|
screen_descriptor_t screen_descriptor;
|
||||||
|
int color_resolution_bits;
|
||||||
|
|
||||||
|
int global_color_table_size =0; // number of entries in global_color_table
|
||||||
|
rgb *global_color_table = NULL;
|
||||||
|
|
||||||
|
unsigned char block_type = 0x0;
|
||||||
|
|
||||||
|
// A GIF file starts with a Header (section 17)
|
||||||
|
READ(header, 6);
|
||||||
|
header[ 6 ] = 0x0;
|
||||||
|
|
||||||
|
// XXX there's another format, GIF87a, that you may still find
|
||||||
|
// floating around.
|
||||||
|
/*if ( strcmp( "GIF89a", (char*)header ) )
|
||||||
|
{
|
||||||
|
fprintf( stderr,
|
||||||
|
"Invalid GIF file (header is '%s', should be 'GIF89a')\n",
|
||||||
|
header );
|
||||||
|
return NULL;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// Followed by a logical screen descriptor
|
||||||
|
// Note that this works because GIFs specify little-endian order; on a
|
||||||
|
// big-endian machine, the height & width would need to be reversed.
|
||||||
|
|
||||||
|
// Can't use sizeof here since GCC does byte alignment;
|
||||||
|
// sizeof( screen_descriptor_t ) = 8!
|
||||||
|
READ(&screen_descriptor, 7);
|
||||||
|
*w = screen_descriptor.width;
|
||||||
|
*h = screen_descriptor.height;
|
||||||
|
|
||||||
|
color_resolution_bits = ( ( screen_descriptor.fields & 0x70 ) >> 4 ) + 1;
|
||||||
|
|
||||||
|
if ( screen_descriptor.fields & 0x80 )
|
||||||
|
{
|
||||||
|
//int i;
|
||||||
|
// If bit 7 is set, the next block is a global color table; read it
|
||||||
|
global_color_table_size = 1 <<
|
||||||
|
( ( ( screen_descriptor.fields & 0x07 ) + 1 ) );
|
||||||
|
|
||||||
|
global_color_table = ( rgb * ) malloc( 3 * global_color_table_size );
|
||||||
|
|
||||||
|
// XXX this could conceivably return a short count...
|
||||||
|
READ(global_color_table, 3 * global_color_table_size);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( block_type != TRAILER )
|
||||||
|
{
|
||||||
|
READ(&block_type, 1);
|
||||||
|
|
||||||
|
unsigned char size;
|
||||||
|
switch ( block_type )
|
||||||
|
{
|
||||||
|
case IMAGE_DESCRIPTOR:
|
||||||
|
return process_image_descriptor(buffer,
|
||||||
|
global_color_table,
|
||||||
|
global_color_table_size,
|
||||||
|
color_resolution_bits);
|
||||||
|
break;
|
||||||
|
case EXTENSION_INTRODUCER:
|
||||||
|
buffer++;
|
||||||
|
size = *(buffer++);
|
||||||
|
buffer += size;
|
||||||
|
do {
|
||||||
|
size = *(buffer++);
|
||||||
|
buffer += size;
|
||||||
|
} while (size != 0);
|
||||||
|
|
||||||
|
/*if ( !process_extension( buffer ) )
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}*/
|
||||||
|
break;
|
||||||
|
case TRAILER:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fprintf( stderr, "Bailing on unrecognized block type %.02x\n",
|
||||||
|
block_type );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unsigned char* LoadGif(unsigned char *buffer, unsigned short* w, unsigned short* h) {
|
||||||
|
return process_gif_stream(buffer, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*int main( int argc, char *argv[] )
|
||||||
|
{
|
||||||
|
FILE* gif_file;
|
||||||
|
|
||||||
|
if ( argc < 2 )
|
||||||
|
{
|
||||||
|
fprintf( stderr, "Usage: %s <path-to-gif-file>\n", argv[ 0 ] );
|
||||||
|
exit( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
gif_file = fopen( argv[ 1 ], "rb" );
|
||||||
|
|
||||||
|
if ( gif_file == NULL )
|
||||||
|
{
|
||||||
|
fprintf( stderr, "Unable to open file '%s'", argv[ 1 ] );
|
||||||
|
perror( ": " );
|
||||||
|
}
|
||||||
|
|
||||||
|
process_gif_stream( gif_file );
|
||||||
|
|
||||||
|
fclose( gif_file );
|
||||||
|
}*/
|
||||||
@@ -1,31 +1,52 @@
|
|||||||
#include "input.h"
|
#include "input.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL.h> // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||||
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
|
#include <SDL2/SDL_events.h> // Para SDL_ENABLE
|
||||||
|
#include <SDL2/SDL_joystick.h> // Para SDL_NumJoysticks
|
||||||
|
#include <SDL2/SDL_keyboard.h> // Para SDL_GetKeyboardState
|
||||||
|
#include <iostream> // Para basic_ostream, operator<<, cout, basi...
|
||||||
|
|
||||||
|
// [SINGLETON]
|
||||||
|
Input *Input::input_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
void Input::init(const std::string &game_controller_db_path)
|
||||||
|
{
|
||||||
|
Input::input_ = new Input(game_controller_db_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
void Input::destroy()
|
||||||
|
{
|
||||||
|
delete Input::input_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
Input *Input::get()
|
||||||
|
{
|
||||||
|
return Input::input_;
|
||||||
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Input::Input(std::string file)
|
Input::Input(const std::string &game_controller_db_path)
|
||||||
|
: db_path_(game_controller_db_path)
|
||||||
{
|
{
|
||||||
// Fichero gamecontrollerdb.txt
|
|
||||||
dbPath = file;
|
|
||||||
|
|
||||||
// Inicializa las variables
|
// Inicializa las variables
|
||||||
keyBindings_t kb;
|
keyBindings_t kb;
|
||||||
kb.scancode = 0;
|
kb.scancode = 0;
|
||||||
kb.active = false;
|
kb.active = false;
|
||||||
keyBindings.resize(17, kb);
|
key_bindings_.resize(input_number_of_inputs, kb);
|
||||||
|
|
||||||
GameControllerBindings_t gcb;
|
GameControllerBindings_t gcb;
|
||||||
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
gcb.button = SDL_CONTROLLER_BUTTON_INVALID;
|
||||||
gcb.active = false;
|
gcb.active = false;
|
||||||
gameControllerBindings.resize(17, gcb);
|
game_controller_bindings_.resize(input_number_of_inputs, gcb);
|
||||||
|
|
||||||
verbose = true;
|
|
||||||
enabled = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el estado del objeto
|
// Actualiza el estado del objeto
|
||||||
void Input::update()
|
void Input::update()
|
||||||
{
|
{
|
||||||
if (disabledUntil == d_keyPressed && !checkAnyInput())
|
if (disabled_until_ == d_keyPressed && !checkAnyInput())
|
||||||
{
|
{
|
||||||
enable();
|
enable();
|
||||||
}
|
}
|
||||||
@@ -34,19 +55,19 @@ void Input::update()
|
|||||||
// Asigna inputs a teclas
|
// Asigna inputs a teclas
|
||||||
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
void Input::bindKey(Uint8 input, SDL_Scancode code)
|
||||||
{
|
{
|
||||||
keyBindings[input].scancode = code;
|
key_bindings_[input].scancode = code;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asigna inputs a botones del mando
|
// Asigna inputs a botones del mando
|
||||||
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
void Input::bindGameControllerButton(Uint8 input, SDL_GameControllerButton button)
|
||||||
{
|
{
|
||||||
gameControllerBindings[input].button = button;
|
game_controller_bindings_[input].button = button;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba si un input esta activo
|
// Comprueba si un input esta activo
|
||||||
bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
||||||
{
|
{
|
||||||
if (!enabled)
|
if (!enabled_)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -65,7 +86,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
|
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (keyStates[keyBindings[input].scancode] != 0)
|
if (keyStates[key_bindings_[input].scancode] != 0)
|
||||||
{
|
{
|
||||||
successKeyboard = true;
|
successKeyboard = true;
|
||||||
}
|
}
|
||||||
@@ -76,11 +97,11 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!keyBindings[input].active)
|
if (!key_bindings_[input].active)
|
||||||
{
|
{
|
||||||
if (keyStates[keyBindings[input].scancode] != 0)
|
if (keyStates[key_bindings_[input].scancode] != 0)
|
||||||
{
|
{
|
||||||
keyBindings[input].active = true;
|
key_bindings_[input].active = true;
|
||||||
successKeyboard = true;
|
successKeyboard = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -90,9 +111,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (keyStates[keyBindings[input].scancode] == 0)
|
if (keyStates[key_bindings_[input].scancode] == 0)
|
||||||
{
|
{
|
||||||
keyBindings[input].active = false;
|
key_bindings_[input].active = false;
|
||||||
successKeyboard = false;
|
successKeyboard = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -108,7 +129,7 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
{
|
{
|
||||||
if (repeat)
|
if (repeat)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
if (SDL_GameControllerGetButton(connected_controllers_[index], game_controller_bindings_[input].button) != 0)
|
||||||
{
|
{
|
||||||
successGameController = true;
|
successGameController = true;
|
||||||
}
|
}
|
||||||
@@ -119,11 +140,11 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (!gameControllerBindings[input].active)
|
if (!game_controller_bindings_[input].active)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) != 0)
|
if (SDL_GameControllerGetButton(connected_controllers_[index], game_controller_bindings_[input].button) != 0)
|
||||||
{
|
{
|
||||||
gameControllerBindings[input].active = true;
|
game_controller_bindings_[input].active = true;
|
||||||
successGameController = true;
|
successGameController = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -133,9 +154,9 @@ bool Input::checkInput(Uint8 input, bool repeat, int device, int index)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[input].button) == 0)
|
if (SDL_GameControllerGetButton(connected_controllers_[index], game_controller_bindings_[input].button) == 0)
|
||||||
{
|
{
|
||||||
gameControllerBindings[input].active = false;
|
game_controller_bindings_[input].active = false;
|
||||||
successGameController = false;
|
successGameController = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -161,9 +182,9 @@ bool Input::checkAnyInput(int device, int index)
|
|||||||
{
|
{
|
||||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||||
|
|
||||||
for (int i = 0; i < (int)keyBindings.size(); ++i)
|
for (int i = 0; i < (int)key_bindings_.size(); ++i)
|
||||||
{
|
{
|
||||||
if (mKeystates[keyBindings[i].scancode] != 0)
|
if (mKeystates[key_bindings_[i].scancode] != 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -174,9 +195,9 @@ bool Input::checkAnyInput(int device, int index)
|
|||||||
{
|
{
|
||||||
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
if (device == INPUT_USE_GAMECONTROLLER || device == INPUT_USE_ANY)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int)gameControllerBindings.size(); ++i)
|
for (int i = 0; i < (int)game_controller_bindings_.size(); ++i)
|
||||||
{
|
{
|
||||||
if (SDL_GameControllerGetButton(connectedControllers[index], gameControllerBindings[i].button) != 0)
|
if (SDL_GameControllerGetButton(connected_controllers_[index], game_controller_bindings_[i].button) != 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -197,56 +218,56 @@ bool Input::discoverGameController()
|
|||||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SDL_GameControllerAddMappingsFromFile(dbPath.c_str()) < 0)
|
if (SDL_GameControllerAddMappingsFromFile(db_path_.c_str()) < 0)
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
std::cout << "Error, could not load " << dbPath.c_str() << " file: " << SDL_GetError() << std::endl;
|
std::cout << "Error, could not load " << db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const int nJoysticks = SDL_NumJoysticks();
|
const int nJoysticks = SDL_NumJoysticks();
|
||||||
numGamepads = 0;
|
num_gamepads_ = 0;
|
||||||
|
|
||||||
// Cuenta el numero de mandos
|
// Cuenta el numero de mandos
|
||||||
for (int i = 0; i < nJoysticks; ++i)
|
for (int i = 0; i < nJoysticks; ++i)
|
||||||
{
|
{
|
||||||
if (SDL_IsGameController(i))
|
if (SDL_IsGameController(i))
|
||||||
{
|
{
|
||||||
numGamepads++;
|
num_gamepads_++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
std::cout << "\nChecking for game controllers...\n";
|
std::cout << "\nChecking for game controllers...\n";
|
||||||
std::cout << nJoysticks << " joysticks found, " << numGamepads << " are gamepads\n";
|
std::cout << nJoysticks << " joysticks found, " << num_gamepads_ << " are gamepads\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numGamepads > 0)
|
if (num_gamepads_ > 0)
|
||||||
{
|
{
|
||||||
found = true;
|
found = true;
|
||||||
|
|
||||||
for (int i = 0; i < numGamepads; i++)
|
for (int i = 0; i < num_gamepads_; i++)
|
||||||
{
|
{
|
||||||
// Abre el mando y lo añade a la lista
|
// Abre el mando y lo añade a la lista
|
||||||
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
SDL_GameController *pad = SDL_GameControllerOpen(i);
|
||||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||||
{
|
{
|
||||||
connectedControllers.push_back(pad);
|
connected_controllers_.push_back(pad);
|
||||||
const std::string separator(" #");
|
const std::string separator(" #");
|
||||||
std::string name = SDL_GameControllerNameForIndex(i);
|
std::string name = SDL_GameControllerNameForIndex(i);
|
||||||
name.resize(25);
|
name.resize(25);
|
||||||
name = name + separator + std::to_string(i);
|
name = name + separator + std::to_string(i);
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
std::cout << name << std::endl;
|
std::cout << name << std::endl;
|
||||||
}
|
}
|
||||||
controllerNames.push_back(name);
|
controller_names_.push_back(name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (verbose)
|
if (verbose_)
|
||||||
{
|
{
|
||||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
@@ -262,7 +283,7 @@ bool Input::discoverGameController()
|
|||||||
// Comprueba si hay algun mando conectado
|
// Comprueba si hay algun mando conectado
|
||||||
bool Input::gameControllerFound()
|
bool Input::gameControllerFound()
|
||||||
{
|
{
|
||||||
if (numGamepads > 0)
|
if (num_gamepads_ > 0)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -275,9 +296,9 @@ bool Input::gameControllerFound()
|
|||||||
// Obten el nombre de un mando de juego
|
// Obten el nombre de un mando de juego
|
||||||
std::string Input::getControllerName(int index)
|
std::string Input::getControllerName(int index)
|
||||||
{
|
{
|
||||||
if (numGamepads > 0)
|
if (num_gamepads_ > 0)
|
||||||
{
|
{
|
||||||
return controllerNames[index];
|
return controller_names_[index];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -288,25 +309,25 @@ std::string Input::getControllerName(int index)
|
|||||||
// Obten el numero de mandos conectados
|
// Obten el numero de mandos conectados
|
||||||
int Input::getNumControllers()
|
int Input::getNumControllers()
|
||||||
{
|
{
|
||||||
return numGamepads;
|
return num_gamepads_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece si ha de mostrar mensajes
|
// Establece si ha de mostrar mensajes
|
||||||
void Input::setVerbose(bool value)
|
void Input::setVerbose(bool value)
|
||||||
{
|
{
|
||||||
verbose = value;
|
verbose_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deshabilita las entradas durante un periodo de tiempo
|
// Deshabilita las entradas durante un periodo de tiempo
|
||||||
void Input::disableUntil(i_disable_e value)
|
void Input::disableUntil(i_disable_e value)
|
||||||
{
|
{
|
||||||
disabledUntil = value;
|
disabled_until_ = value;
|
||||||
enabled = false;
|
enabled_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hablita las entradas
|
// Hablita las entradas
|
||||||
void Input::enable()
|
void Input::enable()
|
||||||
{
|
{
|
||||||
enabled = true;
|
enabled_ = true;
|
||||||
disabledUntil = d_notDisabled;
|
disabled_until_ = d_notDisabled;
|
||||||
}
|
}
|
||||||
134
source/input.h
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_gamecontroller.h> // Para SDL_GameControllerButton, SDL_G...
|
||||||
|
#include <SDL2/SDL_scancode.h> // Para SDL_Scancode
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para Uint8
|
||||||
|
#include <string> // Para string, basic_string
|
||||||
|
#include <vector> // Para vector
|
||||||
|
|
||||||
|
// Definiciones de repetición
|
||||||
|
constexpr bool REPEAT_TRUE = true;
|
||||||
|
constexpr bool REPEAT_FALSE = false;
|
||||||
|
|
||||||
|
// Tipos de entrada
|
||||||
|
constexpr int INPUT_USE_KEYBOARD = 0;
|
||||||
|
constexpr int INPUT_USE_GAMECONTROLLER = 1;
|
||||||
|
constexpr int INPUT_USE_ANY = 2;
|
||||||
|
|
||||||
|
enum inputs_e
|
||||||
|
{
|
||||||
|
// Inputs obligatorios
|
||||||
|
input_null,
|
||||||
|
input_up,
|
||||||
|
input_down,
|
||||||
|
input_left,
|
||||||
|
input_right,
|
||||||
|
input_pause,
|
||||||
|
input_exit,
|
||||||
|
input_accept,
|
||||||
|
input_cancel,
|
||||||
|
|
||||||
|
// Inputs personalizados
|
||||||
|
input_jump,
|
||||||
|
input_window_inc_size,
|
||||||
|
input_window_dec_size,
|
||||||
|
input_toggle_videomode,
|
||||||
|
input_toggle_border,
|
||||||
|
input_toggle_music,
|
||||||
|
input_toggle_palette,
|
||||||
|
input_toggle_shaders,
|
||||||
|
|
||||||
|
// Input obligatorio
|
||||||
|
input_number_of_inputs
|
||||||
|
};
|
||||||
|
|
||||||
|
enum i_disable_e
|
||||||
|
{
|
||||||
|
d_notDisabled,
|
||||||
|
d_forever,
|
||||||
|
d_keyPressed
|
||||||
|
};
|
||||||
|
|
||||||
|
class Input
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto privado
|
||||||
|
static Input *input_;
|
||||||
|
|
||||||
|
struct keyBindings_t
|
||||||
|
{
|
||||||
|
Uint8 scancode; // Scancode asociado
|
||||||
|
bool active; // Indica si está activo
|
||||||
|
};
|
||||||
|
|
||||||
|
struct GameControllerBindings_t
|
||||||
|
{
|
||||||
|
SDL_GameControllerButton button; // GameControllerButton asociado
|
||||||
|
bool active; // Indica si está activo
|
||||||
|
};
|
||||||
|
|
||||||
|
// Objetos y punteros
|
||||||
|
std::vector<SDL_GameController *> connected_controllers_; // Vector con todos los mandos conectados
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
std::vector<keyBindings_t> key_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
|
std::vector<GameControllerBindings_t> game_controller_bindings_; // Vector con las teclas asociadas a los inputs predefinidos
|
||||||
|
std::vector<std::string> controller_names_; // Vector con los nombres de los mandos
|
||||||
|
int num_gamepads_; // Numero de mandos conectados
|
||||||
|
std::string db_path_; // Ruta al archivo gamecontrollerdb.txt
|
||||||
|
bool verbose_ = true; // Indica si ha de mostrar mensajes
|
||||||
|
i_disable_e disabled_until_; // Tiempo que esta deshabilitado
|
||||||
|
bool enabled_ = true; // Indica si está habilitado
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
explicit Input(const std::string &game_controller_db_path);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Input() = default;
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
static void init(const std::string &game_controller_db_path);
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
static Input *get();
|
||||||
|
|
||||||
|
// Actualiza el estado del objeto
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Asigna inputs a teclas
|
||||||
|
void bindKey(Uint8 input, SDL_Scancode code);
|
||||||
|
|
||||||
|
// Asigna inputs a botones del mando
|
||||||
|
void bindGameControllerButton(Uint8 input, SDL_GameControllerButton button);
|
||||||
|
|
||||||
|
// Comprueba si un input esta activo
|
||||||
|
bool checkInput(Uint8 input, bool repeat = true, int device = INPUT_USE_ANY, int index = 0);
|
||||||
|
|
||||||
|
// Comprueba si hay almenos un input activo
|
||||||
|
bool checkAnyInput(int device = INPUT_USE_ANY, int index = 0);
|
||||||
|
|
||||||
|
// Busca si hay un mando conectado
|
||||||
|
bool discoverGameController();
|
||||||
|
|
||||||
|
// Comprueba si hay algun mando conectado
|
||||||
|
bool gameControllerFound();
|
||||||
|
|
||||||
|
// Obten el numero de mandos conectados
|
||||||
|
int getNumControllers();
|
||||||
|
|
||||||
|
// Obten el nombre de un mando de juego
|
||||||
|
std::string getControllerName(int index);
|
||||||
|
|
||||||
|
// Establece si ha de mostrar mensajes
|
||||||
|
void setVerbose(bool value);
|
||||||
|
|
||||||
|
// Deshabilita las entradas durante un periodo de tiempo
|
||||||
|
void disableUntil(i_disable_e value);
|
||||||
|
|
||||||
|
// Hablita las entradas
|
||||||
|
void enable();
|
||||||
|
};
|
||||||
274
source/intro.cpp
@@ -1,274 +0,0 @@
|
|||||||
#include "intro.h"
|
|
||||||
|
|
||||||
// Constructor
|
|
||||||
Intro::Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
|
|
||||||
{
|
|
||||||
// Copia la dirección de los objetos
|
|
||||||
this->resource = resource;
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
|
||||||
eventHandler = new SDL_Event();
|
|
||||||
if (options->palette == p_zxspectrum)
|
|
||||||
{
|
|
||||||
loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png");
|
|
||||||
loadingScreenTexture2 = resource->getTexture("loading_screen_color.png");
|
|
||||||
}
|
|
||||||
else if (options->palette == p_zxarne)
|
|
||||||
{
|
|
||||||
loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png");
|
|
||||||
loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png");
|
|
||||||
}
|
|
||||||
sprite1 = new Sprite(0, 0, loadingScreenTexture1->getWidth(), loadingScreenTexture1->getHeight(), loadingScreenTexture1, renderer);
|
|
||||||
sprite2 = new Sprite(0, 0, loadingScreenTexture2->getWidth(), loadingScreenTexture2->getHeight(), loadingScreenTexture2, renderer);
|
|
||||||
loadingSound1 = JA_LoadMusic(asset->get("loading_sound1.ogg").c_str());
|
|
||||||
loadingSound2 = JA_LoadMusic(asset->get("loading_sound2.ogg").c_str());
|
|
||||||
loadingSound3 = JA_LoadMusic(asset->get("loading_sound3.ogg").c_str());
|
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
preCounter = 0;
|
|
||||||
counter = 0;
|
|
||||||
section.name = SECTION_PROG_INTRO;
|
|
||||||
section.subsection = 0;
|
|
||||||
ticks = 0;
|
|
||||||
ticksSpeed = 15;
|
|
||||||
loadCounter = 0;
|
|
||||||
loadingFirstPart = true;
|
|
||||||
loadRect = {0, 0, 51, 1};
|
|
||||||
|
|
||||||
// Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum
|
|
||||||
for (int i = 0; i < 192; ++i)
|
|
||||||
{
|
|
||||||
if (i < 64)
|
|
||||||
{ // Primer bloque de 2K
|
|
||||||
lineIndex[i] = ((i % 8) * 8) + (i / 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (i >= 64 && i < 128)
|
|
||||||
{ // Segundo bloque de 2K
|
|
||||||
lineIndex[i] = 64 + ((i % 8) * 8) + ((i - 64) / 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (i >= 128 && i < 192)
|
|
||||||
{ // tercer bloque de 2K
|
|
||||||
lineIndex[i] = 128 + ((i % 8) * 8) + ((i - 128) / 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el color del borde
|
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
Intro::~Intro()
|
|
||||||
{
|
|
||||||
delete sprite1;
|
|
||||||
delete sprite2;
|
|
||||||
delete eventHandler;
|
|
||||||
JA_DeleteMusic(loadingSound1);
|
|
||||||
JA_DeleteMusic(loadingSound2);
|
|
||||||
JA_DeleteMusic(loadingSound3);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
|
||||||
void Intro::checkEventHandler()
|
|
||||||
{
|
|
||||||
// Comprueba los eventos que hay en la cola
|
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
|
||||||
{
|
|
||||||
// Evento de salida de la aplicación
|
|
||||||
if (eventHandler->type == SDL_QUIT)
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_QUIT;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
|
||||||
if ((eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONDOWN))
|
|
||||||
{
|
|
||||||
switch (eventHandler->key.keysym.scancode)
|
|
||||||
{
|
|
||||||
case SDL_SCANCODE_ESCAPE:
|
|
||||||
section.name = SECTION_PROG_QUIT;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
|
||||||
screen->switchBorder();
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F:
|
|
||||||
screen->switchVideoMode();
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
|
||||||
screen->setWindowSize(1);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F2:
|
|
||||||
screen->setWindowSize(2);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F3:
|
|
||||||
screen->setWindowSize(3);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
//switchPalette();
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
section.name = SECTION_PROG_TITLE;
|
|
||||||
section.subsection = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gestiona el contador de carga
|
|
||||||
void Intro::updateLoad()
|
|
||||||
{
|
|
||||||
// Primera parte de la carga, la parte en blanco ynegro
|
|
||||||
if (loadingFirstPart)
|
|
||||||
{
|
|
||||||
// Cada 5 pasos el loadCounter se incrementa en uno
|
|
||||||
const int numSteps = 5;
|
|
||||||
const int step = 51;
|
|
||||||
loadCounter = counter / numSteps;
|
|
||||||
|
|
||||||
if (loadCounter < 192)
|
|
||||||
{
|
|
||||||
loadRect.x = step * (counter % numSteps);
|
|
||||||
loadRect.y = lineIndex[loadCounter];
|
|
||||||
sprite1->setSpriteClip(loadRect);
|
|
||||||
sprite1->setRect(loadRect);
|
|
||||||
}
|
|
||||||
// Una vez actualizadas las 192 lineas, pasa a la segunda fase de la carga
|
|
||||||
else if (loadCounter == 192)
|
|
||||||
{
|
|
||||||
loadingFirstPart = false;
|
|
||||||
loadCounter = 0;
|
|
||||||
loadRect = {0, 0, 16, 8};
|
|
||||||
sprite2->setRect(loadRect);
|
|
||||||
sprite2->setSpriteClip(loadRect);
|
|
||||||
JA_PlayMusic(loadingSound3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Segunda parte de la carga, la parte de los bloques en color
|
|
||||||
else
|
|
||||||
{
|
|
||||||
loadCounter += 2;
|
|
||||||
loadRect.x = (loadCounter * 8) % 256;
|
|
||||||
loadRect.y = (loadCounter / 32) * 8;
|
|
||||||
sprite2->setSpriteClip(loadRect);
|
|
||||||
sprite2->setRect(loadRect);
|
|
||||||
|
|
||||||
// Comprueba si ha terminado la intro
|
|
||||||
if (loadCounter >= 768)
|
|
||||||
{
|
|
||||||
section.name = SECTION_PROG_TITLE;
|
|
||||||
section.subsection = 0;
|
|
||||||
JA_StopMusic();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gestiona el contador interno
|
|
||||||
void Intro::updateCounter()
|
|
||||||
{
|
|
||||||
(preCounter >= 50) ? counter++ : preCounter++;
|
|
||||||
|
|
||||||
if (counter == 1)
|
|
||||||
{
|
|
||||||
JA_PlayMusic(loadingSound2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja la pantalla de carga
|
|
||||||
void Intro::renderLoad()
|
|
||||||
{
|
|
||||||
loadingFirstPart ? sprite1->render() : sprite2->render();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void Intro::update()
|
|
||||||
{
|
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
|
||||||
{
|
|
||||||
// Actualiza el contador de ticks
|
|
||||||
ticks = SDL_GetTicks();
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
|
||||||
checkEventHandler();
|
|
||||||
|
|
||||||
// Gestiona el contador interno
|
|
||||||
updateCounter();
|
|
||||||
|
|
||||||
// Gestiona el contador de carga
|
|
||||||
updateLoad();
|
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
|
||||||
screen->updateNotifier();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dibuja en pantalla
|
|
||||||
void Intro::render()
|
|
||||||
{
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// Dibuja la pantalla de carga
|
|
||||||
renderLoad();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bucle para el logo del juego
|
|
||||||
section_t Intro::run()
|
|
||||||
{
|
|
||||||
// Inicia el sonido de carga
|
|
||||||
JA_SetVolume(64);
|
|
||||||
JA_PlayMusic(loadingSound1);
|
|
||||||
|
|
||||||
while (section.name == SECTION_PROG_INTRO)
|
|
||||||
{
|
|
||||||
update();
|
|
||||||
render();
|
|
||||||
}
|
|
||||||
|
|
||||||
JA_SetVolume(128);
|
|
||||||
return section;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia la paleta
|
|
||||||
void Intro::switchPalette()
|
|
||||||
{
|
|
||||||
if (options->palette == p_zxspectrum)
|
|
||||||
{
|
|
||||||
options->palette = p_zxarne;
|
|
||||||
sprite1->setTexture(resource->getTexture("loading_screen_bn_zxarne.png"));
|
|
||||||
sprite2->setTexture(resource->getTexture("loading_screen_color_zxarne.png"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
options->palette = p_zxspectrum;
|
|
||||||
sprite1->setTexture(resource->getTexture("loading_screen_bn.png"));
|
|
||||||
sprite2->setTexture(resource->getTexture("loading_screen_color.png"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "common/asset.h"
|
|
||||||
#include "common/jail_audio.h"
|
|
||||||
#include "common/resource.h"
|
|
||||||
#include "common/screen.h"
|
|
||||||
#include "common/sprite.h"
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include "const.h"
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "common/text.h"
|
|
||||||
|
|
||||||
#ifndef INTRO_H
|
|
||||||
#define INTRO_H
|
|
||||||
|
|
||||||
class Intro
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
// Objetos y punteros
|
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
Resource *resource; // Objeto con los recursos
|
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
|
||||||
Texture *loadingScreenTexture1; // Textura con la pantalla de carga en blanco y negro
|
|
||||||
Texture *loadingScreenTexture2; // Textura con la pantalla de carga en color
|
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
|
||||||
Sprite *sprite1; // Sprite para manejar la textura loadingScreenTexture1
|
|
||||||
Sprite *sprite2; // Sprite para manejar la textura loadingScreenTexture2
|
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
|
|
||||||
// Variables
|
|
||||||
int preCounter; // Contador previo para realizar una pausa inicial
|
|
||||||
int counter; // Contador
|
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
|
||||||
int loadCounter; // Contador para controlar las cargas
|
|
||||||
bool loadingFirstPart; // Para saber en que parte de la carga se encuentra
|
|
||||||
JA_Music_t* loadingSound1; // Sonidos para imitar la carga tipo spectrum
|
|
||||||
JA_Music_t* loadingSound2; // Sonidos para imitar la carga tipo spectrum
|
|
||||||
JA_Music_t* loadingSound3; // Sonidos para imitar la carga tipo spectrum
|
|
||||||
int lineIndex[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga
|
|
||||||
SDL_Rect loadRect; // Rectangulo para dibujar la pantalla de carga
|
|
||||||
|
|
||||||
// Actualiza las variables
|
|
||||||
void update();
|
|
||||||
|
|
||||||
// Dibuja en pantalla
|
|
||||||
void render();
|
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
|
||||||
void checkEventHandler();
|
|
||||||
|
|
||||||
// Gestiona el contador interno
|
|
||||||
void updateCounter();
|
|
||||||
|
|
||||||
// Gestiona el contador de carga
|
|
||||||
void updateLoad();
|
|
||||||
|
|
||||||
// Dibuja la pantalla de carga
|
|
||||||
void renderLoad();
|
|
||||||
|
|
||||||
// Cambia la paleta
|
|
||||||
void switchPalette();
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
Intro(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options);
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~Intro();
|
|
||||||
|
|
||||||
// Bucle principal
|
|
||||||
section_t run();
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "item.h"
|
#include "item.h"
|
||||||
#include <fstream>
|
#include "sprite.h" // Para Sprite
|
||||||
#include <sstream>
|
#include "texture.h" // Para Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Item::Item(item_t item)
|
Item::Item(item_t item)
|
||||||
|
|||||||
@@ -1,25 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
#include "common/sprite.h"
|
#include <string> // Para basic_string, string
|
||||||
#include "common/utils.h"
|
#include <vector> // Para vector
|
||||||
#include <string>
|
#include "utils.h" // Para color_t
|
||||||
|
class Sprite;
|
||||||
#ifndef ITEM_H
|
class Texture;
|
||||||
#define ITEM_H
|
|
||||||
|
|
||||||
struct item_t
|
struct item_t
|
||||||
{
|
{
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
Texture *texture; // Textura con los graficos del item
|
Texture *texture; // Textura con los gráficos del item
|
||||||
std::string tileSetFile; // Ruta al fichero con los graficos del item
|
std::string tileSetFile; // Ruta al fichero con los gráficos del item
|
||||||
int x; // Posicion del item en pantalla
|
int x; // Posición del item en pantalla
|
||||||
int y; // Posicion del item en pantalla
|
int y; // Posición del item en pantalla
|
||||||
int tile; // Numero de tile dentro de la textura
|
int tile; // Número de tile dentro de la textura
|
||||||
int counter; // Contador inicial. Es el que lo hace cambiar de color
|
int counter; // Contador inicial. Es el que lo hace cambiar de color
|
||||||
color_t color1; // Uno de los dos colores que se utiliza para el item
|
color_t color1; // Uno de los dos colores que se utiliza para el item
|
||||||
color_t color2; // Uno de los dos colores que se utiliza para el item
|
color_t color2; // Uno de los dos colores que se utiliza para el item
|
||||||
|
|
||||||
|
// Constructor por defecto
|
||||||
|
item_t() : renderer(nullptr), texture(nullptr), x(0), y(0), tile(0), counter(0), color1(), color2() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
@@ -59,5 +61,3 @@ public:
|
|||||||
// Asigna los colores del objeto
|
// Asigna los colores del objeto
|
||||||
void setColors(color_t col1, color_t col2);
|
void setColors(color_t col1, color_t col2);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <SDL2/SDL.h>
|
|
||||||
#include "common/utils.h"
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef ITEM_TRACKER_H
|
#include <SDL2/SDL_rect.h> // Para SDL_Point
|
||||||
#define ITEM_TRACKER_H
|
#include <string> // Para string, basic_string
|
||||||
|
#include <vector> // Para vector
|
||||||
|
|
||||||
struct item_tracker_t
|
struct item_tracker_t
|
||||||
{
|
{
|
||||||
@@ -35,5 +32,3 @@ public:
|
|||||||
// Añade el objeto a la lista de objetos cogidos
|
// Añade el objeto a la lista de objetos cogidos
|
||||||
void addItem(std::string name, SDL_Point pos);
|
void addItem(std::string name, SDL_Point pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
479
source/jail_audio.cpp
Normal file
@@ -0,0 +1,479 @@
|
|||||||
|
#include "jail_audio.h"
|
||||||
|
#include <SDL2/SDL_rwops.h> // for SDL_RWFromMem
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <stdint.h> // for uint8_t, uint32_t
|
||||||
|
#include <stdio.h> // for NULL, fseek, fclose, fopen, fread, ftell
|
||||||
|
#include <stdlib.h> // for free, malloc
|
||||||
|
#include "stb_vorbis.c" // for stb_vorbis_decode_memory
|
||||||
|
|
||||||
|
constexpr int JA_MAX_SIMULTANEOUS_CHANNELS = 20;
|
||||||
|
|
||||||
|
struct JA_Sound_t
|
||||||
|
{
|
||||||
|
Uint32 length{0};
|
||||||
|
Uint8 *buffer{NULL};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JA_Channel_t
|
||||||
|
{
|
||||||
|
JA_Sound_t *sound;
|
||||||
|
int pos{0};
|
||||||
|
int times{0};
|
||||||
|
JA_Channel_state state{JA_CHANNEL_FREE};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JA_Music_t
|
||||||
|
{
|
||||||
|
int samples{0};
|
||||||
|
Uint32 length{0};
|
||||||
|
int pos{0};
|
||||||
|
int times{0};
|
||||||
|
short *output{NULL};
|
||||||
|
JA_Music_state state{JA_MUSIC_INVALID};
|
||||||
|
};
|
||||||
|
|
||||||
|
JA_Music_t *current_music{NULL};
|
||||||
|
JA_Channel_t channels[JA_MAX_SIMULTANEOUS_CHANNELS];
|
||||||
|
|
||||||
|
int JA_freq{48000};
|
||||||
|
SDL_AudioFormat JA_format{AUDIO_S16};
|
||||||
|
Uint8 JA_channels{2};
|
||||||
|
int JA_musicVolume = 128;
|
||||||
|
int JA_soundVolume = 64;
|
||||||
|
bool JA_musicEnabled = true;
|
||||||
|
bool JA_soundEnabled = true;
|
||||||
|
SDL_AudioDeviceID sdlAudioDevice = 0;
|
||||||
|
|
||||||
|
bool fading = false;
|
||||||
|
int fade_start_time;
|
||||||
|
int fade_duration;
|
||||||
|
int fade_initial_volume;
|
||||||
|
|
||||||
|
void audioCallback(void *userdata, uint8_t *stream, int len)
|
||||||
|
{
|
||||||
|
SDL_memset(stream, 0, len);
|
||||||
|
if (current_music != NULL && current_music->state == JA_MUSIC_PLAYING)
|
||||||
|
{
|
||||||
|
int volume = JA_musicVolume;
|
||||||
|
if (fading)
|
||||||
|
{
|
||||||
|
int time = SDL_GetTicks();
|
||||||
|
if (time > (fade_start_time + fade_duration))
|
||||||
|
{
|
||||||
|
fading = false;
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
volume = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
const int time_passed = time - fade_start_time;
|
||||||
|
const float percent = (float)time_passed / (float)fade_duration;
|
||||||
|
volume = JA_musicVolume * (1.0 - percent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const int size = SDL_min(len, current_music->length - current_music->pos);
|
||||||
|
SDL_MixAudioFormat(stream, (Uint8 *)(current_music->output) + current_music->pos, AUDIO_S16, size, volume);
|
||||||
|
current_music->pos += size;
|
||||||
|
if (size < len)
|
||||||
|
{
|
||||||
|
if (current_music->times != 0)
|
||||||
|
{
|
||||||
|
SDL_MixAudioFormat(stream + size, (Uint8 *)current_music->output, AUDIO_S16, len - size, volume);
|
||||||
|
current_music->pos = len - size;
|
||||||
|
if (current_music->times > 0)
|
||||||
|
current_music->times--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Mixar els channels mi amol
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
|
||||||
|
{
|
||||||
|
if (channels[i].state == JA_CHANNEL_PLAYING)
|
||||||
|
{
|
||||||
|
const int size = SDL_min(len, channels[i].sound->length - channels[i].pos);
|
||||||
|
SDL_MixAudioFormat(stream, channels[i].sound->buffer + channels[i].pos, AUDIO_S16, size, JA_soundVolume);
|
||||||
|
channels[i].pos += size;
|
||||||
|
if (size < len)
|
||||||
|
{
|
||||||
|
if (channels[i].times != 0)
|
||||||
|
{
|
||||||
|
SDL_MixAudioFormat(stream + size, channels[i].sound->buffer, AUDIO_S16, len - size, JA_soundVolume);
|
||||||
|
channels[i].pos = len - size;
|
||||||
|
if (channels[i].times > 0)
|
||||||
|
channels[i].times--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
JA_StopChannel(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels)
|
||||||
|
{
|
||||||
|
JA_freq = freq;
|
||||||
|
JA_format = format;
|
||||||
|
JA_channels = channels;
|
||||||
|
SDL_AudioSpec audioSpec{JA_freq, JA_format, JA_channels, 0, 1024, 0, 0, audioCallback, NULL};
|
||||||
|
if (sdlAudioDevice != 0)
|
||||||
|
SDL_CloseAudioDevice(sdlAudioDevice);
|
||||||
|
sdlAudioDevice = SDL_OpenAudioDevice(NULL, 0, &audioSpec, NULL, 0);
|
||||||
|
SDL_PauseAudioDevice(sdlAudioDevice, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_Quit()
|
||||||
|
{
|
||||||
|
SDL_PauseAudioDevice(sdlAudioDevice, 1);
|
||||||
|
if (sdlAudioDevice != 0)
|
||||||
|
SDL_CloseAudioDevice(sdlAudioDevice);
|
||||||
|
sdlAudioDevice = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Music_t *JA_LoadMusic(Uint8 *buffer, Uint32 length)
|
||||||
|
{
|
||||||
|
int chan, samplerate;
|
||||||
|
JA_Music_t *music = new JA_Music_t();
|
||||||
|
|
||||||
|
music->samples = stb_vorbis_decode_memory(buffer, length, &chan, &samplerate, &music->output);
|
||||||
|
|
||||||
|
SDL_AudioCVT cvt;
|
||||||
|
SDL_BuildAudioCVT(&cvt, AUDIO_S16, chan, samplerate, JA_format, JA_channels, JA_freq);
|
||||||
|
if (cvt.needed)
|
||||||
|
{
|
||||||
|
cvt.len = music->samples * chan * 2;
|
||||||
|
music->length = cvt.len;
|
||||||
|
cvt.buf = (Uint8 *)SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
|
SDL_memcpy(cvt.buf, music->output, cvt.len);
|
||||||
|
SDL_ConvertAudio(&cvt);
|
||||||
|
free(music->output);
|
||||||
|
music->output = (short *)cvt.buf;
|
||||||
|
}
|
||||||
|
music->length = music->samples * chan * 2;
|
||||||
|
music->pos = 0;
|
||||||
|
music->state = JA_MUSIC_STOPPED;
|
||||||
|
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Music_t *JA_LoadMusic(const char *filename)
|
||||||
|
{
|
||||||
|
// [RZC 28/08/22] Carreguem primer el arxiu en memòria i després el descomprimim. Es algo més rapid.
|
||||||
|
FILE *f = fopen(filename, "rb");
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
long fsize = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
Uint8 *buffer = (Uint8 *)malloc(fsize + 1);
|
||||||
|
if (fread(buffer, fsize, 1, f) != 1)
|
||||||
|
return NULL;
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
JA_Music_t *music = JA_LoadMusic(buffer, fsize);
|
||||||
|
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
|
return music;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_PlayMusic(JA_Music_t *music, const int loop)
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (current_music != NULL)
|
||||||
|
{
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
}
|
||||||
|
current_music = music;
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_PLAYING;
|
||||||
|
current_music->times = loop;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_PauseMusic()
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID)
|
||||||
|
return;
|
||||||
|
current_music->state = JA_MUSIC_PAUSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_ResumeMusic()
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID)
|
||||||
|
return;
|
||||||
|
current_music->state = JA_MUSIC_PLAYING;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_StopMusic()
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID)
|
||||||
|
return;
|
||||||
|
current_music->pos = 0;
|
||||||
|
current_music->state = JA_MUSIC_STOPPED;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_FadeOutMusic(const int milliseconds)
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled)
|
||||||
|
return;
|
||||||
|
if (current_music == NULL || current_music->state == JA_MUSIC_INVALID)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fading = true;
|
||||||
|
fade_start_time = SDL_GetTicks();
|
||||||
|
fade_duration = milliseconds;
|
||||||
|
fade_initial_volume = JA_musicVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Music_state JA_GetMusicState()
|
||||||
|
{
|
||||||
|
if (!JA_musicEnabled)
|
||||||
|
return JA_MUSIC_DISABLED;
|
||||||
|
|
||||||
|
if (current_music == NULL)
|
||||||
|
return JA_MUSIC_INVALID;
|
||||||
|
return current_music->state;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_DeleteMusic(JA_Music_t *music)
|
||||||
|
{
|
||||||
|
if (current_music == music)
|
||||||
|
current_music = NULL;
|
||||||
|
free(music->output);
|
||||||
|
delete music;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JA_SetMusicVolume(int volume)
|
||||||
|
{
|
||||||
|
JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0
|
||||||
|
: volume;
|
||||||
|
return JA_musicVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_SetMusicPosition(float value)
|
||||||
|
{
|
||||||
|
if (!current_music)
|
||||||
|
return;
|
||||||
|
current_music->pos = value * JA_freq;
|
||||||
|
}
|
||||||
|
|
||||||
|
float JA_GetMusicPosition()
|
||||||
|
{
|
||||||
|
if (!current_music)
|
||||||
|
return 0;
|
||||||
|
return float(current_music->pos) / float(JA_freq);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_EnableMusic(const bool value)
|
||||||
|
{
|
||||||
|
if (!value && current_music != NULL && current_music->state == JA_MUSIC_PLAYING)
|
||||||
|
JA_StopMusic();
|
||||||
|
|
||||||
|
JA_musicEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Sound_t *JA_NewSound(Uint8 *buffer, Uint32 length)
|
||||||
|
{
|
||||||
|
JA_Sound_t *sound = new JA_Sound_t();
|
||||||
|
sound->buffer = buffer;
|
||||||
|
sound->length = length;
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Sound_t *JA_LoadSound(uint8_t *buffer, uint32_t size)
|
||||||
|
{
|
||||||
|
JA_Sound_t *sound = new JA_Sound_t();
|
||||||
|
SDL_AudioSpec wavSpec;
|
||||||
|
SDL_LoadWAV_RW(SDL_RWFromMem(buffer, size), 1, &wavSpec, &sound->buffer, &sound->length);
|
||||||
|
|
||||||
|
SDL_AudioCVT cvt;
|
||||||
|
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
||||||
|
cvt.len = sound->length;
|
||||||
|
cvt.buf = (Uint8 *)SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
|
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
|
||||||
|
SDL_ConvertAudio(&cvt);
|
||||||
|
SDL_FreeWAV(sound->buffer);
|
||||||
|
sound->buffer = cvt.buf;
|
||||||
|
sound->length = cvt.len_cvt;
|
||||||
|
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Sound_t *JA_LoadSound(const char *filename)
|
||||||
|
{
|
||||||
|
JA_Sound_t *sound = new JA_Sound_t();
|
||||||
|
SDL_AudioSpec wavSpec;
|
||||||
|
SDL_LoadWAV(filename, &wavSpec, &sound->buffer, &sound->length);
|
||||||
|
|
||||||
|
SDL_AudioCVT cvt;
|
||||||
|
SDL_BuildAudioCVT(&cvt, wavSpec.format, wavSpec.channels, wavSpec.freq, JA_format, JA_channels, JA_freq);
|
||||||
|
cvt.len = sound->length;
|
||||||
|
cvt.buf = (Uint8 *)SDL_malloc(cvt.len * cvt.len_mult);
|
||||||
|
SDL_memcpy(cvt.buf, sound->buffer, sound->length);
|
||||||
|
SDL_ConvertAudio(&cvt);
|
||||||
|
SDL_FreeWAV(sound->buffer);
|
||||||
|
sound->buffer = cvt.buf;
|
||||||
|
sound->length = cvt.len_cvt;
|
||||||
|
|
||||||
|
return sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JA_PlaySound(JA_Sound_t *sound, const int loop)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
int channel = 0;
|
||||||
|
while (channel < JA_MAX_SIMULTANEOUS_CHANNELS && channels[channel].state != JA_CHANNEL_FREE)
|
||||||
|
{
|
||||||
|
channel++;
|
||||||
|
}
|
||||||
|
if (channel == JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
|
channel = 0;
|
||||||
|
|
||||||
|
channels[channel].sound = sound;
|
||||||
|
channels[channel].times = loop;
|
||||||
|
channels[channel].pos = 0;
|
||||||
|
channels[channel].state = JA_CHANNEL_PLAYING;
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (channel >= JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
channels[channel].sound = sound;
|
||||||
|
channels[channel].times = loop;
|
||||||
|
channels[channel].pos = 0;
|
||||||
|
channels[channel].state = JA_CHANNEL_PLAYING;
|
||||||
|
return channel;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_DeleteSound(JA_Sound_t *sound)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
|
||||||
|
{
|
||||||
|
if (channels[i].sound == sound)
|
||||||
|
JA_StopChannel(i);
|
||||||
|
}
|
||||||
|
SDL_free(sound->buffer);
|
||||||
|
delete sound;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_PauseChannel(const int channel)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (channel == -1)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
|
||||||
|
{
|
||||||
|
if (channels[i].state == JA_CHANNEL_PLAYING)
|
||||||
|
channels[i].state = JA_CHANNEL_PAUSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
|
{
|
||||||
|
if (channels[channel].state == JA_CHANNEL_PLAYING)
|
||||||
|
channels[channel].state = JA_CHANNEL_PAUSED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_ResumeChannel(const int channel)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (channel == -1)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
|
||||||
|
{
|
||||||
|
if (channels[i].state == JA_CHANNEL_PAUSED)
|
||||||
|
channels[i].state = JA_CHANNEL_PLAYING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
|
{
|
||||||
|
if (channels[channel].state == JA_CHANNEL_PAUSED)
|
||||||
|
channels[channel].state = JA_CHANNEL_PLAYING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_StopChannel(const int channel)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (channel == -1)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
|
||||||
|
{
|
||||||
|
channels[i].state = JA_CHANNEL_FREE;
|
||||||
|
channels[i].pos = 0;
|
||||||
|
channels[i].sound = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (channel >= 0 && channel < JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
|
{
|
||||||
|
channels[channel].state = JA_CHANNEL_FREE;
|
||||||
|
channels[channel].pos = 0;
|
||||||
|
channels[channel].sound = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_Channel_state JA_GetChannelState(const int channel)
|
||||||
|
{
|
||||||
|
if (!JA_soundEnabled)
|
||||||
|
return JA_SOUND_DISABLED;
|
||||||
|
|
||||||
|
if (channel < 0 || channel >= JA_MAX_SIMULTANEOUS_CHANNELS)
|
||||||
|
return JA_CHANNEL_INVALID;
|
||||||
|
return channels[channel].state;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JA_SetSoundVolume(int volume)
|
||||||
|
{
|
||||||
|
JA_soundVolume = volume > 128 ? 128 : volume < 0 ? 0
|
||||||
|
: volume;
|
||||||
|
return JA_soundVolume;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JA_EnableSound(const bool value)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < JA_MAX_SIMULTANEOUS_CHANNELS; i++)
|
||||||
|
{
|
||||||
|
if (channels[i].state == JA_CHANNEL_PLAYING)
|
||||||
|
JA_StopChannel(i);
|
||||||
|
}
|
||||||
|
JA_soundEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int JA_SetVolume(int volume)
|
||||||
|
{
|
||||||
|
JA_musicVolume = volume > 128 ? 128 : volume < 0 ? 0
|
||||||
|
: volume;
|
||||||
|
JA_soundVolume = JA_musicVolume / 2;
|
||||||
|
return JA_musicVolume;
|
||||||
|
}
|
||||||
58
source/jail_audio.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_audio.h> // for SDL_AudioFormat
|
||||||
|
#include <SDL2/SDL_stdinc.h> // for Uint32, Uint8
|
||||||
|
struct JA_Music_t; // lines 8-8
|
||||||
|
struct JA_Sound_t; // lines 7-7
|
||||||
|
|
||||||
|
enum JA_Channel_state
|
||||||
|
{
|
||||||
|
JA_CHANNEL_INVALID,
|
||||||
|
JA_CHANNEL_FREE,
|
||||||
|
JA_CHANNEL_PLAYING,
|
||||||
|
JA_CHANNEL_PAUSED,
|
||||||
|
JA_SOUND_DISABLED
|
||||||
|
};
|
||||||
|
enum JA_Music_state
|
||||||
|
{
|
||||||
|
JA_MUSIC_INVALID,
|
||||||
|
JA_MUSIC_PLAYING,
|
||||||
|
JA_MUSIC_PAUSED,
|
||||||
|
JA_MUSIC_STOPPED,
|
||||||
|
JA_MUSIC_DISABLED
|
||||||
|
};
|
||||||
|
|
||||||
|
struct JA_Sound_t;
|
||||||
|
struct JA_Music_t;
|
||||||
|
|
||||||
|
void JA_Init(const int freq, const SDL_AudioFormat format, const int channels);
|
||||||
|
void JA_Quit();
|
||||||
|
|
||||||
|
JA_Music_t *JA_LoadMusic(const char *filename);
|
||||||
|
JA_Music_t *JA_LoadMusic(Uint8 *buffer, Uint32 length);
|
||||||
|
void JA_PlayMusic(JA_Music_t *music, const int loop = -1);
|
||||||
|
void JA_PauseMusic();
|
||||||
|
void JA_ResumeMusic();
|
||||||
|
void JA_StopMusic();
|
||||||
|
void JA_FadeOutMusic(const int milliseconds);
|
||||||
|
JA_Music_state JA_GetMusicState();
|
||||||
|
void JA_DeleteMusic(JA_Music_t *music);
|
||||||
|
int JA_SetMusicVolume(int volume);
|
||||||
|
void JA_SetMusicPosition(float value);
|
||||||
|
float JA_GetMusicPosition();
|
||||||
|
void JA_EnableMusic(const bool value);
|
||||||
|
|
||||||
|
JA_Sound_t *JA_NewSound(Uint8 *buffer, Uint32 length);
|
||||||
|
JA_Sound_t *JA_LoadSound(Uint8 *buffer, Uint32 length);
|
||||||
|
JA_Sound_t *JA_LoadSound(const char *filename);
|
||||||
|
int JA_PlaySound(JA_Sound_t *sound, const int loop = 0);
|
||||||
|
int JA_PlaySoundOnChannel(JA_Sound_t *sound, const int channel, const int loop = 0);
|
||||||
|
void JA_PauseChannel(const int channel);
|
||||||
|
void JA_ResumeChannel(const int channel);
|
||||||
|
void JA_StopChannel(const int channel);
|
||||||
|
JA_Channel_state JA_GetChannelState(const int channel);
|
||||||
|
void JA_DeleteSound(JA_Sound_t *sound);
|
||||||
|
int JA_SetSoundVolume(int volume);
|
||||||
|
void JA_EnableSound(const bool value);
|
||||||
|
|
||||||
|
int JA_SetVolume(int volume);
|
||||||
248
source/jail_shader.cpp
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
#include "jail_shader.h"
|
||||||
|
#include <SDL2/SDL_rect.h> // para SDL_Point
|
||||||
|
#include <stdlib.h> // para NULL, free, malloc, exit
|
||||||
|
#include <string.h> // para strncmp
|
||||||
|
#include <iostream> // para basic_ostream, char_traits, operator<<
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
#include "CoreFoundation/CoreFoundation.h"
|
||||||
|
#include <OpenGL/OpenGL.h>
|
||||||
|
|
||||||
|
#if ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||||
|
#include <OpenGL/gl3.h>
|
||||||
|
#else
|
||||||
|
#include <OpenGL/gl.h>
|
||||||
|
#endif //! ESSENTIAL_GL_PRACTICES_SUPPORT_GL3
|
||||||
|
#else
|
||||||
|
#include <SDL2/SDL_opengl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace shader
|
||||||
|
{
|
||||||
|
SDL_Window *win = nullptr;
|
||||||
|
SDL_Renderer *renderer = nullptr;
|
||||||
|
GLuint programId = 0;
|
||||||
|
SDL_Texture *backBuffer = nullptr;
|
||||||
|
SDL_Point win_size = {320 * 4, 256 * 4};
|
||||||
|
SDL_Point tex_size = {320, 256};
|
||||||
|
bool usingOpenGL;
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
|
||||||
|
// I'm avoiding the use of GLEW or some extensions handler, but that
|
||||||
|
// doesn't mean you should...
|
||||||
|
PFNGLCREATESHADERPROC glCreateShader;
|
||||||
|
PFNGLSHADERSOURCEPROC glShaderSource;
|
||||||
|
PFNGLCOMPILESHADERPROC glCompileShader;
|
||||||
|
PFNGLGETSHADERIVPROC glGetShaderiv;
|
||||||
|
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
|
||||||
|
PFNGLDELETESHADERPROC glDeleteShader;
|
||||||
|
PFNGLATTACHSHADERPROC glAttachShader;
|
||||||
|
PFNGLCREATEPROGRAMPROC glCreateProgram;
|
||||||
|
PFNGLLINKPROGRAMPROC glLinkProgram;
|
||||||
|
PFNGLVALIDATEPROGRAMPROC glValidateProgram;
|
||||||
|
PFNGLGETPROGRAMIVPROC glGetProgramiv;
|
||||||
|
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
|
||||||
|
PFNGLUSEPROGRAMPROC glUseProgram;
|
||||||
|
|
||||||
|
bool initGLExtensions()
|
||||||
|
{
|
||||||
|
glCreateShader = (PFNGLCREATESHADERPROC)SDL_GL_GetProcAddress("glCreateShader");
|
||||||
|
glShaderSource = (PFNGLSHADERSOURCEPROC)SDL_GL_GetProcAddress("glShaderSource");
|
||||||
|
glCompileShader = (PFNGLCOMPILESHADERPROC)SDL_GL_GetProcAddress("glCompileShader");
|
||||||
|
glGetShaderiv = (PFNGLGETSHADERIVPROC)SDL_GL_GetProcAddress("glGetShaderiv");
|
||||||
|
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)SDL_GL_GetProcAddress("glGetShaderInfoLog");
|
||||||
|
glDeleteShader = (PFNGLDELETESHADERPROC)SDL_GL_GetProcAddress("glDeleteShader");
|
||||||
|
glAttachShader = (PFNGLATTACHSHADERPROC)SDL_GL_GetProcAddress("glAttachShader");
|
||||||
|
glCreateProgram = (PFNGLCREATEPROGRAMPROC)SDL_GL_GetProcAddress("glCreateProgram");
|
||||||
|
glLinkProgram = (PFNGLLINKPROGRAMPROC)SDL_GL_GetProcAddress("glLinkProgram");
|
||||||
|
glValidateProgram = (PFNGLVALIDATEPROGRAMPROC)SDL_GL_GetProcAddress("glValidateProgram");
|
||||||
|
glGetProgramiv = (PFNGLGETPROGRAMIVPROC)SDL_GL_GetProcAddress("glGetProgramiv");
|
||||||
|
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)SDL_GL_GetProcAddress("glGetProgramInfoLog");
|
||||||
|
glUseProgram = (PFNGLUSEPROGRAMPROC)SDL_GL_GetProcAddress("glUseProgram");
|
||||||
|
|
||||||
|
return glCreateShader && glShaderSource && glCompileShader && glGetShaderiv &&
|
||||||
|
glGetShaderInfoLog && glDeleteShader && glAttachShader && glCreateProgram &&
|
||||||
|
glLinkProgram && glValidateProgram && glGetProgramiv && glGetProgramInfoLog &&
|
||||||
|
glUseProgram;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
GLuint compileShader(const char *source, GLuint shaderType)
|
||||||
|
{
|
||||||
|
// Create ID for shader
|
||||||
|
GLuint result = glCreateShader(shaderType);
|
||||||
|
// Add define depending on shader type
|
||||||
|
const char *sources[2] = {shaderType == GL_VERTEX_SHADER ? "#define VERTEX\n" : "#define FRAGMENT\n", source};
|
||||||
|
// Define shader text
|
||||||
|
glShaderSource(result, 2, sources, NULL);
|
||||||
|
// Compile shader
|
||||||
|
glCompileShader(result);
|
||||||
|
|
||||||
|
// Check vertex shader for errors
|
||||||
|
GLint shaderCompiled = GL_FALSE;
|
||||||
|
glGetShaderiv(result, GL_COMPILE_STATUS, &shaderCompiled);
|
||||||
|
if (shaderCompiled != GL_TRUE)
|
||||||
|
{
|
||||||
|
std::cout << "Error en la compilación: " << result << "!" << std::endl;
|
||||||
|
GLint logLength;
|
||||||
|
glGetShaderiv(result, GL_INFO_LOG_LENGTH, &logLength);
|
||||||
|
if (logLength > 0)
|
||||||
|
{
|
||||||
|
GLchar *log = (GLchar *)malloc(logLength);
|
||||||
|
glGetShaderInfoLog(result, logLength, &logLength, log);
|
||||||
|
std::cout << "Shader compile log:" << log << std::endl;
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
glDeleteShader(result);
|
||||||
|
result = 0;
|
||||||
|
// } else {
|
||||||
|
// std::cout << "Shader compilado correctamente. Id = " << result << std::endl;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint compileProgram(const char *vertexShaderSource, const char *fragmentShaderSource)
|
||||||
|
{
|
||||||
|
GLuint programId = 0;
|
||||||
|
GLuint vtxShaderId, fragShaderId;
|
||||||
|
|
||||||
|
programId = glCreateProgram();
|
||||||
|
|
||||||
|
vtxShaderId = compileShader(vertexShaderSource, GL_VERTEX_SHADER);
|
||||||
|
fragShaderId = compileShader(fragmentShaderSource ? fragmentShaderSource : vertexShaderSource, GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
if (vtxShaderId && fragShaderId)
|
||||||
|
{
|
||||||
|
// Associate shader with program
|
||||||
|
glAttachShader(programId, vtxShaderId);
|
||||||
|
glAttachShader(programId, fragShaderId);
|
||||||
|
glLinkProgram(programId);
|
||||||
|
glValidateProgram(programId);
|
||||||
|
|
||||||
|
// Check the status of the compile/link
|
||||||
|
GLint logLen;
|
||||||
|
glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &logLen);
|
||||||
|
if (logLen > 0)
|
||||||
|
{
|
||||||
|
char *log = (char *)malloc(logLen * sizeof(char));
|
||||||
|
// Show any errors as appropriate
|
||||||
|
glGetProgramInfoLog(programId, logLen, &logLen, log);
|
||||||
|
std::cout << "Prog Info Log: " << std::endl
|
||||||
|
<< log << std::endl;
|
||||||
|
free(log);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vtxShaderId)
|
||||||
|
{
|
||||||
|
glDeleteShader(vtxShaderId);
|
||||||
|
}
|
||||||
|
if (fragShaderId)
|
||||||
|
{
|
||||||
|
glDeleteShader(fragShaderId);
|
||||||
|
}
|
||||||
|
return programId;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool init(SDL_Window *win, SDL_Texture *backBuffer, const char *vertexShader, const char *fragmentShader)
|
||||||
|
{
|
||||||
|
shader::win = win;
|
||||||
|
shader::renderer = SDL_GetRenderer(win);
|
||||||
|
shader::backBuffer = backBuffer;
|
||||||
|
SDL_GetWindowSize(win, &win_size.x, &win_size.y);
|
||||||
|
int access;
|
||||||
|
SDL_QueryTexture(backBuffer, NULL, &access, &tex_size.x, &tex_size.y);
|
||||||
|
if (access != SDL_TEXTUREACCESS_TARGET)
|
||||||
|
{
|
||||||
|
std::cout << "ERROR FATAL: La textura per al render ha de tindre SDL_TEXTUREACCESS_TARGET definit." << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_RendererInfo rendererInfo;
|
||||||
|
SDL_GetRendererInfo(renderer, &rendererInfo);
|
||||||
|
|
||||||
|
if (!strncmp(rendererInfo.name, "opengl", 6))
|
||||||
|
{
|
||||||
|
// std::cout << "Es OpenGL!" << std::endl;
|
||||||
|
#ifndef __APPLE__
|
||||||
|
if (!initGLExtensions())
|
||||||
|
{
|
||||||
|
std::cout << "WARNING: No s'han pogut inicialitzar les extensions d'OpenGL!" << std::endl;
|
||||||
|
usingOpenGL = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
// Compilar el shader y dejarlo listo para usar.
|
||||||
|
programId = compileProgram(vertexShader, fragmentShader);
|
||||||
|
// std::cout << "programId = " << programId << std::endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cout << "WARNING: El driver del renderer no es OpenGL." << std::endl;
|
||||||
|
usingOpenGL = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
usingOpenGL = true;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void render()
|
||||||
|
{
|
||||||
|
GLint oldProgramId;
|
||||||
|
// Guarrada para obtener el textureid (en driverdata->texture)
|
||||||
|
// Detach the texture
|
||||||
|
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||||
|
|
||||||
|
SDL_SetRenderTarget(renderer, NULL);
|
||||||
|
SDL_RenderClear(renderer);
|
||||||
|
|
||||||
|
if (usingOpenGL)
|
||||||
|
{
|
||||||
|
SDL_GL_BindTexture(backBuffer, NULL, NULL);
|
||||||
|
if (programId != 0)
|
||||||
|
{
|
||||||
|
glGetIntegerv(GL_CURRENT_PROGRAM, &oldProgramId);
|
||||||
|
glUseProgram(programId);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLfloat minx, miny, maxx, maxy;
|
||||||
|
GLfloat minu, maxu, minv, maxv;
|
||||||
|
|
||||||
|
// Coordenadas de la ventana donde pintar.
|
||||||
|
minx = 0.0f;
|
||||||
|
miny = 0.0f;
|
||||||
|
maxx = tex_size.x;
|
||||||
|
maxy = tex_size.y;
|
||||||
|
|
||||||
|
minu = 0.0f;
|
||||||
|
maxu = 1.0f;
|
||||||
|
minv = 0.0f;
|
||||||
|
maxv = 1.0f;
|
||||||
|
|
||||||
|
glViewport(0, 0, win_size.x, win_size.y);
|
||||||
|
|
||||||
|
glBegin(GL_TRIANGLE_STRIP);
|
||||||
|
glTexCoord2f(minu, minv);
|
||||||
|
glVertex2f(minx, miny);
|
||||||
|
glTexCoord2f(maxu, minv);
|
||||||
|
glVertex2f(maxx, miny);
|
||||||
|
glTexCoord2f(minu, maxv);
|
||||||
|
glVertex2f(minx, maxy);
|
||||||
|
glTexCoord2f(maxu, maxv);
|
||||||
|
glVertex2f(maxx, maxy);
|
||||||
|
glEnd();
|
||||||
|
SDL_GL_SwapWindow(win);
|
||||||
|
|
||||||
|
if (programId != 0)
|
||||||
|
{
|
||||||
|
glUseProgram(oldProgramId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_RenderCopy(renderer, backBuffer, NULL, NULL);
|
||||||
|
SDL_RenderPresent(renderer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
45
source/jail_shader.h
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_render.h> // para SDL_Texture
|
||||||
|
#include <SDL2/SDL_video.h> // para SDL_Window
|
||||||
|
|
||||||
|
// TIPS:
|
||||||
|
// =======================================================================
|
||||||
|
// Abans de crear el renderer, cridar a la següent funció:
|
||||||
|
//
|
||||||
|
// SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengl");
|
||||||
|
//
|
||||||
|
// Aixó li diu que volem un renderer que use especificament opengl. A més,
|
||||||
|
// al crear el renderer li tenim que dir que el volem que use acceeració
|
||||||
|
// per hardware, i que soporte render a textura. Per exemple:
|
||||||
|
//
|
||||||
|
// SDL_Renderer *ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED |
|
||||||
|
// SDL_RENDERER_TARGETTEXTURE);
|
||||||
|
//
|
||||||
|
// Per altra part, al crear la textura tenim que definir que puga ser target
|
||||||
|
// de renderitzat (SDL_TEXTUREACCESS_TARGET), per exemple:
|
||||||
|
//
|
||||||
|
// SDL_Texture *tex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888,
|
||||||
|
// SDL_TEXTUREACCESS_TARGET, 320, 240);
|
||||||
|
//
|
||||||
|
// Els shaders li'ls passem com una cadena, som nosaltres els que s'encarreguem
|
||||||
|
// de carregarlos de disc, amb fopen, ifstream, jfile o el que vullgues.
|
||||||
|
// Si els tens en un std::string, passa-li-la com "cadena.c_str()".
|
||||||
|
//
|
||||||
|
// Poden ser els dos el mateix arxiu, com fa libRetro, jo desde dins ja fique
|
||||||
|
// els defines necessaris. Si es el mateix arxiu, pots no ficar el quart paràmetre.
|
||||||
|
//
|
||||||
|
// Els shaders de libRetro no funcionen directament, hi ha que fer algunes modificacions.
|
||||||
|
//
|
||||||
|
// El pintat final de la teua escena l'has de fer com si "backBuffer" fora la pantalla.
|
||||||
|
//
|
||||||
|
// Ah! una cosa mes: al compilar, en Linux afegir "-lGL", en Windows afegir "-lopengl32".
|
||||||
|
// En Mac ni idea
|
||||||
|
|
||||||
|
namespace shader
|
||||||
|
{
|
||||||
|
const bool init(SDL_Window *win, SDL_Texture *backBuffer,
|
||||||
|
const char *vertexShader, const char *fragmentShader = nullptr);
|
||||||
|
|
||||||
|
void render();
|
||||||
|
}
|
||||||
356
source/loading_screen.cpp
Normal file
@@ -0,0 +1,356 @@
|
|||||||
|
#include "loading_screen.h"
|
||||||
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <stdlib.h> // for rand
|
||||||
|
#include "asset.h" // for Asset
|
||||||
|
#include "const.h" // for SECTION_LOADING_SCREEN, SECTION_QUIT
|
||||||
|
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // for JA_DeleteMusic, JA_LoadMusic, JA_PlayMusic
|
||||||
|
#include "resource.h" // for Resource
|
||||||
|
#include "screen.h" // for Screen
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
#include "utils.h" // for options_t, section_t, color_t, stringToC...
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
LoadingScreen::LoadingScreen()
|
||||||
|
: screen_(Screen::get()),
|
||||||
|
renderer_(Screen::get()->getRenderer()),
|
||||||
|
resource_(Resource::get()),
|
||||||
|
asset_(Asset::get()),
|
||||||
|
input_(Input::get())
|
||||||
|
{
|
||||||
|
// Reserva memoria para los punteros
|
||||||
|
if (options.palette == p_zxspectrum)
|
||||||
|
{
|
||||||
|
mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn.png");
|
||||||
|
color_loading_screen_texture_ = resource_->getTexture("loading_screen_color.png");
|
||||||
|
}
|
||||||
|
else if (options.palette == p_zxarne)
|
||||||
|
{
|
||||||
|
mono_loading_screen_texture_ = resource_->getTexture("loading_screen_bn_zxarne.png");
|
||||||
|
color_loading_screen_texture_ = resource_->getTexture("loading_screen_color_zxarne.png");
|
||||||
|
}
|
||||||
|
mono_loading_screen_sprite_ = new Sprite(0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight(), mono_loading_screen_texture_, renderer_);
|
||||||
|
color_loading_screen_sprite_ = new Sprite(0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight(), color_loading_screen_texture_, renderer_);
|
||||||
|
loading_sound1_ = JA_LoadMusic(asset_->get("loading_sound1.ogg").c_str());
|
||||||
|
loading_sound2_ = JA_LoadMusic(asset_->get("loading_sound2.ogg").c_str());
|
||||||
|
loading_sound3_ = JA_LoadMusic(asset_->get("loading_sound3.ogg").c_str());
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
options.section.name = SECTION_LOADING_SCREEN;
|
||||||
|
options.section.subsection = 0;
|
||||||
|
|
||||||
|
// Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum
|
||||||
|
for (int i = 0; i < 192; ++i)
|
||||||
|
{
|
||||||
|
if (i < 64)
|
||||||
|
{ // Primer bloque de 2K
|
||||||
|
line_index_[i] = ((i % 8) * 8) + (i / 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (i >= 64 && i < 128)
|
||||||
|
{ // Segundo bloque de 2K
|
||||||
|
line_index_[i] = 64 + ((i % 8) * 8) + ((i - 64) / 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (i >= 128 && i < 192)
|
||||||
|
{ // tercer bloque de 2K
|
||||||
|
line_index_[i] = 128 + ((i % 8) * 8) + ((i - 128) / 8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el color del borde
|
||||||
|
screen_->setBorderColor(stringToColor(options.palette, "black"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
LoadingScreen::~LoadingScreen()
|
||||||
|
{
|
||||||
|
delete mono_loading_screen_sprite_;
|
||||||
|
delete color_loading_screen_sprite_;
|
||||||
|
JA_DeleteMusic(loading_sound1_);
|
||||||
|
JA_DeleteMusic(loading_sound2_);
|
||||||
|
JA_DeleteMusic(loading_sound3_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba el manejador de eventos
|
||||||
|
void LoadingScreen::checkEvents()
|
||||||
|
{
|
||||||
|
SDL_Event event;
|
||||||
|
while (SDL_PollEvent(&event))
|
||||||
|
{
|
||||||
|
// Evento de salida de la aplicación
|
||||||
|
if (event.type == SDL_QUIT)
|
||||||
|
{
|
||||||
|
options.section.name = SECTION_QUIT;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void LoadingScreen::checkInput()
|
||||||
|
{
|
||||||
|
|
||||||
|
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
options.section.name = SECTION_QUIT;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->toggleBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->toggleVideoMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->decWindowSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
screen_->incWindowSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
switchPalette();
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE))
|
||||||
|
{
|
||||||
|
options.section.name = SECTION_TITLE;
|
||||||
|
options.section.subsection = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestiona el contador de carga
|
||||||
|
void LoadingScreen::updateLoad()
|
||||||
|
{
|
||||||
|
// Primera parte de la carga, la parte en blanco y negro
|
||||||
|
if (loading_first_part_)
|
||||||
|
{
|
||||||
|
// Cada 5 pasos el loadCounter se incrementa en uno
|
||||||
|
const int numSteps = 5;
|
||||||
|
const int step = 51;
|
||||||
|
load_counter_ = counter_ / numSteps;
|
||||||
|
|
||||||
|
if (load_counter_ < 192)
|
||||||
|
{
|
||||||
|
load_rect_.x = step * (counter_ % numSteps);
|
||||||
|
load_rect_.y = line_index_[load_counter_];
|
||||||
|
mono_loading_screen_sprite_->setSpriteClip(load_rect_);
|
||||||
|
mono_loading_screen_sprite_->setRect(load_rect_);
|
||||||
|
}
|
||||||
|
// Una vez actualizadas las 192 lineas, pasa a la segunda fase de la carga
|
||||||
|
else if (load_counter_ == 192)
|
||||||
|
{
|
||||||
|
loading_first_part_ = false;
|
||||||
|
load_counter_ = 0;
|
||||||
|
load_rect_ = {0, 0, 16, 8};
|
||||||
|
color_loading_screen_sprite_->setRect(load_rect_);
|
||||||
|
color_loading_screen_sprite_->setSpriteClip(load_rect_);
|
||||||
|
JA_PlayMusic(loading_sound3_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Segunda parte de la carga, la parte de los bloques en color
|
||||||
|
else
|
||||||
|
{
|
||||||
|
load_counter_ += 2;
|
||||||
|
load_rect_.x = (load_counter_ * 8) % 256;
|
||||||
|
load_rect_.y = (load_counter_ / 32) * 8;
|
||||||
|
color_loading_screen_sprite_->setSpriteClip(load_rect_);
|
||||||
|
color_loading_screen_sprite_->setRect(load_rect_);
|
||||||
|
|
||||||
|
// Comprueba si ha terminado la intro
|
||||||
|
if (load_counter_ >= 768)
|
||||||
|
{
|
||||||
|
options.section.name = SECTION_TITLE;
|
||||||
|
options.section.subsection = SUBSECTION_TITLE_WITH_LOADING_SCREEN;
|
||||||
|
JA_StopMusic();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestiona el contador interno
|
||||||
|
void LoadingScreen::updateCounter()
|
||||||
|
{
|
||||||
|
(pre_counter_ >= 50) ? counter_++ : pre_counter_++;
|
||||||
|
|
||||||
|
if (counter_ == 1)
|
||||||
|
{
|
||||||
|
JA_PlayMusic(loading_sound2_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja la pantalla de carga
|
||||||
|
void LoadingScreen::renderLoad()
|
||||||
|
{
|
||||||
|
loading_first_part_ ? mono_loading_screen_sprite_->render() : color_loading_screen_sprite_->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el efecto de carga en el borde
|
||||||
|
void LoadingScreen::renderBorder()
|
||||||
|
{
|
||||||
|
// Pinta el borde de colro azul
|
||||||
|
color_t color = stringToColor(options.palette, "blue");
|
||||||
|
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||||
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
|
// Añade lineas amarillas
|
||||||
|
color = stringToColor(options.palette, "yellow");
|
||||||
|
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||||
|
const int width = GAMECANVAS_WIDTH + (options.borderWidth * 2);
|
||||||
|
const int height = GAMECANVAS_HEIGHT + (options.borderHeight * 2);
|
||||||
|
bool drawEnabled = rand() % 2 == 0 ? true : false;
|
||||||
|
// Para (int i = 0; i < height; ++i)
|
||||||
|
//{
|
||||||
|
// if (rand() % 2 == 0)
|
||||||
|
// {
|
||||||
|
// SDL_RenderDrawLine(renderer, 0, i, width, i);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
int row = 0;
|
||||||
|
int rowSize = 1;
|
||||||
|
while (row < height)
|
||||||
|
{
|
||||||
|
rowSize = (rand() % 4) + 3;
|
||||||
|
if (drawEnabled)
|
||||||
|
for (int i = row; i < row + rowSize; ++i)
|
||||||
|
{
|
||||||
|
SDL_RenderDrawLine(renderer_, 0, i, width, i);
|
||||||
|
}
|
||||||
|
row += rowSize;
|
||||||
|
drawEnabled = !drawEnabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void LoadingScreen::update()
|
||||||
|
{
|
||||||
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
|
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||||
|
{
|
||||||
|
// Actualiza el contador de ticks
|
||||||
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
checkInput();
|
||||||
|
|
||||||
|
// Gestiona el contador interno
|
||||||
|
updateCounter();
|
||||||
|
|
||||||
|
// Gestiona el contador de carga
|
||||||
|
updateLoad();
|
||||||
|
|
||||||
|
screen_->update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void LoadingScreen::render()
|
||||||
|
{
|
||||||
|
if (options.borderEnabled)
|
||||||
|
{
|
||||||
|
// Prepara para empezar a dibujar en la textura del borde
|
||||||
|
screen_->startDrawOnBorder();
|
||||||
|
|
||||||
|
// Dibuja el efecto de carga en el borde
|
||||||
|
renderBorder();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen_->start();
|
||||||
|
|
||||||
|
// Dibuja la pantalla de carga
|
||||||
|
renderLoad();
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
screen_->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bucle para el logo del juego
|
||||||
|
void LoadingScreen::run()
|
||||||
|
{
|
||||||
|
// Inicia el sonido de carga
|
||||||
|
JA_SetVolume(64);
|
||||||
|
JA_PlayMusic(loading_sound1_);
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
screen_->start();
|
||||||
|
screen_->clean();
|
||||||
|
screen_->render();
|
||||||
|
|
||||||
|
while (options.section.name == SECTION_LOADING_SCREEN)
|
||||||
|
{
|
||||||
|
update();
|
||||||
|
checkEvents();
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
|
||||||
|
JA_SetVolume(128);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia la paleta
|
||||||
|
void LoadingScreen::switchPalette()
|
||||||
|
{
|
||||||
|
if (options.palette == p_zxspectrum)
|
||||||
|
{
|
||||||
|
options.palette = p_zxarne;
|
||||||
|
mono_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_bn_zxarne.png"));
|
||||||
|
color_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_color_zxarne.png"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options.palette = p_zxspectrum;
|
||||||
|
mono_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_bn.png"));
|
||||||
|
color_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_color.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
recreateLoadingScreen();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reconstruye la pantalla de carga
|
||||||
|
void LoadingScreen::recreateLoadingScreen()
|
||||||
|
{
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
screen_->start();
|
||||||
|
|
||||||
|
// Primera parte de la carga, la parte en blanco y negro
|
||||||
|
if (loading_first_part_)
|
||||||
|
{
|
||||||
|
const int numSteps = 5;
|
||||||
|
const int step = 51;
|
||||||
|
|
||||||
|
for (int i = 0; i <= counter_; i++)
|
||||||
|
{
|
||||||
|
load_counter_ = i / numSteps;
|
||||||
|
load_rect_.x = step * (i % numSteps);
|
||||||
|
load_rect_.y = line_index_[load_counter_];
|
||||||
|
mono_loading_screen_sprite_->setSpriteClip(load_rect_);
|
||||||
|
mono_loading_screen_sprite_->setRect(load_rect_);
|
||||||
|
mono_loading_screen_sprite_->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Segunda parte de la carga, la parte de los bloques en color
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i <= load_counter_; i++)
|
||||||
|
{
|
||||||
|
load_rect_.x = (i * 8) % 256;
|
||||||
|
load_rect_.y = (i / 32) * 8;
|
||||||
|
color_loading_screen_sprite_->setSpriteClip(load_rect_);
|
||||||
|
color_loading_screen_sprite_->setRect(load_rect_);
|
||||||
|
color_loading_screen_sprite_->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
screen_->render();
|
||||||
|
}
|
||||||
83
source/loading_screen.h
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_events.h> // Para SDL_Event
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
|
class Asset;
|
||||||
|
class Input;
|
||||||
|
class Resource;
|
||||||
|
class Screen;
|
||||||
|
class Sprite;
|
||||||
|
class Texture;
|
||||||
|
struct JA_Music_t;
|
||||||
|
struct options_t;
|
||||||
|
struct section_t;
|
||||||
|
|
||||||
|
class LoadingScreen
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// Objetos y punteros
|
||||||
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
|
Resource *resource_; // Objeto con los recursos
|
||||||
|
Asset *asset_; // Objeto con los ficheros de recursos
|
||||||
|
Input *input_; // Objeto pata gestionar la entrada
|
||||||
|
Texture *mono_loading_screen_texture_; // Textura con la pantalla de carga en blanco y negro
|
||||||
|
Texture *color_loading_screen_texture_; // Textura con la pantalla de carga en color
|
||||||
|
Sprite *mono_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture1
|
||||||
|
Sprite *color_loading_screen_sprite_; // Sprite para manejar la textura loadingScreenTexture2
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
int pre_counter_ = 0; // Contador previo para realizar una pausa inicial
|
||||||
|
int counter_ = 0; // Contador
|
||||||
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
|
Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa
|
||||||
|
int load_counter_ = 0; // Contador para controlar las cargas
|
||||||
|
bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra
|
||||||
|
JA_Music_t *loading_sound1_; // Sonidos para imitar la carga tipo spectrum
|
||||||
|
JA_Music_t *loading_sound2_; // Sonidos para imitar la carga tipo spectrum
|
||||||
|
JA_Music_t *loading_sound3_; // Sonidos para imitar la carga tipo spectrum
|
||||||
|
int line_index_[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga
|
||||||
|
SDL_Rect load_rect_ = {0, 0, 51, 1}; // Rectangulo para dibujar la pantalla de carga
|
||||||
|
|
||||||
|
// Actualiza las variables
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Dibuja en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Comprueba el manejador de eventos
|
||||||
|
void checkEvents();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
|
// Gestiona el contador interno
|
||||||
|
void updateCounter();
|
||||||
|
|
||||||
|
// Gestiona el contador de carga
|
||||||
|
void updateLoad();
|
||||||
|
|
||||||
|
// Dibuja la pantalla de carga
|
||||||
|
void renderLoad();
|
||||||
|
|
||||||
|
// Dibuja el efecto de carga en el borde
|
||||||
|
void renderBorder();
|
||||||
|
|
||||||
|
// Cambia la paleta
|
||||||
|
void switchPalette();
|
||||||
|
|
||||||
|
// Reconstruye la pantalla de carga
|
||||||
|
void recreateLoadingScreen();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// Constructor
|
||||||
|
LoadingScreen();
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~LoadingScreen();
|
||||||
|
|
||||||
|
// Bucle principal
|
||||||
|
void run();
|
||||||
|
};
|
||||||
319
source/logo.cpp
@@ -1,163 +1,154 @@
|
|||||||
#include "logo.h"
|
#include "logo.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL_timer.h> // for SDL_GetTicks
|
||||||
|
#include <string> // for basic_string, string
|
||||||
|
#include "const.h" // for SECTION_LOGO, SECTION_TITLE, SUBSECTION_...
|
||||||
|
#include "input.h" // for Input, REPEAT_FALSE, inputs_e
|
||||||
|
#include "jail_audio.h" // for JA_StopMusic
|
||||||
|
#include "resource.h" // for Resource
|
||||||
|
#include "screen.h" // for Screen
|
||||||
|
#include "sprite.h" // for Sprite
|
||||||
|
#include "texture.h" // for Texture
|
||||||
|
#include "utils.h" // for color_t, section_t, options_t, stringToC...
|
||||||
|
#include "asset.h"
|
||||||
|
#include "options.h"
|
||||||
|
class Asset; // lines 11-11
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo::Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection)
|
Logo::Logo()
|
||||||
|
: screen_(Screen::get()),
|
||||||
|
renderer_(Screen::get()->getRenderer()),
|
||||||
|
resource_(Resource::get()),
|
||||||
|
asset_(Asset::get()),
|
||||||
|
input_(Input::get())
|
||||||
{
|
{
|
||||||
// Copia la dirección de los objetos
|
|
||||||
this->resource = resource;
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->screen = screen;
|
|
||||||
this->asset = asset;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los punteros
|
// Reserva memoria para los punteros
|
||||||
eventHandler = new SDL_Event();
|
jailgames_texture_ = resource_->getTexture("jailgames.png");
|
||||||
texture = resource->getTexture("jailgames.png");
|
since_1998_texture_ = resource_->getTexture("since_1998.png");
|
||||||
texture2 = resource->getTexture("since_1998.png");
|
since_1998_sprite_ = new Sprite((256 - since_1998_texture_->getWidth()) / 2, 83 + jailgames_texture_->getHeight() + 5, since_1998_texture_->getWidth(), since_1998_texture_->getHeight(), since_1998_texture_, renderer_);
|
||||||
sprite2 = new Sprite((256 - texture2->getWidth()) / 2, 83 + texture->getHeight() + 5, texture2->getWidth(), texture2->getHeight(), texture2, renderer);
|
since_1998_sprite_->setSpriteClip(0, 0, since_1998_texture_->getWidth(), since_1998_texture_->getHeight());
|
||||||
sprite2->setSpriteClip(0, 0, texture2->getWidth(), texture2->getHeight());
|
since_1998_texture_->setColor(0, 0, 0);
|
||||||
texture2->setColor(0, 0, 0);
|
|
||||||
|
|
||||||
// Crea los sprites de cada linea
|
// Crea los sprites de cada linea
|
||||||
for (int i = 0; i < texture->getHeight(); ++i)
|
for (int i = 0; i < jailgames_texture_->getHeight(); ++i)
|
||||||
{
|
{
|
||||||
sprite.push_back(new Sprite(0, i, texture->getWidth(), 1, texture, renderer));
|
jailgames_sprite_.push_back(new Sprite(0, i, jailgames_texture_->getWidth(), 1, jailgames_texture_, renderer_));
|
||||||
sprite.back()->setSpriteClip(0, i, texture->getWidth(), 1);
|
jailgames_sprite_.back()->setSpriteClip(0, i, jailgames_texture_->getWidth(), 1);
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0)
|
||||||
{
|
{
|
||||||
sprite[i]->setPosX(256 + (i * 3));
|
jailgames_sprite_[i]->setPosX(256 + (i * 3));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprite[i]->setPosX(-181 - (i * 3));
|
jailgames_sprite_[i]->setPosX(-181 - (i * 3));
|
||||||
}
|
}
|
||||||
sprite[i]->setPosY(83 + i);
|
jailgames_sprite_[i]->setPosY(83 + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
counter = 0;
|
options.section.name = SECTION_LOGO;
|
||||||
section.name = SECTION_PROG_LOGO;
|
|
||||||
section.subsection = subsection;
|
|
||||||
ticks = 0;
|
|
||||||
ticksSpeed = 15;
|
|
||||||
initFade = 300;
|
|
||||||
endLogo = 400;
|
|
||||||
postLogo = 20;
|
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||||
for (auto v : vColors)
|
for (auto v : vColors)
|
||||||
{
|
{
|
||||||
color.push_back(stringToColor(options->palette, v));
|
color_.push_back(stringToColor(options.palette, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
screen->setBorderColor(stringToColor(options->palette, "black"));
|
screen_->setBorderColor(stringToColor(options.palette, "black"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
Logo::~Logo()
|
Logo::~Logo()
|
||||||
{
|
{
|
||||||
for (auto s : sprite)
|
for (auto s : jailgames_sprite_)
|
||||||
{
|
{
|
||||||
delete s;
|
delete s;
|
||||||
}
|
}
|
||||||
|
|
||||||
delete sprite2;
|
delete since_1998_sprite_;
|
||||||
delete eventHandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void Logo::checkEventHandler()
|
void Logo::checkEvents()
|
||||||
{
|
{
|
||||||
// Comprueba los eventos que hay en la cola
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(eventHandler) != 0)
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
// Evento de salida de la aplicación
|
// Evento de salida de la aplicación
|
||||||
if (eventHandler->type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_QUIT;
|
options.section.name = SECTION_QUIT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Comprueba las teclas que se han pulsado
|
// Comprueba las entradas
|
||||||
if ((eventHandler->type == SDL_KEYUP && eventHandler->key.repeat == 0) || (eventHandler->type == SDL_JOYBUTTONUP))
|
void Logo::checkInput()
|
||||||
{
|
{
|
||||||
switch (eventHandler->key.keysym.scancode)
|
if (input_->checkInput(input_exit, REPEAT_FALSE))
|
||||||
{
|
{
|
||||||
case SDL_SCANCODE_ESCAPE:
|
options.section.name = SECTION_TITLE;
|
||||||
section.name = SECTION_PROG_QUIT;
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_B:
|
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
|
||||||
screen->switchBorder();
|
{
|
||||||
resource->reLoadTextures();
|
screen_->toggleBorder();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F:
|
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
|
||||||
screen->switchVideoMode();
|
{
|
||||||
resource->reLoadTextures();
|
screen_->toggleVideoMode();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F1:
|
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(1);
|
{
|
||||||
resource->reLoadTextures();
|
screen_->decWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F2:
|
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
|
||||||
screen->setWindowSize(2);
|
{
|
||||||
resource->reLoadTextures();
|
screen_->incWindowSize();
|
||||||
break;
|
}
|
||||||
|
|
||||||
case SDL_SCANCODE_F3:
|
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
|
||||||
screen->setWindowSize(3);
|
{
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F4:
|
|
||||||
screen->setWindowSize(4);
|
|
||||||
resource->reLoadTextures();
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SDL_SCANCODE_F5:
|
|
||||||
switchPalette();
|
switchPalette();
|
||||||
break;
|
}
|
||||||
|
|
||||||
default:
|
else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE))
|
||||||
section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
{
|
||||||
|
options.section.subsection = SUBSECTION_LOGO_TO_TITLE;
|
||||||
endSection();
|
endSection();
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAME
|
||||||
void Logo::updateJAILGAMES()
|
void Logo::updateJAILGAMES()
|
||||||
{
|
{
|
||||||
if (counter > 30)
|
if (counter_ > 30)
|
||||||
{
|
{
|
||||||
for (int i = 1; i < (int)sprite.size(); ++i)
|
for (int i = 1; i < (int)jailgames_sprite_.size(); ++i)
|
||||||
{
|
{
|
||||||
const int speed = 8;
|
const int speed = 8;
|
||||||
const int dest = 37;
|
const int dest = 37;
|
||||||
if (sprite[i]->getPosX() != 37)
|
if (jailgames_sprite_[i]->getPosX() != 37)
|
||||||
{
|
{
|
||||||
if (i % 2 == 0)
|
if (i % 2 == 0)
|
||||||
{
|
{
|
||||||
sprite[i]->incPosX(-speed);
|
jailgames_sprite_[i]->incPosX(-speed);
|
||||||
if (sprite[i]->getPosX() < dest)
|
if (jailgames_sprite_[i]->getPosX() < dest)
|
||||||
{
|
{
|
||||||
sprite[i]->setPosX(dest);
|
jailgames_sprite_[i]->setPosX(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprite[i]->incPosX(speed);
|
jailgames_sprite_[i]->incPosX(speed);
|
||||||
if (sprite[i]->getPosX() > dest)
|
if (jailgames_sprite_[i]->getPosX() > dest)
|
||||||
{
|
{
|
||||||
sprite[i]->setPosX(dest);
|
jailgames_sprite_[i]->setPosX(dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,74 +162,86 @@ void Logo::updateTextureColors()
|
|||||||
const int ini = 70;
|
const int ini = 70;
|
||||||
const int inc = 4;
|
const int inc = 4;
|
||||||
|
|
||||||
if (counter == ini + inc * 0)
|
if (counter_ == ini + inc * 0)
|
||||||
{
|
{
|
||||||
texture2->setColor(color[0].r, color[0].g, color[0].b);
|
since_1998_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
||||||
}
|
|
||||||
else if (counter == ini + inc * 1)
|
|
||||||
{
|
|
||||||
texture2->setColor(color[1].r, color[1].g, color[1].b);
|
|
||||||
}
|
|
||||||
else if (counter == ini + inc * 2)
|
|
||||||
{
|
|
||||||
texture2->setColor(color[2].r, color[2].g, color[2].b);
|
|
||||||
}
|
|
||||||
else if (counter == ini + inc * 3)
|
|
||||||
{
|
|
||||||
texture2->setColor(color[3].r, color[3].g, color[3].b);
|
|
||||||
}
|
|
||||||
else if (counter == ini + inc * 4)
|
|
||||||
{
|
|
||||||
texture2->setColor(color[4].r, color[4].g, color[4].b);
|
|
||||||
}
|
|
||||||
else if (counter == ini + inc * 5)
|
|
||||||
{
|
|
||||||
texture2->setColor(color[5].r, color[5].g, color[5].b);
|
|
||||||
}
|
|
||||||
else if (counter == ini + inc * 6)
|
|
||||||
{
|
|
||||||
texture2->setColor(color[6].r, color[6].g, color[6].b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter == ini + inc * 7)
|
else if (counter_ == ini + inc * 1)
|
||||||
{
|
{
|
||||||
texture2->setColor(color[7].r, color[7].g, color[7].b);
|
since_1998_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (counter == initFade + inc * 0)
|
else if (counter_ == ini + inc * 2)
|
||||||
{
|
{
|
||||||
texture->setColor(color[6].r, color[6].g, color[6].b);
|
since_1998_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
||||||
texture2->setColor(color[6].r, color[6].g, color[6].b);
|
|
||||||
}
|
}
|
||||||
else if (counter == initFade + inc * 1)
|
|
||||||
|
else if (counter_ == ini + inc * 3)
|
||||||
{
|
{
|
||||||
texture->setColor(color[5].r, color[5].g, color[5].b);
|
since_1998_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
||||||
texture2->setColor(color[5].r, color[5].g, color[5].b);
|
|
||||||
}
|
}
|
||||||
else if (counter == initFade + inc * 2)
|
|
||||||
|
else if (counter_ == ini + inc * 4)
|
||||||
{
|
{
|
||||||
texture->setColor(color[4].r, color[4].g, color[4].b);
|
since_1998_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
||||||
texture2->setColor(color[4].r, color[4].g, color[4].b);
|
|
||||||
}
|
}
|
||||||
else if (counter == initFade + inc * 3)
|
|
||||||
|
else if (counter_ == ini + inc * 5)
|
||||||
{
|
{
|
||||||
texture->setColor(color[3].r, color[3].g, color[3].b);
|
since_1998_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
||||||
texture2->setColor(color[3].r, color[3].g, color[3].b);
|
|
||||||
}
|
}
|
||||||
else if (counter == initFade + inc * 4)
|
|
||||||
|
else if (counter_ == ini + inc * 6)
|
||||||
{
|
{
|
||||||
texture->setColor(color[2].r, color[2].g, color[2].b);
|
since_1998_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
||||||
texture2->setColor(color[2].r, color[2].g, color[2].b);
|
|
||||||
}
|
}
|
||||||
else if (counter == initFade + inc * 5)
|
|
||||||
|
else if (counter_ == ini + inc * 7)
|
||||||
{
|
{
|
||||||
texture->setColor(color[1].r, color[1].g, color[1].b);
|
since_1998_texture_->setColor(color_[7].r, color_[7].g, color_[7].b);
|
||||||
texture2->setColor(color[1].r, color[1].g, color[1].b);
|
|
||||||
}
|
}
|
||||||
else if (counter == initFade + inc * 6)
|
|
||||||
|
else if (counter_ == init_fade_ + inc * 0)
|
||||||
{
|
{
|
||||||
texture->setColor(color[0].r, color[0].g, color[0].b);
|
jailgames_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
||||||
texture2->setColor(color[0].r, color[0].g, color[0].b);
|
since_1998_texture_->setColor(color_[6].r, color_[6].g, color_[6].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (counter_ == init_fade_ + inc * 1)
|
||||||
|
{
|
||||||
|
jailgames_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
||||||
|
since_1998_texture_->setColor(color_[5].r, color_[5].g, color_[5].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (counter_ == init_fade_ + inc * 2)
|
||||||
|
{
|
||||||
|
jailgames_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
||||||
|
since_1998_texture_->setColor(color_[4].r, color_[4].g, color_[4].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (counter_ == init_fade_ + inc * 3)
|
||||||
|
{
|
||||||
|
jailgames_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
||||||
|
since_1998_texture_->setColor(color_[3].r, color_[3].g, color_[3].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (counter_ == init_fade_ + inc * 4)
|
||||||
|
{
|
||||||
|
jailgames_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
||||||
|
since_1998_texture_->setColor(color_[2].r, color_[2].g, color_[2].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (counter_ == init_fade_ + inc * 5)
|
||||||
|
{
|
||||||
|
jailgames_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
||||||
|
since_1998_texture_->setColor(color_[1].r, color_[1].g, color_[1].b);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (counter_ == init_fade_ + inc * 6)
|
||||||
|
{
|
||||||
|
jailgames_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
||||||
|
since_1998_texture_->setColor(color_[0].r, color_[0].g, color_[0].b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,16 +249,16 @@ void Logo::updateTextureColors()
|
|||||||
void Logo::update()
|
void Logo::update()
|
||||||
{
|
{
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
||||||
if (SDL_GetTicks() - ticks > ticksSpeed)
|
if (SDL_GetTicks() - ticks_ > ticks_speed_)
|
||||||
{
|
{
|
||||||
// Actualiza el contador de ticks
|
// Actualiza el contador de ticks
|
||||||
ticks = SDL_GetTicks();
|
ticks_ = SDL_GetTicks();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba las entradas
|
||||||
checkEventHandler();
|
checkInput();
|
||||||
|
|
||||||
// Incrementa el contador
|
// Incrementa el contador
|
||||||
counter++;
|
counter_++;
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAME
|
||||||
updateJAILGAMES();
|
updateJAILGAMES();
|
||||||
@@ -263,11 +266,10 @@ void Logo::update()
|
|||||||
// Gestiona el color de las texturas
|
// Gestiona el color de las texturas
|
||||||
updateTextureColors();
|
updateTextureColors();
|
||||||
|
|
||||||
// Actualiza las notificaciones
|
screen_->update();
|
||||||
screen->updateNotifier();
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el logo
|
// Comprueba si ha terminado el logo
|
||||||
if (counter == endLogo + postLogo)
|
if (counter_ == end_logo_ + post_logo_)
|
||||||
{
|
{
|
||||||
endSection();
|
endSection();
|
||||||
}
|
}
|
||||||
@@ -278,45 +280,52 @@ void Logo::update()
|
|||||||
void Logo::render()
|
void Logo::render()
|
||||||
{
|
{
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
screen->start();
|
screen_->start();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
screen->clean();
|
screen_->clean();
|
||||||
|
|
||||||
// Dibuja los objetos
|
// Dibuja los objetos
|
||||||
for (auto s : sprite)
|
for (auto s : jailgames_sprite_)
|
||||||
{
|
{
|
||||||
s->render();
|
s->render();
|
||||||
}
|
}
|
||||||
sprite2->render();
|
since_1998_sprite_->render();
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
screen->blit();
|
screen_->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el logo del juego
|
// Bucle para el logo del juego
|
||||||
section_t Logo::run()
|
void Logo::run()
|
||||||
{
|
{
|
||||||
// Detiene la música
|
// Detiene la música
|
||||||
JA_StopMusic();
|
JA_StopMusic();
|
||||||
|
|
||||||
while (section.name == SECTION_PROG_LOGO)
|
while (options.section.name == SECTION_LOGO)
|
||||||
{
|
{
|
||||||
update();
|
update();
|
||||||
|
checkEvents();
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
return section;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia la paleta
|
// Cambia la paleta
|
||||||
void Logo::switchPalette()
|
void Logo::switchPalette()
|
||||||
{
|
{
|
||||||
options->palette = options->palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
options.palette = options.palette == p_zxspectrum ? p_zxarne : p_zxspectrum;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Termina la sección
|
// Termina la sección
|
||||||
void Logo::endSection()
|
void Logo::endSection()
|
||||||
{
|
{
|
||||||
section.name = SECTION_PROG_ENTER_ID;
|
if (options.section.subsection == SUBSECTION_LOGO_TO_TITLE)
|
||||||
|
{
|
||||||
|
options.section.name = SECTION_TITLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (options.section.subsection == SUBSECTION_LOGO_TO_INTRO)
|
||||||
|
{
|
||||||
|
options.section.name = SECTION_LOADING_SCREEN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,42 +1,41 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_events.h> // for SDL_Event
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_render.h> // for SDL_Renderer
|
||||||
#include "common/jail_audio.h"
|
#include <SDL2/SDL_stdinc.h> // for Uint32
|
||||||
#include "common/resource.h"
|
#include <vector> // for vector
|
||||||
#include "common/screen.h"
|
class Asset; // lines 8-8
|
||||||
#include "common/sprite.h"
|
class Input; // lines 9-9
|
||||||
#include "common/utils.h"
|
class Resource; // lines 10-10
|
||||||
#include "const.h"
|
class Screen; // lines 11-11
|
||||||
#include <vector>
|
class Sprite; // lines 12-12
|
||||||
|
class Texture; // lines 13-13
|
||||||
#ifndef LOGO_H
|
struct color_t;
|
||||||
#define LOGO_H
|
struct options_t;
|
||||||
|
struct section_t;
|
||||||
|
|
||||||
class Logo
|
class Logo
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
Screen *screen_; // Objeto encargado de dibujar en pantalla
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource_; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con los ficheros de recursos
|
Asset *asset_; // Objeto con los ficheros de recursos
|
||||||
Texture *texture; // Textura con los graficos "JAILGAMES"
|
Input *input_; // Objeto pata gestionar la entrada
|
||||||
Texture *texture2; // Textura con los graficos "Since 1998"
|
Texture *jailgames_texture_; // Textura con los graficos "JAILGAMES"
|
||||||
SDL_Event *eventHandler; // Manejador de eventos
|
Texture *since_1998_texture_; // Textura con los graficos "Since 1998"
|
||||||
std::vector<Sprite *> sprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
std::vector<Sprite *> jailgames_sprite_; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES
|
||||||
Sprite *sprite2; // Sprite para manejar la textura2
|
Sprite *since_1998_sprite_; // Sprite para manejar la textura2
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<color_t> color; // Vector con los colores para el fade
|
std::vector<color_t> color_; // Vector con los colores para el fade
|
||||||
int counter; // Contador
|
int counter_ = 0; // Contador
|
||||||
section_t section; // Estado del bucle principal para saber si continua o se sale
|
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
||||||
Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa
|
Uint32 ticks_speed_ = 15; // Velocidad a la que se repiten los bucles del programa
|
||||||
Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa
|
int init_fade_ = 300; // Tiempo del contador cuando inicia el fade a negro
|
||||||
int initFade; // Tiempo del contador cuando inicia el fade a negro
|
int end_logo_ = 400; // Tiempo del contador para terminar el logo
|
||||||
int endLogo; // Tiempo del contador para terminar el logo
|
int post_logo_ = 20; // Tiempo que dura el logo con el fade al maximo
|
||||||
int postLogo; // Tiempo que dura el logo con el fade al maximo
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void update();
|
void update();
|
||||||
@@ -45,7 +44,10 @@ private:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
// Comprueba el manejador de eventos
|
// Comprueba el manejador de eventos
|
||||||
void checkEventHandler();
|
void checkEvents();
|
||||||
|
|
||||||
|
// Comprueba las entradas
|
||||||
|
void checkInput();
|
||||||
|
|
||||||
// Gestiona el logo de JAILGAME
|
// Gestiona el logo de JAILGAME
|
||||||
void updateJAILGAMES();
|
void updateJAILGAMES();
|
||||||
@@ -61,13 +63,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Logo(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, int subsection);
|
Logo();
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Logo();
|
~Logo();
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
section_t run();
|
void run();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -5,24 +5,14 @@ Empezado en Castalla el 01/07/2022.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include "director.h"
|
#include "director.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::cout << "Starting the game...\n\n";
|
|
||||||
|
|
||||||
// Crea el objeto Director
|
// Crea el objeto Director
|
||||||
Director *director = new Director(argc, argv);
|
auto director = std::make_unique<Director>(argc, const_cast<const char **>(argv));
|
||||||
|
|
||||||
// Bucle principal
|
// Bucle principal
|
||||||
director->run();
|
return director->run();
|
||||||
|
|
||||||
// Destruye el objeto Director
|
|
||||||
delete director;
|
|
||||||
director = nullptr;
|
|
||||||
|
|
||||||
std::cout << "\nShutting down the game..." << std::endl;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "../const.h"
|
|
||||||
#include "movingsprite.h"
|
#include "movingsprite.h"
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
|
MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vely, float accelx, float accely, Texture *texture, SDL_Renderer *renderer)
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include "sprite.h"
|
#include <SDL2/SDL_render.h> // Para SDL_RendererFlip, SDL_Renderer
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para Uint16
|
||||||
#ifndef MOVINGSPRITE_H
|
#include "sprite.h" // Para Sprite
|
||||||
#define MOVINGSPRITE_H
|
class Texture;
|
||||||
|
|
||||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||||
class MovingSprite : public Sprite
|
class MovingSprite : public Sprite
|
||||||
@@ -183,5 +183,3 @@ public:
|
|||||||
// Devuelve el incremento en el eje X en pixels
|
// Devuelve el incremento en el eje X en pixels
|
||||||
int getIncX();
|
int getIncX();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
302
source/notifier.cpp
Normal file
@@ -0,0 +1,302 @@
|
|||||||
|
#include "notifier.h"
|
||||||
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
|
#include <string> // Para basic_string, string, char_traits
|
||||||
|
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||||
|
#include "sprite.h" // Para Sprite
|
||||||
|
#include "text.h" // Para Text
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "screen.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
// [SINGLETON]
|
||||||
|
Notifier *Notifier::notifier_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
void Notifier::init(std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile)
|
||||||
|
{
|
||||||
|
Notifier::notifier_ = new Notifier(iconFile, bitmapFile, textFile, soundFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
void Notifier::destroy()
|
||||||
|
{
|
||||||
|
delete Notifier::notifier_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
Notifier *Notifier::get()
|
||||||
|
{
|
||||||
|
return Notifier::notifier_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Notifier::Notifier(std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile)
|
||||||
|
{
|
||||||
|
// Inicializa variables
|
||||||
|
renderer_ = Screen::get()->getRenderer();
|
||||||
|
bg_color_ = options.notifications.color;
|
||||||
|
wait_time_ = 300;
|
||||||
|
|
||||||
|
// Crea objetos
|
||||||
|
icon_texture_ = new Texture(renderer_, iconFile);
|
||||||
|
text_texture_ = new Texture(renderer_, bitmapFile);
|
||||||
|
text_ = new Text(textFile, text_texture_, renderer_);
|
||||||
|
sound_ = JA_LoadSound(soundFile.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Notifier::~Notifier()
|
||||||
|
{
|
||||||
|
// Libera la memoria de los objetos
|
||||||
|
delete text_texture_;
|
||||||
|
delete icon_texture_;
|
||||||
|
delete text_;
|
||||||
|
JA_DeleteSound(sound_);
|
||||||
|
|
||||||
|
for (auto notification : notifications_)
|
||||||
|
{
|
||||||
|
delete notification.sprite;
|
||||||
|
delete notification.texture;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja las notificaciones por pantalla
|
||||||
|
void Notifier::render()
|
||||||
|
{
|
||||||
|
if (active())
|
||||||
|
{
|
||||||
|
for (auto it = notifications_.rbegin(); it != notifications_.rend(); ++it)
|
||||||
|
{
|
||||||
|
it->sprite->render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado de las notificaiones
|
||||||
|
void Notifier::update()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < (int)notifications_.size(); ++i)
|
||||||
|
{
|
||||||
|
// Si la notificación anterior está "saliendo", no hagas nada
|
||||||
|
if (i > 0)
|
||||||
|
{
|
||||||
|
if (notifications_[i - 1].state == ns_rising)
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifications_[i].counter++;
|
||||||
|
|
||||||
|
// Hace sonar la notificación en el primer frame
|
||||||
|
if (notifications_[i].counter == 1)
|
||||||
|
{
|
||||||
|
if (options.notifications.sound)
|
||||||
|
{
|
||||||
|
if (notifications_[i].state == ns_rising)
|
||||||
|
{ // Reproduce el sonido de la notificación
|
||||||
|
JA_PlaySound(sound_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba los estados
|
||||||
|
if (notifications_[i].state == ns_rising)
|
||||||
|
{
|
||||||
|
const float step = ((float)notifications_[i].counter / notifications_[i].travelDist);
|
||||||
|
const int alpha = 255 * step;
|
||||||
|
|
||||||
|
if (options.notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
notifications_[i].rect.y++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notifications_[i].rect.y--;
|
||||||
|
}
|
||||||
|
notifications_[i].texture->setAlpha(alpha);
|
||||||
|
|
||||||
|
if (notifications_[i].rect.y == notifications_[i].y)
|
||||||
|
{
|
||||||
|
notifications_[i].state = ns_stay;
|
||||||
|
notifications_[i].texture->setAlpha(255);
|
||||||
|
notifications_[i].counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (notifications_[i].state == ns_stay)
|
||||||
|
{
|
||||||
|
if (notifications_[i].counter == wait_time_)
|
||||||
|
{
|
||||||
|
notifications_[i].state = ns_vanishing;
|
||||||
|
notifications_[i].counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (notifications_[i].state == ns_vanishing)
|
||||||
|
{
|
||||||
|
|
||||||
|
const float step = (notifications_[i].counter / (float)notifications_[i].travelDist);
|
||||||
|
const int alpha = 255 * (1 - step);
|
||||||
|
|
||||||
|
if (options.notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
notifications_[i].rect.y--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
notifications_[i].rect.y++;
|
||||||
|
}
|
||||||
|
notifications_[i].texture->setAlpha(alpha);
|
||||||
|
|
||||||
|
if (notifications_[i].rect.y == notifications_[i].y - notifications_[i].travelDist)
|
||||||
|
{
|
||||||
|
notifications_[i].state = ns_finished;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
notifications_[i].sprite->setRect(notifications_[i].rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
clearFinishedNotifications();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elimina las notificaciones finalizadas
|
||||||
|
void Notifier::clearFinishedNotifications()
|
||||||
|
{
|
||||||
|
for (int i = (int)notifications_.size() - 1; i >= 0; --i)
|
||||||
|
{
|
||||||
|
if (notifications_[i].state == ns_finished)
|
||||||
|
{
|
||||||
|
delete notifications_[i].sprite;
|
||||||
|
delete notifications_[i].texture;
|
||||||
|
notifications_.erase(notifications_.begin() + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestra una notificación de texto por pantalla;
|
||||||
|
void Notifier::show(std::string text1, std::string text2, int icon)
|
||||||
|
{
|
||||||
|
// Inicializa variables
|
||||||
|
const int iconSize = 16;
|
||||||
|
const int padding = text_->getCharacterSize();
|
||||||
|
const int iconSpace = icon >= 0 ? iconSize + padding : 0;
|
||||||
|
const std::string txt = text1.length() > text2.length() ? text1 : text2;
|
||||||
|
const int width = text_->lenght(txt) + (padding * 2) + iconSpace;
|
||||||
|
const int height = (text_->getCharacterSize() * 2) + (padding * 2);
|
||||||
|
|
||||||
|
// Posición horizontal
|
||||||
|
int despH = 0;
|
||||||
|
if (options.notifications.posH == pos_left)
|
||||||
|
{
|
||||||
|
despH = padding;
|
||||||
|
}
|
||||||
|
else if (options.notifications.posH == pos_middle)
|
||||||
|
{
|
||||||
|
despH = ((options.screen.windowWidth * options.windowSize) / 2 - (width / 2));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
despH = (options.screen.windowWidth * options.windowSize) - width - padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posición vertical
|
||||||
|
int despV = 0;
|
||||||
|
if (options.notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
despV = padding;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
despV = (options.screen.windowHeight * options.windowSize) - height - padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int travelDist = height + padding;
|
||||||
|
|
||||||
|
// Offset
|
||||||
|
int offset = 0;
|
||||||
|
if (options.notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
offset = (int)notifications_.size() > 0 ? notifications_.back().y + travelDist : despV;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
offset = (int)notifications_.size() > 0 ? notifications_.back().y - travelDist : despV;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea la notificacion
|
||||||
|
notification_t n;
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
n.y = offset;
|
||||||
|
n.travelDist = travelDist;
|
||||||
|
n.counter = 0;
|
||||||
|
n.state = ns_rising;
|
||||||
|
n.text1 = text1;
|
||||||
|
n.text2 = text2;
|
||||||
|
if (options.notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
n.rect = {despH, offset - travelDist, width, height};
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
n.rect = {despH, offset + travelDist, width, height};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea la textura
|
||||||
|
n.texture = new Texture(renderer_);
|
||||||
|
n.texture->createBlank(renderer_, width, height, SDL_TEXTUREACCESS_TARGET);
|
||||||
|
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||||
|
|
||||||
|
// Prepara para dibujar en la textura
|
||||||
|
n.texture->setAsRenderTarget(renderer_);
|
||||||
|
|
||||||
|
// Dibuja el fondo de la notificación
|
||||||
|
SDL_SetRenderDrawColor(renderer_, bg_color_.r, bg_color_.g, bg_color_.b, 255);
|
||||||
|
SDL_Rect rect;
|
||||||
|
rect = {4, 0, width - (4 * 2), height};
|
||||||
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
|
rect = {4 / 2, 1, width - 4, height - 2};
|
||||||
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
|
rect = {1, 4 / 2, width - 2, height - 4};
|
||||||
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
|
rect = {0, 4, width, height - (4 * 2)};
|
||||||
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
|
||||||
|
// Dibuja el icono de la notificación
|
||||||
|
if (icon >= 0)
|
||||||
|
{
|
||||||
|
Sprite *sp = new Sprite({0, 0, iconSize, iconSize}, icon_texture_, renderer_);
|
||||||
|
sp->setPos({padding, padding, iconSize, iconSize});
|
||||||
|
sp->setSpriteClip({iconSize * (icon % 10), iconSize * (icon / 10), iconSize, iconSize});
|
||||||
|
sp->render();
|
||||||
|
delete sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe el texto de la notificación
|
||||||
|
color_t color = {255, 255, 255};
|
||||||
|
if (text2 != "")
|
||||||
|
{ // Dos lineas de texto
|
||||||
|
text_->writeColored(padding + iconSpace, padding, text1, color);
|
||||||
|
text_->writeColored(padding + iconSpace, padding + text_->getCharacterSize() + 1, text2, color);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{ // Una linea de texto
|
||||||
|
text_->writeColored(padding + iconSpace, (height / 2) - (text_->getCharacterSize() / 2), text1, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deja de dibujar en la textura
|
||||||
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
|
|
||||||
|
// Crea el sprite de la notificación
|
||||||
|
n.sprite = new Sprite(n.rect, n.texture, renderer_);
|
||||||
|
|
||||||
|
// Deja la notificación invisible
|
||||||
|
n.texture->setAlpha(0);
|
||||||
|
|
||||||
|
// Añade la notificación a la lista
|
||||||
|
notifications_.push_back(n);
|
||||||
|
}
|
||||||
95
source/notifier.h
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
|
#include <string> // Para basic_string, string
|
||||||
|
#include <vector> // Para vector
|
||||||
|
#include "utils.h" // Para color_t
|
||||||
|
class Sprite;
|
||||||
|
class Text;
|
||||||
|
class Texture;
|
||||||
|
struct JA_Sound_t;
|
||||||
|
|
||||||
|
class Notifier
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto notifier
|
||||||
|
static Notifier *notifier_;
|
||||||
|
|
||||||
|
enum notification_state_e
|
||||||
|
{
|
||||||
|
ns_rising,
|
||||||
|
ns_stay,
|
||||||
|
ns_vanishing,
|
||||||
|
ns_finished
|
||||||
|
};
|
||||||
|
|
||||||
|
enum notification_position_e
|
||||||
|
{
|
||||||
|
upperLeft,
|
||||||
|
upperCenter,
|
||||||
|
upperRight,
|
||||||
|
middleLeft,
|
||||||
|
middleRight,
|
||||||
|
bottomLeft,
|
||||||
|
bottomCenter,
|
||||||
|
bottomRight
|
||||||
|
};
|
||||||
|
|
||||||
|
struct notification_t
|
||||||
|
{
|
||||||
|
std::string text1;
|
||||||
|
std::string text2;
|
||||||
|
int counter;
|
||||||
|
notification_state_e state;
|
||||||
|
notification_position_e position;
|
||||||
|
Texture *texture;
|
||||||
|
Sprite *sprite;
|
||||||
|
SDL_Rect rect;
|
||||||
|
int y;
|
||||||
|
int travelDist;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Objetos y punteros
|
||||||
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
|
Texture *text_texture_; // Textura para la fuente de las notificaciones
|
||||||
|
Texture *icon_texture_; // Textura para los iconos de las notificaciones
|
||||||
|
Text *text_; // Objeto para dibujar texto
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
color_t bg_color_; // Color de fondo de las notificaciones
|
||||||
|
int wait_time_; // Tiempo que se ve la notificación
|
||||||
|
std::vector<notification_t> notifications_; // La lista de notificaciones activas
|
||||||
|
JA_Sound_t *sound_; // Sonido a reproducir cuando suena la notificación
|
||||||
|
|
||||||
|
// Elimina las notificaciones finalizadas
|
||||||
|
void clearFinishedNotifications();
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Notifier(std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Notifier();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
static void init(std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile);
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
static Notifier *get();
|
||||||
|
|
||||||
|
// Dibuja las notificaciones por pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Actualiza el estado de las notificaiones
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Muestra una notificación de texto por pantalla;
|
||||||
|
void show(std::string text1 = "", std::string text2 = "", int icon = -1);
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
bool active() const { return !notifications_.empty(); }
|
||||||
|
};
|
||||||
411
source/options.cpp
Normal file
@@ -0,0 +1,411 @@
|
|||||||
|
#include "options.h"
|
||||||
|
#include "const.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include <fstream> // Para basic_ofstream, basic_ifstream
|
||||||
|
#include <iostream> // Para basic_ostream, operator<<, cout
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
options_t options;
|
||||||
|
|
||||||
|
bool setOptions(std::string var, std::string value);
|
||||||
|
|
||||||
|
void initOptions()
|
||||||
|
{
|
||||||
|
// Version del archivo de configuración
|
||||||
|
options.configVersion = "v1.06.1";
|
||||||
|
|
||||||
|
// Opciones de control
|
||||||
|
options.keys = ctrl_cursor;
|
||||||
|
|
||||||
|
// Opciones de video
|
||||||
|
options.gameWidth = GAMECANVAS_WIDTH;
|
||||||
|
options.gameHeight = GAMECANVAS_HEIGHT;
|
||||||
|
options.videoMode = 0;
|
||||||
|
options.windowSize = 3;
|
||||||
|
options.filter = FILTER_NEAREST;
|
||||||
|
options.shaders = false;
|
||||||
|
options.vSync = true;
|
||||||
|
options.integerScale = true;
|
||||||
|
options.keepAspect = true;
|
||||||
|
options.borderEnabled = true;
|
||||||
|
options.borderWidth = 32;
|
||||||
|
options.borderHeight = 24;
|
||||||
|
options.palette = p_zxspectrum;
|
||||||
|
|
||||||
|
#ifdef GAME_CONSOLE
|
||||||
|
options.windowSize = 2;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Estos valores no se guardan en el fichero de configuración
|
||||||
|
options.console = false;
|
||||||
|
#ifdef DEBUG
|
||||||
|
options.console = true;
|
||||||
|
#endif
|
||||||
|
options.cheat.infiniteLives = false;
|
||||||
|
options.cheat.invincible = false;
|
||||||
|
options.cheat.jailEnabled = false;
|
||||||
|
options.cheat.altSkin = false;
|
||||||
|
options.stats.rooms = 0;
|
||||||
|
options.stats.items = 0;
|
||||||
|
|
||||||
|
// Opciones de las notificaciones
|
||||||
|
options.notifications.posV = pos_top;
|
||||||
|
options.notifications.posH = pos_left;
|
||||||
|
options.notifications.sound = true;
|
||||||
|
options.notifications.color = {48, 48, 48};
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
options.section.name = SECTION_TITLE;
|
||||||
|
options.section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||||
|
#else
|
||||||
|
options.section.name = SECTION_LOGO;
|
||||||
|
options.section.subsection = SUBSECTION_LOGO_TO_INTRO;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
bool loadOptionsFromFile(const std::string &file_path)
|
||||||
|
{
|
||||||
|
// Indicador de éxito en la carga
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
// Versión actual del fichero
|
||||||
|
const std::string configVersion = options.configVersion;
|
||||||
|
options.configVersion = "";
|
||||||
|
|
||||||
|
// Variables para manejar el fichero
|
||||||
|
std::string line;
|
||||||
|
std::ifstream file(file_path);
|
||||||
|
|
||||||
|
// Si el fichero se puede abrir
|
||||||
|
if (file.good())
|
||||||
|
{
|
||||||
|
// Procesa el fichero linea a linea
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "Reading file config.txt\n";
|
||||||
|
}
|
||||||
|
while (std::getline(file, line))
|
||||||
|
{
|
||||||
|
// Comprueba que la linea no sea un comentario
|
||||||
|
if (line.substr(0, 1) != "#")
|
||||||
|
{
|
||||||
|
// Encuentra la posición del caracter '='
|
||||||
|
int pos = line.find("=");
|
||||||
|
// Procesa las dos subcadenas
|
||||||
|
if (!setOptions(line.substr(0, pos), line.substr(pos + 1, line.length())))
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "Warning: file config.txt\n";
|
||||||
|
std::cout << "unknown parameter " << line.substr(0, pos).c_str() << std::endl;
|
||||||
|
}
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "Closing file config.txt\n\n";
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// El fichero no existe
|
||||||
|
else
|
||||||
|
{ // Crea el fichero con los valores por defecto
|
||||||
|
saveOptionsToFile(file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si la versión de fichero no coincide, crea un fichero nuevo con los valores por defecto
|
||||||
|
if (configVersion != options.configVersion)
|
||||||
|
{
|
||||||
|
initOptions();
|
||||||
|
saveOptionsToFile(file_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normaliza los valores
|
||||||
|
const bool a = options.videoMode == 0;
|
||||||
|
const bool b = options.videoMode == SDL_WINDOW_FULLSCREEN;
|
||||||
|
const bool c = options.videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
|
if (!(a || b || c))
|
||||||
|
{
|
||||||
|
options.videoMode = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.windowSize < 1 || options.windowSize > 4)
|
||||||
|
{
|
||||||
|
options.windowSize = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool saveOptionsToFile(const std::string &file_path)
|
||||||
|
{
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
// Crea y abre el fichero de texto
|
||||||
|
std::ofstream file(file_path);
|
||||||
|
|
||||||
|
if (file.good())
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << file_path << " open for writing" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << file_path << " can't be opened" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Escribe en el fichero
|
||||||
|
file << "## VERSION\n";
|
||||||
|
file << "configVersion=" + options.configVersion + "\n";
|
||||||
|
|
||||||
|
file << "\n## CONTROL OPTIONS\n";
|
||||||
|
file << "## keys = CURSOR | OPQA | WASD\n";
|
||||||
|
if (options.keys == ctrl_cursor)
|
||||||
|
{
|
||||||
|
file << "keys=CURSOR\n";
|
||||||
|
}
|
||||||
|
else if (options.keys == ctrl_opqa)
|
||||||
|
{
|
||||||
|
file << "keys=OPQA\n";
|
||||||
|
}
|
||||||
|
else if (options.keys == ctrl_wasd)
|
||||||
|
{
|
||||||
|
file << "keys=WASD\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "\n## VISUAL OPTIONS\n";
|
||||||
|
if (options.videoMode == 0)
|
||||||
|
{
|
||||||
|
file << "videoMode=0\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (options.videoMode == SDL_WINDOW_FULLSCREEN)
|
||||||
|
{
|
||||||
|
file << "videoMode=SDL_WINDOW_FULLSCREEN\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (options.videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
|
{
|
||||||
|
file << "videoMode=SDL_WINDOW_FULLSCREEN_DESKTOP\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "windowSize=" + std::to_string(options.windowSize) + "\n";
|
||||||
|
|
||||||
|
if (options.filter == FILTER_NEAREST)
|
||||||
|
{
|
||||||
|
file << "filter=FILTER_NEAREST\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file << "filter=FILTER_LINEAR\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "shaders=" + boolToString(options.shaders) + "\n";
|
||||||
|
file << "vSync=" + boolToString(options.vSync) + "\n";
|
||||||
|
file << "integerScale=" + boolToString(options.integerScale) + "\n";
|
||||||
|
file << "keepAspect=" + boolToString(options.keepAspect) + "\n";
|
||||||
|
file << "borderEnabled=" + boolToString(options.borderEnabled) + "\n";
|
||||||
|
file << "borderWidth=" + std::to_string(options.borderWidth) + "\n";
|
||||||
|
file << "borderHeight=" + std::to_string(options.borderHeight) + "\n";
|
||||||
|
file << "palette=" + std::to_string(options.palette) + "\n";
|
||||||
|
|
||||||
|
file << "\n## NOTIFICATION OPTIONS\n";
|
||||||
|
file << "## notifications.posV = pos_top | pos_bottom\n";
|
||||||
|
if (options.notifications.posV == pos_top)
|
||||||
|
{
|
||||||
|
file << "notifications.posV=pos_top\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file << "notifications.posV=pos_bottom\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "## notifications.posH = pos_left | pos_middle | pos_right\n";
|
||||||
|
if (options.notifications.posH == pos_left)
|
||||||
|
{
|
||||||
|
file << "notifications.posH=pos_left\n";
|
||||||
|
}
|
||||||
|
else if (options.notifications.posH == pos_middle)
|
||||||
|
{
|
||||||
|
file << "notifications.posH=pos_middle\n";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
file << "notifications.posH=pos_right\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "notifications.sound=" + boolToString(options.notifications.sound) + "\n";
|
||||||
|
|
||||||
|
// Cierra el fichero
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool setOptions(std::string var, std::string value)
|
||||||
|
{
|
||||||
|
// Indicador de éxito en la asignación
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
|
if (var == "configVersion")
|
||||||
|
{
|
||||||
|
options.configVersion = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "keys")
|
||||||
|
{
|
||||||
|
if (value == "OPQA")
|
||||||
|
{
|
||||||
|
options.keys = ctrl_opqa;
|
||||||
|
}
|
||||||
|
else if (value == "WASD")
|
||||||
|
{
|
||||||
|
options.keys = ctrl_wasd;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options.keys = ctrl_cursor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "videoMode")
|
||||||
|
{
|
||||||
|
if (value == "SDL_WINDOW_FULLSCREEN_DESKTOP")
|
||||||
|
{
|
||||||
|
options.videoMode = SDL_WINDOW_FULLSCREEN_DESKTOP;
|
||||||
|
}
|
||||||
|
else if (value == "SDL_WINDOW_FULLSCREEN")
|
||||||
|
{
|
||||||
|
options.videoMode = SDL_WINDOW_FULLSCREEN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options.videoMode = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "windowSize")
|
||||||
|
{
|
||||||
|
options.windowSize = std::stoi(value);
|
||||||
|
if ((options.windowSize < 1) || (options.windowSize > 4))
|
||||||
|
{
|
||||||
|
options.windowSize = 3;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "filter")
|
||||||
|
{
|
||||||
|
if (value == "FILTER_LINEAR")
|
||||||
|
{
|
||||||
|
options.filter = FILTER_LINEAR;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options.filter = FILTER_NEAREST;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "shaders")
|
||||||
|
{
|
||||||
|
options.shaders = stringToBool(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "vSync")
|
||||||
|
{
|
||||||
|
options.vSync = stringToBool(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "integerScale")
|
||||||
|
{
|
||||||
|
options.integerScale = stringToBool(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "keepAspect")
|
||||||
|
{
|
||||||
|
options.keepAspect = stringToBool(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "borderEnabled")
|
||||||
|
{
|
||||||
|
options.borderEnabled = stringToBool(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "borderWidth")
|
||||||
|
{
|
||||||
|
options.borderWidth = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "borderHeight")
|
||||||
|
{
|
||||||
|
options.borderHeight = std::stoi(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "palette")
|
||||||
|
{
|
||||||
|
const int pal = std::stoi(value);
|
||||||
|
|
||||||
|
if (pal == 0)
|
||||||
|
{
|
||||||
|
options.palette = p_zxspectrum;
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (pal == 1)
|
||||||
|
{
|
||||||
|
options.palette = p_zxarne;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "notifications.posH")
|
||||||
|
{
|
||||||
|
if (value == "pos_left")
|
||||||
|
{
|
||||||
|
options.notifications.posH = pos_left;
|
||||||
|
}
|
||||||
|
else if (value == "pos_middle")
|
||||||
|
{
|
||||||
|
options.notifications.posH = pos_middle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options.notifications.posH = pos_right;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "notifications.posV")
|
||||||
|
{
|
||||||
|
if (value == "pos_top")
|
||||||
|
{
|
||||||
|
options.notifications.posV = pos_top;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
options.notifications.posV = pos_bottom;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "notifications.sound")
|
||||||
|
{
|
||||||
|
options.notifications.sound = stringToBool(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (var == "" || var.substr(0, 1) == "#")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
101
source/options.h
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||||
|
#include <string> // Para string, basic_string
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
// Posiciones de las notificaciones
|
||||||
|
enum not_pos_e
|
||||||
|
{
|
||||||
|
pos_top,
|
||||||
|
pos_bottom,
|
||||||
|
pos_left,
|
||||||
|
pos_middle,
|
||||||
|
pos_right
|
||||||
|
};
|
||||||
|
|
||||||
|
// Tipos de control de teclado
|
||||||
|
enum ctrl_schem_e
|
||||||
|
{
|
||||||
|
ctrl_cursor,
|
||||||
|
ctrl_opqa,
|
||||||
|
ctrl_wasd
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para las opciones de las notificaciones
|
||||||
|
struct op_notification_t
|
||||||
|
{
|
||||||
|
not_pos_e posH; // Ubicación de las notificaciones en pantalla
|
||||||
|
not_pos_e posV; // Ubicación de las notificaciones en pantalla
|
||||||
|
bool sound; // Indica si las notificaciones suenan
|
||||||
|
color_t color; // Color de las notificaciones
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para saber la seccion y subseccion del programa
|
||||||
|
struct section_t
|
||||||
|
{
|
||||||
|
Uint8 name;
|
||||||
|
Uint8 subsection;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para albergar trucos
|
||||||
|
struct cheat_t
|
||||||
|
{
|
||||||
|
bool infiniteLives; // Indica si el jugador dispone de vidas infinitas
|
||||||
|
bool invincible; // Indica si el jugador puede morir
|
||||||
|
bool jailEnabled; // Indica si la Jail está abierta
|
||||||
|
bool altSkin; // Indicxa si se usa una skin diferente para el jugador
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura para almacenar estadísticas
|
||||||
|
struct op_stats_t
|
||||||
|
{
|
||||||
|
int rooms; // Cantidad de habitaciones visitadas
|
||||||
|
int items; // Cantidad de items obtenidos
|
||||||
|
std::string worstNightmare; // Habitación con más muertes acumuladas
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura con opciones de la pantalla
|
||||||
|
struct op_screen_t
|
||||||
|
{
|
||||||
|
int windowWidth; // Ancho de la ventana
|
||||||
|
int windowHeight; // Alto de la ventana
|
||||||
|
};
|
||||||
|
|
||||||
|
// Estructura con todas las opciones de configuración del programa
|
||||||
|
struct options_t
|
||||||
|
{
|
||||||
|
std::string configVersion; // Versión del programa. Sirve para saber si las opciones son compatibles
|
||||||
|
Uint32 videoMode; // Contiene el valor del modo de pantalla completa
|
||||||
|
int windowSize; // Contiene el valor por el que se multiplica el tamaño de la ventana
|
||||||
|
Uint32 filter; // Filtro usado para el escalado de la imagen
|
||||||
|
bool vSync; // Indica si se quiere usar vsync o no
|
||||||
|
bool shaders; // Indica si se van a usar shaders o no
|
||||||
|
int gameWidth; // Ancho de la resolucion nativa del juego
|
||||||
|
int gameHeight; // Alto de la resolucion nativa del juego
|
||||||
|
bool integerScale; // Indica si el escalado de la imagen ha de ser entero en el modo a pantalla completa
|
||||||
|
bool keepAspect; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||||
|
bool borderEnabled; // Indica si ha de mostrar el borde en el modo de ventana
|
||||||
|
int borderWidth; // Cantidad de pixels que se añade en el borde de la ventana
|
||||||
|
int borderHeight; // Cantidad de pixels que se añade en el borde de la ventana
|
||||||
|
palette_e palette; // Paleta de colores a usar en el juego
|
||||||
|
bool console; // Indica si ha de mostrar información por la consola de texto
|
||||||
|
cheat_t cheat; // Contiene trucos y ventajas para el juego
|
||||||
|
op_stats_t stats; // Datos con las estadisticas de juego
|
||||||
|
op_notification_t notifications; // Opciones relativas a las notificaciones;
|
||||||
|
op_screen_t screen; // Opciones relativas a la clase screen
|
||||||
|
ctrl_schem_e keys; // Teclas usadas para jugar
|
||||||
|
section_t section; // Sección actual del programa
|
||||||
|
};
|
||||||
|
|
||||||
|
extern options_t options;
|
||||||
|
|
||||||
|
// Crea e inicializa las opciones del programa
|
||||||
|
void initOptions();
|
||||||
|
|
||||||
|
// Carga las opciones desde un fichero
|
||||||
|
bool loadOptionsFromFile(const std::string &file_path);
|
||||||
|
|
||||||
|
// Guarda las opciones a un fichero
|
||||||
|
bool saveOptionsToFile(const std::string &file_path);
|
||||||
180
source/paleta.cpp
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
#include "paleta.h"
|
||||||
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_ARGB8888
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
|
#include <fcntl.h> // Para SEEK_END, SEEK_SET
|
||||||
|
#include <stdio.h> // Para NULL, fseek, fclose, fopen, fread, ftell
|
||||||
|
#include <stdlib.h> // Para malloc, free
|
||||||
|
#include "gif.c" // Para LoadGif, LoadPalette
|
||||||
|
|
||||||
|
struct jSurface_s
|
||||||
|
{
|
||||||
|
Uint8 *data;
|
||||||
|
Uint16 w, h;
|
||||||
|
};
|
||||||
|
|
||||||
|
static SDL_Texture *jTex = NULL;
|
||||||
|
static jSurface jScreen;
|
||||||
|
static jSurface jDestSurf;
|
||||||
|
static jSurface jSourceSurf = NULL;
|
||||||
|
static Uint32 paleta[256];
|
||||||
|
static int jWidth = 256;
|
||||||
|
static int jHeight = 128;
|
||||||
|
static int transparentColor = 255;
|
||||||
|
|
||||||
|
void pInit(SDL_Renderer *renderer, int w, int h)
|
||||||
|
{
|
||||||
|
jWidth = w;
|
||||||
|
jHeight = h;
|
||||||
|
jTex = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, w, h);
|
||||||
|
jScreen = pNewSurface(w, h);
|
||||||
|
jDestSurf = jScreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
jSurface pNewSurface(int w, int h)
|
||||||
|
{
|
||||||
|
jSurface surf = (jSurface)malloc(sizeof(jSurface_s));
|
||||||
|
surf->w = w;
|
||||||
|
surf->h = h;
|
||||||
|
surf->data = (Uint8 *)malloc(w * h);
|
||||||
|
return surf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pDeleteSurface(jSurface surf)
|
||||||
|
{
|
||||||
|
if (surf == NULL)
|
||||||
|
return;
|
||||||
|
if (surf->data != NULL)
|
||||||
|
free(surf->data);
|
||||||
|
free(surf);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pSetDest(jSurface surf)
|
||||||
|
{
|
||||||
|
if (surf == NULL)
|
||||||
|
jDestSurf = jScreen;
|
||||||
|
else
|
||||||
|
jDestSurf = surf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pSetSource(jSurface surf)
|
||||||
|
{
|
||||||
|
jSourceSurf = surf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pBlit(int dx, int dy, int sx, int sy, int w, int h)
|
||||||
|
{
|
||||||
|
if (jSourceSurf == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (int iy = 0; iy < h; ++iy)
|
||||||
|
{
|
||||||
|
for (int ix = 0; ix < w; ++ix)
|
||||||
|
pPutPixel(dx + ix, dy + iy, pGetPixel(sx + ix, sy + iy));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
jSurface pLoadSurface(const char *filename)
|
||||||
|
{
|
||||||
|
FILE *f = fopen(filename, "rb");
|
||||||
|
if (!f)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
long size = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
Uint8 *buffer = (Uint8 *)malloc(size);
|
||||||
|
fread(buffer, size, 1, f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
Uint16 w, h;
|
||||||
|
Uint8 *pixels = LoadGif(buffer, &w, &h);
|
||||||
|
if (pixels == NULL)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
jSurface surf = (jSurface)malloc(sizeof(jSurface_s));
|
||||||
|
surf->w = w;
|
||||||
|
surf->h = h;
|
||||||
|
surf->data = pixels;
|
||||||
|
free(buffer);
|
||||||
|
return surf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pLoadPal(const char *filename)
|
||||||
|
{
|
||||||
|
FILE *f = fopen(filename, "rb");
|
||||||
|
if (!f)
|
||||||
|
return;
|
||||||
|
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
long size = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
Uint8 *buffer = (Uint8 *)malloc(size);
|
||||||
|
fread(buffer, size, 1, f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
Uint32 *pal = LoadPalette(buffer);
|
||||||
|
if (pal == NULL)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
free(buffer);
|
||||||
|
for (int i = 0; i < 256; ++i)
|
||||||
|
{
|
||||||
|
paleta[i] = pal[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void pSetPal(int index, Uint32 color)
|
||||||
|
{
|
||||||
|
paleta[index] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pCls(Uint8 color)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < jDestSurf->w * jDestSurf->h; ++i)
|
||||||
|
jDestSurf->data[i] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void pFlip(SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
Uint32 *pixels;
|
||||||
|
int pitch;
|
||||||
|
SDL_LockTexture(jTex, NULL, (void **)&pixels, &pitch);
|
||||||
|
for (int i = 0; i < jWidth * jHeight; ++i)
|
||||||
|
pixels[i] = paleta[jScreen->data[i]];
|
||||||
|
SDL_UnlockTexture(jTex);
|
||||||
|
SDL_Rect rect = {0, 64, 256, 128};
|
||||||
|
SDL_RenderCopy(renderer, jTex, NULL, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pPutPixel(int x, int y, Uint8 color)
|
||||||
|
{
|
||||||
|
if (x < 0 || y < 0 || x >= jDestSurf->w || y >= jDestSurf->h || color == transparentColor)
|
||||||
|
return;
|
||||||
|
jDestSurf->data[x + y * jDestSurf->w] = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8 pGetPixel(int x, int y)
|
||||||
|
{
|
||||||
|
return jSourceSurf->data[x + y * jSourceSurf->w];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFadePal()
|
||||||
|
{
|
||||||
|
// Colores pares
|
||||||
|
for (int i = 18; i > 0; i = i - 2)
|
||||||
|
{
|
||||||
|
paleta[i] = paleta[i - 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Colores impares
|
||||||
|
for (int i = 17; i > 1; i = i - 2)
|
||||||
|
{
|
||||||
|
paleta[i] = paleta[i - 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
paleta[1] = paleta[0];
|
||||||
|
|
||||||
|
return paleta[15] == paleta[0] ? true : false;
|
||||||
|
}
|
||||||
29
source/paleta.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
|
#include <SDL2/SDL_stdinc.h> // Para Uint8, Uint32
|
||||||
|
|
||||||
|
typedef struct jSurface_s *jSurface;
|
||||||
|
|
||||||
|
jSurface pNewSurface(int w, int h);
|
||||||
|
void pDeleteSurface(jSurface surf);
|
||||||
|
void pSetDest(jSurface surf);
|
||||||
|
void pSetSource(jSurface surf);
|
||||||
|
|
||||||
|
jSurface pLoadSurface(const char *filename);
|
||||||
|
|
||||||
|
void pPutPixel(int x, int y, Uint8 color);
|
||||||
|
Uint8 pGetPixel(int x, int y);
|
||||||
|
|
||||||
|
void pBlit(int dx, int dy, int sx, int sy, int w, int h);
|
||||||
|
|
||||||
|
void pInit(SDL_Renderer *renderer, int w, int h);
|
||||||
|
|
||||||
|
void pSetPal(int index, Uint32 color);
|
||||||
|
void pLoadPal(const char *filename);
|
||||||
|
|
||||||
|
void pCls(Uint8 color);
|
||||||
|
|
||||||
|
void pFlip(SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
bool pFadePal();
|
||||||
@@ -1,21 +1,31 @@
|
|||||||
|
// IWYU pragma: no_include <bits/std_abs.h>
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include <fstream>
|
#include <stdlib.h> // Para rand
|
||||||
#include <sstream>
|
#include <algorithm> // Para max, min
|
||||||
|
#include <cmath> // Para ceil, abs
|
||||||
|
#include "animatedsprite.h" // Para AnimatedSprite
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "const.h" // Para BORDER_TOP, BLOCK, BORDER_BOTTOM, BORDER...
|
||||||
|
#include "debug.h" // Para Debug
|
||||||
|
#include "input.h" // Para Input, inputs_e
|
||||||
|
#include "jail_audio.h" // Para JA_LoadSound, JA_Sound_t, JA_PlaySound
|
||||||
|
#include "resource.h" // Para Resource
|
||||||
|
#include "room.h" // Para Room, tile_e
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "options.h"
|
||||||
|
#include "screen.h"
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Player::Player(player_t player)
|
Player::Player(player_t player)
|
||||||
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
|
input_(Input::get()),
|
||||||
|
resource_(Resource::get()),
|
||||||
|
asset_(Asset::get()),
|
||||||
|
room_(player.room),
|
||||||
|
debug_(Debug::get())
|
||||||
{
|
{
|
||||||
// Obten punteros a objetos
|
|
||||||
this->resource = player.resource;
|
|
||||||
this->asset = player.asset;
|
|
||||||
this->renderer = player.renderer;
|
|
||||||
this->input = player.input;
|
|
||||||
this->room = player.room;
|
|
||||||
this->debug = player.debug;
|
|
||||||
this->options = player.options;
|
|
||||||
|
|
||||||
// Crea objetos
|
// Crea objetos
|
||||||
sprite = new AnimatedSprite(renderer, resource->getAnimation(player.animation));
|
sprite_ = new AnimatedSprite(renderer_, resource_->getAnimation(player.animation));
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
reLoadPalette();
|
reLoadPalette();
|
||||||
@@ -38,14 +48,14 @@ Player::Player(player_t player)
|
|||||||
h = 16;
|
h = 16;
|
||||||
maxVY = 1.2f;
|
maxVY = 1.2f;
|
||||||
|
|
||||||
sprite->setPosX(player.spawn.x);
|
sprite_->setPosX(player.spawn.x);
|
||||||
sprite->setPosY(player.spawn.y);
|
sprite_->setPosY(player.spawn.y);
|
||||||
sprite->setWidth(8);
|
sprite_->setWidth(8);
|
||||||
sprite->setHeight(16);
|
sprite_->setHeight(16);
|
||||||
|
|
||||||
sprite->setFlipH(player.spawn.flipH);
|
sprite_->setFlipH(player.spawn.flipH);
|
||||||
sprite->setCurrentAnimation("walk");
|
sprite_->setCurrentAnimation("walk");
|
||||||
sprite->animate();
|
sprite_->animate();
|
||||||
|
|
||||||
lastPosition = getRect();
|
lastPosition = getRect();
|
||||||
colliderBox = getRect();
|
colliderBox = getRect();
|
||||||
@@ -53,45 +63,45 @@ Player::Player(player_t player)
|
|||||||
colliderPoints.insert(colliderPoints.end(), {p, p, p, p, p, p, p, p});
|
colliderPoints.insert(colliderPoints.end(), {p, p, p, p, p, p, p, p});
|
||||||
underFeet.insert(underFeet.end(), {p, p});
|
underFeet.insert(underFeet.end(), {p, p});
|
||||||
feet.insert(feet.end(), {p, p});
|
feet.insert(feet.end(), {p, p});
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump1.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump1.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump2.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump2.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump3.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump3.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump4.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump4.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump5.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump5.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump6.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump6.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump7.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump7.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump8.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump8.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump9.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump9.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump10.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump10.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump11.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump11.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump12.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump12.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump13.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump13.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump14.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump14.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump15.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump15.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump16.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump16.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump17.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump17.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump18.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump18.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump19.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump19.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump20.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump20.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump21.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump21.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump22.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump22.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump23.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump23.wav").c_str()));
|
||||||
jumpSound.push_back(JA_LoadSound(asset->get("jump24.wav").c_str()));
|
jumpSound.push_back(JA_LoadSound(asset_->get("jump24.wav").c_str()));
|
||||||
|
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump11.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump11.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump12.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump12.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump13.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump13.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump14.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump14.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump15.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump15.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump16.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump16.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump17.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump17.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump18.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump18.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump19.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump19.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump20.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump20.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump21.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump21.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump22.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump22.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump23.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump23.wav").c_str()));
|
||||||
fallSound.push_back(JA_LoadSound(asset->get("jump24.wav").c_str()));
|
fallSound.push_back(JA_LoadSound(asset_->get("jump24.wav").c_str()));
|
||||||
|
|
||||||
jumpCounter = 0;
|
jumpCounter = 0;
|
||||||
fallCounter = 0;
|
fallCounter = 0;
|
||||||
@@ -107,7 +117,7 @@ Player::Player(player_t player)
|
|||||||
// Destructor
|
// Destructor
|
||||||
Player::~Player()
|
Player::~Player()
|
||||||
{
|
{
|
||||||
delete sprite;
|
delete sprite_;
|
||||||
|
|
||||||
for (auto s : jumpSound)
|
for (auto s : jumpSound)
|
||||||
{
|
{
|
||||||
@@ -118,38 +128,38 @@ Player::~Player()
|
|||||||
// Pinta el jugador en pantalla
|
// Pinta el jugador en pantalla
|
||||||
void Player::render()
|
void Player::render()
|
||||||
{
|
{
|
||||||
sprite->getTexture()->setColor(color.r, color.g, color.b);
|
sprite_->getTexture()->setColor(color.r, color.g, color.b);
|
||||||
sprite->render();
|
sprite_->render();
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (debug->getEnabled())
|
if (debug_->getEnabled())
|
||||||
{
|
{
|
||||||
// Pinta los underfeet
|
// Pinta los underfeet
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 0, 255, 255);
|
SDL_SetRenderDrawColor(renderer_, 255, 0, 255, 255);
|
||||||
SDL_RenderDrawPoint(renderer, underFeet[0].x, underFeet[0].y);
|
SDL_RenderDrawPoint(renderer_, underFeet[0].x, underFeet[0].y);
|
||||||
SDL_RenderDrawPoint(renderer, underFeet[1].x, underFeet[1].y);
|
SDL_RenderDrawPoint(renderer_, underFeet[1].x, underFeet[1].y);
|
||||||
|
|
||||||
// Pinta rectangulo del jugador
|
// Pinta rectangulo del jugador
|
||||||
SDL_SetRenderDrawColor(renderer, debugColor.r, debugColor.g, debugColor.b, 192);
|
SDL_SetRenderDrawColor(renderer_, debugColor.r, debugColor.g, debugColor.b, 192);
|
||||||
SDL_Rect rect = getRect();
|
SDL_Rect rect = getRect();
|
||||||
SDL_RenderFillRect(renderer, &rect);
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 255);
|
SDL_SetRenderDrawColor(renderer_, 0, 255, 255, 255);
|
||||||
SDL_RenderDrawRect(renderer, &rect);
|
SDL_RenderDrawRect(renderer_, &rect);
|
||||||
|
|
||||||
// Pinta el rectangulo de movimiento
|
// Pinta el rectangulo de movimiento
|
||||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
SDL_SetRenderDrawColor(renderer_, 255, 0, 0, 255);
|
||||||
if (vx != 0.0f)
|
if (vx != 0.0f)
|
||||||
{
|
{
|
||||||
SDL_RenderFillRect(renderer, &rx);
|
SDL_RenderFillRect(renderer_, &rx);
|
||||||
}
|
}
|
||||||
if (vy != 0.0f)
|
if (vy != 0.0f)
|
||||||
{
|
{
|
||||||
SDL_RenderFillRect(renderer, &ry);
|
SDL_RenderFillRect(renderer_, &ry);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el punto de debug
|
// Pinta el punto de debug
|
||||||
SDL_SetRenderDrawColor(renderer, rand() % 256, rand() % 256, rand() % 256, 255);
|
SDL_SetRenderDrawColor(renderer_, rand() % 256, rand() % 256, rand() % 256, 255);
|
||||||
SDL_RenderDrawPoint(renderer, debugPoint.x, debugPoint.y);
|
SDL_RenderDrawPoint(renderer_, debugPoint.x, debugPoint.y);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -181,16 +191,16 @@ void Player::checkInput()
|
|||||||
|
|
||||||
if (!autoMovement)
|
if (!autoMovement)
|
||||||
{ // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
|
{ // Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
|
||||||
if (input->checkInput(INPUT_LEFT, REPEAT_TRUE))
|
if (input_->checkInput(input_left))
|
||||||
{
|
{
|
||||||
vx = -0.6f;
|
vx = -0.6f;
|
||||||
sprite->setFlipH(true);
|
sprite_->setFlipH(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (input->checkInput(INPUT_RIGHT, REPEAT_TRUE))
|
else if (input_->checkInput(input_right))
|
||||||
{
|
{
|
||||||
vx = 0.6f;
|
vx = 0.6f;
|
||||||
sprite->setFlipH(false);
|
sprite_->setFlipH(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -204,19 +214,19 @@ void Player::checkInput()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{ // El movimiento lo proporciona la superficie
|
{ // El movimiento lo proporciona la superficie
|
||||||
vx = 0.6f * room->getAutoSurfaceDirection();
|
vx = 0.6f * room_->getAutoSurfaceDirection();
|
||||||
|
|
||||||
if (vx > 0.0f)
|
if (vx > 0.0f)
|
||||||
{
|
{
|
||||||
sprite->setFlipH(false);
|
sprite_->setFlipH(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sprite->setFlipH(true);
|
sprite_->setFlipH(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input->checkInput(INPUT_UP, REPEAT_TRUE))
|
if (input_->checkInput(input_jump))
|
||||||
{
|
{
|
||||||
// Solo puede saltar si ademas de estar (state == s_standing)
|
// Solo puede saltar si ademas de estar (state == s_standing)
|
||||||
// Esta sobre el suelo, rampa o suelo que se mueve
|
// Esta sobre el suelo, rampa o suelo que se mueve
|
||||||
@@ -398,7 +408,7 @@ void Player::move()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión con las superficies
|
// Comprueba la colisión con las superficies
|
||||||
const int pos = room->checkRightSurfaces(&proj);
|
const int pos = room_->checkRightSurfaces(&proj);
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
if (pos == -1)
|
if (pos == -1)
|
||||||
@@ -414,7 +424,7 @@ void Player::move()
|
|||||||
if (state != s_jumping)
|
if (state != s_jumping)
|
||||||
{
|
{
|
||||||
v_line_t leftSide = {(int)x, (int)y + h - 2, (int)y + h - 1}; // Comprueba solo los dos pixels de abajo
|
v_line_t leftSide = {(int)x, (int)y + h - 2, (int)y + h - 1}; // Comprueba solo los dos pixels de abajo
|
||||||
const int ly = room->checkLeftSlopes(&leftSide);
|
const int ly = room_->checkLeftSlopes(&leftSide);
|
||||||
if (ly > -1)
|
if (ly > -1)
|
||||||
{
|
{
|
||||||
y = ly - h;
|
y = ly - h;
|
||||||
@@ -443,7 +453,7 @@ void Player::move()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión
|
// Comprueba la colisión
|
||||||
const int pos = room->checkLeftSurfaces(&proj);
|
const int pos = room_->checkLeftSurfaces(&proj);
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
if (pos == -1)
|
if (pos == -1)
|
||||||
@@ -459,7 +469,7 @@ void Player::move()
|
|||||||
if (state != s_jumping)
|
if (state != s_jumping)
|
||||||
{
|
{
|
||||||
v_line_t rightSide = {(int)x + w - 1, (int)y + h - 2, (int)y + h - 1}; // Comprueba solo los dos pixels de abajo
|
v_line_t rightSide = {(int)x + w - 1, (int)y + h - 2, (int)y + h - 1}; // Comprueba solo los dos pixels de abajo
|
||||||
const int ry = room->checkRightSlopes(&rightSide);
|
const int ry = room_->checkRightSlopes(&rightSide);
|
||||||
if (ry > -1)
|
if (ry > -1)
|
||||||
{
|
{
|
||||||
y = ry - h;
|
y = ry - h;
|
||||||
@@ -504,7 +514,7 @@ void Player::move()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión
|
// Comprueba la colisión
|
||||||
const int pos = room->checkBottomSurfaces(&proj);
|
const int pos = room_->checkBottomSurfaces(&proj);
|
||||||
|
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
if (pos == -1)
|
if (pos == -1)
|
||||||
@@ -533,7 +543,7 @@ void Player::move()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Comprueba la colisión con las superficies normales y las automáticas
|
// Comprueba la colisión con las superficies normales y las automáticas
|
||||||
const int pos = std::max(room->checkTopSurfaces(&proj), room->checkAutoSurfaces(&proj));
|
const int pos = std::max(room_->checkTopSurfaces(&proj), room_->checkAutoSurfaces(&proj));
|
||||||
if (pos > -1)
|
if (pos > -1)
|
||||||
{ // Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
{ // Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
||||||
y = pos - h;
|
y = pos - h;
|
||||||
@@ -548,7 +558,7 @@ void Player::move()
|
|||||||
{ // Las rampas no se miran si se está saltando
|
{ // Las rampas no se miran si se está saltando
|
||||||
v_line_t leftSide = {proj.x, proj.y, proj.y + proj.h - 1};
|
v_line_t leftSide = {proj.x, proj.y, proj.y + proj.h - 1};
|
||||||
v_line_t rightSide = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1};
|
v_line_t rightSide = {proj.x + proj.w - 1, proj.y, proj.y + proj.h - 1};
|
||||||
const int p = std::max(room->checkRightSlopes(&rightSide), room->checkLeftSlopes(&leftSide));
|
const int p = std::max(room_->checkRightSlopes(&rightSide), room_->checkLeftSlopes(&leftSide));
|
||||||
if (p > -1)
|
if (p > -1)
|
||||||
{ // No está saltando y hay colisión con una rampa
|
{ // No está saltando y hay colisión con una rampa
|
||||||
// Calcula la nueva posición
|
// Calcula la nueva posición
|
||||||
@@ -577,12 +587,12 @@ void Player::move()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza la posición del sprite
|
// Actualiza la posición del sprite
|
||||||
sprite->setPosX(x);
|
sprite_->setPosX(x);
|
||||||
sprite->setPosY(y);
|
sprite_->setPosY(y);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug->add("RECT_X: " + std::to_string(rx.x) + "," + std::to_string(rx.y) + "," + std::to_string(rx.w) + "," + std::to_string(rx.h));
|
debug_->add("RECT_X: " + std::to_string(rx.x) + "," + std::to_string(rx.y) + "," + std::to_string(rx.w) + "," + std::to_string(rx.h));
|
||||||
debug->add("RECT_Y: " + std::to_string(ry.x) + "," + std::to_string(ry.y) + "," + std::to_string(ry.w) + "," + std::to_string(ry.h));
|
debug_->add("RECT_Y: " + std::to_string(ry.x) + "," + std::to_string(ry.y) + "," + std::to_string(ry.w) + "," + std::to_string(ry.h));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,7 +601,7 @@ void Player::animate()
|
|||||||
{
|
{
|
||||||
if (vx != 0)
|
if (vx != 0)
|
||||||
{
|
{
|
||||||
sprite->animate();
|
sprite_->animate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -621,7 +631,7 @@ void Player::playJumpSound()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug->add("JUMP: " + std::to_string(jumpCounter / 4));
|
debug_->add("JUMP: " + std::to_string(jumpCounter / 4));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -634,7 +644,7 @@ void Player::playFallSound()
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
debug->add("FALL: " + std::to_string(fallCounter / 4));
|
debug_->add("FALL: " + std::to_string(fallCounter / 4));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -650,28 +660,28 @@ bool Player::isOnFloor()
|
|||||||
// Comprueba las superficies
|
// Comprueba las superficies
|
||||||
for (auto f : underFeet)
|
for (auto f : underFeet)
|
||||||
{
|
{
|
||||||
onFloor |= room->checkTopSurfaces(&f);
|
onFloor |= room_->checkTopSurfaces(&f);
|
||||||
onFloor |= room->checkAutoSurfaces(&f);
|
onFloor |= room_->checkAutoSurfaces(&f);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Comprueba las rampas
|
// Comprueba las rampas
|
||||||
onSlopeL = room->checkLeftSlopes(&underFeet[0]);
|
onSlopeL = room_->checkLeftSlopes(&underFeet[0]);
|
||||||
onSlopeR = room->checkRightSlopes(&underFeet[1]);
|
onSlopeR = room_->checkRightSlopes(&underFeet[1]);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (onFloor)
|
if (onFloor)
|
||||||
{
|
{
|
||||||
debug->add("ON_FLOOR");
|
debug_->add("ON_FLOOR");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onSlopeL)
|
if (onSlopeL)
|
||||||
{
|
{
|
||||||
debug->add("ON_SLOPE_L: " + std::to_string(underFeet[0].x) + "," + std::to_string(underFeet[0].y));
|
debug_->add("ON_SLOPE_L: " + std::to_string(underFeet[0].x) + "," + std::to_string(underFeet[0].y));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (onSlopeR)
|
if (onSlopeR)
|
||||||
{
|
{
|
||||||
debug->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y));
|
debug_->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -688,13 +698,13 @@ bool Player::isOnAutoSurface()
|
|||||||
// Comprueba las superficies
|
// Comprueba las superficies
|
||||||
for (auto f : underFeet)
|
for (auto f : underFeet)
|
||||||
{
|
{
|
||||||
onAutoSurface |= room->checkAutoSurfaces(&f);
|
onAutoSurface |= room_->checkAutoSurfaces(&f);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (onAutoSurface)
|
if (onAutoSurface)
|
||||||
{
|
{
|
||||||
debug->add("ON_AUTO_SURFACE");
|
debug_->add("ON_AUTO_SURFACE");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -714,13 +724,13 @@ bool Player::isOnDownSlope()
|
|||||||
underFeet[1].y += 1;
|
underFeet[1].y += 1;
|
||||||
|
|
||||||
// Comprueba las rampas
|
// Comprueba las rampas
|
||||||
onSlope |= room->checkLeftSlopes(&underFeet[0]);
|
onSlope |= room_->checkLeftSlopes(&underFeet[0]);
|
||||||
onSlope |= room->checkRightSlopes(&underFeet[1]);
|
onSlope |= room_->checkRightSlopes(&underFeet[1]);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (onSlope)
|
if (onSlope)
|
||||||
{
|
{
|
||||||
debug->add("ON_DOWN_SLOPE");
|
debug_->add("ON_DOWN_SLOPE");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -738,7 +748,7 @@ bool Player::checkKillingTiles()
|
|||||||
|
|
||||||
for (auto c : colliderPoints)
|
for (auto c : colliderPoints)
|
||||||
{
|
{
|
||||||
check |= (room->getTile(c) == t_kill);
|
check |= (room_->getTile(c) == t_kill);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mata al jugador si hay colisión
|
// Mata al jugador si hay colisión
|
||||||
@@ -761,7 +771,7 @@ playerSpawn_t Player::getSpawnParams()
|
|||||||
params.vy = vy;
|
params.vy = vy;
|
||||||
params.jumpIni = jumpIni;
|
params.jumpIni = jumpIni;
|
||||||
params.state = state;
|
params.state = state;
|
||||||
params.flipH = sprite->getFlipH();
|
params.flipH = sprite_->getFlipH();
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
@@ -769,27 +779,27 @@ playerSpawn_t Player::getSpawnParams()
|
|||||||
// Recarga la textura
|
// Recarga la textura
|
||||||
void Player::reLoadTexture()
|
void Player::reLoadTexture()
|
||||||
{
|
{
|
||||||
sprite->getTexture()->reLoad();
|
sprite_->getTexture()->reLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recarga la paleta
|
// Recarga la paleta
|
||||||
void Player::reLoadPalette()
|
void Player::reLoadPalette()
|
||||||
{
|
{
|
||||||
color = stringToColor(options->palette, "white");
|
color = stringToColor(options.palette, "white");
|
||||||
if (options->cheat.infiniteLives)
|
if (options.cheat.infiniteLives)
|
||||||
{
|
{
|
||||||
color = stringToColor(options->palette, "yellow");
|
color = stringToColor(options.palette, "yellow");
|
||||||
}
|
}
|
||||||
if (options->cheat.invincible)
|
if (options.cheat.invincible)
|
||||||
{
|
{
|
||||||
color = stringToColor(options->palette, "cyan");
|
color = stringToColor(options.palette, "cyan");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el valor de la variable
|
// Establece el valor de la variable
|
||||||
void Player::setRoom(Room *room)
|
void Player::setRoom(Room *room)
|
||||||
{
|
{
|
||||||
this->room = room;
|
this->room_ = room;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza los puntos de colisión
|
// Actualiza los puntos de colisión
|
||||||
|
|||||||
@@ -1,19 +1,17 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
#include "common/asset.h"
|
#include <string> // Para basic_string, string
|
||||||
#include "common/debug.h"
|
#include <vector> // Para vector
|
||||||
#include "common/input.h"
|
#include "utils.h" // Para color_t
|
||||||
#include "common/resource.h"
|
class AnimatedSprite;
|
||||||
#include "common/utils.h"
|
class Asset;
|
||||||
#include "const.h"
|
class Debug;
|
||||||
#include "room.h"
|
class Input;
|
||||||
#include <string>
|
class Resource;
|
||||||
#include <vector>
|
class Room;
|
||||||
|
struct JA_Sound_t;
|
||||||
#ifndef PLAYER_H
|
|
||||||
#define PLAYER_H
|
|
||||||
|
|
||||||
enum state_e
|
enum state_e
|
||||||
{
|
{
|
||||||
@@ -38,27 +36,20 @@ struct player_t
|
|||||||
playerSpawn_t spawn;
|
playerSpawn_t spawn;
|
||||||
std::string png;
|
std::string png;
|
||||||
std::string animation;
|
std::string animation;
|
||||||
SDL_Renderer *renderer;
|
|
||||||
Resource *resource;
|
|
||||||
Asset *asset;
|
|
||||||
options_t *options;
|
|
||||||
Input *input;
|
|
||||||
Room *room;
|
Room *room;
|
||||||
Debug *debug;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Player
|
class Player
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
Input *input; // Objeto para gestionar la entrada
|
Input *input_; // Objeto para gestionar la entrada
|
||||||
Resource *resource; // Objeto con los recursos
|
Resource *resource_; // Objeto con los recursos
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
Asset *asset_; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
Room *room; // Objeto encargado de gestionar cada habitación del juego
|
Room *room_; // Objeto encargado de gestionar cada habitación del juego
|
||||||
AnimatedSprite *sprite; // Sprite del enemigo
|
AnimatedSprite *sprite_; // Sprite del jugador
|
||||||
Debug *debug; // Objeto para gestionar la información de debug
|
Debug *debug_; // Objeto para gestionar la información de debug
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
float x; // Posición del jugador en el eje X
|
float x; // Posición del jugador en el eje X
|
||||||
@@ -195,5 +186,3 @@ public:
|
|||||||
// Quita el modo pausa del jugador
|
// Quita el modo pausa del jugador
|
||||||
void resume();
|
void resume();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,12 +1,35 @@
|
|||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include <iostream>
|
#include <iostream> // Para basic_ostream, operator<<, cout, endl
|
||||||
|
#include "animatedsprite.h" // Para animatedSprite_t, loadAnimationFromFile
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "enemy.h" // Para enemy_t
|
||||||
|
#include "item.h" // Para item_t
|
||||||
|
#include "room.h" // Para room_t, loadRoomFile, loadRoomTileFile
|
||||||
|
#include "text.h" // Para textFile_t, LoadTextFile
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "utils.h" // Para options_t
|
||||||
|
#include "screen.h"
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
// Constructor
|
// [SINGLETON]
|
||||||
Resource::Resource(SDL_Renderer *renderer, Asset *asset, options_t *options)
|
Resource *Resource::resource_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
void Resource::init()
|
||||||
{
|
{
|
||||||
this->renderer = renderer;
|
Resource::resource_ = new Resource();
|
||||||
this->asset = asset;
|
}
|
||||||
this->options = options;
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
void Resource::destroy()
|
||||||
|
{
|
||||||
|
delete Resource::resource_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
Resource *Resource::get()
|
||||||
|
{
|
||||||
|
return Resource::resource_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Carga las texturas de una lista
|
// Carga las texturas de una lista
|
||||||
@@ -14,23 +37,23 @@ void Resource::loadTextures(std::vector<std::string> list)
|
|||||||
{
|
{
|
||||||
for (auto l : list)
|
for (auto l : list)
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
|
std::cout << "\nLOAD TEXTURE: " << l << std::endl;
|
||||||
std::cout << "png: " << asset->get(l) << std::endl;
|
std::cout << "png: " << Asset::get()->get(l) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
res_texture_t t;
|
res_texture_t t;
|
||||||
t.name = l;
|
t.name = l;
|
||||||
t.texture = new Texture(renderer, asset->get(t.name), options->console);
|
t.texture = new Texture(Screen::get()->getRenderer(), Asset::get()->get(t.name), options.console);
|
||||||
textures.push_back(t);
|
textures_.push_back(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelve a cargar las texturas
|
// Vuelve a cargar las texturas
|
||||||
void Resource::reLoadTextures()
|
void Resource::reLoadTextures()
|
||||||
{
|
{
|
||||||
for (auto texture : textures)
|
for (auto texture : textures_)
|
||||||
{
|
{
|
||||||
texture.texture->reLoad();
|
texture.texture->reLoad();
|
||||||
}
|
}
|
||||||
@@ -44,17 +67,17 @@ void Resource::loadAnimations(std::vector<std::string> list)
|
|||||||
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
|
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
|
||||||
const std::string pngFile = l.substr(0, l.find_last_of(".")) + ".png";
|
const std::string pngFile = l.substr(0, l.find_last_of(".")) + ".png";
|
||||||
|
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "\nLOAD ANIMATION: " << l << std::endl;
|
std::cout << "\nLOAD ANIMATION: " << l << std::endl;
|
||||||
std::cout << "png: " << asset->get(pngFile) << std::endl;
|
std::cout << "png: " << Asset::get()->get(pngFile) << std::endl;
|
||||||
std::cout << "ani: " << asset->get(l) << std::endl;
|
std::cout << "ani: " << Asset::get()->get(l) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
res_animation_t as;
|
res_animation_t as;
|
||||||
as.name = l;
|
as.name = l;
|
||||||
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(as.name), options->console));
|
as.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), Asset::get()->get(as.name), options.console));
|
||||||
animations.push_back(as);
|
animations_.push_back(as);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,12 +86,12 @@ void Resource::reLoadAnimations()
|
|||||||
{
|
{
|
||||||
// reLoadTextures();
|
// reLoadTextures();
|
||||||
|
|
||||||
for (auto &a : animations)
|
for (auto &a : animations_)
|
||||||
{
|
{
|
||||||
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
|
// Extrae el nombre del fichero sin la extension para crear el nombre del fichero de la textura
|
||||||
const std::string pngFile = a.name.substr(0, a.name.find_last_of(".")) + ".png";
|
const std::string pngFile = a.name.substr(0, a.name.find_last_of(".")) + ".png";
|
||||||
delete a.animation;
|
delete a.animation;
|
||||||
a.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), asset->get(a.name), options->console));
|
a.animation = new animatedSprite_t(loadAnimationFromFile(getTexture(pngFile), Asset::get()->get(a.name), options.console));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,18 +102,18 @@ void Resource::loadOffsets(std::vector<std::string> list)
|
|||||||
{
|
{
|
||||||
res_textOffset_t to;
|
res_textOffset_t to;
|
||||||
to.name = l;
|
to.name = l;
|
||||||
to.textFile = new textFile_t(LoadTextFile(asset->get(l), options->console));
|
to.textFile = new textFile_t(LoadTextFile(Asset::get()->get(l), options.console));
|
||||||
offsets.push_back(to);
|
offsets_.push_back(to);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelve a cargar los offsets
|
// Vuelve a cargar los offsets
|
||||||
void Resource::reLoadOffsets()
|
void Resource::reLoadOffsets()
|
||||||
{
|
{
|
||||||
for (auto &o : offsets)
|
for (auto &o : offsets_)
|
||||||
{
|
{
|
||||||
delete o.textFile;
|
delete o.textFile;
|
||||||
o.textFile = new textFile_t(LoadTextFile(asset->get(o.name), options->console));
|
o.textFile = new textFile_t(LoadTextFile(Asset::get()->get(o.name), options.console));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,18 +124,18 @@ void Resource::loadTileMaps(std::vector<std::string> list)
|
|||||||
{
|
{
|
||||||
res_tileMap_t tm;
|
res_tileMap_t tm;
|
||||||
tm.name = l;
|
tm.name = l;
|
||||||
tm.tileMap = new std::vector<int>(loadRoomTileFile(asset->get(l), options->console));
|
tm.tileMap = new std::vector<int>(loadRoomTileFile(Asset::get()->get(l), options.console));
|
||||||
tileMaps.push_back(tm);
|
tile_maps_.push_back(tm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vuelve a cargar los mapas de tiles
|
// Vuelve a cargar los mapas de tiles
|
||||||
void Resource::reLoadTileMaps()
|
void Resource::reLoadTileMaps()
|
||||||
{
|
{
|
||||||
for (auto &tm : tileMaps)
|
for (auto &tm : tile_maps_)
|
||||||
{
|
{
|
||||||
delete tm.tileMap;
|
delete tm.tileMap;
|
||||||
tm.tileMap = new std::vector<int>(loadRoomTileFile(asset->get(tm.name), options->console));
|
tm.tileMap = new std::vector<int>(loadRoomTileFile(Asset::get()->get(tm.name), options.console));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,7 +146,7 @@ void Resource::loadRooms(std::vector<std::string> list)
|
|||||||
{
|
{
|
||||||
res_room_t r;
|
res_room_t r;
|
||||||
r.name = l;
|
r.name = l;
|
||||||
r.room = new room_t(loadRoomFile(asset->get(l), options->console));
|
r.room = new room_t(loadRoomFile(Asset::get()->get(l), options.console));
|
||||||
r.room->tileMap = getTileMap(r.room->tileMapFile);
|
r.room->tileMap = getTileMap(r.room->tileMapFile);
|
||||||
for (auto &e : r.room->enemies)
|
for (auto &e : r.room->enemies)
|
||||||
{
|
{
|
||||||
@@ -135,7 +158,7 @@ void Resource::loadRooms(std::vector<std::string> list)
|
|||||||
}
|
}
|
||||||
r.room->textureA = getTexture("standard.png");
|
r.room->textureA = getTexture("standard.png");
|
||||||
r.room->textureB = getTexture("standard_zxarne.png");
|
r.room->textureB = getTexture("standard_zxarne.png");
|
||||||
rooms.push_back(r);
|
rooms_.push_back(r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,10 +167,10 @@ void Resource::reLoadRooms()
|
|||||||
{
|
{
|
||||||
reLoadTileMaps();
|
reLoadTileMaps();
|
||||||
|
|
||||||
for (auto &r : rooms)
|
for (auto &r : rooms_)
|
||||||
{
|
{
|
||||||
delete r.room;
|
delete r.room;
|
||||||
r.room = new room_t(loadRoomFile(asset->get(r.name)));
|
r.room = new room_t(loadRoomFile(Asset::get()->get(r.name)));
|
||||||
r.room->tileMap = getTileMap(r.room->tileMapFile);
|
r.room->tileMap = getTileMap(r.room->tileMapFile);
|
||||||
for (auto &e : r.room->enemies)
|
for (auto &e : r.room->enemies)
|
||||||
{
|
{
|
||||||
@@ -173,51 +196,51 @@ void Resource::reLoad()
|
|||||||
// Libera las texturas
|
// Libera las texturas
|
||||||
void Resource::freeTextures()
|
void Resource::freeTextures()
|
||||||
{
|
{
|
||||||
for (auto texture : textures)
|
for (auto texture : textures_)
|
||||||
{
|
{
|
||||||
delete texture.texture;
|
delete texture.texture;
|
||||||
}
|
}
|
||||||
textures.clear();
|
textures_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera las animaciones
|
// Libera las animaciones
|
||||||
void Resource::freeAnimations()
|
void Resource::freeAnimations()
|
||||||
{
|
{
|
||||||
for (auto a : animations)
|
for (auto a : animations_)
|
||||||
{
|
{
|
||||||
delete a.animation;
|
delete a.animation;
|
||||||
}
|
}
|
||||||
animations.clear();
|
animations_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera los offsets
|
// Libera los offsets
|
||||||
void Resource::freeOffsets()
|
void Resource::freeOffsets()
|
||||||
{
|
{
|
||||||
for (auto o : offsets)
|
for (auto o : offsets_)
|
||||||
{
|
{
|
||||||
delete o.textFile;
|
delete o.textFile;
|
||||||
}
|
}
|
||||||
offsets.clear();
|
offsets_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera los mapas de tiles
|
// Libera los mapas de tiles
|
||||||
void Resource::freeTileMaps()
|
void Resource::freeTileMaps()
|
||||||
{
|
{
|
||||||
for (auto t : tileMaps)
|
for (auto t : tile_maps_)
|
||||||
{
|
{
|
||||||
delete t.tileMap;
|
delete t.tileMap;
|
||||||
}
|
}
|
||||||
tileMaps.clear();
|
tile_maps_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera las habitaciones
|
// Libera las habitaciones
|
||||||
void Resource::freeRooms()
|
void Resource::freeRooms()
|
||||||
{
|
{
|
||||||
for (auto r : rooms)
|
for (auto r : rooms_)
|
||||||
{
|
{
|
||||||
delete r.room;
|
delete r.room;
|
||||||
}
|
}
|
||||||
rooms.clear();
|
rooms_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Libera todos los recursos
|
// Libera todos los recursos
|
||||||
@@ -233,7 +256,7 @@ void Resource::free()
|
|||||||
// Obtiene una textura
|
// Obtiene una textura
|
||||||
Texture *Resource::getTexture(std::string name)
|
Texture *Resource::getTexture(std::string name)
|
||||||
{
|
{
|
||||||
for (auto texture : textures)
|
for (auto texture : textures_)
|
||||||
{
|
{
|
||||||
// if (texture.name.find(name) != std::string::npos)
|
// if (texture.name.find(name) != std::string::npos)
|
||||||
if (texture.name == name)
|
if (texture.name == name)
|
||||||
@@ -245,7 +268,7 @@ Texture *Resource::getTexture(std::string name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||||
}
|
}
|
||||||
@@ -255,7 +278,7 @@ Texture *Resource::getTexture(std::string name)
|
|||||||
// Obtiene una animación
|
// Obtiene una animación
|
||||||
animatedSprite_t *Resource::getAnimation(std::string name)
|
animatedSprite_t *Resource::getAnimation(std::string name)
|
||||||
{
|
{
|
||||||
for (auto animation : animations)
|
for (auto animation : animations_)
|
||||||
{
|
{
|
||||||
// if (animation.name.find(name) != std::string::npos)
|
// if (animation.name.find(name) != std::string::npos)
|
||||||
if (animation.name == name)
|
if (animation.name == name)
|
||||||
@@ -266,7 +289,7 @@ animatedSprite_t *Resource::getAnimation(std::string name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||||
}
|
}
|
||||||
@@ -276,7 +299,7 @@ animatedSprite_t *Resource::getAnimation(std::string name)
|
|||||||
// Obtiene un offset
|
// Obtiene un offset
|
||||||
textFile_t *Resource::getOffset(std::string name)
|
textFile_t *Resource::getOffset(std::string name)
|
||||||
{
|
{
|
||||||
for (auto offset : offsets)
|
for (auto offset : offsets_)
|
||||||
{
|
{
|
||||||
// if (offset.name.find(name) != std::string::npos)
|
// if (offset.name.find(name) != std::string::npos)
|
||||||
if (offset.name == name)
|
if (offset.name == name)
|
||||||
@@ -285,7 +308,7 @@ textFile_t *Resource::getOffset(std::string name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||||
}
|
}
|
||||||
@@ -295,7 +318,7 @@ textFile_t *Resource::getOffset(std::string name)
|
|||||||
// Obtiene un mapa de tiles
|
// Obtiene un mapa de tiles
|
||||||
std::vector<int> *Resource::getTileMap(std::string name)
|
std::vector<int> *Resource::getTileMap(std::string name)
|
||||||
{
|
{
|
||||||
for (auto tileMap : tileMaps)
|
for (auto tileMap : tile_maps_)
|
||||||
{
|
{
|
||||||
// if (tileMap.name.find(name) != std::string::npos)
|
// if (tileMap.name.find(name) != std::string::npos)
|
||||||
if (tileMap.name == name)
|
if (tileMap.name == name)
|
||||||
@@ -304,7 +327,7 @@ std::vector<int> *Resource::getTileMap(std::string name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||||
}
|
}
|
||||||
@@ -314,7 +337,7 @@ std::vector<int> *Resource::getTileMap(std::string name)
|
|||||||
// Obtiene una habitacion
|
// Obtiene una habitacion
|
||||||
room_t *Resource::getRoom(std::string name)
|
room_t *Resource::getRoom(std::string name)
|
||||||
{
|
{
|
||||||
for (auto room : rooms)
|
for (auto room : rooms_)
|
||||||
{
|
{
|
||||||
// if (room.name.find(name) != std::string::npos)
|
// if (room.name.find(name) != std::string::npos)
|
||||||
if (room.name == name)
|
if (room.name == name)
|
||||||
@@ -323,7 +346,7 @@ room_t *Resource::getRoom(std::string name)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
std::cout << "NOT FOUND ON CACHE: " << name << std::endl;
|
||||||
}
|
}
|
||||||
@@ -333,5 +356,5 @@ room_t *Resource::getRoom(std::string name)
|
|||||||
// Obtiene todas las habitaciones
|
// Obtiene todas las habitaciones
|
||||||
std::vector<res_room_t> *Resource::getAllRooms()
|
std::vector<res_room_t> *Resource::getAllRooms()
|
||||||
{
|
{
|
||||||
return &rooms;
|
return &rooms_;
|
||||||
}
|
}
|
||||||
@@ -1,17 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
#include "animatedsprite.h"
|
#include <string> // Para string, basic_string
|
||||||
#include "asset.h"
|
#include <vector> // Para vector
|
||||||
#include "../room.h"
|
class Asset;
|
||||||
#include "text.h"
|
class Texture;
|
||||||
#include "texture.h"
|
struct animatedSprite_t;
|
||||||
#include "utils.h"
|
struct options_t;
|
||||||
#include <string>
|
struct room_t;
|
||||||
#include <vector>
|
struct textFile_t;
|
||||||
|
|
||||||
#ifndef RESOURCE_H
|
|
||||||
#define RESOURCE_H
|
|
||||||
|
|
||||||
struct res_texture_t
|
struct res_texture_t
|
||||||
{
|
{
|
||||||
@@ -47,21 +44,31 @@ struct res_room_t
|
|||||||
class Resource
|
class Resource
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// [SINGLETON] Objeto privado
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
static Resource *resource_;
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<res_texture_t> textures;
|
std::vector<res_texture_t> textures_;
|
||||||
std::vector<res_animation_t> animations;
|
std::vector<res_animation_t> animations_;
|
||||||
std::vector<res_textOffset_t> offsets;
|
std::vector<res_textOffset_t> offsets_;
|
||||||
std::vector<res_tileMap_t> tileMaps;
|
std::vector<res_tileMap_t> tile_maps_;
|
||||||
std::vector<res_room_t> rooms;
|
std::vector<res_room_t> rooms_;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Resource() = default;
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Resource() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
Resource(SDL_Renderer *renderer, Asset *asset, options_t *options);
|
static void init();
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
static Resource *get();
|
||||||
|
|
||||||
// Carga las texturas de una lista
|
// Carga las texturas de una lista
|
||||||
void loadTextures(std::vector<std::string> list);
|
void loadTextures(std::vector<std::string> list);
|
||||||
@@ -132,5 +139,3 @@ public:
|
|||||||
// Obtiene todas las habitaciones
|
// Obtiene todas las habitaciones
|
||||||
std::vector<res_room_t> *getAllRooms();
|
std::vector<res_room_t> *getAllRooms();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +1,20 @@
|
|||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include <iostream>
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BLENDMODE_BLEND
|
||||||
#include <fstream>
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
#include <sstream>
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <stdlib.h> // Para rand
|
||||||
|
#include <fstream> // Para basic_ostream, operator<<, basic_ist...
|
||||||
|
#include <iostream> // Para cout
|
||||||
|
#include <sstream> // Para basic_stringstream
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "const.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_W...
|
||||||
|
#include "debug.h" // Para Debug
|
||||||
|
#include "item_tracker.h" // Para ItemTracker
|
||||||
|
#include "jail_audio.h" // Para JA_DeleteSound, JA_LoadSound, JA_Pla...
|
||||||
|
#include "screen.h" // Para Screen
|
||||||
|
#include "sprite.h" // Para Sprite
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||||
std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
|
std::vector<int> loadRoomTileFile(std::string file_path, bool verbose)
|
||||||
@@ -391,17 +404,14 @@ bool setItem(item_t *item, std::string var, std::string value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, ItemTracker *itemTracker, int *itemsPicked, bool jailEnabled, Debug *debug)
|
Room::Room(room_t *room, ItemTracker *itemTracker, int *itemsPicked, bool jailEnabled)
|
||||||
|
: screen(Screen::get()),
|
||||||
|
renderer(Screen::get()->getRenderer()),
|
||||||
|
asset(Asset::get()),
|
||||||
|
debug(Debug::get()),
|
||||||
|
itemTracker(itemTracker),
|
||||||
|
itemsPicked(itemsPicked)
|
||||||
{
|
{
|
||||||
// Copia los punteros a objetos
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->asset = asset;
|
|
||||||
this->screen = screen;
|
|
||||||
this->itemTracker = itemTracker;
|
|
||||||
this->itemsPicked = itemsPicked;
|
|
||||||
this->debug = debug;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
number = room->number;
|
number = room->number;
|
||||||
name = room->name;
|
name = room->name;
|
||||||
bgColor = room->bgColor;
|
bgColor = room->bgColor;
|
||||||
@@ -418,7 +428,7 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o
|
|||||||
textureA = room->textureA;
|
textureA = room->textureA;
|
||||||
textureB = room->textureB;
|
textureB = room->textureB;
|
||||||
tileMap = *room->tileMap;
|
tileMap = *room->tileMap;
|
||||||
texture = (options->palette == p_zxspectrum) ? textureA : textureB;
|
texture = (options.palette == p_zxspectrum) ? textureA : textureB;
|
||||||
this->jailEnabled = jailEnabled;
|
this->jailEnabled = jailEnabled;
|
||||||
|
|
||||||
// Inicializa variables
|
// Inicializa variables
|
||||||
@@ -433,7 +443,7 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o
|
|||||||
for (auto &enemy : room->enemies)
|
for (auto &enemy : room->enemies)
|
||||||
{
|
{
|
||||||
enemy.renderer = renderer;
|
enemy.renderer = renderer;
|
||||||
enemy.palette = options->palette;
|
enemy.palette = options.palette;
|
||||||
enemies.push_back(new Enemy(enemy));
|
enemies.push_back(new Enemy(enemy));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -445,8 +455,8 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o
|
|||||||
if (!itemTracker->hasBeenPicked(room->name, itemPos))
|
if (!itemTracker->hasBeenPicked(room->name, itemPos))
|
||||||
{
|
{
|
||||||
item.renderer = renderer;
|
item.renderer = renderer;
|
||||||
item.color1 = stringToColor(options->palette, itemColor1);
|
item.color1 = stringToColor(options.palette, itemColor1);
|
||||||
item.color2 = stringToColor(options->palette, itemColor2);
|
item.color2 = stringToColor(options.palette, itemColor2);
|
||||||
items.push_back(new Item(item));
|
items.push_back(new Item(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -476,7 +486,7 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o
|
|||||||
mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
mapTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, PLAY_AREA_WIDTH, PLAY_AREA_HEIGHT);
|
||||||
if (mapTexture == nullptr)
|
if (mapTexture == nullptr)
|
||||||
{
|
{
|
||||||
if (options->console)
|
if (options.console)
|
||||||
{
|
{
|
||||||
std::cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
std::cout << "Error: mapTexture could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
}
|
}
|
||||||
@@ -487,7 +497,7 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o
|
|||||||
fillMapTexture();
|
fillMapTexture();
|
||||||
|
|
||||||
// Establece el color del borde
|
// Establece el color del borde
|
||||||
screen->setBorderColor(stringToColor(options->palette, room->borderColor));
|
screen->setBorderColor(stringToColor(options.palette, room->borderColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -522,19 +532,19 @@ std::string Room::getName()
|
|||||||
// Devuelve el color de la habitación
|
// Devuelve el color de la habitación
|
||||||
color_t Room::getBGColor()
|
color_t Room::getBGColor()
|
||||||
{
|
{
|
||||||
return stringToColor(options->palette, bgColor);
|
return stringToColor(options.palette, bgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Devuelve el color del borde
|
// Devuelve el color del borde
|
||||||
color_t Room::getBorderColor()
|
color_t Room::getBorderColor()
|
||||||
{
|
{
|
||||||
return stringToColor(options->palette, borderColor);
|
return stringToColor(options.palette, borderColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Crea la textura con el mapeado de la habitación
|
// Crea la textura con el mapeado de la habitación
|
||||||
void Room::fillMapTexture()
|
void Room::fillMapTexture()
|
||||||
{
|
{
|
||||||
const color_t color = stringToColor(options->palette, bgColor);
|
const color_t color = stringToColor(options.palette, bgColor);
|
||||||
SDL_SetRenderTarget(renderer, mapTexture);
|
SDL_SetRenderTarget(renderer, mapTexture);
|
||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
|
||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
@@ -829,7 +839,7 @@ bool Room::itemCollision(SDL_Rect &rect)
|
|||||||
items.erase(items.begin() + i);
|
items.erase(items.begin() + i);
|
||||||
JA_PlaySound(itemSound);
|
JA_PlaySound(itemSound);
|
||||||
*itemsPicked = *itemsPicked + 1;
|
*itemsPicked = *itemsPicked + 1;
|
||||||
options->stats.items = *itemsPicked;
|
options.stats.items = *itemsPicked;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -860,20 +870,20 @@ void Room::reLoadPalette()
|
|||||||
// Cambia el color de los items
|
// Cambia el color de los items
|
||||||
for (auto item : items)
|
for (auto item : items)
|
||||||
{
|
{
|
||||||
item->setColors(stringToColor(options->palette, itemColor1), stringToColor(options->palette, itemColor2));
|
item->setColors(stringToColor(options.palette, itemColor1), stringToColor(options.palette, itemColor2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cambia el color de los enemigos
|
// Cambia el color de los enemigos
|
||||||
for (auto enemy : enemies)
|
for (auto enemy : enemies)
|
||||||
{
|
{
|
||||||
enemy->setPalette(options->palette);
|
enemy->setPalette(options.palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Establece el color del borde
|
// Establece el color del borde
|
||||||
screen->setBorderColor(stringToColor(options->palette, borderColor));
|
screen->setBorderColor(stringToColor(options.palette, borderColor));
|
||||||
|
|
||||||
// Cambia la textura
|
// Cambia la textura
|
||||||
texture = (options->palette == p_zxspectrum) ? textureA : textureB;
|
texture = (options.palette == p_zxspectrum) ? textureA : textureB;
|
||||||
|
|
||||||
// Pone la nueva textura a los tiles animados
|
// Pone la nueva textura a los tiles animados
|
||||||
for (auto tile : aTile)
|
for (auto tile : aTile)
|
||||||
|
|||||||
@@ -1,21 +1,19 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||||
#include "common/asset.h"
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
#include "common/debug.h"
|
#include <string> // Para string, basic_string
|
||||||
#include "common/jail_audio.h"
|
#include <vector> // Para vector
|
||||||
#include "common/screen.h"
|
#include "enemy.h" // Para enemy_t
|
||||||
#include "common/sprite.h"
|
#include "item.h" // Para item_t
|
||||||
#include "common/utils.h"
|
#include "utils.h" // Para h_line_t, color_t, d_line_t, v_line_t
|
||||||
#include "const.h"
|
class Asset;
|
||||||
#include "enemy.h"
|
class Debug;
|
||||||
#include "item_tracker.h"
|
class ItemTracker;
|
||||||
#include "item.h"
|
class Screen;
|
||||||
#include <string>
|
class Sprite;
|
||||||
#include <vector>
|
class Texture;
|
||||||
|
struct JA_Sound_t;
|
||||||
#ifndef ROOM_H
|
|
||||||
#define ROOM_H
|
|
||||||
|
|
||||||
enum tile_e
|
enum tile_e
|
||||||
{
|
{
|
||||||
@@ -75,19 +73,18 @@ class Room
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// Objetos y punteros
|
||||||
|
Screen *screen; // Objeto encargado de dibujar en pantalla
|
||||||
|
SDL_Renderer *renderer; // El renderizador de la ventana
|
||||||
|
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
||||||
|
Debug *debug; // Objeto para gestionar la información de debug
|
||||||
std::vector<Enemy *> enemies; // Listado con los enemigos de la habitación
|
std::vector<Enemy *> enemies; // Listado con los enemigos de la habitación
|
||||||
std::vector<Item *> items; // Listado con los items que hay en la habitación
|
std::vector<Item *> items; // Listado con los items que hay en la habitación
|
||||||
Texture *texture; // Textura con los graficos de la habitación
|
Texture *texture; // Textura con los graficos de la habitación
|
||||||
Texture *textureA; // Textura con los graficos de la habitación
|
Texture *textureA; // Textura con los graficos de la habitación
|
||||||
Texture *textureB; // Textura con los graficos de la habitación
|
Texture *textureB; // Textura con los graficos de la habitación
|
||||||
Asset *asset; // Objeto con la ruta a todos los ficheros de recursos
|
|
||||||
Screen *screen; // Objeto encargado de dibujar en pantalla
|
|
||||||
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
|
ItemTracker *itemTracker; // Lleva el control de los objetos recogidos
|
||||||
SDL_Renderer *renderer; // El renderizador de la ventana
|
|
||||||
SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación
|
SDL_Texture *mapTexture; // Textura para dibujar el mapa de la habitación
|
||||||
int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego
|
int *itemsPicked; // Puntero a la cantidad de items recogidos que lleva el juego
|
||||||
Debug *debug; // Objeto para gestionar la información de debug
|
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::string number; // Numero de la habitación
|
std::string number; // Numero de la habitación
|
||||||
@@ -162,7 +159,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, options_t *options, ItemTracker *itemTracker, int *itemsPicked, bool jailEnabled, Debug *debug);
|
Room(room_t *room, ItemTracker *itemTracker, int *itemsPicked, bool jailEnabled);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~Room();
|
~Room();
|
||||||
@@ -254,5 +251,3 @@ public:
|
|||||||
// Obten la direccion de las superficies automaticas
|
// Obten la direccion de las superficies automaticas
|
||||||
int getAutoSurfaceDirection();
|
int getAutoSurfaceDirection();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <string> // Para string
|
||||||
#include "common/utils.h"
|
#include <vector> // Para vector
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#ifndef ROOM_TRACKER_H
|
|
||||||
#define ROOM_TRACKER_H
|
|
||||||
|
|
||||||
class RoomTracker
|
class RoomTracker
|
||||||
{
|
{
|
||||||
@@ -27,5 +22,3 @@ public:
|
|||||||
// Añade la habitación a la lista
|
// Añade la habitación a la lista
|
||||||
bool addRoom(std::string name);
|
bool addRoom(std::string name);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -1,20 +1,26 @@
|
|||||||
#include "scoreboard.h"
|
#include "scoreboard.h"
|
||||||
#include <fstream>
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
#include <sstream>
|
#include <SDL2/SDL_timer.h> // Para SDL_GetTicks
|
||||||
|
#include "animatedsprite.h" // Para AnimatedSprite
|
||||||
|
#include "const.h" // Para BLOCK, PLAY_AREA_HEIGHT, PLAY_AREA_WIDTH
|
||||||
|
#include "resource.h" // Para Resource
|
||||||
|
#include "text.h" // Para Text
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
#include "options.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "asset.h"
|
||||||
|
class Asset;
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset, options_t *options, board_t *board)
|
Scoreboard::Scoreboard(board_t *board)
|
||||||
|
: renderer(Screen::get()->getRenderer()),
|
||||||
|
resource(Resource::get()),
|
||||||
|
asset(Asset::get()),
|
||||||
|
board(board)
|
||||||
{
|
{
|
||||||
// Obten punteros a objetos
|
|
||||||
this->resource = resource;
|
|
||||||
this->asset = asset;
|
|
||||||
this->renderer = renderer;
|
|
||||||
this->board = board;
|
|
||||||
this->options = options;
|
|
||||||
|
|
||||||
// Reserva memoria para los objetos
|
// Reserva memoria para los objetos
|
||||||
itemTexture = resource->getTexture("items.png");
|
itemTexture = resource->getTexture("items.png");
|
||||||
const std::string playerANI = options->cheat.altSkin ? "player2.ani" : "player.ani";
|
const std::string playerANI = options.cheat.altSkin ? "player2.ani" : "player.ani";
|
||||||
sprite = new AnimatedSprite(renderer, resource->getAnimation(playerANI));
|
sprite = new AnimatedSprite(renderer, resource->getAnimation(playerANI));
|
||||||
sprite->setCurrentAnimation("walk_menu");
|
sprite->setCurrentAnimation("walk_menu");
|
||||||
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
|
||||||
@@ -25,25 +31,25 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset,
|
|||||||
paused = false;
|
paused = false;
|
||||||
timePaused = 0;
|
timePaused = 0;
|
||||||
totalTimePaused = 0;
|
totalTimePaused = 0;
|
||||||
itemsColor = stringToColor(options->palette, "white");
|
itemsColor = stringToColor(options.palette, "white");
|
||||||
|
|
||||||
// Inicializa el vector de colores
|
// Inicializa el vector de colores
|
||||||
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||||
for (auto v : vColors)
|
for (auto v : vColors)
|
||||||
{
|
{
|
||||||
color.push_back(stringToColor(options->palette, v));
|
color.push_back(stringToColor(options.palette, v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
ScoreBoard::~ScoreBoard()
|
Scoreboard::~Scoreboard()
|
||||||
{
|
{
|
||||||
delete sprite;
|
delete sprite;
|
||||||
delete text;
|
delete text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void ScoreBoard::render()
|
void Scoreboard::render()
|
||||||
{
|
{
|
||||||
// Anclas
|
// Anclas
|
||||||
const int line1 = 19 * BLOCK;
|
const int line1 = 19 * BLOCK;
|
||||||
@@ -82,15 +88,15 @@ void ScoreBoard::render()
|
|||||||
this->text->writeColored(BLOCK, line1, "Items collected ", board->color);
|
this->text->writeColored(BLOCK, line1, "Items collected ", board->color);
|
||||||
this->text->writeColored(17 * BLOCK, line1, itemsTxt, itemsColor);
|
this->text->writeColored(17 * BLOCK, line1, itemsTxt, itemsColor);
|
||||||
this->text->writeColored(20 * BLOCK, line1, " Time ", board->color);
|
this->text->writeColored(20 * BLOCK, line1, " Time ", board->color);
|
||||||
this->text->writeColored(26 * BLOCK, line1, timeTxt, stringToColor(options->palette, "white"));
|
this->text->writeColored(26 * BLOCK, line1, timeTxt, stringToColor(options.palette, "white"));
|
||||||
|
|
||||||
const std::string roomsTxt = std::to_string(board->rooms / 100) + std::to_string((board->rooms % 100) / 10) + std::to_string(board->rooms % 10);
|
const std::string roomsTxt = std::to_string(board->rooms / 100) + std::to_string((board->rooms % 100) / 10) + std::to_string(board->rooms % 10);
|
||||||
this->text->writeColored(22 * BLOCK, line2, "Rooms", stringToColor(options->palette, "white"));
|
this->text->writeColored(22 * BLOCK, line2, "Rooms", stringToColor(options.palette, "white"));
|
||||||
this->text->writeColored(28 * BLOCK, line2, roomsTxt, stringToColor(options->palette, "white"));
|
this->text->writeColored(28 * BLOCK, line2, roomsTxt, stringToColor(options.palette, "white"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables del objeto
|
// Actualiza las variables del objeto
|
||||||
void ScoreBoard::update()
|
void Scoreboard::update()
|
||||||
{
|
{
|
||||||
counter++;
|
counter++;
|
||||||
sprite->update();
|
sprite->update();
|
||||||
@@ -105,7 +111,7 @@ void ScoreBoard::update()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Obtiene el tiempo transcurrido de partida
|
// Obtiene el tiempo transcurrido de partida
|
||||||
ScoreBoard::clock_t ScoreBoard::getTime()
|
Scoreboard::clock_t Scoreboard::getTime()
|
||||||
{
|
{
|
||||||
const Uint32 timeElapsed = SDL_GetTicks() - board->iniClock - totalTimePaused;
|
const Uint32 timeElapsed = SDL_GetTicks() - board->iniClock - totalTimePaused;
|
||||||
|
|
||||||
@@ -119,7 +125,7 @@ ScoreBoard::clock_t ScoreBoard::getTime()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recarga la textura
|
// Recarga la textura
|
||||||
void ScoreBoard::reLoadTexture()
|
void Scoreboard::reLoadTexture()
|
||||||
{
|
{
|
||||||
sprite->getTexture()->reLoad();
|
sprite->getTexture()->reLoad();
|
||||||
// playerTexture->reLoad();
|
// playerTexture->reLoad();
|
||||||
@@ -128,33 +134,33 @@ void ScoreBoard::reLoadTexture()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recarga la paleta
|
// Recarga la paleta
|
||||||
void ScoreBoard::reLoadPalette()
|
void Scoreboard::reLoadPalette()
|
||||||
{
|
{
|
||||||
// Reinicia el vector de colores
|
// Reinicia el vector de colores
|
||||||
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
const std::vector<std::string> vColors = {"blue", "magenta", "green", "cyan", "yellow", "white", "bright_blue", "bright_magenta", "bright_green", "bright_cyan", "bright_yellow", "bright_white"};
|
||||||
color.clear();
|
color.clear();
|
||||||
for (auto v : vColors)
|
for (auto v : vColors)
|
||||||
{
|
{
|
||||||
color.push_back(stringToColor(options->palette, v));
|
color.push_back(stringToColor(options.palette, v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pone el marcador en modo pausa
|
// Pone el marcador en modo pausa
|
||||||
void ScoreBoard::pause()
|
void Scoreboard::pause()
|
||||||
{
|
{
|
||||||
paused = true;
|
paused = true;
|
||||||
timePaused = SDL_GetTicks();
|
timePaused = SDL_GetTicks();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quita el modo pausa del marcador
|
// Quita el modo pausa del marcador
|
||||||
void ScoreBoard::resume()
|
void Scoreboard::resume()
|
||||||
{
|
{
|
||||||
paused = false;
|
paused = false;
|
||||||
totalTimePaused += SDL_GetTicks() - timePaused;
|
totalTimePaused += SDL_GetTicks() - timePaused;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza el color de la cantidad de items recogidos
|
// Actualiza el color de la cantidad de items recogidos
|
||||||
void ScoreBoard::updateItemsColor()
|
void Scoreboard::updateItemsColor()
|
||||||
{
|
{
|
||||||
if (!board->jailEnabled)
|
if (!board->jailEnabled)
|
||||||
{
|
{
|
||||||
@@ -163,10 +169,16 @@ void ScoreBoard::updateItemsColor()
|
|||||||
|
|
||||||
if (counter % 20 < 10)
|
if (counter % 20 < 10)
|
||||||
{
|
{
|
||||||
itemsColor = stringToColor(options->palette, "white");
|
itemsColor = stringToColor(options.palette, "white");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
itemsColor = stringToColor(options->palette, "magenta");
|
itemsColor = stringToColor(options.palette, "magenta");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Devuelve la cantidad de minutos de juego transcurridos
|
||||||
|
int Scoreboard::getMinutes()
|
||||||
|
{
|
||||||
|
return getTime().minutes;
|
||||||
|
}
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||||
#include "common/animatedsprite.h"
|
#include <SDL2/SDL_stdinc.h> // Para Uint32
|
||||||
#include "common/asset.h"
|
#include <string> // Para basic_string, string
|
||||||
#include "common/resource.h"
|
#include <vector> // Para vector
|
||||||
#include "common/text.h"
|
#include "utils.h" // Para color_t
|
||||||
#include "common/utils.h"
|
class AnimatedSprite;
|
||||||
#include "const.h"
|
class Asset;
|
||||||
#include <string>
|
class Resource;
|
||||||
|
class Text;
|
||||||
#ifndef SCOREBOARD_H
|
class Texture;
|
||||||
#define SCOREBOARD_H
|
|
||||||
|
|
||||||
struct board_t
|
struct board_t
|
||||||
{
|
{
|
||||||
@@ -23,7 +22,7 @@ struct board_t
|
|||||||
bool jailEnabled; // Indica si se puede entrar a la Jail
|
bool jailEnabled; // Indica si se puede entrar a la Jail
|
||||||
};
|
};
|
||||||
|
|
||||||
class ScoreBoard
|
class Scoreboard
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
struct clock_t
|
struct clock_t
|
||||||
@@ -42,7 +41,6 @@ private:
|
|||||||
Text *text; // Objeto para escribir texto
|
Text *text; // Objeto para escribir texto
|
||||||
Texture *itemTexture; // Textura con los graficos para las vidas
|
Texture *itemTexture; // Textura con los graficos para las vidas
|
||||||
board_t *board; // Contiene las variables a mostrar en el marcador
|
board_t *board; // Contiene las variables a mostrar en el marcador
|
||||||
options_t *options; // Puntero a las opciones del juego
|
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
std::vector<color_t> color; // Vector con los colores del objeto
|
std::vector<color_t> color; // Vector con los colores del objeto
|
||||||
@@ -62,10 +60,10 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
ScoreBoard(SDL_Renderer *renderer, Resource *resource, Asset *asset, options_t *options, board_t *board);
|
Scoreboard(board_t *board);
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
~ScoreBoard();
|
~Scoreboard();
|
||||||
|
|
||||||
// Pinta el objeto en pantalla
|
// Pinta el objeto en pantalla
|
||||||
void render();
|
void render();
|
||||||
@@ -84,6 +82,7 @@ public:
|
|||||||
|
|
||||||
// Quita el modo pausa del marcador
|
// Quita el modo pausa del marcador
|
||||||
void resume();
|
void resume();
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
// Devuelve la cantidad de minutos de juego transcurridos
|
||||||
|
int getMinutes();
|
||||||
|
};
|
||||||
|
|||||||
492
source/screen.cpp
Normal file
@@ -0,0 +1,492 @@
|
|||||||
|
#include "screen.h"
|
||||||
|
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||||
|
#include <SDL2/SDL_events.h> // Para SDL_DISABLE, SDL_ENABLE
|
||||||
|
#include <SDL2/SDL_mouse.h> // Para SDL_ShowCursor
|
||||||
|
#include <SDL2/SDL_pixels.h> // Para SDL_PIXELFORMAT_RGBA8888
|
||||||
|
#include <algorithm> // Para max, min
|
||||||
|
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream
|
||||||
|
#include <iostream> // Para cout
|
||||||
|
#include <iterator> // Para istreambuf_iterator, operator!=
|
||||||
|
#include <string> // Para basic_string, char_traits, string
|
||||||
|
#include "asset.h" // Para Asset
|
||||||
|
#include "jail_shader.h" // Para init, render
|
||||||
|
#include "notifier.h" // Para Notify
|
||||||
|
#include "options.h"
|
||||||
|
|
||||||
|
// [SINGLETON]
|
||||||
|
Screen *Screen::screen_ = nullptr;
|
||||||
|
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
void Screen::init(SDL_Window *window, SDL_Renderer *renderer)
|
||||||
|
{
|
||||||
|
Screen::screen_ = new Screen(window, renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
void Screen::destroy()
|
||||||
|
{
|
||||||
|
delete Screen::screen_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
Screen *Screen::get()
|
||||||
|
{
|
||||||
|
return Screen::screen_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer)
|
||||||
|
: window_(window),
|
||||||
|
renderer_(renderer)
|
||||||
|
{
|
||||||
|
game_canvas_width_ = options.gameWidth;
|
||||||
|
game_canvas_height_ = options.gameHeight;
|
||||||
|
notification_logical_width_ = game_canvas_width_;
|
||||||
|
notification_logical_height_ = game_canvas_height_;
|
||||||
|
|
||||||
|
iniFade();
|
||||||
|
iniSpectrumFade();
|
||||||
|
|
||||||
|
// Define el color del borde para el modo de pantalla completa
|
||||||
|
border_color_ = {0x00, 0x00, 0x00};
|
||||||
|
|
||||||
|
// Crea la textura donde se dibujan los graficos del juego
|
||||||
|
game_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_, game_canvas_height_);
|
||||||
|
if (game_canvas_ == nullptr)
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "gameCanvas could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crea la textura donde se dibuja el borde que rodea el area de juego
|
||||||
|
border_canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, game_canvas_width_ + options.borderWidth * 2, game_canvas_height_ + options.borderHeight * 2);
|
||||||
|
if (border_canvas_ == nullptr)
|
||||||
|
{
|
||||||
|
if (options.console)
|
||||||
|
{
|
||||||
|
std::cout << "borderCanvas could not be created!\nSDL Error: " << SDL_GetError() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setBorderColor(border_color_);
|
||||||
|
|
||||||
|
// Establece el modo de video
|
||||||
|
setVideoMode(options.videoMode);
|
||||||
|
|
||||||
|
// Muestra la ventana
|
||||||
|
SDL_ShowWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
Screen::~Screen()
|
||||||
|
{
|
||||||
|
SDL_DestroyTexture(game_canvas_);
|
||||||
|
SDL_DestroyTexture(border_canvas_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
void Screen::clean(color_t color)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
|
||||||
|
SDL_RenderClear(renderer_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
void Screen::start()
|
||||||
|
{
|
||||||
|
SDL_SetRenderTarget(renderer_, game_canvas_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura del borde
|
||||||
|
void Screen::startDrawOnBorder()
|
||||||
|
{
|
||||||
|
SDL_SetRenderTarget(renderer_, border_canvas_);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
void Screen::render()
|
||||||
|
{
|
||||||
|
// Renderiza sobre gameCanvas los overlays
|
||||||
|
renderNotifications();
|
||||||
|
|
||||||
|
// Si está el borde activo, vuelca gameCanvas sobre borderCanvas
|
||||||
|
if (options.borderEnabled)
|
||||||
|
{
|
||||||
|
gameCanvasToBorderCanvas();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestra el contenido por pantalla
|
||||||
|
renderPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el modo de video
|
||||||
|
void Screen::setVideoMode(int videoMode)
|
||||||
|
{
|
||||||
|
// Aplica el modo de video
|
||||||
|
SDL_SetWindowFullscreen(window_, videoMode);
|
||||||
|
|
||||||
|
// Modo ventana
|
||||||
|
if (videoMode == 0)
|
||||||
|
{
|
||||||
|
// Muestra el puntero
|
||||||
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
|
// Modifica el tamaño de la ventana en función del borde
|
||||||
|
if (options.borderEnabled)
|
||||||
|
{
|
||||||
|
window_width_ = game_canvas_width_ + options.borderWidth * 2;
|
||||||
|
window_height_ = game_canvas_height_ + options.borderHeight * 2;
|
||||||
|
dest_ = {options.borderWidth, options.borderHeight, game_canvas_width_, game_canvas_height_};
|
||||||
|
}
|
||||||
|
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window_width_ = game_canvas_width_;
|
||||||
|
window_height_ = game_canvas_height_;
|
||||||
|
dest_ = {0, 0, game_canvas_width_, game_canvas_height_};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modifica el tamaño de la ventana
|
||||||
|
SDL_SetWindowSize(window_, window_width_ * options.windowSize, window_height_ * options.windowSize);
|
||||||
|
SDL_SetWindowPosition(window_, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Si está activo el modo de pantalla completa añade el borde
|
||||||
|
else if (videoMode == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||||
|
{
|
||||||
|
// Oculta el puntero
|
||||||
|
SDL_ShowCursor(SDL_DISABLE);
|
||||||
|
|
||||||
|
// Obten el alto y el ancho de la ventana
|
||||||
|
SDL_GetWindowSize(window_, &window_width_, &window_height_);
|
||||||
|
|
||||||
|
// Aplica el escalado al rectangulo donde se pinta la textura del juego
|
||||||
|
if (options.integerScale)
|
||||||
|
{
|
||||||
|
// Calcula el tamaño de la escala máxima
|
||||||
|
int scale = 0;
|
||||||
|
while (((game_canvas_width_ * (scale + 1)) <= window_width_) && ((game_canvas_height_ * (scale + 1)) <= window_height_))
|
||||||
|
{
|
||||||
|
scale++;
|
||||||
|
}
|
||||||
|
|
||||||
|
dest_.w = game_canvas_width_ * scale;
|
||||||
|
dest_.h = game_canvas_height_ * scale;
|
||||||
|
dest_.x = (window_width_ - dest_.w) / 2;
|
||||||
|
dest_.y = (window_height_ - dest_.h) / 2;
|
||||||
|
}
|
||||||
|
else if (options.keepAspect)
|
||||||
|
{
|
||||||
|
float ratio = (float)game_canvas_width_ / (float)game_canvas_height_;
|
||||||
|
if ((window_width_ - game_canvas_width_) >= (window_height_ - game_canvas_height_))
|
||||||
|
{
|
||||||
|
dest_.h = window_height_;
|
||||||
|
dest_.w = (int)((window_height_ * ratio) + 0.5f);
|
||||||
|
dest_.x = (window_width_ - dest_.w) / 2;
|
||||||
|
dest_.y = (window_height_ - dest_.h) / 2;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dest_.w = window_width_;
|
||||||
|
dest_.h = (int)((window_width_ / ratio) + 0.5f);
|
||||||
|
dest_.x = (window_width_ - dest_.w) / 2;
|
||||||
|
dest_.y = (window_height_ - dest_.h) / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dest_.w = window_width_;
|
||||||
|
dest_.h = window_height_;
|
||||||
|
dest_.x = dest_.y = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modifica el tamaño del renderizador
|
||||||
|
SDL_RenderSetLogicalSize(renderer_, window_width_, window_height_);
|
||||||
|
|
||||||
|
// Actualiza las opciones
|
||||||
|
options.videoMode = videoMode;
|
||||||
|
options.screen.windowWidth = window_width_;
|
||||||
|
options.screen.windowHeight = window_height_;
|
||||||
|
|
||||||
|
// Reinicia los shaders
|
||||||
|
if (options.shaders)
|
||||||
|
{
|
||||||
|
const std::string glsl_file = options.screen.windowHeight == 192 ? "crtpi_192.glsl" : "crtpi_240.glsl";
|
||||||
|
std::ifstream f(Asset::get()->get(glsl_file).c_str());
|
||||||
|
std::string source((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());
|
||||||
|
|
||||||
|
if (options.borderEnabled)
|
||||||
|
{
|
||||||
|
shader::init(window_, border_canvas_, source.c_str());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shader::init(window_, game_canvas_, source.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Camibia entre pantalla completa y ventana
|
||||||
|
void Screen::toggleVideoMode()
|
||||||
|
{
|
||||||
|
options.videoMode = (options.videoMode == 0) ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
|
||||||
|
setVideoMode(options.videoMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el tamaño de la ventana
|
||||||
|
void Screen::setWindowSize(int size)
|
||||||
|
{
|
||||||
|
options.windowSize = size;
|
||||||
|
setVideoMode(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reduce el tamaño de la ventana
|
||||||
|
void Screen::decWindowSize()
|
||||||
|
{
|
||||||
|
--options.windowSize;
|
||||||
|
options.windowSize = std::max(options.windowSize, 1);
|
||||||
|
setVideoMode(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aumenta el tamaño de la ventana
|
||||||
|
void Screen::incWindowSize()
|
||||||
|
{
|
||||||
|
++options.windowSize;
|
||||||
|
options.windowSize = std::min(options.windowSize, 4);
|
||||||
|
setVideoMode(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el color del borde
|
||||||
|
void Screen::setBorderColor(color_t color)
|
||||||
|
{
|
||||||
|
border_color_ = color;
|
||||||
|
auto temp = SDL_GetRenderTarget(renderer_);
|
||||||
|
SDL_SetRenderTarget(renderer_, border_canvas_);
|
||||||
|
SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF);
|
||||||
|
SDL_RenderClear(renderer_);
|
||||||
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el tipo de mezcla
|
||||||
|
void Screen::setBlendMode(SDL_BlendMode blendMode)
|
||||||
|
{
|
||||||
|
SDL_SetRenderDrawBlendMode(renderer_, blendMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el tamaño del borde
|
||||||
|
void Screen::setBorderWidth(int s)
|
||||||
|
{
|
||||||
|
options.borderWidth = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece el tamaño del borde
|
||||||
|
void Screen::setBorderHeight(int s)
|
||||||
|
{
|
||||||
|
options.borderHeight = s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Establece si se ha de ver el borde en el modo ventana
|
||||||
|
void Screen::setBorderEnabled(bool value)
|
||||||
|
{
|
||||||
|
options.borderEnabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia entre borde visible y no visible
|
||||||
|
void Screen::toggleBorder()
|
||||||
|
{
|
||||||
|
options.borderEnabled = !options.borderEnabled;
|
||||||
|
setVideoMode(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activa el fade
|
||||||
|
void Screen::setFade()
|
||||||
|
{
|
||||||
|
fade_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el fade
|
||||||
|
bool Screen::fadeEnded()
|
||||||
|
{
|
||||||
|
if (fade_ || fade_counter_ > 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Activa el spectrum fade
|
||||||
|
void Screen::setspectrumFade()
|
||||||
|
{
|
||||||
|
spectrum_fade_ = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el spectrum fade
|
||||||
|
bool Screen::spectrumFadeEnded()
|
||||||
|
{
|
||||||
|
if (spectrum_fade_ || spectrum_fade_counter_ > 0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables para el fade
|
||||||
|
void Screen::iniFade()
|
||||||
|
{
|
||||||
|
fade_ = false;
|
||||||
|
fade_counter_ = 0;
|
||||||
|
fade_lenght_ = 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el fade
|
||||||
|
void Screen::updateFade()
|
||||||
|
{
|
||||||
|
if (!fade_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fade_counter_++;
|
||||||
|
if (fade_counter_ > fade_lenght_)
|
||||||
|
{
|
||||||
|
iniFade();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
void Screen::renderFade()
|
||||||
|
{
|
||||||
|
if (!fade_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const SDL_Rect rect = {0, 0, game_canvas_width_, game_canvas_height_};
|
||||||
|
color_t color = {0, 0, 0};
|
||||||
|
const float step = (float)fade_counter_ / (float)fade_lenght_;
|
||||||
|
const int alpha = 0 + (255 - 0) * step;
|
||||||
|
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, alpha);
|
||||||
|
SDL_RenderFillRect(renderer_, &rect);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Inicializa las variables para el fade spectrum
|
||||||
|
void Screen::iniSpectrumFade()
|
||||||
|
{
|
||||||
|
spectrum_fade_ = false;
|
||||||
|
spectrum_fade_counter_ = 0;
|
||||||
|
spectrum_fade_lenght_ = 50;
|
||||||
|
|
||||||
|
spectrum_color_.clear();
|
||||||
|
|
||||||
|
// Inicializa el vector de colores
|
||||||
|
const std::vector<std::string> vColors = {"black", "blue", "red", "magenta", "green", "cyan", "yellow", "bright_white"};
|
||||||
|
for (auto v : vColors)
|
||||||
|
{
|
||||||
|
spectrum_color_.push_back(stringToColor(options.palette, v));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza el spectrum fade
|
||||||
|
void Screen::updateSpectrumFade()
|
||||||
|
{
|
||||||
|
if (!spectrum_fade_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
spectrum_fade_counter_++;
|
||||||
|
if (spectrum_fade_counter_ > spectrum_fade_lenght_)
|
||||||
|
{
|
||||||
|
iniSpectrumFade();
|
||||||
|
SDL_SetTextureColorMod(game_canvas_, 255, 255, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja el spectrum fade
|
||||||
|
void Screen::renderSpectrumFade()
|
||||||
|
{
|
||||||
|
if (!spectrum_fade_)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const float step = (float)spectrum_fade_counter_ / (float)spectrum_fade_lenght_;
|
||||||
|
const int max = spectrum_color_.size() - 1;
|
||||||
|
const int index = max + (0 - max) * step;
|
||||||
|
const color_t c = spectrum_color_[index];
|
||||||
|
SDL_SetTextureColorMod(game_canvas_, c.r, c.g, c.b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza los efectos
|
||||||
|
void Screen::updateFX()
|
||||||
|
{
|
||||||
|
updateFade();
|
||||||
|
updateSpectrumFade();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja los efectos
|
||||||
|
void Screen::renderFX()
|
||||||
|
{
|
||||||
|
renderFade();
|
||||||
|
renderSpectrumFade();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dibuja las notificaciones
|
||||||
|
void Screen::renderNotifications()
|
||||||
|
{
|
||||||
|
Notifier::get()->render();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copia el gameCanvas en el borderCanvas
|
||||||
|
void Screen::gameCanvasToBorderCanvas()
|
||||||
|
{
|
||||||
|
auto temp = SDL_GetRenderTarget(renderer_);
|
||||||
|
SDL_SetRenderTarget(renderer_, border_canvas_);
|
||||||
|
SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF);
|
||||||
|
SDL_RenderClear(renderer_);
|
||||||
|
SDL_RenderCopy(renderer_, game_canvas_, nullptr, &dest_);
|
||||||
|
SDL_SetRenderTarget(renderer_, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Muestra el contenido de Screen por pantalla
|
||||||
|
void Screen::renderPresent()
|
||||||
|
{
|
||||||
|
SDL_SetRenderTarget(renderer_, nullptr);
|
||||||
|
SDL_SetRenderDrawColor(renderer_, border_color_.r, border_color_.g, border_color_.b, 0xFF);
|
||||||
|
SDL_RenderClear(renderer_);
|
||||||
|
|
||||||
|
if (options.shaders)
|
||||||
|
{
|
||||||
|
// Aplica shaders y renderiza el contenido
|
||||||
|
shader::render();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (options.borderEnabled)
|
||||||
|
{
|
||||||
|
SDL_RenderCopy(renderer_, border_canvas_, nullptr, nullptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SDL_RenderCopy(renderer_, game_canvas_, nullptr, &dest_);
|
||||||
|
}
|
||||||
|
SDL_RenderPresent(renderer_);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cambia el estado de los shaders
|
||||||
|
void Screen::toggleShaders()
|
||||||
|
{
|
||||||
|
options.shaders = !options.shaders;
|
||||||
|
setVideoMode(options.videoMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza la lógica de la clase
|
||||||
|
void Screen::update()
|
||||||
|
{
|
||||||
|
Notifier::get()->update();
|
||||||
|
}
|
||||||
159
source/screen.h
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <SDL2/SDL_blendmode.h> // Para SDL_BlendMode
|
||||||
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||||
|
#include <SDL2/SDL_render.h> // Para SDL_Renderer, SDL_Texture
|
||||||
|
#include <SDL2/SDL_video.h> // Para SDL_Window
|
||||||
|
#include <string> // Para basic_string, string
|
||||||
|
#include <vector> // Para vector
|
||||||
|
#include "utils.h" // Para color_t
|
||||||
|
class Asset;
|
||||||
|
class Notifier;
|
||||||
|
|
||||||
|
constexpr int FILTER_NEAREST = 0;
|
||||||
|
constexpr int FILTER_LINEAR = 1;
|
||||||
|
|
||||||
|
class Screen
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
// [SINGLETON] Objeto privado
|
||||||
|
static Screen *screen_;
|
||||||
|
|
||||||
|
// Objetos y punteros
|
||||||
|
SDL_Window *window_; // Ventana de la aplicación
|
||||||
|
SDL_Renderer *renderer_; // El renderizador de la ventana
|
||||||
|
SDL_Texture *game_canvas_; // Textura donde se dibuja el juego
|
||||||
|
SDL_Texture *border_canvas_; // Textura donde se dibuja el borde del juego
|
||||||
|
|
||||||
|
// Variables
|
||||||
|
int window_width_; // Ancho de la pantalla o ventana
|
||||||
|
int window_height_; // Alto de la pantalla o ventana
|
||||||
|
int game_canvas_width_; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
||||||
|
int game_canvas_height_; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||||
|
SDL_Rect dest_; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||||
|
color_t border_color_; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
|
int notification_logical_width_; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
|
||||||
|
int notification_logical_height_; // Alto lógico de las notificaciones en relación al tamaño de pantalla
|
||||||
|
|
||||||
|
// Variables - Efectos
|
||||||
|
bool fade_; // Indica si esta activo el efecto de fade
|
||||||
|
int fade_counter_; // Temporizador para el efecto de fade
|
||||||
|
int fade_lenght_; // Duración del fade
|
||||||
|
bool spectrum_fade_; // Indica si esta activo el efecto de fade spectrum
|
||||||
|
int spectrum_fade_counter_; // Temporizador para el efecto de fade spectrum
|
||||||
|
int spectrum_fade_lenght_; // Duración del fade spectrum
|
||||||
|
std::vector<color_t> spectrum_color_; // Colores para el fade spectrum
|
||||||
|
|
||||||
|
// Inicializa las variables para el fade
|
||||||
|
void iniFade();
|
||||||
|
|
||||||
|
// Actualiza el fade
|
||||||
|
void updateFade();
|
||||||
|
|
||||||
|
// Dibuja el fade
|
||||||
|
void renderFade();
|
||||||
|
|
||||||
|
// Inicializa las variables para el fade spectrum
|
||||||
|
void iniSpectrumFade();
|
||||||
|
|
||||||
|
// Actualiza el spectrum fade
|
||||||
|
void updateSpectrumFade();
|
||||||
|
|
||||||
|
// Dibuja el spectrum fade
|
||||||
|
void renderSpectrumFade();
|
||||||
|
|
||||||
|
// Dibuja las notificaciones
|
||||||
|
void renderNotifications();
|
||||||
|
|
||||||
|
// Copia el gameCanvas en el borderCanvas
|
||||||
|
void gameCanvasToBorderCanvas();
|
||||||
|
|
||||||
|
// Muestra el contenido de Screen por pantalla
|
||||||
|
void renderPresent();
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
Screen(SDL_Window *window, SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// Destructor
|
||||||
|
~Screen();
|
||||||
|
|
||||||
|
public:
|
||||||
|
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||||
|
static void init(SDL_Window *window, SDL_Renderer *renderer);
|
||||||
|
|
||||||
|
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||||
|
static void destroy();
|
||||||
|
|
||||||
|
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||||
|
static Screen *get();
|
||||||
|
|
||||||
|
// Limpia la pantalla
|
||||||
|
void clean(color_t color = {0x00, 0x00, 0x00});
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura de juego
|
||||||
|
void start();
|
||||||
|
|
||||||
|
// Prepara para empezar a dibujar en la textura del borde
|
||||||
|
void startDrawOnBorder();
|
||||||
|
|
||||||
|
// Vuelca el contenido del renderizador en pantalla
|
||||||
|
void render();
|
||||||
|
|
||||||
|
// Actualiza la lógica de la clase
|
||||||
|
void update();
|
||||||
|
|
||||||
|
// Establece el modo de video
|
||||||
|
void setVideoMode(int videoMode);
|
||||||
|
|
||||||
|
// Camibia entre pantalla completa y ventana
|
||||||
|
void toggleVideoMode();
|
||||||
|
|
||||||
|
// Cambia el tamaño de la ventana
|
||||||
|
void setWindowSize(int size);
|
||||||
|
|
||||||
|
// Reduce el tamaño de la ventana
|
||||||
|
void decWindowSize();
|
||||||
|
|
||||||
|
// Aumenta el tamaño de la ventana
|
||||||
|
void incWindowSize();
|
||||||
|
|
||||||
|
// Cambia el color del borde
|
||||||
|
void setBorderColor(color_t color);
|
||||||
|
|
||||||
|
// Cambia el tipo de mezcla
|
||||||
|
void setBlendMode(SDL_BlendMode blendMode);
|
||||||
|
|
||||||
|
// Establece el tamaño del borde
|
||||||
|
void setBorderWidth(int s);
|
||||||
|
void setBorderHeight(int s);
|
||||||
|
|
||||||
|
// Establece si se ha de ver el borde en el modo ventana
|
||||||
|
void setBorderEnabled(bool value);
|
||||||
|
|
||||||
|
// Cambia entre borde visible y no visible
|
||||||
|
void toggleBorder();
|
||||||
|
|
||||||
|
// Activa el fade
|
||||||
|
void setFade();
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el fade
|
||||||
|
bool fadeEnded();
|
||||||
|
|
||||||
|
// Activa el spectrum fade
|
||||||
|
void setspectrumFade();
|
||||||
|
|
||||||
|
// Comprueba si ha terminado el spectrum fade
|
||||||
|
bool spectrumFadeEnded();
|
||||||
|
|
||||||
|
// Actualiza los efectos
|
||||||
|
void updateFX();
|
||||||
|
|
||||||
|
// Dibuja los efectos
|
||||||
|
void renderFX();
|
||||||
|
|
||||||
|
// Cambia el estado de los shaders
|
||||||
|
void toggleShaders();
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
SDL_Renderer *getRenderer() { return renderer_; }
|
||||||
|
};
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
|
#include "texture.h" // Para Texture
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
|
Sprite::Sprite(int x, int y, int w, int h, Texture *texture, SDL_Renderer *renderer)
|
||||||