Mana
Loading...
Searching...
No Matches
ambientlayer.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2009-2012 The Mana Developers
4 *
5 * This file is part of The Mana Client.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
22
23#include "graphics.h"
24
25#include "resources/image.h"
27
29 : mImage(img)
30{}
31
33
34void AmbientLayer::update(int timePassed, float dx, float dy)
35{
36 // Self scrolling of the overlay
37 mPosX -= mSpeedX * timePassed;
38 mPosY -= mSpeedY * timePassed;
39
40 // Parallax scrolling
41 mPosX += dx * mParallax;
42 mPosY += dy * mParallax;
43
44 int imgW = mImage->getWidth();
45 int imgH = mImage->getHeight();
46
47 // Wrap values
48 while (mPosX > imgW)
49 mPosX -= imgW;
50 while (mPosX < 0)
51 mPosX += imgW;
52
53 while (mPosY > imgH)
54 mPosY -= imgH;
55 while (mPosY < 0)
56 mPosY += imgH;
57}
58
60{
61 const auto screenWidth = graphics->getWidth();
62 const auto screenHeight = graphics->getHeight();
63 const auto x = static_cast<int>(mPosX);
64 const auto y = static_cast<int>(mPosY);
65
66 if (!mKeepRatio)
67 {
69 -x, -y,
70 screenWidth + x,
71 screenHeight + y);
72 }
73 else
74 {
76 -x, -y,
77 screenWidth + x,
78 screenHeight + y,
79 mImage->getWidth() * screenWidth / 800,
80 mImage->getHeight() * screenHeight / 600);
81 }
82}
float mPosY
Current layer Y position.
AmbientLayer(Image *img)
Constructor.
void draw(Graphics *graphics)
float mPosX
Current layer X position.
float mSpeedX
Scrolling speed in X direction.
float mSpeedY
Scrolling speed in Y direction.
bool mKeepRatio
Keep overlay ratio on every resolution like in 800x600.
float mParallax
Scroll factor based on camera position.
ResourceRef< Image > mImage
void update(int timePassed, float dx, float dy)
A central point of control for graphics.
Definition graphics.h:78
virtual void drawImagePattern(const Image *image, int x, int y, int w, int h)
Definition graphics.cpp:99
void drawRescaledImagePattern(const Image *image, int x, int y, int w, int h, int scaledWidth, int scaledHeight)
Draw a pattern based on a rescaled version of the given image.
Definition graphics.cpp:108
int getHeight() const
Returns the logical height of the screen.
Definition graphics.h:226
int getWidth() const
Returns the logical width of the screen.
Definition graphics.h:221
Defines a class for loading and storing images.
Definition image.h:45
int getHeight() const
Returns the height of the image.
Definition image.h:89
int getWidth() const
Returns the width of the image.
Definition image.h:83
Graphics * graphics
Definition client.cpp:104