Week 6: Midterm Project

For the game I would like to do for this midterm,  I am developing a game I created a year ago called Sounds Like NYUAD.

  Concept:

The layout is the Nyuad campus, which I illustrated myself last year. The player’s goal is to find the hidden ‘sounds’ located in various NYUAD locations, and each sound is an addition to the final ‘song’ made up of NYUAD sounds. The sounds were also recorded, edited, and produced by me last year. In the song, there are sounds like the NYUAD birds, the Card Swipe, someone sneezing, and coughing (pre-covid times).

Implementation: 

The main thing I have to make sure of is that all sounds begin at the same time, but remain muted until they are triggered. This is because it is crucial that all the sounds play like one song, and stay on beat to the song I am playing. When the player comes close to the marker, the sound will be triggered, and that part is added.

 

Process: 

The game is currently coded on Python, and so translating it to Java is my first step. This is really exercising everything I learnt on Java, and also trying to keep track of which language I am using. Next I have some developments I would like to add, and bugs  I would like to fix.

  1. Adding a instruction page
  2. More clear indicator when you trigger a sound (and fixing the bug when it is repeated twice).
  3. Inidcating how many sounds are left
  4. Hints/clues where to find them
  5. Score calculated based on how many sounds + how fast
  6. Leadership list
  7. Fix bugs: such as cats and borders + A clear Indicator when you have hit a border

Sample: 

 

 

Game game;
Creature creature;
Borders borders;

void setup(){
    size(1024, 768);
    background(255, 255, 255);
    game = new Game ();
    creature = new Creature ();
    borders = new Borders ();
    

   
}

void draw (){
  game.drawGame();
}
class Borders{
  float x, y, x2, y2;
  
  Borders (){
  displayBorders();
  
  }
  
  void displayBorders(){
  stroke(200);
  line(x,y,x2,y2);
  }
}
class Creature{
  float x, y, r;
  float vy = 0;
  float vx = 0;
  //direction = RIGHT; 
  
  Creature (){
   updateCreature();
   noFill();
   noStroke();
   image( img, x-r, y-r, 50, 50);
   circle(x,y, r*2);
   
  }
  void updateCreature(){
    y += vy;
    x += vx;
  }
  
  //void distanceCreature(self, target){
  //  return ((self.x - target.x)**2 + (self.y - target.y)**2) **0.5;
  //}
  
}
import processing.sound.*;
PImage img, dead, won;
SoundFile backgroundSound;

class Game {
  float w, h, g;
  float count = 120;
  float scorecount = 0;
  boolean totalwin = false;
  
  
  Game(){
  img = loadImage("map.jpg");
  dead = loadImage("sorry.png");
  won = loadImage("finalpage.png");
  //backgroundSound = new SoundFile("OriginalBacktrack.mp3");
  //backgroundSound.play();
}

void drawGame (){
  image (img, 0,0);
  fill (0,0,0);
  textSize(25);
  text("Time Remaining: ", 365, 50);
  fill(255,255,255);
  //textSize(25);
  text("Time Remaining: ", 363, 48 );
}
}

Here is the python code of the original: (its really long and messy, so I have a lot of reorganzing to do)

#Ayham and Suzan final project

add_library('minim')
import os, random 
path = os.getcwd()
player = Minim(this)

class Creature: #creates both the cats and thomas
    def __init__(self, x, y, r):
        self.x = x
        self.y = y
        self.r = r
        self.vy = 0
        self.vx = 0
        self.direction = RIGHT 
        
        
    def display(self):
        self.update()
        noFill()
        noStroke()
        image(self.img, self.x -self.r, self.y-self.r, 50, 50)
        # fill(255, 255, 255)
        circle(self.x, self.y, self.r * 2)
        
    def update(self):
        self.y += self.vy
        self.x += self.vx
        
            
        
    def distance(self, target):
        return ((self.x - target.x)**2 + (self.y - target.y)**2) **0.5
        
   
        
        
class Cats(Creature): #the cats class
    def __init__(self, x, y, r, img, w, h,x1, x2):
        Creature.__init__(self, x, y, r)
        
        self.vx = random.randint(1,3)
        self.x1 = x1
        self.x2 = x2
        self.img = loadImage(path + "/images/" + img)
        print(x,y)
        
    def update(self):
    
        if self.x < self.x1: #movement of the cats
            self.direction = RIGHT
            self.vx *= -1
        elif self.x > self.x2:
            self.direction = LEFT
            self.vx *= -1
        
        self.y += self.vy
        self.x += self.vx

        
class Thomas(Creature): 
    def __init__(self, x, y, r):
        Creature.__init__(self, x, y, r)
        print(x,y)
        self.key_handler = {LEFT:False, RIGHT:False, UP:False,DOWN:False}                                                               
        self.alive = True
        self.img= loadImage(path + "/images/thomas.png" )
        self.ding_sound = player.loadFile(path + "/sounds/Ding.mp3") #plays when one song part is captured
        self.meow_sound = player.loadFile(path + "/sounds/meow.mp3") #plays when it gets killed by a cat
    

                
    def update(self):
        
    
    #movement of thomas
        if self.key_handler[LEFT] == True and not self.x < 0 :
            self.vx = -1
            self.direction = LEFT
        elif self.key_handler[RIGHT] == True and not self.x + self.r > game.w :
            self.vx = 1
            self.direction = RIGHT
        elif self.key_handler[UP] == True and not self.y < 0:
            self.vy = -1
            self.direction = UP
        elif self.key_handler[DOWN] == True and not self.y +self.r > game.h:
            self.vy = 1
            self.direction = DOWN
            
        else:
            self.vx = 0
            self.vy = 0
       
       #boundaries created for thomas
       
       #horizental boundaries
        if (self.vy+(self.r*1)+self.y >= game.borders1.y and 
            self.vy+(self.r*1)+self.y <= game.borders1.y2 and 
             self.vx+self.r+self.x >= game.borders1.x and 
             self.vx+self.r+self.x <= game.borders1.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders2.y and 
            self.vy+(self.r*1)+self.y <= game.borders2.y2 and 
             self.vx+self.r+self.x >= game.borders2.x and 
             self.vx+self.r+self.x <= game.borders2.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders5.y and 
            self.vy+(self.r*1)+self.y <= game.borders5.y2 and 
             self.vx+self.r+self.x >= game.borders5.x and 
             self.vx+self.r+self.x <= game.borders5.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders6.y and 
            self.vy+(self.r*1)+self.y <= game.borders6.y2 and 
             self.vx+self.r+self.x >= game.borders6.x and 
             self.vx+self.r+self.x <= game.borders6.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders7.y and 
            self.vy+(self.r*1)+self.y <= game.borders7.y2 and 
             self.vx+self.r+self.x >= game.borders7.x and 
             self.vx+self.r+self.x <= game.borders7.x2):
            
            self.vy=0
        
        if (self.vy+(self.r*1)+self.y >= game.borders9.y and 
            self.vy+(self.r*1)+self.y <= game.borders9.y2 and 
             self.vx+self.r+self.x >= game.borders9.x and 
             self.vx+self.r+self.x <= game.borders9.x2):
            
            self.vy=0
        
            
        if (self.vy+(self.r*1)+self.y >= game.borders12.y and 
            self.vy+(self.r*1)+self.y <= game.borders12.y2 and 
             self.vx+self.r+self.x >= game.borders12.x and 
             self.vx+self.r+self.x <= game.borders12.x2):
            
            self.vy=0
        
        
        
        if (self.vy+(self.r*2)+self.y >= game.borders15.y and 
            self.vy+(self.r*2)+self.y <= game.borders15.y2 and 
            self.vx+self.r+self.x >= game.borders15.x and 
            self.vx+self.r+self.x <= game.borders15.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders25.y and 
            self.vy+(self.r*1)+self.y <= game.borders25.y2 and 
             self.vx+self.r+self.x >= game.borders25.x and 
             self.vx+self.r+self.x <= game.borders25.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders27.y and 
            self.vy+(self.r*1)+self.y <= game.borders27.y2 and 
             self.vx+self.r+self.x >= game.borders27.x and 
             self.vx+self.r+self.x <= game.borders27.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders30.y and 
            self.vy+(self.r*1)+self.y <= game.borders30.y2 and 
             self.vx+self.r+self.x >= game.borders30.x and 
             self.vx+self.r+self.x <= game.borders30.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders31.y and 
            self.vy+(self.r*1)+self.y <= game.borders31.y2 and 
             self.vx+self.r+self.x >= game.borders31.x and 
             self.vx+self.r+self.x <= game.borders31.x2):
            
            self.vy=0
            
        if (self.vy+(self.r*1)+self.y >= game.borders33.y and 
            self.vy+(self.r*1)+self.y <= game.borders33.y2 and 
             self.vx+self.r+self.x >= game.borders33.x and 
             self.vx+self.r+self.x <= game.borders33.x2):
            
            self.vy=0
        
            
            #vertical
        if (self.vx+(self.r*2)+self.x <= game.borders3.x and 
            self.vx+(self.r*2)+self.x >= game.borders3.x2 and 
            self.vy+self.r+self.y <= game.borders3.y and 
            self.vy+self.r+self.y >= game.borders3.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders4.x and 
            self.vx+(self.r*2)+self.x >= game.borders4.x2 and 
            self.vy+self.r+self.y <= game.borders4.y and 
            self.vy+self.r+self.y >= game.borders4.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders8.x and 
            self.vx+(self.r*2)+self.x >= game.borders8.x2 and 
            self.vy+self.r+self.y <= game.borders8.y and 
            self.vy+self.r+self.y >= game.borders8.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders11.x and 
            self.vx+(self.r*2)+self.x >= game.borders11.x2 and 
            self.vy+self.r+self.y <= game.borders11.y and 
            self.vy+self.r+self.y >= game.borders11.y2):
        
            self.vx = 0
        
        if (self.vx+(self.r*2)+self.x <= game.borders16.x and 
            self.vx+(self.r*2)+self.x >= game.borders16.x2 and 
            self.vy+self.r+self.y <= game.borders16.y and 
            self.vy+self.r+self.y >= game.borders16.y2):
        
            self.vx = 0
        if (self.vx+(self.r*2)+self.x <= game.borders19.x and 
            self.vx+(self.r*2)+self.x >= game.borders19.x2 and 
            self.vy+self.r+self.y <= game.borders19.y and 
            self.vy+self.r+self.y >= game.borders19.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders21.x and 
            self.vx+(self.r*2)+self.x >= game.borders21.x2 and 
            self.vy+self.r+self.y <= game.borders21.y and 
            self.vy+self.r+self.y >= game.borders21.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders22.x and 
            self.vx+(self.r*2)+self.x >= game.borders22.x2 and 
            self.vy+self.r+self.y <= game.borders22.y and 
            self.vy+self.r+self.y >= game.borders22.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders23.x and 
            self.vx+(self.r*2)+self.x >= game.borders23.x2 and 
            self.vy+self.r+self.y <= game.borders23.y and 
            self.vy+self.r+self.y >= game.borders23.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders24.x and 
            self.vx+(self.r*2)+self.x >= game.borders24.x2 and 
            self.vy+self.r+self.y <= game.borders24.y and 
            self.vy+self.r+self.y >= game.borders24.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders26.x and 
            self.vx+(self.r*2)+self.x >= game.borders26.x2 and 
            self.vy+self.r+self.y <= game.borders26.y and 
            self.vy+self.r+self.y >= game.borders26.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders28.x and 
            self.vx+(self.r*2)+self.x >= game.borders28.x2 and 
            self.vy+self.r+self.y <= game.borders28.y and 
            self.vy+self.r+self.y >= game.borders28.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders29.x and 
            self.vx+(self.r*2)+self.x >= game.borders29.x2 and 
            self.vy+self.r+self.y <= game.borders29.y and 
            self.vy+self.r+self.y >= game.borders29.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders32.x and 
            self.vx+(self.r*2)+self.x >= game.borders32.x2 and 
            self.vy+self.r+self.y <= game.borders32.y and 
            self.vy+self.r+self.y >= game.borders32.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders34.x and 
            self.vx+(self.r*2)+self.x >= game.borders34.x2 and 
            self.vy+self.r+self.y <= game.borders34.y and 
            self.vy+self.r+self.y >= game.borders34.y2):
        
            self.vx = 0
            
        if (self.vx+(self.r*2)+self.x <= game.borders35.x and 
            self.vx+(self.r*2)+self.x >= game.borders35.x2 and 
            self.vy+self.r+self.y <= game.borders35.y and 
            self.vy+self.r+self.y >= game.borders35.y2):
        
            self.vx = 0

        
        self.y += self.vy
        self.x += self.vx
        

            
        
            
        
        #sounds of the song and functions to when the song is detected
        if  library.distance(self) < 20:
            self.ding_sound.rewind()
            self.ding_sound.play() 
            game.library.setGain(1)
            library.win = True
            # showimage()
        if knocknock.distance(self) <20:
            self.ding_sound.rewind()
            self.ding_sound.play()
            game.knocknock.setGain(1)
            knocknock.win = True
        if  alarm.distance(self) <20:
            self.ding_sound.rewind()
            self.ding_sound.play()
            game.alarm.setGain(1)
            alarm.win = True
        if  baraha.distance(self) <20:
            self.ding_sound.rewind()
            self.ding_sound.play()
            game.baraha.setGain(1)
            baraha.win = True
        if  dining.distance(self) <20:
            self.ding_sound.rewind()
            self.ding_sound.play()
            game.dining.setGain(1)
            dining.win = True
        if  palms.distance(self) <20:
            self.ding_sound.rewind()
            self.ding_sound.play()
            game.palms.setGain(1)
            palms.win = True
        if  theatre.distance(self) <20:
            self.ding_sound.rewind()
            self.ding_sound.play()
            game.theatre.setGain(1) 
            theatre.win = True  
                
        for g in game.cats: #cats distribution
            if g.distance(self) <= self.r+ g.r:
                self.meow_sound.rewind()
                self.meow_sound.play()
                self.alive = False
        

            
       
        

        
class Locations(): #locaitions for the song parts
    def __init__(self, x, y,r ):
        self.x = x
        self.y= y
        self.r= r
        self.win= False
    
    def display(self):
        noFill()
        noStroke()
        circle(self.x, self.y, self.r)
 
    def distance(self, target):
        return ((self.x - target.x)**2 + (self.y - target.y)**2) **0.5
        

        
class Borders():
    def __init__(self,x,y,x2,y2):
        self.x = x
        self.y= y
        self.x2 = x2
        self.y2 = y2
        
    
    def display(self):
        stroke(200)
        line(self.x,self.y,self.x2,self.y2)
    
        
       
                        
class Game:
    def __init__(self, w, h, g):
        self.w = w
        self.h = h
        self.g = g
        self.img = loadImage(path + "/images/map.jpg")
        self.dead = loadImage(path + "/images/sorry.png")
        self.won = loadImage(path + "/images/finalpage.png")
        self.background_sound = player.loadFile(path + "/sounds/OriginalBacktrack.mp3")
        self.background_sound.play()
        self.baraha = player.loadFile(path + "/sounds/CardSwipe.mp3")
        self.baraha.setGain(-1000)
        self.baraha.play()
        self.knocknock = player.loadFile(path + "/sounds/Knock_RA.mp3")
        self.knocknock.setGain(-1000)
        self.knocknock.play()
        self.theatre = player.loadFile(path + "/sounds/SneezeCough.mp3")
        self.theatre.setGain(-1000)
        self.theatre.play()
        self.library = player.loadFile(path + "/sounds/Typing_clicking.mp3")
        self.library.setGain(-1000)
        self.library.play()
        self.palms = player.loadFile(path + "/sounds/Birds.mp3")
        self.palms.setGain(-1000)
        self.palms.play()
        self.dining = player.loadFile(path + "/sounds/Didyoudothereading.mp3")
        self.dining.setGain(-1000)
        self.dining.play()
        self.alarm = player.loadFile(path + "/sounds/iPhoneAlarm.mp3")
        self.alarm.setGain(-1000)
        self.alarm.play()
        self.thomas = Thomas(75,450,15)
        self.count = 120
        self.scorecount=0
        self.totalwin= False
        
#border coordinates 
        self.borders1 = Borders(444 , 286, 575, 286) #horizental
        self.borders2 = Borders(442 , 346, 520, 346)#horizental 
        self.borders3 = Borders(540 , 455, 540, 346) #V
        self.borders4 = Borders(582 , 456, 582 , 286) #V
        self.borders5 = Borders(402,470,502,470) #H
        self.borders6 = Borders(590,472,712,472)#H 
        self.borders7 = Borders(754,493,812,493)#H
        self.borders8 = Borders(874,541,874,509)#V
        self.borders21 = Borders(948,620,948,533)#V
        self.borders22 = Borders(158,370,158,182)#V
        self.borders23 = Borders(775,720,775,675)#V
        self.borders24 = Borders(800,720,800,675)#V
        self.borders25 = Borders(530,527,586,527)#h
        self.borders26= Borders(586,595,586,527)#V
        self.borders27 = Borders(536,595,586,595)#h
        self.borders28 = Borders(536,595,536,529)#V
        self.borders29 = Borders(396,664,396,614)#v
        self.borders30 = Borders(350,614,396,614)#h
        self.borders31= Borders(754,602,808,602)#h
        self.borders32 = Borders(808,640,808,602)#V
        self.borders33 = Borders(756,640,808,640)#h
        self.borders34 = Borders(756,640,756,602)#V
        self.borders35 = Borders(418,281,418,189)
        self.borders9 = Borders(50,195,470,195)#H
        self.borders11 = Borders(65,300,65,360)#V
        self.borders12 = Borders(65,375,422,375)#H
        self.borders15 = Borders(356,725,950,725)#H
        self.borders16 = Borders(340,750,340,572)#V
        self.borders19 = Borders(955,750,955,640)#V
       
        
        
        #appending the cats in the game
        self.cats = []
        for i in range(3):
            self.cats.append(Cats(random.randint(200, 900), random.randint(200, 600), 15, "cat" + str(random.randint(1,3))+".png", 70, 70, 200, 800))

        
    def display(self):
        image(self.img,0,0)
        fill(0,0,0)
        textSize(25)
        text("Time remaining: "+ str(self.count), 365, 50 )
        fill(255,255,255)
        textSize(25)
        text("Time remaining: "+ str(self.count), 364, 49 )
        if self.count == 0: #stop the game when the game is over
            self.thomas.alive = False
            self.background_sound.close()
            self.baraha.close()
            self.palms.close()
            self.library.close()
            self.dining.close()
            self.theatre.close()
            self.knocknock.close()
            self.alarm.close()
            
        if self.thomas.alive == False: 
            image(self.dead, 187, 59)
            self.background_sound.close()
            self.baraha.close()
            self.palms.close()
            self.library.close()
            self.dining.close()
            self.theatre.close()
            self.knocknock.close()
            self.alarm.close()
            
            return
        if library.win == True and alarm.win == True and palms.win == True and baraha.win == True and theatre.win == True and knocknock.win == True and dining.win == True: #winning of the game 
            self.totalwin= True
            image(self.won, 187, 59)
            self.background_sound.close()
            self.baraha.close()
            self.palms.close()
            self.library.close()
            self.dining.close()
            self.theatre.close()
            self.knocknock.close()
            self.alarm.close()
            return

            
        self.thomas.update()
        self.thomas.display() 
                    
        for g in self.cats:
            g.display() 
   
 #coordinates of the different sounds   
game = Game(1024, 768, 585)
library = Locations (250,270,100)
palms = Locations(250,470,100)
baraha = Locations (400, 310, 50)
theatre = Locations (790, 250, 100)
dining= Locations (950, 400, 100)
knocknock= Locations (800, 620, 200)
alarm= Locations (570, 570, 200)


            
def setup():
    size(game.w, game.h)
    background(255, 255, 255)

def draw():
    print(game.thomas.x,game.thomas.y)
    
    if game.thomas.alive == True and game.totalwin== False :
        if frameCount % 60 ==0:
            game.count -= 1
        print(game.scorecount)
        
    game.display()
    library.display()
    palms.display()
    baraha.display()
    theatre.display()
    dining.display()
    knocknock.display()
    alarm.display()
    
         

def keyPressed(): #aids in movement using the keys
    if keyCode == LEFT:
        game.thomas.key_handler[LEFT] = True
       
    elif keyCode == RIGHT:
        game.thomas.key_handler[RIGHT] = True
    elif keyCode == UP:
        game.thomas.key_handler[UP] = True
    elif keyCode == DOWN:
        game.thomas.key_handler[DOWN] = True
    
def keyReleased():
    if keyCode == LEFT:
        game.thomas.key_handler[LEFT] = False
    elif keyCode == RIGHT:
        game.thomas.key_handler[RIGHT] = False
    elif keyCode == UP:
        game.thomas.key_handler[UP] = False 
    elif keyCode == DOWN:
        game.thomas.key_handler[DOWN] = False 
        
    
def mouseClicked(): 
    global game
    if game.thomas.alive == False or game.totalwin== True: #clicks when game is over 
        game = Game(1024, 768, 585)
    

 

Leave a Reply