Exemple #1
0
def tick_item(item):
	if 'CAN_BURN' in item['flags'] and item['burning'] and item['owner']:
		life.burn(LIFE[item['owner']], item['burning'])
	
	if 'stored_in' in item or is_item_owned(item['uid']):
		return False
	
	_z_max = numbers.clip(item['pos'][2], 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1)
	if item['velocity'][:2] == [0.0, 0.0] and WORLD_INFO['map'][item['pos'][0]][item['pos'][1]][_z_max]:
		return False
	
	_x = item['pos'][0]
	_y = item['pos'][1]
	
	#_view = gfx.get_view_by_name('map')
	#if 0<=_x<_view['draw_size'][0] and 0<=_y<_view['draw_size'][1]:
	if gfx.position_is_in_frame((_x, _y)):
		gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map')
	
	item['realpos'][0] += item['velocity'][0]
	item['realpos'][1] += item['velocity'][1]
	_break = False
	_line = drawing.diag_line(item['pos'],(int(round(item['realpos'][0])),int(round(item['realpos'][1]))))
	
	if not _line:
		item['velocity'][2] -= item['gravity']
		item['realpos'][2] = item['realpos'][2]+item['velocity'][2]
		item['pos'][2] = int(round(item['realpos'][2]))
		
		if item['pos'][0]<0 or item['pos'][0]>=MAP_SIZE[0] or item['pos'][1]<0 or item['pos'][1]>=MAP_SIZE[1]:
			delete_item(item)
			return False
		
		_z_min = numbers.clip(int(round(item['realpos'][2])), 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1)
		if collision_with_solid(item, [item['pos'][0], item['pos'][1], _z_min]):
			pos = item['pos'][:]
			_break = True
		
		create_effects(item, item['pos'], item['realpos'][2], _z_min)
	
	for pos in _line:
		item['realpos'][2] += item['velocity'][2]
		item['velocity'][2] -= item['velocity'][2]*item['gravity']
		
		if 'drag' in item:
			_drag = item['drag']
		else:
			_drag = item['gravity']
			logging.warning('Improper use of gravity.')
			
		_min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item)
		
		if 0<item['velocity'][0]<0.1 or -.1<item['velocity'][0]<0:
			item['velocity'][0] = 0
		
		if 0<item['velocity'][1]<0.1 or -.1<item['velocity'][1]<0:
			item['velocity'][1] = 0
		
		item['velocity'][0] -= numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel)
		item['velocity'][1] -= numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel)
		item['speed'] -= numbers.clip(item['speed']*_drag, 0, 100)
		
		if 0>pos[0] or pos[0]>=MAP_SIZE[0] or 0>pos[1] or pos[1]>=MAP_SIZE[1] or item['realpos'][2]<0 or item['realpos'][2]>=MAP_SIZE[2]-1:
			logging.warning('Item OOM: %s', item['uid'])
			delete_item(item)
			return False
		
		if collision_with_solid(item, [pos[0], pos[1], int(round(item['realpos'][2]))]):
			if item['type'] == 'bullet':
				effects.create_light(item['pos'], (255, 0, 0), 9, 0, fade=0.1)
			
			logging.debug('Item #%s hit a wall.' % item['uid'])
			
			return False
		
		if item['type'] == 'bullet':
			for _life in [LIFE[i] for i in LIFE]:
				if _life['id'] == item['shot_by'] or _life['dead']:
					continue					
				
				if _life['pos'][0] == pos[0] and _life['pos'][1] == pos[1] and _life['pos'][2] == int(round(item['realpos'][2])):
					remove_from_chunk(item)
					item['pos'] = [pos[0],pos[1],_life['pos'][2]]
					add_to_chunk(item)
					life.damage_from_item(_life,item,60)
					
					if item['uid'] in ITEMS:
						delete_item(item)
					
					return False
			
		if _break:
			break
		
		#_z_max = numbers.clip(int(round(item['realpos'][2]))+1, 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1)
		#if MAP[pos[0]][pos[1]][_z_max]:
		#	item['velocity'][0] = 0
		#	item['velocity'][1] = 0
		#	item['velocity'][2] = 0
		#	item['pos'] = [pos[0],pos[1],item['pos'][2]-1]
		#
		#	print 'LANDED',item['pos']	
		#	_break = True
		#	break
	
		_z_min = numbers.clip(int(round(item['realpos'][2])), 0, maputils.get_map_size(WORLD_INFO['map'])[2]-1)
		if collision_with_solid(item, [pos[0], pos[1], _z_min]):
			_break = True
			break
		
		create_effects(item, pos, item['realpos'][2], _z_min)
	
	remove_from_chunk(item)
	
	if _break:
		item['pos'][0] = int(pos[0])
		item['pos'][1] = int(pos[1])
		item['pos'][2] = int(round(item['realpos'][2]))
	else:
		item['pos'][0] = int(round(item['realpos'][0]))
		item['pos'][1] = int(round(item['realpos'][1]))
		item['pos'][2] = int(round(item['realpos'][2]))
	
	add_to_chunk(item)
	
	_x = item['pos'][0]
	_y = item['pos'][1]
	
	if gfx.position_is_in_frame((_x, _y)):
		gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map')

	if item['pos'][0] < 0 or item['pos'][0] > MAP_SIZE[0] \
          or item['pos'][1] < 0 or item['pos'][1] > MAP_SIZE[1]:
		delete_item(item)
		return False
			
	#elif _break:
	#	maps.refresh_chunk(life.get_current_chunk_id(item))

	_min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item)
	
	if 0<item['velocity'][0]<0.1 or -.1<item['velocity'][0]<0:
		item['velocity'][0] = 0
	
	if 0<item['velocity'][1]<0.1 or -.1<item['velocity'][1]<0:
		item['velocity'][1] = 0
	
	#TODO: This isn't gravity...
	if 'drag' in item:
		_drag = item['drag']
	else:
		_drag = item['gravity']
		logging.warning('Improper use of gravity.')
	
	item['velocity'][0] -= numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel)
	item['velocity'][1] -= numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel)
	item['speed'] -= numbers.clip(item['speed']*_drag, 0, 100)
Exemple #2
0
def tick_item(item):
	_z_max = bad_numbers.clip(item['pos'][2], 0, MAP_SIZE[2]-1)
	
	if item['type'] == 'bullet':
		_gravity = 0
	else:
		_gravity = item['gravity']
	
	if not is_moving(item):
		return False
	
	_x = item['pos'][0]
	_y = item['pos'][1]
	_break = False
	
	item['realpos'][0] += item['velocity'][0]
	item['realpos'][1] += item['velocity'][1]	
	
	_line = drawing.diag_line(item['pos'], (int(round(item['realpos'][0])),int(round(item['realpos'][1]))))

	#Refresh even if we're not moving far enough to switch tiles
	if gfx.position_is_in_frame((_x, _y)):
		gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map')
	
	if not _line:
		item['velocity'][2] -= _gravity
		item['realpos'][2] = item['realpos'][2]+item['velocity'][2]
		item['pos'][2] = int(round(item['realpos'][2]))
		
		if maps.is_oob(item['pos']):
			delete_item(item)
			
			return False
		
		_z_min = bad_numbers.clip(int(round(item['realpos'][2])), 0, MAP_SIZE[2]-1)
		
		collision_with_solid(item, [int(round(item['realpos'][0])), int(round(item['realpos'][1])), _z_min])
	
	for pos in _line:
		item['realpos'][2] += item['velocity'][2]
		
		if _gravity:
			item['velocity'][2] -= item['velocity'][2]*_gravity
		
		if 'drag' in item:
			_drag = item['drag']
		else:
			_drag = item['gravity']
			logging.warning('Improper use of gravity.')
			
		_min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item)
		
		if abs(item['velocity'][0])<=1:
			item['velocity'][0] = 0.0
			
		if abs(item['velocity'][1])<=1:
			item['velocity'][1] = 0.0
		
		if not is_moving(item):
			if item['type'] == 'bullet':
				delete_item(item)
				return False
		
		item['velocity'][0] -= bad_numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel)
		item['velocity'][1] -= bad_numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel)
		item['speed'] -= bad_numbers.clip(item['speed']*_drag, 0, 100)
		
		if maps.is_oob((pos[0], pos[1], int(round(item['realpos'][2])))) or maps.is_oob(item['realpos']):
			delete_item(item)
			
			return False
		
		#TODO: Don't just stop the object
		collision_with_solid(item, (pos[0], pos[1], int(round(item['realpos'][2]))))
		
		tick_effects(item)
				
		#TODO: Don't do this here... maybe a callback or something
		if item['type'] == 'bullet':
			for _life in [LIFE[i] for i in LIFE]:
				if not _life['online']:
					continue
				
				if _life['id'] == item['shot_by'] or _life['dead']:
					continue					
				
				if _life['pos'][0] == pos[0] and _life['pos'][1] == pos[1] and _life['pos'][2] == int(round(item['realpos'][2])):
					remove_from_chunk(item)
					item['pos'] = [pos[0],pos[1],_life['pos'][2]]
					add_to_chunk(item)
					life.damage_from_item(_life, item)
					
					if item['uid'] in ITEMS:
						delete_item(item)
					
					return False
		#if _break:
		#	break
	
		#_z_min = bad_numbers.clip(int(round(item['realpos'][2])), 0, MAP_SIZE[2]-1)
		#if collision_with_solid(item, [pos[0], pos[1], _z_min]):
		#	#_break = True
		#	break
		
		#create_effects(item, pos, item['realpos'][2], _z_min)
	
	remove_from_chunk(item)
	
	if _break:
		item['pos'][0] = int(pos[0])
		item['pos'][1] = int(pos[1])
		item['pos'][2] = int(round(item['realpos'][2]))
	else:
		item['pos'][0] = int(round(item['realpos'][0]))
		item['pos'][1] = int(round(item['realpos'][1]))
		item['pos'][2] = int(round(item['realpos'][2]))
	
	add_to_chunk(item)
	
	_x = item['pos'][0]
	_y = item['pos'][1]
	
	if gfx.position_is_in_frame((_x, _y)):
		gfx.refresh_view_position(_x-CAMERA_POS[0], _y-CAMERA_POS[1], 'map')

	if maps.is_oob(item['pos']):
		delete_item(item)
		
		return False

	_min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item)
	
	if abs(item['velocity'][0])<.35:
		item['velocity'][0] = 0.0
			
	if abs(item['velocity'][1])<.35:
		item['velocity'][1] = 0.0
	
	#TODO: This isn't gravity...
	if 'drag' in item:
		_drag = item['drag']
	else:
		_drag = item['gravity']
		logging.warning('Improper use of gravity.')
	
	item['velocity'][0] -= bad_numbers.clip(item['velocity'][0]*_drag, _min_x_vel, _max_x_vel)
	item['velocity'][1] -= bad_numbers.clip(item['velocity'][1]*_drag, _min_y_vel, _max_y_vel)
	item['speed'] -= bad_numbers.clip(item['speed']*_drag, 0, 100)
Exemple #3
0
def tick_item(item):
    _z_max = bad_numbers.clip(item['pos'][2], 0, MAP_SIZE[2] - 1)

    if item['type'] == 'bullet':
        _gravity = 0
    else:
        _gravity = item['gravity']

    if not is_moving(item):
        return False

    _x = item['pos'][0]
    _y = item['pos'][1]
    _break = False

    item['realpos'][0] += item['velocity'][0]
    item['realpos'][1] += item['velocity'][1]

    _line = drawing.diag_line(
        item['pos'],
        (int(round(item['realpos'][0])), int(round(item['realpos'][1]))))

    #Refresh even if we're not moving far enough to switch tiles
    if gfx.position_is_in_frame((_x, _y)):
        gfx.refresh_view_position(_x - CAMERA_POS[0], _y - CAMERA_POS[1],
                                  'map')

    if not _line:
        item['velocity'][2] -= _gravity
        item['realpos'][2] = item['realpos'][2] + item['velocity'][2]
        item['pos'][2] = int(round(item['realpos'][2]))

        if maps.is_oob(item['pos']):
            delete_item(item)

            return False

        _z_min = bad_numbers.clip(int(round(item['realpos'][2])), 0,
                                  MAP_SIZE[2] - 1)

        collision_with_solid(item, [
            int(round(item['realpos'][0])),
            int(round(item['realpos'][1])), _z_min
        ])

    for pos in _line:
        item['realpos'][2] += item['velocity'][2]

        if _gravity:
            item['velocity'][2] -= item['velocity'][2] * _gravity

        if 'drag' in item:
            _drag = item['drag']
        else:
            _drag = item['gravity']
            logging.warning('Improper use of gravity.')

        _min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(
            item)

        if abs(item['velocity'][0]) <= 1:
            item['velocity'][0] = 0.0

        if abs(item['velocity'][1]) <= 1:
            item['velocity'][1] = 0.0

        if not is_moving(item):
            if item['type'] == 'bullet':
                delete_item(item)
                return False

        item['velocity'][0] -= bad_numbers.clip(item['velocity'][0] * _drag,
                                                _min_x_vel, _max_x_vel)
        item['velocity'][1] -= bad_numbers.clip(item['velocity'][1] * _drag,
                                                _min_y_vel, _max_y_vel)
        item['speed'] -= bad_numbers.clip(item['speed'] * _drag, 0, 100)

        if maps.is_oob((pos[0], pos[1], int(round(
                item['realpos'][2])))) or maps.is_oob(item['realpos']):
            delete_item(item)

            return False

        #TODO: Don't just stop the object
        collision_with_solid(item,
                             (pos[0], pos[1], int(round(item['realpos'][2]))))

        tick_effects(item)

        #TODO: Don't do this here... maybe a callback or something
        if item['type'] == 'bullet':
            for _life in [LIFE[i] for i in LIFE]:
                if not _life['online']:
                    continue

                if _life['id'] == item['shot_by'] or _life['dead']:
                    continue

                if _life['pos'][0] == pos[0] and _life['pos'][
                        1] == pos[1] and _life['pos'][2] == int(
                            round(item['realpos'][2])):
                    remove_from_chunk(item)
                    item['pos'] = [pos[0], pos[1], _life['pos'][2]]
                    add_to_chunk(item)
                    life.damage_from_item(_life, item)

                    if item['uid'] in ITEMS:
                        delete_item(item)

                    return False
        #if _break:
        #	break

        #_z_min = bad_numbers.clip(int(round(item['realpos'][2])), 0, MAP_SIZE[2]-1)
        #if collision_with_solid(item, [pos[0], pos[1], _z_min]):
        #	#_break = True
        #	break

        #create_effects(item, pos, item['realpos'][2], _z_min)

    remove_from_chunk(item)

    if _break:
        item['pos'][0] = int(pos[0])
        item['pos'][1] = int(pos[1])
        item['pos'][2] = int(round(item['realpos'][2]))
    else:
        item['pos'][0] = int(round(item['realpos'][0]))
        item['pos'][1] = int(round(item['realpos'][1]))
        item['pos'][2] = int(round(item['realpos'][2]))

    add_to_chunk(item)

    _x = item['pos'][0]
    _y = item['pos'][1]

    if gfx.position_is_in_frame((_x, _y)):
        gfx.refresh_view_position(_x - CAMERA_POS[0], _y - CAMERA_POS[1],
                                  'map')

    if maps.is_oob(item['pos']):
        delete_item(item)

        return False

    _min_x_vel, _min_y_vel, _max_x_vel, _max_y_vel = get_min_max_velocity(item)

    if abs(item['velocity'][0]) < .35:
        item['velocity'][0] = 0.0

    if abs(item['velocity'][1]) < .35:
        item['velocity'][1] = 0.0

    #TODO: This isn't gravity...
    if 'drag' in item:
        _drag = item['drag']
    else:
        _drag = item['gravity']
        logging.warning('Improper use of gravity.')

    item['velocity'][0] -= bad_numbers.clip(item['velocity'][0] * _drag,
                                            _min_x_vel, _max_x_vel)
    item['velocity'][1] -= bad_numbers.clip(item['velocity'][1] * _drag,
                                            _min_y_vel, _max_y_vel)
    item['speed'] -= bad_numbers.clip(item['speed'] * _drag, 0, 100)