-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathisContact.py
More file actions
203 lines (188 loc) · 7.47 KB
/
isContact.py
File metadata and controls
203 lines (188 loc) · 7.47 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 5 14:32:50 2014
@author: koenigin
"""
import pygame, sys, random
from pygame.locals import *
# set up pygame
pygame.init()
mainClock = pygame.time.Clock()
# set up the window
WINDOWWIDTH = 1600
WINDOWHEIGHT = 850
windowSurface = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT), 0, 32)
pygame.display.set_caption('Ladders')
# set up the colors
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
WHITE = (255, 255, 255)
BLUE = (0, 0, 255)
# set up movement variables
moveLeft = False
moveRight = False
moveUp = False
moveDown = False
MOVESPEED = 6
player = [pygame.draw.rect(windowSurface, WHITE, (100,0,100,100))]
ladder = [pygame.draw.rect(windowSurface, BLUE, (50, 100, 150, 850))]
plat = [pygame.draw.rect(windowSurface, GREEN, (0, 800, 300, 100))]
def isContact(actor, other):
'''takes in the jumpmann actor and an object and determines if there is contact between the two'''
if (actor.right - 0.5* actor.width <= other.right) and (actor.right - 0.5*actor.width >= other.left):
if actor.bottom <= other.top:
return True
else:
return False
def modeSelect(actor, climb, walk):
'''take in a list of climable object called 'climb', and list of platforms
called 'walk' and determines the mode (controls allowed) based on what
the jumperman is in contact with'''
for up in climb:
if isContact(actor, up):
Climb = True
break
for platform in walk:
if isContact(actor, platform):
Walk = True
break
if Walk and Climb:
return 'both'
elif Walk and not Climb:
return 'walk'
elif Climb and not Walk:
return 'climb'
else:
return 'non-interactive'
#Code below currently does not work!!!
#was attempting to use case selector for mode
#while True:
# for event in pygame.event.get():
# mode = modeSelect(player, ladder, plat)
# if event.type == QUIT:
# running = False
# pygame.quit()
# sys.exit()
# if mode == 'both':
# if event.type == KEYDOWN: #denotes that one or more keys are pushed down
# # change the keyboard variables
# if event.key == K_LEFT or event.key == ord('a'):
# moveRight = False
# moveLeft = True
# if event.key == K_RIGHT or event.key == ord('d'):
# moveLeft = False
# moveRight = True
# if event.key == K_UP or event.key == ord('w'):
# moveDown = False
# moveUp = True
# if event.key == K_DOWN or event.key == ord('s'):
# moveUp = False
# moveDown = True
# if event.type == KEYUP: #denotes that no keys are pushed down
# if event.key == K_ESCAPE:
# pygame.quit()
# sys.exit()
# if event.key == K_LEFT or event.key == ord('a'):
# moveLeft = False
# if event.key == K_RIGHT or event.key == ord('d'):
# moveRight = False
# if event.key == K_UP or event.key == ord('w'):
# moveUp = False
# if event.key == K_DOWN or event.key == ord('s'):
# moveDown = False
# if event.key == ord('x'):
# player.top = random.randint(0, WINDOWHEIGHT - player.height)
# player.left = random.randint(0, WINDOWWIDTH - player.width)
# elif mode == 'climb':
# if event.type == KEYDOWN: #denotes that one or more keys are pushed down
# # change the keyboard variables
# if event.key == K_LEFT or event.key == ord('a'):
# moveRight = False
# moveLeft = False
# if event.key == K_RIGHT or event.key == ord('d'):
# moveLeft = False
# moveRight = False
# if event.key == K_UP or event.key == ord('w'):
# moveDown = False
# moveUp = True
# if event.key == K_DOWN or event.key == ord('s'):
# moveUp = False
# moveDown = True
# if event.type == KEYUP: #denotes that no keys are pushed down
# if event.key == K_ESCAPE:
# pygame.quit()
# sys.exit()
# if event.key == K_LEFT or event.key == ord('a'):
# moveLeft = False
# if event.key == K_RIGHT or event.key == ord('d'):
# moveRight = False
# if event.key == K_UP or event.key == ord('w'):
# moveUp = False
# if event.key == K_DOWN or event.key == ord('s'):
# moveDown = False
# if event.key == ord('x'):
# player.top = random.randint(0, WINDOWHEIGHT - player.height)
# player.left = random.randint(0, WINDOWWIDTH - player.width)
# elif mode == 'walk':
# if event.type == KEYDOWN: #denotes that one or more keys are pushed down
# # change the keyboard variables
# if event.key == K_LEFT or event.key == ord('a'):
# moveRight = False
# moveLeft = True
# if event.key == K_RIGHT or event.key == ord('d'):
# moveLeft = False
# moveRight = True
# if event.key == K_UP or event.key == ord('w'):
# moveDown = False
# moveUp = False
# if event.key == K_DOWN or event.key == ord('s'):
# moveUp = False
# moveDown = False
# if event.type == KEYUP: #denotes that no keys are pushed down
# if event.key == K_ESCAPE:
# pygame.quit()
# sys.exit()
# if event.key == K_LEFT or event.key == ord('a'):
# moveLeft = False
# if event.key == K_RIGHT or event.key == ord('d'):
# moveRight = False
# if event.key == K_UP or event.key == ord('w'):
# moveUp = False
# if event.key == K_DOWN or event.key == ord('s'):
# moveDown = False
# if event.key == ord('x'):
# player.top = random.randint(0, WINDOWHEIGHT - player.height)
# player.left = random.randint(0, WINDOWWIDTH - player.width)
# else:
# moveRight = False
# moveLeft = False
# moveUp = False
# moveDown = False
#
# # draw the black background onto the surface
# windowSurface.fill(BLACK)
# # move the player
# if moveDown and player.bottom < WINDOWHEIGHT:
# player.top += MOVESPEED
# if moveUp and player.top > 0:
# player.top -= MOVESPEED
# if moveLeft and player.left > 0:
# player.left -= MOVESPEED
# if moveRight and player.right < WINDOWWIDTH:
# player.right += MOVESPEED
#
# # draw the player onto the surface
# pygame.draw.rect(windowSurface, BLUE, ladder)
# pygame.draw.rect(windowSurface, WHITE, player)
#
#
# # draw the window onto the screen
# pygame.display.update()
# mainClock.tick(40)
#pygame.quit()
#
#
#
#
#
#