-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtp0.py
45 lines (42 loc) · 1.16 KB
/
tp0.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#Abdulwahab Al-Rumaihi, andrewID:arumaihi
#Imports
import pygame as pg
import sys
#Initializing the main window
pg.init()
clock=pg.time.Clock()
black=0, 0, 0
screen=pg.display.set_mode((1280, 720))
pg.display.set_caption("Pikmin")
pikminList=[]
def createPikmin():
#This function creates a pikmin
pikmin=pg.image.load("pikmin.png")
pikRect=pikmin.get_rect()
pikminList.append([pikmin, pikRect])
def followMouse(pikRect, pos):
#This function let's the pikmin follow the mouse
pikX, pikY=pikRect.center[0], pikRect.center[1]
mouseX, mouseY=pos[0], pos[1]
if pikX<mouseX:
pikRect.move_ip([1,0])
if pikX>mouseX:
pikRect.move_ip([-1,0])
if pikY<mouseY:
pikRect.move_ip([0,1])
if pikY>mouseY:
pikRect.move_ip([0,-1])
#This is the game loop
while True:
screen.fill(black)
for event in pg.event.get():
if event.type==pg.QUIT:
sys.exit()
if event.type==pg.MOUSEBUTTONDOWN:
if len(pikminList)<20:
createPikmin()
mPosition=pg.mouse.get_pos()
for i in pikminList:
followMouse(i[1], mPosition)
screen.blit(i[0], i[1])
pg.display.flip()