Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Wie ändere ich genau in diesem Beispiel die Gametime() und abhängig von der Rendertime()?
- final int X = 30;
- int S = 0;
- PImage alien_pic;
- PImage shooter_pic;
- class Alien {
- float x, y;
- float vx, vy;
- int i;
- int down;
- Alien(float x_Pos, float y_Pos) {
- x = x_Pos;
- y = y_Pos;
- vx = 30;
- vy = 30;
- down = 0;
- }
- void move() {
- if (down==0) {
- x = x + 30;
- }
- if (x == width) {
- x = width;
- for (int i=0; i<=1; i++) {
- y = y + vy;
- down=1;
- }
- }
- if (down==1) {
- vy=0;
- x = x - 30;
- }
- if (down==1) {
- if (x==0) {
- x = 0;
- vy=X;
- for (int i=0; i<=1; i++) {
- y = y + vy;
- down=0;
- }
- }
- }
- }
- void display() {
- image(alien_pic, x, y);
- move();
- }
- }
- class Shooter {
- float x, y;
- Shooter(float x_Pos, float y_Pos) {
- x = x_Pos;
- y = y_Pos;
- }
- void display() {
- image(shooter_pic, x, y);
- }
- }
- class Bullet {
- float x, y;
- float w, h;
- float vy;
- Bullet(float x_Pos) {
- x = x_Pos;
- y = 19*X;
- w = 5;
- h = 15;
- vy = 20;
- }
- void move() {
- y = y - vy;
- }
- void display() {
- rect(x, y, w, h);
- move();
- }
- }
- Alien alien1 = new Alien(X, X);
- Alien alien2 = new Alien(3*X, X);
- Alien alien3 = new Alien(5*X, X);
- Shooter shooter = new Shooter(8*X, 18*X);
- Bullet bullet = new Bullet(shooter.x+12);
- void setup() {
- size(17*X, 19*X);
- background(0);
- frameRate(5);
- alien_pic = loadImage("alien.jpg");
- shooter_pic = loadImage("shooter.jpg");
- //for-Schhleife zum Erstellen der 4 Reihen Aliens
- }
- void draw() {
- background(0);
- alien1.display();
- alien2.display();
- alien3.display();
- shooter.display();
- if (S >= 1) {
- bullet.display();
- }
- }
- void keyPressed() {
- if (key == ' ') {
- S = 1;
- }
- if (key == CODED){
- if (keyCode == LEFT) {
- if (shooter.x>=0+30){
- shooter.x = shooter.x - 30;
- }
- }
- if (keyCode == RIGHT) {
- if (shooter.x<=15*X){
- shooter.x = shooter.x + 30;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement