Skip to content

Commit

Permalink
Auto stash before merge of "master" and "origin/master"
Browse files Browse the repository at this point in the history
  • Loading branch information
CaseyGFL committed Jun 20, 2017
1 parent 9085010 commit e232369
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 93 deletions.
98 changes: 50 additions & 48 deletions Zelda.pro
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
#-------------------------------------------------
#
# Project created by QtCreator 2017-05-25T11:05:25
#
#-------------------------------------------------

QT += core gui multimedia

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Zelda
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp \
view.cpp \
game.cpp \
entity.cpp \
tile.cpp \
world.cpp \
camera.cpp \
aabb.cpp \
watertile.cpp \
slime.cpp \
resource.cpp \
player.cpp \
gui.cpp \
skeleton.cpp \
worldloader.cpp

HEADERS += mainwindow.h \
view.h \
game.h \
entity.h \
tile.h \
world.h \
camera.h \
aabb.h \
watertile.h \
slime.h \
resource.h \
player.h \
gui.h \
skeleton.h \
worldloader.h

FORMS += mainwindow.ui
#-------------------------------------------------
#
# Project created by QtCreator 2017-05-25T11:05:25
#
#-------------------------------------------------
QT += core gui multimedia
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Zelda
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
view.cpp \
game.cpp \
entity.cpp \
tile.cpp \
world.cpp \
camera.cpp \
aabb.cpp \
watertile.cpp \
slime.cpp \
resource.cpp \
player.cpp \
gui.cpp \
skeleton.cpp \
coin.cpp
worldloader.cpp
HEADERS += mainwindow.h \
view.h \
game.h \
entity.h \
tile.h \
world.h \
camera.h \
aabb.h \
watertile.h \
slime.h \
resource.h \
player.h \
gui.h \
skeleton.h \
coin.h
worldloader.h
FORMS += mainwindow.ui
Expand Down
27 changes: 27 additions & 0 deletions coin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "coin.h"
#include "game.h"
#include <QDebug>

Coin::Coin(Game *game, int x, int y) : Entity(game,x,y,32,32)
{

}


void Coin::draw(QPainter *gl)
{

QRect texture;
QRectF bounds = boundingRect();
//painter->drawImage(QRect(15, 1030, 32, 32), game->resource->objects, QRect((game->STEPS/16%4)*15, 64, 15, 15));
texture = QRect((game->STEPS/16%4)*15, 64, 15, 15);


gl->drawImage(bounds, game->resource->objects, texture);
}

void Coin::update()
{
setDX(dx);
updateMove();
}
23 changes: 23 additions & 0 deletions coin.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef COIN_H
#define COIN_H

#include "entity.h"

class Game;

class Coin : public Entity
{
public:
Coin(Game *game, int x, int y);
void draw(QPainter *gl);
void update();
};

#endif // COIN_H







7 changes: 5 additions & 2 deletions entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "tile.h"
#include <QDebug>
#include <math.h>
#include "coin.h"

Entity::Entity(Game *game, int x, int y, int width, int height)
{
Expand Down Expand Up @@ -50,6 +51,8 @@ void Entity::damaged(int damage)
if(entity == this){
game->world->entities->removeAt(i);
game->world->scene()->removeItem(entity);
game->world->addCoin(x, y);

}
}
}
Expand All @@ -60,15 +63,15 @@ QRectF Entity::boundingRect() const
return QRectF(0, 0, width, height);
}

QRectF Entity::collisionRect()
QRectF Entity::collisionRect() const
{
return QRectF(x, y, width, height);
}

QPainterPath Entity::shape() const
{
QPainterPath path;
path.addRect(boundingRect());
path.addRect(collisionRect());
return path;
}

Expand Down
5 changes: 4 additions & 1 deletion entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#include <QPainter>
#include <QGraphicsItem>


class Game;

class Entity : public QGraphicsItem
{
public:
Entity(Game *game, int x, int y, int width, int height);
QRectF boundingRect() const;
QRectF collisionRect();
QRectF collisionRect() const;
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

Expand All @@ -26,6 +27,7 @@ class Entity : public QGraphicsItem
bool playerWithinRange(float range);
void chasePlayer(float distance);


float x, y;
int width, height;
float speed;
Expand All @@ -37,6 +39,7 @@ class Entity : public QGraphicsItem

protected:
Game *game;

};

#endif // ENTITY_H
2 changes: 2 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ void Game::load(){
void Game::loadEntities(){
world->addEntity(new Slime(this, 300, 300));
world->addEntity(new Skeleton(this, 200, 200));

}

void Game::update(){
STEPS++;
player->update();
world->update();
player->pickup();
}
2 changes: 2 additions & 0 deletions game.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "camera.h"
#include "resource.h"
#include "player.h"
#include "coin.h"
#include "gui.h"

class View;
Expand All @@ -29,6 +30,7 @@ class Game
Camera *camera;
World *world;
Player *player;
Coin *coin;
Gui *gui;

QGraphicsScene *scene;
Expand Down
6 changes: 5 additions & 1 deletion gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <QPainter>
#include <QPainterPath>
#include <QDebug>

class Game;

Expand All @@ -27,19 +28,22 @@ QPainterPath Gui::shape() const

void Gui::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{

if(game->player->health > 0){
for (int i = 0; i < game->player->health; ++i) {
painter->drawImage(QRect(20+i*40, 30, 32, 32), game->resource->objects, QRect(64, 2, 14, 13));
}
}


painter->drawImage(QRect(15, 1030, 32, 32), game->resource->objects, QRect((game->STEPS/16%4)*15, 64, 15, 15));

QFont font;
font.setPixelSize(20);
painter->setPen(QColor(207,213,38));
painter->setFont(font);
painter->drawText(QPointF(60, 1050), QString("Počet mincí"));
QString coinval = QString::number(game->player->coins);
painter->drawText(QPointF(60, 1050), QString("Počet mincí: " + coinval));

if (game->player->health == 0) {
QFont font;
Expand Down
22 changes: 20 additions & 2 deletions player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
Player::Player(Game *game, int x, int y) : Entity(game, x, y, 32, 48)
{
speed = 2;
health = 1;
health = 5;
dmg = 20;
coins = 0;
}

void Player::draw(QPainter *gl)
Expand Down Expand Up @@ -62,6 +63,7 @@ void Player::update()

// Důležité pro pohyb (každý druh pohybu by měl mít vlastní funkci v entitě)
updateMove();
pickup();
}

void Player::attack()
Expand All @@ -81,14 +83,30 @@ void Player::attack()
entity->damaged(dmg);
}
}



}



void Player::damaged(int damage)
{
health-=damage;
}

void Player::died()
void Player::pickup()
{
for (int i = 0; i < game->world->coines->length(); ++i) {
if(this->collidesWithItem(game->world->coines->at(i))){
game->scene->removeItem(game->world->coines->at(i));
game->world->coines->removeAt(i);
game->player->coins++;
qDebug()<<game->player->coins;

}
}
}



6 changes: 4 additions & 2 deletions player.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ class Player : public Entity
void update();
void attack();
void damaged(int damage);
void died();

void pickup();
int swing = 0;
int health;
int dmg;
int direction = 0;
int coins;


};

#endif // PLAYER_H
3 changes: 2 additions & 1 deletion view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ void View::keyReleaseEvent(QKeyEvent *event)
if((event->key() == Qt::Key_Right || event->key() == Qt::Key_D) && game->player->dx == 1) game->player->setDX(0);
if((event->key() == Qt::Key_Up || event->key() == Qt::Key_W) && game->player->dy == -1) game->player->setDY(0);
if((event->key() == Qt::Key_Down || event->key() == Qt::Key_S) && game->player->dy == 1) game->player->setDY(0);
if(event->key()== Qt::Key_Shift) game->player->speed=2;
if(event->key()== Qt::Key_Shift)game->player->speed=2;

}
9 changes: 9 additions & 0 deletions world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ World::World(Game *game)
this->game = game;
this->loader = new WorldLoader(this);
entities = new QList<Entity*>();
coines = new QList<Coin*>();
}

void World::update()
Expand Down Expand Up @@ -51,6 +52,14 @@ void World::addEntity(Entity *entity)
this->game->scene->addItem(entity);
}

void World::addCoin(int x, int y)
{
Coin *coin = new Coin(game, x, y);
this->coines->append(coin);
this->game->scene->addItem(coin);

}

void World::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
int bx = game->camera->getPosition().rx()/Tile::SIZE;
Expand Down
Loading

0 comments on commit e232369

Please sign in to comment.