Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

stubborn code

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
4 replies to this topic

#1 MiniKong   Members   

178
Like
1Likes
Like

Posted 17 March 2013 - 01:43 AM

today i decided to do a simple shooter game so i could practice scrolling backgrounds but for some reason code that i use on a regular basis isn't working! my plan was to have the player shoot at/avoid  meteorites unfortunately my code to spawn multiple meteorites is only spawning a single one.iv spent hours trying to fix it.  i event opens a new page and typed up the code for that event but nothing seems to work. iv used similar code for my frogger clone and similar games. can someone please help? im sure its a noob mistake

Attached Files



#2 Alpheus   GDNet+   

6891
Like
2Likes
Like

Posted 17 March 2013 - 04:10 AM

Do you mind posting the code? Some people here don't trust downloads (from anybody). Plus it will be easier for people to respond to.


External Articulation of Concepts Materializes Innate Knowledge of One's Craft and Science
 
Beginner in Game Development? Read here. And read here.
 
Super Mario Bros clone tutorial written in XNA 4.0 [MonoGame, ANX, and MonoXNA] by Scott Haley
 
If you have found any of the posts helpful, please show your appreciation by clicking the up arrow on those posts Posted Image
 
Spoiler

#3 MiniKong   Members   

178
Like
0Likes
Like

Posted 17 March 2013 - 04:17 AM

Oh ok sure

#4 MiniKong   Members   

178
Like
1Likes
Like

Posted 17 March 2013 - 04:22 AM

 
 
# IMPORT------------------------------------------
 
import pygame, sys, random
from pygame.locals import*
 
pygame.init()
 
 
# DISPLAY----------------------------------------
screen = pygame.display.set_mode([500,700])
 
WHITE = (255,255,255)
BLUE  = (  0,  0,255)
 
 
 
#ENTITIES------------------------------------------
class backg(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load('stars.jpg')
        self.image = self.image.convert()
        self.rect = self.image.get_rect()
        self.dy = 5
        self.reset()
 
    def update(self):
        self.rect.bottom += self.dy
        if self.rect.top >= 0:
            self.reset()
 
    def reset(self):
        self.rect.bottom = screen.get_height()
 
#--------------------------------------------------
#this is the metorite
rock_speed = 3
class Rock(pygame.sprite.Sprite):
    def __init__(self):
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load('roid01.png')
        self.image.set_colorkey(WHITE)
        
        self.rect = self.image.get_rect()
 
    def reset_pos(self):
        self.rect.x = random.randrange(0,700)
        self.rect.y = 0
 
    def update(self):
        self.rect.y += rock_speed
 
        if self.rect.y > 600:
            self.reset_pos()
        
 
    
# ACTION------------------------------------------    
      # A - ASSIGN VALUES TO KEY VARIABLES----------------
 
Stars = backg()
star_list = []
#------------------------------------------
for i in range(100):
    x = random.randrange(0,500)
    y = random.randrange(-100,400)
    star_list.append([x,y])
    
#------------------------------------------------
#this is the metorite
rock_number = 5
for i in range(rock_number):
    srock = Rock()
    srock.rect.x = random.randrange(10,475)
    srock.rect.y = -100
 
    space_rocks = pygame.sprite.Group(srock)
 
 
#--------------------------------------------------------------
 
all_sprites_list = pygame.sprite.Group(Stars)
 
 
clock = pygame.time.Clock()
 
 
     # L - SET UP MAIN GAME LOOP-------------------------------
done = False
     
while done == False:
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        
 
    # draw background scrolling-------------------------------
    all_sprites_list.draw(screen)
    
    
    # draw scrolling stars
    for i in range(len(star_list)):
        pygame.draw.circle(screen,WHITE,star_list[i],2)
        star_list[i][1] += 15
 
        if star_list[i][1] > 700:
            y = random.randrange(-50,300)
            star_list[i][1] = y
 
            x = random.randrange(0,500)
            star_list[i][0] = x
       
            
 
      # T - TIMER TO SET FRAME RATE------------------------
    clock.tick(40)
 
      # E - EVENT HANDLEING
 
    space_rocks.draw(screen)
    
 
      # R - REFRESH DISPLAY---------------------------------
    space_rocks.update()
    all_sprites_list.update()
 
    pygame.display.flip()
    
pygame.quit()


#5 MiniKong   Members   

178
Like
1Likes
Like

Posted 17 March 2013 - 01:42 PM

ok i kinda figured out the problem. i decided to add the meteorites to the all_sprites_list< ill use the space_rocks group for collision instead.
its spawning more rocks but when its set to spawn 10 it only spawn like 5 >_<
but when i set rock_number to rock number = 5 * 2 and tell it to spawn the number in rock_number it will then spawn 5 rocks or what ever number i set the multiplied number by. And collision isn't working for the meteorites when I shoot them usually one will disapear and the others aren't affected

Edited by MiniKong, 17 March 2013 - 08:21 PM.





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.