|
|
|
@ -1,25 +1,25 @@ |
|
|
|
|
/*
|
|
|
|
|
Copyright (c) 2004-2020, Lode Vandevenne |
|
|
|
|
Copyright (c) 2004-2020, Lode Vandevenne |
|
|
|
|
|
|
|
|
|
All rights reserved. |
|
|
|
|
All rights reserved. |
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
|
|
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: |
|
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
|
|
|
|
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. |
|
|
|
|
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. |
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
|
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
|
|
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
|
|
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
|
|
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
|
|
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
|
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
|
|
*/ |
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
|
|
|
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
|
|
|
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
|
|
|
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
|
|
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
|
|
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
|
|
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
#include <cmath> |
|
|
|
|
#include <string> |
|
|
|
@ -30,9 +30,9 @@ |
|
|
|
|
using namespace QuickCG; |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
g++ *.cpp -lSDL -O3 -W -Wall -ansi -pedantic |
|
|
|
|
g++ *.cpp -lSDL |
|
|
|
|
*/ |
|
|
|
|
g++ *.cpp -lSDL -O3 -W -Wall -ansi -pedantic |
|
|
|
|
g++ *.cpp -lSDL |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define screenWidth 640 |
|
|
|
@ -135,14 +135,14 @@ int main(int /*argc*/, char */*argv*/[]) |
|
|
|
|
|
|
|
|
|
//load some textures
|
|
|
|
|
unsigned long tw, th, error = 0; |
|
|
|
|
error |= loadImage(texture[0], tw, th, "assets/eagle.png"); |
|
|
|
|
error |= loadImage(texture[1], tw, th, "assets/redbrick.png"); |
|
|
|
|
error |= loadImage(texture[2], tw, th, "assets/purplestone.png"); |
|
|
|
|
error |= loadImage(texture[3], tw, th, "assets/greystone.png"); |
|
|
|
|
error |= loadImage(texture[4], tw, th, "assets/bluestone.png"); |
|
|
|
|
error |= loadImage(texture[5], tw, th, "assets/mossy.png"); |
|
|
|
|
error |= loadImage(texture[6], tw, th, "assets/wood.png"); |
|
|
|
|
error |= loadImage(texture[7], tw, th, "assets/colorstone.png"); |
|
|
|
|
error |= loadImage(texture[0], tw, th, "pics/eagle.png"); |
|
|
|
|
error |= loadImage(texture[1], tw, th, "pics/redbrick.png"); |
|
|
|
|
error |= loadImage(texture[2], tw, th, "pics/purplestone.png"); |
|
|
|
|
error |= loadImage(texture[3], tw, th, "pics/greystone.png"); |
|
|
|
|
error |= loadImage(texture[4], tw, th, "pics/bluestone.png"); |
|
|
|
|
error |= loadImage(texture[5], tw, th, "pics/mossy.png"); |
|
|
|
|
error |= loadImage(texture[6], tw, th, "pics/wood.png"); |
|
|
|
|
error |= loadImage(texture[7], tw, th, "pics/colorstone.png"); |
|
|
|
|
if(error) { std::cout << "error loading images" << std::endl; return 1; } |
|
|
|
|
|
|
|
|
|
//load some sprite textures
|
|
|
|
@ -335,11 +335,7 @@ int main(int /*argc*/, char */*argv*/[]) |
|
|
|
|
for(int i = 0; i < numSprites; i++) |
|
|
|
|
{ |
|
|
|
|
spriteOrder[i] = i; |
|
|
|
|
spriteDistance[i] = |
|
|
|
|
((posX - sprite[i].x) * |
|
|
|
|
(posX - sprite[i].x) + |
|
|
|
|
(posY - sprite[i].y) * |
|
|
|
|
(posY - sprite[i].y)); //sqrt not taken, unneeded
|
|
|
|
|
spriteDistance[i] = ((posX - sprite[i].x) * (posX - sprite[i].x) + (posY - sprite[i].y) * (posY - sprite[i].y)); //sqrt not taken, unneeded
|
|
|
|
|
} |
|
|
|
|
sortSprites(spriteOrder, spriteDistance, numSprites); |
|
|
|
|
|
|
|
|
@ -363,9 +359,9 @@ int main(int /*argc*/, char */*argv*/[]) |
|
|
|
|
int spriteScreenX = int((w / 2) * (1 + transformX / transformY)); |
|
|
|
|
|
|
|
|
|
//parameters for scaling and moving the sprites
|
|
|
|
|
#define uDiv 1 |
|
|
|
|
#define vDiv 1 |
|
|
|
|
#define vMove 0.0 |
|
|
|
|
#define uDiv 1 |
|
|
|
|
#define vDiv 1 |
|
|
|
|
#define vMove 0.0 |
|
|
|
|
int vMoveScreen = int(vMove / transformY); |
|
|
|
|
|
|
|
|
|
//calculate height of the sprite on screen
|
|
|
|
|