Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from com.badlogic.gdx import Gdx, Game, Screen
- from com.badlogic.gdx.graphics.g2d import BitmapFont, SpriteBatch, Sprite
- from com.badlogic.gdx.graphics import GL10, Texture, Pixmap, Color
- import random
- class Mine(Sprite):
- def __init__(self):
- tex = Texture(Gdx.files.internal("assets/gfx/tile_untouched.png"))
- Sprite.__init__(self, tex)
- # 10% chance for true, else false
- self.is_mine = (random.random() < 0.1)
- def reveal(self):
- pass
- class PoopSweeper(Game):
- def create(self):
- self.batch = SpriteBatch()
- self.font = BitmapFont()
- self.screen = PlayScreen(self)
- def dispose(self):
- self.batch.dispose()
- self.font.dispose()
- def render(self):
- self.super__render()
- class PlayScreen(Screen):
- def __init__(self, game):
- self.game = game
- self.font = BitmapFont()
- self.batch = game.batch
- # Init 25*25 mines
- self.mines = []
- for _ in range(25*25):
- self.mines.append(Mine())
- # Create 25*25 grid
- self.grid = Pixmap(16*25, 16*25, Pixmap.Format.RGBA8888)
- self.grid.setColor(Color.LIGHT_GRAY)
- for line_x in range(25):
- self.grid.drawLine(16*line_x, 0, 16*line_x, Gdx.graphics.height)
- for line_y in range(25):
- self.grid.drawLine(0, 16*line_y, Gdx.graphics.width, 16*line_y)
- def update(self):
- delta = Gdx.graphics.getDeltaTime()
- def render(self):
- self.update()
- # Clear screen
- Gdx.gl.glClearColor(0, 0, 0.2, 1)
- Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT)
- self.batch.begin()
- # Draw FPS number
- self.font.draw(self.batch, "FPS: {0}".format(Gdx.graphics.framesPerSecond), 10, Gdx.graphics.height-10)
- # Draw grid
- self.batch.draw(self.grid, 0, 0)
- self.batch.end()
Advertisement
Add Comment
Please, Sign In to add comment