Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fill = ('white')
- var score = 0
- var health = 20
- var yoda = {
- x: 50,
- y: 150,
- vel: 0.5,
- gravity: 0.6
- }
- random = (0, 400)
- var seaguls = [
- {x: -200,y: 100},
- {x: -400,y: 200},
- {x: -600,y: 300},
- {x: -800,y: 250},
- {x: -1100,y: 200},
- ]
- var platforms = [
- {x: 100, y:300},
- {x: 200,y: 200},
- {x: 300,y: 380},
- {x: 440, y:200},
- {x: 500,y: 350},
- {x: 600, y: 180},
- {x: 700,y: 100},
- ]
- function setup() {
- createCanvas(400, 400);
- }
- //yoda jump
- function keyPressed() {
- if (keyCode == (UP_ARROW)) {
- yoda.vel = -10;
- }}
- function draw() {
- background(100, 100, 255)
- //yoda image
- //rotate( 1),
- fill('brown')
- rect(yoda.x, yoda.y, 30, 30, 5)
- line(yoda.x + 40, yoda.y + 40, yoda.x - 25, yoda.y);
- fill('lightgreen')
- ellipse(yoda.x + 20, yoda.y - 10, 50, 50);
- arc(yoda.x, yoda.y - 10, 25, 15, 60, HALF_PI);
- fill('black');
- ellipse(yoda.x + 32, yoda.y - 10, 10, 10);
- fill('lightgreen');;
- resetMatrix();
- //yoda movement
- if (keyIsDown(DOWN_ARROW)) {
- yoda.y += 5;
- }
- if (keyIsDown(LEFT_ARROW)) {
- yoda.x -= 5;
- //platforms.x += 5;
- }
- if (keyIsDown(RIGHT_ARROW)) {
- yoda.x += 5;
- for (var platform of platforms) {
- platform.x -= 5;
- }
- }
- for (var seagul of seaguls)
- {
- drawSeagul(seagul.x, seagul.y)
- seagul.x += 2;
- if (seagul.x > 900 ) {seagul.x= seagul.x-random(1200, 4000)}
- if (score > 200) {
- seagul.x +=4
- }
- if (score > 300) {
- seagul.x +=5
- }
- if (score > 600) {
- seagul.x +=8
- }
- }
- yoda.vel += yoda.gravity;
- for (var platform of platforms) {
- platform.x -= 1
- drawPlatform(platform.x, platform.y)
- if (platform.x < -100 ) {platform.x= platform.x+700}
- if (score > 200) {
- platform.x -=2
- }
- if (score > 300) {
- platform.x -=3
- }
- if (score > 400) {
- platform.x -=5
- }
- }
- yoda.y += yoda.vel;
- //score
- score += 0.5;
- text('score ' + score, 300, 20)
- text('health ' + health, 200, 20)
- }
- //seagul
- function drawSeagul(x, y) {
- fill('white')
- scale(1, 1);
- ellipse(x -20, y + 20, 80, 20);
- ellipse(x - 20, y+20, 50, 50);
- ellipse(x, y, 50, 50);
- fill('black')
- ellipse(x -10, y, 10, 10);
- fill('yellow')
- rect(x + 5, y, 20, 12, 10);
- resetMatrix();
- //yoda hits seagul or falls of platform - health low
- if (dist(yoda.x, yoda.y , x , y) < 50)
- {
- score = 0 ,
- health -=1 ,
- fill('red')
- rect( 0, 0 , 400, 400);
- }
- if (yoda.y >400 )
- {
- score = 0 ,
- health -=1 ,
- fill('red')
- rect( 0, 0 , 400, 400);
- }
- if
- (health < 0) {
- fill('red')
- rect( 0, 0 , 400, 400);
- }
- //platform draw and logic
- }
- function drawPlatform(x, y) {
- fill('lightgreen')
- if (yoda.y > y - 30 && yoda.y < y) {
- if (yoda.x > x - 30 && yoda.x < x + 50)
- {
- fill('yellow'); yoda.vel = 0;
- if (keyIsDown(DOWN_ARROW)) {
- yoda.y -= 5;
- }
- if (keyIsDown(UP_ARROW)) {
- yoda.y -=120;
- yoda.vel =-5
- }
- }
- }
- rect(x, y, 50, 25, 20)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement