Hey I want to build a little game for a pc.
I already have the ground mechanics and now I dont have any Idea what the target of the game should be.
So have you some Ideas?
Thank you in andvance
Here is the code:
Click to see the code
Main Code:
/*
Controlls:
SPACE = JUMP
W = CHANGE ROTATE DIRECTION
*/
final float GRAVITY = 500;
ArrayList<Gear> gears;
float deltaTime = 0;
Player player;
void setup() {
rectMode(CENTER);
fullScreen();
//size(600, 600);
gears = new ArrayList<Gear>();
gears.add(new Gear(width/2, height/2+300, 70, radians(40)));
gears.add(new Gear(width/2+100, height/2, 100, radians(50)));
gears.add(new Gear(width/2-300, height/2-200, 200, radians(50)));
player = new Player(width/2, 0);
}
void draw() {
//println("Framerate: " + frameRate + "\n" + player.pos);
deltaTime = 1 / frameRate;
background(0);
for (int i = 0; i < gears.size(); i++) {
Gear g = gears.get(i);
g.show();
g.upadte();
}
player.move();
player.update();
player.show();
}
void mousePressed() {
gears.add(new Gear(mouseX, mouseY, random(50, 150), radians(random(20, 80))));
}
void keyPressed() {
if (key == ' ') {
player.jump();
} else if (key == 'w' || key == 'W') {
player.currentGear.rotateSpeed *= -1;
}
}
Gear Class
class Gear {
PVector pos;
float size;
float rotation;
float rotateSpeed;
boolean playerOnGear;
Gear(float x, float y, float r, float s) {
pos = new PVector(x, y);
size = r;
rotation = 0;
rotateSpeed = s;
playerOnGear = false;
}
PVector getPlayerPosition(PVector p, float a) {
float dir = a;
PVector v = PVector.fromAngle(dir);
v.normalize();
v.mult(size/2);
v.add(pos);
v.add(PVector.sub(p, pos).normalize().mult(player.size.y/2));
return v;
}
float getPlayerDirection(PVector p) {
PVector v = PVector.sub(p, pos);
return v.heading();
}
void show() {
noFill();
stroke(255);
strokeWeight(3);
pushMatrix();
translate(pos.x, pos.y);
rotate(rotation);
ellipse(0, 0, size, size);
line(0, 0, size/2, 0);
line(0, 0, -size/2, 0);
line(0, 0, 0, size/2);
line(0, 0, 0, -size/2);
popMatrix();
}
void upadte() {
rotation += rotateSpeed*deltaTime;
}
}
Player Class
class Player {
Gear currentGear;
PVector pos, size, vel;
float rotation, dirToGear;
float speed;
int pointHelpCount = 10;
Player(float x, float y) {
pos = new PVector(x, y);
size = new PVector(30, 50);
vel = new PVector(0, GRAVITY);
speed = 700;
rotation = 0;
}
void show() {
noFill();
stroke(255);
strokeWeight(2);
pushMatrix();
translate(pos.x, pos.y);
rotate(rotation);
rect(0, 0, size.x, size.y, 15, 15, 0, 0);
if (currentGear != null) {
for (int i = pointHelpCount; i > 0; i--) {
strokeWeight(i);
point(0, -i*10);
}
}
popMatrix();
}
void move() {
PVector v = vel.copy();
v.mult(deltaTime);
rotation = vel.heading() + PI/2;
pos.add(v);
if (pos.x > width) {
pos.x = 0;
currentGear = null;
}
if (pos.x < 0) {
pos.x = width;
currentGear = null;
}
if (pos.y > height) {
pos.y = 0;
currentGear = null;
}
if (pos.y < 0) {
pos.y = height;
currentGear = null;
}
if (currentGear != null) {
pos.set(currentGear.getPlayerPosition(pos, dirToGear));
rotation = currentGear.getPlayerDirection(pos) + PI/2;
dirToGear += currentGear.rotateSpeed*deltaTime;
vel.set(0, 0);
}
}
void update() {
if (currentGear == null) {
for (int i = 0; i < gears.size(); i++) {
Gear g = gears.get(i);
float d = PVector.dist(pos, g.pos);
if (d < size.y/2+g.size/2) {
println("On Gear");
currentGear = g;
dirToGear = g.getPlayerDirection(pos);
vel.set(0, 0);
}
}
}
}
void jump() {
if (currentGear == null) return;
PVector dir = PVector.sub(pos, currentGear.pos);
dir.normalize();
dir.mult(speed);
vel.set(dir);
currentGear = null;
println("JUMP");
}
}