DEADSOFTWARE

Minor enhancements
[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.Sprite;
4 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
5 import com.badlogic.gdx.math.RandomXS128;
6 import com.badlogic.gdx.math.Rectangle;
7 import com.badlogic.gdx.math.Vector2;
8 import ru.deadsoftware.cavecraft.Assets;
9 import ru.deadsoftware.cavecraft.game.GameProc;
11 public class Human extends Mob{
13 private RandomXS128 rand = new RandomXS128();
14 private GameProc gameProc;
15 private Sprite[][] tex;
17 public Human(int x, int y, GameProc gameProc) {
18 this.gameProc = gameProc;
19 position = new Vector2(x, y);
20 moveX = new Vector2(0, 0);
21 moveY = new Vector2(0, 0);
22 width = 8;
23 height = 30;
24 dir = 0;
25 canJump = false;
26 tex = Assets.playerSkin.clone();
27 animation = 0;
28 anim_d = 1;
29 }
31 @Override
32 public void ai() {
33 if (canJump && gameProc.world.getForeMap(
34 (int)(position.x/16)+(dir*2-1), (int)(position.y/16)+1)>0)
35 moveY.add(0, -8);
36 if (rand.nextInt(500)>490) dir++;
37 if (dir>1) dir = 0;
38 moveX.setZero();
39 moveX.add(-2+4*dir, 0);
40 }
42 @Override
43 public void draw(SpriteBatch spriteBatch, float x, float y) {
44 if (moveX.x!=0) {
45 animation+=Mob.ANIM_SPEED*anim_d;
46 if (animation<=-60 || animation>=60) anim_d=-anim_d;
47 }
48 tex[0][2].setRotation(animation);
49 tex[1][2].setRotation(-animation);
50 tex[0][3].setRotation(-animation);
51 tex[1][3].setRotation(animation);
52 spriteBatch.draw(tex[dir][0], x-2, y-2);
53 if (tex[0][2].getRotation()>=60 || tex[0][2].getRotation()<=-60)
54 Mob.ANIM_SPEED = -Mob.ANIM_SPEED;
55 tex[1][2].setPosition(x-6,y);
56 tex[1][2].draw(spriteBatch);
57 tex[1][3].setPosition(x-6, y+10);
58 tex[1][3].draw(spriteBatch);
59 tex[0][3].setPosition(x-6, y+10);
60 tex[0][3].draw(spriteBatch);
61 spriteBatch.draw(tex[dir][1], x-2, y + 8);
63 tex[0][2].setPosition(x-6, y);
64 tex[0][2].draw(spriteBatch);
65 }
67 public Rectangle getRect() {
68 return new Rectangle(position.x, position.y, width, height);
69 }
70 }