DEADSOFTWARE

97b1c18dc0b16f86bed4e7ba3998202691f3be48
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / mobs / Human.java
1 package ru.deadsoftware.cavecraft.game.mobs;
3 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
4 import com.badlogic.gdx.math.RandomXS128;
5 import com.badlogic.gdx.math.Rectangle;
6 import com.badlogic.gdx.math.Vector2;
7 import ru.deadsoftware.cavecraft.Assets;
8 import ru.deadsoftware.cavecraft.game.GameProc;
10 public class Human extends Mob{
12 private RandomXS128 rand = new RandomXS128();
13 private GameProc gameProc;
15 public Human(int x, int y, GameProc gameProc) {
16 this.gameProc = gameProc;
17 position = new Vector2(x, y);
18 moveX = new Vector2(0, 0);
19 moveY = new Vector2(0, 0);
20 width = 8;
21 height = 30;
22 dir = 1;
23 canJump = false;
24 }
26 @Override
27 public void ai() {
28 if (canJump && gameProc.world.getForeMap(
29 (int)(position.x/16)+(dir*2-1), (int)(position.y/16)+1)>0)
30 moveY.add(0, -8);
31 if (rand.nextInt(500)>490) dir++;
32 if (dir>1) dir = 0;
33 moveX.setZero();
34 moveX.add(-2+4*dir, 0);
35 }
37 @Override
38 public void draw(SpriteBatch spriteBatch, float x, float y) {
39 spriteBatch.draw(Assets.playerSkin[dir][0], x-2, y-2);
40 if (Assets.playerSkin[0][2].getRotation()>=60 || Assets.playerSkin[0][2].getRotation()<=-60)
41 Mob.ANIM_SPEED = -Mob.ANIM_SPEED;
42 Assets.playerSkin[1][2].setPosition(x-6,y);
43 Assets.playerSkin[1][2].draw(spriteBatch);
44 Assets.playerSkin[1][3].setPosition(x-6, y+10);
45 Assets.playerSkin[1][3].draw(spriteBatch);
46 Assets.playerSkin[0][3].setPosition(x-6, y+10);
47 Assets.playerSkin[0][3].draw(spriteBatch);
48 spriteBatch.draw(Assets.playerSkin[dir][1], x-2, y + 8);
50 Assets.playerSkin[0][2].setPosition(x-6, y);
51 Assets.playerSkin[0][2].draw(spriteBatch);
52 }
54 public Rectangle getRect() {
55 return new Rectangle(position.x, position.y, width, height);
56 }
57 }