cleaning and better system state handling

This commit is contained in:
Pòsweg 2017-06-17 14:13:03 +02:00
parent 6718af26dd
commit 6ad338c631
13 changed files with 192 additions and 26 deletions

3
.gitignore vendored
View File

@ -42,4 +42,5 @@ reated by https://www.gitignore.io/api/vim,c++,linux
bin/
obj/
# auto-generated tag files
### My files ###
*.project.cpp

20
Licenses/COPYING.txt Normal file
View File

@ -0,0 +1,20 @@
/*
SDL_image: An example image loading library for use with SDL
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/

114
Licenses/LICENSE.png.txt Normal file
View File

@ -0,0 +1,114 @@
The source code to this library used with SDL_image can be found here:
http://www.libsdl.org/projects/SDL_image/libs/
---
This copy of the libpng notices is provided for your convenience. In case of
any discrepancy between this copy and the notices in the file png.h that is
included in the libpng distribution, the latter shall prevail.
COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:
If you modify libpng you may insert additional notices immediately following
this sentence.
This code is released under the libpng license.
libpng versions 1.2.6, August 15, 2004, through 1.5.7, December 15, 2011, are
Copyright (c) 2004, 2006-2011 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.2.5
with the following individual added to the list of Contributing Authors
Cosmin Truta
libpng versions 1.0.7, July 1, 2000, through 1.2.5 - October 3, 2002, are
Copyright (c) 2000-2002 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-1.0.6
with the following individuals added to the list of Contributing Authors
Simon-Pierre Cadieux
Eric S. Raymond
Gilles Vollant
and with the following additions to the disclaimer:
There is no warranty against interference with your enjoyment of the
library or against infringement. There is no warranty that our
efforts or the library will fulfill any of your particular purposes
or needs. This library is provided with all faults, and the entire
risk of satisfactory quality, performance, accuracy, and effort is with
the user.
libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are
Copyright (c) 1998, 1999 Glenn Randers-Pehrson, and are
distributed according to the same disclaimer and license as libpng-0.96,
with the following individuals added to the list of Contributing Authors:
Tom Lane
Glenn Randers-Pehrson
Willem van Schaik
libpng versions 0.89, June 1996, through 0.96, May 1997, are
Copyright (c) 1996, 1997 Andreas Dilger
Distributed according to the same disclaimer and license as libpng-0.88,
with the following individuals added to the list of Contributing Authors:
John Bowler
Kevin Bracey
Sam Bushell
Magnus Holmgren
Greg Roelofs
Tom Tanner
libpng versions 0.5, May 1995, through 0.88, January 1996, are
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
For the purposes of this copyright and license, "Contributing Authors"
is defined as the following set of individuals:
Andreas Dilger
Dave Martindale
Guy Eric Schalnat
Paul Schmidt
Tim Wegner
The PNG Reference Library is supplied "AS IS". The Contributing Authors
and Group 42, Inc. disclaim all warranties, expressed or implied,
including, without limitation, the warranties of merchantability and of
fitness for any purpose. The Contributing Authors and Group 42, Inc.
assume no liability for direct, indirect, incidental, special, exemplary,
or consequential damages, which may result from the use of the PNG
Reference Library, even if advised of the possibility of such damage.
Permission is hereby granted to use, copy, modify, and distribute this
source code, or portions hereof, for any purpose, without fee, subject
to the following restrictions:
1. The origin of this source code must not be misrepresented.
2. Altered versions must be plainly marked as such and must not
be misrepresented as being the original source.
3. This Copyright notice may not be removed or altered from any
source or altered source distribution.
The Contributing Authors and Group 42, Inc. specifically permit, without
fee, and encourage the use of this source code as a component to
supporting the PNG file format in commercial products. If you use this
source code in a product, acknowledgment is not required but would be
appreciated.
A "png_get_copyright" function is available, for convenient use in "about"
boxes and the like:
printf("%s",png_get_copyright(NULL));
Also, the PNG logo (in PNG format, of course) is supplied in the
files "pngbar.png" and "pngbar.jpg (88x31) and "pngnow.png" (98x31).
Libpng is OSI Certified Open Source Software. OSI Certified Open Source is a
certification mark of the Open Source Initiative.
Glenn Randers-Pehrson
glennrp at users.sourceforge.net
December 15, 2011

31
Licenses/LICENSE.zlib.txt Normal file
View File

@ -0,0 +1,31 @@
The source code to this library used with SDL_image can be found here:
http://www.libsdl.org/projects/SDL_image/libs/
---
Copyright notice:
(C) 1995-2010 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
If you use the zlib library in a product, we would appreciate *not* receiving
lengthy legal documents to sign. The sources are provided for free but without
warranty of any kind. The library has been entirely written by Jean-loup
Gailly and Mark Adler; it does not include third-party code.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -23,31 +23,20 @@ void Core::close(){
int Core::coreInit(){
init();
/*bool quit = false;
SDL_Event e;
int gamestate = 0;
while(!quit){
while(SDL_PollEvent(&e)!=0){
if(e.type == SDL_QUIT){
quit = true;
}
}
SDL_SetRenderDrawColor(gRenderer,0,0,100,0xFF);
SDL_RenderClear(gRenderer);
//-1 = quit, 0 = Menu, 1 = playing,
SDL_RenderPresent(gRenderer);
}*/
if(menu(gRenderer) == 1){
map1();
while (gamestate != -1){
if(gamestate == 0) gamestate = menu(gRenderer);
if(gamestate == 1) gamestate = map1();
}
close();
return 0;
};
void Core::map1(){
int Core::map1(){
Player posweg(&gRenderer);
bool quit = false;
@ -64,7 +53,7 @@ void Core::map1(){
Camera camera(36*sz,SCREEN_WIDTH);
posweg.print(40,8*sz ,camera.getPosX());
if(posweg.print(40,8*sz ,camera.getPosX()) == 1) return 0;
camera.update(posweg.getRectangle().x,posweg.getRectangle().y);
Block wallA(8*sz,7*sz,sz*2,sz*2,&gRenderer,&posweg,camera.getPosX());
@ -77,5 +66,5 @@ void Core::map1(){
SDL_RenderPresent(gRenderer);
}
return -1;
};

View File

@ -19,7 +19,7 @@ class Core{
void init();
void close();
void map1();
int map1();
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;

View File

@ -1,8 +1,8 @@
//Player class cpp
//Player class body
#include"player.h"
void Player::print(int x,int y,int cameraX){
int Player::print(int x,int y,int cameraX){
if(first == true){
first = false;
posX = x;
@ -29,6 +29,14 @@ void Player::print(int x,int y,int cameraX){
move();
ground = false;
topCollision = false;
//Check if the player has fell out of the world (not horizontally, sadly).
int SCREEN_WIDTH, SCREEN_HEIGHT;
SDL_GetRendererOutputSize(*renderer,&SCREEN_WIDTH,&SCREEN_HEIGHT);
if(posY >= SCREEN_HEIGHT) return 1;
return 0;
};
Player::Player(SDL_Renderer** render){
@ -107,7 +115,7 @@ void Player::move(){
velocityX -= speed * dt * dur;
if(intVelX() < -speed) velocityX = -speed;
}
if(direction == 0 and velocityX != 0)
if(direction == 0 and velocityX != 0){
if(intVelX() > 0){
velocityX -= speed * dt * dur;
if(intVelX() < 0) velocityX = 0;
@ -117,6 +125,7 @@ void Player::move(){
if(intVelX() > 0) velocityX = 0;
}
else if(velocityX <= 1 or velocityX >= -1) velocityX = 0;
}
//Jump and gravity logic
if(ground){
@ -142,6 +151,8 @@ void Player::move(){
//Convert and set new int position
posX += static_cast<int>(x);
posY -= static_cast<int>(y+0.5);
};
int Player::check(SDL_Rect rectA, int type){

View File

@ -14,7 +14,7 @@ class Entity;
class Player: public Entity{
public:
void print(int x, int y,int cameraX);
int print(int x, int y,int cameraX);
int check(SDL_Rect rectA,int type);
Player(SDL_Renderer** render);
private:

View File

@ -82,5 +82,5 @@ int menu(SDL_Renderer* renderer){
SDL_RenderPresent(renderer);
}
return 0;
return -1;
}