Reading and Altering Drawing Tablet inputs for use in FPS games - python

Not an important question, I know, but just a silly side project a friend asked of me. Is there a way I can read and alter the inputs from a drawing tablet so that I can use it in a First Person Shooter game, using something like Python.
From what I know, the pen will set the mouse position to the location corresponding to the tablet, which causes you to stare at the ground and spin, verses a mouse changing the current location of the mouse, which is what a game is expecting.
My plan is to read the location of the pen compared to the last location, have the mouse moved to that location on the screen, instead of set to the location.
Any tips or guidance is appreciated!

It is already possible, if you change the drawing tablet input mode from absolute to relative

Related

Trying to fix a script for a game I play (Wizard101 Auto Farming)

I've been trying to tailor this code to work for my desktop so I can auto-farm some enemies in this game I play. Right now the code is stuck at a point where it scans the UI at a certain pixel for a certain shade of blue. if it's the correct shade, the code progresses. if not, it completely stops. I'm not sure what to do but if someone could take a look I'd greatly appreciate it. Here are some screenshots and the code:
Also, the code is broken into two pieces: the first script which allows for interaction with the game, and the second being programming automatic movement, clicking etcetera. the second piece is simple enough where it doesn't need to be put here, nor is it necessary.
First Piece (main problem is in the POSITION and COLOR part of def is_mana_low:
def is_mana_low(self):
self.set_active()
# Matches a pixel in the lower third of the mana globe
POSITION = (79, 565)
COLOR = (66, 13, 83)
THRESHOLD = 10
return not self.pixel_matches_color(POSITION, COLOR, threshold=THRESHOLD)
def use_potion_if_needed(self):
mana_low = self.is_mana_low()
health_low = self.is_health_low()
if mana_low:
print('Mana is low, using potion')
if health_low:
print('Health is low, using potion')
if mana_low or health_low:
self.click(160, 590, delay=.2)
My Discord is APieceofString#5151 if you wanted to hit me up for more information or a better explanation. I really appreciate this :)
I had the same issue when setting it to a specific x,y coordinate. So here's how I resolved this:
I used pyautogui and cv2. I got a screen cap, and then created a fairly thin rectangle, right below where the yellow number showing your remaining mana is, and going from the edge of the Energy globe to the edge of the mana globe. And then while my script is running, it checks for a match of that rectangle. If there's a match, you have plenty of mana, if not, you may want to drink a potion.
I tried to do the same thing to check for mana wisps, and if it sees one on the screen, run to the wisp, and then back to the home position (but that function is kind of hinky atm and I'm trying to get it working better).

How to make something rotate based on where another object is

I am making a scrolling background type of game, kind of like Mario. I have a character that walks on the ground and can go left or right, and I want to introduce a flying eyeball that is suspended in the sky that follows the character's movements. I have an eyeball png (the eye of chuthulhu from Terraria). All I want it to do is rotate based on where the character is, and seem to stare at it (the next step is to have it shoot lasers at the character). How would I do this? Thanks in advance.
You could use the PyGame function pygame.transform.rotate() or pygame.transform.rotozoom() to pre-create rotated versions of your eyeball.
It sounds like the eyeball will pass over the top of the player when the player changes walking directions (since it's always following). So simply comparing the difference in sideways-position between the player and the eyeball should be enough to determine which of the pre-rotated eyeball images to choose.
If the eyeball's X co-ordinate is a long way from the player, then a slight angle is needed. As the player gets closer to having the eyeball above them, the angle should change to the point where the eye is looking straight down. This corresponds to the difference between the eyeball-X and player-X being small (tending towards zero).
Maybe even a simple mapping table between X-difference and sprite-image would be enough.

Create a menu home screen for piTFT using pygame

I would like to create a home screen(menu) for my project using pygame(?).
I have a piTFT 2.8" Capactive display from adafruit.
I have design the whole display menu. Take a look on this demo screen for example:
Now I would like to built this on my pi. is there any easy way to position each element as can be seen on the attached image?
The display is 320 x 240, and I think if I try position the elements blindly it will take a lot of time which in this case, I dont really have spare time to waste.
Have you got any other suggestions about the use of pygame? Would you suggest me something different?
This answer may be a bit general, but what I do to find each position is go to paint or some paint program and then I add markers where positions are, then I can select rectangles and find there positions. It would be hard to find the positions by itself just from that image. Do you have a mac, windows, linux?'
just paste your menu, into the paint program and draw rectangles around certain icons, after that just go to the top left of the rect and it will tell you the position, so you will get both the width, height, and position.

2D Game Engine - Implementing a Camera

So I've been making a game using Python, specifically the PyGame module. Everything has been going fairly well (except Python's speed, am I right :P), and I've got a nice list of accomplishments from this, but I just ran into a... speedbump. Maybe a mountain. I'm not to sure yet. The problem is:
How do I go about implementing a Camera with my current engine?
That probably means nothing to you, though, so let me explain what my current engine is doing: I have a spritesheet that I use for all images. The map is made up of a double array of Tile objects, which fills up the display (800 x 640). The map also contains references to all Entity's and Particles. So now I want to create a a camera, so that the map object can be Larger than the display. To do this I've devised that I'll need some kind of camera that follows the player (with the player at the center of the screen). I've seen this implemented before in games, and even read a few other similar posts, but I need to also know Will I have to restructure all game code to work this in? My first attempt was to make all object move on the screen when the player moves, but I feel that there is a better way to do this, as this screws up collision detection and such.
So, if anyone knows any good references to problems like this, or a way to fix it, I'm all ears... er.. eyes.
Thanks
You may find this link to be of interest.
In essence, what you need to do is to distinguish between the "actual" coordinates, and the "display" coordinates of each object.
What you would do is do the bulk of the work using the actual coordinates of each entity in your game. If it helps, imagine that you have a gigantic screen that can show everything at once, and calculate everything as normal. It might help if you also designed the camera to be an entity, so that you can update the position of your camera just like any other object.
Once everything is updated, you go to the camera object, and determine what tiles, objects, particles, etc. are visible within the window, and convert their actual, world coordinates to the pixel coordinates you need to display them correctly.
If this is done correctly, you can also do things like scale and otherwise modify the image your camera is displaying without affecting gameplay.
In essence, you want to have a very clear distinction between gameplay and physics logic/code, and your rendering/display code, so your game can do whatever it wants, and you can render it however you want, with minimal crossover between the two.
So the good news is, you probably don't need to change anything about how your game itself works. The bad news is, you'll probably have to go in and rewrite your rendering/drawing code so that everything is drawn relative to the camera, not to the world.
Since I can't have a look into your code, I can't assess how useful this answer will be for you.
My approach for side scroller, moveable maps, etc. is to blit all tiles onto a pygame.Surface spanning the dimensions of the whole level/map/ etc. or at least a big chunk of it. This way I have to blit only one surface per frame which is already prepared.
For collision detection I keep the x/y values (not the entire rect) of the tiles involved in a separate list. Updating is then mainly shifting numbers around and not surfaces anymore.
Feel free to ask for more details, if you deem it useful :)

how to add interface in python, with pygame

Help! I am new to programming! I am trying to make a monopoly game. My program so far creates player and card objects, these objects have some values stored.
I am trying to use pygame to implement some kind of animations and create a menu bar that pops up on the pygame screen, but I don't know how to get started. So far all I have is a pygame background screen, I want to know how I can place a small rectangle on the pygame screen given position, depending on the players object's position value. I need to know how I can have all that code I have written just for the game logic, and have it run along side with this pygame stuff.
I really need to know how to get started. If anyone is willing to spend some time with me, to get me going in the right direction, I would really appreciate it, thanks!
Reading over some pygame tutorials will certainly help.
The flow of your program will eventually look something like this:
# This is intentionally simplified pseudocode, but at the bottom-most level most
# simple games have a similar structure to this.
#Construct your game objects
players = [Player(args) for n in range(num_players)]
cards = loadCards() #or however you load your cards (files,database,etc)
board = Board()
#initialize your display context
pygame_screen.init() #or whatever is the correct syntax for Pygame
# Main game loop
while 1:
check_inputs() #get key/mouse input inputs for this frame
handle_inputs() #handle each input that has occurred during this frame
update_gamestate() #update the state on the game (who's turn, etc)
update_display() #update pygame window graphics (draw stuff, flip display)
cleanup()
As for the details on how to draw rectangles and whatnot, you should read about the various draw functions here

Categories

Resources