Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var state = 0;
- var img;
- var player_img;
- var font;
- var player;
- var fish1;
- var fish2;
- var fish1_img;
- var fish2_img;
- var cat1;
- // 0 = START
- // 1 = MAIN
- // 2 = STOP
- var _startText;
- var background1;
- var blowfish;
- var blowfish_img
- var shark;
- var shark_img;
- var score = 0;
- function start() {
- background(47,47,47)
- image(img, 32, height/5, img.width/5, img.height/5);
- textFont(font, 16)
- fill(255);
- text('Press SPACE to play', 50, height/2 +100)
- }
- function main() {
- background(background1)
- if (keyIsDown(39) && player.position.x < width - 33 ) {
- player.setSpeed(5, 0);
- }
- else {
- player.setSpeed(0, 0);
- }
- if (keyIsDown(37) && player.position.x > + 33) {
- player.setSpeed(5, 180);
- }
- if (keyCode == 32) {
- player.setSpeed(0, 0);
- }
- drawSprites();
- // move first fish across canvas
- fish1.position.y +=4
- if (fish1.position.y > height + 33){
- fish1.position.y =-33
- fish1.position.x = random(30, 300)
- }
- if(player.overlap(fish1)){
- fish1.position.x = random(30, 300)
- fish1.position.y =-33
- score +=1
- }
- // move tropical fish across canvas
- fish2.position.y +=8
- if (fish2.position.y > height + 33){
- fish2.position.y =-33
- fish2.position.x = random(30, 300)
- }
- if(player.overlap(fish2)){
- fish2.position.x = random(30, 300)
- fish2.position.y =-33
- score +=2
- }
- // move blowfish across canvas
- blowfish.position.y +=4
- if (blowfish.position.y > height + 33){
- blowfish.position.y =-33
- blowfish.position.x = random(30, 300)
- }
- if(player.overlap(blowfish)){
- blowfish.position.x = random(30, 300)
- blowfish.position.y =-33
- score +=1
- }
- // move shark across canvas
- fish1.position.y +=4
- if (fish1.position.y > height + 33){
- fish1.position.y =-33
- fish1.position.x = random(30, 300)
- }
- if(player.overlap(fish1)){
- fish1.position.x = random(30, 300)
- fish1.position.y =-33
- score +=1
- }
- fill(255, 255, 255)
- textFont(font) && textSize(16) && textStyle(BOLD) && textAlign(RIGHT);
- text('Score :' + score, width/1.125, height/9);
- // textFont(font, 16)
- // fill(255);
- // text('Score: ', + score, 50, height/2 +100);
- }
- function stop() {
- }
- function fishMovement() {
- }
- function keyPressed() {
- if (state === 0 && keyCode === 32) {
- state = 1
- }
- }
- function preload() {
- font = loadFont("prstart.ttf")
- img = loadImage("assets/cat catch logo.png");
- player_img = loadImage("assets/cat1.png");
- // create a sprite
- player = createSprite(200, 564);
- player.addImage(player_img);
- player.scale = 0.28;
- fish1_img = loadImage('assets/fish.png')
- fish2_img = loadImage('assets/tropical fish.png')
- //create fish sprites
- fish1 = createSprite(200, 204);
- fish1.addImage(fish1_img);
- fish1.scale = 0.4;
- fish1.rotation = 270
- //create 2nd fish
- fish2 = createSprite(200, 204);
- fish2.addImage(fish2_img);
- fish2.scale = 0.4;
- fish2.rotation = 270
- background1 = loadImage('assets/background.PNG')
- blowfish = createSprite(200, 204);
- blowfish = loadImage('assets/blowfish.png')
- blowfish.addImage(blowfish_img)
- blowfish.scale = 0.4
- }
- function setup() {
- createCanvas(400, 600)
- }
- function draw() {
- if (state === 0) {
- start()
- }
- else if (state === 1) {
- main()
- }
- else if (state === 2) {
- stop()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement