Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage
- player,
- donut;
- float
- playerX,
- playerY,
- playerSize,
- step,
- donutX,
- donutY,
- donutSize;
- int score = 0;
- boolean
- left, // false
- right, // false
- up, // false
- down; // false
- void setup () {
- size(1200, 600);
- imageMode (CENTER);
- player = loadImage("data/player.png");
- donut = loadImage("data/donut.png");
- playerX = width * 0.5;
- playerY = height * 0.5;
- playerSize = height * 0.15;
- step = height * 0.02;
- donutX = donutY = donutSize = height * 0.1;
- }
- void donut () {
- image (donut, donutX, donutY, donutSize, donutSize);
- //float a = donutY - playerY;
- //float b = donutX - playerX;
- //float c = sqrt (a * a + b * b);
- float c = dist (donutX, donutY, playerX, playerY);
- if (c < (donutSize + playerSize)/2) {
- donutX = random (width - donutSize / 2);
- donutY = random (height - donutSize / 2);
- //score = score + 1;
- //score += 1;
- ++score;
- }
- }
- void player () {
- image (player, playerX, playerY, playerSize, playerSize);
- if (left) // if (left == true)
- playerX -= step;
- if (right)
- playerX += step;
- if (up)
- playerY -= step;
- if (down)
- playerY += step;
- }
- void keyPressed () {
- if (key == 'a')
- left = true;
- if (key == 'd')
- right = true;
- if (key == 'w')
- up = true;
- if (key == 's')
- down = true;
- }
- void keyReleased () {
- left = right = up = down = false;
- }
- void score () {
- fill (0); // tekstas bus juodas
- textSize (donutSize); // teksto dydis bus lygus spurgos dydžiui
- text (score, width - donutSize * 1.5, donutSize);
- if (score == 3){
- background (100);
- textAlign (CENTER);
- text ("Game Over", width / 2, height / 2);
- }
- }
- void draw () {
- background (255);
- donut ();
- player ();
- score ();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement