I didn’t actually try to do a project today but I did watch a few videos on how to make a FPS 3D game in Unity. It explained the basics on how to make the player rig, and the different components to make the player rig be able to be controlled. It also explained the basic movement for the player rig, how to connect them to VS code in Unity, and rigging components together to make the player rig moveable.
That’s the farthest I got since I decided it would be a splendid idea and go do other errands… I promise to actually work on something next Friday :D.
This year went by FAST. Quicker than sophomore year and MUCH quicker than freshman year. I honestly don’t know what things we did this year that I liked the most. I did like learning about JavaScript and using it to make websites in the backend, even though it was pretty confusing. I do like messing around in the frontend more than the backend because it gives me more freedom, but the backend makes your website POP in a way that the frontend doesn’t. IDK I know there’s tons of other stuff we’ve done this year but my mind has forced me to not remember maybe because of how stressful and frustrating it was, but that’s how it is with coding. I kinda enjoyed this year. I just hope senior year is just as fun ;-;.
import pygame as pg
# general setup
pg.init()
pg.display.set_caption("Space Shooter")
WINDOW_WIDTH, WINDOW_HEIGHT = 1280, 720
display_surf = pg.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
run = True
while run:
#event loop
for event in pg.event.get():
if event.type == pg.QUIT:
run = False
#draw the game
display_surf.fill('dodgerblue1')
pg.display.update()
pg.quit()
created the window using pygame!!!!
Create a window width and height global variables for the window.
WINDOW_WIDTH, WINDOW_HEIGHT = 1280, 720
Make a display surface variable that sets the width and height for the pygame window.
Make a while loop so that it stays on the screen and so the user can close the window at any time.
while run:
#event loop
for event in pg.event.get():
if event.type == pg.QUIT:
run = False
Now instead of having a black background, change the background color using the .fill() method. After that, use the .update() method to put it on the screen
#draw the game
display_surf.fill('dodgerblue1')
pg.display.update()
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap');
body {
font-family: "Poppins", sans-serif;
}
app.js
import LoginRegister from './components/LoginResgister/LoginRegister';
function App() {
return (
<div>
<LoginRegister />
</div>
);
}
export default App;
I tweaked up app.js and took out all the sample code from index.css and put the stuff needed for the font we’re using. Then I added login inputs for username and password.
added the ability to move the player’s car left/right using the arrow keys.
if event.type == KEYDOWN:
if event.key == K_LEFT and player.rect.center[0] > left_lane:
player.rect.x -= 100
elif event.key == K_RIGHT and player.rect.center[0] < right_lane:
player.rect.x += 100
result:
left lane
and right lane (also added other cars. i’ll get to that later)
Made the crash image pop up determining where the player crashed into the npc car
# check if there's a side swipe collision after changing lanes
for vehicle in vehicle_group:
if pygame.sprite.collide_rect(player, vehicle):
gameover = True
# place the player's car next to other vehicle
# and determine where to position the crash image
if event.key == K_LEFT:
player.rect.left = vehicle.rect.right
crash_rect.center = [player.rect.left, (player.rect.center[1] + vehicle.rect.center[1]) / 2]
elif event.key == K_RIGHT:
player.rect.right = vehicle.rect.left
crash_rect.center = [player.rect.right, (player.rect.center[1] + vehicle.rect.center[1]) / 2]
So my main.py file for the racing game just pooped out for no reason and I can’t open it back up without getting an error. The only thing I am able to open is utils.py and the images. That’s it.
So, I copied the code from github and started off from where I think I left off.
PlayerCar is MUCH shorter and only has the image of the car that we need and the start position of the car.
class PlayerCar(AbstractCar):
IMG = GREY_CAR
START_POS = (180, 200)
and a draw function that draws the images, and the player car on the screen.
def draw(win, images, player_car):
for img, pos in images:
win.blit(img, pos)
player_car.draw(win)
pygame.display.update()
made while loop function that starts and quits the game (when the user clicks the x) and also has the keys to control the player car.
while run:
clock.tick(FPS)
draw(WIN, images, player_car)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
break
keys = pygame.key.get_pressed()
moved = False
if keys[pygame.K_a]:
player_car.rotate(left=True)
if keys[pygame.K_d]:
player_car.rotate(right=True)
if keys[pygame.K_w]:
moved = True
player_car.move_forward()
if not moved:
player_car.reduce_speed()
pygame.quit()
result:
You can move it but these dang computers don’t have screen recording (curse you IT!!!!)
for row in range(rows + 1):
y = origin_offset.y + row * TILE_SIZE
pygame.draw.line(self.display_surface, LINE_COLOR, (0,y), (WINDOW_WIDTH,y))
Same as x, but it makes lines horizontal from the left to the right of the window
This is what the it should look like. The y tile lines will be horizontal, and the x tile lines will be vertical.
Result:
Tried to make the lines green so it will look better and…
oh boy…
Okay I took out the green and made the lines a little transparent.
Changing the mouse cursor
Changed the mouse cursor to this:
What we need in order to change the mouse is to find the clickable area, which would be somewhere around the tip of the mouse, the rest is the attached stuff to it.
We load the image in, then we set where it should be clickable. In this case, it’s (o,0). After that, we replace the mouse with the cursor that we have.
result:
Creating the menu
To make the menu work, in editor.py we’ll have a variable called selection_index that will have value between 2 and 18. Each number represents a certain kind of tile in the editor.
Ex. 2: water, 3; terrain, 4: gold coin and so on.
The selection_index can be changed by clicking on the menu or via hotkeys (this is where that colossal file settings.py comes in).
what we will need are the indexes 2-18. 0 and 1 are ignored b/c 0 is the player and 1 is the sky. They will also be in the editor so they don’t need to be created.
2-18 the player can create like the terrain, coin, etc…
Making the hotkeys for the menu
editor.py
def selection_hotkeys(self, event):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
self.selection_index += 1
if event.key == pygame.K_LEFT:
self.selection_index -= 1
Detects if the user is pressing a button. It’s not checking if we’re holding down a button so there’s no need for a timer.
The problem is that when you repeatedly press the button the number can go below 0 and above 18.
The menu took a little bit for me b/c there was something wrong with the place of the rectangle. It kept going offscreen (I put a random number for one of the window dimensions instead of its variable).