Android Open Source - raycaster Player






From Project

Back to project page raycaster.

License

The source code is released under:

Copyright (c) 2014 Fredrik Wallgren Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the...

If you think the Android project raycaster listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.ramblingsby.raycaster;
//from w w  w . java2 s.co m
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;

public class Player {
  protected double x;
  protected double y;
  protected double direction;
  protected double paces;

  protected Texture weapon;

  public Player(double x, double y, double direction) {
    this.x = x;
    this.y = y;
    this.direction = direction;
    this.paces = 0;
    this.weapon = new Texture(Gdx.files.internal("knife_hand.png"));
  }

  public void rotate(double angle) {
    this.direction = (this.direction + angle + Raycaster.CIRCLE) % (Raycaster.CIRCLE);
  }

  public void walk(double distance, Map map) {
    double dx = Math.cos(this.direction) * distance;
    double dy = Math.sin(this.direction) * distance;
    if (map.get(this.x + dx, this.y) <= 0) this.x += dx;
    if (map.get(this.x, this.y + dy) <= 0) this.y += dy;
    this.paces += distance;
  }

  public void update(Controls controls, Map map, double seconds) {
    if (controls.left) this.rotate(-Math.PI * seconds);
    if (controls.right) this.rotate(Math.PI * seconds);
    if (controls.forward) this.walk(3 * seconds, map);
    if (controls.backward) this.walk(-3 * seconds, map);
  }

  public Point toPoint() {
    return new Point(this.x, this.y);
  }
}




Java Source Code List

me.ramblingsby.raycaster.Camera.java
me.ramblingsby.raycaster.Controls.java
me.ramblingsby.raycaster.IOSLauncher.java
me.ramblingsby.raycaster.Map.java
me.ramblingsby.raycaster.Player.java
me.ramblingsby.raycaster.Point.java
me.ramblingsby.raycaster.Projection.java
me.ramblingsby.raycaster.Ray.java
me.ramblingsby.raycaster.Raycaster.java
me.ramblingsby.raycaster.Step.java
me.ramblingsby.raycaster.android.AndroidLauncher.java
me.ramblingsby.raycaster.client.HtmlLauncher.java
me.ramblingsby.raycaster.desktop.DesktopLauncher.java