]> git.lizzy.rs Git - dragonblocks-bedrock.git/blob - src/player.cpp
Some structure Changes
[dragonblocks-bedrock.git] / src / player.cpp
1 #include <iostream>
2 #include <math.h>
3 #include "texture.h"
4 #include "entity.h"
5 #include "player.h"
6 #include "map.h"
7 #include "mapgen.h"
8 #include "graphics.h"
9 #include "game.h"
10 using namespace std;
11 Player::Player(){
12         name = "player";
13         texture = new Texture("textures/player.png", true);
14         width = 1;
15         height = 2;
16         int spawnposX = MAPWIDTH / 2;
17         int spawnposY = MAPHEIGHT - 2;
18         while((Game::map->getNode(spawnposX, spawnposY) != MAPGEN_AIR) || (Game::map->getNode(spawnposX, spawnposY + 1) != MAPGEN_AIR))
19                 spawnposY--;
20         spawn(spawnposX, spawnposY, true);
21         inventory = new Inventory();
22 }
23 void Player::left(){
24         if(vx == -PLAYER_SPEED)
25                 return;
26         physics_reset_x();
27         vx = -PLAYER_SPEED;
28 }
29 void Player::right(){
30         if(vx == PLAYER_SPEED)
31                 return;
32         physics_reset_x();
33         vx = PLAYER_SPEED;
34 }
35 void Player::stop(){
36         physics_reset_x();
37 }
38 void Player::jump(){
39         vy = -PLAYER_JUMPSPEED;
40 }