At the program start, you should disable all turtle animations and make the turtle hidden. Next your program should implement the following requirements.
Prompt the user for a couple of inputs, the grid size N and a difficulty level between 1 to 3.
Draw an N × N grid as shown in this figure. Put the game title, start button and score on the top.
Handle mouse clicks in the turtle window. Clicking on the start button should, well, start the game but other clicks should be ignored.
Implement the gameplay, which includes displaying ten squares on the grid one after the other. Display the current square number (1 to 10) at the top. Each square should occupy a random box on the grid. A square would only stay on screen for a period of 2, 1.5 or 1 seconds, corresponding to difficulty levels of 1, 2 and 3 respectively.
Let the user play the game with mouse. Objective of the game is to shoot (click) as many squares as possible. A hit increases the score and a miss deducts the score by one. Only the clicks inside grid boundaries should be entertained. If a square is successfully hit, its colour should change to give user an indication of success.
Once the time is elapsed for all ten squares, replace the box number at the top with the ‘finished’ label.
Note that turtle graphics do not provide support for erasing a part of drawing (or text). To mimic erasing, you should repaint the desired area with a white (or whatever your background color) filled rectangle.
To show and hide the target squares at regular time intervals, do not use a loop. This job can be managed via task scheduling as shown below in the sample codes.
Constraints
You can only import the following library modules: turtle, threading, random, math, sys
In many online examples of turtle graphics applications, multiple turtle objects are used on the same window. You are NOT allowed to proceed that way. Use a single turtle for all drawings.
You should follow good programming practices, for example using named constants, creating several reusable functions (top down design) and minimizing the use of global variables. A few global variables will be essential though, for example, to store the data required by multiple functions.
Suggested dimensions and locations of elements
Window size: 750 × 800
Grid Size: 700 × 700
Bottom left corner of grid: (–350, –375)
Size of target squares: Depends on size of a grid box. Leave 10 pixels margin around sides, so that squares do not touch the grid lines.
Game title text location: (–350, 345) left aligned
Start button / current square number location: (0, 345) centre aligned
Score display location (350, 345) right aligned
Related
I am make a rhythm game where you click on a circle to the beat of a song and want to use the range of frequency in the song to determine where the circle is placed on the screen. For example for higher frequencies they may be placed in the top left quadrant and for lower frequency in the top right quadrant. Is there anyway of doing this in python or at all?
I have not try the problem out because I do not know where to start with the problem.
So I dont have code because its not an issue with coding as I already have the program done and working however I noticed that:
In gaming menus mouse sensitivity doesnt matter because I set coords to click/move and since its not sensitivity related it works just fine.
However,
When moving a game camera(character view) if I do for example 'move 1000 pixels to the right' this will be affected by mouse sensitivity & ingame sensitivity is there no way to make this work in all resolutions / mouse sensitivity?
Essentially I need to be able to make my friends 'camera"/'character view' to move as much as mine while having a different mouse DPI
Instead of moving in a relative way move to a fixed point of your display for example:
import pyautogui
import time
time.sleep(3)
pyautogui.moveTo(100, 100)
This will move your mouse to 100 pixels along 100 pixels down on your monitor. Other examples:
# To make it drag along the screen
# (x, y, time taken)
pyautogui.moveTo(100, 100, 5)
# To make it hold while moving
# The 5 slows it
pyautogui.dragTo(100, 100, 5)
# To check if the next move pos is on display
# This will return false
pyautogui.onScreen(0, -1)
# To Move only x/y
pyautogui.moveTo(None, 500)
Allthough pyautogui should only move directional to the pixels irrespective of the DPI so may you please attach your code.
I'm trying to program an experiment in which I want to find out how humans cognitively segment movement streams. For example, if the movement stream could is a person climbing a flight of stairs, each step might be a single segment.
The study is bascially a replication of this one here, but with another set of stimuli: http://dl.acm.org/citation.cfm?doid=2010325.2010326
Each trial should be structured like the following:
Present a video of a motion stream. Display a bar beneath the video that has a marker that moves in sync with the current time of the video (very similar to GUI of a video player).
Present that video again, but now let the participant add stationary markers to the bar beneath the video by pressing a key. The marker is supposed to be placed at the time point in the video bar that corresponds with the time the buttom was pressed (e.g. when the video is 100 seconds long and the buttom was pressed 10 seconds into the video, it should be placed at the 10% mark of the bar).
My instructor suggested programming the whole thing using PsychoPy. PsychoPy currently only supports Python 2.7.
I've looked into the program and it looks promising. One can display a video easily and the rating scale class is similar to the bar we want to implement. However, several features are missing, namely:
One can only set a single marker, subjects should be able to set multiples
As mentioned in point (1) we want to have a marker that moves in synch with the video.
When a key press occurs a marker should be placed at the point in the bar that corresponds with the current time point in the video.
Hence my questions: Do you have any tips for implementing the features described above using the PsychoPy module?
I don't know how much this gets into recommendation question territory, but in case you know of a module for writing experiment GUIs that has widgets with the features we want for this experiment I would be curious to hear about them.
PsychoPy is a good choice for this. The rating scale however (as you note) is probably not the right tool for creating the markers. You can make simple polygon shapes though, which could serve as your multiple markers as well as the continuous time indicator.
e.g. you could make a polygon stimulus with three vertices (to make a triangle indicator) and set its location to be something like this (assuming you are using normalised coordinates):
$[((t/movie_duration) * 2 - 1) , -0.9]
t is a Builder variable that represents the time elapsed in the current trial in seconds. The centre of the screen is at coordinates [0, 0]. So the code above would make the pointer move smoothly from the left hand edge of the screen to the right, close to the bottom edge of the screen, reaching the right hand edge once the move ends. Set the polygon's position field to update every frame so that the animation is continuous.
movie_duration is a placeholder variable for the duration of the movie in seconds. You could specify this in your conditions file, or you can query the movie component to get its duration I think, something like:
$[((t/movie_stim_name.duration()) * 2 - 1) , -0.9]
You could leave markers on the screen in response to keypresses in a similar way, but this would require a little Python code in a code component.
I am working on a Tank game as a school project and I am trying to make it as user-friendly as possible (with things like customizable keybindings, display settings). However, I don't want the game window to lose it proportions so I figured I would add borders to the sides of the game window in order to support wide screens.
I've attached an imageto illustrate what I'm looking for:
So for this to work, I would need a way to make "screen layers". The base layer is the whole screen with some graphics on the sides added to it and a font displaying score. And then a second layer would be rendered in the middle of the screen which will be the game window and its width and height will be obviously smaller than the base layer.
At the moment, the game is rendered from the top left corner of the screen until all the tiles have been rendered out. So that is why I figured it would be the best to make the tiles render out on a separate surface positioned in the middle of the screen surface.
Would really appreciate some tips on how I can make this possible! :) I don't have that much experience in Classes and pygame, so it would be awesome if you could give a fleshed out description as well! :D
Just draw your different stuff on different surfaces.
For example, create a Surface for your game window (let's call it game_surf), and draw your tanks and bullets etc. on that new Surface instead of the pygame main window (which is just another Surface).
# the main window
screen = pygame.display.init()
# just a regular surface
game_surf = pygame.surface.Surface(width, height)
...
# in your main loop
# or however you draw your sprites
your_sprite_group.draw(game_surf)
Then blit it onto the screen
screen.blit(game_surf, the_position)
Simplest way: Create a group for each 'layer'.
import pygame
front_sprites = pygame.sprite.Group()
middle_sprites = pygame.sprite.Group()
background_sprites = pygame.sprite.Group()
Then, just draw them all onto the screen in the following order:
background_sprites.draw(screen)
middle_sprites.draw(screen)
front_sprites.draw(screen)
Thanks for taking the time to read this.
Right now I'm making a really basic tile based game. The map is a large amount of 16x16 tiles, and the character image is 16x16 as well. My character has its own class that is an extension of the sprite class, and the x and y position is saved in terms of the tile position.
To note I am fairly inexperienced with pygame.
My question is, I am planning to have character movement restricted to one tile at a time, and I'm not sure how to make it so that, even if the player hits the directional key dozens of time quickly, (WASD or arrow keys) it will only move from tile to tile at a certain speed. How could I implement this generally with pygame? (Similar to game movement of like Pokemon or NexusTk). One movement would result in a player being in a tile. They couldn't stop halfway between tiles for example.
Thanks for your time! Ryan
You store your characters location as a grid coordinate. So if he's at (2,0) he is rendered at (32,0). The game then animates him moving between tiles, but, he's either on one or the other. While in the move state, you render an (x,y) offset between 0 to tilewidth.
It sounds like you want one move per keypress, if time elapsed / animation has completed. So:
On keypress, toggle to: animating state
Set destination tile coordinate
draw offset, between 0 and tilewidth, depending on time elapsed. offset = (elapsed_ms / 1000.) * tile_w would scale between 0 to 16 if time is less<= 1 second.
Once time elapsed is >= animation length (I chose 1000. above), switch to stationary state.
If keypress happens while in animation state, ignore it.
Pygame example: using numpy for map array.