|
| 1 | +package com.redomar.game.entities; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import com.redomar.game.entities.efx.Swim; |
| 6 | +import com.redomar.game.gfx.Colours; |
| 7 | +import com.redomar.game.gfx.Screen; |
| 8 | +import com.redomar.game.level.LevelHandler; |
| 9 | +import com.redomar.game.level.Node; |
| 10 | + |
| 11 | +public class Vendor extends Mob { |
| 12 | + |
| 13 | + private int colour, shirtCol, faceCol; // = Colours.get(-1, 111, 240, 310); |
| 14 | + private int tickCount = 0; |
| 15 | + private int tick = 0; |
| 16 | + private double xa = 0; |
| 17 | + private double ya = 0; |
| 18 | + private double[] movement; |
| 19 | + private boolean[] swimType; |
| 20 | + private int[] swimColour; |
| 21 | + private static double speed = 0.75; |
| 22 | + private List<Node> path = null; |
| 23 | + private int time = 0; |
| 24 | + private static int[] collisionBoders = {0, 7, 0, 7}; |
| 25 | + |
| 26 | + private Swim swim; |
| 27 | + |
| 28 | + public Vendor(LevelHandler level, String name, int x, int y, int shirtCol, |
| 29 | + int faceCol) { |
| 30 | + super(level, "h", x, y, speed, collisionBoders); |
| 31 | + this.faceCol = faceCol; |
| 32 | + this.shirtCol = shirtCol; |
| 33 | + this.colour = Colours.get(-1, 111, shirtCol, faceCol); |
| 34 | + } |
| 35 | + |
| 36 | + public void tick() { |
| 37 | + |
| 38 | + tick++; |
| 39 | + movement = randomMovementAI(x, y, xa, ya, tick); |
| 40 | + |
| 41 | + this.xa = movement[0]; |
| 42 | + this.ya = movement[1]; |
| 43 | + |
| 44 | + moveMob(xa, ya, this); |
| 45 | + |
| 46 | + setSwim(new Swim(level, (int) getX(), (int) getY())); |
| 47 | + swimType = getSwim().swimming(isSwimming, isMagma, isMuddy); |
| 48 | + isSwimming = swimType[0]; |
| 49 | + isMagma = swimType[1]; |
| 50 | + isMuddy = swimType[2]; |
| 51 | + |
| 52 | + tickCount++; |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + public void render(Screen screen) { |
| 57 | + setTime(getTime() + 1); |
| 58 | + int xTile = 8; |
| 59 | + int yTile = 28; |
| 60 | + int walkingSpeed = 4; |
| 61 | + int flipTop = (numSteps >> walkingSpeed) & 1; |
| 62 | + int flipBottom = (numSteps >> walkingSpeed) & 1; |
| 63 | + |
| 64 | + if (movingDir == 1) { |
| 65 | + xTile += 2; |
| 66 | + if (!isMoving || swim.isActive(swimType)){ |
| 67 | + yTile -= 2; |
| 68 | + } |
| 69 | + } else if (movingDir == 0 && !isMoving || movingDir == 0 && swim.isActive(swimType)) { |
| 70 | + yTile -= 2; |
| 71 | + } else if (movingDir > 1) { |
| 72 | + xTile += 4 + ((numSteps >> walkingSpeed) & 1) * 2; |
| 73 | + flipTop = (movingDir - 1) % 2; |
| 74 | + if(!isMoving){ |
| 75 | + xTile = 4; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + int modifier = 8 * scale; |
| 80 | + int xOffset = (int) getX() - modifier / 2; |
| 81 | + int yOffset = (int) getY() - modifier / 2 - 4; |
| 82 | + |
| 83 | + if (isSwimming || isMagma || isMuddy) { |
| 84 | + swimColour = getSwim().waveCols(isSwimming, isMagma, isMuddy); |
| 85 | + |
| 86 | + int waterColour = 0; |
| 87 | + yOffset += 4; |
| 88 | + |
| 89 | + colour = Colours.get(-1, 111, -1, faceCol); |
| 90 | + |
| 91 | + if (tickCount % 60 < 15) { |
| 92 | + waterColour = Colours.get(-1, -1, swimColour[0], -1); |
| 93 | + } else if (15 <= tickCount % 60 && tickCount % 60 < 30) { |
| 94 | + yOffset--; |
| 95 | + waterColour = Colours.get(-1, swimColour[1], swimColour[2], -1); |
| 96 | + } else if (30 <= tickCount % 60 && tickCount % 60 < 45) { |
| 97 | + waterColour = Colours.get(-1, swimColour[2], -1, swimColour[1]); |
| 98 | + } else { |
| 99 | + yOffset--; |
| 100 | + waterColour = Colours.get(-1, -1, swimColour[1], swimColour[2]); |
| 101 | + } |
| 102 | + |
| 103 | + screen.render(xOffset, yOffset + 3, 31 + 31 * 32, waterColour, |
| 104 | + 0x00, 1); |
| 105 | + screen.render(xOffset + 8, yOffset + 3, 31 + 31 * 32, waterColour, |
| 106 | + 0x01, 1); |
| 107 | + } |
| 108 | + |
| 109 | + screen.render((xOffset + (modifier * flipTop)), yOffset, |
| 110 | + (xTile + yTile * 32), colour, flipTop, scale); |
| 111 | + screen.render((xOffset + modifier - (modifier * flipTop)), yOffset, |
| 112 | + ((xTile + 1) + yTile * 32), colour, flipTop, scale); |
| 113 | + if (!isSwimming && !isMagma && !isMuddy) { |
| 114 | + screen.render((xOffset + (modifier * flipBottom)), |
| 115 | + (yOffset + modifier), (xTile + (yTile + 1) * 32), colour, |
| 116 | + flipBottom, scale); |
| 117 | + screen.render((xOffset + modifier - (modifier * flipBottom)), |
| 118 | + (yOffset + modifier), ((xTile + 1) + (yTile + 1) * 32), |
| 119 | + colour, flipBottom, scale); |
| 120 | + colour = Colours.get(-1, 111, shirtCol, faceCol); |
| 121 | + } |
| 122 | + } |
| 123 | + |
| 124 | + public Swim getSwim() { |
| 125 | + return swim; |
| 126 | + } |
| 127 | + |
| 128 | + public void setSwim(Swim swim) { |
| 129 | + this.swim = swim; |
| 130 | + } |
| 131 | + |
| 132 | + public List<Node> getPath() { |
| 133 | + return path; |
| 134 | + } |
| 135 | + |
| 136 | + public void setPath(List<Node> path) { |
| 137 | + this.path = path; |
| 138 | + } |
| 139 | + |
| 140 | + public int getTime() { |
| 141 | + return time; |
| 142 | + } |
| 143 | + |
| 144 | + public void setTime(int time) { |
| 145 | + this.time = time; |
| 146 | + } |
| 147 | +} |
0 commit comments