Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

meowonID

2
Posts
A member registered Nov 07, 2023 · View creator page →

Creator of

Recent community posts

(1 edit)

code for the app:

also w a s d for to go to top,left,bottom,right and f for shoot

import pygame,random,time
from sys import exit
pygame.init()
width=480
height=240
fps=60
screen=pygame.display.set_mode((width,height))
pygame.display.set_caption("meowonID's rectangle game (Inactive)")
plr=pygame.Surface((15,15))
plr.fill((50,50,135))
bullet=pygame.Surface((20,5))
bullet.fill((165,165,55))
enemy=pygame.Surface((15,15))
enemy.fill((165,10,10))
border=pygame.Surface((15,240))
border.fill((255,255,255))
borderrect= border.get_rect(center=(15, height//2))
enemylist=[]
bulletlist=[]
plrrect=plr.get_rect(center=(width//2,height//2))
plrspeed=2.5
maxammo=15
ammo=15
score=0
isreloading=False
isshooting=False
reloadtime=1000
shootdebounce=250
lastshoottime=0
middletime=2500
enemyevent=pygame.USEREVENT+1
pygame.time.set_timer(enemyevent,1000)
active="False"
dev=False
def enemytouchedborderUI():
    screen.fill((35,5,5))
    etbfont=pygame.font.SysFont("Arial",25,bold=True,italic=False)
    etbtext=etbfont.render("game over! enemy touched the white border",True,pygame.Color(135,10,10))
    etbrect=etbtext.get_rect(center=(width//2,height//2))
    screen.blit(etbtext,etbrect)
    pygame.display.update()
    pygame.time.delay(2000)
    pygame.quit()
    exit()
def enemytouchedplayerUI():
    screen.fill((35,5,5))
    etpfont=pygame.font.SysFont("Arial",25,bold=True,italic=False)
    etptext=etpfont.render("game over! enemy touched the player :C",True,pygame.Color(135,10,10))
    etprect=etptext.get_rect(center=(width//2,height//2))
    screen.blit(etptext,etprect)
    pygame.display.update()
    pygame.time.delay(2000)
    pygame.quit()
    exit()
def movementhandler():
    #move enemy
    for enemyrect in enemylist[:]:
        enemyrect.x-=3
        enemyrect.y+=random.randint(-2,2)
        if enemyrect.y<=0:
            enemyrect.y+=20
        if enemyrect.y>=height:
            enemyrect.y-=20
    #move stuff
    for bulletrect in bulletlist[:]:
        bulletrect.x+=5
    for bulletrect in bulletlist:
        screen.blit(bullet,bulletrect)
    key=pygame.key.get_pressed()
    bordercollideplr=pygame.Rect.colliderect(plrrect,borderrect)
    if key[pygame.K_a] and not bordercollideplr:
        plrrect.x-=plrspeed+0.5
    if key[pygame.K_d] and plrrect.right<width:
        plrrect.x+=plrspeed
    if key[pygame.K_w] and plrrect.top>height-height:
        plrrect.y-=plrspeed+0.5
    if key[pygame.K_s] and plrrect.bottom<height:
        plrrect.y+=plrspeed
def shootingreloadinghandler():
    global isreloading,isshooting,ammo,maxammo
    if isreloading==True:
        current_time_reload=pygame.time.get_ticks()
        reloadingfont = pygame.font.SysFont("Arial", 65, bold=True)
        reloadtext = reloadingfont.render("Reloading...", True, pygame.Color(255, 255, 255))
        reloadrect = reloadtext.get_rect(center=(width//2,height//2))
        screen.blit(reloadtext, reloadrect)
        if current_time_reload-reloadstarttime>=reloadtime:
            # as current time reload gets larger reload start times effect on minusing gets smaller
            # and thus can be above reloadtime
            ammo=maxammo
            isreloading=False
    if isshooting==True:
        current_time_shooting=pygame.time.get_ticks()
        if current_time_shooting-lastshoottime >= shootdebounce:
            isshooting=False
def collisionhandler():
    global score
    for enemyrect in enemylist:
        screen.blit(enemy,enemyrect)
        collide=pygame.Rect.colliderect(plrrect,enemyrect)
        collide2=pygame.Rect.colliderect(borderrect,enemyrect)
        if collide and dev==False:
            enemytouchedplayerUI()
        if collide2 and dev==False:
            enemytouchedborderUI()
        for bulletrect in bulletlist:
            collide3=pygame.Rect.colliderect(enemyrect,bulletrect)
            if collide3:
                bulletlist.remove(bulletrect)
                enemylist.remove(enemyrect)
                score+=1
def wincondition():
    if score==45:
        pygame.display.set_caption("OMG U WON !@(#@$! thanks for playing - meowonID")
        screen.fill((30,125,30))
        wintxt=pygame.font.SysFont("Arial",25,bold=True).render("you won :O!!!#!# (u dont get anything.)",True,pygame.Color(25,76,25))
        wintxtrect=wintxt.get_rect(center=(width//2,height//2))
        screen.blit(wintxt,wintxtrect)
        pygame.display.flip()
        pygame.time.delay(3500)
        exit()
while True:
    for event in pygame.event.get():
        if event.type==pygame.QUIT or event.type==pygame.KEYDOWN and event.key==pygame.K_ESCAPE:
            pygame.quit()
            exit()
        if event.type==pygame.KEYDOWN and event.key==pygame.K_j and active=="False":
            active="Middle"
            middle_start_time=pygame.time.get_ticks()
        if event.type==enemyevent and active=="True":
            newenemy=enemy.get_rect(center=(500,random.randint(15,height-15)))
            enemylist.append(newenemy)
        if event.type==pygame.KEYDOWN and event.key==pygame.K_f and active=="True":
            if ammo>0 and not isshooting:
                newbullet=bullet.get_rect(midleft=(plrrect.x+15,plrrect.y+6.5))
                bulletlist.append(newbullet)
                ammo-=1
                isshooting=True
                lastshoottime=pygame.time.get_ticks()
            if ammo==0 and not isreloading:
                isreloading=True
                reloadstarttime=pygame.time.get_ticks()
    if active=="False":
        #starting screen
        screen.fill((35,35,35))
        startfont=pygame.font.SysFont('Arial',55,bold=True,italic=True)
        starttxt=startfont.render("J to start the game :D",True,pygame.Color(255,255,255))
        starttxtrect=starttxt.get_rect(center=(width//2,height//2))
        screen.blit(starttxt,starttxtrect)
    if active=="Middle":
        pygame.display.set_caption("meowonID's rectangle game (Middle)")
        screen.fill((35,35,35))
        current_middle_time=pygame.time.get_ticks()
        middletext=pygame.font.SysFont('Arial',17,bold=True).render("Mission: kill red rectangles and dont let them collide with the border",True,pygame.Color(255,255,255))
        middletext2=pygame.font.SysFont('Arial',25,bold=True).render("And main goal: get 45 score to win!!",True,pygame.Color(100,200,100))
        middletext3=pygame.font.SysFont('Arial',25,bold=True).render("(And stats are in the title bar of the window)",True,pygame.Color(255,255,255))
        middletextrect=middletext.get_rect(center=(width/2,height/2))
        middletext2rect=middletext2.get_rect(center=(width/2,height/2+17))
        middletext3rect=middletext3.get_rect(center=(width/2,height/2+17+25))
        screen.blit(middletext,middletextrect)
        screen.blit(middletext2,middletext2rect)
        screen.blit(middletext3,middletext3rect)
        pygame.display.update()
        if current_middle_time - middle_start_time >=middletime:
            active="True"
    if active=="True":
        pygame.display.set_caption("Ingame | Ammo: " + str(ammo) + " | Score: " + str(score))
        screen.fill((15,15,15))
        #collision detection
        # for enemyrect in enemylist:
        #     screen.blit(enemy,enemyrect)
        #     collide=pygame.Rect.colliderect(plrrect,enemyrect)
        #     collide2=pygame.Rect.colliderect(borderrect,enemyrect)
        #     if collide and dev==False:
        #         enemytouchedplayer()
        #     if collide2 and dev==False:
        #         enemytouchedborder()
        #     for bulletrect in bulletlist:
        #         collide3=pygame.Rect.colliderect(enemyrect,bulletrect)
        #         if collide3 and dev==True:
        #             bulletlist.remove(bulletrect)
        #             enemylist.remove(enemyrect)
        collisionhandler()
        movementhandler()
        shootingreloadinghandler()
        wincondition()
            
        #blit
        screen.blit(plr,plrrect)
        screen.blit(border,borderrect)
    pygame.display.update()
    pygame.time.Clock().tick(fps)