[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] Re: [pygame] Moving a ….sprite…item?



Hi,

This is quite easy:
One way of doing this:

If game have only one resolution, first set coordinates where you arrows will be:

arrow pos = { 0 : (20,20) , 1:(20,40) , 2:(20,60) , 3 :(20,60) }

Now in your main loop on K_UP and K_DOWN events you can control on which position your arrows will be displayed:

counter = 0
while menu == "go":
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_ESCAPE:
menu = "off"

if event.key == K_UP:
if counter > 0:
counter -= 1

if event.key == K_DOWN:
if counter < 4:
counter += 1

if event.key == K_RETURN:
"action"


Now screen redraw:

menuscreen.blit(background,(0,0))
menuscreen.blit(arrow,arrow_pos[counter])
pygame.display.update()

Hope it will help you.

Ps. you don't have to use dictionary, list will do as well.
Ps. remember to use pygame.time.Clock() as well not to max out your CPU on a simple menu.

Cheers
Bart 

On Mon, Feb 27, 2012 at 8:48 PM, Zack Baker <zbaker1398@xxxxxxxxx> wrote:
Ok so im writing this game and i want to have a menu where you can select one of the items with the arrow keys. This should be simple but i cant figure it out and its driving me insane. By the way the background and arrow that i need are attached at bottom. Thank you all and any  help is greatly apprectiated. I know here it appears i havent tried but trust me i have. I deleted most of the code in frustratian and googled to no avail. Good luck,
Zack

Heres some code

import pygame 

pygame.init()
import sys,random,os
from pygame.locals import*


clock=pygame.time.Clock()
clock.tick(20)

def main_menu():
    menuscreen=pygame.display.set_mode((640, 480))#FULLSCREEN
    pygame.display.set_caption('Dog Fight')
    #pygame.mouse.set_visible(False)

    WHITE=(255,255,255)
    BLACK=(0,0,0)
    GREEN=(0,255,0)
    BLUE=(0,0,255)
    background="" style="color:#2934d5">'data/background.png')
    #lasersound=pygame.mixer.Sound('data/lasershot.wav')

    


    menuexit=False

    while menuexit==False:
        menuscreen.blit(background,(0,0))

#AHHHHHHHH!!!!!!

        for event in pygame.event.get():
            if event.type==QUIT:
                pygame.quit()
                sys.exit()
        pygame.display.update()


main_menu()


   <----Theres the arrow i want blitted next to the menu and then return a 1 2 3 o4 4 depending on what its clicked on




Thats the menu