Zed McJack

Members
  • Content count

    27
  • Joined

  • Last visited

Community Reputation

349 Neutral

About Zed McJack

  • Rank
    Member
  1. [Development] Hooded Development #3

    Well, you are certainly right that writing your thoughts is much better than just thinking. The conversation is even better. Keep going and youll reach the target.
  2. [Case] Breakout!

    Its nice to read your thoughts on Breakout, especially considering that I plan to do that next.
  3. My first game MyPong, finished at last

    Thanks 1. You are right about paddle speed. I left it as it is now cause I wanted to finish game, it took me too long to actually finish it. Otherwise I could do more improvements. But anyway thanks. 2. Same as above. Its left as is, because of my lack of commitment. 3. You are again right I should move the code, probably to Game class. 4. Heh, At first I thought it was paddle speed and that I made mistake during translation, but its actually wrong variable name even in my language. Thanks man. Well, the game could be improved in many ways, but its good to know what other people think and see. Thanks again.
  4. My first game MyPong, finished at last

    Good idea! I should have thought about it myself. Thanks anyway, though I still need more people to look at the code. Well, I thought about starting my game, but decided to try out my hands first at breakout. I did some coding in JavaScript and I code regularly in VFP (database programing), but this is my new vice. Thanks
  5. Ok guys, it lasted more than 2 moths, but at last I finished my first game. It was actually finished month ago but I lost the endurance to sit and split the game in several files. So I did it today and now its here for review. I am not new to programming, but I am new to Python and game development. So I would like to hear whats ok and whats not ok and how to do it right. The game was written in my language and I translated variables, methods and class names to English an hour ago so you might notice some weird expressions. I started to pass object properties that I needed in class methods but switched to passing whole object, so you will see the difference. I am not sure is proper way to do it and is it efficient, but.. The game intentionally does not use sprites and images as I wanted to see is it possible to make this simple game without using images. Thanks PS For some reason I am not allowed to upload files so here is the code. File: MyPong.py# -*- coding: utf-8 -*- import pygame from pygame.locals import * from Pad import Pad from Ball import Ball from Text import Text from Game import Game #Creating instances game = Game() my_pad = Pad(0, 0, 100, 20, [255, 0, 255]) my_pad.rect.topleft = (100,430) ai_pad = Pad(0, 0, 100, 20, [255, 100, 100]) ai_pad.rect.topleft=(0, 30) ball = Ball(10,[0, 100, 50]) text_pause = Text("PAUSE", (255,255,255), None, game.background.get_rect().center, 100) my_result = Text("Player: %s" % my_pad.points, (150,255,0), (0, 0), (50,50), 30) ai_result = Text("AI: %s" % ai_pad.points, (150,255,0), (game.width-50, 0), (50,50), 30) while game.all_ok: game.update(my_pad, ai_pad, ball) if game.pause: if game.game_over: text_pause = Text("GAME OVER - The winner is: %s" % game.winner, (255,255,255), None, game.background.get_rect().center, 50) game.screen.blit(text_pause.text, text_pause.poz) else: my_pad.calculate_position(game.width) ai_pad.calculate_ai(ball.rect.center, game.width) ball.calculate_position(game, my_pad, ai_pad, my_result, ai_result) my_pad.rect.left+=my_pad.movement game.background.fill(game.background_color) game.screen.blit(game.background, game.background_rect) game.screen.blit(my_result.text, my_result.poz) game.screen.blit(ai_result.text, ai_result.poz) game.screen.blit(my_pad.picture, my_pad.rect) game.screen.blit(ai_pad.picture, ai_pad.rect) game.screen.blit(ball.picture, ball.rect) game.clock.tick(game.refresh_rate) pygame.display.flip() File: Pad.py# -*- coding: utf-8 -*- import pygame from pygame.locals import * class Pad(object): def __init__(self, x, y, width, height, color): self.x = x self.y = y self.width = width self.height = height self.ball_speed = 3 self.pad_direction = 0 self.movement = 0 self.points = 0 self.color = color self.picture, self.rect = self.draw_rectangle() def draw_rectangle(self): rectangle = pygame.Rect(self.x, self.y, self.width, self.height) picture = pygame.Surface(( self.width, self.height)) pygame.draw.rect(picture, self.color , rectangle) return picture , picture.get_rect() def calculate_position(self, width): #Calculate pad position if its in the screen if self.rect.left>=0 and self.rect.left+self.rect.width<=width: self.movement = self.ball_speed * self.pad_direction #If ball is out of the left border elif self.rect.left < 0: self.rect.left = 0 self.movement = 0 self.pad_direction = 0 #If ball is out of the right border elif self.rect.left+self.rect.width>width: self.rect.left = width - self.rect.width self.movement = 0 self.pad_direction = 0 def calculate_ai(self, ball_position, width): diff = abs(ball_position[0]-self.rect.center[0]) if self.rect.center[0] > ball_position[0]: if self.rect.left < 0: self.rect.left = 0 else: self.rect.centerx -=3 else: if self.rect.right > width: self.rect.right = width self.rect.centerx +=3 File: Ball.py# -*- coding: utf-8 -*- import pygame from pygame.locals import * from random import randint class Ball(object): def __init__(self, radius, color): self.directionX = -1 self.directionY = -1 self.positionX=randint(100,540) self.positionY=randint(100,380) self.radius = radius self.color = color self.ball_speed = 4 self.picture, self.rect = self.draw_circle(self.radius, self.color) self.picture.set_colorkey((0,0,0)) #Initial positioning is random self.rect.center = self.positionX, self.positionY def draw_circle(self, radius, color): size = radius*2 picture = pygame.Surface((size, size)) pygame.draw.circle(picture, color, (radius, radius), radius) return picture, picture.get_rect() def calculate_position(self, game, my_pad, ai_pad, my_result, ai_result): if not game.goal: if self.rect.top <= 0: my_pad.points +=1 my_result.text = my_result.font.render("Player: %s" % my_pad.points, 1, (150,255,0)) game.goal = 1 elif self.rect.bottom > game.height: game.goal = 1 ai_pad.points +=1 ai_result.text = ai_result.font.render("AI: %s" % ai_pad.points, 1, (150,255,0)) if ai_pad.points == 11 or my_pad.points == 11: if ai_pad.points == 11: game.winner = "AI" else: game.winner = "Player" game.game_over = 1 game.pause = 1 #If the ball is out of the right border, corection and changing the direction X if self.positionX > game.width-self.radius: self.positionX = self.positionX - self.ball_speed self.directionX = -1 #If the ball is out of the left border, corection and direction change if self.positionX < 0+self.radius: self.positionX = self.positionX + self.ball_speed self.directionX = 1 elif self.rect.bottom < 0 or self.rect.top > game.height: game.goal = 0 self.positionX = randint(100,540) self.positionY = randint(100,380) if randint(0,1): self.directionY = 1 else: self.directionY = -1 #updating new position self.positionX += self.ball_speed * self.directionX self.positionY += self.ball_speed * self.directionY self.rect.center = self.positionX, self.positionY File: Text.py# -*- coding: utf-8 -*- import pygame from pygame.locals import * class Text(object): def __init__(self, text, color, position, center, size): self.font = pygame.font.Font(None,size) self.text = text self.color = color self.text = self.font.render(self.text, 1, self.color) self.poz = self.text.get_rect() self.poz.center = center if position <> None: self.poz.topleft = position self.picture = pygame.Surface((self.poz.width, self.poz.height))   File: Game.py  # -*- coding: utf-8 -*- import pygame from pygame.locals import * class Game(object): def __init__(self): pygame.init() self.width, self.height = 640, 480 self.screen_resolution = (self.width, self.height) if pygame.display.mode_ok(self.screen_resolution): self.screen = pygame.display.set_mode(self.screen_resolution) self.refresh_rate = 40 self.clock = pygame.time.Clock() self.pause = 0 self.goal = 0 self.all_ok = 1 self.background_color = [0, 0, 0] self.background = pygame.Surface((self.width, self.height)) self.background_rect = self.background.get_rect() self.game_over = 0 self.winner = "" def update(self, my_pad, ai_pad, ball): keys = pygame.key.get_pressed() if keys[K_LEFT] or keys[K_RIGHT]: if keys[K_LEFT]: my_pad.pad_direction = -1 elif keys[K_RIGHT]: my_pad.pad_direction = 1 else: my_pad.pad_direction = 0 events = pygame.event.get() for event in events: if event.type == QUIT or (event.type == KEYDOWN and event.key in [K_ESCAPE, K_q]): #quiting self.all_ok = 0 elif event.type ==KEYDOWN and event.key == K_SPACE: if self.pause == 0: self.pause =1 else: self.pause = 0 if not self.pause: mylist = (my_pad.rect, ai_pad.rect) colision = ball.rect.collidelist(mylist) if colision == 0: # Ball hit the pad #from above if ball.rect.top < my_pad.rect.top and ball.rect.bottom > my_pad.rect.top: ball.directionY = ball.directionY * -1 ball.positionY = ball.positionY - ball.ball_speed #from side elif ball.rect.top < my_pad.rect.bottom: ball.directionX = ball.directionX * -1 ball.positionX = ball.positionX - ball.ball_speed elif colision == 1: if ball.rect.top <= ai_pad.rect.bottom: ball.directionY = ball.directionY * -1 ball.positionY = ball.positionY + ball.ball_speed
  6. How to create and work with not tile based map?

    [quote name='amrazek111' timestamp='1355323136' post='5009837'] Why not define provinces in terms of polygons? Sort the polygons spatially in some way and then a point-in-polygon test to determine exact polygon that's been selected. [/quote] Uh, I am note sure what you mean with "Sort the polygons spatially in some way"? You mean drawing polygons one by one? This might be what they do cause there is a file that represents rectangles that define extreme borders of the province in question (left, top, bottom, right). In this way they know where to draw the province although I have not seen single province images. They might acquire them from the big map or somehow? [quote] This has some advantages:[list] [*]Your artist could create any kind of map with any kinds of colors and details on it. An editor could be used to draw out the borders of the provinces. No requirements would be placed on the map, so your artist could add trees and other fine details without issue. This also means you could release the editor to your players and have them create their own maps easily if they wanted. [/list] [/quote] I cant imagine an editor with indenpendetly drawn provinces? How do you control their precise position on map? [quote][list] [*]You could easily determine which provinces are attackable from a given province based on which edges are shared. This would additionally make it easy to draw those attacker arrows, since you would have well-defined edges and could select the most visually appropriate one pretty easily [/list] [/quote] All adjacent provinces are kept in a file similar to the one I described for hit testing. There is a province Id, followed by ids of adjacent provinces so its easy to know where you can go. [quote][list] [*]Territories can be any shape (as long as the polygon isn't complex) and border any number of provinces (or none--say, an island) [*]Those overlays based on territory, economy or what have you would be really easy to implement. Just overlay a translucent filled polygon on each territory. You could also use the province's polygon to clip drawing on that province -- say, if you wanted to draw a texture on it. [/list] Boost has a really nifty Polygon library for C++ that would make this a snap. I'm sure Python has something similar you could use. [/quote] I am not sure if Python has such library, I am even not sure can it be done in Python? But I need some more info about substance of working with maps like this one.
  7. How to create and work with not tile based map?

    Ok, Ive researched this a bit further. The map is actually tiled based, but not in simple way. The position of the mouse click (X,Y) is used to find out what province is being clicked at in the following way. There used to be a file made of two parts of information. First part stored y values and pointer to the second part where there was block of information containing following pairs starting pixel, province id, ending pixel. So it was actually look-up table where you would first search your Y value and then jump to block that represent the X row. And than scan till you find your X pixels value and coresponding province id. That was in EU2 when they used 2D graphics, from EU3 they switched to 3D, but as I am planing to use 2D in my game it is good to know how they did it. This was just a simple hit test. But bigger problem was painting the map according to the applied filter. Its much more complicated and I dont really understand how they do that. They used quad tree, but its still mystery to me. If someone has some good reading please post links or write here. (I regret that I tagged topic with python cause I probably missed someone who has experience with this from other languages. Can moderator fix that?)
  8. How to create and work with not tile based map?

    [quote name='Cdrandin' timestamp='1354781472' post='5007674'] Aren't pixels essentially very tiny "tiles". Looks to me those irregular lines are just tiled in probably, but could be yet very inefficient. My guess, check collision in between these countries, at the point of collision place a tile and I guess do it for all edges then have it anti-aliased to make it look smoother and there is your outline i guess. I wouldn't know, but would be interested as to how to get that feature working. [/quote] Well, in this game the problem is not in checking collisions because there are not too many objects moving around. When enemy armies are in the same province the battle commence and that is all. Much of it is just abstracted, there are no bullets flying, just my attributes vs your attributes + - some other modifiers and die roll. The map is static, meaning the shapes of provinces are fixed in that big file (I havent supplied yet (but I can if you insist)), so if province change hands just different color is applied, there are no collisions to check. The armies are not moving, you issue an movement order, the path is calculated and an arrow is drawn that is being filled up. When arrow fills, the movement of armies occur and the engine draws the army sprite in the other province, and redraws the arrow if army is moving even further or erases the arrow if that province was final destination.
  9. How to create and work with not tile based map?

    [quote name='makuto' timestamp='1354745689' post='5007542'] I'm not sure if I understand your question. If you can, post the "huge map". That will make it a lot easier to see what you are wondering about. [/quote] Below is the screenshot of zoomed in map from EU3 game. This filter is political so it shows you countries. There are dozen filters that paint the map differently depending on what you want to see. For example Terrain map, Rebel risk map, Holy roman empire map, Economy map etc. The basis of this shown map is a BMP file of 38MB, with resolution 5616x2160 where the individual provinces are painted with different RGB color. As you could see from the pic the borders are irregular and province can have any number of bordering provinces from 1(island) to 7-8 I never actually counted what is maximum. I dont see this as tile based map, but you can prove me wrong. In tile based map you have screen (rectangle) divided in rows and columns. Each tile is a position on map. So you store tiled based map in an array and its easy to tell what (game) object is at what position and where it is heading. With eu3 map this is not the case.
  10. Determinism

    Its interesting that a couple of hours before finding this topic I was reading news about NASA big announcement from Mars mission that cant be announced yet, and from there, followed link about what is going on when we die. The[url="http://www.robertlanza.com/what-happens-when-you-die-evidence-suggests-time-simply-reboots/"] link[/url] went to the site of Robert Lanza who has theory called Biocentrism which states among other things that conciosness use tools like time and space to decsribe the world around us. He repeatedly says about experiment in quantum physic where [b]"measurements an observer makes can influence events that have already happened in the past[/b][b]. One experiment (Science 315, 966, 2007) confirmed that flipping a switch could retroactively change a result that had happened before the switch was flipped. Regardless of the choice you, the observer, make, it'll be you who will experience the outcomes ?- the universes ?- that will result.[/b][b]"[/b] So the world is as we see it or "the world is in the eye of beholder". [img]http://public.gamedev.net//public/style_emoticons/default/wink.png[/img]
  11. Ok, I know its early to think about creating map while I am still cleaning code for MyPong, but the idea for a strategic game like Paradox's Europa Universalis or Crusader King is haunting me. Anyway, from what I was researching their huge map is just bmp file. The provinces are painted with different RGB color which gives them number of 16,777,216 possible provinces. Thats way to much for my need, but its good to know how it works. The other files establish the ID of the province and coresponding provincial atributes. There are of course tons of missing information here but I could not find more info on this type of mapping which for me is not tile based though I might be wrong. If someone could give me links of their thoughts on this I would appreciate it.
  12. I was looking where I got my rating up, so in my profile under the ratings, there is a list of topics and rating earned. In this case topic was "Convicted felon as a game programmer", but clicking on a hiperlink brought 404 "page not found". There was no trace of that topic in the for beginers forum (as it should?) that it was moved. I tried search and found the topic in the "Breaking in the industry" forum at this link: [url="http://http://www.gamedev.net/topic/634143-convicted-felon-as-a-game-programmer/"]http://http://www.gamedev.net/topic/634143-convicted-felon-as-a-game-programmer/[/url] Now the poll is gone so it might be another bug? hth
  13. Convicted Felon as a game programmer

    I dont see how that has any connection with for beginners forum its more about society, but, yes, everyone deserves a second chance. Though I can argue that all system is ill based and obsolete, it does not work very much, except as means of ruining lifes of already socialy problematic people and their behaviours
  14. import issues in Python

    I think that I found where is the problem... In the begining of the root.py you define screen area with [source='lang="python"']DISPLAY = pygame.display.set_mode((640, 480))[/source] then in class Letter you have draw metod [source='lang="python"'] def draw(self, display): self.display = display display.blit(self.image, (self.x, self.y))[/source] where you recieve as parameter what to display and in while loop you have [source='lang="python"'] if event.key == pygame.K_a: global a print "detection" a.draw(DISPLAY)[/source] where you actually send your whole display to draw method of the letter class and with it you draw [b]only[/b] your screan again overwriting whole screen.
  15. import issues in Python

    I was reading your code a bit and even if I didnt find out why it does not display text I find that you have to better organize your code. You have parts of capturing input in check_input() function and part in several while loops. Whenever you find code that repeats move it in the function or class, add parameters and make it reusable. It wil be cleaner and easier to look at and find problematic spots. btw I still have uncorrected version of your code so I dont have a clue what you corrected to make root.py work again. hth Z