StevePaget / Pygame_Functions

A set of functions that make working with Pygame and Python much easier.
GNU General Public License v2.0
180 stars 88 forks source link

custom hitbox not working. #26

Closed xXLarryTFVWXx closed 5 years ago

xXLarryTFVWXx commented 5 years ago

Hi, new adopter to pygame_functions

I have a problem with my custom hitbox, mainly with location.

So I have a sprite with a green background (don't know how to make that color transparent, but that's eside the point), I found out that I can't use the touching function (also besides the point), so I decided to draw some rects instead for the hit boxes but I have a problem with one of the rects, no matter how many pixels I add to the x coordinate, it just doesn't move. Here's my code:

Note: I changed the name of the pygame_functions to pygfunc so it would be less likely for me to misspell.

Note 2: I also slightly modified pygame_functions a little, mainly adding support for left alt, capslock and function keys 1-12, also changed endWait() a little, moved clock() so the new endWait would work, nothing about any of the other functions or variables so it wouldn't have been from modding the file... I think?

Note 3: I also only have one sprite sheet at the moment.

[code] from pygfunc import *

screen size(600,600) screenRefresh = False

cara = {"sprite": makeSprite("images/cara.png", 4), "width": 19, "height": 27, "hitbox": {}} setBackGround color((0,0,139,255)) make music("music/testing.mid") play music(0) carb = {'sprite': makeSprite("images/cara.png", 4), "height": 27, "width": 19, "hitbox": {}} cara['x'] = 300 cara['y'] = 300

carb['x'] = 50 carb['y'] = 50

while True: cara['xa'] = cara['x']+2 cara['ya'] = cara['y']+1 cara['xb'] = cara['xa']+cara['width'] cara['yb'] = cara['ya']+cara['height'] carb['xa'] = carb['x']+2 carb['ya'] = carb['y']+1 carb['xb'] = carb['xa']+carb['width'] carb['yb'] = carb['ya']+carb['height'] moveSprite(carb['sprite'], carb['x'], carb['y'], False) if keyPressed("right"): changeSpriteImage(cara["sprite"], 1) if keyPressed("left"): changeSpriteImage(cara["sprite"], 2) if keyPressed("up"): changeSpriteImage(cara["sprite"], 3) if keyPressed("down"): changeSpriteImage(cara["sprite"], 0) if keyPressed("w"): cara['y'] -= 1 if keyPressed("a"): cara['x'] -= 1 if keyPressed("s"): cara['y'] += 1 if keyPressed("d"): cara['x'] += 1 showSprite(cara['sprite']) showSprite(carb['sprite']) drawRect(cara['xa'], cara['ya'], cara['width'], cara['height'], (255,0,0,128)) drawRect(carb['x']+1, carb['y']+1, carb['width'], carb['height'], (255,0,255,128))

tick(30)

stopMusic() pause(250) end() [/code]

I don't know what went wrong. will you please tell me what I did wrong?

StevePaget commented 5 years ago

You're changing Carb['xa'] etc, but you never actually change Carb['x']

It stays at 300 forever.

On Sat, 16 Mar 2019, 10:38 xXLarryTFVWXx, notifications@github.com wrote:

Hi, new adopter to pygame_functions

I have a problem with my custom hitbox, mainly with location.

So I have a sprite with a green background (don't know how to make that color transparent, but that's eside the point), I found out that I can't use the touching function (also besides the point), so I decided to draw some rects instead for the hit boxes but I have a problem with one of the rects, no matter how many pixels I add to the x coordinate, it just doesn't move. Here's my code:

Note: I changed the name of the pygame_functions to pygfunc so it would be less likely for me to misspell.

Note 2: I also slightly modified pygame_functions a little, mainly adding support for left alt, capslock and function keys 1-12, also changed endWait() a little, moved clock() so the new endWait would work, nothing about any of the other functions or variables so it wouldn't have been from modding the file... I think 🙄

Note 3: I also only have one sprite sheet at the moment.

[code] from pygfunc import *

screen size(600,600) screenRefresh = False

cara = {"sprite": makeSprite("images/cara.png", 4), "width": 19, "height": 27, "hitbox": {}} setBackGround color((0,0,139,255)) make music("music/testing.mid") play music(0) carb = {'sprite': makeSprite("images/cara.png", 4), "height": 27, "width": 19, "hitbox": {}} cara['x'] = 300 cara['y'] = 300

carb['x'] = 50 carb['y'] = 50

while True: cara['xa'] = cara['x']+2 cara['ya'] = cara['y']+1 cara['xb'] = cara['xa']+cara['width'] cara['yb'] = cara['ya']+cara['height'] carb['xa'] = carb['x']+2 carb['ya'] = carb['y']+1 carb['xb'] = carb['xa']+carb['width'] carb['yb'] = carb['ya']+carb['height'] moveSprite(carb['sprite'], carb['x'], carb['y'], False)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/StevePaget/Pygame_Functions/issues/26, or mute the thread https://github.com/notifications/unsubscribe-auth/ACfFQAUIw3zJk6nodav4QLRO1IpRqehVks5vXMm7gaJpZM4b3u8a .

StevePaget commented 5 years ago

50, I mean.

On Sat, 16 Mar 2019, 11:27 Steve Paget, pagetworld@gmail.com wrote:

You're changing Carb['xa'] etc, but you never actually change Carb['x']

It stays at 300 forever.

On Sat, 16 Mar 2019, 10:38 xXLarryTFVWXx, notifications@github.com wrote:

Hi, new adopter to pygame_functions

I have a problem with my custom hitbox, mainly with location.

So I have a sprite with a green background (don't know how to make that color transparent, but that's eside the point), I found out that I can't use the touching function (also besides the point), so I decided to draw some rects instead for the hit boxes but I have a problem with one of the rects, no matter how many pixels I add to the x coordinate, it just doesn't move. Here's my code:

Note: I changed the name of the pygame_functions to pygfunc so it would be less likely for me to misspell.

Note 2: I also slightly modified pygame_functions a little, mainly adding support for left alt, capslock and function keys 1-12, also changed endWait() a little, moved clock() so the new endWait would work, nothing about any of the other functions or variables so it wouldn't have been from modding the file... I think 🙄

Note 3: I also only have one sprite sheet at the moment.

[code] from pygfunc import *

screen size(600,600) screenRefresh = False

cara = {"sprite": makeSprite("images/cara.png", 4), "width": 19, "height": 27, "hitbox": {}} setBackGround color((0,0,139,255)) make music("music/testing.mid") play music(0) carb = {'sprite': makeSprite("images/cara.png", 4), "height": 27, "width": 19, "hitbox": {}} cara['x'] = 300 cara['y'] = 300

carb['x'] = 50 carb['y'] = 50

while True: cara['xa'] = cara['x']+2 cara['ya'] = cara['y']+1 cara['xb'] = cara['xa']+cara['width'] cara['yb'] = cara['ya']+cara['height'] carb['xa'] = carb['x']+2 carb['ya'] = carb['y']+1 carb['xb'] = carb['xa']+carb['width'] carb['yb'] = carb['ya']+carb['height'] moveSprite(carb['sprite'], carb['x'], carb['y'], False)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/StevePaget/Pygame_Functions/issues/26, or mute the thread https://github.com/notifications/unsubscribe-auth/ACfFQAUIw3zJk6nodav4QLRO1IpRqehVks5vXMm7gaJpZM4b3u8a .

xXLarryTFVWXx commented 5 years ago

Oh, okay then, that's an error on my part.

The reason why I have different x keys in the dicts is so then my hitbox can be either bigger or smaller than my sprite. (Feel free to use this in one of your tutorials)

If you'd like, I can put my modified pygame_functions file on GitHub, I'll make sure to credit you.