Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Python Pyxel in the pyxel.blt(...rotate) [BUG / HELP] #586

Open
Zazoudu67 opened this issue Dec 13, 2024 · 1 comment
Open

Comments

@Zazoudu67
Copy link

Hello, sorry to bother you, I noticed myself and other friends using your Python library that when we want to use pyxel.blt(x, y, img, u, v, w, h, [colkey], [rotate], [scale])

we do rotation = float.
but the program displays this error:

pyxel.blt(self.player_x, self.player_y, 0, 0, 0, 8, 8, colkey=0, rotate=63.0, scale=1.0)
TypeError: blt() got an unexpected keyword argument 'rotate'

Process ended with exit code 1.
──────────────────────────────────────

could you tell us what to do if we made a mistake in the code? and if it is a bug, please give us an alternative that would work (we need it to study).

Thank you for your understanding and attention to my problem.

image

My code :

import pyxel, random

from random import randint

class Jeu:
    
    # =====================================================
    # == INITIALIZATION
    # =====================================================
    def __init__(self):
        #Screen variable
        self.sizeScreenGame_x = 200
        self.sizeScreenGame_y = 200
        self.fpsGame = 60
        self.sizeMap_x = 1000
        self.sizeMap_y = 1000
        
        #Camera variable
        self.camera_x = 0
        self.camera_y = 0
        
        #Player variable
        self.player_x = self.sizeScreenGame_x / 2
        self.player_y = self.sizeScreenGame_y / 2
        self.playerScaleSprite_x = 8
        self.playerScaleSprite_y = 8
        self.playerSpeedWalk = 1
        self.playerSpeedRun = 2
        self.playerSpeed = 0
        self.lifePlayerMax = 100
        self.lifePlayer = self.lifePlayerMax
        
        #Health Scroll Bar variable
        self.scollBar_x = 0
        self.scollBar_y = 8
        self.countScrollBar = 1
        self.colourScrollBar = 0
        
        #Score variable
        self.scoreKillEnemy = 0
        self.scoreBestKillEnemy = 0
        self.moneyPlayer = 0
                
        #Shooting variable
        self.shoot_list = []
        self.bulletSpeed = 6
        self.rpm = 0.3
        self.shootTime = self.rpm
        self.bulletDamage = 2
        
        #Enemi variable
        self.enemy_List = []
        self.countEnemyDebug = 0
        
        #Enemi Normal variable
        self.enemyNormalScaleSprite_x = 8
        self.enemyNormalScaleSprite_y = 8
        self.enemyNormal_list = []
        self.enemyNormalSpeed = 0.9
        self.enemyNormalDamage = 1
        self.lifeEnemyNormal = 10
        self.delaySpawnEnemyNormal = 10
        self.spawnTimeEnemyNormal = self.delaySpawnEnemyNormal
        self.giveMoney = 5
        
        #Menu in game variable
        self.gameInPause = False
        
        #Main menu variable
        self.gameIsLanching = True
        
        #Initialization of game
        pyxel.init(self.sizeScreenGame_x, self.sizeScreenGame_y, title="Crazy Hives", fps=self.fpsGame)
        pyxel.run(self.update,self.draw)
        pyxel.load("player.pyxres")


    # =====================================================
    # == UPDATE
    # =====================================================
    def update(self):       
        #Update menu in game
        self.menuInGame()

        #Update player
        if self.gameInPause == False:
            self.playerMove()
        #Update health scroll bar
            self.healthScrollBar()
        #Update shoot to player
            self.shootMove()
            self.shootPlayer()
            self.shootDamage()
        #Update enemi
            self.enemyNormalSpawn()
            self.enemyNormalMove()
            self.enemyNormalHealth()
            self.enemyNormalDoDamage()
        #Update timing game 
            self.shootTime -= self.fpsGame/1000
            self.spawnTimeEnemyNormal -= self.fpsGame/1000
            pyxel.camera(self.camera_x + self.playerScaleSprite_x/2, self.camera_y + self.playerScaleSprite_y/2)
        
        
    # =====================================================
    # == MENU
    # =====================================================
    def menuInGame(self):
        if pyxel.btn(pyxel.KEY_DELETE) and self.gameInPause == False :
            self.gameInPause = True
        elif pyxel.btn(pyxel.KEY_DELETE) and self.gameInPause == True :
            self.gameInPause = False
            
    #def mainMenu(self):
        
    
    # =====================================================
    # == GAME OVER
    # =====================================================
    
    
    
    # =====================================================
    # == PLAYER MOVE
    # =====================================================    
    def playerMove(self):        
        #Input to sprint
        if pyxel.btn(pyxel.KEY_SHIFT):
            self.playerSpeed = self.playerSpeedRun
        else:
            self.playerSpeed = self.playerSpeedWalk
            
        #Input to move player axe X and Y
        if (pyxel.btn(pyxel.KEY_D) or pyxel.btn(pyxel.KEY_RIGHT)) and self.player_x < (self.sizeMap_x - self.playerScaleSprite_x):
            self.player_x += self.playerSpeed
            self.camera_x += self.playerSpeed
            
        if (pyxel.btn(pyxel.KEY_Q) or pyxel.btn(pyxel.KEY_LEFT)) and self.player_x > 0:
            self.player_x -= self.playerSpeed
            self.camera_x -= self.playerSpeed
            
        if (pyxel.btn(pyxel.KEY_S) or pyxel.btn(pyxel.KEY_DOWN)) and self.player_y < (self.sizeMap_y - self.playerScaleSprite_y):
            self.player_y += self.playerSpeed
            self.camera_y += self.playerSpeed
            
        if (pyxel.btn(pyxel.KEY_Z) or pyxel.btn(pyxel.KEY_UP)) and self.player_y > 0:
            self.player_y -= self.playerSpeed
            self.camera_y -= self.playerSpeed
                           
    
    # =====================================================
    # == PLAYER SHOOT
    # =====================================================
    def shootPlayer(self):
        if pyxel.btn(pyxel.KEY_SPACE) and self.shootTime <= 0:
            self.shoot_list.append([self.player_x + (self.playerScaleSprite_x/2), self.player_y - (self.playerScaleSprite_y/2)])
            self.shootTime = self.rpm

    def shootMove(self):
        for shoot in  self.shoot_list:
            shoot[1] -= self.bulletSpeed      
            if  shoot[1]<- self.playerScaleSprite_y or shoot[0] <= 0 or shoot[1] <= 0 or shoot[0] >= self.sizeMap_x or shoot[1] >= self.sizeMap_y :
                self.shoot_list.remove(shoot)
                
    def shootDamage(self):
        for enemy in self.enemyNormal_list:
            for shoot in self.shoot_list:
                 if enemy[0] <= shoot[0]+1 and enemy[0]+8 >= shoot[0] and enemy[0]-8 <= shoot[0] and enemy[1]+8 >= shoot[1] and enemy[1]-8 <= shoot[1]:
                    enemy[2] -= self.bulletDamage
                    self.shoot_list.remove(shoot)
                    
    
    # =====================================================
    # == HEALTH SCROLL BAR
    # =====================================================
    def healthScrollBar(self):
        self.scollBar_x = self.lifePlayer/self.countScrollBar
        
        if self.lifePlayer >= 75:
            self.colourScrollBar = 11
        if self.lifePlayer < 75 and self.lifePlayer >= 50:
            self.colourScrollBar = 10
        if self.lifePlayer < 50 and self.lifePlayer >= 25:
            self.colourScrollBar = 9
        if self.lifePlayer < 25 and self.lifePlayer >= 0:
            self.colourScrollBar = 8
    
    # =====================================================
    # == ENEMY NORMAL
    # =====================================================    
    def enemyNormalSpawn(self):
        if self.spawnTimeEnemyNormal <= 0:
            self.enemy_List.append([self.enemyNormal_list.append([randint(0, self.sizeMap_x), randint(0, self.sizeMap_y), self.lifeEnemyNormal])])
            self.countEnemyDebug += 1
            self.spawnTimeEnemyNormal = self.delaySpawnEnemyNormal
        
    def enemyNormalMove(self):
        for enemy in self.enemyNormal_list:
            if self.player_x > enemy[0]:
                enemy[0] += self.enemyNormalSpeed
            elif self.player_x < enemy[0]:
                enemy[0] -= self.enemyNormalSpeed

            if self.player_y > enemy[1]:
                enemy[1] += self.enemyNormalSpeed
            elif self.player_y < enemy[1]:
                enemy[1] -= self.enemyNormalSpeed
    
    def enemyNormalDoDamage(self):
        for enemy in self.enemyNormal_list:
            if enemy[0] <= self.player_x and enemy[0]+self.enemyNormalScaleSprite_x >= self.player_x and enemy[0]-self.enemyNormalScaleSprite_x <= self.player_x and enemy[1]+self.enemyNormalScaleSprite_y >= self.player_y and enemy[1]-self.enemyNormalScaleSprite_y <= self.player_y:
                self.lifePlayer -= self.enemyNormalDamage
    
    def enemyNormalHealth(self):
        for enemy in self.enemyNormal_list:
            if enemy[2] <= 0:
                self.enemyNormal_list.remove(enemy)
                self.scoreKillEnemy += 1 
                for enemyListing in self.enemy_List:
                    self.enemy_List.remove(enemyListing)
                    

    # =====================================================
    # == DRAW
    # =====================================================
    def draw(self):
        #color background screen
        pyxel.cls(0)
        pyxel.rect(0,0,self.sizeMap_x, self.sizeMap_y, 1)
        
        #player sprit
        #pyxel.rect(self.player_x, self.player_y, self.playerScaleSprite_x, self.playerScaleSprite_y,2)
        pyxel.rectb(self.player_x, self.player_y, 8, 8, 2)
        pyxel.blt(self.player_x, self.player_y, 0, 0, 0, 8, 8, colkey=0, rotate=63.0, scale=1.0)
        
        #health scroll bar sprite
        pyxel.rect((self.player_x + 5) - (self.sizeScreenGame_x/2), (self.player_y + 5) - (self.sizeScreenGame_y/2), self.lifePlayerMax, self.scollBar_y, 13)#Background of Scroll Bar
        pyxel.rect((self.player_x + 5) - (self.sizeScreenGame_x/2), (self.player_y + 5) - (self.sizeScreenGame_y/2), self.scollBar_x, self.scollBar_y, self.colourScrollBar)
        pyxel.text((self.player_x + 7) - (self.sizeScreenGame_x/2), (self.player_y + 6) - (self.sizeScreenGame_y/2), "Player Life : " + str(self.lifePlayer), 0)
        
        #shoot sprit
        for shoot in self.shoot_list:
            pyxel.rect(shoot[0], shoot[1], 1, 4, 10)
            
        #enemy normal sprit
        for enemy in self.enemyNormal_list:
            pyxel.rect(enemy[0], enemy[1], self.enemyNormalScaleSprite_x, self.enemyNormalScaleSprite_y, 4)
            pyxel.text(enemy[0], enemy[1], str(enemy[2]),0)
            
        #variable text
        pyxel.text(self.player_x + (self.sizeScreenGame_x/2) - 100, (self.player_y + 5) - (self.sizeScreenGame_y/2), "Enemy Killing : " + str(self.scoreKillEnemy),15)
        
Jeu()
@DiddiLeija
Copy link
Contributor

What's your Pyxel version? rotate is a recent addition, so if you're using a lower Pyxel version the keyword doesn't exist at all. Try updating your Pyxel distribution and retry, then let us know if it worked :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants