A simple yet fun game that I wrote. *Survive *Shoot *Get fuel
Enjoy!
__[ keys: ]___ ………………………………………………………………………………………………………………………… keys [Arrows] = Fly Spaceship ( 8 directions: Up,Down, Left, Right, Diagonal*4 ) key [OK] = Shoot key [Backspace] = Pause/Resume …………………………………………………………………………………………………………………………
from math import * from random import * from kandinsky import * from kandinsky import fill_rect as F from ion import * from time import * sleep(0.4) bg="black" F(0,0,322,222,bg) while not keydown(KEY_OK) and not keydown(KEY_EXE): draw_string("SIMPLE GAME",100,10,"cyan",bg) draw_string("KEYs [Arrow] = 8 Directions",30,60,"yellow",bg) draw_string("KEY [OK] = Shoot",65,80,"white",bg) draw_string("KEY [Backspace] = Pause/Resume",10,100,"orange",bg) draw_string("(Press [OK] or [EXE] to Start)",15,160,"gray",bg) laser_fire=True bg=(randint(0,100),randint(0,100),randint(0,100)) pe=35 px=7 py=100 pw=12 ph=7 pc="blue" pscore=0 fuel_x=randint(500,800) fuel_y=randint(30,170) fuel_w=fuel_h=9 fuel_c="green" meteor_x=randint(200,300) meteor_y=randint(0,20) meteor_w=meteor_h=randint(7,15) meteor_c=(randint(0,35),randint(0,35),randint(0,35)) rect_x=randint(250,400) rect_y=randint(22,200) rect_w=randint(20,150) rect_h=randint(15,150) rect_c=(randint(0,255),randint(0,255),randint(0,255)) F(0,0,322,222,bg) F(0,0,322,24,"black") # main loop while pe>0: fuel_x-=1 meteor_c=(randint(50,255),0,0) rect_x-=choice([2,3,4]) meteor_x-=choice([0,1,1,2]) meteor_y+=choice([0,1]) F(0,24,322,3,(randint(0,255),0,0)) F(0,219,322,3,(randint(0,255),0,0)) F(0,0,3,222,"white") F(317,0,3,222,"white") F(px,py,pw,ph,pc) F(px,py,1,ph,"cyan") F(px+pw-1,py,1,ph,"cyan") F(px,py,pw,1,"cyan") F(px,py+ph-1,pw,1,"cyan") F(fuel_x,fuel_y,fuel_w,fuel_h,fuel_c) F(fuel_x+fuel_w,fuel_y,1,fuel_h,bg) F(fuel_x,fuel_y,2,fuel_h,"white") F(fuel_x+fuel_w-2,fuel_y,2,fuel_h,"white") F(fuel_x,fuel_y,fuel_w,2,"white") F(fuel_x,fuel_y+fuel_h-2,fuel_w,2,"white") F(rect_x,rect_y,rect_w,rect_h,rect_c) F(rect_x,rect_y,2,rect_h,"red") F(rect_x+rect_w-2,rect_y,2,rect_h,"red") F(rect_x,rect_y,rect_w,2,"red") F(rect_x,rect_y+rect_h-2,rect_w,2,"red") F(rect_x+rect_w,rect_y,4,rect_h,bg) F(meteor_x,meteor_y,meteor_w,meteor_h,meteor_c) F(meteor_x+meteor_w,meteor_y,2,meteor_h,bg) F(meteor_x,meteor_y-2,meteor_w,2,bg) draw_string("SCORE:"+str(pscore),7,3,"orange","black") draw_string("ENERGY: ",140,3,"green","black") F(210,6,round(pe),12,"red") if rect_x+rect_w<0: rect_x=randint(250,400) rect_y=randint(-10,170) rect_w=randint(20,200) rect_h=randint(100,180) rect_c=(randint(100,255),randint(100,255),randint(100,255)) pscore+=randint(5,20) pe+=1 bg=(randint(0,100),randint(0,100),randint(0,100)) F(3,26,317,219,bg) if meteor_x+meteor_w<0-randint(5,20): meteor_x=randint(500,800) meteor_y=randint(-50,50) meteor_w=meteor_h=randint(5,12) if meteor_y+meteor_h>222+randint(20,50): meteor_x=randint(200,800) meteor_y=randint(-50,50) meteor_w=meteor_h=randint(10,20) if keydown(KEY_OK): if laser_fire: F(px+pw,py+1,322-px,3,(randint(0,255),randint(0,255),randint(0,255))) sleep(0.001) F(px+pw,py+1,322-px,3,bg) if keydown(KEY_OK) and meteor_y+meteor_h>=py+1 and meteor_y<=py+4: F(meteor_x,meteor_y,meteor_w,meteor_h,"black") sleep(0.04) F(meteor_x,meteor_y,meteor_w,meteor_h,bg) meteor_x=randint(300,900) meteor_y=randint(-200,-50) meteor_w=meteor_h=randint(10,20) pe+=0.2 #pause/resume game if keydown(KEY_BACKSPACE): draw_string("(PAUSED)",110,50,(randint(100,255),randint(100,255),randint(100,255)),bg) while keydown(KEY_BACKSPACE): pass while not keydown(KEY_BACKSPACE): pass while keydown(KEY_BACKSPACE): draw_string(" ",110,50,bg,bg) #player flies if keydown(KEY_LEFT): px-=2 F(px+pw,py,2,ph,bg) if keydown(KEY_RIGHT): px+=2 F(px-2,py,2,ph,bg) if keydown(KEY_UP): py-=2 F(px,py+ph,pw,2,bg) if keydown(KEY_DOWN): py+=2 F(px,py-2,pw,2,bg) #"The Spaceship crashing into # ceiling or ground...not good." # -Elon Musk, 2022 if py<26: py=26 F(px,py,pw,ph,"red") F(0,0,322,22,"black") pe-=0.4 if py+ph>219: py=219-ph F(px,py,pw,ph,"red") F(0,0,322,22,"black") pe-=0.4 if px<3:px=3 if px+pw>318:px=318-pw if meteor_y>=py:meteor_y-=1 # collision if px+pw>=rect_x and px<=rect_x+rect_w and py+ph>=rect_y and py<=rect_y+rect_h: pe-=0.5 F(px,py,pw,ph,"red") F(rect_x,rect_y,rect_w,rect_h,pc) F(0,0,322,22,"black") if px+pw>=meteor_x and px<=meteor_x+meteor_w and py+ph>=meteor_y and py<=meteor_y+meteor_h: pe-=0.4 F(px,py,pw,ph,"red") F(0,0,322,22,"black") if fuel_x+fuel_w<0-randint(2,10): fuel_x=randint(600,1200) fuel_y=randint(30,200) #player grabs random fuel capsule if px+pw>=fuel_x and px<=fuel_x+fuel_w and py+ph>=fuel_y and py<=fuel_y+fuel_h: F(px,py,pw,ph,"cyan") pe+=3 F(fuel_x,fuel_y,fuel_w,fuel_h,bg) fuel_x=randint(500,1000) fuel_y=randint(30,200) if pe<10: F(px,py,pw,ph,choice(["red","white",bg])) F(px,py+ph,2,2,"red") F(px,py-1,pw,1,bg) py+=choice([0,0,1]) #game over sx=450 sleep(1.2) F(0,0,322,222,(0,0,0)) draw_string("Written by: Wilson",11,7,"gray","black") while pe<1 and not keydown(KEY_OK): F(0,1,322,5,"red") F(0,217,322,5,"red") F(0,0,5,222,"red") F(316,0,5,222,"red") sleep(0.05) sx-=8 if sx<170: sx=170 draw_string("GAME OVER",100,80,(randint(0,255),0,randint(0,55)),"black") draw_string("SCORE:",100,120,"orange","black") draw_string(str(pscore)+" ",sx,120,"cyan","black") F(0,180,322,40,"red")